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 *****************************************************************************/
44 /****************************************************************************/
46 /****************************************************************************/
47 #ifndef FGWeatherUtils_H
48 #define FGWeatherUtils_H
50 /****************************************************************************/
52 /****************************************************************************/
55 /****************************************************************************/
57 /****************************************************************************/
59 /****************************************************************************/
60 /*assuming as given: */
62 /* t: temperature in °C */
63 /* p: preasure in mbar */
64 /* //abs_hum: absoloute humidity in g/m^3, */
65 /* act_vp: actual vapor pressure pascal */
67 /* Calculated vaues: */
68 /* //max_hum: maximum of humidity in g/m^3, */
69 /* sat_vp: saturated vapor pressure in pascal */
70 /* rel_hum: relative humidity in % */
71 /* dp: dew point in °C */
72 /* wb: approximate wetbulp in °C */
74 /* NOTE: Pascal is the SI unit for preasure and is defined as Pa = N/m^2 */
75 /* 1 mbar = 1 hPa = 100 Pa */
76 /* NOTE: °C isn't a SI unit, so I should use °K instead. But as all */
77 /* formulas are given in °C and the weather database only uses */
78 /* 'normal' temperatures, I've kept it in °C */
79 /****************************************************************************/
81 #define SAT_VP_CONST1 610.483125
82 #define SAT_VP_CONST2 7.444072452
83 #define SAT_VP_CONST3 235.3120919
85 inline WeatherPrecision sat_vp(const WeatherPrecision temp)
88 //return 6.112 * pow( 10, (7.5*dp)/(237.7+dp) ); //in mbar
91 //advantages: return the result as SI unit pascal and the constants
92 //are choosen that the correct results are returned for 0°C, 20°C and
93 //100°C. By 100°C I'm now returning a preasure of 1013.25 hPa
94 return SAT_VP_CONST1 * pow( 10, (SAT_VP_CONST2*temp)/(SAT_VP_CONST3+temp) ); //in pascal
97 inline WeatherPrecision rel_hum(const WeatherPrecision act_vp, const WeatherPrecision sat_vp)
99 return (act_vp / sat_vp) * 100; //in %
102 inline WeatherPrecision dp(const WeatherPrecision sat_vp)
104 return (SAT_VP_CONST3*log10(sat_vp/SAT_VP_CONST1))/(SAT_VP_CONST2-log10(sat_vp/SAT_VP_CONST1)); //in °C
107 inline WeatherPrecision wb(const WeatherPrecision t, const WeatherPrecision p, const WeatherPrecision dp)
109 WeatherPrecision e = sat_vp(dp);
110 WeatherPrecision tcur, tcvp, peq, diff;
111 WeatherPrecision tmin, tmax;
129 peq = 0.000660*(1+0.00155*tcur)*p*(t-tcur);
133 if (fabs(diff) < 0.01)
144 inline WeatherPrecision Celsius (const WeatherPrecision celsius)
146 return celsius + 273.16; //Kelvin
149 inline WeatherPrecision Fahrenheit (const WeatherPrecision fahrenheit)
151 return (fahrenheit * 9.0 / 5.0) + 32.0 + 273.16; //Kelvin
154 inline WeatherPrecision Kelvin2Celsius (const WeatherPrecision kelvin)
156 return kelvin - 273.16; //Celsius
159 inline WeatherPrecision Kelvin2Fahrenheit (const WeatherPrecision kelvin)
161 return ((kelvin - 273.16) * 9.0 / 5.0) + 32.0; //Fahrenheit
164 inline WeatherPrecision Celsius2Fahrenheit (const WeatherPrecision celsius)
166 return (celsius * 9.0 / 5.0) + 32.0; //Fahrenheit
169 inline WeatherPrecision Fahrenheit2Celsius (const WeatherPrecision fahrenheit)
171 return (fahrenheit - 32.0) * 5.0 / 9.0; //Celsius
174 inline WeatherPrecision Torr2Pascal (const WeatherPrecision torr)
176 return (101325.0/760.0)*torr; //Pascal
179 inline WeatherPrecision Rankine2Kelvin (const WeatherPrecision Rankine)
181 return (5.0 / 9.0) * Rankine; //Kelvin
184 inline WeatherPrecision JSBsim2SIdensity (const WeatherPrecision JSBsim)
186 return JSBsim / 0.0019403203; //kg / cubic metres
189 inline WeatherPrecision psf2Pascal (const WeatherPrecision psf)
191 return psf / 0.0020885434; //lbs / square foot (used in JSBsim)
194 inline WeatherPrecision Kelvin2Rankine (const WeatherPrecision kelvin)
196 return (9.0 / 5.0) * kelvin; //Rankine (used in JSBsim)
199 inline WeatherPrecision SIdensity2JSBsim (const WeatherPrecision SIdensity)
201 return 0.0019403203 * SIdensity; //slug / cubic feet (used in JSBsim)
204 inline WeatherPrecision Pascal2psf (const WeatherPrecision Pascal)
206 return 0.0020885434 * Pascal; //lbs / square feet (used in JSBsim)
209 /****************************************************************************/
210 /* CLASS DECLARATION */
211 /****************************************************************************/
213 /****************************************************************************/
214 #endif /*FGWeatherUtils_H*/