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
00044 #include <xsh_data_order.h>
00045 #include <xsh_error.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_data_instrument.h>
00048 #include <xsh_dfs.h>
00049 #include <xsh_pfits.h>
00050 #include <tests.h>
00051 #include <xsh_data_spectralformat.h>
00052 #include <xsh_data_arclist.h>
00053 #include <xsh_data_wavesol.h>
00054 #include <xsh_utils_table.h>
00055 #include <cpl.h>
00056 #include <math.h>
00057 #include <getopt.h>
00058
00059
00060
00061
00062 #define XSH_FLOAT_PRECISION 0.000001
00063 #define MODULE_ID "XSH_DATA_WAVE_TAB_2D"
00064
00065 #define SYNTAX "Test the wave tab 2d\n"\
00066 "usage : ./the_xsh_data_wave_tab_2d [OPTIONS] WAVE_TAB_2D ARC_LIST SPECTRAL_FORMAT\n"\
00067 "WAVE_TAB_2D => The wave tab 2d\n"\
00068 "ARC_LIST => An arclist\n"\
00069 "SPECTRAL_FORMAT => The spectral format\n"\
00070 "OPTIONS => :\n"\
00071 " --slit-step=<nn> : Step in slit. Default 0.2 \n"
00072
00073
00074 static const char * Options = "";
00075
00076 enum {
00077 SLIT_STEP_OPT
00078 } ;
00079
00080 static float slit_step = 1.4;
00081
00082
00083 static struct option LongOptions[] = {
00084 {"slit-step", required_argument, 0, SLIT_STEP_OPT},
00085 {NULL, 0, 0, 0}
00086 } ;
00087
00088
00089
00090
00091
00092 static void HandleOptions( int argc, char ** argv)
00093 {
00094 int opt ;
00095 int option_index = 0;
00096
00097 while( (opt = getopt_long( argc, argv, Options,
00098 LongOptions, &option_index )) != EOF )
00099 switch( opt ) {
00100 case SLIT_STEP_OPT:
00101 slit_step = atof(optarg);
00102 break ;
00103 default:
00104 printf( SYNTAX ) ;
00105 exit( 0 ) ;
00106 }
00107 }
00108
00109
00117
00118 int main(int argc, char** argv)
00119 {
00120 int ret = 0;
00121 int i;
00122 float j,k;
00123 xsh_instrument * instrument = NULL ;
00124
00125
00126 char* wave_tab_2d_name = NULL;
00127 cpl_frame *wave_tab_2d_frame = NULL;
00128 char* spectralformat_name = NULL;
00129 cpl_frame *spectralformat_frame = NULL;
00130 char* arclist_name = NULL;
00131 cpl_frame *arclist_frame = NULL;
00132 xsh_spectralformat_list *spec_list = NULL;
00133 xsh_wavesol *wave_tab_2d = NULL;
00134 FILE* wave_tab_2d_file = NULL;
00135 FILE* wave_tab_2d_dat_file = NULL;
00136 xsh_arclist *arclist = NULL;
00137
00138
00139
00140 TESTS_INIT(MODULE_ID);
00141 cpl_msg_set_level(CPL_MSG_DEBUG);
00142 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00143
00144 HandleOptions( argc, argv);
00145
00146
00147 if ( (argc-optind) == 3) {
00148 wave_tab_2d_name = argv[optind++];
00149 arclist_name = argv[optind++];
00150 spectralformat_name = argv[optind++];
00151 }
00152 else{
00153 printf(SYNTAX);
00154 return 0;
00155 }
00156 xsh_msg("Wave tab 2d : %s", wave_tab_2d_name);
00157 xsh_msg("Arclist : %s", arclist_name);
00158 xsh_msg("Spectral format : %s", spectralformat_name);
00159 xsh_msg(" Options : slit-step %f", slit_step);
00160
00161
00162 XSH_ASSURE_NOT_NULL( wave_tab_2d_name);
00163 wave_tab_2d_frame = cpl_frame_new();
00164 cpl_frame_set_filename( wave_tab_2d_frame, wave_tab_2d_name) ;
00165 cpl_frame_set_level( wave_tab_2d_frame, CPL_FRAME_LEVEL_TEMPORARY);
00166 cpl_frame_set_group( wave_tab_2d_frame, CPL_FRAME_GROUP_RAW);
00167
00168 XSH_ASSURE_NOT_NULL( arclist_name);
00169 arclist_frame = cpl_frame_new();
00170 cpl_frame_set_filename( arclist_frame, arclist_name) ;
00171 cpl_frame_set_level( arclist_frame, CPL_FRAME_LEVEL_TEMPORARY);
00172 cpl_frame_set_group( arclist_frame, CPL_FRAME_GROUP_RAW);
00173
00174 XSH_ASSURE_NOT_NULL( spectralformat_name);
00175 spectralformat_frame = cpl_frame_new();
00176 cpl_frame_set_filename( spectralformat_frame, spectralformat_name) ;
00177 cpl_frame_set_level( spectralformat_frame, CPL_FRAME_LEVEL_TEMPORARY);
00178 cpl_frame_set_group( spectralformat_frame, CPL_FRAME_GROUP_RAW);
00179
00180 instrument = xsh_instrument_new();
00181 check( spec_list = xsh_spectralformat_list_load( spectralformat_frame,
00182 instrument));
00183 check( wave_tab_2d = xsh_wavesol_load( wave_tab_2d_frame, instrument));
00184 xsh_msg("Wavesol lambda (%f,%f)", wave_tab_2d->min_lambda,
00185 wave_tab_2d->max_lambda);
00186 xsh_msg("Wavesol order (%f,%f)", wave_tab_2d->min_order,
00187 wave_tab_2d->max_order);
00188 xsh_msg("Wavesol slit (%f,%f)", wave_tab_2d->min_slit,
00189 wave_tab_2d->max_slit);
00190
00191 wave_tab_2d_file = fopen( "WAVE_TAB_2D_sample.reg", "w");
00192 wave_tab_2d_dat_file = fopen( "WAVE_TAB_2D_sample.dat", "w");
00193
00194 fprintf( wave_tab_2d_file, "# Region file format: DS9 version 4.0\n"\
00195 "global color=red font=\"helvetica 10 normal\""\
00196 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
00197 "source\nimage\n");
00198 fprintf( wave_tab_2d_dat_file, "# x y lambda slit\n");
00199
00200 check( arclist = xsh_arclist_load( arclist_frame));
00201
00202 for( i=0; i< arclist->size; i++){
00203 double absorder;
00204 float lambda;
00205 cpl_vector* orders = NULL;
00206 int nb_orders;
00207
00208 check( lambda = xsh_arclist_get_wavelength( arclist, i));
00209 check( orders = xsh_spectralformat_list_get_orders( spec_list, lambda));
00210 if (orders != NULL){
00211 check( nb_orders = cpl_vector_get_size( orders));
00212 }
00213 else{
00214 nb_orders = 0;
00215 }
00216 for(j=0; j < nb_orders; j++){
00217 double x, y;
00218 absorder= cpl_vector_get( orders, j);
00219 xsh_msg("order %f lambda %f", absorder, lambda);
00220 check( x = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, 0.0));
00221 check( y = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, 0.0));
00222 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=red font="\
00223 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, lambda);
00224 fprintf( wave_tab_2d_dat_file,"%f %f %f %f\n", x, y , lambda, 0.0);
00225
00226
00227
00228
00229
00230
00231
00232
00233 for( k=wave_tab_2d->min_slit; k <= (wave_tab_2d->max_slit+0.00001-slit_step); k+=slit_step){
00234 double x1,x2,y1,y2;
00235 check( x1 = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, k));
00236 check( y1 = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, k));
00237 check( x2 = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, k+slit_step));
00238 check( y2 = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, k+slit_step));
00239 fprintf( wave_tab_2d_file, "line(%f,%f,%f,%f) #color=green font="\
00240 "\"helvetica 10 normal\"\n", x1, y1, x2, y2);
00241 fprintf( wave_tab_2d_dat_file,"%f %f %f %f\n", x, y , lambda, k);
00242 }
00243 }
00244 }
00245 fclose( wave_tab_2d_file);
00246 fclose( wave_tab_2d_dat_file);
00247
00248 cleanup:
00249 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00250 xsh_error_dump(CPL_MSG_ERROR);
00251 ret = 1;
00252 }
00253 return ret ;
00254 }
00255