24#ifdef HAVE_SYS_TYPES_H
25# include <sys/types.h>
32#include <cxstrutils.h>
36#include <cpl_errorstate.h>
37#include <cpl_matrix.h>
38#include <cpl_version.h>
42#include "gimessages.h"
59static const cxchar *_giraffe_license =
60 " This file is part of the GIRAFFE Instrument Pipeline\n"
61 " Copyright (C) 2002-2014 European Southern Observatory\n"
63 " This program is free software; you can redistribute it and/or modify\n"
64 " it under the terms of the GNU General Public License as published by\n"
65 " the Free Software Foundation; either version 2 of the License, or\n"
66 " (at your option) any later version.\n"
68 " This program is distributed in the hope that it will be useful,\n"
69 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
70 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
71 " GNU General Public License for more details.\n"
73 " You should have received a copy of the GNU General Public License\n"
74 " along with this program; if not, write to the Free Software\n"
75 " Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301"
80_giraffe_plist_append(cpl_propertylist *self, cpl_property *p)
83 const cxchar *name = cpl_property_get_name(p);
84 const cxchar *comment = cpl_property_get_comment(p);
87 switch (cpl_property_get_type(p)) {
90 cxbool value = cpl_property_get_bool(p);
92 cpl_propertylist_append_bool(self, name, value);
98 cxchar value = cpl_property_get_char(p);
100 cpl_propertylist_append_char(self, name, value);
106 cxint value = cpl_property_get_int(p);
108 cpl_propertylist_append_int(self, name, value);
114 cxlong value = cpl_property_get_long(p);
116 cpl_propertylist_append_long(self, name, value);
122 cxfloat value = cpl_property_get_float(p);
124 cpl_propertylist_append_float(self, name, value);
128 case CPL_TYPE_DOUBLE:
130 cxdouble value = cpl_property_get_double(p);
132 cpl_propertylist_append_double(self, name, value);
136 case CPL_TYPE_STRING:
138 const cxchar *value = cpl_property_get_string(p);
140 cpl_propertylist_append_string(self, name, value);
156 if (comment != NULL) {
157 cpl_propertylist_set_comment(self, name, comment);
166_giraffe_add_frame_info(cpl_propertylist *plist,
const cxchar *name,
167 const cxchar *tag, cxint sequence, cxint frame_index,
171 const cxchar *
id = NULL;
172 const cxchar *group = NULL;
176 cx_string *key = NULL;
177 cx_string *comment = NULL;
192 group =
"calibration";
200 key = cx_string_new();
201 comment = cx_string_new();
208 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
id,
209 frame_index,
"NAME");
210 cx_string_sprintf(comment,
"%s %s %s",
"File name of", group,
"frame");
212 status = cpl_propertylist_update_string(plist, cx_string_get(key), name);
214 if (status != CPL_ERROR_NONE) {
215 cx_string_delete(key);
216 cx_string_delete(comment);
221 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
222 cx_string_get(comment));
225 cx_string_delete(key);
226 cx_string_delete(comment);
236 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
id,
237 frame_index,
"CATG");
238 cx_string_sprintf(comment,
"%s %s %s",
"Frame category of", group,
241 status = cpl_propertylist_update_string(plist, cx_string_get(key), tag);
243 if (status != CPL_ERROR_NONE) {
244 cx_string_delete(key);
245 cx_string_delete(comment);
250 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
251 cx_string_get(comment));
254 cx_string_delete(key);
255 cx_string_delete(comment);
260 cx_string_delete(key);
261 cx_string_delete(comment);
269_giraffe_add_option_info(cpl_propertylist *plist,
270 const cpl_parameterlist *options, cxint sequence)
272 cx_assert(plist != NULL);
273 cx_assert(options != NULL);
274 cx_assert(sequence >= 1);
276 cx_string *key = cx_string_new();
277 cx_string *comment = cx_string_new();
280 const cpl_parameter *p = cpl_parameterlist_get_first_const(options);
283 cx_string_delete(key);
284 cx_string_delete(comment);
291 const cxchar *alias = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI);
292 cx_string *value = cx_string_new();
293 cx_string *preset = cx_string_new();
295 switch (cpl_parameter_get_type(p)) {
298 int bval = cpl_parameter_get_bool(p);
299 cx_string_sprintf(value,
"%s", (bval == 1) ?
"true" :
"false");
301 bval = cpl_parameter_get_default_bool(p);
302 cx_string_sprintf(preset,
"%s", (bval == 1) ?
"true" :
"false");
307 cx_string_sprintf(value,
"%d", cpl_parameter_get_int(p));
308 cx_string_sprintf(preset,
"%d", cpl_parameter_get_default_int(p));
311 case CPL_TYPE_DOUBLE:
313 cx_string_sprintf(value,
"%g", cpl_parameter_get_double(p));
314 cx_string_sprintf(preset,
"%g", cpl_parameter_get_default_double(p));
317 case CPL_TYPE_STRING:
319 cx_string_sprintf(value,
"%s", cpl_parameter_get_string(p));
320 cx_string_sprintf(preset,
"%s", cpl_parameter_get_default_string(p));
332 cx_string_delete(key);
333 cx_string_delete(comment);
334 cx_string_delete(value);
335 cx_string_delete(preset);
341 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
342 "PARAM", pcount,
"NAME");
343 status = cpl_propertylist_update_string(plist, cx_string_get(key), alias);
346 cx_string_delete(key);
347 cx_string_delete(comment);
348 cx_string_delete(value);
349 cx_string_delete(preset);
354 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
355 cpl_parameter_get_help(p));
358 cx_string_delete(key);
359 cx_string_delete(comment);
360 cx_string_delete(value);
361 cx_string_delete(preset);
367 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
368 "PARAM", pcount,
"VALUE");
369 cx_string_sprintf(comment,
"Default: %s", cx_string_get(preset));
371 status = cpl_propertylist_update_string(plist, cx_string_get(key),
372 cx_string_get(value));
375 cx_string_delete(key);
376 cx_string_delete(comment);
377 cx_string_delete(value);
378 cx_string_delete(preset);
383 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
384 cx_string_get(comment));
387 cx_string_delete(key);
388 cx_string_delete(comment);
389 cx_string_delete(value);
390 cx_string_delete(preset);
395 cx_string_delete(value);
396 cx_string_delete(preset);
398 p = cpl_parameterlist_get_next_const(options);
402 cx_string_delete(key);
403 cx_string_delete(comment);
423 return _giraffe_license;
445 const cxchar *fctid =
"giraffe_get_mode";
450 GiInstrumentMode insmode;
454 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
459 if (!cpl_propertylist_has(properties, GIALIAS_INSMODE)) {
460 gi_warning(
"%s: Property (%s) not found\n", fctid, GIALIAS_INSMODE);
462 if (!cpl_propertylist_has(properties, GIALIAS_SLITNAME)) {
463 cx_warning(
"%s: Property (%s) not found\n", fctid,
468 mode = cpl_propertylist_get_string(properties, GIALIAS_SLITNAME);
472 mode = cpl_propertylist_get_string(properties, GIALIAS_SLITNAME);
475 if (!mode || strlen(mode) == 0) {
476 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
481 s = cx_string_create(mode);
484 if (strncmp(cx_string_get(s),
"med", 3) == 0) {
485 insmode = GIMODE_MEDUSA;
487 else if (strncmp(cx_string_get(s),
"ifu", 3) == 0) {
488 insmode = GIMODE_IFU;
490 else if (strncmp(cx_string_get(s),
"arg", 3) == 0) {
491 insmode = GIMODE_ARGUS;
494 cpl_error_set(fctid, CPL_ERROR_UNSUPPORTED_MODE);
495 insmode = GIMODE_NONE;
523 register cxssize base;
524 register cxssize last_nonslash;
535 if (path[0] ==
'\0') {
536 return cx_strdup(
".");
539 last_nonslash = strlen(path) - 1;
541 while (last_nonslash >= 0 && path[last_nonslash] ==
'/') {
548 if (last_nonslash == -1) {
549 return cx_strdup(
"/");
552 base = last_nonslash;
554 while (base >=0 && path[base] !=
'/') {
558 len = last_nonslash - base;
560 result = cx_malloc(len + 1);
561 memcpy(result, path + base + 1, len);
587 time_t seconds = time(NULL);
589 cxchar *sdate = NULL;
591 cxulong milliseconds = 0;
593 cx_string *self = cx_string_new();
596 cx_assert(self != NULL);
598 ts = localtime(&seconds);
600 cx_string_sprintf(self,
"%4d-%02d-%02dT%02d:%02d:%02d.%03ld",
609 sdate = cx_strdup(cx_string_get(self));
610 cx_string_delete(self);
636 cx_string *name = cx_string_new();
637 cx_string *value = cx_string_new();
640 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC", info->sequence,
642 cx_string_sprintf(value,
"%s", info->recipe);
644 status = cpl_propertylist_update_string(plist, cx_string_get(name),
645 cx_string_get(value));
648 if (status != CPL_ERROR_NONE) {
649 cx_string_delete(name);
650 cx_string_delete(value);
655 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
656 "Pipeline recipe (unique) identifier");
659 cx_string_delete(name);
660 cx_string_delete(value);
665 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC", info->sequence,
667 cx_string_sprintf(value,
"%s/%s", PACKAGE, VERSION);
669 status = cpl_propertylist_update_string(plist, cx_string_get(name),
670 cx_string_get(value));
673 if (status != CPL_ERROR_NONE) {
674 cx_string_delete(name);
675 cx_string_delete(value);
680 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
681 "Pipeline (unique) identifier");
684 cx_string_delete(name);
685 cx_string_delete(value);
690 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC", info->sequence,
692 cx_string_sprintf(value,
"cpl-%s", cpl_version_get_version());
694 status = cpl_propertylist_update_string(plist, cx_string_get(name),
695 cx_string_get(value));
698 if (status != CPL_ERROR_NONE) {
699 cx_string_delete(name);
700 cx_string_delete(value);
705 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
706 "Data Reduction System identifier");
709 cx_string_delete(name);
710 cx_string_delete(value);
715 if (info->start != NULL) {
716 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC",
717 info->sequence,
"START");
718 status = cpl_propertylist_update_string(plist,
722 if (status != CPL_ERROR_NONE) {
723 cx_string_delete(name);
724 cx_string_delete(value);
729 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
730 "Date when recipe execution "
734 cx_string_delete(name);
735 cx_string_delete(value);
741 cx_string_delete(name);
742 cx_string_delete(value);
749 status = _giraffe_add_option_info(plist, info->options, info->sequence);
797 cx_string *key = cx_string_new();
799 const cpl_frame *frame = NULL;
801 cpl_frameset_iterator *it = cpl_frameset_iterator_new(set);
804 while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) {
806 cpl_frame_group group = cpl_frame_get_group(frame);
808 const cxchar *name = cpl_frame_get_filename(frame);
809 const cxchar *tag = cpl_frame_get_tag(frame);
813 cx_assert(base != NULL);
816 case CPL_FRAME_GROUP_RAW:
829 if (!cpl_propertylist_has(plist, GIALIAS_ANCESTOR)) {
833 cpl_propertylist *_plist = cpl_propertylist_load(name, 0);
835 if (_plist == NULL) {
838 cx_free((cxchar *)base);
841 cpl_frameset_iterator_delete(it);
842 cx_string_delete(key);
848 if (cpl_propertylist_has(_plist, GIALIAS_ANCESTOR)) {
849 cpl_propertylist_copy_property(plist, _plist,
855 cpl_propertylist_get_string(_plist,
857 const cxchar *c =
"Inherited archive file name "
858 "of the first raw data frame";
861 cpl_propertylist_append_string(plist,
862 GIALIAS_ANCESTOR, s);
863 cpl_propertylist_set_comment(plist,
864 GIALIAS_ANCESTOR, c);
869 cpl_propertylist_delete(_plist);
876 status = _giraffe_add_frame_info(plist, base, tag,
881 cx_free((cxchar *)base);
884 cpl_frameset_iterator_delete(it);
885 cx_string_delete(key);
894 case CPL_FRAME_GROUP_CALIB:
897 cpl_propertylist *_plist = NULL;
901 cxint status = _giraffe_add_frame_info(plist, base, tag,
902 sequence, ncalib, 1);
906 cx_free((cxchar *)base);
909 cpl_frameset_iterator_delete(it);
910 cx_string_delete(key);
915 _plist = cpl_propertylist_load(name, 0);
917 if (_plist == NULL) {
919 cx_free((cxchar *)base);
922 cpl_frameset_iterator_delete(it);
923 cx_string_delete(key);
929 if (cpl_propertylist_has(_plist, GIALIAS_DATAMD5)) {
932 cpl_propertylist_get_string(_plist, GIALIAS_DATAMD5);
934 if (strcmp(s,
"Not computed") != 0) {
936 cx_string* md5 = cx_string_new();
938 cx_string_sprintf(md5,
"%s%d %s%"
939 CX_PRINTF_FORMAT_SIZE_TYPE
"%s",
940 "ESO PRO REC", sequence,
"CAL",
944 cpl_propertylist_update_string(plist,
948 if (status != CPL_ERROR_NONE) {
949 cx_string_delete(md5);
950 cpl_propertylist_delete(_plist);
953 cx_free((cxchar *)base);
956 cpl_frameset_iterator_delete(it);
957 cx_string_delete(key);
962 cx_string_delete(md5);
967 cpl_propertylist_delete(_plist);
977 cx_free((cxchar *)base);
980 cpl_frameset_iterator_advance(it, 1);
984 cpl_frameset_iterator_delete(it);
985 cx_string_delete(key);
1016 cpl_propertylist *properties,
1017 const cxchar *regexp)
1020 const cxchar *fctid =
"giraffe_propertylist_update";
1026 cx_assert(self != NULL);
1028 if (properties == NULL) {
1029 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
1033 sz = cpl_propertylist_get_size(properties);
1035 if (regexp == NULL || regexp[0] ==
'\0') {
1037 for (i = 0; i < sz; i++) {
1039 cpl_property *p = cpl_propertylist_get(properties, i);
1040 const cxchar *name = cpl_property_get_name(p);
1043 if (!cpl_propertylist_has(self, name)) {
1045 cxint status = _giraffe_plist_append(self, p);
1048 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
1061 status = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
1064 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
1068 for (i = 0; i < sz; i++) {
1070 cpl_property *p = cpl_propertylist_get(properties, i);
1071 const cxchar *name = cpl_property_get_name(p);
1074 if (regexec(&re, name, (
size_t)0, NULL, 0) == REG_NOMATCH) {
1078 if (!cpl_propertylist_has(self, name)) {
1080 status = _giraffe_plist_append(self, p);
1083 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
1108 const cpl_propertylist *other,
1109 const cxchar *othername)
1112 const cxchar *fctid =
"giraffe_propertylist_copy";
1116 const cxchar *comment;
1122 cx_assert(self != NULL);
1124 if (other == NULL) {
1128 if (othername == NULL) {
1132 if (!cpl_propertylist_has(other, othername)) {
1136 type = cpl_propertylist_get_type(other, othername);
1143 s = name == NULL ? othername : name;
1153 cxchar value = cpl_propertylist_get_char(other, othername);
1155 if (cpl_propertylist_has(self, s)) {
1156 cpl_propertylist_set_char(self, s, value);
1159 cpl_propertylist_append_char(self, s, value);
1166 cxbool value = cpl_propertylist_get_bool(other, othername);
1168 if (cpl_propertylist_has(self, s)) {
1169 cpl_propertylist_set_bool(self, s, value);
1172 cpl_propertylist_append_bool(self, s, value);
1179 cxint value = cpl_propertylist_get_int(other, othername);
1181 if (cpl_propertylist_has(self, s)) {
1182 cpl_propertylist_set_int(self, s, value);
1185 cpl_propertylist_append_int(self, s, value);
1192 cxlong value = cpl_propertylist_get_long(other, othername);
1194 if (cpl_propertylist_has(self, s)) {
1195 cpl_propertylist_set_long(self, s, value);
1198 cpl_propertylist_append_long(self, s, value);
1203 case CPL_TYPE_FLOAT:
1205 cxfloat value = cpl_propertylist_get_float(other, othername);
1207 if (cpl_propertylist_has(self, s)) {
1208 cpl_propertylist_set_float(self, s, value);
1211 cpl_propertylist_append_float(self, s, value);
1216 case CPL_TYPE_DOUBLE:
1218 cxdouble value = cpl_propertylist_get_double(other, othername);
1220 if (cpl_propertylist_has(self, s)) {
1221 cpl_propertylist_set_double(self, s, value);
1224 cpl_propertylist_append_double(self, s, value);
1229 case CPL_TYPE_STRING:
1231 const cxchar *value = cpl_propertylist_get_string(other,
1234 if (cpl_propertylist_has(self, s)) {
1235 cpl_propertylist_set_string(self, s, value);
1238 cpl_propertylist_append_string(self, s, value);
1244 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
1249 comment = cpl_propertylist_get_comment(other, othername);
1251 if (comment != NULL) {
1252 cpl_propertylist_set_comment(self, s, comment);
1261giraffe_propertylist_update_wcs(cpl_propertylist* properties, cxsize naxis,
1262 const cxdouble* crpix,
const cxdouble* crval,
1263 const cxchar** ctype,
const cxchar** cunit,
1264 const cpl_matrix* cd)
1267 if (properties == NULL) {
1271 cpl_propertylist_erase_regexp(properties,
"^CRPIX[0-9]", 0);
1272 cpl_propertylist_erase_regexp(properties,
"^CRVAL[0-9]", 0);
1273 cpl_propertylist_erase_regexp(properties,
"^CDELT[0-9]", 0);
1274 cpl_propertylist_erase_regexp(properties,
"^CTYPE[0-9]", 0);
1275 cpl_propertylist_erase_regexp(properties,
"^CUNIT[0-9]", 0);
1276 cpl_propertylist_erase_regexp(properties,
"^CROTA[0-9]", 0);
1277 cpl_propertylist_erase_regexp(properties,
"^CD[0-9]*_[0-9]", 0);
1278 cpl_propertylist_erase_regexp(properties,
"^PC[0-9]*_[0-9]", 0);
1284 register cxsize i = 0;
1286 cx_string* keyword = cx_string_new();
1287 cx_string* comment = cx_string_new();
1290 cx_assert(cpl_matrix_get_nrow(cd) == cpl_matrix_get_ncol(cd));
1292 for (i = 0; i < naxis; i++) {
1294 cx_string_sprintf(keyword,
"CTYPE%-" CX_PRINTF_FORMAT_SIZE_TYPE,
1296 cx_string_sprintf(comment,
"Coordinate system of axis %"
1297 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1298 cpl_propertylist_append_string(properties,
1299 cx_string_get(keyword), ctype[i]);
1300 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
1301 cx_string_get(comment));
1305 for (i = 0; i < naxis; i++) {
1307 cx_string_sprintf(keyword,
"CRPIX%-" CX_PRINTF_FORMAT_SIZE_TYPE,
1309 cx_string_sprintf(comment,
"Reference pixel of axis %"
1310 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1311 cpl_propertylist_append_double(properties,
1312 cx_string_get(keyword), crpix[i]);
1313 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
1314 cx_string_get(comment));
1318 for (i = 0; i < naxis; i++) {
1320 cx_string_sprintf(keyword,
"CRVAL%-" CX_PRINTF_FORMAT_SIZE_TYPE,
1322 cx_string_sprintf(comment,
"Coordinate of axis %"
1323 CX_PRINTF_FORMAT_SIZE_TYPE
" at reference "
1325 cpl_propertylist_append_double(properties,
1326 cx_string_get(keyword), crval[i]);
1327 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
1328 cx_string_get(comment));
1332 for (i = 0; i < naxis; i++) {
1334 if (cunit[i] != NULL) {
1335 cx_string_sprintf(keyword,
"CUNIT%-"
1336 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1337 cx_string_sprintf(comment,
"Unit of coordinate axis %"
1338 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1339 cpl_propertylist_append_string(properties,
1340 cx_string_get(keyword),
1342 cpl_propertylist_set_comment(properties,
1343 cx_string_get(keyword),
1344 cx_string_get(comment));
1354 for (i = 0; i < naxis; i++) {
1356 register cxsize j = 0;
1359 for (j = 0; j < naxis; j++) {
1361 cx_string_sprintf(keyword,
"CD%-" CX_PRINTF_FORMAT_SIZE_TYPE
1362 "_%-" CX_PRINTF_FORMAT_SIZE_TYPE, i + 1,
1364 cx_string_sprintf(comment,
"Coordinate transformation matrix "
1366 cpl_propertylist_append_double(properties,
1367 cx_string_get(keyword),
1368 cpl_matrix_get(cd, i, j));
1369 cpl_propertylist_set_comment(properties,
1370 cx_string_get(keyword),
1371 cx_string_get(comment));
1376 cx_string_delete(keyword);
1379 cx_string_delete(comment);
1390giraffe_frameset_set_groups(cpl_frameset* set, GiGroupInfo *groups)
1393 cpl_frame* frame = NULL;
1395 cpl_frameset_iterator *it = NULL;
1402 if (groups == NULL || groups->tag == NULL) {
1406 it = cpl_frameset_iterator_new(set);
1408 while ((frame = cpl_frameset_iterator_get(it)) != NULL) {
1410 const cxchar* tag = cpl_frame_get_tag(frame);
1413 cpl_frame_get_group(frame) == CPL_FRAME_GROUP_NONE) {
1415 const GiGroupInfo* g = groups;
1417 while (g->tag != NULL) {
1418 if (strcmp(tag, g->tag) == 0) {
1419 cpl_frame_set_group(frame, g->group);
1427 cpl_frameset_iterator_advance(it, 1);
1431 cpl_frameset_iterator_delete(it);
1474 const cxchar*
const fctid =
"giraffe_propertylist_get_conad";
1476 const cxchar *names[2] = {GIALIAS_CONAD, GIALIAS_CONAD_LEGACY};
1477 const cxchar *name = NULL;
1479 cxdouble conad = 1.;
1482 cx_assert(properties != NULL);
1485 if (!cpl_propertylist_has(properties, GIALIAS_CONAD)) {
1487 if (!cpl_propertylist_has(properties, GIALIAS_CONAD_LEGACY)) {
1489 cpl_msg_error(fctid,
"Missing detector gain property (%s, %s)! ",
1490 GIALIAS_CONAD, GIALIAS_CONAD_LEGACY);
1491 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
1506 conad = cpl_propertylist_get_double(properties, name);
1510 cpl_msg_error(fctid,
"Invalid conversion factor (%s) %.3g "
1511 "[e-/ADU]", name, conad);
1512 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
1558 const cxchar*
const fctid =
"giraffe_propertylist_get_ron";
1564 cx_assert(properties != NULL);
1566 if (!cpl_propertylist_has(properties, GIALIAS_BIASSIGMA)) {
1567 if (!cpl_propertylist_has(properties, GIALIAS_RON)) {
1568 cpl_msg_error(fctid,
"Missing detector read-out noise "
1569 "property (%s)!", GIALIAS_RON);
1570 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
1581 cpl_msg_warning(fctid,
"Missing bias RMS property (%s)! "
1582 "Using detector read-out noise property (%s).",
1583 GIALIAS_BIASSIGMA, GIALIAS_RON);
1584 ron = cpl_propertylist_get_double(properties, GIALIAS_RON);
1589 cxdouble conad = 0.;
1597 giraffe_error_push();
1601 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1605 giraffe_error_pop();
1607 ron = cpl_propertylist_get_double(properties, GIALIAS_BIASSIGMA) *
1619const char * giraffe_get_flat_type(cpl_propertylist* plist) {
1620 cpl_error_code error_code;
1621 cpl_errorstate prev_state = cpl_errorstate_get();
1623 const char* CATG = cpl_propertylist_get_string(plist,
"ESO DPR CATG");
1625 error_code = cpl_error_get_code();
1626 cpl_msg_warning(
"getDO_CATG",
"Failed to get ESO DPR CATG: %d", error_code);
1627 cpl_errorstate_set(prev_state);
1631 const char* TYPE = cpl_propertylist_get_string(plist,
"ESO DPR TYPE");
1633 error_code = cpl_error_get_code();
1634 cpl_msg_warning(
"getDO_CATG",
"Failed to get ESO DPR TYPE: %d", error_code);
1635 cpl_errorstate_set(prev_state);
1639 const char* TECH = cpl_propertylist_get_string(plist,
"ESO DPR TECH");
1641 error_code = cpl_error_get_code();
1642 cpl_msg_warning(
"getDO_CATG",
"Failed to get ESO DPR TECH: %d", error_code);
1643 cpl_errorstate_set(prev_state);
1647 if (strstr(CATG,
"CALIB") != NULL) {
1648 if (strstr(TYPE,
"FLAT") != NULL && strstr(TYPE,
"LAMP") != NULL) {
1649 if (strstr(TYPE,
"NASMYTH") != NULL) {
1650 if (strstr(TECH,
"MOS") != NULL || strstr(TECH,
"IFU") != NULL) {
1654 else if (strstr(TECH,
"MOS") != NULL || strstr(TECH,
"IFU") != NULL) {
1658 else if (strstr(TYPE,
"SKY") != NULL) {
1659 if (strstr(TECH,
"MOS") != NULL || strstr(TECH,
"IFU") != NULL) {
1670giraffe_qc_airm_see_avg(cpl_propertylist *properties)
1672 double airmass = 0.0;
1673 double seeing = 0.0;
1675 const cxchar *
const fctid =
"giraffe_qc_airm_see_avg";
1677 char *qcairm = GIALIAS_QCAIRMAVG;
1678 char *qcsee = GIALIAS_QCSEEAVG;
1680 cpl_errorstate tempes = cpl_errorstate_get();
1682 if (cpl_propertylist_has(properties, GIALIAS_PROSCIENCE)) {
1683 if (cpl_propertylist_get_bool(properties, GIALIAS_PROSCIENCE)) {
1684 qcairm = GIALIAS_QCAIR;
1685 qcsee = GIALIAS_QCFWHM;
1689 cxbool start = cpl_propertylist_has(properties, GIALIAS_AIRMASS_START);
1690 cxbool end = cpl_propertylist_has(properties, GIALIAS_AIRMASS_END);
1692 if ((start == FALSE) || (end == FALSE)) {
1693 cpl_msg_debug(fctid,
"Unable to compute airmass of the "
1701 (cpl_propertylist_get_double(properties, GIALIAS_AIRMASS_START) +
1702 cpl_propertylist_get_double(properties, GIALIAS_AIRMASS_END));
1705 cpl_propertylist_update_double(properties, qcairm, airmass);
1706 cpl_propertylist_set_comment(properties, qcairm,
1708 " in the first raw frame");
1710 start = cpl_propertylist_has(properties, GIALIAS_FWHM_START);
1711 end = cpl_propertylist_has(properties, GIALIAS_FWHM_END);
1713 if ((start == FALSE) || (end == FALSE)) {
1714 cpl_msg_warning(fctid,
"Unable to compute seeing of the "
1721 0.5 * (cpl_propertylist_get_double(properties, GIALIAS_FWHM_START) +
1722 cpl_propertylist_get_double(properties, GIALIAS_FWHM_END));
1725 cpl_propertylist_update_double(properties, qcsee, seeing);
1726 cpl_propertylist_set_comment(properties, qcsee,
1728 " in the first raw frame");
1731 cpl_errorstate_set(tempes);
1736const int giraffe_qc_update_sci_props(cpl_propertylist* properties, GiTable* fibers) {
1738 cpl_errorstate tempes = cpl_errorstate_get();
1740 cpl_propertylist_append_string(properties, GIALIAS_QCSCHEME,
"UVES_STACK");
1741 giraffe_qc_airm_see_avg(properties);
1750 nsci = cpl_table_and_selected_string(fibtab,
"TYPE", CPL_EQUAL_TO,
"M");
1751 cpl_table_select_all(fibtab);
1752 nsky = cpl_table_and_selected_string(fibtab,
"TYPE", CPL_EQUAL_TO,
"S");
1753 cpl_table_select_all(fibtab);
1755 cpl_propertylist_append_int(properties, GIALIAS_QCNFIBSCI, nsci);
1756 cpl_propertylist_append_int(properties, GIALIAS_QCNFIBSKY, nsky);
1758 cpl_errorstate_set(tempes);
void gi_warning(const cxchar *format,...)
Log a warning.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
cxint giraffe_add_recipe_info(cpl_propertylist *plist, const GiRecipeInfo *info)
Add recipe specific information to a property list.
cxchar * giraffe_localtime_iso8601(void)
Get the current date and time in ISO 8601 format.
cxint giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set, cxint sequence)
Add frameset specific information to a property list.
cxchar * giraffe_path_get_basename(const cxchar *path)
Gets the name of a file without any leading directory components.
cxint giraffe_propertylist_copy(cpl_propertylist *self, const cxchar *name, const cpl_propertylist *other, const cxchar *othername)
Copy a property from one list to another.
cxdouble giraffe_propertylist_get_conad(const cpl_propertylist *properties)
Retrieve the ADU to electrons conversion factor from the given properties.
const cxchar * giraffe_get_license(void)
Get the pipeline copyright and license.
cxint giraffe_propertylist_update(cpl_propertylist *self, cpl_propertylist *properties, const cxchar *regexp)
Update a property list.
cxdouble giraffe_propertylist_get_ron(const cpl_propertylist *properties)
Retrieve the read-out noise from the given properties.
GiInstrumentMode giraffe_get_mode(cpl_propertylist *properties)
Determines the instrument mode from a property list.