# include <stdlib.h>
#endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
+#endif
#ifdef HAVE_SYS_TIMEB_H
# include <sys/timeb.h> // for ftime() and struct timeb
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h> // for gettimeofday()
#endif
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
-#endif
#include <math.h> // for NAN
static const double SIDRATE = 0.9972695677;
-SGTime::SGTime( double lon, double lat, const string& root )
+void SGTime::init( 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 = "
}
}
+SGTime::SGTime( double lon, double lat, const string& root, time_t init_time )
+{
+ init( lon, lat, root, init_time );
+}
+
SGTime::SGTime( const string& root ) {
- SGTime( 0.0, 0.0, root );
+ init( 0.0, 0.0, root, 0 );
}
SGTime::SGTime() {
- SGTime( 0.0, 0.0, "" );
+ init( 0.0, 0.0, "", 0 );
}
if ( zonename != NULL ) {
char *tmp = zonename;
zonename = NULL;
- delete tmp;
+ free(tmp);
}
}
// return a courser but cheaper estimate of sidereal time
-static double sidereal_course( time_t cur_time, struct tm *gmt, double lng )
+static double sidereal_course( time_t cur_time, const struct tm *gmt, double lng )
{
time_t start_gmt, now;
double diff, part, days, hours, lstTmp;
// 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__)
// 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 );
<< gmt->tm_sec );
// calculate modified Julian date starting with current
- mjd = sgTimeCurrentMJD( warp );
+ mjd = sgTimeCurrentMJD( ct, warp );
// add in partial day
mjd += (gmt->tm_hour / 24.0) + (gmt->tm_min / (24.0 * 60.0)) +
if ( zonename ) {
char *ptr = zonename;
zonename = NULL;
- delete ptr;
+ free(ptr);
}
zonename = strdup( zone.c_str() );
// 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
+ struct tm *gmt = &m_gmt;
#else
struct tm *gmt;
#endif
-#if defined(_MSC_VER) || defined(__MINGW32__)
- tm * gmt = &m_gmt;
-#endif
-
// get current Unix calendar time (in seconds)
// warp += warp_delta;
- time_t cur_time = time(NULL) + warp;
+ time_t cur_time;
+ 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 );