1 /*****************************************************************************
3 Header: FGWeatherUtils.h
4 Author: Christian Mayer
7 ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.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 *****************************************************************************/
38 /****************************************************************************/
40 /****************************************************************************/
41 #ifndef FGWeatherUtils_H
42 #define FGWeatherUtils_H
44 /****************************************************************************/
46 /****************************************************************************/
49 /****************************************************************************/
51 /****************************************************************************/
53 /****************************************************************************/
54 /*assuming as given: */
56 /* t: temperature in °C */
57 /* p: preasure in mbar */
58 /* //abs_hum: absoloute humidity in g/m^3, */
59 /* act_vp: actual vapor pressure pascal */
61 /* Calculated vaues: */
62 /* //max_hum: maximum of humidity in g/m^3, */
63 /* sat_vp: saturated vapor pressure in pascal */
64 /* rel_hum: relative humidity in % */
65 /* dp: dew point in °C */
66 /* wb: approximate wetbulp in °C */
68 /* NOTE: Pascal is the SI unit for preasure and is defined as Pa = N/m^2 */
69 /* 1 mbar = 1 hPa = 100 Pa */
70 /* NOTE: °C isn't a SI unit, so I should use °K instead. But as all */
71 /* formulas are given in °C and the weather database only uses */
72 /* 'normal' temperatures, I've kept it in °C */
73 /****************************************************************************/
75 #define SAT_VP_CONST1 610.483125
76 #define SAT_VP_CONST2 7.444072452
77 #define SAT_VP_CONST3 235.3120919
79 inline WeatherPrecition sat_vp(const WeatherPrecition& temp)
82 //return 6.112 * pow( 10, (7.5*dp)/(237.7+dp) ); //in mbar
85 //advantages: return the result as SI unit pascal and the constants
86 //are choosen that the correct results are returned for 0°C, 20°C and
87 //100°C. By 100°C I'm now returning a preasure of 1013.25 hPa
88 return SAT_VP_CONST1 * pow( 10, (SAT_VP_CONST2*temp)/(SAT_VP_CONST3+temp) ); //in pascal
91 inline WeatherPrecition rel_hum(const WeatherPrecition& act_vp, const WeatherPrecition& sat_vp)
93 return (act_vp / sat_vp) * 100; //in %
96 inline WeatherPrecition dp(const WeatherPrecition& sat_vp)
98 return (SAT_VP_CONST3*log10(sat_vp/SAT_VP_CONST1))/(SAT_VP_CONST2-log10(sat_vp/SAT_VP_CONST1)); //in °C
101 inline WeatherPrecition wb(const WeatherPrecition& t, const WeatherPrecition& p, const WeatherPrecition& dp)
103 WeatherPrecition e = sat_vp(dp);
104 WeatherPrecition tcur, tcvp, peq, diff;
105 WeatherPrecition tmin, tmax;
123 peq = 0.000660*(1+0.00155*tcur)*p*(t-tcur);
127 if (fabs(diff) < 0.01)
138 inline WeatherPrecition Celsius(const WeatherPrecition& celsius)
140 return celsius + 273.16; //Kelvin
143 inline WeatherPrecition Fahrenheit(const WeatherPrecition& fahrenheit)
145 return (fahrenheit * 9.0 / 5.0) + 32.0 + 273.16; //Kelvin
148 inline WeatherPrecition Kelvin2Celsius(const WeatherPrecition& kelvin)
150 return kelvin - 273.16; //Celsius
153 inline WeatherPrecition Kelvin2Fahrenheit(const WeatherPrecition& kelvin)
155 return ((kelvin - 273.16) * 9.0 / 5.0) + 32.0; //Fahrenheit
158 inline WeatherPrecition Celsius2Fahrenheit(const WeatherPrecition& celsius)
160 return (celsius * 9.0 / 5.0) + 32.0; //Fahrenheit
163 inline WeatherPrecition Fahrenheit2Celsius(const WeatherPrecition& fahrenheit)
165 return (fahrenheit - 32.0) * 5.0 / 9.0; //Celsius
168 inline WeatherPrecition Torr2Pascal(const WeatherPrecition& torr)
170 return (101325.0/760.0)*torr;
173 /****************************************************************************/
174 /* CLASS DECLARATION */
175 /****************************************************************************/
177 /****************************************************************************/
178 #endif /*FGWeatherUtils_H*/