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 #include <time.h>
00024
00025 #include <lal/LALStdlib.h>
00026 #include <lal/Date.h>
00027
00028 INT4 lalDebugLevel = 0;
00029
00030 NRCSID (LALTESTLEAPSECSC, "$Id: TestLeapSecs.c,v 1.4 2007/06/08 14:41:43 bema Exp $");
00031
00032 typedef struct gps_leap_sec {
00033 time_t gps;
00034 INT4 tai_utc;
00035 } gps_leap_sec_t;
00036
00037 int main(int argc, char *argv[])
00038 {
00039 static LALStatus status;
00040 static const gps_leap_sec_t leapsec_data[] =
00041 {
00042 {0, 19},
00043 {46828801, 20},
00044 {78364802, 21},
00045 {109900803, 22},
00046 {173059204, 23},
00047 {252028805, 24},
00048 {315187206, 25},
00049 {346723207, 26},
00050 {393984008, 27},
00051 {425520009, 28},
00052 {457056010, 29},
00053 {504489611, 30},
00054 {551750412, 31},
00055 {599184013, 32},
00056 };
00057 static const INT4 num_data = sizeof(leapsec_data)/sizeof(gps_leap_sec_t);
00058 LIGOTimeGPS gpsTime = {0, 0};
00059 INT4 gps_utc = 0;
00060 INT4 tai_utc = 0;
00061 INT4 i = 0;
00062 LALLeapSecFormatAndAcc formatAndAcc = {LALLEAPSEC_GPSUTC, LALLEAPSEC_STRICT};
00063
00064
00065 if (argc > 1)
00066 lalDebugLevel = atoi(argv[1]);
00067
00068
00069
00070
00071
00072
00073
00074 if (lalDebugLevel > 0)
00075 printf("TestLeapSecs: TESTING GPS-UTC\n");
00076
00077 gpsTime.gpsSeconds = 0;
00078 LALLeapSecs(&status, &gps_utc, &gpsTime, &formatAndAcc);
00079
00080 if (lalDebugLevel > 0)
00081 printf("\tGPS = %9d; GPS-UTC = %d\n", gpsTime.gpsSeconds,
00082 gps_utc);
00083
00084 if (status.statusCode && lalDebugLevel > 0)
00085 {
00086 fprintf(stderr, "TestLeapSecs: LALLeapSecs() failed, line %i, %s\n",
00087 __LINE__, LALTESTLEAPSECSC);
00088 REPORTSTATUS(&status);
00089 return status.statusCode;
00090 }
00091
00092 if (gps_utc != 0)
00093 {
00094 if (lalDebugLevel > 0)
00095 {
00096 fprintf(stderr,
00097 "TestLeapSecs: LALLeapSecs returned wrong value: expected 0, got %d; i = %d\n",
00098 gps_utc, i);
00099 REPORTSTATUS(&status);
00100 }
00101 return 1;
00102 }
00103
00104 gpsTime.gpsSeconds = 1;
00105 LALLeapSecs(&status, &gps_utc, &gpsTime, &formatAndAcc);
00106 if (lalDebugLevel > 0)
00107 printf("\tGPS = %9d; GPS-UTC = %d\n", gpsTime.gpsSeconds,
00108 gps_utc);
00109
00110 if (status.statusCode && lalDebugLevel > 0)
00111 {
00112 fprintf(stderr, "TestLeapSecs: LALLeapSecs() failed, line %i, %s\n",
00113 __LINE__, LALTESTLEAPSECSC);
00114 REPORTSTATUS(&status);
00115 return status.statusCode;
00116 }
00117
00118 if (gps_utc != 0)
00119 {
00120 if (lalDebugLevel > 0)
00121 {
00122 fprintf(stderr,
00123 "TestLeapSecs: LALLeapSecs returned wrong value: expected 0, got %d; i = %d\n",
00124 gps_utc, i);
00125 REPORTSTATUS(&status);
00126 }
00127 return 1;
00128 }
00129
00130
00131
00132 for (i = 1; i < num_data; ++i)
00133 {
00134 if (lalDebugLevel > 2)
00135 {
00136 printf("TestLeapSecs: BEFORE LEAP SECOND ADDED\n");
00137 }
00138
00139 gpsTime.gpsSeconds = leapsec_data[i].gps - 1;
00140 LALLeapSecs(&status, &gps_utc, &gpsTime, &formatAndAcc);
00141 if (lalDebugLevel > 0)
00142 printf("\tGPS = %9d; GPS-UTC = %d\n", gpsTime.gpsSeconds,
00143 gps_utc);
00144
00145 if (status.statusCode && lalDebugLevel > 0)
00146 {
00147 fprintf(stderr, "TestLeapSecs: LALLeapSecs() failed, line %i, %s\n",
00148 __LINE__, LALTESTLEAPSECSC);
00149 REPORTSTATUS(&status);
00150 return status.statusCode;
00151 }
00152
00153 if (gps_utc != leapsec_data[i-1].tai_utc - 19)
00154 {
00155 if (lalDebugLevel > 0)
00156 {
00157 fprintf(stderr,
00158 "TestLeapSecs: LALLeapSecs returned wrong value: expected %d, got %d; i = %d\n",
00159 leapsec_data[i-1].tai_utc - 19, gps_utc, i);
00160 REPORTSTATUS(&status);
00161 }
00162 return 1;
00163 }
00164
00165 if (lalDebugLevel > 2)
00166 {
00167 printf("TestLeapSecs: AFTER LEAP SECOND ADDED\n");
00168 }
00169
00170 gpsTime.gpsSeconds += 2;
00171 LALLeapSecs(&status, &gps_utc, &gpsTime, &formatAndAcc);
00172 if (lalDebugLevel > 0)
00173 printf("\tGPS = %9d; GPS-UTC = %d\n\n", gpsTime.gpsSeconds,
00174 gps_utc);
00175
00176 if (status.statusCode && lalDebugLevel > 0)
00177 {
00178 fprintf(stderr, "TestLeapSecs: LALLeapSecs() failed, line %i, %s\n",
00179 __LINE__, LALTESTLEAPSECSC);
00180 REPORTSTATUS(&status);
00181 return status.statusCode;
00182 }
00183
00184 if (gps_utc != leapsec_data[i].tai_utc - 19)
00185 {
00186 if (lalDebugLevel > 0)
00187 {
00188 fprintf(stderr,
00189 "TestLeapSecs: LALLeapSecs returned wrong value: expected %d, got %d; i = %d\n",
00190 leapsec_data[i-1].tai_utc - 19, gps_utc, i);
00191 REPORTSTATUS(&status);
00192 }
00193 return 1;
00194 }
00195 }
00196
00197
00198 formatAndAcc.accuracy = LALLEAPSEC_LOOSE;
00199 gpsTime.gpsSeconds = 701654353 + 4;
00200
00201 LALLeapSecs(&status, &gps_utc, &gpsTime, &formatAndAcc);
00202 if (lalDebugLevel > 0)
00203 printf("\tGPS = %9d; GPS-UTC = %d\n", gpsTime.gpsSeconds,
00204 gps_utc);
00205
00206 if (status.statusCode && lalDebugLevel > 0)
00207 {
00208 fprintf(stderr, "TestLeapSecs: LALLeapSecs() failed, line %i, %s\n",
00209 __LINE__, LALTESTLEAPSECSC);
00210 REPORTSTATUS(&status);
00211 return status.statusCode;
00212 }
00213
00214 if (gps_utc != 13)
00215 {
00216 if (lalDebugLevel > 0)
00217 {
00218 fprintf(stderr,
00219 "TestLeapSecs: LALLeapSecs returned wrong value: expected 13, got %d; i = %d\n",
00220 gps_utc, i);
00221 REPORTSTATUS(&status);
00222 }
00223 return 1;
00224 }
00225
00226 if (lalDebugLevel > 0)
00227 printf("\nTestLeapSecs: TESTING TAI-UTC\n\n");
00228
00229
00230
00231
00232 formatAndAcc.format = LALLEAPSEC_TAIUTC;
00233
00234 for (i = 1; i < num_data; ++i)
00235 {
00236 if (lalDebugLevel > 2)
00237 {
00238 printf("TestLeapSecs: BEFORE LEAP SECOND ADDED\n");
00239 }
00240
00241 gpsTime.gpsSeconds = leapsec_data[i].gps - 1;
00242 LALLeapSecs(&status, &tai_utc, &gpsTime, &formatAndAcc);
00243 if (lalDebugLevel > 0)
00244 printf("\tGPS = %9d; TAI-UTC = %d\n", gpsTime.gpsSeconds,
00245 tai_utc);
00246
00247 if (status.statusCode && lalDebugLevel > 0)
00248 {
00249 fprintf(stderr, "TestLeapSecs: LALLeapSecs() failed, line %i, %s\n",
00250 __LINE__, LALTESTLEAPSECSC);
00251 REPORTSTATUS(&status);
00252 return status.statusCode;
00253 }
00254
00255 if (tai_utc != leapsec_data[i-1].tai_utc)
00256 {
00257 if (lalDebugLevel > 0)
00258 {
00259 fprintf(stderr,
00260 "TestLeapSecs: LALLeapSecs returned wrong value: expected %d, got %d; i = %d\n",
00261 leapsec_data[i-1].tai_utc, tai_utc, i);
00262 REPORTSTATUS(&status);
00263 }
00264 return 1;
00265 }
00266
00267 if (lalDebugLevel > 2)
00268 {
00269 printf("TestLeapSecs: AFTER LEAP SECOND ADDED\n");
00270 }
00271
00272 gpsTime.gpsSeconds += 2;
00273 LALLeapSecs(&status, &tai_utc, &gpsTime, &formatAndAcc);
00274 if (lalDebugLevel > 0)
00275 printf("\tGPS = %9d; TAI-UTC = %d\n\n", gpsTime.gpsSeconds,
00276 tai_utc);
00277
00278 if (status.statusCode && lalDebugLevel > 0)
00279 {
00280 fprintf(stderr, "TestLeapSecs: LALLeapSecs() failed, line %i, %s\n",
00281 __LINE__, LALTESTLEAPSECSC);
00282 REPORTSTATUS(&status);
00283 return status.statusCode;
00284 }
00285
00286 if (tai_utc != leapsec_data[i].tai_utc)
00287 {
00288 if (lalDebugLevel > 0)
00289 {
00290 fprintf(stderr,
00291 "TestLeapSecs: LALLeapSecs returned wrong value: expected %d, got %d; i = %d\n",
00292 leapsec_data[i-1].tai_utc, tai_utc, i);
00293 REPORTSTATUS(&status);
00294 }
00295 return 1;
00296 }
00297 }
00298
00299 return 0;
00300 }