X-shooter Pipeline Reference Manual 3.8.15
xsh_util_ima_getextno.c
Go to the documentation of this file.
1/* $Id: xsh_util_ima_getextno.c,v 1.8 2012-04-26 14:03:50 amodigli Exp $
2 *
3 * This file is part of the XSHOOTER 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: 2012-04-26 14:03:50 $
24 * $Revision: 1.8 $
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
40#include <xsh_dfs.h>
41#include <xsh_data_pre.h>
42#include <xsh_parameters.h>
43#include <xsh_drl.h>
44#include <xsh_msg.h>
45#include <xsh_pfits.h>
46#include <xsh_error.h>
47//#include <xsh_utils_wrappers.h>
48
49
50/*-----------------------------------------------------------------------------
51 Defines
52 ----------------------------------------------------------------------------*/
53
54#define XSH_UTL_IMA_FSTEXT_RECIPE_ID "xsh_util_ima_getextno"
55#define XSH_UTL_IMA_FSTEXT_RECIPE_AUTHOR "A.Modigliani"
56#define XSH_UTL_IMA_FSTEXT_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
57#define PRO_IMA "PRO_IMA_UVB"
58#define KEY_VALUE_HPRO_DID "PRO-1.15"
59/*-----------------------------------------------------------------------------
60 Functions prototypes
61 ----------------------------------------------------------------------------*/
62
63static int xsh_util_ima_getextno_create(cpl_plugin *) ;
64static int xsh_util_ima_getextno_exec(cpl_plugin *) ;
65static int xsh_util_ima_getextno_destroy(cpl_plugin *) ;
66static int xsh_util_ima_getextno(cpl_parameterlist *, cpl_frameset *) ;
67
68/*-----------------------------------------------------------------------------
69 Static variables
70 ----------------------------------------------------------------------------*/
71
72static char
74"Extract extention extno from input image";
76"Extract extention extno from input image.\n"
77"extno is an input parameter.\n"
78"xsh.xsh_util_ima_getextno.extno having alias 'extno' and default 0\n"
79"Information on relevant parameters can be found with\n"
80"esorex --params xsh_util_ima_getextno\n"
81"esorex --help xsh_util_ima_getextno\n"
82"\n";
83
84/*-----------------------------------------------------------------------------
85 Functions code
86 ----------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
95/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104int cpl_plugin_get_info(cpl_pluginlist * list)
105{
106 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
107 cpl_plugin * plugin = &recipe->interface ;
108
109 cpl_plugin_init(plugin,
110 CPL_PLUGIN_API,
111 XSH_BINARY_VERSION,
112 CPL_PLUGIN_TYPE_RECIPE,
122
123 cpl_pluginlist_append(list, plugin) ;
124
125 return 0;
126}
127
128/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138static int xsh_util_ima_getextno_create(cpl_plugin * plugin)
139{
140 cpl_recipe * recipe ;
141 cpl_parameter * p ;
142
143 /* Reset library state */
144 xsh_init();
145
146 /* Get the recipe out of the plugin */
147 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
148 recipe = (cpl_recipe *)plugin ;
149 else return -1 ;
150 cpl_error_reset();
151
152
153 /* Create the parameters list in the cpl_recipe object */
154 recipe->parameters = cpl_parameterlist_new() ;
155
156
157 /* Set generic parameters (common to all recipes) */
159 recipe->parameters ) ) ;
161 /* Fill the parameters list */
162 p = cpl_parameter_new_value("xsh.xsh_util_ima_getextno.extno",
163 CPL_TYPE_INT,
164 "Extention to extract",
165 "xsh.xsh_util_ima_getextno",0);
166 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extno") ;
167 cpl_parameterlist_append(recipe->parameters, p) ;
168
169 cleanup:
170
171 /* Return */
172 return 0;
173}
174
175/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182static int xsh_util_ima_getextno_exec(cpl_plugin * plugin)
183{
184 cpl_recipe * recipe ;
185 int code=0;
186 cpl_errorstate initial_errorstate = cpl_errorstate_get();
187
188 /* Get the recipe out of the plugin */
189 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
190 recipe = (cpl_recipe *)plugin ;
191 else return -1 ;
192 cpl_error_reset();
193
194 code = xsh_util_ima_getextno(recipe->parameters, recipe->frames) ;
195
196
197 if (!cpl_errorstate_is_equal(initial_errorstate)) {
198 /* Dump the error history since recipe execution start.
199 At this point the recipe cannot recover from the error */
200 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
201 }
202
203 return code ;
204}
205
206/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
213static int xsh_util_ima_getextno_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}
225
226/*---------------------------------------------------------------------------*/
233/*---------------------------------------------------------------------------*/
234static int
235xsh_util_ima_getextno( cpl_parameterlist * parlist,
236 cpl_frameset * frames)
237{
238 cpl_parameter * param= NULL ;
239 cpl_frame* frm=NULL;
240 cpl_image* ima=NULL;
241 cpl_propertylist* plist=NULL;
242
243 int extno=0;
244 int nfrm=0;
245 int i=0;
246 const char* name=NULL;
247 char new_name[256];
248 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
249 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
250
251 /* HOW TO RETRIEVE INPUT PARAMETERS */
252 /* --stropt */
253 check(param=cpl_parameterlist_find(parlist,
254 "xsh.xsh_util_ima_getextno.extno"));
255 check(extno=cpl_parameter_get_int(param));
256
257 nfrm=cpl_frameset_get_size(frames);
258
259 for (i=0;i<nfrm;i++) {
260 frm=cpl_frameset_get_frm(frm,i);
261 check(name=cpl_frame_get_filename(frm));
262 plist=cpl_propertylist_load(name,0);
263 sprintf(new_name,"ext%d_%s",extno,name);
264 xsh_msg("new_name=%s",new_name);
265 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,extno));
266 check(cpl_image_save(ima,new_name,CPL_BPP_IEEE_FLOAT,plist,
267 CPL_IO_DEFAULT));
268 xsh_free_image(&ima);
269 xsh_free_propertylist(&plist);
270 }
271
272 cleanup:
273 xsh_free_image(&ima);
274
275
276 if (cpl_error_get_code()) {
277 return -1 ;
278 } else {
279 return 0 ;
280 }
281
282}
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
static int xsh_util_ima_getextno_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_ima_getextno_create(cpl_plugin *)
Setup the recipe options
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_ima_getextno_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_ima_getextno(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
const char * xsh_get_license(void)
Get the pipeline copyright and license.
Definition: xsh_utils.c:1193
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
#define XSH_UTL_IMA_FSTEXT_RECIPE_CONTACT
static char xsh_util_ima_getextno_description_short[]
static char xsh_util_ima_getextno_description[]
#define XSH_UTL_IMA_FSTEXT_RECIPE_ID
#define XSH_UTL_IMA_FSTEXT_RECIPE_AUTHOR