39static int kmos_gen_reflines_save(cpl_table *,
const cpl_parameterlist *,
42static int kmos_gen_reflines_create(cpl_plugin *);
43static int kmos_gen_reflines_exec(cpl_plugin *);
44static int kmos_gen_reflines_destroy(cpl_plugin *);
45static int kmos_gen_reflines(
const cpl_parameterlist *, cpl_frameset *);
51static char kmos_gen_reflines_description[] =
52"This recipe is used to generate the REFLINES calibration file.\n"
53"The sof file contains the name of the input ASCII file\n"
54"tagged with "KMOS_GEN_REFLINES_RAW
".\n"
55"The ASCII file must contain seven columns like the output of:\n"
56" dtfits -d -s ' ' kmos_wave_ref_table.fits\n"
57"The six column titles are:\n"
58"FILTER|DETECTOR|WAVELENGTH|REFERENCE| OFFSET| RANGE| CUT\n"
59"The entries are like:\n"
60" HK 3 1.79196 0 210 20 577\n"
61" HK 3 2.25365 4 427 15 71\n"
62" HK 3 2.06129 -1 1313 50 140\n"
63" HK 3 2.32666 4 594 15 32\n"
64" IZ 1 0.912547 -1 775 80 4000\n"
65" IZ 1 0.966044 -1 1150 80 2000\n"
66" IZ 1 1.04729 -1 1730 80 200\n"
67" IZ 1 1.06765 2 128 40 80\n"
69"This recipe produces 1 file:\n"
70"First product: the table with the configuration for the model.\n" ;
96 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
97 cpl_plugin *plugin = &recipe->interface;
99 cpl_plugin_init(plugin,
102 CPL_PLUGIN_TYPE_RECIPE,
104 "Create REFLINES calibration file",
105 kmos_gen_reflines_description,
107 "https://support.eso.org/",
109 kmos_gen_reflines_create,
110 kmos_gen_reflines_exec,
111 kmos_gen_reflines_destroy);
113 cpl_pluginlist_append(list, plugin);
126static int kmos_gen_reflines_create(cpl_plugin *plugin)
131 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
132 recipe = (cpl_recipe *)plugin;
137 recipe->parameters = cpl_parameterlist_new();
151static int kmos_gen_reflines_exec(cpl_plugin *plugin)
156 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
157 recipe = (cpl_recipe *)plugin;
160 return kmos_gen_reflines(recipe->parameters, recipe->frames);
170static int kmos_gen_reflines_destroy(cpl_plugin *plugin)
175 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
176 recipe = (cpl_recipe *)plugin;
179 cpl_parameterlist_delete(recipe->parameters);
191static int kmos_gen_reflines(
192 const cpl_parameterlist * parlist,
193 cpl_frameset * framelist)
197 cpl_frame * cur_frame ;
198 const char * cur_fname ;
201 int det, ref, offset, range, cut ;
209 if (kmo_dfs_set_groups(framelist) != 1) {
210 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
211 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
216 cur_frame = cpl_frameset_get_position(framelist, 0) ;
217 cur_fname = cpl_frame_get_filename(cur_frame) ;
220 if ((in = fopen(cur_fname,
"r")) == NULL) {
221 cpl_msg_error(__func__,
"Could not open %s", cur_fname) ;
222 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
228 while (fgets(line, 1024, in) != NULL) {
229 if (line[0] !=
'#' && sscanf(line,
"%1023s %d %lg %d %d %d %d",
230 band, &det, &wave, &ref, &offset, &range, &cut) == 7)
234 cpl_msg_error(__func__,
"No valid entry in the file") ;
240 tab = cpl_table_new(nentries) ;
241 cpl_table_new_column(tab,
"FILTER", CPL_TYPE_STRING) ;
242 cpl_table_new_column(tab,
"DETECTOR", CPL_TYPE_INT) ;
243 cpl_table_new_column(tab,
"WAVELENGTH", CPL_TYPE_DOUBLE) ;
244 cpl_table_new_column(tab,
"REFERENCE", CPL_TYPE_INT) ;
245 cpl_table_new_column(tab,
"OFFSET", CPL_TYPE_INT) ;
246 cpl_table_new_column(tab,
"RANGE", CPL_TYPE_INT) ;
247 cpl_table_new_column(tab,
"CUT", CPL_TYPE_INT) ;
252 while (fgets(line, 1024, in) != NULL) {
253 if (line[0] !=
'#' && sscanf(line,
"%1023s %d %lg %d %d %d %d",
254 band, &det, &wave, &ref, &offset, &range, &cut) == 7) {
255 cpl_table_set_string(tab,
"FILTER", i, band) ;
256 cpl_table_set_int(tab,
"DETECTOR", i, det) ;
257 cpl_table_set_double(tab,
"WAVELENGTH", i, wave) ;
258 cpl_table_set_int(tab,
"REFERENCE", i, ref) ;
259 cpl_table_set_int(tab,
"OFFSET", i, offset) ;
260 cpl_table_set_int(tab,
"RANGE", i, range) ;
261 cpl_table_set_int(tab,
"CUT", i, cut) ;
268 cpl_msg_info(__func__,
"Saving the table with %d rows", nentries) ;
269 if (kmos_gen_reflines_save(tab, parlist, framelist) == -1) {
270 cpl_msg_error(__func__,
"Cannot write the table") ;
271 cpl_table_delete(tab) ;
274 cpl_table_delete(tab) ;
287static int kmos_gen_reflines_save(
288 cpl_table * out_table,
289 const cpl_parameterlist * parlist,
292 cpl_propertylist * plist ;
293 cpl_propertylist * plist_ext ;
295 plist = cpl_propertylist_new();
296 cpl_propertylist_append_string(plist,
"INSTRUME",
"KMOS") ;
297 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
"REF_LINES") ;
298 plist_ext = cpl_propertylist_new();
299 cpl_propertylist_append_string(plist_ext,
"EXTNAME",
"LIST") ;
301 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
302 plist_ext,
"kmos_gen_reflines", plist, NULL,
303 PACKAGE
"/" PACKAGE_VERSION,
304 "kmos_gen_reflines.fits") != CPL_ERROR_NONE) {
305 cpl_msg_error(__func__,
"Cannot save the table") ;
306 cpl_propertylist_delete(plist) ;
307 cpl_propertylist_delete(plist_ext) ;
310 cpl_propertylist_delete(plist) ;
311 cpl_propertylist_delete(plist_ext) ;
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.