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
00037
00040
00041
00042
00043
00044
00045 #include <xsh_data_order.h>
00046 #include <xsh_data_dispersol.h>
00047 #include <xsh_data_pre.h>
00048 #include <xsh_error.h>
00049 #include <xsh_msg.h>
00050 #include <xsh_data_instrument.h>
00051 #include <xsh_dfs.h>
00052 #include <xsh_pfits.h>
00053 #include <tests.h>
00054 #include <xsh_utils_table.h>
00055 #include <cpl.h>
00056 #include <math.h>
00057
00058
00059
00060
00061 #define MODULE_ID "XSH_WAVECAL_FWHM"
00062
00063 #define SYNTAX "Add evaluation of wavelength ans slit by dispersion solution to file fwhm.dat produce by wavecal\n"\
00064 "usage : ./the_xsh_wavecal_fwhm DATA_FILE DISP_TAB\n"\
00065 "DATA_FILE => File fwhm.dat produce by wavecal\n"\
00066 "DISP_TAB => dispersion solution to apply\n"
00067
00068
00069
00070
00071
00072
00079
00080 int main( int argc, char** argv)
00081 {
00082 int ret = 0;
00083 xsh_instrument * instrument = NULL ;
00084 XSH_ARM arm;
00085 const char *fwhm_name = NULL;
00086 const char* disp_tab_name = NULL;
00087 cpl_frame *disp_tab_frame = NULL;
00088 cpl_propertylist *header = NULL;
00089 xsh_dispersol_list *displist = NULL;
00090 FILE *fwhm_file = NULL;
00091 FILE *res_file = NULL;
00092 cpl_vector *pos = NULL;
00093
00094
00095 TESTS_INIT( MODULE_ID);
00096 cpl_msg_set_level( CPL_MSG_DEBUG);
00097 xsh_debug_level_set( XSH_DEBUG_LEVEL_MEDIUM) ;
00098
00099
00100 if ( argc > 2) {
00101 fwhm_name = argv[1];
00102 disp_tab_name = argv[2];
00103 }
00104 else{
00105 printf(SYNTAX);
00106 TEST_END();
00107 return 0;
00108 }
00109 xsh_msg( "Fwhm data file: %s", fwhm_name);
00110 xsh_msg( "Disp tab file: %s", disp_tab_name);
00111
00112
00113 check( header = cpl_propertylist_load( disp_tab_name, 0));
00114 instrument = xsh_instrument_new();
00115 check( arm = xsh_pfits_get_arm( header));
00116 xsh_instrument_set_arm( instrument, arm);
00117
00118 disp_tab_frame = cpl_frame_new();
00119 cpl_frame_set_filename( disp_tab_frame, disp_tab_name) ;
00120 cpl_frame_set_level( disp_tab_frame, CPL_FRAME_LEVEL_TEMPORARY);
00121 cpl_frame_set_group( disp_tab_frame, CPL_FRAME_GROUP_RAW);
00122
00123 check( displist = xsh_dispersol_list_load( disp_tab_frame, instrument));
00124 check( pos = cpl_vector_new(2));
00125
00126
00127 fwhm_file = fopen( fwhm_name, "r");
00128 res_file = fopen( "fwhm_full.dat", "w+");
00129
00130 if ( fwhm_file != NULL && res_file!=NULL){
00131 char line[200];
00132 char *read;
00133
00134 read = fgets( line, 200, fwhm_file);
00135 fputs( "# wavelength order xcen xcen-x0 ygauss ytilt fwhm area good lambdaG slitG lambdaT slitT\n", res_file);
00136 while ( fgets( line, 200, fwhm_file)){
00137 double wavelength, xcen, xcen_x0, ygauss, ytilt, fwhm, area;
00138 int order, good;
00139 double lambdaG, slitG, lambdaT, slitT;
00140 int iorder=0;
00141
00142 sscanf( line, "%lf %d %lf %lf %lf %lf %lf %lf %d\n",
00143 &wavelength, &order, &xcen, &xcen_x0, &ygauss, &ytilt, &fwhm, &area, &good);
00144
00145 while( order != displist->list[iorder].absorder){
00146 iorder++;
00147 }
00148
00149 cpl_vector_set( pos, 0, xcen);
00150 cpl_vector_set( pos, 1, ygauss);
00151 check( lambdaG = xsh_dispersol_list_eval( displist,
00152 displist->list[iorder].lambda_poly, pos));
00153 check( slitG = xsh_dispersol_list_eval( displist,
00154 displist->list[iorder].slit_poly, pos));
00155
00156 cpl_vector_set( pos, 0, xcen);
00157 cpl_vector_set( pos, 1, ytilt);
00158 check( lambdaT = xsh_dispersol_list_eval( displist,
00159 displist->list[iorder].lambda_poly, pos));
00160 check( slitT = xsh_dispersol_list_eval( displist,
00161 displist->list[iorder].slit_poly, pos));
00162 fprintf( res_file, "%f %d %f %f %f %f %f %f %d %f %f %f %f\n",
00163 wavelength, order, xcen, xcen_x0, ygauss, ytilt, fwhm, area,
00164 good, lambdaG, slitG, lambdaT, slitT);
00165 }
00166 }
00167
00168
00169 cleanup:
00170 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00171 xsh_error_dump(CPL_MSG_ERROR);
00172 ret = 1;
00173 }
00174 if ( fwhm_file != NULL && res_file!=NULL){
00175 fclose( fwhm_file);
00176 fclose( res_file);
00177 }
00178 xsh_dispersol_list_free( &displist);
00179 xsh_instrument_free( &instrument);
00180 xsh_free_frame( &disp_tab_frame);
00181 TEST_END();
00182 return ret ;
00183 }
00184