# include <config.h>
#endif
+#include <cstring> // for strlen
+
#include "metarproperties.hxx"
#include "fgmetar.hxx"
#include "environment.hxx"
// calculation of magnetic variation is expensive. Cache the position
// and perform this calculation only if it has changed
if( _lon != lon || _lat != lat || _alt != alt ) {
- SG_LOG(SG_ALL, SG_DEBUG, "Recalculating magvar for lon=" << lon << ", lat=" << lat << ", alt=" << alt );
+ SG_LOG(SG_ENVIRONMENT, SG_DEBUG, "Recalculating magvar for lon=" << lon << ", lat=" << lat << ", alt=" << alt );
_lon = lon;
_lat = lat;
_alt = alt;
- lon *= SGD_DEGREES_TO_RADIANS;
- lat *= SGD_DEGREES_TO_RADIANS;
- alt *= SG_FEET_TO_METER;
- _time.update( lon, lat, 0, 0 );
+ SGGeod location(SGGeod::fromDegFt(lon, lat, alt));
+ _time.update( location, 0, 0 );
update( lon, lat, alt, _time.getJD() );
}
}
_hail(0.0),
_snow(0.0),
_snow_cover(false),
+ _day(0),
+ _hour(0),
+ _minute(0),
+ _cavok(false),
_magneticVariation(new MagneticVariation())
{
// Hack to avoid static initialization order problems on OSX
- if( coverage_string.size() == 0 ) {
+ if( coverage_string.empty() ) {
coverage_string.push_back(SGCloudLayer::SG_CLOUD_CLEAR_STRING);
coverage_string.push_back(SGCloudLayer::SG_CLOUD_FEW_STRING);
coverage_string.push_back(SGCloudLayer::SG_CLOUD_SCATTERED_STRING);
_tiedProperties.Tie("hail-norm", &_hail );
_tiedProperties.Tie("snow-norm", &_snow);
_tiedProperties.Tie("snow-cover", &_snow_cover );
+ _tiedProperties.Tie("day", &_day );
+ _tiedProperties.Tie("hour", &_hour );
+ _tiedProperties.Tie("minute", &_minute );
_tiedProperties.Tie("decoded", this, &MetarProperties::get_decoded );
+ _tiedProperties.Tie("cavok", &_cavok );
}
MetarProperties::~MetarProperties()
static const double thickness_value[] = { 0, 65, 600, 750, 1000 };
-void MetarProperties::set_metar( const char * metar )
+const char* MetarProperties::get_metar() const
+{
+ if (!_metar) return "";
+ return _metar->getData();
+}
+
+void MetarProperties::set_metar( const char * metarString )
{
- _metar = metar;
-
SGSharedPtr<FGMetar> m;
+ if ((metarString == NULL) || (strlen(metarString) == 0)) {
+ setMetar(m);
+ return;
+ }
+
try {
- m = new FGMetar( _metar );
+ m = new FGMetar( metarString );
}
catch( sg_io_exception ) {
- SG_LOG( SG_GENERAL, SG_WARN, "Can't parse metar: " << _metar );
+ SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << metarString );
_metarValidNode->setBoolValue(false);
return;
}
-
+
+ setMetar(m);
+}
+
+void MetarProperties::setMetar( SGSharedPtr<FGMetar> m )
+{
+ _metar = m;
_decoded.clear();
+ if (!m) {
+ return;
+ }
+
const vector<string> weather = m->getWeather();
- for( vector<string>::const_iterator it = weather.begin(); it != weather.end(); it++ ) {
+ for( vector<string>::const_iterator it = weather.begin(); it != weather.end(); ++it ) {
if( false == _decoded.empty() ) _decoded.append(", ");
_decoded.append(*it);
}
}
}
- vector<SGMetarCloud> cv = m->getClouds();
- vector<SGMetarCloud>::const_iterator cloud, cloud_end = cv.end();
-
{
static const char * LAYER = "layer";
SGPropertyNode_ptr cloudsNode = _rootNode->getNode("clouds", true );
_hail = m->getHail();
_snow = m->getSnow();
_snow_cover = m->getSnowCover();
+ _day = m->getDay();
+ _hour = m->getHour();
+ _minute = m->getMinute();
+ _cavok = m->getCAVOK();
_metarValidNode->setBoolValue(true);
}