37 #include "crires_recipe.h"
43 #define RECIPE_STRING "crires_util_genconfig"
49 static int crires_util_genconfig_save(cpl_table *,
const cpl_parameterlist *,
52 static char crires_util_genconfig_description[] =
53 "This recipe is used to generate the model configuration file.\n"
54 "The sof file contains the names of the input ASCII file\n"
55 "tagged with "CRIRES_UTIL_GENCONFIG_RAW
".\n"
56 "The ASCII file must contain five columns:\n"
57 "1st: The best guess value\n"
58 "2nd: The low limit\n"
59 "3th: The high limit\n"
60 "4th: The Flag to recompute or not\n"
61 "5th: Name of the Parameter\n"
62 "The ASCII files are in the catalogs/ directory of the CRIRES distribution.\n"
63 "This recipe produces 1 file:\n"
64 "First product: the table with the configuration for the model.\n"
65 " (PRO TYPE = "CRIRES_PROTYPE_MOD_CONF
")\n" ;
67 CRIRES_RECIPE_DEFINE(crires_util_genconfig,
68 CRIRES_PARAM_CONFIG_MODE,
69 "Generate spectrum calibration FITS tables",
70 crires_util_genconfig_description) ;
79 } crires_util_genconfig_config ;
93 static int crires_util_genconfig(
94 cpl_frameset * framelist,
95 const cpl_parameterlist * parlist)
99 cpl_frame * cur_frame ;
100 const char * cur_fname ;
103 double best, low, high ;
109 setlocale(LC_NUMERIC,
"C");
112 crires_util_genconfig_config.mode = crires_parameterlist_get_int(parlist,
113 RECIPE_STRING, CRIRES_PARAM_CONFIG_MODE) ;
116 if (crires_dfs_set_groups(framelist, NULL)) {
117 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
122 cur_frame = cpl_frameset_get_position(framelist, 0) ;
123 cur_fname = cpl_frame_get_filename(cur_frame) ;
126 if ((in = fopen(cur_fname,
"r")) == NULL) {
127 cpl_msg_error(__func__,
"Could not open %s", cur_fname) ;
133 while (fgets(line, 1024, in) != NULL) {
134 if (line[0] !=
'#' && sscanf(line,
"%lg %lg %lg %d %s",
135 &best, &low, &high, &flag, name) == 5) nentries++ ;
138 cpl_msg_error(__func__,
"No valid entryin the file") ;
144 tab = cpl_table_new(nentries) ;
145 cpl_table_new_column(tab, CRIRES_COL_MODEL_CONF_BEST, CPL_TYPE_DOUBLE) ;
146 cpl_table_new_column(tab, CRIRES_COL_MODEL_CONF_LOW, CPL_TYPE_DOUBLE) ;
147 cpl_table_new_column(tab, CRIRES_COL_MODEL_CONF_HIGH, CPL_TYPE_DOUBLE) ;
148 cpl_table_new_column(tab, CRIRES_COL_MODEL_CONF_FLAG, CPL_TYPE_INT) ;
149 cpl_table_new_column(tab, CRIRES_COL_MODEL_CONF_NAME, CPL_TYPE_STRING) ;
154 while (fgets(line, 1024, in) != NULL) {
155 if (line[0] !=
'#' && sscanf(line,
"%lg %lg %lg %d %s",
156 &best, &low, &high, &flag, name) == 5) {
157 cpl_table_set_string(tab, CRIRES_COL_MODEL_CONF_NAME, i, name) ;
158 cpl_table_set_double(tab, CRIRES_COL_MODEL_CONF_BEST, i, best) ;
159 cpl_table_set_double(tab, CRIRES_COL_MODEL_CONF_LOW, i, low) ;
160 cpl_table_set_double(tab, CRIRES_COL_MODEL_CONF_HIGH, i, high) ;
161 cpl_table_set_int(tab, CRIRES_COL_MODEL_CONF_FLAG, i, flag) ;
168 cpl_msg_info(__func__,
"Saving the table with %d rows", nentries) ;
169 if (crires_util_genconfig_save(tab, parlist, framelist) == -1) {
170 cpl_msg_error(__func__,
"Cannot write the table") ;
171 cpl_table_delete(tab) ;
174 cpl_table_delete(tab) ;
187 static int crires_util_genconfig_save(
188 cpl_table * out_table,
189 const cpl_parameterlist * parlist,
192 cpl_propertylist * plist ;
193 const char * procat ;
195 if (crires_util_genconfig_config.mode == 1)
196 procat = CRIRES_CALPRO_MODEL_REFINE_CONF ;
197 else if (crires_util_genconfig_config.mode == 2)
198 procat = CRIRES_CALPRO_MODEL_CONFIG ;
200 cpl_msg_error(__func__,
"Unsupported mode") ;
204 plist = cpl_propertylist_new();
205 cpl_propertylist_append_string(plist,
"INSTRUME",
"CRIRES") ;
206 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, procat) ;
207 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
208 CRIRES_PROTYPE_MOD_CONF) ;
209 cpl_propertylist_append_string(plist,
"ESO PRO CFG-IDENT",
212 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
213 NULL,
"crires_util_genconfig", plist, NULL,
214 PACKAGE
"/" PACKAGE_VERSION,
215 "crires_util_genconfig.fits") != CPL_ERROR_NONE) {
216 cpl_msg_error(__func__,
"Cannot save the table") ;
219 cpl_propertylist_delete(plist) ;