X-shooter Pipeline Reference Manual 3.8.15
xsh_util_apply_response.c
Go to the documentation of this file.
1/* $Id: xsh_util_apply_response.c,v 1.11 2012-12-18 14:12:51 amodigli Exp $
2 *
3 * This file is part of the XSHOOTER Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: amodigli $
23 * $Date: 2012-12-18 14:12:51 $
24 * $Revision: 1.11 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 ----------------------------------------------------------------------------*/
35#include <string.h>
36
37/* cpl */
38#include <cpl.h>
39
40/* irplib */
41#include <xsh_dfs.h>
42//#include <xsh_data_pre.h>
43#include <xsh_parameters.h>
44#include <xsh_utils.h>
45#include <xsh_drl.h>
46#include <xsh_msg.h>
47#include <xsh_pfits.h>
48#include <xsh_error.h>
49
50
51/*-----------------------------------------------------------------------------
52 Defines
53 ----------------------------------------------------------------------------*/
54
55#define RECIPE_ID "xsh_util_apply_response"
56#define RECIPE_AUTHOR "A.Modigliani"
57#define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
58#define PRO_IMA "PRO_IMA"
59#define KEY_VALUE_HPRO_DID "PRO-1.15"
60/*-----------------------------------------------------------------------------
61 Functions prototypes
62 ----------------------------------------------------------------------------*/
63
64static int xsh_util_apply_response_create(cpl_plugin *) ;
65static int xsh_util_apply_response_exec(cpl_plugin *) ;
66static int xsh_util_apply_response_destroy(cpl_plugin *) ;
67static int xsh_util_apply_response(cpl_parameterlist *, cpl_frameset *) ;
68
69/*-----------------------------------------------------------------------------
70 Static variables
71 ----------------------------------------------------------------------------*/
72
73static char
74xsh_util_apply_response_description_short[] = "Shift an image along X or Y";
76 "This recipe applies response to 2D merged frame.\n"
77 "Information on relevant parameters can be found with\n"
78 "esorex --params xsh_util_apply_response\n"
79 "esorex --help xsh_util_apply_response\n"
80 "\n";
81
82/*-----------------------------------------------------------------------------
83 Functions code
84 ----------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
93/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102int cpl_plugin_get_info(cpl_pluginlist * list)
103{
104 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
105 cpl_plugin * plugin = &recipe->interface ;
106
107 cpl_plugin_init(plugin,
108 CPL_PLUGIN_API,
109 XSH_BINARY_VERSION,
110 CPL_PLUGIN_TYPE_RECIPE,
111 RECIPE_ID,
120
121 cpl_pluginlist_append(list, plugin) ;
122
123 return 0;
124}
125
126/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136static int xsh_util_apply_response_create(cpl_plugin * plugin)
137{
138 cpl_recipe * recipe ;
139 //cpl_parameter * p ;
140
141 /* Reset library state */
142 xsh_init();
143
144 /* Get the recipe out of the plugin */
145 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
146 recipe = (cpl_recipe *)plugin ;
147 else return -1 ;
148 cpl_error_reset();
149
150
151 /* Create the parameters list in the cpl_recipe object */
152 recipe->parameters = cpl_parameterlist_new() ;
153
154 /* Set generic parameters (common to all recipes) */
155 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
156 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
157
158 cleanup:
159
160 /* Return */
161 return 0;
162}
163
164/*---------------------------------------------------------------------------*/
170/*---------------------------------------------------------------------------*/
171static int xsh_util_apply_response_exec(cpl_plugin * plugin)
172{
173 cpl_recipe * recipe ;
174 int code=0;
175 cpl_errorstate initial_errorstate = cpl_errorstate_get();
176
177 /* Get the recipe out of the plugin */
178 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
179 recipe = (cpl_recipe *)plugin ;
180 else return -1 ;
181 cpl_error_reset();
182
183 code = xsh_util_apply_response(recipe->parameters, recipe->frames) ;
184
185
186 if (!cpl_errorstate_is_equal(initial_errorstate)) {
187 /* Dump the error history since recipe execution start.
188 At this point the recipe cannot recover from the error */
189 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
190 }
191
192 return code ;
193}
194
195/*---------------------------------------------------------------------------*/
201/*---------------------------------------------------------------------------*/
202static int xsh_util_apply_response_destroy(cpl_plugin * plugin)
203{
204 cpl_recipe * recipe ;
205
206 /* Get the recipe out of the plugin */
207 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
208 recipe = (cpl_recipe *)plugin ;
209 else return -1 ;
210
211 cpl_parameterlist_delete(recipe->parameters) ;
212 return 0 ;
213}
214
215/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223static int
224xsh_util_apply_response( cpl_parameterlist * parlist,
225 cpl_frameset * framelist)
226{
227 //cpl_parameter * param= NULL ;
228 int n=0;
229 cpl_frame* response_frame=NULL;
230 cpl_frame* atmos_ext_frame=NULL;
231 cpl_frame* sci_2D_frame=NULL;
232 cpl_frame* fluxcal_rect_2D_frame=NULL;
233 cpl_frame* fluxcal_2D_frame=NULL;
234 cpl_frame* nrm_2D_frame=NULL;
235 cpl_frameset* raws=NULL;
236 cpl_frameset* calib=NULL;
238
239 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_STARE,
242 int recipe_tags_size = 3;
243 char file_tag[256];
244 int merge_par = 0;
245
246 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
247 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
248 check( xsh_begin( framelist, parlist, &instrument, &raws, &calib,
249 recipe_tags, recipe_tags_size,
250 RECIPE_ID,
251 XSH_BINARY_VERSION,
253
254 n=cpl_frameset_get_size(framelist);
255
256 if(n<1) {
257 xsh_msg_error("Empty input frame list!");
258 goto cleanup ;
259 }
260
262 instrument));
263
265
266 check( sci_2D_frame = xsh_find_frame_with_tag(framelist,XSH_IMA,instrument));
267
268 if(response_frame != NULL) {
269 sprintf(file_tag,"NORM_%s",cpl_frame_get_tag(sci_2D_frame));
270 check(nrm_2D_frame=xsh_normalize_spectrum_ord(sci_2D_frame,atmos_ext_frame,0,
271 instrument,file_tag));
272 sprintf(file_tag,"FLUXCAL_%s",cpl_frame_get_tag(sci_2D_frame));
273 check(fluxcal_rect_2D_frame=xsh_util_multiply_by_response_ord(sci_2D_frame,
274 response_frame,
275 file_tag));
276 check( fluxcal_2D_frame = xsh_merge_ord(fluxcal_rect_2D_frame, instrument,
277 merge_par,"PIPPO" ));
278 }
279 cleanup:
280
281 xsh_free_frame(&nrm_2D_frame);
282 xsh_free_frame(&fluxcal_rect_2D_frame);
283 xsh_free_frame(&fluxcal_2D_frame);
284 xsh_free_frameset(&raws);
285 xsh_free_frameset(&calib);
286
288 if (cpl_error_get_code()) {
289 return -1 ;
290 } else {
291 return 0 ;
292 }
293}
static xsh_instrument * instrument
#define check(COMMAND)
Definition: xsh_error.h:71
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
cpl_frame * xsh_merge_ord(cpl_frame *sci_frame, xsh_instrument *instrument, int merge, const char *rec_prefix)
Merge orders of the rectified frame using merge parameters.
#define xsh_msg_error(...)
Print an error message.
Definition: xsh_msg.h:62
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_apply_response_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_apply_response(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_apply_response_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_apply_response_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
cpl_frame * xsh_normalize_spectrum_ord(const cpl_frame *obj_frame, const cpl_frame *atm_ext_frame, cpl_boolean correct_binning, xsh_instrument *instrument, const char *tag_o)
Normalize a spectrum.
Definition: xsh_utils.c:5893
cpl_frame * xsh_util_multiply_by_response_ord(cpl_frame *extracted_sci, cpl_frame *response, const char *tag_o)
Multiply input frame by response frame.
Definition: xsh_utils.c:5016
const char * xsh_get_license(void)
Get the pipeline copyright and license.
Definition: xsh_utils.c:1193
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
cpl_error_code xsh_begin(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument **instrument, cpl_frameset **raws, cpl_frameset **calib, const char *tag_list[], int tag_list_size, const char *recipe_id, unsigned int binary_version, const char *short_descr)
Recipe initialization.
Definition: xsh_utils.c:1244
int n
Definition: xsh_detmon_lg.c:92
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
#define XSH_STD_TELL_SLIT_STARE
Definition: xsh_dfs.h:462
#define XSH_ATMOS_EXT
Definition: xsh_dfs.h:1191
#define XSH_STD_FLUX_SLIT_STARE
Definition: xsh_dfs.h:449
#define XSH_IMA
Definition: xsh_dfs.h:236
#define XSH_OBJECT_SLIT_STARE
Definition: xsh_dfs.h:226
#define XSH_RESPONSE_ORDER1D_SLIT
Definition: xsh_dfs.h:1165
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
#define RECIPE_CONTACT
static char xsh_util_apply_response_description_short[]
#define RECIPE_ID
#define RECIPE_AUTHOR
static char xsh_util_apply_response_description[]