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_the_map.h>
00050 #include <xsh_data_localization.h>
00051 #include <xsh_drl.h>
00052 #include <xsh_pfits.h>
00053
00054 #include <xsh_badpixelmap.h>
00055
00056 #include <cpl.h>
00057 #include <math.h>
00058
00059 #include <getopt.h>
00060
00061
00062
00063
00064
00065 #define MODULE_ID "XSH_THEMAP"
00066 #define SYNTAX "Test the theoretical map\n"\
00067 "use : ./the_xsh_themap THE_MAP PRE_FRAME\n"\
00068 "THE_MAP => the theoretical map table\n"
00069
00070
00071
00072
00073
00074
00082 int main( int argc, char **argv)
00083 {
00084
00085 int ret = 0 ;
00086 char* the_name = NULL;
00087 cpl_frame* the_frame = NULL;
00088 xsh_the_map* themap = NULL;
00089 int themap_size = 0;
00090 int i = 0;
00091 FILE* themap_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 the_name = argv[1];
00102 }
00103 else{
00104 printf(SYNTAX);
00105 TEST_END();
00106 return 0;
00107 }
00108
00109
00110 XSH_ASSURE_NOT_NULL( the_name);
00111 the_frame = cpl_frame_new();
00112 cpl_frame_set_filename( the_frame, the_name) ;
00113 cpl_frame_set_level( the_frame, CPL_FRAME_LEVEL_TEMPORARY);
00114 cpl_frame_set_group( the_frame, CPL_FRAME_GROUP_RAW ) ;
00115
00116 check( themap = xsh_the_map_load( the_frame));
00117 check(themap_size = xsh_the_map_get_size(themap));
00118
00119
00120 themap_file = fopen( "THEMAP.reg", "w");
00121 fprintf( themap_file, "# Region file format: DS9 version 4.0\n\
00122 global color=red font=\"helvetica 4 normal\"\
00123 select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source \nimage\n");
00124
00125 for( i=0; i<themap_size; i++){
00126 float lambdaTHE = 0.0;
00127 double xd, yd, order, slit;
00128
00129 check(lambdaTHE = xsh_the_map_get_wavelength(themap, i));
00130 check(xd = xsh_the_map_get_detx(themap, i));
00131 check(yd = xsh_the_map_get_dety(themap, i));
00132 check(order = (double)xsh_the_map_get_order(themap, i));
00133 check(slit = (double) xsh_the_map_get_slit_position( themap, i));
00134 if (slit == 0){
00135 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
00136 "font=\"helvetica 10 normal\" text={THE %.3f}\n", xd, yd, lambdaTHE);
00137 }
00138 else{
00139 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
00140 "font=\"helvetica 10 normal\" text={slit %f}\n", xd, yd, slit);
00141 }
00142 }
00143
00144
00145 cleanup:
00146 xsh_free_frame( &the_frame);
00147 xsh_the_map_free( &themap);
00148 if(themap_file != NULL) {
00149 fclose( themap_file);
00150 }
00151 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00152 xsh_error_dump(CPL_MSG_ERROR);
00153 ret = 1;
00154 }
00155 TEST_END();
00156 return ret ;
00157 }
00158