X-shooter Pipeline Reference Manual 3.8.15
test-xsh_wavecal_fwhm.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.5 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
37/*--------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------
41 Includes
42 ---------------------------------------------------------------------------*/
43
44
45#include <xsh_data_order.h>
46#include <xsh_data_dispersol.h>
47#include <xsh_data_pre.h>
48#include <xsh_error.h>
49#include <xsh_msg.h>
50#include <xsh_data_instrument.h>
51#include <xsh_dfs.h>
52#include <xsh_pfits.h>
53#include <tests.h>
54#include <xsh_utils_table.h>
55#include <cpl.h>
56#include <math.h>
57
58/*---------------------------------------------------------------------------
59 Defines
60 ---------------------------------------------------------------------------*/
61#define MODULE_ID "XSH_WAVECAL_FWHM"
62
63#define SYNTAX "Add evaluation of wavelength ans slit by dispersion solution to file fwhm.dat produce by wavecal\n"\
64 "usage : ./the_xsh_wavecal_fwhm DATA_FILE DISP_TAB\n"\
65 "DATA_FILE => File fwhm.dat produce by wavecal\n"\
66 "DISP_TAB => dispersion solution to apply\n"
67
68/*--------------------------------------------------------------------------
69 Implementation
70 --------------------------------------------------------------------------*/
71
72/*--------------------------------------------------------------------------*/
79/*--------------------------------------------------------------------------*/
80int main( int argc, char** argv)
81{
82 int ret = 0;
83 xsh_instrument * instrument = NULL ;
84 XSH_ARM arm;
85 const char *fwhm_name = NULL;
86 const char* disp_tab_name = NULL;
87 cpl_frame *disp_tab_frame = NULL;
88 cpl_propertylist *header = NULL;
89 xsh_dispersol_list *displist = NULL;
90 FILE *fwhm_file = NULL;
91 FILE *res_file = NULL;
92 cpl_vector *pos = NULL;
93
94 /* Initialize libraries */
96 cpl_msg_set_level( CPL_MSG_DEBUG);
98
99 /* Analyse parameters */
100 if ( argc > 2) {
101 fwhm_name = argv[1];
102 disp_tab_name = argv[2];
103 }
104 else{
105 printf(SYNTAX);
106 TEST_END();
107 return 0;
108 }
109 xsh_msg( "Fwhm data file: %s", fwhm_name);
110 xsh_msg( "Disp tab file: %s", disp_tab_name);
111
112 /* Create frames */
113 check( header = cpl_propertylist_load( disp_tab_name, 0));
115 check( arm = xsh_pfits_get_arm( header));
117
118 disp_tab_frame = cpl_frame_new();
119 cpl_frame_set_filename( disp_tab_frame, disp_tab_name) ;
120 cpl_frame_set_level( disp_tab_frame, CPL_FRAME_LEVEL_TEMPORARY);
121 cpl_frame_set_group( disp_tab_frame, CPL_FRAME_GROUP_RAW);
122
123 check( displist = xsh_dispersol_list_load( disp_tab_frame, instrument));
124 check( pos = cpl_vector_new(2));
125
126
127 fwhm_file = fopen( fwhm_name, "r");
128 res_file = fopen( "fwhm_full.dat", "w+");
129
130 if ( fwhm_file != NULL && res_file!=NULL){
131 char line[200];
132 char *read;
133 /* read first line */
134 read = fgets( line, 200, fwhm_file);
135 fputs( "# wavelength order xcen xcen-x0 ygauss ytilt fwhm area good lambdaG slitG lambdaT slitT\n", res_file);
136 while ( fgets( line, 200, fwhm_file)){
137 double wavelength, xcen, xcen_x0, ygauss, ytilt, fwhm, area;
138 int order, good;
139 double lambdaG, slitG, lambdaT, slitT;
140 int iorder=0;
141
142 sscanf( line, "%64lf %64d %64lf %64lf %64lf %64lf %64lf %64lf %64d\n",
143 &wavelength, &order, &xcen, &xcen_x0, &ygauss, &ytilt, &fwhm, &area, &good);
144
145 while( order != displist->list[iorder].absorder){
146 iorder++;
147 }
148
149 cpl_vector_set( pos, 0, xcen);
150 cpl_vector_set( pos, 1, ygauss);
151 check( lambdaG = xsh_dispersol_list_eval( displist,
152 displist->list[iorder].lambda_poly, pos));
153 check( slitG = xsh_dispersol_list_eval( displist,
154 displist->list[iorder].slit_poly, pos));
155
156 cpl_vector_set( pos, 0, xcen);
157 cpl_vector_set( pos, 1, ytilt);
158 check( lambdaT = xsh_dispersol_list_eval( displist,
159 displist->list[iorder].lambda_poly, pos));
160 check( slitT = xsh_dispersol_list_eval( displist,
161 displist->list[iorder].slit_poly, pos));
162 fprintf( res_file, "%f %d %f %f %f %f %f %f %d %f %f %f %f\n",
163 wavelength, order, xcen, xcen_x0, ygauss, ytilt, fwhm, area,
164 good, lambdaG, slitG, lambdaT, slitT);
165 }
166 }
167
168
169 cleanup:
170 if (cpl_error_get_code() != CPL_ERROR_NONE) {
171 xsh_error_dump(CPL_MSG_ERROR);
172 ret = 1;
173 }
174 if ( fwhm_file != NULL && res_file!=NULL){
175 fclose( fwhm_file);
176 fclose( res_file);
177 }
178 xsh_dispersol_list_free( &displist);
180 xsh_free_frame( &disp_tab_frame);
181 TEST_END();
182 return ret ;
183}
184
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
#define MODULE_ID
#define SYNTAX
xsh_dispersol_list * xsh_dispersol_list_load(cpl_frame *frame, xsh_instrument *instrument)
Load a dispersion list from a frame.
void xsh_dispersol_list_free(xsh_dispersol_list **list)
Free the dispersion list.
double xsh_dispersol_list_eval(xsh_dispersol_list *list, cpl_polynomial *poly, cpl_vector *pos)
Evaluate the polynomial according the binning.
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
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
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
XSH_ARM xsh_pfits_get_arm(const cpl_propertylist *plist)
Definition: xsh_pfits.c:270
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
xsh_dispersol * list
cpl_polynomial * slit_poly
cpl_polynomial * lambda_poly
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
int order
Definition: xsh_detmon_lg.c:80
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138