00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00032
00033
00034 #include <cpl.h>
00035 #include <math.h>
00036
00037 #include <stdlib.h>
00038 #include <stdio.h>
00039 #include <string.h>
00040
00041 #include "irplib_utils.h"
00042
00043 #include "crires_model_anneal.h"
00044 #include "crires_dfs.h"
00045 #include "crires_utils.h"
00046 #include "crires_pfits.h"
00047
00048
00049
00050
00051
00052 static int crires_test_model_anneal_create(cpl_plugin *) ;
00053 static int crires_test_model_anneal_exec(cpl_plugin *) ;
00054 static int crires_test_model_anneal_destroy(cpl_plugin *) ;
00055 static int crires_test_model_anneal(cpl_parameterlist *, cpl_frameset *) ;
00056 static int crires_test_model_anneal_save(const cpl_table *, cpl_parameterlist *,
00057 cpl_frameset *) ;
00058
00059
00060
00061
00062
00063 static char crires_test_model_anneal_description[] =
00064 "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";
00065
00066
00067
00068
00069
00070
00079
00080 int cpl_plugin_get_info(cpl_pluginlist * list)
00081 {
00082 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00083 cpl_plugin * plugin = &recipe->interface ;
00084
00085 cpl_plugin_init(plugin,
00086 CPL_PLUGIN_API,
00087 CRIRES_BINARY_VERSION,
00088 CPL_PLUGIN_TYPE_RECIPE,
00089 "crires_test_model_anneal",
00090 "Compute optimum config given wvlens and obs detec posns",
00091 crires_test_model_anneal_description,
00092 "Paul Bristow",
00093 "bristowp@eso.org",
00094 crires_get_license(),
00095 crires_test_model_anneal_create,
00096 crires_test_model_anneal_exec,
00097 crires_test_model_anneal_destroy) ;
00098
00099 cpl_pluginlist_append(list, plugin) ;
00100
00101 return 0;
00102 }
00103
00104
00112
00113 static int crires_test_model_anneal_create(cpl_plugin * plugin)
00114 {
00115 cpl_recipe * recipe ;
00116
00117
00118 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00119 recipe = (cpl_recipe *)plugin ;
00120 else return -1 ;
00121
00122
00123 recipe->parameters = cpl_parameterlist_new() ;
00124
00125
00126 return 0;
00127 }
00128
00134
00135 static int crires_test_model_anneal_exec(cpl_plugin * plugin)
00136 {
00137 cpl_recipe * recipe ;
00138
00139
00140 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00141 recipe = (cpl_recipe *)plugin ;
00142 else return -1 ;
00143
00144 return crires_test_model_anneal(recipe->parameters, recipe->frames) ;
00145 }
00146
00147
00153
00154 static int crires_test_model_anneal_destroy(cpl_plugin * plugin)
00155 {
00156 cpl_recipe * recipe ;
00157
00158
00159 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00160 recipe = (cpl_recipe *)plugin ;
00161 else return -1 ;
00162
00163 cpl_parameterlist_delete(recipe->parameters) ;
00164 return 0 ;
00165 }
00166
00167
00174
00175 static int crires_test_model_anneal(
00176 cpl_parameterlist * parlist,
00177 cpl_frameset * frameset)
00178 {
00179 cpl_frame * cri_config ;
00180 cpl_frame * meas_coord ;
00181 cpl_table * config_table ;
00182
00183
00184 if (crires_dfs_set_groups(frameset, NULL)) {
00185 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00186 return -1 ;
00187 }
00188
00189
00190 cri_config = cpl_frameset_find(frameset, CRIRES_CALPRO_MODEL_CONFIG) ;
00191 meas_coord = cpl_frameset_find(frameset, "CALPRO_MODEL_MEASCOORD") ;
00192
00193
00194 if ((config_table = crires_model_anneal_reduce(
00195 cpl_frame_get_filename(cri_config),
00196 cpl_frame_get_filename(meas_coord))) == NULL) {
00197 cpl_msg_error(__func__, "Failed computing the model") ;
00198 return -1 ;
00199 }
00200
00201
00202 cpl_msg_info(__func__, "Save the products") ;
00203 cpl_msg_indent_more() ;
00204 if (crires_test_model_anneal_save((const cpl_table *)config_table, parlist,
00205 frameset) == -1) {
00206 cpl_msg_error(__func__, "Cannot save products") ;
00207 cpl_msg_indent_less() ;
00208 cpl_table_delete(config_table) ;
00209 return -1 ;
00210 }
00211 cpl_table_delete(config_table) ;
00212 cpl_msg_indent_less() ;
00213
00214
00215 if (cpl_error_get_code())
00216 return -1 ;
00217 else
00218 return 0 ;
00219 }
00220
00221
00229
00230 static int crires_test_model_anneal_save(
00231 const cpl_table * out_table,
00232 cpl_parameterlist * parlist,
00233 cpl_frameset * set)
00234 {
00235 char name_o[512] ;
00236 cpl_propertylist * plist ;
00237 cpl_frame * ref_frame ;
00238 cpl_frame * product_frame ;
00239
00240
00241 ref_frame = irplib_frameset_get_first_from_group(set, CPL_FRAME_GROUP_RAW) ;
00242
00243
00244 sprintf(name_o, "crires_test_model_anneal_save.fits") ;
00245 cpl_msg_info(__func__, "Writing %s" , name_o) ;
00246
00247
00248 plist = cpl_propertylist_new();
00249 cpl_propertylist_append_string(plist, "INSTRUME", "CRIRES") ;
00250
00251
00252 product_frame = cpl_frame_new() ;
00253 cpl_frame_set_filename(product_frame, name_o) ;
00254 cpl_frame_set_tag(product_frame, CRIRES_CALPRO_MODEL_CONFIG) ;
00255 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE);
00256 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
00257 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
00258
00259
00260 if (cpl_dfs_setup_product_header(plist, product_frame, set, parlist,
00261 "crires_test_model_anneal", PACKAGE "/" PACKAGE_VERSION,
00262 "PRO-1.15", NULL)!=CPL_ERROR_NONE) {
00263 cpl_msg_warning(__func__, "Problem in the product DFS-compliance") ;
00264 cpl_error_reset() ;
00265 }
00266
00267
00268 if (cpl_table_save(out_table, plist, NULL, name_o,
00269 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00270 cpl_msg_error(__func__, "Cannot save the product");
00271 cpl_frame_delete(product_frame) ;
00272 cpl_propertylist_delete(plist) ;
00273 return -1 ;
00274 }
00275 cpl_propertylist_delete(plist) ;
00276
00277
00278 cpl_frameset_insert(set, product_frame);
00279
00280 return 0 ;
00281 }
00282