]> git.mxchange.org Git - flightgear.git/blobdiff - src/WeatherCM/FGWeatherUtils.h
Moved random ground cover object management code (userdata.[ch]xx) over
[flightgear.git] / src / WeatherCM / FGWeatherUtils.h
index 166a23117d966b2340994e0e2ff55ce4f0432a0b..505fcdc58cc81103daa0d03449cdab997444a683 100644 (file)
@@ -4,7 +4,7 @@
  Author:       Christian Mayer
  Date started: 28.05.99
 
- ---------- Copyright (C) 1999  Christian Mayer (vader@t-online.de) ----------
+ -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
@@ -33,6 +33,14 @@ HISTORY
 08.06.1999 Christian Mayer      Changed sat_vp
 16.06.1999 Durk Talsma         Portability for Linux
 20.06.1999 Christian Mayer     added lots of consts
+11.10.1999 Christian Mayer     changed set<> to map<> on Bernie Bright's 
+                               suggestion
+19.10.1999 Christian Mayer     change to use PLIB's sg instead of Point[2/3]D
+                               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
 *****************************************************************************/
 
 /****************************************************************************/
@@ -65,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       */
@@ -76,7 +84,7 @@ HISTORY
 #define SAT_VP_CONST2 7.444072452
 #define SAT_VP_CONST3 235.3120919
 
-inline WeatherPrecition sat_vp(const WeatherPrecition& temp)
+inline WeatherPrecision sat_vp(const WeatherPrecision temp)
 {
     //old:
     //return 6.112 * pow( 10, (7.5*dp)/(237.7+dp) );    //in mbar
@@ -88,21 +96,21 @@ inline WeatherPrecition sat_vp(const WeatherPrecition& temp)
     return SAT_VP_CONST1 * pow( 10, (SAT_VP_CONST2*temp)/(SAT_VP_CONST3+temp) );    //in pascal
 }
 
-inline WeatherPrecition rel_hum(const WeatherPrecition& act_vp, const WeatherPrecition& sat_vp)
+inline WeatherPrecision rel_hum(const WeatherPrecision act_vp, const WeatherPrecision sat_vp)
 {
     return (act_vp / sat_vp) * 100;    //in %
 }
 
-inline WeatherPrecition dp(const WeatherPrecition& sat_vp)
+inline WeatherPrecision dp(const WeatherPrecision sat_vp)
 {
     return (SAT_VP_CONST3*log10(sat_vp/SAT_VP_CONST1))/(SAT_VP_CONST2-log10(sat_vp/SAT_VP_CONST1)); //in °C 
 }
 
-inline WeatherPrecition wb(const WeatherPrecition& t, const WeatherPrecition& p, const WeatherPrecition& dp)
+inline WeatherPrecision wb(const WeatherPrecision t, const WeatherPrecision p, const WeatherPrecision dp)
 {
-    WeatherPrecition e = sat_vp(dp); 
-    WeatherPrecition tcur, tcvp, peq, diff;
-    WeatherPrecition tmin, tmax;
+    WeatherPrecision e = sat_vp(dp); 
+    WeatherPrecision tcur, tcvp, peq, diff;
+    WeatherPrecision tmin, tmax;
 
     if (t > dp)
     {
@@ -135,39 +143,77 @@ inline WeatherPrecition wb(const WeatherPrecition& t, const WeatherPrecition& p,
 
 }
 
-inline WeatherPrecition Celsius(const WeatherPrecition& celsius)
+// Assume that we've got an ideal gas in normal altitudes
+inline WeatherPrecision Density(const WeatherPrecision AirPressure, const WeatherPrecision Temperature )
 {
-    return celsius + 273.16;                           //Kelvin
+    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.15;                           //Kelvin
 }
 
-inline WeatherPrecition Fahrenheit(const WeatherPrecition& fahrenheit)
+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 WeatherPrecition Kelvin2Celsius(const WeatherPrecition& kelvin)
+inline WeatherPrecision Kelvin2Celsius     (const WeatherPrecision kelvin)
 {
-    return kelvin - 273.16;                            //Celsius
+    return kelvin - 273.15;                            //Celsius
 }
 
-inline WeatherPrecition Kelvin2Fahrenheit(const WeatherPrecition& kelvin)
+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 WeatherPrecition Celsius2Fahrenheit(const WeatherPrecition& celsius)
+inline WeatherPrecision Celsius2Fahrenheit  (const WeatherPrecision celsius)
 {
-    return (celsius * 9.0 / 5.0) + 32.0;                //Fahrenheit
+    return (celsius * 9.0 / 5.0) + 32.0;               //Fahrenheit
 }
 
-inline WeatherPrecition Fahrenheit2Celsius(const WeatherPrecition& fahrenheit)
+inline WeatherPrecision Fahrenheit2Celsius  (const WeatherPrecision fahrenheit)
 {
     return (fahrenheit - 32.0) * 5.0 / 9.0;            //Celsius
 }
 
-inline WeatherPrecition Torr2Pascal(const WeatherPrecition& torr)
+inline WeatherPrecision Torr2Pascal        (const WeatherPrecision torr)
+{
+    return (101325.0/760.0)*torr;                      //Pascal
+}
+
+inline WeatherPrecision Rankine2Kelvin     (const WeatherPrecision Rankine)
+{
+    return (5.0 / 9.0) * Rankine;                      //Kelvin
+}
+
+inline WeatherPrecision JSBsim2SIdensity    (const WeatherPrecision JSBsim)
+{
+    return JSBsim / 0.0019403203;                      //kg / cubic metres
+}
+
+inline WeatherPrecision psf2Pascal         (const WeatherPrecision psf)
+{
+    return psf / 0.020885434;                          //lbs / square foot (used in JSBsim)
+}
+
+inline WeatherPrecision Kelvin2Rankine     (const WeatherPrecision kelvin)
+{
+    return (9.0 / 5.0) * kelvin;                       //Rankine (used in JSBsim)
+}
+
+inline WeatherPrecision SIdensity2JSBsim    (const WeatherPrecision SIdensity)
+{
+    return 0.0019403203 * SIdensity;                   //slug / cubic feet (used in JSBsim)
+}
+
+inline WeatherPrecision Pascal2psf         (const WeatherPrecision Pascal)
 {
-    return (101325.0/760.0)*torr;
+    return 0.020885434 * Pascal;                       //lbs / square feet (used in JSBsim)
 }
 
 /****************************************************************************/
@@ -175,4 +221,4 @@ inline WeatherPrecition Torr2Pascal(const WeatherPrecition& torr)
 /****************************************************************************/
 
 /****************************************************************************/
-#endif /*FGWeatherUtils_H*/
\ No newline at end of file
+#endif /*FGWeatherUtils_H*/