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
00157 cleanup:
00158
00159
00160 return 0;
00161 }
00162
00163
00169
00170 static int xsh_util_compute_response_exec(cpl_plugin * plugin)
00171 {
00172 cpl_recipe * recipe ;
00173 int code=0;
00174 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00175
00176
00177 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00178 recipe = (cpl_recipe *)plugin ;
00179 else return -1 ;
00180 cpl_error_reset();
00181
00182 code = xsh_util_compute_response(recipe->parameters, recipe->frames) ;
00183
00184
00185 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00186
00187
00188 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00189 }
00190
00191 return code ;
00192 }
00193
00194
00200
00201 static int xsh_util_compute_response_destroy(cpl_plugin * plugin)
00202 {
00203 cpl_recipe * recipe ;
00204
00205
00206 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00207 recipe = (cpl_recipe *)plugin ;
00208 else return -1 ;
00209
00210 cpl_parameterlist_delete(recipe->parameters) ;
00211 return 0 ;
00212 }
00213
00214
00221
00222 static int
00223 xsh_util_compute_response( cpl_parameterlist * parlist,
00224 cpl_frameset * framelist)
00225 {
00226
00227 int n=0;
00228 cpl_frame* high_abs_win_frame=NULL;
00229 cpl_frame* response_frame=NULL;
00230 cpl_frame* merged_frame=NULL;
00231 cpl_frame* atmext_frame=NULL;
00232 cpl_frame* flux_std_cat_frame=NULL;
00233
00234 cpl_frameset* raws=NULL;
00235 cpl_frameset* calib=NULL;
00236 xsh_instrument* instrument=NULL;
00237 double exptime=0;
00238 cpl_propertylist* plist=NULL;
00239 char file_name[80];
00240
00241 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_STARE,
00242 XSH_STD_TELL_SLIT_STARE,
00243 XSH_STD_FLUX_SLIT_STARE};
00244 int recipe_tags_size = 3;
00245
00246 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00247 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00248 check( xsh_begin( framelist, parlist, &instrument, &raws, &calib,
00249 recipe_tags, recipe_tags_size,
00250 RECIPE_ID,
00251 XSH_BINARY_VERSION,
00252 xsh_util_compute_response_description_short ) ) ;
00253
00254 n=cpl_frameset_get_size(framelist);
00255
00256 if(n<1) {
00257 xsh_msg_error("Empty input frame list!");
00258 goto cleanup ;
00259 }
00260
00261
00262
00263 check( merged_frame = xsh_find_frame_with_tag(framelist,XSH_IMA,instrument));
00264 plist=cpl_propertylist_load(cpl_frame_get_filename(merged_frame),0);
00265 exptime=xsh_pfits_get_exptime(plist);
00266 xsh_free_propertylist(&plist);
00267 atmext_frame=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument);
00268 if(atmext_frame==NULL) {
00269 xsh_msg_error("Provide atmospheric extinction frame");
00270 return CPL_ERROR_DATA_NOT_FOUND;
00271 }
00272
00273 flux_std_cat_frame=xsh_find_frame_with_tag(calib,XSH_FLUX_STD_CAT,instrument);
00274 if(flux_std_cat_frame==NULL) {
00275 xsh_msg_error("Provide std star catalog frame");
00276 return CPL_ERROR_DATA_NOT_FOUND;
00277 }
00278
00279 high_abs_win_frame=xsh_find_frame_with_tag(calib,XSH_HIGH_ABS_WIN,instrument);
00280
00281 check( response_frame = xsh_compute_response_ord( merged_frame,
00282 flux_std_cat_frame,
00283 atmext_frame,
00284 high_abs_win_frame,
00285 instrument,
00286 exptime ));
00287
00288 check(xsh_frame_table_monitor_flux_qc(response_frame,"LAMBDA","FLUX","RESP",
00289 instrument));
00290
00291 cleanup:
00292 xsh_free_frameset(&raws);
00293 xsh_free_frameset(&calib);
00294 xsh_free_frame(&response_frame);
00295 xsh_free_propertylist(&plist);
00296 xsh_instrument_free(&instrument );
00297 if (cpl_error_get_code()) {
00298 return -1 ;
00299 } else {
00300 return 0 ;
00301 }
00302 }