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_drl.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_pfits.h>
00048 #include <xsh_error.h>
00049
00050
00051
00052
00053
00054
00055 #define RECIPE_ID "xsh_util_apply_response"
00056 #define RECIPE_AUTHOR "A.Modigliani"
00057 #define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00058 #define PRO_IMA "PRO_IMA"
00059 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00060
00061
00062
00063
00064 static int xsh_util_apply_response_create(cpl_plugin *) ;
00065 static int xsh_util_apply_response_exec(cpl_plugin *) ;
00066 static int xsh_util_apply_response_destroy(cpl_plugin *) ;
00067 static int xsh_util_apply_response(cpl_parameterlist *, cpl_frameset *) ;
00068
00069
00070
00071
00072
00073 static char
00074 xsh_util_apply_response_description_short[] = "Shift an image along X or Y";
00075 static char xsh_util_apply_response_description[] =
00076 "This recipe applies response to 2D merged frame.\n"
00077 "Information on relevant parameters can be found with\n"
00078 "esorex --params xsh_util_apply_response\n"
00079 "esorex --help xsh_util_apply_response\n"
00080 "\n";
00081
00082
00083
00084
00085
00090
00091
00093
00101
00102 int cpl_plugin_get_info(cpl_pluginlist * list)
00103 {
00104 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00105 cpl_plugin * plugin = &recipe->interface ;
00106
00107 cpl_plugin_init(plugin,
00108 CPL_PLUGIN_API,
00109 XSH_BINARY_VERSION,
00110 CPL_PLUGIN_TYPE_RECIPE,
00111 RECIPE_ID,
00112 xsh_util_apply_response_description_short,
00113 xsh_util_apply_response_description,
00114 RECIPE_AUTHOR,
00115 RECIPE_CONTACT,
00116 xsh_get_license(),
00117 xsh_util_apply_response_create,
00118 xsh_util_apply_response_exec,
00119 xsh_util_apply_response_destroy) ;
00120
00121 cpl_pluginlist_append(list, plugin) ;
00122
00123 return 0;
00124 }
00125
00126
00135
00136 static int xsh_util_apply_response_create(cpl_plugin * plugin)
00137 {
00138 cpl_recipe * recipe ;
00139
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 check(xsh_parameters_merge_ord_create(RECIPE_ID,
00158 recipe->parameters,
00159 WEIGHTED_MERGE_METHOD)) ;
00160
00161 cleanup:
00162
00163
00164 return 0;
00165 }
00166
00167
00173
00174 static int xsh_util_apply_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_apply_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_apply_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_apply_response( cpl_parameterlist * parlist,
00228 cpl_frameset * framelist)
00229 {
00230
00231 int n=0;
00232 cpl_frame* response_frame=NULL;
00233 cpl_frame* atmos_ext_frame=NULL;
00234 cpl_frame* sci_2D_frame=NULL;
00235 cpl_frame* fluxcal_rect_2D_frame=NULL;
00236 cpl_frame* fluxcal_2D_frame=NULL;
00237 cpl_frame* nrm_2D_frame=NULL;
00238 cpl_frameset* raws=NULL;
00239 cpl_frameset* calib=NULL;
00240 xsh_instrument* instrument=NULL;
00241
00242 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_STARE,
00243 XSH_STD_TELL_SLIT_STARE,
00244 XSH_STD_FLUX_SLIT_STARE};
00245 int recipe_tags_size = 3;
00246 char file_tag[80];
00247 xsh_merge_param * merge_par = NULL;
00248
00249 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00250 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00251 check( xsh_begin( framelist, parlist, &instrument, &raws, &calib,
00252 recipe_tags, recipe_tags_size,
00253 RECIPE_ID,
00254 XSH_BINARY_VERSION,
00255 xsh_util_apply_response_description_short ) ) ;
00256
00257 n=cpl_frameset_get_size(framelist);
00258
00259 if(n<1) {
00260 xsh_msg_error("Empty input frame list!");
00261 goto cleanup ;
00262 }
00263 check( merge_par = xsh_parameters_merge_ord_get(RECIPE_ID,parlist));
00264
00265 check( response_frame = xsh_find_frame_with_tag(calib,XSH_RESPONSE_ORDER1D_SLIT,
00266 instrument));
00267
00268 check(atmos_ext_frame=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument));
00269
00270 check( sci_2D_frame = xsh_find_frame_with_tag(framelist,XSH_IMA,instrument));
00271
00272 if(response_frame != NULL) {
00273 sprintf(file_tag,"NORM_%s",cpl_frame_get_tag(sci_2D_frame));
00274 check(nrm_2D_frame=xsh_normalize_spectrum_ord(sci_2D_frame,atmos_ext_frame,0,
00275 instrument,file_tag));
00276 sprintf(file_tag,"FLUXCAL_%s",cpl_frame_get_tag(sci_2D_frame));
00277 check(fluxcal_rect_2D_frame=xsh_util_multiply_by_response_ord(sci_2D_frame,
00278 response_frame,
00279 file_tag));
00280 check( fluxcal_2D_frame = xsh_merge_ord(fluxcal_rect_2D_frame, instrument,
00281 merge_par,"PIPPO" ));
00282 }
00283 cleanup:
00284
00285 xsh_free_frame(&nrm_2D_frame);
00286 xsh_free_frame(&fluxcal_rect_2D_frame);
00287 xsh_free_frame(&fluxcal_2D_frame);
00288 xsh_free_frameset(&raws);
00289 xsh_free_frameset(&calib);
00290
00291 xsh_instrument_free(&instrument);
00292 if (cpl_error_get_code()) {
00293 return -1 ;
00294 } else {
00295 return 0 ;
00296 }
00297 }