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
LMST2Test.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 David Chin, Jolien Creighton
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#include <stdlib.h>
21#include <time.h>
22#include <lal/LALStdlib.h>
23#include <lal/AVFactories.h>
24#include <lal/Date.h>
25
26
27/*int main(int argc, char *argv[])*/
28int main(void)
29{
30/* FIXME: this needs to be ported to test the XLAL replacements */
31#if 0
32 static LALStatus status;
33 LALDate date;
34 LALDate mstdate;
35 REAL8 gmsthours, lmsthours;
36 REAL8 gmstsecs;
37 LALDetector detector;
38 LALPlaceAndDate place_and_date;
39 LALPlaceAndGPS place_and_gps;
40 CHAR timestr[128];
41 CHAR tmpstr[128];
42 CHARVector *datestamp = NULL;
43 INT4 testid;
44 INT4 dayofmonth, monthofyear;
45 LIGOTimeGPS gpstime;
46 LALLeapSecAccuracy accuracy = LALLEAPSEC_STRICT;
47 LALMSTUnitsAndAcc units_and_acc;
48
49
50 if (argc != 3)
51 {
52 /*
53 * Print help message and exit
54 */
55 printf("Usage: TestLMST testid debug_level\n");
56 printf(" testid = [1,2]\n");
57 printf(" debug_level = [0,1,2]\n");
58 return 0;
59 }
60
61 testid = atoi(argv[1]);
62
63 LALCHARCreateVector(&status, &datestamp, (UINT4)64);
64
65 /*
66 * Initialize date structures. Prevents strftime() from
67 * dumping core under Solaris 2.7/gcc-2.95.2
68 */
69 date.unixDate.tm_sec = 0;
70 date.unixDate.tm_min = 0;
71 date.unixDate.tm_hour = 0;
72 date.unixDate.tm_mday = 0;
73 date.unixDate.tm_mon = 0;
74 date.unixDate.tm_year = 0;
75 date.unixDate.tm_wday = 0;
76 date.unixDate.tm_yday = 0;
77 date.unixDate.tm_isdst = 0;
78
79 date.unixDate.tm_sec = 0;
80 date.unixDate.tm_min = 0;
81 date.unixDate.tm_hour = 0;
82 date.unixDate.tm_mday = 0;
83 date.unixDate.tm_mon = 0;
84 date.unixDate.tm_year = 0;
85 date.unixDate.tm_wday = 0;
86 date.unixDate.tm_yday = 0;
87 date.unixDate.tm_isdst = 0;
88
89 printf("TEST of LALGMST1 routine\n");
90 printf("========================\n");
91
92 if (testid == 1)
93 {
94 /*
95 * Check against the Astronomical Almanac:
96 * For 1994-11-16 0h UT - Julian Date 2449672.5, GMST 03h 39m 21.2738s
97 */
98 date.unixDate.tm_sec = 0;
99 date.unixDate.tm_min = 0;
100 date.unixDate.tm_hour = 0;
101 date.unixDate.tm_mday = 16;
102 date.unixDate.tm_mon = 10;
103 date.unixDate.tm_year = 94;
104
105 /* all other fields to 0 */
106 date.unixDate.tm_wday = 0;
107 date.unixDate.tm_yday = 0;
108 date.unixDate.tm_isdst = 0;
109
110 /* The corresponding GPS time is */
111 gpstime.gpsSeconds = 468979210;
112 gpstime.gpsNanoSeconds = 0;
113
114 detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
115 place_and_date.p_detector = &detector;
116 place_and_date.p_date = &date;
117 LALGMST1(&status, &gmsthours, &date, MST_HRS);
118 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
119
120 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
121 LALSecsToLALDate(&status, &mstdate, gmstsecs);
122 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
123 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
124 strcat(timestr, tmpstr+1); /* remove leading 0 */
125 LALDateString(&status, datestamp, &date);
126
127 printf(" Time = %s\n", datestamp->data);
128 printf("gmsthours = %f = %s\n", gmsthours, timestr);
129 printf(" expect: 3.655728 = 03h 39m 20.6222s \n");
130 printf("lmsthours = %f\n", lmsthours);
131
132 printf("\n");
133 printf("Using the GPStoGMST1() and GPStoLMST1() routines instead:\n");
134 units_and_acc.units = MST_SEC;
135 units_and_acc.accuracy = LALLEAPSEC_STRICT;
136 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
137 units_and_acc.units = MST_HRS;
138 LALGPStoGMST1(&status, &gmsthours, &gpstime, &units_and_acc);
139 LALSecsToLALDate(&status, &mstdate, gmstsecs);
140 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
141 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
142 strcat(timestr, tmpstr+1); /* remove leading 0 */
143 /* LALDateString(&status, datestamp, &date); */
144
145 place_and_gps.p_detector = &detector;
146 place_and_gps.p_gps = &gpstime;
147 units_and_acc.units = MST_HRS;
148 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
149 printf(" Time = %s\n", datestamp->data);
150 printf("gmsthours = %f = %s\n", gmsthours, timestr);
151 printf(" expect: 3.655728 = 03h 39m 20.6222s \n");
152 printf("lmsthours = %f\n", lmsthours);
153
154
155 /* Doing the GPS to MST1 conversions the long way */
156 printf("\n");
157 printf("\nConverting GPS to LMST the long way instead:\n");
158 LALGPStoUTC(&status, &date, &gpstime, &accuracy);
159 LALGMST1(&status, &gmsthours, &date, MST_HRS);
160 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
161
162 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
163 LALSecsToLALDate(&status, &mstdate, gmstsecs);
164 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
165 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
166 strcat(timestr, tmpstr+1); /* remove leading 0 */
167 LALDateString(&status, datestamp, &date);
168
169 printf(" Time = %s\n", datestamp->data);
170 printf("gmsthours = %f = %s\n", gmsthours, timestr);
171 printf(" expect: 3.655728 = 03h 39m 20.6222s \n");
172 printf("lmsthours = %f\n", lmsthours);
173
174
175 /*
176 * Another check against the Almanac:
177 * For 1994-08-17 2h 19m 03.0736s -> 0h GMST
178 */
179 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
180 date.residualNanoSeconds = 73600000;
181 date.unixDate.tm_sec = 3;
182 date.unixDate.tm_min = 19;
183 date.unixDate.tm_hour = 2;
184 date.unixDate.tm_mday = 17;
185 date.unixDate.tm_mon = 7;
186 date.unixDate.tm_year = 94;
187
188 gpstime.gpsSeconds = 461125153;
189 gpstime.gpsNanoSeconds = date.residualNanoSeconds;
190
191 detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
192 place_and_date.p_detector = &detector;
193 place_and_date.p_date = &date;
194 LALGMST1(&status, &gmsthours, &date, MST_HRS);
195 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
196
197 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
198 LALSecsToLALDate(&status, &mstdate, gmstsecs);
199 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
200 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
201 strcat(timestr, tmpstr+1); /* remove leading 0 */
202 /* LALDateString(&status, datestamp, &date); */
203
204 printf(" Time = %s\n", datestamp->data);
205 printf("gmsthours = %f = %s\n", gmsthours, timestr);
206 printf(" expect: 0h = 00h 00m 00s \n");
207
208 printf("\nUsing the GPStoGMST1() and GPStoLMST1() routines instead:\n");
209 units_and_acc.units = MST_SEC;
210 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
211 LALSecsToLALDate(&status, &mstdate, gmstsecs);
212 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
213 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
214 strcat(timestr, tmpstr+1); /* remove leading 0 */
215 /* LALDateString(&status, datestamp, &date); */
216
217 place_and_gps.p_detector = &detector;
218 place_and_gps.p_gps = &gpstime;
219 units_and_acc.units = MST_HRS;
220 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
221 printf(" Time = %s\n", datestamp->data);
222 printf("gmsthours = %f = %s\n", gmsthours, timestr);
223 printf(" expect: 0h = 00h 00m 00s \n");
224 printf("lmsthours = %f\n", lmsthours);
225
226 /* Doing the GPS to MST1 conversions the long way */
227 printf("\n");
228 printf("\nConverting GPS to LMST the long way instead:\n");
229 LALGPStoUTC(&status, &date, &gpstime, &accuracy);
230 LALGMST1(&status, &gmsthours, &date, MST_HRS);
231 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
232
233 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
234 LALSecsToLALDate(&status, &mstdate, gmstsecs);
235 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
236 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
237 strcat(timestr, tmpstr+1); /* remove leading 0 */
238 LALDateString(&status, datestamp, &date);
239
240 printf(" Time = %s\n", datestamp->data);
241 printf("gmsthours = %f = %s\n", gmsthours, timestr);
242 printf(" expect: 0h = 00h 00m 00s \n");
243 printf("lmsthours = %f\n", lmsthours);
244
245
246 /*
247 * A third check against the Almanac:
248 * For 1994-05-17 0h
249 */
250 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
251 date.residualNanoSeconds = 0;
252 date.unixDate.tm_sec = 0;
253 date.unixDate.tm_min = 0;
254 date.unixDate.tm_hour = 0;
255 date.unixDate.tm_mday = 17;
256 date.unixDate.tm_mon = 4;
257 date.unixDate.tm_year = 94;
258
259 gpstime.gpsSeconds = 453168010;
260 gpstime.gpsNanoSeconds = 0;
261
262 detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
263 place_and_date.p_detector = &detector;
264 place_and_date.p_date = &date;
265
266 LALGMST1(&status, &gmsthours, &date, MST_HRS);
267 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
268
269 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
270 LALSecsToLALDate(&status, &mstdate, gmstsecs);
271 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
272 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
273 strcat(timestr, tmpstr+1); /* remove leading 0 */
274 /* LALDateString(&status, datestamp, &date); */
275
276 printf(" Time = %s\n", datestamp->data);
277 printf("gmsthours = %f = %s\n", gmsthours, timestr);
278 printf(" expect: 15.63105328 = 15h 37m 51.7918s\n");
279
280 printf("\n");
281 printf("Using the GPStoGMST1() and GPStoLMST1() routines instead:\n");
282 units_and_acc.units = MST_SEC;
283 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
284 LALSecsToLALDate(&status, &mstdate, gmstsecs);
285 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
286 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
287 strcat(timestr, tmpstr+1); /* remove leading 0 */
288 /* LALDateString(&status, datestamp, &date); */
289
290 place_and_gps.p_detector = &detector;
291 place_and_gps.p_gps = &gpstime;
292 units_and_acc.units = MST_HRS;
293 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
294 printf(" Time = %s\n", datestamp->data);
295 printf("gmsthours = %f = %s\n", gmsthours, timestr);
296 printf(" expect: 15.63105328 = 15h 37m 51.7918s\n");
297 printf("lmsthours = %f\n", lmsthours);
298
299
300 /* And increment the date by 1 hour to see
301 * if it makes GMST change */
302 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
303 date.residualNanoSeconds = 0;
304 date.unixDate.tm_sec = 0;
305 date.unixDate.tm_min = 0;
306 date.unixDate.tm_hour = 1;
307 date.unixDate.tm_mday = 17;
308 date.unixDate.tm_mon = 4;
309 date.unixDate.tm_year = 94;
310
311 gpstime.gpsSeconds += 3600;
312
313 detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
314 place_and_date.p_detector = &detector;
315 place_and_date.p_date = &date;
316
317 LALGMST1(&status, &gmsthours, &date, MST_HRS);
318 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
319
320 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
321 LALSecsToLALDate(&status, &mstdate, gmstsecs);
322 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
323 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
324 strcat(timestr, tmpstr+1); /* remove leading 0 */
325 /* LALDateString(&status, datestamp, &date); */
326
327 printf(" Time = %s\n", datestamp->data);
328 printf("gmsthours = %f = %s\n", gmsthours, timestr);
329 printf(" expect: 16.63105328 = 16h 37m 51.7918s\n");
330
331 printf("\nUsing the GPStoGMST1() and GPStoLMST1() routines instead:\n");
332 units_and_acc.units = MST_SEC;
333 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
334 LALSecsToLALDate(&status, &mstdate, gmstsecs);
335 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
336 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
337 strcat(timestr, tmpstr+1); /* remove leading 0 */
338 /* LALDateString(&status, datestamp, &date); */
339
340 place_and_gps.p_detector = &detector;
341 place_and_gps.p_gps = &gpstime;
342 units_and_acc.units = MST_HRS;
343 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
344 printf(" Time = %s\n", datestamp->data);
345 printf("gmsthours = %f = %s\n", gmsthours, timestr);
346 printf(" expect: 16.63105328 = 16h 37m 51.7918s\n");
347 printf("lmsthours = %f\n", lmsthours);
348
349
350
351
352 /*
353 * A fourth check against the Almanac:
354 * For 1994-05-17 08:20:46.7448 -> 0h GMST
355 */
356 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
357 date.residualNanoSeconds = 744800000;
358 date.unixDate.tm_sec = 46;
359 date.unixDate.tm_min = 20;
360 date.unixDate.tm_hour = 8;
361 date.unixDate.tm_mday = 17;
362 date.unixDate.tm_mon = 4;
363 date.unixDate.tm_year = 94;
364
365 gpstime.gpsSeconds = 453168010;
366 gpstime.gpsNanoSeconds = date.residualNanoSeconds;
367
368 detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
369 place_and_date.p_detector = &detector;
370 place_and_date.p_date = &date;
371
372 LALGMST1(&status, &gmsthours, &date, MST_HRS);
373 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
374
375 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
376 LALSecsToLALDate(&status, &mstdate, gmstsecs);
377 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
378 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
379 strcat(timestr, tmpstr+1); /* remove leading 0 */
380 /* LALDateString(&status, datestamp, &date); */
381
382 printf(" Time = %s\n", datestamp->data);
383 printf("gmsthours = %f = %s\n", gmsthours, timestr);
384 printf(" expect: 0h = 00h 00m 00s \n");
385 }
386
387 if (testid == 2)
388 {
389 /* Generate column G (Mean) of Sec. B of the Almanac for 1994 */
390 date.unixDate.tm_sec = 0;
391 date.unixDate.tm_min = 0;
392 date.unixDate.tm_hour = 0;
393 date.unixDate.tm_year = 94;
394
395 /* all other fields to 0 */
396 date.unixDate.tm_wday = 0;
397 date.unixDate.tm_yday = 0;
398 date.unixDate.tm_isdst = 0;
399
400 printf("\nGMST1 of 0h UT1 for 1994 (check against Almanac):\n");
401 for (monthofyear = 0; monthofyear < 12; ++monthofyear)
402 {
403 date.unixDate.tm_mon = monthofyear;
404
405 for (dayofmonth = 1; dayofmonth < 32; ++dayofmonth)
406 {
407 date.unixDate.tm_mday = dayofmonth;
408
409 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
410 LALSecsToLALDate(&status, &mstdate, gmstsecs);
411 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
412 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
413 strcat(timestr, tmpstr+1); /* remove leading 0 */
414 LALDateString(&status, datestamp, &date);
415 printf("%s: %s\n", datestamp->data, timestr);
416
417 /* February */
418 if (monthofyear == 1)
419 if (dayofmonth == 28)
420 break;
421 /* the 30-day months */
422 if (monthofyear == 3 || monthofyear == 5 ||
423 monthofyear == 8 || monthofyear == 10)
424 if (dayofmonth == 30)
425 break;
426 }
427 }
428 }
429
430 /*
431 * Housekeeping
432 */
433 LALCHARDestroyVector(&status, &datestamp);
434#endif
435 return(0);
436}
int main(void)
Definition: LMST2Test.c:28
double REAL8
Double precision real floating-point number (8 bytes).
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
void LALCHARCreateVector(LALStatus *, CHARVector **, UINT4)
void LALCHARDestroyVector(LALStatus *, CHARVector **)
Vector of type CHAR, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:73
CHAR * data
Pointer to the data array.
Definition: LALDatatypes.h:78
Detector structure.
Definition: LALDetectors.h:278
LALFrDetector frDetector
The original LALFrDetector structure from which this was created.
Definition: LALDetectors.h:282
REAL8 vertexLongitudeRadians
The geodetic longitude of the vertex in radians.
Definition: LALDetectors.h:258
This structure stores pointers to a LALDetector and a LIGOTimeGPS.
Definition: Date.h:102
LIGOTimeGPS * p_gps
Pointer to a GPS time structure.
Definition: Date.h:104
const LALDetector * p_detector
pointer to a detector
Definition: Date.h:103
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
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