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