X-shooter Pipeline Reference Manual 3.8.15
xsh_util_integrate.c
Go to the documentation of this file.
1/* $Id: xsh_util_integrate.c,v 1.5 2012-04-26 14:03:50 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 * $Name: not supported by cvs2svn $
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27/*-----------------------------------------------------------------------------
28 Includes
29 ----------------------------------------------------------------------------*/
30#include <string.h>
31
32/* cpl */
33#include <cpl.h>
34
35#include <xsh_dfs.h>
36#include <xsh_data_pre.h>
37#include <xsh_utils.h>
38#include <xsh_parameters.h>
39#include <xsh_drl.h>
40#include <xsh_msg.h>
41#include <xsh_pfits.h>
42#include <xsh_error.h>
43//#include <xsh_utils_wrappers.h>
44
45
46/*-----------------------------------------------------------------------------
47 Defines
48 ----------------------------------------------------------------------------*/
49
50#define XSH_UTL_INTEGRATE_RECIPE_ID "xsh_util_integrate"
51#define XSH_UTL_INTEGRATE_RECIPE_AUTHOR "A.Modigliani"
52#define XSH_UTL_INTEGRATE_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
53#define PRO_IMA "PRO_IMA_UVB"
54#define KEY_VALUE_HPRO_DID "PRO-1.15"
55/*-----------------------------------------------------------------------------
56 Functions prototypes
57 ----------------------------------------------------------------------------*/
58
59static int xsh_util_integrate_create(cpl_plugin *) ;
60static int xsh_util_integrate_exec(cpl_plugin *) ;
61static int xsh_util_integrate_destroy(cpl_plugin *) ;
62static int xsh_util_integrate(cpl_parameterlist *, cpl_frameset *) ;
63
64/*-----------------------------------------------------------------------------
65 Static variables
66 ----------------------------------------------------------------------------*/
67
68static char
71"This recipe performs spectra integration (with flux conservation).\n"
72"The input files should be list of files\n"
73"Information on relevant parameters can be found with\n"
74"esorex --params xsh_util_integrate\n"
75"esorex --help xsh_util_integrate\n"
76"\n";
77
78/*-----------------------------------------------------------------------------
79 Functions code
80 ----------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
89/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98int cpl_plugin_get_info(cpl_pluginlist * list)
99{
100 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
101 cpl_plugin * plugin = &recipe->interface ;
102
103 cpl_plugin_init(plugin,
104 CPL_PLUGIN_API,
105 XSH_BINARY_VERSION,
106 CPL_PLUGIN_TYPE_RECIPE,
116
117 cpl_pluginlist_append(list, plugin) ;
118
119 return 0;
120}
121
122/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132static int xsh_util_integrate_create(cpl_plugin * plugin)
133{
134 cpl_recipe * recipe ;
135 cpl_parameter * p ;
136
137 /* Reset library state */
138 xsh_init();
139
140 /* Get the recipe out of the plugin */
141 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
142 recipe = (cpl_recipe *)plugin ;
143 else return -1 ;
144 cpl_error_reset();
145
146
147 /* Create the parameters list in the cpl_recipe object */
148 recipe->parameters = cpl_parameterlist_new() ;
149
150
151 /* Set generic parameters (common to all recipes) */
153 recipe->parameters ) ) ;
155 /* Fill the parameters list */
156 p = cpl_parameter_new_range("xsh.xsh_util_integrate.binw",
157 CPL_TYPE_DOUBLE,
158 "Sampling bin [nm]",
159 "xsh.xsh_util_integrate",1,0.01,100);
160 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "binw") ;
161 cpl_parameterlist_append(recipe->parameters, p) ;
162
163 cleanup:
164
165 /* Return */
166 return 0;
167}
168
169/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176static int xsh_util_integrate_exec(cpl_plugin * plugin)
177{
178 cpl_recipe * recipe ;
179 int code=0;
180 cpl_errorstate initial_errorstate = cpl_errorstate_get();
181
182 /* Get the recipe out of the plugin */
183 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
184 recipe = (cpl_recipe *)plugin ;
185 else return -1 ;
186 cpl_error_reset();
187
188 code = xsh_util_integrate(recipe->parameters, recipe->frames) ;
189
190
191 if (!cpl_errorstate_is_equal(initial_errorstate)) {
192 /* Dump the error history since recipe execution start.
193 At this point the recipe cannot recover from the error */
194 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
195 }
196
197 return code ;
198}
199
200/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
207static int xsh_util_integrate_destroy(cpl_plugin * plugin)
208{
209 cpl_recipe * recipe ;
210
211 /* Get the recipe out of the plugin */
212 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
213 recipe = (cpl_recipe *)plugin ;
214 else return -1 ;
215
216 cpl_parameterlist_delete(recipe->parameters) ;
217 return 0 ;
218}
219
220/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
228static int
229xsh_util_integrate( cpl_parameterlist * parlist,
230 cpl_frameset * frames)
231{
232
233 const char* recipe_tags[1] = {XSH_RAW_IMA_SLIT};
234 int recipe_tags_size = 1;
235
236 cpl_parameter * param= NULL ;
237
238 cpl_frameset* raws = NULL;
239 cpl_frameset* calib = NULL;
240
241 cpl_frame* std_obs=NULL;
242 cpl_frame* std_cat=NULL;
243 cpl_frame* atm_ext=NULL;
244 cpl_frame* response=NULL;
245
246
247 cpl_propertylist* plist=NULL;
248
249
251 const char* fname=NULL;
252 double binw=0;
253 double exptime=0;
254 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
255 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
256
257 /* HOW TO RETRIEVE INPUT PARAMETERS */
258 /* --stropt */
259 check(param=cpl_parameterlist_find(parlist,"xsh.xsh_util_integrate.binw"));
260 check(binw=cpl_parameter_get_double(param));
261
262
263 check( xsh_begin( frames, parlist, &instrument, &raws, &calib,
264 recipe_tags, recipe_tags_size,
265 XSH_UTL_INTEGRATE_RECIPE_ID, XSH_BINARY_VERSION,
267
271
272 fname=cpl_frame_get_filename(std_obs);
273 plist=cpl_propertylist_load(fname,0);
275 xsh_msg("exptime=%g",exptime);
276
277 check(response=xsh_compute_response(std_obs,std_cat,atm_ext,NULL,
279
280 cleanup:
281 xsh_free_frame(&response);
282 xsh_free_frameset(&raws);
283 xsh_free_frameset(&calib);
284
286 xsh_free_propertylist(&plist);
287 if (cpl_error_get_code()) {
288 return -1 ;
289 } else {
290 return 0 ;
291 }
292
293}
static double exptime
static xsh_instrument * instrument
#define check(COMMAND)
Definition: xsh_error.h:71
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
double xsh_pfits_get_exptime(const cpl_propertylist *plist)
find out the exposure time
Definition: xsh_pfits.c:2254
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_integrate_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_integrate(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_integrate_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_integrate_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
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_response(cpl_frame *spectrum_frame, cpl_frame *flux_std_star_cat_frame, cpl_frame *atmos_ext_frame, cpl_frame *high_abs_frame, xsh_instrument *instrument, double exptime)
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_ATMOS_EXT
Definition: xsh_dfs.h:1191
#define XSH_FLUX_STD_CAT
Definition: xsh_dfs.h:272
#define XSH_RAW_IMA_SLIT
Definition: xsh_dfs.h:241
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 XSH_UTL_INTEGRATE_RECIPE_ID
#define XSH_UTL_INTEGRATE_RECIPE_AUTHOR
#define XSH_UTL_INTEGRATE_RECIPE_CONTACT
static char xsh_util_integrate_description[]
static char xsh_util_integrate_description_short[]