VISIR Pipeline Reference Manual  4.1.7
visir_inputs-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 <visir_inputs.h>
29 
30 #include "visir_inputs.c"
31 /* for unlink */
32 #include <unistd.h>
33 
34 /*-----------------------------------------------------------------------------
35  Defines
36  -----------------------------------------------------------------------------*/
37 
38 #ifndef BOX_SIZE
39 #define BOX_SIZE 11
40 #endif
41 
42 #ifndef LINE_SIZE
43 #define LINE_SIZE BOX_SIZE
44 #endif
45 
46 #define TEST_LIST(list, value) \
47 do { \
48  for (int i = 0; i < cpl_imagelist_get_size((list)); i++) { \
49  int b; \
50  const cpl_image * image = cpl_imagelist_get_const((list), i); \
51  cpl_test_eq((value), cpl_image_get(image, 1, 1, &b)); \
52  } \
53 } \
54 while(0)
55 
56 #define A_VAL 4.
57 #define B_VAL 3.
58 
59 /*-----------------------------------------------------------------------------
60  Declarations of private functions
61  -----------------------------------------------------------------------------*/
62 
63 static void visir_img_check_box_test(void);
64 static void visir_img_check_align_test(void);
65 static void visir_img_check_line_test(void);
66 static void visir_check_get_type(void);
67 static void visir_img_check_burst_find_delta_chop(void);
68 static void visir_img_check_load_burst(void);
69 static void visir_img_check_get_to_off_plane(void);
70 static void visir_img_check_load_cube2(void);
71 
72 static cpl_propertylist * create_property_list(const char *,
73  const char *,
74  const double,
75  const double,
76  const double);
77 static cpl_imagelist * create_cube2_imagelist(int);
78 static cpl_imagelist * create_input_imagelist(const int *, int);
79 
80 
81 /*----------------------------------------------------------------------------*/
85 /*----------------------------------------------------------------------------*/
86 
87 
88 /*----------------------------------------------------------------------------*/
92 /*----------------------------------------------------------------------------*/
93 int main(void)
94 {
95 
96  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
97 
98  visir_img_check_line_test();
99  visir_img_check_align_test();
100  visir_img_check_box_test();
101  visir_check_get_type();
102  visir_img_check_burst_find_delta_chop();
103  visir_img_check_load_burst();
104  visir_img_check_get_to_off_plane();
105  visir_img_check_load_cube2();
106 
107  return cpl_test_end(0);
108 
109 }
110 
111 /* FIXME: Write a short doxygen of each static function */
112 
113 static void visir_img_check_box_test(void)
114 {
115 
116  cpl_image * image;
117  const double sigma = 1.0;
118  cpl_apertures * appos;
119  cpl_apertures * apneg;
120  double ecc;
121  cpl_boolean swapp, swapn;
122  FILE * stream;
123  cpl_error_code error = CPL_ERROR_NONE;
124  int i, j;
125 
126  stream = cpl_msg_get_level() > CPL_MSG_INFO
127  ? fopen("/dev/null", "a") : stdout;
128 
129  cpl_test_nonnull( stream );
130 
131  image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE, CPL_TYPE_INT);
132 
133  /* Create four 3x3-pixel objects */
134  for (j = -1; j <= 1; j++) {
135  for (i = -1; i <= 1; i++) {
136  error |= cpl_image_set(image, BOX_SIZE + i, BOX_SIZE + j, -1.0);
137  error |= cpl_image_set(image, 2*BOX_SIZE + i, 2*BOX_SIZE + j, -1.0);
138  error |= cpl_image_set(image, BOX_SIZE + i, 2*BOX_SIZE + j, 1.0);
139  error |= cpl_image_set(image, 2*BOX_SIZE + i, BOX_SIZE + j, 1.0);
140  cpl_test_eq_error(error, CPL_ERROR_NONE);
141  }
142  }
143 
144  appos = cpl_apertures_extract_sigma(image, sigma);
145  cpl_test_error(CPL_ERROR_NONE);
146  cpl_test_nonnull(appos);
147  cpl_test_eq(cpl_apertures_get_size(appos), 2);
148 
149  cpl_apertures_dump(appos, stream);
150 
151  error = cpl_image_multiply_scalar(image, -1.0);
152  cpl_test_eq_error(error, CPL_ERROR_NONE);
153 
154  apneg = cpl_apertures_extract_sigma(image, sigma);
155  cpl_test_error(CPL_ERROR_NONE);
156  cpl_test_nonnull(apneg);
157  cpl_test_eq(cpl_apertures_get_size(apneg), 2);
158 
159  cpl_apertures_dump(apneg, stream);
160 
161  /* Various error checks */
162  ecc = visir_img_check_box(NULL, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
163  &swapp, &swapn);
164  cpl_test_error(CPL_ERROR_NULL_INPUT);
165 
166  ecc = visir_img_check_box(appos, 1, 2, NULL, 1, 2, BOX_SIZE, 0.,
167  &swapp, &swapn);
168  cpl_test_error(CPL_ERROR_NULL_INPUT);
169 
170  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
171  &swapp, NULL);
172  cpl_test_error(CPL_ERROR_UNSPECIFIED);
173 
174  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
175  NULL, &swapn);
176  cpl_test_error(CPL_ERROR_UNSPECIFIED);
177 
178  ecc = visir_img_check_box(appos, 1, 2, appos, 1, 2, BOX_SIZE, 0.,
179  &swapp, &swapn);
180  cpl_test_error(CPL_ERROR_UNSPECIFIED);
181 
182  ecc = visir_img_check_box(appos, 0, 2, apneg, 1, 2, BOX_SIZE, 0.,
183  &swapp, &swapn);
184  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
185 
186  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 0, BOX_SIZE, 0.,
187  &swapp, &swapn);
188  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
189 
190  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 3, BOX_SIZE, 0.,
191  &swapp, &swapn);
192  cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
193 
194  ecc = visir_img_check_box(appos, 3, 2, apneg, 1, 2, BOX_SIZE, 0.,
195  &swapp, &swapn);
196  cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
197 
198  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, 0.0, 0., &swapp, &swapn);
199  cpl_test_error(CPL_ERROR_UNSPECIFIED);
200 
201  /* Verify output of correct call - with zero eccentricity */
202  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
203  &swapp, &swapn);
204  cpl_test_error(CPL_ERROR_NONE);
205 
206  cpl_test_abs(ecc, 0.0, FLT_EPSILON);
207  cpl_test(swapp);
208  cpl_test_zero(swapn);
209 
210  /* - and points are swapped when needed */
211  ecc = visir_img_check_box(appos, 2, 1, apneg, 2, 1, BOX_SIZE, 0.,
212  &swapp, &swapn);
213  cpl_test_error(CPL_ERROR_NONE);
214 
215  cpl_test_abs(ecc, 0.0, FLT_EPSILON);
216  cpl_test_zero(swapp);
217  cpl_test(swapn);
218 
219  /* Verify output of correct call - with maximum (?) eccentricity */
220  ecc = visir_img_check_box(apneg, 1, 2, appos, 1, 2, BOX_SIZE, 0.,
221  &swapp, &swapn);
222  cpl_test_error(CPL_ERROR_NONE);
223 
224  cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
225  cpl_test_zero(swapp);
226  cpl_test(swapn);
227 
228  /* - and points are swapped when needed */
229  ecc = visir_img_check_box(apneg, 2, 1, appos, 2, 1, BOX_SIZE, 0.,
230  &swapp, &swapn);
231  cpl_test_error(CPL_ERROR_NONE);
232 
233  cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
234  cpl_test(swapp);
235  cpl_test_zero(swapn);
236 
237  cpl_image_delete(image);
238  cpl_apertures_delete(appos);
239  cpl_apertures_delete(apneg);
240 
241  /* verify with angle 45° */
242  image = cpl_image_new(600, 600, CPL_TYPE_INT);
243  double throw = 220;
244 
245  /* Create four 3x3-pixel objects */
246  for (j = -1; j <= 1; j++) {
247  for (i = -1; i <= 1; i++) {
248  cpl_image_set(image, 350 + i, 80 + j, 1.0);
249  cpl_image_set(image, 350 + i, 400 + j, 1.0);
250  cpl_image_set(image, 190 + i, 240 + j, -1.0);
251  cpl_image_set(image, 510 + i, 240 + j, -1.0);
252  }
253  }
254 
255  appos = cpl_apertures_extract_sigma(image, sigma);
256  cpl_image_multiply_scalar(image, -1.0);
257  apneg = cpl_apertures_extract_sigma(image, sigma);
258 
259  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, throw,
260  45. * CPL_MATH_RAD_DEG,
261  &swapp, &swapn);
262  cpl_test_error(CPL_ERROR_NONE);
263 
264  cpl_test_rel(ecc, 0.057, 0.1);
265  cpl_test(swapp);
266  cpl_test_zero(swapn);
267 
268  cpl_image_delete(image);
269  cpl_apertures_delete(appos);
270  cpl_apertures_delete(apneg);
271 
272  /* 30° */
273  image = cpl_image_new(600, 600, CPL_TYPE_INT);
274 
275  for (j = -1; j <= 1; j++) {
276  for (i = -1; i <= 1; i++) {
277  cpl_image_set(image, 453 + i, 172 + j, 1.0);
278  cpl_image_set(image, 373 + i, 470 + j, 1.0);
279  cpl_image_set(image, 260 + i, 280 + j, -1.0);
280  cpl_image_set(image, 570 + i, 360 + j, -1.0);
281  }
282  }
283 
284  appos = cpl_apertures_extract_sigma(image, sigma);
285  cpl_image_multiply_scalar(image, -1.0);
286  apneg = cpl_apertures_extract_sigma(image, sigma);
287 
288  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, throw,
289  30. * CPL_MATH_RAD_DEG,
290  &swapp, &swapn);
291  cpl_test_error(CPL_ERROR_NONE);
292 
293  cpl_test_rel(ecc, 0.049, 0.1);
294  cpl_test(swapp);
295  cpl_test_zero(swapn);
296 
297  cpl_image_delete(image);
298  cpl_apertures_delete(appos);
299  cpl_apertures_delete(apneg);
300 
301  /* 85° */
302  image = cpl_image_new(600, 600, CPL_TYPE_INT);
303 
304  for (j = -1; j <= 1; j++) {
305  for (i = -1; i <= 1; i++) {
306  cpl_image_set(image, 363 + i, 396 + j, 1.0);
307  cpl_image_set(image, 156 + i, 159 + j, 1.0);
308  cpl_image_set(image, 138 + i, 382 + j, -1.0);
309  cpl_image_set(image, 381 + i, 175 + j, -1.0);
310  }
311  }
312 
313  appos = cpl_apertures_extract_sigma(image, sigma);
314  cpl_image_multiply_scalar(image, -1.0);
315  apneg = cpl_apertures_extract_sigma(image, sigma);
316 
317  ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, throw,
318  85. * CPL_MATH_RAD_DEG,
319  &swapp, &swapn);
320  cpl_test_error(CPL_ERROR_NONE);
321 
322  cpl_test_rel(ecc, 0.049, 0.1);
323  cpl_test(swapp);
324  /* fails, not required to be correct for aqu pipeline */
325  //cpl_test_zero(swapn);
326 
327  cpl_image_delete(image);
328  cpl_apertures_delete(appos);
329  cpl_apertures_delete(apneg);
330 
331  if (stream != stdout) cpl_test_zero( fclose(stream) );
332 
333 }
334 
335 static void visir_img_check_align_test(void)
336 {
337 
338  FILE * stream;
339  cpl_error_code error = CPL_ERROR_NONE;
340  int idir;
341  cpl_boolean is_hor = CPL_FALSE;
342 
343  stream = cpl_msg_get_level() > CPL_MSG_INFO
344  ? fopen("/dev/null", "a") : stdout;
345 
346  cpl_test_nonnull( stream );
347 
348  for (idir = 0; idir < 2; idir++, is_hor = CPL_TRUE) {
349  cpl_image * image = cpl_image_new(4 * LINE_SIZE, 4 * LINE_SIZE,
350  CPL_TYPE_INT);
351  const double sigma = 1.0;
352  cpl_apertures * appos;
353  cpl_apertures * apneg;
354  double ecc;
355  cpl_boolean swapn, swapn2;
356  int i, j;
357  double dhor = 90 * CPL_MATH_RAD_DEG;
358 
359 
360  /* Create three 3x3-pixel objects */
361  for (j = -1; j <= 1; j++) {
362  for (i = -1; i <= 1; i++) {
363  error |= cpl_image_set(image, 2*LINE_SIZE + i,
364  2*LINE_SIZE + j, 1.0);
365 
366  if (is_hor) {
367  error |= cpl_image_set(image, LINE_SIZE + i,
368  2*LINE_SIZE + j, -1.0);
369  error |= cpl_image_set(image, 3*LINE_SIZE + i,
370  2*LINE_SIZE + j, -1.0);
371  } else {
372  error |= cpl_image_set(image, 2*LINE_SIZE + i,
373  LINE_SIZE + j, -1.0);
374  error |= cpl_image_set(image, 2*LINE_SIZE + i,
375  3*LINE_SIZE + j, -1.0);
376  }
377  cpl_test_eq_error(error, CPL_ERROR_NONE);
378  }
379  }
380 
381  appos = cpl_apertures_extract_sigma(image, sigma);
382  cpl_test_error(CPL_ERROR_NONE);
383  cpl_test_nonnull(appos);
384  cpl_test_eq(cpl_apertures_get_size(appos), 1);
385 
386  cpl_apertures_dump(appos, stream);
387 
388  error = cpl_image_multiply_scalar(image, -1.0);
389  cpl_test_eq_error(error, CPL_ERROR_NONE);
390 
391  apneg = cpl_apertures_extract_sigma(image, sigma);
392  cpl_test_error(CPL_ERROR_NONE);
393  cpl_test_nonnull(apneg);
394  cpl_test_eq(cpl_apertures_get_size(apneg), 2);
395 
396  cpl_apertures_dump(apneg, stream);
397 
398  /* Various error checks */
399  ecc = visir_img_check_align(NULL, 1, apneg, 1, 2, LINE_SIZE, 0.,
400  &swapn);
401  cpl_test_error(CPL_ERROR_NULL_INPUT);
402 
403  ecc = visir_img_check_align(appos, 1, NULL, 1, 2, LINE_SIZE, 0.,
404  &swapn);
405  cpl_test_error(CPL_ERROR_NULL_INPUT);
406 
407  ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, 0.,
408  NULL);
409  cpl_test_error(CPL_ERROR_UNSPECIFIED);
410 
411  ecc = visir_img_check_align(appos, 0, apneg, 1, 2, LINE_SIZE, 0.,
412  &swapn);
413  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
414 
415  ecc = visir_img_check_align(appos, 1, apneg, 1, 0, LINE_SIZE, 0.,
416  &swapn);
417  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
418 
419  ecc = visir_img_check_align(appos, 1, apneg, 0, 1, LINE_SIZE, 0.,
420  &swapn);
421  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
422 
423  ecc = visir_img_check_align(appos, 1, apneg, 1, 3, LINE_SIZE, 0.,
424  &swapn);
425  cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
426 
427  ecc = visir_img_check_align(appos, 3, apneg, 1, 2, LINE_SIZE, 0.,
428  &swapn);
429  cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
430 
431  ecc = visir_img_check_align(appos, 1, apneg, 1, 2, 0.0, 0., &swapn);
432  cpl_test_error(CPL_ERROR_UNSPECIFIED);
433 
434  /* Verify output of correct call - with zero eccentricity */
435  ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE,
436  is_hor ? dhor : 0., &swapn);
437  cpl_test_error(CPL_ERROR_NONE);
438 
439  cpl_test_abs(ecc, 0.0, FLT_EPSILON);
440  cpl_test_zero(swapn);
441 
442  /* - and points are swapped when needed */
443  ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE,
444  is_hor ? dhor : 0., &swapn);
445  cpl_test_error(CPL_ERROR_NONE);
446 
447  cpl_test_abs(ecc, 0.0, FLT_EPSILON);
448  cpl_test(swapn);
449 
450  /* Verify output of correct call - with maximum (?) eccentricity */
451  ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE,
452  !is_hor ? dhor : 0., &swapn);
453  cpl_test_error(CPL_ERROR_NONE);
454 
455  cpl_test_abs(ecc, 2.0, FLT_EPSILON);
456 
457  /* - also with points swapped */
458  ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE,
459  !is_hor ? dhor : 0. ,&swapn2);
460  cpl_test_error(CPL_ERROR_NONE);
461 
462  cpl_test_abs(ecc, 2.0, FLT_EPSILON);
463 
464  /* FIXME: When to exactly swap here is not well-defined. */
465 
466  cpl_image_delete(image);
467  cpl_apertures_delete(appos);
468  cpl_apertures_delete(apneg);
469  }
470 
471  if (stream != stdout) cpl_test_zero( fclose(stream) );
472 
473 }
474 
475 static void visir_img_check_line_test(void)
476 {
477 
478  FILE * stream;
479  cpl_error_code error = CPL_ERROR_NONE;
480  int idir;
481  cpl_boolean is_hor = CPL_FALSE;
482 
483  stream = cpl_msg_get_level() > CPL_MSG_INFO
484  ? fopen("/dev/null", "a") : stdout;
485 
486  cpl_test_nonnull( stream );
487 
488  for (idir = 0; idir < 2; idir++, is_hor = CPL_TRUE) {
489  cpl_image * image = cpl_image_new(4 * LINE_SIZE, 4 * LINE_SIZE,
490  CPL_TYPE_INT);
491  const double sigma = 1.0;
492  cpl_apertures * appos;
493  cpl_apertures * apneg;
494  double ecc;
495  int i, j;
496  double dhor = 90 * CPL_MATH_RAD_DEG;
497 
498 
499  /* Create three 3x3-pixel objects */
500  for (j = -1; j <= 1; j++) {
501  for (i = -1; i <= 1; i++) {
502  error |= cpl_image_set(image, 2*LINE_SIZE + i,
503  2*LINE_SIZE + j, 1.0);
504 
505  if (is_hor) {
506  error |= cpl_image_set(image, LINE_SIZE + i,
507  2*LINE_SIZE + j, -1.0);
508  error |= cpl_image_set(image, 3*LINE_SIZE + i,
509  2*LINE_SIZE + j, -1.0);
510  } else {
511  error |= cpl_image_set(image, 2*LINE_SIZE + i,
512  LINE_SIZE + j, -1.0);
513  error |= cpl_image_set(image, 2*LINE_SIZE + i,
514  3*LINE_SIZE + j, -1.0);
515  }
516  cpl_test_eq_error(error, CPL_ERROR_NONE);
517  }
518  }
519 
520  appos = cpl_apertures_extract_sigma(image, sigma);
521  cpl_test_error(CPL_ERROR_NONE);
522  cpl_test_nonnull(appos);
523  cpl_test_eq(cpl_apertures_get_size(appos), 1);
524 
525  cpl_apertures_dump(appos, stream);
526 
527  error = cpl_image_multiply_scalar(image, -1.0);
528  cpl_test_eq_error(error, CPL_ERROR_NONE);
529 
530  apneg = cpl_apertures_extract_sigma(image, sigma);
531  cpl_test_error(CPL_ERROR_NONE);
532  cpl_test_nonnull(apneg);
533  cpl_test_eq(cpl_apertures_get_size(apneg), 2);
534 
535  cpl_apertures_dump(apneg, stream);
536 
537  /* Various error checks */
538  ecc = visir_img_check_line(NULL, 1, apneg, 1, LINE_SIZE, 0.);
539  cpl_test_error(CPL_ERROR_NULL_INPUT);
540 
541  ecc = visir_img_check_line(appos, 1, NULL, 1, LINE_SIZE, 0.);
542  cpl_test_error(CPL_ERROR_NULL_INPUT);
543 
544  ecc = visir_img_check_line(appos, 0, apneg, 1, LINE_SIZE, 0.);
545  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
546 
547  ecc = visir_img_check_line(appos, 1, apneg, 0, LINE_SIZE, 0.);
548  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
549 
550  ecc = visir_img_check_line(appos, 1, apneg, 0, LINE_SIZE, 0.);
551  cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
552 
553  ecc = visir_img_check_line(appos, 1, apneg, 3, LINE_SIZE, 0.);
554  cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
555 
556  ecc = visir_img_check_line(appos, 3, apneg, 1, LINE_SIZE, 0.);
557  cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
558 
559  ecc = visir_img_check_line(appos, 1, apneg, 1, 0.0, 0.);
560  cpl_test_error(CPL_ERROR_UNSPECIFIED);
561 
562  /* Verify output of correct call - with zero eccentricity */
563  ecc = visir_img_check_line(apneg, 1, appos, 1, LINE_SIZE,
564  is_hor ? dhor : 0.);
565  cpl_test_error(CPL_ERROR_NONE);
566 
567  cpl_test_abs(ecc, 0.0, FLT_EPSILON);
568 
569  /* Verify output of correct call - with maximum (?) eccentricity */
570  ecc = visir_img_check_line(appos, 1, apneg, 1, LINE_SIZE,
571  is_hor ? dhor : 0.);
572  cpl_test_error(CPL_ERROR_NONE);
573 
574  cpl_test_abs(ecc, 2.0, FLT_EPSILON);
575 
576  /* Verify output of correct call - with maximum (?) eccentricity */
577  ecc = visir_img_check_line(appos, 1, apneg, 1, LINE_SIZE,
578  !is_hor ? dhor : 0.);
579  cpl_test_error(CPL_ERROR_NONE);
580 
581  cpl_test_abs(ecc, CPL_MATH_SQRT2, FLT_EPSILON);
582 
583  /* - also with points swapped */
584  ecc = visir_img_check_line(apneg, 1, appos, 1, LINE_SIZE,
585  !is_hor ? dhor : 0.);
586  cpl_test_error(CPL_ERROR_NONE);
587 
588  cpl_test_abs(ecc, CPL_MATH_SQRT2, FLT_EPSILON);
589 
590  /* FIXME: When to exactly swap here is not well-defined. */
591 
592  cpl_image_delete(image);
593  cpl_apertures_delete(appos);
594  cpl_apertures_delete(apneg);
595  }
596 
597  if (stream != stdout) cpl_test_zero( fclose(stream) );
598 
599 }
600 
601 static void load_frame(const char * fn, cpl_frame ** frm,
602  cpl_propertylist ** plist, const int iext)
603 {
604  *frm = cpl_frame_new();
605  cpl_frame_set_filename(*frm, fn);
606  *plist = cpl_propertylist_load(fn, iext);
607 }
608 
609 
610 static void visir_check_get_type(void)
611 {
612 
613  FILE * stream;
614  const char * fn = "get_type_check.fits";
615 
616  stream = cpl_msg_get_level() > CPL_MSG_INFO
617  ? fopen("/dev/null", "a") : stdout;
618 
619  cpl_propertylist * plist;
620  cpl_imagelist * l;
621  cpl_frame * frm;
622  cpl_propertylist * lplist;
623  cpl_size next;
624  visir_data_type type;
625 
626  /* CUBE1 */
627  {
628  l = cpl_imagelist_new();
629  plist = cpl_propertylist_new();
630  cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
631  "CUBE1");
632  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 2);
633  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
634  for (int i = 0; i < 4; i++)
635  cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
636  cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
637  load_frame(fn, &frm, &lplist, 0);
638 
639  visir_get_data_type(frm, lplist, &type, &next);
640  cpl_test_error(CPL_ERROR_NONE);
641  cpl_test_eq(VISIR_DATA_CUBE1, type);
642  cpl_test_eq(0, next);
643 
644  cpl_frame_delete(frm);
645  cpl_propertylist_delete(lplist);
646  cpl_imagelist_delete(l);
647  cpl_propertylist_delete(plist);
648  }
649 
650  /* CUBE2 */
651  {
652  l = cpl_imagelist_new();
653  plist = cpl_propertylist_new();
654  cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
655  "CUBE2");
656  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
657  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
658  for (int i = 0; i < 5 * 2 + 1; i++)
659  cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
660  cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
661  load_frame(fn, &frm, &lplist, 0);
662 
663  visir_get_data_type(frm, lplist, &type, &next);
664  cpl_test_error(CPL_ERROR_NONE);
665  cpl_test_eq(VISIR_DATA_CUBE2, type);
666  cpl_test_eq(0, next);
667 
668  cpl_frame_delete(frm);
669  cpl_propertylist_delete(lplist);
670  cpl_imagelist_delete(l);
671  cpl_propertylist_delete(plist);
672  }
673 
674  /* BURST */
675  {
676  l = cpl_imagelist_new();
677  plist = cpl_propertylist_new();
678  cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
679  "UNDEFINED");
680  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
681  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
682  for (int i = 0; i < 5 * 2 * 10; i++)
683  cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
684  cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
685  load_frame(fn, &frm, &lplist, 0);
686 
687  visir_get_data_type(frm, lplist, &type, &next);
688  cpl_test_error(CPL_ERROR_NONE);
689  cpl_test_eq(VISIR_DATA_BURST, type);
690  cpl_test_eq(0, next);
691 
692  cpl_frame_delete(frm);
693  cpl_propertylist_delete(lplist);
694  cpl_imagelist_delete(l);
695  cpl_propertylist_delete(plist);
696  }
697 
698  /* BURST incomplete*/
699  {
700  l = cpl_imagelist_new();
701  plist = cpl_propertylist_new();
702  cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
703  "UNDEFINED");
704  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
705  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
706  for (int i = 0; i < 5 * 2 * 10 - 10; i++)
707  cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
708  cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
709  load_frame(fn, &frm, &lplist, 0);
710 
711  visir_get_data_type(frm, lplist, &type, &next);
712  cpl_test_error(CPL_ERROR_NONE);
713  cpl_test_eq(VISIR_DATA_BURST, type);
714  cpl_test_eq(0, next);
715 
716  cpl_frame_delete(frm);
717  cpl_propertylist_delete(lplist);
718  cpl_imagelist_delete(l);
719  cpl_propertylist_delete(plist);
720  }
721 
722  /* AQU HCYCLE */
723  {
724  cpl_image * img = cpl_image_new(4, 4, CPL_TYPE_INT);
725  plist = cpl_propertylist_new();
726  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NAVRG, 1);
727  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
728  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
729  cpl_propertylist_save(plist, fn, CPL_IO_CREATE);
730  for (int i = 0; i < 5 * 2 + 1; i++)
731  cpl_image_save(img, fn, CPL_TYPE_INT, NULL, CPL_IO_EXTEND);
732  load_frame(fn, &frm, &lplist, 0);
733 
734  visir_get_data_type(frm, lplist, &type, &next);
735  cpl_test_error(CPL_ERROR_NONE);
736  cpl_test_eq(VISIR_DATA_AQU_HCYCLE, type);
737  cpl_test_eq(11, next);
738 
739  cpl_frame_delete(frm);
740  cpl_propertylist_delete(lplist);
741  cpl_image_delete(img);
742  cpl_propertylist_delete(plist);
743  }
744 
745  /* AQU BURST */
746  {
747  plist = cpl_propertylist_new();
748  l = cpl_imagelist_new();
749  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NAVRG, 1);
750  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
751  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
752  for (int i = 0; i < 5 * 2 * 10; i++)
753  cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
754  cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
755  load_frame(fn, &frm, &lplist, 0);
756 
757  visir_get_data_type(frm, lplist, &type, &next);
758  cpl_test_error(CPL_ERROR_NONE);
759  cpl_test_eq(VISIR_DATA_AQU_BURST, type);
760  cpl_test_eq(0, next);
761 
762  cpl_frame_delete(frm);
763  cpl_propertylist_delete(lplist);
764  cpl_imagelist_delete(l);
765  cpl_propertylist_delete(plist);
766  }
767 
768  /* AQU BURST EXT */
769  {
770  plist = cpl_propertylist_new();
771  l = cpl_imagelist_new();
772  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NAVRG, 1);
773  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
774  cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
775  cpl_propertylist_save(plist, fn, CPL_IO_CREATE);
776  for (int i = 0; i < 5 * 2 * 10; i++)
777  cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
778  cpl_imagelist_save(l, fn, CPL_TYPE_INT, NULL, CPL_IO_EXTEND);
779  load_frame(fn, &frm, &lplist, 0);
780 
781  visir_get_data_type(frm, lplist, &type, &next);
782  cpl_test_error(CPL_ERROR_NONE);
783  cpl_test_eq(VISIR_DATA_AQU_BURST_EXT, type);
784  cpl_test_eq(1, next);
785 
786  cpl_frame_delete(frm);
787  cpl_propertylist_delete(lplist);
788  cpl_imagelist_delete(l);
789  cpl_propertylist_delete(plist);
790  }
791 
792  unlink(fn);
793  if (stream != stdout) cpl_test_zero( fclose(stream) );
794 }
795 
796 static cpl_propertylist * create_property_list(const char * obs_start,
797  const char * chop_start,
798  const double chop_freq,
799  const double dit,
800  const double nditskip)
801 {
802  cpl_propertylist * prop = cpl_propertylist_new();
803  cpl_propertylist_append_string(prop, VISIR_PFITS_STRING_OBS_START,
804  obs_start);
805  cpl_propertylist_append_string(prop, VISIR_PFITS_STRING_CHOP_START,
806  chop_start);
807  cpl_propertylist_append_double(prop, VISIR_PFITS_DOUBLE_CHOP_FREQ,
808  chop_freq);
809  cpl_propertylist_append_double(prop, VISIR_PFITS_DOUBLE_DIT, dit);
810  cpl_propertylist_append_int(prop, VISIR_PFITS_INT_NDITSKIP, nditskip);
811  return prop;
812 }
813 
814 static void visir_img_check_burst_find_delta_chop(void)
815 {
816 
817  FILE * stream;
818 
819  stream = cpl_msg_get_level() > CPL_MSG_INFO
820  ? fopen("/dev/null", "a") : stdout;
821 
822  cpl_test_nonnull( stream );
823 
824  {
825  int ifirst = 0, ihalfcycle = 0;
826  cpl_propertylist * prop =
827  create_property_list("2011-08-13T23:13:38.0612",
828  "2011-08-13T23:10:16",
829  0.25, 0.02, 2);
830  visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
831  cpl_test_eq(94, ifirst);
832  cpl_test_eq(100, ihalfcycle);
833  cpl_propertylist_delete(prop);
834  }
835 
836  {
837  int ifirst = 0, ihalfcycle = 0;
838  cpl_propertylist * prop =
839  create_property_list("2011-08-13T23:10:16.0612",
840  "2011-08-13T23:13:38",
841  0.25, 0.02, 2);
842  visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
843  cpl_test_eq(94, ifirst);
844  cpl_test_eq(100, ihalfcycle);
845  cpl_propertylist_delete(prop);
846  }
847 
848  {
849  int ifirst = 0, ihalfcycle = 0;
850  cpl_propertylist * prop =
851  create_property_list("2011-08-13T23:13:35.9999",
852  "2011-08-13T23:10:16",
853  0.25, 0.02, 0);
854  visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
855  cpl_test_eq(0, ifirst);
856  cpl_test_eq(100, ihalfcycle);
857  cpl_propertylist_delete(prop);
858  }
859  /* ichopchange > ihalfcycle testcase in visir_img_check_load_burst */
860 
861  if (stream != stdout) cpl_test_zero( fclose(stream) );
862 
863 }
864 
865 static cpl_imagelist * create_input_imagelist(const int * values, int naxis3)
866 {
867  cpl_imagelist * list = cpl_imagelist_new();
868  for (int i = 0; i < naxis3; i++) {
869  cpl_image * image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE,
870  CPL_TYPE_INT);
871  cpl_image_set(image, 1, 1, values[i]);
872  cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
873  }
874  return list;
875 }
876 
877 static void visir_img_check_load_burst(void)
878 {
879  FILE * stream;
880 
881  stream = cpl_msg_get_level() > CPL_MSG_INFO
882  ? fopen("/dev/null", "a") : stdout;
883 
884  cpl_test_nonnull( stream );
885 
886  /* large data test */
887  {
888  cpl_imagelist * list = cpl_imagelist_new();
889  cpl_imagelist * blist = cpl_imagelist_new();
890  cpl_imagelist * alist = cpl_imagelist_new();
891  cpl_propertylist * prop;
892  int naxis3 = 100;
893  int ichopchange = 0, ihalfcycle = 0;
894 
895  prop = create_property_list("2011-08-13T23:11:04.0000",
896  "2011-08-13T23:10:00", 0.1, 1, 0);
897  // chopstart 6
898  visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
899  cpl_test_eq(6, ichopchange);
900  cpl_test_eq(5, ihalfcycle);
901 
902  for (int i = 0; i < naxis3; i++) {
903  cpl_image * image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE,
904  CPL_TYPE_INT);
905  cpl_image_set(image, 1, 1, 0xA);
906 
907  cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
908  }
909  /* mark images to skip bad (1, 6, 11, 16, ...) */
910  for (int i = 0; i< 20; i++) {
911  cpl_image * img =
912  cpl_imagelist_get(list,
913  i * ihalfcycle + (ichopchange % ihalfcycle));
914  cpl_image_set(img, 1, 1, 0xBADBEEF);
915  }
916 
917  visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
918  cpl_test_eq(40, cpl_imagelist_get_size(alist));
919  cpl_test_eq(40, cpl_imagelist_get_size(blist));
920 
921  TEST_LIST(alist, 0xA);
922  TEST_LIST(blist, 0xA);
923 
924  cpl_imagelist_delete(alist);
925  cpl_imagelist_delete(blist);
926  cpl_imagelist_delete(list);
927  cpl_propertylist_delete(prop);
928  }
929 
930 
931  /* detailed test small data */
932  {
933  cpl_imagelist * alist = cpl_imagelist_new();
934  cpl_imagelist * blist = cpl_imagelist_new();
935  cpl_propertylist * prop;
936  const int values[] = {0xB, 0xBADBEEF, 0xA, 0xA, 0xA, 0xA, 0xBADBEEF,
937  0xB, 0xB, 0xB, 0xB, 0xBADBEEF};
938  int naxis3 =sizeof(values)/sizeof(values[0]);
939  int ichopchange = 0, ihalfcycle = 0;
940  cpl_imagelist * list = create_input_imagelist(values, naxis3);
941 
942  // halfcycle 5, chopstart 6
943  prop = create_property_list("2011-08-13T23:11:04.0000",
944  "2011-08-13T23:10:00", 0.1, 1, 0);
945  visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
946  cpl_test_eq(6, ichopchange);
947  cpl_test_eq(5, ihalfcycle);
948 
949  visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
950  cpl_test_eq(4, cpl_imagelist_get_size(alist));
951  cpl_test_eq(5, cpl_imagelist_get_size(blist));
952 
953  TEST_LIST(alist, 0xA);
954  TEST_LIST(blist, 0xB);
955 
956  cpl_imagelist_delete(list);
957 
958  /* test trimming */
959 
960  list = create_input_imagelist(values, naxis3);
961  cpl_imagelist_empty(alist);
962  cpl_imagelist_empty(blist);
963 
964  visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 1, 1);
965  cpl_test_eq(2, cpl_imagelist_get_size(alist));
966  cpl_test_eq(2, cpl_imagelist_get_size(blist));
967 
968  TEST_LIST(alist, 0xA);
969  TEST_LIST(blist, 0xB);
970 
971  cpl_imagelist_delete(list);
972 
973  /* test trimming ichopchange % ihalfcycle - trim < 0*/
974 
975  list = create_input_imagelist(values, naxis3);
976  cpl_imagelist_empty(alist);
977  cpl_imagelist_empty(blist);
978 
979  visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 2, 1);
980  cpl_test_eq(1, cpl_imagelist_get_size(alist));
981  cpl_test_eq(1, cpl_imagelist_get_size(blist));
982 
983  TEST_LIST(alist, 0xA);
984  TEST_LIST(blist, 0xB);
985 
986  cpl_imagelist_delete(list);
987 
988  /* test full chop/trim range*/
989 
990  for (int i = 0; i < ihalfcycle * 2; i++) {
991  for (int h = 0; h < ihalfcycle / 2; h++) {
992  for (int l = 0; l < ihalfcycle / 2; l++) {
993  list = create_input_imagelist(values, naxis3);
994  cpl_imagelist_empty(alist);
995  cpl_imagelist_empty(blist);
996 
997  visir_load_burst_(alist, blist, list, i, ihalfcycle, l, h);
998  // FIXME: test non trim case too
999  while (cpl_imagelist_get_size(alist) < cpl_imagelist_get_size(blist))
1000  cpl_image_delete(cpl_imagelist_unset(blist, cpl_imagelist_get_size(blist) - 1));
1001  while (cpl_imagelist_get_size(alist) > cpl_imagelist_get_size(blist))
1002  cpl_image_delete(cpl_imagelist_unset(alist, cpl_imagelist_get_size(alist) - 1));
1003  cpl_test_eq(4 - (h + l), cpl_imagelist_get_size(alist));
1004  cpl_test_eq(4 - (h + l), cpl_imagelist_get_size(blist));
1005 
1006  cpl_imagelist_delete(list);
1007  }
1008  }
1009  }
1010 
1011  cpl_imagelist_delete(alist);
1012  cpl_imagelist_delete(blist);
1013  cpl_propertylist_delete(prop);
1014  }
1015 
1016  /* test assymmetric rejects */
1017  {
1018  cpl_imagelist * blist = cpl_imagelist_new();
1019  cpl_imagelist * alist = cpl_imagelist_new();
1020  const int values[] = {0, 1, 1, 0, 0, 0xBAD, 0, 1, 1, 0, 0, 0xBAD, 0, 1};
1021  int naxis3 = sizeof(values)/sizeof(values[0]);
1022  int ichopchange = 5, ihalfcycle = 6;
1023  cpl_imagelist * list = create_input_imagelist(values, naxis3);
1024 
1025  visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 2, 1);
1026  cpl_test_eq(3, cpl_imagelist_get_size(alist));
1027  cpl_test_eq(2, cpl_imagelist_get_size(blist));
1028 
1029  TEST_LIST(alist, 1);
1030  TEST_LIST(blist, 1);
1031 
1032  cpl_imagelist_delete(list);
1033  cpl_imagelist_delete(alist);
1034  cpl_imagelist_delete(blist);
1035  }
1036 
1037  /* sliced with chopchange in first half cycle */
1038  {
1039  cpl_imagelist * blist = cpl_imagelist_new();
1040  cpl_imagelist * alist = cpl_imagelist_new();
1041  cpl_propertylist * prop;
1042  const int values[] = {0xA, 0xBADBEEF, 0xB, 0xB, 0xB, 0xB, 0xBADBEEF,
1043  0xA, 0xA, 0xA, 0xA, 0xBADBEEF};
1044  int naxis3 = sizeof(values)/sizeof(values[0]);
1045  int ichopchange = 0, ihalfcycle = 0;
1046  cpl_imagelist * list = create_input_imagelist(values, naxis3);
1047 
1048  // halfcycle 5, chopstart 1
1049  prop = create_property_list("2011-08-13T23:11:09.0000",
1050  "2011-08-13T23:10:00", 0.1, 1, 0);
1051  visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
1052  cpl_test_eq(1, ichopchange);
1053  cpl_test_eq(5, ihalfcycle);
1054 
1055  visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
1056  cpl_test_eq(5, cpl_imagelist_get_size(alist));
1057  cpl_test_eq(4, cpl_imagelist_get_size(blist));
1058 
1059  TEST_LIST(alist, 0xA);
1060  TEST_LIST(blist, 0xB);
1061 
1062  cpl_imagelist_delete(list);
1063  cpl_imagelist_delete(alist);
1064  cpl_imagelist_delete(blist);
1065  cpl_propertylist_delete(prop);
1066  }
1067 
1068  {
1069  cpl_imagelist * blist = cpl_imagelist_new();
1070  cpl_imagelist * alist = cpl_imagelist_new();
1071  cpl_propertylist * prop;
1072  const int values[] = {0xBADBEEF, 0xB, 0xB, 0xB, 0xB, 0xBADBEEF,
1073  0xA, 0xA, 0xA, 0xA, 0xBADBEEF, 0xB};
1074  int naxis3 = sizeof(values)/sizeof(values[0]);
1075  int ichopchange = 0, ihalfcycle = 0;
1076  cpl_imagelist * list = create_input_imagelist(values, naxis3);
1077 
1078  // halfcycle 5, chopstart 0
1079  prop = create_property_list("2011-08-13T23:10:00.0000",
1080  "2011-08-13T23:10:00", 0.1, 1, 0);
1081  visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
1082  cpl_test_eq(0, ichopchange);
1083  cpl_test_eq(5, ihalfcycle);
1084 
1085  visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
1086  cpl_test_eq(4, cpl_imagelist_get_size(alist));
1087  cpl_test_eq(5, cpl_imagelist_get_size(blist));
1088 
1089  TEST_LIST(alist, 0xA);
1090  TEST_LIST(blist, 0xB);
1091 
1092  cpl_imagelist_delete(list);
1093  cpl_imagelist_delete(alist);
1094  cpl_imagelist_delete(blist);
1095  cpl_propertylist_delete(prop);
1096  }
1097 
1098  {
1099  const char * fn = "load_burst.fits";
1100  cpl_imagelist * blist = cpl_imagelist_new();
1101  cpl_imagelist * alist = cpl_imagelist_new();
1102  cpl_propertylist * prop = cpl_propertylist_new();
1103  cpl_frame * frame = cpl_frame_new();
1104  const int values[] = {0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA};
1105  int naxis3 = sizeof(values)/sizeof(values[0]);
1106  cpl_imagelist * list = create_input_imagelist(values, naxis3);
1107 
1108  cpl_propertylist_append_bool(prop, VISIR_PFITS_BOOL_CHOP_STATUS, CPL_FALSE);
1109  cpl_imagelist_save(list, fn, CPL_TYPE_UNSPECIFIED,
1110  prop, CPL_IO_CREATE);
1111  cpl_propertylist_delete(prop);
1112  prop = cpl_propertylist_load(fn, 0);
1113  cpl_frame_set_filename(frame, fn);
1114 
1115  // TODO reenable when chop st is fixed
1116  //visir_load_burst(alist, blist, frame, prop, 0, naxis3, 0, naxis3, 0, 0);
1117  //cpl_test_eq(naxis3, cpl_imagelist_get_size(alist));
1118  //cpl_test_eq(0, cpl_imagelist_get_size(blist));
1119 
1120  TEST_LIST(alist, 0xA);
1121 
1122  cpl_imagelist_delete(list);
1123  cpl_imagelist_delete(alist);
1124  cpl_imagelist_delete(blist);
1125  cpl_propertylist_delete(prop);
1126  cpl_frame_delete(frame);
1127  unlink(fn);
1128  }
1129 
1130  if (stream != stdout) cpl_test_zero( fclose(stream) );
1131 
1132 }
1133 
1134 
1135 static void visir_img_check_get_to_off_plane(void)
1136 {
1137 
1138  FILE * stream;
1139 
1140  stream = cpl_msg_get_level() > CPL_MSG_INFO
1141  ? fopen("/dev/null", "a") : stdout;
1142 
1143  cpl_test_nonnull( stream );
1144 
1145  {
1146  /* cc < hc tests */
1147  int icc = 27;
1148  int istart = 0;
1149  int ihc = 100;
1150  cpl_test_eq(27, get_to_off_plane(icc, istart, ihc));
1151 
1152  istart = 10;
1153  cpl_test_eq(17, get_to_off_plane(icc, istart, ihc));
1154 
1155  istart = icc;
1156  cpl_test_eq(0, get_to_off_plane(icc, istart, ihc));
1157 
1158  istart = 50;
1159  cpl_test_eq(177, get_to_off_plane(icc, istart, ihc));
1160 
1161  istart = ihc;
1162  cpl_test_eq(127, get_to_off_plane(icc, istart, ihc));
1163 
1164  istart = ihc + icc;
1165  cpl_test_eq(100, get_to_off_plane(icc, istart, ihc));
1166 
1167  istart = 150;
1168  cpl_test_eq(77, get_to_off_plane(icc, istart, ihc));
1169 
1170  istart = ihc * 2;
1171  cpl_test_eq(27, get_to_off_plane(icc, istart, ihc));
1172 
1173  istart = ihc * 2 + 10;
1174  cpl_test_eq(17, get_to_off_plane(icc, istart, ihc));
1175 
1176  istart = ihc * 2 + 50;
1177  cpl_test_eq(177, get_to_off_plane(icc, istart, ihc));
1178 
1179  istart = 50;
1180  ihc = 80;
1181  cpl_test_eq(139, get_to_off_plane(29, istart, ihc));
1182 
1183  /* cc > hc tests */
1184  icc = 157;
1185  istart = 240;
1186  ihc = 80;
1187  cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
1188 
1189  istart = 230;
1190  cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
1191 
1192  istart = 160;
1193  cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
1194 
1195  istart = 150;
1196  cpl_test_eq(157 - istart, get_to_off_plane(icc, istart, ihc));
1197 
1198  istart = 320;
1199  cpl_test_eq(477 - istart, get_to_off_plane(icc, istart, ihc));
1200 
1201  istart = 310;
1202  cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
1203 
1204  /* cc == hc tests */
1205  icc = 80;
1206  istart = 0;
1207  ihc = 80;
1208  cpl_test_eq(80, get_to_off_plane(icc, istart, ihc));
1209 
1210  istart = 80;
1211  cpl_test_eq(0, get_to_off_plane(icc, istart, ihc));
1212 
1213  istart = 160;
1214  cpl_test_eq(80, get_to_off_plane(icc, istart, ihc));
1215 
1216  istart = 240;
1217  cpl_test_eq(0, get_to_off_plane(icc, istart, ihc));
1218 
1219  istart = 30;
1220  cpl_test_eq(50, get_to_off_plane(icc, istart, ihc));
1221 
1222  istart = 130;
1223  cpl_test_eq(110, get_to_off_plane(icc, istart, ihc));
1224  }
1225 
1226  if (stream != stdout) cpl_test_zero( fclose(stream) );
1227 }
1228 
1229 /* creates cube2 formated list, length 2*n + 1 */
1230 static cpl_imagelist * create_cube2_imagelist(int ncycles)
1231 {
1232  cpl_imagelist * list = cpl_imagelist_new();
1233  cpl_image * image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
1234  float prev_val = 0.0;
1235 
1236  for (int i = 0; i < ncycles; i++) {
1237  const float val = (prev_val * i + A_VAL - B_VAL) / (i + 1);
1238  cpl_image_set(image, 1, 1, A_VAL - VISIR_HCYCLE_OFFSET);
1239  cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
1240  image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
1241 
1242  cpl_image_set(image, 1, 1, val);
1243  cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
1244  image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
1245  prev_val = val;
1246  }
1247 
1248  cpl_image_set(image, 1, 1, prev_val);
1249  cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
1250  return list;
1251 }
1252 
1253 static void visir_img_check_load_cube2(void)
1254 {
1255 
1256  FILE * stream;
1257 
1258  stream = cpl_msg_get_level() > CPL_MSG_INFO
1259  ? fopen("/dev/null", "a") : stdout;
1260 
1261  cpl_test_nonnull( stream );
1262 
1263  {
1264  const int ncycles = 20;
1265  cpl_imagelist * list = create_cube2_imagelist(ncycles);
1266  cpl_imagelist * alist = cpl_imagelist_new();
1267  cpl_imagelist * blist = cpl_imagelist_new();
1268  cpl_test_eq(2 * ncycles + 1, cpl_imagelist_get_size(list));
1269 
1270  /* strip the sum */
1271  cpl_image_delete(cpl_imagelist_unset(list, cpl_imagelist_get_size(list) - 1));
1272 
1273  visir_load_cube2_split_(alist, blist, list, NULL);
1274  cpl_test_eq(ncycles, cpl_imagelist_get_size(alist));
1275  cpl_test_eq(ncycles, cpl_imagelist_get_size(blist));
1276  TEST_LIST(alist, A_VAL);
1277  TEST_LIST(blist, B_VAL);
1278 
1279  cpl_imagelist_delete(list);
1280  cpl_imagelist_delete(alist);
1281  cpl_imagelist_delete(blist);
1282  }
1283 
1284  /* test chunks */
1285  {
1286  const int ncycles = 40;
1287  cpl_image * prevd;
1288  cpl_imagelist * list = create_cube2_imagelist(ncycles);
1289  cpl_imagelist * alist = cpl_imagelist_new();
1290  cpl_imagelist * blist = cpl_imagelist_new();
1291  cpl_imagelist * chunk2 = cpl_imagelist_new();
1292 
1293  cpl_test_eq(2 * ncycles + 1, cpl_imagelist_get_size(list));
1294 
1295  /* strip the sum */
1296  cpl_image_delete(cpl_imagelist_unset(list,
1297  cpl_imagelist_get_size(list) - 1));
1298 
1299  for (int i = ncycles; i > 0; i--) {
1300  cpl_image * tmp =
1301  cpl_imagelist_unset(list, cpl_imagelist_get_size(list) - i);
1302  cpl_imagelist_set(chunk2, tmp, cpl_imagelist_get_size(chunk2));
1303  }
1304  prevd =
1305  cpl_image_duplicate(cpl_imagelist_get(list,
1306  cpl_imagelist_get_size(list) - 1));
1307 
1308  visir_load_cube2_split_(alist, blist, list, NULL);
1309  cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(alist));
1310  cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(blist));
1311  TEST_LIST(alist, A_VAL);
1312  TEST_LIST(blist, B_VAL);
1313 
1314  cpl_imagelist_empty(alist);
1315  cpl_imagelist_empty(blist);
1316 
1317  visir_load_cube2_split_(alist, blist, chunk2, prevd);
1318  cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(alist));
1319  cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(blist));
1320  TEST_LIST(alist, A_VAL);
1321  TEST_LIST(blist, B_VAL);
1322 
1323  cpl_imagelist_delete(list);
1324  cpl_imagelist_delete(chunk2);
1325  cpl_imagelist_delete(alist);
1326  cpl_imagelist_delete(blist);
1327  cpl_image_delete(prevd);
1328  }
1329 
1330  if (stream != stdout) cpl_test_zero( fclose(stream) );
1331 }
int main(void)
Find a plugin and submit it to some tests.
Definition: recipe_main.c:61