CirclingWind: eliminate attributes min_vector, max_vector
[xcsoar.git] / src / Atmosphere / Pressure.hpp
blobe1c1c741eaf249b54dcb557bb1f58fd16035e851
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_ATMOSPHERE_PRESSURE_H
25 #define XCSOAR_ATMOSPHERE_PRESSURE_H
27 #include "Math/fixed.hpp"
28 #include "Compiler.h"
30 /**
31 * ICAO Standard Atmosphere calculations (valid in Troposphere, alt<11000m)
34 class AtmosphericPressure
36 /** Pressure in hPa */
37 fixed value;
39 /**
40 * @param value the pressure in hPa
42 explicit constexpr
43 AtmosphericPressure(fixed _value):value(_value) {}
45 public:
46 /**
47 * Non-initialising constructor.
49 AtmosphericPressure() = default;
51 /**
52 * Returns an object representing zero pressure. This value doesn't
53 * make a lot of practical sense (unless you're an astronaut), but
54 * it may be used internally to mark an instance of this class
55 * "invalid" (IsPlausible() returns false).
57 static constexpr
58 AtmosphericPressure Zero() {
59 return AtmosphericPressure(fixed(0));
62 /**
63 * Returns an object representing the standard pressure (1013.25
64 * hPa).
66 static constexpr
67 AtmosphericPressure Standard() {
68 return AtmosphericPressure(fixed(1013.25));
71 static constexpr
72 AtmosphericPressure Pascal(fixed value) {
73 return AtmosphericPressure(value / 100);
76 static constexpr
77 AtmosphericPressure HectoPascal(fixed value) {
78 return AtmosphericPressure(value);
81 /**
82 * Is this a plausible value?
84 constexpr
85 bool IsPlausible() const {
86 return value > fixed(100) && value < fixed(1200);
89 fixed GetPascal() const {
90 return GetHectoPascal() * 100;
93 /**
94 * Access QNH value
96 * @return QNH value (hPa)
98 fixed GetHectoPascal() const {
99 return value;
103 * Calculates the current QNH by comparing a pressure value to a
104 * known altitude of a certain location
106 * @param pressure Current pressure
107 * @param alt_known Altitude of a known location (m)
109 gcc_const
110 static AtmosphericPressure FindQNHFromPressure(const AtmosphericPressure pressure,
111 const fixed alt_known);
114 * Converts altitude with QNH=1013.25 reference to QNH adjusted altitude
115 * @param alt 1013.25-based altitude (m)
116 * @return QNH-based altitude (m)
118 gcc_pure
119 fixed PressureAltitudeToQNHAltitude(const fixed alt) const;
122 * Converts QNH adjusted altitude to pressure altitude (with QNH=1013.25 as reference)
123 * @param alt QNH-based altitude(m)
124 * @return pressure altitude (m)
126 gcc_pure
127 fixed QNHAltitudeToPressureAltitude(const fixed alt) const;
130 * Converts a pressure value to the corresponding QNH-based altitude
132 * See http://wahiduddin.net/calc/density_altitude.htm
134 * Example:
135 * QNH=1014, ps=100203 => alt = 100
136 * @see QNHAltitudeToStaticPressure
137 * @param ps Air pressure
138 * @return Altitude over QNH-based zero (m)
140 gcc_pure
141 fixed StaticPressureToQNHAltitude(const AtmosphericPressure ps) const;
144 * Converts a QNH-based altitude to the corresponding pressure
146 * See http://wahiduddin.net/calc/density_altitude.htm
148 * Example:
149 * alt= 100, QNH=1014 => ps = 100203 Pa
150 * @see StaticPressureToAltitude
151 * @param alt Altitude over QNH-based zero (m)
152 * @return Air pressure at given altitude
154 gcc_pure
155 AtmosphericPressure QNHAltitudeToStaticPressure(const fixed alt) const;
158 * Converts a pressure value to pressure altitude (with QNH=1013.25 as reference)
159 * @param ps Air pressure
160 * @return pressure altitude (m)
162 gcc_const
163 static fixed StaticPressureToPressureAltitude(const AtmosphericPressure ps);
166 * Converts a 1013.25 hPa based altitude to the corresponding pressure
168 * @see StaticPressureToAltitude
169 * @param alt Altitude over 1013.25 hPa based zero(m)
170 * @return Air pressure at given altitude
172 gcc_const
173 static AtmosphericPressure PressureAltitudeToStaticPressure(const fixed alt);
176 #endif