00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00036
00039
00040
00041
00042
00043 #include <xsh_data_instrument.h>
00044 #include <xsh_pfits.h>
00045 #include <xsh_msg.h>
00046 #include <xsh_utils.h>
00047 #include <tests.h>
00048 #include <cpl.h>
00049 #include <math.h>
00050
00051 #include <getopt.h>
00052
00053 #include <xsh_data_spectrum.h>
00054
00055
00056
00057 #define MODULE_ID "XSH_COMPUTE_RESPONSE"
00058
00059 XSH_ARM TheArm = XSH_ARM_VIS ;
00060 char DbgLevel[8] ;
00061
00062 enum {
00063 ARM_OPT, DBG_OPT
00064 } ;
00065
00066 static struct option LongOptions[] = {
00067 {"arm", required_argument, 0, ARM_OPT},
00068 {"debug-level", required_argument, 0, DBG_OPT},
00069 {NULL, 0, 0, 0}
00070 } ;
00071 static const char * Options = "?" ;
00072
00073 static void Help( void )
00074 {
00075 puts( "Unitary test of xsh_compute_response" ) ;
00076 puts( "Usage: test_xsh_compute_response [options] <spectrum> <star_table> [<atmos_ext>] " ) ;
00077 puts( "Options:" ) ;
00078 puts( " --arm=<arm> : Set the arm (NIR/UVB/VIS). Default 'VIS'" ) ;
00079 puts( " --debug-level=<level> : Set the debug level (none/low/medium/high)." ) ;
00080 puts( " Default 'low'" ) ;
00081 TEST_END();
00082 exit( 0 ) ;
00083 }
00084
00085 static void HandleOptions( int argc, char **argv )
00086 {
00087 int opt ;
00088 int option_index = 0;
00089
00090 while (( opt = getopt_long (argc, argv, Options, LongOptions,
00091 &option_index )) != EOF )
00092 switch( opt ) {
00093 case ARM_OPT:
00094 TheArm = xsh_arm_get( optarg );
00095 break ;
00096 case DBG_OPT:
00097 strcpy( DbgLevel, optarg ) ;
00098 break ;
00099 default:
00100 Help() ;
00101 }
00102 }
00103
00104
00111
00112
00113 int main( int argc, char **argv)
00114 {
00115 int ret = 1;
00116
00117 xsh_instrument* instrument = NULL;
00118 cpl_frame * spectrum_frame = NULL ;
00119 cpl_frame * star_frame = NULL ;
00120 cpl_frame * atmos_frame = NULL ;
00121 cpl_frame * result = NULL ;
00122 const char * spectrum_name = NULL ;
00123 const char * star_name = NULL ;
00124 const char * atmos_name = NULL ;
00125 const char * tag ;
00126 const char * res_name ;
00127 char arm_str[8] ;
00128 double exptime = 1. ;
00129 int nbframes ;
00130
00131 TESTS_INIT(MODULE_ID);
00132 cpl_msg_set_level(CPL_MSG_DEBUG);
00133 if ( strcmp( DbgLevel, "low" ) == 0 )
00134 xsh_debug_level_set(XSH_DEBUG_LEVEL_LOW);
00135 else if ( strcmp( DbgLevel, "medium" ) == 0 )
00136 xsh_debug_level_set(XSH_DEBUG_LEVEL_LOW);
00137 else if ( strcmp( DbgLevel, "high" ) == 0 )
00138 xsh_debug_level_set(XSH_DEBUG_LEVEL_LOW);
00139 else xsh_debug_level_set(XSH_DEBUG_LEVEL_NONE);
00140
00141
00142 HandleOptions( argc, argv );
00143
00144 nbframes = argc - optind ;
00145 if ( nbframes >= 2 ) {
00146 spectrum_name = argv[optind] ;
00147 star_name = argv[optind+1] ;
00148 if ( nbframes == 3 ) atmos_name = argv[optind+2] ;
00149 }
00150 else Help() ;
00151
00152 TESTS_XSH_INSTRUMENT_CREATE( instrument, XSH_MODE_SLIT, TheArm,
00153 XSH_LAMP_UNDEFINED, "xsh_respon_stare");
00154 sprintf( arm_str, "%s", xsh_instrument_arm_tostring(instrument) ) ;
00155
00156 tag = XSH_GET_TAG_FROM_ARM( XSH_MERGE1D, instrument ) ;
00157 xsh_msg_dbg_medium( "%s tag: %s", spectrum_name, tag ) ;
00158 TESTS_XSH_FRAME_CREATE( spectrum_frame, tag, spectrum_name ) ;
00159
00160 tag = XSH_GET_TAG_FROM_ARM( XSH_STD_STAR_FLUX, instrument ) ;
00161 xsh_msg_dbg_medium( "%s tag: %s", star_name, tag ) ;
00162 TESTS_XSH_FRAME_CREATE( star_frame, tag, star_name ) ;
00163
00164 if ( atmos_name != NULL ) {
00165 tag = XSH_GET_TAG_FROM_ARM( XSH_ATMOS_EXT, instrument ) ;
00166 xsh_msg_dbg_medium( "%s tag: %s", atmos_name, tag ) ;
00167 TESTS_XSH_FRAME_CREATE( atmos_frame, tag, atmos_name ) ;
00168 }
00169
00170
00171 {
00172 xsh_spectrum * xspec = NULL ;
00173
00174 check( xspec = xsh_spectrum_load( spectrum_frame) ) ;
00175 check( exptime = xsh_pfits_get_exptime( xspec->flux_header ) ) ;
00176 xsh_msg( "EXPTIME: %lf", exptime ) ;
00177
00178 xsh_spectrum_free( &xspec ) ;
00179 }
00180
00181 res_name = xsh_stringcat_any( "RESPONSE_SLIT_", arm_str, ".fits", NULL ) ;
00182
00183 check( result = xsh_compute_response( spectrum_frame,
00184 star_frame,
00185 atmos_frame,
00186 NULL,
00187 instrument,
00188 exptime ) ) ;
00189 ret = 0 ;
00190
00191 cleanup:
00192 xsh_msg( "Finished %d", ret ) ;
00193 return ret ;
00194
00195 }