62#define MODULE_ID "XSH_DATA_WAVE_TAB_2D"
76 {
"binx", required_argument, 0,
BINX_OPT},
77 {
"biny", required_argument, 0,
BINY_OPT},
78 {
"debug", required_argument, 0,
DEBUG_OPT},
86 puts (
"Unitary test of wave tab 2d");
87 puts(
"Usage : ./the_xsh_data_wave_tab_2d [options] <SOF>");
90 puts(
" --binx=<n> : Binning in X (default 1)" );
91 puts(
" --biny=<n> : Binning in Y (default 1)" );
92 puts(
" --lambda-step=<n> : Step in lambda. Default 0.2" );
93 puts(
" --slit-step=<n> : Step in slit. Default 0.2" );
94 puts(
" --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
95 puts(
" --help : What you see" ) ;
97 puts(
"The input files argument MUST be in this order:" ) ;
98 puts(
" 1. SOF [WAVE_TAB_2D, SPECTRAL_FORMAT, ARC_LIST]");
110 int option_index = 0;
112 while( (opt = getopt_long( argc, argv,
"debug:help",
127 if ( strcmp( optarg,
"LOW")==0){
130 else if ( strcmp( optarg,
"HIGH")==0){
151int main(
int argc,
char** argv)
157 cpl_frameset* set = NULL;
158 char *sof_name = NULL;
159 cpl_frame *wave_tab_2d_frame = NULL;
160 cpl_frame *spectralformat_frame = NULL;
161 cpl_frame *arclist_frame = NULL;
165 FILE* wave_tab_2d_file = NULL;
166 FILE* wave_tab_2d_dat_file = NULL;
170 cpl_msg_set_level(CPL_MSG_DEBUG);
176 if ( (argc-optind) >= 1) {
177 sof_name = argv[optind];
191 xsh_msg(
"Wave tab 2d : %s", cpl_frame_get_filename(wave_tab_2d_frame));
192 xsh_msg(
"Spectral format : %s", cpl_frame_get_filename(spectralformat_frame));
193 if ( arclist_frame != NULL){
194 xsh_msg(
"Arclines : %s", cpl_frame_get_filename( arclist_frame));
211 wave_tab_2d_file = fopen(
"WAVE_TAB_2D.reg",
"w");
212 wave_tab_2d_dat_file = fopen(
"WAVE_TAB_2D.dat",
"w");
213 fprintf( wave_tab_2d_file,
"# Region file format: DS9 version 4.0\n"\
214 "global color=red font=\"helvetica 10 normal\""\
215 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
217 fprintf( wave_tab_2d_dat_file,
"# x y lambda slit\n");
219 if ( arclist_frame == NULL){
220 for( i=0; i< spec_list->
size; i++){
222 float lambda_min, lambda_max;
223 float lambda_min_full, lambda_max_full;
230 xsh_msg(
"order %f lambda %f->%f-%f<-%f",absorder, lambda_min_full,
231 lambda_min, lambda_max, lambda_max_full);
233 for(j=lambda_min_full; j <= lambda_max_full; j+=
lambda_step){
235 const char* full_lambda_color =
"yellow";
236 const char* lambda_color =
"red";
237 const char* color = NULL;
239 if ( (j < lambda_min)|| (j > lambda_max) ){
240 color = full_lambda_color;
243 color = lambda_color;
249 fprintf( wave_tab_2d_file,
"point(%f,%f) #point=cross color=%s font="\
250 "\"helvetica 10 normal\" text={ %.3f}\n",
x,
y, color, j);
251 fprintf( wave_tab_2d_dat_file,
"%f %f %f %f\n",
x,
y, j, 0.0);
256 fprintf( wave_tab_2d_file,
"point(%f,%f) #point=cross color=green font="\
257 "\"helvetica 10 normal\" text={ %.3f}\n",
x,
y, k);
258 fprintf( wave_tab_2d_dat_file,
"%f %f %f %f\n",
x,
y, j, k);
269 for( i=0; i<
size; i++){
271 cpl_vector *orders = NULL;
276 order_size = cpl_vector_get_size( orders);
278 for( j=0; j < order_size; j++){
282 absorder = cpl_vector_get( orders, j);
287 fprintf( wave_tab_2d_file,
"point(%f,%f) #point=cross color=red font="\
288 "\"helvetica 10 normal\" text={ %.3f}\n",
x,
y, lambda);
289 fprintf( wave_tab_2d_dat_file,
"%f %f %f %f\n",
x,
y, lambda, 0.0);
294 fprintf( wave_tab_2d_file,
"point(%f,%f) #point=cross color=green font="\
295 "\"helvetica 10 normal\" text={ %.3f}\n",
x,
y, k);
296 fprintf( wave_tab_2d_dat_file,
"%f %f %f %f\n",
x,
y, lambda, k);
299 fprintf( wave_tab_2d_file,
"point(%f,%f) #point=cross color=green font="\
300 "\"helvetica 10 normal\" text={ %.3f}\n",
x,
y, -k);
301 fprintf( wave_tab_2d_dat_file,
"%f %f %f %f\n",
x,
y, lambda, -k);
318 if (cpl_error_get_code() != CPL_ERROR_NONE) {
322 if ( NULL != wave_tab_2d_dat_file) {
323 fclose( wave_tab_2d_dat_file);
325 if ( NULL != wave_tab_2d_file) {
326 fclose( wave_tab_2d_file);
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
static struct option LongOptions[]
cpl_frameset * sof_to_frameset(const char *sof_name)
float xsh_arclist_get_wavelength(xsh_arclist *list, int idx)
get wavelength of a line in the arcline list
void xsh_arclist_free(xsh_arclist **list)
free memory associated to a arclist
xsh_arclist * xsh_arclist_load(cpl_frame *frame)
load an arcline list frame in arclist structure
void xsh_wavesol_set_bin_y(xsh_wavesol *wsol, int bin)
Set the bin of wave table in y.
void xsh_wavesol_set_bin_x(xsh_wavesol *wsol, int bin)
Set the bin of wave table in x.
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
void xsh_wavesol_free(xsh_wavesol **w)
free wavelength solution structure
double xsh_wavesol_eval_polx(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in X
#define xsh_error_dump(level)
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
#define xsh_msg(...)
Print a message on info level.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
static void HandleOptions(int argc, char **argv)
#define TESTS_INIT(DRL_ID)
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
cpl_frame * xsh_find_wave_tab_2d(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D.
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
cpl_frame * xsh_find_arc_line_list(cpl_frameset *frames, xsh_instrument *instr)
Find an arc line list frame.