#include <stdlib.h>
#include <algorithm>
+#include <simgear/structure/commands.hxx>
#include <simgear/structure/exception.hxx>
+#include <Airports/simple.hxx>
#include <Main/fg_props.hxx>
#include <Main/util.hxx>
}
+// use a "command" to set station temp at station elevation
+static void set_temp_at_altitude( float temp_degc, float altitude_ft ) {
+ SGPropertyNode args;
+ SGPropertyNode *node = args.getNode("temp-degc", 0, true);
+ node->setFloatValue( temp_degc );
+ node = args.getNode("altitude-ft", 0, true);
+ node->setFloatValue( altitude_ft );
+ globals->get_commands()->execute("set-outside-air-temp-degc", &args);
+}
+
+
+static void set_dewpoint_at_altitude( float dewpoint_degc, float altitude_ft ) {
+ SGPropertyNode args;
+ SGPropertyNode *node = args.getNode("dewpoint-degc", 0, true);
+ node->setFloatValue( dewpoint_degc );
+ node = args.getNode("altitude-ft", 0, true);
+ node->setFloatValue( altitude_ft );
+ globals->get_commands()->execute("set-dewpoint-temp-degc", &args);
+}
+
+
void
FGMetarEnvironmentCtrl::init ()
{
fgDefaultWeatherValue( "visibility-m",
fgGetDouble("/environment/metar/min-visibility-m") );
-
- // FIXME: this isn't the correct place in the property tree to set
- // the weather and it doesn't account for weather station
- // elevation.
- fgSetDouble("/environment/temperature-degc",
- fgGetDouble("/environment/metar/temperature-degc"));
- fgSetDouble("/environment/dewpoint-degc",
- fgGetDouble("/environment/metar/dewpoint-degc"));
-
+ set_temp_at_altitude( fgGetDouble("/environment/metar/temperature-degc"),
+ station_elevation_ft );
+ set_dewpoint_at_altitude( fgGetDouble("/environment/metar/dewpoint-degc"),
+ station_elevation_ft );
fgDefaultWeatherValue( "pressure-sea-level-inhg",
fgGetDouble("/environment/metar/pressure-inhg") );
fgDefaultWeatherValue( "visibility-m",
fgGetDouble("/environment/metar/min-visibility-m") );
-
- // FIXME: this isn't the correct place in the property tree to set
- // the weather and it doesn't account for weather station
- // elevation.
- fgSetDouble("/environment/temperature-degc",
- fgGetDouble("/environment/metar/temperature-degc"));
- fgSetDouble("/environment/dewpoint-degc",
- fgGetDouble("/environment/metar/dewpoint-degc"));
-
+ set_temp_at_altitude( fgGetDouble("/environment/metar/temperature-degc"),
+ station_elevation_ft );
+ set_dewpoint_at_altitude( fgGetDouble("/environment/metar/dewpoint-degc"),
+ station_elevation_ft );
fgDefaultWeatherValue( "pressure-sea-level-inhg",
fgGetDouble("/environment/metar/pressure-inhg") );
#endif
_icao = strdup(icao);
}
+ // fetch station elevation if exists
+ FGAirport a = globals->get_airports()->search( _icao );
+ station_elevation_ft = a.elevation;
+
+ // fetch current metar data
SGMetar *m;
try {
m = new SGMetar(_icao);
strncat(s, "/elevation-ft", 128);
d = cloud->getAltitude_ft();
d = (d != SGMetarNaN) ? d : -9999;
- fgSetDouble(s, d);
+ fgSetDouble(s, d + station_elevation_ft);
snprintf(s, 128, cl, i);
strncat(s, "/thickness-ft", 128);
{
const string &temp_str = arg->getStringValue("temp-degc", "15.0");
- static const SGPropertyNode *altitude_ft
- = fgGetNode("/position/altitude-ft");
+ // check for an altitude specified in the arguments, otherwise use
+ // current aircraft altitude.
+ const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
+ if ( altitude_ft == NULL ) {
+ altitude_ft = fgGetNode("/position/altitude-ft");
+ }
FGEnvironment dummy; // instantiate a dummy so we can leech a method
dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
return true;
}
+/**
+ * Set the sea level outside air dewpoint and assigning that to all
+ * boundary and aloft environment layers.
+ */
+static bool
+do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
+{
+ double dewpoint_sea_level_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
+
+ SGPropertyNode *node, *child;
+
+ // boundary layers
+ node = fgGetNode( "/environment/config/boundary" );
+ if ( node != NULL ) {
+ int i = 0;
+ while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+ child->setDoubleValue( "dewpoint-sea-level-degc",
+ dewpoint_sea_level_degc );
+ ++i;
+ }
+ }
+
+ // aloft layers
+ node = fgGetNode( "/environment/config/aloft" );
+ if ( node != NULL ) {
+ int i = 0;
+ while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+ child->setDoubleValue( "dewpoint-sea-level-degc",
+ dewpoint_sea_level_degc );
+ ++i;
+ }
+ }
+
+ return true;
+}
+
+
+/**
+ * Set the outside air dewpoint at the "current" altitude by first
+ * calculating the corresponding sea level dewpoint, and assigning
+ * that to all boundary and aloft environment layers.
+ */
+static bool
+do_set_dewpoint_degc (const SGPropertyNode * arg)
+{
+ const string &dewpoint_str = arg->getStringValue("dewpoint-degc", "5.0");
+
+ // check for an altitude specified in the arguments, otherwise use
+ // current aircraft altitude.
+ const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
+ if ( altitude_ft == NULL ) {
+ altitude_ft = fgGetNode("/position/altitude-ft");
+ }
+
+ FGEnvironment dummy; // instantiate a dummy so we can leech a method
+ dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
+ dummy.set_dewpoint_degc( atof( dewpoint_str.c_str() ) );
+ double dewpoint_sea_level_degc = dummy.get_dewpoint_sea_level_degc();
+
+ cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
+ cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl;
+ cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl;
+
+ SGPropertyNode *node, *child;
+
+ // boundary layers
+ node = fgGetNode( "/environment/config/boundary" );
+ if ( node != NULL ) {
+ int i = 0;
+ while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+ child->setDoubleValue( "dewpoint-sea-level-degc",
+ dewpoint_sea_level_degc );
+ ++i;
+ }
+ }
+
+ // aloft layers
+ node = fgGetNode( "/environment/config/aloft" );
+ if ( node != NULL ) {
+ int i = 0;
+ while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+ child->setDoubleValue( "dewpoint-sea-level-degc",
+ dewpoint_sea_level_degc );
+ ++i;
+ }
+ }
+
+ return true;
+}
+
/**
* Update the lighting manually.
*/
{ "tile-cache-reload", do_tile_cache_reload },
{ "set-sea-level-air-temp-degc", do_set_sea_level_degc },
{ "set-outside-air-temp-degc", do_set_oat_degc },
+ { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
+ { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
{ "timeofday", do_timeofday },
{ "property-toggle", do_property_toggle },
{ "property-assign", do_property_assign },