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
00040
00042
00043
00044
00045
00046 #include <cpl.h>
00047 #include <math.h>
00048
00049 #include <stdlib.h>
00050 #include <stdio.h>
00051 #include <string.h>
00052
00053 #include <xsh_model_anneal.h>
00054 #include <xsh_dfs.h>
00055 #include <xsh_utils.h>
00056 #include <xsh_pfits.h>
00057 #include <xsh_msg.h>
00058 #include <xsh_error.h>
00059
00060
00061
00062
00063
00064 static int xsh_model_anneal_create(cpl_plugin *) ;
00065 static int xsh_model_anneal_exec(cpl_plugin *) ;
00066 static int xsh_model_anneal_destroy(cpl_plugin *) ;
00067 static int xsh_model_anneal(cpl_parameterlist *, cpl_frameset *) ;
00068 static int xsh_model_anneal_save(const cpl_table *, cpl_parameterlist *,
00069 cpl_frameset *) ;
00070
00071
00072
00073
00074
00075 static char xsh_model_anneal_description[] =
00076 "This recipe is for development use only.\n";
00077 static char xsh_model_anneal_description_short[] =
00078 "Compute optimum config given wavelengths and observed detected positions";
00079
00080
00081
00082
00083
00092
00093 int cpl_plugin_get_info(cpl_pluginlist * list)
00094 {
00095 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00096 cpl_plugin * plugin = &recipe->interface ;
00097
00098 cpl_plugin_init(plugin,
00099 CPL_PLUGIN_API,
00100 XSH_BINARY_VERSION,
00101 CPL_PLUGIN_TYPE_RECIPE,
00102 "xsh_model_anneal",
00103 xsh_model_anneal_description_short,
00104 xsh_model_anneal_description,
00105 "Paul Bristow",
00106 "bristowp@eso.org",
00107 xsh_get_license(),
00108 xsh_model_anneal_create,
00109 xsh_model_anneal_exec,
00110 xsh_model_anneal_destroy) ;
00111
00112 cpl_pluginlist_append(list, plugin) ;
00113
00114 return 0;
00115 }
00116
00117
00125
00126 static int xsh_model_anneal_create(cpl_plugin * plugin)
00127 {
00128 cpl_recipe * recipe ;
00129 cpl_parameter * p=NULL;
00130
00131
00132 xsh_init();
00133
00134
00135 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00136
00137
00138
00139 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00140 recipe = (cpl_recipe *)plugin ;
00141 else return -1 ;
00142
00143
00144 recipe->parameters = cpl_parameterlist_new() ;
00145
00146 p = cpl_parameter_new_enum("xsh.xsh_model_compute.arm",
00147 CPL_TYPE_STRING,
00148 "Arm setting: ",
00149 "xsh.xsh_model_compute",
00150 "vis",
00151 3,"uvb","vis","nir");
00152
00153 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"arm");
00154 cpl_parameterlist_append(recipe->parameters, p);
00155
00156 cleanup:
00157
00158
00159 return 0;
00160 }
00161
00167
00168 static int xsh_model_anneal_exec(cpl_plugin * plugin)
00169 {
00170 cpl_recipe * recipe ;
00171
00172
00173 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00174 recipe = (cpl_recipe *)plugin ;
00175 else return -1 ;
00176
00177 return xsh_model_anneal(recipe->parameters, recipe->frames) ;
00178 }
00179
00180
00186
00187 static int xsh_model_anneal_destroy(cpl_plugin * plugin)
00188 {
00189 cpl_recipe * recipe ;
00190
00191
00192 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00193 recipe = (cpl_recipe *)plugin ;
00194 else return -1 ;
00195
00196 cpl_parameterlist_delete(recipe->parameters) ;
00197 return 0 ;
00198 }
00199
00200
00207
00208 static int xsh_model_anneal(
00209 cpl_parameterlist* parlist,
00210 cpl_frameset* frameset)
00211 {
00212 cpl_frame* xs_config ;
00213
00214 cpl_frame* meas_coord ;
00215
00216 cpl_table* config_table ;
00217 cpl_parameter* param=NULL;
00218 xsh_instrument* instrument = NULL;
00219 const char* arm=NULL;
00220 int nraw=0;
00221
00222
00223
00224
00225
00226
00227
00228 if( (nraw=cpl_frameset_get_size(frameset)) ==0) goto cleanup;
00229
00230 param = cpl_parameterlist_find(parlist,"xsh.xsh_model_compute.arm");
00231
00232 arm = cpl_parameter_get_string(param);
00233
00234 instrument=xsh_instrument_new();
00235 if(strcmp(arm,"uvb") == 0) xsh_instrument_set_arm(instrument,XSH_ARM_UVB);
00236 if(strcmp(arm,"vis") == 0) xsh_instrument_set_arm(instrument,XSH_ARM_VIS);
00237 if(strcmp(arm,"nir") == 0) xsh_instrument_set_arm(instrument,XSH_ARM_NIR);
00238
00239
00240 check(xs_config = xsh_find_calpro_model_config(frameset,instrument)) ;
00241 check(meas_coord = xsh_find_calpro_model_meas_coord(frameset,instrument)) ;
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 if ((config_table = xsh_model_anneal_reduce(
00272 cpl_frame_get_filename(xs_config),
00273 cpl_frame_get_tag(xs_config),
00274 cpl_frame_get_filename(meas_coord))) == NULL) {
00275 cpl_msg_error(__func__, "Failed computing the model") ;
00276 return -1 ;
00277 }
00278
00279
00280
00281 cpl_msg_info(__func__, "Save the products") ;
00282 cpl_msg_indent_more() ;
00283 if (xsh_model_anneal_save((const cpl_table*)config_table, parlist,
00284 frameset) == -1) {
00285 cpl_msg_error(__func__, "Cannot save products") ;
00286 cpl_msg_indent_less() ;
00287 cpl_table_delete(config_table) ;
00288 return -1 ;
00289 }
00290 cpl_table_delete(config_table) ;
00291 cpl_msg_indent_less() ;
00292
00293 cleanup:
00294 xsh_instrument_free(&instrument);
00295
00296
00297 if (cpl_error_get_code())
00298 return -1 ;
00299 else
00300 return 0 ;
00301 }
00302
00303
00311
00312 static int xsh_model_anneal_save(
00313 const cpl_table* out_table,
00314 cpl_parameterlist* parlist,
00315 cpl_frameset* set)
00316 {
00317 char name_o[512] ;
00318 cpl_propertylist* plist ;
00319 cpl_frame* product_frame ;
00320
00321
00322
00323
00324
00325 sprintf(name_o, "xsh_model_anneal_save.fits") ;
00326 cpl_msg_info(__func__, "Writing %s" , name_o) ;
00327
00328
00329 plist = cpl_propertylist_new();
00330 cpl_propertylist_append_string(plist, "INSTRUME", "XSH") ;
00331 cpl_propertylist_append_int(plist,"Num_pinh",9);
00332
00333
00334
00335 product_frame = cpl_frame_new() ;
00336 cpl_frame_set_filename(product_frame, name_o) ;
00337 cpl_frame_set_tag(product_frame, XSH_MOD_CFG) ;
00338 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE);
00339 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
00340 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
00341
00342
00343 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)
00344 if (cpl_dfs_setup_product_header(plist, product_frame, set, parlist,
00345 "xsh_model_anneal",
00346 PACKAGE "/" PACKAGE_VERSION,
00347 "PRO-1.15",NULL)!=CPL_ERROR_NONE) {
00348 cpl_msg_warning(__func__, "Problem in the product DFS-compliance") ;
00349 cpl_error_reset() ;
00350 }
00351 #else
00352 if (cpl_dfs_setup_product_header(plist, product_frame, set, parlist,
00353 "xsh_model_anneal",
00354 PACKAGE "/" PACKAGE_VERSION,
00355 "PRO-1.15")!=CPL_ERROR_NONE) {
00356 cpl_msg_warning(__func__, "Problem in the product DFS-compliance") ;
00357 cpl_error_reset() ;
00358 }
00359 #endif
00360
00361
00362 if (cpl_table_save(out_table, plist, NULL, name_o,
00363 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00364 cpl_msg_error(__func__, "Cannot save the product");
00365 cpl_frame_delete(product_frame) ;
00366 cpl_propertylist_delete(plist) ;
00367 return -1 ;
00368 }
00369 cpl_propertylist_delete(plist) ;
00370
00371
00372 cpl_frameset_insert(set, product_frame);
00373
00374 return 0 ;
00375 }