irplib_detmon_lg-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO IRPLIB 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 
00029 #include <irplib_detmon_lg.h>
00030 
00031 
00032 #include <math.h>
00033 /*---------------------------------------------------------------------------*/
00034 /*
00035  * @defgroup irplib_detmon_test   Testing of the IRPLIB utilities
00036  */
00037 /*---------------------------------------------------------------------------*/
00038 
00039 #define PI 3.141592653
00040 /*----------------------------------------------------------------------------
00041                                 Defines
00042  ----------------------------------------------------------------------------*/
00043 
00044 #ifndef IMAGESIZE
00045 #define IMAGESIZE       64
00046 #endif
00047 
00048 #define IMAGELISTSIZE   10
00049 
00050 #define NBADPIXS        10
00051 
00052 #define ON_LEVEL        300.0
00053 #define OFF_LEVEL       100.0
00054 
00055 #define NOISE_MIN       10.0
00056 #define NOISE_MAX       40.0
00057 
00058 #define ON TRUE
00059 #define OFF FALSE
00060 
00061 
00062 /*----------------------------------------------------------------------------
00063                             Private Function prototypes
00064  ----------------------------------------------------------------------------*/
00065 
00066 static void irplib_detmon_lg_tests(void);
00067 
00068 cpl_frameset * irplib_detmon_tests_fill_frameset(const char     * tag_on,
00069                                                  const char     * tag_off,
00070                                                  int              non,
00071                                                  cpl_boolean      opt_nir,
00072                                                  cpl_boolean      with_exts,
00073                                                  int              nexts,
00074                                                  int              nsettings);
00075 
00076 cpl_frameset * irplib_detmon_tests_fill_frameset_oct(const char         * tag_on,
00077                                                  const char     * tag_off,
00078                                                  int              non,
00079                                                  cpl_boolean      opt_nir,
00080                                                  cpl_boolean      with_exts,
00081                                                      int              nexts);
00082 
00083 int compare_settings(const cpl_frame * frame1, const cpl_frame * frame2);
00084 
00085 cpl_imagelist * irplib_detmon_tests_imlist(int ndits, cpl_boolean onoff);
00086 
00087 /*---------------------------------------------------------------------------*/
00088 /*
00089  * @brief   Unit tests of fit module
00090  */
00091 /*---------------------------------------------------------------------------*/
00092 
00093 int main(void)
00094 {
00095     /* Initialize CPL + IRPLIB */
00096     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00097 
00098     irplib_detmon_lg_tests();
00099 
00100     return cpl_test_end(0);
00101 }
00102 
00103 static void irplib_detmon_lg_tests(void)
00104 {
00105 
00106     /* Variables used for correlation function */
00107     int                   px, py;
00108     cpl_image           * image1;
00109 #ifdef HAVE_FFTW
00110     cpl_image           * image2;
00111 #endif
00112     cpl_image           * result;
00113 
00114     cpl_parameterlist   * parlist;
00115     cpl_frameset        * frameset;
00116     cpl_frameset        * set;
00117 
00118 
00119     /* Variables used for detmon_ir_lg function */
00120     const char                * tag_on;
00121     const char                * tag_off;
00122 
00123     /* Variable used for irplib_detmon_gain() testing */
00124     cpl_table * gain_table;
00125     cpl_imagelist * imlist_on;
00126     cpl_imagelist * imlist_off;
00127     cpl_imagelist * diff;
00128     cpl_imagelist * corr;
00129     cpl_vector * exptimes;
00130     cpl_propertylist * qclist;
00131     int i;
00132     double gain;
00133     if(0) {
00134 #ifdef HAVE_FFTW
00135     /* CORRELATION */
00136 
00137     /* 1. trial: all inputs illegal, NULL pointers */
00138     result = irplib_detmon_image_correlate(NULL, NULL, 0, 0);
00139     cpl_test_error(CPL_ERROR_NULL_INPUT);
00140     cpl_error_reset();
00141     cpl_test_null(result);
00142     cpl_image_delete(result);
00143 
00144     /* 2. trial: 2 equal and symmetrical images */
00145     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00146     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00147 
00148     image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00149     cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00150 
00151     px = -1;
00152     py = -1;
00153 
00154     result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00155 
00156     cpl_image_get_maxpos(result, &px, &py);
00157     cpl_test(px == 13+1 && py == 13+1);
00158 
00159     cpl_image_delete(image1);
00160     cpl_image_delete(image2);
00161     cpl_image_delete(result);
00162 
00163     /* 3. trial: 2 equal but not symmetrical images */
00164     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00165     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00166 
00167     image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00168     cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00169 
00170     px = -1;
00171     py = -1;
00172 
00173     result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00174 
00175     cpl_image_get_maxpos(result, &px, &py);
00176     cpl_test(px == 13+1 && py == 13+1);
00177 
00178     cpl_image_delete(image1);
00179     cpl_image_delete(image2);
00180     cpl_image_delete(result);
00181 
00182     /* 4. trial: 2 different images */
00183     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00184     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00185 
00186     image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00187     cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2+40, (IMAGESIZE + 1)/2+40, 25, 40, 40);
00188 
00189     px = -1;
00190     py = -1;
00191  
00192     result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00193 
00194     cpl_image_get_maxpos(result, &px, &py);
00195 //  FIXME
00196 //    cpl_test(px == 13+11 && py == 13+11);
00197         
00198     cpl_image_delete(image1);
00199     cpl_image_delete(image2);
00200     cpl_image_delete(result);
00201 #else
00202     /* CORRELATION with cpl_image_fft() */
00203 
00204     /* 1. trial: all inputs illegal, NULL pointers */
00205     result = irplib_detmon_autocorrelate(NULL, 0, 0);
00206     cpl_test_error(CPL_ERROR_NULL_INPUT);
00207     cpl_error_reset();
00208     cpl_test_null(result);
00209     cpl_image_delete(result);
00210 
00211     /* 2. trial: 2 equal and symmetrical images */
00212     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00213     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00214 
00215     px = -1;
00216     py = -1;
00217 
00218     result = irplib_detmon_autocorrelate(image1, 13, 13);
00219 //    cpl_msg_error(cpl_func, cpl_error_get_where());
00220 
00221     cpl_image_get_maxpos(result, &px, &py);
00222     cpl_test(px == 13+1 && py == 13+1);
00223 
00224     cpl_image_delete(image1);
00225     cpl_image_delete(result);
00226 
00227 #endif
00228 
00229     /* HIGH LEVEL FUNCTION FOR LINEARITY/GAIN RECIPE */
00230 
00231     tag_on  = "FRAME_ON";
00232     tag_off = "FRAME_OFF";
00233 
00234     set = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00235                         20, TRUE, FALSE, 0, 1);
00236     
00237 
00238     /* 1. test: All inputs illegal, NULL pointers */
00239     irplib_detmon_lg(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
00240              NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE);
00241     cpl_test_error(CPL_ERROR_NULL_INPUT);
00242     cpl_error_reset();
00243 
00244 
00245     /* 2. test: Default use, NIR case */
00246     parlist = cpl_parameterlist_new();
00247     irplib_detmon_lg_fill_parlist_nir_default(parlist,
00248                           "detmon_ir_lg", "detmon");
00249 
00250     frameset = cpl_frameset_duplicate(set);
00251 
00252     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00253              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00254              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00255              NULL, NULL, TRUE);
00256     cpl_test_error(CPL_ERROR_NONE);
00257     cpl_error_reset();
00258 
00259     cpl_frameset_delete(frameset);
00260     cpl_parameterlist_delete(parlist);
00261 
00262 
00263     /* 3. test: NIR case, MED method applied for GAIN */
00264     parlist = cpl_parameterlist_new();
00265     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00266                   "MED",
00267                             3,                /* --order         */
00268                             3,                /* --kappa         */
00269                             25,               /* --niter         */
00270                             -1,               /* --llx           */
00271                             -1,               /* --lly           */    
00272                             -1,               /* --urx           */
00273                             -1,               /* --ury           */
00274                             10000,            /* --ref_level     */
00275                             "CPL_FALSE",      /* --intermediate  */
00276                             "CPL_FALSE",      /* --autocorr      */
00277                             "CPL_FALSE",      /* --collapse      */
00278                             "CPL_TRUE",       /* --rescale       */
00279                             "CPL_TRUE",       /* --pix2pix       */
00280                             "CPL_FALSE",       /* --bpmbin       */
00281                               -1,             /* --filter        */
00282                             26,               /* --m             */
00283                             26,               /* --n             */
00284                   1e-3,
00285                   "detmon_ir_lg",
00286                             -1,               /* --llx1          */
00287                             -1,               /* --lly1          */
00288                             -1,               /* --urx1          */
00289                             -1,               /* --ury1          */
00290                             -1,               /* --llx2          */
00291                             -1,               /* --lly2          */
00292                             -1,               /* --urx2          */
00293                             -1,               /* --ury2          */
00294                             -1,               /* --llx3          */
00295                             -1,               /* --lly3          */
00296                             -1,               /* --urx3          */
00297                             -1,               /* --ury3          */
00298                             -1,               /* --llx4          */
00299                             -1,               /* --lly4          */
00300                             -1,               /* --urx4          */
00301                             -1,               /* --ury4          */
00302                             -1,               /* --llx5          */
00303                             -1,               /* --lly5          */
00304                             -1,               /* --urx5          */
00305                             -1,               /* --ury5          */
00306                   0,               /* --exts          */
00307     NIR);
00308 
00309     frameset = cpl_frameset_duplicate(set);
00310 
00311     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00312              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00313              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00314              NULL, NULL, TRUE);
00315     cpl_test_error(CPL_ERROR_NONE);
00316     cpl_error_reset();
00317 
00318     cpl_frameset_delete(frameset);
00319     cpl_parameterlist_delete(parlist);
00320 
00321     /*FIXME: The products should be checked to see that MED has been in fact
00322       applied (not only that it finished without errors) */
00323 
00324     /* 4. test: NIR case, --intermediate activated */
00325     parlist = cpl_parameterlist_new();
00326     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00327                   "PTC",
00328                             3,                /* --order         */
00329                             3,                /* --kappa         */
00330                             25,               /* --niter         */
00331                             -1,               /* --llx           */
00332                             -1,               /* --lly           */    
00333                             -1,               /* --urx           */
00334                             -1,               /* --ury           */
00335                             10000,            /* --ref_level     */
00336                             "CPL_TRUE",      /* --intermediate  */
00337                             "CPL_FALSE",      /* --autocorr      */
00338                             "CPL_FALSE",      /* --collapse      */
00339                             "CPL_TRUE",       /* --rescale       */
00340                             "CPL_TRUE",       /* --pix2pix       */
00341                             "CPL_FALSE",       /* --bpmbin       */
00342                               -1,             /* --filter        */
00343                             26,               /* --m             */
00344                             26,               /* --n             */
00345                   1e-3,
00346                   "detmon_ir_lg",
00347                             -1,               /* --llx1          */
00348                             -1,               /* --lly1          */
00349                             -1,               /* --urx1          */
00350                             -1,               /* --ury1          */
00351                             -1,               /* --llx2          */
00352                             -1,               /* --lly2          */
00353                             -1,               /* --urx2          */
00354                             -1,               /* --ury2          */
00355                             -1,               /* --llx3          */
00356                             -1,               /* --lly3          */
00357                             -1,               /* --urx3          */
00358                             -1,               /* --ury3          */
00359                             -1,               /* --llx4          */
00360                             -1,               /* --lly4          */
00361                             -1,               /* --urx4          */
00362                             -1,               /* --ury4          */
00363                             -1,               /* --llx5          */
00364                             -1,               /* --lly5          */
00365                             -1,               /* --urx5          */
00366                             -1,               /* --ury5          */
00367                   0,               /* --exts          */
00368     NIR);
00369 
00370     frameset = cpl_frameset_duplicate(set);
00371 
00372     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00373              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00374              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00375              NULL, NULL, TRUE);
00376     cpl_test_error(CPL_ERROR_NONE);
00377     cpl_error_reset();
00378 
00379     cpl_frameset_delete(frameset);
00380     cpl_parameterlist_delete(parlist);
00381 
00382     /*FIXME: Check that the new intermediate have been in fact created */
00383 
00384     /* 5. test: NIR case, --rescale deactivated */
00385     parlist = cpl_parameterlist_new();
00386     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00387                   "PTC",
00388                             3,                /* --order         */
00389                             3,                /* --kappa         */
00390                             25,               /* --niter         */
00391                             -1,               /* --llx           */
00392                             -1,               /* --lly           */    
00393                             -1,               /* --urx           */
00394                             -1,               /* --ury           */
00395                             10000,            /* --ref_level     */
00396                             "CPL_FALSE",      /* --intermediate  */
00397                             "CPL_FALSE",      /* --autocorr      */
00398                             "CPL_FALSE",      /* --collapse      */
00399                             "CPL_FALSE",       /* --rescale       */
00400                             "CPL_TRUE",       /* --pix2pix       */
00401                             "CPL_FALSE",       /* --bpmbin       */
00402                               -1,             /* --filter        */
00403                             26,               /* --m             */
00404                             26,               /* --n             */
00405                   1e-3,
00406                   "detmon_ir_lg",
00407                             -1,               /* --llx1          */
00408                             -1,               /* --lly1          */
00409                             -1,               /* --urx1          */
00410                             -1,               /* --ury1          */
00411                             -1,               /* --llx2          */
00412                             -1,               /* --lly2          */
00413                             -1,               /* --urx2          */
00414                             -1,               /* --ury2          */
00415                             -1,               /* --llx3          */
00416                             -1,               /* --lly3          */
00417                             -1,               /* --urx3          */
00418                             -1,               /* --ury3          */
00419                             -1,               /* --llx4          */
00420                             -1,               /* --lly4          */
00421                             -1,               /* --urx4          */
00422                             -1,               /* --ury4          */
00423                             -1,               /* --llx5          */
00424                             -1,               /* --lly5          */
00425                             -1,               /* --urx5          */
00426                             -1,               /* --ury5          */
00427                   0,               /* --exts          */
00428     NIR);
00429 
00430     frameset = cpl_frameset_duplicate(set);
00431 
00432     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00433              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00434              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00435              NULL, NULL, TRUE);
00436     cpl_test_error(CPL_ERROR_NONE);
00437     cpl_error_reset();
00438 
00439     cpl_frameset_delete(frameset);
00440     cpl_parameterlist_delete(parlist);
00441 
00442     /* 5a. test: NIR case, --bpmbin activated */
00443     parlist = cpl_parameterlist_new();
00444     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00445                   "PTC",
00446                             3,                /* --order         */
00447                             3,                /* --kappa         */
00448                             25,               /* --niter         */
00449                             -1,               /* --llx           */
00450                             -1,               /* --lly           */    
00451                             -1,               /* --urx           */
00452                             -1,               /* --ury           */
00453                             10000,            /* --ref_level     */
00454                             "CPL_FALSE",      /* --intermediate  */
00455                             "CPL_FALSE",      /* --autocorr      */
00456                             "CPL_FALSE",      /* --collapse      */
00457                             "CPL_TRUE",       /* --rescale       */
00458                             "CPL_TRUE",       /* --pix2pix       */
00459                             "CPL_TRUE",       /* --bpmbin       */
00460                               -1,             /* --filter        */
00461                             26,               /* --m             */
00462                             26,               /* --n             */
00463                   1e-3,
00464                   "detmon_ir_lg",
00465                             -1,               /* --llx1          */
00466                             -1,               /* --lly1          */
00467                             -1,               /* --urx1          */
00468                             -1,               /* --ury1          */
00469                             -1,               /* --llx2          */
00470                             -1,               /* --lly2          */
00471                             -1,               /* --urx2          */
00472                             -1,               /* --ury2          */
00473                             -1,               /* --llx3          */
00474                             -1,               /* --lly3          */
00475                             -1,               /* --urx3          */
00476                             -1,               /* --ury3          */
00477                             -1,               /* --llx4          */
00478                             -1,               /* --lly4          */
00479                             -1,               /* --urx4          */
00480                             -1,               /* --ury4          */
00481                             -1,               /* --llx5          */
00482                             -1,               /* --lly5          */
00483                             -1,               /* --urx5          */
00484                             -1,               /* --ury5          */
00485                   0,               /* --exts          */
00486     NIR);
00487 
00488     frameset = cpl_frameset_duplicate(set);
00489 
00490     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00491              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00492              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00493              NULL, NULL, TRUE);
00494     cpl_test_error(CPL_ERROR_NONE);
00495     cpl_error_reset();
00496 
00497     {
00498     /* Check that the image is in fact binary */
00499     cpl_image * bpm = cpl_image_load("detmon_ir_lg_bpm.fits",
00500                      CPL_TYPE_INT, 0, 0);
00501 
00502     cpl_mask * mask = cpl_mask_threshold_image_create(bpm, 0.5, 1.5);
00503 
00504     int nbpixs = cpl_mask_count(mask);
00505 
00506     int flux = (int)cpl_image_get_flux(bpm);
00507 
00508     cpl_test_eq(flux, nbpixs);
00509 
00510     cpl_image_delete(bpm);
00511     cpl_mask_delete(mask);
00512     }
00513 
00514     cpl_frameset_delete(frameset);
00515     cpl_parameterlist_delete(parlist);
00516 
00517     /* Is there any way, looking into the products, to know if the --rescale
00518        has been in fact deactivated? Other health checkings should be done 
00519        here to prove that the deactivation doesn't compromise correctness */
00520 
00521     /* 6. test: NIR case, --pix2pix deactivated */
00522     parlist = cpl_parameterlist_new();
00523     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00524                   "PTC",
00525                             3,                /* --order         */
00526                             3,                /* --kappa         */
00527                             25,               /* --niter         */
00528                             -1,               /* --llx           */
00529                             -1,               /* --lly           */    
00530                             -1,               /* --urx           */
00531                             -1,               /* --ury           */
00532                             10000,            /* --ref_level     */
00533                             "CPL_FALSE",      /* --intermediate  */
00534                             "CPL_FALSE",      /* --autocorr      */
00535                             "CPL_FALSE",      /* --collapse      */
00536                             "CPL_TRUE",       /* --rescale       */
00537                             "CPL_FALSE",       /* --pix2pix       */
00538                             "CPL_FALSE",       /* --bpmbin       */
00539                               -1,             /* --filter        */
00540                             26,               /* --m             */
00541                             26,               /* --n             */
00542                   1e-3,
00543                   "detmon_ir_lg",
00544                             -1,               /* --llx1          */
00545                             -1,               /* --lly1          */
00546                             -1,               /* --urx1          */
00547                             -1,               /* --ury1          */
00548                             -1,               /* --llx2          */
00549                             -1,               /* --lly2          */
00550                             -1,               /* --urx2          */
00551                             -1,               /* --ury2          */
00552                             -1,               /* --llx3          */
00553                             -1,               /* --lly3          */
00554                             -1,               /* --urx3          */
00555                             -1,               /* --ury3          */
00556                             -1,               /* --llx4          */
00557                             -1,               /* --lly4          */
00558                             -1,               /* --urx4          */
00559                             -1,               /* --ury4          */
00560                             -1,               /* --llx5          */
00561                             -1,               /* --lly5          */
00562                             -1,               /* --urx5          */
00563                             -1,               /* --ury5          */
00564                   0,               /* --exts          */
00565     NIR);
00566 
00567     frameset = cpl_frameset_duplicate(set);
00568 
00569 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00570              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00571              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00572              NULL, NULL, TRUE);
00573     cpl_test_error(CPL_ERROR_NONE);
00574     cpl_error_reset();
00575 */
00576     cpl_frameset_delete(frameset);
00577     cpl_parameterlist_delete(parlist);
00578 
00579     /* Should check at least that there is no data cube */
00580 
00581     /* 7. test: NIR case, --filter activated (4000) */
00582     parlist = cpl_parameterlist_new();
00583     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00584                   "PTC",
00585                             3,                /* --order         */
00586                             3,                /* --kappa         */
00587                             25,               /* --niter         */
00588                             -1,               /* --llx           */
00589                             -1,               /* --lly           */    
00590                             -1,               /* --urx           */
00591                             -1,               /* --ury           */
00592                             10000,            /* --ref_level     */
00593                             "CPL_FALSE",      /* --intermediate  */
00594                             "CPL_FALSE",      /* --autocorr      */
00595                             "CPL_FALSE",      /* --collapse      */
00596                             "CPL_TRUE",       /* --rescale       */
00597                             "CPL_TRUE",       /* --pix2pix       */
00598                             "CPL_FALSE",       /* --bpmbin       */
00599                               4000,             /* --filter        */
00600                             26,               /* --m             */
00601                             26,               /* --n             */
00602                   1e-3,
00603                   "detmon_ir_lg",
00604                             -1,               /* --llx1          */
00605                             -1,               /* --lly1          */
00606                             -1,               /* --urx1          */
00607                             -1,               /* --ury1          */
00608                             -1,               /* --llx2          */
00609                             -1,               /* --lly2          */
00610                             -1,               /* --urx2          */
00611                             -1,               /* --ury2          */
00612                             -1,               /* --llx3          */
00613                             -1,               /* --lly3          */
00614                             -1,               /* --urx3          */
00615                             -1,               /* --ury3          */
00616                             -1,               /* --llx4          */
00617                             -1,               /* --lly4          */
00618                             -1,               /* --urx4          */
00619                             -1,               /* --ury4          */
00620                             -1,               /* --llx5          */
00621                             -1,               /* --lly5          */
00622                             -1,               /* --urx5          */
00623                             -1,               /* --ury5          */
00624                   0,               /* --exts          */
00625     NIR);
00626 
00627     frameset = cpl_frameset_duplicate(set);
00628 
00629     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00630              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00631              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00632              NULL, NULL, TRUE);
00633     cpl_test_error(CPL_ERROR_NONE);
00634     cpl_error_reset();
00635 
00636     cpl_frameset_delete(frameset);
00637     cpl_parameterlist_delete(parlist);
00638 
00639     /*FIXME: Move this deletion more to the end if standard set used
00640       for more tests */
00641     cpl_frameset_delete(set);
00642 
00643     /* Check that there are less entries into the table.
00644      We should know for sure how many entries are going to be!
00645     To avoid other errors as not having enough points for fitting!*/
00646 
00647     /* 8. test: Check that it fails when not enough frames for order-degree
00648        fitting */
00649     parlist = cpl_parameterlist_new();
00650     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00651                   "PTC",
00652                             3,                /* --order         */
00653                             3,                /* --kappa         */
00654                             25,               /* --niter         */
00655                             -1,               /* --llx           */
00656                             -1,               /* --lly           */    
00657                             -1,               /* --urx           */
00658                             -1,               /* --ury           */
00659                             10000,            /* --ref_level     */
00660                             "CPL_FALSE",      /* --intermediate  */
00661                             "CPL_FALSE",      /* --autocorr      */
00662                             "CPL_FALSE",      /* --collapse      */
00663                             "CPL_TRUE",       /* --rescale       */
00664                             "CPL_TRUE",       /* --pix2pix       */
00665                             "CPL_FALSE",       /* --bpmbin       */
00666                               -1,             /* --filter        */
00667                             26,               /* --m             */
00668                             26,               /* --n             */
00669                   1e-3,
00670                   "detmon_ir_lg",
00671                             -1,               /* --llx1          */
00672                             -1,               /* --lly1          */
00673                             -1,               /* --urx1          */
00674                             -1,               /* --ury1          */
00675                             -1,               /* --llx2          */
00676                             -1,               /* --lly2          */
00677                             -1,               /* --urx2          */
00678                             -1,               /* --ury2          */
00679                             -1,               /* --llx3          */
00680                             -1,               /* --lly3          */
00681                             -1,               /* --urx3          */
00682                             -1,               /* --ury3          */
00683                             -1,               /* --llx4          */
00684                             -1,               /* --lly4          */
00685                             -1,               /* --urx4          */
00686                             -1,               /* --ury4          */
00687                             -1,               /* --llx5          */
00688                             -1,               /* --lly5          */
00689                             -1,               /* --urx5          */
00690                             -1,               /* --ury5          */
00691                   0,               /* --exts          */
00692     NIR);
00693 
00694     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00695                          6, TRUE, FALSE, 0, 1);
00696 
00697 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00698              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00699              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00700              NULL, NULL, TRUE);
00701     cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
00702     cpl_error_reset();
00703 */
00704     cpl_frameset_delete(frameset);
00705     cpl_parameterlist_delete(parlist);
00706 
00707 
00708     /* 9. test: Default use, OPT case */
00709     parlist = cpl_parameterlist_new();
00710     irplib_detmon_lg_fill_parlist_opt_default(parlist,
00711                           "detmon_opt_lg", "detmon");
00712 
00713     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00714                          20, FALSE, FALSE, 0, 1);
00715 
00716 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_opt_lg",
00717              "detmon", REGEXP, "PRO-1.15", "PRO-1.15", "PRO-1.15",
00718              "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0",
00719              NULL, NULL, FALSE);
00720     cpl_test_error(CPL_ERROR_NONE);
00721     cpl_error_reset();
00722 */
00723     cpl_frameset_delete(frameset);
00724     cpl_parameterlist_delete(parlist);
00725 
00726 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 1, 0)
00727     /* 4. test: Passing a frameset where frames have extensions */
00728     parlist = cpl_parameterlist_new();
00729     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00730                   "PTC",
00731                             3,                /* --order         */
00732                             3,                /* --kappa         */
00733                             25,               /* --niter         */
00734                             -1,               /* --llx           */
00735                             -1,               /* --lly           */    
00736                             -1,               /* --urx           */
00737                             -1,               /* --ury           */
00738                             10000,            /* --ref_level     */
00739                             "CPL_FALSE",      /* --intermediate  */
00740                             "CPL_FALSE",      /* --autocorr      */
00741                             "CPL_FALSE",      /* --collapse      */
00742                             "CPL_TRUE",       /* --rescale       */
00743                             "CPL_TRUE",       /* --pix2pix       */
00744                             "CPL_FALSE",       /* --bpmbin       */
00745                               -1,             /* --filter        */
00746                             26,               /* --m             */
00747                             26,               /* --n             */
00748                   1e-3,
00749                   "detmon_ir_lg",
00750                             -1,               /* --llx1          */
00751                             -1,               /* --lly1          */
00752                             -1,               /* --urx1          */
00753                             -1,               /* --ury1          */
00754                             -1,               /* --llx2          */
00755                             -1,               /* --lly2          */
00756                             -1,               /* --urx2          */
00757                             -1,               /* --ury2          */
00758                             -1,               /* --llx3          */
00759                             -1,               /* --lly3          */
00760                             -1,               /* --urx3          */
00761                             -1,               /* --ury3          */
00762                             -1,               /* --llx4          */
00763                             -1,               /* --lly4          */
00764                             -1,               /* --urx4          */
00765                             -1,               /* --ury4          */
00766                             -1,               /* --llx5          */
00767                             -1,               /* --lly5          */
00768                             -1,               /* --urx5          */
00769                             -1,               /* --ury5          */
00770                   -1,               /* --exts          */
00771     NIR);
00772     /*
00773                                     * Unique change of this call with
00774                                     * respect of the default call:
00775                                     * last parameter --exts = -1
00776                                     * to tell the recipe to compute on
00777                                     * all extensions.
00778                                     */
00779 
00780     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00781                                                  20, TRUE, TRUE, 8, 1);
00782     
00783     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00784                      "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", NULL, NULL, TRUE);
00785     cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00786                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00787     //    cpl_msg_error(cpl_func, cpl_error_get_where());
00788     cpl_error_reset();
00789     
00790     cpl_parameterlist_delete(parlist);
00791     cpl_frameset_delete(frameset);
00792 #endif
00793 
00794     /* 2 Trial: passing a frameset where frames have extensions,
00795        but computing on a single extension */
00796     parlist = cpl_parameterlist_new();
00797     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00798                   "PTC",
00799                             3,                /* --order         */
00800                             3,                /* --kappa         */
00801                             25,               /* --niter         */
00802                             -1,               /* --llx           */
00803                             -1,               /* --lly           */    
00804                             -1,               /* --urx           */
00805                             -1,               /* --ury           */
00806                             10000,            /* --ref_level     */
00807                             "CPL_FALSE",      /* --intermediate  */
00808                             "CPL_FALSE",      /* --autocorr      */
00809                             "CPL_FALSE",      /* --collapse      */
00810                             "CPL_TRUE",       /* --rescale       */
00811                             "CPL_TRUE",       /* --pix2pix       */
00812                             "CPL_FALSE",       /* --bpmbin       */
00813                               -1,             /* --filter        */
00814                             26,               /* --m             */
00815                             26,               /* --n             */
00816                   1e-3,
00817                   "detmon_ir_lg",
00818                             -1,               /* --llx1          */
00819                             -1,               /* --lly1          */
00820                             -1,               /* --urx1          */
00821                             -1,               /* --ury1          */
00822                             -1,               /* --llx2          */
00823                             -1,               /* --lly2          */
00824                             -1,               /* --urx2          */
00825                             -1,               /* --ury2          */
00826                             -1,               /* --llx3          */
00827                             -1,               /* --lly3          */
00828                             -1,               /* --urx3          */
00829                             -1,               /* --ury3          */
00830                             -1,               /* --llx4          */
00831                             -1,               /* --lly4          */
00832                             -1,               /* --urx4          */
00833                             -1,               /* --ury4          */
00834                             -1,               /* --llx5          */
00835                             -1,               /* --lly5          */
00836                             -1,               /* --urx5          */
00837                             -1,               /* --ury5          */
00838                   2,               /* --exts          */
00839     NIR);
00840     /*
00841                                     * Main change of this call with
00842                                     * respect of the default call:
00843                                     * last parameter --exts = 2
00844                                     * to tell the recipe to compute only on
00845                                     * the second extension.
00846                                     */
00847 
00848     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00849                                                  20, TRUE, TRUE, 8, 1);
00850     
00851     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00852                      "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", NULL, NULL, TRUE);
00853     cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00854                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00855     //    cpl_msg_error(cpl_func, cpl_error_get_where());
00856     cpl_error_reset();
00857     
00858     cpl_parameterlist_delete(parlist);
00859     cpl_frameset_delete(frameset);
00860 
00861 
00862     /* New trial. With a octatett instead of a quartett. */
00863     parlist = cpl_parameterlist_new();
00864     irplib_detmon_lg_fill_parlist_nir_default(parlist, "detmon_ir_lg", "detmon");
00865 
00866     frameset = irplib_detmon_tests_fill_frameset_oct(tag_on, tag_off, 20, TRUE, FALSE, 0);
00867 
00868 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00869                      "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", NULL, NULL, TRUE);
00870     cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00871                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00872     cpl_error_reset();
00873 */
00874     cpl_parameterlist_delete(parlist);
00875     cpl_frameset_delete(frameset);
00876 
00877     /* Test with more than a single setting */
00878     parlist = cpl_parameterlist_new();
00879     irplib_detmon_lg_fill_parlist_nir_default(parlist, "detmon_ir_lg", "detmon");
00880 
00881     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00882                                                  20, TRUE, FALSE, 0, 3);
00883 
00884     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP, 
00885                      "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", compare_settings, NULL, TRUE);
00886 
00887     cpl_test_error(CPL_ERROR_NONE);
00888 
00889     cpl_parameterlist_delete(parlist);
00890     cpl_frameset_delete(frameset);
00891 
00892     cpl_test_zero(system("rm *.paf *.fits"));
00893 
00894     }
00895     /* TESTS for irplib_detmon_gain() */
00896 
00897     /* Test with NULL inputs */
00898     gain_table = irplib_detmon_gain(NULL, NULL, NULL, 0, 0, 0, 0, 0.0,
00899                                     0, 0, 0, NULL, 0, NULL, NULL);
00900     cpl_test_null(gain_table);
00901     cpl_test_error(CPL_ERROR_NULL_INPUT);
00902 
00903     imlist_on  = irplib_detmon_tests_imlist(8, ON);
00904     imlist_off = irplib_detmon_tests_imlist(8, OFF);
00905 
00906     exptimes = cpl_vector_new(16);
00907 
00908     for(i = 0; i < 16; i++) {
00909       cpl_vector_set(exptimes, i, (double)(i/2 + 1));
00910     }
00911 
00912     qclist = cpl_propertylist_new();
00913 
00914     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00915                                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00916                                     qclist, IRPLIB_GAIN_NO_COLLAPSE,
00917                                     NULL, NULL);
00918     cpl_test_nonnull(gain_table);
00919     cpl_test_error(CPL_ERROR_NONE);
00920 
00921     /* Check correctness */
00922     gain = cpl_propertylist_get_double(qclist, DETMON_QC_GAIN);
00923     cpl_test(gain > 220.0 && gain < 240.0);
00924 
00925     cpl_table_delete(gain_table);
00926     cpl_propertylist_delete(qclist);
00927 
00928 
00929     qclist = cpl_propertylist_new();
00930 
00931     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00932                                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00933                                     qclist, IRPLIB_GAIN_NO_COLLAPSE |
00934                                     IRPLIB_GAIN_PTC,
00935                                     NULL, NULL);
00936     cpl_test_nonnull(gain_table);
00937     cpl_test_error(CPL_ERROR_NONE);
00938 
00939     /* Check correctness */
00940     gain = cpl_propertylist_get_double(qclist, DETMON_QC_GAIN);
00941     cpl_test(gain > 160.0 && gain < 180.0);
00942 
00943     cpl_table_delete(gain_table);
00944     cpl_propertylist_delete(qclist);
00945 
00946     qclist = cpl_propertylist_new();
00947 
00948     diff = NULL;
00949     corr = NULL;
00950 
00951     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00952                                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00953                                     qclist, IRPLIB_GAIN_NO_COLLAPSE |
00954                                     IRPLIB_GAIN_WITH_AUTOCORR, &diff, &corr);
00955     cpl_test_nonnull(gain_table);
00956     cpl_test_nonnull(diff);
00957     cpl_test_nonnull(corr);
00958     cpl_test_error(CPL_ERROR_NONE);
00959 
00960     cpl_imagelist_delete(diff);
00961     cpl_imagelist_delete(corr);
00962     cpl_table_delete(gain_table);
00963     cpl_propertylist_delete(qclist);
00964 
00965     qclist = cpl_propertylist_new();
00966 
00967     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 1, 1,
00968                                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00969                                     qclist, IRPLIB_GAIN_NO_COLLAPSE |
00970                                     IRPLIB_GAIN_WITH_AUTOCORR, NULL, NULL);
00971     cpl_test_nonnull(gain_table);
00972     cpl_test_error(CPL_ERROR_NONE);
00973 
00974     cpl_imagelist_delete(imlist_on);
00975     cpl_imagelist_delete(imlist_off);
00976     cpl_propertylist_delete(qclist);
00977     cpl_vector_delete(exptimes);
00978     cpl_table_delete(gain_table);
00979 }
00980 
00981 /*---------------------------------------------------------------------------*/
00982 /*
00983  * @brief  Detect bad pixels of a selected type
00984  * @param  in           Input image
00985  * @param  mean         Mean level of the image - used to compute threshold
00986  * @param  sigma        Stdev level of the image - used to compute threshold
00987  * @param  flag         Flag - represents selected type of bad pixels (see enum)
00988  * @return The detected bad pixels in a cpl_mask.
00989  */
00990 /*---------------------------------------------------------------------------*/
00991 
00992 cpl_frameset * irplib_detmon_tests_fill_frameset(const char     * tag_on,
00993                                                  const char     * tag_off,
00994                                                  int              non,
00995                                                  cpl_boolean      opt_nir,
00996                                                  cpl_boolean      with_exts,
00997                                                  int              nexts,
00998                                                  int              nsettings)
00999 {
01000     cpl_frameset                * frameset;
01001     cpl_frame                   * frame;
01002     int i, h;
01003     char                        frame_name[20];
01004     cpl_propertylist            * plist;
01005     cpl_image                   * image;
01006     frameset = cpl_frameset_new();
01007 
01008     for (h = 0; h < nsettings; h++) {
01009     for (i=0; i<non; i++) {
01010         frame = cpl_frame_new();
01011         sprintf(frame_name, "dummyon%d%d.fits",i,h);
01012         cpl_frame_set_filename(frame, frame_name);
01013         cpl_frame_set_tag(frame, tag_on);
01014         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01015         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01016 
01017         cpl_frameset_insert(frameset, frame);
01018 
01019         plist = cpl_propertylist_new();
01020         if(opt_nir == TRUE) {
01021         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01022         } else {
01023         cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01024         }
01025 
01026         cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2 + 1) );
01027         cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01028 
01029         cpl_propertylist_append_double(plist, "SETTING", h+1);
01030         if(with_exts == TRUE) {
01031         int j;
01032         cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01033         for(j = 0; j < nexts; j++) {
01034             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01035             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01036             cpl_image_add_scalar(image,300* i);
01037             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01038 
01039             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01040             cpl_image_delete(image);
01041         }
01042         } else {
01043         image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01044         cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01045         cpl_image_add_scalar(image,300* i);
01046         cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01047 
01048         cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01049 
01050 
01051         cpl_image_delete(image);
01052         }
01053         cpl_propertylist_delete(plist);
01054     }
01055     for (i=0; i<non; i++) {
01056 
01057 
01058         frame = cpl_frame_new();
01059         sprintf(frame_name, "dummyoff%d%d.fits",i,h);
01060         cpl_frame_set_filename(frame, frame_name);
01061         cpl_frame_set_tag(frame, tag_off);
01062         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01063         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01064 
01065         cpl_frameset_insert(frameset, frame);
01066 
01067         plist = cpl_propertylist_new();
01068         if(opt_nir == TRUE) {
01069         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01070         } else {
01071         cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01072         }
01073         cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01074         cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2 + 1));
01075         cpl_propertylist_append_double(plist, "SETTING", h+1);
01076 
01077         if(with_exts == TRUE) {
01078         int j;
01079         cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01080         for(j = 0; j < nexts; j++) {
01081             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01082             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01083             cpl_image_add_scalar(image, i);
01084             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01085 
01086             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01087             cpl_image_delete(image);
01088         }
01089         } else {
01090         image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01091         cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01092         cpl_image_add_scalar(image, i);
01093         cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01094 
01095         cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01096 
01097 
01098         cpl_image_delete(image);
01099         }
01100         cpl_propertylist_delete(plist);
01101     }
01102     }
01103 
01104     return frameset;
01105 }
01106 
01107 
01108 cpl_frameset * irplib_detmon_tests_fill_frameset_oct(const char         * tag_on,
01109                                                  const char     * tag_off,
01110                                                  int              non,
01111                                                  cpl_boolean      opt_nir,
01112                                                  cpl_boolean      with_exts,
01113                                                  int              nexts)
01114 {
01115     cpl_frameset                * frameset;
01116     cpl_frame                   * frame;
01117     int i;
01118     char                        frame_name[20];
01119     cpl_propertylist            * plist;
01120     cpl_image                   * image;
01121     frameset = cpl_frameset_new();
01122 
01123     for (i=0; i<non; i++) {
01124         frame = cpl_frame_new();
01125         sprintf(frame_name, "dummyon%d.fits",i);
01126         cpl_frame_set_filename(frame, frame_name);
01127         cpl_frame_set_tag(frame, tag_on);
01128         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01129         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01130 
01131         cpl_frameset_insert(frameset, frame);
01132 
01133         plist = cpl_propertylist_new();
01134         if(opt_nir == TRUE) {
01135           if( i == 2 || i == 3) {
01136             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(1));
01137             cpl_propertylist_append_double(plist, "EXPTIME", (double)(1));
01138             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01139           } else {
01140             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01141             cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
01142             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01143           }
01144         } else {
01145             cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01146             cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
01147             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01148         }
01149 
01150         if(with_exts == TRUE) {
01151           int j;
01152           cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01153           for(j = 0; j < nexts; j++) {
01154             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01155             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01156         if(i == 0 || i == 1 || i== 2 || i == 3) {
01157         cpl_image_add_scalar(image,300);
01158         } else
01159         cpl_image_add_scalar(image,300* i);
01160             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01161 
01162             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01163             cpl_image_delete(image);
01164           }
01165         } else {
01166             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01167             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01168         if(i == 0 || i == 1 || i== 2 || i == 3) {
01169         cpl_image_add_scalar(image,300);
01170         } else
01171         cpl_image_add_scalar(image,300* i);
01172 
01173             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01174 
01175             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01176 
01177 
01178             cpl_image_delete(image);
01179         }
01180         cpl_propertylist_delete(plist);
01181     }
01182 
01183     for (i=0; i<non; i++) {
01184 
01185 
01186         frame = cpl_frame_new();
01187         sprintf(frame_name, "dummyoff%d.fits",i);
01188         cpl_frame_set_filename(frame, frame_name);
01189         cpl_frame_set_tag(frame, tag_off);
01190         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01191         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01192 
01193         cpl_frameset_insert(frameset, frame);
01194 
01195         plist = cpl_propertylist_new();
01196         if(opt_nir == TRUE) {
01197           if( i == 2 || i == 3) {
01198             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(1));
01199             cpl_propertylist_append_double(plist, "EXPTIME", (double)(1));
01200             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01201           } else {
01202             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01203             cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
01204             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01205           }
01206         } else {
01207             cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01208             cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
01209             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01210         }
01211 
01212         if(with_exts == TRUE) {
01213           int j;
01214           cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01215           for(j = 0; j < nexts; j++) {
01216             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01217             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01218         if(i == 0 || i == 1 || i== 2 || i == 3) {
01219         cpl_image_add_scalar(image,300);
01220         } else
01221         cpl_image_add_scalar(image,300* i);
01222 
01223             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01224 
01225             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01226             cpl_image_delete(image);
01227           }
01228         } else {
01229             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01230             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01231         if(i == 0 || i == 1 || i== 2 || i == 3) {
01232         cpl_image_add_scalar(image,300);
01233         } else
01234         cpl_image_add_scalar(image,300* i);
01235 
01236             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01237 
01238             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01239 
01240 
01241             cpl_image_delete(image);
01242         }
01243         cpl_propertylist_delete(plist);
01244     }
01245 
01246     return frameset;
01247 }
01248 
01249 
01250 int compare_settings(const cpl_frame * frame1, const cpl_frame * frame2)
01251 {
01252     int                     comparison;
01253     cpl_propertylist       *plist1;
01254     cpl_propertylist       *plist2;
01255     double                  dval1, dval2;
01256 
01257     /* Test entries */
01258     if(frame1 == NULL || frame2 == NULL)
01259         return -1;
01260 
01261     /* Get property lists */
01262     if((plist1 = cpl_propertylist_load(cpl_frame_get_filename(frame1),
01263                                        0)) == NULL) {
01264         cpl_msg_error(cpl_func, "getting header from reference frame");
01265         return -1;
01266     }
01267     if((plist2 = cpl_propertylist_load(cpl_frame_get_filename(frame2),
01268                                        0)) == NULL) {
01269         cpl_msg_error(cpl_func, "getting header from reference frame");
01270         cpl_propertylist_delete(plist1);
01271         return -1;
01272     }
01273 
01274     /* Test status */
01275     if(cpl_error_get_code()) {
01276         cpl_propertylist_delete(plist1);
01277         cpl_propertylist_delete(plist2);
01278         return -1;
01279     }
01280 
01281     /* Compare exposure time */
01282     comparison = 1;
01283     dval1 = cpl_propertylist_get_double(plist1, "SETTING");
01284     dval2 = cpl_propertylist_get_double(plist2, "SETTING");
01285     if(cpl_error_get_code()) {
01286         cpl_msg_error(cpl_func, "cannot get exposure time");
01287         cpl_propertylist_delete(plist1);
01288         cpl_propertylist_delete(plist2);
01289         return -1;
01290     }
01291     if( dval1 != dval2)
01292         comparison = 0;
01293 
01294     /* Free and return */
01295     cpl_propertylist_delete(plist1);
01296     cpl_propertylist_delete(plist2);
01297     return comparison;
01298 
01299 }
01300 
01301 cpl_imagelist * irplib_detmon_tests_imlist(int ndits, cpl_boolean onoff)
01302 {
01303   cpl_imagelist * imlist = cpl_imagelist_new();
01304   int i;
01305 
01306   double levelstep = onoff ? ON_LEVEL : OFF_LEVEL;
01307   double factor    = onoff ? 1.0 : 0.5;
01308 
01309   for (i = 1; i <= ndits; i++) {
01310     cpl_image * im1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01311     cpl_image * im2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01312     double noise_min = NOISE_MIN * sqrt(i) / (double) ndits * factor;
01313     double noise_max = NOISE_MAX * sqrt(i) / (double) ndits * factor;
01314     cpl_image_fill_noise_uniform(im1, noise_min, noise_max);
01315     cpl_image_fill_noise_uniform(im2, noise_min, noise_max);
01316     cpl_image_add_scalar(im1, levelstep * i);
01317     cpl_image_add_scalar(im2, levelstep * i);
01318     cpl_imagelist_set(imlist, im1, 2 * (i - 1));
01319     cpl_imagelist_set(imlist, im2, 2 * (i - 1) + 1);
01320   }
01321 
01322   return imlist;
01323 }
01324 

Generated on Mon Apr 21 10:56:53 2008 for UVES Pipeline Reference Manual by  doxygen 1.5.1