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 <tests.h>
00044
00045 #include <xsh_error.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_drl.h>
00048 #include <cpl.h>
00049 #include <math.h>
00050 #include <xsh_data_spectrum.h>
00051 #include <string.h>
00052 #include <getopt.h>
00053
00054
00055
00056
00057
00058 #define MODULE_ID "XSH_MARK_TELL"
00059
00060 enum {
00061 HELP_OPT
00062 } ;
00063
00064 static struct option long_options[] = {
00065 {"help", 0, 0, HELP_OPT},
00066 {0, 0, 0, 0}
00067 };
00068
00069 static void Help( void )
00070 {
00071 puts( "Unitary test of xsh_mark_tell");
00072 puts( "Usage: test_xsh_mark_tell [options] S1D TELLLIST");
00073
00074 puts( "Options" ) ;
00075 puts( " --help : What you see" ) ;
00076 puts( "\nInput Files" ) ;
00077 puts( "S1D : 1D spectrum file");
00078 puts( "TELL_MASK : telluric mask");
00079 TEST_END();
00080 }
00081
00082
00083 static void HandleOptions( int argc, char **argv)
00084 {
00085 int opt ;
00086 int option_index = 0;
00087
00088 while (( opt = getopt_long (argc, argv,
00089 "help",
00090 long_options, &option_index)) != EOF ){
00091
00092 switch ( opt ) {
00093 default:
00094 Help(); exit(-1);
00095 }
00096 }
00097 return;
00098 }
00099
00100 static void analyse_spectrum( cpl_frame* spectrum_frame);
00101
00102
00103
00104
00105 static void analyse_spectrum( cpl_frame* spectrum_frame)
00106 {
00107 const char* spectrum_name = NULL;
00108 xsh_spectrum *spectrum = NULL;
00109 int i;
00110 FILE* fulldatfile = NULL;
00111 double* flux = NULL;
00112 int *qual = NULL;
00113
00114 XSH_ASSURE_NOT_NULL( spectrum_frame);
00115
00116 check (spectrum_name = cpl_frame_get_filename( spectrum_frame));
00117
00118 xsh_msg("Spectrum frame : %s", spectrum_name);
00119
00120 check( spectrum = xsh_spectrum_load( spectrum_frame));
00121 check( flux = xsh_spectrum_get_flux( spectrum));
00122 check( qual = xsh_spectrum_get_qual( spectrum));
00123
00124 fulldatfile = fopen("s1d_with_tell.dat","w");
00125 for(i=0; i< spectrum->size; i++){
00126 fprintf( fulldatfile, "%f %f %d\n", spectrum->lambda_min+i*spectrum->lambda_step, flux[i],
00127 qual[i]);
00128 }
00129 xsh_msg("Save file s1d_with_tell.dat");
00130 fclose( fulldatfile);
00131
00132 cleanup:
00133 xsh_spectrum_free( &spectrum);
00134 return;
00135 }
00136
00137 int main( int argc, char **argv)
00138 {
00139
00140 int ret = 0 ;
00141 const char *s1d_name = NULL;
00142 cpl_frame *s1d_frame = NULL;
00143 const char *mask_name = NULL;
00144 cpl_frame *mask_frame = NULL;
00145 xsh_instrument *instr = NULL;
00146
00147
00148 TESTS_INIT(MODULE_ID);
00149
00150 cpl_msg_set_level(CPL_MSG_DEBUG);
00151 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM);
00152
00153
00154 HandleOptions( argc, argv);
00155
00156 if ( (argc - optind) > 1 ) {
00157 s1d_name = argv[optind];
00158 mask_name = argv[optind+1];
00159 }
00160 else {
00161 Help();
00162 exit( 0);
00163 }
00164
00165 xsh_msg("---Input Files");
00166 xsh_msg("S1D File : %s ", s1d_name);
00167 xsh_msg("Tell mask File : %s ", mask_name);
00168
00169 instr = xsh_instrument_new();
00170 TESTS_XSH_FRAME_CREATE( s1d_frame, "S1D", s1d_name);
00171 TESTS_XSH_FRAME_CREATE( mask_frame, "TELL_MASK", mask_name);
00172
00173 check( xsh_mark_tell( s1d_frame, mask_frame));
00174
00175 analyse_spectrum( s1d_frame);
00176 cleanup:
00177 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00178 xsh_error_dump(CPL_MSG_ERROR);
00179 ret=1;
00180 }
00181 xsh_free_frame( &s1d_frame);
00182 xsh_free_frame( &mask_frame);
00183 TEST_END();
00184 return ret ;
00185 }
00186
00187