time calculations for an alternate calendar time (i.e. if the application
is being driven from an external source of data.)
Fix a bug in sg_binobj.cxx which disrupted the 'broken down time' globally
for the entire application.
// read creation time
time_t calendar_time;
sgReadLong( fp, &calendar_time );
// read creation time
time_t calendar_time;
sgReadLong( fp, &calendar_time );
+
+#if 0
+ // The following code has a global effect on the host application
+ // and can screws up the time elsewhere. It should be avoided
+ // unless you need this for debugging in which case you should
+ // disable it again once the debugging task is finished.
struct tm *local_tm;
local_tm = localtime( &calendar_time );
char time_str[256];
strftime( time_str, 256, "%a %b %d %H:%M:%S %Z %Y", local_tm);
struct tm *local_tm;
local_tm = localtime( &calendar_time );
char time_str[256];
strftime( time_str, 256, "%a %b %d %H:%M:%S %Z %Y", local_tm);
- // cout << "File created on " << time_str << endl;
+ cout << "File created on " << time_str << endl;
+#endif
// read number of top level objects
short nobjects;
// read number of top level objects
short nobjects;
static const double SIDRATE = 0.9972695677;
static const double SIDRATE = 0.9972695677;
-SGTime::SGTime( double lon, double lat, const string& root, time_t init_time )
+void SGTime::init( double lon, double lat,
+ const string& root, time_t init_time )
{
SG_LOG( SG_EVENT, SG_INFO, "Initializing Time" );
{
SG_LOG( SG_EVENT, SG_INFO, "Initializing 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::SGTime( const string& root ) {
- SGTime( 0.0, 0.0, root );
+ init( 0.0, 0.0, root, 0 );
- SGTime( 0.0, 0.0, "" );
+ init( 0.0, 0.0, "", 0 );
// return a courser but cheaper estimate of sidereal time
// 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;
{
time_t start_gmt, now;
double diff, part, days, hours, lstTmp;
<< gmt->tm_sec );
// calculate modified Julian date starting with current
<< 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)) +
// add in partial day
mjd += (gmt->tm_hour / 24.0) + (gmt->tm_min / (24.0 * 60.0)) +
// get current Unix calendar time (in seconds)
// warp += warp_delta;
// 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 );
SG_LOG( SG_EVENT, SG_DEBUG,
" Current Unix calendar time = " << cur_time
<< " warp = " << warp );
* @param root root path point to data file location (timezone, etc.)
* @param init_time provide an initialization time, 0 means use
current clock time */
* @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 );
+ SGTime( double lon, double lat, const string& root, time_t init_time /* = 0 */ );
/**
* Create an instance given a data file path.
/**
* Create an instance given a data file path.
/** Destructor */
~SGTime();
/** Destructor */
~SGTime();
+ /** init common constructor code */
+ void init( double lon, double lat, const string& root, time_t init_time /* = 0 */ );
+
/**
* Update the time related variables.
* The update() method requires you to pass in your position and
/**
* Update the time related variables.
* The update() method requires you to pass in your position and
clock time
* @param warp an optional time offset specified in seconds. This
* allows us to advance or rewind "time" if we choose to. */
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, time_t ct = 0, 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
/**
* Given lon/lat, update timezone information and local_offset
* @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. */
* @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( time_t ct = 0, long int warp = 0 );
+double sgTimeCurrentMJD( time_t ct /* = 0 */, long int warp /* = 0 */ );