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
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00039
00041
00042
00043
00044
00045 #include <cpl.h>
00046
00047 #include "xsh_utils.h"
00048
00049 #include "xsh_dfs.h"
00050 #include "xsh_drl.h"
00051 #include "xsh_pfits.h"
00052 #include <xsh_model_io.h>
00053 #include <xsh_model_kernel.h>
00054 #include <xsh_model_utils.h>
00055 #include <xsh_error.h>
00056 #include <xsh_model_io.h>
00057 #include <xsh_parameters.h>
00058
00059 #define RECIPE_ID "xsh_util_guess_xy"
00060 #define RECIPE_AUTHOR "A.Modigliani, P. Bristow"
00061 #define RECIPE_CONTACT "amodigli@eso.org"
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 static int xsh_util_guess_xy_create(cpl_plugin *);
00072 static int xsh_util_guess_xy_exec(cpl_plugin *);
00073 static int xsh_util_guess_xy_destroy(cpl_plugin *);
00074 static int xsh_util_guess_xy(cpl_parameterlist *, cpl_frameset *);
00075
00076
00077
00078
00079
00080
00081 static char xsh_util_guess_xy_description[] =
00082 "This recipe finds X-Y guesses corresponding to 'grating_order','wavelength','slit' as in input tab. \n"
00083 "The sof file contains the names of the input FITS file\n"
00084 "tagged with XSH_MOD_CFG_arm.\n"
00085 "tagged with ARC_LINE_LIST_arm.\n"
00086 "This recipe has the following products:\n"
00087 "Model predictions (PRO CATG = MOD_arm)\n" ;
00088
00089 static char xsh_util_guess_xy_description_short[] ="Generate physical model guesses";
00090
00091
00092
00093
00094
00095
00103
00104 int cpl_plugin_get_info(cpl_pluginlist * list)
00105 {
00106 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
00107 cpl_plugin * plugin = &recipe->interface;
00108
00109 cpl_plugin_init(plugin,
00110 CPL_PLUGIN_API,
00111 XSH_BINARY_VERSION,
00112 CPL_PLUGIN_TYPE_RECIPE,
00113 "xsh_util_guess_xy",
00114 xsh_util_guess_xy_description_short,
00115 xsh_util_guess_xy_description,
00116 "Andrea Modigliani",
00117 "amodigli@eso.org",
00118 xsh_get_license(),
00119 xsh_util_guess_xy_create,
00120 xsh_util_guess_xy_exec,
00121 xsh_util_guess_xy_destroy);
00122
00123 cpl_pluginlist_append(list, plugin);
00124
00125 return 0 ;
00126 }
00127
00128
00137
00138 static int xsh_util_guess_xy_create(cpl_plugin * plugin)
00139 {
00140 cpl_recipe * recipe ;
00141 cpl_parameter* p=NULL;
00142
00143 xsh_init();
00144
00145
00146 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00147 recipe = (cpl_recipe *)plugin ;
00148 else return -1 ;
00149
00150
00151 recipe->parameters = cpl_parameterlist_new() ;
00152
00153
00154 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00155
00156 p = cpl_parameter_new_value("xsh.xsh_model.binx",
00157 CPL_TYPE_INT,
00158 "X binning ",
00159 "xsh.xsh_model", 1);
00160
00161 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"binx");
00162 cpl_parameterlist_append(recipe->parameters,p);
00163
00164
00165 p = cpl_parameter_new_value("xsh.xsh_model.biny",
00166 CPL_TYPE_INT,
00167 "X binning ",
00168 "xsh.xsh_model", 1);
00169
00170 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"biny");
00171 cpl_parameterlist_append(recipe->parameters,p);
00172
00173
00174
00175 cleanup:
00176
00177 return 0 ;
00178 }
00179
00180
00186
00187 static int xsh_util_guess_xy_exec(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 return xsh_util_guess_xy(recipe->parameters, recipe->frames) ;
00197 }
00198
00199
00205
00206 static int xsh_util_guess_xy_destroy(cpl_plugin * plugin)
00207 {
00208 cpl_recipe * recipe ;
00209
00210
00211 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00212 recipe = (cpl_recipe *)plugin ;
00213 else return -1 ;
00214
00215 cpl_parameterlist_delete(recipe->parameters) ;
00216 return 0 ;
00217 }
00218
00219
00227
00228 static int xsh_util_guess_xy(
00229 cpl_parameterlist * parameters,
00230 cpl_frameset * frameset)
00231 {
00232
00233
00234 const char* recipe_tags[1] = {XSH_MOD_CFG};
00235
00236 int recipe_tags_size = 1;
00237
00238 cpl_frameset* raws=NULL;
00239 cpl_frameset* calib=NULL;
00240 cpl_frame* wave_list=NULL ;
00241 cpl_frame* xsh_config=NULL ;
00242 xsh_instrument* instrument=NULL;
00243 cpl_parameter* p=NULL;
00244 int binx=0;
00245 int biny=0;
00246 int i=0;
00247 int nrow=0;
00248 double* pord=NULL;
00249 double* pwav=NULL;
00250 double* pslit=NULL;
00251 double x=0;
00252 double y=0;
00253 xsh_xs_3 model_config ;
00254 cpl_table* input_table=NULL;
00255 const char* input_table_name = NULL;
00256
00257 double wave=0;
00258 int ord=0;
00259 double s=0;
00260
00261 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00262 recipe_tags, recipe_tags_size, RECIPE_ID,
00263 XSH_BINARY_VERSION,
00264 xsh_util_guess_xy_description_short ) ) ;
00265 check(xsh_config = xsh_find_frame_with_tag( calib,XSH_MOD_CFG,
00266 instrument));
00267 check(wave_list = xsh_find_frame_with_tag( calib, XSH_ARC_LINE_LIST,
00268 instrument));
00269 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.binx"));
00270 check(binx = cpl_parameter_get_int(p));
00271
00272 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.biny"));
00273 check(biny = cpl_parameter_get_int(p));
00274 xsh_msg("cfg frm name=%s",cpl_frame_get_filename(xsh_config));
00275 check( xsh_model_config_load_best( xsh_config, &model_config));
00276 xsh_model_binxy(&model_config,binx,biny);
00277
00278
00279 input_table_name=cpl_frame_get_filename(wave_list);
00280 input_table=cpl_table_load(input_table_name,1,0);
00281 check(nrow=cpl_table_get_nrow(input_table));
00282
00283 check(pwav=cpl_table_get_data_double(input_table,"wavelength"));
00284 check(pord=cpl_table_get_data_double(input_table,"grating_order"));
00285 check(pslit=cpl_table_get_data_double(input_table,"slit"));
00286
00287 for(i=0;i<nrow;i++) {
00288
00289 wave=pwav[i];
00290 ord=(int)pord[i];
00291 s=pslit[i];
00292 check(xsh_model_get_xy(&model_config,instrument,wave,ord,s,&x,&y));
00293 xsh_msg("ord=%d wav=%10.8g s=%g ==>x=%16.13g y=%16.13g",ord,wave,s,x,y);
00294 }
00295
00296 cleanup:
00297 xsh_instrument_free(&instrument);
00298 xsh_free_frameset(&raws);
00299 xsh_free_frameset(&calib);
00300
00301 return 0 ;
00302 }
00303
00304
00305
00306
00307
00308
00309