VISIR Pipeline Reference Manual  4.1.0
visir_utils-test.c
1 /* *
2  * This file is part of the ESO VISIR package *
3  * Copyright (C) 2004,2005 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 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23 
24 /*-----------------------------------------------------------------------------
25  Includes
26  -----------------------------------------------------------------------------*/
27 
28 #include <cpl.h>
29 
30 #include <visir_utils.h>
31 #include <string.h>
32 #include <stdlib.h>
33 
34 #include "visir_serialize.c"
35 
36 /*----------------------------------------------------------------------------*/
40 /*----------------------------------------------------------------------------*/
41 
42 #define CONCAT(a,b) a ## _ ## b
43 #define CONCAT2X(a,b) CONCAT(a,b)
44 
45 #define PIXEL_TYPE double
46 #define STDEV_TYPE CPL_TYPE_DOUBLE
47 #define PIXEL_TYPE_CPL CPL_TYPE_DOUBLE
48 static size_t prnok_nz = 0;
49 static double * prnok = NULL;
50 #include "../recipes/visir_util_clip_body.c"
51 #undef PIXEL_TYPE
52 #undef STDEV_TYPE
53 #undef PIXEL_TYPE_CPL
54 
55 /* column major */
56 #define IND(x,y,nx) ((x) + (y) * (nx))
57 
58 size_t visir_get_next_regular(size_t a);
59 
60 static void visir_serialize_test(void);
61 static void visir_macro_test(void);
62 static void visir_bound_test(void);
63 static void visir_get_kth_test(void);
64 static void visir_clip_kappa_sigma_test(void);
65 static void visir_fftxcorrelate_test(void);
66 static void visir_interpolate_rejected_test(void);
67 static void visir_num_threads_test(void);
68 static void visir_mean_fast_test(void);
69 static void visir_next_regular_test(void);
70 static void visir_test_parallel_median(void);
71 static void visir_test_linintp_values(void);
72 #include <cxlist.h>
73 #include <stdlib.h>
74 
75 /*----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------*/
80 
81 #define LEN(a) sizeof((a))/sizeof((a)[0])
82 
83 int main(void)
84 {
85 
86  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
87  visir_serialize_test();
88  visir_macro_test();
89  visir_bound_test();
90  visir_get_kth_test();
91  visir_clip_kappa_sigma_test();
92  visir_fftxcorrelate_test();
93  visir_interpolate_rejected_test();
94  visir_num_threads_test();
95  visir_mean_fast_test();
96  visir_next_regular_test();
97  visir_test_parallel_median();
98  visir_test_linintp_values();
99 
100  return cpl_test_end(0);
101 }
102 
103 
104 static void visir_num_threads_test(void)
105 {
106  FILE * stream;
107 
108  stream = cpl_msg_get_level() > CPL_MSG_INFO
109  ? fopen("/dev/null", "a") : stdout;
110 
111  {
112  const char * orig = getenv("OMP_NUM_THREADS");
113  unsetenv("OMP_NUM_THREADS");
114  cpl_test_lt(0, visir_get_num_threads(CPL_FALSE));
115  unsetenv("OMP_NUM_THREADS");
116  cpl_test_lt(0, visir_get_num_threads(CPL_FALSE));
117  setenv("OMP_NUM_THREADS", "1", 1);
118  cpl_test_eq(visir_get_num_threads(CPL_FALSE), 1);
119  setenv("OMP_NUM_THREADS", "3", 1);
120  cpl_test_eq(visir_get_num_threads(CPL_FALSE), 3);
121  setenv("OMP_NUM_THREADS", "-3", 1);
122  cpl_test_eq(visir_get_num_threads(CPL_FALSE), 1);
123  setenv("OMP_NUM_THREADS", "4ghdsg", 1);
124  cpl_test_eq(visir_get_num_threads(CPL_FALSE), 4);
125  setenv("OMP_NUM_THREADS", "ghdsg", 1);
126  cpl_test_eq(visir_get_num_threads(CPL_FALSE), 1);
127  setenv("OMP_NUM_THREADS", "490348563984693763894", 1);
128  cpl_test_lt(0, visir_get_num_threads(CPL_FALSE));
129  setenv("OMP_NUM_THREADS", "20000", 1);
130  cpl_test_lt(0, visir_get_num_threads(CPL_TRUE));
131  cpl_test_lt(visir_get_num_threads(CPL_TRUE), 20000);
132  if (orig)
133  setenv("OMP_NUM_THREADS", orig, 1);
134  else
135  unsetenv("OMP_NUM_THREADS");
136  }
137 
138  cpl_test_nonnull( stream );
139  if (stream != stdout) cpl_test_zero( fclose(stream) );
140 }
141 
142 static void visir_serialize_test(void)
143 {
144  FILE * stream;
145 
146  stream = cpl_msg_get_level() > CPL_MSG_INFO
147  ? fopen("/dev/null", "a") : stdout;
148 
149  {
150  char * block = cpl_malloc(5);
151  visir_stream * wstream = visir_stream_new(block, 5);
152  serialize_string(wstream, "12345");
153  serialize_uint32(wstream, 12345);
154  visir_stream * rstream =
155  visir_stream_new(wstream->base_buffer, 0);
156  cpl_free(wstream);
157  char * rs = deserialize_string(rstream);
158  int ri = deserialize_uint32(rstream);
159  cpl_test(strcmp(rs, "12345") == 0);
160  cpl_test_eq(ri, 12345);
161  cpl_free(rs);
162  cpl_free(rstream->base_buffer);
163  cpl_free(rstream);
164  }
165 
166  {
167  cpl_frameset * frames = cpl_frameset_new();
168  size_t size;
169  char * s = visir_frameset_serialize(frames, NULL);
170  cpl_test_eq_ptr(s, NULL);
171  cpl_test_error(CPL_ERROR_NULL_INPUT);
172 
173  s = visir_frameset_serialize(frames, &size);
174  cpl_frameset * d = visir_frameset_deserialize(s, NULL);
175  cpl_test_eq(cpl_frameset_get_size(frames), cpl_frameset_get_size(d));
176  cpl_frameset_delete(d);
177  cpl_free(s);
178 
179 
180  for (int i = 0; i < 17; i++) {
181  cpl_frame * frm = cpl_frame_new();
182  cpl_frame_set_tag(frm, "test");
183  cpl_frame_set_group(frm, CPL_FRAME_GROUP_PRODUCT);
184  cpl_frame_set_level(frm, CPL_FRAME_LEVEL_FINAL);
185  cpl_frame_set_type(frm, CPL_FRAME_TYPE_TABLE);
186  cpl_frame_set_filename(frm, "filename.fits");
187  cpl_frameset_insert(frames, frm);
188 
189  frm = cpl_frame_new();
190  cpl_frame_set_tag(frm, "tsdfasfijiotw3ty");
191  cpl_frame_set_group(frm, CPL_FRAME_GROUP_PRODUCT);
192  cpl_frame_set_level(frm, CPL_FRAME_LEVEL_INTERMEDIATE);
193  cpl_frame_set_type(frm, CPL_FRAME_TYPE_IMAGE);
194  cpl_frame_set_filename(frm, "folder/fiename.fits");
195  cpl_frameset_insert(frames, frm);
196 
197  frm = cpl_frame_new();
198  cpl_frame_set_tag(frm, "TSDFASFIJIOTW3TY");
199  cpl_frame_set_group(frm, CPL_FRAME_GROUP_RAW);
200  cpl_frame_set_level(frm, CPL_FRAME_LEVEL_TEMPORARY);
201  cpl_frame_set_type(frm, CPL_FRAME_TYPE_PAF);
202  cpl_frame_set_filename(frm, "/folder/fiename.fits");
203  cpl_frameset_insert(frames, frm);
204  }
205 
206  s = visir_frameset_serialize(frames, &size);
207  cpl_test_lt(0, size);
208  size_t size2;
209  d = visir_frameset_deserialize(s, &size2);
210  cpl_test_eq(cpl_frameset_get_size(frames), cpl_frameset_get_size(d));
211  cpl_test_eq(size, size2);
212 
213  for (cpl_size i = 0; i < cpl_frameset_get_size(d); i++) {
214  const cpl_frame * nfrm = cpl_frameset_get_position_const(d, i);
215  const cpl_frame * ofrm = cpl_frameset_get_position_const(frames, i);
216  cpl_test_eq(cpl_frame_get_group(ofrm), cpl_frame_get_group(nfrm));
217  cpl_test_eq(cpl_frame_get_level(ofrm), cpl_frame_get_level(nfrm));
218  cpl_test_eq(cpl_frame_get_type(ofrm), cpl_frame_get_type(nfrm));
219  cpl_test_zero(strcmp(cpl_frame_get_tag(ofrm),
220  cpl_frame_get_tag(nfrm)));
221  cpl_test_zero(strcmp(cpl_frame_get_filename(ofrm),
222  cpl_frame_get_filename(nfrm)));
223  }
224 
225  cpl_free(s);
226  cpl_frameset_delete(frames);
227  cpl_frameset_delete(d);
228  }
229 
230  cpl_test_nonnull( stream );
231 
232  if (stream != stdout) cpl_test_zero( fclose(stream) );
233 
234 }
235 
236 static void visir_macro_test(void)
237 {
238  FILE * stream;
239 
240  stream = cpl_msg_get_level() > CPL_MSG_INFO
241  ? fopen("/dev/null", "a") : stdout;
242 
243  {
244  double a[10];
245  size_t i = 0;
246 
247  cx_list * l = cx_list_new();
248  for (i = 0; i < LEN(a); i++)
249  cx_list_push_back(l, (void*)&a[i]);
250 
251  i = 0;
252  FOR_EACH(it, l)
253  cpl_test_eq_ptr(&a[i++], cx_list_get(l, it));
254 
255  cpl_test_eq(i, LEN(a));
256  cpl_test_eq((size_t)cx_list_size(l), LEN(a));
257 
258  i = 0;
259  FOR_EACH_T(void * p, l)
260  cpl_test_eq_ptr(&a[i++], p);
261 
262  cpl_test_eq(i, LEN(a));
263  cpl_test_eq((size_t)cx_list_size(l), LEN(a));
264 
265  cx_list_delete(l);
266  }
267 
268  cpl_test_nonnull( stream );
269 
270  if (stream != stdout) cpl_test_zero( fclose(stream) );
271 
272 }
273 
274 
275 static void visir_bound_test(void)
276 {
277  FILE * stream;
278 
279  stream = cpl_msg_get_level() > CPL_MSG_INFO
280  ? fopen("/dev/null", "a") : stdout;
281 
282  {
283  cpl_vector * v = cpl_vector_new(10);
284  cpl_vector_fill(v, 0.);
285  cpl_test_eq(visir_lower_bound(v, 0.), 0);
286  cpl_test_eq(visir_upper_bound(v, 0.), 10);
287  cpl_vector_delete(v);
288  }
289 {
290  double d[] = {1., 1., 2., 3., 3., 4., 5., 5.};
291  cpl_vector * v = cpl_vector_wrap(LEN(d), d);
292  cpl_test_eq(visir_lower_bound(v, 0.), 0);
293  cpl_test_eq(visir_lower_bound(v, 1.), 0);
294  cpl_test_eq(visir_lower_bound(v, 1.1), 2);
295  cpl_test_eq(visir_lower_bound(v, 2.), 2);
296  cpl_test_eq(visir_lower_bound(v, 2.1), 3);
297  cpl_test_eq(visir_lower_bound(v, 5.), LEN(d) - 2);
298  cpl_test_eq(visir_lower_bound(v, 6.), LEN(d));
299 
300  cpl_test_eq(visir_upper_bound(v, 0.), 0);
301  cpl_test_eq(visir_upper_bound(v, 1.), 2);
302  cpl_test_eq(visir_upper_bound(v, 1.1), 2);
303  cpl_test_eq(visir_upper_bound(v, 2.), 3);
304  cpl_test_eq(visir_upper_bound(v, 2.1), 3);
305  cpl_test_eq(visir_upper_bound(v, 4.), LEN(d) - 2);
306  cpl_test_eq(visir_upper_bound(v, 5.), LEN(d));
307  cpl_test_eq(visir_upper_bound(v, 6.), LEN(d));
308  cpl_vector_unwrap(v);
309  }
310 
311  cpl_test_nonnull( stream );
312 
313  if (stream != stdout) cpl_test_zero( fclose(stream) );
314 
315 }
316 
317 static void visir_get_kth_test(void)
318 {
319  FILE * stream;
320  double res = -1;
321 
322  stream = cpl_msg_get_level() > CPL_MSG_INFO
323  ? fopen("/dev/null", "a") : stdout;
324 
325  {
326  double a[10];
327 
328  for (size_t i = 0; i < LEN(a); i++)
329  a[i] = 0;
330  for (size_t i = 0; i < LEN(a); i++) {
331  res = cpl_tools_get_kth_double(a, LEN(a), i);
332  cpl_test_eq(0, res);
333  }
334 
335  for (size_t i = 0; i < LEN(a); i++)
336  a[i] = i;
337  for (size_t i = 0; i < LEN(a); i++) {
338  res = cpl_tools_get_kth_double(a, LEN(a), i);
339  cpl_test_eq(i, res);
340  }
341 
342  for (size_t i = 0; i < LEN(a); i++)
343  a[i] = -(int)i;
344  for (size_t i = 0; i < LEN(a); i++) {
345  res = cpl_tools_get_kth_double(a, LEN(a), i);
346  cpl_test_eq((double)i - LEN(a) + 1., res);
347  }
348  }
349 
350  {
351  double a[] = {3,1,4,2,0,9,7,8,6,5};
352  res = cpl_tools_get_kth_double(a, LEN(a), 4);
353  cpl_test_eq(4, res);
354  for (size_t i = 0; i < LEN(a) / 2; i++)
355  cpl_test_leq(a[i], 4);
356  for (size_t i = LEN(a)/2; i < LEN(a); i++)
357  cpl_test_lt(4, a[i]);
358  }
359 
360  {
361  double a[] = {8,5,9,2,0,4,6,3,7,1};
362  res = cpl_tools_get_kth_double(a, LEN(a), 2);
363  cpl_test_eq(2, res);
364  res = cpl_tools_get_kth_double(a, LEN(a), 7);
365  cpl_test_eq(7, res);
366 
367  cpl_test_eq(9, a[LEN(a) - 1]);
368  cpl_test_eq(8, a[LEN(a) - 2]);
369  cpl_test_eq(0, a[0]);
370  cpl_test_eq(1, a[1]);
371  }
372 
373  {
374  double a[] = {8,5,9,2,0,4,6,3,7,1};
375  res = cpl_tools_get_kth_double(a, LEN(a), 7);
376  cpl_test_eq(7, res);
377  res = cpl_tools_get_kth_double(a, LEN(a), 2);
378  cpl_test_eq(2, res);
379 
380  cpl_test_eq(9, a[LEN(a) - 1]);
381  cpl_test_eq(8, a[LEN(a) - 2]);
382  cpl_test_eq(0, a[0]);
383  cpl_test_eq(1, a[1]);
384  }
385 
386  cpl_test_nonnull( stream );
387 
388  if (stream != stdout) cpl_test_zero( fclose(stream) );
389 
390 }
391 
392 static void visir_clip_kappa_sigma_test(void)
393 {
394  FILE * stream;
395  int dump;
396 
397  stream = cpl_msg_get_level() > CPL_MSG_INFO
398  ? fopen("/dev/null", "a") : stdout;
399 
400  cpl_test_nonnull( stream );
401 
402  {
403  double * pixels = cpl_calloc(9, sizeof(double));
404  int shifts[3 * 2] = {0};
405  pixels[1 + 3 * 1] = 1;
406 
407  cpl_imagelist * list = cpl_imagelist_new();
408  cpl_imagelist * dev = cpl_imagelist_new();
409 
410  cpl_image* img = cpl_image_wrap_double(3, 3, pixels);
411  cpl_imagelist_set(list, img, 0);
412  img = cpl_image_duplicate(img);
413  cpl_imagelist_set(list, img, 1);
414  img = cpl_image_duplicate(img);
415  cpl_imagelist_set(list, img, 2);
416 
417  visir_util_clip_kappa_sigma_double(list, dev, 1.0, 3, 3, shifts);
418 
419  cpl_image * map = cpl_image_new_from_accepted(list);
420  cpl_test_eq(3, cpl_image_get(map, 2, 2, &dump));
421 
422  cpl_image_delete(map);
423  cpl_imagelist_delete(list);
424  cpl_imagelist_delete(dev);
425  }
426 
427 
428  {
429  double * pixels = cpl_calloc(9, sizeof(double));
430  /* gaus mean 100 sigma 5, 2 sigma range */
431  int values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97,
432  97, 97, 97, 98, 98, 98, 98, 99, 99, 99,
433  99, 100, 100, 100, 100, 100, 101, 101, 101, 101,
434  102, 102, 102, 102, 103, 103, 103, 103, 104, 104,
435  104, 105, 105, 106, 106, 107, 108 };
436  int shifts[LEN(values) * 2] = {0};
437 
438  cpl_imagelist * list = cpl_imagelist_new();
439  cpl_imagelist * dev = cpl_imagelist_new();
440 
441  cpl_image* img = cpl_image_wrap_double(3, 3, pixels);
442  for (size_t i = 0; i < LEN(values); i++) {
443  cpl_image_set(img, 2, 2, values[i]);
444  cpl_imagelist_set(list, img, i);
445  img = cpl_image_duplicate(img);
446  }
447  cpl_image_delete(img);
448 
449  visir_util_clip_kappa_sigma_double(list, dev, 1.0, 3, 3, shifts);
450 
451  cpl_image * map = cpl_image_new_from_accepted(list);
452  cpl_test_eq(LEN(values), cpl_image_get(map, 2, 2, &dump));
453 
454  cpl_image_delete(map);
455  cpl_imagelist_delete(list);
456  cpl_imagelist_delete(dev);
457  }
458 
459  {
460  double * pixels = cpl_calloc(9, sizeof(double));
461  /* gaus mean 100 sigma 5, 2 sigma range, 2 outliers */
462  int values[] = {1, 150, 94, 94, 95, 95, 96, 96, 96, 97,
463  97, 97, 97, 98, 98, 98, 98, 99, 99, 99,
464  99, 100, 100, 100, 100, 100, 101, 101, 101, 101,
465  102, 102, 102, 102, 103, 103, 103, 103, 104, 104,
466  104, 105, 105, 106, 106, 107, 108 };
467  int shifts[LEN(values) * 2] = {0};
468 
469  cpl_imagelist * list = cpl_imagelist_new();
470  cpl_imagelist * dev = cpl_imagelist_new();
471 
472  cpl_image* img = cpl_image_wrap_double(3, 3, pixels);
473  for (size_t i = 0; i < LEN(values); i++) {
474  cpl_image_set(img, 2, 2, values[i]);
475  cpl_imagelist_set(list, img, i);
476  img = cpl_image_duplicate(img);
477  }
478  cpl_image_delete(img);
479 
480  visir_util_clip_kappa_sigma_double(list, dev, 1.0, 3, 3, shifts);
481 
482  cpl_image * map = cpl_image_new_from_accepted(list);
483  //cpl_image_dump_structure(map, stdout);
484  //cpl_image_dump_window(map, 1, 1, 3, 3, stdout);
485  //cpl_image_dump_window(img, 1, 1, 3, 3, stdout);
486  cpl_test_eq(LEN(values) - 2, cpl_image_get(map, 2, 2, &dump));
487 
488  cpl_image_delete(map);
489  cpl_imagelist_delete(list);
490  cpl_imagelist_delete(dev);
491  }
492 
493  {
494  double * pixels = cpl_calloc(9, sizeof(double));
495  cpl_msg_info(cpl_func, "-----------------");
496  int values[] = { -3, 10, 10, 10, 10, 10, 10, 10 };
497  int shifts[LEN(values) * 2] = {0};
498 
499  cpl_imagelist * list = cpl_imagelist_new();
500  cpl_imagelist * dev = cpl_imagelist_new();
501 
502  cpl_image* origimg = cpl_image_wrap_double(3, 3, pixels);
503  for (size_t i = 0; i < LEN(values); i++) {
504  cpl_image * img = cpl_image_duplicate(origimg);
505  if (i == 1) {
506  cpl_image_set(img, 1, 2, values[i]);
507  shifts[i * 2] = -1;
508  }
509  else if (i == 2) {
510  cpl_image_set(img, 2, 3, values[i]);
511  shifts[i * 2 + 1] = 1;
512  }
513  else if (i == 3) {
514  cpl_image_set(img, 3, 1, values[i]);
515  shifts[i * 2] = 1;
516  shifts[i * 2 + 1] = -1;
517  }
518  else
519  cpl_image_set(img, 2, 2, values[i]);
520  cpl_imagelist_set(list, img, i);
521  }
522  cpl_image_delete(origimg);
523 
524  visir_util_clip_kappa_sigma_double(list, dev, 1.0, 2, 2, shifts);
525 
526  cpl_image * map = cpl_image_new_from_accepted(list);
527  //cpl_image_dump_window(map, 1, 1, 3, 3, stdout);
528  /* to test boundaries change recipes/visir_util_clip_body.c to mark
529  * pixels shifted out of bounds as bad */
530  if (0) {
531  cpl_test_eq(LEN(values) - 2, cpl_image_get(map, 1, 1, &dump));
532  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 1, 2, &dump));
533  cpl_test_eq(LEN(values) - 2, cpl_image_get(map, 1, 3, &dump));
534  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 2, 1, &dump));
535  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 2, 2, &dump)); // one rejected
536  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 2, 3, &dump));
537  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 3, 1, &dump));
538  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 3, 2, &dump));
539  cpl_test_eq(LEN(values) - 2, cpl_image_get(map, 3, 3, &dump));
540  }
541  else
542  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 2, 2, &dump));
543 
544  cpl_image_delete(map);
545  cpl_imagelist_delete(list);
546  cpl_imagelist_delete(dev);
547  }
548 
549  /* test shifted rejects */
550  {
551  double * pixels = cpl_calloc(9, sizeof(double));
552  /* gaus mean 100 sigma 5, 2 sigma range, 3 outliers */
553  int values[] = {1, 150, -94, 94, 95, 95, 96, 96, 96, 97,
554  97, 97, 97, 98, 98, 98, 98, 99, 99, 99,
555  99, 100, 100, 100, 100, 100, 101, 101, 101, 101,
556  102, 102, 102, 102, 103, 103, 103, 103, 104, 104,
557  104, 105, 105, 106, 106, 107, 108 };
558  int shifts[LEN(values) * 2] = {0};
559  shifts[2] = 1;
560  shifts[4] = 1;
561  cpl_image * out1, * out2;
562 
563  cpl_imagelist * list = cpl_imagelist_new();
564  cpl_imagelist * dev = cpl_imagelist_new();
565 
566  cpl_image* img = cpl_image_wrap_double(3, 3, pixels);
567  for (size_t i = 0; i < LEN(values); i++) {
568  cpl_image_set(img, 2, 2, values[i]);
569  cpl_imagelist_set(list, img, i);
570  img = cpl_image_duplicate(img);
571  }
572  cpl_image_delete(img);
573  out1 = cpl_imagelist_get(list, 1);
574  out2 = cpl_imagelist_get(list, 2);
575  cpl_image_set(out1, 2, 2, 0);
576  cpl_image_set(out1, 3, 2, -94);
577  cpl_image_set(out2, 2, 2, 0);
578  cpl_image_set(out2, 3, 2, 150);
579 
580  visir_util_clip_kappa_sigma_double(list, dev, 1.0, 3, 3, shifts);
581 
582  cpl_image * map = cpl_image_new_from_accepted(list);
583  //cpl_image_dump_structure(map, stdout);
584  //cpl_image_dump_window(map, 2, 2, 3, 3, stdout);
585  //cpl_image_dump_window(img, 1, 1, 3, 3, stdout);
586  cpl_test_eq(LEN(values) - 1, cpl_image_get(map, 2, 2, &dump));
587  cpl_test_eq(LEN(values) - 2, cpl_image_get(map, 3, 2, &dump));
588  dump = 0;
589  cpl_image_get(out1, 3, 2, &dump);
590  cpl_test_eq(dump, 1);
591  dump = 0;
592  cpl_image_get(out2, 3, 2, &dump);
593  cpl_test_eq(dump, 1);
594 
595  cpl_image_delete(map);
596  cpl_imagelist_delete(list);
597  cpl_imagelist_delete(dev);
598  }
599  cpl_free(prnok);
600  prnok_nz = 0;
601 
602  if (stream != stdout) cpl_test_zero( fclose(stream) );
603 
604 }
605 
606 static void visir_fftxcorrelate_test(void)
607 {
608  FILE * stream;
609 
610  stream = cpl_msg_get_level() > CPL_MSG_INFO
611  ? fopen("/dev/null", "a") : stdout;
612 
613  cpl_test_nonnull( stream );
614  {
615  double xshift = 0, yshift = 0;
616  double max_correlation;
617  double * values = cpl_calloc(16, sizeof(double));
618  cpl_error_code err;
619 
620  values[IND(2,2,4)] = 1;
621  cpl_image * tmp = cpl_image_wrap_double(4, 4, values);
622  values = cpl_calloc(16, sizeof(double));
623  values[IND(3,3,4)] = 1;
624  cpl_image * img2 = cpl_image_wrap_double(4, 4, values);
625 
626  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift, &yshift,
627  &max_correlation, NULL);
628  cpl_test_eq(CPL_ERROR_NONE, err);
629 
630  cpl_test_rel(1, xshift, 0.05);
631  cpl_test_rel(1, yshift, 0.05);
632 
633  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE,
634  &xshift, NULL, NULL, NULL);
635  cpl_test_eq(CPL_ERROR_NONE, err);
636  cpl_test_rel(1, xshift, 0.05);
637 
638  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE,
639  NULL, &yshift, NULL, NULL);
640  cpl_test_eq(CPL_ERROR_NONE, err);
641  cpl_test_rel(1, yshift, 0.05);
642 
643  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, NULL, NULL,
644  &max_correlation, NULL);
645  cpl_test_eq(CPL_ERROR_NONE, err);
646  cpl_test_lt(0.91, max_correlation);
647 
648  err = visir_fftxcorrelate(tmp, img2, CPL_FALSE,
649  NULL, NULL, NULL, NULL);
650  cpl_test_eq(CPL_ERROR_NONE, err);
651 
652  cpl_image_delete(tmp);
653  cpl_image_delete(img2);
654  }
655  /* same image */
656  {
657  cpl_size N = 10;
658  double xshift = 0, yshift = 0;
659  double max_correlation;
660  double * values = cpl_calloc(N*(N+5), sizeof(double));
661  cpl_error_code err;
662 
663  values[IND(5,5,N)] = 1;
664  values[IND(5,6,N)] = 9;
665  values[IND(3,5,N)] = 2;
666  values[IND(3,7,N)] = -3;
667  cpl_image * tmp = cpl_image_wrap_double(N,N+5, values);
668  cpl_image * img2 = cpl_image_duplicate(tmp);
669 
670  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift, &yshift,
671  &max_correlation, NULL);
672  cpl_test_eq(CPL_ERROR_NONE, err);
673 
674  cpl_test_rel(1, xshift + 1, 0.05);
675  cpl_test_rel(1, yshift + 1, 0.05);
676  cpl_test_rel(1.00, max_correlation, 0.02);
677 
678  cpl_image_delete(tmp);
679  cpl_image_delete(img2);
680  }
681  /* subpixel shift test */
682  {
683  cpl_size N = 5;
684  double xshift = 0, yshift = 0;
685  double * values = cpl_calloc(N*N, sizeof(double));
686  cpl_error_code err;
687 
688  values[IND(2,1,N)] = 1;
689  values[IND(2,2,N)] = 3;
690  values[IND(2,3,N)] = 2;
691  cpl_image * tmp = cpl_image_wrap_double(N, N, values);
692  values = cpl_calloc(N*N, sizeof(double));
693  values[IND(2,1,N)] = 0.5;
694  values[IND(2,2,N)] = 2;
695  values[IND(2,3,N)] = 2.5;
696  values[IND(2,4,N)] = 1;
697  cpl_image * img2 = cpl_image_wrap_double(N, N, values);
698 
699  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift, &yshift,
700  NULL, NULL);
701  cpl_test_eq(CPL_ERROR_NONE, err);
702 
703  cpl_test_rel(1, xshift+1, 0.05);
704  /* subpixel estimate has low precision */
705  cpl_test_rel(0.5, yshift, 0.15);
706 
707  cpl_image_delete(tmp);
708  cpl_image_delete(img2);
709  }
710  /* subpixel shift test 2*/
711  {
712  cpl_size N = 5;
713  double xshift = 0, yshift = 0;
714  double max_correlation;
715  double * values = cpl_calloc(N*N, sizeof(double));
716  cpl_error_code err;
717 
718  values[IND(2,1,N)] = 1;
719  values[IND(2,2,N)] = 3;
720  values[IND(2,3,N)] = 2;
721  cpl_image * tmp = cpl_image_wrap_double(N, N, values);
722  values = cpl_calloc(N*N, sizeof(double));
723  values[IND(3,0,N)] = 2;
724  values[IND(3,1,N)] = 2.5;
725  values[IND(3,2,N)] = 1;
726  cpl_image * img2 = cpl_image_wrap_double(N, N, values);
727 
728  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift, &yshift,
729  &max_correlation, NULL);
730  cpl_test_eq(CPL_ERROR_NONE, err);
731 
732  cpl_test_rel(1, xshift, 0.05);
733  /* subpixel estimate has low precision */
734  cpl_test_rel(-1.5, yshift, 0.1);
735 
736  cpl_image_delete(tmp);
737  cpl_image_delete(img2);
738  }
739  /* test bad pixel */
740  {
741  double xshift = 0, yshift = 0;
742  double max_correlation;
743  double * values = cpl_calloc(16, sizeof(double));
744  cpl_error_code err;
745 
746  values[IND(2,2,4)] = 1;
747  cpl_image * tmp = cpl_image_wrap_double(4, 4, values);
748  values = cpl_calloc(16, sizeof(double));
749  values[IND(3,1,4)] = 2;
750  values[IND(1,1,4)] = 200;
751  cpl_image * img2 = cpl_image_wrap_double(4, 4, values);
752 
753  cpl_mask * m = cpl_mask_threshold_image_create(img2, 10, FLT_MAX);
754  cpl_image_reject_from_mask(img2, m);
755  cpl_mask_delete(m);
756 
757  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift, &yshift,
758  &max_correlation, NULL);
759  cpl_test_eq(CPL_ERROR_NONE, err);
760 
761  cpl_test_rel(1, xshift, 0.05);
762  cpl_test_rel(-1, yshift, 0.05);
763 
764  cpl_image_delete(tmp);
765  cpl_image_delete(img2);
766  }
767  /* test non-square */
768  {
769  cpl_size Nx = 8, Ny = 4;
770  double xshift = 0, yshift = 0;
771  double max_correlation;
772  double * values = cpl_calloc(Nx*Ny, sizeof(double));
773  cpl_error_code err;
774 
775  values[IND(2,1,Nx)] = 1;
776  values[IND(2,2,Nx)] = 3;
777  values[IND(2,3,Nx)] = 2;
778  cpl_image * tmp = cpl_image_wrap_double(Nx, Ny, values);
779  values = cpl_calloc(Nx*Ny, sizeof(double));
780  values[IND(3,0,Nx)] = 2;
781  values[IND(3,1,Nx)] = 2.5;
782  values[IND(3,2,Nx)] = 1;
783  cpl_image * img2 = cpl_image_wrap_double(Nx, Ny, values);
784 
785  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift, &yshift,
786  &max_correlation, NULL);
787  cpl_test_eq(CPL_ERROR_NONE, err);
788 
789  cpl_test_rel(1, xshift, 0.05);
790  /* subpixel estimate has low precision */
791  cpl_test_rel(-1.5, yshift, 0.1);
792 
793  cpl_image_delete(tmp);
794  cpl_image_delete(img2);
795  }
796  /* test template reuse */
797  {
798  cpl_size Nx = 18, Ny = 27;
799  double xshift = 0, yshift = 0;
800  double max_correlation = 0;
801  double * values = cpl_calloc(Nx*Ny, sizeof(double));
802  cpl_error_code err;
803 
804  values[IND(5, 8,Nx)] = 1;
805  values[IND(5, 9,Nx)] = 3;
806  values[IND(5,10,Nx)] = 2;
807  values[IND(4, 9,Nx)] = 1;
808  values[IND(5, 9,Nx)] = 3;
809  values[IND(6, 9,Nx)] = 2;
810  cpl_image * tmp = cpl_image_wrap_double(Nx, Ny, values);
811  values = cpl_calloc(Nx*Ny, sizeof(double));
812  values[IND(4, 9,Nx)] = 1;
813  values[IND(4,10,Nx)] = 3;
814  values[IND(4,11,Nx)] = 2;
815  values[IND(3,10,Nx)] = 1;
816  values[IND(4,10,Nx)] = 3;
817  values[IND(5,10,Nx)] = 2;
818  cpl_image * img2 = cpl_image_wrap_double(Nx, Ny, values);
819  visir_fftx_cache * cache = visir_new_fftx_cache();
820 
821  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift, &yshift,
822  &max_correlation, cache);
823  cpl_test_eq(CPL_ERROR_NONE, err);
824  cpl_test_rel(-1, xshift, 0.05);
825  cpl_test_rel(1, yshift, 0.05);
826  cpl_test_rel(1, max_correlation, 0.05);
827 
828  double xshift2 = 0, yshift2 = 0;
829  double max_correlation2 = 0;
830  err = visir_fftxcorrelate(tmp, img2, CPL_TRUE, &xshift2, &yshift2,
831  &max_correlation2, cache);
832  cpl_test_eq(CPL_ERROR_NONE, err);
833  cpl_test_eq(xshift, xshift2);
834  cpl_test_eq(yshift, yshift2);
835  cpl_test_eq(max_correlation, max_correlation2);
836 
837  cpl_image_delete(tmp);
838  visir_delete_fftx_cache(cache);
839  cpl_image_delete(img2);
840  }
841 
842  if (stream != stdout) cpl_test_zero( fclose(stream) );
843 }
844 
845 static void visir_interpolate_rejected_test(void)
846 {
847  FILE * stream;
848 
849  stream = cpl_msg_get_level() > CPL_MSG_INFO
850  ? fopen("/dev/null", "a") : stdout;
851 
852  cpl_test_nonnull( stream );
853 
854  {
855  float input[] = {
856  1,9,3,9,
857  0,9,4,1,
858  9,2,0,1,
859  1,0,3,0};
860  cpl_binary bpmdata[] = {
861  0,1,0,1,
862  0,1,0,0,
863  1,0,1,0,
864  1,1,0,0};
865  float expected[] = {
866  1.0, 2.0, 3.0, 2.0,
867  0.0, 2.0, 4.0, 1.0,
868  1.0, 2.0, 2.5, 1.0,
869  1.5, 2.5, 3.0, 0.0};
870 
871 
872  cpl_image * in = cpl_image_wrap(4, 4, CPL_TYPE_FLOAT, input);
873  cpl_mask * bpm = cpl_mask_wrap(4, 4, bpmdata);
874 
875  cpl_image_reject_from_mask(in, bpm);
876  cpl_image * in2 = cpl_image_duplicate(in);
877  cpl_image * in3 = cpl_image_duplicate(in);
878  cpl_image * ex = cpl_image_wrap(4, 4, CPL_TYPE_FLOAT, expected);
879  size_t *buffer = NULL;
880  size_t n;
881  visir_interpolate_rejected(in, &buffer, &n);
882  cpl_test_error(CPL_ERROR_NONE);
883 
884  cpl_test_image_abs(in, ex, 1e-6);
885 
886  visir_interpolate_rejected(in2, &buffer, &n);
887  cpl_test_error(CPL_ERROR_NONE);
888 
889  cpl_test_image_abs(in2, ex, 1e-6);
890  cpl_test_image_abs(in2, in, 1e-6);
891 
892  visir_interpolate_rejected(in3, NULL, NULL);
893  cpl_test_error(CPL_ERROR_NONE);
894 
895  cpl_test_image_abs(in3, ex, 1e-6);
896  cpl_test_image_abs(in3, in, 1e-6);
897 
898  cpl_image_unwrap(in);
899  cpl_image_delete(in2);
900  cpl_image_delete(in3);
901  cpl_mask_unwrap(bpm);
902  cpl_image_unwrap(ex);
903  cpl_free(buffer);
904  }
905  {
906  float input[] = {
907  1,7,3,9,9,9,
908  0,9,4,1,1,1,
909  9,2,0,2,2,2,
910  1,0,3,3,0,2,
911  1,1,3,0,1,0};
912  cpl_binary bpmdata[] = {
913  0,0,0,0,0,0,
914  0,1,1,0,0,0,
915  0,1,1,0,0,0,
916  0,1,1,0,0,0,
917  0,0,0,0,0,0};
918  float expected[] = {
919  1.0,7.0,3.0,9.0,9.0,9.0,
920  0.0,8./3.,4./3.,1.0,1.0,1.0,
921  9.0,4.75,4.25,2.0,2.0,2.0,
922  1.0,5./3.,7./3.,3.0,0.0,2.0,
923  1.0,1.0,3.0,0.0,1.0,0.0};
924 
925 
926  cpl_image * in = cpl_image_wrap(6, 5, CPL_TYPE_FLOAT, input);
927  cpl_mask * bpm = cpl_mask_wrap(6, 5, bpmdata);
928  cpl_image * ex = cpl_image_wrap(6, 5, CPL_TYPE_FLOAT, expected);
929 
930  cpl_image_reject_from_mask(in, bpm);
931  visir_interpolate_rejected(in, NULL, NULL);
932  cpl_test_error(CPL_ERROR_NONE);
933 
934  cpl_test_image_abs(in, ex, 1e-6);
935 
936  cpl_image_unwrap(in);
937  cpl_mask_unwrap(bpm);
938  cpl_image_unwrap(ex);
939  }
940  {
941  float input[] = {
942  1,7,3,9,9,9,
943  0,9,4,1,1,1,
944  9,2,0,2,2,2,
945  1,0,3,3,0,2,
946  1,1,3,0,1,0};
947  cpl_binary bpmdata[] = {
948  0,0,0,0,0,0,
949  0,1,1,1,1,0,
950  0,1,1,1,1,1,
951  0,0,0,0,0,0,
952  1,1,1,1,1,1};
953  float expected[] = {
954  1.0,7.0,3.0,9.0,9.0,9.0,
955  0.0,7./3.,2.0,13./3.,10./3.,1.0,
956  9.0,16./3.,5.0,6.0,4.5,1.5,
957  1.0,0.0,3.0,3.0,0.0,2.0,
958  1.0,0.0,3.0,3.0,0.0,2.0};
959 
960 
961  cpl_image * in = cpl_image_wrap(6, 5, CPL_TYPE_FLOAT, input);
962  cpl_mask * bpm = cpl_mask_wrap(6, 5, bpmdata);
963  cpl_image * ex = cpl_image_wrap(6, 5, CPL_TYPE_FLOAT, expected);
964 
965  cpl_image_reject_from_mask(in, bpm);
966  cpl_image * in2 = cpl_image_duplicate(in);
967  size_t *buffer = NULL;
968  size_t n;
969  visir_interpolate_rejected(in, &buffer, &n);
970  cpl_test_error(CPL_ERROR_NONE);
971 
972  cpl_test_image_abs(in, ex, 1e-6);
973 
974  visir_interpolate_rejected(in, &buffer, &n);
975  cpl_test_error(CPL_ERROR_NONE);
976 
977  cpl_test_image_abs(in2, ex, 1e-6);
978  cpl_test_image_abs(in2, in, 1e-6);
979 
980  cpl_image_unwrap(in);
981  cpl_image_delete(in2);
982  cpl_mask_unwrap(bpm);
983  cpl_image_unwrap(ex);
984  cpl_free(buffer);
985  }
986 
987  if (stream != stdout) cpl_test_zero( fclose(stream) );
988 }
989 
990 static void visir_mean_fast_test(void)
991 {
992  FILE * stream;
993 
994  stream = cpl_msg_get_level() > CPL_MSG_INFO
995  ? fopen("/dev/null", "a") : stdout;
996 
997  cpl_test_nonnull( stream );
998 
999  {
1000  cpl_image * im = cpl_image_new(3, 43, CPL_TYPE_FLOAT);
1001  cpl_image_add_scalar(im, 3.2);
1002  cpl_test_abs(visir_image_get_mean_fast(im), 3.2, FLT_EPSILON);
1003  cpl_image_delete(im);
1004  }
1005  {
1006  cpl_image * im = cpl_image_new(4, 4, CPL_TYPE_FLOAT);
1007  cpl_image_add_scalar(im, 3.2);
1008  cpl_test_abs(visir_image_get_mean_fast(im), 3.2, FLT_EPSILON);
1009  cpl_image_delete(im);
1010  }
1011  {
1012  float val[] =
1013  {0.99226231, 0.6164352, 0.04541705, 0.94691027, 0.68742416};
1014  cpl_image * im = cpl_image_wrap(5, 1, CPL_TYPE_FLOAT, val);
1015  cpl_image_reject(im, 3, 1);
1016  cpl_test_abs(visir_image_get_mean_fast(im), 0.810758, FLT_EPSILON);
1017  cpl_image_unwrap(im);
1018  }
1019  {
1020  for (size_t i = 1; i < 17; i++) {
1021  cpl_image * im = cpl_image_new(1, i, CPL_TYPE_FLOAT);
1022  cpl_image_add_scalar(im, 3.2);
1023  cpl_test_abs(visir_image_get_mean_fast(im), 3.2, FLT_EPSILON);
1024  cpl_image_reject(im, 1, i);
1025  if (i == 1) {
1026  cpl_test_eq(visir_image_get_mean_fast(im), 0.);
1027  }
1028  else {
1029  cpl_test_abs(visir_image_get_mean_fast(im), 3.2, FLT_EPSILON);
1030  }
1031  cpl_image_delete(im);
1032  }
1033  }
1034 
1035  if (stream != stdout) cpl_test_zero( fclose(stream) );
1036 }
1037 
1038 static void visir_next_regular_test(void)
1039 {
1040  FILE * stream;
1041 
1042  stream = cpl_msg_get_level() > CPL_MSG_INFO
1043  ? fopen("/dev/null", "a") : stdout;
1044 
1045  cpl_test_nonnull( stream );
1046 
1047  cpl_test_eq(visir_get_next_regular(6), 6);
1048  cpl_test_eq(visir_get_next_regular(7), 8);
1049  cpl_test_eq(visir_get_next_regular(9), 9);
1050  cpl_test_eq(visir_get_next_regular(11), 12);
1051  cpl_test_eq(visir_get_next_regular(15), 15);
1052  cpl_test_eq(visir_get_next_regular(64), 64);
1053  cpl_test_eq(visir_get_next_regular(65), 72);
1054  cpl_test_eq(visir_get_next_regular(66), 72);
1055  cpl_test_eq(visir_get_next_regular(67), 72);
1056  cpl_test_eq(visir_get_next_regular(111), 120);
1057  cpl_test_eq(visir_get_next_regular(128), 128);
1058  cpl_test_eq(visir_get_next_regular(129), 135);
1059  cpl_test_eq(visir_get_next_regular(250), 250);
1060  cpl_test_eq(visir_get_next_regular(256), 256);
1061  cpl_test_eq(visir_get_next_regular(257), 270);
1062  cpl_test_eq(visir_get_next_regular(1023), 1024);
1063  cpl_test_eq(visir_get_next_regular(1024), 1024);
1064  cpl_test_eq(visir_get_next_regular(1025), 1080);
1065  cpl_test_eq(visir_get_next_regular(SIZE_MAX - 100), SIZE_MAX - 100);
1066  cpl_test_eq(visir_get_next_regular(SIZE_MAX), SIZE_MAX);
1067 
1068  for (cpl_size i = 0; i < 2048; i++) {
1069  size_t r = visir_get_next_regular(i);
1070  cpl_test(r >= i);
1071  size_t d = 2;
1072  int large_primes = 0;
1073  while(r > 1) {
1074  while (r % d == 0) {
1075  large_primes += (d > 5);
1076  r /= d;
1077  }
1078  d++;
1079  if (d * d > r || large_primes) {
1080  large_primes += (r > 1) && (d > 5);
1081  break;
1082  }
1083  }
1084  /* avoid too many log messages by only testing after the loop */
1085  cpl_test_eq(large_primes, 0);
1086  }
1087  if (stream != stdout) cpl_test_zero( fclose(stream) );
1088 }
1089 
1090 static void visir_test_parallel_median(void)
1091 {
1092  FILE * stream;
1093 
1094  stream = cpl_msg_get_level() > CPL_MSG_INFO
1095  ? fopen("/dev/null", "a") : stdout;
1096 
1097  cpl_test_nonnull( stream );
1098  cpl_size nys[] = {1, 3, 4, 100, 105, 217};
1099  for (size_t j = 0; j < sizeof(nys)/sizeof(nys[0]); j++) {
1100  cpl_size ny = nys[j];
1101  cpl_imagelist * l = cpl_imagelist_new();
1102  size_t n = 57;
1103  cpl_size nx = 100;
1104  for (size_t i = 0; i < n; i++) {
1105  cpl_image * img = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
1106  float * d = cpl_image_get_data_float(img);
1107  for (size_t i = 0; i < nx * ny; i++) {
1108  d[i] = rand() % nx;
1109  /* fully bad timeline */
1110  cpl_image_reject(img, 1, 1);
1111  /* random bad pixels */
1112  if ((rand() % 25) == 0) {
1113  cpl_image_reject(img, i % nx + 1, i / nx + 1);
1114  }
1115  }
1116  cpl_imagelist_set(l, img, i);
1117  }
1118  cpl_msg_info(cpl_func, "parallel median test ny: %ld", (long)ny);
1119  cpl_image * r1 = cpl_imagelist_collapse_median_create(l);
1120  cpl_image * r2 = visir_parallel_median_collapse(l);
1121  cpl_test_image_abs(r1, r2, 0);
1122  cpl_imagelist_delete(l);
1123  cpl_image_delete(r1);
1124  cpl_image_delete(r2);
1125  }
1126  cpl_test_eq_ptr(visir_parallel_median_collapse(NULL), NULL);
1127  cpl_test_error(CPL_ERROR_NULL_INPUT);
1128 
1129  cpl_imagelist * elist = cpl_imagelist_new();
1130  cpl_test_eq_ptr(visir_parallel_median_collapse(elist), NULL);
1131  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1132  cpl_imagelist_delete(elist);
1133 
1134  if (stream != stdout) cpl_test_zero( fclose(stream) );
1135 }
1136 
1137 static void visir_test_linintp_values(void)
1138 {
1139  FILE * stream;
1140 
1141  stream = cpl_msg_get_level() > CPL_MSG_INFO
1142  ? fopen("/dev/null", "a") : stdout;
1143  cpl_image * inp, * eimg, * res;
1144  double refx[] = {10, 20, 30};
1145  double refy[] = {1, 2, 1.5};
1146  size_t nref = sizeof(refx)/sizeof(refx[0]);
1147  cpl_vector * vrefx = cpl_vector_wrap(nref, refx);
1148  cpl_vector * vrefy = cpl_vector_wrap(nref, refy);
1149  cpl_bivector * ref = cpl_bivector_wrap_vectors(vrefx, vrefy);
1150 
1151  {
1152  double data[] = {10, 20, 30, 40, 15, 25, 12, 0, 5};
1153  //double edat[] = {1, 2, 1.5, 1, 1.5, 1.75, 1.2, 0, 0.5};
1154  double edat[] = {1, 2, 1.5, 1.5, 1.5, 1.75, 1.2, 1, 1.0};
1155  inp = cpl_image_wrap(2, 4, CPL_TYPE_DOUBLE, data);
1156  eimg = cpl_image_wrap(2, 4, CPL_TYPE_DOUBLE, edat);
1157  res = visir_linintp_values(inp, ref);
1158  cpl_test_image_abs(eimg, res, 1e-7);
1159  cpl_image_unwrap(inp);
1160  cpl_image_unwrap(eimg);
1161  cpl_image_delete(res);
1162  }
1163  cpl_bivector_unwrap_vectors(ref);
1164  cpl_vector_unwrap(vrefx);
1165  cpl_vector_unwrap(vrefy);
1166 
1167  if (stream != stdout) cpl_test_zero( fclose(stream) );
1168 }
int main(void)
Find a plugin and submit it to some tests.
Definition: recipe_main.c:61