SINFONI Pipeline Reference Manual  2.5.2
recipes/sinfo_utl_cube2spectrum.c
1 /* $Id: sinfo_utl_cube2spectrum.c,v 1.12 2007-10-26 08:33:11 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 08:33:11 $
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 /* irplib */
39 #include <irplib_utils.h>
40 
41 #include <sinfo_tpl_utils.h>
42 #include <sinfo_pfits.h>
43 #include <sinfo_tpl_dfs.h>
44 #include <sinfo_utl_cube2spectrum.h>
45 #include <sinfo_msg.h>
46 /*-----------------------------------------------------------------------------
47  Functions prototypes
48  -----------------------------------------------------------------------------*/
49 
50 static int sinfo_utl_cube2spectrum_create(cpl_plugin *) ;
51 static int sinfo_utl_cube2spectrum_exec(cpl_plugin *) ;
52 static int sinfo_utl_cube2spectrum_destroy(cpl_plugin *) ;
53 
54 /*-----------------------------------------------------------------------------
55  Static variables
56  -----------------------------------------------------------------------------*/
57 
58 static char sinfo_utl_cube2spectrum_description[] =
59  "This recipe performs cube to 1D spectrum image conversion.\n"
60  "The input files is a cube\n"
61  "Its associated tag should be CUBE.\n"
62  "The output is an image resulting from the cube manipulated \n"
63  "according to the value of op\n"
64  "Over an aperture as specified by the parameter \n"
65  "sinfoni.sinfo_utl_cube2spectrum.aperture having alias 'op', 'ap'"
66  "\n";
67 
68 /*-----------------------------------------------------------------------------
69  Functions code
70  ----------------------------------------------------------------------------*/
71 /*---------------------------------------------------------------------------*/
75 /*---------------------------------------------------------------------------*/
76 
78 /*---------------------------------------------------------------------------*/
86 /*---------------------------------------------------------------------------*/
87 int cpl_plugin_get_info(cpl_pluginlist * list)
88 {
89  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
90  cpl_plugin * plugin = &recipe->interface ;
91 
92  cpl_plugin_init(plugin,
93  CPL_PLUGIN_API,
94  SINFONI_BINARY_VERSION,
95  CPL_PLUGIN_TYPE_RECIPE,
96  "sinfo_utl_cube2spectrum",
97  "Collapse a cube to an image over an aperture",
98  sinfo_utl_cube2spectrum_description,
99  "Andrea Modigliani",
100  "Andrea.Modigliani@eso.org",
101  sinfo_get_license(),
102  sinfo_utl_cube2spectrum_create,
103  sinfo_utl_cube2spectrum_exec,
104  sinfo_utl_cube2spectrum_destroy) ;
105 
106  cpl_pluginlist_append(list, plugin) ;
107 
108  return 0;
109 }
110 
111 /*---------------------------------------------------------------------------*/
120 /*---------------------------------------------------------------------------*/
121 static int sinfo_utl_cube2spectrum_create(cpl_plugin * plugin)
122 {
123  cpl_recipe * recipe ;
124  cpl_parameter * p ;
125 
126  /* Get the recipe out of the plugin */
127  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
128  recipe = (cpl_recipe *)plugin ;
129  else return -1 ;
130  cpl_error_reset();
131  irplib_reset();
132 
133  /* Create the parameters list in the cpl_recipe object */
134  recipe->parameters = cpl_parameterlist_new() ;
135 
136  /* Fill the parameters list */
137  /* --stropt */
138  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.op",
139  CPL_TYPE_STRING, "A possible operation:"
140  " average, clean_mean, median, sum",
141  "sinfoni.sinfo_utl_cube2spectrum","average");
142  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;
143  cpl_parameterlist_append(recipe->parameters, p) ;
144 
145 
146  /* --stropt */
147  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.ap",
148  CPL_TYPE_STRING, "A possible aperture: rectangle, circle",
149  "sinfoni.sinfo_utl_cube2spectrum","rectangle");
150  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ap") ;
151  cpl_parameterlist_append(recipe->parameters, p) ;
152 
153 
154  /* --doubleopt */
155  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.llx",
156  CPL_TYPE_INT,
157  "Lower left X rectangle coordinate",
158  "sinfoni.sinfo_utl_cube2spectrum", 2) ;
159  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "llx") ;
160  cpl_parameterlist_append(recipe->parameters, p) ;
161 
162 
163  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.lly",
164  CPL_TYPE_INT,
165  "Lower left Y rectangle coordinate",
166  "sinfoni.sinfo_utl_cube2spectrum", 2) ;
167  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lly") ;
168  cpl_parameterlist_append(recipe->parameters, p) ;
169 
170 
171  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.urx",
172  CPL_TYPE_INT, "Upper right X rectangle coordinate",
173  "sinfoni.sinfo_utl_cube2spectrum", 28) ;
174  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "urx") ;
175  cpl_parameterlist_append(recipe->parameters, p) ;
176 
177 
178  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.ury",
179  CPL_TYPE_INT,
180  "Upper right Y rectangle coordinate",
181  "sinfoni.sinfo_utl_cube2spectrum", 28) ;
182  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ury") ;
183  cpl_parameterlist_append(recipe->parameters, p) ;
184 
185 
186 
187  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.lo_rej",
188  CPL_TYPE_INT,
189  "Clean mean low rejection",
190  "sinfoni.sinfo_utl_cube2spectrum", 10) ;
191  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lo_rej") ;
192  cpl_parameterlist_append(recipe->parameters, p) ;
193 
194 
195  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.hi_rej",
196  CPL_TYPE_INT,
197  "Clean mean low rejection",
198  "sinfoni.sinfo_utl_cube2spectrum", 10) ;
199  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "hi_rej") ;
200  cpl_parameterlist_append(recipe->parameters, p) ;
201 
202 
203 
204  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.centerx",
205  CPL_TYPE_INT,
206  "Circle center X coordinate",
207  "sinfoni.sinfo_utl_cube2spectrum", 16) ;
208  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "centerx") ;
209  cpl_parameterlist_append(recipe->parameters, p) ;
210 
211 
212  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.centery",
213  CPL_TYPE_INT,
214  "Circle center Y coordinate",
215  "sinfoni.sinfo_utl_cube2spectrum", 16) ;
216  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "centery") ;
217  cpl_parameterlist_append(recipe->parameters, p) ;
218 
219 
220  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube2spectrum.radius",
221  CPL_TYPE_INT, "Circle radii",
222  "sinfoni.sinfo_utl_cube2spectrum", 5) ;
223  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "radius") ;
224  cpl_parameterlist_append(recipe->parameters, p) ;
225 
226 
227  /* Return */
228  return 0;
229 }
230 
231 /*---------------------------------------------------------------------------*/
237 /*---------------------------------------------------------------------------*/
238 static int sinfo_utl_cube2spectrum_exec(cpl_plugin * plugin)
239 {
240  cpl_recipe * recipe ;
241  int result=0;
242  cpl_errorstate initial_errorstate = cpl_errorstate_get();
243 
244  /* Get the recipe out of the plugin */
245  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
246  recipe = (cpl_recipe *)plugin ;
247  else return -1 ;
248 
249  if(sinfo_dfs_set_groups(recipe->frames)) {
250  sinfo_msg_error( "Cannot indentify RAW and CALIB frames") ;
251  return -1;
252  }
253  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
254  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
255 
256  result = sinfo_utl_cube2spectrum(recipe->parameters, recipe->frames,NULL);
257  if (!cpl_errorstate_is_equal(initial_errorstate)) {
258  /* Dump the error history since recipe execution start.
259  At this point the recipe cannot recover from the error */
260  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
261  }
262 
263  return result;
264 }
265 
266 /*---------------------------------------------------------------------------*/
272 /*----------------------------------------------------------------------------*/
273 static int sinfo_utl_cube2spectrum_destroy(cpl_plugin * plugin)
274 {
275  cpl_recipe * recipe ;
276 
277  /* Get the recipe out of the plugin */
278  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
279  recipe = (cpl_recipe *)plugin ;
280  else return -1 ;
281 
282  cpl_parameterlist_delete(recipe->parameters) ;
283  return 0 ;
284 }
285