70#define MODULE_ID "XSH_GAUSSIAN_FIT"
83 puts(
"Unitary test of xsh_gaussian_fit");
84 puts(
"Usage: test_xsh_gaussian_fit [options] DATA_FILE");
87 puts(
" --help : What you see" ) ;
88 puts(
"\nInput Files" ) ;
89 puts(
"DATA_FILE :ASCII x,y file y column is use for decomposition");
99 while (( opt = getopt_long (argc, argv,
112int main(
int argc,
char **argv)
116 const char *file_name = NULL;
126 double cpl_area=0, cpl_sigma=0, cpl_x0=0, cpl_offset=0;
129 cpl_vector *pos_vect = NULL;
130 cpl_vector *data_vect = NULL;
139 cpl_msg_set_level(CPL_MSG_DEBUG);
145 if ( (argc - optind) > 0 ) {
146 file_name = argv[optind];
154 xsh_msg(
"File : %s ", file_name);
157 file = fopen( file_name,
"r");
160 while (
size <
max && fgets( line, 200, file)){
164 if ( line[0] !=
'#'){
167 sscanf(line,
"%19s %19s", col1, col2);
168 xpos[
size] = atof(col1);
169 ypos[
size] = atof(col2);
178 check( pos_vect = cpl_vector_wrap(
size, xpos));
179 check( data_vect = cpl_vector_wrap(
size, ypos));
181 cpl_vector_fit_gaussian( pos_vect, NULL, data_vect,
182 NULL,CPL_FIT_ALL,&cpl_x0,&cpl_sigma,&cpl_area,&cpl_offset,NULL,NULL,NULL);
184 printf(
"CPL FIT area %f x0 %f sigma %f offset %f\n", cpl_area, cpl_x0, cpl_sigma, cpl_offset);
190 printf (
"area = %.5f +/- %.5f\n", init_par[0], errs_par[0]);
191 printf (
"a = %.5f +/- %.5f\n", init_par[1], errs_par[1]);
192 printf (
"b = %.5f +/- %.5f\n", init_par[2], errs_par[2]);
193 printf (
"c = %.5f +/- %.5f\n", init_par[3], errs_par[3]);
194 printf (
"x0 = %.5f +/- %.5f\n", init_par[4], errs_par[4]);
195 printf (
"sigma = %.5f +/- %.5f\n", init_par[5], errs_par[5]);
197 sprintf( res_name,
"GSL_FIT_%s.dat", file_name);
199 file = fopen( res_name,
"w+");
200 fprintf( file,
"#x y\n");
202 for( i=0; i<
size; i++){
203 double step = xpos[1]-xpos[0];
207 double t = xpos[i]+j;
209 double area = init_par[0];
210 double a = init_par[1];
211 double b = init_par[2];
212 double c = init_par[3];
213 double x0 = init_par[4];
214 double sigma =init_par[5];
219 double Yi = height*exp(-W)+a+b*t+c*t*t;
222 fprintf( file,
"%f %f\n", t, Yi);
227 sprintf( res_name,
"CPL_FIT_%s.dat", file_name);
229 file = fopen( res_name,
"w+");
230 fprintf( file,
"#x y\n");
232 for( i=0; i<
size; i++){
233 double step = xpos[1]-xpos[0];
237 double t = xpos[i]+j;
239 double area = cpl_area;
240 double a = cpl_offset;
244 double sigma = cpl_sigma;
249 double Yi = height*exp(-W)+a+b*t+c*t*t;
252 fprintf( file,
"%f %f\n", t, Yi);
261 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int main()
Unit test of xsh_bspline_interpol.
static void HandleOptions(int argc, char **argv)
static struct option long_options[]
#define xsh_error_dump(level)
#define xsh_msg(...)
Print a message on info level.
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
int xsh_debug_level_set(int level)
set debug level
void xsh_gsl_init_gaussian_fit(cpl_vector *xpos_vect, cpl_vector *ypos_vect, double *init_par)
void xsh_gsl_fit_gaussian(cpl_vector *xpos_vect, cpl_vector *ypos_vect, int deg, double *params, double *errs, int *status)
#define TESTS_INIT(DRL_ID)