+ return lstTmp;
+}
+
+
+// Update the time related variables
+void SGTime::update( double lon_rad, double lat_rad,
+ time_t ct, long int warp )
+{
+ double gst_precise, gst_course;
+
+
+ tm * gmt = &m_gmt;
+
+
+ SG_LOG( SG_EVENT, SG_DEBUG, "Updating time" );
+
+ // get current Unix calendar time (in seconds)
+ // warp += warp_delta;
+ 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 );
+
+ // get GMT break down for current time
+
+ memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
+ SG_LOG( SG_EVENT, SG_DEBUG,
+ " Current GMT = " << gmt->tm_mon+1 << "/"
+ << gmt->tm_mday << "/" << (1900 + gmt->tm_year) << " "
+ << gmt->tm_hour << ":" << gmt->tm_min << ":"
+ << gmt->tm_sec );
+
+ // calculate modified Julian date starting with current
+ mjd = sgTimeCurrentMJD( ct, warp );
+
+ // add in partial day
+ mjd += (gmt->tm_hour / 24.0) + (gmt->tm_min / (24.0 * 60.0)) +
+ (gmt->tm_sec / (24.0 * 60.0 * 60.0));
+
+ // convert "back" to Julian date + partial day (as a fraction of one)
+ jd = mjd + MJD0;
+ SG_LOG( SG_EVENT, SG_DEBUG, " Current Julian Date = " << jd );
+
+ // printf(" Current Longitude = %.3f\n", FG_Longitude * SGD_RADIANS_TO_DEGREES);
+
+ // Calculate local side real time
+ if ( gst_diff < -100.0 ) {
+ // first time through do the expensive calculation & cheap
+ // calculation to get the difference.
+ SG_LOG( SG_EVENT, SG_INFO, " First time, doing precise gst" );
+ gst_precise = gst = sidereal_precise( mjd, 0.00 );
+ gst_course = sidereal_course( cur_time, gmt, 0.00 );
+
+ gst_diff = gst_precise - gst_course;
+
+ lst = sidereal_course( cur_time, gmt,
+ -(lon_rad * SGD_RADIANS_TO_DEGREES) ) + gst_diff;
+ } else {
+ // course + difference should drift off very slowly
+ gst = sidereal_course( cur_time, gmt, 0.00 ) + gst_diff;
+ lst = sidereal_course( cur_time, gmt,
+ -(lon_rad * SGD_RADIANS_TO_DEGREES) ) + gst_diff;
+ }
+
+ SG_LOG( SG_EVENT, SG_DEBUG,
+ " Current lon=0.00 Sidereal Time = " << gst );
+ SG_LOG( SG_EVENT, SG_DEBUG,
+ " Current LOCAL Sidereal Time = " << lst << " ("
+ << sidereal_precise( mjd, -(lon_rad * SGD_RADIANS_TO_DEGREES) )
+ << ") (diff = " << gst_diff << ")" );
+}
+
+
+// Given lon/lat, update timezone information and local_offset
+void SGTime::updateLocal( double lon_rad, double lat_rad, const string& root ) {
+ // sanity checking
+ if ( lon_rad < -SGD_PI || lon_rad> SGD_PI ) {
+ // not within -180 ... 180
+ lon_rad = 0.0;
+ }
+ if ( lat_rad < -SGD_PI_2 || lat_rad > SGD_PI_2 ) {
+ // not within -90 ... 90
+ lat_rad = 0.0;
+ }
+ if ( lon_rad != lon_rad ) {
+ // only true if lon_rad == nan
+ SG_LOG( SG_EVENT, SG_ALERT,
+ " Detected lon_rad == nan, resetting to 0.0" );
+ lon_rad = 0.0;
+ }
+ if ( lat_rad != lat_rad ) {
+ // only true if lat_rad == nan
+ SG_LOG( SG_EVENT, SG_ALERT,
+ " Detected lat_rad == nan, resetting to 0.0" );
+ lat_rad = 0.0;
+ }
+ time_t currGMT;
+ time_t aircraftLocalTime;
+ SGGeoCoord location( SGD_RADIANS_TO_DEGREES * lat_rad,
+ SGD_RADIANS_TO_DEGREES * lon_rad );
+ SGGeoCoord* nearestTz = tzContainer->getNearest(location);
+ SGPath zone( root );
+ zone.append ( nearestTz->getDescription() );
+ zonename = zone.str();
+
+ //Avoid troubles when zone.tab hasn't got the right line endings
+ if (zonename[zonename.size()-1] == '\r')
+ {
+ zonename[zonename.size()-1]=0;
+ zone.set( zonename );
+ }
+
+ currGMT = sgTimeGetGMT( gmtime(&cur_time) );
+ aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zone.c_str())) );
+ local_offset = aircraftLocalTime - currGMT;
+ // cout << "Using " << local_offset << " as local time offset Timezone is "
+ // << zonename << endl;