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) {
226 cpl_msg_info(cpl_func,
"Product frame%s:",
227 cpl_frameset_get_size(frames) != 1 ?
"s" :
"");
229 for (i_frame = 0; i_frame < cpl_frameset_get_size(frames); ++i_frame) {
230 f = cpl_frameset_get_position_const(frames, i_frame);
231 if (cpl_frame_get_group(f) == CPL_FRAME_GROUP_PRODUCT) {
262 assure( set != NULL,
return, NULL );
264 for (i_frame = 0; i_frame < cpl_frameset_get_size(set); ++i_frame) {
266 f = cpl_frameset_get_position_const(set, i_frame);
268 const char *tag = cpl_frame_get_tag(f);
271 if (strcmp(tag, BIAS ) == 0 ||
272 strcmp(tag, DARK ) == 0 ||
273 strcmp(tag, SCREEN_FLAT_IMG ) == 0 ||
274 strcmp(tag, SKY_FLAT_IMG ) == 0 ||
275 strcmp(tag, STANDARD_IMG ) == 0 ||
276 strcmp(tag,
"LAMP_PMOS" ) == 0 ||
277 strcmp(tag,
"LAMP_MXU" ) == 0 ||
278 strcmp(tag,
"LAMP_MOS" ) == 0 ||
279 strcmp(tag,
"LAMP_LSS" ) == 0 ||
280 strcmp(tag,
"SCREEN_FLAT_PMOS") == 0 ||
281 strcmp(tag,
"STANDARD_PMOS" ) == 0 ||
282 strcmp(tag,
"SCIENCE_PMOS" ) == 0 ||
283 strcmp(tag,
"SCIENCE_MOS" ) == 0 ||
284 strcmp(tag,
"SCIENCE_MXU" ) == 0 ||
285 strcmp(tag,
"SCIENCE_LSS" ) == 0 ||
286 strcmp(tag,
"STANDARD_MOS" ) == 0 ||
287 strcmp(tag,
"STANDARD_MXU" ) == 0 ||
288 strcmp(tag,
"STANDARD_LSS" ) == 0 ||
289 strcmp(tag, SCIENCE_IMG ) == 0 ||
290 strcmp(tag,
"SCREEN_FLAT_MXU" ) == 0 ||
291 strcmp(tag,
"SCREEN_FLAT_MOS" ) == 0 ||
292 strcmp(tag,
"SCREEN_FLAT_LSS" ) == 0 ) {
293 cpl_frame_set_group(f, CPL_FRAME_GROUP_RAW);
295 else if (strcmp(tag, MASTER_BIAS ) == 0 ||
296 strcmp(tag, MASTER_DARK ) == 0 ||
297 strcmp(tag, MASTER_SCREEN_FLAT_IMG ) == 0 ||
298 strcmp(tag, MASTER_SKY_FLAT_IMG ) == 0 ||
299 strcmp(tag, ALIGNED_PHOT ) == 0 ||
300 strcmp(tag,
"MASTER_NORM_FLAT_PMOS" ) == 0 ||
301 strcmp(tag,
"DISP_COEFF_PMOS" ) == 0 ||
302 strcmp(tag,
"CURV_COEFF_PMOS" ) == 0 ||
303 strcmp(tag,
"SLIT_LOCATION_PMOS" ) == 0 ||
304 strcmp(tag,
"MASTER_NORM_FLAT_MOS" ) == 0 ||
305 strcmp(tag,
"MASTER_NORM_FLAT_MXU" ) == 0 ||
306 strcmp(tag,
"MASTER_NORM_FLAT_LSS" ) == 0 ||
307 strcmp(tag,
"MASTER_NORM_FLAT_LONG_MOS" ) == 0 ||
308 strcmp(tag,
"SLIT_LOCATION_MOS" ) == 0 ||
309 strcmp(tag,
"SLIT_LOCATION_MXU" ) == 0 ||
310 strcmp(tag,
"SLIT_LOCATION_LSS" ) == 0 ||
311 strcmp(tag,
"SLIT_LOCATION_LONG_MOS" ) == 0 ||
312 strcmp(tag,
"CURV_COEFF_MOS" ) == 0 ||
313 strcmp(tag,
"CURV_COEFF_MXU" ) == 0 ||
314 strcmp(tag,
"CURV_COEFF_LSS" ) == 0 ||
315 strcmp(tag,
"DISP_COEFF_MOS" ) == 0 ||
316 strcmp(tag,
"DISP_COEFF_MXU" ) == 0 ||
317 strcmp(tag,
"DISP_COEFF_LSS" ) == 0 ||
318 strcmp(tag,
"DISP_COEFF_LONG_MOS" ) == 0 ||
319 strcmp(tag,
"FLAT_SED_MOS" ) == 0 ||
320 strcmp(tag,
"FLAT_SED_MXU" ) == 0 ||
321 strcmp(tag,
"FLAT_SED_LSS" ) == 0 ||
322 strcmp(tag,
"FLAT_SED_LONG_MOS" ) == 0 ||
324 strcmp(tag, FLX_STD_IMG ) == 0 ||
325 strcmp(tag,
"EXTINCT_TABLE" ) == 0 ||
326 strcmp(tag,
"MASTER_LINECAT" ) == 0 ||
327 strcmp(tag,
"MASTER_DISTORTION_TABLE" ) == 0 ||
328 strcmp(tag,
"GLOBAL_DISTORTION_TABLE" ) == 0 ||
329 strcmp(tag,
"RETARDER_WAVEPLATE_CHROMATISM") == 0 ||
330 strcmp(tag,
"GRISM_TABLE" ) == 0 ||
331 strcmp(tag,
"STD_PMOS_TABLE" ) == 0 ||
332 strcmp(tag,
"TELLURIC_CONTAMINATION" ) == 0 ||
333 strcmp(tag,
"STD_FLUX_TABLE" ) == 0 ||
334 strcmp(tag,
"SPECPHOT_TABLE" ) == 0 ||
335 strcmp(tag, PHOT_TABLE ) == 0) {
336 cpl_frame_set_group(f, CPL_FRAME_GROUP_CALIB);
339 cpl_msg_warning(cpl_func,
"Unrecognized frame tag: '%s'",
362 const char **instrument_version)
364 const char *instrume = NULL;
366 instrume = cpl_propertylist_get_string(header,
367 FORS_PFITS_INSTRUME);
368 assure( !cpl_error_get_code(),
return NULL,
369 "Missing keyword %s in input header", FORS_PFITS_INSTRUME);
371 assure( strlen(instrume) >= 5,
return NULL,
372 "%s keyword must be 'fors1' or 'fors2', not '%s'",
373 FORS_PFITS_INSTRUME, instrume);
375 assure( instrume[4] ==
'1' || instrume[4] ==
'2',
return NULL,
376 "Unrecognized %s: %s", FORS_PFITS_INSTRUME, instrume);
378 if (instrument_version != NULL) {
379 *instrument_version = cpl_sprintf(
"%s", instrume);
382 return cpl_sprintf(
"fors%c/%s", instrume[4], PACKAGE_VERSION);
409 const cpl_table *defaults)
411 const char *func =
"dfs_get_parameter_int";
414 cpl_parameter *param;
417 if (parlist == NULL) {
418 cpl_msg_error(func,
"Missing input parameter list");
419 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
424 cpl_msg_error(func,
"Missing input parameter name");
425 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
429 param = cpl_parameterlist_find(parlist, name);
432 cpl_msg_error(func,
"Wrong parameter name: %s", name);
433 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
437 if (cpl_parameter_get_type(param) != CPL_TYPE_INT) {
438 cpl_msg_error(func,
"Unexpected type for parameter "
439 "\"%s\": it should be integer", name);
440 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
444 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
448 cpl_parameter_get_default_int(param) == cpl_parameter_get_int(param)) {
450 if (cpl_table_has_column(defaults, alias)) {
451 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_INT) {
452 cpl_msg_error(func,
"Unexpected type for GRISM_TABLE "
453 "column \"%s\": it should be integer", alias);
454 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
457 if (cpl_table_is_valid(defaults, alias, 0)) {
458 cpl_parameter_set_int(param, cpl_table_get_int(defaults,
462 cpl_msg_error(func,
"Invalid parameter value in table "
463 "column \"%s\"", alias);
464 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
469 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
470 "- using recipe default", alias);
474 cpl_msg_info(func,
"%s: %d", alias, cpl_parameter_get_int(param));
476 return cpl_parameter_get_int(param);
504 const char *name,
const cpl_table *defaults)
506 const char *func =
"dfs_get_parameter_double";
509 cpl_parameter *param;
512 if (parlist == NULL) {
513 cpl_msg_error(func,
"Missing input parameter list");
514 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
519 cpl_msg_error(func,
"Missing input parameter name");
520 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
524 param = cpl_parameterlist_find(parlist, name);
527 cpl_msg_error(func,
"Wrong parameter name: %s", name);
528 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
532 if (cpl_parameter_get_type(param) != CPL_TYPE_DOUBLE) {
533 cpl_msg_error(func,
"Unexpected type for parameter "
534 "\"%s\": it should be double", name);
535 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
539 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
543 cpl_parameter_get_default_double(param) ==
544 cpl_parameter_get_double(param)) {
546 if (cpl_table_has_column(defaults, alias)) {
547 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_DOUBLE) {
548 cpl_msg_error(func,
"Unexpected type for GRISM_TABL "
549 "column \"%s\": it should be double", alias);
550 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
553 if (cpl_table_is_valid(defaults, alias, 0)) {
554 cpl_parameter_set_double(param, cpl_table_get_double(defaults,
558 cpl_msg_error(func,
"Invalid parameter value in table "
559 "column \"%s\"", alias);
560 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
565 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
566 "- using recipe default", alias);
570 cpl_msg_info(func,
"%s: %f", alias, cpl_parameter_get_double(param));
572 return cpl_parameter_get_double(param);
601 const cpl_table *defaults)
603 const char *func =
"dfs_get_parameter_string";
606 cpl_parameter *param;
609 if (parlist == NULL) {
610 cpl_msg_error(func,
"Missing input parameter list");
611 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
616 cpl_msg_error(func,
"Missing input parameter name");
617 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
621 param = cpl_parameterlist_find(parlist, name);
624 cpl_msg_error(func,
"Wrong parameter name: %s", name);
625 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
629 if (cpl_parameter_get_type(param) != CPL_TYPE_STRING) {
630 cpl_msg_error(func,
"Unexpected type for parameter "
631 "\"%s\": it should be string", name);
632 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
636 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
640 strcmp(cpl_parameter_get_default_string(param),
641 cpl_parameter_get_string(param)) == 0) {
643 if (cpl_table_has_column(defaults, alias)) {
644 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_STRING) {
645 cpl_msg_error(func,
"Unexpected type for GRISM_TABLE "
646 "column \"%s\": it should be string", alias);
647 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
650 if (cpl_table_is_valid(defaults, alias, 0)) {
651 cpl_parameter_set_string(param, cpl_table_get_string(defaults,
655 cpl_msg_error(func,
"Invalid parameter value in table "
656 "column \"%s\"", alias);
657 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
662 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
663 "- using recipe default", alias);
667 cpl_msg_info(func,
"%s: %s", alias, cpl_parameter_get_string(param));
669 return cpl_parameter_get_string(param);
697 const cpl_table *defaults)
699 const char *func =
"dfs_get_parameter_bool";
702 cpl_parameter *param;
706 if (parlist == NULL) {
707 cpl_msg_error(func,
"Missing input parameter list");
708 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
713 cpl_msg_error(func,
"Missing input parameter name");
714 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
718 param = cpl_parameterlist_find(parlist, name);
721 cpl_msg_error(func,
"Wrong parameter name: %s", name);
722 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
726 if (cpl_parameter_get_type(param) != CPL_TYPE_BOOL) {
727 cpl_msg_error(func,
"Unexpected type for parameter "
728 "\"%s\": it should be boolean", name);
729 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
733 alias = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
737 cpl_parameter_get_default_bool(param) ==
738 cpl_parameter_get_bool(param)) {
740 if (cpl_table_has_column(defaults, alias)) {
741 if (cpl_table_get_column_type(defaults, alias) != CPL_TYPE_INT) {
742 cpl_msg_error(func,
"Unexpected type for GRISM_TABLE "
743 "column \"%s\": it should be integer", alias);
744 cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
747 if (cpl_table_is_valid(defaults, alias, 0)) {
748 value = cpl_table_get_int(defaults, alias, 0, NULL);
749 if (value < 0 || value > 1) {
750 cpl_msg_error(func,
"Illegal parameter value in table "
751 "column \"%s\": it should be either 0 or 1",
753 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
756 cpl_parameter_set_bool(param, value);
759 cpl_msg_error(func,
"Invalid parameter value in table "
760 "column \"%s\"", alias);
761 cpl_error_set(func, CPL_ERROR_ILLEGAL_INPUT);
766 cpl_msg_warning(func,
"Parameter \"%s\" not found in GRISM_TABLE "
767 "- using recipe default", alias);
771 value = cpl_parameter_get_bool(param);
774 cpl_msg_info(func,
"%s: TRUE", alias);
777 cpl_msg_info(func,
"%s: FALSE", alias);
854 cpl_type type,
int ext,
int calib)
856 const char *func =
"dfs_load_image";
858 cpl_frame *frame = NULL;
859 cpl_image *image = NULL;
862 frame = cpl_frameset_find(frameset, category);
865 image = cpl_image_load(cpl_frame_get_filename(frame), type, 0, ext);
867 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
868 cpl_msg_error(func,
"Cannot load image %s",
869 cpl_frame_get_filename(frame));
873 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
875 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
911 const char *func =
"dfs_load_table";
913 cpl_frame *frame = NULL;
914 cpl_table *table = NULL;
917 frame = cpl_frameset_find(frameset, category);
920 table = cpl_table_load(cpl_frame_get_filename(frame), ext, 1);
922 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
923 cpl_msg_error(func,
"Cannot load table %s",
924 cpl_frame_get_filename(frame));
958 const char *category,
int ext)
960 const char *func =
"dfs_load_header";
962 cpl_frame *frame = NULL;
963 cpl_propertylist *plist = NULL;
966 frame = cpl_frameset_find(frameset, category);
969 plist = cpl_propertylist_load(cpl_frame_get_filename(frame), ext);
971 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
972 cpl_msg_error(func,
"Cannot load header from %s",
973 cpl_frame_get_filename(frame));
989 dfs_save(cpl_frameset *frameset,
const void *
object, fors_type type,
990 const char *category, cpl_propertylist *header,
991 cpl_propertylist *extra_header,
992 const cpl_parameterlist *parlist,
const char *recipename,
993 const cpl_frame *inherit_frame)
997 cpl_propertylist *plist;
998 const char *version = NULL;
999 cpl_propertylist *raw_header = NULL;
1002 if (category == NULL || frameset == NULL ||
object == NULL ||
1003 inherit_frame == NULL) {
1004 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
1005 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
1009 if (type == FORS_TYPE_TABLE) {
1010 cpl_msg_debug(cpl_func,
"Saving %s table to disk...", category);
1013 cpl_msg_debug(cpl_func,
"Saving %s image to disk...", category);
1018 const char *raw_filename =
1019 cpl_frame_get_filename(inherit_frame);
1021 raw_header = cpl_propertylist_load(raw_filename, 0);
1022 if (raw_header == NULL) {
1023 cpl_msg_error(cpl_func,
"Could not read %s primary header", raw_filename);
1028 cpl_propertylist_delete(raw_header);
1030 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1031 cpl_msg_error(cpl_func,
"Could not identify instrument version from %s header",
1037 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1039 strlower(strcpy(filename, category));
1040 strcat(filename,
".fits");
1042 frame = cpl_frame_new();
1044 cpl_frame_set_filename(frame, filename);
1045 cpl_frame_set_tag(frame, category);
1046 cpl_frame_set_type(frame, CPL_FRAME_TYPE_ANY);
1047 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
1048 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL);
1049 if (cpl_error_get_code()) {
1050 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
1051 cpl_msg_error(cpl_func,
"Cannot initialise the product frame");
1052 cpl_frame_delete(frame);
1054 cpl_free((
void *)version);
1064 plist = cpl_propertylist_new();
1066 plist = cpl_propertylist_duplicate(header);
1068 if (cpl_dfs_setup_product_header(plist, frame, frameset, parlist,
1069 recipename, version,
"PRO-1.15",
1071 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1072 cpl_error_get_where(), cpl_error_get_message());
1073 cpl_msg_error(cpl_func,
"Problem with product %s FITS header definition",
1075 cpl_propertylist_delete(plist);
1076 cpl_frame_delete(frame);
1078 cpl_free((
void *)version);
1082 cpl_free((
void *)version);
1088 if (type == FORS_TYPE_IMAGE_ERR) {
1091 else if (type == FORS_TYPE_IMAGE) {
1092 cpl_image_save((cpl_image *)
object, filename, CPL_BPP_IEEE_FLOAT, plist,
1096 cpl_table_save((cpl_table *)
object,
1097 plist, NULL, filename, CPL_IO_DEFAULT);
1100 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1101 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1102 cpl_error_get_where(), cpl_error_get_message());
1103 cpl_msg_error(cpl_func,
"Cannot save product %s to disk", filename);
1104 cpl_propertylist_delete(plist);
1105 cpl_frame_delete(frame);
1110 cpl_propertylist_delete(plist);
1114 cpl_frameset_insert(frameset, frame);
1143 const char *category, cpl_propertylist *header,
1144 const cpl_parameterlist *parlist,
const char *recipename,
1145 const cpl_frame *inherit_frame)
1147 dfs_save(frameset, image, FORS_TYPE_IMAGE,
1148 category, header, NULL,
1149 parlist, recipename,
1178 const cpl_image *mask,
const char *category,
1179 cpl_propertylist *header,
1180 const cpl_parameterlist *parlist,
const char *recipename,
1181 const cpl_frame *inherit_frame)
1184 cpl_propertylist * extension_header;
1186 dfs_save(frameset, image, FORS_TYPE_IMAGE,
1187 category, header, NULL,
1188 parlist, recipename,
1191 extension_header = cpl_propertylist_new();
1192 cpl_propertylist_append_string(extension_header,
1193 "EXTNAME",
"IMAGE.BPM");
1195 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1197 strlower(strcpy(filename, category));
1198 strcat(filename,
".fits");
1200 cpl_image_save(mask, filename, CPL_BPP_IEEE_FLOAT, extension_header,
1202 cpl_propertylist_delete(extension_header);
1231 const char *category, cpl_propertylist *header,
1232 cpl_propertylist *err_header,
1233 const cpl_parameterlist *parlist,
const char *recipename,
1234 const cpl_frame *inherit_frame)
1236 dfs_save(frameset, image, FORS_TYPE_IMAGE_ERR,
1237 category, header, err_header,
1238 parlist, recipename,
1268 const cpl_image *mask,
const char *category,
1269 cpl_propertylist *header,
1270 const cpl_parameterlist *parlist,
const char *recipename,
1271 const cpl_frame *inherit_frame)
1274 cpl_propertylist * extension_header;
1276 dfs_save(frameset, image, FORS_TYPE_IMAGE_ERR,
1277 category, header, NULL,
1278 parlist, recipename,
1281 extension_header = cpl_propertylist_new();
1282 cpl_propertylist_append_string(extension_header,
1283 "EXTNAME",
"IMAGE.BPM");
1285 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1287 strlower(strcpy(filename, category));
1288 strcat(filename,
".fits");
1290 cpl_image_save(mask, filename, CPL_BPP_IEEE_FLOAT, extension_header,
1292 cpl_propertylist_delete(extension_header);
1299 cpl_propertylist_delete(wcs_header); \
1309 bool invert =
false;
1312 cpl_propertylist *wcs_header =
1313 cpl_propertylist_load_regexp(cpl_frame_get_filename(frame),
1314 extension, WCS_KEYS, invert);
1316 cpl_propertylist_copy_property_regexp(header, wcs_header,
".*", invert);
1318 double crpix1 = cpl_propertylist_get_double(header, FORS_PFITS_CRPIX1);
1320 assure( !cpl_error_get_code(),
return,
1321 "Could not read %s from %s", FORS_PFITS_CRPIX1,
1322 cpl_frame_get_filename(frame));
1324 double crpix2 = cpl_propertylist_get_double(header, FORS_PFITS_CRPIX2);
1326 assure( !cpl_error_get_code(),
return,
1327 "Could not read %s from %s", FORS_PFITS_CRPIX2,
1328 cpl_frame_get_filename(frame));
1330 cpl_propertylist_update_double(header, FORS_PFITS_CRPIX1,
1331 crpix1 - setting->prescan_x);
1333 cpl_propertylist_update_double(header, FORS_PFITS_CRPIX2,
1334 crpix2 - setting->prescan_y);
1345 cpl_propertylist_delete(time_header); \
1363 bool invert =
false;
1366 cpl_propertylist *time_header = NULL;
1371 cpl_propertylist_load_regexp(cpl_frame_get_filename(frame),
1372 extension,
"EXPTIME", invert);
1375 cpl_propertylist_copy_property_regexp(header,
1376 time_header,
".*", invert);
1383 while (cpl_propertylist_erase(header,
"EXPTIME"));
1384 cpl_propertylist_update_double(header,
"EXPTIME", exptime);
1401 const char *category, cpl_propertylist *header,
1402 const cpl_parameterlist *parlist,
const char *recipename,
1403 const cpl_frame *inherit_frame)
1405 dfs_save(frameset, table, FORS_TYPE_TABLE,
1406 category, header, NULL,
1407 parlist, recipename,
1445 const char *category, cpl_propertylist *header,
1446 const cpl_parameterlist *parlist,
const char *recipename,
1447 const char *version)
1449 const char *func =
"dfs_save_image";
1453 cpl_propertylist *plist;
1456 if (category == NULL || frameset == NULL || image == NULL) {
1457 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1458 cpl_error_get_where(), cpl_error_get_message());
1459 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
1463 cpl_msg_info(func,
"Saving %s image to disk...", category);
1465 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1467 strlower(strcpy(filename, category));
1468 strcat(filename,
".fits");
1470 frame = cpl_frame_new();
1472 cpl_frame_set_filename(frame, filename);
1473 cpl_frame_set_tag(frame, category);
1474 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
1475 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
1476 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL);
1477 if (cpl_error_get_code()) {
1478 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1479 cpl_error_get_where(), cpl_error_get_message());
1480 cpl_msg_error(func,
"Cannot initialise the product frame");
1481 cpl_frame_delete(frame);
1492 plist = cpl_propertylist_new();
1496 if (cpl_dfs_setup_product_header(plist, frame, frameset, parlist,
1497 recipename, version,
"PRO-1.15", NULL)) {
1498 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1499 cpl_error_get_where(), cpl_error_get_message());
1500 cpl_msg_error(func,
"Problem with product %s FITS header definition",
1503 cpl_propertylist_delete(plist);
1504 cpl_frame_delete(frame);
1513 if (cpl_image_save(image, filename, CPL_BPP_IEEE_FLOAT, plist,
1515 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1516 cpl_error_get_where(), cpl_error_get_message());
1517 cpl_msg_error(func,
"Cannot save product %s to disk", filename);
1519 cpl_propertylist_delete(plist);
1520 cpl_frame_delete(frame);
1526 cpl_propertylist_delete(plist);
1530 cpl_frameset_insert(frameset, frame);
1569 const char *category, cpl_propertylist *header,
1570 const cpl_parameterlist *parlist,
const char *recipename,
1571 const char *version)
1573 const char *func =
"dfs_save_table";
1577 cpl_propertylist *plist;
1580 if (category == NULL || frameset == NULL || table == NULL) {
1581 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
1582 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1583 cpl_error_get_where(), cpl_error_get_message());
1587 cpl_msg_info(func,
"Saving %s table to disk...", category);
1589 filename = cpl_calloc(strlen(category) + 6,
sizeof(
char));
1591 strlower(strcpy(filename, category));
1593 strcat(filename,
".fits");
1595 frame = cpl_frame_new();
1597 cpl_frame_set_filename(frame, filename);
1598 cpl_frame_set_tag(frame, category);
1599 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
1600 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
1601 cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL);
1602 if (cpl_error_get_code()) {
1603 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1604 cpl_error_get_where(), cpl_error_get_message());
1605 cpl_msg_error(func,
"Cannot initialise the product frame");
1606 cpl_frame_delete(frame);
1617 plist = cpl_propertylist_new();
1621 if (cpl_dfs_setup_product_header(plist, frame, frameset, parlist,
1622 recipename, version,
"PRO-1.15", NULL)) {
1623 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1624 cpl_error_get_where(), cpl_error_get_message());
1625 cpl_msg_error(func,
"Problem with product %s FITS header definition",
1628 cpl_propertylist_delete(plist);
1629 cpl_frame_delete(frame);
1638 if (cpl_table_save(table, plist, NULL, filename, CPL_IO_DEFAULT)) {
1639 cpl_msg_error(cpl_func,
"Error found in %s: %s",
1640 cpl_error_get_where(), cpl_error_get_message());
1641 cpl_msg_error(func,
"Cannot save product %s to disk", filename);
1643 cpl_propertylist_delete(plist);
1644 cpl_frame_delete(frame);
1650 cpl_propertylist_delete(plist);
1653 cpl_frameset_insert(frameset, frame);
1678 const char *func =
"dfs_equal_keyword";
1681 cpl_propertylist *reference;
1684 const char *rstring;
1691 if (frameset == NULL || keyword == NULL) {
1692 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
1696 if (cpl_frameset_is_empty(frameset)) {
1697 cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
1701 frame = cpl_frameset_get_first(frameset);
1707 reference = cpl_propertylist_load(cpl_frame_get_filename(frame), 0);
1708 if (cpl_error_get_code() == CPL_ERROR_BAD_FILE_FORMAT) {
1710 frame = cpl_frameset_get_next(frameset);
1714 if (cpl_propertylist_has(reference, keyword)) {
1715 rtype = cpl_propertylist_get_type(reference, keyword);
1717 if (rtype == CPL_TYPE_STRING) {
1719 rstring = cpl_strdup(cpl_propertylist_get_string(reference,
1721 cpl_propertylist_delete(reference);
1725 if (rtype == CPL_TYPE_INT) {
1727 rintero = cpl_propertylist_get_int(reference, keyword);
1728 cpl_propertylist_delete(reference);
1732 cpl_propertylist_delete(reference);
1736 cpl_propertylist_delete(reference);
1738 frame = cpl_frameset_get_next(frameset);
1745 frame = cpl_frameset_get_first(frameset);
1749 reference = cpl_propertylist_load(cpl_frame_get_filename(frame), 0);
1750 if (cpl_error_get_code() == CPL_ERROR_BAD_FILE_FORMAT) {
1752 frame = cpl_frameset_get_next(frameset);
1756 if (cpl_propertylist_has(reference, keyword)) {
1758 type = cpl_propertylist_get_type(reference, keyword);
1760 if (rtype != type) {
1761 cpl_propertylist_delete(reference);
1765 if (rtype == CPL_TYPE_STRING) {
1766 string = cpl_propertylist_get_string(reference,
1768 if (strncmp(rstring,
string, 15)) {
1769 cpl_propertylist_delete(reference);
1774 if (rtype == CPL_TYPE_INT) {
1775 intero = cpl_propertylist_get_int(reference, keyword);
1776 if (rintero - intero) {
1777 cpl_propertylist_delete(reference);
1783 cpl_propertylist_delete(reference);
1785 frame = cpl_frameset_get_next(frameset);
1788 if (rtype == CPL_TYPE_STRING)
1789 cpl_free((
void *)rstring);
1806 cpl_propertylist * extheader)
1808 char * filename = cpl_calloc(strlen(tag) + 6,
sizeof(
char));
1809 cpl_propertylist * header;
1812 header = cpl_propertylist_duplicate(extheader);
1814 cpl_propertylist_erase_regexp(header,
1815 "^ESO DPR |^ARCFILE$|^ORIGFILE$", 0);
1820 strlower(strcpy(filename, tag));
1821 strcat(filename,
".fits");
1823 if (cpl_table_save(table, NULL, header, filename, CPL_IO_EXTEND)) {
1825 cpl_ensure_code(0, CPL_ERROR_FILE_IO);
1828 cpl_propertylist_delete(header);
1831 return CPL_ERROR_NONE;
1845 cpl_propertylist * extheader)
1847 char * filename = cpl_calloc(strlen(tag) + 6,
sizeof(
char));
1849 cpl_propertylist * header;
1852 header = cpl_propertylist_duplicate(extheader);
1854 cpl_propertylist_erase_regexp(header,
1855 "^ESO DPR |^ARCFILE$|^ORIGFILE$", 0);
1860 strlower(strcpy(filename, tag));
1861 strcat(filename,
".fits");
1863 if (cpl_image_save(image, filename, CPL_BPP_IEEE_FLOAT,
1864 header, CPL_IO_EXTEND)) {
1866 cpl_ensure_code(0, CPL_ERROR_FILE_IO);
1869 cpl_propertylist_delete(header);
1872 return CPL_ERROR_NONE;
1887 cpl_parameterlist * parlist,
1889 const char * recipename,
1890 const char * version)
1893 char * filename = cpl_calloc(strlen(tag) + 6,
sizeof(
char));
1895 cpl_error_code error;
1897 cpl_propertylist * pro = cpl_propertylist_new();
1899 cpl_propertylist_append_string(pro,
"ESO PRO CATG", tag);
1901 strlower(strcpy(filename, tag));
1902 strcat(filename,
".fits");
1904 error = cpl_dfs_save_image(frameset, NULL, parlist, frameset, NULL, NULL,
1905 CPL_BPP_IEEE_FLOAT, recipename, pro,
1906 NULL, version, filename);
1909 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, cpl_propertylist *extra_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)
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)
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
void fors_image_save(const fors_image *image, const cpl_propertylist *header, const cpl_propertylist *err_header, const char *filename)
Save image.
double dfs_get_parameter_double_const(const cpl_parameterlist *parlist, const char *name)
void fors_dfs_save_image_err(cpl_frameset *frameset, const fors_image *image, const char *category, cpl_propertylist *header, cpl_propertylist *err_header, const cpl_parameterlist *parlist, const char *recipename, const cpl_frame *inherit_frame)
Save DFS product (image) with it error data.