X-shooter Pipeline Reference Manual 3.8.15
xsh_molecfit_utils.c
Go to the documentation of this file.
2
3cpl_error_code xsh_molecfit_model_check_extensions_and_ranges(cpl_size extension, double min_wav, double max_wav, cpl_table* range) {
4 //cpl_msg_info(cpl_func,"fors_molecfit_model_check_extensions_and_ranges");
5 //cpl_msg_info(cpl_func,"selected rows: %lld",cpl_table_count_selected(range));
6
7 //cpl_msg_info (cpl_func,"CHECK FOR extension %lld, min %f max %f", extension, min_wav,max_wav);
8 //cpl_table_dump(range,0,cpl_table_get_nrow(range),NULL);
9
10 /* Check all ranges that are mapped to this extension */
11
12 cpl_size nranges=cpl_table_get_nrow(range);
13 cpl_boolean check_ok= CPL_TRUE;
14 for (cpl_size i=0;i<nranges;i++) {
15
16 //cpl_size range_idx=i+1;
17
18 int range_assigned_extension = cpl_table_get_int (range,MF_COL_WAVE_RANGE_MAP2CHIP,i,NULL);
19 double range_low_limit = cpl_table_get_double(range,MF_COL_WAVE_RANGE_LOWER, i, NULL);
20 double range_upp_limit = cpl_table_get_double(range,MF_COL_WAVE_RANGE_UPPER, i,NULL);
21
22 /* Only check ranges that have been mapped to this extension data */
23 if (range_assigned_extension!=extension) continue;
24
25 if(range_upp_limit<=min_wav || range_low_limit>=max_wav){
26 cpl_table_unselect_row(range,i);
27 }
28 }
29
30 cpl_msg_info(cpl_func,"selected rows: %lld",cpl_table_count_selected(range));
31 if(cpl_table_count_selected(range) == 0){
32 check_ok = CPL_FALSE;
33 }
34
35 /* If the check is not ok then set error message and return illegal input flag */
36 if (!check_ok) {
37 cpl_msg_error(cpl_func,"No valid ranges");
38 //cpl_msg_error(cpl_func,"Range %lld [%f , %f] Assigned to Extension %d [%f , %f]. Check Overlap NOT OK",
39 // range_idx, range_low_limit, range_upp_limit, range_assigned_extension,min_wav,max_wav);
40 return CPL_ERROR_ILLEGAL_INPUT;
41 }
42
43 /* Output that this range has been checked and show details */
44 //cpl_msg_info(cpl_func,"Range %lld [%f , %f] Assigned to Extension %d [%f , %f]. Check Overlap OK",
45 // range_idx, range_low_limit, range_upp_limit, range_assigned_extension,min_wav,max_wav);
46
47
48
49 return CPL_ERROR_NONE;
50}
51
52/* Is it always only one input spectrum per frameset?*/
53cpl_error_code xsh_molecfit_utils_find_input_frame(cpl_frameset *frameset,cpl_parameterlist* iframe){
54 /* The cpl_parameterlist* of results - iframe - should already have a size of 3 allocated*/
55
56 //cpl_frameset_dump(frameset,stdout);
57 /* X-SHOOTER has 3 distinct arms - XXX */
58 cpl_size n_arms = 3;
59 cpl_array* arms = cpl_array_new(n_arms,CPL_TYPE_STRING);
60 cpl_array_set_string(arms,0,"UVB");
61 cpl_array_set_string(arms,1,"VIS");
62 cpl_array_set_string(arms,2,"NIR");
63
64 /* X-SHOOTER has 3 distinct observation modes - YYY */
65 cpl_size n_omodes = 3;
66 cpl_array* omodes = cpl_array_new(n_omodes,CPL_TYPE_STRING);
67 cpl_array_set_string(omodes,0,"NOD");
68 cpl_array_set_string(omodes,1,"STARE");
69 cpl_array_set_string(omodes,2,"OFFSET");
70
71 /* First consider SCI and TELL combinations */
72 cpl_size n_bases= 7;
73 cpl_array* bases = cpl_array_new(n_bases,CPL_TYPE_STRING);
74 cpl_array_set_string(bases,0,"SCI_SLIT_FLUX_IDP");
75 cpl_array_set_string(bases,1,"SCI_SLIT_FLUX_MERGE1D");
76 cpl_array_set_string(bases,2,"SCI_SLIT_MERGE1D");
77 cpl_array_set_string(bases,3,"SCI_SLIT_FLUX_MERGE2D");
78 cpl_array_set_string(bases,4,"TELL_SLIT_MERGE1D");
79 cpl_array_set_string(bases,5,"TELL_SLIT_FLUX_MERGE1D");
80 cpl_array_set_string(bases,6,"TELL_SLIT_FLUX_IDP");
81 //structure for setting results in iframe
82 //idx 0 == input tag name
83 //idx 1 == ARM (UVB, VIS, NIR)
84 //idx 2 == OBSMODE (NOD, STARE or OFFSET); If none of these, it is set to DEFAULT
85 //idx 3 == IDP (TRUE or FALSE)
86 for (int i=0;i<n_bases;i++){
87 const char* base = cpl_array_get_string(bases,i);
88 const char* idp = (strstr(base,"IDP")) ? "TRUE" : "FALSE";
89 for (int j=0;j<n_arms;j++){
90 const char* arm = cpl_array_get_string(arms,j);
91 const char* tag = cpl_sprintf("%s_%s",base,arm);
92 cpl_msg_info(cpl_func,"Looking for TAG %s",tag);
93 cpl_frame* input_frame = NULL;
94 input_frame = cpl_frameset_find(frameset, tag);
95 if(input_frame){
96 const char* fname = cpl_frame_get_filename(input_frame);
97 cpl_msg_info(cpl_func,"FOUND frame with TAG %s and filename %s",tag,fname);
98 cpl_parameterlist_append(iframe,cpl_parameter_new_value("INPUTNAME",CPL_TYPE_STRING,NULL,NULL,tag));
99 cpl_parameterlist_append(iframe,cpl_parameter_new_value("ARM",CPL_TYPE_STRING,NULL,NULL,arm));
100 cpl_parameterlist_append(iframe,cpl_parameter_new_value("OBSMODE",CPL_TYPE_STRING,NULL,NULL,"DEFAULT"));
101 cpl_parameterlist_append(iframe,cpl_parameter_new_value("IDP",CPL_TYPE_STRING,NULL,NULL,idp));
102 cpl_parameterlist_append(iframe,cpl_parameter_new_value("INPUTFILENAME",CPL_TYPE_STRING,NULL,NULL,fname));
103
104 cpl_array_delete(arms);
105 cpl_array_delete(omodes);
106 cpl_array_delete(bases);
107 return CPL_ERROR_NONE;
108 }
109 }
110 }
111 /* Handle STD_SLIT_FLUX_IDP_YYY_XXX combinations*/
112 for (int i=0;i<n_omodes;i++){
113 const char* omode = cpl_array_get_string(omodes,i);
114 for (int j=0;j<n_arms;j++){
115 const char* arm = cpl_array_get_string(arms,j);
116 const char* tag = cpl_sprintf("STD_SLIT_FLUX_IDP_%s_%s",omode,arm);
117 cpl_msg_info(cpl_func,"Looking for TAG %s",tag);
118 cpl_frame* input_frame = NULL;
119 input_frame = cpl_frameset_find(frameset, tag);
120 if(input_frame){
121 const char* fname = cpl_frame_get_filename(input_frame);
122 cpl_parameterlist_append(iframe,cpl_parameter_new_value("INPUTNAME",CPL_TYPE_STRING,NULL,NULL,tag));
123 cpl_parameterlist_append(iframe,cpl_parameter_new_value("ARM",CPL_TYPE_STRING,NULL,NULL,arm));
124 cpl_parameterlist_append(iframe,cpl_parameter_new_value("OBSMODE",CPL_TYPE_STRING,NULL,NULL,omode));
125 cpl_parameterlist_append(iframe,cpl_parameter_new_value("IDP",CPL_TYPE_STRING,NULL,NULL,"TRUE"));
126 cpl_parameterlist_append(iframe,cpl_parameter_new_value("INPUTFILENAME",CPL_TYPE_STRING,NULL,NULL,fname));
127 cpl_array_delete(arms);
128 cpl_array_delete(omodes);
129 cpl_array_delete(bases);
130 return CPL_ERROR_NONE;
131 }
132 }
133 }
134 cpl_array_delete(arms);
135 cpl_array_delete(omodes);
136 cpl_array_delete(bases);
137 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
138 return CPL_ERROR_NULL_INPUT;
139}
140
141
cpl_error_code xsh_molecfit_utils_find_input_frame(cpl_frameset *frameset, cpl_parameterlist *iframe)
cpl_error_code xsh_molecfit_model_check_extensions_and_ranges(cpl_size extension, double min_wav, double max_wav, cpl_table *range)