This code had been written to assume current clock time. Added options

to allow specifying an alternate clock time.
This commit is contained in:
curt
2002-02-10 03:16:03 +00:00
parent 5b40eed554
commit 8c41081a5c
2 changed files with 24 additions and 9 deletions
+14 -5
View File
@@ -70,13 +70,18 @@ static const double J2000 = 2451545.0 - MJD0;
static const double SIDRATE = 0.9972695677;
SGTime::SGTime( double lon, double lat, const string& root )
SGTime::SGTime( double lon, double lat, const string& root, time_t init_time )
{
SG_LOG( SG_EVENT, SG_INFO, "Initializing Time" );
gst_diff = -9999.0;
cur_time = time(NULL);
if ( init_time ) {
cur_time = init_time;
} else {
cur_time = time(NULL);
}
cout << "Current greenwich mean time = " << asctime(gmtime(&cur_time))
<< endl;
cout << "Current local time = "
@@ -190,7 +195,7 @@ static double sidereal_course( time_t cur_time, struct tm *gmt, double lng )
// Update the time related variables
void SGTime::update( double lon, double lat, long int warp ) {
void SGTime::update( double lon, double lat, time_t ct, long int warp ) {
double gst_precise, gst_course;
#if defined(_MSC_VER) || defined(__MINGW32__)
@@ -201,7 +206,11 @@ void SGTime::update( double lon, double lat, long int warp ) {
// get current Unix calendar time (in seconds)
// warp += warp_delta;
cur_time = time(NULL) + warp;
if ( ct ) {
cur_time = ct + warp;
} else {
cur_time = time(NULL) + warp;
}
SG_LOG( SG_EVENT, SG_DEBUG,
" Current Unix calendar time = " << cur_time
<< " warp = " << warp );
@@ -359,7 +368,7 @@ double sgTimeCalcMJD(int mn, double dy, int yr) {
// return the current modified Julian date (number of days elapsed
// since 1900 jan 0.5), mjd.
double sgTimeCurrentMJD( long int warp ) {
double sgTimeCurrentMJD( time_t ct, long int warp ) {
#if defined(_MSC_VER) || defined(__MINGW32__)
struct tm m_gmt; // copy of system gmtime(&time_t) structure
+10 -4
View File
@@ -122,8 +122,10 @@ public:
* 0).
* @param lon current longitude
* @param lat current latitude
* @param root root path point to data file location (timezone, etc.) */
SGTime( double lon, double lat, const string& root );
* @param root root path point to data file location (timezone, etc.)
* @param init_time provide an initialization time, 0 means use
current clock time */
SGTime( double lon, double lat, const string& root, time_t init_time = 0 );
/**
* Create an instance given a data file path.
@@ -143,9 +145,11 @@ public:
* every frame.
* @param lon current longitude
* @param lat current latitude
* @param ct specify a unix time, otherwise specify 0 to use current
clock time
* @param warp an optional time offset specified in seconds. This
* allows us to advance or rewind "time" if we choose to. */
void update( double lon, double lat, long int warp = 0 );
void update( double lon, double lat, time_t ct = 0, long int warp = 0 );
/**
* Given lon/lat, update timezone information and local_offset
@@ -235,10 +239,12 @@ double sgTimeCalcMJD(int mn, double dy, int yr);
* \relates SGTime
* Given an optional offset from current time calculate the current
* modified julian date.
* @param ct specify a unix time, otherwise specify 0 to use current
clock time
* @param warp number of seconds to offset from current time (0 if no offset)
* @return current modified Julian date (number of days elapsed
* since 1900 jan 0.5), mjd. */
double sgTimeCurrentMJD( long int warp );
double sgTimeCurrentMJD( time_t ct = 0, long int warp = 0 );
/**
* \relates SGTime