X-shooter Pipeline Reference Manual 3.8.15
test-xsh_guess.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.4 $
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_error.h>
46#include <xsh_msg.h>
47#include <xsh_data_instrument.h>
48#include <xsh_drl.h>
49#include <xsh_model_io.h>
50#include <xsh_data_the_map.h>
51#include <xsh_pfits.h>
52
53#include <cpl.h>
54#include <math.h>
55
56#include <getopt.h>
57
58/*--------------------------------------------------------------------------
59 Defines
60 --------------------------------------------------------------------------*/
61
62#define MODULE_ID "XSH_GUESS"
63#define SYNTAX "Test X,Y point generation\n"\
64 "use : ./the_xsh_guess XSH_MODEL_CFG INPUT_MODEL_TAB (columns 'order', 'wavelength', 'slit')\n"\
65 "(table with predicted 'x','y' predicted positions)\n"
66
67
68/*--------------------------------------------------------------------------
69 Implementation
70 --------------------------------------------------------------------------*/
71
79int main( int argc, char **argv)
80{
81 /* Declarations */
82 int ret = 0 ;
83 const char* tag=NULL;
84 char* model_cfg_name = NULL;
85 char* input_tab_name = NULL;
86 cpl_propertylist* plist=NULL;
87 cpl_frame* model_cfg_frame = NULL;
88 cpl_frame* the_map_frame = NULL;
89 xsh_the_map* the_map_list=NULL;
90 int i = 0;
91 FILE* themap_file = NULL;
92 xsh_xs_3 model_config ;
93 int binx=1;
94 int biny=1;
95 cpl_table* the_map_tab=NULL;
96 int* pord=NULL;
97 float* pwav=NULL;
98 int* ps=NULL;
99 int nrow=0;
100 double x=0;
101 double y=0;
102 xsh_instrument* inst;
103 /* Initialize libraries */
105
106 cpl_msg_set_level(CPL_MSG_DEBUG);
108
109 /* Analyse parameters */
110 if (argc > 1){
111 model_cfg_name = argv[1];
112 input_tab_name = argv[2];
113 }
114 else{
115 printf(SYNTAX);
116 return 0;
117 }
118
119 /* Create frames */
120 XSH_ASSURE_NOT_NULL( model_cfg_name);
121 plist=cpl_propertylist_load(model_cfg_name,0);
122 tag=xsh_pfits_get_pcatg(plist);
123
124 check(model_cfg_frame = cpl_frame_new());
125 cpl_frame_set_filename( model_cfg_frame, model_cfg_name) ;
126 cpl_frame_set_level( model_cfg_frame, CPL_FRAME_LEVEL_TEMPORARY);
127 cpl_frame_set_group( model_cfg_frame, CPL_FRAME_GROUP_RAW ) ;
128 cpl_frame_set_type( model_cfg_frame, CPL_FRAME_TYPE_TABLE ) ;
129 check(cpl_frame_set_tag( model_cfg_frame, tag ) );
130
131 xsh_msg("model_cfg_name=%s",model_cfg_name);
132 xsh_msg("input_tab_name=%s",input_tab_name);
133
134 inst=xsh_instrument_new();
136 check( xsh_model_config_load_best( model_cfg_frame, &model_config));
137 xsh_model_binxy(&model_config,binx,biny);
138 the_map_tab=cpl_table_load(input_tab_name,1,0);
139
140 check(pwav=cpl_table_get_data_float(the_map_tab,XSH_THE_MAP_TABLE_COLNAME_WAVELENGTH));
141 check(pord=cpl_table_get_data_int(the_map_tab,XSH_THE_MAP_TABLE_COLNAME_ORDER));
142 check(ps=cpl_table_get_data_int(the_map_tab,XSH_THE_MAP_TABLE_COLNAME_SLITINDEX));
143
144 nrow=cpl_table_get_nrow(the_map_tab);
145 for(i=0;i<nrow;i++) {
146 check(xsh_model_get_xy(&model_config,inst,pwav[i],pord[i],ps[i],&x,&y));
147 }
148 xsh_free_table(&the_map_tab);
149
150
151 /* Create DS9 REGION FILE */
152 themap_file = fopen( "THEMAP.reg", "w");
153 fprintf( themap_file, "# Region file format: DS9 version 4.0\n\
154 global color=red font=\"helvetica 4 normal\"\
155 select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source \nimage\n");
156
157
158 the_map_frame = cpl_frame_new();
159 cpl_frame_set_filename( the_map_frame, input_tab_name) ;
160 cpl_frame_set_level( the_map_frame, CPL_FRAME_LEVEL_TEMPORARY);
161 cpl_frame_set_group( the_map_frame, CPL_FRAME_GROUP_RAW ) ;
162 cpl_frame_set_type( the_map_frame, CPL_FRAME_TYPE_TABLE ) ;
163 cpl_frame_set_tag( the_map_frame, tag ) ;
164
165 the_map_list=xsh_the_map_load(the_map_frame);
166
167 int themap_size=nrow;
168 for( i=0; i<themap_size; i++){
169 float lambdaTHE = 0.0;
170 double xd, yd, slit;
171
172 check(lambdaTHE = xsh_the_map_get_wavelength(the_map_list, i));
173
174 check(xd = xsh_the_map_get_detx(the_map_list, i));
175 check(yd = xsh_the_map_get_dety(the_map_list, i));
176 check(slit = (double) xsh_the_map_get_slit_position( the_map_list, i));
177 if (slit == 0){
178 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
179 "font=\"helvetica 10 normal\" text={THE %.3f}\n", xd, yd, lambdaTHE);
180 }
181 else{
182 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
183 "font=\"helvetica 10 normal\" text={slit %f}\n", xd, yd, slit);
184 }
185 }
186
187
188
189 cleanup:
190 xsh_free_propertylist(&plist);
191 xsh_the_map_free(&the_map_list);
192 xsh_free_table(&the_map_tab);
193 xsh_free_frame(&the_map_frame);
194 xsh_free_frame(&model_cfg_frame);
195 xsh_instrument_free(&inst);
196 if(themap_file != NULL) {
197 fclose( themap_file);
198 }
199 if (cpl_error_get_code() != CPL_ERROR_NONE) {
200 xsh_error_dump(CPL_MSG_ERROR);
201 ret = -1;
202 }
203 return ret ;
204}
205
int main()
Unit test of xsh_bspline_interpol.
#define MODULE_ID
#define SYNTAX
int binx
int biny
void xsh_the_map_free(xsh_the_map **list)
free memory associated to a the_map
double xsh_the_map_get_detx(xsh_the_map *list, int idx)
get detx of the map list
float xsh_the_map_get_slit_position(xsh_the_map *list, int idx)
get slit position of the map list
double xsh_the_map_get_dety(xsh_the_map *list, int idx)
get dety of the map list
float xsh_the_map_get_wavelength(xsh_the_map *list, int idx)
get wavelength of the map list
xsh_the_map * xsh_the_map_load(cpl_frame *frame)
load a theoretical map frame in the_map structure. Suppress spurious entries in the THE MAP (marked w...
#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_parse_tag(xsh_instrument *inst, const char *tag)
analyse a frame tag to set data in instrument structure
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new 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_get_xy(xsh_xs_3 *p_xs_3, xsh_instrument *instr, double lambda_nm, int morder, double ent_slit_pos, double *x, double *y)
Compute the detector location (floating point pixels) of a given wavelength/entrance slit position.
void xsh_model_binxy(xsh_xs_3 *p_xs_3, int bin_X, int bin_Y)
corrects model for detector's binning
int * y
int * x
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
const char * xsh_pfits_get_pcatg(const cpl_propertylist *plist)
find out the pcatg
Definition: xsh_pfits.c:1627
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
Definition: xsh_utils.c:2133
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
#define XSH_THE_MAP_TABLE_COLNAME_SLITINDEX
#define XSH_THE_MAP_TABLE_COLNAME_WAVELENGTH
#define XSH_THE_MAP_TABLE_COLNAME_ORDER
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138