X-shooter Pipeline Reference Manual 3.8.15
xsh_util_efficiency1d.c
Go to the documentation of this file.
1/* $Id: xsh_util_efficiency1d.c,v 1.18 2012-04-26 14:08:32 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<<<<<<< xsh_util_efficiency1d.c
23 * $Author: amodigli $
24 * $Date: 2012-04-26 14:08:32 $
25 * $Revision: 1.18 $
26=======
27 * $Author: amodigli $
28 * $Date: 2012-04-26 14:08:32 $
29 * $Revision: 1.18 $
30>>>>>>> 1.13.2.1
31 * $Name: not supported by cvs2svn $
32 */
33
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38/*-----------------------------------------------------------------------------
39 Includes
40 ----------------------------------------------------------------------------*/
41#include <string.h>
42#include <math.h>
43
44/* cpl */
45#include <cpl.h>
46
47#include <xsh_dfs.h>
48#include <xsh_data_pre.h>
49#include <xsh_parameters.h>
50#include <xsh_drl.h>
51#include <xsh_msg.h>
52#include <xsh_pfits.h>
53#include <xsh_pfits_qc.h>
54#include <xsh_error.h>
55#include <xsh_utils_image.h>
56#include <xsh_utils_table.h>
58
59
60/*-----------------------------------------------------------------------------
61 Defines
62 ----------------------------------------------------------------------------*/
63
64#define RECIPE_ID "xsh_util_efficiency1d"
65#define RECIPE_AUTHOR "A.Modigliani"
66#define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
67#define PRO_IMA "PRO_IMA_UVB"
68#define KEY_VALUE_HPRO_DID "PRO-1.15"
69
70#define SPEED_LIGHT 2.99792458*1.E8 /* m s-1 */
71#define TEL_AREA 51.2e4 /* collecting area in cm2 */
72/*-----------------------------------------------------------------------------
73 Functions prototypes
74 ----------------------------------------------------------------------------*/
75
76static int xsh_util_efficiency1d_create(cpl_plugin *) ;
77static int xsh_util_efficiency1d_exec(cpl_plugin *) ;
78static int xsh_util_efficiency1d_destroy(cpl_plugin *) ;
79static int xsh_util_efficiency1d(cpl_parameterlist *, cpl_frameset *) ;
80
81/*-----------------------------------------------------------------------------
82 Static variables
83 ----------------------------------------------------------------------------*/
84
85static char
88"This recipe compute efficiency.\n"
89"The input files should be tagged as: \n"
90"input observed spectrum: RAW_IMA_SLIT_arm,\n"
91"input reference spectrum: FLUX_STD_TABLE_arm,\n"
92"input atmospheric extintion table: EXTCOEFF_TABLE_arm)\n"
93"The output is a table with efficiency as function of wavelength\n"
94"Information on relevant parameters can be found with\n"
95"esorex --params xsh_util_efficiency1d\n"
96"esorex --help xsh_util_efficiency1d\n"
97"\n";
98
99/*-----------------------------------------------------------------------------
100 Functions code
101 ----------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108
110/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119int cpl_plugin_get_info(cpl_pluginlist * list)
120{
121 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
122 cpl_plugin * plugin = &recipe->interface ;
123
124 cpl_plugin_init(plugin,
125 CPL_PLUGIN_API,
126 XSH_BINARY_VERSION,
127 CPL_PLUGIN_TYPE_RECIPE,
128 RECIPE_ID,
137
138 cpl_pluginlist_append(list, plugin) ;
139
140 return 0;
141}
142
143/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153static int xsh_util_efficiency1d_create(cpl_plugin * plugin)
154{
155 cpl_recipe * recipe ;
156
157 /* Reset library state */
158 xsh_init();
159
160 /* Get the recipe out of the plugin */
161 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
162 recipe = (cpl_recipe *)plugin ;
163 else return -1 ;
164 cpl_error_reset();
165
166
167 /* Create the parameters list in the cpl_recipe object */
168 recipe->parameters = cpl_parameterlist_new() ;
169
170
171 /* Set generic parameters (common to all recipes) */
173 recipe->parameters ) ) ;
174 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
175 cleanup:
176
177 /* Return */
178 return 0;
179}
180
181/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188static int xsh_util_efficiency1d_exec(cpl_plugin * plugin)
189{
190 cpl_recipe * recipe ;
191 int code=0;
192 cpl_errorstate initial_errorstate = cpl_errorstate_get();
193
194 /* Get the recipe out of the plugin */
195 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
196 recipe = (cpl_recipe *)plugin ;
197 else return -1 ;
198 cpl_error_reset();
199
200 code = xsh_util_efficiency1d(recipe->parameters, recipe->frames) ;
201
202
203 if (!cpl_errorstate_is_equal(initial_errorstate)) {
204 /* Dump the error history since recipe execution start.
205 At this point the recipe cannot recover from the error */
206 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
207 }
208
209 return code ;
210}
211
212/*---------------------------------------------------------------------------*/
218/*---------------------------------------------------------------------------*/
219static int xsh_util_efficiency1d_destroy(cpl_plugin * plugin)
220{
221 cpl_recipe * recipe ;
222
223 /* Get the recipe out of the plugin */
224 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
225 recipe = (cpl_recipe *)plugin ;
226 else return -1 ;
227
228 cpl_parameterlist_delete(recipe->parameters) ;
229 return 0 ;
230}
231
232
233
234/*---------------------------------------------------------------------------*/
241/*---------------------------------------------------------------------------*/
242static int
243xsh_util_efficiency1d( cpl_parameterlist * parlist,
244 cpl_frameset * frames)
245{
246 const char* recipe_tags[1] = {XSH_RAW_IMA_SLIT};
247 int recipe_tags_size = 1;
248
250
251 cpl_frameset* raws=NULL;
252 cpl_frameset* calib=NULL;
253 cpl_frame* frm_std_cat=NULL;
254 cpl_frame* frm_atmext=NULL;
255 cpl_frame* frm_eff=NULL;
256 cpl_frame* frm_sci=NULL;
257
258 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
259 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
260
261
262 check( xsh_begin( frames, parlist, &instrument, &raws, &calib,
263 recipe_tags, recipe_tags_size,
264 RECIPE_ID, XSH_BINARY_VERSION,
266
267 /* HOW TO RETRIEVE INPUT PARAMETERS */
268 /* --stropt */
270 if(frm_atmext==NULL) {
271 xsh_msg_error("Provide atmospheric extinction frame");
272 return CPL_ERROR_DATA_NOT_FOUND;
273 }
274
276 if(frm_std_cat==NULL) {
277 xsh_msg_error("Provide std star catalog frame");
278 return CPL_ERROR_DATA_NOT_FOUND;
279 }
280
281 if( (frm_sci=xsh_find_frame_with_tag(frames,XSH_RAW_IMA_SLIT,
282 instrument)) == NULL) {
283 goto cleanup;
284 }
285
286 check(frm_eff=xsh_efficiency_compute(frm_sci,frm_std_cat,frm_atmext,
287 instrument));
288
289 check(xsh_frame_table_monitor_flux_qc(frm_eff,"WAVELENGTH","EFF","EFF",
290 instrument));
291
292
293 check(xsh_add_product_table(frm_eff, frames,parlist,
294 RECIPE_ID, instrument,NULL));
295
296
297 cleanup:
298
299 xsh_free_frame(&frm_eff);
300 xsh_free_frameset(&raws);
301 xsh_free_frameset(&calib);
303
304 if (cpl_error_get_code()) {
305 return -1 ;
306 } else {
307 return 0 ;
308 }
309
310}
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_error(...)
Print an error message.
Definition: xsh_msg.h:62
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
static int xsh_util_efficiency1d_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_efficiency1d_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_efficiency1d_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_efficiency1d(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
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_frame_table_monitor_flux_qc(cpl_frame *frm, const char *colw, const char *colf, const char *prefix, xsh_instrument *instrument)
Computes statistics on spectrum for QC.
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_add_product_table(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Save Table product (input frame has several extensions, 1 table per extension)
Definition: xsh_dfs.c:3146
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 RECIPE_CONTACT
static char xsh_util_efficiency1d_description[]
#define RECIPE_ID
#define RECIPE_AUTHOR
static char xsh_util_efficiency1d_description_short[]
cpl_frame * xsh_efficiency_compute(cpl_frame *frm_sci, cpl_frame *frm_cat, cpl_frame *frm_atmext, cpl_frame *high_abs_win, xsh_instrument *instrument)
computes efficiency