X-shooter Pipeline Reference Manual 3.8.15
test-xsh_atrous.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2012-04-27 17:35:03 $
23 * $Revision: 1.3 $
24 */
25
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*-------------------------------------------------------------------------*/
36/*-------------------------------------------------------------------------*/
39/*--------------------------------------------------------------------------
40 Includes
41 --------------------------------------------------------------------------*/
42
43#include <tests.h>
44
45#include <xsh_data_pre.h>
46#include <xsh_error.h>
47#include <xsh_msg.h>
48#include <xsh_data_instrument.h>
49#include <xsh_data_spectrum.h>
51#include <xsh_drl.h>
52#include <xsh_pfits.h>
53#include <xsh_parameters.h>
54#include <xsh_badpixelmap.h>
55#include <xsh_utils_ifu.h>
56#include <cpl.h>
57#include <math.h>
58
59#include <string.h>
60#include <getopt.h>
61
62/*--------------------------------------------------------------------------
63 Defines
64 --------------------------------------------------------------------------*/
65
66#define MODULE_ID "XSH_ATROUS"
67
68enum {
70} ;
71
72static struct option long_options[] = {
73 {"nscales", required_argument, 0, NSCALES_OPT},
74 {"help", 0, 0, HELP_OPT},
75 {0, 0, 0, 0}
76};
77
78static void Help( void )
79{
80 puts( "Unitary test of xsh_atrous");
81 puts( "Usage: test_xsh_atrous [options] DATA_FILE");
82
83 puts( "Options" ) ;
84 puts( " --help : What you see" ) ;
85 puts( " --nscales= : Number os scales");
86 puts( "\nInput Files" ) ;
87 puts( "DATA_FILE :ASCII x,y file y column is use for decomposition");
88 TEST_END();
89}
90
91
92static void HandleOptions( int argc, char **argv,
93 int *nscales)
94{
95 int opt ;
96 int option_index = 0;
97
98 while (( opt = getopt_long (argc, argv,
99 "nscales",
100 long_options, &option_index)) != EOF ){
101
102 switch ( opt ) {
103 case NSCALES_OPT:
104 *nscales = atoi(optarg);
105 break ;
106 default:
107 Help(); exit(-1);
108 }
109 }
110 return;
111}
112
113
114int main( int argc, char **argv)
115{
116 /* Declarations */
117 int ret = 0 ;
118 int nscales = 5;
119 const char *file_name = NULL;
120 FILE* file = NULL;
121 cpl_vector *data_vect = NULL;
122 char line[200];
123 double xpos[10000];
124 double ypos[10000];
125 int i, k, size=0;
126 int max = 10000;
127 cpl_matrix *result = NULL;
128 char res_name[256];
129
130 /* Initialize libraries */
132
133 cpl_msg_set_level(CPL_MSG_DEBUG);
135
136 /* Analyse parameters */
137 HandleOptions( argc, argv, &nscales);
138
139 if ( (argc - optind) > 0 ) {
140 file_name = argv[optind];
141 }
142 else {
143 Help();
144 exit( 0);
145 }
146
147 xsh_msg("---Input Files");
148 xsh_msg("File : %s ", file_name);
149 xsh_msg("---Options");
150 xsh_msg("NSCALES : %d ", nscales);
151
152 /* READ data */
153 file = fopen( file_name, "r");
154 if (file != NULL){
155 size=0;
156 while ( size < max && fgets( line, 200, file)){
157 char col1[20];
158 char col2[20];
159
160 if ( line[0] != '#'){
161 /* Note: update the string format (the %__s) if col1(2) changes size.
162 * Remember: field width must equal 1 less than sizeof(col1(2)). */
163 sscanf(line,"%19s %19s", col1, col2);
164 xpos[size] = atof(col1);
165 ypos[size] = atof(col2);
166 size++;
167 }
168 }
169 }
170 if (file != NULL){
171 fclose(file);
172 }
173
174 check( data_vect = cpl_vector_wrap( size, ypos));
175
176 check ( result = xsh_atrous( data_vect, nscales));
177
178 sprintf( res_name, "%s_ATROUS.dat", file_name);
179
180 file = fopen( res_name, "w+");
181 fprintf( file, "#x y");
182 for(k=0; k< nscales+1; k++){
183 fprintf( file, " n%d", k);
184 }
185 fprintf( file, "\n");
186
187 for( i=0; i< size; i++){
188 fprintf( file, "%f %f", xpos[i], ypos[i]);
189 for(k=0; k< nscales+1; k++){
190 double val;
191
192 val = cpl_matrix_get( result, k, i);
193 fprintf( file, " %f", val);
194 }
195 fprintf( file, "\n");
196 }
197
198 fclose(file);
199
200
201 cleanup:
202 if (cpl_error_get_code() != CPL_ERROR_NONE) {
203 xsh_error_dump(CPL_MSG_ERROR);
204 ret=1;
205 }
206 xsh_free_matrix( &result);
207 xsh_unwrap_vector( &data_vect);
208 TEST_END();
209 return ret ;
210}
211
int main()
Unit test of xsh_bspline_interpol.
static void Help(void)
static void HandleOptions(int argc, char **argv, int *nscales)
#define MODULE_ID
static struct option long_options[]
@ HELP_OPT
@ NSCALES_OPT
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
int size
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
Definition: xsh_utils.c:2345
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
void xsh_free_matrix(cpl_matrix **m)
Deallocate a matrix and set the pointer to NULL.
Definition: xsh_utils.c:2209
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
#define max(a, b)
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138
cpl_matrix * xsh_atrous(cpl_vector *spec, int nscales)
Do a wavelet decomposition using atrous from IDL.