X-shooter Pipeline Reference Manual 3.8.15
xsh_util_ima_shift.c
Go to the documentation of this file.
1/* $Id: xsh_util_ima_shift.c,v 1.6 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.6 $
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/* irplib */
41#include <xsh_dfs.h>
42//#include <xsh_data_pre.h>
43#include <xsh_parameters.h>
44#include <xsh_drl.h>
45#include <xsh_msg.h>
46#include <xsh_pfits.h>
47#include <xsh_error.h>
48
49
50/*-----------------------------------------------------------------------------
51 Defines
52 ----------------------------------------------------------------------------*/
53
54#define XSH_UTL_IMA_SHIFT_RECIPE_ID "xsh_util_ima_shift"
55#define XSH_UTL_IMA_SHIFT_RECIPE_AUTHOR "A.Modigliani"
56#define XSH_UTL_IMA_SHIFT_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
57#define PRO_IMA "PRO_IMA"
58#define KEY_VALUE_HPRO_DID "PRO-1.15"
59/*-----------------------------------------------------------------------------
60 Functions prototypes
61 ----------------------------------------------------------------------------*/
62
63static int xsh_util_ima_shift_create(cpl_plugin *) ;
64static int xsh_util_ima_shift_exec(cpl_plugin *) ;
65static int xsh_util_ima_shift_destroy(cpl_plugin *) ;
66static int xsh_util_ima_shift(cpl_parameterlist *, cpl_frameset *) ;
67
68/*-----------------------------------------------------------------------------
69 Static variables
70 ----------------------------------------------------------------------------*/
71
72static char
73xsh_util_ima_shift_description_short[] = "Shift an image along X or Y";
75 "This recipe performs image shift along x or y.\n"
76 "The input file is an image tagged as 'IMA'.\n"
77 "The output is a shifted image\n"
78 "xsh.xsh_util_ima_shift.shiftx having alias 'shiftx'\n"
79 "xsh.xsh_util_ima_shift.shifty having alias 'shifty'\n"
80 "Information on relevant parameters can be found with\n"
81 "esorex --params xsh_util_ima_shift\n"
82 "esorex --help xsh_util_ima_shift\n"
83 "\n";
84
85/*-----------------------------------------------------------------------------
86 Functions code
87 ----------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
96/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105int cpl_plugin_get_info(cpl_pluginlist * list)
106{
107 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
108 cpl_plugin * plugin = &recipe->interface ;
109
110 cpl_plugin_init(plugin,
111 CPL_PLUGIN_API,
112 XSH_BINARY_VERSION,
113 CPL_PLUGIN_TYPE_RECIPE,
123
124 cpl_pluginlist_append(list, plugin) ;
125
126 return 0;
127}
128
129/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139static int xsh_util_ima_shift_create(cpl_plugin * plugin)
140{
141 cpl_recipe * recipe ;
142 cpl_parameter * p ;
143
144 /* Reset library state */
145 xsh_init();
146
147 /* Get the recipe out of the plugin */
148 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
149 recipe = (cpl_recipe *)plugin ;
150 else return -1 ;
151 cpl_error_reset();
152
153
154 /* Create the parameters list in the cpl_recipe object */
155 recipe->parameters = cpl_parameterlist_new() ;
156
157
158 /* Set generic parameters (common to all recipes) */
160 recipe->parameters ) ) ;
162
163 p = cpl_parameter_new_value("xsh.xsh_util_ima_shift.shiftx",
164 CPL_TYPE_INT,
165 "A possible X shift",
166 "xsh.xsh_util_ima_shiftx",0);
167 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "shiftx") ;
168 cpl_parameterlist_append(recipe->parameters, p) ;
169
170 p = cpl_parameter_new_value("xsh.xsh_util_ima_shift.shifty",
171 CPL_TYPE_INT,
172 "A possible Y shift",
173 "xsh.xsh_util_ima_shifty",0);
174 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "shifty") ;
175 cpl_parameterlist_append(recipe->parameters, p) ;
176
177 cleanup:
178
179 /* Return */
180 return 0;
181}
182
183/*---------------------------------------------------------------------------*/
189/*---------------------------------------------------------------------------*/
190static int xsh_util_ima_shift_exec(cpl_plugin * plugin)
191{
192 cpl_recipe * recipe ;
193 int code=0;
194 cpl_errorstate initial_errorstate = cpl_errorstate_get();
195
196 /* Get the recipe out of the plugin */
197 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
198 recipe = (cpl_recipe *)plugin ;
199 else return -1 ;
200 cpl_error_reset();
201
202 code = xsh_util_ima_shift(recipe->parameters, recipe->frames) ;
203
204
205 if (!cpl_errorstate_is_equal(initial_errorstate)) {
206 /* Dump the error history since recipe execution start.
207 At this point the recipe cannot recover from the error */
208 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
209 }
210
211 return code ;
212}
213
214/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221static int xsh_util_ima_shift_destroy(cpl_plugin * plugin)
222{
223 cpl_recipe * recipe ;
224
225 /* Get the recipe out of the plugin */
226 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
227 recipe = (cpl_recipe *)plugin ;
228 else return -1 ;
229
230 cpl_parameterlist_delete(recipe->parameters) ;
231 return 0 ;
232}
233
234/*---------------------------------------------------------------------------*/
241/*---------------------------------------------------------------------------*/
242static int
243xsh_util_ima_shift( cpl_parameterlist * parlist,
244 cpl_frameset * framelist)
245{
246 cpl_parameter * param= NULL ;
247 int shiftx=0 ;
248 int shifty=0 ;
249 cpl_image * ima=NULL ;
250 char name_o[256];
251 cpl_propertylist * plist=NULL ;
252 cpl_frameset * raw_set=NULL;
253 int nraw=0;
254 int n=0;
255 int i=0;
256 cpl_frame* frm=NULL;
257 const char* name=NULL;
258
259 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
260 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
261
262 /* HOW TO RETRIEVE INPUT PARAMETERS */
263 /* --stropt */
264 check(param=cpl_parameterlist_find(parlist,
265 "xsh.xsh_util_ima_shift.shiftx"));
266 check(shiftx=cpl_parameter_get_int(param));
267
268 check(param=cpl_parameterlist_find(parlist,
269 "xsh.xsh_util_ima_shift.shifty"));
270 check(shifty=cpl_parameter_get_int(param));
271
272
273 n=cpl_frameset_get_size(framelist);
274 if(n<1) {
275 xsh_msg_error("Empty input frame list!");
276 goto cleanup ;
277 }
278
279 /* HOW TO ACCESS INPUT DATA */
280 check_msg(raw_set=xsh_frameset_extract(framelist,XSH_IMA),
281 "Found no input frames with tag %s",XSH_IMA);
282 check(nraw=cpl_frameset_get_size(raw_set));
283 if (nraw<1) {
284 xsh_msg_error("Found no input frames with tag %s",XSH_IMA);
285 goto cleanup;
286 } else {
287 for(i=0;i<nraw;i++) {
288 check(frm=cpl_frameset_get_frame(raw_set,i));
289 check(name=cpl_frame_get_filename(frm));
290 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
291 check(cpl_image_shift(ima,shiftx,shifty));
292 check(plist=cpl_propertylist_load(name,0));
293 check(sprintf(name_o,"shiftx%d_shifty%d_%s",shiftx,shifty,name));
294 xsh_msg("name_o=%s",name_o);
295 check(cpl_image_save(ima,name_o,CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
296 xsh_free_propertylist(&plist);
297 xsh_free_image(&ima);
298 }
299 }
300 xsh_free_frameset(&raw_set);
301
302 cleanup:
303 xsh_free_propertylist(&plist);
304 xsh_free_image(&ima);
305 xsh_free_frameset(&raw_set);
306
307 if (cpl_error_get_code()) {
308 return -1 ;
309 } else {
310 return 0 ;
311 }
312}
#define check(COMMAND)
Definition: xsh_error.h:71
#define check_msg(COMMAND,...)
Definition: xsh_error.h:62
#define xsh_msg_error(...)
Print an error message.
Definition: xsh_msg.h:62
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_ima_shift_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_ima_shift_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_ima_shift(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_ima_shift_create(cpl_plugin *)
Setup the recipe options
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
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
int n
Definition: xsh_detmon_lg.c:92
cpl_frameset * xsh_frameset_extract(const cpl_frameset *frames, const char *tag)
Extract frames with given tag from frameset.
Definition: xsh_dfs.c:983
#define XSH_IMA
Definition: xsh_dfs.h:236
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_SHIFT_RECIPE_AUTHOR
#define XSH_UTL_IMA_SHIFT_RECIPE_ID
#define XSH_UTL_IMA_SHIFT_RECIPE_CONTACT
static char xsh_util_ima_shift_description_short[]
static char xsh_util_ima_shift_description[]