Updates so clouds, temp, and dewpoint can be set correctly using weather
station base elevation.
This commit is contained in:
parent
b464703a6f
commit
969fbe4601
3 changed files with 136 additions and 21 deletions
|
@ -25,8 +25,10 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <simgear/structure/commands.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
|
#include <Airports/simple.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/util.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
|
void
|
||||||
FGMetarEnvironmentCtrl::init ()
|
FGMetarEnvironmentCtrl::init ()
|
||||||
{
|
{
|
||||||
|
@ -349,15 +372,10 @@ FGMetarEnvironmentCtrl::init ()
|
||||||
|
|
||||||
fgDefaultWeatherValue( "visibility-m",
|
fgDefaultWeatherValue( "visibility-m",
|
||||||
fgGetDouble("/environment/metar/min-visibility-m") );
|
fgGetDouble("/environment/metar/min-visibility-m") );
|
||||||
|
set_temp_at_altitude( fgGetDouble("/environment/metar/temperature-degc"),
|
||||||
// FIXME: this isn't the correct place in the property tree to set
|
station_elevation_ft );
|
||||||
// the weather and it doesn't account for weather station
|
set_dewpoint_at_altitude( fgGetDouble("/environment/metar/dewpoint-degc"),
|
||||||
// elevation.
|
station_elevation_ft );
|
||||||
fgSetDouble("/environment/temperature-degc",
|
|
||||||
fgGetDouble("/environment/metar/temperature-degc"));
|
|
||||||
fgSetDouble("/environment/dewpoint-degc",
|
|
||||||
fgGetDouble("/environment/metar/dewpoint-degc"));
|
|
||||||
|
|
||||||
fgDefaultWeatherValue( "pressure-sea-level-inhg",
|
fgDefaultWeatherValue( "pressure-sea-level-inhg",
|
||||||
fgGetDouble("/environment/metar/pressure-inhg") );
|
fgGetDouble("/environment/metar/pressure-inhg") );
|
||||||
|
|
||||||
|
@ -381,15 +399,10 @@ FGMetarEnvironmentCtrl::reinit ()
|
||||||
|
|
||||||
fgDefaultWeatherValue( "visibility-m",
|
fgDefaultWeatherValue( "visibility-m",
|
||||||
fgGetDouble("/environment/metar/min-visibility-m") );
|
fgGetDouble("/environment/metar/min-visibility-m") );
|
||||||
|
set_temp_at_altitude( fgGetDouble("/environment/metar/temperature-degc"),
|
||||||
// FIXME: this isn't the correct place in the property tree to set
|
station_elevation_ft );
|
||||||
// the weather and it doesn't account for weather station
|
set_dewpoint_at_altitude( fgGetDouble("/environment/metar/dewpoint-degc"),
|
||||||
// elevation.
|
station_elevation_ft );
|
||||||
fgSetDouble("/environment/temperature-degc",
|
|
||||||
fgGetDouble("/environment/metar/temperature-degc"));
|
|
||||||
fgSetDouble("/environment/dewpoint-degc",
|
|
||||||
fgGetDouble("/environment/metar/dewpoint-degc"));
|
|
||||||
|
|
||||||
fgDefaultWeatherValue( "pressure-sea-level-inhg",
|
fgDefaultWeatherValue( "pressure-sea-level-inhg",
|
||||||
fgGetDouble("/environment/metar/pressure-inhg") );
|
fgGetDouble("/environment/metar/pressure-inhg") );
|
||||||
#endif
|
#endif
|
||||||
|
@ -426,6 +439,11 @@ FGMetarEnvironmentCtrl::fetch_data (const char *icao)
|
||||||
_icao = strdup(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;
|
SGMetar *m;
|
||||||
try {
|
try {
|
||||||
m = new SGMetar(_icao);
|
m = new SGMetar(_icao);
|
||||||
|
@ -510,7 +528,7 @@ FGMetarEnvironmentCtrl::fetch_data (const char *icao)
|
||||||
strncat(s, "/elevation-ft", 128);
|
strncat(s, "/elevation-ft", 128);
|
||||||
d = cloud->getAltitude_ft();
|
d = cloud->getAltitude_ft();
|
||||||
d = (d != SGMetarNaN) ? d : -9999;
|
d = (d != SGMetarNaN) ? d : -9999;
|
||||||
fgSetDouble(s, d);
|
fgSetDouble(s, d + station_elevation_ft);
|
||||||
|
|
||||||
snprintf(s, 128, cl, i);
|
snprintf(s, 128, cl, i);
|
||||||
strncat(s, "/thickness-ft", 128);
|
strncat(s, "/thickness-ft", 128);
|
||||||
|
|
|
@ -154,6 +154,7 @@ private:
|
||||||
FGInterpolateEnvironmentCtrl *env;
|
FGInterpolateEnvironmentCtrl *env;
|
||||||
|
|
||||||
char *_icao;
|
char *_icao;
|
||||||
|
float station_elevation_ft;
|
||||||
void fetch_data (const char *icao);
|
void fetch_data (const char *icao);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -526,8 +526,12 @@ do_set_oat_degc (const SGPropertyNode * arg)
|
||||||
{
|
{
|
||||||
const string &temp_str = arg->getStringValue("temp-degc", "15.0");
|
const string &temp_str = arg->getStringValue("temp-degc", "15.0");
|
||||||
|
|
||||||
static const SGPropertyNode *altitude_ft
|
// check for an altitude specified in the arguments, otherwise use
|
||||||
= fgGetNode("/position/altitude-ft");
|
// 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
|
FGEnvironment dummy; // instantiate a dummy so we can leech a method
|
||||||
dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
|
dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
|
||||||
|
@ -565,6 +569,96 @@ do_set_oat_degc (const SGPropertyNode * arg)
|
||||||
return true;
|
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.
|
* Update the lighting manually.
|
||||||
*/
|
*/
|
||||||
|
@ -1118,6 +1212,8 @@ static struct {
|
||||||
{ "tile-cache-reload", do_tile_cache_reload },
|
{ "tile-cache-reload", do_tile_cache_reload },
|
||||||
{ "set-sea-level-air-temp-degc", do_set_sea_level_degc },
|
{ "set-sea-level-air-temp-degc", do_set_sea_level_degc },
|
||||||
{ "set-outside-air-temp-degc", do_set_oat_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 },
|
{ "timeofday", do_timeofday },
|
||||||
{ "property-toggle", do_property_toggle },
|
{ "property-toggle", do_property_toggle },
|
||||||
{ "property-assign", do_property_assign },
|
{ "property-assign", do_property_assign },
|
||||||
|
|
Loading…
Add table
Reference in a new issue