]> git.mxchange.org Git - flightgear.git/commitdiff
Updates from Christian Mayer to put some of the weather data "on the bus."
authorcurt <curt>
Sat, 30 Sep 2000 03:55:57 +0000 (03:55 +0000)
committercurt <curt>
Sat, 30 Sep 2000 03:55:57 +0000 (03:55 +0000)
src/WeatherCM/FGLocalWeatherDatabase.cpp
src/WeatherCM/FGLocalWeatherDatabase.h
src/WeatherCM/FGWeatherUtils.h

index a2fbe0bd239703f14489032de6bc3094f025bc3e..cc4a2a15aeb82431ae45515f3cc1eae99e75616e 100644 (file)
@@ -42,6 +42,10 @@ HISTORY
                                 Eberly's spherical interpolation code. This
                                stops our dependancy on the (ugly) voronoi
                                code and simplyfies the code structure a lot.
+07.05.2000 Tony Peden           Added functionality to get the weather data
+                                on 'the bus'
+18.05.2000 Christian Mayer      Minor clean-ups. Changed the code to use 
+                                FGWeatherUtils.h for unit conversion
 *****************************************************************************/
 
 /****************************************************************************/
@@ -49,7 +53,6 @@ HISTORY
 /****************************************************************************/
 #include <simgear/compiler.h>
 #include <simgear/constants.h>
-#include <simgear/misc/fgpath.hxx>
 
 #include <Aircraft/aircraft.hxx>
 
@@ -57,6 +60,8 @@ HISTORY
 
 #include "FGWeatherParse.h"
 
+#include "FGWeatherUtils.h"
+
 /****************************************************************************/
 /********************************** CODE ************************************/
 /****************************************************************************/
@@ -66,7 +71,7 @@ FGLocalWeatherDatabase *WeatherDatabase;
 
 void FGLocalWeatherDatabase::init( const WeatherPrecision visibility,
                                   const DatabaseWorkingType type,
-                                  const stringroot )
+                                  const string &root )
 {
     cerr << "Initializing FGLocalWeatherDatabase\n";
     cerr << "-----------------------------------\n";
@@ -98,10 +103,7 @@ void FGLocalWeatherDatabase::init( const WeatherPrecision visibility,
        {
            FGWeatherParse *parsed_data = new FGWeatherParse();
 
-           FGPath file( root );
-           file.append( "Weather" );
-           file.append( "current.txt.gz" );
-           parsed_data->input( file.c_str() );
+           parsed_data->input( "weather/current.gz" );
            unsigned int n = parsed_data->stored_stations();
 
            sgVec2               *p = new sgVec2              [n];
@@ -251,33 +253,29 @@ void FGLocalWeatherDatabase::setProperties(const FGPhysicalProperties2D& x)
 void fgUpdateWeatherDatabase(void)
 {
     sgVec3 position;
-       sgVec3 wind;
+    sgVec3 wind;
+    
+    
+    sgSetVec3(position, 
+        current_aircraft.fdm_state->get_Latitude(),
+        current_aircraft.fdm_state->get_Longitude(),
+        current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER);
     
-       
-       sgSetVec3(position, 
-       current_aircraft.fdm_state->get_Latitude(),
-       current_aircraft.fdm_state->get_Longitude(),
-       current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER);
-
     WeatherDatabase->update( position );
-       
-       #define rho0 1.293 /*for air in normal altitudes*/
-    #define PATOPSF  0.02089    // Pascals to psf
-       #define KTOR     1.8        // Kelvin to degree Rankine
-       #define KGMTOSGF 0.0019403  // kg/m^3 to slug/ft^3
-
-
-    FGPhysicalProperty my_value = WeatherDatabase->get(position);
-    current_aircraft.fdm_state->set_Static_temperature(my_value.Temperature*KTOR);
-    current_aircraft.fdm_state->set_Static_pressure(my_value.AirPressure*PATOPSF);
-    float density=rho0 * 273.15 * my_value.AirPressure / (101300 *my_value.Temperature )*KGMTOSGF;
-    current_aircraft.fdm_state->set_Density(density*KGMTOSGF);
-       
-#define KPHTOFPS 0.9113 //km/hr to ft/s
+       
+    // get the data on 'the bus' for the FDM
+
+    FGPhysicalProperty porperty = WeatherDatabase->get(position);
+
+    current_aircraft.fdm_state->set_Static_temperature( Kelvin2Rankine(porperty.Temperature) );
+    current_aircraft.fdm_state->set_Static_pressure( Pascal2psf(porperty.AirPressure) );
+
+    current_aircraft.fdm_state->set_Density( SIdensity2JSBsim( Density(porperty.AirPressure, porperty.Temperature) ) );
+    
 #define MSTOFPS  3.2808 //m/s to ft/s
-    current_aircraft.fdm_state->set_Velocities_Local_Airmass(my_value.Wind[1]*KPHTOFPS,
-                                                            my_value.Wind[0]*KPHTOFPS,
-                                                            my_value.Wind[2]*KPHTOFPS);
-       
+    current_aircraft.fdm_state->set_Velocities_Local_Airmass(porperty.Wind[1]*MSTOFPS,
+        porperty.Wind[0]*MSTOFPS,
+        porperty.Wind[2]*MSTOFPS);
+    
 }
 
index 213f07d18844bab4a5d7a659f5bfb714555200e0..96e72453f6895c16419e065025985e2b894f10a6 100644 (file)
@@ -114,7 +114,7 @@ public:
 
     void init( const WeatherPrecision visibility,
               const DatabaseWorkingType type,
-              const stringroot );
+              const string &root );
 
     /************************************************************************/
     /* Constructor and Destructor                                          */
index cf25b988dfb6a77af9250b8055ac3fdfd8988ca1..59283d3e466de893441e4702c54c1891c9ad37d9 100644 (file)
@@ -39,6 +39,8 @@ HISTORY
                                and lots of wee code cleaning
 17.01.2000 Christian Mayer     Added conversion routines make it easier for
                                JSBsim to use the weather database.
+18.05.2000 Christian Mayer      Added function for geting the density when
+                                temperature and pressure are given
 *****************************************************************************/
 
 /****************************************************************************/
@@ -71,7 +73,7 @@ HISTORY
 /* dp:     dew point in °C                                                 */
 /* wb:     approximate wetbulp in °C                                       */
 /*                                                                         */
-/* NOTE: Pascal is the SI unit for preasure and is defined as Pa = N/m^2    */
+/* NOTE: Pascal is the SI unit for pressure and is defined as Pa = N/m^2    */
 /*       1 mbar = 1 hPa = 100 Pa                                           */
 /* NOTE: °C isn't a SI unit, so I should use °K instead. But as all        */
 /*       formulas are given in °C and the weather database only uses       */
@@ -141,24 +143,32 @@ inline WeatherPrecision wb(const WeatherPrecision t, const WeatherPrecision p, c
 
 }
 
+// Assume that we've got an ideal gas in normal altitudes
+inline WeatherPrecision Density(const WeatherPrecision AirPressure, const WeatherPrecision Temperature )
+{
+    const float rho0 = 1.293; /*density for air in normal altitudes at 0°C and 1013 mbar*/
+
+    return rho0 * 273.15 * AirPressure / (101300.0 * Temperature);
+}
+
 inline WeatherPrecision Celsius                    (const WeatherPrecision celsius)
 {
-    return celsius + 273.16;                           //Kelvin
+    return celsius + 273.15;                           //Kelvin
 }
 
 inline WeatherPrecision Fahrenheit         (const WeatherPrecision fahrenheit)
 {
-    return (fahrenheit * 9.0 / 5.0) + 32.0 + 273.16;   //Kelvin
+    return (fahrenheit * 9.0 / 5.0) + 32.0 + 273.15;   //Kelvin
 }
 
 inline WeatherPrecision Kelvin2Celsius     (const WeatherPrecision kelvin)
 {
-    return kelvin - 273.16;                            //Celsius
+    return kelvin - 273.15;                            //Celsius
 }
 
 inline WeatherPrecision Kelvin2Fahrenheit   (const WeatherPrecision kelvin)
 {
-    return ((kelvin - 273.16) * 9.0 / 5.0) + 32.0;     //Fahrenheit
+    return ((kelvin - 273.15) * 9.0 / 5.0) + 32.0;     //Fahrenheit
 }
 
 inline WeatherPrecision Celsius2Fahrenheit  (const WeatherPrecision celsius)