visir_inputs-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO VISIR package                                 *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00004  *                                                                              *
00005  *   This library is free software; you can redistribute it and/or modify       *
00006  *   it under the terms of the GNU General Public License as published by       *
00007  *   the Free Software Foundation; either version 2 of the License, or          *
00008  *   (at your option) any later version.                                        *
00009  *                                                                              *
00010  *   This program is distributed in the hope that it will be useful,            *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00013  *   GNU General Public License for more details.                               *
00014  *                                                                              *
00015  *   You should have received a copy of the GNU General Public License          *
00016  *   along with this program; if not, write to the Free Software                *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
00018  *                                                                              */
00019  
00020 #ifdef HAVE_CONFIG_H
00021 #  include <config.h>
00022 #endif
00023 
00024 /*-----------------------------------------------------------------------------
00025                                 Includes
00026  -----------------------------------------------------------------------------*/
00027 
00028 #include <visir_inputs.h>
00029 
00030 #include "visir_inputs.c"
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Defines
00034  -----------------------------------------------------------------------------*/
00035 
00036 /* TEMPORARY SUPPORT OF CPL 5.x */
00037 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE < CPL_VERSION(6, 0, 0)
00038 #define VISIR_ERROR_ACCESS_OUT_OF_RANGE CPL_ERROR_ILLEGAL_INPUT
00039 #else
00040 #define VISIR_ERROR_ACCESS_OUT_OF_RANGE CPL_ERROR_ACCESS_OUT_OF_RANGE
00041 #endif
00042 /* END TEMPORARY SUPPORT OF CPL 5.x */
00043 
00044 
00045 /*----------------------------------------------------------------------------*/
00049 /*----------------------------------------------------------------------------*/
00050 
00051 
00052 /*----------------------------------------------------------------------------*/
00056 /*----------------------------------------------------------------------------*/
00057 
00058 static void visir_img_check_box_test(void);
00059 static void visir_img_check_align_test(void);
00060 static void visir_img_check_line_test(void);
00061 static void visir_img_check_burst_find_delta_chop(void);
00062 static void visir_img_check_load_burst(void);
00063 static void visir_img_check_get_to_off_plane(void);
00064 static void visir_img_check_load_cube2(void);
00065 
00066 void cpl_imagelist_empty(cpl_imagelist * self);
00067 
00068 #ifndef BOX_SIZE
00069 #define BOX_SIZE 11
00070 #endif
00071 
00072 #ifndef LINE_SIZE
00073 #define LINE_SIZE BOX_SIZE
00074 #endif
00075 
00076 int main(void)
00077 {
00078 
00079     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00080 
00081     visir_img_check_line_test();
00082     visir_img_check_align_test();
00083     visir_img_check_box_test();
00084     visir_img_check_burst_find_delta_chop();
00085     visir_img_check_load_burst();
00086     visir_img_check_get_to_off_plane();
00087     visir_img_check_load_cube2();
00088 
00089     return cpl_test_end(0);
00090 
00091 }
00092 
00093 static void visir_img_check_box_test(void)
00094 {
00095 
00096     cpl_image     * image;
00097     const double    sigma = 1.0;
00098     cpl_apertures * appos;
00099     cpl_apertures * apneg;
00100     double          ecc;
00101     cpl_boolean     swapp, swapn;
00102     FILE          * stream;
00103     cpl_error_code  error = CPL_ERROR_NONE;
00104     int i, j;
00105 
00106     stream = cpl_msg_get_level() > CPL_MSG_INFO
00107         ? fopen("/dev/null", "a") : stdout;
00108 
00109     cpl_test_nonnull( stream );
00110 
00111     image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE, CPL_TYPE_INT);
00112 
00113     /* Create four 3x3-pixel objects */
00114     for (j = -1; j <= 1; j++) {
00115       for (i = -1; i <= 1; i++) {
00116           error |= cpl_image_set(image,   BOX_SIZE + i,   BOX_SIZE + j, -1.0);
00117           error |= cpl_image_set(image, 2*BOX_SIZE + i, 2*BOX_SIZE + j, -1.0);
00118           error |= cpl_image_set(image,   BOX_SIZE + i, 2*BOX_SIZE + j,  1.0);
00119           error |= cpl_image_set(image, 2*BOX_SIZE + i,   BOX_SIZE + j,  1.0);
00120           cpl_test_eq_error(error, CPL_ERROR_NONE);
00121       }
00122     }
00123 
00124     appos = cpl_apertures_extract_sigma(image, sigma);
00125     cpl_test_error(CPL_ERROR_NONE);
00126     cpl_test_nonnull(appos);
00127     cpl_test_eq(cpl_apertures_get_size(appos), 2);
00128 
00129     cpl_apertures_dump(appos, stream);
00130 
00131     error = cpl_image_multiply_scalar(image, -1.0);
00132     cpl_test_eq_error(error, CPL_ERROR_NONE);
00133 
00134     apneg = cpl_apertures_extract_sigma(image, sigma);
00135     cpl_test_error(CPL_ERROR_NONE);
00136     cpl_test_nonnull(apneg);
00137     cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00138 
00139     cpl_apertures_dump(apneg, stream);
00140 
00141     /* Various error checks */
00142     ecc = visir_img_check_box(NULL, 1, 2, apneg, 1, 2, BOX_SIZE,
00143                               &swapp, &swapn);
00144     cpl_test_error(CPL_ERROR_NULL_INPUT);
00145 
00146     ecc = visir_img_check_box(appos, 1, 2, NULL, 1, 2, BOX_SIZE,
00147                               &swapp, &swapn);
00148     cpl_test_error(CPL_ERROR_NULL_INPUT);
00149 
00150     ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE,
00151                               &swapp, NULL);
00152     cpl_test_error(CPL_ERROR_UNSPECIFIED);
00153 
00154     ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE,
00155                               NULL, &swapn);
00156     cpl_test_error(CPL_ERROR_UNSPECIFIED);
00157 
00158     ecc = visir_img_check_box(appos, 1, 2, appos, 1, 2, BOX_SIZE,
00159                               &swapp, &swapn);
00160     cpl_test_error(CPL_ERROR_UNSPECIFIED);
00161 
00162     ecc = visir_img_check_box(appos, 0, 2, apneg, 1, 2, BOX_SIZE,
00163                               &swapp, &swapn);
00164     cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00165 
00166     ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 0, BOX_SIZE,
00167                               &swapp, &swapn);
00168     cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00169 
00170     ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 3, BOX_SIZE,
00171                               &swapp, &swapn);
00172     cpl_test_error(VISIR_ERROR_ACCESS_OUT_OF_RANGE);
00173 
00174     ecc = visir_img_check_box(appos, 3, 2, apneg, 1, 2, BOX_SIZE,
00175                               &swapp, &swapn);
00176     cpl_test_error(VISIR_ERROR_ACCESS_OUT_OF_RANGE);
00177 
00178     ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, 0.0, &swapp, &swapn);
00179     cpl_test_error(CPL_ERROR_UNSPECIFIED);
00180 
00181     /* Verify output of correct call - with zero eccentricity */
00182     ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE,
00183                               &swapp, &swapn);
00184     cpl_test_error(CPL_ERROR_NONE);
00185 
00186     cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00187     cpl_test(swapp);
00188     cpl_test_zero(swapn);
00189 
00190     /* - and points are swapped when needed */
00191     ecc = visir_img_check_box(appos, 2, 1, apneg, 2, 1, BOX_SIZE,
00192                               &swapp, &swapn);
00193     cpl_test_error(CPL_ERROR_NONE);
00194 
00195     cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00196     cpl_test_zero(swapp);
00197     cpl_test(swapn);
00198 
00199     /* Verify output of correct call - with maximum (?) eccentricity */
00200     ecc = visir_img_check_box(apneg, 1, 2, appos, 1, 2, BOX_SIZE,
00201                               &swapp, &swapn);
00202     cpl_test_error(CPL_ERROR_NONE);
00203 
00204     cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
00205     cpl_test_zero(swapp);
00206     cpl_test(swapn);
00207 
00208     /* - and points are swapped when needed */
00209     ecc = visir_img_check_box(apneg, 2, 1, appos, 2, 1, BOX_SIZE,
00210                               &swapp, &swapn);
00211     cpl_test_error(CPL_ERROR_NONE);
00212 
00213     cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
00214     cpl_test(swapp);
00215     cpl_test_zero(swapn);
00216 
00217     cpl_image_delete(image);
00218     cpl_apertures_delete(appos);
00219     cpl_apertures_delete(apneg);
00220 
00221     if (stream != stdout) cpl_test_zero( fclose(stream) );
00222 
00223 }
00224 
00225 static void visir_img_check_align_test(void)
00226 {
00227 
00228     FILE          * stream;
00229     cpl_error_code  error = CPL_ERROR_NONE;
00230     int             idir;
00231     cpl_boolean     is_hor = CPL_FALSE;
00232 
00233     stream = cpl_msg_get_level() > CPL_MSG_INFO
00234         ? fopen("/dev/null", "a") : stdout;
00235 
00236     cpl_test_nonnull( stream );
00237 
00238     for (idir = 0; idir < 2; idir++, is_hor = CPL_TRUE) {
00239         cpl_image     * image = cpl_image_new(4 * LINE_SIZE, 4 * LINE_SIZE,
00240                                               CPL_TYPE_INT);
00241         const double    sigma = 1.0;
00242         cpl_apertures * appos;
00243         cpl_apertures * apneg;
00244         double          ecc;
00245         cpl_boolean     swapn, swapn2;
00246         int i, j;
00247 
00248 
00249         /* Create three 3x3-pixel objects */
00250         for (j = -1; j <= 1; j++) {
00251             for (i = -1; i <= 1; i++) {
00252                 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00253                                        2*LINE_SIZE + j,  1.0);
00254 
00255                 if (is_hor) {
00256                     error |= cpl_image_set(image,   LINE_SIZE + i,
00257                                            2*LINE_SIZE + j, -1.0);
00258                     error |= cpl_image_set(image, 3*LINE_SIZE + i,
00259                                            2*LINE_SIZE + j, -1.0);
00260                 } else {
00261                     error |= cpl_image_set(image, 2*LINE_SIZE + i,
00262                                            LINE_SIZE + j, -1.0);
00263                     error |= cpl_image_set(image, 2*LINE_SIZE + i,
00264                                            3*LINE_SIZE + j, -1.0);
00265                 }
00266                 cpl_test_eq_error(error, CPL_ERROR_NONE);
00267             }
00268         }
00269 
00270         appos = cpl_apertures_extract_sigma(image, sigma);
00271         cpl_test_error(CPL_ERROR_NONE);
00272         cpl_test_nonnull(appos);
00273         cpl_test_eq(cpl_apertures_get_size(appos), 1);
00274 
00275         cpl_apertures_dump(appos, stream);
00276 
00277         error = cpl_image_multiply_scalar(image, -1.0);
00278         cpl_test_eq_error(error, CPL_ERROR_NONE);
00279 
00280         apneg = cpl_apertures_extract_sigma(image, sigma);
00281         cpl_test_error(CPL_ERROR_NONE);
00282         cpl_test_nonnull(apneg);
00283         cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00284 
00285         cpl_apertures_dump(apneg, stream);
00286 
00287         /* Various error checks */
00288         ecc = visir_img_check_align(NULL, 1, apneg, 1, 2, LINE_SIZE, is_hor,
00289                                     &swapn);
00290         cpl_test_error(CPL_ERROR_NULL_INPUT);
00291 
00292         ecc = visir_img_check_align(appos, 1, NULL, 1, 2, LINE_SIZE, is_hor,
00293                                     &swapn);
00294         cpl_test_error(CPL_ERROR_NULL_INPUT);
00295 
00296         ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, is_hor,
00297                                     NULL);
00298         cpl_test_error(CPL_ERROR_UNSPECIFIED);
00299 
00300         ecc = visir_img_check_align(appos, 0, apneg, 1, 2, LINE_SIZE, is_hor,
00301                                     &swapn);
00302         cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00303 
00304         ecc = visir_img_check_align(appos, 1, apneg, 1, 0, LINE_SIZE, is_hor,
00305                                     &swapn);
00306         cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00307 
00308         ecc = visir_img_check_align(appos, 1, apneg, 0, 1, LINE_SIZE, is_hor,
00309                                     &swapn);
00310         cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00311 
00312         ecc = visir_img_check_align(appos, 1, apneg, 1, 3, LINE_SIZE, is_hor,
00313                                     &swapn);
00314         cpl_test_error(VISIR_ERROR_ACCESS_OUT_OF_RANGE);
00315 
00316         ecc = visir_img_check_align(appos, 3, apneg, 1, 2, LINE_SIZE, is_hor,
00317                                     &swapn);
00318         cpl_test_error(VISIR_ERROR_ACCESS_OUT_OF_RANGE);
00319 
00320         ecc = visir_img_check_align(appos, 1, apneg, 1, 2, 0.0, is_hor, &swapn);
00321         cpl_test_error(CPL_ERROR_UNSPECIFIED);
00322 
00323         /* Verify output of correct call - with zero eccentricity */
00324         ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, is_hor,
00325                                     &swapn);
00326         cpl_test_error(CPL_ERROR_NONE);
00327 
00328         cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00329         cpl_test_zero(swapn);
00330 
00331         /* - and points are swapped when needed */
00332         ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE, is_hor,
00333                                     &swapn);
00334         cpl_test_error(CPL_ERROR_NONE);
00335 
00336         cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00337         cpl_test(swapn);
00338 
00339         /* Verify output of correct call - with maximum (?) eccentricity */
00340         ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, !is_hor,
00341                                     &swapn);
00342         cpl_test_error(CPL_ERROR_NONE);
00343 
00344         cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00345 
00346         /* - also with points swapped */
00347         ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE, !is_hor,
00348                                     &swapn2);
00349         cpl_test_error(CPL_ERROR_NONE);
00350 
00351         cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00352 
00353         /* FIXME: When to exactly swap here is not well-defined. */
00354 
00355         cpl_image_delete(image);
00356         cpl_apertures_delete(appos);
00357         cpl_apertures_delete(apneg);
00358     }
00359 
00360     if (stream != stdout) cpl_test_zero( fclose(stream) );
00361 
00362 }
00363 
00364 static void visir_img_check_line_test(void)
00365 {
00366 
00367     FILE          * stream;
00368     cpl_error_code  error = CPL_ERROR_NONE;
00369     int             idir;
00370     cpl_boolean     is_hor = CPL_FALSE;
00371 
00372     stream = cpl_msg_get_level() > CPL_MSG_INFO
00373         ? fopen("/dev/null", "a") : stdout;
00374 
00375     cpl_test_nonnull( stream );
00376 
00377     for (idir = 0; idir < 2; idir++, is_hor = CPL_TRUE) {
00378         cpl_image     * image = cpl_image_new(4 * LINE_SIZE, 4 * LINE_SIZE,
00379                                               CPL_TYPE_INT);
00380         const double    sigma = 1.0;
00381         cpl_apertures * appos;
00382         cpl_apertures * apneg;
00383         double          ecc;
00384         int i, j;
00385 
00386 
00387         /* Create three 3x3-pixel objects */
00388         for (j = -1; j <= 1; j++) {
00389             for (i = -1; i <= 1; i++) {
00390                 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00391                                        2*LINE_SIZE + j,  1.0);
00392 
00393                 if (is_hor) {
00394                     error |= cpl_image_set(image,   LINE_SIZE + i,
00395                                            2*LINE_SIZE + j, -1.0);
00396                     error |= cpl_image_set(image, 3*LINE_SIZE + i,
00397                                            2*LINE_SIZE + j, -1.0);
00398                 } else {
00399                     error |= cpl_image_set(image, 2*LINE_SIZE + i,
00400                                            LINE_SIZE + j, -1.0);
00401                     error |= cpl_image_set(image, 2*LINE_SIZE + i,
00402                                            3*LINE_SIZE + j, -1.0);
00403                 }
00404                 cpl_test_eq_error(error, CPL_ERROR_NONE);
00405             }
00406         }
00407 
00408         appos = cpl_apertures_extract_sigma(image, sigma);
00409         cpl_test_error(CPL_ERROR_NONE);
00410         cpl_test_nonnull(appos);
00411         cpl_test_eq(cpl_apertures_get_size(appos), 1);
00412 
00413         cpl_apertures_dump(appos, stream);
00414 
00415         error = cpl_image_multiply_scalar(image, -1.0);
00416         cpl_test_eq_error(error, CPL_ERROR_NONE);
00417 
00418         apneg = cpl_apertures_extract_sigma(image, sigma);
00419         cpl_test_error(CPL_ERROR_NONE);
00420         cpl_test_nonnull(apneg);
00421         cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00422 
00423         cpl_apertures_dump(apneg, stream);
00424 
00425         /* Various error checks */
00426         ecc = visir_img_check_line(NULL, 1, apneg, 1, LINE_SIZE, is_hor);
00427         cpl_test_error(CPL_ERROR_NULL_INPUT);
00428 
00429         ecc = visir_img_check_line(appos, 1, NULL, 1, LINE_SIZE, is_hor);
00430         cpl_test_error(CPL_ERROR_NULL_INPUT);
00431 
00432         ecc = visir_img_check_line(appos, 0, apneg, 1, LINE_SIZE, is_hor);
00433         cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00434 
00435         ecc = visir_img_check_line(appos, 1, apneg, 0, LINE_SIZE, is_hor);
00436         cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00437 
00438         ecc = visir_img_check_line(appos, 1, apneg, 0, LINE_SIZE, is_hor);
00439         cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00440 
00441         ecc = visir_img_check_line(appos, 1, apneg, 3, LINE_SIZE, is_hor);
00442         cpl_test_error(VISIR_ERROR_ACCESS_OUT_OF_RANGE);
00443 
00444         ecc = visir_img_check_line(appos, 3, apneg, 1, LINE_SIZE, is_hor);
00445         cpl_test_error(VISIR_ERROR_ACCESS_OUT_OF_RANGE);
00446 
00447         ecc = visir_img_check_line(appos, 1, apneg, 1, 0.0, is_hor);
00448         cpl_test_error(CPL_ERROR_UNSPECIFIED);
00449 
00450         /* Verify output of correct call - with zero eccentricity */
00451         ecc = visir_img_check_line(apneg, 1, appos, 1, LINE_SIZE, is_hor);
00452         cpl_test_error(CPL_ERROR_NONE);
00453 
00454         cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00455 
00456         /* Verify output of correct call - with maximum (?) eccentricity */
00457         ecc = visir_img_check_line(appos, 1, apneg, 1, LINE_SIZE, is_hor);
00458         cpl_test_error(CPL_ERROR_NONE);
00459 
00460         cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00461 
00462         /* Verify output of correct call - with maximum (?) eccentricity */
00463         ecc = visir_img_check_line(appos, 1, apneg, 1, LINE_SIZE, !is_hor);
00464         cpl_test_error(CPL_ERROR_NONE);
00465 
00466         cpl_test_abs(ecc, CPL_MATH_SQRT2, FLT_EPSILON);
00467 
00468         /* - also with points swapped */
00469         ecc = visir_img_check_line(apneg, 1, appos, 1, LINE_SIZE, !is_hor);
00470         cpl_test_error(CPL_ERROR_NONE);
00471 
00472         cpl_test_abs(ecc, CPL_MATH_SQRT2, FLT_EPSILON);
00473 
00474         /* FIXME: When to exactly swap here is not well-defined. */
00475 
00476         cpl_image_delete(image);
00477         cpl_apertures_delete(appos);
00478         cpl_apertures_delete(apneg);
00479     }
00480 
00481     if (stream != stdout) cpl_test_zero( fclose(stream) );
00482 
00483 }
00484 
00485 cpl_propertylist *
00486 create_property_list(const char * obs_start,
00487                      const char * chop_start,
00488                      const double chop_freq,
00489                      const double dit,
00490                      const double nditskip)
00491 {
00492     cpl_propertylist * prop = cpl_propertylist_new();
00493     cpl_propertylist_append_string(prop, VISIR_PFITS_STRING_OBS_START,
00494             obs_start);
00495     cpl_propertylist_append_string(prop, VISIR_PFITS_STRING_CHOP_START,
00496             chop_start);
00497     cpl_propertylist_append_double(prop, VISIR_PFITS_DOUBLE_CHOP_FREQ,
00498             chop_freq);
00499     cpl_propertylist_append_double(prop, VISIR_PFITS_DOUBLE_DIT, dit);
00500     cpl_propertylist_append_int(prop, VISIR_PFITS_INT_NDITSKIP, nditskip);
00501     return prop;
00502 }
00503 
00504 static void visir_img_check_burst_find_delta_chop(void)
00505 {
00506 
00507     FILE          * stream;
00508     cpl_error_code  error = CPL_ERROR_NONE;
00509 
00510     stream = cpl_msg_get_level() > CPL_MSG_INFO
00511         ? fopen("/dev/null", "a") : stdout;
00512 
00513     cpl_test_nonnull( stream );
00514 
00515     {
00516         int ifirst = 0, ihalfcycle = 0;
00517         cpl_propertylist * prop =
00518             create_property_list("2011-08-13T23:13:38.0612",
00519                                  "2011-08-13T23:10:16",
00520                                  0.25, 0.02, 2);
00521         visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
00522         cpl_test_eq(94, ifirst);
00523         cpl_test_eq(100, ihalfcycle);
00524         cpl_propertylist_delete(prop);
00525     }
00526 
00527     {
00528         int ifirst = 0, ihalfcycle = 0;
00529         cpl_propertylist * prop =
00530             create_property_list("2011-08-13T23:10:16.0612",
00531                                  "2011-08-13T23:13:38",
00532                                  0.25, 0.02, 2);
00533         visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
00534         cpl_test_eq(94, ifirst);
00535         cpl_test_eq(100, ihalfcycle);
00536         cpl_propertylist_delete(prop);
00537     }
00538 
00539     {
00540         int ifirst = 0, ihalfcycle = 0;
00541         cpl_propertylist * prop =
00542             create_property_list("2011-08-13T23:13:35.9999",
00543                                  "2011-08-13T23:10:16",
00544                                  0.25, 0.02, 0);
00545         visir_img_burst_find_delta_chop(prop, &ifirst, &ihalfcycle);
00546         cpl_test_eq(0, ifirst);
00547         cpl_test_eq(100, ihalfcycle);
00548         cpl_propertylist_delete(prop);
00549     }
00550     /* ichopchange > ihalfcycle testcase in visir_img_check_load_burst */
00551 
00552     if (stream != stdout) cpl_test_zero( fclose(stream) );
00553 
00554 }
00555 
00556 #define TEST_LIST(list, value) \
00557 do { \
00558     for (int i = 0; i < cpl_imagelist_get_size((list)); i++) { \
00559         int b; \
00560         const cpl_image * image = cpl_imagelist_get_const((list), i); \
00561         cpl_test_eq((value), cpl_image_get(image, 1, 1, &b)); \
00562     } \
00563 } \
00564 while(0)
00565 
00566 cpl_imagelist *
00567 create_input_imagelist(const int * values, int naxis3)
00568 {
00569     cpl_imagelist * list = cpl_imagelist_new();
00570     for (int i = 0; i < naxis3; i++) {
00571         cpl_image * image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE,
00572                                           CPL_TYPE_INT);
00573         cpl_image_set(image, 1, 1, values[i]);
00574         cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
00575     }
00576     return list;
00577 }
00578 
00579 static void visir_img_check_load_burst(void)
00580 {
00581     FILE          * stream;
00582     cpl_error_code  error = CPL_ERROR_NONE;
00583 
00584     stream = cpl_msg_get_level() > CPL_MSG_INFO
00585         ? fopen("/dev/null", "a") : stdout;
00586 
00587     cpl_test_nonnull( stream );
00588 
00589     /* large data test */
00590     {
00591         cpl_imagelist * list = cpl_imagelist_new();
00592         cpl_imagelist * blist = cpl_imagelist_new();
00593         cpl_imagelist * alist = cpl_imagelist_new();
00594         cpl_propertylist * prop;
00595         int naxis3 = 100;
00596         int ichopchange = 0, ihalfcycle = 0;
00597 
00598         prop = create_property_list("2011-08-13T23:11:04.0000",
00599                                     "2011-08-13T23:10:00", 0.1, 1, 0);
00600         // chopstart 6
00601         visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
00602         cpl_test_eq(6, ichopchange);
00603         cpl_test_eq(5, ihalfcycle);
00604 
00605         for (int i = 0; i < naxis3; i++) {
00606             cpl_image * image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE,
00607                                               CPL_TYPE_INT);
00608             cpl_image_set(image, 1, 1, 0xA);
00609 
00610             cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
00611         }
00612         /* mark images to skip bad (1, 6, 11, 16, ...) */
00613         for (int i = 0; i< 20; i++) {
00614             cpl_image * img = 
00615                 cpl_imagelist_get(list,
00616                                   i * ihalfcycle + (ichopchange % ihalfcycle));
00617             cpl_image_set(img, 1, 1, 0xBADBEEF);
00618         }
00619 
00620         visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
00621         cpl_test_eq(40, cpl_imagelist_get_size(alist));
00622         cpl_test_eq(40, cpl_imagelist_get_size(blist));
00623 
00624         TEST_LIST(alist, 0xA);
00625         TEST_LIST(blist, 0xA);
00626 
00627         cpl_imagelist_delete(alist);
00628         cpl_imagelist_delete(blist);
00629         cpl_imagelist_delete(list);
00630         cpl_propertylist_delete(prop);
00631     }
00632 
00633 
00634     /* detailed test small data */
00635     {
00636         cpl_imagelist * alist = cpl_imagelist_new();
00637         cpl_imagelist * blist = cpl_imagelist_new();
00638         cpl_propertylist * prop;
00639         const int values[] = {0xB, 0xBADBEEF, 0xA, 0xA, 0xA, 0xA, 0xBADBEEF,
00640                               0xB, 0xB, 0xB, 0xB, 0xBADBEEF};
00641         int naxis3 =sizeof(values)/sizeof(values[0]);
00642         int ichopchange = 0, ihalfcycle = 0;
00643         cpl_imagelist * list = create_input_imagelist(values, naxis3);
00644 
00645         // halfcycle 5, chopstart 6
00646         prop = create_property_list("2011-08-13T23:11:04.0000",
00647                                     "2011-08-13T23:10:00", 0.1, 1, 0);
00648         visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
00649         cpl_test_eq(6, ichopchange);
00650         cpl_test_eq(5, ihalfcycle);
00651 
00652         visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
00653         cpl_test_eq(4, cpl_imagelist_get_size(alist));
00654         cpl_test_eq(5, cpl_imagelist_get_size(blist));
00655 
00656         TEST_LIST(alist, 0xA);
00657         TEST_LIST(blist, 0xB);
00658 
00659         cpl_imagelist_delete(list);
00660 
00661         /* test trimming */
00662 
00663         list = create_input_imagelist(values, naxis3);
00664         cpl_imagelist_empty(alist);
00665         cpl_imagelist_empty(blist);
00666 
00667         visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 1, 1);
00668         cpl_test_eq(2, cpl_imagelist_get_size(alist));
00669         cpl_test_eq(2, cpl_imagelist_get_size(blist));
00670 
00671         TEST_LIST(alist, 0xA);
00672         TEST_LIST(blist, 0xB);
00673 
00674         cpl_imagelist_delete(list);
00675 
00676         /* test trimming ichopchange % ihalfcycle - trim < 0*/
00677 
00678         list = create_input_imagelist(values, naxis3);
00679         cpl_imagelist_empty(alist);
00680         cpl_imagelist_empty(blist);
00681 
00682         visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 2, 1);
00683         cpl_test_eq(1, cpl_imagelist_get_size(alist));
00684         cpl_test_eq(1, cpl_imagelist_get_size(blist));
00685 
00686         TEST_LIST(alist, 0xA);
00687         TEST_LIST(blist, 0xB);
00688 
00689         cpl_imagelist_delete(list);
00690 
00691         /* test full chop/trim range*/
00692 
00693         for (int i = 0; i < ihalfcycle * 2; i++) {
00694             for (int h = 0; h < ihalfcycle / 2; h++) {
00695                 for (int l = 0; l < ihalfcycle / 2; l++) {
00696                     list = create_input_imagelist(values, naxis3);
00697                     cpl_imagelist_empty(alist);
00698                     cpl_imagelist_empty(blist);
00699 
00700                     visir_load_burst_(alist, blist, list, i, ihalfcycle, l, h);
00701                     // FIXME: test non trim case too
00702                     while (cpl_imagelist_get_size(alist) < cpl_imagelist_get_size(blist))
00703                         cpl_image_delete(cpl_imagelist_unset(blist, cpl_imagelist_get_size(blist) - 1));
00704                     while (cpl_imagelist_get_size(alist) > cpl_imagelist_get_size(blist))
00705                         cpl_image_delete(cpl_imagelist_unset(alist, cpl_imagelist_get_size(alist) - 1));
00706                     cpl_test_eq(4 - (h + l), cpl_imagelist_get_size(alist));
00707                     cpl_test_eq(4 - (h + l), cpl_imagelist_get_size(blist));
00708 
00709                     cpl_imagelist_delete(list);
00710                 }
00711             }
00712         }
00713 
00714         cpl_imagelist_delete(alist);
00715         cpl_imagelist_delete(blist);
00716         cpl_propertylist_delete(prop);
00717     }
00718 
00719     /* test assymmetric rejects */
00720     {
00721         cpl_imagelist * blist = cpl_imagelist_new();
00722         cpl_imagelist * alist = cpl_imagelist_new();
00723         cpl_propertylist * prop;
00724         const int values[] = {0, 1, 1, 0, 0, 0xBAD, 0, 1, 1, 0, 0, 0xBAD, 0, 1};
00725         int naxis3 = sizeof(values)/sizeof(values[0]);
00726         int ichopchange = 5, ihalfcycle = 6;
00727         cpl_imagelist * list = create_input_imagelist(values, naxis3);
00728 
00729         visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 2, 1);
00730         cpl_test_eq(3, cpl_imagelist_get_size(alist));
00731         cpl_test_eq(2, cpl_imagelist_get_size(blist));
00732 
00733         TEST_LIST(alist, 1);
00734         TEST_LIST(blist, 1);
00735 
00736         cpl_imagelist_delete(list);
00737         cpl_imagelist_delete(alist);
00738         cpl_imagelist_delete(blist);
00739     }
00740 
00741     /* sliced with chopchange in first half cycle */
00742     {
00743         cpl_imagelist * blist = cpl_imagelist_new();
00744         cpl_imagelist * alist = cpl_imagelist_new();
00745         cpl_propertylist * prop;
00746         const int values[] = {0xA, 0xBADBEEF, 0xB, 0xB, 0xB, 0xB, 0xBADBEEF,
00747                               0xA, 0xA, 0xA, 0xA, 0xBADBEEF};
00748         int naxis3 = sizeof(values)/sizeof(values[0]);
00749         int ichopchange = 0, ihalfcycle = 0;
00750         cpl_imagelist * list = create_input_imagelist(values, naxis3);
00751 
00752         // halfcycle 5, chopstart 1
00753         prop = create_property_list("2011-08-13T23:11:09.0000",
00754                                     "2011-08-13T23:10:00", 0.1, 1, 0);
00755         visir_img_burst_find_delta_chop(prop, &ichopchange, &ihalfcycle);
00756         cpl_test_eq(1, ichopchange);
00757         cpl_test_eq(5, ihalfcycle);
00758 
00759         visir_load_burst_(alist, blist, list, ichopchange, ihalfcycle, 0, 0);
00760         cpl_test_eq(5, cpl_imagelist_get_size(alist));
00761         cpl_test_eq(4, cpl_imagelist_get_size(blist));
00762 
00763         TEST_LIST(alist, 0xA);
00764         TEST_LIST(blist, 0xB);
00765 
00766         cpl_imagelist_delete(list);
00767         cpl_imagelist_delete(alist);
00768         cpl_imagelist_delete(blist);
00769         cpl_propertylist_delete(prop);
00770     }
00771 
00772     if (stream != stdout) cpl_test_zero( fclose(stream) );
00773 
00774 }
00775 
00776 
00777 static void visir_img_check_get_to_off_plane(void)
00778 {
00779 
00780     FILE          * stream;
00781     cpl_error_code  error = CPL_ERROR_NONE;
00782 
00783     stream = cpl_msg_get_level() > CPL_MSG_INFO
00784         ? fopen("/dev/null", "a") : stdout;
00785 
00786     cpl_test_nonnull( stream );
00787 
00788     {
00789         const int icc = 27;
00790         int istart = 0;
00791         int ihc = 100;
00792         cpl_test_eq(27, get_to_off_plane(icc, istart, ihc));
00793 
00794         istart = 10;
00795         cpl_test_eq(17, get_to_off_plane(icc, istart, ihc));
00796 
00797         istart = icc;
00798         cpl_test_eq(0, get_to_off_plane(icc, istart, ihc));
00799 
00800         istart = 50;
00801         cpl_test_eq(177, get_to_off_plane(icc, istart, ihc));
00802 
00803         istart = ihc;
00804         cpl_test_eq(127, get_to_off_plane(icc, istart, ihc));
00805 
00806         istart = ihc + icc;
00807         cpl_test_eq(100, get_to_off_plane(icc, istart, ihc));
00808 
00809         istart = 150;
00810         cpl_test_eq(77, get_to_off_plane(icc, istart, ihc));
00811 
00812         istart = ihc * 2;
00813         cpl_test_eq(27, get_to_off_plane(icc, istart, ihc));
00814 
00815         istart = ihc * 2 + 10;
00816         cpl_test_eq(17, get_to_off_plane(icc, istart, ihc));
00817 
00818         istart = ihc * 2 + 50;
00819         cpl_test_eq(177, get_to_off_plane(icc, istart, ihc));
00820 
00821         istart = 50;
00822         ihc = 80;
00823         cpl_test_eq(139, get_to_off_plane(29, istart, ihc));
00824     }
00825 
00826     if (stream != stdout) cpl_test_zero( fclose(stream) );
00827 }
00828 
00829 #define A_VAL 4.
00830 #define B_VAL 3.
00831 
00832 /* creates cube2 formated list, length 2*n + 1 */
00833 cpl_imagelist * create_cube2_imagelist(int ncycles)
00834 {
00835     cpl_imagelist * list = cpl_imagelist_new();
00836     float prev_val = 0;
00837     for (int i = 0; i < ncycles; i++) {
00838         cpl_image * image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
00839         cpl_image_set(image, 1, 1, A_VAL);
00840         cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
00841 
00842         image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
00843         float val = (prev_val * i + A_VAL - B_VAL) / (i + 1);
00844         cpl_image_set(image, 1, 1, val);
00845         cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
00846         prev_val = val;
00847     }
00848 
00849     cpl_image * image = cpl_image_new(3, 3, CPL_TYPE_FLOAT);
00850     cpl_image_set(image, 1, 1, prev_val);
00851     cpl_imagelist_set(list, image, cpl_imagelist_get_size(list));
00852     return list;
00853 }
00854 
00855 static void visir_img_check_load_cube2(void)
00856 {
00857 
00858     FILE          * stream;
00859     cpl_error_code  error = CPL_ERROR_NONE;
00860 
00861     stream = cpl_msg_get_level() > CPL_MSG_INFO
00862         ? fopen("/dev/null", "a") : stdout;
00863 
00864     cpl_test_nonnull( stream );
00865 
00866     {
00867         const int ncycles = 20;
00868         cpl_imagelist * list = create_cube2_imagelist(ncycles);
00869         cpl_imagelist * alist = cpl_imagelist_new();
00870         cpl_imagelist * blist = cpl_imagelist_new();
00871         cpl_test_eq(2 * ncycles + 1, cpl_imagelist_get_size(list));
00872 
00873         /* strip the sum */
00874         cpl_image_delete(cpl_imagelist_unset(list, cpl_imagelist_get_size(list) - 1));
00875 
00876         visir_load_cube2_split_(alist, blist, list, NULL);
00877         cpl_test_eq(ncycles, cpl_imagelist_get_size(alist));
00878         cpl_test_eq(ncycles, cpl_imagelist_get_size(blist));
00879         TEST_LIST(alist, A_VAL);
00880         TEST_LIST(blist, B_VAL);
00881 
00882         cpl_imagelist_delete(list);
00883         cpl_imagelist_delete(alist);
00884         cpl_imagelist_delete(blist);
00885     }
00886 
00887     /* test chunks */
00888     {
00889         const int ncycles = 40;
00890         cpl_image * prevd;
00891         cpl_imagelist * list = create_cube2_imagelist(ncycles);
00892         cpl_imagelist * alist = cpl_imagelist_new();
00893         cpl_imagelist * blist = cpl_imagelist_new();
00894         cpl_test_eq(2 * ncycles + 1, cpl_imagelist_get_size(list));
00895         cpl_imagelist * chunk2 = cpl_imagelist_new();
00896 
00897         /* strip the sum */
00898         cpl_image_delete(cpl_imagelist_unset(list,
00899                                              cpl_imagelist_get_size(list) - 1));
00900 
00901         for (int i = ncycles; i > 0; i--) {
00902             cpl_image * tmp =
00903                 cpl_imagelist_unset(list, cpl_imagelist_get_size(list) - i);
00904             cpl_imagelist_set(chunk2, tmp, cpl_imagelist_get_size(chunk2));
00905         }
00906         prevd =
00907             cpl_image_duplicate(cpl_imagelist_get(list,
00908                                                   cpl_imagelist_get_size(list) - 1));
00909 
00910         visir_load_cube2_split_(alist, blist, list, NULL);
00911         cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(alist));
00912         cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(blist));
00913         TEST_LIST(alist, A_VAL);
00914         TEST_LIST(blist, B_VAL);
00915 
00916         cpl_imagelist_empty(alist);
00917         cpl_imagelist_empty(blist);
00918 
00919         visir_load_cube2_split_(alist, blist, chunk2, prevd);
00920         cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(alist));
00921         cpl_test_eq(ncycles / 2, cpl_imagelist_get_size(blist));
00922         TEST_LIST(alist, A_VAL);
00923         TEST_LIST(blist, B_VAL);
00924 
00925         cpl_imagelist_delete(list);
00926         cpl_imagelist_delete(chunk2);
00927         cpl_imagelist_delete(alist);
00928         cpl_imagelist_delete(blist);
00929         cpl_image_delete(prevd);
00930     }
00931 
00932     if (stream != stdout) cpl_test_zero( fclose(stream) );
00933 }

Generated on Mon Feb 6 15:23:49 2012 for VISIR Pipeline Reference Manual by  doxygen 1.5.8