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_data_pre.h>
00046 #include <xsh_error.h>
00047 #include <xsh_msg.h>
00048 #include <xsh_data_instrument.h>
00049 #include <xsh_data_rec.h>
00050 #include <xsh_data_localization.h>
00051 #include <xsh_drl.h>
00052 #include <xsh_pfits.h>
00053
00054 #include <xsh_badpixelmap.h>
00055
00056 #include <cpl.h>
00057 #include <math.h>
00058
00059 #include <getopt.h>
00060
00061
00062
00063
00064
00065 #define MODULE_ID "XSH_EXTRACT"
00066
00067 #define SYNTAX "Test a spectrum order 1D file\n"\
00068 "use : ./test_xsh_data_spectrum_order_1D FRAME\n"\
00069 "FRAME => the spectrum order 1D frame\n"
00070
00071 static void analyse_extraction( cpl_frame* rec_frame, xsh_instrument* instr);
00072
00073
00074
00075
00076 static void analyse_extraction( cpl_frame* rec_frame, xsh_instrument* instr)
00077 {
00078 const char* rec_name = NULL;
00079 xsh_rec_list* rec_list = NULL;
00080 int iorder;
00081
00082 XSH_ASSURE_NOT_NULL( rec_frame);
00083
00084 check( rec_name = cpl_frame_get_filename( rec_frame));
00085
00086 printf("RECTIFY frame : %s\n", rec_name);
00087 check( rec_list = xsh_rec_list_load( rec_frame, instr));
00088
00089 for(iorder=0; iorder< rec_list->size; iorder++){
00090 int order = 0, ilambda = 0;
00091 int nlambda = 0;
00092 float *flux = NULL;
00093 float *err = NULL;
00094 double *lambda = NULL;
00095 char name[256];
00096 FILE* datfile = NULL;
00097
00098 check( order = xsh_rec_list_get_order(rec_list, iorder));
00099 check( nlambda = xsh_rec_list_get_nlambda(rec_list, iorder));
00100 check( flux = xsh_rec_list_get_data1( rec_list, iorder));
00101 check( err = xsh_rec_list_get_errs1( rec_list, iorder));
00102 check( lambda = xsh_rec_list_get_lambda( rec_list, iorder));
00103
00104 sprintf( name, "spectrum1D_order%d.dat",order);
00105 xsh_msg("Save file %s",name);
00106 datfile = fopen( name, "w");
00107
00108 fprintf( datfile, "#lambda flux err\n");
00109
00110 for(ilambda=0; ilambda < nlambda; ilambda++){
00111 fprintf( datfile,"%f %f %f\n",lambda[ilambda],flux[ilambda], err[ilambda]);
00112 }
00113 fclose(datfile);
00114
00115 }
00116 cleanup:
00117 xsh_rec_list_free( &rec_list);
00118 return;
00119 }
00120
00128 int main( int argc, char **argv)
00129 {
00130
00131 int ret = 0 ;
00132 xsh_instrument* instrument = NULL;
00133 char* rec_name = NULL;
00134 cpl_frame* rec_frame = NULL;
00135
00136
00137 TESTS_INIT(MODULE_ID);
00138
00139 cpl_msg_set_level(CPL_MSG_DEBUG);
00140 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00141
00142
00143
00144 if ( argc == 2 ) {
00145 rec_name = argv[1];
00146 }
00147 else{
00148 printf(SYNTAX);
00149 TEST_END();
00150 exit(0);
00151 }
00152 rec_frame = cpl_frame_new();
00153 XSH_ASSURE_NOT_NULL (rec_frame);
00154 cpl_frame_set_filename( rec_frame, rec_name) ;
00155 cpl_frame_set_level( rec_frame, CPL_FRAME_LEVEL_TEMPORARY);
00156 cpl_frame_set_group( rec_frame, CPL_FRAME_GROUP_RAW ) ;
00157
00158
00159
00160 instrument = xsh_instrument_new() ;
00161 check( analyse_extraction( rec_frame, instrument));
00162
00163 cleanup:
00164 xsh_instrument_free( &instrument);
00165 xsh_free_frame( &rec_frame);
00166
00167 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00168 xsh_error_dump(CPL_MSG_ERROR);
00169 ret=1;
00170 }
00171 TEST_END();
00172 return ret ;
00173 }
00174