36 #include "crires_recipe.h"
42 #define RECIPE_STRING "crires_util_genlines"
48 static int crires_util_genlines_save(cpl_table *,
const cpl_parameterlist *,
51 static char crires_util_genlines_description[] =
52 "This recipe is used to generate spectrum calibration tables.\n"
53 "The sof file contains the names of the input ASCII file\n"
54 "tagged with "CRIRES_UTIL_GENLINES_RAW
".\n"
55 "The ASCII file must contain two columns:\n"
56 "1st: Wavelengths in increasing order (the unit is corrected by\n"
57 " the factor option to obtain nanometers).\n"
58 "2nd: The atmospheric emission.\n"
59 "The ASCII files are in the catalogs/ directory of the CRIRES distribution.\n"
60 "This recipe produces 1 file:\n"
61 "First product: the table with the lines.\n"
62 " (PRO TYPE = "CRIRES_PROTYPE_CATALOG
")\n" ;
64 CRIRES_RECIPE_DEFINE(crires_util_genlines,
65 CRIRES_PARAM_FILL_BLANKS |
67 CRIRES_PARAM_LINES_MODE |
68 CRIRES_PARAM_WL_FACTOR,
69 "Generate spectrum calibration FITS tables",
70 crires_util_genlines_description) ;
83 } crires_util_genlines_config ;
99 static int crires_util_genlines(
100 cpl_frameset * framelist,
101 const cpl_parameterlist * parlist)
103 cpl_bivector * bivec ;
106 cpl_bivector * bivec_fill ;
107 double * pbivec_fill_x ;
108 double * pbivec_fill_y ;
109 cpl_frame * cur_frame ;
110 int nvals, nb_new_vals ;
116 crires_util_genlines_config.fill_blanks = crires_parameterlist_get_bool(
117 parlist, RECIPE_STRING, CRIRES_PARAM_FILL_BLANKS) ;
118 crires_util_genlines_config.display = crires_parameterlist_get_bool(
119 parlist, RECIPE_STRING, CRIRES_PARAM_PLOT) ;
120 crires_util_genlines_config.mode = crires_parameterlist_get_int(
121 parlist, RECIPE_STRING, CRIRES_PARAM_LINES_MODE) ;
122 crires_util_genlines_config.wl_factor = crires_parameterlist_get_double(
123 parlist, RECIPE_STRING, CRIRES_PARAM_WL_FACTOR) ;
126 if (crires_dfs_set_groups(framelist, NULL)) {
127 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
132 cur_frame = cpl_frameset_get_position(framelist, 0) ;
133 if ((bivec=cpl_bivector_read(cpl_frame_get_filename(cur_frame)))==NULL) {
134 cpl_msg_error(__func__,
"Cannot load the file in the bivector") ;
137 nvals = cpl_bivector_get_size(bivec) ;
140 if (crires_util_genlines_config.fill_blanks) {
141 nb_new_vals = 3 * nvals ;
142 bivec_fill = cpl_bivector_new(nb_new_vals) ;
143 pbivec_fill_x = cpl_bivector_get_x_data(bivec_fill) ;
144 pbivec_fill_y = cpl_bivector_get_y_data(bivec_fill) ;
145 pbivec_x = cpl_bivector_get_x_data(bivec) ;
146 pbivec_y = cpl_bivector_get_y_data(bivec) ;
147 for (i=0 ; i<nvals ; i++) {
148 wavel = pbivec_x[i] * crires_util_genlines_config.wl_factor ;
149 pbivec_fill_x[3*i] = wavel - 0.01 ;
150 pbivec_fill_y[3*i] = 0.0 ;
151 pbivec_fill_x[3*i+1] = wavel ;
152 pbivec_fill_y[3*i+1] = pbivec_y[i] ;
153 pbivec_fill_x[3*i+2] = wavel + 0.01 ;
154 pbivec_fill_y[3*i+2] = 0.0 ;
156 cpl_bivector_delete(bivec);
159 nvals = cpl_bivector_get_size(bivec) ;
161 cpl_vector_multiply_scalar(cpl_bivector_get_x(bivec),
162 crires_util_genlines_config.wl_factor) ;
166 if (crires_util_genlines_config.display) {
168 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Emission';",
169 "t 'Catalog lines' w lines",
"", bivec);
173 tab = cpl_table_new(nvals) ;
174 cpl_table_wrap_double(tab, cpl_bivector_get_x_data(bivec),
175 CRIRES_COL_WAVELENGTH) ;
176 cpl_table_wrap_double(tab, cpl_bivector_get_y_data(bivec),
177 CRIRES_COL_EMISSION) ;
180 cpl_msg_info(__func__,
"Saving the table with %d rows", nvals) ;
181 if (crires_util_genlines_save(tab, parlist, framelist) == -1) {
182 cpl_msg_error(__func__,
"Cannot write the table") ;
183 cpl_bivector_delete(bivec) ;
184 cpl_table_unwrap(tab, CRIRES_COL_WAVELENGTH) ;
185 cpl_table_unwrap(tab, CRIRES_COL_EMISSION) ;
186 cpl_table_delete(tab) ;
189 cpl_bivector_delete(bivec) ;
190 cpl_table_unwrap(tab, CRIRES_COL_WAVELENGTH) ;
191 cpl_table_unwrap(tab, CRIRES_COL_EMISSION) ;
192 cpl_table_delete(tab) ;
205 static int crires_util_genlines_save(
206 cpl_table * out_table,
207 const cpl_parameterlist * parlist,
210 cpl_propertylist * plist ;
211 const char * procat ;
213 if (crires_util_genlines_config.mode == 1)
214 procat = CRIRES_CALPRO_HITRAN_CAT ;
215 else if (crires_util_genlines_config.mode == 2)
216 procat = CRIRES_CALPRO_OH_CAT ;
217 else if (crires_util_genlines_config.mode == 3)
218 procat = CRIRES_CALPRO_THAR_CAT ;
219 else if (crires_util_genlines_config.mode == 4)
220 procat = CRIRES_CALPRO_N2O_CAT ;
221 else if (crires_util_genlines_config.mode == 5)
222 procat = CRIRES_CALPRO_MODEL_WAVEEG ;
226 plist = cpl_propertylist_new();
227 cpl_propertylist_append_string(plist,
"INSTRUME",
"CRIRES") ;
228 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, procat) ;
229 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
230 CRIRES_PROTYPE_CATALOG) ;
232 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
233 NULL,
"crires_util_genlines", plist, NULL,
234 PACKAGE
"/" PACKAGE_VERSION,
235 "crires_util_genlines.fits") != CPL_ERROR_NONE) {
236 cpl_msg_error(__func__,
"Cannot save the table") ;
239 cpl_propertylist_delete(plist) ;