LAL  7.5.0.1-fe68b98
LMSTTest.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 <stdio.h>
21 #include <math.h>
22 #include <stdlib.h>
23 #include <time.h>
24 
25 #include <lal/LALStdlib.h>
26 #include <lal/Date.h>
27 #include <lal/AVFactories.h>
28 
29 
30 #define SUCCESS 0
31 #define TESTLMSTC_DATESTRING 1
32 
33 #if 0
34 static BOOLEAN mstdate_ok_p(const LALDate *p_date,
35  const LALDate *p_expected_date);
36 #endif
37 
38 /*int main(int argc, char *argv[])*/
39 int main(void)
40 {
41 /* FIXME: this needs to be ported to test the XLAL replacements */
42 #if 0
43  static LALStatus stat;
44  LIGOTimeGPS gpstime;
45  /* REAL8 gmsthours, lmsthours; */
46  REAL8 gmstsecs;
47  LALDate date;
48  LALDate mstdate;
49  LALDate expected_mstdate;
50  LALDetector detector;
51  LALPlaceAndDate place_and_date;
52  /* LALPlaceAndGPS place_and_gps; */
53  char refstr[256];
54  char tmpstr[128];
55  LALLeapSecAccuracy accuracy = LALLEAPSEC_STRICT;
56 
57 
58  if (argc > 1)
59 
60  /** TEST NO. 1 **/
61 
62  /*
63  * Check against the Astronomical Almanac:
64  * For 1994-11-16 0h UT - Julian Date 2449672.5, GMST 03h 39m 21.2738s
65  */
66  date.unixDate.tm_sec = 0;
67  date.unixDate.tm_min = 0;
68  date.unixDate.tm_hour = 0;
69  date.unixDate.tm_mday = 16;
70  date.unixDate.tm_mon = 10;
71  date.unixDate.tm_year = 94;
72  date.residualNanoSeconds = 0;
73 
74  /* The corresponding GPS time is */
75  gpstime.gpsSeconds = 468979210;
76  gpstime.gpsNanoSeconds = 0;
77 
78  LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
79  if (stat.statusCode && lalDebugLevel > 0)
80  {
81  fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
82  __LINE__, LALTESTLMSTC);
83  REPORTSTATUS(&stat);
84  return stat.statusCode;
85  }
86 
87  detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
88  place_and_date.p_detector = &detector;
89  place_and_date.p_date = &date;
90 
91  LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
92  if (stat.statusCode && lalDebugLevel > 0)
93  {
94  fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
95  __LINE__, LALTESTLMSTC);
96  REPORTSTATUS(&stat);
97  return stat.statusCode;
98  }
99 
100  LALSecsToLALDate(&stat, &mstdate, gmstsecs);
101  if (stat.statusCode && lalDebugLevel > 0)
102  {
103  fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
104  __LINE__, LALTESTLMSTC);
105  REPORTSTATUS(&stat);
106  return stat.statusCode;
107  }
108 
109  /*strftime(refstr, 64, "%Hh %Mm %S", &(mstdate.unixDate)); */
110  /*sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);*/
111  /*strcat(refstr, tmpstr+1); / * remove leading 0 */
112  /*printf(" get: %s\n", refstr);*/
113 
114  expected_mstdate.residualNanoSeconds = 0.2738 * 1.e9;
115  expected_mstdate.unixDate.tm_sec = 21;
116  expected_mstdate.unixDate.tm_min = 39;
117  expected_mstdate.unixDate.tm_hour = 3;
118 
119  if (!mstdate_ok_p(&mstdate, &expected_mstdate))
120  {
121  fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
122 
123  sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
124  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
125  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
126  strcat(refstr, tmpstr+1);
127  fprintf(stderr, " GMST at 0h UTC on 1994-11-16:\n");
128  fprintf(stderr, " get: %s\n", refstr);
129 
130  sprintf(tmpstr, " 03h 39m 21.2738s");
131  fprintf(stderr, " expect: %s\n", tmpstr);
132  fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
133  fprintf(stderr, " expect up to one sidereal second disagreement\n");
134 
135  return (1);
136  }
137 
138  if (lalDebugLevel > 2)
139  {
140  sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
141  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
142  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
143  strcat(refstr, tmpstr+1);
144  printf("GMST at 0h UTC on 1994-11-16:\n");
145  printf(" get: %s\n", refstr);
146 
147  sprintf(tmpstr, "03h 39m 21.2738s");
148  printf(" expect: %s\n", tmpstr);
149  printf("but since we don't have the equation of equinoxes in, can\n");
150  printf("expect up to one sidereal second disagreement\n");
151  }
152 
153  /** TEST NO. 2 **/
154 
155  /*
156  * Check against the Astronomical Almanac:
157  * For 1994-08-08 0h UT - Julian Date 2449572.5, GMST 21h 05m 05.9812s
158  */
159  date.unixDate.tm_sec = 0;
160  date.unixDate.tm_min = 0;
161  date.unixDate.tm_hour = 0;
162  date.unixDate.tm_mday = 8;
163  date.unixDate.tm_mon = 7;
164  date.unixDate.tm_year = 94;
165  date.residualNanoSeconds = 0;
166 
167  /* The corresponding GPS time is */
168  gpstime.gpsSeconds = 460339210;
169  gpstime.gpsNanoSeconds = 0;
170 
171  LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
172  if (stat.statusCode && lalDebugLevel > 0)
173  {
174  fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
175  __LINE__, LALTESTLMSTC);
176  REPORTSTATUS(&stat);
177  return stat.statusCode;
178  }
179 
180  detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
181  place_and_date.p_detector = &detector;
182  place_and_date.p_date = &date;
183 
184  LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
185  if (stat.statusCode && lalDebugLevel > 0)
186  {
187  fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
188  __LINE__, LALTESTLMSTC);
189  REPORTSTATUS(&stat);
190  return stat.statusCode;
191  }
192 
193  LALSecsToLALDate(&stat, &mstdate, gmstsecs);
194  if (stat.statusCode && lalDebugLevel > 0)
195  {
196  fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
197  __LINE__, LALTESTLMSTC);
198  REPORTSTATUS(&stat);
199  return stat.statusCode;
200  }
201 
202  /* strftime(refstr, 64, "%Hh %Mm %S", &(mstdate.unixDate)); */
203  /* sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9); */
204  /* strcat(refstr, tmpstr+1); / * remove leading 0 */
205  /* printf(" get: %s\n", refstr); */
206 
207  expected_mstdate.residualNanoSeconds = 0.9812*1.e9;
208  expected_mstdate.unixDate.tm_sec = 5;
209  expected_mstdate.unixDate.tm_min = 5;
210  expected_mstdate.unixDate.tm_hour = 21;
211 
212  if (!mstdate_ok_p(&mstdate, &expected_mstdate))
213  {
214  fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
215 
216  sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
217  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
218  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
219  strcat(refstr, tmpstr+1);
220  fprintf(stderr, " GMST at 0h UTC on 1994-08-08:\n");
221  fprintf(stderr, " get: %s\n", refstr);
222 
223  sprintf(tmpstr, " 21h 05m 05.9812s");
224  fprintf(stderr, " expect: %s\n", tmpstr);
225  fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
226  fprintf(stderr, " expect up to one sidereal second disagreement\n");
227 
228  return (1);
229  }
230 
231  if (lalDebugLevel > 2)
232  {
233  sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
234  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
235  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
236  printf("\n");
237  printf("GMST at 0h UTC on 1994-08-08:\n");
238  strcat(refstr, tmpstr+1);
239  printf(" get: %s\n", refstr);
240 
241  sprintf(tmpstr, "21h 05m 05.9812s");
242  printf(" expect: %s\n", tmpstr);
243  printf("but since we don't have the equation of equinoxes in, can\n");
244  printf("expect up to one sidereal second disagreement\n");
245  }
246 
247 
248  /** TEST NO. 3 **/
249 
250  /*** check another date/time ***/
251 
252  /*
253  * Check against the Astronomical Almanac:
254  * For 2003-01-11 0h UT - Julian Date 2452650.5, GMST 7h 20m 21.5980s
255  */
256  date.unixDate.tm_sec = 0;
257  date.unixDate.tm_min = 0;
258  date.unixDate.tm_hour = 0;
259  date.unixDate.tm_mday = 11;
260  date.unixDate.tm_mon = 0;
261  date.unixDate.tm_year = 103;
262  date.residualNanoSeconds = 0;
263 
264  /* The corresponding GPS time is */
265  gpstime.gpsSeconds = 726278413;
266  gpstime.gpsNanoSeconds = 0;
267 
268  LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
269  if (stat.statusCode && lalDebugLevel > 0)
270  {
271  fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
272  __LINE__, LALTESTLMSTC);
273  REPORTSTATUS(&stat);
274  return stat.statusCode;
275  }
276 
277  detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
278  place_and_date.p_detector = &detector;
279  place_and_date.p_date = &date;
280 
281  LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
282  if (stat.statusCode && lalDebugLevel > 0)
283  {
284  fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
285  __LINE__, LALTESTLMSTC);
286  REPORTSTATUS(&stat);
287  return stat.statusCode;
288  }
289 
290  LALSecsToLALDate(&stat, &mstdate, gmstsecs);
291  if (stat.statusCode && lalDebugLevel > 0)
292  {
293  fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
294  __LINE__, LALTESTLMSTC);
295  REPORTSTATUS(&stat);
296  return stat.statusCode;
297  }
298 
299  /* strftime(refstr, 64, "%Hh %Mm %S", &(mstdate.unixDate)); */
300  /* sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9); */
301  /* strcat(refstr, tmpstr+1); / * remove leading 0 */
302  /* printf(" get: %s\n", refstr); */
303 
304  expected_mstdate.residualNanoSeconds = 0.5980*1.e9;
305  expected_mstdate.unixDate.tm_sec = 21;
306  expected_mstdate.unixDate.tm_min = 20;
307  expected_mstdate.unixDate.tm_hour = 7;
308 
309  if (!mstdate_ok_p(&mstdate, &expected_mstdate))
310  {
311  fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
312 
313  sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
314  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
315  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
316  strcat(refstr, tmpstr+1);
317  fprintf(stderr, " GMST at 0h UTC on 2003-01-11:\n");
318  fprintf(stderr, " get: %s\n", refstr);
319 
320  sprintf(tmpstr, " 07h 20m 21.5980s");
321  fprintf(stderr, " expect: %s\n", tmpstr);
322  fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
323  fprintf(stderr, " expect up to one sidereal second disagreement\n");
324 
325  return (1);
326  }
327 
328 
329 
330  if (lalDebugLevel > 2)
331  {
332  sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
333  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
334  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
335  strcat(refstr, tmpstr+1);
336  printf("\n");
337  printf("GMST at 0h UTC on 2003-01-11:\n");
338  printf(" get: %s\n", refstr);
339 
340  sprintf(tmpstr, "07h 20m 21.5980s");
341  printf(" expect: %s\n", tmpstr);
342  printf("but since we don't have the equation of equinoxes in, can\n");
343  printf("expect up to one sidereal second disagreement\n");
344  }
345 
346 
347 
348  /** TEST NO. 4 **/
349 
350  /*** check another date/time ***/
351 
352  /*
353  * Check against the Astronomical Almanac:
354  * For 2003-04-01 0h UT - Julian Date 2452730.5, GMST 12h 35m 45.9989s
355  */
356  date.unixDate.tm_sec = 0;
357  date.unixDate.tm_min = 0;
358  date.unixDate.tm_hour = 0;
359  date.unixDate.tm_mday = 1;
360  date.unixDate.tm_mon = 4;
361  date.unixDate.tm_year = 103;
362  date.residualNanoSeconds = 0;
363 
364  /* The corresponding GPS time is */
365  gpstime.gpsSeconds = 733190413;
366  gpstime.gpsNanoSeconds = 0;
367 
368  LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
369  if (stat.statusCode && lalDebugLevel > 0)
370  {
371  fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
372  __LINE__, LALTESTLMSTC);
373  REPORTSTATUS(&stat);
374  return stat.statusCode;
375  }
376 
377  detector.frDetector.vertexLongitudeRadians = 0.; /* Greenwich */
378  place_and_date.p_detector = &detector;
379  place_and_date.p_date = &date;
380 
381  LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
382  if (stat.statusCode && lalDebugLevel > 0)
383  {
384  fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
385  __LINE__, LALTESTLMSTC);
386  REPORTSTATUS(&stat);
387  return stat.statusCode;
388  }
389 
390  LALSecsToLALDate(&stat, &mstdate, gmstsecs);
391  if (stat.statusCode && lalDebugLevel > 0)
392  {
393  fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
394  __LINE__, LALTESTLMSTC);
395  REPORTSTATUS(&stat);
396  return stat.statusCode;
397  }
398 
399  /* strftime(refstr, 64, "%Hh %Mm %S", &(mstdate.unixDate)); */
400  /* sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9); */
401  /* strcat(refstr, tmpstr+1); / * remove leading 0 */
402  /* printf(" get: %s\n", refstr); */
403 
404 
405  expected_mstdate.residualNanoSeconds = 0.6093*1.e9;
406  expected_mstdate.unixDate.tm_sec = 2;
407  expected_mstdate.unixDate.tm_min = 34;
408  expected_mstdate.unixDate.tm_hour = 14;
409 
410  if (!mstdate_ok_p(&mstdate, &expected_mstdate))
411  {
412  fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
413 
414  sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
415  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
416  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
417  strcat(refstr, tmpstr+1);
418  fprintf(stderr, " GMST at 0h UTC on 2003-04-01:\n");
419  fprintf(stderr, " get: %s\n", refstr);
420 
421  sprintf(tmpstr, " 14h 34m 02.6093s ");
422  fprintf(stderr, " expect: %s\n", tmpstr);
423  fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
424  fprintf(stderr, " expect up to one sidereal second disagreement\n");
425 
426  return (1);
427  }
428 
429 
430  if (lalDebugLevel > 2)
431  {
432  sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
433  mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
434  sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
435  strcat(refstr, tmpstr+1);
436  printf("\n");
437  printf("GMST at 0h UTC on 2003-04-01:\n");
438  printf(" get: %s\n", refstr);
439 
440  sprintf(tmpstr, "14h 34m 02.6093s");
441  printf(" expect: %s\n", tmpstr);
442  printf("but since we don't have the equation of equinoxes in, can\n");
443  printf("expect up to one sidereal second disagreement\n");
444  }
445 
446 
447  return stat.statusCode;
448 #else
449  return 0;
450 #endif
451 }
452 
453 #if 0
454 /* allow up to 1 sidereal second difference */
455 static BOOLEAN mstdate_ok_p(const LALDate *p_date,
456  const LALDate *p_expected_date)
457 {
458  BOOLEAN secs_ok_p;
459  double secs, expected_secs;
460 
461  secs = (double)((*p_date).unixDate.tm_sec) +
462  (*p_date).residualNanoSeconds / 1.e9;
463  expected_secs = (double)((*p_expected_date).unixDate.tm_sec) +
464  (*p_expected_date).residualNanoSeconds / 1.e9;
465 
466 #if 0
467  printf(" secs = % 20.14e\n", secs);
468  printf("expected_secs = % 20.14e\n", expected_secs);
469 #endif
470 
471  secs_ok_p = (fabs(secs - expected_secs) < 1.);
472 
473  return (secs_ok_p &&
474  (*p_date).unixDate.tm_min == (*p_expected_date).unixDate.tm_min &&
475  (*p_date).unixDate.tm_hour == (*p_expected_date).unixDate.tm_hour);
476 }
477 #endif
void REPORTSTATUS(LALStatus *status)
Definition: LALError.c:322
int main(void)
Definition: LMSTTest.c:39
#define fprintf
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
double REAL8
Double precision real floating-point number (8 bytes).
#define lalDebugLevel
Definition: LALDebugLevel.h:58
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
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
INT4 statusCode
A numerical code identifying the type of error, or 0 for nominal status; Negative values are reserved...
Definition: LALDatatypes.h:948
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