X-shooter Pipeline Reference Manual 3.8.15
xsh_model_anneal.c
Go to the documentation of this file.
1/* $Id: xsh_model_anneal.c,v 1.20 2011-12-02 14:15:46 amodigli Exp $
2 *
3 * This file is part of the XSH 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: 2011-12-02 14:15:46 $
24 * $Revision: 1.20 $
25 * $Name: not supported by cvs2svn $
26 */
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
42/*-----------------------------------------------------------------------------
43 Includes
44 ---------------------------------------------------------------------------*/
45
46#include <cpl.h>
47#include <math.h>
48
49#include <stdlib.h>
50#include <stdio.h>
51#include <string.h>
52
53#include <xsh_model_anneal.h>
54#include <xsh_dfs.h>
55#include <xsh_utils.h>
56#include <xsh_pfits.h>
57#include <xsh_msg.h>
58#include <xsh_error.h>
59
60/*-----------------------------------------------------------------------------
61 Functions prototypes
62 ---------------------------------------------------------------------------*/
63
64static int xsh_model_anneal_create(cpl_plugin *) ;
65static int xsh_model_anneal_exec(cpl_plugin *) ;
66static int xsh_model_anneal_destroy(cpl_plugin *) ;
67static int xsh_model_anneal(cpl_parameterlist *, cpl_frameset *) ;
68static int xsh_model_anneal_save(const cpl_table *, cpl_parameterlist *,
69 cpl_frameset *) ;
70
71/*-----------------------------------------------------------------------------
72 Static variables
73 ---------------------------------------------------------------------------*/
74
76 "This recipe is for development use only.\n";
78"Compute optimum config given wavelengths and observed detected positions";
79/*-----------------------------------------------------------------------------
80 Functions code
81 ---------------------------------------------------------------------------*/
82
83/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93int cpl_plugin_get_info(cpl_pluginlist * list)
94{
95 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
96 cpl_plugin * plugin = &recipe->interface ;
97
98 cpl_plugin_init(plugin,
99 CPL_PLUGIN_API,
100 XSH_BINARY_VERSION,
101 CPL_PLUGIN_TYPE_RECIPE,
102 "xsh_model_anneal",
105 "Paul Bristow",
106 "bristowp@eso.org",
111
112 cpl_pluginlist_append(list, plugin) ;
113
114 return 0;
115}
116
117/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126static int xsh_model_anneal_create(cpl_plugin * plugin)
127{
128 cpl_recipe * recipe ;
129 cpl_parameter * p=NULL;
130
131 /* Reset library state */
132 xsh_init();
133
134 /* Check input */
135 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
136
137
138 /* Check that the plugin is part of a valid recipe */
139 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
140 recipe = (cpl_recipe *)plugin ;
141 else return -1 ;
142
143 /* Create the parameters list in the cpl_recipe object */
144 recipe->parameters = cpl_parameterlist_new() ;
145
146 p = cpl_parameter_new_enum("xsh.xsh_model_compute.arm",
147 CPL_TYPE_STRING,
148 "Arm setting: ",
149 "xsh.xsh_model_compute",
150 "vis",
151 3,"uvb","vis","nir");
152
153 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"arm");
154 cpl_parameterlist_append(recipe->parameters, p);
155
156 cleanup:
157
158 /* Return */
159 return 0;
160}
161/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168static int xsh_model_anneal_exec(cpl_plugin * plugin)
169{
170 cpl_recipe * recipe ;
171
172 /* Get the recipe out of the plugin */
173 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
174 recipe = (cpl_recipe *)plugin ;
175 else return -1 ;
176
177 return xsh_model_anneal(recipe->parameters, recipe->frames) ;
178}
179
180/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187static int xsh_model_anneal_destroy(cpl_plugin * plugin)
188{
189 cpl_recipe * recipe ;
190
191 /* Get the recipe out of the plugin */
192 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
193 recipe = (cpl_recipe *)plugin ;
194 else return -1 ;
195
196 cpl_parameterlist_delete(recipe->parameters) ;
197 return 0 ;
198}
199
200/*---------------------------------------------------------------------------*/
207/*---------------------------------------------------------------------------*/
209 cpl_parameterlist* parlist,
210 cpl_frameset* frameset)
211{
212 cpl_frame* xs_config ;
213 //cpl_frame* resid_frame ;
214 cpl_frame* meas_coord ;
215 //cpl_frame* new_config_frame;
216 cpl_table* config_table ;
217 cpl_parameter* param=NULL;
219 const char* arm=NULL;
220 int nraw=0;
221
222 /* Identify the RAW and CALIB frames in the input frameset
223 if (xsh_dfs_set_groups(frameset)) {
224 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
225 return -1 ;
226 }*/
227
228 if( (nraw=cpl_frameset_get_size(frameset)) ==0) goto cleanup;
229
230 param = cpl_parameterlist_find(parlist,"xsh.xsh_model_compute.arm");
231
232 arm = cpl_parameter_get_string(param);
233
235 if(strcmp(arm,"uvb") == 0) xsh_instrument_set_arm(instrument,XSH_ARM_UVB);
236 if(strcmp(arm,"vis") == 0) xsh_instrument_set_arm(instrument,XSH_ARM_VIS);
237 if(strcmp(arm,"nir") == 0) xsh_instrument_set_arm(instrument,XSH_ARM_NIR);
238
239 /* Retrieve calibration data */
240 check(xs_config = xsh_find_calpro_model_config(frameset,instrument)) ;
241 check(meas_coord = xsh_find_calpro_model_meas_coord(frameset,instrument)) ;
242
243
244/* /\*Test pipe anneal function BEGIN*\/ */
245/* struct xs_3 xs_3_config; */
246/* struct xs_3* p_xs_3_config; */
247/* p_xs_3_config=&xs_3_config; */
248/* resid_frame = cpl_frameset_find(frameset, XSH_MEASCOORD); */
249/* if (xsh_model_config_load_best(xs_config, p_xs_3_config) == -1) { */
250/* cpl_msg_error(__func__, "Cannot load %s as a config", */
251/* cpl_frame_get_filename(xs_config)) ; */
252/* return -1 ; */
253/* } */
254
255/* new_config_frame = xsh_model_pipe_anneal(xs_config, */
256/* resid_frame, */
257/* 200); */
258/* double x,y; */
259/* xsh_model_get_xy(p_xs_3_config,1,750.0,22,0.0,&x,&y); */
260/* printf("750nm in order 22 on arm %d : x=%lf y=%lf \n",
261 xsh_instrument_get_arm(1),x,y); */
262
263/* xsh_msg("new config_frame %s %s",
264 cpl_frame_get_tag(new_config_frame),
265 cpl_frame_get_filename(new_config_frame)); */
266
267/* exit(-1); */
268/* /\*Test pipe anneal function END*\/ */
269
270 /* Apply the computation here */
271 if ((config_table = xsh_model_anneal_reduce(
272 cpl_frame_get_filename(xs_config),
273 cpl_frame_get_tag(xs_config),
274 cpl_frame_get_filename(meas_coord))) == NULL) {
275 cpl_msg_error(__func__, "Failed computing the model") ;
276 return -1 ;
277 }
278
279
280 /* Save the result */
281 cpl_msg_info(__func__, "Save the products") ;
282 cpl_msg_indent_more() ;
283 if (xsh_model_anneal_save((const cpl_table*)config_table, parlist,
284 frameset) == -1) {
285 cpl_msg_error(__func__, "Cannot save products") ;
286 cpl_msg_indent_less() ;
287 cpl_table_delete(config_table) ;
288 return -1 ;
289 }
290 cpl_table_delete(config_table) ;
291 cpl_msg_indent_less() ;
292
293 cleanup:
295
296 /* Return */
297 if (cpl_error_get_code())
298 return -1 ;
299 else
300 return 0 ;
301}
302
303/*---------------------------------------------------------------------------*/
311/*---------------------------------------------------------------------------*/
313 const cpl_table* out_table,
314 cpl_parameterlist* parlist,
315 cpl_frameset* set)
316{
317 char name_o[512] ;
318 cpl_propertylist* plist ;
319 cpl_frame* product_frame ;
320
321 /* Get the reference frame */
322 //ref_frame=irplib_frameset_get_first_from_group(set,CPL_FRAME_GROUP_RAW);
323
324 /* Set the file name */
325 sprintf(name_o, "xsh_model_anneal_save.fits") ;
326 cpl_msg_info(__func__, "Writing %s" , name_o) ;
327
328 /* Get FITS header from reference file */
329 plist = cpl_propertylist_new();
330 cpl_propertylist_append_string(plist, "INSTRUME", "XSH") ;
331 cpl_propertylist_append_int(plist,"Num_pinh",9);
332
333
334 /* Create product frame */
335 product_frame = cpl_frame_new() ;
336 cpl_frame_set_filename(product_frame, name_o) ;
337 cpl_frame_set_tag(product_frame, XSH_MOD_CFG) ;
338 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE);
339 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
340 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
341
342 /* Add DataFlow keywords */
343 if (cpl_dfs_setup_product_header(plist, product_frame, set, parlist,
344 "xsh_model_anneal",
345 PACKAGE "/" PACKAGE_VERSION,
346 "PRO-1.15",NULL)!=CPL_ERROR_NONE) {
347 cpl_msg_warning(__func__, "Problem in the product DFS-compliance") ;
348 cpl_error_reset() ;
349 }
350
351 /* Save the file */
352 if (cpl_table_save(out_table, plist, NULL, name_o,
353 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
354 cpl_msg_error(__func__, "Cannot save the product");
355 cpl_frame_delete(product_frame) ;
356 cpl_propertylist_delete(plist) ;
357 return -1 ;
358 }
359 cpl_propertylist_delete(plist) ;
360
361 /* Log the saved file in the input frameset */
362 cpl_frameset_insert(set, product_frame);
363 /* Return */
364 return 0 ;
365}
static xsh_instrument * instrument
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define check(COMMAND)
Definition: xsh_error.h:71
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
cpl_table * xsh_model_anneal_reduce(const char *xsh_config_file, const char *xsh_config_tag, const char *meas_coord_file)
The actual anneal computation takes place here.
static int xsh_model_anneal_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_model_anneal_save(const cpl_table *, cpl_parameterlist *, cpl_frameset *)
Save the product of the recipe.
static char xsh_model_anneal_description_short[]
static char xsh_model_anneal_description[]
static int xsh_model_anneal_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_model_anneal_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_model_anneal(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
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
@ XSH_ARM_UVB
@ XSH_ARM_NIR
@ XSH_ARM_VIS
cpl_frame * xsh_find_calpro_model_meas_coord(cpl_frameset *frames, xsh_instrument *instr)
Find model config frame.
Definition: xsh_dfs.c:4240
cpl_frame * xsh_find_calpro_model_config(cpl_frameset *frames, xsh_instrument *instr)
Find model config frame.
Definition: xsh_dfs.c:4186
#define XSH_MOD_CFG
Definition: xsh_dfs.h:1261