The Time computation software includes a number of different representations of time, the most useful of which I have found to be the following:
1.0 GPST -- GPS Time
GPS, or "Global Positioning System" time was created by the Department of Defense for the needs of their satellite based navigation system which is fast becoming a standardized, world wide navigation service for all civil aerospace users as well as a military system. GPS time is atomic time and is measured from midnight, January 5, 1980, and it is for all practical purposes, uniform. GPS time can be represented as the number of seconds since January 5, 1980, but for convenience it is usually expressed as an integer number of weeks since the epoch, plus the number of seconds of the current GPS week. The GPS week begins at approximately midnight p.m. Saturday. There are 604800.0 seconds in a week.
The module "subtime.h" declares the class GPST (short for GPS Time) as follows:
//////////////////////////////////////////// Global Positioning Satellite Time// Time in weeks/sec since GPS epoch//////////////////////////////////////////class GPST : public JD{private: int week; // number of weeks since GPS epoch#ifdef USE_LONG_DOUBLE long double seconds; // number of seconds in week#else double seconds; // number of seconds in week#endifpublic: GPST() {}; #ifdef USE_LONG_DOUBLE GPST(int wk, long double sc) {set(wk, sc);}; void set(int wk, long double sc); void get(int *wk, long double *sc);#else GPST(int wk, double sc) {set(wk, sc);}; void set(int wk, double sc); void get(int *wk, double *sc);#endif void print();#ifdef USE_LONG_DOUBLE long double operator-(GPST time); GPST operator+(long double time); GPST operator-(long double time);#else double operator-(GPST time); GPST operator+(double time); GPST operator-(double time);#endif int operator==(GPST time); int operator!=(GPST time); int operator<(GPST time); int operator>(GPST time); int operator<=(GPST time); int operator>=(GPST time);};
Notice that the internal representation of GPS time is private. Users should access GPS time through the "set" and "get" functions. There are also functions for performing arithmetic with GPS time, such as addition of an interval in seconds to a GPS time to give a later (earlier for negative intervals) GPS time, comparing two GPS times, and computing the interval between two GPS times. Note that the difference between two GPS times is an interval, therefore you can subtract one GPS time from another. However, you cannot add two GPS times.
2.0 STST -- Shuttle Time
Shuttle time is based on Coordinated Universal Time (UTC) because it is measured with respect to the UTC epoch of midnight a.m. December 31 of the current year. Notice that the choice of epoch causes January 1 to be "day 1" rather than "day 0" of the year. This was done for convenience and in hopes of avoiding mistakes. One may occasionally see a written reference to "January 0" which actually means December 31. The time software we are presenting here creates an unambiguous time by using the calendar year and number of seconds of year to specify an instant. The subtime.h module declares STST or shuttle time as follows:
//////////////////////////////////////////// Shuttle Time Base//////////////////////////////////////////class STST : public JD{private: int year; // year of current mission start#ifdef USE_LONG_DOUBLE long double seconds; // seconds of year#else double seconds; // seconds of year#endifpublic: STST () {}; #ifdef USE_LONG_DOUBLE STST (int yr, long double sc)#else STST (int yr, double sc)#endif { set( yr, sc ); };#ifdef USE_LONG_DOUBLE void set(int yr, long double sc); void get(int *yr, long double *sc);#else void set(int yr, double sc); void get(int *yr, double *sc);#endif void print();};#endif
3.1 utc_to_gps
Here is a simple application that accepts a UTC time and prints out the date and time in several different formats, including GPS time and shuttle time.
In order to use the time functions, you must include the modules time.cpp,subtime.cpp, and julian_date.cpp in your project. You should also obtain a copy of the file "leapsec.dat" which is maintained online by the U.S. NavalObservatory (ftp://maia.usno.navy.mil/ser7/leapsec.dat).
#include "time.h"int main(){ Time time; GPST gps; STST sts; UTC utc; int month,year,day; int hour,minute; double second; double soy; printf("YYYY/MM/DD HH:MM:SS.SSSHere is a sample run using the application:
"); scanf( "%d/%d/%d %d:%d:%lf",&year,&month,&day,&hour,&minute,&second); utc.set(year,month,day,hour,minute,second); time.convert(&utc,&gps); time.convert(&gps,&sts); utc.print(); printf("JD: %f
",utc.julian_day); sts.print(); sts.get(&year,&soy); day = (int)(soy/86400.0); printf("GMT: %04d/%03d:%02d:%02d:%06.3f
",year,day,hour,minute,second); gps.print(); return 1;}
C:>utc_to_gpsYYYY/MM/DD HH:MM:SS.SSS2000/02/21 13:51:00utc time: 2000/2/21 13:51:00.000JD: 2451596.077083shuttle time: 2000 4542660.000GMT: 2000/052:13:51:00.000gps time: 1050 136273.000C:>
For convenience we use the terms UTC, GMT, and GPS to identify three different formats ofexpressing time, although in fact they are different names for the same thing.
UTC: YYYY/MM/DD HH:MM:SS.SSSGMT: YYYY/DDD:HH:MM:SS.SSSGPS: WWWW SSSSSS.SSSIn "UTC" time, YYYY = calendar year, MM = month, and DD = day of the month, HH = hour,MM = minute and SS.SSS = seconds of the minute.
In "GMT" time, YYYY = calendar year, DDD = day of the year, HH=hour, MM=minute, and SS.SSS=second.
In "GPS" time, WWWW=GPS week and SSSSSS.SSS = seconds of the GPS week (since midnight a.m. Sunday).
3.2 gmt_to_gps
Here is a useful utility for converting gmt time expressed in the following format:
YYYY:DDD:HH:MM:SS.SSSS
into GPS time.
//---------------------------------------------------------------------------//$Id: gmt_to_gps.cxx,v 1.1 1998/02/26 19:58:08 semar Exp semar $//// Utility to convert GMT to gps time.// Interactive.//#include "time.h"int main(){ Time time; GPST gps; STST sts; UTC utc; int year,day; int hour,minute; double second; double soy; printf("YYYY:DDD:HH:MM:SS.SSS
"); scanf( "%d:%d:%d:%d:%lf",&year,&day,&hour,&minute,&second); soy = second + 60.0*(float)minute+3600.0*(float)hour+ 86400.0*(float)day; sts.set(year,soy); time.convert(&sts,&gps); time.convert(&gps,&utc); printf("JD: %f
",utc.julian_day); gps.print(); utc.print(); return 1;}
Here is a sample run:
C:Program FilesBorlandCBuilder3GaiaDOS>YYYY:DDD:HH:MM:SS.SSS1999:349:00:00:00.0JD: 2451527.500000gps time: 1040 259213.000utc time: 1999/12/15 0:00:00.000C:Program FilesBorlandCBuilder3GaiaDOS>
3.3 gps_to_gmt
Rounding out the set of time utilities is gps_to_gmt which accepts as input a GPS time and prints it out in the other formats.
#include "time.h"//---------------------------------------------------------------------------int main(){ Time tyme; GPST gps; STST sts; UTC utc; int year,day,dom; int week,month; int hour,minute; double second; double soy; printf("Enter week/second "); scanf("%d/%lf",&week,&second); gps.set(week,second); tyme.convert(&gps,&sts); tyme.convert(&gps,&utc); gps.print(); sts.print(); utc.print(); sts.get(&year,&soy); day = (int)(soy/86400.0); utc.get(&year,&month,&dom,&hour,&minute,&second); printf("JD: %f
",utc.julian_day); printf("GMT: %04d/%03d:%02d:%02d:%06.3f
",year,day,hour,minute,second); return 0;}
Here is a sample run of this utility:
C:Program FilesBorlandCBuilder3GaiaDOS>Enter week/second 1040/259213gps time: 1040 259213.000shuttle time: 1999 30153600.000utc time: 1999/12/15 0:00:00.000JD: 2451527.500000GMT: 1999/349:00:00:00.000C:Program FilesBorlandCBuilder3GaiaDOS>There you have it.
To download the source code for the time modules, click on the names of the modules.
time.h
time.cpp
subtime.h
subtime.cpp
julian_date.h
julian_date.cpp
leapsec.dat
Here is a zip file with all of the source code and the DOS executables for the time utilities: