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