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_data_instrument.h>
00048 #include <xsh_drl.h>
00049 #include <xsh_model_io.h>
00050 #include <xsh_data_the_map.h>
00051 #include <xsh_pfits.h>
00052
00053 #include <cpl.h>
00054 #include <math.h>
00055
00056 #include <getopt.h>
00057
00058
00059
00060
00061
00062 #define MODULE_ID "XSH_GUESS"
00063 #define SYNTAX "Test X,Y point generation\n"\
00064 "use : ./the_xsh_guess XSH_MODEL_CFG INPUT_MODEL_TAB (columns 'order', 'wavelength', 'slit')\n"\
00065 "(table with predicted 'x','y' predicted positions)\n"
00066
00067
00068
00069
00070
00071
00079 int main( int argc, char **argv)
00080 {
00081
00082 int ret = 0 ;
00083 const char* tag=NULL;
00084 char* model_cfg_name = NULL;
00085 char* input_tab_name = NULL;
00086 cpl_propertylist* plist=NULL;
00087 cpl_frame* model_cfg_frame = NULL;
00088 cpl_frame* the_map_frame = NULL;
00089 xsh_the_map* the_map_list=NULL;
00090 int i = 0;
00091 FILE* themap_file = NULL;
00092 xsh_xs_3 model_config ;
00093 int binx=1;
00094 int biny=1;
00095 cpl_table* the_map_tab=NULL;
00096 int* pord=NULL;
00097 float* pwav=NULL;
00098 int* ps=NULL;
00099 int nrow=0;
00100 double x=0;
00101 double y=0;
00102 xsh_instrument* inst;
00103
00104 TESTS_INIT(MODULE_ID);
00105
00106 cpl_msg_set_level(CPL_MSG_DEBUG);
00107 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00108
00109
00110 if (argc > 1){
00111 model_cfg_name = argv[1];
00112 input_tab_name = argv[2];
00113 }
00114 else{
00115 printf(SYNTAX);
00116 return 0;
00117 }
00118
00119
00120 XSH_ASSURE_NOT_NULL( model_cfg_name);
00121 plist=cpl_propertylist_load(model_cfg_name,0);
00122 tag=xsh_pfits_get_pcatg(plist);
00123
00124 check(model_cfg_frame = cpl_frame_new());
00125 cpl_frame_set_filename( model_cfg_frame, model_cfg_name) ;
00126 cpl_frame_set_level( model_cfg_frame, CPL_FRAME_LEVEL_TEMPORARY);
00127 cpl_frame_set_group( model_cfg_frame, CPL_FRAME_GROUP_RAW ) ;
00128 cpl_frame_set_type( model_cfg_frame, CPL_FRAME_TYPE_TABLE ) ;
00129 check(cpl_frame_set_tag( model_cfg_frame, tag ) );
00130
00131 xsh_msg("model_cfg_name=%s",model_cfg_name);
00132 xsh_msg("input_tab_name=%s",input_tab_name);
00133
00134 inst=xsh_instrument_new();
00135 check(xsh_instrument_parse_tag(inst,tag));
00136 check( xsh_model_config_load_best( model_cfg_frame, &model_config));
00137 xsh_model_binxy(&model_config,binx,biny);
00138 the_map_tab=cpl_table_load(input_tab_name,1,0);
00139
00140 check(pwav=cpl_table_get_data_float(the_map_tab,XSH_THE_MAP_TABLE_COLNAME_WAVELENGTH));
00141 check(pord=cpl_table_get_data_int(the_map_tab,XSH_THE_MAP_TABLE_COLNAME_ORDER));
00142 check(ps=cpl_table_get_data_int(the_map_tab,XSH_THE_MAP_TABLE_COLNAME_SLITINDEX));
00143
00144 nrow=cpl_table_get_nrow(the_map_tab);
00145 for(i=0;i<nrow;i++) {
00146 check(xsh_model_get_xy(&model_config,inst,pwav[i],pord[i],ps[i],&x,&y));
00147 }
00148 xsh_free_table(&the_map_tab);
00149
00150
00151
00152 themap_file = fopen( "THEMAP.reg", "w");
00153 fprintf( themap_file, "# Region file format: DS9 version 4.0\n\
00154 global color=red font=\"helvetica 4 normal\"\
00155 select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source \nimage\n");
00156
00157
00158 the_map_frame = cpl_frame_new();
00159 cpl_frame_set_filename( the_map_frame, input_tab_name) ;
00160 cpl_frame_set_level( the_map_frame, CPL_FRAME_LEVEL_TEMPORARY);
00161 cpl_frame_set_group( the_map_frame, CPL_FRAME_GROUP_RAW ) ;
00162 cpl_frame_set_type( the_map_frame, CPL_FRAME_TYPE_TABLE ) ;
00163 cpl_frame_set_tag( the_map_frame, tag ) ;
00164
00165 the_map_list=xsh_the_map_load(the_map_frame);
00166
00167 int themap_size=nrow;
00168 for( i=0; i<themap_size; i++){
00169 float lambdaTHE = 0.0;
00170 double xd, yd, order, slit;
00171
00172 check(lambdaTHE = xsh_the_map_get_wavelength(the_map_list, i));
00173
00174 check(xd = xsh_the_map_get_detx(the_map_list, i));
00175 check(yd = xsh_the_map_get_dety(the_map_list, i));
00176 check(order = (double)xsh_the_map_get_order(the_map_list, i));
00177 check(slit = (double) xsh_the_map_get_slit_position( the_map_list, i));
00178 if (slit == 0){
00179 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
00180 "font=\"helvetica 10 normal\" text={THE %.3f}\n", xd, yd, lambdaTHE);
00181 }
00182 else{
00183 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
00184 "font=\"helvetica 10 normal\" text={slit %f}\n", xd, yd, slit);
00185 }
00186 }
00187
00188
00189
00190 cleanup:
00191 xsh_free_propertylist(&plist);
00192 xsh_the_map_free(&the_map_list);
00193 xsh_free_table(&the_map_tab);
00194 xsh_free_frame(&the_map_frame);
00195 xsh_free_frame(&model_cfg_frame);
00196 xsh_instrument_free(&inst);
00197 if(themap_file != NULL) {
00198 fclose( themap_file);
00199 }
00200 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00201 xsh_error_dump(CPL_MSG_ERROR);
00202 ret = -1;
00203 }
00204 return ret ;
00205 }
00206