SINFONI Pipeline Reference Manual  2.6.0
recipes/sinfo_utl_spectrum_wavelength_shift.c
1 /* $Id: sinfo_utl_spectrum_wavelength_shift.c,v 1.11 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.11 $
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 /* irplib */
37 #include <cpl.h>
38 
39 /* irplib */
40 #include <irplib_utils.h>
41 #include <sinfo_msg.h>
42 
43 #include <sinfo_tpl_utils.h>
44 #include <sinfo_pfits.h>
45 #include <sinfo_tpl_dfs.h>
46 #include <sinfo_utl_spectrum_wavelength_shift.h>
47 /*-----------------------------------------------------------------------------
48  Functions prototypes
49  ----------------------------------------------------------------------------*/
50 
51 static int sinfo_utl_spectrum_wavelength_shift_create(cpl_plugin *) ;
52 static int sinfo_utl_spectrum_wavelength_shift_exec(cpl_plugin *) ;
53 static int sinfo_utl_spectrum_wavelength_shift_destroy(cpl_plugin *) ;
54 
55 /*-----------------------------------------------------------------------------
56  Static variables
57  ----------------------------------------------------------------------------*/
58 
59 static char sinfo_utl_spectrum_wavelength_shift_description1[] =
60  "This recipe shifts a spectrum in wavelength using a given \n"
61  "interpolation method. The input file is a spectrum.\n"
62  "Its associated tag should be SPECTRUM.\n"
63  "The output is a spectrum shifted by a given amount. \n";
64 
65 static char sinfo_utl_spectrum_wavelength_shift_description2[] =
66  "Parameters are \n"
67  "sinfoni.sinfo_utl_spectrum_arith.method\n"
68  "sinfoni.sinfo_utl_spectrum_wavelength_shift.shift\n"
69  "having aliases 'method' and 'shift' \n"
70  "\n";
71 
72 static char sinfo_utl_spectrum_wavelength_shift_description[900];
73 
74 /*-----------------------------------------------------------------------------
75  Functions code
76  ----------------------------------------------------------------------------*/
77 /*---------------------------------------------------------------------------*/
82 /*---------------------------------------------------------------------------*/
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  strcpy(sinfo_utl_spectrum_wavelength_shift_description,
100  sinfo_utl_spectrum_wavelength_shift_description1);
101  strcat(sinfo_utl_spectrum_wavelength_shift_description,
102  sinfo_utl_spectrum_wavelength_shift_description2);
103 
104  cpl_plugin_init(plugin,
105  CPL_PLUGIN_API,
106  SINFONI_BINARY_VERSION,
107  CPL_PLUGIN_TYPE_RECIPE,
108  "sinfo_utl_spectrum_wavelength_shift",
109  "Spectrum wavelength shift",
110  sinfo_utl_spectrum_wavelength_shift_description,
111  "Andrea Modigliani",
112  "Andrea.Modigliani@eso.org",
113  sinfo_get_license(),
114  sinfo_utl_spectrum_wavelength_shift_create,
115  sinfo_utl_spectrum_wavelength_shift_exec,
116  sinfo_utl_spectrum_wavelength_shift_destroy) ;
117 
118  cpl_pluginlist_append(list, plugin) ;
119 
120  return 0;
121 }
122 
123 /*---------------------------------------------------------------------------*/
132 /*---------------------------------------------------------------------------*/
133 static int sinfo_utl_spectrum_wavelength_shift_create(cpl_plugin * plugin)
134 {
135  cpl_recipe * recipe ;
136  cpl_parameter * p ;
137 
138  /* Get the recipe out of the plugin */
139  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
140  recipe = (cpl_recipe *)plugin ;
141  else return -1 ;
142  cpl_error_reset();
143  irplib_reset();
144 
145  /* Create the parameters list in the cpl_recipe object */
146  recipe->parameters = cpl_parameterlist_new() ;
147 
148  /* Fill the parameters list */
149  /* --stropt */
150  p = cpl_parameter_new_value("sinfoni.sinfo_utl_spectrum_arith.method",
151  CPL_TYPE_STRING,
152  "A spectral shift method: "
153  "'S' (Spline),'P' (Polynomial)",
154  "sinfoni.sinfo_utl_spectrum_arith","S");
155  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "method") ;
156  cpl_parameterlist_append(recipe->parameters, p) ;
157 
158  /* --doubleopt */
159  p = cpl_parameter_new_value("sinfoni.sinfo_utl_spectrum_wavelength_shift.shift",
160  CPL_TYPE_DOUBLE,
161  "wavelength shift in micron",
162  "sinfoni.sinfo_utl_spectrum_wavelength_shift",
163  0.1) ;
164  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "shift") ;
165  cpl_parameterlist_append(recipe->parameters, p) ;
166 
167  /* Return */
168  return 0;
169 }
170 
171 /*---------------------------------------------------------------------------*/
177 /*---------------------------------------------------------------------------*/
178 static int sinfo_utl_spectrum_wavelength_shift_exec(cpl_plugin * plugin)
179 {
180  cpl_recipe * recipe ;
181  int code=0;
182  cpl_errorstate initial_errorstate = cpl_errorstate_get();
183 
184  /* Get the recipe out of the plugin */
185  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
186  recipe = (cpl_recipe *)plugin ;
187  else return -1 ;
188  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
189  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
190  code = sinfo_utl_spectrum_wavelength_shift(recipe->parameters,
191  recipe->frames) ;
192  if (!cpl_errorstate_is_equal(initial_errorstate)) {
193  /* Dump the error history since recipe execution start.
194  At this point the recipe cannot recover from the error */
195  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
196  }
197  return code ;
198 }
199 
200 /*---------------------------------------------------------------------------*/
206 /*---------------------------------------------------------------------------*/
207 static int sinfo_utl_spectrum_wavelength_shift_destroy(cpl_plugin * plugin)
208 {
209  cpl_recipe * recipe ;
210 
211  /* Get the recipe out of the plugin */
212  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
213  recipe = (cpl_recipe *)plugin ;
214  else return -1 ;
215 
216  cpl_parameterlist_delete(recipe->parameters) ;
217  return 0 ;
218 }
219 
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
void irplib_reset(void)
Reset IRPLIB state.