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_drl.h>
00050 #include <xsh_pfits.h>
00051 #include <xsh_badpixelmap.h>
00052 #include <cpl.h>
00053 #include <math.h>
00054 #include <getopt.h>
00055
00056
00057
00058
00059
00060 #define MODULE_ID "XSH_DIVIDE_FLAT"
00061
00062
00063 enum {
00064 DEBUG_OPT, HELP_OPT
00065 };
00066
00067 static struct option long_options[] = {
00068 {"debug", required_argument, 0, DEBUG_OPT},
00069 {"help", 0, 0, HELP_OPT},
00070 {0, 0, 0, 0}
00071 };
00072
00073
00074 static void Help( void )
00075 {
00076 puts( "Unitary test of xsh_divide_flat");
00077 puts( "Usage: test_xsh_divide_flat [options] <input_files>");
00078
00079 puts( "Options" ) ;
00080 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
00081 puts( " --help : What you see" ) ;
00082 puts( "\nInput Files" ) ;
00083 puts( "The input files argument MUST be in this order:" ) ;
00084 puts( " 1. Science frame in PRE format" ) ;
00085 puts( " 2. SOF [MASTER_FLAT]");
00086 TEST_END();
00087 exit(0);
00088 }
00089
00090 static void HandleOptions( int argc, char **argv)
00091 {
00092 int opt ;
00093 int option_index = 0;
00094 while (( opt = getopt_long (argc, argv, "debug:help",
00095 long_options, &option_index)) != EOF ){
00096
00097 switch ( opt ) {
00098 case DEBUG_OPT:
00099 if ( strcmp( optarg, "LOW")==0){
00100 xsh_debug_level_set( XSH_DEBUG_LEVEL_LOW);
00101 }
00102 else if ( strcmp( optarg, "HIGH")==0){
00103 xsh_debug_level_set( XSH_DEBUG_LEVEL_HIGH);
00104 }
00105 break;
00106 case HELP_OPT:
00107 Help();
00108 break;
00109 default:
00110 break;
00111 }
00112 }
00113 return;
00114 }
00115
00116
00117
00118
00126 int main( int argc, char **argv)
00127 {
00128
00129 int ret = 0 ;
00130 xsh_instrument* instrument = NULL;
00131 cpl_frame* result = NULL;
00132 char *sci_name = NULL;
00133 char *sof_name = NULL;
00134 cpl_frame *sci_frame = NULL;
00135 cpl_frame *flat_frame = NULL;
00136 cpl_frameset *set = NULL;
00137
00138
00139 TESTS_INIT(MODULE_ID);
00140
00141 cpl_msg_set_level(CPL_MSG_DEBUG);
00142 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM);
00143
00144
00145 HandleOptions( argc, argv);
00146
00147 if ( (argc-optind) >= 2 ) {
00148 sci_name = argv[optind];
00149 sof_name = argv[optind+1];
00150
00151
00152 check( set = sof_to_frameset( sof_name));
00153
00154
00155 check( instrument = xsh_dfs_set_groups( set));
00156 check( flat_frame = xsh_find_master_flat( set, instrument));
00157 TESTS_XSH_FRAME_CREATE( sci_frame, "OBJECT_SLIT_STARE_arm",
00158 sci_name);
00159 }
00160 else{
00161 Help();
00162 }
00163
00164
00165 xsh_msg("PRE : %s", cpl_frame_get_filename( sci_frame));
00166 xsh_msg("MASTER_FLAT : %s", cpl_frame_get_filename( flat_frame));
00167
00168 xsh_instrument_set_recipe_id( instrument, "xsh_mdark");
00169
00170 check( result = xsh_divide_flat( sci_frame, flat_frame, "DIVIDE_FLAT",
00171 instrument));
00172 xsh_msg("Save DIVIDE_FLAT.fits frame");
00173
00174 cleanup:
00175 xsh_free_frame( &sci_frame);
00176 xsh_free_frameset( &set);
00177 xsh_free_frame( &result);
00178 xsh_instrument_free( &instrument);
00179
00180 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00181 xsh_error_dump(CPL_MSG_ERROR);
00182 ret = 1;
00183 }
00184 TEST_END();
00185 return ret;
00186 }
00187