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 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
00157
00158 cleanup:
00159
00160
00161 return 0;
00162 }
00163
00164
00170
00171 static int xsh_util_apply_response_exec(cpl_plugin * plugin)
00172 {
00173 cpl_recipe * recipe ;
00174 int code=0;
00175 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00176
00177
00178 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00179 recipe = (cpl_recipe *)plugin ;
00180 else return -1 ;
00181 cpl_error_reset();
00182
00183 code = xsh_util_apply_response(recipe->parameters, recipe->frames) ;
00184
00185
00186 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00187
00188
00189 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00190 }
00191
00192 return code ;
00193 }
00194
00195
00201
00202 static int xsh_util_apply_response_destroy(cpl_plugin * plugin)
00203 {
00204 cpl_recipe * recipe ;
00205
00206
00207 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00208 recipe = (cpl_recipe *)plugin ;
00209 else return -1 ;
00210
00211 cpl_parameterlist_delete(recipe->parameters) ;
00212 return 0 ;
00213 }
00214
00215
00222
00223 static int
00224 xsh_util_apply_response( cpl_parameterlist * parlist,
00225 cpl_frameset * framelist)
00226 {
00227
00228 int n=0;
00229 cpl_frame* response_frame=NULL;
00230 cpl_frame* atmos_ext_frame=NULL;
00231 cpl_frame* sci_2D_frame=NULL;
00232 cpl_frame* fluxcal_rect_2D_frame=NULL;
00233 cpl_frame* fluxcal_2D_frame=NULL;
00234 cpl_frame* nrm_2D_frame=NULL;
00235 cpl_frameset* raws=NULL;
00236 cpl_frameset* calib=NULL;
00237 xsh_instrument* instrument=NULL;
00238
00239 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_STARE,
00240 XSH_STD_TELL_SLIT_STARE,
00241 XSH_STD_FLUX_SLIT_STARE};
00242 int recipe_tags_size = 3;
00243 char file_tag[256];
00244 int merge_par = 0;
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_apply_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 check( response_frame = xsh_find_frame_with_tag(calib,XSH_RESPONSE_ORDER1D_SLIT,
00262 instrument));
00263
00264 check(atmos_ext_frame=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument));
00265
00266 check( sci_2D_frame = xsh_find_frame_with_tag(framelist,XSH_IMA,instrument));
00267
00268 if(response_frame != NULL) {
00269 sprintf(file_tag,"NORM_%s",cpl_frame_get_tag(sci_2D_frame));
00270 check(nrm_2D_frame=xsh_normalize_spectrum_ord(sci_2D_frame,atmos_ext_frame,0,
00271 instrument,file_tag));
00272 sprintf(file_tag,"FLUXCAL_%s",cpl_frame_get_tag(sci_2D_frame));
00273 check(fluxcal_rect_2D_frame=xsh_util_multiply_by_response_ord(sci_2D_frame,
00274 response_frame,
00275 file_tag));
00276 check( fluxcal_2D_frame = xsh_merge_ord(fluxcal_rect_2D_frame, instrument,
00277 merge_par,"PIPPO" ));
00278 }
00279 cleanup:
00280
00281 xsh_free_frame(&nrm_2D_frame);
00282 xsh_free_frame(&fluxcal_rect_2D_frame);
00283 xsh_free_frame(&fluxcal_2D_frame);
00284 xsh_free_frameset(&raws);
00285 xsh_free_frameset(&calib);
00286
00287 xsh_instrument_free(&instrument);
00288 if (cpl_error_get_code()) {
00289 return -1 ;
00290 } else {
00291 return 0 ;
00292 }
00293 }