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 #include <math.h>
00037
00038
00039 #include <cpl.h>
00040
00041 #include <xsh_dfs.h>
00042 #include <xsh_data_pre.h>
00043 #include <xsh_parameters.h>
00044 #include <xsh_drl.h>
00045 #include <xsh_msg.h>
00046 #include <xsh_pfits.h>
00047 #include <xsh_pfits_qc.h>
00048 #include <xsh_error.h>
00049 #include <xsh_utils_image.h>
00050 #include <xsh_utils_table.h>
00051 #include <xsh_utils_efficiency.h>
00052
00053
00054
00055
00056
00057
00058 #define RECIPE_ID "xsh_util_efficiency1d"
00059 #define RECIPE_AUTHOR "A.Modigliani"
00060 #define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00061 #define PRO_IMA "PRO_IMA_UVB"
00062 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00063
00064 #define SPEED_LIGHT 2.99792458*1.E8
00065 #define TEL_AREA 51.2e4
00066
00067
00068
00069
00070 static int xsh_util_efficiency1d_create(cpl_plugin *) ;
00071 static int xsh_util_efficiency1d_exec(cpl_plugin *) ;
00072 static int xsh_util_efficiency1d_destroy(cpl_plugin *) ;
00073 static int xsh_util_efficiency1d(cpl_parameterlist *, cpl_frameset *) ;
00074
00075
00076
00077
00078
00079 static char
00080 xsh_util_efficiency1d_description_short[] = "Compute efficiency";
00081 static char xsh_util_efficiency1d_description[] =
00082 "This recipe compute efficiency.\n"
00083 "The input files should be tagged as: \n"
00084 "input observed spectrum: RAW_IMA_SLIT_arm,\n"
00085 "input reference spectrum: FLUX_STD_TABLE_arm,\n"
00086 "input atmospheric extintion table: EXTCOEFF_TABLE_arm)\n"
00087 "The output is a table with efficiency as function of wavelength\n"
00088 "Information on relevant parameters can be found with\n"
00089 "esorex --params xsh_util_efficiency1d\n"
00090 "esorex --help xsh_util_efficiency1d\n"
00091 "\n";
00092
00093
00094
00095
00096
00101
00102
00104
00112
00113 int cpl_plugin_get_info(cpl_pluginlist * list)
00114 {
00115 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00116 cpl_plugin * plugin = &recipe->interface ;
00117
00118 cpl_plugin_init(plugin,
00119 CPL_PLUGIN_API,
00120 XSH_BINARY_VERSION,
00121 CPL_PLUGIN_TYPE_RECIPE,
00122 RECIPE_ID,
00123 xsh_util_efficiency1d_description_short,
00124 xsh_util_efficiency1d_description,
00125 RECIPE_AUTHOR,
00126 RECIPE_CONTACT,
00127 xsh_get_license(),
00128 xsh_util_efficiency1d_create,
00129 xsh_util_efficiency1d_exec,
00130 xsh_util_efficiency1d_destroy) ;
00131
00132 cpl_pluginlist_append(list, plugin) ;
00133
00134 return 0;
00135 }
00136
00137
00146
00147 static int xsh_util_efficiency1d_create(cpl_plugin * plugin)
00148 {
00149 cpl_recipe * recipe ;
00150
00151
00152 xsh_init();
00153
00154
00155 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00156 recipe = (cpl_recipe *)plugin ;
00157 else return -1 ;
00158 cpl_error_reset();
00159
00160
00161
00162 recipe->parameters = cpl_parameterlist_new() ;
00163
00164
00165
00166 check( xsh_parameters_generic(RECIPE_ID,
00167 recipe->parameters ) ) ;
00168
00169 cleanup:
00170
00171
00172 return 0;
00173 }
00174
00175
00181
00182 static int xsh_util_efficiency1d_exec(cpl_plugin * plugin)
00183 {
00184 cpl_recipe * recipe ;
00185 int code=0;
00186 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00187
00188
00189 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00190 recipe = (cpl_recipe *)plugin ;
00191 else return -1 ;
00192 cpl_error_reset();
00193
00194 code = xsh_util_efficiency1d(recipe->parameters, recipe->frames) ;
00195
00196
00197 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00198
00199
00200 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00201 }
00202
00203 return code ;
00204 }
00205
00206
00212
00213 static int xsh_util_efficiency1d_destroy(cpl_plugin * plugin)
00214 {
00215 cpl_recipe * recipe ;
00216
00217
00218 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00219 recipe = (cpl_recipe *)plugin ;
00220 else return -1 ;
00221
00222 cpl_parameterlist_delete(recipe->parameters) ;
00223 return 0 ;
00224 }
00225
00226
00227
00228
00235
00236 static int
00237 xsh_util_efficiency1d( cpl_parameterlist * parlist,
00238 cpl_frameset * frames)
00239 {
00240 const char* recipe_tags[1] = {XSH_RAW_IMA_SLIT};
00241 int recipe_tags_size = 1;
00242
00243 xsh_instrument* instrument=NULL;
00244
00245 cpl_frameset* raws=NULL;
00246 cpl_frameset* calib=NULL;
00247 cpl_frame* frm_std_cat=NULL;
00248 cpl_frame* frm_atmext=NULL;
00249 cpl_frame* frm_eff=NULL;
00250 cpl_frame* frm_sci=NULL;
00251
00252 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00253 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00254
00255
00256 check( xsh_begin( frames, parlist, &instrument, &raws, &calib,
00257 recipe_tags, recipe_tags_size,
00258 RECIPE_ID, XSH_BINARY_VERSION,
00259 xsh_util_efficiency1d_description_short ) ) ;
00260
00261
00262
00263 frm_atmext=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument);
00264 if(frm_atmext==NULL) {
00265 xsh_msg_error("Provide atmospheric extinction frame");
00266 return CPL_ERROR_DATA_NOT_FOUND;
00267 }
00268
00269 frm_std_cat=xsh_find_frame_with_tag(calib,XSH_FLUX_STD_CAT,instrument);
00270 if(frm_std_cat==NULL) {
00271 xsh_msg_error("Provide std star catalog frame");
00272 return CPL_ERROR_DATA_NOT_FOUND;
00273 }
00274
00275 if( (frm_sci=xsh_find_frame_with_tag(frames,XSH_RAW_IMA_SLIT,
00276 instrument)) == NULL) {
00277 goto cleanup;
00278 }
00279
00280 check(frm_eff=xsh_efficiency_compute(frm_sci,frm_std_cat,frm_atmext,
00281 instrument));
00282
00283 check(xsh_frame_table_monitor_flux_qc(frm_eff,"WAVELENGTH","EFF","EFF",
00284 instrument));
00285
00286 check(xsh_add_product_table_multi(frm_eff, frames,parlist,
00287 RECIPE_ID, instrument));
00288
00289 cleanup:
00290
00291 xsh_free_frame(&frm_eff);
00292 xsh_free_frameset(&raws);
00293 xsh_free_frameset(&calib);
00294 xsh_instrument_free( &instrument);
00295
00296 if (cpl_error_get_code()) {
00297 return -1 ;
00298 } else {
00299 return 0 ;
00300 }
00301
00302 }