X-shooter Pipeline Reference Manual 3.8.15
xsh_data_spectralformat.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: 2011-01-17 08:02:36 $
23 * $Revision: 1.16 $
24 */
25
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
40/*-----------------------------------------------------------------------------
41 Includes
42 ----------------------------------------------------------------------------*/
43#include <math.h>
45#include <xsh_utils.h>
46#include <xsh_error.h>
47#include <xsh_msg.h>
48#include <xsh_pfits.h>
49#include <cpl.h>
50#include <xsh_utils_table.h>
51#include <xsh_drl.h>
52
53/*----------------------------------------------------------------------------
54 Function implementation
55 ----------------------------------------------------------------------------*/
56
57/*****************************************************************************/
66/*****************************************************************************/
68 const char * fname )
69{
70 int i ;
71 FILE * fout ;
72
73 if ( fname == NULL ) fout = stdout ;
74 else fout = fopen( fname, "w" ) ;
75
76 for( i = 0 ; i<list->size ; i++ ) {
77 fprintf( fout, "Order: %d, Lambda Min: %f,Lambda Max: %f\n",
78 list->list[i].absorder, list->list[i].lambda_min,
79 list->list[i].lambda_max ) ;
80 }
81 if ( fname != NULL ) fclose( fout ) ;
82}
83/*****************************************************************************/
84
85
86/*****************************************************************************/
96/*****************************************************************************/
98 xsh_instrument* instr)
99{
100 xsh_spectralformat_list* result = NULL;
101
102 /* check input parameters */
104
106 result->size = size;
107
108 result->instrument = instr;
109 XSH_CALLOC(result->list, xsh_spectralformat, result->size);
111
112 cleanup:
113 if (cpl_error_get_code() != CPL_ERROR_NONE) {
115 }
116 return result;
117}
118/*****************************************************************************/
119
120/*****************************************************************************/
131/*****************************************************************************/
133 xsh_instrument* instr)
134{
135 cpl_table* table = NULL;
136 cpl_propertylist* header = NULL;
137 const char* tablename = NULL;
138 xsh_spectralformat_list * result = NULL;
139 int i = 0 ;
140 double value ;
141 int size;
142
143 /* check input parameters */
144 XSH_ASSURE_NOT_NULL( frame);
145 XSH_ASSURE_NOT_NULL( instr);
146
147 /* get table filename */
148 check( tablename = cpl_frame_get_filename( frame));
149
150 XSH_TABLE_LOAD( table, tablename);
151
152 check( size = cpl_table_get_nrow( table));
153 check( result = xsh_spectralformat_list_create( size, instr));
154
155 check( header = cpl_propertylist_load(tablename,1));
156 check( cpl_propertylist_append(result->header, header));
157
158 for(i=0;i<result->size;i++){
159 const char * lamp ;
160
161 /* load the order in structure */
163 CPL_TYPE_INT, i, &(result->list[i].absorder)));
164 /* Lamp */
165 check( lamp = cpl_table_get_string(table,
167 strcpy( result->list[i].lamp, lamp);
168 /* wlminful */
169 check( value = cpl_table_get( table,
171 result->list[i].lambda_min_full = (float)value;
172 /* wlmaxful */
173 check( value = cpl_table_get( table,
175 result->list[i].lambda_max_full = (float)value;
176 /* Wlmin */
177 check( value = cpl_table_get( table,
179 result->list[i].lambda_min = (float)value;
180 /* Wlmax */
181 check( value = cpl_table_get( table,
183 result->list[i].lambda_max = (float)value;
184 /* flsr */
185 check( value = cpl_table_get( table,
187 result->list[i].flsr = (float)value;
188 /* ufsr */
189 check( value = cpl_table_get( table,
191 result->list[i].ufsr = (float)value;
192
193 /* xmin */
194 if(cpl_table_has_column(table,XSH_SPECTRALFORMAT_TABLE_COLNAME_XMIN)) {
195 check( value = cpl_table_get( table,
197 result->list[i].xmin = (float)value;
198 /* xmax */
199 check( value = cpl_table_get( table,
201 result->list[i].xmax = (float)value;
202
203 /* ymin */
204 check( value = cpl_table_get( table,
206 result->list[i].ymin = (float)value;
207 /* ymax */
208 check( value = cpl_table_get( table,
210 result->list[i].ymax = (float)value;
211
212 }
213 }
214 cleanup:
215 if (cpl_error_get_code () != CPL_ERROR_NONE) {
216 xsh_error_msg( "can't load frame %s",cpl_frame_get_filename(frame));
218 }
219 xsh_free_propertylist( &header);
220 XSH_TABLE_FREE( table);
221 return result;
222}
223/*****************************************************************************/
224
225/*****************************************************************************/
232/*****************************************************************************/
234{
235 if ( list && *list){
236 /* free the list */
237 if ( ( *list)->list){
238 cpl_free( (*list)->list);
239 }
240 xsh_free_propertylist( &((*list)->header));
241 cpl_free( *list);
242 *list = NULL;
243 }
244}
245/*****************************************************************************/
246
247
248
249/*****************************************************************************/
258/*****************************************************************************/
261{
262 cpl_propertylist *res = NULL;
263
265 res = list->header;
266 cleanup:
267 return res;
268}
269/*****************************************************************************/
270
271/*****************************************************************************/
282/*****************************************************************************/
284 int absorder)
285{
286 int i ;
287 float res = 0. ;
288
290
291 for( i = 0; i<list->size; i++){
292 if ( list->list[i].absorder == absorder){
293 res = list->list[i].lambda_min ;
294 break ;
295 }
296 }
297 cleanup:
298 return res ;
299}
300/*****************************************************************************/
301
302/*****************************************************************************/
303/*****************************************************************************/
305 int absorder )
306{
307 int i ;
308 const char *res = NULL;
309
310 XSH_ASSURE_NOT_NULL( list);
311
312 for( i = 0 ; i<list->size ; i++ )
313 if ( list->list[i].absorder == absorder ) {
314 res = list->list[i].lamp ;
315 break ;
316 }
317
318 cleanup:
319 return res ;
320}
321/*****************************************************************************/
322
323/*---------------------------------------------------------------------------*/
332/*---------------------------------------------------------------------------*/
334 int absorder )
335{
336 int i ;
337 float res = 0. ;
338
340 for( i = 0 ; i<list->size ; i++ )
341 if ( list->list[i].absorder == absorder ) {
342 res = list->list[i].lambda_max ;
343 break ;
344 }
345
346 cleanup:
347 return res ;
348}
349/*****************************************************************************/
350
351/*****************************************************************************/
362/*****************************************************************************/
364 xsh_spectralformat_list *list, float lambda)
365{
366 cpl_vector* result = NULL;
367 int i;
368 int size = 0;
369 int order_tab[20];
370
372
373 for( i = 0 ; i<list->size ; i++ ){
374 float min=0.0, max=0.0;
375
376 min = list->list[i].lambda_min_full;
377 max = list->list[i].lambda_max_full;
378
379 xsh_msg_dbg_high( "search lambda %f in [%f,%f]", lambda, min, max);
380
381 if (lambda >= min && lambda <= max){
382 order_tab[size] = list->list[i].absorder;
383 size++;
384 }
385 }
386
387 if (size > 0){
388 check( result = cpl_vector_new( size));
389 for( i=0; i< size; i++){
390 check( cpl_vector_set( result, i, order_tab[i]));
391 }
392 }
393 cleanup:
394 if ( cpl_error_get_code() != CPL_ERROR_NONE){
395 xsh_free_vector( &result);
396 }
397 return result;
398}
399
401 xsh_order_list* orderlist, xsh_wavesol *wavesol,
402 xsh_xs_3 *model, xsh_instrument *instr)
403{
404 int iorder = 0;
405
406 XSH_ASSURE_NOT_NULL( spectralformat);
407 XSH_ASSURE_NOT_NULL( orderlist);
408
409 for( iorder=0; iorder < spectralformat->size; iorder++){
410 double absorder = 0;
411 double slit = 0.0;
412 double wmin, wmax;
413 double ymin, ymax;
414 double y_wmin, y_wmax;
415
416 absorder = (double)spectralformat->list[iorder].absorder;
417 wmin = spectralformat->list[iorder].lambda_min;
418 wmax = spectralformat->list[iorder].lambda_max;
419
420 ymin = (double)orderlist->list[iorder].starty;
421 ymax = (double)orderlist->list[iorder].endy;
422
423 if (wavesol != NULL){
424 check( y_wmin = xsh_wavesol_eval_poly( wavesol, wmin, absorder,
425 slit));
426 check( y_wmax = xsh_wavesol_eval_poly( wavesol, wmax, absorder,
427 slit));
428 }
429 else{
430 double x;
431
432 check( xsh_model_get_xy( model, instr, wmin, absorder, slit,
433 &x, &y_wmin));
434 check( xsh_model_get_xy( model, instr, wmax, absorder, slit,
435 &x, &y_wmax));
436 }
437 if ( y_wmin < ymin || y_wmin > ymax){
438 xsh_msg_warning("For order %f at wmin %f : y %f not in [%f,%f]",
439 absorder, wmin, y_wmin, ymin, ymax);
440 }
441 if ( y_wmax > ymax || y_wmax < ymin){
442 xsh_msg_warning("For order %f at wmax %f : y %f not in [%f,%f]",
443 absorder, wmax, y_wmax, ymin, ymax);
444 }
445
446
447 }
448
449 cleanup:
450 return;
451}
452/*****************************************************************************/
cpl_propertylist * xsh_spectralformat_list_get_header(xsh_spectralformat_list *list)
Get header of the table.
void xsh_spectralformat_check_wlimit(xsh_spectralformat_list *spectralformat, xsh_order_list *orderlist, xsh_wavesol *wavesol, xsh_xs_3 *model, xsh_instrument *instr)
const char * xsh_spectralformat_list_get_lamp(xsh_spectralformat_list *list, int absorder)
void xsh_spectralformat_list_dump(xsh_spectralformat_list *list, const char *fname)
Dump main info about an order table (for each order of the list)
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_create(int size, xsh_instrument *instr)
Create an empty spectralformat list.
xsh_spectralformat_list * xsh_spectralformat_list_load(cpl_frame *frame, xsh_instrument *instr)
Load a spectralformat list from a frame.
float xsh_spectralformat_list_get_lambda_max(xsh_spectralformat_list *list, int absorder)
float xsh_spectralformat_list_get_lambda_min(xsh_spectralformat_list *list, int absorder)
Returns lambda min for a given absolute order.
void xsh_spectralformat_list_free(xsh_spectralformat_list **list)
Free memory associated to an spactralformat_list.
double xsh_wavesol_eval_poly(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in Y
#define XSH_ASSURE_NOT_ILLEGAL(cond)
Definition: xsh_error.h:107
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_msg(...)
Definition: xsh_error.h:94
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
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.
int size
int * x
#define xsh_msg_warning(...)
Print an warning message.
Definition: xsh_msg.h:88
#define xsh_msg_dbg_high(...)
Definition: xsh_msg.h:40
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
Definition: xsh_utils.c:2284
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_error_code xsh_get_table_value(const cpl_table *table, const char *colname, cpl_type coltype, int i, void *result)
Read a table value from a fits table.
xsh_order * list
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_LAMP
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_ORDER
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_YMAX
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_WLMINFUL
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_WLMIN
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_YMIN
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_WLMAXFUL
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_XMIN
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_UFSR
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_FLSR
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_WLMAX
#define XSH_SPECTRALFORMAT_TABLE_COLNAME_XMAX
#define max(a, b)
#define XSH_NEW_PROPERTYLIST(POINTER)
Definition: xsh_utils.h:70
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)