24#ifdef HAVE_SYS_TYPES_H
25# include <sys/types.h>
32#include <cxmessages.h>
34#include <cxstrutils.h>
38#include <cpl_errorstate.h>
39#include <cpl_matrix.h>
40#include <cpl_version.h>
44#include "gimessages.h"
61static const cxchar *_giraffe_license =
62 " This file is part of the GIRAFFE Instrument Pipeline\n"
63 " Copyright (C) 2002-2014 European Southern Observatory\n"
65 " This program is free software; you can redistribute it and/or modify\n"
66 " it under the terms of the GNU General Public License as published by\n"
67 " the Free Software Foundation; either version 2 of the License, or\n"
68 " (at your option) any later version.\n"
70 " This program is distributed in the hope that it will be useful,\n"
71 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
72 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
73 " GNU General Public License for more details.\n"
75 " You should have received a copy of the GNU General Public License\n"
76 " along with this program; if not, write to the Free Software\n"
77 " Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301"
82_giraffe_plist_append(cpl_propertylist *self, cpl_property *p)
85 const cxchar *name = cpl_property_get_name(p);
86 const cxchar *comment = cpl_property_get_comment(p);
89 switch (cpl_property_get_type(p)) {
92 cxbool value = cpl_property_get_bool(p);
94 cpl_propertylist_append_bool(self, name, value);
100 cxchar value = cpl_property_get_char(p);
102 cpl_propertylist_append_char(self, name, value);
108 cxint value = cpl_property_get_int(p);
110 cpl_propertylist_append_int(self, name, value);
116 cxlong value = cpl_property_get_long(p);
118 cpl_propertylist_append_long(self, name, value);
124 cxfloat value = cpl_property_get_float(p);
126 cpl_propertylist_append_float(self, name, value);
130 case CPL_TYPE_DOUBLE:
132 cxdouble value = cpl_property_get_double(p);
134 cpl_propertylist_append_double(self, name, value);
138 case CPL_TYPE_STRING:
140 const cxchar *value = cpl_property_get_string(p);
142 cpl_propertylist_append_string(self, name, value);
158 if (comment != NULL) {
159 cpl_propertylist_set_comment(self, name, comment);
168_giraffe_add_frame_info(cpl_propertylist *plist,
const cxchar *name,
169 const cxchar *tag, cxint sequence, cxint frame_index,
173 const cxchar *
id = NULL;
174 const cxchar *group = NULL;
178 cx_string *key = NULL;
179 cx_string *comment = NULL;
194 group =
"calibration";
202 key = cx_string_new();
203 comment = cx_string_new();
210 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
id,
211 frame_index,
"NAME");
212 cx_string_sprintf(comment,
"%s %s %s",
"File name of", group,
"frame");
214 status = cpl_propertylist_update_string(plist, cx_string_get(key), name);
216 if (status != CPL_ERROR_NONE) {
217 cx_string_delete(key);
218 cx_string_delete(comment);
223 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
224 cx_string_get(comment));
227 cx_string_delete(key);
228 cx_string_delete(comment);
238 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
id,
239 frame_index,
"CATG");
240 cx_string_sprintf(comment,
"%s %s %s",
"Frame category of", group,
243 status = cpl_propertylist_update_string(plist, cx_string_get(key), tag);
245 if (status != CPL_ERROR_NONE) {
246 cx_string_delete(key);
247 cx_string_delete(comment);
252 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
253 cx_string_get(comment));
256 cx_string_delete(key);
257 cx_string_delete(comment);
262 cx_string_delete(key);
263 cx_string_delete(comment);
271_giraffe_add_option_info(cpl_propertylist *plist,
272 const cpl_parameterlist *options, cxint sequence)
274 cx_assert(plist != NULL);
275 cx_assert(options != NULL);
276 cx_assert(sequence >= 1);
278 cx_string *key = cx_string_new();
279 cx_string *comment = cx_string_new();
282 const cpl_parameter *p = cpl_parameterlist_get_first_const(options);
285 cx_string_delete(key);
286 cx_string_delete(comment);
293 const cxchar *alias = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI);
294 cx_string *value = cx_string_new();
295 cx_string *preset = cx_string_new();
297 switch (cpl_parameter_get_type(p)) {
300 int bval = cpl_parameter_get_bool(p);
301 cx_string_sprintf(value,
"%s", (bval == 1) ?
"true" :
"false");
303 bval = cpl_parameter_get_default_bool(p);
304 cx_string_sprintf(preset,
"%s", (bval == 1) ?
"true" :
"false");
309 cx_string_sprintf(value,
"%d", cpl_parameter_get_int(p));
310 cx_string_sprintf(preset,
"%d", cpl_parameter_get_default_int(p));
313 case CPL_TYPE_DOUBLE:
315 cx_string_sprintf(value,
"%g", cpl_parameter_get_double(p));
316 cx_string_sprintf(preset,
"%g", cpl_parameter_get_default_double(p));
319 case CPL_TYPE_STRING:
321 cx_string_sprintf(value,
"%s", cpl_parameter_get_string(p));
322 cx_string_sprintf(preset,
"%s", cpl_parameter_get_default_string(p));
334 cx_string_delete(key);
335 cx_string_delete(comment);
336 cx_string_delete(value);
337 cx_string_delete(preset);
343 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
344 "PARAM", pcount,
"NAME");
345 status = cpl_propertylist_update_string(plist, cx_string_get(key), alias);
348 cx_string_delete(key);
349 cx_string_delete(comment);
350 cx_string_delete(value);
351 cx_string_delete(preset);
356 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
357 cpl_parameter_get_help(p));
360 cx_string_delete(key);
361 cx_string_delete(comment);
362 cx_string_delete(value);
363 cx_string_delete(preset);
369 cx_string_sprintf(key,
"%s%-d %s%-d %s",
"ESO PRO REC", sequence,
370 "PARAM", pcount,
"VALUE");
371 cx_string_sprintf(comment,
"Default: %s", cx_string_get(preset));
373 status = cpl_propertylist_update_string(plist, cx_string_get(key),
374 cx_string_get(value));
377 cx_string_delete(key);
378 cx_string_delete(comment);
379 cx_string_delete(value);
380 cx_string_delete(preset);
385 status = cpl_propertylist_set_comment(plist, cx_string_get(key),
386 cx_string_get(comment));
389 cx_string_delete(key);
390 cx_string_delete(comment);
391 cx_string_delete(value);
392 cx_string_delete(preset);
397 cx_string_delete(value);
398 cx_string_delete(preset);
400 p = cpl_parameterlist_get_next_const(options);
404 cx_string_delete(key);
405 cx_string_delete(comment);
425 return _giraffe_license;
447 const cxchar *fctid =
"giraffe_get_mode";
452 GiInstrumentMode insmode;
456 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
461 if (!cpl_propertylist_has(properties, GIALIAS_INSMODE)) {
462 gi_warning(
"%s: Property (%s) not found\n", fctid, GIALIAS_INSMODE);
464 if (!cpl_propertylist_has(properties, GIALIAS_SLITNAME)) {
465 cx_warning(
"%s: Property (%s) not found\n", fctid,
470 mode = cpl_propertylist_get_string(properties, GIALIAS_SLITNAME);
474 mode = cpl_propertylist_get_string(properties, GIALIAS_SLITNAME);
477 if (!mode || strlen(mode) == 0) {
478 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
483 s = cx_string_create(mode);
486 if (strncmp(cx_string_get(s),
"med", 3) == 0) {
487 insmode = GIMODE_MEDUSA;
489 else if (strncmp(cx_string_get(s),
"ifu", 3) == 0) {
490 insmode = GIMODE_IFU;
492 else if (strncmp(cx_string_get(s),
"arg", 3) == 0) {
493 insmode = GIMODE_ARGUS;
496 cpl_error_set(fctid, CPL_ERROR_UNSUPPORTED_MODE);
497 insmode = GIMODE_NONE;
525 register cxssize base;
526 register cxssize last_nonslash;
537 if (path[0] ==
'\0') {
538 return cx_strdup(
".");
541 last_nonslash = strlen(path) - 1;
543 while (last_nonslash >= 0 && path[last_nonslash] ==
'/') {
550 if (last_nonslash == -1) {
551 return cx_strdup(
"/");
554 base = last_nonslash;
556 while (base >=0 && path[base] !=
'/') {
560 len = last_nonslash - base;
562 result = cx_malloc(len + 1);
563 memcpy(result, path + base + 1, len);
589 time_t seconds = time(NULL);
591 cxchar *sdate = NULL;
593 cxulong milliseconds = 0;
595 cx_string *self = cx_string_new();
598 cx_assert(self != NULL);
600 ts = localtime(&seconds);
602 cx_string_sprintf(self,
"%4d-%02d-%02dT%02d:%02d:%02d.%03ld",
611 sdate = cx_strdup(cx_string_get(self));
612 cx_string_delete(self);
638 cx_string *name = cx_string_new();
639 cx_string *value = cx_string_new();
642 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC", info->sequence,
644 cx_string_sprintf(value,
"%s", info->recipe);
646 status = cpl_propertylist_update_string(plist, cx_string_get(name),
647 cx_string_get(value));
650 if (status != CPL_ERROR_NONE) {
651 cx_string_delete(name);
652 cx_string_delete(value);
657 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
658 "Pipeline recipe (unique) identifier");
661 cx_string_delete(name);
662 cx_string_delete(value);
667 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC", info->sequence,
669 cx_string_sprintf(value,
"%s/%s", PACKAGE, VERSION);
671 status = cpl_propertylist_update_string(plist, cx_string_get(name),
672 cx_string_get(value));
675 if (status != CPL_ERROR_NONE) {
676 cx_string_delete(name);
677 cx_string_delete(value);
682 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
683 "Pipeline (unique) identifier");
686 cx_string_delete(name);
687 cx_string_delete(value);
692 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC", info->sequence,
694 cx_string_sprintf(value,
"cpl-%s", cpl_version_get_version());
696 status = cpl_propertylist_update_string(plist, cx_string_get(name),
697 cx_string_get(value));
700 if (status != CPL_ERROR_NONE) {
701 cx_string_delete(name);
702 cx_string_delete(value);
707 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
708 "Data Reduction System identifier");
711 cx_string_delete(name);
712 cx_string_delete(value);
717 if (info->start != NULL) {
718 cx_string_sprintf(name,
"%s%-d %s",
"ESO PRO REC",
719 info->sequence,
"START");
720 status = cpl_propertylist_update_string(plist,
724 if (status != CPL_ERROR_NONE) {
725 cx_string_delete(name);
726 cx_string_delete(value);
731 status = cpl_propertylist_set_comment(plist, cx_string_get(name),
732 "Date when recipe execution "
736 cx_string_delete(name);
737 cx_string_delete(value);
743 cx_string_delete(name);
744 cx_string_delete(value);
751 status = _giraffe_add_option_info(plist, info->options, info->sequence);
799 cx_string *key = cx_string_new();
801 const cpl_frame *frame = NULL;
803 cpl_frameset_iterator *it = cpl_frameset_iterator_new(set);
806 while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) {
808 cpl_frame_group group = cpl_frame_get_group(frame);
810 const cxchar *name = cpl_frame_get_filename(frame);
811 const cxchar *tag = cpl_frame_get_tag(frame);
815 cx_assert(base != NULL);
818 case CPL_FRAME_GROUP_RAW:
831 if (!cpl_propertylist_has(plist, GIALIAS_ANCESTOR)) {
835 cpl_propertylist *_plist = cpl_propertylist_load(name, 0);
837 if (_plist == NULL) {
840 cx_free((cxchar *)base);
843 cpl_frameset_iterator_delete(it);
844 cx_string_delete(key);
850 if (cpl_propertylist_has(_plist, GIALIAS_ANCESTOR)) {
851 cpl_propertylist_copy_property(plist, _plist,
857 cpl_propertylist_get_string(_plist,
859 const cxchar *c =
"Inherited archive file name "
860 "of the first raw data frame";
863 cpl_propertylist_append_string(plist,
864 GIALIAS_ANCESTOR, s);
865 cpl_propertylist_set_comment(plist,
866 GIALIAS_ANCESTOR, c);
871 cpl_propertylist_delete(_plist);
878 status = _giraffe_add_frame_info(plist, base, tag,
883 cx_free((cxchar *)base);
886 cpl_frameset_iterator_delete(it);
887 cx_string_delete(key);
896 case CPL_FRAME_GROUP_CALIB:
899 cpl_propertylist *_plist = NULL;
903 cxint status = _giraffe_add_frame_info(plist, base, tag,
904 sequence, ncalib, 1);
908 cx_free((cxchar *)base);
911 cpl_frameset_iterator_delete(it);
912 cx_string_delete(key);
917 _plist = cpl_propertylist_load(name, 0);
919 if (_plist == NULL) {
921 cx_free((cxchar *)base);
924 cpl_frameset_iterator_delete(it);
925 cx_string_delete(key);
931 if (cpl_propertylist_has(_plist, GIALIAS_DATAMD5)) {
934 cpl_propertylist_get_string(_plist, GIALIAS_DATAMD5);
936 if (strcmp(s,
"Not computed") != 0) {
938 cx_string* md5 = cx_string_new();
940 cx_string_sprintf(md5,
"%s%d %s%"
941 CX_PRINTF_FORMAT_SIZE_TYPE
"%s",
942 "ESO PRO REC", sequence,
"CAL",
946 cpl_propertylist_update_string(plist,
950 if (status != CPL_ERROR_NONE) {
951 cx_string_delete(md5);
952 cpl_propertylist_delete(_plist);
955 cx_free((cxchar *)base);
958 cpl_frameset_iterator_delete(it);
959 cx_string_delete(key);
964 cx_string_delete(md5);
969 cpl_propertylist_delete(_plist);
979 cx_free((cxchar *)base);
982 cpl_frameset_iterator_advance(it, 1);
986 cpl_frameset_iterator_delete(it);
987 cx_string_delete(key);
1018 cpl_propertylist *properties,
1019 const cxchar *regexp)
1022 const cxchar *fctid =
"giraffe_propertylist_update";
1028 cx_assert(self != NULL);
1030 if (properties == NULL) {
1031 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
1035 sz = cpl_propertylist_get_size(properties);
1037 if (regexp == NULL || regexp[0] ==
'\0') {
1039 for (i = 0; i < sz; i++) {
1041 cpl_property *p = cpl_propertylist_get(properties, i);
1042 const cxchar *name = cpl_property_get_name(p);
1045 if (!cpl_propertylist_has(self, name)) {
1047 cxint status = _giraffe_plist_append(self, p);
1050 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
1063 status = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB);
1066 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
1070 for (i = 0; i < sz; i++) {
1072 cpl_property *p = cpl_propertylist_get(properties, i);
1073 const cxchar *name = cpl_property_get_name(p);
1076 if (regexec(&re, name, (
size_t)0, NULL, 0) == REG_NOMATCH) {
1080 if (!cpl_propertylist_has(self, name)) {
1082 status = _giraffe_plist_append(self, p);
1085 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
1110 const cpl_propertylist *other,
1111 const cxchar *othername)
1114 const cxchar *fctid =
"giraffe_propertylist_copy";
1118 const cxchar *comment;
1124 cx_assert(self != NULL);
1126 if (other == NULL) {
1130 if (othername == NULL) {
1134 if (!cpl_propertylist_has(other, othername)) {
1138 type = cpl_propertylist_get_type(other, othername);
1145 s = name == NULL ? othername : name;
1155 cxchar value = cpl_propertylist_get_char(other, othername);
1157 if (cpl_propertylist_has(self, s)) {
1158 cpl_propertylist_set_char(self, s, value);
1161 cpl_propertylist_append_char(self, s, value);
1168 cxbool value = cpl_propertylist_get_bool(other, othername);
1170 if (cpl_propertylist_has(self, s)) {
1171 cpl_propertylist_set_bool(self, s, value);
1174 cpl_propertylist_append_bool(self, s, value);
1181 cxint value = cpl_propertylist_get_int(other, othername);
1183 if (cpl_propertylist_has(self, s)) {
1184 cpl_propertylist_set_int(self, s, value);
1187 cpl_propertylist_append_int(self, s, value);
1194 cxlong value = cpl_propertylist_get_long(other, othername);
1196 if (cpl_propertylist_has(self, s)) {
1197 cpl_propertylist_set_long(self, s, value);
1200 cpl_propertylist_append_long(self, s, value);
1205 case CPL_TYPE_FLOAT:
1207 cxfloat value = cpl_propertylist_get_float(other, othername);
1209 if (cpl_propertylist_has(self, s)) {
1210 cpl_propertylist_set_float(self, s, value);
1213 cpl_propertylist_append_float(self, s, value);
1218 case CPL_TYPE_DOUBLE:
1220 cxdouble value = cpl_propertylist_get_double(other, othername);
1222 if (cpl_propertylist_has(self, s)) {
1223 cpl_propertylist_set_double(self, s, value);
1226 cpl_propertylist_append_double(self, s, value);
1231 case CPL_TYPE_STRING:
1233 const cxchar *value = cpl_propertylist_get_string(other,
1236 if (cpl_propertylist_has(self, s)) {
1237 cpl_propertylist_set_string(self, s, value);
1240 cpl_propertylist_append_string(self, s, value);
1246 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
1251 comment = cpl_propertylist_get_comment(other, othername);
1253 if (comment != NULL) {
1254 cpl_propertylist_set_comment(self, s, comment);
1263giraffe_propertylist_update_wcs(cpl_propertylist* properties, cxsize naxis,
1264 const cxdouble* crpix,
const cxdouble* crval,
1265 const cxchar** ctype,
const cxchar** cunit,
1266 const cpl_matrix* cd)
1269 if (properties == NULL) {
1273 cpl_propertylist_erase_regexp(properties,
"^CRPIX[0-9]", 0);
1274 cpl_propertylist_erase_regexp(properties,
"^CRVAL[0-9]", 0);
1275 cpl_propertylist_erase_regexp(properties,
"^CDELT[0-9]", 0);
1276 cpl_propertylist_erase_regexp(properties,
"^CTYPE[0-9]", 0);
1277 cpl_propertylist_erase_regexp(properties,
"^CUNIT[0-9]", 0);
1278 cpl_propertylist_erase_regexp(properties,
"^CROTA[0-9]", 0);
1279 cpl_propertylist_erase_regexp(properties,
"^CD[0-9]*_[0-9]", 0);
1280 cpl_propertylist_erase_regexp(properties,
"^PC[0-9]*_[0-9]", 0);
1286 register cxsize i = 0;
1288 cx_string* keyword = cx_string_new();
1289 cx_string* comment = cx_string_new();
1292 cx_assert(cpl_matrix_get_nrow(cd) == cpl_matrix_get_ncol(cd));
1294 for (i = 0; i < naxis; i++) {
1296 cx_string_sprintf(keyword,
"CTYPE%-" CX_PRINTF_FORMAT_SIZE_TYPE,
1298 cx_string_sprintf(comment,
"Coordinate system of axis %"
1299 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1300 cpl_propertylist_append_string(properties,
1301 cx_string_get(keyword), ctype[i]);
1302 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
1303 cx_string_get(comment));
1307 for (i = 0; i < naxis; i++) {
1309 cx_string_sprintf(keyword,
"CRPIX%-" CX_PRINTF_FORMAT_SIZE_TYPE,
1311 cx_string_sprintf(comment,
"Reference pixel of axis %"
1312 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1313 cpl_propertylist_append_double(properties,
1314 cx_string_get(keyword), crpix[i]);
1315 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
1316 cx_string_get(comment));
1320 for (i = 0; i < naxis; i++) {
1322 cx_string_sprintf(keyword,
"CRVAL%-" CX_PRINTF_FORMAT_SIZE_TYPE,
1324 cx_string_sprintf(comment,
"Coordinate of axis %"
1325 CX_PRINTF_FORMAT_SIZE_TYPE
" at reference "
1327 cpl_propertylist_append_double(properties,
1328 cx_string_get(keyword), crval[i]);
1329 cpl_propertylist_set_comment(properties, cx_string_get(keyword),
1330 cx_string_get(comment));
1334 for (i = 0; i < naxis; i++) {
1336 if (cunit[i] != NULL) {
1337 cx_string_sprintf(keyword,
"CUNIT%-"
1338 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1339 cx_string_sprintf(comment,
"Unit of coordinate axis %"
1340 CX_PRINTF_FORMAT_SIZE_TYPE, i + 1);
1341 cpl_propertylist_append_string(properties,
1342 cx_string_get(keyword),
1344 cpl_propertylist_set_comment(properties,
1345 cx_string_get(keyword),
1346 cx_string_get(comment));
1356 for (i = 0; i < naxis; i++) {
1358 register cxsize j = 0;
1361 for (j = 0; j < naxis; j++) {
1363 cx_string_sprintf(keyword,
"CD%-" CX_PRINTF_FORMAT_SIZE_TYPE
1364 "_%-" CX_PRINTF_FORMAT_SIZE_TYPE, i + 1,
1366 cx_string_sprintf(comment,
"Coordinate transformation matrix "
1368 cpl_propertylist_append_double(properties,
1369 cx_string_get(keyword),
1370 cpl_matrix_get(cd, i, j));
1371 cpl_propertylist_set_comment(properties,
1372 cx_string_get(keyword),
1373 cx_string_get(comment));
1378 cx_string_delete(keyword);
1381 cx_string_delete(comment);
1392giraffe_frameset_set_groups(cpl_frameset* set, GiGroupInfo *groups)
1395 cpl_frame* frame = NULL;
1397 cpl_frameset_iterator *it = NULL;
1404 if (groups == NULL || groups->tag == NULL) {
1408 it = cpl_frameset_iterator_new(set);
1410 while ((frame = cpl_frameset_iterator_get(it)) != NULL) {
1412 const cxchar* tag = cpl_frame_get_tag(frame);
1415 cpl_frame_get_group(frame) == CPL_FRAME_GROUP_NONE) {
1417 const GiGroupInfo* g = groups;
1419 while (g->tag != NULL) {
1420 if (strcmp(tag, g->tag) == 0) {
1421 cpl_frame_set_group(frame, g->group);
1429 cpl_frameset_iterator_advance(it, 1);
1433 cpl_frameset_iterator_delete(it);
1476 const cxchar*
const fctid =
"giraffe_propertylist_get_conad";
1478 const cxchar *names[2] = {GIALIAS_CONAD, GIALIAS_CONAD_LEGACY};
1479 const cxchar *name = NULL;
1481 cxdouble conad = 1.;
1484 cx_assert(properties != NULL);
1487 if (!cpl_propertylist_has(properties, GIALIAS_CONAD)) {
1489 if (!cpl_propertylist_has(properties, GIALIAS_CONAD_LEGACY)) {
1491 cpl_msg_error(fctid,
"Missing detector gain property (%s, %s)! ",
1492 GIALIAS_CONAD, GIALIAS_CONAD_LEGACY);
1493 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
1508 conad = cpl_propertylist_get_double(properties, name);
1512 cpl_msg_error(fctid,
"Invalid conversion factor (%s) %.3g "
1513 "[e-/ADU]", name, conad);
1514 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
1560 const cxchar*
const fctid =
"giraffe_propertylist_get_ron";
1566 cx_assert(properties != NULL);
1568 if (!cpl_propertylist_has(properties, GIALIAS_BIASSIGMA)) {
1569 if (!cpl_propertylist_has(properties, GIALIAS_RON)) {
1570 cpl_msg_error(fctid,
"Missing detector read-out noise "
1571 "property (%s)!", GIALIAS_RON);
1572 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
1583 cpl_msg_warning(fctid,
"Missing bias RMS property (%s)! "
1584 "Using detector read-out noise property (%s).",
1585 GIALIAS_BIASSIGMA, GIALIAS_RON);
1586 ron = cpl_propertylist_get_double(properties, GIALIAS_RON);
1591 cxdouble conad = 0.;
1599 giraffe_error_push();
1603 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1607 giraffe_error_pop();
1609 ron = cpl_propertylist_get_double(properties, GIALIAS_BIASSIGMA) *
1621const char * giraffe_get_flat_type(cpl_propertylist* plist) {
1622 cpl_error_code error_code;
1623 cpl_errorstate prev_state = cpl_errorstate_get();
1625 const char* CATG = cpl_propertylist_get_string(plist,
"ESO DPR CATG");
1627 error_code = cpl_error_get_code();
1628 cpl_msg_warning(
"getDO_CATG",
"Failed to get ESO DPR CATG: %d", error_code);
1629 cpl_errorstate_set(prev_state);
1633 const char* TYPE = cpl_propertylist_get_string(plist,
"ESO DPR TYPE");
1635 error_code = cpl_error_get_code();
1636 cpl_msg_warning(
"getDO_CATG",
"Failed to get ESO DPR TYPE: %d", error_code);
1637 cpl_errorstate_set(prev_state);
1641 const char* TECH = cpl_propertylist_get_string(plist,
"ESO DPR TECH");
1643 error_code = cpl_error_get_code();
1644 cpl_msg_warning(
"getDO_CATG",
"Failed to get ESO DPR TECH: %d", error_code);
1645 cpl_errorstate_set(prev_state);
1649 if (strstr(CATG,
"CALIB") != NULL) {
1650 if (strstr(TYPE,
"FLAT") != NULL && strstr(TYPE,
"LAMP") != NULL) {
1651 if (strstr(TYPE,
"NASMYTH") != NULL) {
1652 if (strstr(TECH,
"MOS") != NULL || strstr(TECH,
"IFU") != NULL) {
1656 else if (strstr(TECH,
"MOS") != NULL || strstr(TECH,
"IFU") != NULL) {
1660 else if (strstr(TYPE,
"SKY") != NULL) {
1661 if (strstr(TECH,
"MOS") != NULL || strstr(TECH,
"IFU") != NULL) {
1672giraffe_qc_airm_see_avg(cpl_propertylist *properties)
1674 double airmass = 0.0;
1675 double seeing = 0.0;
1677 const cxchar *
const fctid =
"giraffe_qc_airm_see_avg";
1679 const char *qcairm = GIALIAS_QCAIRMAVG;
1680 const char *qcsee = GIALIAS_QCSEEAVG;
1682 cpl_errorstate tempes = cpl_errorstate_get();
1684 if (cpl_propertylist_has(properties, GIALIAS_PROSCIENCE)) {
1685 if (cpl_propertylist_get_bool(properties, GIALIAS_PROSCIENCE)) {
1686 qcairm = GIALIAS_QCAIR;
1687 qcsee = GIALIAS_QCFWHM;
1691 cxbool start = cpl_propertylist_has(properties, GIALIAS_AIRMASS_START);
1692 cxbool end = cpl_propertylist_has(properties, GIALIAS_AIRMASS_END);
1694 if ((start == FALSE) || (end == FALSE)) {
1695 cpl_msg_debug(fctid,
"Unable to compute airmass of the "
1703 (cpl_propertylist_get_double(properties, GIALIAS_AIRMASS_START) +
1704 cpl_propertylist_get_double(properties, GIALIAS_AIRMASS_END));
1707 cpl_propertylist_update_double(properties, qcairm, airmass);
1708 cpl_propertylist_set_comment(properties, qcairm,
1710 " in the first raw frame");
1712 start = cpl_propertylist_has(properties, GIALIAS_FWHM_START);
1713 end = cpl_propertylist_has(properties, GIALIAS_FWHM_END);
1715 if ((start == FALSE) || (end == FALSE)) {
1716 cpl_msg_warning(fctid,
"Unable to compute seeing of the "
1723 0.5 * (cpl_propertylist_get_double(properties, GIALIAS_FWHM_START) +
1724 cpl_propertylist_get_double(properties, GIALIAS_FWHM_END));
1727 cpl_propertylist_update_double(properties, qcsee, seeing);
1728 cpl_propertylist_set_comment(properties, qcsee,
1730 " in the first raw frame");
1733 cpl_errorstate_set(tempes);
1738int giraffe_qc_update_sci_props(cpl_propertylist* properties, GiTable* fibers) {
1740 cpl_errorstate tempes = cpl_errorstate_get();
1742 giraffe_qc_airm_see_avg(properties);
1751 nsci = cpl_table_and_selected_string(fibtab,
"TYPE", CPL_EQUAL_TO,
"M");
1752 cpl_table_select_all(fibtab);
1753 nsky = cpl_table_and_selected_string(fibtab,
"TYPE", CPL_EQUAL_TO,
"S");
1754 cpl_table_select_all(fibtab);
1756 cpl_propertylist_append_int(properties, GIALIAS_QCNFIBSCI, nsci);
1757 cpl_propertylist_append_int(properties, GIALIAS_QCNFIBSKY, nsky);
1759 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.