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_resid_tab.h>
00050 #include <xsh_drl.h>
00051 #include <xsh_pfits.h>
00052
00053 #include <xsh_model_io.h>
00054 #include <xsh_model_kernel.h>
00055 #include <cpl.h>
00056 #include <math.h>
00057
00058 #include <getopt.h>
00059
00060
00061
00062
00063
00064 #define MODULE_ID "XSH_MODEL_MAPS_CREATE"
00065 #define SYNTAX "Create a wave and a slit map from model\n"\
00066 "use : ./test_xsh_model_maps_create SOF\n"\
00067 "SOF => model config and arclist\n"\
00068 "Options:\n"\
00069 " --binx=<n> : binning in X (default 1)\n"\
00070 " --biny=<n> : binning in Y (default 1)\n"
00071
00072
00073
00074
00075
00076
00077
00078
00079
00087 static const char * Options = "?" ;
00088
00089 enum {
00090 BINX_OPT, BINY_OPT
00091 } ;
00092
00093 static struct option LongOptions[] = {
00094 {"binx", required_argument, 0, BINX_OPT},
00095 {"biny", required_argument, 0, BINY_OPT},
00096
00097 {NULL, 0, 0, 0}
00098 } ;
00099 static char mode[32] ;
00100 int binx =1;
00101 int biny =1;
00102
00103 static void HandleOptions( int argc, char ** argv )
00104 {
00105 int opt ;
00106 int option_index = 0;
00107
00108
00109 strcpy( mode, "SLIT" ) ;
00110
00111 while( (opt = getopt_long( argc, argv, Options,
00112 LongOptions, &option_index )) != EOF )
00113 switch( opt ) {
00114 case BINX_OPT:
00115 binx = atoi(optarg);
00116 case BINY_OPT:
00117 biny = atoi(optarg);
00118 break ;
00119
00120
00121
00122
00123 default:
00124 printf( SYNTAX ) ;
00125 TEST_END();
00126 exit( 0 ) ;
00127 }
00128
00129 }
00130
00131
00132 int main( int argc, char **argv)
00133 {
00134 int ret=0;
00135 xsh_instrument *instrument = NULL ;
00136 const char *sof_name = NULL;
00137 const char *model_config_name = NULL;
00138 const char *lines_list_name = NULL;
00139 cpl_frame *model_config_frame = NULL;
00140 cpl_frame *lines_list_frame = NULL;
00141 cpl_frame *the_frame = NULL;
00142 cpl_frameset *set = NULL;
00143 cpl_frameset *raws = NULL;
00144 cpl_frameset *calib = NULL;
00145 int i = 0;
00146 FILE* sof_file = NULL;
00147 char sof_line[200];
00148 xsh_xs_3 config_model;
00149 cpl_frame* wmap_frame=NULL;
00150 cpl_frame* smap_frame=NULL;
00151
00152 char *pre_name = NULL;
00153
00154
00155
00156 TESTS_INIT(MODULE_ID);
00157 cpl_msg_set_level(CPL_MSG_DEBUG);
00158 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00159
00160 HandleOptions( argc, argv );
00161
00162
00163
00164 if ((argc-optind) <= 2){
00165 pre_name = argv[optind];
00166 sof_name = argv[optind];
00167 }
00168 else{
00169 printf(SYNTAX);
00170 return 0;
00171 }
00172
00173
00174 XSH_ASSURE_NOT_NULL( sof_name);
00175
00176
00177 check( set = cpl_frameset_new());
00178 sof_file = fopen( sof_name, "r");
00179
00180 while ( fgets( sof_line, 200, sof_file)){
00181 char raw_name[200];
00182 char raw_tag[200];
00183 cpl_frame *raw_frame = NULL;
00184 sscanf( sof_line, "%s %s", raw_name, raw_tag);
00185 check( raw_frame = cpl_frame_new());
00186 check( cpl_frame_set_filename( raw_frame, raw_name));
00187 check( cpl_frame_set_tag( raw_frame, raw_tag));
00188 check( cpl_frameset_insert(set, raw_frame));
00189 }
00190 fclose( sof_file);
00191
00192
00193 check( instrument = xsh_dfs_set_groups( set));
00194 XSH_NEW_FRAMESET( raws);
00195 XSH_NEW_FRAMESET( calib);
00196 check( xsh_dfs_split_in_group( set, raws, calib));
00197
00198 check( lines_list_frame = xsh_find_arc_line_list( calib, instrument));
00199 check( model_config_frame = xsh_find_model_config_tab( calib, instrument));
00200
00201 check( lines_list_name = cpl_frame_get_filename( lines_list_frame));
00202 check( model_config_name = cpl_frame_get_filename( model_config_frame));
00203
00204 xsh_msg(" Find model %s\n", model_config_name);
00205 xsh_msg(" Find lines list %s\n", lines_list_name);
00206
00207 check( xsh_model_config_load_best( model_config_frame, &config_model));
00208
00209 xsh_model_binxy(&config_model,binx,biny);
00210 check(xsh_model_maps_create( &config_model, instrument,
00211 "WAVE_MAP_TEST","SLIT_MAP_TEST",
00212 &wmap_frame,&smap_frame));
00213
00214
00215
00216 cleanup:
00217 xsh_free_frame(&wmap_frame);
00218 xsh_free_frame(&smap_frame);
00219 xsh_free_frameset(&set);
00220 xsh_free_frameset(&raws);
00221 xsh_free_frameset(&calib);
00222 xsh_instrument_free(&instrument);
00223
00224 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00225 xsh_error_dump(CPL_MSG_ERROR);
00226 return 1;
00227 }
00228 else return ret ;
00229 }
00230