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_spectrum.h>
00050 #include <xsh_data_localization.h>
00051 #include <xsh_drl.h>
00052 #include <xsh_pfits.h>
00053 #include <xsh_parameters.h>
00054 #include <xsh_badpixelmap.h>
00055 #include <xsh_utils_ifu.h>
00056 #include <cpl.h>
00057 #include <math.h>
00058
00059 #include <string.h>
00060 #include <getopt.h>
00061
00062
00063
00064
00065
00066 #define MODULE_ID "XSH_ATROUS"
00067
00068 enum {
00069 NSCALES_OPT, HELP_OPT
00070 } ;
00071
00072 static struct option long_options[] = {
00073 {"nscales", required_argument, 0, NSCALES_OPT},
00074 {"help", 0, 0, HELP_OPT},
00075 {0, 0, 0, 0}
00076 };
00077
00078 static void Help( void )
00079 {
00080 puts( "Unitary test of xsh_atrous");
00081 puts( "Usage: test_xsh_atrous [options] DATA_FILE");
00082
00083 puts( "Options" ) ;
00084 puts( " --help : What you see" ) ;
00085 puts( " --nscales= : Number os scales");
00086 puts( "\nInput Files" ) ;
00087 puts( "DATA_FILE :ASCII x,y file y column is use for decomposition");
00088 TEST_END();
00089 }
00090
00091
00092 static void HandleOptions( int argc, char **argv,
00093 int *nscales)
00094 {
00095 int opt ;
00096 int option_index = 0;
00097
00098 while (( opt = getopt_long (argc, argv,
00099 "nscales",
00100 long_options, &option_index)) != EOF ){
00101
00102 switch ( opt ) {
00103 case NSCALES_OPT:
00104 *nscales = atoi(optarg);
00105 break ;
00106 default:
00107 Help(); exit(-1);
00108 }
00109 }
00110 return;
00111 }
00112
00113
00114 int main( int argc, char **argv)
00115 {
00116
00117 int ret = 0 ;
00118 int nscales = 5;
00119 const char *file_name = NULL;
00120 FILE* file = NULL;
00121 cpl_vector *data_vect = NULL;
00122 char line[200];
00123 double xpos[10000];
00124 double ypos[10000];
00125 int i, k, size=0;
00126 int max = 10000;
00127 cpl_matrix *result = NULL;
00128 char res_name[256];
00129
00130
00131 TESTS_INIT(MODULE_ID);
00132
00133 cpl_msg_set_level(CPL_MSG_DEBUG);
00134 xsh_debug_level_set(XSH_DEBUG_LEVEL_MEDIUM);
00135
00136
00137 HandleOptions( argc, argv, &nscales);
00138
00139 if ( (argc - optind) > 0 ) {
00140 file_name = argv[optind];
00141 }
00142 else {
00143 Help();
00144 exit( 0);
00145 }
00146
00147 xsh_msg("---Input Files");
00148 xsh_msg("File : %s ", file_name);
00149 xsh_msg("---Options");
00150 xsh_msg("NSCALES : %d ", nscales);
00151
00152
00153 file = fopen( file_name, "r");
00154 if (file != NULL){
00155 size=0;
00156 while ( size < max && fgets( line, 200, file)){
00157 char col1[20];
00158 char col2[20];
00159
00160 if ( line[0] != '#'){
00161 sscanf(line,"%s %s", col1, col2);
00162 xpos[size] = atof(col1);
00163 ypos[size] = atof(col2);
00164 size++;
00165 }
00166 }
00167 }
00168 if (file != NULL){
00169 fclose(file);
00170 }
00171
00172 check( data_vect = cpl_vector_wrap( size, ypos));
00173
00174 check ( result = xsh_atrous( data_vect, nscales));
00175
00176 sprintf( res_name, "%s_ATROUS.dat", file_name);
00177
00178 file = fopen( res_name, "w+");
00179 fprintf( file, "#x y");
00180 for(k=0; k< nscales+1; k++){
00181 fprintf( file, " n%d", k);
00182 }
00183 fprintf( file, "\n");
00184
00185 for( i=0; i< size; i++){
00186 fprintf( file, "%f %f", xpos[i], ypos[i]);
00187 for(k=0; k< nscales+1; k++){
00188 double val;
00189
00190 val = cpl_matrix_get( result, k, i);
00191 fprintf( file, " %f", val);
00192 }
00193 fprintf( file, "\n");
00194 }
00195
00196 fclose(file);
00197
00198
00199 cleanup:
00200 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00201 xsh_error_dump(CPL_MSG_ERROR);
00202 ret=1;
00203 }
00204 xsh_free_matrix( &result);
00205 xsh_unwrap_vector( &data_vect);
00206 TEST_END();
00207 return ret ;
00208 }
00209