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
00029
00030
00031
00032
00033
00034 #ifdef HAVE_CONFIG_H
00035 #include <config.h>
00036 #endif
00037
00038
00039
00040
00041 #include <string.h>
00042
00043
00044 #include <cpl.h>
00045
00046 #include <xsh_dfs.h>
00047 #include <xsh_data_pre.h>
00048 #include <xsh_utils.h>
00049 #include <xsh_parameters.h>
00050 #include <xsh_drl.h>
00051 #include <xsh_msg.h>
00052 #include <xsh_pfits.h>
00053 #include <xsh_error.h>
00054
00055
00056
00057
00058
00059
00060
00061 #define XSH_UTL_INTEGRATE_RECIPE_ID "xsh_util_integrate"
00062 #define XSH_UTL_INTEGRATE_RECIPE_AUTHOR "A.Modigliani"
00063 #define XSH_UTL_INTEGRATE_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00064 #define PRO_IMA "PRO_IMA_UVB"
00065 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00066
00067
00068
00069
00070 static int xsh_util_integrate_create(cpl_plugin *) ;
00071 static int xsh_util_integrate_exec(cpl_plugin *) ;
00072 static int xsh_util_integrate_destroy(cpl_plugin *) ;
00073 static int xsh_util_integrate(cpl_parameterlist *, cpl_frameset *) ;
00074
00075
00076
00077
00078
00079 static char
00080 xsh_util_integrate_description_short[] = "Integrate spectra";
00081 static char xsh_util_integrate_description[] =
00082 "This recipe performs spectra integration (with flux conservation).\n"
00083 "The input files should be list of files\n"
00084 "Information on relevant parameters can be found with\n"
00085 "esorex --params xsh_util_integrate\n"
00086 "esorex --help xsh_util_integrate\n"
00087 "\n";
00088
00089
00090
00091
00092
00097
00098
00100
00108
00109 int cpl_plugin_get_info(cpl_pluginlist * list)
00110 {
00111 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00112 cpl_plugin * plugin = &recipe->interface ;
00113
00114 cpl_plugin_init(plugin,
00115 CPL_PLUGIN_API,
00116 XSH_BINARY_VERSION,
00117 CPL_PLUGIN_TYPE_RECIPE,
00118 XSH_UTL_INTEGRATE_RECIPE_ID,
00119 xsh_util_integrate_description_short,
00120 xsh_util_integrate_description,
00121 XSH_UTL_INTEGRATE_RECIPE_AUTHOR,
00122 XSH_UTL_INTEGRATE_RECIPE_CONTACT,
00123 xsh_get_license(),
00124 xsh_util_integrate_create,
00125 xsh_util_integrate_exec,
00126 xsh_util_integrate_destroy) ;
00127
00128 cpl_pluginlist_append(list, plugin) ;
00129
00130 return 0;
00131 }
00132
00133
00142
00143 static int xsh_util_integrate_create(cpl_plugin * plugin)
00144 {
00145 cpl_recipe * recipe ;
00146 cpl_parameter * p ;
00147
00148
00149 xsh_init();
00150
00151
00152 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00153 recipe = (cpl_recipe *)plugin ;
00154 else return -1 ;
00155 cpl_error_reset();
00156
00157
00158
00159 recipe->parameters = cpl_parameterlist_new() ;
00160
00161
00162
00163 check( xsh_parameters_generic(XSH_UTL_INTEGRATE_RECIPE_ID,
00164 recipe->parameters ) ) ;
00165
00166
00167 p = cpl_parameter_new_range("xsh.xsh_util_integrate.binw",
00168 CPL_TYPE_DOUBLE,
00169 "Sampling bin [nm]",
00170 "xsh.xsh_util_integrate",1,0.01,100);
00171 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "binw") ;
00172 cpl_parameterlist_append(recipe->parameters, p) ;
00173
00174 cleanup:
00175
00176
00177 return 0;
00178 }
00179
00180
00186
00187 static int xsh_util_integrate_exec(cpl_plugin * plugin)
00188 {
00189 cpl_recipe * recipe ;
00190 int code=0;
00191 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00192
00193
00194 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00195 recipe = (cpl_recipe *)plugin ;
00196 else return -1 ;
00197 cpl_error_reset();
00198
00199 code = xsh_util_integrate(recipe->parameters, recipe->frames) ;
00200
00201
00202 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00203
00204
00205 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00206 }
00207
00208 return code ;
00209 }
00210
00211
00217
00218 static int xsh_util_integrate_destroy(cpl_plugin * plugin)
00219 {
00220 cpl_recipe * recipe ;
00221
00222
00223 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00224 recipe = (cpl_recipe *)plugin ;
00225 else return -1 ;
00226
00227 cpl_parameterlist_delete(recipe->parameters) ;
00228 return 0 ;
00229 }
00230
00231
00238
00239 static int
00240 xsh_util_integrate( cpl_parameterlist * parlist,
00241 cpl_frameset * frames)
00242 {
00243
00244 const char* recipe_tags[1] = {XSH_RAW_IMA_SLIT};
00245 int recipe_tags_size = 1;
00246
00247 cpl_parameter * param= NULL ;
00248
00249 cpl_frameset* raws = NULL;
00250 cpl_frameset* calib = NULL;
00251
00252 cpl_frame* std_obs=NULL;
00253 cpl_frame* std_cat=NULL;
00254 cpl_frame* atm_ext=NULL;
00255 cpl_frame* response=NULL;
00256
00257
00258 cpl_propertylist* plist=NULL;
00259
00260
00261 xsh_instrument* instrument = NULL;
00262 const char* fname=NULL;
00263 double binw=0;
00264 double exptime=0;
00265 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00266 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00267
00268
00269
00270 check(param=cpl_parameterlist_find(parlist,"xsh.xsh_util_integrate.binw"));
00271 check(binw=cpl_parameter_get_double(param));
00272
00273
00274 check( xsh_begin( frames, parlist, &instrument, &raws, &calib,
00275 recipe_tags, recipe_tags_size,
00276 XSH_UTL_INTEGRATE_RECIPE_ID, XSH_BINARY_VERSION,
00277 xsh_util_integrate_description_short ) ) ;
00278
00279 std_obs=xsh_find_frame_with_tag(raws,XSH_RAW_IMA_SLIT, instrument);
00280 std_cat=xsh_find_frame_with_tag(calib,XSH_FLUX_STD_CAT,instrument);
00281 atm_ext=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument);
00282
00283 fname=cpl_frame_get_filename(std_obs);
00284 plist=cpl_propertylist_load(fname,0);
00285 exptime=xsh_pfits_get_exptime(plist);
00286 xsh_msg("exptime=%g",exptime);
00287
00288 check(response=xsh_compute_response(std_obs,std_cat,atm_ext,NULL,
00289 instrument,exptime));
00290
00291 cleanup:
00292 xsh_free_frame(&response);
00293 xsh_free_frameset(&raws);
00294 xsh_free_frameset(&calib);
00295
00296 xsh_instrument_free( &instrument);
00297 xsh_free_propertylist(&plist);
00298 if (cpl_error_get_code()) {
00299 return -1 ;
00300 } else {
00301 return 0 ;
00302 }
00303
00304 }