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_frameset *set = NULL;
00142 cpl_frameset *raws = NULL;
00143 cpl_frameset *calib = NULL;
00144
00145 FILE* sof_file = NULL;
00146 char sof_line[200];
00147 xsh_xs_3 config_model;
00148 cpl_frame* wmap_frame=NULL;
00149 cpl_frame* smap_frame=NULL;
00150
00151 char *pre_name = NULL;
00152
00153
00154
00155 TESTS_INIT(MODULE_ID);
00156 cpl_msg_set_level(CPL_MSG_DEBUG);
00157 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00158
00159 HandleOptions( argc, argv );
00160
00161
00162
00163 if ((argc-optind) <= 2){
00164 pre_name = argv[optind];
00165 sof_name = argv[optind];
00166 }
00167 else{
00168 printf(SYNTAX);
00169 return 0;
00170 }
00171
00172
00173 XSH_ASSURE_NOT_NULL( sof_name);
00174
00175
00176 check( set = cpl_frameset_new());
00177 sof_file = fopen( sof_name, "r");
00178
00179 while ( fgets( sof_line, 200, sof_file)){
00180 char raw_name[200];
00181 char raw_tag[200];
00182 cpl_frame *raw_frame = NULL;
00183 sscanf( sof_line, "%s %s", raw_name, raw_tag);
00184 check( raw_frame = cpl_frame_new());
00185 check( cpl_frame_set_filename( raw_frame, raw_name));
00186 check( cpl_frame_set_tag( raw_frame, raw_tag));
00187 check( cpl_frameset_insert(set, raw_frame));
00188 }
00189
00190
00191
00192 check( instrument = xsh_dfs_set_groups( set));
00193 XSH_NEW_FRAMESET( raws);
00194 XSH_NEW_FRAMESET( calib);
00195 check( xsh_dfs_split_in_group( set, raws, calib));
00196
00197 check( lines_list_frame = xsh_find_arc_line_list( calib, instrument));
00198 check( model_config_frame = xsh_find_model_config_tab( calib, instrument));
00199
00200 check( lines_list_name = cpl_frame_get_filename( lines_list_frame));
00201 check( model_config_name = cpl_frame_get_filename( model_config_frame));
00202
00203 xsh_msg(" Find model %s\n", model_config_name);
00204 xsh_msg(" Find lines list %s\n", lines_list_name);
00205
00206 check( xsh_model_config_load_best( model_config_frame, &config_model));
00207
00208 xsh_model_binxy(&config_model,binx,biny);
00209 check(xsh_model_maps_create( &config_model, instrument,
00210 "WAVE_MAP_TEST","SLIT_MAP_TEST",
00211 &wmap_frame,&smap_frame,0));
00212
00213
00214
00215 cleanup:
00216 if(sof_file!=NULL) {
00217 fclose( sof_file);
00218 }
00219 xsh_free_frame(&wmap_frame);
00220 xsh_free_frame(&smap_frame);
00221 xsh_free_frameset(&set);
00222 xsh_free_frameset(&raws);
00223 xsh_free_frameset(&calib);
00224 xsh_instrument_free(&instrument);
00225
00226 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00227 xsh_error_dump(CPL_MSG_ERROR);
00228 return 1;
00229 }
00230 else return ret ;
00231 }
00232