X-shooter Pipeline Reference Manual 3.8.15
xsh_util_compute_response.c
Go to the documentation of this file.
1/* $Id: xsh_util_compute_response.c,v 1.19 2013-08-29 10:50:46 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: 2013-08-29 10:50:46 $
24 * $Revision: 1.19 $
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_utils_table.h>
46#include <xsh_drl.h>
47#include <xsh_msg.h>
48#include <xsh_pfits.h>
49#include <xsh_error.h>
50
51
52/*-----------------------------------------------------------------------------
53 Defines
54 ----------------------------------------------------------------------------*/
55
56#define RECIPE_ID "xsh_util_compute_response"
57#define RECIPE_AUTHOR "A.Modigliani"
58#define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
59#define PRO_IMA "PRO_IMA"
60#define KEY_VALUE_HPRO_DID "PRO-1.15"
61/*-----------------------------------------------------------------------------
62 Functions prototypes
63 ----------------------------------------------------------------------------*/
64
65static int xsh_util_compute_response_create(cpl_plugin *) ;
66static int xsh_util_compute_response_exec(cpl_plugin *) ;
67static int xsh_util_compute_response_destroy(cpl_plugin *) ;
68static int xsh_util_compute_response(cpl_parameterlist *, cpl_frameset *) ;
69
70/*-----------------------------------------------------------------------------
71 Static variables
72 ----------------------------------------------------------------------------*/
73
74static char
77 "This recipe compute response frame.\n"
78 "Information on relevant parameters can be found with\n"
79 "esorex --params xsh_util_compute_response\n"
80 "esorex --help xsh_util_compute_response\n"
81 "\n";
82
83/*-----------------------------------------------------------------------------
84 Functions code
85 ----------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
92
94/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103int cpl_plugin_get_info(cpl_pluginlist * list)
104{
105 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
106 cpl_plugin * plugin = &recipe->interface ;
107
108 cpl_plugin_init(plugin,
109 CPL_PLUGIN_API,
110 XSH_BINARY_VERSION,
111 CPL_PLUGIN_TYPE_RECIPE,
112 RECIPE_ID,
121
122 cpl_pluginlist_append(list, plugin) ;
123
124 return 0;
125}
126
127/*---------------------------------------------------------------------------*/
136/*---------------------------------------------------------------------------*/
137static int xsh_util_compute_response_create(cpl_plugin * plugin)
138{
139 cpl_recipe * recipe ;
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 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
158 "correct-tellurics", TRUE,
159 "TRUE if during response computation we apply telluric correction"));
160
161 cleanup:
162
163 /* Return */
164 return 0;
165}
166
167/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174static int xsh_util_compute_response_exec(cpl_plugin * plugin)
175{
176 cpl_recipe * recipe ;
177 int code=0;
178 cpl_errorstate initial_errorstate = cpl_errorstate_get();
179
180 /* Get the recipe out of the plugin */
181 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
182 recipe = (cpl_recipe *)plugin ;
183 else return -1 ;
184 cpl_error_reset();
185
186 code = xsh_util_compute_response(recipe->parameters, recipe->frames) ;
187
188
189 if (!cpl_errorstate_is_equal(initial_errorstate)) {
190 /* Dump the error history since recipe execution start.
191 At this point the recipe cannot recover from the error */
192 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
193 }
194
195 return code ;
196}
197
198/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205static int xsh_util_compute_response_destroy(cpl_plugin * plugin)
206{
207 cpl_recipe * recipe ;
208
209 /* Get the recipe out of the plugin */
210 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
211 recipe = (cpl_recipe *)plugin ;
212 else return -1 ;
213
214 cpl_parameterlist_delete(recipe->parameters) ;
215 return 0 ;
216}
217
218/*---------------------------------------------------------------------------*/
225/*---------------------------------------------------------------------------*/
226static int
227xsh_util_compute_response( cpl_parameterlist * parlist,
228 cpl_frameset * framelist)
229{
230
231 int n=0;
232 cpl_frame* high_abs_win_frame=NULL;
233 cpl_frame* response_frame=NULL;
234 cpl_frame* merged_frame=NULL;
235 cpl_frame* atmext_frame=NULL;
236 cpl_frame* flux_std_cat_frame=NULL;
237
238 cpl_frameset* raws=NULL;
239 cpl_frameset* calib=NULL;
241 double exptime=0;
242 cpl_propertylist* plist=NULL;
243 cpl_frame* tell_mod_cat=NULL;
244 cpl_frame* resp_fit_points_cat_frame=NULL;
245 int corr_tell=0;
246 int ndit=0;
247 double dit=0;
248
249 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_STARE,
252 int recipe_tags_size = 3;
253
254 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
255 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
256 check( xsh_begin( framelist, parlist, &instrument, &raws, &calib,
257 recipe_tags, recipe_tags_size,
258 RECIPE_ID,
259 XSH_BINARY_VERSION,
261
262 n=cpl_frameset_get_size(framelist);
263
264 if(n<1) {
265 xsh_msg_error("Empty input frame list!");
266 goto cleanup ;
267 }
268
269 check( corr_tell = xsh_parameters_get_boolean( parlist, RECIPE_ID,
270 "correct-tellurics"));
272
273 check( merged_frame = xsh_find_frame_with_tag(framelist,XSH_IMA,instrument));
274 plist=cpl_propertylist_load(cpl_frame_get_filename(merged_frame),0);
276 dit = xsh_pfits_get_dit(plist);
277 ndit = xsh_pfits_get_ndit(plist);
278 exptime=dit*ndit;
279 } else {
281 }
282 xsh_free_propertylist(&plist);
284
285 if(atmext_frame==NULL) {
286 xsh_msg_error("Provide atmospheric extinction frame");
287 return CPL_ERROR_DATA_NOT_FOUND;
288 }
289
290 flux_std_cat_frame=xsh_find_frame_with_tag(calib,XSH_FLUX_STD_CAT,instrument);
291 if(flux_std_cat_frame==NULL) {
292 xsh_msg_error("Provide std star catalog frame");
293 return CPL_ERROR_DATA_NOT_FOUND;
294 }
295
296 resp_fit_points_cat_frame=xsh_find_frame_with_tag(calib,XSH_RESP_FIT_POINTS_CAT,instrument);
297 /*
298 if(resp_fit_points_cat_frame==NULL) {
299 xsh_msg_error("Provide response fit points catalog frame");
300 return CPL_ERROR_DATA_NOT_FOUND;
301 }
302 */
303
304 check( response_frame = xsh_compute_response2( merged_frame,
305 flux_std_cat_frame,
306 atmext_frame,
307 high_abs_win_frame,
308 resp_fit_points_cat_frame,
309 tell_mod_cat,
311 exptime,corr_tell ));
312 xsh_msg("response_frame=%p",response_frame);
313 /*
314 check(xsh_frame_table_monitor_flux_qc(response_frame,"LAMBDA","RESPONSE","RESP",
315 instrument));
316*/
317
318 cleanup:
319 xsh_free_frameset(&raws);
320 xsh_free_frameset(&calib);
321 xsh_free_frame(&response_frame);
322 xsh_free_propertylist(&plist);
324
325 if (cpl_error_get_code()) {
326 return -1 ;
327 } else {
328 return 0 ;
329 }
330}
static double exptime
static xsh_instrument * instrument
#define check(COMMAND)
Definition: xsh_error.h:71
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
#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 xsh_pfits_get_ndit(const cpl_propertylist *plist)
find out the NDIT value
Definition: xsh_pfits.c:1426
double xsh_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: xsh_pfits.c:1405
double xsh_pfits_get_exptime(const cpl_propertylist *plist)
find out the exposure time
Definition: xsh_pfits.c:2254
static int xsh_util_compute_response(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_compute_response_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_compute_response_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_compute_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
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
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_frame * xsh_compute_response2(cpl_frame *obs_std_star, cpl_frame *flux_std_star_cat, cpl_frame *atmos_ext, cpl_frame *high_abs, cpl_frame *resp_fit_points, cpl_frame *tell_mod_cat, xsh_instrument *instrument, double exptime, const int tell_corr)
@ XSH_ARM_NIR
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_TELL_MOD_CAT
Definition: xsh_dfs.h:181
#define XSH_STD_TELL_SLIT_STARE
Definition: xsh_dfs.h:462
#define XSH_ATMOS_EXT
Definition: xsh_dfs.h:1191
#define XSH_FLUX_STD_CAT
Definition: xsh_dfs.h:272
#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_RESP_FIT_POINTS_CAT
Definition: xsh_dfs.h:126
void xsh_parameters_new_boolean(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
int xsh_parameters_get_boolean(const cpl_parameterlist *list, const char *recipe_id, const char *name)
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_compute_response_description_short[]
static char xsh_util_compute_response_description[]
#define RECIPE_ID
#define RECIPE_AUTHOR