00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <math.h>
00022 #include <stdlib.h>
00023
00024 #include <lal/LALStdlib.h>
00025 #include <lal/Date.h>
00026 #include <lal/AVFactories.h>
00027
00028 INT4 lalDebugLevel = 0;
00029
00030 NRCSID (LALTESTLMSTC, "$Id: TestLMST.c,v 1.21 2007/06/08 14:41:43 bema Exp $");
00031
00032 #define SUCCESS 0
00033 #define TESTLMSTC_DATESTRING 1
00034
00035 static BOOLEAN mstdate_ok_p(const LALDate *p_date,
00036 const LALDate *p_expected_date);
00037
00038 int main(int argc, char *argv[])
00039 {
00040 static LALStatus stat;
00041 LIGOTimeGPS gpstime;
00042
00043 REAL8 gmstsecs;
00044 LALDate date;
00045 LALDate mstdate;
00046 LALDate expected_mstdate;
00047 LALDetector detector;
00048 LALPlaceAndDate place_and_date;
00049
00050 char refstr[256];
00051 char tmpstr[128];
00052 LALLeapSecAccuracy accuracy = LALLEAPSEC_STRICT;
00053
00054
00055 if (argc > 1)
00056 lalDebugLevel = atoi(argv[1]);
00057
00058
00059
00060
00061
00062
00063
00064 date.unixDate.tm_sec = 0;
00065 date.unixDate.tm_min = 0;
00066 date.unixDate.tm_hour = 0;
00067 date.unixDate.tm_mday = 16;
00068 date.unixDate.tm_mon = 10;
00069 date.unixDate.tm_year = 94;
00070 date.residualNanoSeconds = 0;
00071
00072
00073 gpstime.gpsSeconds = 468979210;
00074 gpstime.gpsNanoSeconds = 0;
00075
00076 LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
00077 if (stat.statusCode && lalDebugLevel > 0)
00078 {
00079 fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
00080 __LINE__, LALTESTLMSTC);
00081 REPORTSTATUS(&stat);
00082 return stat.statusCode;
00083 }
00084
00085 detector.frDetector.vertexLongitudeRadians = 0.;
00086 place_and_date.p_detector = &detector;
00087 place_and_date.p_date = &date;
00088
00089 LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
00090 if (stat.statusCode && lalDebugLevel > 0)
00091 {
00092 fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
00093 __LINE__, LALTESTLMSTC);
00094 REPORTSTATUS(&stat);
00095 return stat.statusCode;
00096 }
00097
00098 LALSecsToLALDate(&stat, &mstdate, gmstsecs);
00099 if (stat.statusCode && lalDebugLevel > 0)
00100 {
00101 fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
00102 __LINE__, LALTESTLMSTC);
00103 REPORTSTATUS(&stat);
00104 return stat.statusCode;
00105 }
00106
00107
00108
00109
00110
00111
00112 expected_mstdate.residualNanoSeconds = 0.2738 * 1.e9;
00113 expected_mstdate.unixDate.tm_sec = 21;
00114 expected_mstdate.unixDate.tm_min = 39;
00115 expected_mstdate.unixDate.tm_hour = 3;
00116
00117 if (!mstdate_ok_p(&mstdate, &expected_mstdate))
00118 {
00119 fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
00120
00121 sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
00122 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00123 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00124 strcat(refstr, tmpstr+1);
00125 fprintf(stderr, " GMST at 0h UTC on 1994-11-16:\n");
00126 fprintf(stderr, " get: %s\n", refstr);
00127
00128 sprintf(tmpstr, " 03h 39m 21.2738s");
00129 fprintf(stderr, " expect: %s\n", tmpstr);
00130 fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
00131 fprintf(stderr, " expect up to one sidereal second disagreement\n");
00132
00133 return (1);
00134 }
00135
00136 if (lalDebugLevel > 2)
00137 {
00138 sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
00139 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00140 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00141 strcat(refstr, tmpstr+1);
00142 printf("GMST at 0h UTC on 1994-11-16:\n");
00143 printf(" get: %s\n", refstr);
00144
00145 sprintf(tmpstr, "03h 39m 21.2738s");
00146 printf(" expect: %s\n", tmpstr);
00147 printf("but since we don't have the equation of equinoxes in, can\n");
00148 printf("expect up to one sidereal second disagreement\n");
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 date.unixDate.tm_sec = 0;
00158 date.unixDate.tm_min = 0;
00159 date.unixDate.tm_hour = 0;
00160 date.unixDate.tm_mday = 8;
00161 date.unixDate.tm_mon = 7;
00162 date.unixDate.tm_year = 94;
00163 date.residualNanoSeconds = 0;
00164
00165
00166 gpstime.gpsSeconds = 460339210;
00167 gpstime.gpsNanoSeconds = 0;
00168
00169 LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
00170 if (stat.statusCode && lalDebugLevel > 0)
00171 {
00172 fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
00173 __LINE__, LALTESTLMSTC);
00174 REPORTSTATUS(&stat);
00175 return stat.statusCode;
00176 }
00177
00178 detector.frDetector.vertexLongitudeRadians = 0.;
00179 place_and_date.p_detector = &detector;
00180 place_and_date.p_date = &date;
00181
00182 LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
00183 if (stat.statusCode && lalDebugLevel > 0)
00184 {
00185 fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
00186 __LINE__, LALTESTLMSTC);
00187 REPORTSTATUS(&stat);
00188 return stat.statusCode;
00189 }
00190
00191 LALSecsToLALDate(&stat, &mstdate, gmstsecs);
00192 if (stat.statusCode && lalDebugLevel > 0)
00193 {
00194 fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
00195 __LINE__, LALTESTLMSTC);
00196 REPORTSTATUS(&stat);
00197 return stat.statusCode;
00198 }
00199
00200
00201
00202
00203
00204
00205 expected_mstdate.residualNanoSeconds = 0.9812*1.e9;
00206 expected_mstdate.unixDate.tm_sec = 5;
00207 expected_mstdate.unixDate.tm_min = 5;
00208 expected_mstdate.unixDate.tm_hour = 21;
00209
00210 if (!mstdate_ok_p(&mstdate, &expected_mstdate))
00211 {
00212 fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
00213
00214 sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
00215 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00216 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00217 strcat(refstr, tmpstr+1);
00218 fprintf(stderr, " GMST at 0h UTC on 1994-08-08:\n");
00219 fprintf(stderr, " get: %s\n", refstr);
00220
00221 sprintf(tmpstr, " 21h 05m 05.9812s");
00222 fprintf(stderr, " expect: %s\n", tmpstr);
00223 fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
00224 fprintf(stderr, " expect up to one sidereal second disagreement\n");
00225
00226 return (1);
00227 }
00228
00229 if (lalDebugLevel > 2)
00230 {
00231 sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
00232 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00233 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00234 printf("\n");
00235 printf("GMST at 0h UTC on 1994-08-08:\n");
00236 strcat(refstr, tmpstr+1);
00237 printf(" get: %s\n", refstr);
00238
00239 sprintf(tmpstr, "21h 05m 05.9812s");
00240 printf(" expect: %s\n", tmpstr);
00241 printf("but since we don't have the equation of equinoxes in, can\n");
00242 printf("expect up to one sidereal second disagreement\n");
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 date.unixDate.tm_sec = 0;
00255 date.unixDate.tm_min = 0;
00256 date.unixDate.tm_hour = 0;
00257 date.unixDate.tm_mday = 11;
00258 date.unixDate.tm_mon = 0;
00259 date.unixDate.tm_year = 103;
00260 date.residualNanoSeconds = 0;
00261
00262
00263 gpstime.gpsSeconds = 726278413;
00264 gpstime.gpsNanoSeconds = 0;
00265
00266 LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
00267 if (stat.statusCode && lalDebugLevel > 0)
00268 {
00269 fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
00270 __LINE__, LALTESTLMSTC);
00271 REPORTSTATUS(&stat);
00272 return stat.statusCode;
00273 }
00274
00275 detector.frDetector.vertexLongitudeRadians = 0.;
00276 place_and_date.p_detector = &detector;
00277 place_and_date.p_date = &date;
00278
00279 LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
00280 if (stat.statusCode && lalDebugLevel > 0)
00281 {
00282 fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
00283 __LINE__, LALTESTLMSTC);
00284 REPORTSTATUS(&stat);
00285 return stat.statusCode;
00286 }
00287
00288 LALSecsToLALDate(&stat, &mstdate, gmstsecs);
00289 if (stat.statusCode && lalDebugLevel > 0)
00290 {
00291 fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
00292 __LINE__, LALTESTLMSTC);
00293 REPORTSTATUS(&stat);
00294 return stat.statusCode;
00295 }
00296
00297
00298
00299
00300
00301
00302 expected_mstdate.residualNanoSeconds = 0.5980*1.e9;
00303 expected_mstdate.unixDate.tm_sec = 21;
00304 expected_mstdate.unixDate.tm_min = 20;
00305 expected_mstdate.unixDate.tm_hour = 7;
00306
00307 if (!mstdate_ok_p(&mstdate, &expected_mstdate))
00308 {
00309 fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
00310
00311 sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
00312 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00313 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00314 strcat(refstr, tmpstr+1);
00315 fprintf(stderr, " GMST at 0h UTC on 2003-01-11:\n");
00316 fprintf(stderr, " get: %s\n", refstr);
00317
00318 sprintf(tmpstr, " 07h 20m 21.5980s");
00319 fprintf(stderr, " expect: %s\n", tmpstr);
00320 fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
00321 fprintf(stderr, " expect up to one sidereal second disagreement\n");
00322
00323 return (1);
00324 }
00325
00326
00327
00328 if (lalDebugLevel > 2)
00329 {
00330 sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
00331 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00332 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00333 strcat(refstr, tmpstr+1);
00334 printf("\n");
00335 printf("GMST at 0h UTC on 2003-01-11:\n");
00336 printf(" get: %s\n", refstr);
00337
00338 sprintf(tmpstr, "07h 20m 21.5980s");
00339 printf(" expect: %s\n", tmpstr);
00340 printf("but since we don't have the equation of equinoxes in, can\n");
00341 printf("expect up to one sidereal second disagreement\n");
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 date.unixDate.tm_sec = 0;
00355 date.unixDate.tm_min = 0;
00356 date.unixDate.tm_hour = 0;
00357 date.unixDate.tm_mday = 1;
00358 date.unixDate.tm_mon = 4;
00359 date.unixDate.tm_year = 103;
00360 date.residualNanoSeconds = 0;
00361
00362
00363 gpstime.gpsSeconds = 733190413;
00364 gpstime.gpsNanoSeconds = 0;
00365
00366 LALUTCtoGPS(&stat, &gpstime, &date, &accuracy);
00367 if (stat.statusCode && lalDebugLevel > 0)
00368 {
00369 fprintf(stderr, "TestLMST: LALUTCtoGPS() failed, line %i, %s\n",
00370 __LINE__, LALTESTLMSTC);
00371 REPORTSTATUS(&stat);
00372 return stat.statusCode;
00373 }
00374
00375 detector.frDetector.vertexLongitudeRadians = 0.;
00376 place_and_date.p_detector = &detector;
00377 place_and_date.p_date = &date;
00378
00379 LALGMST1(&stat, &gmstsecs, &date, MST_SEC);
00380 if (stat.statusCode && lalDebugLevel > 0)
00381 {
00382 fprintf(stderr, "TestLMST: LALGMST1() failed, line %i, %s\n",
00383 __LINE__, LALTESTLMSTC);
00384 REPORTSTATUS(&stat);
00385 return stat.statusCode;
00386 }
00387
00388 LALSecsToLALDate(&stat, &mstdate, gmstsecs);
00389 if (stat.statusCode && lalDebugLevel > 0)
00390 {
00391 fprintf(stderr, "TestLMST: LALSecsToLALDate() failed, line %i, %s\n",
00392 __LINE__, LALTESTLMSTC);
00393 REPORTSTATUS(&stat);
00394 return stat.statusCode;
00395 }
00396
00397
00398
00399
00400
00401
00402
00403 expected_mstdate.residualNanoSeconds = 0.6093*1.e9;
00404 expected_mstdate.unixDate.tm_sec = 2;
00405 expected_mstdate.unixDate.tm_min = 34;
00406 expected_mstdate.unixDate.tm_hour = 14;
00407
00408 if (!mstdate_ok_p(&mstdate, &expected_mstdate))
00409 {
00410 fprintf(stderr, "TestLMST: ERROR: wrong sidereal time:\n");
00411
00412 sprintf(refstr, " %02dh %02dm %02d", mstdate.unixDate.tm_hour,
00413 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00414 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00415 strcat(refstr, tmpstr+1);
00416 fprintf(stderr, " GMST at 0h UTC on 2003-04-01:\n");
00417 fprintf(stderr, " get: %s\n", refstr);
00418
00419 sprintf(tmpstr, " 14h 34m 02.6093s ");
00420 fprintf(stderr, " expect: %s\n", tmpstr);
00421 fprintf(stderr, " but since we don't have the equation of equinoxes in, can\n");
00422 fprintf(stderr, " expect up to one sidereal second disagreement\n");
00423
00424 return (1);
00425 }
00426
00427
00428 if (lalDebugLevel > 2)
00429 {
00430 sprintf(refstr, "%02dh %02dm %02d", mstdate.unixDate.tm_hour,
00431 mstdate.unixDate.tm_min, mstdate.unixDate.tm_sec);
00432 sprintf(tmpstr, "%.4fs", mstdate.residualNanoSeconds * 1.e-9);
00433 strcat(refstr, tmpstr+1);
00434 printf("\n");
00435 printf("GMST at 0h UTC on 2003-04-01:\n");
00436 printf(" get: %s\n", refstr);
00437
00438 sprintf(tmpstr, "14h 34m 02.6093s");
00439 printf(" expect: %s\n", tmpstr);
00440 printf("but since we don't have the equation of equinoxes in, can\n");
00441 printf("expect up to one sidereal second disagreement\n");
00442 }
00443
00444
00445 return stat.statusCode;
00446
00447 }
00448
00449
00450
00451 static BOOLEAN mstdate_ok_p(const LALDate *p_date,
00452 const LALDate *p_expected_date)
00453 {
00454 BOOLEAN secs_ok_p;
00455 double secs, expected_secs;
00456
00457 secs = (double)((*p_date).unixDate.tm_sec) +
00458 (*p_date).residualNanoSeconds / 1.e9;
00459 expected_secs = (double)((*p_expected_date).unixDate.tm_sec) +
00460 (*p_expected_date).residualNanoSeconds / 1.e9;
00461
00462 #if 0
00463 printf(" secs = % 20.14e\n", secs);
00464 printf("expected_secs = % 20.14e\n", expected_secs);
00465 #endif
00466
00467 secs_ok_p = (fabs(secs - expected_secs) < 1.);
00468
00469 return (secs_ok_p &&
00470 (*p_date).unixDate.tm_min == (*p_expected_date).unixDate.tm_min &&
00471 (*p_date).unixDate.tm_hour == (*p_expected_date).unixDate.tm_hour);
00472 }