123 #include <uves_utils_cpl.h>
124 #include <uves_utils.h>
125 #include <uves_utils_wrappers.h>
126 #include <uves_error.h>
128 #include <cpl_test.h>
151 static cpl_error_code
154 cpl_image *image = NULL;
155 cpl_image *noise = NULL;
161 int norm[2] = {1, 1000};
162 int background[3] = {-3, 2, 900};
163 int sigma_x[2] = {2, 15};
164 int sigma_y[2] = {6, 10};
166 int n_norm =
sizeof(norm) /
sizeof(
int);
167 int n_back =
sizeof(background) /
sizeof(
int);
168 int n_sx =
sizeof(sigma_x) /
sizeof(
int);
169 int n_sy =
sizeof(sigma_y) /
sizeof(
int);
170 int i_norm, i_back, i_sx, i_sy;
173 double tolerance_xy = 1;
174 double tolerance_z = 1;
178 for (i_norm = 0; i_norm < n_norm; i_norm++)
179 for (i_back = 0; i_back < n_back; i_back++)
180 for (i_sx = 0; i_sx < n_sx ; i_sx++)
181 for (i_sy = 0; i_sy < n_sy ; i_sy++)
183 cpl_image *noisep[2] = {NULL, NULL};
184 int n_noise =
sizeof(noisep) /
sizeof(cpl_image *);
188 uves_free_image(&image);
189 uves_free_image(&noise);
190 image = cpl_image_new(sizex, sizey, CPL_TYPE_DOUBLE);
191 noise = cpl_image_new(sizex, sizey, CPL_TYPE_DOUBLE);
195 check(( cpl_image_fill_gaussian(image,
198 sigma_x[i_sx], sigma_y[i_sy]),
199 cpl_image_add_scalar(image, background[i_back])),
200 "Error creating test image");
207 check(( cpl_image_fill_gaussian(noise,
210 sigma_x[i_sx], sigma_y[i_sy]),
211 cpl_image_power(noise, 0.5),
212 cpl_image_add_scalar(noise, .0001)),
213 "Error creating noise image");
218 for (i_noise = 0; i_noise < n_noise; i_noise++)
220 double x0, y_0, sx, sy;
225 "Sigma = (%.2f, %.2f) Norm = %.2f Bkg = %.2f",
226 (
double) center_x, (
double) center_y,
227 (
double) sigma_x[i_sx], (
double) sigma_y[i_sy],
228 (
double) norm[i_norm], (
double) background[i_back]);
236 "2d fitting routine failed");
239 norm_fit = height * 2 * M_PI * sx * sy;
242 "Sigma = (%.2f, %.2f) Norm = %.2f Height = %.2e",
247 assure( fabs(center_x - x0) < tolerance_xy,
248 CPL_ERROR_ILLEGAL_OUTPUT,
249 "x-center deviates more than %f pixel(s)",
251 assure( fabs(center_y - y_0) < tolerance_xy,
252 CPL_ERROR_ILLEGAL_OUTPUT,
253 "y-center deviates more than %f pixel(s)",
255 assure( fabs(sigma_x[i_sx] - sx) < tolerance_xy,
256 CPL_ERROR_ILLEGAL_OUTPUT,
257 "sigma_x deviates more than %f pixel(s)",
259 assure( fabs(sigma_y[i_sy] - sy) < tolerance_xy,
260 CPL_ERROR_ILLEGAL_OUTPUT,
261 "sigma_y deviates more than %f pixel(s)",
267 assure( fabs(norm[i_norm] - norm_fit) < tolerance_z,
268 CPL_ERROR_ILLEGAL_OUTPUT,
269 "Norm deviates more than %f", tolerance_z);
274 uves_free_image(&image);
275 uves_free_image(&noise);
277 return cpl_error_get_code();
283 #define QFITS_MEMORY_MAXPTRS 200003
284 #define PTR_HASH(ptr) (((unsigned long int) ptr) % QFITS_MEMORY_MAXPTRS)
293 for (i = LOOP; i >=0; i--) p = cpl_realloc(p, 16);
298 realloc_system(
void *p)
302 for (j = 0; j < 5000; j++)
303 for (i = LOOP; i >=0; i--) p = realloc(p, 16);
319 99440, 99820, 99820, 99820, 99820,
320 99820, 99820, 99820, 99820, 99800,
321 99820, 99820, 99820, 99820, 99820,
322 99820, 99820, 99820, 99820, 99800,
323 99820, 99820, 99820, 99820, 99820,
324 99820, 99820, 99820, 99820, 99800,
325 99820, 99820, 99820, 99820, 99800,
326 99820, 99820, 99820, 99820, 99800,
327 99820, 99820, 99820, 99820, 99800,
328 99820, 99820, 99820, 99820, 99800,
331 for (j = 0; j <
sizeof(size)/
sizeof(
int); j++)
333 for (i = 0; i < N; i++)
342 void *p1 = cpl_malloc(16);
343 void *p2 = malloc(16);
348 const char *p = NULL;
353 int M =
sizeof(size)/
sizeof(
int);
356 for (j = 0; j < M; j++)
358 unsigned long alloc = 0;
360 for (i = 0; i < N; i++)
365 fprintf(stderr,
"%x, %d, %d alloc=%d\n", p, p, PTR_HASH(p), alloc);
368 fprintf(stderr,
"-----------------------%d\n", j);
370 for (i = 0; i < 2; i++)
372 p = cpl_malloc(size[j]);
374 fprintf(stderr,
"%d %x, %d, %d alloc=%d\n", size, p, p, PTR_HASH(p), alloc);
376 fprintf(stderr,
"-----------------------\n");
396 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
398 check( uves_check_version(),
399 "Dependency libraries version check failed");
404 "Test of gaussian fitting failed");
407 return cpl_test_end(0);