X-shooter Pipeline Reference Manual 3.8.15
xsh_util_bpmap2rp.c
Go to the documentation of this file.
1/* $Id: xsh_util_bpmap2rp.c,v 1.3 2012-04-26 14:07:00 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:07:00 $
24 * $Revision: 1.3 $
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 <irplib_utils.h>
42
43//#include <xsh_tpl_utils.h>
44//#include <xsh_pfits.h>
45//#include <xsh_tpl_dfs.h>
46//#include <xsh_key_names.h>
47//#include <xsh_pro_types.h>
48//#include <xsh_functions.h>
49#include <xsh_dfs.h>
50#include <xsh_data_pre.h>
51#include <xsh_parameters.h>
52#include <xsh_drl.h>
53#include <xsh_msg.h>
54#include <xsh_pfits.h>
55#include <xsh_error.h>
56//#include <xsh_utils_wrappers.h>
57
58
59/*-----------------------------------------------------------------------------
60 Defines
61 ----------------------------------------------------------------------------*/
62
63#define XSH_UTL_BPMAP2RP_RECIPE_ID "xsh_util_bpmap2rp"
64#define XSH_UTL_BPMAP2RP_RECIPE_AUTHOR "A.Modigliani"
65#define XSH_UTL_BPMAP2RP_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
66#define PRO_IMA "PRO_IMA_UVB"
67#define KEY_VALUE_HPRO_DID "PRO-1.15"
68/*-----------------------------------------------------------------------------
69 Functions prototypes
70 ----------------------------------------------------------------------------*/
71
72static int xsh_util_bpmap2rp_create(cpl_plugin *) ;
73static int xsh_util_bpmap2rp_exec(cpl_plugin *) ;
74static int xsh_util_bpmap2rp_destroy(cpl_plugin *) ;
75static int xsh_util_bpmap2rp(cpl_parameterlist *, cpl_frameset *) ;
76
77/*-----------------------------------------------------------------------------
78 Static variables
79 ----------------------------------------------------------------------------*/
80
81static char
82xsh_util_bpmap2rp_description_short[] = "Converts BP map code to RP code";
84"This recipe performs image computation.\n"
85"Information on relevant parameters can be found with\n"
86"esorex --params xsh_util_bpmap2rp\n"
87"esorex --help xsh_util_bpmap2rp\n"
88"\n";
89
90/*-----------------------------------------------------------------------------
91 Functions code
92 ----------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
98/*---------------------------------------------------------------------------*/
99
101/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110int cpl_plugin_get_info(cpl_pluginlist * list)
111{
112 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
113 cpl_plugin * plugin = &recipe->interface ;
114
115 cpl_plugin_init(plugin,
116 CPL_PLUGIN_API,
117 XSH_BINARY_VERSION,
118 CPL_PLUGIN_TYPE_RECIPE,
128
129 cpl_pluginlist_append(list, plugin) ;
130
131 return 0;
132}
133
134/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144static int xsh_util_bpmap2rp_create(cpl_plugin * plugin)
145{
146 cpl_recipe * recipe ;
147 cpl_parameter * p ;
148
149 /* Reset library state */
150 xsh_init();
151
152 /* Get the recipe out of the plugin */
153 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
154 recipe = (cpl_recipe *)plugin ;
155 else return -1 ;
156 cpl_error_reset();
157
158
159 /* Create the parameters list in the cpl_recipe object */
160 recipe->parameters = cpl_parameterlist_new() ;
161
162
163 /* Set generic parameters (common to all recipes) */
165 recipe->parameters ) ) ;
167 /* Fill the parameters list */
168 /* --stropt */
169 p = cpl_parameter_new_value("xsh.xsh_util_bpmap2rp.op",
170 CPL_TYPE_STRING,
171 "A possible operation",
172 "xsh.xsh_util_bpmap2rp","+");
173 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;
174 cpl_parameterlist_append(recipe->parameters, p) ;
175
176 /* --doubleopt */
177 p = cpl_parameter_new_value("xsh.xsh_util_bpmap2rp.value",
178 CPL_TYPE_DOUBLE, "a value", "xsh.xsh_util_bpmap2rp", 9999.) ;
179 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "value") ;
180 cpl_parameterlist_append(recipe->parameters, p) ;
181 cleanup:
182
183 /* Return */
184 return 0;
185}
186
187/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
194static int xsh_util_bpmap2rp_exec(cpl_plugin * plugin)
195{
196 cpl_recipe * recipe ;
197 int code=0;
198 cpl_errorstate initial_errorstate = cpl_errorstate_get();
199
200 /* Get the recipe out of the plugin */
201 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
202 recipe = (cpl_recipe *)plugin ;
203 else return -1 ;
204 cpl_error_reset();
205
206 code = xsh_util_bpmap2rp(recipe->parameters, recipe->frames) ;
207
208
209 if (!cpl_errorstate_is_equal(initial_errorstate)) {
210 /* Dump the error history since recipe execution start.
211 At this point the recipe cannot recover from the error */
212 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
213 }
214
215 return code ;
216}
217
218/*---------------------------------------------------------------------------*/
224/*---------------------------------------------------------------------------*/
225static int xsh_util_bpmap2rp_destroy(cpl_plugin * plugin)
226{
227 cpl_recipe * recipe ;
228
229 /* Get the recipe out of the plugin */
230 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
231 recipe = (cpl_recipe *)plugin ;
232 else return -1 ;
233
234 cpl_parameterlist_delete(recipe->parameters) ;
235 return 0 ;
236}
237
238/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246static int
247xsh_util_bpmap2rp( cpl_parameterlist * parlist,
248 cpl_frameset * framelist)
249{
250 cpl_image * ima=NULL ;
251 cpl_propertylist * head=NULL ;
252 int n=0;
253 int i=0;
254 const char* name=NULL;
255 cpl_frame* frm=NULL;
256
257 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
258 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
259
260 n=cpl_frameset_get_size(framelist);
261 if(n<1) {
262 xsh_msg_error("Empty input frame list!");
263 goto cleanup ;
264 }
265
266
267 for(i=0;i<n;i++) {
268 frm=cpl_frameset_get_frame(framelist,i);
269 name=cpl_frame_get_filename(frm);
270 ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
271 head=cpl_propertylist_load(name,0);
273 cpl_image_save(ima,name,CPL_BPP_IEEE_FLOAT,head,CPL_IO_DEFAULT);
275 xsh_free_image(&ima);
276 }
277
278 cleanup:
279
280 xsh_free_image(&ima);
281 xsh_free_propertylist(&head) ;
282
283 if (cpl_error_get_code()) {
284 return -1 ;
285 } else {
286 return 0 ;
287 }
288
289}
void xsh_bpmap_bitwise_to_flag(cpl_image *bpmap, int flag)
#define check(COMMAND)
Definition: xsh_error.h:71
#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_bpmap2rp_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_bpmap2rp_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_bpmap2rp_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_bpmap2rp(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
#define QFLAG_CALIB_FILE_DEFECT
int n
Definition: xsh_detmon_lg.c:92
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_BPMAP2RP_RECIPE_ID
#define XSH_UTL_BPMAP2RP_RECIPE_AUTHOR
static char xsh_util_bpmap2rp_description[]
static char xsh_util_bpmap2rp_description_short[]
#define XSH_UTL_BPMAP2RP_RECIPE_CONTACT