X-shooter Pipeline Reference Manual 3.8.15
test-xsh_compute_response.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-12-02 14:13:14 $
23 * $Revision: 1.7 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42
43#include <xsh_data_instrument.h>
44#include <xsh_pfits.h>
45#include <xsh_msg.h>
46#include <xsh_utils.h>
47#include <tests.h>
48#include <cpl.h>
49#include <math.h>
50
51#include <getopt.h>
52
53#include <xsh_data_spectrum.h>
54/*---------------------------------------------------------------------------
55 Defines
56 ---------------------------------------------------------------------------*/
57#define MODULE_ID "XSH_COMPUTE_RESPONSE"
58
60char DbgLevel[8] ;
61
62enum {
64} ;
65
66static struct option LongOptions[] = {
67 {"arm", required_argument, 0, ARM_OPT},
68 {"debug-level", required_argument, 0, DBG_OPT},
69 {NULL, 0, 0, 0}
70} ;
71static const char * Options = "?" ;
72
73static void Help( void )
74{
75 puts( "Unitary test of xsh_compute_response" ) ;
76 puts( "Usage: test_xsh_compute_response [options] <spectrum> <star_table> [<atmos_ext>] " ) ;
77 puts( "Options:" ) ;
78 puts( " --arm=<arm> : Set the arm (NIR/UVB/VIS). Default 'VIS'" ) ;
79 puts( " --debug-level=<level> : Set the debug level (none/low/medium/high)." ) ;
80 puts( " Default 'low'" ) ;
81 TEST_END();
82 exit( 0 ) ;
83}
84
85static void HandleOptions( int argc, char **argv )
86{
87 int opt ;
88 int option_index = 0;
89
90 while (( opt = getopt_long (argc, argv, Options, LongOptions,
91 &option_index )) != EOF )
92 switch( opt ) {
93 case ARM_OPT:
94 TheArm = xsh_arm_get( optarg );
95 break ;
96 case DBG_OPT:
97 strcpy( DbgLevel, optarg ) ;
98 break ;
99 default:
100 Help() ;
101 }
102}
103
104/*--------------------------------------------------------------------------*/
111/*--------------------------------------------------------------------------*/
112
113int main( int argc, char **argv)
114{
115 int ret = 1;
116
118 cpl_frame * spectrum_frame = NULL ;
119 cpl_frame * star_frame = NULL ;
120 cpl_frame * atmos_frame = NULL ;
121 cpl_frame * result = NULL ;
122 const char * spectrum_name = NULL ;
123 const char * star_name = NULL ;
124 const char * atmos_name = NULL ;
125 const char * tag ;
126
127 char arm_str[8] ;
128 double exptime = 1. ;
129 int nbframes ;
130
132 cpl_msg_set_level(CPL_MSG_DEBUG);
133 if ( strcmp( DbgLevel, "low" ) == 0 )
135 else if ( strcmp( DbgLevel, "medium" ) == 0 )
137 else if ( strcmp( DbgLevel, "high" ) == 0 )
140
141 /* Analyse parameters */
142 HandleOptions( argc, argv );
143
144 nbframes = argc - optind ;
145 if ( nbframes >= 2 ) {
146 spectrum_name = argv[optind] ;
147 star_name = argv[optind+1] ;
148 if ( nbframes == 3 ) atmos_name = argv[optind+2] ;
149 }
150 else Help() ;
151
153 XSH_LAMP_UNDEFINED, "xsh_respon_stare");
154 sprintf( arm_str, "%s", xsh_instrument_arm_tostring(instrument) ) ;
155
157 xsh_msg_dbg_medium( "%s tag: %s", spectrum_name, tag ) ;
158 TESTS_XSH_FRAME_CREATE( spectrum_frame, tag, spectrum_name ) ;
159
161 xsh_msg_dbg_medium( "%s tag: %s", star_name, tag ) ;
162 TESTS_XSH_FRAME_CREATE( star_frame, tag, star_name ) ;
163
164 if ( atmos_name != NULL ) {
166 xsh_msg_dbg_medium( "%s tag: %s", atmos_name, tag ) ;
167 TESTS_XSH_FRAME_CREATE( atmos_frame, tag, atmos_name ) ;
168 }
169
170 /* Get Exptime */
171 {
172 xsh_spectrum * xspec = NULL ;
173
174 check( xspec = xsh_spectrum_load( spectrum_frame) ) ;
176 xsh_msg( "EXPTIME: %lf", exptime ) ;
177
178 xsh_spectrum_free( &xspec ) ;
179 }
180
181
182 check( result = xsh_compute_response( spectrum_frame,
183 star_frame,
184 atmos_frame,
185 NULL,
187 exptime ) ) ;
188 ret = 0 ;
189
190 cleanup:
191 xsh_free_frame(&result);
192 xsh_msg( "Finished %d", ret ) ;
193 return ret ;
194
195}
int main()
Unit test of xsh_bspline_interpol.
static double exptime
static xsh_instrument * instrument
static void HandleOptions(int argc, char **argv)
static const char * Options
char DbgLevel[8]
XSH_ARM TheArm
static void Help(void)
#define MODULE_ID
static struct option LongOptions[]
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
void xsh_spectrum_free(xsh_spectrum **s)
free memory associated to an 1D spectrum
#define check(COMMAND)
Definition: xsh_error.h:71
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_ARM xsh_arm_get(const char *tag)
get the arm from the frame tag
#define xsh_msg_dbg_medium(...)
Definition: xsh_msg.h:44
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
double xsh_pfits_get_exptime(const cpl_propertylist *plist)
find out the exposure time
Definition: xsh_pfits.c:2254
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
cpl_propertylist * flux_header
#define TESTS_XSH_INSTRUMENT_CREATE(instr, mode, arm, lamp, recipe)
Definition: tests.h:115
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
cpl_frame * xsh_compute_response(cpl_frame *spectrum_frame, cpl_frame *flux_std_star_cat_frame, cpl_frame *atmos_ext_frame, cpl_frame *high_abs_frame, xsh_instrument *instrument, double exptime)
@ XSH_LAMP_UNDEFINED
@ XSH_ARM_VIS
@ XSH_MODE_SLIT
#define XSH_ATMOS_EXT
Definition: xsh_dfs.h:1191
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_MERGE1D
Definition: xsh_dfs.h:592
#define XSH_STD_STAR_FLUX(arm)
Definition: xsh_dfs.h:1513
@ XSH_DEBUG_LEVEL_NONE
Definition: xsh_utils.h:137
@ XSH_DEBUG_LEVEL_LOW
Definition: xsh_utils.h:137