]> git.mxchange.org Git - flightgear.git/commitdiff
Updates so clouds, temp, and dewpoint can be set correctly using weather
authorcurt <curt>
Sun, 22 Feb 2004 14:21:37 +0000 (14:21 +0000)
committercurt <curt>
Sun, 22 Feb 2004 14:21:37 +0000 (14:21 +0000)
station base elevation.

src/Environment/environment_ctrl.cxx
src/Environment/environment_ctrl.hxx
src/Main/fg_commands.cxx

index e40c3805af78622d1ec616ebefec158a99dba42c..b987a6b6d9c3225add82287c89354950740ff2b6 100644 (file)
 #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>
 
@@ -333,6 +335,27 @@ FGMetarEnvironmentCtrl::~FGMetarEnvironmentCtrl ()
 }
 
 
+// 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 ()
 {
@@ -349,15 +372,10 @@ 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") );
 
@@ -381,15 +399,10 @@ FGMetarEnvironmentCtrl::reinit ()
 
     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
@@ -426,6 +439,11 @@ FGMetarEnvironmentCtrl::fetch_data (const char *icao)
         _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);
@@ -510,7 +528,7 @@ FGMetarEnvironmentCtrl::fetch_data (const char *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);
index d22e30641496a8d2abb0dc01fa08f4f16cd517df..343359ca90f61ed71bc0837a61bda445fec32b26 100644 (file)
@@ -154,6 +154,7 @@ private:
     FGInterpolateEnvironmentCtrl *env;
 
     char *_icao;
+    float station_elevation_ft;
     void fetch_data (const char *icao);
 };
 
index cdbb8dd2e7ba5fc7c8bc3274e482d616fe6e76bd..9bb24a5543a80aeef97a1e191848cda9381910b1 100644 (file)
@@ -526,8 +526,12 @@ do_set_oat_degc (const SGPropertyNode * arg)
 {
     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() );
@@ -565,6 +569,96 @@ do_set_oat_degc (const SGPropertyNode * arg)
     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.
  */
@@ -1118,6 +1212,8 @@ static struct {
     { "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 },