X-shooter Pipeline Reference Manual 3.8.15
test-xsh_data_wave_tab_2d_sample.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.6 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42
43
44#include <xsh_data_order.h>
45#include <xsh_error.h>
46#include <xsh_msg.h>
47#include <xsh_data_instrument.h>
48#include <xsh_dfs.h>
49#include <xsh_pfits.h>
50#include <tests.h>
52#include <xsh_data_arclist.h>
53#include <xsh_data_wavesol.h>
54#include <xsh_utils_table.h>
55#include <cpl.h>
56#include <math.h>
57#include <getopt.h>
58
59/*---------------------------------------------------------------------------
60 Defines
61 ---------------------------------------------------------------------------*/
62#define MODULE_ID "XSH_DATA_WAVE_TAB_2D_SAMPLE"
63
64#define SYNTAX "Test the wave tab 2d\n"\
65 "usage : ./the_xsh_data_wave_tab_2d [OPTIONS] WAVE_TAB_2D ARC_LIST SPECTRAL_FORMAT\n"\
66 "WAVE_TAB_2D => The wave tab 2d\n"\
67 "ARC_LIST => An arclist\n"\
68 "SPECTRAL_FORMAT => The spectral format\n"\
69 "OPTIONS => :\n"\
70 " --slit-step=<nn> : Step in slit. Default 0.2 \n"
71
72
73static const char * Options = "";
74
75enum {
77} ;
78
79static float slit_step = 1.4;
80
81
82static struct option LongOptions[] = {
83 {"slit-step", required_argument, 0, SLIT_STEP_OPT},
84 {NULL, 0, 0, 0}
85} ;
86
87/*--------------------------------------------------------------------------
88 Implementation
89 --------------------------------------------------------------------------*/
90
91static void HandleOptions( int argc, char ** argv)
92{
93 int opt ;
94 int option_index = 0;
95
96 while( (opt = getopt_long( argc, argv, Options,
97 LongOptions, &option_index )) != EOF )
98 switch( opt ) {
99 case SLIT_STEP_OPT:
100 slit_step = atof(optarg);
101 break ;
102 default:
103 printf( SYNTAX ) ;
104 exit( 0 ) ;
105 }
106}
107
108/*--------------------------------------------------------------------------*/
116/*--------------------------------------------------------------------------*/
117int main(int argc, char** argv)
118{
119 int ret = 0;
120 int i;
121 float j,k;
122 xsh_instrument * instrument = NULL ;
123 // XSH_INSTRCONFIG* iconfig = NULL;
124
125 char* wave_tab_2d_name = NULL;
126 cpl_frame *wave_tab_2d_frame = NULL;
127 char* spectralformat_name = NULL;
128 cpl_frame *spectralformat_frame = NULL;
129 char* arclist_name = NULL;
130 cpl_frame *arclist_frame = NULL;
131 xsh_spectralformat_list *spec_list = NULL;
132 xsh_wavesol *wave_tab_2d = NULL;
133 FILE* wave_tab_2d_file = NULL;
134 FILE* wave_tab_2d_dat_file = NULL;
135 xsh_arclist *arclist = NULL;
136
137
138 /* Initialize libraries */
140 cpl_msg_set_level(CPL_MSG_DEBUG);
142
143 HandleOptions( argc, argv);
144
145 /* Analyse parameters */
146 if ( (argc-optind) == 3) {
147 wave_tab_2d_name = argv[optind++];
148 arclist_name = argv[optind++];
149 spectralformat_name = argv[optind++];
150 }
151 else{
152 printf(SYNTAX);
153 return 0;
154 }
155 xsh_msg("Wave tab 2d : %s", wave_tab_2d_name);
156 xsh_msg("Arclist : %s", arclist_name);
157 xsh_msg("Spectral format : %s", spectralformat_name);
158 xsh_msg(" Options : slit-step %f", slit_step);
159
160 /* Create frames */
161 XSH_ASSURE_NOT_NULL( wave_tab_2d_name);
162 wave_tab_2d_frame = cpl_frame_new();
163 cpl_frame_set_filename( wave_tab_2d_frame, wave_tab_2d_name) ;
164 cpl_frame_set_level( wave_tab_2d_frame, CPL_FRAME_LEVEL_TEMPORARY);
165 cpl_frame_set_group( wave_tab_2d_frame, CPL_FRAME_GROUP_RAW);
166
167 XSH_ASSURE_NOT_NULL( arclist_name);
168 arclist_frame = cpl_frame_new();
169 cpl_frame_set_filename( arclist_frame, arclist_name) ;
170 cpl_frame_set_level( arclist_frame, CPL_FRAME_LEVEL_TEMPORARY);
171 cpl_frame_set_group( arclist_frame, CPL_FRAME_GROUP_RAW);
172
173 XSH_ASSURE_NOT_NULL( spectralformat_name);
174 spectralformat_frame = cpl_frame_new();
175 cpl_frame_set_filename( spectralformat_frame, spectralformat_name) ;
176 cpl_frame_set_level( spectralformat_frame, CPL_FRAME_LEVEL_TEMPORARY);
177 cpl_frame_set_group( spectralformat_frame, CPL_FRAME_GROUP_RAW);
178
180 check( spec_list = xsh_spectralformat_list_load( spectralformat_frame,
181 instrument));
182 check( wave_tab_2d = xsh_wavesol_load( wave_tab_2d_frame, instrument));
183 xsh_msg("Wavesol lambda (%f,%f)", wave_tab_2d->min_lambda,
184 wave_tab_2d->max_lambda);
185 xsh_msg("Wavesol order (%f,%f)", wave_tab_2d->min_order,
186 wave_tab_2d->max_order);
187 xsh_msg("Wavesol slit (%f,%f)", wave_tab_2d->min_slit,
188 wave_tab_2d->max_slit);
189
190 wave_tab_2d_file = fopen( "WAVE_TAB_2D_sample.reg", "w");
191 wave_tab_2d_dat_file = fopen( "WAVE_TAB_2D_sample.dat", "w");
192
193 fprintf( wave_tab_2d_file, "# Region file format: DS9 version 4.0\n"\
194 "global color=red font=\"helvetica 10 normal\""\
195 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
196 "source\nimage\n");
197 fprintf( wave_tab_2d_dat_file, "# x y lambda slit\n");
198
199 check( arclist = xsh_arclist_load( arclist_frame));
200
201 for( i=0; i< arclist->size; i++){
202 double absorder;
203 float lambda;
204 cpl_vector* orders = NULL;
205 int nb_orders;
206
207 check( lambda = xsh_arclist_get_wavelength( arclist, i));
208 check( orders = xsh_spectralformat_list_get_orders( spec_list, lambda));
209 if (orders != NULL){
210 check( nb_orders = cpl_vector_get_size( orders));
211 }
212 else{
213 nb_orders = 0;
214 }
215 for(j=0; j < nb_orders; j++){
216 double x, y;
217 absorder= cpl_vector_get( orders, j);
218 xsh_msg("order %f lambda %f", absorder, lambda);
219 check( x = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, 0.0));
220 check( y = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, 0.0));
221 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=red font="\
222 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, lambda);
223 fprintf( wave_tab_2d_dat_file,"%f %f %f %f\n", x, y , lambda, 0.0);
224/*
225 for( k=wave_tab_2d->min_slit; k <= (wave_tab_2d->max_slit+0.00001); k+=slit_step){
226 check( x = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, k));
227 check( y = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, k));
228 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=green font="\
229 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, k);
230 }
231*/
232 for( k=wave_tab_2d->min_slit; k <= (wave_tab_2d->max_slit+0.00001-slit_step); k+=slit_step){
233 double x1,x2,y1,y2;
234 check( x1 = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, k));
235 check( y1 = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, k));
236 check( x2 = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, k+slit_step));
237 check( y2 = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, k+slit_step));
238 fprintf( wave_tab_2d_file, "line(%f,%f,%f,%f) #color=green font="\
239 "\"helvetica 10 normal\"\n", x1, y1, x2, y2);
240 fprintf( wave_tab_2d_dat_file,"%f %f %f %f\n", x, y , lambda, k);
241 }
242 }
243 }
244
245 cleanup:
246 if (cpl_error_get_code() != CPL_ERROR_NONE) {
247 xsh_error_dump(CPL_MSG_ERROR);
248 ret = 1;
249 }
250 if ( NULL != wave_tab_2d_file) {
251 fclose( wave_tab_2d_file);
252 }
253 if ( NULL != wave_tab_2d_dat_file) {
254 fclose( wave_tab_2d_dat_file);
255 }
256
257 return ret ;
258}
259
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
static const char * Options
static float slit_step
static struct option LongOptions[]
float xsh_arclist_get_wavelength(xsh_arclist *list, int idx)
get wavelength of a line in the arcline list
xsh_arclist * xsh_arclist_load(cpl_frame *frame)
load an arcline list frame in arclist structure
cpl_vector * xsh_spectralformat_list_get_orders(xsh_spectralformat_list *list, float lambda)
Returns list of absolute orders containing lambda.
xsh_spectralformat_list * xsh_spectralformat_list_load(cpl_frame *frame, xsh_instrument *instr)
Load a spectralformat list from a frame.
xsh_wavesol * xsh_wavesol_load(cpl_frame *frame, xsh_instrument *instrument)
load a wavelength solution
double xsh_wavesol_eval_poly(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in Y
double xsh_wavesol_eval_polx(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in X
#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
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
int * y
int * x
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
static void HandleOptions(int argc, char **argv)
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138