SINFONI Pipeline Reference Manual  2.5.2
recipes/sinfo_utl_cube_combine.c
1 /* $Id: sinfo_utl_cube_combine.c,v 1.12 2007-10-26 09:40:28 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: 2007-10-26 09:40:28 $
24  * $Revision: 1.12 $
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 
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_msg.h>
46 #include <sinfo_utl_cube_combine.h>
47 
48 /*-----------------------------------------------------------------------------
49  Functions prototypes
50  ----------------------------------------------------------------------------*/
51 
52 static int sinfo_utl_cube_combine_create(cpl_plugin *) ;
53 static int sinfo_utl_cube_combine_exec(cpl_plugin *) ;
54 static int sinfo_utl_cube_combine_destroy(cpl_plugin *) ;
55 
56 /*-----------------------------------------------------------------------------
57  Static variables
58  ----------------------------------------------------------------------------*/
59 
60 static char sinfo_utl_cube_combine_description[] =
61  "This recipe perform cubes combination.\n"
62  "The input files are several cubeses\n"
63  "their associated tags should be the same that is supported by the \n"
64  "recipe sinfo_rec_jitter: OBS_OBJ, OBS_STD, OBS_PSF.\n"
65  "The output is a cube PRO_CUBE resulting from the input cubes accurding \n"
66  "to the value of op, where op indicates\n"
67  "the operation to be performed specified by the parameter \n"
68  "sinfoni.sinfo_utl_cube_combine.op\n"
69  " having alias 'op'\n"
70  "\n";
71 
72 /*-----------------------------------------------------------------------------
73  Functions code
74  ----------------------------------------------------------------------------*/
75 /*---------------------------------------------------------------------------*/
79 /*---------------------------------------------------------------------------*/
80 
82 /*---------------------------------------------------------------------------*/
90 /*---------------------------------------------------------------------------*/
91 int cpl_plugin_get_info(cpl_pluginlist * list)
92 {
93  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
94  cpl_plugin * plugin = &recipe->interface ;
95 
96  cpl_plugin_init(plugin,
97  CPL_PLUGIN_API,
98  SINFONI_BINARY_VERSION,
99  CPL_PLUGIN_TYPE_RECIPE,
100  "sinfo_utl_cube_combine",
101  "Coadd cubes in an output cube according "
102  "to user defined offsets",
103  sinfo_utl_cube_combine_description,
104  "Andrea Modigliani",
105  "Andrea.Modigliani@eso.org",
106  sinfo_get_license(),
107  sinfo_utl_cube_combine_create,
108  sinfo_utl_cube_combine_exec,
109  sinfo_utl_cube_combine_destroy) ;
110 
111  cpl_pluginlist_append(list, plugin) ;
112 
113  return 0;
114 }
115 
116 /*---------------------------------------------------------------------------*/
125 /*---------------------------------------------------------------------------*/
126 static int sinfo_utl_cube_combine_create(cpl_plugin * plugin)
127 {
128  cpl_recipe * recipe ;
129  cpl_parameter * p ;
130 
131  /* Get the recipe out of the plugin */
132  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
133  recipe = (cpl_recipe *)plugin ;
134  else return -1 ;
135  cpl_error_reset();
136  irplib_reset();
137 
138  /* Create the parameters list in the cpl_recipe object */
139  recipe->parameters = cpl_parameterlist_new() ;
140 
141  /* Fill the parameters list */
142  /* --stropt */
143  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.name_i",
144  CPL_TYPE_STRING,
145  "Input filename. This must be provided and allow the user to set X "
146  "and Y cumulative offsets in a two column format",
147  "sinfoni.sinfo_utl_cube_combine","offset.list");
148  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "name_i") ;
149  cpl_parameterlist_append(recipe->parameters, p) ;
150 
151  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.name_o",
152  CPL_TYPE_STRING, "Output filename",
153  "sinfoni.sinfo_utl_cube_combine","out_coadd_cube.fits");
154  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "name_o") ;
155  cpl_parameterlist_append(recipe->parameters, p) ;
156 
157 
158  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.ks_clip",
159  CPL_TYPE_BOOL, "Kappa sigma clipping",
160  "sinfoni.sinfo_utl_cube_combine",FALSE);
161  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ks_clip") ;
162  cpl_parameterlist_append(recipe->parameters, p) ;
163 
164  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.scale_sky",
165  CPL_TYPE_BOOL, "Scale spatial mean",
166  "sinfoni.sinfo_utl_cube_combine",FALSE);
167  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "scale_sky") ;
168  cpl_parameterlist_append(recipe->parameters, p) ;
169 
170  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.kappa",
171  CPL_TYPE_DOUBLE, "Kappa value for sigma clip",
172  "sinfoni.sinfo_utl_cube_combine",2.);
173  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "kappa") ;
174  cpl_parameterlist_append(recipe->parameters, p) ;
175 
176 
177  /* --doubleopt */
178  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.xsize",
179  CPL_TYPE_INT, "Output cube X size",
180  "sinfoni.sinfo_utl_cube_combine", 80) ;
181  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "xsize") ;
182  cpl_parameterlist_append(recipe->parameters, p) ;
183 
184 
185  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_combine.ysize",
186  CPL_TYPE_INT, "Output cube Y size",
187  "sinfoni.sinfo_utl_cube_combine", 80) ;
188  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ysize") ;
189  cpl_parameterlist_append(recipe->parameters, p) ;
190 
191 
192  /* Return */
193  return 0;
194 }
195 
196 /*---------------------------------------------------------------------------*/
202 /*---------------------------------------------------------------------------*/
203 static int sinfo_utl_cube_combine_exec(cpl_plugin * plugin)
204 {
205  cpl_recipe * recipe ;
206  int result=0;
207  cpl_errorstate initial_errorstate = cpl_errorstate_get();
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  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
214  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
215 
216  result=sinfo_utl_cube_combine(recipe->parameters, recipe->frames) ;
217  if (!cpl_errorstate_is_equal(initial_errorstate)) {
218  /* Dump the error history since recipe execution start.
219  At this point the recipe cannot recover from the error */
220  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
221  }
222  return result;
223 }
224 
225 /*---------------------------------------------------------------------------*/
231 /*---------------------------------------------------------------------------*/
232 static int sinfo_utl_cube_combine_destroy(cpl_plugin * plugin)
233 {
234  cpl_recipe * recipe ;
235 
236  /* Get the recipe out of the plugin */
237  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
238  recipe = (cpl_recipe *)plugin ;
239  else return -1 ;
240 
241  cpl_parameterlist_delete(recipe->parameters) ;
242  return 0 ;
243 }
244