SINFONI Pipeline Reference Manual  2.6.0
sinfo_utl_eff.c
1 /* $Id: sinfo_utl_eff.c,v 1.7 2010-02-18 19:14:41 amodigli Exp $
2  *
3  * This file is part of the SINFONI 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: 2010-02-18 19:14:41 $
24  * $Revision: 1.7 $
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 
31 /*-----------------------------------------------------------------------------
32  Includes
33  ----------------------------------------------------------------------------*/
34 #include <string.h>
35 
36 /* cpl */
37 #include <cpl.h>
38 
39 /* irplib */
40 #include <irplib_utils.h>
41 
42 #include <sinfo_tpl_utils.h>
43 #include <sinfo_pfits.h>
44 #include <sinfo_tpl_dfs.h>
45 #include <sinfo_key_names.h>
46 #include <sinfo_pro_types.h>
47 #include <sinfo_ref_types.h>
48 #include <sinfo_functions.h>
49 #include <sinfo_msg.h>
50 #include <sinfo_error.h>
51 #include <sinfo_utils_wrappers.h>
52 #include <sinfo_utl_efficiency.h>
53 
54 /*-----------------------------------------------------------------------------
55  Functions prototypes
56  ----------------------------------------------------------------------------*/
57 
58 static int sinfo_utl_eff_create(cpl_plugin *) ;
59 static int sinfo_utl_eff_exec(cpl_plugin *) ;
60 static int sinfo_utl_eff_destroy(cpl_plugin *) ;
61 static int sinfo_utl_eff(cpl_parameterlist *, cpl_frameset *) ;
62 
63 /*-----------------------------------------------------------------------------
64  Static variables
65  ----------------------------------------------------------------------------*/
66 
67 static char sinfo_utl_eff_description[] =
68  "This recipe calculate a efficiency\n"
69  "esorex --params sinfo_utl_eff\n"
70  "esorex --help sinfo_utl_eff\n"
71  "\n";
72 
73 
74 
75 /*-----------------------------------------------------------------------------
76  Functions code
77  ----------------------------------------------------------------------------*/
78 /*---------------------------------------------------------------------------*/
82 /*---------------------------------------------------------------------------*/
83 
85 /*---------------------------------------------------------------------------*/
93 /*---------------------------------------------------------------------------*/
94 int cpl_plugin_get_info(cpl_pluginlist * list)
95 {
96  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
97  cpl_plugin * plugin = &recipe->interface ;
98 
99  cpl_plugin_init(plugin,
100  CPL_PLUGIN_API,
101  SINFONI_BINARY_VERSION,
102  CPL_PLUGIN_TYPE_RECIPE,
103  "sinfo_utl_eff",
104  "Produce a table with efficiency",
105  sinfo_utl_eff_description,
106  "Konstantin Mirny",
107  "kmirny@eso.org",
108  sinfo_get_license(),
109  sinfo_utl_eff_create,
110  sinfo_utl_eff_exec,
111  sinfo_utl_eff_destroy) ;
112 
113  cpl_pluginlist_append(list, plugin) ;
114 
115  return 0;
116 }
117 
118 /*---------------------------------------------------------------------------*/
127 /*---------------------------------------------------------------------------*/
128 static int sinfo_utl_eff_create(cpl_plugin * plugin)
129 {
130  cpl_recipe * recipe ;
131 
132  /* Get the recipe out of the plugin */
133  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
134  recipe = (cpl_recipe *)plugin ;
135  else return -1 ;
136  cpl_error_reset();
137  irplib_reset();
138 
139  /* Create the parameters list in the cpl_recipe object */
140  recipe->parameters = cpl_parameterlist_new() ;
141 
142  /* Fill the parameters list */
143 
144 
145  /* Return */
146  return 0;
147 }
148 
149 /*---------------------------------------------------------------------------*/
155 /*---------------------------------------------------------------------------*/
156 static int sinfo_utl_eff_exec(cpl_plugin * plugin)
157 {
158  cpl_recipe * recipe ;
159  int code=0;
160  cpl_errorstate initial_errorstate = cpl_errorstate_get();
161 
162  /* Get the recipe out of the plugin */
163  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
164  recipe = (cpl_recipe *)plugin ;
165  else return -1 ;
166  cpl_error_reset();
167  irplib_reset();
168  code = sinfo_utl_eff(recipe->parameters, recipe->frames) ;
169 
170 
171  if (!cpl_errorstate_is_equal(initial_errorstate)) {
172  /* Dump the error history since recipe execution start.
173  At this point the recipe cannot recover from the error */
174  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
175  }
176 
177  return code ;
178 }
179 
180 /*---------------------------------------------------------------------------*/
186 /*---------------------------------------------------------------------------*/
187 static int sinfo_utl_eff_destroy(cpl_plugin * plugin)
188 {
189  cpl_recipe * recipe ;
190 
191  /* Get the recipe out of the plugin */
192  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
193  recipe = (cpl_recipe *)plugin ;
194  else return -1 ;
195 
196  cpl_parameterlist_delete(recipe->parameters) ;
197  return 0 ;
198 }
199 
200 /*---------------------------------------------------------------------------*/
207 /*---------------------------------------------------------------------------*/
208 static int
209 sinfo_utl_eff( cpl_parameterlist * parlist,
210  cpl_frameset * framelist)
211 {
212 
213  const char * name_o = NULL ;
214 
215  cpl_frame* product_frame = 0;
216  cpl_propertylist * plist = NULL ;
217  int pos = 0;
218  int npos = 0;
219  cpl_frame* frm_sci=NULL;
220  cpl_frame* frm_atm_ext=NULL;
221  cpl_frame* frm_std_cat=NULL;
222  cpl_table* eff_tbl=NULL;
223 
224  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
225  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
226  ck0(sinfo_dfs_set_groups(framelist),"Cannot indentify RAW and CALIB frames");
227 
228  /* HOW TO GET THE VALUE OF A FITS KEYWORD */
229  check(plist=cpl_propertylist_new(),"Cannot create a Property List");
230 
231 
232  /* Now performing the data reduction */
233  name_o = "eff_res.fits" ;
234 
235  check_nomsg(frm_sci=cpl_frameset_find (framelist, PRO_STD_STAR_SPECTRA));
236  check_nomsg(frm_std_cat=cpl_frameset_find (framelist, FLUX_STD_CATALOG));
237  check_nomsg(frm_atm_ext=cpl_frameset_find (framelist, EXTCOEFF_TABLE));
238  sinfo_msg("frm_sci=%p frm_std=%p frm_atm_ext=%p",frm_sci,frm_std_cat,frm_atm_ext);
239  check_nomsg(eff_tbl=sinfo_efficiency_compute(frm_sci,frm_std_cat,frm_atm_ext));
240  npos = cpl_frameset_get_size(framelist);
241  for (pos = 0; pos < npos; pos++)
242  {
243  cpl_frame* pframe = cpl_frameset_get_frame(framelist, pos);
244  cpl_frame_group group = cpl_frame_get_group(pframe);
245  if (CPL_FRAME_GROUP_PRODUCT == group)
246  {
247  check_nomsg(cpl_frame_set_group (pframe, CPL_FRAME_GROUP_CALIB));
248  }
249  }
250  /* Create product frame */
251  check_nomsg(product_frame = cpl_frame_new());
252  check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
253  check_nomsg(cpl_frame_set_tag(product_frame,"sinfo_efficiency" )) ;
254  check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
255  check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
256  check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
257  "Error while initialising the product frame") ;
258 
259  /* Add DataFlow keywords */
260  check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
261  /* Log the saved file in the input frameset */
262  check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
263  check(cpl_dfs_setup_product_header(plist,
264  product_frame,
265  framelist,
266  parlist,
267  "sinfo_utl_eff",
268  "SINFONI",
269  KEY_VALUE_HPRO_DID,NULL),
270  "Problem in the product DFS-compliance") ;
271  sinfo_free_propertylist(&plist) ;
272 
273  cleanup:
274  sinfo_free_propertylist(&plist) ;
275  return (cpl_error_get_code()) ? -1 : 0;
276 }
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: sinfo_utl_eff.c:94
void irplib_reset(void)
Reset IRPLIB state.