TestJulianDay.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 David Chin, Jolien Creighton
00003  *
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by the
00006  * Free Software Foundation; either version 2 of the License, or (at your
00007  * option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with with program; see the file COPYING. If not, write to the Free
00016  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017  * 02111-1307  USA
00018  */
00019 
00020 #include <math.h>
00021 #include <lal/LALStdlib.h>
00022 #include <lal/Date.h>
00023 #include <lal/XLALError.h>
00024 
00025 INT4 lalDebugLevel = 0;
00026 
00027 NRCSID(LALTESTJULIANDAYC, "$Id: TestJulianDay.c,v 1.13 2008/04/29 01:06:59 kipp Exp $");
00028 
00029 #define SUCCESS              0
00030 #define FAIL_JULIAN_DAY      1
00031 #define FAIL_MOD_JULIAN_DAY  2
00032 #define FAIL_JULIAN_DATE     3
00033 #define FAIL_MOD_JULIAN_DATE 4
00034 
00035 /* good to 1 micro-day  */
00036 const REAL8 julian_precision = 1.e-6;
00037 
00038 const REAL8 coarse_precision = 0.001;
00039 
00040 /*  Output of NASA/AMES code:
00041  Date/time: 1 1 0 12 0 0
00042  PDS format: "2000-01-01T12:00:00.000Z"
00043  SQL format: "Jan 1, 2000 12:00:00:000"
00044 
00045   UTC day  =        0
00046   UTC secs =    43200.000000
00047   TAI secs =          32.000000
00048    ET secs =          64.183927
00049 
00050   JD (UTC) =  2451545.000000
00051   JD (TAI) =  2451545.000370
00052   JD (ET)  =  2451545.001115
00053  MJD (UTC) =    51544.500000
00054  MJD (TAI) =    51544.500370
00055  MJD (ET)  =    51544.501115
00056 
00057   Date/time: 94 11 16 0 0 0
00058  PDS format: "1994-11-16T00:00:00.000Z"
00059  SQL format: "Nov 16, 1994 00:00:00:000"
00060 
00061   UTC day  =    -1872
00062   UTC secs =        0.000000
00063   TAI secs =  -161783971.000000
00064    ET secs =  -161783938.817245
00065 
00066   JD (UTC) =  2449672.500000
00067   JD (TAI) =  2449672.500336
00068   JD (ET)  =  2449672.501081
00069  MJD (UTC) =    49672.000000
00070  MJD (TAI) =    49672.000336
00071  MJD (ET)  =    49672.001081
00072 
00073  Date/time: 01 05 15 02 37 54
00074  PDS format: "2001-05-15T02:37:54.000Z"
00075  SQL format: "May 15, 2001 02:37:54:000"
00076 
00077   UTC day  =      500
00078   UTC secs =     9474.000000
00079   TAI secs =    43166306.000000
00080    ET secs =    43166338.185257
00081 
00082   JD (UTC) =  2452044.609653
00083   JD (TAI) =  2452044.610023
00084   JD (ET)  =  2452044.610768
00085  MJD (UTC) =    52044.109653
00086  MJD (TAI) =    52044.110023
00087  MJD (ET)  =    52044.110768
00088 
00089 
00090  http://tycho.usno.navy.mil/cgi-bin/date
00091 15-May-01
00092 MJD 52044.109653
00093 UTC 02:37:54
00094 
00095 */
00096 
00097 
00098 /*
00099  * pass 0 for expected_julian_day or expected_modified_julian_day to disable testing
00100  */
00101 
00102 static int test(const struct tm *utc, double expected_julian_day, double expected_modified_julian_day, int line)
00103 {
00104         double julian_day;
00105         double modified_julian_day;
00106         int result = 0;
00107 
00108         if(lalDebugLevel)
00109                 fprintf(stderr, "Testing %s ...\n", asctime(utc));
00110 
00111         julian_day = XLALJulianDay(utc);
00112         modified_julian_day = XLALModifiedJulianDay(utc);
00113 
00114         if(expected_julian_day && (julian_day != expected_julian_day)) {
00115                 fprintf(stderr, "XLALJulianDay() failed (line %d):  expected %.17g got %.17g\n", line, expected_julian_day, julian_day);
00116                 result = -1;
00117         } else if(lalDebugLevel) {
00118                 fprintf(stderr, "XLALJulianDay() returned %.16g\n", julian_day);
00119         }
00120         if(expected_modified_julian_day && (modified_julian_day != expected_modified_julian_day)) {
00121                 fprintf(stderr, "XLALModifiedJulianDay() failed (line %d):  expected %.17g got %.17g\n", line, expected_modified_julian_day, modified_julian_day);
00122                 result = -1;
00123         } else if(lalDebugLevel) {
00124                 fprintf(stderr, "XLALModifiedJulianDay() returned %.17g\n", modified_julian_day);
00125         }
00126 
00127         return result;
00128 }
00129 
00130 
00131 int main(int argc, char *argv[])
00132 {
00133         time_t now;
00134         struct tm utc;
00135         REAL8 ref_julian_day;
00136         REAL8 julian_day;
00137         INT4 old_debuglvl;
00138         REAL8 ref_mod_julian_day;
00139         REAL8 mod_julian_day;
00140 
00141 
00142         /*
00143          * Distinctly not robust
00144          */
00145 
00146         if(argc > 1)
00147                 lalDebugLevel = atoi(argv[1]);
00148 
00149         /*
00150          * Get current local time
00151          */
00152 
00153         time(&now);
00154         if(test(localtime(&now), 0, 0, __LINE__))
00155                 return 1;
00156 
00157         /*
00158          * Check Julian Day/Date for special dates and times
00159          */
00160 
00161         utc.tm_sec = 0;
00162         utc.tm_min = 0;
00163         utc.tm_hour = 12;
00164         utc.tm_mday = 1;
00165         utc.tm_mon = 0;
00166         utc.tm_year = 100;
00167         utc.tm_wday = 6;
00168         utc.tm_yday = 0;
00169         utc.tm_isdst = 0;
00170 
00171         if(test(&utc, 2451545.0, 51544.0, __LINE__))
00172                 return 1;
00173 
00174         utc.tm_sec = 0;
00175         utc.tm_min = 0;
00176         utc.tm_hour = 11;
00177         utc.tm_mday = 1;
00178         utc.tm_mon = 0;
00179         utc.tm_year = 100;
00180         utc.tm_wday = 6;
00181         utc.tm_yday = 0;
00182         utc.tm_isdst = 0;
00183 
00184         if(test(&utc, 2451544.9583333333, 51544.0, __LINE__))
00185                 return 1;
00186 
00187         /* */
00188 
00189         if(lalDebugLevel > 1) {
00190                 old_debuglvl = lalDebugLevel;
00191 
00192                 lalDebugLevel = 1;      /* LAL seems to not consider any debug level > 1 */
00193 
00194                 utc.tm_sec = 0;
00195                 utc.tm_min = 0;
00196                 utc.tm_hour = 11;
00197                 utc.tm_mday = 1;
00198                 utc.tm_mon = 0;
00199                 utc.tm_year = -100;
00200                 utc.tm_wday = 6;
00201                 utc.tm_yday = 0;
00202                 utc.tm_isdst = 0;
00203 
00204                 /* here, we EXPECT an error */
00205                 if(test(&utc, XLAL_REAL8_FAIL_NAN, XLAL_REAL8_FAIL_NAN, __LINE__))
00206                         return 1;
00207 
00208                 lalDebugLevel = old_debuglvl;
00209         }
00210 
00211 
00212 
00213         /* */
00214 
00215         utc.tm_sec = 0;
00216         utc.tm_min = 0;
00217         utc.tm_hour = 0;
00218         utc.tm_mday = 16;
00219         utc.tm_mon = 10;
00220         utc.tm_year = 94;
00221         utc.tm_wday = 3;
00222         utc.tm_yday = 0;
00223         utc.tm_isdst = 0;
00224 
00225         if(test(&utc, 2449672.5, 49672.0, __LINE__))
00226                 return 1;
00227 
00228         /* */
00229 
00230         utc.tm_sec = 54;
00231         utc.tm_min = 37;
00232         utc.tm_hour = 2;
00233         utc.tm_mday = 15;
00234         utc.tm_mon = 4;
00235         utc.tm_year = 101;
00236         utc.tm_wday = 1;
00237         utc.tm_yday = 0;
00238         utc.tm_isdst = 1;
00239 
00240         if(test(&utc, 2452044.6096527777, 52044.0, __LINE__))
00241                 return 1;
00242 
00243         return SUCCESS;
00244 }

Generated on Sun Sep 7 03:07:23 2008 for LAL by  doxygen 1.5.2