X-shooter Pipeline Reference Manual 3.8.15
test-xsh_data_spectrum_order_1D.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: rhaigron $
22 * $Date: 2010-04-21 13:37:05 $
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_data_pre.h>
46#include <xsh_error.h>
47#include <xsh_msg.h>
48#include <xsh_data_instrument.h>
49#include <xsh_data_rec.h>
51#include <xsh_drl.h>
52#include <xsh_pfits.h>
53
54#include <xsh_badpixelmap.h>
55
56#include <cpl.h>
57#include <math.h>
58
59#include <getopt.h>
60
61/*--------------------------------------------------------------------------
62 Defines
63 --------------------------------------------------------------------------*/
64
65#define MODULE_ID "XSH_DATA_SPECTRUM_ORDER_1D"
66
67#define SYNTAX "Test a spectrum order 1D file\n"\
68 "use : ./test_xsh_data_spectrum_order_1D FRAME\n"\
69 "FRAME => the spectrum order 1D frame\n"
70
71static void analyse_extraction( cpl_frame* rec_frame, xsh_instrument* instr);
72
73/*--------------------------------------------------------------------------
74 Implementation
75 --------------------------------------------------------------------------*/
76static void analyse_extraction( cpl_frame* rec_frame, xsh_instrument* instr)
77{
78 const char* rec_name = NULL;
79 xsh_rec_list* rec_list = NULL;
80 int iorder;
81
82 XSH_ASSURE_NOT_NULL( rec_frame);
83
84 check( rec_name = cpl_frame_get_filename( rec_frame));
85
86 printf("RECTIFY frame : %s\n", rec_name);
87 check( rec_list = xsh_rec_list_load( rec_frame, instr));
88
89 for(iorder=0; iorder< rec_list->size; iorder++){
90 int order = 0, ilambda = 0;
91 int nlambda = 0;
92 float *flux = NULL;
93 float *err = NULL;
94 double *lambda = NULL;
95 char name[256];
96 FILE* datfile = NULL;
97
98 check( order = xsh_rec_list_get_order(rec_list, iorder));
99 check( nlambda = xsh_rec_list_get_nlambda(rec_list, iorder));
100 check( flux = xsh_rec_list_get_data1( rec_list, iorder));
101 check( err = xsh_rec_list_get_errs1( rec_list, iorder));
102 check( lambda = xsh_rec_list_get_lambda( rec_list, iorder));
103
104 sprintf( name, "spectrum1D_order%d.dat",order);
105 xsh_msg("Save file %s",name);
106 datfile = fopen( name, "w");
107
108 fprintf( datfile, "#lambda flux err\n");
109
110 for(ilambda=0; ilambda < nlambda; ilambda++){
111 fprintf( datfile,"%f %f %f\n",lambda[ilambda],flux[ilambda], err[ilambda]);
112 }
113 fclose(datfile);
114
115 }
116 cleanup:
117 xsh_rec_list_free( &rec_list);
118 return;
119}
120
128int main( int argc, char **argv)
129{
130 /* Declarations */
131 int ret = 0 ;
133 char* rec_name = NULL;
134 cpl_frame* rec_frame = NULL;
135
136 /* Initialize libraries */
138
139 cpl_msg_set_level(CPL_MSG_DEBUG);
141
142
143 /* Analyse parameters */
144 if ( argc == 2 ) {
145 rec_name = argv[1];
146 }
147 else{
148 printf(SYNTAX);
149 TEST_END();
150 exit(0);
151 }
152 rec_frame = cpl_frame_new();
153 XSH_ASSURE_NOT_NULL (rec_frame);
154 cpl_frame_set_filename( rec_frame, rec_name) ;
155 cpl_frame_set_level( rec_frame, CPL_FRAME_LEVEL_TEMPORARY);
156 cpl_frame_set_group( rec_frame, CPL_FRAME_GROUP_RAW ) ;
157
158
159 /* Create instrument structure and fill */
161 check( analyse_extraction( rec_frame, instrument));
162
163 cleanup:
165 xsh_free_frame( &rec_frame);
166
167 if (cpl_error_get_code() != CPL_ERROR_NONE) {
168 xsh_error_dump(CPL_MSG_ERROR);
169 ret=1;
170 }
171 TEST_END();
172 return ret ;
173}
174
int main()
Unit test of xsh_bspline_interpol.
static void analyse_extraction(cpl_frame *rec_frame, xsh_instrument *instr)
static xsh_instrument * instrument
double * xsh_rec_list_get_lambda(xsh_rec_list *list, int idx)
xsh_rec_list * xsh_rec_list_load(cpl_frame *frame, xsh_instrument *instrument)
load an rec list from a frame
Definition: xsh_data_rec.c:289
float * xsh_rec_list_get_data1(xsh_rec_list *list, int idx)
float * xsh_rec_list_get_errs1(xsh_rec_list *list, int idx)
int xsh_rec_list_get_order(xsh_rec_list *list, int idx)
Definition: xsh_data_rec.c:846
int xsh_rec_list_get_nlambda(xsh_rec_list *list, int idx)
Definition: xsh_data_rec.c:865
void xsh_rec_list_free(xsh_rec_list **list)
free memory associated to a rec_list
Definition: xsh_data_rec.c:760
#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_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
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
#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