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 *****************************************************************************/
42 /****************************************************************************/
44 /****************************************************************************/
45 #ifndef FGWeatherUtils_H
46 #define FGWeatherUtils_H
48 /****************************************************************************/
50 /****************************************************************************/
53 /****************************************************************************/
55 /****************************************************************************/
57 /****************************************************************************/
58 /*assuming as given: */
60 /* t: temperature in °C */
61 /* p: preasure in mbar */
62 /* //abs_hum: absoloute humidity in g/m^3, */
63 /* act_vp: actual vapor pressure pascal */
65 /* Calculated vaues: */
66 /* //max_hum: maximum of humidity in g/m^3, */
67 /* sat_vp: saturated vapor pressure in pascal */
68 /* rel_hum: relative humidity in % */
69 /* dp: dew point in °C */
70 /* wb: approximate wetbulp in °C */
72 /* NOTE: Pascal is the SI unit for preasure and is defined as Pa = N/m^2 */
73 /* 1 mbar = 1 hPa = 100 Pa */
74 /* NOTE: °C isn't a SI unit, so I should use °K instead. But as all */
75 /* formulas are given in °C and the weather database only uses */
76 /* 'normal' temperatures, I've kept it in °C */
77 /****************************************************************************/
79 #define SAT_VP_CONST1 610.483125
80 #define SAT_VP_CONST2 7.444072452
81 #define SAT_VP_CONST3 235.3120919
83 inline WeatherPrecision sat_vp(const WeatherPrecision temp)
86 //return 6.112 * pow( 10, (7.5*dp)/(237.7+dp) ); //in mbar
89 //advantages: return the result as SI unit pascal and the constants
90 //are choosen that the correct results are returned for 0°C, 20°C and
91 //100°C. By 100°C I'm now returning a preasure of 1013.25 hPa
92 return SAT_VP_CONST1 * pow( 10, (SAT_VP_CONST2*temp)/(SAT_VP_CONST3+temp) ); //in pascal
95 inline WeatherPrecision rel_hum(const WeatherPrecision act_vp, const WeatherPrecision sat_vp)
97 return (act_vp / sat_vp) * 100; //in %
100 inline WeatherPrecision dp(const WeatherPrecision sat_vp)
102 return (SAT_VP_CONST3*log10(sat_vp/SAT_VP_CONST1))/(SAT_VP_CONST2-log10(sat_vp/SAT_VP_CONST1)); //in °C
105 inline WeatherPrecision wb(const WeatherPrecision t, const WeatherPrecision p, const WeatherPrecision dp)
107 WeatherPrecision e = sat_vp(dp);
108 WeatherPrecision tcur, tcvp, peq, diff;
109 WeatherPrecision tmin, tmax;
127 peq = 0.000660*(1+0.00155*tcur)*p*(t-tcur);
131 if (fabs(diff) < 0.01)
142 inline WeatherPrecision Celsius(const WeatherPrecision celsius)
144 return celsius + 273.16; //Kelvin
147 inline WeatherPrecision Fahrenheit(const WeatherPrecision fahrenheit)
149 return (fahrenheit * 9.0 / 5.0) + 32.0 + 273.16; //Kelvin
152 inline WeatherPrecision Kelvin2Celsius(const WeatherPrecision kelvin)
154 return kelvin - 273.16; //Celsius
157 inline WeatherPrecision Kelvin2Fahrenheit(const WeatherPrecision kelvin)
159 return ((kelvin - 273.16) * 9.0 / 5.0) + 32.0; //Fahrenheit
162 inline WeatherPrecision Celsius2Fahrenheit(const WeatherPrecision celsius)
164 return (celsius * 9.0 / 5.0) + 32.0; //Fahrenheit
167 inline WeatherPrecision Fahrenheit2Celsius(const WeatherPrecision fahrenheit)
169 return (fahrenheit - 32.0) * 5.0 / 9.0; //Celsius
172 inline WeatherPrecision Torr2Pascal(const WeatherPrecision torr)
174 return (101325.0/760.0)*torr;
177 /****************************************************************************/
178 /* CLASS DECLARATION */
179 /****************************************************************************/
181 /****************************************************************************/
182 #endif /*FGWeatherUtils_H*/