33#include "irplib_wlxcorr.h"
36#include "cr2res_io_eop_table.h"
37#include "cr2res_idp.h"
38#include "cr2res_utils.h"
39#include "cr2res_dfs.h"
40#include "cr2res_pfits.h"
41#include "cr2res_bpm.h"
48static int cr2res_io_set_bpm_as_NaNs(
50static int cr2res_io_set_NaNs_as_bpm(
52static int cr2res_io_check_drs_type(
53 const char * filename,
54 const char * expected_drstype) ;
55static cpl_imagelist * cr2res_hdrl_to_cpl_list(
56 const hdrl_imagelist * in,
58static int cr2res_io_save_imagelist(
59 const char * filename,
60 cpl_frameset * allframes,
61 cpl_frameset * inframes,
62 const cpl_parameterlist * parlist,
63 hdrl_imagelist ** data,
64 const cpl_propertylist * qc_list,
65 cpl_propertylist ** ext_plist,
69 const char * drstype) ;
71static int cr2res_io_save_image(
72 const char * filename,
73 cpl_frameset * allframes,
74 cpl_frameset * inframes,
75 const cpl_parameterlist * parlist,
77 const cpl_propertylist * qc_list,
78 cpl_propertylist ** ext_plist,
82 const char * drstype) ;
83static int cr2res_io_save_table(
84 const char * filename,
85 cpl_frameset * allframes,
86 cpl_frameset * inframes,
87 const cpl_parameterlist * parlist,
88 cpl_table ** slit_func,
89 const cpl_propertylist * qc_list,
90 cpl_propertylist ** ext_plist,
93 const char * drstype) ;
94static int cr2res_io_save_one_table(
95 const char * filename,
96 cpl_frameset * allframes,
97 cpl_frameset * inframes,
98 const cpl_parameterlist * parlist,
100 const cpl_propertylist * qc_list,
101 cpl_propertylist * ext_plist,
102 const char * extname,
104 const char * procatg,
105 const char * drstype) ;
122 cpl_table * eop_table;
125 eop_table = cpl_table_new(EOP_TABLE_SIZE);
126 cpl_table_new_column(eop_table,
"MJD", CPL_TYPE_DOUBLE) ;
127 cpl_table_new_column(eop_table,
"PMX", CPL_TYPE_DOUBLE) ;
128 cpl_table_new_column(eop_table,
"PMY", CPL_TYPE_DOUBLE) ;
129 cpl_table_new_column(eop_table,
"DUT", CPL_TYPE_DOUBLE) ;
130 cpl_table_new_column(eop_table,
"FLAG", CPL_TYPE_STRING) ;
131 for (i=0; i<EOP_TABLE_SIZE; i++) {
132 cpl_table_set_double(eop_table,
"MJD", i,
133 eop_table_double_entries[i][0]) ;
134 cpl_table_set_double(eop_table,
"PMX", i,
135 eop_table_double_entries[i][1]) ;
136 cpl_table_set_double(eop_table,
"PMY", i,
137 eop_table_double_entries[i][2]) ;
138 cpl_table_set_double(eop_table,
"DUT", i,
139 eop_table_double_entries[i][3]) ;
140 cpl_table_set_string(eop_table,
"FLAG", i,
141 eop_table_string_entries[i]) ;
168 const cpl_frameset * in,
169 const char * setting_id,
170 cr2res_decker decker)
172 cpl_frameset * fset ;
176 const cpl_frame * cur_frame ;
177 const char * cur_fname ;
178 cpl_propertylist * plist ;
179 cr2res_decker cur_decker ;
184 if (in == NULL)
return NULL ;
191 tags = cpl_malloc(ntags *
sizeof(
char *)) ;
192 tags[0] = cpl_sprintf(CR2RES_CAL_FLAT_SLIT_MODEL_PROCATG) ;
193 tags[1] = cpl_sprintf(CR2RES_UTIL_SLIT_MODEL_PROCATG) ;
194 tags[2] = cpl_sprintf( CR2RES_OBS_NODDING_SLITMODELA_PROCATG) ;
195 tags[3] = cpl_sprintf(CR2RES_OBS_NODDING_SLITMODELB_PROCATG) ;
200 for (i=0 ; i<ntags ; i++) cpl_free(tags[i]) ;
202 if (fset == NULL)
return NULL ;
205 for (i=0 ; i<cpl_frameset_get_size(fset) ; i++) {
208 cur_frame = cpl_frameset_get_position(fset, i) ;
209 cur_fname = cpl_frame_get_filename(cur_frame) ;
210 plist = cpl_propertylist_load(cur_fname, 0);
214 cpl_propertylist_delete(plist) ;
215 if (!strcmp(cur_setting, setting_id) && cur_decker == decker)
216 out = cpl_frame_duplicate(cur_frame) ;
217 cpl_free(cur_setting) ;
220 cpl_frameset_delete(fset) ;
233 const cpl_frame * out ;
236 if (in == NULL)
return NULL ;
238 out=cpl_frameset_find_const(in, CR2RES_CAL_FLAT_TW_PROCATG) ;
240 out=cpl_frameset_find_const(in, CR2RES_CAL_FLAT_TW_MERGED_PROCATG) ;
242 out=cpl_frameset_find_const(in, CR2RES_UTIL_TRACE_TW_PROCATG) ;
244 out=cpl_frameset_find_const(in, CR2RES_UTIL_WAVE_TW_PROCATG) ;
246 out=cpl_frameset_find_const(in, CR2RES_CAL_WAVE_TW_PROCATG) ;
248 out=cpl_frameset_find_const(in, CR2RES_UTIL_SLIT_CURV_TW_PROCATG);
250 out=cpl_frameset_find_const(in, CR2RES_OBS_NODDING_TWA_PROCATG);
252 out=cpl_frameset_find_const(in, CR2RES_OBS_NODDING_TWB_PROCATG);
254 out=cpl_frameset_find_const(in, CR2RES_OBS_POL_TWA_PROCATG);
256 out=cpl_frameset_find_const(in, CR2RES_OBS_POL_TWB_PROCATG);
269 const cpl_frame * out ;
272 if (in == NULL)
return NULL ;
274 out=cpl_frameset_find_const(in, CR2RES_CAL_FLAT_SLIT_FUNC_PROCATG) ;
276 out=cpl_frameset_find_const(in, CR2RES_UTIL_SLIT_FUNC_PROCATG) ;
278 out=cpl_frameset_find_const(in, CR2RES_OBS_NODDING_SLITFUNCA_PROCATG) ;
280 out=cpl_frameset_find_const(in, CR2RES_OBS_NODDING_SLITFUNCB_PROCATG) ;
282 out=cpl_frameset_find_const(in, CR2RES_OBS_STARING_SLITFUNC_PROCATG) ;
300 if (in == NULL)
return NULL ;
304 tags = cpl_malloc(ntags *
sizeof(
char *)) ;
305 tags[0] = cpl_sprintf(CR2RES_CAL_FLAT_TW_PROCATG) ;
306 tags[1] = cpl_sprintf(CR2RES_CAL_FLAT_TW_MERGED_PROCATG) ;
307 tags[2] = cpl_sprintf(CR2RES_UTIL_TRACE_TW_PROCATG) ;
308 tags[3] = cpl_sprintf(CR2RES_UTIL_WAVE_TW_PROCATG) ;
309 tags[4] = cpl_sprintf(CR2RES_CAL_WAVE_TW_PROCATG) ;
310 tags[5] = cpl_sprintf(CR2RES_UTIL_SLIT_CURV_TW_PROCATG) ;
311 tags[6] = cpl_sprintf(CR2RES_OBS_NODDING_TWA_PROCATG) ;
312 tags[7] = cpl_sprintf(CR2RES_OBS_NODDING_TWB_PROCATG) ;
313 tags[8] = cpl_sprintf(CR2RES_OBS_POL_TWA_PROCATG) ;
314 tags[9] = cpl_sprintf(CR2RES_OBS_POL_TWB_PROCATG) ;
319 for (i=0 ; i<ntags ; i++) cpl_free(tags[i]) ;
338 if (in == NULL)
return NULL ;
342 tags = cpl_malloc(ntags *
sizeof(
char *)) ;
343 tags[0] = cpl_sprintf(CR2RES_CAL_FLAT_EXTRACT_1D_PROCATG) ;
344 tags[1] = cpl_sprintf(CR2RES_UTIL_EXTRACT_1D_PROCATG) ;
345 tags[2] = cpl_sprintf(CR2RES_UTIL_WAVE_EXTRACT_1D_PROCATG) ;
346 tags[3] = cpl_sprintf(CR2RES_CAL_WAVE_EXTRACT_1D_PROCATG) ;
347 tags[4] = cpl_sprintf(CR2RES_OBS_NODDING_EXTRACTA_PROCATG) ;
348 tags[5] = cpl_sprintf(CR2RES_OBS_NODDING_EXTRACTB_PROCATG) ;
349 tags[6] = cpl_sprintf(CR2RES_OBS_NODDING_EXTRACTC_PROCATG) ;
350 tags[7] = cpl_sprintf(CR2RES_OBS_STARING_EXTRACT_PROCATG) ;
351 tags[8] = cpl_sprintf(CR2RES_OBS_POL_EXTRACTA_PROCATG) ;
352 tags[9] = cpl_sprintf(CR2RES_OBS_POL_EXTRACTB_PROCATG) ;
357 for (i=0 ; i<ntags ; i++) cpl_free(tags[i]) ;
371 const cpl_frame * out ;
374 if (in == NULL)
return NULL ;
376 out=cpl_frameset_find_const(in, CR2RES_CAL_DARK_BPM_PROCATG) ;
378 out = cpl_frameset_find_const(in, CR2RES_CAL_FLAT_BPM_PROCATG) ;
380 out = cpl_frameset_find_const(in, CR2RES_CAL_DETLIN_BPM_PROCATG) ;
382 out = cpl_frameset_find_const(in, CR2RES_UTIL_BPM_MERGE_PROCATG) ;
384 out = cpl_frameset_find_const(in, CR2RES_UTIL_BPM_SPLIT_PROCATG) ;
386 out = cpl_frameset_find_const(in, CR2RES_UTIL_NORM_BPM_PROCATG) ;
404 if (in == NULL)
return NULL ;
408 tags = cpl_malloc(ntags *
sizeof(
char *)) ;
409 tags[0] = cpl_sprintf(CR2RES_CAL_DARK_BPM_PROCATG) ;
410 tags[1] = cpl_sprintf(CR2RES_CAL_FLAT_BPM_PROCATG) ;
411 tags[2] = cpl_sprintf(CR2RES_CAL_DETLIN_BPM_PROCATG) ;
412 tags[3] = cpl_sprintf(CR2RES_UTIL_BPM_MERGE_PROCATG) ;
413 tags[4] = cpl_sprintf(CR2RES_UTIL_BPM_SPLIT_PROCATG) ;
414 tags[5] = cpl_sprintf(CR2RES_UTIL_NORM_BPM_PROCATG) ;
419 for (i=0 ; i<ntags ; i++) cpl_free(tags[i]) ;
438 if (in == NULL)
return NULL ;
441 dits = cpl_vector_new(cpl_frameset_get_size(in)) ;
444 for (i=0 ; i< cpl_vector_get_size(dits) ; i++) {
445 cpl_propertylist * plist ;
446 plist = cpl_propertylist_load(cpl_frame_get_filename(
447 cpl_frameset_get_position_const(in, i)), 0) ;
449 cpl_propertylist_delete(plist) ;
468 if (in == NULL)
return NULL ;
471 ndits = cpl_vector_new(cpl_frameset_get_size(in)) ;
474 for (i=0 ; i< cpl_vector_get_size(ndits) ; i++) {
475 cpl_propertylist * plist ;
476 plist = cpl_propertylist_load(cpl_frame_get_filename(
477 cpl_frameset_get_position_const(in, i)), 0) ;
479 cpl_propertylist_delete(plist) ;
493 cr2res_decker * out ;
494 cpl_size nframes, i ;
497 if (in == NULL)
return NULL ;
500 nframes = cpl_frameset_get_size(in) ;
503 out = cpl_malloc(nframes *
sizeof(cr2res_decker)) ;
506 for (i = 0; i < nframes; i++) {
507 cpl_propertylist *plist;
508 plist = cpl_propertylist_load(cpl_frame_get_filename(
509 cpl_frameset_get_position_const(in, i)), 0) ;
511 cpl_propertylist_delete(plist) ;
528 const cpl_frameset * in,
530 cr2res_decker decker)
533 cpl_frame * loc_frame ;
535 cpl_propertylist * plist ;
539 if (in == NULL)
return NULL ;
540 if (tag == NULL)
return NULL ;
541 if (decker != CR2RES_DECKER_NONE && decker != CR2RES_DECKER_1_3 &&
542 decker != CR2RES_DECKER_2_4)
546 nbframes = cpl_frameset_get_size(in) ;
549 if ((cpl_frameset_count_tags(in, tag)) == 0)
return NULL ;
552 out = cpl_frameset_new() ;
555 for (i=0 ; i<nbframes ; i++) {
556 const cpl_frame * cur_frame ;
557 cur_frame = cpl_frameset_get_position_const(in, i) ;
558 if (!strcmp(cpl_frame_get_tag(cur_frame), tag)) {
560 plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
562 loc_frame = cpl_frame_duplicate(cur_frame) ;
563 cpl_frameset_insert(out, loc_frame) ;
565 cpl_propertylist_delete(plist) ;
569 if (cpl_frameset_get_size(out) == 0){
570 cpl_frameset_delete(out) ;
586 if (order_idx < -49 || order_idx > 50)
return -1 ;
589 if (order_idx < 0)
return order_idx + 100 ;
590 else return order_idx ;
600int cr2res_io_convert_order_idxp_to_idx(
int order_idxp)
603 if (order_idxp < 0 || order_idxp > 99)
return -1 ;
606 if (order_idxp > 50)
return order_idxp - 100 ;
607 else return order_idxp ;
622 char * wished_extname ;
625 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
629 if (data) wished_extname = cpl_sprintf(
"CHIP%d.INT1", detector) ;
630 else wished_extname = cpl_sprintf(
"CHIP%dERR.INT1", detector) ;
632 return wished_extname ;
645 const char * filename,
649 char * wished_extname ;
650 int wished_ext_nb = -1 ;
654 if (filename == NULL)
return -1 ;
655 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return -1 ;
661 nb_ext = cpl_fits_count_extensions(filename) ;
664 for (i=1 ; i<=nb_ext ; i++) {
665 const char * extname ;
666 cpl_propertylist * pl ;
668 pl = cpl_propertylist_load(filename, i) ;
670 extname = cpl_propertylist_get_string(pl,
"EXTNAME");
673 if (strcmp(extname, wished_extname)==0) wished_ext_nb = i ;
674 cpl_propertylist_delete(pl) ;
676 cpl_free(wished_extname) ;
679 if (wished_ext_nb < 0) {
682 cpl_msg_warning(__func__,
683 "EXTNAME is supposed to match CHIPn.INT1 or CHIPnERR.INT1 (n=1/2/3)") ;
686 return wished_ext_nb ;
711 int ext_nr_data, ext_nr_err ;
714 if (in == NULL)
return NULL ;
715 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
722 if (ext_nr_data < 0)
return NULL ;
725 data = cpl_image_load(in, CPL_TYPE_DOUBLE, 0, ext_nr_data) ;
727 err = cpl_image_load(in, CPL_TYPE_DOUBLE, 0, ext_nr_err) ;
732 cr2res_io_set_NaNs_as_bpm(data) ;
738 if (data != NULL) cpl_image_delete(data) ;
739 if (err != NULL) cpl_image_delete(err) ;
758 hdrl_imagelist * out ;
759 cpl_imagelist * data ;
760 cpl_imagelist * error ;
762 int wished_ext_nb_data, wished_ext_nb_error ;
765 if (in == NULL)
return NULL ;
766 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
773 if (wished_ext_nb_data < 0)
return NULL ;
776 data = cpl_imagelist_load(in, CPL_TYPE_DOUBLE, wished_ext_nb_data);
777 if (wished_ext_nb_error >= 0)
778 error = cpl_imagelist_load(in, CPL_TYPE_DOUBLE, wished_ext_nb_error);
783 for (i=0 ; i<cpl_imagelist_get_size(data) ; i++)
784 cr2res_io_set_NaNs_as_bpm(cpl_imagelist_get(data, i)) ;
790 if (data != NULL) cpl_imagelist_delete(data) ;
791 if (error != NULL) cpl_imagelist_delete(error) ;
809 const cpl_frameset * in,
812 const char * first_file ;
813 hdrl_imagelist * out ;
814 cpl_imagelist * data ;
815 cpl_imagelist * err ;
817 int ext_nr_data, ext_nr_err ;
820 if (in == NULL)
return NULL ;
821 if (cpl_frameset_get_size(in) < 1)
return NULL ;
822 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
825 first_file = cpl_frame_get_filename(cpl_frameset_get_position_const(in,0)) ;
830 if (ext_nr_data < 0)
return NULL ;
833 data = cpl_imagelist_load_frameset(in, CPL_TYPE_DOUBLE, 1, ext_nr_data) ;
835 err = cpl_imagelist_load_frameset(in, CPL_TYPE_DOUBLE, 1, ext_nr_err) ;
840 for (i=0 ; i<cpl_imagelist_get_size(data) ; i++)
841 cr2res_io_set_NaNs_as_bpm(cpl_imagelist_get(data, i)) ;
847 if (data != NULL) cpl_imagelist_delete(data) ;
848 if (err != NULL) cpl_imagelist_delete(err) ;
869 cpl_table * out_tmp ;
873 if (in == NULL)
return NULL ;
874 if (det_nr < 1 || det_nr > CR2RES_NB_DETECTORS)
return NULL ;
880 if ((out = cpl_table_load(in, det_nr, 0)) == NULL) {
881 cpl_msg_error(__func__,
"Cannot load %s as a table", in) ;
886 if (pmin>0 && pmax>0 && pmax >= pmin && pmax <= cpl_table_get_nrow(out)) {
887 out_tmp = cpl_table_extract(out, pmin, pmax-pmin+1) ;
888 if (out_tmp != NULL) {
889 cpl_table_delete(out) ;
904 const char * filename)
906 cpl_bivector * lines ;
909 cpl_table * lines_tab ;
913 if (filename == NULL)
return NULL ;
916 if (cr2res_io_check_drs_type(filename, CR2RES_DRSTYPE_CATALOG) != 1) {
917 cpl_msg_info(__func__,
"File check failed for %s", filename);
925 lines_tab = cpl_table_load(filename, 1, 1) ;
926 tab_size = cpl_table_get_nrow(lines_tab) ;
929 lines = cpl_bivector_new(tab_size) ;
930 lines_x = cpl_bivector_get_x_data(lines) ;
931 lines_y = cpl_bivector_get_y_data(lines) ;
932 for (i=0 ; i<tab_size ; i++) {
935 lines_x[i] = cpl_table_get(lines_tab, CR2RES_COL_WAVELENGTH, i, NULL) ;
936 val = cpl_table_get(lines_tab, CR2RES_COL_EMISSION, i, NULL) ;
943 cpl_table_delete(lines_tab) ;
958 const char * filename,
965 if (filename == NULL)
return NULL ;
966 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
969 if (cr2res_io_check_drs_type(filename, CR2RES_BPM_DRSTYPE) != 1)
976 if (wished_ext_nb < 0)
return NULL ;
978 return cpl_image_load(filename, CPL_TYPE_INT, 0, wished_ext_nb);
991 const char * filename,
994 hdrl_image * master_dark ;
997 if (filename == NULL)
return NULL ;
998 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1001 if (cr2res_io_check_drs_type(filename, CR2RES_MASTER_DARK_DRSTYPE) != 1)
1015 cpl_msg_error(__func__,
"The error is missing") ;
1021 return master_dark ;
1035 const char * filename,
1038 hdrl_imagelist * detlin_coeffs ;
1041 if (filename == NULL)
return NULL ;
1042 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1045 if (cr2res_io_check_drs_type(filename, CR2RES_DETLIN_COEFFS_DRSTYPE) != 1)
1054 return detlin_coeffs ;
1067 const char * filename,
1070 hdrl_image * master_flat ;
1073 if (filename == NULL)
return NULL ;
1074 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1077 if (cr2res_io_check_drs_type(filename, CR2RES_MASTER_FLAT_DRSTYPE) != 1)
1091 cpl_msg_error(__func__,
"The error is missing") ;
1097 return master_flat ;
1110 const char * filename,
1113 cpl_table * trace_wave_tab ;
1116 if (filename == NULL)
return NULL ;
1117 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1120 if (cr2res_io_check_drs_type(filename, CR2RES_TW_DRSTYPE) != 1)
1127 return trace_wave_tab ;
1140 const char * filename,
1143 cpl_table * slit_func_tab ;
1146 if (filename == NULL)
return NULL ;
1147 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1150 if (cr2res_io_check_drs_type(filename, CR2RES_SLIT_FUNC_DRSTYPE) != 1)
1157 return slit_func_tab ;
1170 const char * filename,
1173 hdrl_image * slit_model ;
1176 if (filename == NULL)
return NULL ;
1177 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1180 if (cr2res_io_check_drs_type(filename, CR2RES_SLIT_MODEL_DRSTYPE) != 1)
1188 cpl_msg_error(__func__,
"The error is missing") ;
1206hdrl_image * cr2res_io_load_TRACE_MAP(
1207 const char * filename,
1210 hdrl_image * trace_map ;
1213 if (filename == NULL)
return NULL ;
1214 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1217 if (cr2res_io_check_drs_type(filename, CR2RES_TRACE_MAP_DRSTYPE) != 1)
1236hdrl_image * cr2res_io_load_WAVE_MAP(
1237 const char * filename,
1240 hdrl_image * wave_map ;
1243 if (filename == NULL)
return NULL ;
1244 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1247 if (cr2res_io_check_drs_type(filename, CR2RES_WAVE_MAP_DRSTYPE) != 1)
1266hdrl_image * cr2res_io_load_SLIT_CURV_MAP(
1267 const char * filename,
1270 hdrl_image * slit_curv_map ;
1273 if (filename == NULL)
return NULL ;
1274 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1277 if (cr2res_io_check_drs_type(filename, CR2RES_SLIT_CURV_MAP_DRSTYPE) != 1)
1284 return slit_curv_map ;
1297 const char * filename,
1300 cpl_table * extract_1D_tab ;
1303 if (filename == NULL)
return NULL ;
1304 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1307 if (cr2res_io_check_drs_type(filename, CR2RES_EXTRACT_1D_DRSTYPE) != 1)
1314 return extract_1D_tab ;
1326cpl_table * cr2res_io_load_SPLICED_1D(
1327 const char * filename,
1330 cpl_table * spliced_1D_tab ;
1333 if (filename == NULL)
return NULL ;
1334 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1337 if (cr2res_io_check_drs_type(filename, CR2RES_SPLICED_1D_DRSTYPE) != 1)
1344 return spliced_1D_tab ;
1356cpl_table * cr2res_io_load_EXTRACT_2D(
1357 const char * filename,
1360 cpl_table * extract_2D_tab ;
1363 if (cr2res_io_check_drs_type(filename, CR2RES_EXTRACT_2D_DRSTYPE) != 1)
1370 return extract_2D_tab ;
1390 const char * filename,
1391 cpl_table * out_table,
1392 const cpl_parameterlist * parlist,
1394 const char * recipe)
1396 cpl_propertylist * plist ;
1399 plist = cpl_propertylist_new();
1400 cpl_propertylist_append_string(plist, CR2RES_HEADER_INSTRUMENT,
"CRIRES") ;
1401 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
1402 CR2RES_PHOTO_FLUX_PROCATG) ;
1403 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
"STATIC") ;
1404 cpl_propertylist_append_string(plist, CR2RES_HEADER_DRS_TYPE,
1405 CR2RES_PHOTO_FLUX_DRSTYPE) ;
1407 cpl_propertylist_append_double(plist, CR2RES_HEADER_MJD_OBS, mjd_obs) ;
1410 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
1411 NULL, recipe, plist, NULL,
1412 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
1413 cpl_msg_error(__func__,
"Cannot save the table") ;
1414 cpl_propertylist_delete(plist) ;
1417 cpl_propertylist_delete(plist) ;
1436 const char * filename,
1437 cpl_table * out_table,
1438 const cpl_parameterlist * parlist,
1440 const char * recipe,
1441 const char * setting_string)
1443 cpl_propertylist * plist ;
1446 plist = cpl_propertylist_new();
1447 cpl_propertylist_append_string(plist, CR2RES_HEADER_INSTRUMENT,
"CRIRES") ;
1448 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
1449 CR2RES_EMISSION_LINES_PROCATG) ;
1450 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
"STATIC") ;
1451 cpl_propertylist_append_string(plist, CR2RES_HEADER_DRS_TYPE,
1452 CR2RES_DRSTYPE_CATALOG) ;
1455 cpl_propertylist_append_double(plist, CR2RES_HEADER_MJD_OBS, mjd_obs) ;
1457 if (setting_string != NULL) {
1458 cpl_propertylist_append_string(plist, CR2RES_HEADER_WLEN_ID,
1462 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
1463 NULL, recipe, plist, NULL,
1464 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
1465 cpl_msg_error(__func__,
"Cannot save the table") ;
1466 cpl_propertylist_delete(plist) ;
1469 cpl_propertylist_delete(plist) ;
1492 const char * filename,
1493 cpl_frameset * allframes,
1494 cpl_frameset * inframes,
1495 const cpl_parameterlist * parlist,
1496 hdrl_image ** master_darks,
1497 const cpl_propertylist * qc_list,
1498 cpl_propertylist ** ext_plist,
1499 const char * procatg,
1500 const char * recipe)
1502 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1503 master_darks, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1504 procatg, CR2RES_MASTER_DARK_DRSTYPE) ;
1524 const char * filename,
1525 cpl_frameset * allframes,
1526 cpl_frameset * inframes,
1527 const cpl_parameterlist * parlist,
1528 hdrl_imagelist ** coeffs,
1529 const cpl_propertylist * qc_list,
1530 cpl_propertylist ** ext_plist,
1531 const char * procatg,
1532 const char * recipe)
1534 return cr2res_io_save_imagelist(filename, allframes, inframes, parlist,
1535 coeffs, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1536 procatg, CR2RES_DETLIN_COEFFS_DRSTYPE) ;
1556 const char * filename,
1557 cpl_frameset * allframes,
1558 cpl_frameset * inframes,
1559 const cpl_parameterlist * parlist,
1561 const cpl_propertylist * qc_list,
1562 cpl_propertylist ** ext_plist,
1563 const char * procatg,
1564 const char * recipe)
1566 hdrl_image * hdrl_bpms[CR2RES_NB_DETECTORS] ;
1568 cpl_image * bpm_tmp;
1571 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
1572 if (bpms[det_nr-1] == NULL){
1573 hdrl_bpms[det_nr-1] = NULL ;
1575 bpm_tmp = cr2res_bpm_mask_edgepix(bpms[det_nr-1]);
1577 cpl_image_delete(bpm_tmp);
1582 ret = cr2res_io_save_image(filename, allframes, inframes, parlist,
1583 hdrl_bpms, qc_list, ext_plist, CPL_TYPE_INT, recipe,
1584 procatg, CR2RES_BPM_DRSTYPE) ;
1587 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
1609 const char * filename,
1610 cpl_frameset * allframes,
1611 cpl_frameset * inframes,
1612 const cpl_parameterlist * parlist,
1613 hdrl_image ** calib_collapsed,
1614 const cpl_propertylist * qc_list,
1615 cpl_propertylist ** ext_plist,
1616 const char * procatg,
1617 const char * recipe)
1619 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1620 calib_collapsed, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1621 procatg, CR2RES_CALIBRATED_DRSTYPE) ;
1640 const char * filename,
1641 cpl_frameset * allframes,
1642 cpl_frameset * inframes,
1643 const cpl_parameterlist * parlist,
1644 hdrl_image ** master_flats,
1645 const cpl_propertylist * qc_list,
1646 cpl_propertylist ** ext_plist,
1647 const char * procatg,
1648 const char * recipe)
1650 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1651 master_flats, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1652 procatg, CR2RES_MASTER_FLAT_DRSTYPE) ;
1671 const char * filename,
1672 cpl_frameset * allframes,
1673 cpl_frameset * inframes,
1674 const cpl_parameterlist * parlist,
1675 cpl_table ** tables,
1676 const cpl_propertylist * qc_list,
1677 cpl_propertylist ** ext_plist,
1678 const char * procatg,
1679 const char * recipe)
1682 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
1683 qc_list, ext_plist, recipe, procatg, CR2RES_TW_DRSTYPE) ;
1702 const char * filename,
1703 cpl_frameset * allframes,
1704 cpl_frameset * inframes,
1705 const cpl_parameterlist * parlist,
1706 cpl_table ** tables,
1707 const cpl_propertylist * qc_list,
1708 cpl_propertylist ** ext_plist,
1709 const char * procatg,
1710 const char * recipe)
1712 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
1713 qc_list, ext_plist, recipe, procatg,
1714 CR2RES_LINES_DIAGNOSTICS_DRSTYPE) ;
1733 const char * filename,
1734 cpl_frameset * allframes,
1735 cpl_frameset * inframes,
1736 const cpl_parameterlist * parlist,
1737 cpl_table ** tables,
1738 const cpl_propertylist * qc_list,
1739 cpl_propertylist ** ext_plist,
1740 const char * procatg,
1741 const char * recipe)
1743 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
1744 qc_list, ext_plist, recipe, procatg, CR2RES_EXTRACT_1D_DRSTYPE) ;
1763 const char * filename,
1764 cpl_frameset * allframes,
1765 cpl_frameset * inframes,
1766 const cpl_parameterlist * parlist,
1767 cpl_table ** tables,
1768 const cpl_propertylist * qc_list,
1769 cpl_propertylist ** ext_plist,
1770 const char * procatg,
1771 const char * recipe)
1773 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
1774 qc_list, ext_plist, recipe, procatg, CR2RES_THROUGHPUT_DRSTYPE) ;
1793 const char * filename,
1794 cpl_frameset * allframes,
1795 cpl_frameset * inframes,
1796 const cpl_parameterlist * parlist,
1797 cpl_table ** slit_func,
1798 const cpl_propertylist * qc_list,
1799 cpl_propertylist ** ext_plist,
1800 const char * procatg,
1801 const char * recipe)
1803 return cr2res_io_save_table(filename, allframes, inframes, parlist,
1804 slit_func, qc_list, ext_plist, recipe, procatg,
1805 CR2RES_SLIT_FUNC_DRSTYPE) ;
1824 const char * filename,
1825 cpl_frameset * allframes,
1826 cpl_frameset * inframes,
1827 const cpl_parameterlist * parlist,
1829 const cpl_propertylist * qc_list,
1830 cpl_propertylist ** ext_plist,
1831 const char * procatg,
1832 const char * recipe)
1834 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1835 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe, procatg,
1836 CR2RES_SLIT_MODEL_DRSTYPE) ;
1855 const char * filename,
1856 cpl_frameset * allframes,
1857 cpl_frameset * inframes,
1858 const cpl_parameterlist * parlist,
1860 const cpl_propertylist * qc_list,
1861 cpl_propertylist ** ext_plist,
1862 const char * procatg,
1863 const char * recipe)
1865 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1866 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe, procatg,
1867 CR2RES_COMBINED_DRSTYPE) ;
1886 const char * filename,
1887 cpl_frameset * allframes,
1888 cpl_frameset * inframes,
1889 const cpl_parameterlist * parlist,
1891 const cpl_propertylist * qc_list,
1892 cpl_propertylist ** ext_plist,
1893 const char * procatg,
1894 const char * recipe)
1896 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1897 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1898 procatg, CR2RES_TRACE_MAP_DRSTYPE) ;
1917 const char * filename,
1918 cpl_frameset * allframes,
1919 cpl_frameset * inframes,
1920 const cpl_parameterlist * parlist,
1922 const cpl_propertylist * qc_list,
1923 cpl_propertylist ** ext_plist,
1924 const char * procatg,
1925 const char * recipe)
1927 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1928 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1929 procatg, CR2RES_WAVE_MAP_DRSTYPE) ;
1948 const char * filename,
1949 cpl_frameset * allframes,
1950 cpl_frameset * inframes,
1951 const cpl_parameterlist * parlist,
1953 const cpl_propertylist * qc_list,
1954 cpl_propertylist ** ext_plist,
1955 const char * procatg,
1956 const char * recipe)
1958 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1959 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1960 procatg, CR2RES_SLIT_CURV_MAP_DRSTYPE) ;
1979 const char * filename,
1980 cpl_frameset * allframes,
1981 cpl_frameset * inframes,
1982 const cpl_parameterlist * parlist,
1983 cpl_table * spliced_1d,
1984 const cpl_propertylist * qc_list,
1985 cpl_propertylist * ext_plist,
1986 const char * procatg,
1987 const char * recipe)
1989 return cr2res_io_save_one_table(filename, allframes, inframes, parlist,
1990 spliced_1d, qc_list, ext_plist,
"SPLICED", recipe, procatg,
1991 CR2RES_SPLICED_1D_DRSTYPE) ;
2010 const char * filename,
2011 cpl_frameset * allframes,
2012 cpl_frameset * inframes,
2013 const cpl_parameterlist * parlist,
2014 cpl_table ** tables,
2015 const cpl_propertylist * qc_list,
2016 cpl_propertylist ** ext_plist,
2017 const char * procatg,
2018 const char * recipe)
2020 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
2021 qc_list, ext_plist, recipe, procatg, CR2RES_EXTRACT_2D_DRSTYPE) ;
2040 const char * filename,
2041 cpl_frameset * allframes,
2042 cpl_frameset * inframes,
2043 const cpl_parameterlist * parlist,
2044 cpl_table ** tables,
2045 const cpl_propertylist * qc_list,
2046 cpl_propertylist ** ext_plist,
2047 const char * procatg,
2048 const char * recipe)
2050 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
2051 qc_list, ext_plist, recipe, procatg, CR2RES_POL_SPEC_DRSTYPE) ;
2064static int cr2res_io_set_bpm_as_NaNs(
2067 cpl_size nx, ny, i, j ;
2071 if (in == NULL)
return -1 ;
2072 if (cpl_image_get_type(in) != CPL_TYPE_DOUBLE)
return 0 ;
2075 nx = cpl_image_get_size_x(in) ;
2076 ny = cpl_image_get_size_y(in) ;
2077 pdata = cpl_image_get_data_double(in) ;
2080 for (j=0 ; j<ny ; j++) {
2081 for (i=0 ; i<nx ; i++) {
2082 if (cpl_image_is_rejected(in, i+1, j+1)) pdata[i+j*nx] = NAN ;
2095static int cr2res_io_set_NaNs_as_bpm(
2098 cpl_size nx, ny, i, j ;
2102 if (in == NULL)
return -1 ;
2103 if (cpl_image_get_type(in) != CPL_TYPE_DOUBLE)
return 0 ;
2106 nx = cpl_image_get_size_x(in) ;
2107 ny = cpl_image_get_size_y(in) ;
2108 pdata = cpl_image_get_data_double(in) ;
2111 for (j=0 ; j<ny ; j++) {
2112 for (i=0 ; i<nx ; i++) {
2113 if (isnan(pdata[i+j*nx])) cpl_image_reject(in, i+1, j+1) ;
2135static int cr2res_io_save_table(
2136 const char * filename,
2137 cpl_frameset * allframes,
2138 cpl_frameset * inframes,
2139 const cpl_parameterlist * parlist,
2141 const cpl_propertylist * qc_list,
2142 cpl_propertylist ** ext_plist,
2143 const char * recipe,
2144 const char * procatg,
2145 const char * drstype)
2147 cpl_propertylist * pro_list ;
2148 cpl_propertylist * ext_head ;
2149 char * wished_extname ;
2154 if (allframes == NULL || filename == NULL || ext_plist == NULL)
return -1 ;
2157 if (qc_list != NULL) pro_list = cpl_propertylist_duplicate(qc_list) ;
2158 else pro_list = cpl_propertylist_new() ;
2161 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procatg) ;
2162 cpl_propertylist_append_string(pro_list, CR2RES_HEADER_DRS_TYPE, drstype) ;
2164 cr2res_qc_dup_mtrlgy_key(inframes, pro_list);
2167 if (ext_plist[0]==NULL) {
2168 ext_head = cpl_propertylist_new() ;
2170 ext_head = cpl_propertylist_duplicate(ext_plist[0]);
2171 cpl_propertylist_erase(ext_head,
"EXTNAME");
2172 if (cpl_propertylist_get_property(ext_head,
"BUNIT") != NULL)
2173 cpl_propertylist_erase(ext_head,
"BUNIT");
2176 cpl_propertylist_update_string(ext_head,
"EXTNAME", wished_extname) ;
2177 cpl_free(wished_extname) ;
2179 cr2res_qc_dup_chip_idx(ext_head);
2182 to_remove = cpl_sprintf(
"NODPOS") ;
2185 if (tab[0] != NULL) {
2186 if (cpl_dfs_save_table(allframes, NULL, parlist, inframes, NULL,
2187 tab[0], ext_head, recipe, pro_list, to_remove,
2188 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2189 cpl_msg_error(__func__,
"Cannot save the first extension table") ;
2190 cpl_propertylist_delete(ext_head) ;
2191 cpl_propertylist_delete(pro_list) ;
2192 cpl_free(to_remove) ;
2196 if (cpl_dfs_save_propertylist(allframes, NULL, parlist,
2197 inframes, NULL, recipe, pro_list, to_remove, PACKAGE
"/"
2198 PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2199 cpl_msg_error(__func__,
"Cannot save the empty HDU") ;
2200 cpl_propertylist_delete(ext_head) ;
2201 cpl_propertylist_delete(pro_list) ;
2202 cpl_free(to_remove) ;
2205 cpl_propertylist_save(ext_head, filename, CPL_IO_EXTEND) ;
2207 cpl_free(to_remove) ;
2208 cpl_propertylist_delete(ext_head) ;
2209 cpl_propertylist_delete(pro_list) ;
2212 for (i=1 ; i<CR2RES_NB_DETECTORS ; i++) {
2214 if (ext_plist[i] == NULL) {
2215 ext_head = cpl_propertylist_new() ;
2217 ext_head = cpl_propertylist_duplicate(ext_plist[i]);
2218 cpl_propertylist_erase(ext_head,
"EXTNAME");
2219 cpl_propertylist_erase(ext_head,
"BUNIT");
2222 cpl_propertylist_update_string(ext_head,
"EXTNAME", wished_extname) ;
2223 cpl_free(wished_extname) ;
2224 cr2res_qc_dup_chip_idx(ext_head);
2226 if (tab[i] != NULL) {
2227 cpl_table_save(tab[i], NULL, ext_head, filename, CPL_IO_EXTEND) ;
2229 cpl_propertylist_save(ext_head, filename, CPL_IO_EXTEND) ;
2231 cpl_propertylist_delete(ext_head) ;
2253static int cr2res_io_save_one_table(
2254 const char * filename,
2255 cpl_frameset * allframes,
2256 cpl_frameset * inframes,
2257 const cpl_parameterlist * parlist,
2259 const cpl_propertylist * qc_list,
2260 cpl_propertylist * ext_plist,
2261 const char * extname,
2262 const char * recipe,
2263 const char * procatg,
2264 const char * drstype)
2266 cpl_propertylist * pro_list ;
2267 cpl_propertylist * ext_head ;
2270 if (allframes == NULL || filename == NULL || ext_plist == NULL ||
2271 extname == NULL)
return -1 ;
2274 if (qc_list != NULL) pro_list = cpl_propertylist_duplicate(qc_list) ;
2275 else pro_list = cpl_propertylist_new() ;
2278 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procatg) ;
2279 cpl_propertylist_append_string(pro_list, CR2RES_HEADER_DRS_TYPE, drstype) ;
2282 ext_head = cpl_propertylist_duplicate(ext_plist);
2283 cpl_propertylist_erase(ext_head,
"EXTNAME");
2284 cpl_propertylist_update_string(ext_head,
"EXTNAME", extname) ;
2287 if (cpl_dfs_save_table(allframes, NULL, parlist, inframes, NULL,
2288 tab, ext_head, recipe, pro_list, NULL,
2289 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2290 cpl_msg_error(__func__,
"Cannot save the first extension table") ;
2291 cpl_propertylist_delete(ext_head) ;
2292 cpl_propertylist_delete(pro_list) ;
2295 cpl_propertylist_delete(ext_head) ;
2296 cpl_propertylist_delete(pro_list) ;
2318static int cr2res_io_save_image(
2319 const char * filename,
2320 cpl_frameset * allframes,
2321 cpl_frameset * inframes,
2322 const cpl_parameterlist * parlist,
2324 const cpl_propertylist * qc_list,
2325 cpl_propertylist ** ext_plist,
2327 const char * recipe,
2328 const char * procatg,
2329 const char * drstype)
2331 cpl_propertylist * qclist_loc ;
2332 cpl_image * to_save ;
2337 if (qc_list == NULL) {
2338 qclist_loc = cpl_propertylist_new();
2340 qclist_loc = cpl_propertylist_duplicate(qc_list) ;
2342 cpl_propertylist_update_string(qclist_loc, CPL_DFS_PRO_CATG, procatg);
2343 cpl_propertylist_update_string(qclist_loc, CR2RES_HEADER_DRS_TYPE, drstype);
2345 cr2res_qc_dup_mtrlgy_key(inframes, qclist_loc);
2348 to_remove = cpl_sprintf(
"NODPOS") ;
2351 if (cpl_dfs_save_propertylist(allframes, NULL, parlist, inframes, NULL,
2352 recipe, qclist_loc, to_remove,
2353 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2354 cpl_msg_error(__func__,
"Cannot save the empty primary HDU") ;
2355 cpl_propertylist_delete(qclist_loc) ;
2356 cpl_free(to_remove) ;
2359 cpl_free(to_remove) ;
2362 cpl_propertylist_delete(qclist_loc) ;
2365 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
2366 char * wished_extname ;
2367 if (ext_plist[det_nr-1] == NULL) {
2368 qclist_loc = cpl_propertylist_new();
2370 qclist_loc = cpl_propertylist_duplicate(ext_plist[det_nr-1]) ;
2371 cpl_propertylist_erase(qclist_loc,
"EXTNAME");
2376 cpl_propertylist_prepend_string(qclist_loc,
"EXTNAME", wished_extname) ;
2378 cr2res_qc_dup_chip_idx(qclist_loc);
2380 if (data[det_nr-1] == NULL)
2386 if (to_save != NULL) cr2res_io_set_bpm_as_NaNs(to_save) ;
2389 cpl_image_save(to_save, filename, type, qclist_loc, CPL_IO_EXTEND) ;
2390 cpl_free(wished_extname) ;
2393 if (strcmp(drstype, CR2RES_BPM_DRSTYPE)) {
2395 cpl_propertylist_update_string(qclist_loc,
"EXTNAME",
2397 if (data[det_nr-1] == NULL)
2401 cpl_image_save(to_save, filename, type, qclist_loc, CPL_IO_EXTEND) ;
2402 cpl_free(wished_extname) ;
2404 cpl_propertylist_delete(qclist_loc) ;
2427static int cr2res_io_save_imagelist(
2428 const char * filename,
2429 cpl_frameset * allframes,
2430 cpl_frameset * inframes,
2431 const cpl_parameterlist * parlist,
2432 hdrl_imagelist ** data,
2433 const cpl_propertylist * qc_list,
2434 cpl_propertylist ** ext_plist,
2436 const char * recipe,
2437 const char * procatg,
2438 const char * drstype)
2440 cpl_propertylist * qclist_loc ;
2441 cpl_imagelist * list_data ;
2442 cpl_imagelist * list_noise ;
2447 if (qc_list == NULL) {
2448 qclist_loc = cpl_propertylist_new();
2450 qclist_loc = cpl_propertylist_duplicate(qc_list) ;
2452 cpl_propertylist_update_string(qclist_loc, CPL_DFS_PRO_CATG, procatg);
2453 cpl_propertylist_update_string(qclist_loc, CR2RES_HEADER_DRS_TYPE, drstype);
2455 cr2res_qc_dup_mtrlgy_key(inframes, qclist_loc);
2458 if (cpl_dfs_save_propertylist(allframes, NULL, parlist, inframes, NULL,
2459 recipe, qclist_loc, NULL,
2460 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2461 cpl_msg_error(__func__,
"Cannot save the empty primary HDU") ;
2462 cpl_propertylist_delete(qclist_loc) ;
2466 cpl_propertylist_delete(qclist_loc) ;
2469 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
2470 char * wished_extname ;
2473 if (data[det_nr-1] == NULL) {
2474 list_data = list_noise = NULL ;
2476 list_data = cr2res_hdrl_to_cpl_list(data[det_nr-1], 1) ;
2477 list_noise = cr2res_hdrl_to_cpl_list(data[det_nr-1], 0) ;
2481 if (list_data != NULL)
2482 for (i=0 ; i<cpl_imagelist_get_size(list_data) ; i++)
2483 cr2res_io_set_bpm_as_NaNs(cpl_imagelist_get(list_data, i)) ;
2486 if (ext_plist[det_nr-1] == NULL) {
2487 qclist_loc = cpl_propertylist_new();
2489 qclist_loc = cpl_propertylist_duplicate(ext_plist[det_nr-1]) ;
2490 cpl_propertylist_erase(qclist_loc,
"EXTNAME");
2495 cpl_propertylist_prepend_string(qclist_loc,
"EXTNAME", wished_extname) ;
2496 cr2res_qc_dup_chip_idx(qclist_loc);
2497 if (list_data == NULL) {
2498 cpl_propertylist_save(qclist_loc, filename, CPL_IO_EXTEND) ;
2500 cpl_imagelist_save(list_data, filename, type, qclist_loc,
2502 cpl_imagelist_delete(list_data) ;
2504 cpl_free(wished_extname) ;
2508 cpl_propertylist_update_string(qclist_loc,
"EXTNAME", wished_extname) ;
2509 if (list_noise == NULL) {
2510 cpl_propertylist_save(qclist_loc, filename, CPL_IO_EXTEND) ;
2512 cpl_imagelist_save(list_noise, filename, type, qclist_loc,
2514 cpl_imagelist_delete(list_noise) ;
2516 cpl_propertylist_delete(qclist_loc) ;
2517 cpl_free(wished_extname) ;
2531static cpl_imagelist * cr2res_hdrl_to_cpl_list(
2532 const hdrl_imagelist * in,
2535 cpl_imagelist * out ;
2536 const cpl_image * cur_cpl_im ;
2540 if (in == NULL)
return NULL ;
2541 if (data != 0 && data != 1)
return NULL ;
2544 out = cpl_imagelist_new() ;
2546 const hdrl_image * cur_im ;
2551 cpl_imagelist_set(out, cpl_image_duplicate(cur_cpl_im),
2552 cpl_imagelist_get_size(out)) ;
2557 cpl_imagelist_delete(out) ;
2564static int cr2res_io_check_drs_type(
2565 const char * filename,
2566 const char * expected_drstype)
2568 cpl_propertylist * plist ;
2569 const char * drstype ;
2572 if (filename == NULL)
return -1 ;
2575 plist = cpl_propertylist_load(filename, 0) ;
2576 if (plist == NULL)
return -1;
2578 if (cpl_error_get_code()) {
2580 const char * protype ;
2590 if (cpl_error_get_code()) {
2592 cpl_propertylist_delete(plist) ;
2595 if (strcmp(protype, expected_drstype)) {
2596 cpl_msg_error(__func__,
"Unexpected PRO.TYPE (old data): %s != %s",
2597 protype, expected_drstype) ;
2598 cpl_propertylist_delete(plist) ;
2602 if (strcmp(drstype, expected_drstype)) {
2603 cpl_msg_error(__func__,
"Unexpected DRS.TYPE: %s != %s",
2604 drstype, expected_drstype) ;
2605 cpl_propertylist_delete(plist) ;
2609 cpl_propertylist_delete(plist) ;
int cr2res_io_save_EMISSION_LINES(const char *filename, cpl_table *out_table, const cpl_parameterlist *parlist, cpl_frameset *set, const char *recipe, const char *setting_string)
Save EMISSION_LINES file.
cpl_table * cr2res_io_load_EXTRACT_1D(const char *filename, int detector)
Load a table from a EXTRACT_1D.
cpl_frame * cr2res_io_find_SLIT_MODEL(const cpl_frameset *in, const char *setting_id, cr2res_decker decker)
Get the first CR2RES_SLIT_MODEL_DRSTYPE frame from a frameset.
const cpl_frame * cr2res_io_find_BPM(const cpl_frameset *in)
Get the first CR2RES_BPM_DRSTYPE frame from a frameset.
int cr2res_io_save_SLIT_MODEL(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a SLIT_MODEL.
const cpl_frame * cr2res_io_find_SLIT_FUNC(const cpl_frameset *in)
Get the first CR2RES_SLIT_FUNC_DRSTYPE frame from a frameset.
const cpl_frame * cr2res_io_find_TRACE_WAVE(const cpl_frameset *in)
Get the first CR2RES_TW_DRSTYPE frame from a frameset.
int cr2res_io_save_PHOTO_FLUX(const char *filename, cpl_table *out_table, const cpl_parameterlist *parlist, cpl_frameset *set, const char *recipe)
Save PHOTO_FLUX file.
char * cr2res_io_create_extname(int detector, int data)
Create Extname.
int cr2res_io_save_WAVE_MAP(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a WAVE_MAP.
int cr2res_io_convert_order_idx_to_idxp(int order_idx)
Convert the order_idx to the order_idxp.
int cr2res_io_save_TRACE_WAVE(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **tables, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a TRACE_WAVE.
int cr2res_io_save_SPLICED_1D(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table *spliced_1d, const cpl_propertylist *qc_list, cpl_propertylist *ext_plist, const char *procatg, const char *recipe)
Save a SPLICED_1D.
cpl_frameset * cr2res_io_extract_decker_frameset(const cpl_frameset *in, const char *tag, cr2res_decker decker)
Extract the frames with the given tag and Decker position.
int cr2res_io_save_EXTRACT_2D(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **tables, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a 2D extracted spectrum.
cpl_vector * cr2res_io_read_dits(const cpl_frameset *in)
Get the DITS from a frame set.
int cr2res_io_save_EXTRACT_1D(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **tables, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a 1D extracted spectrum.
cpl_table * cr2res_load_table(const char *in, int det_nr, int pmin, int pmax)
Load the table accordingly.
hdrl_image * cr2res_io_load_SLIT_MODEL(const char *filename, int detector)
Load an hdrl image from a SLIT MODEL.
cpl_frameset * cr2res_io_find_TRACE_WAVE_all(const cpl_frameset *in)
Get the CR2RES_TW_DRSTYPE frames from a frameset.
hdrl_imagelist * cr2res_io_load_image_list_from_set(const cpl_frameset *in, int detector)
Load an hdrl image list from an images frameset.
hdrl_imagelist * cr2res_io_load_DETLIN_COEFFS(const char *filename, int detector)
Load the detlin coefficients.
hdrl_image * cr2res_io_load_MASTER_DARK(const char *filename, int detector)
Load an image from a MASTER_DARK.
cpl_table * cr2res_io_get_eop_table()
Get the eop_table.
int cr2res_io_save_MASTER_FLAT(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **master_flats, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a MASTER_FLAT.
int cr2res_io_save_MASTER_DARK(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **master_darks, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a MASTER_DARK.
cpl_frameset * cr2res_io_find_BPM_all(const cpl_frameset *in)
Get the CR2RES_BPM_DRSTYPE frames from a frameset.
int cr2res_io_save_DETLIN_COEFFS(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_imagelist **coeffs, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a DETLIN COEFFS.
int cr2res_io_save_THROUGHPUT(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **tables, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a THROUGHPUT table.
int cr2res_io_get_ext_idx(const char *filename, int detector, int data)
Get the wished extension number for a detector.
int cr2res_io_save_TRACE_MAP(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a TRACE_MAP.
cpl_table * cr2res_io_load_SLIT_FUNC(const char *filename, int detector)
Load a table from a SLIT_FUNC.
int cr2res_io_save_SLIT_CURV_MAP(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a SLIT_CURV_MAP.
hdrl_image * cr2res_io_load_image(const char *in, int detector)
Load an hdrl image from a image file.
int cr2res_io_save_CALIBRATED(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **calib_collapsed, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a CALIBRATED frame.
int cr2res_io_save_SLIT_FUNC(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **slit_func, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a SLIT_FUNC.
int cr2res_io_save_BPM(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_image **bpms, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a BPM.
cpl_frameset * cr2res_io_find_EXTRACT_1D_all(const cpl_frameset *in)
Get the CR2RES_EXTRACT_1D_DRSTYPE frames from a frameset.
int cr2res_io_save_COMBINED(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a COMBINED.
cr2res_decker * cr2res_io_read_decker_positions(const cpl_frameset *in)
Get the decker positions from a frame set.
cpl_bivector * cr2res_io_load_EMISSION_LINES(const char *filename)
Load an EMISSION_LINES bivector.
cpl_table * cr2res_io_load_TRACE_WAVE(const char *filename, int detector)
Load a table from a TRACE_WAVE.
int cr2res_io_save_LINES_DIAGNOSTICS(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **tables, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a LINES_DIAGNOSTICS.
cpl_image * cr2res_io_load_BPM(const char *filename, int detector, int data)
Load an image from a BPM.
cpl_vector * cr2res_io_read_ndits(const cpl_frameset *in)
Get the NDITs from a frame set.
hdrl_imagelist * cr2res_io_load_image_list(const char *in, int detector)
Load an hdrl image list from a cube file.
int cr2res_io_save_POL_SPEC(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **tables, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a Polarimetry spectrum.
hdrl_image * cr2res_io_load_MASTER_FLAT(const char *filename, int detector)
Load an hdrl image from a MASTER_FLAT.
cr2res_decker cr2res_pfits_get_decker_position(const cpl_propertylist *plist)
find out the decker position
const char * cr2res_pfits_get_wlen_id(const cpl_propertylist *plist)
find out the Setting
const char * cr2res_pfits_get_protype(const cpl_propertylist *plist)
find out the PRO.TYPE
double cr2res_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
int cr2res_pfits_get_ndit(const cpl_propertylist *plist)
find out the NDIT value
const char * cr2res_pfits_get_drstype(const cpl_propertylist *plist)
find out the DRS.TYPE
double cr2res_mjd_obs_now(void)
Get the current MJD-OBS.
int cr2res_format_setting(char *setting_id)
Format the setting.
cpl_frameset * cr2res_extract_frameset_several_tags(const cpl_frameset *in, const char **tags, int ntags)
Extract the frames whose tag is within a list from a frameset.
cpl_error_code hdrl_image_reject_value(hdrl_image *self, cpl_value mode)
Reject pixels with the specified special value(s)
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
const cpl_image * hdrl_image_get_error_const(const hdrl_image *himg)
get error as cpl image
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
hdrl_imagelist * hdrl_imagelist_create(cpl_imagelist *imlist, cpl_imagelist *errlist)
Create an hdrl_imagelist out of 2 cpl_imagelist.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.