41 #include "irplib_utils.h"
43 #include "crires_model_anneal.h"
44 #include "crires_dfs.h"
45 #include "crires_utils.h"
46 #include "crires_pfits.h"
52 static int crires_test_model_anneal_create(cpl_plugin *) ;
53 static int crires_test_model_anneal_exec(cpl_plugin *) ;
54 static int crires_test_model_anneal_destroy(cpl_plugin *) ;
55 static int crires_test_model_anneal(cpl_parameterlist *, cpl_frameset *) ;
56 static int crires_test_model_anneal_save(
const cpl_table *, cpl_parameterlist *,
63 static char crires_test_model_anneal_description[] =
64 "This recipe facilitates the optimisation of the physical model\nconfiguration given a set of observed detector positions for known\ncalibration features.\nThe files listed in the Set Of Frames (sof-file) must be tagged:\n start-cfg.fits CALPRO_MODEL_CONFIG\n matched-coords.dat CALPRO_MODEL_MEASCOORD\n";
80 int cpl_plugin_get_info(cpl_pluginlist * list)
82 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
83 cpl_plugin * plugin = &recipe->interface ;
85 cpl_plugin_init(plugin,
87 CRIRES_BINARY_VERSION,
88 CPL_PLUGIN_TYPE_RECIPE,
89 "crires_test_model_anneal",
90 "Compute optimum config given wvlens and obs detec posns",
91 crires_test_model_anneal_description,
95 crires_test_model_anneal_create,
96 crires_test_model_anneal_exec,
97 crires_test_model_anneal_destroy) ;
99 cpl_pluginlist_append(list, plugin) ;
113 static int crires_test_model_anneal_create(cpl_plugin * plugin)
115 cpl_recipe * recipe ;
118 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
119 recipe = (cpl_recipe *)plugin ;
123 recipe->parameters = cpl_parameterlist_new() ;
135 static int crires_test_model_anneal_exec(cpl_plugin * plugin)
137 cpl_recipe * recipe ;
140 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
141 recipe = (cpl_recipe *)plugin ;
144 return crires_test_model_anneal(recipe->parameters, recipe->frames) ;
154 static int crires_test_model_anneal_destroy(cpl_plugin * plugin)
156 cpl_recipe * recipe ;
159 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
160 recipe = (cpl_recipe *)plugin ;
163 cpl_parameterlist_delete(recipe->parameters) ;
175 static int crires_test_model_anneal(
176 cpl_parameterlist * parlist,
177 cpl_frameset * frameset)
179 cpl_frame * cri_config ;
180 cpl_frame * meas_coord ;
181 cpl_table * config_table ;
184 if (crires_dfs_set_groups(frameset, NULL)) {
185 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
190 cri_config = cpl_frameset_find(frameset, CRIRES_CALPRO_MODEL_CONFIG) ;
191 meas_coord = cpl_frameset_find(frameset,
"CALPRO_MODEL_MEASCOORD") ;
194 if ((config_table = crires_model_anneal_reduce(
195 cpl_frame_get_filename(cri_config),
196 cpl_frame_get_filename(meas_coord))) == NULL) {
197 cpl_msg_error(__func__,
"Failed computing the model") ;
202 cpl_msg_info(__func__,
"Save the products") ;
203 cpl_msg_indent_more() ;
204 if (crires_test_model_anneal_save((
const cpl_table *)config_table, parlist,
206 cpl_msg_error(__func__,
"Cannot save products") ;
207 cpl_msg_indent_less() ;
208 cpl_table_delete(config_table) ;
211 cpl_table_delete(config_table) ;
212 cpl_msg_indent_less() ;
215 if (cpl_error_get_code())
230 static int crires_test_model_anneal_save(
231 const cpl_table * out_table,
232 cpl_parameterlist * parlist,
236 cpl_propertylist * plist ;
238 cpl_frame * product_frame ;
244 sprintf(name_o,
"crires_test_model_anneal_save.fits") ;
245 cpl_msg_info(__func__,
"Writing %s" , name_o) ;
248 plist = cpl_propertylist_new();
249 cpl_propertylist_append_string(plist,
"INSTRUME",
"CRIRES") ;
252 product_frame = cpl_frame_new() ;
253 cpl_frame_set_filename(product_frame, name_o) ;
254 cpl_frame_set_tag(product_frame, CRIRES_CALPRO_MODEL_CONFIG) ;
255 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE);
256 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
257 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
260 if (cpl_dfs_setup_product_header(plist, product_frame, set, parlist,
261 "crires_test_model_anneal", PACKAGE
"/" PACKAGE_VERSION,
262 "PRO-1.15", NULL)!=CPL_ERROR_NONE) {
263 cpl_msg_warning(__func__,
"Problem in the product DFS-compliance") ;
268 if (cpl_table_save(out_table, plist, NULL, name_o,
269 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
270 cpl_msg_error(__func__,
"Cannot save the product");
271 cpl_frame_delete(product_frame) ;
272 cpl_propertylist_delete(plist) ;
275 cpl_propertylist_delete(plist) ;
278 cpl_frameset_insert(set, product_frame);