1 /*****************************************************************************
3 Header: FGWeatherUtils.h
4 Author: Christian Mayer
7 -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Utilities for the weather calculation like converting formulas
31 ------------------------------------------------------------------------------
32 02.06.1999 Christian Mayer Created
33 08.06.1999 Christian Mayer Changed sat_vp
34 16.06.1999 Durk Talsma Portability for Linux
35 20.06.1999 Christian Mayer added lots of consts
36 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
38 19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
39 and lots of wee code cleaning
40 17.01.2000 Christian Mayer Added conversion routines make it easier for
41 JSBsim to use the weather database.
42 18.05.2000 Christian Mayer Added function for geting the density when
43 temperature and pressure are given
44 *****************************************************************************/
46 /****************************************************************************/
48 /****************************************************************************/
49 #ifndef FGWeatherUtils_H
50 #define FGWeatherUtils_H
52 /****************************************************************************/
54 /****************************************************************************/
57 /****************************************************************************/
59 /****************************************************************************/
61 /****************************************************************************/
62 /*assuming as given: */
64 /* t: temperature in °C */
65 /* p: preasure in mbar */
66 /* //abs_hum: absoloute humidity in g/m^3, */
67 /* act_vp: actual vapor pressure pascal */
69 /* Calculated vaues: */
70 /* //max_hum: maximum of humidity in g/m^3, */
71 /* sat_vp: saturated vapor pressure in pascal */
72 /* rel_hum: relative humidity in % */
73 /* dp: dew point in °C */
74 /* wb: approximate wetbulp in °C */
76 /* NOTE: Pascal is the SI unit for pressure and is defined as Pa = N/m^2 */
77 /* 1 mbar = 1 hPa = 100 Pa */
78 /* NOTE: °C isn't a SI unit, so I should use °K instead. But as all */
79 /* formulas are given in °C and the weather database only uses */
80 /* 'normal' temperatures, I've kept it in °C */
81 /****************************************************************************/
83 #define SAT_VP_CONST1 610.483125
84 #define SAT_VP_CONST2 7.444072452
85 #define SAT_VP_CONST3 235.3120919
87 inline WeatherPrecision sat_vp(const WeatherPrecision temp)
90 //return 6.112 * pow( 10, (7.5*dp)/(237.7+dp) ); //in mbar
93 //advantages: return the result as SI unit pascal and the constants
94 //are choosen that the correct results are returned for 0°C, 20°C and
95 //100°C. By 100°C I'm now returning a preasure of 1013.25 hPa
96 return SAT_VP_CONST1 * pow( 10, (SAT_VP_CONST2*temp)/(SAT_VP_CONST3+temp) ); //in pascal
99 inline WeatherPrecision rel_hum(const WeatherPrecision act_vp, const WeatherPrecision sat_vp)
101 return (act_vp / sat_vp) * 100; //in %
104 inline WeatherPrecision dp(const WeatherPrecision sat_vp)
106 return (SAT_VP_CONST3*log10(sat_vp/SAT_VP_CONST1))/(SAT_VP_CONST2-log10(sat_vp/SAT_VP_CONST1)); //in °C
109 inline WeatherPrecision wb(const WeatherPrecision t, const WeatherPrecision p, const WeatherPrecision dp)
111 WeatherPrecision e = sat_vp(dp);
112 WeatherPrecision tcur, tcvp, peq, diff;
113 WeatherPrecision tmin, tmax;
131 peq = 0.000660*(1+0.00155*tcur)*p*(t-tcur);
135 if (fabs(diff) < 0.01)
146 // Assume that we've got an ideal gas in normal altitudes
147 inline WeatherPrecision Density(const WeatherPrecision AirPressure, const WeatherPrecision Temperature )
149 const float rho0 = 1.293; /*density for air in normal altitudes at 0°C and 1013 mbar*/
151 return rho0 * 273.15 * AirPressure / (101300.0 * Temperature);
154 inline WeatherPrecision Celsius (const WeatherPrecision celsius)
156 return celsius + 273.15; //Kelvin
159 inline WeatherPrecision Fahrenheit (const WeatherPrecision fahrenheit)
161 return (fahrenheit * 9.0 / 5.0) + 32.0 + 273.15; //Kelvin
164 inline WeatherPrecision Kelvin2Celsius (const WeatherPrecision kelvin)
166 return kelvin - 273.15; //Celsius
169 inline WeatherPrecision Kelvin2Fahrenheit (const WeatherPrecision kelvin)
171 return ((kelvin - 273.15) * 9.0 / 5.0) + 32.0; //Fahrenheit
174 inline WeatherPrecision Celsius2Fahrenheit (const WeatherPrecision celsius)
176 return (celsius * 9.0 / 5.0) + 32.0; //Fahrenheit
179 inline WeatherPrecision Fahrenheit2Celsius (const WeatherPrecision fahrenheit)
181 return (fahrenheit - 32.0) * 5.0 / 9.0; //Celsius
184 inline WeatherPrecision Torr2Pascal (const WeatherPrecision torr)
186 return (101325.0/760.0)*torr; //Pascal
189 inline WeatherPrecision Rankine2Kelvin (const WeatherPrecision Rankine)
191 return (5.0 / 9.0) * Rankine; //Kelvin
194 inline WeatherPrecision JSBsim2SIdensity (const WeatherPrecision JSBsim)
196 return JSBsim / 0.0019403203; //kg / cubic metres
199 inline WeatherPrecision psf2Pascal (const WeatherPrecision psf)
201 return psf / 0.020885434; //lbs / square foot (used in JSBsim)
204 inline WeatherPrecision Kelvin2Rankine (const WeatherPrecision kelvin)
206 return (9.0 / 5.0) * kelvin; //Rankine (used in JSBsim)
209 inline WeatherPrecision SIdensity2JSBsim (const WeatherPrecision SIdensity)
211 return 0.0019403203 * SIdensity; //slug / cubic feet (used in JSBsim)
214 inline WeatherPrecision Pascal2psf (const WeatherPrecision Pascal)
216 return 0.020885434 * Pascal; //lbs / square feet (used in JSBsim)
219 /****************************************************************************/
220 /* CLASS DECLARATION */
221 /****************************************************************************/
223 /****************************************************************************/
224 #endif /*FGWeatherUtils_H*/