-void SGTime::updateLocal( double lon, double lat, const string& root )
-{
- time_t currGMT;
- time_t aircraftLocalTime;
- GeoCoord location( RAD_TO_DEG * lat, RAD_TO_DEG * lon );
- GeoCoord* nearestTz = tzContainer->getNearest(location);
- FGPath zone( root );
- zone.append ( nearestTz->getDescription() );
- if ( zonename ) {
- delete zonename;
- }
- zonename = strdup( zone.c_str() );
- 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;
+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;
+ SGGeod location(SGGeod::fromRad(lon_rad, lat_rad));
+ SGTimeZone* 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;