55#define MODULE_ID "XSH_CPL_VECTOR_CORREL_GAUSSIANS"
62 {
"debug", required_argument, 0,
DEBUG_OPT},
69 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");
70 puts(
"Usage : ./tetst_xsh_correl_gaussians [options]");
73 puts(
" --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
74 puts(
" --help : What you see" ) ;
76 puts(
"The input files argument MUST be in this order:" );
77 puts(
" 1. PRE frame");
78 puts(
" 2. SOF a) MODEL : [XSH_MOD_CFG_TAB_UVB]");
79 puts(
" b) POLYNOMIAL: [DISP_TAB, ORDER_TAB_EDGES]");
91 while( (opt = getopt_long( argc, argv,
"debug:help",
95 if ( strcmp( optarg,
"LOW")==0){
98 else if ( strcmp( optarg,
"HIGH")==0){
118 double norm=
sigma*sqrt(2*CPL_MATH_PI);
121 for(i=0;i<
size;i++) {
123 data[i]=a*exp(-(
x-center)*(
x-center)*inv_2_c2);
126 return cpl_error_get_code();
142int main(
int argc,
char** argv)
147 cpl_msg_set_level( CPL_MSG_DEBUG);
153 if ( (argc-optind) >= 2) {
161 double gauss_c=0.5*
size;
163 double* gauss_d1=NULL;
164 double* gauss_d2=NULL;
167 cpl_vector* gauss_v1=cpl_vector_new(
size);
168 cpl_vector* gauss_v2=cpl_vector_new(
size);
170 gauss_d1=cpl_vector_get_data(gauss_v1);
171 gauss_d2=cpl_vector_get_data(gauss_v2);
178 int len_corr=2*
size-1;
183 cpl_vector* correl=cpl_vector_new(len_corr);
184 check(cpl_vector_fill(correl, 0.0));
185 double shift=cpl_vector_correlate(correl,gauss_v1,gauss_v2);
187 cpl_vector_save(correl,
"correl.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
194 pvec=cpl_vector_get_data(correl);
197 for(i=1;i<len_corr;i++) {
203 xsh_msg(
"maxpos my determination: %d",maxpos);
210 a=cpl_vector_get(correl,maxpos-1);
211 b=cpl_vector_get(correl,maxpos+1);
212 c=cpl_vector_get(correl,maxpos);
213 fraction=(a-b)/(2.*a+2.*b-4.*c);
214 xsh_msg(
"len_corr=%d",len_corr);
215 xsh_msg(
"a=%g b=%g c=%g fraction=%g",a,b,c,fraction);
217 xsh_msg(
"fraction shift - (size-1)=%g",shift -(
size-1)+fraction);
226 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
cpl_error_code xsh_gauss_gen(double *data, const double center, const double sigma, const int size)
static struct option LongOptions[]
#define xsh_error_dump(level)
#define xsh_msg(...)
Print a message on info level.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
static void HandleOptions(int argc, char **argv)
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
#define TESTS_INIT_WORKSPACE(DRL_ID)
#define TESTS_INIT(DRL_ID)