SINFONI Pipeline Reference Manual  2.6.0
recipes/sinfo_utl_cube_arith.c
1 /* $Id: sinfo_utl_cube_arith.c,v 1.10 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.10 $
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 #include <string.h>
36 
37 /* cpl */
38 #include <cpl.h>
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_utl_cube_arith.h>
46 #include <sinfo_msg.h>
47 
48 /*-----------------------------------------------------------------------------
49  Functions prototypes
50  ----------------------------------------------------------------------------*/
51 
52 static int sinfo_utl_cube_arith_create(cpl_plugin *) ;
53 static int sinfo_utl_cube_arith_exec(cpl_plugin *) ;
54 static int sinfo_utl_cube_arith_destroy(cpl_plugin *) ;
55 
56 /*-----------------------------------------------------------------------------
57  Static variables
58  ----------------------------------------------------------------------------*/
59 
60 static char sinfo_utl_cube_arith_description1[] =
61  "This recipe perform cube arithmetics.\n"
62  "If parameter value is specified the input frame is a cube \n"
63  "in a sof file with tag CUBE\n"
64  "Else the input files are a cube and an images or a spectrum\n"
65  "their associated tags should be respectively CUBE, IMA or SPECTRUM.\n"
66  "The output is a cube with tag PRO_CUBE resulting from the operation \n"
67  "CUBE op IMA or \n"
68  "CUBE op SPECTRUM or\n"
69  "CUBE op value where op indicates\n"
70  "the operation to be performed\n"
71  "\n";
72 
73 
74 static char sinfo_utl_cube_arith_description[600];
75 
76 
77 
78 /*-----------------------------------------------------------------------------
79  Functions code
80  ----------------------------------------------------------------------------*/
81 /*---------------------------------------------------------------------------*/
85 /*---------------------------------------------------------------------------*/
87 /*---------------------------------------------------------------------------*/
95 /*---------------------------------------------------------------------------*/
96 int cpl_plugin_get_info(cpl_pluginlist * list)
97 {
98  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
99  cpl_plugin * plugin = &recipe->interface ;
100 
101  strcpy(sinfo_utl_cube_arith_description,sinfo_utl_cube_arith_description1);
102 
103  cpl_plugin_init(plugin,
104  CPL_PLUGIN_API,
105  SINFONI_BINARY_VERSION,
106  CPL_PLUGIN_TYPE_RECIPE,
107  "sinfo_utl_cube_arith",
108  "Cube arithmetics",
109  sinfo_utl_cube_arith_description,
110  "Andrea Modigliani",
111  "Andrea.Modigliani@eso.org",
112  sinfo_get_license(),
113  sinfo_utl_cube_arith_create,
114  sinfo_utl_cube_arith_exec,
115  sinfo_utl_cube_arith_destroy) ;
116 
117  cpl_pluginlist_append(list, plugin) ;
118 
119  return 0;
120 }
121 
122 /*---------------------------------------------------------------------------*/
131 /*---------------------------------------------------------------------------*/
132 static int sinfo_utl_cube_arith_create(cpl_plugin * plugin)
133 {
134  cpl_recipe * recipe ;
135  cpl_parameter * p ;
136 
137  /* Get the recipe out of the plugin */
138  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
139  recipe = (cpl_recipe *)plugin ;
140  else return -1 ;
141  cpl_error_reset();
142  irplib_reset();
143  /* Create the parameters list in the cpl_recipe object */
144  recipe->parameters = cpl_parameterlist_new() ;
145 
146  /* Fill the parameters list */
147  /* --stropt */
148  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.op",
149  CPL_TYPE_STRING,
150  "A possible operation: "
151  "`/','*','+' or `-'",
152  "sinfoni.sinfo_utl_cube_arith","/");
153  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;
154  cpl_parameterlist_append(recipe->parameters, p) ;
155 
156 
157  /* --doubleopt */
158  /*
159  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.temperature",
160  CPL_TYPE_DOUBLE, "Black Body Temperature",
161  "sinfoni.sinfo_utl_cube_arith", 100000.) ;
162  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "temp") ;
163  cpl_parameterlist_append(recipe->parameters, p) ;
164  */
165 
166  p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.value",
167  CPL_TYPE_DOUBLE, "A constant to add",
168  "sinfoni.sinfo_utl_cube_arith", 99999.0) ;
169  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "value") ;
170  cpl_parameterlist_append(recipe->parameters, p) ;
171 
172  /* Return */
173  return 0;
174 }
175 
176 /*---------------------------------------------------------------------------*/
182 /*---------------------------------------------------------------------------*/
183 static int sinfo_utl_cube_arith_exec(cpl_plugin * plugin)
184 {
185  cpl_recipe * recipe ;
186  int code=0;
187  cpl_errorstate initial_errorstate = cpl_errorstate_get();
188 
189  /* Get the recipe out of the plugin */
190  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
191  recipe = (cpl_recipe *)plugin ;
192  else return -1 ;
193  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
194  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
195 
196  code = sinfo_utl_cube_arith(recipe->parameters, recipe->frames) ;
197 
198  if (!cpl_errorstate_is_equal(initial_errorstate)) {
199  /* Dump the error history since recipe execution start.
200  At this point the recipe cannot recover from the error */
201  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
202  }
203  return code;
204 }
205 
206 /*---------------------------------------------------------------------------*/
212 /*---------------------------------------------------------------------------*/
213 static int sinfo_utl_cube_arith_destroy(cpl_plugin * plugin)
214 {
215  cpl_recipe * recipe ;
216 
217  /* Get the recipe out of the plugin */
218  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
219  recipe = (cpl_recipe *)plugin ;
220  else return -1 ;
221 
222  cpl_parameterlist_delete(recipe->parameters) ;
223  return 0 ;
224 }
void irplib_reset(void)
Reset IRPLIB state.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.