From 29fe6569c41de08163572567ac01988e210cb1cf Mon Sep 17 00:00:00 2001 From: Richard Senior Date: Tue, 26 Apr 2016 10:30:15 +0100 Subject: [PATCH] Fix incorrect QNH in spoken ATIS when using live weather fetch When using live weather fetch, the QNH should be obtained from environment/metar/pressure-inhg. See: http://sourceforge.net/p/flightgear/mailman/message/35037125 Add new method getQnhInHg to ATISInformationProvider and its implementations to avoid rounding errors converting from hPa back to inches in ATIS reports. The CurrentWeatherATISInformationProvider (used when live weather fetch is not in use) continues to use the property environment/pressure-sea-level-inhg. This produces the incorrect QNH at airports significantly above sea level but this needs fixing elsewhere to calculate the correct QNH. --- src/ATC/ATISEncoder.cxx | 4 ++-- src/ATC/ATISEncoder.hxx | 1 + src/ATC/CurrentWeatherATISInformationProvider.cxx | 7 +++++++ src/ATC/CurrentWeatherATISInformationProvider.hxx | 1 + src/ATC/MetarPropertiesATISInformationProvider.cxx | 8 ++++++-- src/ATC/MetarPropertiesATISInformationProvider.hxx | 1 + 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ATC/ATISEncoder.cxx b/src/ATC/ATISEncoder.cxx index 03f48e282..294bb8306 100644 --- a/src/ATC/ATISEncoder.cxx +++ b/src/ATC/ATISEncoder.cxx @@ -565,13 +565,13 @@ string ATISEncoder::getQnh( SGPropertyNode_ptr ) string ATISEncoder::getInhgInteger( SGPropertyNode_ptr ) { - double qnh = _atis->getQnh() * 100 / SG_INHG_TO_PA; + double qnh = _atis->getQnhInHg(); return getSpokenNumber( (int)qnh, true, 2 ); } string ATISEncoder::getInhgFraction( SGPropertyNode_ptr ) { - double qnh = _atis->getQnh() * 100 / SG_INHG_TO_PA; + double qnh = _atis->getQnhInHg(); int f = int(100 * (qnh - int(qnh)) + 0.5); return getSpokenNumber( f, true, 2 ); } diff --git a/src/ATC/ATISEncoder.hxx b/src/ATC/ATISEncoder.hxx index 57958a1a1..ee5089a0e 100644 --- a/src/ATC/ATISEncoder.hxx +++ b/src/ATC/ATISEncoder.hxx @@ -53,6 +53,7 @@ public: virtual int getWindSpeedKt() = 0; virtual int getGustsKt() = 0; virtual int getQnh() = 0; + virtual double getQnhInHg() = 0; virtual bool isCavok() = 0; virtual int getVisibilityMeters() = 0; virtual std::string getPhenomena() = 0; diff --git a/src/ATC/CurrentWeatherATISInformationProvider.cxx b/src/ATC/CurrentWeatherATISInformationProvider.cxx index b2c0ca629..a19bbe433 100644 --- a/src/ATC/CurrentWeatherATISInformationProvider.cxx +++ b/src/ATC/CurrentWeatherATISInformationProvider.cxx @@ -85,9 +85,16 @@ int CurrentWeatherATISInformationProvider::getGustsKt() int CurrentWeatherATISInformationProvider::getQnh() { + // TODO: Calculate QNH correctly from environment return roundToInt( _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue() * SG_INHG_TO_PA / 100 ); } +double CurrentWeatherATISInformationProvider::getQnhInHg() +{ + // TODO: Calculate QNH correctly from environment + return _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue(); +} + bool CurrentWeatherATISInformationProvider::isCavok() { return false; diff --git a/src/ATC/CurrentWeatherATISInformationProvider.hxx b/src/ATC/CurrentWeatherATISInformationProvider.hxx index 1c96bacec..2b679fe9b 100644 --- a/src/ATC/CurrentWeatherATISInformationProvider.hxx +++ b/src/ATC/CurrentWeatherATISInformationProvider.hxx @@ -41,6 +41,7 @@ protected: virtual int getWindSpeedKt(); virtual int getGustsKt(); virtual int getQnh(); + virtual double getQnhInHg(); virtual bool isCavok(); virtual int getVisibilityMeters(); virtual std::string getPhenomena(); diff --git a/src/ATC/MetarPropertiesATISInformationProvider.cxx b/src/ATC/MetarPropertiesATISInformationProvider.cxx index 7380ca93e..3dcb9a3b5 100644 --- a/src/ATC/MetarPropertiesATISInformationProvider.cxx +++ b/src/ATC/MetarPropertiesATISInformationProvider.cxx @@ -72,10 +72,14 @@ int MetarPropertiesATISInformationProvider::getGustsKt() return _metar->getIntValue( "gust-wind-speed-kt" ); } - int MetarPropertiesATISInformationProvider::getQnh() { - return _metar->getDoubleValue("pressure-sea-level-inhg") * SG_INHG_TO_PA / 100.0; + return _metar->getDoubleValue("pressure-inhg") * SG_INHG_TO_PA / 100.0; +} + +double MetarPropertiesATISInformationProvider::getQnhInHg() +{ + return _metar->getDoubleValue("pressure-inhg"); } bool MetarPropertiesATISInformationProvider::isCavok() diff --git a/src/ATC/MetarPropertiesATISInformationProvider.hxx b/src/ATC/MetarPropertiesATISInformationProvider.hxx index 151ded475..660a5814f 100644 --- a/src/ATC/MetarPropertiesATISInformationProvider.hxx +++ b/src/ATC/MetarPropertiesATISInformationProvider.hxx @@ -43,6 +43,7 @@ protected: virtual int getWindSpeedKt(); virtual int getGustsKt(); virtual int getQnh(); + virtual double getQnhInHg(); virtual bool isCavok(); virtual int getVisibilityMeters(); virtual std::string getPhenomena(); -- 2.39.5