uves_wavecal-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO UVES Pipeline                                 *
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 /*
00021  * $Author: amodigli $
00022  * $Date: 2007/08/13 12:15:43 $
00023  * $Revision: 1.3 $
00024  * $Name: uves-3_9_0 $
00025  * $Log: uves_wavecal-test.c,v $
00026  * Revision 1.3  2007/08/13 12:15:43  amodigli
00027  * support of CPL4
00028  *
00029  * Revision 1.2  2007/05/23 06:43:23  jmlarsen
00030  * Removed unused variables
00031  *
00032  * Revision 1.1  2007/03/15 12:27:18  jmlarsen
00033  * Moved unit tests to ./uves/tests and ./flames/tests
00034  *
00035  * Revision 1.3  2007/02/27 14:04:14  jmlarsen
00036  * Move unit test infrastructure to IRPLIB
00037  *
00038  * Revision 1.2  2007/01/29 12:17:54  jmlarsen
00039  * Support setting verbosity from command line
00040  *
00041  * Revision 1.1  2006/11/28 08:26:35  jmlarsen
00042  * Added QC log unit test
00043  *
00044  */
00045 
00046 /*-----------------------------------------------------------------------------
00047                                 Includes
00048  -----------------------------------------------------------------------------*/
00049 
00050 #ifdef HAVE_CONFIG_H
00051 #  include <config.h>
00052 #endif
00053 
00054 #include <uves_wavecal_identify.h>
00055 #include <uves_wavecal_utils.h>
00056 #include <uves_utils_wrappers.h>
00057 #include <uves_error.h>
00058 #include <irplib_test.h>
00059 
00060 #include <cpl.h>
00061 #include <math.h>
00062 /*-----------------------------------------------------------------------------
00063                                 Defines
00064  -----------------------------------------------------------------------------*/
00065 
00066 /*-----------------------------------------------------------------------------
00067                             Functions prototypes
00068  -----------------------------------------------------------------------------*/
00069 
00070 
00071 /*----------------------------------------------------------------------------*/
00075 /*----------------------------------------------------------------------------*/
00078 /*----------------------------------------------------------------------------*/
00082 /*----------------------------------------------------------------------------*/
00083 static void
00084 test_ppm(void)
00085 {
00086     int nlines = 50;
00087     int minorder = 94;
00088     int maxorder = 97;
00089     const int norders = maxorder - minorder + 1;
00090     int i, order;
00091 
00092     cpl_table *linetable  = cpl_table_new(norders * nlines);
00093     cpl_table *line_refer = cpl_table_new(nlines);
00094 
00095     cpl_table_new_column(line_refer, "Wave", CPL_TYPE_DOUBLE);
00096  
00097     for (i = 0; i < nlines; i++)
00098         {
00099             cpl_table_set_double(line_refer, "Wave", i, 1000 + 500*sin(i));
00100         }
00101 
00102     irplib_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
00103     
00104     cpl_table_new_column(linetable, "X"              , CPL_TYPE_DOUBLE);
00105     cpl_table_new_column(linetable, "Order"          , CPL_TYPE_INT);
00106     cpl_table_new_column(linetable, LINETAB_LAMBDAC  , CPL_TYPE_DOUBLE);
00107     cpl_table_new_column(linetable, LINETAB_PIXELSIZE, CPL_TYPE_DOUBLE);
00108     
00109     for (order = minorder; order <= maxorder; order++)
00110         {
00111             for (i = 0; i < nlines; i++)
00112                 {
00113                     int row = (order-minorder)*nlines + i;
00114 
00115                     cpl_table_set_int(linetable, "Order", row, 
00116                                       order);
00117 
00118                     cpl_table_set_double(linetable, LINETAB_PIXELSIZE, row, 1);
00119 
00120                     /* Set X = catalogue wavelength */
00121                     cpl_table_set_double(linetable, "X", row, 
00122                                          cpl_table_get_double(line_refer, "Wave", i, NULL));
00123                     
00124                     cpl_table_set_double(linetable, LINETAB_LAMBDAC, row, 
00125                                          cpl_table_get_double(line_refer, "Wave", i, NULL));
00126                 }
00127         }
00128 
00129     irplib_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
00130 
00131 /*
00132   cpl_table_dump_structure(linetable, stdout);
00133   cpl_table_dump(linetable, 0, cpl_table_get_nrow(linetable), stdout);
00134   cpl_table_dump(line_refer, 0, cpl_table_get_nrow(line_refer), stdout);
00135 */
00136 
00137     uves_wavecal_identify_lines_ppm(linetable, 
00138                                     line_refer);
00139 
00140     irplib_test( cpl_table_has_column(linetable, "Ident_ppm") );
00141 
00142     uves_free_table(&linetable);
00143     uves_free_table(&line_refer);    
00144 
00145     return;
00146 }
00147 
00148    
00149 /*----------------------------------------------------------------------------*/
00153 /*----------------------------------------------------------------------------*/
00154 
00155 int main(void)
00156 {
00157     IRPLIB_TEST_INIT;
00158 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 0, 0)
00159     cpl_errorstate initial_errorstate = cpl_errorstate_get();
00160 #endif
00161     test_ppm();
00162 
00163     if (cpl_error_get_code() != CPL_ERROR_NONE)
00164         {
00165 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 0, 0)
00166       cpl_errorstate_dump(initial_errorstate,CPL_FALSE,NULL);
00167 #else
00168             uves_error_dump();
00169 #endif
00170         }
00171     IRPLIB_TEST_END;
00172 }
00173 
00174 

Generated on Fri Apr 18 14:11:44 2008 for UVES Pipeline Reference Manual by  doxygen 1.5.1