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 <cpl.h>
00054 #include <math.h>
00055
00056 #include <getopt.h>
00057
00058
00059
00060
00061
00062 #define MODULE_ID "XSH_RESID_TAB"
00063 #define SYNTAX "Test the residual tab\n"\
00064 "use : ./the_xsh_resid_tab RESID_TAB \n"\
00065 "RESID_TAB => the residual table\n"
00066
00067
00068
00069
00070
00071
00079 int main( int argc, char **argv)
00080 {
00081
00082 int ret = 0 ;
00083 xsh_instrument* instrument = NULL;
00084
00085 char* resid_tab_name = NULL;
00086 cpl_frame* resid_tab_frame = NULL;
00087 xsh_resid_tab* resid_tab = NULL;
00088 int resid_tab_size = 0;
00089
00090 int i = 0;
00091 FILE* resid_tab_the_file = NULL;
00092
00093
00094 TESTS_INIT(MODULE_ID);
00095
00096 cpl_msg_set_level(CPL_MSG_DEBUG);
00097 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00098
00099
00100 if (argc > 1){
00101 resid_tab_name = argv[1];
00102 }
00103 else{
00104 printf(SYNTAX);
00105 TEST_END();
00106 return 0;
00107 }
00108
00109
00110 instrument = xsh_instrument_new() ;
00111 xsh_instrument_set_mode( instrument, XSH_MODE_IFU );
00112 xsh_instrument_set_arm( instrument, XSH_ARM_VIS);
00113
00114
00115 XSH_ASSURE_NOT_NULL( resid_tab_name);
00116 resid_tab_frame = cpl_frame_new();
00117 cpl_frame_set_filename( resid_tab_frame, resid_tab_name) ;
00118 cpl_frame_set_level( resid_tab_frame, CPL_FRAME_LEVEL_TEMPORARY);
00119 cpl_frame_set_group( resid_tab_frame, CPL_FRAME_GROUP_RAW ) ;
00120
00121 check( resid_tab = xsh_resid_tab_load( resid_tab_frame));
00122 check( resid_tab_size = xsh_resid_tab_get_size( resid_tab));
00123
00124
00125 xsh_msg("Save residual tab in RESID_TAB.reg");
00126 resid_tab_the_file = fopen( "RESID_TAB.reg", "w");
00127
00128 fprintf( resid_tab_the_file, "# Region file format: DS9 version 4.0\n"\
00129 "global color=red font=\"helvetica 10 normal\""\
00130 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
00131 "source\nimage\n");
00132 fprintf( resid_tab_the_file, "# RED the_x the_y (pixels)\n"\
00133 "# MAGENTA corr_x corr_y (pixels)\n"\
00134 "# GREEN gauss_x gauss_y (pixels)\n"\
00135 "# BLUE poly_x poly_y (pixels)\n");
00136
00137 if (resid_tab->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00138 xsh_msg("Residual tab compute from POLYNOMIAL");
00139 }
00140 else{
00141 xsh_msg("Residual tab compute from PHYSICAL MODEL");
00142 }
00143 for( i=0; i<resid_tab_size; i++){
00144 double the_x, the_y;
00145 double corr_x, corr_y;
00146 double gauss_x, gauss_y;
00147 double poly_x, poly_y;
00148 double lambda;
00149
00150 lambda = resid_tab->lambda[i];
00151 the_x = resid_tab->thpre_x[i];
00152 the_y = resid_tab->thpre_y[i];
00153 corr_x = resid_tab->thcor_x[i];
00154 corr_y = resid_tab->thcor_y[i];
00155 gauss_x = resid_tab->xgauss[i];
00156 gauss_y = resid_tab->ygauss[i];
00157 if (resid_tab->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00158 poly_x = resid_tab->xpoly[i];
00159 poly_y = resid_tab->ypoly[i];
00160 }
00161 else{
00162 poly_x = resid_tab->thanneal_x[i];
00163 poly_y = resid_tab->thanneal_y[i];
00164 }
00165 fprintf( resid_tab_the_file, "point(%f,%f) #point=cross color=red text={THE %.3f} font="\
00166 "\"helvetica 10 normal\"\n", the_x, the_y, lambda);
00167 fprintf( resid_tab_the_file, "point(%f,%f) #point=diamond color=magenta font="\
00168 "\"helvetica 4 normal\"\n", corr_x, corr_y);
00169 fprintf( resid_tab_the_file, "point(%f,%f) #point=circle color=green font="\
00170 "\"helvetica 4 normal\"\n", gauss_x, gauss_y);
00171 fprintf( resid_tab_the_file, "point(%f,%f) #point=x color=blue font="\
00172 "\"helvetica 4 normal\"\n", poly_x, poly_y);
00173 }
00174 fclose( resid_tab_the_file);
00175 xsh_msg( "Save residual tab in RESID_TAB.dat");
00176 check( xsh_resid_tab_log( resid_tab, "RESID_TAB.dat"));
00177
00178 cleanup:
00179 xsh_instrument_free( &instrument);
00180 xsh_free_frame (&resid_tab_frame);
00181 xsh_resid_tab_free( &resid_tab);
00182
00183 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00184 xsh_error_dump(CPL_MSG_ERROR);
00185 ret = 1;
00186 }
00187 TEST_END();
00188 return ret ;
00189 }
00190