X-shooter Pipeline Reference Manual 3.8.15
test-xsh_xcorrel_gaussians.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: 2013-02-15 13:05:54 $
23 * $Revision: 1.4 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42
43
44#include <xsh_error.h>
45#include <xsh_msg.h>
46#include <xsh_dfs.h>
47#include <xsh_utils.h>
48#include <tests.h>
49#include <cpl.h>
50#include <math.h>
51#include <getopt.h>
52#include <string.h>
53
54/*---------------------------------------------------------------------------
55 Defines
56 ---------------------------------------------------------------------------*/
57#define MODULE_ID "XSH_XCORREL_GAUSSIANS"
58
59enum {
61};
62
63static struct option LongOptions[] = {
64 {"debug", required_argument, 0, DEBUG_OPT},
65 {"help", 0, 0, HELP_OPT},
66 {NULL, 0, 0, 0}
67};
68
69static void Help( void )
70{
71 puts ("Unitary test : Create two Gaussians one shifted to the other of a given quantity, then correlate them to check if correlation returns expected shift");
72 puts( "Usage : ./tetst_xsh_correl_gaussians [options]");
73
74 puts( "Options" ) ;
75 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
76 puts( " --help : What you see" ) ;
77
78 puts( "The input files argument MUST be in this order:" );
79 puts( " 1. PRE frame");
80 puts( " 2. SOF a) MODEL : [XSH_MOD_CFG_TAB_UVB]");
81 puts( " b) POLYNOMIAL: [DISP_TAB, ORDER_TAB_EDGES]");
82
84 TEST_END();
85 exit(0);
86}
87
88static void HandleOptions( int argc, char ** argv)
89{
90 int opt ;
91 int option_index = 0;
92
93 while( (opt = getopt_long( argc, argv, "debug:help",
94 LongOptions, &option_index )) != EOF){
95 switch( opt ) {
96 case DEBUG_OPT:
97 if ( strcmp( optarg, "LOW")==0){
99 }
100 else if ( strcmp( optarg, "HIGH")==0){
102 }
103 break;
104 case HELP_OPT:
105 Help();
106 break;
107 default:
108 break;
109 }
110 }
111}
112
113
114cpl_error_code
115xsh_gauss_gen(double* data,const double center,const double sigma, const int size)
116{
117
118 int i=0;
119 double x=0;
120 double inv_2_c2=0.5/sigma/sigma;
121 double norm=sigma*sqrt(2*CPL_MATH_PI);
122 double a=1./norm;
123
124 for(i=0;i<size;i++) {
125 x=i;
126 data[i]=a*exp(-(x-center)*(x-center)*inv_2_c2);
127 }
128
129 return cpl_error_get_code();
130}
131
132/*---------------------------------------------------------------------------
133 Functions prototypes
134 ---------------------------------------------------------------------------*/
135
136/*--------------------------------------------------------------------------*/
143/*--------------------------------------------------------------------------*/
144
145int main( int argc, char** argv)
146{
147 /* Initialize libraries */
150 cpl_msg_set_level( CPL_MSG_DEBUG);
152
153 HandleOptions( argc, argv);
154
155 /* Analyse parameters */
156 if ( (argc-optind) >= 2) {
157 Help();
158 }
159
160 int ret=0;
161 int size=1000000;
162 double shift_i=5.15;
163 double shift_o=0;
164 double gauss_c=0.5*size;
165 double gauss_s=10.;
166 double* gauss_d1=NULL;
167 double* gauss_d2=NULL;
168
169 cpl_vector* gauss_v1=cpl_vector_new(size);
170 cpl_vector* gauss_v2=cpl_vector_new(size);
171
172 gauss_d1=cpl_vector_get_data(gauss_v1);
173 gauss_d2=cpl_vector_get_data(gauss_v2);
174
175 check(xsh_gauss_gen(gauss_d1,gauss_c,gauss_s,size));
176 check(xsh_gauss_gen(gauss_d2,gauss_c+shift_i,gauss_s,size));
177
178 int half_search=(int)(3*gauss_s+1);
179 //int len_corr=2*size-1;
180 //half_search=len_corr;
181 double* xcorr=NULL;
182
183 double corr=0;
184 xcorr=xsh_function1d_xcorrelate(gauss_d1,size,gauss_d2,size,half_search,1,&corr,&shift_o);
185 cpl_vector_save(gauss_v1,"gauss_v1.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
186 cpl_vector_save(gauss_v2,"gauss_v2.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
187 cpl_free(xcorr);
188
189 cleanup:
190 xsh_free_vector(&gauss_v1);
191 xsh_free_vector(&gauss_v2);
192
193
194 if (cpl_error_get_code() != CPL_ERROR_NONE) {
195 xsh_error_dump( CPL_MSG_ERROR);
196 ret=1;
197 }
199 TEST_END();
200 return ret;
201}
202
int main()
Unit test of xsh_bspline_interpol.
static double sigma
cpl_error_code xsh_gauss_gen(double *data, const double center, const double sigma, const int size)
#define MODULE_ID
static struct option LongOptions[]
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
int size
int * x
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
Definition: xsh_utils.c:2284
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
double * xsh_function1d_xcorrelate(double *line_i, int width_i, double *line_t, int width_t, int half_search, int normalise, double *xcorr_max, double *delta)
Definition: xsh_utils.c:7101
static void HandleOptions(int argc, char **argv)
static void Help(void)
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
Definition: tests.h:139
#define TESTS_INIT_WORKSPACE(DRL_ID)
Definition: tests.h:133
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_DEBUG_LEVEL_HIGH
Definition: xsh_utils.h:138
@ XSH_DEBUG_LEVEL_LOW
Definition: xsh_utils.h:137
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138