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
00044 #include <xsh_data_order.h>
00045 #include <xsh_error.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_data_instrument.h>
00048 #include <xsh_dfs.h>
00049 #include <xsh_pfits.h>
00050 #include <tests.h>
00051 #include <xsh_utils_table.h>
00052 #include <cpl.h>
00053 #include <math.h>
00054 #include <getopt.h>
00055
00056
00057
00058
00059 #define XSH_FLOAT_PRECISION 0.000001
00060 #define MODULE_ID "XSH_DATA_ORDER"
00061
00062 #define SYNTAX "Test the order table\n"\
00063 "usage : ./the_xsh_data_order [options] ORDER_TAB \n"\
00064 "ORDER_TAB => the order table\n"\
00065 "Options:\n"\
00066 " --binx=<n> : binning in X (default 1)\n"\
00067 " --biny=<n> : binning in Y (default 1)\n"\
00068 " --point=<str> : Point Type (cross, x, diamond, ...)\n"\
00069 " Default is 'cross'\n"\
00070 " --size=<n> : Point size (pixels). Default is default DS9 value\n"\
00071 " --step=<nn> : Step in pixels. Default '8'\n"
00072
00073
00074 static const char * Options = "?" ;
00075
00076 enum {
00077 POINT_OPT, SIZE_OPT, STEP_OPT, C_COLOR_OPT,BINX_OPT,BINY_OPT
00078 } ;
00079
00080 static struct option LongOptions[] = {
00081 {"point", required_argument, 0, POINT_OPT},
00082 {"size", required_argument, 0, SIZE_OPT},
00083 {"step", required_argument, 0, STEP_OPT},
00084 {"c-color", required_argument, 0, C_COLOR_OPT},
00085 {"binx", required_argument, 0, BINX_OPT},
00086 {"biny", required_argument, 0, BINY_OPT},
00087 {NULL, 0, 0, 0}
00088 } ;
00089
00090 static char PointType[16] ;
00091 static char PointSize[8] ;
00092 static int PointStep = 8 ;
00093 static char CentralColor[32] ;
00094 int binx =1;
00095 int biny =1;
00096
00097
00098
00099
00100 static void HandleOptions( int argc, char ** argv )
00101 {
00102 int opt ;
00103 int option_index = 0;
00104
00105
00106 strcpy( PointType, "cross" ) ;
00107 strcpy( PointSize, "" ) ;
00108 strcpy( CentralColor, "green" ) ;
00109
00110 while( (opt = getopt_long( argc, argv, Options,
00111 LongOptions, &option_index )) != EOF )
00112 switch( opt ) {
00113 case POINT_OPT:
00114 strcpy( PointType, optarg ) ;
00115 break ;
00116 case SIZE_OPT:
00117 strcpy( PointSize, optarg ) ;
00118 break ;
00119 case STEP_OPT:
00120 sscanf( optarg, "%d", &PointStep ) ;
00121 break ;
00122 case C_COLOR_OPT:
00123 strcpy( CentralColor, optarg ) ;
00124 case BINX_OPT:
00125 binx = atoi(optarg);
00126 case BINY_OPT:
00127 biny = atoi(optarg);
00128 break ;
00129 default:
00130 printf( SYNTAX ) ;
00131 TEST_END();
00132 exit( 0 ) ;
00133 }
00134 }
00135
00136
00144
00145 int main(int argc, char** argv)
00146 {
00147 int ret = 0;
00148 xsh_instrument * instrument = NULL ;
00149 XSH_INSTRCONFIG* iconfig = NULL;
00150
00151 char* order_tab_name = NULL;
00152 cpl_frame* order_tab_frame = NULL;
00153 cpl_table* table = NULL;
00154 int nbcol;
00155 xsh_order_list* order_tab = NULL;
00156 int order_tab_size = 0;
00157 int iy, iorder;
00158 int ny;
00159 FILE* order_tab_file = NULL;
00160 cpl_propertylist *header = NULL;
00161 const char* pro_catg = NULL;
00162
00163
00164 TESTS_INIT(MODULE_ID);
00165 cpl_msg_set_level(CPL_MSG_DEBUG);
00166 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM) ;
00167
00168 HandleOptions( argc, argv );
00169
00170
00171 if ( optind < argc ) {
00172 order_tab_name = argv[optind] ;
00173 }
00174 else{
00175 printf(SYNTAX);
00176 TEST_END();
00177 return 0;
00178 }
00179
00180
00181 XSH_ASSURE_NOT_NULL( order_tab_name);
00182 order_tab_frame = cpl_frame_new();
00183 cpl_frame_set_filename( order_tab_frame, order_tab_name) ;
00184 cpl_frame_set_level( order_tab_frame, CPL_FRAME_LEVEL_TEMPORARY);
00185 cpl_frame_set_group( order_tab_frame, CPL_FRAME_GROUP_RAW );
00186
00187 XSH_TABLE_LOAD( table, order_tab_name);
00188 check( nbcol = cpl_table_get_nrow(table));
00189 instrument = xsh_instrument_new() ;
00190 xsh_instrument_set_arm( instrument, XSH_ARM_UVB);
00191
00192 XSH_ASSURE_NOT_NULL( instrument);
00193
00194 check (iconfig = xsh_instrument_get_config( instrument));
00195 iconfig->orders = nbcol;
00196
00197 ny = iconfig->ny;
00198 check( order_tab = xsh_order_list_load( order_tab_frame, instrument));
00199 order_tab_size = order_tab->size;
00200 xsh_order_list_set_bin_x( order_tab, binx);
00201 xsh_order_list_set_bin_y( order_tab, biny);
00202 check ( header = cpl_propertylist_load( order_tab_name, 0));
00203 check( pro_catg = xsh_pfits_get_pcatg( header));
00204
00205 xsh_msg( "Order Table of type %s bin %dx%d",pro_catg, binx, biny);
00206
00207 xsh_msg("Save order tab in ORDER_TAB.reg");
00208 order_tab_file = fopen( "ORDER_TAB.reg", "w");
00209 fprintf( order_tab_file, "# Region file format: DS9 version 4.0\n"\
00210 "global color=red font=\"helvetica 10 normal\""\
00211 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
00212 "source\nimage\n");
00213 fprintf( order_tab_file,
00214 "# GREEN center_x center_y (pixels)\n"\
00215 "# RED low_x low_y (pixels)\n"\
00216 "# BLUE up_x up_y (pixels)\n");
00217
00218 xsh_msg("Using step %d", PointStep);
00219 for( iorder=0; iorder< order_tab_size; iorder++){
00220 int starty, endy, absorder;
00221
00222 check( starty = xsh_order_list_get_starty( order_tab, iorder));
00223 check( endy = xsh_order_list_get_endy( order_tab, iorder));
00224
00225 absorder = order_tab->list[iorder].absorder;
00226 xsh_msg(" Dump order %d (%d => %d)", absorder, starty, endy);
00227 if (starty == 0 && endy == 0){
00228 xsh_msg("Warning starty and endy equal zero, put endy to %d",ny);
00229 starty =1;
00230 endy = ny;
00231 }
00232 for( iy=starty; iy<=endy; iy= iy+PointStep){
00233 float dx;
00234
00235 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].cenpoly,
00236 iy));
00237
00238 if (iy==starty){
00239 fprintf( order_tab_file, "point(%f,%d) #point=%s %s color=%s font="\
00240 "\"helvetica 10 normal\" text={absorder %d}\n", dx, iy, PointType,
00241 PointSize, CentralColor, absorder);
00242 } else if (iy==endy){
00243 fprintf( order_tab_file, "point(%f,%d) #point=%s %s color=%s font="\
00244 "\"helvetica 10 normal\" text={absorder %d}\n", dx, iy, PointType,
00245 PointSize, CentralColor, absorder);
00246 }
00247 else{
00248 fprintf( order_tab_file, "point(%f,%d) #point=%s %s color=%s font="\
00249 "\"helvetica 10 normal\"\n", dx, iy, PointType, PointSize,
00250 CentralColor);
00251 }
00252 if ( XSH_CMP_TAG_LAMP( pro_catg, XSH_ORDER_TAB_EDGES)|| XSH_CMP_TAG_MODE( pro_catg, XSH_ORDER_TAB_AFC)){
00253 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].edglopoly,
00254 iy));
00255
00256 fprintf( order_tab_file, "point(%f,%d) #point=cross color=red font="\
00257 "\"helvetica 10 normal\"\n", dx, iy);
00258 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].edguppoly,
00259 iy));
00260 fprintf( order_tab_file, "point(%f,%d) #point=cross color=blue font="\
00261 "\"helvetica 10 normal\"\n", dx, iy);
00262
00263 if ( order_tab->list[iorder].slicuppoly != NULL ) {
00264 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].slicuppoly,
00265 iy));
00266 fprintf( order_tab_file,
00267 "point(%f,%d) #point=diamond color=blue font=" \
00268 "\"helvetica 10 normal\"\n", dx, iy);
00269 }
00270 if ( order_tab->list[iorder].sliclopoly != NULL ) {
00271 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].sliclopoly,
00272 iy));
00273 fprintf( order_tab_file,
00274 "point(%f,%d) #point=diamond color=red font=" \
00275 "\"helvetica 10 normal\"\n", dx, iy);
00276 }
00277 }
00278
00279 if ( (iy+PointStep > endy) && (iy != endy)){
00280 iy=endy-PointStep;
00281 }
00282 }
00283 }
00284 fclose( order_tab_file);
00285
00286 cleanup:
00287 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00288 xsh_error_dump(CPL_MSG_ERROR);
00289 ret = 1;
00290 }
00291 xsh_free_frame( &order_tab_frame);
00292 xsh_instrument_free( &instrument);
00293 xsh_free_propertylist( &header);
00294 xsh_order_list_free( &order_tab);
00295 XSH_TABLE_FREE( table);
00296 TEST_END();
00297 return ret ;
00298 }
00299