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

Generated on 9 Mar 2012 for UVES Pipeline Reference Manual by  doxygen 1.6.1