X-shooter Pipeline Reference Manual 3.8.15
test-xsh_model_maps_create.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2012-12-07 16:51:34 $
23 * $Revision: 1.9 $
24*/
25
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*-------------------------------------------------------------------------*/
36/*-------------------------------------------------------------------------*/
39/*--------------------------------------------------------------------------
40 Includes
41 --------------------------------------------------------------------------*/
42
43#include <tests.h>
44
45#include <xsh_data_pre.h>
46#include <xsh_error.h>
47#include <xsh_msg.h>
48#include <xsh_data_instrument.h>
49#include <xsh_data_resid_tab.h>
50#include <xsh_drl.h>
51#include <xsh_pfits.h>
52
53#include <xsh_model_io.h>
54#include <xsh_model_kernel.h>
55#include <cpl.h>
56#include <math.h>
57
58#include <getopt.h>
59
60/*--------------------------------------------------------------------------
61 Defines
62 --------------------------------------------------------------------------*/
63
64#define MODULE_ID "XSH_MODEL_MAPS_CREATE"
65#define SYNTAX "Create a wave and a slit map from model\n"\
66 "use : ./test_xsh_model_maps_create SOF\n"\
67 "SOF => model config and arclist\n"\
68 "Options:\n"\
69 " --binx=<n> : binning in X (default 1)\n"\
70 " --biny=<n> : binning in Y (default 1)\n"
71
72/*
73 " --mode=<str> : observing mode ([SLIT]/IFU\n"
74*/
75
76/*--------------------------------------------------------------------------
77 Implementation
78 --------------------------------------------------------------------------*/
79
87static const char * Options = "?" ;
88
89enum {
90 BINX_OPT, BINY_OPT /*, MODE_OPT */
91} ;
92
93static struct option LongOptions[] = {
94 {"binx", required_argument, 0, BINX_OPT},
95 {"biny", required_argument, 0, BINY_OPT},
96/* {"mode", required_argument, 0, MODE_OPT}, */
97 {NULL, 0, 0, 0}
98} ;
99static char mode[32] ;
100int binx =1;
101int biny =1;
102
103static void HandleOptions( int argc, char ** argv )
104{
105 int opt ;
106 int option_index = 0;
107
108 /* Set default values */
109 strcpy( mode, "SLIT" ) ;
110
111 while( (opt = getopt_long( argc, argv, Options,
112 LongOptions, &option_index )) != EOF )
113 switch( opt ) {
114 case BINX_OPT:
115 binx = atoi(optarg);
116 case BINY_OPT:
117 biny = atoi(optarg);
118 break ;
119/*
120 case MODE_OPT:
121 strcpy( mode, optarg ) ;
122*/
123 default:
124 printf( SYNTAX ) ;
125 TEST_END();
126 exit( 0 ) ;
127 }
128
129}
130
131
132int main( int argc, char **argv)
133{
134 int ret=0;
135 xsh_instrument *instrument = NULL ;
136 const char *sof_name = NULL;
137 const char *model_config_name = NULL;
138 const char *lines_list_name = NULL;
139 cpl_frame *model_config_frame = NULL;
140 cpl_frame *lines_list_frame = NULL;
141 cpl_frameset *set = NULL;
142 cpl_frameset *raws = NULL;
143 cpl_frameset *calib = NULL;
144
145 FILE* sof_file = NULL;
146 char sof_line[200];
147 xsh_xs_3 config_model;
148 cpl_frame* wmap_frame=NULL;
149 cpl_frame* smap_frame=NULL;
150
151 char *pre_name = NULL;
152
153 /* Initialize libraries */
154
156 cpl_msg_set_level(CPL_MSG_DEBUG);
158
159 HandleOptions( argc, argv );
160
161
162 /* Analyse parameters */
163 if ((argc-optind) <= 2){
164 pre_name = argv[optind];
165 sof_name = argv[optind];
166 }
167 else{
168 printf(SYNTAX);
169 return 0;
170 }
171
172
173 XSH_ASSURE_NOT_NULL( sof_name);
174
175 /* Create frameset from sof */
176 check( set = cpl_frameset_new());
177 sof_file = fopen( sof_name, "r");
178
179 while ( fgets( sof_line, 200, sof_file)){
180 char raw_name[200];
181 char raw_tag[200];
182 cpl_frame *raw_frame = NULL;
183 /* Note: update the string format (the %__s) if raw_name(tag) changes size.
184 * Remember: field width must equal 1 less than sizeof(raw_name(tag)). */
185 sscanf( sof_line, "%199s %199s", raw_name, raw_tag);
186 check( raw_frame = cpl_frame_new());
187 check( cpl_frame_set_filename( raw_frame, raw_name));
188 check( cpl_frame_set_tag( raw_frame, raw_tag));
189 check( cpl_frameset_insert(set, raw_frame));
190 }
191
192
193 /* Validate frame set */
195 XSH_NEW_FRAMESET( raws);
196 XSH_NEW_FRAMESET( calib);
197 check( xsh_dfs_split_in_group( set, raws, calib));
198
199 check( lines_list_frame = xsh_find_arc_line_list( calib, instrument));
200 check( model_config_frame = xsh_find_model_config_tab( calib, instrument));
201
202 check( lines_list_name = cpl_frame_get_filename( lines_list_frame));
203 check( model_config_name = cpl_frame_get_filename( model_config_frame));
204
205 xsh_msg(" Find model %s\n", model_config_name);
206 xsh_msg(" Find lines list %s\n", lines_list_name);
207
208 check( xsh_model_config_load_best( model_config_frame, &config_model));
209
210 xsh_model_binxy(&config_model,binx,biny);
211 check(xsh_model_maps_create( &config_model, instrument,
212 "WAVE_MAP_TEST","SLIT_MAP_TEST",
213 &wmap_frame,&smap_frame,0));
214
215
216
217 cleanup:
218 if(sof_file!=NULL) {
219 fclose( sof_file);
220 }
221 xsh_free_frame(&wmap_frame);
222 xsh_free_frame(&smap_frame);
223 xsh_free_frameset(&set);
224 xsh_free_frameset(&raws);
225 xsh_free_frameset(&calib);
227
228 if (cpl_error_get_code() != CPL_ERROR_NONE) {
229 xsh_error_dump(CPL_MSG_ERROR);
230 return 1;
231 }
232 else return ret ;
233}
234
int main()
Unit test of xsh_bspline_interpol.
static void HandleOptions(int argc, char **argv)
static const char * Options
Unit test of xsh_model_maps_create.
#define MODULE_ID
static struct option LongOptions[]
#define SYNTAX
static char mode[32]
static xsh_instrument * instrument
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
cpl_error_code xsh_model_config_load_best(cpl_frame *config_frame, xsh_xs_3 *p_xs_3)
Load the config model table and fill the struct.
Definition: xsh_model_io.c:174
void xsh_model_binxy(xsh_xs_3 *p_xs_3, int bin_X, int bin_Y)
corrects model for detector's binning
cpl_error_code xsh_model_maps_create(xsh_xs_3 *p_xs_3, xsh_instrument *instr, const char *wtag, const char *stag, cpl_frame **wmap_frame, cpl_frame **smap_frame, const int save_tmp)
Compute the wavelength and slit maps.
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
void xsh_dfs_split_in_group(cpl_frameset *input, cpl_frameset *raws, cpl_frameset *calib)
split input sof in groups: raw and calib
Definition: xsh_dfs.c:1202
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
Definition: xsh_dfs.c:1046
cpl_frame * xsh_find_model_config_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a model configuration table frame.
Definition: xsh_dfs.c:3957
cpl_frame * xsh_find_arc_line_list(cpl_frameset *frames, xsh_instrument *instr)
Find an arc line list frame.
Definition: xsh_dfs.c:3908
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138
#define XSH_NEW_FRAMESET(POINTER)
Definition: xsh_utils.h:84