irplib_wcs-test.c

00001 /* $Id: irplib_wcs-test.c,v 1.8 2010/10/07 14:10:55 llundin Exp $
00002  *
00003  * This file is part of the ESO Common Pipeline Library
00004  * Copyright (C) 2001-2008 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: llundin $
00023  * $Date: 2010/10/07 14:10:55 $
00024  * $Revision: 1.8 $
00025  * $Name: HEAD $
00026  */
00027 
00028 /*-----------------------------------------------------------------------------
00029                                    Includes
00030  -----------------------------------------------------------------------------*/
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include <cpl_test.h>
00036 
00037 #include "irplib_wcs.h"
00038 
00039 /*-----------------------------------------------------------------------------
00040                                    Static functions
00041  -----------------------------------------------------------------------------*/
00042 static void irplib_wcs_all_test(void);
00043 
00044 static void irplib_wcs_mjd_test(void);
00045 
00046 
00047 /*-----------------------------------------------------------------------------
00048                                   Main
00049  -----------------------------------------------------------------------------*/
00050 int main (void)
00051 {
00052 
00053     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00054 
00055     irplib_wcs_all_test();
00056 
00057     irplib_wcs_mjd_test();
00058 
00059     return cpl_test_end(0);
00060 }
00061 
00062 /*----------------------------------------------------------------------------*/
00068 /*----------------------------------------------------------------------------*/
00069 static void irplib_wcs_all_test(void)
00070 {
00071     const double       xorig = 1.0;
00072     const double       yorig = 2.0;
00073     double             xnew,ynew;
00074     double             ra, dec;
00075     cpl_propertylist * prop_wcs; 
00076     cpl_wcs *          wcs = NULL;
00077     cpl_error_code     error;
00078 
00079     
00080     /* Create WCS object */
00081     prop_wcs = cpl_propertylist_new();
00082     cpl_test_nonnull(prop_wcs);
00083 
00084     cpl_propertylist_append_double(prop_wcs, "CRVAL1", 10.);
00085     cpl_propertylist_append_double(prop_wcs, "CRVAL2", 20.);
00086     cpl_propertylist_append_int(prop_wcs, "CRPIX1", 1);
00087     cpl_propertylist_append_int(prop_wcs, "CRPIX2", 2);
00088     cpl_propertylist_append_double(prop_wcs, "CD1_1", 10.);
00089     cpl_propertylist_append_double(prop_wcs, "CD1_2", 11.);
00090     cpl_propertylist_append_double(prop_wcs, "CD2_1", 13.);
00091     cpl_propertylist_append_double(prop_wcs, "CD2_2", 14.);
00092 
00093     cpl_test_error(CPL_ERROR_NONE);
00094 
00095     wcs = cpl_wcs_new_from_propertylist(prop_wcs);
00096     cpl_propertylist_delete(prop_wcs);
00097 
00098     if (cpl_error_get_code() == CPL_ERROR_NO_WCS) {
00099 
00100         cpl_msg_warning(cpl_func, "No WCS present. Tests disabled");
00101         cpl_test_error(CPL_ERROR_NO_WCS);
00102         cpl_test_null(wcs);
00103 
00104     } else {
00105 
00106         cpl_test_nonnull(wcs);
00107     
00108         /* Test that a simple call to xytoradec does not fail*/
00109         error = irplib_wcs_xytoradec(wcs, xorig, yorig, &ra, &dec);
00110         cpl_test_eq_error(error, CPL_ERROR_NONE);
00111     
00112         /* Get the transformation back and compare */
00113         error = irplib_wcs_radectoxy(wcs, ra, dec, &xnew, &ynew);
00114         cpl_test_eq_error(error, CPL_ERROR_NONE);
00115 
00116         cpl_test_abs(xnew, xorig, 2.0 * DBL_EPSILON);
00117         cpl_test_abs(ynew, yorig, 2.0 * DBL_EPSILON);
00118 
00119         /* Error testing */
00120 
00121         error = irplib_wcs_xytoradec(wcs, xorig, yorig, NULL, &dec);
00122         cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00123     
00124         error = irplib_wcs_radectoxy(wcs, ra, dec, NULL, &ynew);
00125         cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00126 
00127         error = irplib_wcs_xytoradec(wcs, xorig, yorig, &ra, NULL);
00128         cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00129     
00130         error = irplib_wcs_radectoxy(wcs, ra, dec, &xnew, NULL);
00131         cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00132 
00133         cpl_wcs_delete(wcs);
00134     
00135     }    
00136 
00137     /* Error testing */
00138 
00139     error = irplib_wcs_xytoradec(NULL, xorig, yorig, &ra, &dec);
00140     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00141     
00142     error = irplib_wcs_radectoxy(NULL, ra, dec, &xnew, &ynew);
00143     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00144 
00145 
00146 }
00147 
00148 
00149 /*----------------------------------------------------------------------------*/
00155 /*----------------------------------------------------------------------------*/
00156 static void irplib_wcs_mjd_test(void)
00157 {
00158 
00159     /* Matching example from some VLT header */
00160     const char * iso8601  = "2010-07-13T23:24:39.284";
00161     const double mjd  = 55390.97545467;
00162 
00163     /* Two equal dates */
00164     const char * iso8601a = "2010-07-13T24:00:00";
00165     const char * iso8601b = "2010-07-14T00:00:00.000";
00166 
00167     const double mstol = 1e-3/86400.0; /* 1ms tolerance in MJD */
00168     int year, day, month, hour, minute;
00169     double second;
00170     double tmjd, tmjd2;
00171     cpl_error_code error;
00172 
00173     /* The MJD counts the number of days since November 17, 1858 */
00174     /* Test 1a: Conversion of MJD == 0 */
00175     error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
00176                                         &minute, &second, 0.0);
00177     cpl_test_eq_error(error, CPL_ERROR_NONE);
00178 
00179     cpl_test_eq(year,  1858);
00180     cpl_test_eq(month,   11);
00181     cpl_test_eq(day,     17);
00182     cpl_test_eq(hour,     0);
00183     cpl_test_eq(minute,   0);
00184     cpl_test_abs(second, 0.0, 2.0 * DBL_EPSILON);
00185 
00186     /* Test 1b: - and convert back */
00187     error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
00188                                         second);
00189     cpl_test_eq_error(error, CPL_ERROR_NONE);
00190 
00191     cpl_test_abs(tmjd, 0.0, 2.0 * DBL_EPSILON);
00192 
00193     /* Test 2: Conversion back and forth of some recent date */
00194     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00195                                            &minute, &second, iso8601);
00196     cpl_test_eq_error(error, CPL_ERROR_NONE);
00197 
00198     error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
00199                                         second);
00200     cpl_test_eq_error(error, CPL_ERROR_NONE);
00201 
00202     cpl_test_abs(mjd, tmjd, mstol);
00203 
00204     error = irplib_wcs_mjd_from_string(&tmjd, iso8601);
00205     cpl_test_eq_error(error, CPL_ERROR_NONE);
00206 
00207     cpl_test_abs(mjd, tmjd, mstol);
00208 
00209     error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
00210                                         &minute, &second, mjd);
00211     cpl_test_eq_error(error, CPL_ERROR_NONE);
00212 
00213     error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
00214                                         second);
00215     cpl_test_eq_error(error, CPL_ERROR_NONE);
00216 
00217     cpl_test_abs(mjd, tmjd, 2.0 * DBL_EPSILON);
00218 
00219     /* Test 3: 24:00:00 == 00.00.00 + 1 day */
00220     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00221                                            &minute, &second, iso8601a);
00222     cpl_test_eq_error(error, CPL_ERROR_NONE);
00223 
00224     error = irplib_wcs_mjd_from_iso8601(&tmjd, year, month, day, hour, minute,
00225                                         second);
00226     cpl_test_eq_error(error, CPL_ERROR_NONE);
00227 
00228     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00229                                            &minute, &second, iso8601b);
00230     cpl_test_eq_error(error, CPL_ERROR_NONE);
00231 
00232     error = irplib_wcs_mjd_from_iso8601(&tmjd2, year, month, day, hour, minute,
00233                                         second);
00234     cpl_test_eq_error(error, CPL_ERROR_NONE);
00235 
00236     cpl_test_abs(tmjd, tmjd2, 2.0 * DBL_EPSILON);
00237 
00238     /* Test 4: Do not allow days from y10k */
00239     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00240                                            &minute, &second,
00241                                            "10000-07-13T23:24:39.284");
00242     cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT);
00243 
00244     /* Test 5: Verify validation of length of a non-leap year month */
00245     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00246                                            &minute, &second,
00247                                            "2010-02-29T23:24:39.284");
00248     cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT);
00249 
00250     /* Test 6: NULL pointer checking */
00251     error = irplib_wcs_mjd_from_iso8601(NULL, year, month, day, hour, minute,
00252                                         second);
00253     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00254 
00255     error = irplib_wcs_iso8601_from_string(NULL, &month, &day, &hour,
00256                                            &minute, &second, iso8601);
00257     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00258 
00259     error = irplib_wcs_iso8601_from_string(&year, NULL, &day, &hour,
00260                                            &minute, &second, iso8601);
00261     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00262 
00263     error = irplib_wcs_iso8601_from_string(&year, &month, NULL, &hour,
00264                                            &minute, &second, iso8601);
00265     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00266 
00267     error = irplib_wcs_iso8601_from_string(&year, &month, &day, NULL,
00268                                            &minute, &second, iso8601);
00269     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00270 
00271     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00272                                            NULL, &second, iso8601);
00273     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00274 
00275     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00276                                            &minute, NULL, iso8601);
00277     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00278 
00279     error = irplib_wcs_iso8601_from_string(&year, &month, &day, &hour,
00280                                            &minute, &second, NULL);
00281     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00282 
00283     error = irplib_wcs_iso8601_from_mjd(NULL, &month, &day, &hour,
00284                                         &minute, &second, mjd);
00285     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00286 
00287     error = irplib_wcs_iso8601_from_mjd(&year, NULL, &day, &hour,
00288                                         &minute, &second, mjd);
00289     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00290 
00291     error = irplib_wcs_iso8601_from_mjd(&year, &month, NULL, &hour,
00292                                         &minute, &second, mjd);
00293     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00294 
00295     error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, NULL,
00296                                         &minute, &second, mjd);
00297     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00298 
00299     error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
00300                                         NULL, &second, mjd);
00301     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00302 
00303     error = irplib_wcs_iso8601_from_mjd(&year, &month, &day, &hour,
00304                                         &minute, NULL, mjd);
00305     cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT);
00306 
00307 }

Generated on Thu Mar 24 11:59:39 2011 for VISIR Pipeline Reference Manual by  doxygen 1.5.8