00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023
00024
00025
00026
00027
00028 #include <visir_inputs.h>
00029
00030 #include "visir_inputs.c"
00031
00032 #include <unistd.h>
00033
00034
00035
00036
00037
00038 #ifndef BOX_SIZE
00039 #define BOX_SIZE 11
00040 #endif
00041
00042 #ifndef LINE_SIZE
00043 #define LINE_SIZE BOX_SIZE
00044 #endif
00045
00046 #define TEST_LIST(list, value) \
00047 do { \
00048 for (int i = 0; i < cpl_imagelist_get_size((list)); i++) { \
00049 int b; \
00050 const cpl_image * image = cpl_imagelist_get_const((list), i); \
00051 cpl_test_eq((value), cpl_image_get(image, 1, 1, &b)); \
00052 } \
00053 } \
00054 while(0)
00055
00056 #define A_VAL 4.
00057 #define B_VAL 3.
00058
00059
00060
00061
00062
00063 static void visir_img_check_box_test(void);
00064 static void visir_img_check_align_test(void);
00065 static void visir_img_check_line_test(void);
00066 static void visir_check_get_type(void);
00067 static void visir_img_check_burst_find_delta_chop(void);
00068 static void visir_img_check_load_burst(void);
00069 static void visir_img_check_get_to_off_plane(void);
00070 static void visir_img_check_load_cube2(void);
00071
00072 static cpl_propertylist * create_property_list(const char *,
00073 const char *,
00074 const double,
00075 const double,
00076 const double);
00077 static cpl_imagelist * create_cube2_imagelist(int);
00078 static cpl_imagelist * create_input_imagelist(const int *, int);
00079
00080
00081
00085
00086
00087
00088
00092
00093 int main(void)
00094 {
00095
00096 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00097
00098 visir_img_check_line_test();
00099 visir_img_check_align_test();
00100 visir_img_check_box_test();
00101 visir_check_get_type();
00102 visir_img_check_burst_find_delta_chop();
00103 visir_img_check_load_burst();
00104 visir_img_check_get_to_off_plane();
00105 visir_img_check_load_cube2();
00106
00107 return cpl_test_end(0);
00108
00109 }
00110
00111
00112
00113 static void visir_img_check_box_test(void)
00114 {
00115
00116 cpl_image * image;
00117 const double sigma = 1.0;
00118 cpl_apertures * appos;
00119 cpl_apertures * apneg;
00120 double ecc;
00121 cpl_boolean swapp, swapn;
00122 FILE * stream;
00123 cpl_error_code error = CPL_ERROR_NONE;
00124 int i, j;
00125
00126 stream = cpl_msg_get_level() > CPL_MSG_INFO
00127 ? fopen("/dev/null", "a") : stdout;
00128
00129 cpl_test_nonnull( stream );
00130
00131 image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE, CPL_TYPE_INT);
00132
00133
00134 for (j = -1; j <= 1; j++) {
00135 for (i = -1; i <= 1; i++) {
00136 error |= cpl_image_set(image, BOX_SIZE + i, BOX_SIZE + j, -1.0);
00137 error |= cpl_image_set(image, 2*BOX_SIZE + i, 2*BOX_SIZE + j, -1.0);
00138 error |= cpl_image_set(image, BOX_SIZE + i, 2*BOX_SIZE + j, 1.0);
00139 error |= cpl_image_set(image, 2*BOX_SIZE + i, BOX_SIZE + j, 1.0);
00140 cpl_test_eq_error(error, CPL_ERROR_NONE);
00141 }
00142 }
00143
00144 appos = cpl_apertures_extract_sigma(image, sigma);
00145 cpl_test_error(CPL_ERROR_NONE);
00146 cpl_test_nonnull(appos);
00147 cpl_test_eq(cpl_apertures_get_size(appos), 2);
00148
00149 cpl_apertures_dump(appos, stream);
00150
00151 error = cpl_image_multiply_scalar(image, -1.0);
00152 cpl_test_eq_error(error, CPL_ERROR_NONE);
00153
00154 apneg = cpl_apertures_extract_sigma(image, sigma);
00155 cpl_test_error(CPL_ERROR_NONE);
00156 cpl_test_nonnull(apneg);
00157 cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00158
00159 cpl_apertures_dump(apneg, stream);
00160
00161
00162 ecc = visir_img_check_box(NULL, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
00163 &swapp, &swapn);
00164 cpl_test_error(CPL_ERROR_NULL_INPUT);
00165
00166 ecc = visir_img_check_box(appos, 1, 2, NULL, 1, 2, BOX_SIZE, 0.,
00167 &swapp, &swapn);
00168 cpl_test_error(CPL_ERROR_NULL_INPUT);
00169
00170 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
00171 &swapp, NULL);
00172 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00173
00174 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
00175 NULL, &swapn);
00176 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00177
00178 ecc = visir_img_check_box(appos, 1, 2, appos, 1, 2, BOX_SIZE, 0.,
00179 &swapp, &swapn);
00180 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00181
00182 ecc = visir_img_check_box(appos, 0, 2, apneg, 1, 2, BOX_SIZE, 0.,
00183 &swapp, &swapn);
00184 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00185
00186 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 0, BOX_SIZE, 0.,
00187 &swapp, &swapn);
00188 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00189
00190 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 3, BOX_SIZE, 0.,
00191 &swapp, &swapn);
00192 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
00193
00194 ecc = visir_img_check_box(appos, 3, 2, apneg, 1, 2, BOX_SIZE, 0.,
00195 &swapp, &swapn);
00196 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
00197
00198 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, 0.0, 0., &swapp, &swapn);
00199 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00200
00201
00202 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE, 0.,
00203 &swapp, &swapn);
00204 cpl_test_error(CPL_ERROR_NONE);
00205
00206 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00207 cpl_test(swapp);
00208 cpl_test_zero(swapn);
00209
00210
00211 ecc = visir_img_check_box(appos, 2, 1, apneg, 2, 1, BOX_SIZE, 0.,
00212 &swapp, &swapn);
00213 cpl_test_error(CPL_ERROR_NONE);
00214
00215 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00216 cpl_test_zero(swapp);
00217 cpl_test(swapn);
00218
00219
00220 ecc = visir_img_check_box(apneg, 1, 2, appos, 1, 2, BOX_SIZE, 0.,
00221 &swapp, &swapn);
00222 cpl_test_error(CPL_ERROR_NONE);
00223
00224 cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
00225 cpl_test_zero(swapp);
00226 cpl_test(swapn);
00227
00228
00229 ecc = visir_img_check_box(apneg, 2, 1, appos, 2, 1, BOX_SIZE, 0.,
00230 &swapp, &swapn);
00231 cpl_test_error(CPL_ERROR_NONE);
00232
00233 cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
00234 cpl_test(swapp);
00235 cpl_test_zero(swapn);
00236
00237 cpl_image_delete(image);
00238 cpl_apertures_delete(appos);
00239 cpl_apertures_delete(apneg);
00240
00241
00242 image = cpl_image_new(600, 600, CPL_TYPE_INT);
00243 double throw = 220;
00244
00245
00246 for (j = -1; j <= 1; j++) {
00247 for (i = -1; i <= 1; i++) {
00248 cpl_image_set(image, 350 + i, 80 + j, 1.0);
00249 cpl_image_set(image, 350 + i, 400 + j, 1.0);
00250 cpl_image_set(image, 190 + i, 240 + j, -1.0);
00251 cpl_image_set(image, 510 + i, 240 + j, -1.0);
00252 }
00253 }
00254
00255 appos = cpl_apertures_extract_sigma(image, sigma);
00256 cpl_image_multiply_scalar(image, -1.0);
00257 apneg = cpl_apertures_extract_sigma(image, sigma);
00258
00259 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, throw,
00260 45. * CPL_MATH_RAD_DEG,
00261 &swapp, &swapn);
00262 cpl_test_error(CPL_ERROR_NONE);
00263
00264 cpl_test_rel(ecc, 0.057, 0.1);
00265 cpl_test(swapp);
00266 cpl_test_zero(swapn);
00267
00268 cpl_image_delete(image);
00269 cpl_apertures_delete(appos);
00270 cpl_apertures_delete(apneg);
00271
00272
00273 image = cpl_image_new(600, 600, CPL_TYPE_INT);
00274
00275 for (j = -1; j <= 1; j++) {
00276 for (i = -1; i <= 1; i++) {
00277 cpl_image_set(image, 453 + i, 172 + j, 1.0);
00278 cpl_image_set(image, 373 + i, 470 + j, 1.0);
00279 cpl_image_set(image, 260 + i, 280 + j, -1.0);
00280 cpl_image_set(image, 570 + i, 360 + j, -1.0);
00281 }
00282 }
00283
00284 appos = cpl_apertures_extract_sigma(image, sigma);
00285 cpl_image_multiply_scalar(image, -1.0);
00286 apneg = cpl_apertures_extract_sigma(image, sigma);
00287
00288 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, throw,
00289 30. * CPL_MATH_RAD_DEG,
00290 &swapp, &swapn);
00291 cpl_test_error(CPL_ERROR_NONE);
00292
00293 cpl_test_rel(ecc, 0.049, 0.1);
00294 cpl_test(swapp);
00295 cpl_test_zero(swapn);
00296
00297 cpl_image_delete(image);
00298 cpl_apertures_delete(appos);
00299 cpl_apertures_delete(apneg);
00300
00301
00302 image = cpl_image_new(600, 600, CPL_TYPE_INT);
00303
00304 for (j = -1; j <= 1; j++) {
00305 for (i = -1; i <= 1; i++) {
00306 cpl_image_set(image, 363 + i, 396 + j, 1.0);
00307 cpl_image_set(image, 156 + i, 159 + j, 1.0);
00308 cpl_image_set(image, 138 + i, 382 + j, -1.0);
00309 cpl_image_set(image, 381 + i, 175 + j, -1.0);
00310 }
00311 }
00312
00313 appos = cpl_apertures_extract_sigma(image, sigma);
00314 cpl_image_multiply_scalar(image, -1.0);
00315 apneg = cpl_apertures_extract_sigma(image, sigma);
00316
00317 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, throw,
00318 85. * CPL_MATH_RAD_DEG,
00319 &swapp, &swapn);
00320 cpl_test_error(CPL_ERROR_NONE);
00321
00322 cpl_test_rel(ecc, 0.049, 0.1);
00323 cpl_test(swapp);
00324
00325
00326
00327 cpl_image_delete(image);
00328 cpl_apertures_delete(appos);
00329 cpl_apertures_delete(apneg);
00330
00331 if (stream != stdout) cpl_test_zero( fclose(stream) );
00332
00333 }
00334
00335 static void visir_img_check_align_test(void)
00336 {
00337
00338 FILE * stream;
00339 cpl_error_code error = CPL_ERROR_NONE;
00340 int idir;
00341 cpl_boolean is_hor = CPL_FALSE;
00342
00343 stream = cpl_msg_get_level() > CPL_MSG_INFO
00344 ? fopen("/dev/null", "a") : stdout;
00345
00346 cpl_test_nonnull( stream );
00347
00348 for (idir = 0; idir < 2; idir++, is_hor = CPL_TRUE) {
00349 cpl_image * image = cpl_image_new(4 * LINE_SIZE, 4 * LINE_SIZE,
00350 CPL_TYPE_INT);
00351 const double sigma = 1.0;
00352 cpl_apertures * appos;
00353 cpl_apertures * apneg;
00354 double ecc;
00355 cpl_boolean swapn, swapn2;
00356 int i, j;
00357 double dhor = 90 * CPL_MATH_RAD_DEG;
00358
00359
00360
00361 for (j = -1; j <= 1; j++) {
00362 for (i = -1; i <= 1; i++) {
00363 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00364 2*LINE_SIZE + j, 1.0);
00365
00366 if (is_hor) {
00367 error |= cpl_image_set(image, LINE_SIZE + i,
00368 2*LINE_SIZE + j, -1.0);
00369 error |= cpl_image_set(image, 3*LINE_SIZE + i,
00370 2*LINE_SIZE + j, -1.0);
00371 } else {
00372 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00373 LINE_SIZE + j, -1.0);
00374 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00375 3*LINE_SIZE + j, -1.0);
00376 }
00377 cpl_test_eq_error(error, CPL_ERROR_NONE);
00378 }
00379 }
00380
00381 appos = cpl_apertures_extract_sigma(image, sigma);
00382 cpl_test_error(CPL_ERROR_NONE);
00383 cpl_test_nonnull(appos);
00384 cpl_test_eq(cpl_apertures_get_size(appos), 1);
00385
00386 cpl_apertures_dump(appos, stream);
00387
00388 error = cpl_image_multiply_scalar(image, -1.0);
00389 cpl_test_eq_error(error, CPL_ERROR_NONE);
00390
00391 apneg = cpl_apertures_extract_sigma(image, sigma);
00392 cpl_test_error(CPL_ERROR_NONE);
00393 cpl_test_nonnull(apneg);
00394 cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00395
00396 cpl_apertures_dump(apneg, stream);
00397
00398
00399 ecc = visir_img_check_align(NULL, 1, apneg, 1, 2, LINE_SIZE, 0.,
00400 &swapn);
00401 cpl_test_error(CPL_ERROR_NULL_INPUT);
00402
00403 ecc = visir_img_check_align(appos, 1, NULL, 1, 2, LINE_SIZE, 0.,
00404 &swapn);
00405 cpl_test_error(CPL_ERROR_NULL_INPUT);
00406
00407 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, 0.,
00408 NULL);
00409 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00410
00411 ecc = visir_img_check_align(appos, 0, apneg, 1, 2, LINE_SIZE, 0.,
00412 &swapn);
00413 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00414
00415 ecc = visir_img_check_align(appos, 1, apneg, 1, 0, LINE_SIZE, 0.,
00416 &swapn);
00417 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00418
00419 ecc = visir_img_check_align(appos, 1, apneg, 0, 1, LINE_SIZE, 0.,
00420 &swapn);
00421 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00422
00423 ecc = visir_img_check_align(appos, 1, apneg, 1, 3, LINE_SIZE, 0.,
00424 &swapn);
00425 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
00426
00427 ecc = visir_img_check_align(appos, 3, apneg, 1, 2, LINE_SIZE, 0.,
00428 &swapn);
00429 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
00430
00431 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, 0.0, 0., &swapn);
00432 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00433
00434
00435 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE,
00436 is_hor ? dhor : 0., &swapn);
00437 cpl_test_error(CPL_ERROR_NONE);
00438
00439 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00440 cpl_test_zero(swapn);
00441
00442
00443 ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE,
00444 is_hor ? dhor : 0., &swapn);
00445 cpl_test_error(CPL_ERROR_NONE);
00446
00447 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00448 cpl_test(swapn);
00449
00450
00451 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE,
00452 !is_hor ? dhor : 0., &swapn);
00453 cpl_test_error(CPL_ERROR_NONE);
00454
00455 cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00456
00457
00458 ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE,
00459 !is_hor ? dhor : 0. ,&swapn2);
00460 cpl_test_error(CPL_ERROR_NONE);
00461
00462 cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00463
00464
00465
00466 cpl_image_delete(image);
00467 cpl_apertures_delete(appos);
00468 cpl_apertures_delete(apneg);
00469 }
00470
00471 if (stream != stdout) cpl_test_zero( fclose(stream) );
00472
00473 }
00474
00475 static void visir_img_check_line_test(void)
00476 {
00477
00478 FILE * stream;
00479 cpl_error_code error = CPL_ERROR_NONE;
00480 int idir;
00481 cpl_boolean is_hor = CPL_FALSE;
00482
00483 stream = cpl_msg_get_level() > CPL_MSG_INFO
00484 ? fopen("/dev/null", "a") : stdout;
00485
00486 cpl_test_nonnull( stream );
00487
00488 for (idir = 0; idir < 2; idir++, is_hor = CPL_TRUE) {
00489 cpl_image * image = cpl_image_new(4 * LINE_SIZE, 4 * LINE_SIZE,
00490 CPL_TYPE_INT);
00491 const double sigma = 1.0;
00492 cpl_apertures * appos;
00493 cpl_apertures * apneg;
00494 double ecc;
00495 int i, j;
00496 double dhor = 90 * CPL_MATH_RAD_DEG;
00497
00498
00499
00500 for (j = -1; j <= 1; j++) {
00501 for (i = -1; i <= 1; i++) {
00502 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00503 2*LINE_SIZE + j, 1.0);
00504
00505 if (is_hor) {
00506 error |= cpl_image_set(image, LINE_SIZE + i,
00507 2*LINE_SIZE + j, -1.0);
00508 error |= cpl_image_set(image, 3*LINE_SIZE + i,
00509 2*LINE_SIZE + j, -1.0);
00510 } else {
00511 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00512 LINE_SIZE + j, -1.0);
00513 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00514 3*LINE_SIZE + j, -1.0);
00515 }
00516 cpl_test_eq_error(error, CPL_ERROR_NONE);
00517 }
00518 }
00519
00520 appos = cpl_apertures_extract_sigma(image, sigma);
00521 cpl_test_error(CPL_ERROR_NONE);
00522 cpl_test_nonnull(appos);
00523 cpl_test_eq(cpl_apertures_get_size(appos), 1);
00524
00525 cpl_apertures_dump(appos, stream);
00526
00527 error = cpl_image_multiply_scalar(image, -1.0);
00528 cpl_test_eq_error(error, CPL_ERROR_NONE);
00529
00530 apneg = cpl_apertures_extract_sigma(image, sigma);
00531 cpl_test_error(CPL_ERROR_NONE);
00532 cpl_test_nonnull(apneg);
00533 cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00534
00535 cpl_apertures_dump(apneg, stream);
00536
00537
00538 ecc = visir_img_check_line(NULL, 1, apneg, 1, LINE_SIZE, 0.);
00539 cpl_test_error(CPL_ERROR_NULL_INPUT);
00540
00541 ecc = visir_img_check_line(appos, 1, NULL, 1, LINE_SIZE, 0.);
00542 cpl_test_error(CPL_ERROR_NULL_INPUT);
00543
00544 ecc = visir_img_check_line(appos, 0, apneg, 1, LINE_SIZE, 0.);
00545 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00546
00547 ecc = visir_img_check_line(appos, 1, apneg, 0, LINE_SIZE, 0.);
00548 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00549
00550 ecc = visir_img_check_line(appos, 1, apneg, 0, LINE_SIZE, 0.);
00551 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00552
00553 ecc = visir_img_check_line(appos, 1, apneg, 3, LINE_SIZE, 0.);
00554 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
00555
00556 ecc = visir_img_check_line(appos, 3, apneg, 1, LINE_SIZE, 0.);
00557 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
00558
00559 ecc = visir_img_check_line(appos, 1, apneg, 1, 0.0, 0.);
00560 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00561
00562
00563 ecc = visir_img_check_line(apneg, 1, appos, 1, LINE_SIZE,
00564 is_hor ? dhor : 0.);
00565 cpl_test_error(CPL_ERROR_NONE);
00566
00567 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00568
00569
00570 ecc = visir_img_check_line(appos, 1, apneg, 1, LINE_SIZE,
00571 is_hor ? dhor : 0.);
00572 cpl_test_error(CPL_ERROR_NONE);
00573
00574 cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00575
00576
00577 ecc = visir_img_check_line(appos, 1, apneg, 1, LINE_SIZE,
00578 !is_hor ? dhor : 0.);
00579 cpl_test_error(CPL_ERROR_NONE);
00580
00581 cpl_test_abs(ecc, CPL_MATH_SQRT2, FLT_EPSILON);
00582
00583
00584 ecc = visir_img_check_line(apneg, 1, appos, 1, LINE_SIZE,
00585 !is_hor ? dhor : 0.);
00586 cpl_test_error(CPL_ERROR_NONE);
00587
00588 cpl_test_abs(ecc, CPL_MATH_SQRT2, FLT_EPSILON);
00589
00590
00591
00592 cpl_image_delete(image);
00593 cpl_apertures_delete(appos);
00594 cpl_apertures_delete(apneg);
00595 }
00596
00597 if (stream != stdout) cpl_test_zero( fclose(stream) );
00598
00599 }
00600
00601 static void load_frame(const char * fn, cpl_frame ** frm,
00602 cpl_propertylist ** plist, const int iext)
00603 {
00604 *frm = cpl_frame_new();
00605 cpl_frame_set_filename(*frm, fn);
00606 *plist = cpl_propertylist_load(fn, iext);
00607 }
00608
00609
00610 static void visir_check_get_type(void)
00611 {
00612
00613 FILE * stream;
00614 const char * fn = "get_type_check.fits";
00615
00616 stream = cpl_msg_get_level() > CPL_MSG_INFO
00617 ? fopen("/dev/null", "a") : stdout;
00618
00619 cpl_propertylist * plist;
00620 cpl_imagelist * l;
00621 cpl_frame * frm;
00622 cpl_propertylist * lplist;
00623 cpl_size next;
00624 visir_data_type type;
00625
00626
00627 {
00628 l = cpl_imagelist_new();
00629 plist = cpl_propertylist_new();
00630 cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
00631 "CUBE1");
00632 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 2);
00633 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
00634 for (int i = 0; i < 4; i++)
00635 cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
00636 cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
00637 load_frame(fn, &frm, &lplist, 0);
00638
00639 visir_get_data_type(frm, lplist, &type, &next);
00640 cpl_test_error(CPL_ERROR_NONE);
00641 cpl_test_eq(VISIR_DATA_CUBE1, type);
00642 cpl_test_eq(0, next);
00643
00644 cpl_frame_delete(frm);
00645 cpl_propertylist_delete(lplist);
00646 cpl_imagelist_delete(l);
00647 cpl_propertylist_delete(plist);
00648 }
00649
00650
00651 {
00652 l = cpl_imagelist_new();
00653 plist = cpl_propertylist_new();
00654 cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
00655 "CUBE2");
00656 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
00657 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
00658 for (int i = 0; i < 5 * 2 + 1; i++)
00659 cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
00660 cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
00661 load_frame(fn, &frm, &lplist, 0);
00662
00663 visir_get_data_type(frm, lplist, &type, &next);
00664 cpl_test_error(CPL_ERROR_NONE);
00665 cpl_test_eq(VISIR_DATA_CUBE2, type);
00666 cpl_test_eq(0, next);
00667
00668 cpl_frame_delete(frm);
00669 cpl_propertylist_delete(lplist);
00670 cpl_imagelist_delete(l);
00671 cpl_propertylist_delete(plist);
00672 }
00673
00674
00675 {
00676 l = cpl_imagelist_new();
00677 plist = cpl_propertylist_new();
00678 cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
00679 "UNDEFINED");
00680 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
00681 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
00682 for (int i = 0; i < 5 * 2 * 10; i++)
00683 cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
00684 cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
00685 load_frame(fn, &frm, &lplist, 0);
00686
00687 visir_get_data_type(frm, lplist, &type, &next);
00688 cpl_test_error(CPL_ERROR_NONE);
00689 cpl_test_eq(VISIR_DATA_BURST, type);
00690 cpl_test_eq(0, next);
00691
00692 cpl_frame_delete(frm);
00693 cpl_propertylist_delete(lplist);
00694 cpl_imagelist_delete(l);
00695 cpl_propertylist_delete(plist);
00696 }
00697
00698
00699 {
00700 l = cpl_imagelist_new();
00701 plist = cpl_propertylist_new();
00702 cpl_propertylist_append_string(plist, VISIR_PFITS_STRING_FRAME_TYPE,
00703 "UNDEFINED");
00704 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
00705 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
00706 for (int i = 0; i < 5 * 2 * 10 - 10; i++)
00707 cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
00708 cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
00709 load_frame(fn, &frm, &lplist, 0);
00710
00711 visir_get_data_type(frm, lplist, &type, &next);
00712 cpl_test_error(CPL_ERROR_NONE);
00713 cpl_test_eq(VISIR_DATA_BURST, type);
00714 cpl_test_eq(0, next);
00715
00716 cpl_frame_delete(frm);
00717 cpl_propertylist_delete(lplist);
00718 cpl_imagelist_delete(l);
00719 cpl_propertylist_delete(plist);
00720 }
00721
00722
00723 {
00724 cpl_image * img = cpl_image_new(4, 4, CPL_TYPE_INT);
00725 plist = cpl_propertylist_new();
00726 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NAVRG, 1);
00727 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
00728 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
00729 cpl_propertylist_save(plist, fn, CPL_IO_CREATE);
00730 for (int i = 0; i < 5 * 2 + 1; i++)
00731 cpl_image_save(img, fn, CPL_TYPE_INT, NULL, CPL_IO_EXTEND);
00732 load_frame(fn, &frm, &lplist, 0);
00733
00734 visir_get_data_type(frm, lplist, &type, &next);
00735 cpl_test_error(CPL_ERROR_NONE);
00736 cpl_test_eq(VISIR_DATA_AQU_HCYCLE, type);
00737 cpl_test_eq(11, next);
00738
00739 cpl_frame_delete(frm);
00740 cpl_propertylist_delete(lplist);
00741 cpl_image_delete(img);
00742 cpl_propertylist_delete(plist);
00743 }
00744
00745
00746 {
00747 plist = cpl_propertylist_new();
00748 l = cpl_imagelist_new();
00749 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NAVRG, 1);
00750 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
00751 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
00752 for (int i = 0; i < 5 * 2 * 10; i++)
00753 cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
00754 cpl_imagelist_save(l, fn, CPL_TYPE_INT, plist, CPL_IO_CREATE);
00755 load_frame(fn, &frm, &lplist, 0);
00756
00757 visir_get_data_type(frm, lplist, &type, &next);
00758 cpl_test_error(CPL_ERROR_NONE);
00759 cpl_test_eq(VISIR_DATA_AQU_BURST, type);
00760 cpl_test_eq(0, next);
00761
00762 cpl_frame_delete(frm);
00763 cpl_propertylist_delete(lplist);
00764 cpl_imagelist_delete(l);
00765 cpl_propertylist_delete(plist);
00766 }
00767
00768
00769 {
00770 plist = cpl_propertylist_new();
00771 l = cpl_imagelist_new();
00772 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NAVRG, 1);
00773 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_CHOP_NCYCLES, 5);
00774 cpl_propertylist_append_int(plist, VISIR_PFITS_INT_NDIT, 10);
00775 cpl_propertylist_save(plist, fn, CPL_IO_CREATE);
00776 for (int i = 0; i < 5 * 2 * 10; i++)
00777 cpl_imagelist_set(l, cpl_image_new(4, 4, CPL_TYPE_INT), i);
00778 cpl_imagelist_save(l, fn, CPL_TYPE_INT, NULL, CPL_IO_EXTEND);
00779 load_frame(fn, &frm, &lplist, 0);
00780
00781 visir_get_data_type(frm, lplist, &type, &next);
00782 cpl_test_error(CPL_ERROR_NONE);
00783 cpl_test_eq(VISIR_DATA_AQU_BURST_EXT, type);
00784 cpl_test_eq(1, next);
00785
00786 cpl_frame_delete(frm);
00787 cpl_propertylist_delete(lplist);
00788 cpl_imagelist_delete(l);
00789 cpl_propertylist_delete(plist);
00790 }
00791
00792 unlink(fn);
00793 if (stream != stdout) cpl_test_zero( fclose(stream) );
00794 }
00795
00796 static cpl_propertylist * create_property_list(const char * obs_start,
00797 const char * chop_start,
00798 const double chop_freq,
00799 const double dit,
00800 const double nditskip)
00801 {
00802 cpl_propertylist * prop = cpl_propertylist_new();
00803 cpl_propertylist_append_string(prop, VISIR_PFITS_STRING_OBS_START,
00804 obs_start);
00805 cpl_propertylist_append_string(prop, VISIR_PFITS_STRING_CHOP_START,
00806 chop_start);
00807 cpl_propertylist_append_double(prop, VISIR_PFITS_DOUBLE_CHOP_FREQ,
00808 chop_freq);
00809 cpl_propertylist_append_double(prop, VISIR_PFITS_DOUBLE_DIT, dit);
00810 cpl_propertylist_append_int(prop, VISIR_PFITS_INT_NDITSKIP, nditskip);
00811 return prop;
00812 }
00813
00814 static void visir_img_check_burst_find_delta_chop(void)
00815 {
00816
00817 FILE * stream;
00818
00819 stream = cpl_msg_get_level() > CPL_MSG_INFO
00820 ? fopen("/dev/null", "a") : stdout;
00821
00822 cpl_test_nonnull( stream );
00823
00824 {
00825 int ifirst = 0, ihalfcycle = 0;
00826 cpl_propertylist * prop =
00827 create_property_list("2011-08-13T23:13:38.0612",
00828 "2011-08-13T23:10:16",
00829 0.25, 0.02, 2);
00830 visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
00831 cpl_test_eq(94, ifirst);
00832 cpl_test_eq(100, ihalfcycle);
00833 cpl_propertylist_delete(prop);
00834 }
00835
00836 {
00837 int ifirst = 0, ihalfcycle = 0;
00838 cpl_propertylist * prop =
00839 create_property_list("2011-08-13T23:10:16.0612",
00840 "2011-08-13T23:13:38",
00841 0.25, 0.02, 2);
00842 visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
00843 cpl_test_eq(94, ifirst);
00844 cpl_test_eq(100, ihalfcycle);
00845 cpl_propertylist_delete(prop);
00846 }
00847
00848 {
00849 int ifirst = 0, ihalfcycle = 0;
00850 cpl_propertylist * prop =
00851 create_property_list("2011-08-13T23:13:35.9999",
00852 "2011-08-13T23:10:16",
00853 0.25, 0.02, 0);
00854 visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
00855 cpl_test_eq(0, ifirst);
00856 cpl_test_eq(100, ihalfcycle);
00857 cpl_propertylist_delete(prop);
00858 }
00859
00860
00861 if (stream != stdout) cpl_test_zero( fclose(stream) );
00862
00863 }
00864
00865 static cpl_imagelist * create_input_imagelist(const int * values, int naxis3)
00866 {
00867 cpl_imagelist * list = cpl_imagelist_new();
00868 for (int i = 0; i < naxis3; i++) {
00869 cpl_image * image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE,
00870 CPL_TYPE_INT);
00871 cpl_image_set(image, 1, 1, values[i]);
00872 cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
00873 }
00874 return list;
00875 }
00876
00877 static void visir_img_check_load_burst(void)
00878 {
00879 FILE * stream;
00880
00881 stream = cpl_msg_get_level() > CPL_MSG_INFO
00882 ? fopen("/dev/null", "a") : stdout;
00883
00884 cpl_test_nonnull( stream );
00885
00886
00887 {
00888 cpl_imagelist * list = cpl_imagelist_new();
00889 cpl_imagelist * blist = cpl_imagelist_new();
00890 cpl_imagelist * alist = cpl_imagelist_new();
00891 cpl_propertylist * prop;
00892 int naxis3 = 100;
00893 int ichopchange = 0, ihalfcycle = 0;
00894
00895 prop = create_property_list("2011-08-13T23:11:04.0000",
00896 "2011-08-13T23:10:00", 0.1, 1, 0);
00897
00898 visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
00899 cpl_test_eq(6, ichopchange);
00900 cpl_test_eq(5, ihalfcycle);
00901
00902 for (int i = 0; i < naxis3; i++) {
00903 cpl_image * image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE,
00904 CPL_TYPE_INT);
00905 cpl_image_set(image, 1, 1, 0xA);
00906
00907 cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
00908 }
00909
00910 for (int i = 0; i< 20; i++) {
00911 cpl_image * img =
00912 cpl_imagelist_get(list,
00913 i * ihalfcycle + (ichopchange % ihalfcycle));
00914 cpl_image_set(img, 1, 1, 0xBADBEEF);
00915 }
00916
00917 visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
00918 cpl_test_eq(40, cpl_imagelist_get_size(alist));
00919 cpl_test_eq(40, cpl_imagelist_get_size(blist));
00920
00921 TEST_LIST(alist, 0xA);
00922 TEST_LIST(blist, 0xA);
00923
00924 cpl_imagelist_delete(alist);
00925 cpl_imagelist_delete(blist);
00926 cpl_imagelist_delete(list);
00927 cpl_propertylist_delete(prop);
00928 }
00929
00930
00931
00932 {
00933 cpl_imagelist * alist = cpl_imagelist_new();
00934 cpl_imagelist * blist = cpl_imagelist_new();
00935 cpl_propertylist * prop;
00936 const int values[] = {0xB, 0xBADBEEF, 0xA, 0xA, 0xA, 0xA, 0xBADBEEF,
00937 0xB, 0xB, 0xB, 0xB, 0xBADBEEF};
00938 int naxis3 =sizeof(values)/sizeof(values[0]);
00939 int ichopchange = 0, ihalfcycle = 0;
00940 cpl_imagelist * list = create_input_imagelist(values, naxis3);
00941
00942
00943 prop = create_property_list("2011-08-13T23:11:04.0000",
00944 "2011-08-13T23:10:00", 0.1, 1, 0);
00945 visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
00946 cpl_test_eq(6, ichopchange);
00947 cpl_test_eq(5, ihalfcycle);
00948
00949 visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
00950 cpl_test_eq(4, cpl_imagelist_get_size(alist));
00951 cpl_test_eq(5, cpl_imagelist_get_size(blist));
00952
00953 TEST_LIST(alist, 0xA);
00954 TEST_LIST(blist, 0xB);
00955
00956 cpl_imagelist_delete(list);
00957
00958
00959
00960 list = create_input_imagelist(values, naxis3);
00961 cpl_imagelist_empty(alist);
00962 cpl_imagelist_empty(blist);
00963
00964 visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 1, 1);
00965 cpl_test_eq(2, cpl_imagelist_get_size(alist));
00966 cpl_test_eq(2, cpl_imagelist_get_size(blist));
00967
00968 TEST_LIST(alist, 0xA);
00969 TEST_LIST(blist, 0xB);
00970
00971 cpl_imagelist_delete(list);
00972
00973
00974
00975 list = create_input_imagelist(values, naxis3);
00976 cpl_imagelist_empty(alist);
00977 cpl_imagelist_empty(blist);
00978
00979 visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 2, 1);
00980 cpl_test_eq(1, cpl_imagelist_get_size(alist));
00981 cpl_test_eq(1, cpl_imagelist_get_size(blist));
00982
00983 TEST_LIST(alist, 0xA);
00984 TEST_LIST(blist, 0xB);
00985
00986 cpl_imagelist_delete(list);
00987
00988
00989
00990 for (int i = 0; i < ihalfcycle * 2; i++) {
00991 for (int h = 0; h < ihalfcycle / 2; h++) {
00992 for (int l = 0; l < ihalfcycle / 2; l++) {
00993 list = create_input_imagelist(values, naxis3);
00994 cpl_imagelist_empty(alist);
00995 cpl_imagelist_empty(blist);
00996
00997 visir_load_burst_(alist, blist, list, i, ihalfcycle, l, h);
00998
00999 while (cpl_imagelist_get_size(alist) < cpl_imagelist_get_size(blist))
01000 cpl_image_delete(cpl_imagelist_unset(blist, cpl_imagelist_get_size(blist) - 1));
01001 while (cpl_imagelist_get_size(alist) > cpl_imagelist_get_size(blist))
01002 cpl_image_delete(cpl_imagelist_unset(alist, cpl_imagelist_get_size(alist) - 1));
01003 cpl_test_eq(4 - (h + l), cpl_imagelist_get_size(alist));
01004 cpl_test_eq(4 - (h + l), cpl_imagelist_get_size(blist));
01005
01006 cpl_imagelist_delete(list);
01007 }
01008 }
01009 }
01010
01011 cpl_imagelist_delete(alist);
01012 cpl_imagelist_delete(blist);
01013 cpl_propertylist_delete(prop);
01014 }
01015
01016
01017 {
01018 cpl_imagelist * blist = cpl_imagelist_new();
01019 cpl_imagelist * alist = cpl_imagelist_new();
01020 const int values[] = {0, 1, 1, 0, 0, 0xBAD, 0, 1, 1, 0, 0, 0xBAD, 0, 1};
01021 int naxis3 = sizeof(values)/sizeof(values[0]);
01022 int ichopchange = 5, ihalfcycle = 6;
01023 cpl_imagelist * list = create_input_imagelist(values, naxis3);
01024
01025 visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 2, 1);
01026 cpl_test_eq(3, cpl_imagelist_get_size(alist));
01027 cpl_test_eq(2, cpl_imagelist_get_size(blist));
01028
01029 TEST_LIST(alist, 1);
01030 TEST_LIST(blist, 1);
01031
01032 cpl_imagelist_delete(list);
01033 cpl_imagelist_delete(alist);
01034 cpl_imagelist_delete(blist);
01035 }
01036
01037
01038 {
01039 cpl_imagelist * blist = cpl_imagelist_new();
01040 cpl_imagelist * alist = cpl_imagelist_new();
01041 cpl_propertylist * prop;
01042 const int values[] = {0xA, 0xBADBEEF, 0xB, 0xB, 0xB, 0xB, 0xBADBEEF,
01043 0xA, 0xA, 0xA, 0xA, 0xBADBEEF};
01044 int naxis3 = sizeof(values)/sizeof(values[0]);
01045 int ichopchange = 0, ihalfcycle = 0;
01046 cpl_imagelist * list = create_input_imagelist(values, naxis3);
01047
01048
01049 prop = create_property_list("2011-08-13T23:11:09.0000",
01050 "2011-08-13T23:10:00", 0.1, 1, 0);
01051 visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
01052 cpl_test_eq(1, ichopchange);
01053 cpl_test_eq(5, ihalfcycle);
01054
01055 visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
01056 cpl_test_eq(5, cpl_imagelist_get_size(alist));
01057 cpl_test_eq(4, cpl_imagelist_get_size(blist));
01058
01059 TEST_LIST(alist, 0xA);
01060 TEST_LIST(blist, 0xB);
01061
01062 cpl_imagelist_delete(list);
01063 cpl_imagelist_delete(alist);
01064 cpl_imagelist_delete(blist);
01065 cpl_propertylist_delete(prop);
01066 }
01067
01068 {
01069 cpl_imagelist * blist = cpl_imagelist_new();
01070 cpl_imagelist * alist = cpl_imagelist_new();
01071 cpl_propertylist * prop;
01072 const int values[] = {0xBADBEEF, 0xB, 0xB, 0xB, 0xB, 0xBADBEEF,
01073 0xA, 0xA, 0xA, 0xA, 0xBADBEEF, 0xB};
01074 int naxis3 = sizeof(values)/sizeof(values[0]);
01075 int ichopchange = 0, ihalfcycle = 0;
01076 cpl_imagelist * list = create_input_imagelist(values, naxis3);
01077
01078
01079 prop = create_property_list("2011-08-13T23:10:00.0000",
01080 "2011-08-13T23:10:00", 0.1, 1, 0);
01081 visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
01082 cpl_test_eq(0, ichopchange);
01083 cpl_test_eq(5, ihalfcycle);
01084
01085 visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
01086 cpl_test_eq(4, cpl_imagelist_get_size(alist));
01087 cpl_test_eq(5, cpl_imagelist_get_size(blist));
01088
01089 TEST_LIST(alist, 0xA);
01090 TEST_LIST(blist, 0xB);
01091
01092 cpl_imagelist_delete(list);
01093 cpl_imagelist_delete(alist);
01094 cpl_imagelist_delete(blist);
01095 cpl_propertylist_delete(prop);
01096 }
01097
01098 {
01099 const char * fn = "load_burst.fits";
01100 cpl_imagelist * blist = cpl_imagelist_new();
01101 cpl_imagelist * alist = cpl_imagelist_new();
01102 cpl_propertylist * prop = cpl_propertylist_new();
01103 cpl_frame * frame = cpl_frame_new();
01104 const int values[] = {0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA};
01105 int naxis3 = sizeof(values)/sizeof(values[0]);
01106 cpl_imagelist * list = create_input_imagelist(values, naxis3);
01107
01108 cpl_propertylist_append_bool(prop, VISIR_PFITS_BOOL_CHOP_STATUS, CPL_FALSE);
01109 cpl_imagelist_save(list, fn, CPL_TYPE_UNSPECIFIED,
01110 prop, CPL_IO_CREATE);
01111 cpl_propertylist_delete(prop);
01112 prop = cpl_propertylist_load(fn, 0);
01113 cpl_frame_set_filename(frame, fn);
01114
01115
01116
01117
01118
01119
01120 TEST_LIST(alist, 0xA);
01121
01122 cpl_imagelist_delete(list);
01123 cpl_imagelist_delete(alist);
01124 cpl_imagelist_delete(blist);
01125 cpl_propertylist_delete(prop);
01126 cpl_frame_delete(frame);
01127 unlink(fn);
01128 }
01129
01130 if (stream != stdout) cpl_test_zero( fclose(stream) );
01131
01132 }
01133
01134
01135 static void visir_img_check_get_to_off_plane(void)
01136 {
01137
01138 FILE * stream;
01139
01140 stream = cpl_msg_get_level() > CPL_MSG_INFO
01141 ? fopen("/dev/null", "a") : stdout;
01142
01143 cpl_test_nonnull( stream );
01144
01145 {
01146
01147 int icc = 27;
01148 int istart = 0;
01149 int ihc = 100;
01150 cpl_test_eq(27, get_to_off_plane(icc, istart, ihc));
01151
01152 istart = 10;
01153 cpl_test_eq(17, get_to_off_plane(icc, istart, ihc));
01154
01155 istart = icc;
01156 cpl_test_eq(0, get_to_off_plane(icc, istart, ihc));
01157
01158 istart = 50;
01159 cpl_test_eq(177, get_to_off_plane(icc, istart, ihc));
01160
01161 istart = ihc;
01162 cpl_test_eq(127, get_to_off_plane(icc, istart, ihc));
01163
01164 istart = ihc + icc;
01165 cpl_test_eq(100, get_to_off_plane(icc, istart, ihc));
01166
01167 istart = 150;
01168 cpl_test_eq(77, get_to_off_plane(icc, istart, ihc));
01169
01170 istart = ihc * 2;
01171 cpl_test_eq(27, get_to_off_plane(icc, istart, ihc));
01172
01173 istart = ihc * 2 + 10;
01174 cpl_test_eq(17, get_to_off_plane(icc, istart, ihc));
01175
01176 istart = ihc * 2 + 50;
01177 cpl_test_eq(177, get_to_off_plane(icc, istart, ihc));
01178
01179 istart = 50;
01180 ihc = 80;
01181 cpl_test_eq(139, get_to_off_plane(29, istart, ihc));
01182
01183
01184 icc = 157;
01185 istart = 240;
01186 ihc = 80;
01187 cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
01188
01189 istart = 230;
01190 cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
01191
01192 istart = 160;
01193 cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
01194
01195 istart = 150;
01196 cpl_test_eq(157 - istart, get_to_off_plane(icc, istart, ihc));
01197
01198 istart = 320;
01199 cpl_test_eq(477 - istart, get_to_off_plane(icc, istart, ihc));
01200
01201 istart = 310;
01202 cpl_test_eq(317 - istart, get_to_off_plane(icc, istart, ihc));
01203
01204
01205 icc = 80;
01206 istart = 0;
01207 ihc = 80;
01208 cpl_test_eq(80, get_to_off_plane(icc, istart, ihc));
01209
01210 istart = 80;
01211 cpl_test_eq(0, get_to_off_plane(icc, istart, ihc));
01212
01213 istart = 160;
01214 cpl_test_eq(80, get_to_off_plane(icc, istart, ihc));
01215
01216 istart = 240;
01217 cpl_test_eq(0, get_to_off_plane(icc, istart, ihc));
01218
01219 istart = 30;
01220 cpl_test_eq(50, get_to_off_plane(icc, istart, ihc));
01221
01222 istart = 130;
01223 cpl_test_eq(110, get_to_off_plane(icc, istart, ihc));
01224 }
01225
01226 if (stream != stdout) cpl_test_zero( fclose(stream) );
01227 }
01228
01229
01230 static cpl_imagelist * create_cube2_imagelist(int ncycles)
01231 {
01232 cpl_imagelist * list = cpl_imagelist_new();
01233 cpl_image * image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
01234 float prev_val = 0.0;
01235
01236 for (int i = 0; i < ncycles; i++) {
01237 const float val = (prev_val * i + A_VAL - B_VAL) / (i + 1);
01238 cpl_image_set(image, 1, 1, A_VAL - VISIR_HCYCLE_OFFSET);
01239 cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
01240 image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
01241
01242 cpl_image_set(image, 1, 1, val);
01243 cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
01244 image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
01245 prev_val = val;
01246 }
01247
01248 cpl_image_set(image, 1, 1, prev_val);
01249 cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
01250 return list;
01251 }
01252
01253 static void visir_img_check_load_cube2(void)
01254 {
01255
01256 FILE * stream;
01257
01258 stream = cpl_msg_get_level() > CPL_MSG_INFO
01259 ? fopen("/dev/null", "a") : stdout;
01260
01261 cpl_test_nonnull( stream );
01262
01263 {
01264 const int ncycles = 20;
01265 cpl_imagelist * list = create_cube2_imagelist(ncycles);
01266 cpl_imagelist * alist = cpl_imagelist_new();
01267 cpl_imagelist * blist = cpl_imagelist_new();
01268 cpl_test_eq(2 * ncycles + 1, cpl_imagelist_get_size(list));
01269
01270
01271 cpl_image_delete(cpl_imagelist_unset(list, cpl_imagelist_get_size(list) - 1));
01272
01273 visir_load_cube2_split_(alist, blist, list, NULL);
01274 cpl_test_eq(ncycles, cpl_imagelist_get_size(alist));
01275 cpl_test_eq(ncycles, cpl_imagelist_get_size(blist));
01276 TEST_LIST(alist, A_VAL);
01277 TEST_LIST(blist, B_VAL);
01278
01279 cpl_imagelist_delete(list);
01280 cpl_imagelist_delete(alist);
01281 cpl_imagelist_delete(blist);
01282 }
01283
01284
01285 {
01286 const int ncycles = 40;
01287 cpl_image * prevd;
01288 cpl_imagelist * list = create_cube2_imagelist(ncycles);
01289 cpl_imagelist * alist = cpl_imagelist_new();
01290 cpl_imagelist * blist = cpl_imagelist_new();
01291 cpl_imagelist * chunk2 = cpl_imagelist_new();
01292
01293 cpl_test_eq(2 * ncycles + 1, cpl_imagelist_get_size(list));
01294
01295
01296 cpl_image_delete(cpl_imagelist_unset(list,
01297 cpl_imagelist_get_size(list) - 1));
01298
01299 for (int i = ncycles; i > 0; i--) {
01300 cpl_image * tmp =
01301 cpl_imagelist_unset(list, cpl_imagelist_get_size(list) - i);
01302 cpl_imagelist_set(chunk2, tmp, cpl_imagelist_get_size(chunk2));
01303 }
01304 prevd =
01305 cpl_image_duplicate(cpl_imagelist_get(list,
01306 cpl_imagelist_get_size(list) - 1));
01307
01308 visir_load_cube2_split_(alist, blist, list, NULL);
01309 cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(alist));
01310 cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(blist));
01311 TEST_LIST(alist, A_VAL);
01312 TEST_LIST(blist, B_VAL);
01313
01314 cpl_imagelist_empty(alist);
01315 cpl_imagelist_empty(blist);
01316
01317 visir_load_cube2_split_(alist, blist, chunk2, prevd);
01318 cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(alist));
01319 cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(blist));
01320 TEST_LIST(alist, A_VAL);
01321 TEST_LIST(blist, B_VAL);
01322
01323 cpl_imagelist_delete(list);
01324 cpl_imagelist_delete(chunk2);
01325 cpl_imagelist_delete(alist);
01326 cpl_imagelist_delete(blist);
01327 cpl_image_delete(prevd);
01328 }
01329
01330 if (stream != stdout) cpl_test_zero( fclose(stream) );
01331 }