00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027
00028
00029
00030 #include <string.h>
00031
00032
00033 #include <cpl.h>
00034
00035 #include <xsh_dfs.h>
00036 #include <xsh_data_pre.h>
00037 #include <xsh_utils.h>
00038 #include <xsh_parameters.h>
00039 #include <xsh_drl.h>
00040 #include <xsh_msg.h>
00041 #include <xsh_pfits.h>
00042 #include <xsh_error.h>
00043
00044
00045
00046
00047
00048
00049
00050 #define XSH_UTL_INTEGRATE_RECIPE_ID "xsh_util_integrate"
00051 #define XSH_UTL_INTEGRATE_RECIPE_AUTHOR "A.Modigliani"
00052 #define XSH_UTL_INTEGRATE_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00053 #define PRO_IMA "PRO_IMA_UVB"
00054 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00055
00056
00057
00058
00059 static int xsh_util_integrate_create(cpl_plugin *) ;
00060 static int xsh_util_integrate_exec(cpl_plugin *) ;
00061 static int xsh_util_integrate_destroy(cpl_plugin *) ;
00062 static int xsh_util_integrate(cpl_parameterlist *, cpl_frameset *) ;
00063
00064
00065
00066
00067
00068 static char
00069 xsh_util_integrate_description_short[] = "Integrate spectra";
00070 static char xsh_util_integrate_description[] =
00071 "This recipe performs spectra integration (with flux conservation).\n"
00072 "The input files should be list of files\n"
00073 "Information on relevant parameters can be found with\n"
00074 "esorex --params xsh_util_integrate\n"
00075 "esorex --help xsh_util_integrate\n"
00076 "\n";
00077
00078
00079
00080
00081
00086
00087
00089
00097
00098 int cpl_plugin_get_info(cpl_pluginlist * list)
00099 {
00100 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00101 cpl_plugin * plugin = &recipe->interface ;
00102
00103 cpl_plugin_init(plugin,
00104 CPL_PLUGIN_API,
00105 XSH_BINARY_VERSION,
00106 CPL_PLUGIN_TYPE_RECIPE,
00107 XSH_UTL_INTEGRATE_RECIPE_ID,
00108 xsh_util_integrate_description_short,
00109 xsh_util_integrate_description,
00110 XSH_UTL_INTEGRATE_RECIPE_AUTHOR,
00111 XSH_UTL_INTEGRATE_RECIPE_CONTACT,
00112 xsh_get_license(),
00113 xsh_util_integrate_create,
00114 xsh_util_integrate_exec,
00115 xsh_util_integrate_destroy) ;
00116
00117 cpl_pluginlist_append(list, plugin) ;
00118
00119 return 0;
00120 }
00121
00122
00131
00132 static int xsh_util_integrate_create(cpl_plugin * plugin)
00133 {
00134 cpl_recipe * recipe ;
00135 cpl_parameter * p ;
00136
00137
00138 xsh_init();
00139
00140
00141 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00142 recipe = (cpl_recipe *)plugin ;
00143 else return -1 ;
00144 cpl_error_reset();
00145
00146
00147
00148 recipe->parameters = cpl_parameterlist_new() ;
00149
00150
00151
00152 check( xsh_parameters_generic(XSH_UTL_INTEGRATE_RECIPE_ID,
00153 recipe->parameters ) ) ;
00154 xsh_parameters_decode_bp(XSH_UTL_INTEGRATE_RECIPE_ID,recipe->parameters,-1);
00155
00156 p = cpl_parameter_new_range("xsh.xsh_util_integrate.binw",
00157 CPL_TYPE_DOUBLE,
00158 "Sampling bin [nm]",
00159 "xsh.xsh_util_integrate",1,0.01,100);
00160 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "binw") ;
00161 cpl_parameterlist_append(recipe->parameters, p) ;
00162
00163 cleanup:
00164
00165
00166 return 0;
00167 }
00168
00169
00175
00176 static int xsh_util_integrate_exec(cpl_plugin * plugin)
00177 {
00178 cpl_recipe * recipe ;
00179 int code=0;
00180 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00181
00182
00183 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00184 recipe = (cpl_recipe *)plugin ;
00185 else return -1 ;
00186 cpl_error_reset();
00187
00188 code = xsh_util_integrate(recipe->parameters, recipe->frames) ;
00189
00190
00191 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00192
00193
00194 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00195 }
00196
00197 return code ;
00198 }
00199
00200
00206
00207 static int xsh_util_integrate_destroy(cpl_plugin * plugin)
00208 {
00209 cpl_recipe * recipe ;
00210
00211
00212 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00213 recipe = (cpl_recipe *)plugin ;
00214 else return -1 ;
00215
00216 cpl_parameterlist_delete(recipe->parameters) ;
00217 return 0 ;
00218 }
00219
00220
00227
00228 static int
00229 xsh_util_integrate( cpl_parameterlist * parlist,
00230 cpl_frameset * frames)
00231 {
00232
00233 const char* recipe_tags[1] = {XSH_RAW_IMA_SLIT};
00234 int recipe_tags_size = 1;
00235
00236 cpl_parameter * param= NULL ;
00237
00238 cpl_frameset* raws = NULL;
00239 cpl_frameset* calib = NULL;
00240
00241 cpl_frame* std_obs=NULL;
00242 cpl_frame* std_cat=NULL;
00243 cpl_frame* atm_ext=NULL;
00244 cpl_frame* response=NULL;
00245
00246
00247 cpl_propertylist* plist=NULL;
00248
00249
00250 xsh_instrument* instrument = NULL;
00251 const char* fname=NULL;
00252 double binw=0;
00253 double exptime=0;
00254 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00255 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00256
00257
00258
00259 check(param=cpl_parameterlist_find(parlist,"xsh.xsh_util_integrate.binw"));
00260 check(binw=cpl_parameter_get_double(param));
00261
00262
00263 check( xsh_begin( frames, parlist, &instrument, &raws, &calib,
00264 recipe_tags, recipe_tags_size,
00265 XSH_UTL_INTEGRATE_RECIPE_ID, XSH_BINARY_VERSION,
00266 xsh_util_integrate_description_short ) ) ;
00267
00268 std_obs=xsh_find_frame_with_tag(raws,XSH_RAW_IMA_SLIT, instrument);
00269 std_cat=xsh_find_frame_with_tag(calib,XSH_FLUX_STD_CAT,instrument);
00270 atm_ext=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument);
00271
00272 fname=cpl_frame_get_filename(std_obs);
00273 plist=cpl_propertylist_load(fname,0);
00274 exptime=xsh_pfits_get_exptime(plist);
00275 xsh_msg("exptime=%g",exptime);
00276
00277 check(response=xsh_compute_response(std_obs,std_cat,atm_ext,NULL,
00278 instrument,exptime));
00279
00280 cleanup:
00281 xsh_free_frame(&response);
00282 xsh_free_frameset(&raws);
00283 xsh_free_frameset(&calib);
00284
00285 xsh_instrument_free( &instrument);
00286 xsh_free_propertylist(&plist);
00287 if (cpl_error_get_code()) {
00288 return -1 ;
00289 } else {
00290 return 0 ;
00291 }
00292
00293 }