00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032 #ifdef HAVE_SYS_TYPES_H
00033 # include <sys/types.h>
00034 #endif
00035 #include <time.h>
00036 #include <string.h>
00037 #include <regex.h>
00038
00039 #include <cxstring.h>
00040 #include <cxstrutils.h>
00041
00042 #include <cpl_msg.h>
00043 #include <cpl_error.h>
00044 #include <cpl_matrix.h>
00045
00046 #include "gialias.h"
00047 #include "gimessages.h"
00048 #include "giutils.h"
00049
00050
00059
00060
00061
00062
00063 static const cxchar *_giraffe_license =
00064 " This file is part of the GIRAFFE Instrument Pipeline\n"
00065 " Copyright (C) 2002-2006 European Southern Observatory\n"
00066 "\n"
00067 " This program is free software; you can redistribute it and/or modify\n"
00068 " it under the terms of the GNU General Public License as published by\n"
00069 " the Free Software Foundation; either version 2 of the License, or\n"
00070 " (at your option) any later version.\n"
00071 "\n"
00072 " This program is distributed in the hope that it will be useful,\n"
00073 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00074 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00075 " GNU General Public License for more details.\n"
00076 "\n"
00077 " You should have received a copy of the GNU General Public License\n"
00078 " along with this program; if not, write to the Free Software\n"
00079 " Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301"
00080 " USA";
00081
00082
00083 inline static cxint
00084 _giraffe_plist_append(cpl_propertylist *self, cpl_property *p)
00085 {
00086
00087 const cxchar *name = cpl_property_get_name(p);
00088 const cxchar *comment = cpl_property_get_comment(p);
00089
00090
00091 switch (cpl_property_get_type(p)) {
00092 case CPL_TYPE_BOOL:
00093 {
00094 cxbool value = cpl_property_get_bool(p);
00095
00096 cpl_propertylist_append_bool(self, name, value);
00097 break;
00098 }
00099
00100 case CPL_TYPE_CHAR:
00101 {
00102 cxchar value = cpl_property_get_char(p);
00103
00104 cpl_propertylist_append_char(self, name, value);
00105 break;
00106 }
00107
00108 case CPL_TYPE_INT:
00109 {
00110 cxint value = cpl_property_get_int(p);
00111
00112 cpl_propertylist_append_int(self, name, value);
00113 break;
00114 }
00115
00116 case CPL_TYPE_LONG:
00117 {
00118 cxlong value = cpl_property_get_long(p);
00119
00120 cpl_propertylist_append_long(self, name, value);
00121 break;
00122 }
00123
00124 case CPL_TYPE_FLOAT:
00125 {
00126 cxfloat value = cpl_property_get_float(p);
00127
00128 cpl_propertylist_append_float(self, name, value);
00129 break;
00130 }
00131
00132 case CPL_TYPE_DOUBLE:
00133 {
00134 cxdouble value = cpl_property_get_double(p);
00135
00136 cpl_propertylist_append_double(self, name, value);
00137 break;
00138 }
00139
00140 case CPL_TYPE_STRING:
00141 {
00142 const cxchar *value = cpl_property_get_string(p);
00143
00144 cpl_propertylist_append_string(self, name, value);
00145 break;
00146 }
00147
00148 default:
00149
00150
00151
00152
00153
00154
00155
00156 return 1;
00157 break;
00158 }
00159
00160 if (comment != NULL) {
00161 cpl_propertylist_set_comment(self, name, comment);
00162 }
00163
00164 return 0;
00165
00166 }
00167
00168
00169 inline static cxint
00170 _giraffe_add_frame_info(cpl_propertylist *plist, const cxchar *name,
00171 const cxchar *tag, cxint sequence, cxint frame_index,
00172 cxint mode)
00173 {
00174
00175 const cxchar *id = NULL;
00176 const cxchar *group = NULL;
00177
00178 cxint status = 0;
00179
00180 cx_string *key = NULL;
00181 cx_string *comment = NULL;
00182
00183
00184 if (plist == NULL) {
00185 return 1;
00186 }
00187
00188 switch (mode) {
00189 case 0:
00190 id = "RAW";
00191 group = "raw";
00192 break;
00193
00194 case 1:
00195 id = "CAL";
00196 group = "calibration";
00197 break;
00198
00199 default:
00200 return 2;
00201 break;
00202 }
00203
00204 key = cx_string_new();
00205 comment = cx_string_new();
00206
00207
00208
00209
00210
00211
00212 cx_string_sprintf(key, "%s%-d %s%-d %s", "ESO PRO REC", sequence, id,
00213 frame_index, "NAME");
00214 cx_string_sprintf(comment, "%s %s %s", "File name of", group, "frame");
00215
00216 status = cpl_propertylist_update_string(plist, cx_string_get(key), name);
00217
00218 if (status != CPL_ERROR_NONE) {
00219 cx_string_delete(key);
00220 cx_string_delete(comment);
00221
00222 return 3;
00223 }
00224
00225 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
00226 cx_string_get(comment));
00227
00228 if (status != 0) {
00229 cx_string_delete(key);
00230 cx_string_delete(comment);
00231
00232 return 3;
00233 }
00234
00235
00236
00237
00238
00239
00240 cx_string_sprintf(key, "%s%-d %s%-d %s", "ESO PRO REC", sequence, id,
00241 frame_index, "CATG");
00242 cx_string_sprintf(comment, "%s %s %s", "Frame category of", group,
00243 "frame");
00244
00245 status = cpl_propertylist_update_string(plist, cx_string_get(key), tag);
00246
00247 if (status != CPL_ERROR_NONE) {
00248 cx_string_delete(key);
00249 cx_string_delete(comment);
00250
00251 return 4;
00252 }
00253
00254 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
00255 cx_string_get(comment));
00256
00257 if (status != 0) {
00258 cx_string_delete(key);
00259 cx_string_delete(comment);
00260
00261 return 4;
00262 }
00263
00264 cx_string_delete(key);
00265 cx_string_delete(comment);
00266
00267 return 0;
00268
00269 }
00270
00271
00282 const cxchar *
00283 giraffe_get_license(void)
00284 {
00285
00286 return _giraffe_license;
00287
00288 }
00289
00290
00304 GiInstrumentMode
00305 giraffe_get_mode(cpl_propertylist *properties)
00306 {
00307
00308 const cxchar *fctid = "giraffe_get_mode";
00309 const cxchar *mode;
00310
00311 cx_string *s = NULL;
00312
00313 GiInstrumentMode insmode;
00314
00315
00316 if (!properties) {
00317 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
00318 return GIMODE_NONE;
00319 }
00320
00321
00322 if (!cpl_propertylist_has(properties, GIALIAS_INSMODE)) {
00323 gi_warning("%s: Property (%s) not found\n", fctid, GIALIAS_INSMODE);
00324
00325 if (!cpl_propertylist_has(properties, GIALIAS_SLITNAME)) {
00326 cx_warning("%s: Property (%s) not found\n", fctid,
00327 GIALIAS_SLITNAME);
00328 return GIMODE_NONE;
00329 }
00330 else {
00331 mode = cpl_propertylist_get_string(properties, GIALIAS_SLITNAME);
00332 }
00333 }
00334 else {
00335 mode = cpl_propertylist_get_string(properties, GIALIAS_SLITNAME);
00336 }
00337
00338 if (!mode || strlen(mode) == 0) {
00339 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
00340 return GIMODE_NONE;
00341 }
00342
00343
00344 s = cx_string_create(mode);
00345 cx_string_lower(s);
00346
00347 if (strncmp(cx_string_get(s), "med", 3) == 0) {
00348 insmode = GIMODE_MEDUSA;
00349 }
00350 else if (strncmp(cx_string_get(s), "ifu", 3) == 0) {
00351 insmode = GIMODE_IFU;
00352 }
00353 else if (strncmp(cx_string_get(s), "arg", 3) == 0) {
00354 insmode = GIMODE_ARGUS;
00355 }
00356 else {
00357 cpl_error_set(fctid, CPL_ERROR_UNSUPPORTED_MODE);
00358 insmode = GIMODE_NONE;
00359 }
00360
00361 cx_string_delete(s);
00362
00363 return insmode;
00364
00365 }
00366
00382 cxchar *
00383 giraffe_path_get_basename(const cxchar *path)
00384 {
00385
00386 register cxssize base;
00387 register cxssize last_nonslash;
00388
00389 cxsize len;
00390
00391 cxchar *result;
00392
00393
00394 if (path == NULL) {
00395 return NULL;
00396 }
00397
00398 if (path[0] == '\0') {
00399 return cx_strdup(".");
00400 }
00401
00402 last_nonslash = strlen(path) - 1;
00403
00404 while (last_nonslash >= 0 && path[last_nonslash] == '/') {
00405 --last_nonslash;
00406 }
00407
00408
00409
00410
00411 if (last_nonslash == -1) {
00412 return cx_strdup("/");
00413 }
00414
00415 base = last_nonslash;
00416
00417 while (base >=0 && path[base] != '/') {
00418 --base;
00419 }
00420
00421 len = last_nonslash - base;
00422
00423 result = cx_malloc(len + 1);
00424 memcpy(result, path + base + 1, len);
00425 result[len] = '\0';
00426
00427 return result;
00428
00429 }
00430
00431
00444 cxchar *
00445 giraffe_localtime_iso8601(void)
00446 {
00447
00448 struct tm *ts;
00449
00450 time_t seconds = time(NULL);
00451
00452 cxchar *sdate = NULL;
00453
00454 cxulong milliseconds = 0;
00455
00456 cx_string *self = cx_string_new();
00457
00458
00459 cx_assert(self != NULL);
00460
00461 ts = localtime(&seconds);
00462
00463 cx_string_sprintf(self, "%4d-%02d-%02dT%02d:%02d:%02d.%03ld",
00464 ts->tm_year + 1900,
00465 ts->tm_mon + 1,
00466 ts->tm_mday,
00467 ts->tm_hour,
00468 ts->tm_min,
00469 ts->tm_sec,
00470 milliseconds);
00471
00472 sdate = cx_strdup(cx_string_get(self));
00473 cx_string_delete(self);
00474
00475 return sdate;
00476
00477 }
00478
00479
00487 cxint
00488 giraffe_add_recipe_info(cpl_propertylist *plist, const GiRecipeInfo *info)
00489 {
00490
00491 if (plist == NULL) {
00492 return -1;
00493 }
00494
00495 if (info != NULL) {
00496
00497 cxint status = 0;
00498
00499 cx_string *name = cx_string_new();
00500 cx_string *value = cx_string_new();
00501
00502
00503 cx_string_sprintf(name, "%s%-d %s", "ESO PRO REC", info->sequence,
00504 "PIPE ID");
00505 cx_string_sprintf(value, "%s/%s", PACKAGE, VERSION);
00506
00507 status = cpl_propertylist_update_string(plist, cx_string_get(name),
00508 cx_string_get(value));
00509
00510
00511 if (status != CPL_ERROR_NONE) {
00512 cx_string_delete(name);
00513 cx_string_delete(value);
00514
00515 return 1;
00516 }
00517
00518 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
00519 "Pipeline (unique) identifier");
00520
00521 if (status != 0) {
00522 cx_string_delete(name);
00523 cx_string_delete(value);
00524
00525 return 1;
00526 }
00527
00528 if (info->start != NULL) {
00529 cx_string_sprintf(name, "%s%-d %s", "ESO PRO REC",
00530 info->sequence, "START");
00531 status = cpl_propertylist_update_string(plist,
00532 cx_string_get(name),
00533 info->start);
00534
00535 if (status != CPL_ERROR_NONE) {
00536 cx_string_delete(name);
00537 cx_string_delete(value);
00538
00539 return 1;
00540 }
00541
00542 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
00543 "Date when recipe execution "
00544 "started.");
00545
00546 if (status != 0) {
00547 cx_string_delete(name);
00548 cx_string_delete(value);
00549
00550 return 1;
00551 }
00552 }
00553
00554 cx_string_delete(name);
00555 cx_string_delete(value);
00556
00557 }
00558
00559 return 0;
00560
00561 }
00562
00563
00585 cxint
00586 giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set,
00587 cxint sequence)
00588 {
00589
00590 if (plist == NULL) {
00591 return -1;
00592 }
00593
00594 if (set != NULL) {
00595
00596 cxsize nraw = 0;
00597 cxsize ncalib = 0;
00598
00599 cx_string *key = cx_string_new();
00600
00601 const cpl_frame *frame = cpl_frameset_get_first_const(set);
00602
00603 while (frame != NULL) {
00604
00605 cxint status = 0;
00606
00607 cpl_frame_group group = cpl_frame_get_group(frame);
00608
00609 const cxchar *name = cpl_frame_get_filename(frame);
00610 const cxchar *tag = cpl_frame_get_tag(frame);
00611 const cxchar *base = giraffe_path_get_basename(name);
00612
00613
00614 cx_assert(base != NULL);
00615
00616 switch (group) {
00617 case CPL_FRAME_GROUP_RAW:
00618 {
00619 ++nraw;
00620 status = _giraffe_add_frame_info(plist, base, tag, sequence,
00621 nraw, 0);
00622
00623 if (status != 0) {
00624 if (base != NULL) {
00625 cx_free((cxchar *)base);
00626 }
00627
00628 cx_string_delete(key);
00629 return -2;
00630 }
00631
00632 break;
00633 }
00634
00635 case CPL_FRAME_GROUP_CALIB:
00636 {
00637
00638 cpl_propertylist *_plist = NULL;
00639
00640
00641 ++ncalib;
00642 status = _giraffe_add_frame_info(plist, base, tag, sequence,
00643 ncalib, 1);
00644
00645 if (status != 0) {
00646 if (base != NULL) {
00647 cx_free((cxchar *)base);
00648 }
00649
00650 cx_string_delete(key);
00651 return -3;
00652 }
00653
00654 _plist = cpl_propertylist_load(name, 0);
00655
00656 if (_plist == NULL) {
00657 if (base != NULL) {
00658 cx_free((cxchar *)base);
00659 }
00660
00661 cx_string_delete(key);
00662 return -3;
00663 }
00664
00665
00666 if (cpl_propertylist_has(_plist, GIALIAS_DATAMD5)) {
00667
00668 const cxchar *s =
00669 cpl_propertylist_get_string(_plist, GIALIAS_DATAMD5);
00670
00671 if (strcmp(s, "Not computed") != 0) {
00672
00673 cx_string* md5 = cx_string_new();
00674
00675 cx_string_sprintf(md5, "%s%d %s%d %s", "ESO PRO REC",
00676 sequence, "CAL", ncalib, "DATAMD5");
00677
00678 status =
00679 cpl_propertylist_update_string(plist,
00680 cx_string_get(md5),
00681 s);
00682
00683 if (status != CPL_ERROR_NONE) {
00684 cx_string_delete(md5);
00685 cpl_propertylist_delete(_plist);
00686
00687 if (base != NULL) {
00688 cx_free((cxchar *)base);
00689 }
00690
00691 cx_string_delete(key);
00692 return -3;
00693 }
00694
00695 cx_string_delete(md5);
00696 }
00697
00698 }
00699
00700 cpl_propertylist_delete(_plist);
00701 break;
00702 }
00703
00704 default:
00705 break;
00706 }
00707
00708
00709 if (base != NULL) {
00710 cx_free((cxchar *)base);
00711 }
00712
00713 frame = cpl_frameset_get_next_const(set);
00714
00715 }
00716
00717 cx_string_delete(key);
00718
00719 }
00720
00721 return 0;
00722
00723 }
00724
00725
00746 cxint
00747 giraffe_propertylist_update(cpl_propertylist *self,
00748 cpl_propertylist *properties,
00749 const cxchar *regexp)
00750 {
00751
00752 const cxchar *fctid = "giraffe_propertylist_update";
00753
00754 cxlong i;
00755 cxlong sz = 0;
00756
00757
00758 cx_assert(self != NULL);
00759
00760 if (properties == NULL) {
00761 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
00762 return -1;
00763 }
00764
00765 sz = cpl_propertylist_get_size(properties);
00766
00767 if (regexp == NULL || regexp[0] == '\0') {
00768
00769 for (i = 0; i < sz; i++) {
00770
00771 cpl_property *p = cpl_propertylist_get(properties, i);
00772 const cxchar *name = cpl_property_get_name(p);
00773
00774
00775 if (!cpl_propertylist_has(self, name)) {
00776
00777 cxint status = _giraffe_plist_append(self, p);
00778
00779 if (status) {
00780 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
00781 return 1;
00782 }
00783 }
00784 }
00785 }
00786 else {
00787
00788 cxint status = 0;
00789
00790 regex_t re;
00791
00792
00793 status = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
00794
00795 if (status) {
00796 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
00797 return 1;
00798 }
00799
00800 for (i = 0; i < sz; i++) {
00801
00802 cpl_property *p = cpl_propertylist_get(properties, i);
00803 const cxchar *name = cpl_property_get_name(p);
00804
00805
00806 if (regexec(&re, name, (size_t)0, NULL, 0) == REG_NOMATCH) {
00807 continue;
00808 }
00809
00810 if (!cpl_propertylist_has(self, name)) {
00811
00812 status = _giraffe_plist_append(self, p);
00813
00814 if (status) {
00815 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
00816 return 1;
00817 }
00818 }
00819 }
00820
00821 regfree(&re);
00822
00823 }
00824
00825 return 0;
00826
00827 }
00828
00829
00837 cxint
00838 giraffe_propertylist_copy(cpl_propertylist *self,
00839 const cxchar *name,
00840 const cpl_propertylist *other,
00841 const cxchar *othername)
00842 {
00843
00844 const cxchar *fctid = "giraffe_propertylist_copy";
00845
00846
00847 const cxchar *s;
00848 const cxchar *comment;
00849
00850 cpl_type type;
00851
00852
00853
00854 cx_assert(self != NULL);
00855
00856 if (other == NULL) {
00857 return -1;
00858 }
00859
00860 if (othername == NULL) {
00861 return -2;
00862 }
00863
00864 if (!cpl_propertylist_has(other, othername)) {
00865 return 1;
00866 }
00867
00868 type = cpl_propertylist_get_type(other, othername);
00869
00870
00871
00872
00873
00874
00875 s = name == NULL ? othername : name;
00876
00877
00878
00879
00880
00881
00882 switch (type) {
00883 case CPL_TYPE_CHAR:
00884 {
00885 cxchar value = cpl_propertylist_get_char(other, othername);
00886
00887 if (cpl_propertylist_has(self, s)) {
00888 cpl_propertylist_set_char(self, s, value);
00889 }
00890 else {
00891 cpl_propertylist_append_char(self, s, value);
00892 }
00893 }
00894 break;
00895
00896 case CPL_TYPE_BOOL:
00897 {
00898 cxbool value = cpl_propertylist_get_bool(other, othername);
00899
00900 if (cpl_propertylist_has(self, s)) {
00901 cpl_propertylist_set_bool(self, s, value);
00902 }
00903 else {
00904 cpl_propertylist_append_bool(self, s, value);
00905 }
00906 }
00907 break;
00908
00909 case CPL_TYPE_INT:
00910 {
00911 cxint value = cpl_propertylist_get_int(other, othername);
00912
00913 if (cpl_propertylist_has(self, s)) {
00914 cpl_propertylist_set_int(self, s, value);
00915 }
00916 else {
00917 cpl_propertylist_append_int(self, s, value);
00918 }
00919 }
00920 break;
00921
00922 case CPL_TYPE_LONG:
00923 {
00924 cxlong value = cpl_propertylist_get_long(other, othername);
00925
00926 if (cpl_propertylist_has(self, s)) {
00927 cpl_propertylist_set_long(self, s, value);
00928 }
00929 else {
00930 cpl_propertylist_append_long(self, s, value);
00931 }
00932 }
00933 break;
00934
00935 case CPL_TYPE_FLOAT:
00936 {
00937 cxfloat value = cpl_propertylist_get_float(other, othername);
00938
00939 if (cpl_propertylist_has(self, s)) {
00940 cpl_propertylist_set_float(self, s, value);
00941 }
00942 else {
00943 cpl_propertylist_append_float(self, s, value);
00944 }
00945 }
00946 break;
00947
00948 case CPL_TYPE_DOUBLE:
00949 {
00950 cxdouble value = cpl_propertylist_get_double(other, othername);
00951
00952 if (cpl_propertylist_has(self, s)) {
00953 cpl_propertylist_set_double(self, s, value);
00954 }
00955 else {
00956 cpl_propertylist_append_double(self, s, value);
00957 }
00958 }
00959 break;
00960
00961 case CPL_TYPE_STRING:
00962 {
00963 const cxchar *value = cpl_propertylist_get_string(other,
00964 othername);
00965
00966 if (cpl_propertylist_has(self, s)) {
00967 cpl_propertylist_set_string(self, s, value);
00968 }
00969 else {
00970 cpl_propertylist_append_string(self, s, value);
00971 }
00972 }
00973 break;
00974
00975 default:
00976 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
00977 return 2;
00978 break;
00979 }
00980
00981 comment = cpl_propertylist_get_comment(other, othername);
00982
00983 if (comment != NULL) {
00984 cpl_propertylist_set_comment(self, s, comment);
00985 }
00986
00987 return 0;
00988
00989 }
00990
00991
00992 cxint
00993 giraffe_propertylist_update_wcs(cpl_propertylist* properties, cxsize naxis,
00994 const cxdouble* crpix, const cxdouble* crval,
00995 const cxchar** ctype, const cxchar** cunit,
00996 const cpl_matrix* cd)
00997 {
00998
00999 if (properties == NULL) {
01000 return 0;
01001 }
01002
01003 cpl_propertylist_erase_regexp(properties, "^CRPIX[0-9]", 0);
01004 cpl_propertylist_erase_regexp(properties, "^CRVAL[0-9]", 0);
01005 cpl_propertylist_erase_regexp(properties, "^CDELT[0-9]", 0);
01006 cpl_propertylist_erase_regexp(properties, "^CTYPE[0-9]", 0);
01007 cpl_propertylist_erase_regexp(properties, "^CUNIT[0-9]", 0);
01008 cpl_propertylist_erase_regexp(properties, "^CROTA[0-9]", 0);
01009 cpl_propertylist_erase_regexp(properties, "^CD[0-9]*_[0-9]", 0);
01010 cpl_propertylist_erase_regexp(properties, "^PC[0-9]*_[0-9]", 0);
01011
01012
01013 if (naxis > 0) {
01014
01015
01016 register cxsize i = 0;
01017
01018 cx_string* keyword = cx_string_new();
01019 cx_string* comment = cx_string_new();
01020
01021
01022 cx_assert(cpl_matrix_get_nrow(cd) == cpl_matrix_get_ncol(cd));
01023
01024 for (i = 0; i < naxis; i++) {
01025
01026 cx_string_sprintf(keyword, "CTYPE%-d", i + 1);
01027 cx_string_sprintf(comment, "Coordinate system of axis %d", i + 1);
01028 cpl_propertylist_append_string(properties,
01029 cx_string_get(keyword), ctype[i]);
01030 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
01031 cx_string_get(comment));
01032
01033 }
01034
01035 for (i = 0; i < naxis; i++) {
01036
01037 cx_string_sprintf(keyword, "CRPIX%-d", i + 1);
01038 cx_string_sprintf(comment, "Reference pixel of axis %d", i + 1);
01039 cpl_propertylist_append_double(properties,
01040 cx_string_get(keyword), crpix[i]);
01041 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
01042 cx_string_get(comment));
01043
01044 }
01045
01046 for (i = 0; i < naxis; i++) {
01047
01048 cx_string_sprintf(keyword, "CRVAL%-d", i + 1);
01049 cx_string_sprintf(comment, "Coordinate of axis %d at reference "
01050 "pixel", i + 1);
01051 cpl_propertylist_append_double(properties,
01052 cx_string_get(keyword), crval[i]);
01053 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
01054 cx_string_get(comment));
01055
01056 }
01057
01058 for (i = 0; i < naxis; i++) {
01059
01060 if (cunit[i] != NULL) {
01061 cx_string_sprintf(keyword, "CUNIT%-d", i + 1);
01062 cx_string_sprintf(comment, "Unit of coordinate axis %d",
01063 i + 1);
01064 cpl_propertylist_append_string(properties,
01065 cx_string_get(keyword),
01066 cunit[i]);
01067 cpl_propertylist_set_comment(properties,
01068 cx_string_get(keyword),
01069 cx_string_get(comment));
01070 }
01071
01072 }
01073
01074
01075
01076
01077
01078
01079 for (i = 0; i < naxis; i++) {
01080
01081 register cxsize j = 0;
01082
01083
01084 for (j = 0; j < naxis; j++) {
01085
01086 cx_string_sprintf(keyword, "CD%-d_%-d", i + 1, j + 1);
01087 cx_string_sprintf(comment, "Coordinate transformation matrix "
01088 "element");
01089 cpl_propertylist_append_double(properties,
01090 cx_string_get(keyword),
01091 cpl_matrix_get(cd, i, j));
01092 cpl_propertylist_set_comment(properties,
01093 cx_string_get(keyword),
01094 cx_string_get(comment));
01095 }
01096
01097 }
01098
01099 cx_string_delete(keyword);
01100 keyword = NULL;
01101
01102 cx_string_delete(comment);
01103 comment = NULL;
01104
01105 }
01106
01107 return 0;
01108
01109 }
01110
01111
01112 cxint
01113 giraffe_frameset_set_groups(cpl_frameset* set, GiGroupInfo *groups)
01114 {
01115
01116 cpl_frame* frame = NULL;
01117
01118
01119 if (set == NULL) {
01120 return -1;
01121 }
01122
01123 if (groups == NULL || groups->tag == NULL) {
01124 return 0;
01125 }
01126
01127 frame = cpl_frameset_get_first(set);
01128
01129 while (frame != NULL) {
01130
01131 const cxchar* tag = cpl_frame_get_tag(frame);
01132
01133 if (tag != NULL &&
01134 cpl_frame_get_group(frame) == CPL_FRAME_GROUP_NONE) {
01135
01136 const GiGroupInfo* g = groups;
01137
01138 while (g->tag != NULL) {
01139 if (strcmp(tag, g->tag) == 0) {
01140 cpl_frame_set_group(frame, g->group);
01141 break;
01142 }
01143 ++g;
01144 }
01145
01146 }
01147
01148 frame = cpl_frameset_get_next(set);
01149
01150 }
01151
01152 return 0;
01153
01154 }
01155
01156
01187 cxdouble
01188 giraffe_propertylist_get_ron(const cpl_propertylist* properties)
01189 {
01190
01191 const cxchar* const fctid = "giraffe_propertylist_get_ron";
01192
01193
01194 cxdouble ron = 0.;
01195
01196
01197 cx_assert(properties != NULL);
01198
01199 if (!cpl_propertylist_has(properties, GIALIAS_BIASSIGMA)) {
01200 if (!cpl_propertylist_has(properties, GIALIAS_RON)) {
01201 cpl_msg_error(fctid, "Missing detector read-out noise "
01202 "property (%s)!", GIALIAS_RON);
01203 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
01204
01205 return 0.;
01206 }
01207 else {
01208
01209
01210
01211
01212
01213
01214 cpl_msg_warning(fctid, "Missing bias RMS property (%s)! "
01215 "Using detector read-out noise property (%s).",
01216 GIALIAS_BIASSIGMA, GIALIAS_RON);
01217 ron = cpl_propertylist_get_double(properties, GIALIAS_RON);
01218 }
01219 }
01220 else {
01221
01222 cxdouble conad = 0.;
01223
01224
01225
01226
01227
01228
01229
01230 if (!cpl_propertylist_has(properties, GIALIAS_CONAD)) {
01231 cpl_msg_error(fctid, "Missing detector gain property (%s)! ",
01232 GIALIAS_CONAD);
01233 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
01234
01235 return 0.;
01236 }
01237 else {
01238 conad = cpl_propertylist_get_double(properties, GIALIAS_CONAD);
01239 }
01240
01241 if (conad < 0.) {
01242 cpl_msg_error(fctid, "Invalid conversion factor (%s) %.3g "
01243 "[e-/ADU]", GIALIAS_CONAD, conad);
01244 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
01245
01246 return 0.;
01247 }
01248
01249 ron = cpl_propertylist_get_double(properties, GIALIAS_BIASSIGMA) *
01250 conad;
01251
01252 }
01253
01254 return ron;
01255
01256 }