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) ;
494 cpl_vector * ndsamples ;
498 if (in == NULL)
return NULL ;
501 ndsamples = cpl_vector_new(cpl_frameset_get_size(in)) ;
504 for (i=0 ; i< cpl_vector_get_size(ndsamples) ; i++) {
505 cpl_propertylist * plist ;
506 plist = cpl_propertylist_load(cpl_frame_get_filename(
507 cpl_frameset_get_position_const(in, i)), 0) ;
509 cpl_propertylist_delete(plist) ;
523 cr2res_decker * out ;
524 cpl_size nframes, i ;
527 if (in == NULL)
return NULL ;
530 nframes = cpl_frameset_get_size(in) ;
533 out = cpl_malloc(nframes *
sizeof(cr2res_decker)) ;
536 for (i = 0; i < nframes; i++) {
537 cpl_propertylist *plist;
538 plist = cpl_propertylist_load(cpl_frame_get_filename(
539 cpl_frameset_get_position_const(in, i)), 0) ;
541 cpl_propertylist_delete(plist) ;
558 const cpl_frameset * in,
560 cr2res_decker decker)
563 cpl_frame * loc_frame ;
565 cpl_propertylist * plist ;
569 if (in == NULL)
return NULL ;
570 if (tag == NULL)
return NULL ;
571 if (decker != CR2RES_DECKER_NONE && decker != CR2RES_DECKER_1_3 &&
572 decker != CR2RES_DECKER_2_4)
576 nbframes = cpl_frameset_get_size(in) ;
579 if ((cpl_frameset_count_tags(in, tag)) == 0)
return NULL ;
582 out = cpl_frameset_new() ;
585 for (i=0 ; i<nbframes ; i++) {
586 const cpl_frame * cur_frame ;
587 cur_frame = cpl_frameset_get_position_const(in, i) ;
588 if (!strcmp(cpl_frame_get_tag(cur_frame), tag)) {
590 plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
592 loc_frame = cpl_frame_duplicate(cur_frame) ;
593 cpl_frameset_insert(out, loc_frame) ;
595 cpl_propertylist_delete(plist) ;
599 if (cpl_frameset_get_size(out) == 0){
600 cpl_frameset_delete(out) ;
616 if (order_idx < -49 || order_idx > 50)
return -1 ;
619 if (order_idx < 0)
return order_idx + 100 ;
620 else return order_idx ;
630int cr2res_io_convert_order_idxp_to_idx(
int order_idxp)
633 if (order_idxp < 0 || order_idxp > 99)
return -1 ;
636 if (order_idxp > 50)
return order_idxp - 100 ;
637 else return order_idxp ;
652 char * wished_extname ;
655 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
659 if (data) wished_extname = cpl_sprintf(
"CHIP%d.INT1", detector) ;
660 else wished_extname = cpl_sprintf(
"CHIP%dERR.INT1", detector) ;
662 return wished_extname ;
675 const char * filename,
679 char * wished_extname ;
680 int wished_ext_nb = -1 ;
684 if (filename == NULL)
return -1 ;
685 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return -1 ;
691 nb_ext = cpl_fits_count_extensions(filename) ;
694 for (i=1 ; i<=nb_ext ; i++) {
695 const char * extname ;
696 cpl_propertylist * pl ;
698 pl = cpl_propertylist_load(filename, i) ;
700 extname = cpl_propertylist_get_string(pl,
"EXTNAME");
703 if (strcmp(extname, wished_extname)==0) wished_ext_nb = i ;
704 cpl_propertylist_delete(pl) ;
706 cpl_free(wished_extname) ;
709 if (wished_ext_nb < 0) {
712 cpl_msg_warning(__func__,
713 "EXTNAME is supposed to match CHIPn.INT1 or CHIPnERR.INT1 (n=1/2/3)") ;
716 return wished_ext_nb ;
741 int ext_nr_data, ext_nr_err ;
744 if (in == NULL)
return NULL ;
745 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
752 if (ext_nr_data < 0)
return NULL ;
755 data = cpl_image_load(in, CPL_TYPE_DOUBLE, 0, ext_nr_data) ;
757 err = cpl_image_load(in, CPL_TYPE_DOUBLE, 0, ext_nr_err) ;
762 cr2res_io_set_NaNs_as_bpm(data) ;
768 if (data != NULL) cpl_image_delete(data) ;
769 if (err != NULL) cpl_image_delete(err) ;
788 hdrl_imagelist * out ;
789 cpl_imagelist * data ;
790 cpl_imagelist * error ;
792 int wished_ext_nb_data, wished_ext_nb_error ;
795 if (in == NULL)
return NULL ;
796 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
803 if (wished_ext_nb_data < 0)
return NULL ;
806 data = cpl_imagelist_load(in, CPL_TYPE_DOUBLE, wished_ext_nb_data);
807 if (wished_ext_nb_error >= 0)
808 error = cpl_imagelist_load(in, CPL_TYPE_DOUBLE, wished_ext_nb_error);
813 for (i=0 ; i<cpl_imagelist_get_size(data) ; i++)
814 cr2res_io_set_NaNs_as_bpm(cpl_imagelist_get(data, i)) ;
820 if (data != NULL) cpl_imagelist_delete(data) ;
821 if (error != NULL) cpl_imagelist_delete(error) ;
839 const cpl_frameset * in,
842 const char * first_file ;
843 hdrl_imagelist * out ;
844 cpl_imagelist * data ;
845 cpl_imagelist * err ;
847 int ext_nr_data, ext_nr_err ;
850 if (in == NULL)
return NULL ;
851 if (cpl_frameset_get_size(in) < 1)
return NULL ;
852 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
855 first_file = cpl_frame_get_filename(cpl_frameset_get_position_const(in,0)) ;
860 if (ext_nr_data < 0)
return NULL ;
863 data = cpl_imagelist_load_frameset(in, CPL_TYPE_DOUBLE, 1, ext_nr_data) ;
865 err = cpl_imagelist_load_frameset(in, CPL_TYPE_DOUBLE, 1, ext_nr_err) ;
870 for (i=0 ; i<cpl_imagelist_get_size(data) ; i++)
871 cr2res_io_set_NaNs_as_bpm(cpl_imagelist_get(data, i)) ;
877 if (data != NULL) cpl_imagelist_delete(data) ;
878 if (err != NULL) cpl_imagelist_delete(err) ;
899 cpl_table * out_tmp ;
903 if (in == NULL)
return NULL ;
904 if (det_nr < 1 || det_nr > CR2RES_NB_DETECTORS)
return NULL ;
910 if ((out = cpl_table_load(in, det_nr, 0)) == NULL) {
911 cpl_msg_error(__func__,
"Cannot load %s as a table", in) ;
916 if (pmin>0 && pmax>0 && pmax >= pmin && pmax <= cpl_table_get_nrow(out)) {
917 out_tmp = cpl_table_extract(out, pmin, pmax-pmin+1) ;
918 if (out_tmp != NULL) {
919 cpl_table_delete(out) ;
934 const char * filename)
936 cpl_bivector * lines ;
939 cpl_table * lines_tab ;
943 if (filename == NULL)
return NULL ;
946 if (cr2res_io_check_drs_type(filename, CR2RES_DRSTYPE_CATALOG) != 1) {
947 cpl_msg_info(__func__,
"File check failed for %s", filename);
955 lines_tab = cpl_table_load(filename, 1, 1) ;
956 tab_size = cpl_table_get_nrow(lines_tab) ;
959 lines = cpl_bivector_new(tab_size) ;
960 lines_x = cpl_bivector_get_x_data(lines) ;
961 lines_y = cpl_bivector_get_y_data(lines) ;
962 for (i=0 ; i<tab_size ; i++) {
965 lines_x[i] = cpl_table_get(lines_tab, CR2RES_COL_WAVELENGTH, i, NULL) ;
966 val = cpl_table_get(lines_tab, CR2RES_COL_EMISSION, i, NULL) ;
973 cpl_table_delete(lines_tab) ;
988 const char * filename,
995 if (filename == NULL)
return NULL ;
996 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
999 if (cr2res_io_check_drs_type(filename, CR2RES_BPM_DRSTYPE) != 1)
1006 if (wished_ext_nb < 0)
return NULL ;
1008 return cpl_image_load(filename, CPL_TYPE_INT, 0, wished_ext_nb);
1021 const char * filename,
1024 hdrl_image * master_dark ;
1027 if (filename == NULL)
return NULL ;
1028 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1031 if (cr2res_io_check_drs_type(filename, CR2RES_MASTER_DARK_DRSTYPE) != 1)
1045 cpl_msg_error(__func__,
"The error is missing") ;
1051 return master_dark ;
1065 const char * filename,
1068 hdrl_imagelist * detlin_coeffs ;
1071 if (filename == NULL)
return NULL ;
1072 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1075 if (cr2res_io_check_drs_type(filename, CR2RES_DETLIN_COEFFS_DRSTYPE) != 1)
1084 return detlin_coeffs ;
1097 const char * filename,
1100 hdrl_image * master_flat ;
1103 if (filename == NULL)
return NULL ;
1104 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1107 if (cr2res_io_check_drs_type(filename, CR2RES_MASTER_FLAT_DRSTYPE) != 1)
1121 cpl_msg_error(__func__,
"The error is missing") ;
1127 return master_flat ;
1140 const char * filename,
1143 cpl_table * trace_wave_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_TW_DRSTYPE) != 1)
1157 return trace_wave_tab ;
1170 const char * filename,
1173 cpl_table * slit_func_tab ;
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_FUNC_DRSTYPE) != 1)
1187 return slit_func_tab ;
1200 const char * filename,
1203 hdrl_image * slit_model ;
1206 if (filename == NULL)
return NULL ;
1207 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1210 if (cr2res_io_check_drs_type(filename, CR2RES_SLIT_MODEL_DRSTYPE) != 1)
1218 cpl_msg_error(__func__,
"The error is missing") ;
1236hdrl_image * cr2res_io_load_TRACE_MAP(
1237 const char * filename,
1240 hdrl_image * trace_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_TRACE_MAP_DRSTYPE) != 1)
1266hdrl_image * cr2res_io_load_WAVE_MAP(
1267 const char * filename,
1270 hdrl_image * wave_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_WAVE_MAP_DRSTYPE) != 1)
1296hdrl_image * cr2res_io_load_SLIT_CURV_MAP(
1297 const char * filename,
1300 hdrl_image * slit_curv_map ;
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_SLIT_CURV_MAP_DRSTYPE) != 1)
1314 return slit_curv_map ;
1327 const char * filename,
1330 cpl_table * extract_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_EXTRACT_1D_DRSTYPE) != 1)
1344 return extract_1D_tab ;
1356cpl_table * cr2res_io_load_SPLICED_1D(
1357 const char * filename,
1360 cpl_table * spliced_1D_tab ;
1363 if (filename == NULL)
return NULL ;
1364 if (detector < 1 || detector > CR2RES_NB_DETECTORS)
return NULL ;
1367 if (cr2res_io_check_drs_type(filename, CR2RES_SPLICED_1D_DRSTYPE) != 1)
1374 return spliced_1D_tab ;
1386cpl_table * cr2res_io_load_EXTRACT_2D(
1387 const char * filename,
1390 cpl_table * extract_2D_tab ;
1393 if (cr2res_io_check_drs_type(filename, CR2RES_EXTRACT_2D_DRSTYPE) != 1)
1400 return extract_2D_tab ;
1420 const char * filename,
1421 cpl_table * out_table,
1422 const cpl_parameterlist * parlist,
1424 const char * recipe)
1426 cpl_propertylist * plist ;
1429 plist = cpl_propertylist_new();
1430 cpl_propertylist_append_string(plist, CR2RES_HEADER_INSTRUMENT,
"CRIRES") ;
1431 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
1432 CR2RES_PHOTO_FLUX_PROCATG) ;
1433 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
"STATIC") ;
1434 cpl_propertylist_append_string(plist, CR2RES_HEADER_DRS_TYPE,
1435 CR2RES_PHOTO_FLUX_DRSTYPE) ;
1437 cpl_propertylist_append_double(plist, CR2RES_HEADER_MJD_OBS, mjd_obs) ;
1440 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
1441 NULL, recipe, plist, NULL,
1442 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
1443 cpl_msg_error(__func__,
"Cannot save the table") ;
1444 cpl_propertylist_delete(plist) ;
1447 cpl_propertylist_delete(plist) ;
1466 const char * filename,
1467 cpl_table * out_table,
1468 const cpl_parameterlist * parlist,
1470 const char * recipe,
1471 const char * setting_string)
1473 cpl_propertylist * plist ;
1476 plist = cpl_propertylist_new();
1477 cpl_propertylist_append_string(plist, CR2RES_HEADER_INSTRUMENT,
"CRIRES") ;
1478 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
1479 CR2RES_EMISSION_LINES_PROCATG) ;
1480 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
"STATIC") ;
1481 cpl_propertylist_append_string(plist, CR2RES_HEADER_DRS_TYPE,
1482 CR2RES_DRSTYPE_CATALOG) ;
1485 cpl_propertylist_append_double(plist, CR2RES_HEADER_MJD_OBS, mjd_obs) ;
1487 if (setting_string != NULL) {
1488 cpl_propertylist_append_string(plist, CR2RES_HEADER_WLEN_ID,
1492 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
1493 NULL, recipe, plist, NULL,
1494 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
1495 cpl_msg_error(__func__,
"Cannot save the table") ;
1496 cpl_propertylist_delete(plist) ;
1499 cpl_propertylist_delete(plist) ;
1522 const char * filename,
1523 cpl_frameset * allframes,
1524 cpl_frameset * inframes,
1525 const cpl_parameterlist * parlist,
1526 hdrl_image ** master_darks,
1527 const cpl_propertylist * qc_list,
1528 cpl_propertylist ** ext_plist,
1529 const char * procatg,
1530 const char * recipe)
1532 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1533 master_darks, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1534 procatg, CR2RES_MASTER_DARK_DRSTYPE) ;
1554 const char * filename,
1555 cpl_frameset * allframes,
1556 cpl_frameset * inframes,
1557 const cpl_parameterlist * parlist,
1558 hdrl_imagelist ** coeffs,
1559 const cpl_propertylist * qc_list,
1560 cpl_propertylist ** ext_plist,
1561 const char * procatg,
1562 const char * recipe)
1564 return cr2res_io_save_imagelist(filename, allframes, inframes, parlist,
1565 coeffs, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1566 procatg, CR2RES_DETLIN_COEFFS_DRSTYPE) ;
1586 const char * filename,
1587 cpl_frameset * allframes,
1588 cpl_frameset * inframes,
1589 const cpl_parameterlist * parlist,
1591 const cpl_propertylist * qc_list,
1592 cpl_propertylist ** ext_plist,
1593 const char * procatg,
1594 const char * recipe)
1596 hdrl_image * hdrl_bpms[CR2RES_NB_DETECTORS] ;
1598 cpl_image * bpm_tmp;
1601 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
1602 if (bpms[det_nr-1] == NULL){
1603 hdrl_bpms[det_nr-1] = NULL ;
1605 bpm_tmp = cr2res_bpm_mask_edgepix(bpms[det_nr-1]);
1607 cpl_image_delete(bpm_tmp);
1612 ret = cr2res_io_save_image(filename, allframes, inframes, parlist,
1613 hdrl_bpms, qc_list, ext_plist, CPL_TYPE_INT, recipe,
1614 procatg, CR2RES_BPM_DRSTYPE) ;
1617 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
1639 const char * filename,
1640 cpl_frameset * allframes,
1641 cpl_frameset * inframes,
1642 const cpl_parameterlist * parlist,
1643 hdrl_image ** calib_collapsed,
1644 const cpl_propertylist * qc_list,
1645 cpl_propertylist ** ext_plist,
1646 const char * procatg,
1647 const char * recipe)
1649 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1650 calib_collapsed, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1651 procatg, CR2RES_CALIBRATED_DRSTYPE) ;
1670 const char * filename,
1671 cpl_frameset * allframes,
1672 cpl_frameset * inframes,
1673 const cpl_parameterlist * parlist,
1674 hdrl_image ** master_flats,
1675 const cpl_propertylist * qc_list,
1676 cpl_propertylist ** ext_plist,
1677 const char * procatg,
1678 const char * recipe)
1680 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1681 master_flats, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1682 procatg, CR2RES_MASTER_FLAT_DRSTYPE) ;
1701 const char * filename,
1702 cpl_frameset * allframes,
1703 cpl_frameset * inframes,
1704 const cpl_parameterlist * parlist,
1705 cpl_table ** tables,
1706 const cpl_propertylist * qc_list,
1707 cpl_propertylist ** ext_plist,
1708 const char * procatg,
1709 const char * recipe)
1712 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
1713 qc_list, ext_plist, recipe, procatg, CR2RES_TW_DRSTYPE) ;
1732 const char * filename,
1733 cpl_frameset * allframes,
1734 cpl_frameset * inframes,
1735 const cpl_parameterlist * parlist,
1736 cpl_table ** tables,
1737 const cpl_propertylist * qc_list,
1738 cpl_propertylist ** ext_plist,
1739 const char * procatg,
1740 const char * recipe)
1742 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
1743 qc_list, ext_plist, recipe, procatg,
1744 CR2RES_LINES_DIAGNOSTICS_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_EXTRACT_1D_DRSTYPE) ;
1793 const char * filename,
1794 cpl_frameset * allframes,
1795 cpl_frameset * inframes,
1796 const cpl_parameterlist * parlist,
1797 cpl_table ** tables,
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, tables,
1804 qc_list, ext_plist, recipe, procatg, CR2RES_THROUGHPUT_DRSTYPE) ;
1823 const char * filename,
1824 cpl_frameset * allframes,
1825 cpl_frameset * inframes,
1826 const cpl_parameterlist * parlist,
1827 cpl_table ** slit_func,
1828 const cpl_propertylist * qc_list,
1829 cpl_propertylist ** ext_plist,
1830 const char * procatg,
1831 const char * recipe)
1833 return cr2res_io_save_table(filename, allframes, inframes, parlist,
1834 slit_func, qc_list, ext_plist, recipe, procatg,
1835 CR2RES_SLIT_FUNC_DRSTYPE) ;
1854 const char * filename,
1855 cpl_frameset * allframes,
1856 cpl_frameset * inframes,
1857 const cpl_parameterlist * parlist,
1859 const cpl_propertylist * qc_list,
1860 cpl_propertylist ** ext_plist,
1861 const char * procatg,
1862 const char * recipe)
1864 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1865 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe, procatg,
1866 CR2RES_SLIT_MODEL_DRSTYPE) ;
1885 const char * filename,
1886 cpl_frameset * allframes,
1887 cpl_frameset * inframes,
1888 const cpl_parameterlist * parlist,
1890 const cpl_propertylist * qc_list,
1891 cpl_propertylist ** ext_plist,
1892 const char * procatg,
1893 const char * recipe)
1895 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1896 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe, procatg,
1897 CR2RES_COMBINED_DRSTYPE) ;
1916 const char * filename,
1917 cpl_frameset * allframes,
1918 cpl_frameset * inframes,
1919 const cpl_parameterlist * parlist,
1921 const cpl_propertylist * qc_list,
1922 cpl_propertylist ** ext_plist,
1923 const char * procatg,
1924 const char * recipe)
1926 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1927 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1928 procatg, CR2RES_TRACE_MAP_DRSTYPE) ;
1947 const char * filename,
1948 cpl_frameset * allframes,
1949 cpl_frameset * inframes,
1950 const cpl_parameterlist * parlist,
1952 const cpl_propertylist * qc_list,
1953 cpl_propertylist ** ext_plist,
1954 const char * procatg,
1955 const char * recipe)
1957 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1958 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1959 procatg, CR2RES_WAVE_MAP_DRSTYPE) ;
1978 const char * filename,
1979 cpl_frameset * allframes,
1980 cpl_frameset * inframes,
1981 const cpl_parameterlist * parlist,
1983 const cpl_propertylist * qc_list,
1984 cpl_propertylist ** ext_plist,
1985 const char * procatg,
1986 const char * recipe)
1988 return cr2res_io_save_image(filename, allframes, inframes, parlist,
1989 data, qc_list, ext_plist, CPL_TYPE_DOUBLE, recipe,
1990 procatg, CR2RES_SLIT_CURV_MAP_DRSTYPE) ;
2009 const char * filename,
2010 cpl_frameset * allframes,
2011 cpl_frameset * inframes,
2012 const cpl_parameterlist * parlist,
2013 cpl_table * spliced_1d,
2014 const cpl_propertylist * qc_list,
2015 cpl_propertylist * ext_plist,
2016 const char * procatg,
2017 const char * recipe)
2019 return cr2res_io_save_one_table(filename, allframes, inframes, parlist,
2020 spliced_1d, qc_list, ext_plist,
"SPLICED", recipe, procatg,
2021 CR2RES_SPLICED_1D_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_EXTRACT_2D_DRSTYPE) ;
2070 const char * filename,
2071 cpl_frameset * allframes,
2072 cpl_frameset * inframes,
2073 const cpl_parameterlist * parlist,
2074 cpl_table ** tables,
2075 const cpl_propertylist * qc_list,
2076 cpl_propertylist ** ext_plist,
2077 const char * procatg,
2078 const char * recipe)
2080 return cr2res_io_save_table(filename, allframes, inframes, parlist, tables,
2081 qc_list, ext_plist, recipe, procatg, CR2RES_POL_SPEC_DRSTYPE) ;
2094static int cr2res_io_set_bpm_as_NaNs(
2097 cpl_size nx, ny, i, j ;
2101 if (in == NULL)
return -1 ;
2102 if (cpl_image_get_type(in) != CPL_TYPE_DOUBLE)
return 0 ;
2105 nx = cpl_image_get_size_x(in) ;
2106 ny = cpl_image_get_size_y(in) ;
2107 pdata = cpl_image_get_data_double(in) ;
2110 for (j=0 ; j<ny ; j++) {
2111 for (i=0 ; i<nx ; i++) {
2112 if (cpl_image_is_rejected(in, i+1, j+1)) pdata[i+j*nx] = NAN ;
2125static int cr2res_io_set_NaNs_as_bpm(
2128 cpl_size nx, ny, i, j ;
2132 if (in == NULL)
return -1 ;
2133 if (cpl_image_get_type(in) != CPL_TYPE_DOUBLE)
return 0 ;
2136 nx = cpl_image_get_size_x(in) ;
2137 ny = cpl_image_get_size_y(in) ;
2138 pdata = cpl_image_get_data_double(in) ;
2141 for (j=0 ; j<ny ; j++) {
2142 for (i=0 ; i<nx ; i++) {
2143 if (isnan(pdata[i+j*nx])) cpl_image_reject(in, i+1, j+1) ;
2165static int cr2res_io_save_table(
2166 const char * filename,
2167 cpl_frameset * allframes,
2168 cpl_frameset * inframes,
2169 const cpl_parameterlist * parlist,
2171 const cpl_propertylist * qc_list,
2172 cpl_propertylist ** ext_plist,
2173 const char * recipe,
2174 const char * procatg,
2175 const char * drstype)
2177 cpl_propertylist * pro_list ;
2178 cpl_propertylist * ext_head ;
2179 char * wished_extname ;
2184 if (allframes == NULL || filename == NULL || ext_plist == NULL)
return -1 ;
2187 if (qc_list != NULL) pro_list = cpl_propertylist_duplicate(qc_list) ;
2188 else pro_list = cpl_propertylist_new() ;
2191 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procatg) ;
2192 cpl_propertylist_append_string(pro_list, CR2RES_HEADER_DRS_TYPE, drstype) ;
2194 cr2res_qc_dup_mtrlgy_key(inframes, pro_list);
2197 if (ext_plist[0]==NULL) {
2198 ext_head = cpl_propertylist_new() ;
2200 ext_head = cpl_propertylist_duplicate(ext_plist[0]);
2201 cpl_propertylist_erase(ext_head,
"EXTNAME");
2202 if (cpl_propertylist_get_property(ext_head,
"BUNIT") != NULL)
2203 cpl_propertylist_erase(ext_head,
"BUNIT");
2206 cpl_propertylist_update_string(ext_head,
"EXTNAME", wished_extname) ;
2207 cpl_free(wished_extname) ;
2209 cr2res_qc_dup_chip_idx(ext_head);
2212 to_remove = cpl_sprintf(
"NODPOS") ;
2215 if (tab[0] != NULL) {
2216 if (cpl_dfs_save_table(allframes, NULL, parlist, inframes, NULL,
2217 tab[0], ext_head, recipe, pro_list, to_remove,
2218 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2219 cpl_msg_error(__func__,
"Cannot save the first extension table") ;
2220 cpl_propertylist_delete(ext_head) ;
2221 cpl_propertylist_delete(pro_list) ;
2222 cpl_free(to_remove) ;
2226 if (cpl_dfs_save_propertylist(allframes, NULL, parlist,
2227 inframes, NULL, recipe, pro_list, to_remove, PACKAGE
"/"
2228 PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2229 cpl_msg_error(__func__,
"Cannot save the empty HDU") ;
2230 cpl_propertylist_delete(ext_head) ;
2231 cpl_propertylist_delete(pro_list) ;
2232 cpl_free(to_remove) ;
2235 cpl_propertylist_save(ext_head, filename, CPL_IO_EXTEND) ;
2237 cpl_free(to_remove) ;
2238 cpl_propertylist_delete(ext_head) ;
2239 cpl_propertylist_delete(pro_list) ;
2242 for (i=1 ; i<CR2RES_NB_DETECTORS ; i++) {
2244 if (ext_plist[i] == NULL) {
2245 ext_head = cpl_propertylist_new() ;
2247 ext_head = cpl_propertylist_duplicate(ext_plist[i]);
2248 cpl_propertylist_erase(ext_head,
"EXTNAME");
2249 cpl_propertylist_erase(ext_head,
"BUNIT");
2252 cpl_propertylist_update_string(ext_head,
"EXTNAME", wished_extname) ;
2253 cpl_free(wished_extname) ;
2254 cr2res_qc_dup_chip_idx(ext_head);
2256 if (tab[i] != NULL) {
2257 cpl_table_save(tab[i], NULL, ext_head, filename, CPL_IO_EXTEND) ;
2259 cpl_propertylist_save(ext_head, filename, CPL_IO_EXTEND) ;
2261 cpl_propertylist_delete(ext_head) ;
2283static int cr2res_io_save_one_table(
2284 const char * filename,
2285 cpl_frameset * allframes,
2286 cpl_frameset * inframes,
2287 const cpl_parameterlist * parlist,
2289 const cpl_propertylist * qc_list,
2290 cpl_propertylist * ext_plist,
2291 const char * extname,
2292 const char * recipe,
2293 const char * procatg,
2294 const char * drstype)
2296 cpl_propertylist * pro_list ;
2297 cpl_propertylist * ext_head ;
2300 if (allframes == NULL || filename == NULL || ext_plist == NULL ||
2301 extname == NULL)
return -1 ;
2304 if (qc_list != NULL) pro_list = cpl_propertylist_duplicate(qc_list) ;
2305 else pro_list = cpl_propertylist_new() ;
2308 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procatg) ;
2309 cpl_propertylist_append_string(pro_list, CR2RES_HEADER_DRS_TYPE, drstype) ;
2312 ext_head = cpl_propertylist_duplicate(ext_plist);
2313 cpl_propertylist_erase(ext_head,
"EXTNAME");
2314 cpl_propertylist_update_string(ext_head,
"EXTNAME", extname) ;
2317 if (cpl_dfs_save_table(allframes, NULL, parlist, inframes, NULL,
2318 tab, ext_head, recipe, pro_list, NULL,
2319 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2320 cpl_msg_error(__func__,
"Cannot save the first extension table") ;
2321 cpl_propertylist_delete(ext_head) ;
2322 cpl_propertylist_delete(pro_list) ;
2325 cpl_propertylist_delete(ext_head) ;
2326 cpl_propertylist_delete(pro_list) ;
2348static int cr2res_io_save_image(
2349 const char * filename,
2350 cpl_frameset * allframes,
2351 cpl_frameset * inframes,
2352 const cpl_parameterlist * parlist,
2354 const cpl_propertylist * qc_list,
2355 cpl_propertylist ** ext_plist,
2357 const char * recipe,
2358 const char * procatg,
2359 const char * drstype)
2361 cpl_propertylist * qclist_loc ;
2362 cpl_image * to_save ;
2367 if (qc_list == NULL) {
2368 qclist_loc = cpl_propertylist_new();
2370 qclist_loc = cpl_propertylist_duplicate(qc_list) ;
2372 cpl_propertylist_update_string(qclist_loc, CPL_DFS_PRO_CATG, procatg);
2373 cpl_propertylist_update_string(qclist_loc, CR2RES_HEADER_DRS_TYPE, drstype);
2375 cr2res_qc_dup_mtrlgy_key(inframes, qclist_loc);
2378 to_remove = cpl_sprintf(
"NODPOS") ;
2381 if (cpl_dfs_save_propertylist(allframes, NULL, parlist, inframes, NULL,
2382 recipe, qclist_loc, to_remove,
2383 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2384 cpl_msg_error(__func__,
"Cannot save the empty primary HDU") ;
2385 cpl_propertylist_delete(qclist_loc) ;
2386 cpl_free(to_remove) ;
2389 cpl_free(to_remove) ;
2392 cpl_propertylist_delete(qclist_loc) ;
2395 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
2396 char * wished_extname ;
2397 if (ext_plist[det_nr-1] == NULL) {
2398 qclist_loc = cpl_propertylist_new();
2400 qclist_loc = cpl_propertylist_duplicate(ext_plist[det_nr-1]) ;
2401 cpl_propertylist_erase(qclist_loc,
"EXTNAME");
2406 cpl_propertylist_prepend_string(qclist_loc,
"EXTNAME", wished_extname) ;
2408 cr2res_qc_dup_chip_idx(qclist_loc);
2410 if (data[det_nr-1] == NULL)
2416 if (to_save != NULL) cr2res_io_set_bpm_as_NaNs(to_save) ;
2419 cpl_image_save(to_save, filename, type, qclist_loc, CPL_IO_EXTEND) ;
2420 cpl_free(wished_extname) ;
2423 if (strcmp(drstype, CR2RES_BPM_DRSTYPE)) {
2425 cpl_propertylist_update_string(qclist_loc,
"EXTNAME",
2427 if (data[det_nr-1] == NULL)
2431 cpl_image_save(to_save, filename, type, qclist_loc, CPL_IO_EXTEND) ;
2432 cpl_free(wished_extname) ;
2434 cpl_propertylist_delete(qclist_loc) ;
2457static int cr2res_io_save_imagelist(
2458 const char * filename,
2459 cpl_frameset * allframes,
2460 cpl_frameset * inframes,
2461 const cpl_parameterlist * parlist,
2462 hdrl_imagelist ** data,
2463 const cpl_propertylist * qc_list,
2464 cpl_propertylist ** ext_plist,
2466 const char * recipe,
2467 const char * procatg,
2468 const char * drstype)
2470 cpl_propertylist * qclist_loc ;
2471 cpl_imagelist * list_data ;
2472 cpl_imagelist * list_noise ;
2477 if (qc_list == NULL) {
2478 qclist_loc = cpl_propertylist_new();
2480 qclist_loc = cpl_propertylist_duplicate(qc_list) ;
2482 cpl_propertylist_update_string(qclist_loc, CPL_DFS_PRO_CATG, procatg);
2483 cpl_propertylist_update_string(qclist_loc, CR2RES_HEADER_DRS_TYPE, drstype);
2485 cr2res_qc_dup_mtrlgy_key(inframes, qclist_loc);
2488 if (cpl_dfs_save_propertylist(allframes, NULL, parlist, inframes, NULL,
2489 recipe, qclist_loc, NULL,
2490 PACKAGE
"/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
2491 cpl_msg_error(__func__,
"Cannot save the empty primary HDU") ;
2492 cpl_propertylist_delete(qclist_loc) ;
2496 cpl_propertylist_delete(qclist_loc) ;
2499 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
2500 char * wished_extname ;
2503 if (data[det_nr-1] == NULL) {
2504 list_data = list_noise = NULL ;
2506 list_data = cr2res_hdrl_to_cpl_list(data[det_nr-1], 1) ;
2507 list_noise = cr2res_hdrl_to_cpl_list(data[det_nr-1], 0) ;
2511 if (list_data != NULL)
2512 for (i=0 ; i<cpl_imagelist_get_size(list_data) ; i++)
2513 cr2res_io_set_bpm_as_NaNs(cpl_imagelist_get(list_data, i)) ;
2516 if (ext_plist[det_nr-1] == NULL) {
2517 qclist_loc = cpl_propertylist_new();
2519 qclist_loc = cpl_propertylist_duplicate(ext_plist[det_nr-1]) ;
2520 cpl_propertylist_erase(qclist_loc,
"EXTNAME");
2525 cpl_propertylist_prepend_string(qclist_loc,
"EXTNAME", wished_extname) ;
2526 cr2res_qc_dup_chip_idx(qclist_loc);
2527 if (list_data == NULL) {
2528 cpl_propertylist_save(qclist_loc, filename, CPL_IO_EXTEND) ;
2530 cpl_imagelist_save(list_data, filename, type, qclist_loc,
2532 cpl_imagelist_delete(list_data) ;
2534 cpl_free(wished_extname) ;
2538 cpl_propertylist_update_string(qclist_loc,
"EXTNAME", wished_extname) ;
2539 if (list_noise == NULL) {
2540 cpl_propertylist_save(qclist_loc, filename, CPL_IO_EXTEND) ;
2542 cpl_imagelist_save(list_noise, filename, type, qclist_loc,
2544 cpl_imagelist_delete(list_noise) ;
2546 cpl_propertylist_delete(qclist_loc) ;
2547 cpl_free(wished_extname) ;
2561static cpl_imagelist * cr2res_hdrl_to_cpl_list(
2562 const hdrl_imagelist * in,
2565 cpl_imagelist * out ;
2566 const cpl_image * cur_cpl_im ;
2570 if (in == NULL)
return NULL ;
2571 if (data != 0 && data != 1)
return NULL ;
2574 out = cpl_imagelist_new() ;
2576 const hdrl_image * cur_im ;
2581 cpl_imagelist_set(out, cpl_image_duplicate(cur_cpl_im),
2582 cpl_imagelist_get_size(out)) ;
2587 cpl_imagelist_delete(out) ;
2594static int cr2res_io_check_drs_type(
2595 const char * filename,
2596 const char * expected_drstype)
2598 cpl_propertylist * plist ;
2599 const char * drstype ;
2602 if (filename == NULL)
return -1 ;
2605 plist = cpl_propertylist_load(filename, 0) ;
2606 if (plist == NULL)
return -1;
2608 if (cpl_error_get_code()) {
2610 const char * protype ;
2620 if (cpl_error_get_code()) {
2622 cpl_propertylist_delete(plist) ;
2625 if (strcmp(protype, expected_drstype)) {
2626 cpl_msg_error(__func__,
"Unexpected PRO.TYPE (old data): %s != %s",
2627 protype, expected_drstype) ;
2628 cpl_propertylist_delete(plist) ;
2632 if (strcmp(drstype, expected_drstype)) {
2633 cpl_msg_error(__func__,
"Unexpected DRS.TYPE: %s != %s",
2634 drstype, expected_drstype) ;
2635 cpl_propertylist_delete(plist) ;
2639 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.
cpl_vector * cr2res_io_read_ndsamples(const cpl_frameset *in)
Get the NDSAMPLES from a frame set.
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_ndsamples(const cpl_propertylist *plist)
find out the NDSAMPLES value (up-the-ramp reads per DIT)
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.