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
00041 #include <xsh_dfs.h>
00042
00043 #include <xsh_parameters.h>
00044 #include <xsh_utils.h>
00045 #include <xsh_utils_table.h>
00046 #include <xsh_drl.h>
00047 #include <xsh_msg.h>
00048 #include <xsh_pfits.h>
00049 #include <xsh_error.h>
00050
00051
00052
00053
00054
00055
00056 #define RECIPE_ID "xsh_util_compute_response"
00057 #define RECIPE_AUTHOR "A.Modigliani"
00058 #define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00059 #define PRO_IMA "PRO_IMA"
00060 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00061
00062
00063
00064
00065 static int xsh_util_compute_response_create(cpl_plugin *) ;
00066 static int xsh_util_compute_response_exec(cpl_plugin *) ;
00067 static int xsh_util_compute_response_destroy(cpl_plugin *) ;
00068 static int xsh_util_compute_response(cpl_parameterlist *, cpl_frameset *) ;
00069
00070
00071
00072
00073
00074 static char
00075 xsh_util_compute_response_description_short[] = "Compute response";
00076 static char xsh_util_compute_response_description[] =
00077 "This recipe compute response frame.\n"
00078 "Information on relevant parameters can be found with\n"
00079 "esorex --params xsh_util_compute_response\n"
00080 "esorex --help xsh_util_compute_response\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 RECIPE_ID,
00113 xsh_util_compute_response_description_short,
00114 xsh_util_compute_response_description,
00115 RECIPE_AUTHOR,
00116 RECIPE_CONTACT,
00117 xsh_get_license(),
00118 xsh_util_compute_response_create,
00119 xsh_util_compute_response_exec,
00120 xsh_util_compute_response_destroy) ;
00121
00122 cpl_pluginlist_append(list, plugin) ;
00123
00124 return 0;
00125 }
00126
00127
00136
00137 static int xsh_util_compute_response_create(cpl_plugin * plugin)
00138 {
00139 cpl_recipe * recipe ;
00140
00141
00142 xsh_init();
00143
00144
00145 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00146 recipe = (cpl_recipe *)plugin ;
00147 else return -1 ;
00148 cpl_error_reset();
00149
00150
00151
00152 recipe->parameters = cpl_parameterlist_new() ;
00153
00154
00155 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00156 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
00157 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00158 "correct-tellurics", TRUE,
00159 "TRUE if during response computation we apply telluric correction"));
00160
00161 cleanup:
00162
00163
00164 return 0;
00165 }
00166
00167
00173
00174 static int xsh_util_compute_response_exec(cpl_plugin * plugin)
00175 {
00176 cpl_recipe * recipe ;
00177 int code=0;
00178 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00179
00180
00181 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00182 recipe = (cpl_recipe *)plugin ;
00183 else return -1 ;
00184 cpl_error_reset();
00185
00186 code = xsh_util_compute_response(recipe->parameters, recipe->frames) ;
00187
00188
00189 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00190
00191
00192 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00193 }
00194
00195 return code ;
00196 }
00197
00198
00204
00205 static int xsh_util_compute_response_destroy(cpl_plugin * plugin)
00206 {
00207 cpl_recipe * recipe ;
00208
00209
00210 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00211 recipe = (cpl_recipe *)plugin ;
00212 else return -1 ;
00213
00214 cpl_parameterlist_delete(recipe->parameters) ;
00215 return 0 ;
00216 }
00217
00218
00225
00226 static int
00227 xsh_util_compute_response( cpl_parameterlist * parlist,
00228 cpl_frameset * framelist)
00229 {
00230
00231 int n=0;
00232 cpl_frame* high_abs_win_frame=NULL;
00233 cpl_frame* response_frame=NULL;
00234 cpl_frame* merged_frame=NULL;
00235 cpl_frame* atmext_frame=NULL;
00236 cpl_frame* flux_std_cat_frame=NULL;
00237
00238 cpl_frameset* raws=NULL;
00239 cpl_frameset* calib=NULL;
00240 xsh_instrument* instrument=NULL;
00241 double exptime=0;
00242 cpl_propertylist* plist=NULL;
00243 cpl_frame* tell_mod_cat=NULL;
00244 int corr_tell=0;
00245 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_STARE,
00246 XSH_STD_TELL_SLIT_STARE,
00247 XSH_STD_FLUX_SLIT_STARE};
00248 int recipe_tags_size = 3;
00249
00250 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00251 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00252 check( xsh_begin( framelist, parlist, &instrument, &raws, &calib,
00253 recipe_tags, recipe_tags_size,
00254 RECIPE_ID,
00255 XSH_BINARY_VERSION,
00256 xsh_util_compute_response_description_short ) ) ;
00257
00258 n=cpl_frameset_get_size(framelist);
00259
00260 if(n<1) {
00261 xsh_msg_error("Empty input frame list!");
00262 goto cleanup ;
00263 }
00264
00265 check( corr_tell = xsh_parameters_get_boolean( parlist, RECIPE_ID,
00266 "correct-tellurics"));
00267 tell_mod_cat=xsh_find_frame_with_tag(calib,XSH_TELL_MOD_CAT,instrument);
00268
00269 check( merged_frame = xsh_find_frame_with_tag(framelist,XSH_IMA,instrument));
00270 plist=cpl_propertylist_load(cpl_frame_get_filename(merged_frame),0);
00271 exptime=xsh_pfits_get_exptime(plist);
00272 xsh_free_propertylist(&plist);
00273 atmext_frame=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument);
00274 if(atmext_frame==NULL) {
00275 xsh_msg_error("Provide atmospheric extinction frame");
00276 return CPL_ERROR_DATA_NOT_FOUND;
00277 }
00278
00279 flux_std_cat_frame=xsh_find_frame_with_tag(calib,XSH_FLUX_STD_CAT,instrument);
00280 if(flux_std_cat_frame==NULL) {
00281 xsh_msg_error("Provide std star catalog frame");
00282 return CPL_ERROR_DATA_NOT_FOUND;
00283 }
00284
00285 high_abs_win_frame=xsh_find_frame_with_tag(calib,XSH_HIGH_ABS_WIN,instrument);
00286
00287 check( response_frame = xsh_compute_response2( merged_frame,
00288 flux_std_cat_frame,
00289 atmext_frame,
00290 high_abs_win_frame,
00291 tell_mod_cat,
00292 instrument,
00293 exptime,corr_tell ));
00294
00295 check(xsh_frame_table_monitor_flux_qc(response_frame,"LAMBDA","RESPONSE","RESP",
00296 instrument));
00297
00298 cleanup:
00299 xsh_free_frameset(&raws);
00300 xsh_free_frameset(&calib);
00301 xsh_free_frame(&response_frame);
00302 xsh_free_propertylist(&plist);
00303 xsh_instrument_free(&instrument );
00304 if (cpl_error_get_code()) {
00305 return -1 ;
00306 } else {
00307 return 0 ;
00308 }
00309 }