LAL  7.5.0.1-89842e6
TranslateMJDTest.c
Go to the documentation of this file.
1 //
2 // Copyright (C) 2015 Reinhard Prix
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with with program; see the file COPYING. If not, write to the
16 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 // MA 02110-1301 USA
18 //
19 
20 // Tests of the unit conversion functions in the UserInputParser.[ch] module
21 
22 #include <stdio.h>
23 #include <math.h>
24 #include <string.h>
25 
26 #include <lal/LALStdio.h>
27 #include <lal/XLALError.h>
28 #include <lal/LALMalloc.h>
29 #include <lal/LALConstants.h>
30 #include <lal/TranslateMJD.h>
31 
32 
33 // ---------- local prototypes ----------
34 int test_MJDTT_GPS ( void );
35 
36 // ==================== function definitions ====================
37 int main(void)
38 {
39  // ---------- test MJD(TT) to GPS conversions ----------
41 
42  // check for memory leaks
44 
45  return EXIT_SUCCESS;
46 
47 } // main()
48 
49 ///
50 /// test conversion between MJD(TT) string and GPS value
51 ///
52 int
54 {
55 
56  INT4 mjdTTDays;
57  REAL8 mjdTTFracDays;
58  char mjdTTString[256];
59  LIGOTimeGPS gps, gpsRef;
60 
61  // ----- example 1: J200 epoch, see https://en.wikipedia.org/wiki/Epoch_%28astronomy%29#Julian_years_and_J2000
62  mjdTTDays = 51544;
63  mjdTTFracDays = 0.5;
64  gpsRef.gpsSeconds = 630763148; // $ lalapps_tconvert "Jan 01 2000 11:58:55 UTC"
65  gpsRef.gpsNanoSeconds = 816000000;
66 
67  XLAL_CHECK ( XLALTranslateMJDTTtoGPS ( &gps, mjdTTDays, mjdTTFracDays ) != NULL, XLAL_EFUNC );
68  XLAL_CHECK ( (gps.gpsSeconds == gpsRef.gpsSeconds) && (gps.gpsNanoSeconds == gpsRef.gpsNanoSeconds), XLAL_ETOL,
69  "XLALTranslateMJDTTtoGPS(%s) = (%d,%d) failed, correct result = (%d,%d)\n",
70  mjdTTString, gps.gpsSeconds, gps.gpsNanoSeconds, gpsRef.gpsSeconds, gpsRef.gpsNanoSeconds );
71 
72  sprintf ( mjdTTString, "%d.%014" LAL_INT8_FORMAT, mjdTTDays, (INT8)round(mjdTTFracDays*1e14) );
73  XLAL_CHECK ( XLALTranslateStringMJDTTtoGPS ( &gps, mjdTTString ) != NULL, XLAL_EFUNC );
74  XLAL_CHECK ( (gps.gpsSeconds == gpsRef.gpsSeconds) && (gps.gpsNanoSeconds == gpsRef.gpsNanoSeconds), XLAL_ETOL,
75  "XLALTranslateStringMJDTTtoGPS(%s) = (%d,%d) failed, correct result = (%d,%d)\n",
76  mjdTTString, gps.gpsSeconds, gps.gpsNanoSeconds, gpsRef.gpsSeconds, gpsRef.gpsNanoSeconds );
77 
78  // ----- example 2: Chandra MET http://cxc.cfa.harvard.edu/contrib/arots/time/time_tutorial.html
79  mjdTTDays = 50814;
80  mjdTTFracDays = 0;
81  gpsRef.gpsSeconds = 567647948;
82  gpsRef.gpsNanoSeconds = 816000000;
83 
84  XLAL_CHECK ( XLALTranslateMJDTTtoGPS ( &gps, mjdTTDays, mjdTTFracDays ) != NULL, XLAL_EFUNC );
85  XLAL_CHECK ( (gps.gpsSeconds == gpsRef.gpsSeconds) && (gps.gpsNanoSeconds == gpsRef.gpsNanoSeconds), XLAL_ETOL,
86  "XLALTranslateMJDTTtoGPS(%s) = (%d,%d) failed, correct result = (%d,%d)\n",
87  mjdTTString, gps.gpsSeconds, gps.gpsNanoSeconds, gpsRef.gpsSeconds, gpsRef.gpsNanoSeconds );
88 
89  sprintf ( mjdTTString, "%d.%014" LAL_INT8_FORMAT, mjdTTDays, (INT8)round(mjdTTFracDays*1e14) );
90  XLAL_CHECK ( XLALTranslateStringMJDTTtoGPS ( &gps, mjdTTString ) != NULL, XLAL_EFUNC );
91  XLAL_CHECK ( (gps.gpsSeconds == gpsRef.gpsSeconds) && (gps.gpsNanoSeconds == gpsRef.gpsNanoSeconds), XLAL_ETOL,
92  "XLALTranslateStringMJDTTtoGPS(%s) = (%d,%d) failed, correct result = (%d,%d)\n",
93  mjdTTString, gps.gpsSeconds, gps.gpsNanoSeconds, gpsRef.gpsSeconds, gpsRef.gpsNanoSeconds );
94 
95 
96  // ----- example 3: RXTE MET https://heasarc.gsfc.nasa.gov/docs/xte/abc/time_tutorial.html
97  mjdTTDays = 49353;
98  mjdTTFracDays = 0.000696574074074074;
99  gpsRef.gpsSeconds = 441417609; // $ lalapps_tconvert -g "Jan 1 1994 0:00:00 UTC"
100  gpsRef.gpsNanoSeconds = 0;
101 
102  XLAL_CHECK ( XLALTranslateMJDTTtoGPS ( &gps, mjdTTDays, mjdTTFracDays ) != NULL, XLAL_EFUNC );
103  XLAL_CHECK ( (gps.gpsSeconds == gpsRef.gpsSeconds) && (gps.gpsNanoSeconds == gpsRef.gpsNanoSeconds), XLAL_ETOL,
104  "XLALTranslateMJDTTtoGPS(%s) = (%d,%d) failed, correct result = (%d,%d)\n",
105  mjdTTString, gps.gpsSeconds, gps.gpsNanoSeconds, gpsRef.gpsSeconds, gpsRef.gpsNanoSeconds );
106 
107  sprintf ( mjdTTString, "%d.%014" LAL_INT8_FORMAT, mjdTTDays, (INT8)round(mjdTTFracDays*1e14) );
108  XLAL_CHECK ( XLALTranslateStringMJDTTtoGPS ( &gps, mjdTTString ) != NULL, XLAL_EFUNC );
109  XLAL_CHECK ( (gps.gpsSeconds == gpsRef.gpsSeconds) && (gps.gpsNanoSeconds == gpsRef.gpsNanoSeconds), XLAL_ETOL,
110  "XLALTranslateStringMJDTTtoGPS(%s) = (%d,%d) failed, correct result = (%d,%d)\n",
111  mjdTTString, gps.gpsSeconds, gps.gpsNanoSeconds, gpsRef.gpsSeconds, gpsRef.gpsNanoSeconds );
112 
113  return XLAL_SUCCESS;
114 } // test_MJDTT_GPS()
void LALCheckMemoryLeaks(void)
Definition: LALMalloc.c:784
int test_MJDTT_GPS(void)
test conversion between MJD(TT) string and GPS value
int main(void)
double REAL8
Double precision real floating-point number (8 bytes).
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
int32_t INT4
Four-byte signed integer.
#define LAL_INT8_FORMAT
Definition: LALStdio.h:128
LIGOTimeGPS * XLALTranslateMJDTTtoGPS(LIGOTimeGPS *gps, INT4 mjdDays, REAL8 mjdFracDays)
convert given MJD(TT) time, mjd = mjdDays + mjdFracDays into LIGOTimeGPS format, preserving full (ns)...
Definition: TranslateMJD.c:49
LIGOTimeGPS * XLALTranslateStringMJDTTtoGPS(LIGOTimeGPS *gps, const char *mjdString)
Parse and convert given string representing MJD(TT) time into LIGOTimeGPS gps time,...
Definition: TranslateMJD.c:91
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
Definition: XLALError.h:810
#define XLAL_CHECK_MAIN(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a C main() routine.
Definition: XLALError.h:885
@ XLAL_SUCCESS
Success return value (not an error number)
Definition: XLALError.h:401
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:462
@ XLAL_ETOL
Failed to reach specified tolerance.
Definition: XLALError.h:458
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
Definition: LALDatatypes.h:459
INT4 gpsNanoSeconds
Residual nanoseconds.
Definition: LALDatatypes.h:460