00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdlib.h>
00021 #include <lal/LALStdlib.h>
00022 #include <lal/AVFactories.h>
00023 #include <lal/Date.h>
00024
00025 INT4 lalDebugLevel = 2;
00026
00027 NRCSID (TESTLMSTC, "$Id: TestLMST2.c,v 1.5 2007/06/08 14:41:43 bema Exp $");
00028
00029 int
00030 main(int argc, char *argv[])
00031 {
00032 static LALStatus status;
00033 LALDate date;
00034 LALDate mstdate;
00035 REAL8 gmsthours, lmsthours;
00036 REAL8 gmstsecs;
00037 LALDetector detector;
00038 LALPlaceAndDate place_and_date;
00039 LALPlaceAndGPS place_and_gps;
00040 CHAR timestr[128];
00041 CHAR tmpstr[128];
00042 CHARVector *datestamp = NULL;
00043 INT4 testid;
00044 INT4 dayofmonth, monthofyear;
00045 LIGOTimeGPS gpstime;
00046 LALLeapSecAccuracy accuracy = LALLEAPSEC_STRICT;
00047 LALMSTUnitsAndAcc units_and_acc;
00048
00049
00050 if (argc != 3)
00051 {
00052
00053
00054
00055 printf("Usage: TestLMST testid debug_level\n");
00056 printf(" testid = [1,2]\n");
00057 printf(" debug_level = [0,1,2]\n");
00058 return 0;
00059 }
00060
00061 testid = atoi(argv[1]);
00062 lalDebugLevel = atoi(argv[2]);
00063
00064 LALCHARCreateVector(&status, &datestamp, (UINT4)64);
00065
00066
00067
00068
00069
00070 date.unixDate.tm_sec = 0;
00071 date.unixDate.tm_min = 0;
00072 date.unixDate.tm_hour = 0;
00073 date.unixDate.tm_mday = 0;
00074 date.unixDate.tm_mon = 0;
00075 date.unixDate.tm_year = 0;
00076 date.unixDate.tm_wday = 0;
00077 date.unixDate.tm_yday = 0;
00078 date.unixDate.tm_isdst = 0;
00079
00080 date.unixDate.tm_sec = 0;
00081 date.unixDate.tm_min = 0;
00082 date.unixDate.tm_hour = 0;
00083 date.unixDate.tm_mday = 0;
00084 date.unixDate.tm_mon = 0;
00085 date.unixDate.tm_year = 0;
00086 date.unixDate.tm_wday = 0;
00087 date.unixDate.tm_yday = 0;
00088 date.unixDate.tm_isdst = 0;
00089
00090 printf("TEST of LALGMST1 routine\n");
00091 printf("========================\n");
00092
00093 if (testid == 1)
00094 {
00095
00096
00097
00098
00099 date.unixDate.tm_sec = 0;
00100 date.unixDate.tm_min = 0;
00101 date.unixDate.tm_hour = 0;
00102 date.unixDate.tm_mday = 16;
00103 date.unixDate.tm_mon = 10;
00104 date.unixDate.tm_year = 94;
00105
00106
00107 date.unixDate.tm_wday = 0;
00108 date.unixDate.tm_yday = 0;
00109 date.unixDate.tm_isdst = 0;
00110
00111
00112 gpstime.gpsSeconds = 468979210;
00113 gpstime.gpsNanoSeconds = 0;
00114
00115 detector.frDetector.vertexLongitudeRadians = 0.;
00116 place_and_date.p_detector = &detector;
00117 place_and_date.p_date = &date;
00118 LALGMST1(&status, &gmsthours, &date, MST_HRS);
00119 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
00120
00121 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00122 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00123 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00124 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00125 strcat(timestr, tmpstr+1);
00126 LALDateString(&status, datestamp, &date);
00127
00128 printf(" Time = %s\n", datestamp->data);
00129 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00130 printf(" expect: 3.655728 = 03h 39m 20.6222s \n");
00131 printf("lmsthours = %f\n", lmsthours);
00132
00133 printf("\n");
00134 printf("Using the GPStoGMST1() and GPStoLMST1() routines instead:\n");
00135 units_and_acc.units = MST_SEC;
00136 units_and_acc.accuracy = LALLEAPSEC_STRICT;
00137 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
00138 units_and_acc.units = MST_HRS;
00139 LALGPStoGMST1(&status, &gmsthours, &gpstime, &units_and_acc);
00140 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00141 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00142 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00143 strcat(timestr, tmpstr+1);
00144
00145
00146 place_and_gps.p_detector = &detector;
00147 place_and_gps.p_gps = &gpstime;
00148 units_and_acc.units = MST_HRS;
00149 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
00150 printf(" Time = %s\n", datestamp->data);
00151 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00152 printf(" expect: 3.655728 = 03h 39m 20.6222s \n");
00153 printf("lmsthours = %f\n", lmsthours);
00154
00155
00156
00157 printf("\n");
00158 printf("\nConverting GPS to LMST the long way instead:\n");
00159 LALGPStoUTC(&status, &date, &gpstime, &accuracy);
00160 LALGMST1(&status, &gmsthours, &date, MST_HRS);
00161 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
00162
00163 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00164 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00165 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00166 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00167 strcat(timestr, tmpstr+1);
00168 LALDateString(&status, datestamp, &date);
00169
00170 printf(" Time = %s\n", datestamp->data);
00171 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00172 printf(" expect: 3.655728 = 03h 39m 20.6222s \n");
00173 printf("lmsthours = %f\n", lmsthours);
00174
00175
00176
00177
00178
00179
00180 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
00181 date.residualNanoSeconds = 73600000;
00182 date.unixDate.tm_sec = 3;
00183 date.unixDate.tm_min = 19;
00184 date.unixDate.tm_hour = 2;
00185 date.unixDate.tm_mday = 17;
00186 date.unixDate.tm_mon = 7;
00187 date.unixDate.tm_year = 94;
00188
00189 gpstime.gpsSeconds = 461125153;
00190 gpstime.gpsNanoSeconds = date.residualNanoSeconds;
00191
00192 detector.frDetector.vertexLongitudeRadians = 0.;
00193 place_and_date.p_detector = &detector;
00194 place_and_date.p_date = &date;
00195 LALGMST1(&status, &gmsthours, &date, MST_HRS);
00196 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
00197
00198 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00199 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00200 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00201 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00202 strcat(timestr, tmpstr+1);
00203
00204
00205 printf(" Time = %s\n", datestamp->data);
00206 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00207 printf(" expect: 0h = 00h 00m 00s \n");
00208
00209 printf("\nUsing the GPStoGMST1() and GPStoLMST1() routines instead:\n");
00210 units_and_acc.units = MST_SEC;
00211 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
00212 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00213 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00214 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00215 strcat(timestr, tmpstr+1);
00216
00217
00218 place_and_gps.p_detector = &detector;
00219 place_and_gps.p_gps = &gpstime;
00220 units_and_acc.units = MST_HRS;
00221 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
00222 printf(" Time = %s\n", datestamp->data);
00223 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00224 printf(" expect: 0h = 00h 00m 00s \n");
00225 printf("lmsthours = %f\n", lmsthours);
00226
00227
00228 printf("\n");
00229 printf("\nConverting GPS to LMST the long way instead:\n");
00230 LALGPStoUTC(&status, &date, &gpstime, &accuracy);
00231 LALGMST1(&status, &gmsthours, &date, MST_HRS);
00232 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
00233
00234 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00235 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00236 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00237 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00238 strcat(timestr, tmpstr+1);
00239 LALDateString(&status, datestamp, &date);
00240
00241 printf(" Time = %s\n", datestamp->data);
00242 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00243 printf(" expect: 0h = 00h 00m 00s \n");
00244 printf("lmsthours = %f\n", lmsthours);
00245
00246
00247
00248
00249
00250
00251 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
00252 date.residualNanoSeconds = 0;
00253 date.unixDate.tm_sec = 0;
00254 date.unixDate.tm_min = 0;
00255 date.unixDate.tm_hour = 0;
00256 date.unixDate.tm_mday = 17;
00257 date.unixDate.tm_mon = 4;
00258 date.unixDate.tm_year = 94;
00259
00260 gpstime.gpsSeconds = 453168010;
00261 gpstime.gpsNanoSeconds = 0;
00262
00263 detector.frDetector.vertexLongitudeRadians = 0.;
00264 place_and_date.p_detector = &detector;
00265 place_and_date.p_date = &date;
00266
00267 LALGMST1(&status, &gmsthours, &date, MST_HRS);
00268 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
00269
00270 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00271 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00272 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00273 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00274 strcat(timestr, tmpstr+1);
00275
00276
00277 printf(" Time = %s\n", datestamp->data);
00278 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00279 printf(" expect: 15.63105328 = 15h 37m 51.7918s\n");
00280
00281 printf("\n");
00282 printf("Using the GPStoGMST1() and GPStoLMST1() routines instead:\n");
00283 units_and_acc.units = MST_SEC;
00284 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
00285 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00286 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00287 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00288 strcat(timestr, tmpstr+1);
00289
00290
00291 place_and_gps.p_detector = &detector;
00292 place_and_gps.p_gps = &gpstime;
00293 units_and_acc.units = MST_HRS;
00294 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
00295 printf(" Time = %s\n", datestamp->data);
00296 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00297 printf(" expect: 15.63105328 = 15h 37m 51.7918s\n");
00298 printf("lmsthours = %f\n", lmsthours);
00299
00300
00301
00302
00303 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
00304 date.residualNanoSeconds = 0;
00305 date.unixDate.tm_sec = 0;
00306 date.unixDate.tm_min = 0;
00307 date.unixDate.tm_hour = 1;
00308 date.unixDate.tm_mday = 17;
00309 date.unixDate.tm_mon = 4;
00310 date.unixDate.tm_year = 94;
00311
00312 gpstime.gpsSeconds += 3600;
00313
00314 detector.frDetector.vertexLongitudeRadians = 0.;
00315 place_and_date.p_detector = &detector;
00316 place_and_date.p_date = &date;
00317
00318 LALGMST1(&status, &gmsthours, &date, MST_HRS);
00319 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
00320
00321 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00322 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00323 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00324 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00325 strcat(timestr, tmpstr+1);
00326
00327
00328 printf(" Time = %s\n", datestamp->data);
00329 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00330 printf(" expect: 16.63105328 = 16h 37m 51.7918s\n");
00331
00332 printf("\nUsing the GPStoGMST1() and GPStoLMST1() routines instead:\n");
00333 units_and_acc.units = MST_SEC;
00334 LALGPStoGMST1(&status, &gmstsecs, &gpstime, &units_and_acc);
00335 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00336 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00337 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00338 strcat(timestr, tmpstr+1);
00339
00340
00341 place_and_gps.p_detector = &detector;
00342 place_and_gps.p_gps = &gpstime;
00343 units_and_acc.units = MST_HRS;
00344 LALGPStoLMST1(&status, &lmsthours, &place_and_gps, &units_and_acc);
00345 printf(" Time = %s\n", datestamp->data);
00346 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00347 printf(" expect: 16.63105328 = 16h 37m 51.7918s\n");
00348 printf("lmsthours = %f\n", lmsthours);
00349
00350
00351
00352
00353
00354
00355
00356
00357 printf("\n* * * * * * * * * * * * * * * * * *\n\n");
00358 date.residualNanoSeconds = 744800000;
00359 date.unixDate.tm_sec = 46;
00360 date.unixDate.tm_min = 20;
00361 date.unixDate.tm_hour = 8;
00362 date.unixDate.tm_mday = 17;
00363 date.unixDate.tm_mon = 4;
00364 date.unixDate.tm_year = 94;
00365
00366 gpstime.gpsSeconds = 453168010;
00367 gpstime.gpsNanoSeconds = date.residualNanoSeconds;
00368
00369 detector.frDetector.vertexLongitudeRadians = 0.;
00370 place_and_date.p_detector = &detector;
00371 place_and_date.p_date = &date;
00372
00373 LALGMST1(&status, &gmsthours, &date, MST_HRS);
00374 LALLMST1(&status, &lmsthours, &place_and_date, MST_HRS);
00375
00376 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00377 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00378 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00379 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00380 strcat(timestr, tmpstr+1);
00381
00382
00383 printf(" Time = %s\n", datestamp->data);
00384 printf("gmsthours = %f = %s\n", gmsthours, timestr);
00385 printf(" expect: 0h = 00h 00m 00s \n");
00386 }
00387
00388 if (testid == 2)
00389 {
00390
00391 date.unixDate.tm_sec = 0;
00392 date.unixDate.tm_min = 0;
00393 date.unixDate.tm_hour = 0;
00394 date.unixDate.tm_year = 94;
00395
00396
00397 date.unixDate.tm_wday = 0;
00398 date.unixDate.tm_yday = 0;
00399 date.unixDate.tm_isdst = 0;
00400
00401 printf("\nGMST1 of 0h UT1 for 1994 (check against Almanac):\n");
00402 for (monthofyear = 0; monthofyear < 12; ++monthofyear)
00403 {
00404 date.unixDate.tm_mon = monthofyear;
00405
00406 for (dayofmonth = 1; dayofmonth < 32; ++dayofmonth)
00407 {
00408 date.unixDate.tm_mday = dayofmonth;
00409
00410 LALGMST1(&status, &gmstsecs, &date, MST_SEC);
00411 LALSecsToLALDate(&status, &mstdate, gmstsecs);
00412 strftime(timestr, 64, "%Hh %Mm %S", &(mstdate.unixDate));
00413 sprintf(tmpstr, "%fs", mstdate.residualNanoSeconds * 1.e-9);
00414 strcat(timestr, tmpstr+1);
00415 LALDateString(&status, datestamp, &date);
00416 printf("%s: %s\n", datestamp->data, timestr);
00417
00418
00419 if (monthofyear == 1)
00420 if (dayofmonth == 28)
00421 break;
00422
00423 if (monthofyear == 3 || monthofyear == 5 ||
00424 monthofyear == 8 || monthofyear == 10)
00425 if (dayofmonth == 30)
00426 break;
00427 }
00428 }
00429 }
00430
00431
00432
00433
00434 LALCHARDestroyVector(&status, &datestamp);
00435
00436 return(0);
00437 }