X-shooter Pipeline Reference Manual 3.8.15
xsh_util_ima_subsample.c
Go to the documentation of this file.
1/* $Id: xsh_util_ima_subsample.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.h>
48#include <xsh_utils_image.h>
49
50/*-----------------------------------------------------------------------------
51 Defines
52 ----------------------------------------------------------------------------*/
53
54#define XSH_UTL_IMA_SUBSAMPLE_RECIPE_ID "xsh_util_ima_subsample"
55#define XSH_UTL_IMA_SUBSAMPLE_RECIPE_AUTHOR "A.Modigliani"
56#define XSH_UTL_IMA_SUBSAMPLE_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_subsample_create(cpl_plugin *) ;
64static int xsh_util_ima_subsample_exec(cpl_plugin *) ;
65static int xsh_util_ima_subsample_destroy(cpl_plugin *) ;
66static int xsh_util_ima_subsample(cpl_parameterlist *, cpl_frameset *) ;
67
68/*-----------------------------------------------------------------------------
69 Static variables
70 ----------------------------------------------------------------------------*/
71
72static char
75"This recipe performs image subsampling (no flux conservation).\n"
76"The input files should be list in an input file (no need to specify a tag)\n"
77"The output are resampled images with filenames\n"
78"binX_binY_filename.fits, \n"
79"where X and Y are the input binx/y parameters values\n"
80"Information on relevant parameters can be found with\n"
81"esorex --params xsh_util_ima_subsample\n"
82"esorex --help xsh_util_ima_subsample\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_subsample_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 /* Fill the parameters list */
163 p = cpl_parameter_new_range("xsh.xsh_util_ima_subsample.fctx",
164 CPL_TYPE_INT,
165 "Over-sampling X factor: pix_size_0/pix_size_i",
166 "xsh.xsh_util_ima_subsample",1,1,2);
167 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fctx") ;
168 cpl_parameterlist_append(recipe->parameters, p) ;
169
170 p = cpl_parameter_new_range("xsh.xsh_util_ima_subsample.fcty",
171 CPL_TYPE_INT,
172 "Over-sampling Y factor: pix_size_o/pix_size_i",
173 "xsh.xsh_util_ima_subsample",1,1,2);
174 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fcty") ;
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_subsample_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_subsample(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_subsample_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_subsample( cpl_parameterlist * parlist,
244 cpl_frameset * frames)
245{
246 cpl_parameter * param= NULL ;
247 cpl_frame* frm=NULL;
248 cpl_frame* frm_cor=NULL;
249 cpl_image* ima_dat=NULL;
250
251 cpl_image* ima_datr=NULL;
252 cpl_propertylist* plist=NULL;
253
254 int fctx=1;
255 int fcty=1;
256
257 int nfrm=0;
258 int i=0;
259
260 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
261 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
262
263 /* HOW TO RETRIEVE INPUT PARAMETERS */
264 /* --stropt */
265 check(param=cpl_parameterlist_find(parlist,
266 "xsh.xsh_util_ima_subsample.fctx"));
267 check(fctx=cpl_parameter_get_int(param));
268
269
270 check(param=cpl_parameterlist_find(parlist,
271 "xsh.xsh_util_ima_subsample.fcty"));
272 check(fcty=cpl_parameter_get_int(param));
273 nfrm=cpl_frameset_get_size(frames);
274
275 for(i=0;i,nfrm;i++) {
276 frm = cpl_frameset_get_frame(frames,i);
277 check(frm_cor=xsh_frame_image_div_by_fct(frm,fctx,fcty));
278 }
279
280 cleanup:
281 xsh_free_image(&ima_dat);
282 xsh_free_image(&ima_datr);
283 xsh_free_propertylist(&plist);
284
285 if (cpl_error_get_code()) {
286 return -1 ;
287 } else {
288 return 0 ;
289 }
290
291}
#define check(COMMAND)
Definition: xsh_error.h:71
#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_subsample_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_ima_subsample_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_ima_subsample(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_ima_subsample_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
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_SUBSAMPLE_RECIPE_CONTACT
#define XSH_UTL_IMA_SUBSAMPLE_RECIPE_AUTHOR
static char xsh_util_ima_subsample_description_short[]
static char xsh_util_ima_subsample_description[]
#define XSH_UTL_IMA_SUBSAMPLE_RECIPE_ID
cpl_frame * xsh_frame_image_div_by_fct(cpl_frame *frm, const int fctx, const int fcty)