Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
IncrementGPSTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 David Chin, Jolien Creighton, Kipp Cannon, 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/*
21 * Author: David Chin <dwchin@umich.edu> +1-734-730-1274
22 */
23
24#include <stdio.h>
25#include <math.h>
26#include <stdlib.h>
27#include <string.h>
28
29#include <lal/LALStdlib.h>
30#include <lal/Date.h>
31#include <lal/AVFactories.h>
32
33
34#define SUCCESS 0
35#define FAILURE 1
36
37#define TRUE 1
38#define FALSE 0
39
40#define LONGESTSTR 256
41
42/* Error codes and messages */
43#define LALTESTINCREMENTGPSC_ENORM 0
44#define LALTESTINCREMENTGPSC_ESUB 1
45
46#define LALTESTINCREMENTGPSC_MSGENORM "Normal exit"
47#define LALTESTINCREMENTGPSC_MSGESUB "LAL Subroutine failed"
48
49/* module-scope variable */
51const INT4 oneBillion = 1000000000;
52
53
54
55static int print_compare_errmsg_maybe(const char *msg,
56 int expected_val,
57 int got_val);
58
59static BOOLEAN compare_gps_ok(const LIGOTimeGPS *p_gps1,
60 const LIGOTimeGPS *p_gps2,
61 int expected_val);
62
63/* static int sprint_time_interval(char *str,
64 const LALTimeInterval *p_time_interval); */
65
66int main(void)
67{
68 LIGOTimeGPS gps;
69
70
71 if (lalDebugLevel >= 4)
73
74 /*
75 * TEST No. 0 -- test LALCompareGPS()
76 */
77 {
78 LIGOTimeGPS gps2;
79
80 gps.gpsSeconds = 1249389;
81 gps.gpsNanoSeconds = 498512352;
82
83 /* equal */
84 gps2.gpsSeconds = 1249389;
85 gps2.gpsNanoSeconds = 498512352;
86
87 if (!compare_gps_ok(&gps, &gps2, 0))
88 return FAILURE;
89
90 /* later */
91 gps2.gpsNanoSeconds -= 1;
92
93 if (!compare_gps_ok(&gps, &gps2, 1))
94 return FAILURE;
95
96 /* earlier */
97 gps2.gpsNanoSeconds += 2;
98
99 if (!compare_gps_ok(&gps, &gps2, -1))
100 return FAILURE;
101
102 /* later */
103 gps2.gpsSeconds -= 1;
104 gps2.gpsNanoSeconds -= 1;
105
106 if (!compare_gps_ok(&gps, &gps2, 1))
107 return FAILURE;
108
109 /* earlier */
110 gps2.gpsSeconds += 2;
111
112 if (!compare_gps_ok(&gps, &gps2, -1))
113 return FAILURE;
114
115 } /* END: test of LALCompareGPS() */
116
117
118 /*----------------------------------------------------------------------*/
119 /* test XLALGPSAdd() and XLALGPSDiff() */
120 {
121 LIGOTimeGPS gps1, gps2, gpsTest, gps3;
122 double deltaT1, deltaT0;
123
124 gps1.gpsSeconds = 714153733;
125 gps1.gpsNanoSeconds = 23421234;
126
127 gps2.gpsSeconds = 715615153;
128 gps2.gpsNanoSeconds = 712343412;
129 /* now use XLALGPSDiff() to calculate the difference in seconds */
130 deltaT1 = XLALGPSDiff(&gps1, &gps2);
131 /* compare to correct result (error must be < 0.5 ns) */
132 deltaT0 = -1461420.688922178;
133 if (fabs(deltaT1 - deltaT0) >= .5e-9) {
134 LALPrintError ("Failure in XLALGPSDiff(): got %.17g instead of %.17g\n", deltaT1, deltaT0);
135 return FAILURE;
136 }
137 /* now see if deltaT1 takes us from gps1 to gps2 and vice-versa */
138 gpsTest = gps2;
139 XLALGPSAdd(&gpsTest, deltaT1);
140 if ( (gpsTest.gpsSeconds != gps1.gpsSeconds) || (gpsTest.gpsNanoSeconds != gps1.gpsNanoSeconds) ) {
141 LALPrintError ("Failure in 1.) XLALGPSAdd(): got %d.%09ds instead of %d.%09ds\n",
142 gpsTest.gpsSeconds, gpsTest.gpsNanoSeconds, gps1.gpsSeconds, gps1.gpsNanoSeconds);
143 return FAILURE;
144 }
145 /* no go the other direction..*/
146 deltaT1 = -deltaT1;
147 gpsTest = gps1;
148 XLALGPSAdd(&gpsTest, deltaT1);
149 if ( (gpsTest.gpsSeconds != gps2.gpsSeconds) || (gpsTest.gpsNanoSeconds != gps2.gpsNanoSeconds) ) {
150 LALPrintError ("Failure in 2.) XLALGPSAdd(): got %d.%09ds instead of %d.%09ds\n",
151 gpsTest.gpsSeconds, gpsTest.gpsNanoSeconds, gps2.gpsSeconds, gps2.gpsNanoSeconds);
152 return FAILURE;
153 }
154 /* test over-run in ns-position is handled properly */
155 gpsTest = gps2;
156 XLALGPSAdd(&gpsTest, deltaT1);
157 gps3.gpsSeconds = 717076574;
158 gps3.gpsNanoSeconds = 401265590;
159 if ( (gpsTest.gpsSeconds != gps3.gpsSeconds) || (gpsTest.gpsNanoSeconds != gps3.gpsNanoSeconds) ) {
160 LALPrintError ("Failure in 3.) XLALGPSAdd(): got %d.%09ds instead of %d.%09ds\n",
161 gpsTest.gpsSeconds, gpsTest.gpsNanoSeconds, gps2.gpsSeconds, gps2.gpsNanoSeconds);
162 return FAILURE;
163 }
164 gpsTest = gps1;
165 XLALGPSAdd(&gpsTest, deltaT1);
166 gps3.gpsSeconds = 715615153;
167 gps3.gpsNanoSeconds = 712343412;
168 if ( (gpsTest.gpsSeconds != gps3.gpsSeconds) || (gpsTest.gpsNanoSeconds != gps3.gpsNanoSeconds) ) {
169 LALPrintError ("Failure in 4.) XLALGPSAdd(): got %d.%09ds instead of %d.%09ds\n",
170 gpsTest.gpsSeconds, gpsTest.gpsNanoSeconds, gps2.gpsSeconds, gps2.gpsNanoSeconds);
171 return FAILURE;
172 }
173
174
175 } /* testing XLALGPSAdd() and XLALGPSDiff() */
176 /*----------------------------------------------------------------------*/
177
178 return SUCCESS;
179} /* END: main() */
180
181
182
183static int print_compare_errmsg_maybe(const char *msg,
184 int expected_val,
185 int got_val)
186{
187 if (verbose_p)
188 fprintf(stderr, "%s; expected %d got %d\n\n", msg, expected_val, got_val);
189 return 0;
190}
191
192
193
194static BOOLEAN compare_gps_ok(const LIGOTimeGPS *p_gps1,
195 const LIGOTimeGPS *p_gps2,
196 int expected_val)
197{
198 if (XLALGPSCmp(p_gps1, p_gps2) != expected_val)
199 {
200 print_compare_errmsg_maybe("XLALGPSCmp() failed",
201 expected_val, XLALGPSCmp(p_gps1, p_gps2));
202 return FALSE;
203 }
204 else
205 {
206 return TRUE;
207 }
208}
209
210
211#if 0 /* NOT USED */
212static int sprint_time_interval(char *str,
213 const LALTimeInterval *p_time_interval)
214{
215 return snprintf(str, LONGESTSTR - 1 - strlen(str),
216 "%9d:%09d", p_time_interval->seconds,
217 p_time_interval->nanoSeconds);
218}
219#endif
#define FAILURE
#define LONGESTSTR
int main(void)
static BOOLEAN compare_gps_ok(const LIGOTimeGPS *p_gps1, const LIGOTimeGPS *p_gps2, int expected_val)
#define TRUE
#define SUCCESS
#define FALSE
const INT4 oneBillion
static int print_compare_errmsg_maybe(const char *msg, int expected_val, int got_val)
BOOLEAN verbose_p
#define fprintf
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
int32_t INT4
Four-byte signed integer.
#define lalDebugLevel
Definition: LALDebugLevel.h:58
int LALPrintError(const char *fmt,...)
Definition: LALError.c:46
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
Adds a double to a GPS time.
Definition: XLALTime.c:131
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
Compares two GPS times.
Definition: XLALTime.c:174
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
Difference between two GPS times as double.
Definition: XLALTime.c:157
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