34 #include <fors_utils.h>
35 #include <fors_image.h>
36 #include <fors_pfits.h>
58 #define WCS_KEYS "^((CRVAL|CRPIX|CTYPE|CDELT)[0-9]|RADECSYS|CD[0-9]_[0-9])$"
69 static char *strlower(
char *s)
85 char *dfs_generate_filename(
const char *category)
87 char *filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
89 strlower(strcpy(filename, category));
90 strcat(filename,
".fits");
111 const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE;
112 const unsigned newest = is_reverse ? first : last;
113 const unsigned oldest = is_reverse ? last : first;
114 const char * revmsg = is_reverse ?
" in reverse order" :
"";
121 cpl_msg_info(cpl_func,
"No error(s) to dump");
128 cpl_msg_debug(cpl_func,
"Dumping all %u error(s)%s:", newest,
131 cpl_msg_error(cpl_func,
"Dumping the %u most recent error(s) "
132 "out of a total of %u errors%s:",
133 newest - oldest + 1, newest, revmsg);
137 const char *message_from_cpl = cpl_error_get_message();
139 if (message_from_cpl == NULL) {
141 cpl_msg_error(cpl_func,
"Unspecified error");
150 while (*message_from_cpl !=
'\0' && *message_from_cpl !=
':') {
151 message_from_cpl += 1;
154 if (*message_from_cpl !=
'\0') {
155 message_from_cpl += 1;
157 if (*message_from_cpl ==
' ') message_from_cpl++;
159 if (*message_from_cpl !=
'\0') {
161 cpl_msg_error(cpl_func,
"%s [%s]", message_from_cpl,
162 cpl_error_get_where());
165 cpl_msg_error(cpl_func,
"%s [%s]",
166 cpl_error_get_message(), cpl_error_get_where());
171 cpl_msg_error(cpl_func,
"%s [%s]",
172 cpl_error_get_message(), cpl_error_get_where());
192 const char *description_short)
194 cpl_msg_info(cpl_func,
"%s", PACKAGE_STRING);
195 cpl_msg_info(cpl_func,
"%s", description_short);
198 cpl_msg_info(cpl_func,
"Input frame%s:",
199 cpl_frameset_get_size(frames) != 1 ?
"s" :
"");
219 int fors_end(
const cpl_frameset *frames, cpl_errorstate before_exec)
221 if (cpl_error_get_code() == CPL_ERROR_NONE) {
225 cpl_msg_info(cpl_func,
"Product frame%s:",
226 cpl_frameset_get_size(frames) != 1 ?
"s" :
"");
228 for (f = cpl_frameset_get_first_const(frames);
230 f = cpl_frameset_get_next_const(frames)) {
231 if (cpl_frame_get_group(f) == CPL_FRAME_GROUP_PRODUCT) {
261 assure( set != NULL,
return, NULL );
263 for (f = cpl_frameset_get_first(set);
265 f = cpl_frameset_get_next(set)) {
267 const char *tag = cpl_frame_get_tag(f);
270 if (strcmp(tag, BIAS ) == 0 ||
271 strcmp(tag, DARK ) == 0 ||
272 strcmp(tag, SCREEN_FLAT_IMG ) == 0 ||
273 strcmp(tag, SKY_FLAT_IMG ) == 0 ||
274 strcmp(tag, STANDARD_IMG ) == 0 ||
275 strcmp(tag,
"LAMP_PMOS" ) == 0 ||
276 strcmp(tag,
"SCREEN_FLAT_PMOS") == 0 ||
277 strcmp(tag,
"STANDARD_PMOS" ) == 0 ||
278 strcmp(tag,
"SCIENCE_PMOS" ) == 0 ||
279 strcmp(tag,
"SCIENCE_MOS" ) == 0 ||
280 strcmp(tag,
"SCIENCE_MXU" ) == 0 ||
281 strcmp(tag,
"SCIENCE_LSS" ) == 0 ||
282 strcmp(tag,
"STANDARD_MOS" ) == 0 ||
283 strcmp(tag,
"STANDARD_MXU" ) == 0 ||
284 strcmp(tag,
"STANDARD_LSS" ) == 0 ||
285 strcmp(tag, SCIENCE_IMG ) == 0 ||
286 strcmp(tag,
"SCREEN_FLAT_MXU" ) == 0 ||
287 strcmp(tag,
"SCREEN_FLAT_MOS" ) == 0 ||
288 strcmp(tag,
"SCREEN_FLAT_LSS" ) == 0 ) {
289 cpl_frame_set_group(f, CPL_FRAME_GROUP_RAW);
291 else if (strcmp(tag, MASTER_BIAS ) == 0 ||
292 strcmp(tag, MASTER_DARK ) == 0 ||
293 strcmp(tag, MASTER_SCREEN_FLAT_IMG ) == 0 ||
294 strcmp(tag, MASTER_SKY_FLAT_IMG ) == 0 ||
295 strcmp(tag, ALIGNED_PHOT ) == 0 ||
296 strcmp(tag,
"MASTER_NORM_FLAT_PMOS" ) == 0 ||
297 strcmp(tag,
"DISP_COEFF_PMOS" ) == 0 ||
298 strcmp(tag,
"CURV_COEFF_PMOS" ) == 0 ||
299 strcmp(tag,
"SLIT_LOCATION_PMOS" ) == 0 ||
300 strcmp(tag,
"MASTER_NORM_FLAT_MOS" ) == 0 ||
301 strcmp(tag,
"MASTER_NORM_FLAT_MXU" ) == 0 ||
302 strcmp(tag,
"MASTER_NORM_FLAT_LSS" ) == 0 ||
303 strcmp(tag,
"SLIT_LOCATION_MOS" ) == 0 ||
304 strcmp(tag,
"SLIT_LOCATION_MXU" ) == 0 ||
305 strcmp(tag,
"SLIT_LOCATION_LSS" ) == 0 ||
306 strcmp(tag,
"CURV_COEFF_MOS" ) == 0 ||
307 strcmp(tag,
"CURV_COEFF_MXU" ) == 0 ||
308 strcmp(tag,
"CURV_COEFF_LSS" ) == 0 ||
309 strcmp(tag,
"DISP_COEFF_MOS" ) == 0 ||
310 strcmp(tag,
"DISP_COEFF_MXU" ) == 0 ||
311 strcmp(tag,
"DISP_COEFF_LSS" ) == 0 ||
313 strcmp(tag, FLX_STD_IMG ) == 0 ||
314 strcmp(tag,
"MASTER_LINECAT" ) == 0 ||
315 strcmp(tag,
"MASTER_DISTORTION_TABLE" ) == 0 ||
316 strcmp(tag,
"RETARDER_WAVEPLATE_CHROMATISM") == 0 ||
317 strcmp(tag,
"GRISM_TABLE" ) == 0 ||
318 strcmp(tag,
"STD_PMOS_TABLE" ) == 0 ||
319 strcmp(tag, PHOT_TABLE ) == 0) {
320 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
323 cpl_msg_warning(cpl_func,
"Unrecognized frame tag: '%s'",
346 const char **instrument_version)
348 const char *instrume = NULL;
350 instrume = cpl_propertylist_get_string(header,
351 FORS_PFITS_INSTRUME);
352 assure( !cpl_error_get_code(),
return NULL,
353 "Missing keyword %s in input header", FORS_PFITS_INSTRUME);
355 assure( strlen(instrume) >= 5,
return NULL,
356 "%s keyword must be 'fors1' or 'fors2', not '%s'",
357 FORS_PFITS_INSTRUME, instrume);
359 assure( instrume[4] ==
'1' || instrume[4] ==
'2',
return NULL,
360 "Unrecognized %s: %s", FORS_PFITS_INSTRUME, instrume);
362 if (instrument_version != NULL) {
363 *instrument_version = cpl_sprintf(
"%s", instrume);
366 return cpl_sprintf(
"fors%c/%s", instrume[4], PACKAGE_VERSION);
393 const cpl_table *defaults)
395 const char *func =
"dfs_get_parameter_int";
398 cpl_parameter *param;
401 if (parlist == NULL) {
402 cpl_msg_error(func,
"Missing input parameter list");
403 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
408 cpl_msg_error(func,
"Missing input parameter name");
409 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
413 param = cpl_parameterlist_find(parlist, name);
416 cpl_msg_error(func,
"Wrong parameter name: %s", name);
417 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
421 if (cpl_parameter_get_type(param) != CPL_TYPE_INT) {
422 cpl_msg_error(func,
"Unexpected type for parameter "
423 "\"%s\": it should be integer", name);
424 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
428 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
432 cpl_parameter_get_default_int(param) == cpl_parameter_get_int(param)) {
434 if (cpl_table_has_column(defaults, alias)) {
435 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_INT) {
436 cpl_msg_error(func,
"Unexpected type for GRISM_TABLE "
437 "column \"%s\": it should be integer", alias);
438 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
441 if (cpl_table_is_valid(defaults, alias, 0)) {
442 cpl_parameter_set_int(param, cpl_table_get_int(defaults,
446 cpl_msg_error(func,
"Invalid parameter value in table "
447 "column \"%s\"", alias);
448 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
453 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
454 "- using recipe default", alias);
458 cpl_msg_info(func,
"%s:", alias);
459 cpl_msg_info(func,
"%s: %d",
460 cpl_parameter_get_help(param), cpl_parameter_get_int(param));
462 return cpl_parameter_get_int(param);
490 const char *name,
const cpl_table *defaults)
492 const char *func =
"dfs_get_parameter_double";
495 cpl_parameter *param;
498 if (parlist == NULL) {
499 cpl_msg_error(func,
"Missing input parameter list");
500 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
505 cpl_msg_error(func,
"Missing input parameter name");
506 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
510 param = cpl_parameterlist_find(parlist, name);
513 cpl_msg_error(func,
"Wrong parameter name: %s", name);
514 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
518 if (cpl_parameter_get_type(param) != CPL_TYPE_DOUBLE) {
519 cpl_msg_error(func,
"Unexpected type for parameter "
520 "\"%s\": it should be double", name);
521 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
525 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
529 cpl_parameter_get_default_double(param) ==
530 cpl_parameter_get_double(param)) {
532 if (cpl_table_has_column(defaults, alias)) {
533 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_DOUBLE) {
534 cpl_msg_error(func,
"Unexpected type for GRISM_TABL "
535 "column \"%s\": it should be double", alias);
536 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
539 if (cpl_table_is_valid(defaults, alias, 0)) {
540 cpl_parameter_set_double(param, cpl_table_get_double(defaults,
544 cpl_msg_error(func,
"Invalid parameter value in table "
545 "column \"%s\"", alias);
546 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
551 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
552 "- using recipe default", alias);
556 cpl_msg_info(func,
"%s:", alias);
557 cpl_msg_info(func,
"%s: %f",
558 cpl_parameter_get_help(param), cpl_parameter_get_double(param));
560 return cpl_parameter_get_double(param);
589 const cpl_table *defaults)
591 const char *func =
"dfs_get_parameter_string";
594 cpl_parameter *param;
597 if (parlist == NULL) {
598 cpl_msg_error(func,
"Missing input parameter list");
599 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
604 cpl_msg_error(func,
"Missing input parameter name");
605 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
609 param = cpl_parameterlist_find(parlist, name);
612 cpl_msg_error(func,
"Wrong parameter name: %s", name);
613 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
617 if (cpl_parameter_get_type(param) != CPL_TYPE_STRING) {
618 cpl_msg_error(func,
"Unexpected type for parameter "
619 "\"%s\": it should be string", name);
620 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
624 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
628 strcmp(cpl_parameter_get_default_string(param),
629 cpl_parameter_get_string(param)) == 0) {
631 if (cpl_table_has_column(defaults, alias)) {
632 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_STRING) {
633 cpl_msg_error(func,
"Unexpected type for GRISM_TABLE "
634 "column \"%s\": it should be string", alias);
635 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
638 if (cpl_table_is_valid(defaults, alias, 0)) {
639 cpl_parameter_set_string(param, cpl_table_get_string(defaults,
643 cpl_msg_error(func,
"Invalid parameter value in table "
644 "column \"%s\"", alias);
645 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
650 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
651 "- using recipe default", alias);
655 cpl_msg_info(func,
"%s:", alias);
656 cpl_msg_info(func,
"%s: %s", cpl_parameter_get_help(param),
657 cpl_parameter_get_string(param));
659 return cpl_parameter_get_string(param);
687 const cpl_table *defaults)
689 const char *func =
"dfs_get_parameter_bool";
692 cpl_parameter *param;
696 if (parlist == NULL) {
697 cpl_msg_error(func,
"Missing input parameter list");
698 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
703 cpl_msg_error(func,
"Missing input parameter name");
704 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
708 param = cpl_parameterlist_find(parlist, name);
711 cpl_msg_error(func,
"Wrong parameter name: %s", name);
712 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
716 if (cpl_parameter_get_type(param) != CPL_TYPE_BOOL) {
717 cpl_msg_error(func,
"Unexpected type for parameter "
718 "\"%s\": it should be boolean", name);
719 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
723 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
727 cpl_parameter_get_default_bool(param) ==
728 cpl_parameter_get_bool(param)) {
730 if (cpl_table_has_column(defaults, alias)) {
731 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_INT) {
732 cpl_msg_error(func,
"Unexpected type for GRISM_TABLE "
733 "column \"%s\": it should be integer", alias);
734 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
737 if (cpl_table_is_valid(defaults, alias, 0)) {
738 value = cpl_table_get_int(defaults, alias, 0, NULL);
739 if (value < 0 || value > 1) {
740 cpl_msg_error(func,
"Illegal parameter value in table "
741 "column \"%s\": it should be either 0 or 1",
743 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
746 cpl_parameter_set_bool(param, value);
749 cpl_msg_error(func,
"Invalid parameter value in table "
750 "column \"%s\"", alias);
751 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
756 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
757 "- using recipe default", alias);
761 value = cpl_parameter_get_bool(param);
764 cpl_msg_info(func,
"%s:", alias);
765 cpl_msg_info(func,
"%s: TRUE", cpl_parameter_get_help(param));
768 cpl_msg_info(func,
"%s:", alias);
769 cpl_msg_info(func,
"%s: FALSE", cpl_parameter_get_help(param));
846 cpl_type type,
int ext,
int calib)
848 const char *func =
"dfs_load_image";
850 cpl_frame *frame = NULL;
851 cpl_image *image = NULL;
854 frame = cpl_frameset_find(frameset, category);
857 image = cpl_image_load(cpl_frame_get_filename(frame), type, 0, ext);
859 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
860 cpl_msg_error(func,
"Cannot load image %s",
861 cpl_frame_get_filename(frame));
865 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
867 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
903 const char *func =
"dfs_load_table";
905 cpl_frame *frame = NULL;
906 cpl_table *table = NULL;
909 frame = cpl_frameset_find(frameset, category);
912 table = cpl_table_load(cpl_frame_get_filename(frame), ext, 1);
914 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
915 cpl_msg_error(func,
"Cannot load table %s",
916 cpl_frame_get_filename(frame));
919 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
952 const char *category,
int ext)
954 const char *func =
"dfs_load_header";
956 cpl_frame *frame = NULL;
957 cpl_propertylist *plist = NULL;
960 frame = cpl_frameset_find(frameset, category);
963 plist = cpl_propertylist_load(cpl_frame_get_filename(frame), ext);
965 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
966 cpl_msg_error(func,
"Cannot load header from %s",
967 cpl_frame_get_filename(frame));
983 dfs_save(cpl_frameset *frameset,
const void *
object, fors_type type,
984 const char *category, cpl_propertylist *header,
985 const cpl_parameterlist *parlist,
const char *recipename,
986 const cpl_frame *inherit_frame)
990 cpl_propertylist *plist;
991 const char *version = NULL;
992 cpl_propertylist *raw_header = NULL;
995 if (category == NULL || frameset == NULL ||
object == NULL ||
996 inherit_frame == NULL) {
997 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
998 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
1002 if (type == FORS_TYPE_TABLE) {
1003 cpl_msg_debug(cpl_func,
"Saving %s table to disk...", category);
1006 cpl_msg_debug(cpl_func,
"Saving %s image to disk...", category);
1011 const char *raw_filename =
1012 cpl_frame_get_filename(inherit_frame);
1014 raw_header = cpl_propertylist_load(raw_filename, 0);
1015 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1016 cpl_msg_error(cpl_func,
"Could not read %s primary header", raw_filename);
1021 cpl_propertylist_delete(raw_header);
1023 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1024 cpl_msg_error(cpl_func,
"Could not identify instrument version from %s header",
1030 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1032 strlower(strcpy(filename, category));
1033 strcat(filename,
".fits");
1035 frame = cpl_frame_new();
1037 cpl_frame_set_filename(frame, filename);
1038 cpl_frame_set_tag(frame, category);
1039 cpl_frame_set_type(frame, CPL_FRAME_TYPE_ANY);
1040 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
1041 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL);
1042 if (cpl_error_get_code()) {
1043 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
1044 cpl_msg_error(cpl_func,
"Cannot initialise the product frame");
1045 cpl_frame_delete(frame);
1047 cpl_free((
void *)version);
1057 plist = cpl_propertylist_new();
1061 if (cpl_dfs_setup_product_header(plist, frame, frameset, parlist,
1062 recipename, version,
"PRO-1.15",
1064 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1065 cpl_error_get_where(), cpl_error_get_message());
1066 cpl_msg_error(cpl_func,
"Problem with product %s FITS header definition",
1069 cpl_propertylist_delete(plist);
1070 cpl_frame_delete(frame);
1072 cpl_free((
void *)version);
1076 cpl_free((
void *)version);
1083 cpl_propertylist_erase(plist,
"ESO DET OUT1 OVSCX");
1084 cpl_propertylist_erase(plist,
"ESO DET OUT1 PRSCX");
1085 cpl_propertylist_erase(plist,
"ESO DET OUT1 OVSCY");
1086 cpl_propertylist_erase(plist,
"ESO DET OUT1 PRSCY");
1092 if (type == FORS_TYPE_IMAGE_ERR) {
1095 else if (type == FORS_TYPE_IMAGE) {
1096 cpl_image_save((cpl_image *)
object, filename, CPL_BPP_IEEE_FLOAT, plist,
1100 cpl_table_save((cpl_table *)
object,
1101 plist, NULL, filename, CPL_IO_DEFAULT);
1104 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1105 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1106 cpl_error_get_where(), cpl_error_get_message());
1107 cpl_msg_error(cpl_func,
"Cannot save product %s to disk", filename);
1109 cpl_propertylist_delete(plist);
1110 cpl_frame_delete(frame);
1116 cpl_propertylist_delete(plist);
1120 cpl_frameset_insert(frameset, frame);
1149 const char *category, cpl_propertylist *header,
1150 const cpl_parameterlist *parlist,
const char *recipename,
1151 const cpl_frame *inherit_frame)
1153 dfs_save(frameset, image, FORS_TYPE_IMAGE,
1155 parlist, recipename,
1184 const cpl_image *mask,
const char *category,
1185 cpl_propertylist *header,
1186 const cpl_parameterlist *parlist,
const char *recipename,
1187 const cpl_frame *inherit_frame)
1190 cpl_propertylist * extension_header;
1192 dfs_save(frameset, image, FORS_TYPE_IMAGE,
1194 parlist, recipename,
1197 extension_header = cpl_propertylist_new();
1198 cpl_propertylist_append_string(extension_header,
1199 "EXTNAME",
"IMAGE.BPM");
1201 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1203 strlower(strcpy(filename, category));
1204 strcat(filename,
".fits");
1206 cpl_image_save(mask, filename, CPL_BPP_IEEE_FLOAT, extension_header,
1208 cpl_propertylist_delete(extension_header);
1236 const char *category, cpl_propertylist *header,
1237 const cpl_parameterlist *parlist,
const char *recipename,
1238 const cpl_frame *inherit_frame)
1240 dfs_save(frameset, image, FORS_TYPE_IMAGE_ERR,
1242 parlist, recipename,
1272 const cpl_image *mask,
const char *category,
1273 cpl_propertylist *header,
1274 const cpl_parameterlist *parlist,
const char *recipename,
1275 const cpl_frame *inherit_frame)
1278 cpl_propertylist * extension_header;
1280 dfs_save(frameset, image, FORS_TYPE_IMAGE_ERR,
1282 parlist, recipename,
1285 extension_header = cpl_propertylist_new();
1286 cpl_propertylist_append_string(extension_header,
1287 "EXTNAME",
"IMAGE.BPM");
1289 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1291 strlower(strcpy(filename, category));
1292 strcat(filename,
".fits");
1294 cpl_image_save(mask, filename, CPL_BPP_IEEE_FLOAT, extension_header,
1296 cpl_propertylist_delete(extension_header);
1302 cpl_propertylist_delete(wcs_header); \
1312 bool invert =
false;
1315 cpl_propertylist *wcs_header =
1316 cpl_propertylist_load_regexp(cpl_frame_get_filename(frame),
1317 extension, WCS_KEYS, invert);
1319 cpl_propertylist_copy_property_regexp(header, wcs_header,
".*", invert);
1321 double crpix1 = cpl_propertylist_get_double(header, FORS_PFITS_CRPIX1);
1323 assure( !cpl_error_get_code(),
return,
1324 "Could not read %s from %s", FORS_PFITS_CRPIX1,
1325 cpl_frame_get_filename(frame));
1327 double crpix2 = cpl_propertylist_get_double(header, FORS_PFITS_CRPIX2);
1329 assure( !cpl_error_get_code(),
return,
1330 "Could not read %s from %s", FORS_PFITS_CRPIX2,
1331 cpl_frame_get_filename(frame));
1333 cpl_propertylist_update_double(header, FORS_PFITS_CRPIX1,
1334 crpix1 - setting->prescan_x);
1336 cpl_propertylist_update_double(header, FORS_PFITS_CRPIX2,
1337 crpix2 - setting->prescan_y);
1348 cpl_propertylist_delete(time_header); \
1366 bool invert =
false;
1369 cpl_propertylist *time_header = NULL;
1374 cpl_propertylist_load_regexp(cpl_frame_get_filename(frame),
1375 extension,
"EXPTIME", invert);
1378 cpl_propertylist_copy_property_regexp(header,
1379 time_header,
".*", invert);
1386 while (cpl_propertylist_erase(header,
"EXPTIME"));
1387 cpl_propertylist_update_double(header,
"EXPTIME", exptime);
1404 const char *category, cpl_propertylist *header,
1405 const cpl_parameterlist *parlist,
const char *recipename,
1406 const cpl_frame *inherit_frame)
1408 dfs_save(frameset, table, FORS_TYPE_TABLE,
1410 parlist, recipename,
1448 const char *category, cpl_propertylist *header,
1449 const cpl_parameterlist *parlist,
const char *recipename,
1450 const char *version)
1452 const char *func =
"dfs_save_image";
1456 cpl_propertylist *plist;
1459 if (category == NULL || frameset == NULL || image == NULL) {
1460 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1461 cpl_error_get_where(), cpl_error_get_message());
1462 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
1466 cpl_msg_info(func,
"Saving %s image to disk...", category);
1468 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1470 strlower(strcpy(filename, category));
1471 strcat(filename,
".fits");
1473 frame = cpl_frame_new();
1475 cpl_frame_set_filename(frame, filename);
1476 cpl_frame_set_tag(frame, category);
1477 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
1478 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
1479 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL);
1480 if (cpl_error_get_code()) {
1481 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1482 cpl_error_get_where(), cpl_error_get_message());
1483 cpl_msg_error(func,
"Cannot initialise the product frame");
1484 cpl_frame_delete(frame);
1495 plist = cpl_propertylist_new();
1499 if (cpl_dfs_setup_product_header(plist, frame, frameset, parlist,
1500 recipename, version,
"PRO-1.15", NULL)) {
1501 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1502 cpl_error_get_where(), cpl_error_get_message());
1503 cpl_msg_error(func,
"Problem with product %s FITS header definition",
1506 cpl_propertylist_delete(plist);
1507 cpl_frame_delete(frame);
1512 cpl_propertylist_erase_regexp(plist,
"^ESO DET OUT1 OVSC*", 0);
1513 cpl_propertylist_erase_regexp(plist,
"^ESO DET OUT1 PRSC*", 0);
1519 if (cpl_image_save(image, filename, CPL_BPP_IEEE_FLOAT, plist,
1521 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1522 cpl_error_get_where(), cpl_error_get_message());
1523 cpl_msg_error(func,
"Cannot save product %s to disk", filename);
1525 cpl_propertylist_delete(plist);
1526 cpl_frame_delete(frame);
1532 cpl_propertylist_delete(plist);
1536 cpl_frameset_insert(frameset, frame);
1575 const char *category, cpl_propertylist *header,
1576 const cpl_parameterlist *parlist,
const char *recipename,
1577 const char *version)
1579 const char *func =
"dfs_save_table";
1583 cpl_propertylist *plist;
1586 if (category == NULL || frameset == NULL || table == NULL) {
1587 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
1588 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1589 cpl_error_get_where(), cpl_error_get_message());
1593 cpl_msg_info(func,
"Saving %s table to disk...", category);
1595 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1597 strlower(strcpy(filename, category));
1599 strcat(filename,
".fits");
1601 frame = cpl_frame_new();
1603 cpl_frame_set_filename(frame, filename);
1604 cpl_frame_set_tag(frame, category);
1605 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
1606 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
1607 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL);
1608 if (cpl_error_get_code()) {
1609 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1610 cpl_error_get_where(), cpl_error_get_message());
1611 cpl_msg_error(func,
"Cannot initialise the product frame");
1612 cpl_frame_delete(frame);
1623 plist = cpl_propertylist_new();
1627 if (cpl_dfs_setup_product_header(plist, frame, frameset, parlist,
1628 recipename, version,
"PRO-1.15", NULL)) {
1629 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1630 cpl_error_get_where(), cpl_error_get_message());
1631 cpl_msg_error(func,
"Problem with product %s FITS header definition",
1634 cpl_propertylist_delete(plist);
1635 cpl_frame_delete(frame);
1640 cpl_propertylist_erase_regexp(plist,
"^ESO DET OUT1 OVSC*", 0);
1641 cpl_propertylist_erase_regexp(plist,
"^ESO DET OUT1 PRSC*", 0);
1647 if (cpl_table_save(table, plist, NULL, filename, CPL_IO_DEFAULT)) {
1648 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1649 cpl_error_get_where(), cpl_error_get_message());
1650 cpl_msg_error(func,
"Cannot save product %s to disk", filename);
1652 cpl_propertylist_delete(plist);
1653 cpl_frame_delete(frame);
1659 cpl_propertylist_delete(plist);
1662 cpl_frameset_insert(frameset, frame);
1687 const char *func =
"dfs_equal_keyword";
1690 cpl_propertylist *reference;
1693 const char *rstring;
1700 if (frameset == NULL || keyword == NULL) {
1701 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
1705 if (cpl_frameset_is_empty(frameset)) {
1706 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
1710 frame = cpl_frameset_get_first(frameset);
1716 reference = cpl_propertylist_load(cpl_frame_get_filename(frame), 0);
1717 if (cpl_error_get_code() == CPL_ERROR_BAD_FILE_FORMAT) {
1719 frame = cpl_frameset_get_next(frameset);
1723 if (cpl_propertylist_has(reference, keyword)) {
1724 rtype = cpl_propertylist_get_type(reference, keyword);
1726 if (rtype == CPL_TYPE_STRING) {
1728 rstring = cpl_strdup(cpl_propertylist_get_string(reference,
1730 cpl_propertylist_delete(reference);
1734 if (rtype == CPL_TYPE_INT) {
1736 rintero = cpl_propertylist_get_int(reference, keyword);
1737 cpl_propertylist_delete(reference);
1741 cpl_propertylist_delete(reference);
1745 cpl_propertylist_delete(reference);
1747 frame = cpl_frameset_get_next(frameset);
1754 frame = cpl_frameset_get_first(frameset);
1758 reference = cpl_propertylist_load(cpl_frame_get_filename(frame), 0);
1759 if (cpl_error_get_code() == CPL_ERROR_BAD_FILE_FORMAT) {
1761 frame = cpl_frameset_get_next(frameset);
1765 if (cpl_propertylist_has(reference, keyword)) {
1767 type = cpl_propertylist_get_type(reference, keyword);
1769 if (rtype != type) {
1770 cpl_propertylist_delete(reference);
1774 if (rtype == CPL_TYPE_STRING) {
1775 string = cpl_propertylist_get_string(reference,
1777 if (strncmp(rstring,
string, 15)) {
1778 cpl_propertylist_delete(reference);
1783 if (rtype == CPL_TYPE_INT) {
1784 intero = cpl_propertylist_get_int(reference, keyword);
1785 if (rintero - intero) {
1786 cpl_propertylist_delete(reference);
1792 cpl_propertylist_delete(reference);
1794 frame = cpl_frameset_get_next(frameset);
1797 if (rtype == CPL_TYPE_STRING)
1798 cpl_free((
void *)rstring);
1815 cpl_propertylist * extheader)
1817 char * filename = cpl_calloc(strlen(tag) + 6,
sizeof(
char));
1818 cpl_propertylist * header;
1821 header = cpl_propertylist_duplicate(extheader);
1823 cpl_propertylist_erase_regexp(header,
1824 "^ESO DPR |^ARCFILE$|^ORIGFILE$", 0);
1829 strlower(strcpy(filename, tag));
1830 strcat(filename,
".fits");
1832 if (cpl_table_save(table, NULL, header, filename, CPL_IO_EXTEND)) {
1834 cpl_ensure_code(0, CPL_ERROR_FILE_IO);
1837 cpl_propertylist_delete(header);
1840 return CPL_ERROR_NONE;
1854 cpl_propertylist * extheader)
1856 char * filename = cpl_calloc(strlen(tag) + 6,
sizeof(
char));
1858 cpl_propertylist * header;
1861 header = cpl_propertylist_duplicate(extheader);
1863 cpl_propertylist_erase_regexp(header,
1864 "^ESO DPR |^ARCFILE$|^ORIGFILE$", 0);
1869 strlower(strcpy(filename, tag));
1870 strcat(filename,
".fits");
1872 if (cpl_image_save(image, filename, CPL_BPP_IEEE_FLOAT,
1873 header, CPL_IO_EXTEND)) {
1875 cpl_ensure_code(0, CPL_ERROR_FILE_IO);
1878 cpl_propertylist_delete(header);
1881 return CPL_ERROR_NONE;
1896 cpl_parameterlist * parlist,
1898 const char * recipename,
1899 const char * version)
1901 const char * regexp =
"ESO DET OUT1 OVSCX|"
1902 "ESO DET OUT1 PRSCX|"
1903 "ESO DET OUT1 OVSCY|"
1904 "ESO DET OUT1 PRSCY";
1906 char * filename = cpl_calloc(strlen(tag) + 6,
sizeof(
char));
1908 cpl_error_code error;
1910 cpl_propertylist * pro = cpl_propertylist_new();
1912 cpl_propertylist_append_string(pro,
"ESO PRO CATG", tag);
1914 strlower(strcpy(filename, tag));
1915 strcat(filename,
".fits");
1917 error = cpl_dfs_save_image(frameset, NULL, parlist, frameset, NULL, NULL,
1918 CPL_BPP_IEEE_FLOAT, recipename, pro,
1919 regexp, version, filename);
1922 cpl_propertylist_delete(pro);
static void errorstate_dump_one(unsigned self, unsigned first, unsigned last)
Dump a single CPL error.
void fors_dfs_save_image_err_mask(cpl_frameset *frameset, const fors_image *image, const cpl_image *mask, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const cpl_frame *inherit_frame)
Save DFS product (image) with it error data and a bad pixel mask.
int fors_end(const cpl_frameset *frames, cpl_errorstate before_exec)
End recipe execution.
cpl_image * dfs_load_image(cpl_frameset *frameset, const char *category, cpl_type type, int ext, int calib)
Loading image data of given category.
const char * dfs_get_parameter_string(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe string parameter value.
void fors_frameset_print(const cpl_frameset *frames)
Print a frame set.
cpl_propertylist * dfs_load_header(cpl_frameset *frameset, const char *category, int ext)
Loading header associated to data of given category.
void fors_dfs_add_exptime(cpl_propertylist *header, const cpl_frame *frame, double exptime)
Add keyword EXPTIME to header.
cpl_error_code dfs_save_image_null(cpl_frameset *frameset, cpl_parameterlist *parlist, const char *tag, const char *recipename, const char *version)
Save a product with an empty primary extension.
cpl_error_code dfs_save_image_ext(cpl_image *image, const char *tag, cpl_propertylist *extheader)
Save an image in a extension.
void fors_begin(cpl_frameset *frames, const char *description_short)
Start recipe execution.
void fors_dfs_save_image(cpl_frameset *frameset, const cpl_image *image, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const cpl_frame *inherit_frame)
Save DFS product (image)
static void dfs_save(cpl_frameset *frameset, const void *object, fors_type type, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const cpl_frame *inherit_frame)
Save DFS product.
void fors_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
int dfs_get_parameter_bool(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe boolean parameter value.
int dfs_equal_keyword(cpl_frameset *frameset, const char *keyword)
Saving table data of given category.
int dfs_get_parameter_int_const(const cpl_parameterlist *parlist, const char *name)
cpl_error_code dfs_save_table_ext(cpl_table *table, const char *tag, cpl_propertylist *extheader)
Save a table in a extension (different from the first one)
void fors_dfs_save_image_err(cpl_frameset *frameset, const fors_image *image, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const cpl_frame *inherit_frame)
Save DFS product (image) with it error data.
int dfs_get_parameter_bool_const(const cpl_parameterlist *parlist, const char *name)
void fors_dfs_save_table(cpl_frameset *frameset, const cpl_table *table, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const cpl_frame *inherit_frame)
Save DFS product (table)
void fors_dfs_save_image_mask(cpl_frameset *frameset, const cpl_image *image, const cpl_image *mask, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const cpl_frame *inherit_frame)
Save DFS product (image)
int dfs_save_image(cpl_frameset *frameset, const cpl_image *image, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const char *version)
Saving image data of given category.
cpl_table * dfs_load_table(cpl_frameset *frameset, const char *category, int ext)
Loading table data of given category.
int dfs_get_parameter_int(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe integer parameter value.
int dfs_save_table(cpl_frameset *frameset, const cpl_table *table, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const char *version)
Saving table data of given category.
const char * dfs_get_parameter_string_const(const cpl_parameterlist *parlist, const char *name)
void fors_image_save(const fors_image *image, const cpl_propertylist *header, const char *filename)
Save image.
double dfs_get_parameter_double(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe double parameter value.
void fors_frame_print(const cpl_frame *f)
Print a frame.
const char * fors_dfs_pipeline_version(const cpl_propertylist *header, const char **instrument_version)
Get pipeline and instrument versions.
void fors_dfs_add_wcs(cpl_propertylist *header, const cpl_frame *frame, const fors_setting *setting)
add WCS keywords to header
double dfs_get_parameter_double_const(const cpl_parameterlist *parlist, const char *name)