]> git.mxchange.org Git - simgear.git/blob - simgear/environment/metar.hxx
Comment out an improperly written constructor.
[simgear.git] / simgear / environment / metar.hxx
1 // metar interface class
2 //
3 // Written by Melchior FRANZ, started December 2003.
4 //
5 // Copyright (C) 2003  Melchior FRANZ - mfranz@aon.at
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20 //
21 // $Id$
22
23 #ifndef _METAR_HXX
24 #define _METAR_HXX
25
26 #include <vector>
27 #include <map>
28 #include <string>
29
30 #include <simgear/constants.h>
31
32 SG_USING_STD(vector);
33 SG_USING_STD(map);
34 SG_USING_STD(string);
35
36 const double SGMetarNaN = -1E20;
37 #define NaN SGMetarNaN
38
39 struct Token {
40         char    *id;
41         char    *text;
42 };
43
44
45 class SGMetar;
46
47 class SGMetarVisibility {
48         friend class SGMetar;
49 public:
50         SGMetarVisibility() :
51                 _distance(NaN),
52                 _direction(-1),
53                 _modifier(EQUALS),
54                 _tendency(NONE) {}
55
56         enum Modifier {
57                 NOGO,
58                 EQUALS,
59                 LESS_THAN,
60                 GREATER_THAN
61         };
62
63         enum Tendency {
64                 NONE,
65                 STABLE,
66                 INCREASING,
67                 DECREASING
68         };
69
70         inline double   getVisibility_m()       const { return _distance; }
71         inline double   getVisibility_ft()      const { return _distance == NaN ? NaN : _distance * SG_METER_TO_FEET; }
72         inline double   getVisibility_sm()      const { return _distance == NaN ? NaN : _distance * SG_METER_TO_SM; }
73         inline int      getDirection()          const { return _direction; }
74         inline int      getModifier()           const { return _modifier; }
75         inline int      getTendency()           const { return _tendency; }
76
77 protected:
78         double  _distance;
79         int     _direction;
80         int     _modifier;
81         int     _tendency;
82 };
83
84
85 // runway condition (surface and visibility)
86 class SGMetarRunway {
87         friend class SGMetar;
88 public:
89         SGMetarRunway() :
90                 _deposit(0),
91                 _extent(-1),
92                 _extent_string(0),
93                 _depth(NaN),
94                 _friction(NaN),
95                 _friction_string(0),
96                 _comment(0),
97                 _wind_shear(false) {}
98
99         inline const char               *getDeposit()           const { return _deposit; }
100         inline double                   getExtent()             const { return _extent; }
101         inline const char               *getExtentString()      const { return _extent_string; }
102         inline double                   getDepth()              const { return _depth; }
103         inline double                   getFriction()           const { return _friction; }
104         inline const char               *getFrictionString()    const { return _friction_string; }
105         inline const char               *getComment()           const { return _comment; }
106         inline const bool               getWindShear()          const { return _wind_shear; }
107         inline SGMetarVisibility        getMinVisibility()      const { return _min_visibility; }
108         inline SGMetarVisibility        getMaxVisibility()      const { return _max_visibility; }
109
110 protected:
111         SGMetarVisibility _min_visibility;
112         SGMetarVisibility _max_visibility;
113         const char      *_deposit;
114         int             _extent;
115         const char      *_extent_string;
116         double          _depth;
117         double          _friction;
118         const char      *_friction_string;
119         const char      *_comment;
120         bool            _wind_shear;
121 };
122
123
124 // cloud layer
125 class SGMetarCloud {
126         friend class SGMetar;
127 public:
128         SGMetarCloud() :
129                 _coverage(-1),
130                 _altitude(NaN),
131                 _type(0),
132                 _type_long(0) {}
133
134         inline int      getCoverage()           const { return _coverage; }
135         inline double   getAltitude_m()         const { return _altitude; }
136         inline double   getAltitude_ft()        const { return _altitude == NaN ? NaN : _altitude * SG_METER_TO_FEET; }
137         inline char     *getTypeString()        const { return _type; }
138         inline char     *getTypeLongString()    const { return _type_long; }
139
140 protected:
141         int     _coverage;              // quarters: 0 -> clear ... 4 -> overcast
142         double  _altitude;              // 1000 m
143         char    *_type;                 // CU
144         char    *_type_long;            // cumulus
145 };
146
147
148 class SGMetar {
149 public:
150         SGMetar(const char *m);
151
152         // The following contructor is tempting, but it is not
153         // correct, it creates an anonymous instance of SGMetar and
154         // then immediately throws it away.
155         // SGMetar(const string m) { SGMetar(m.c_str()); }
156
157         ~SGMetar();
158
159         enum ReportType {
160                 NONE,
161                 AUTO,
162                 COR,
163                 RTD
164         };
165
166         inline const char *getData()            const { return _data; }
167         inline const char *getUnusedData()      const { return _m; }
168         inline const char *getId()              const { return _icao; }
169         inline int      getYear()               const { return _year; }
170         inline int      getMonth()              const { return _month; }
171         inline int      getDay()                const { return _day; }
172         inline int      getHour()               const { return _hour; }
173         inline int      getMinute()             const { return _minute; }
174         inline int      getReportType()         const { return _report_type; }
175
176         inline int      getWindDir()            const { return _wind_dir; }
177         inline double   getWindSpeed_mps()      const { return _wind_speed; }
178         inline double   getWindSpeed_kmh()      const { return _wind_speed == NaN ? NaN : _wind_speed * 3.6; }
179         inline double   getWindSpeed_kt()       const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KT; }
180         inline double   getWindSpeed_mph()      const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_MPH; }
181
182         inline double   getGustSpeed_mps()      const { return _gust_speed; }
183         inline double   getGustSpeed_kmh()      const { return _gust_speed == NaN ? NaN : _gust_speed * 3.6; }
184         inline double   getGustSpeed_kt()       const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KT; }
185         inline double   getGustSpeed_mph()      const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_MPH; }
186
187         inline int      getWindRangeFrom()      const { return _wind_range_from; }
188         inline int      getWindRangeTo()        const { return _wind_range_to; }
189
190         inline SGMetarVisibility& getMinVisibility()    { return _min_visibility; }
191         inline SGMetarVisibility& getMaxVisibility()    { return _max_visibility; }
192         inline SGMetarVisibility& getVertVisibility()   { return _vert_visibility; }
193         inline SGMetarVisibility *getDirVisibility()    { return _dir_visibility; }
194
195         inline double   getTemperature_C()      const { return _temp; }
196         inline double   getTemperature_F()      const { return _temp == NaN ? NaN : 1.8 * _temp + 32; }
197         inline double   getDewpoint_C()         const { return _dewp; }
198         inline double   getDewpoint_F()         const { return _dewp == NaN ? NaN : 1.8 * _dewp + 32; }
199         inline double   getPressure_hPa()       const { return _pressure == NaN ? NaN : _pressure / 100; }
200         inline double   getPressure_inHg()      const { return _pressure == NaN ? NaN : _pressure * SG_PA_TO_INHG; }
201
202         double          getRelHumidity()        const;
203
204         inline vector<SGMetarCloud>& getClouds()        { return _clouds; }
205         inline map<string, SGMetarRunway>& getRunways() { return _runways; }
206         inline vector<string>& getWeather()             { return _weather; }
207
208 protected:
209         int     _grpcount;
210         char    *_data;
211         char    *_m;
212         char    _icao[5];
213         int     _year;
214         int     _month;
215         int     _day;
216         int     _hour;
217         int     _minute;
218         int     _report_type;
219         int     _wind_dir;
220         double  _wind_speed;
221         double  _gust_speed;
222         int     _wind_range_from;
223         int     _wind_range_to;
224         double  _temp;
225         double  _dewp;
226         double  _pressure;
227
228         SGMetarVisibility               _min_visibility;
229         SGMetarVisibility               _max_visibility;
230         SGMetarVisibility               _vert_visibility;
231         SGMetarVisibility               _dir_visibility[8];
232         vector<SGMetarCloud>            _clouds;
233         map<string, SGMetarRunway>      _runways;
234         vector<string>                  _weather;
235
236         bool    scanPreambleDate();
237         bool    scanPreambleTime();
238
239         bool    scanType();
240         bool    scanId();
241         bool    scanDate();
242         bool    scanModifier();
243         bool    scanWind();
244         bool    scanVariability();
245         bool    scanVisibility();
246         bool    scanRwyVisRange();
247         bool    scanSkyCondition();
248         bool    scanWeather();
249         bool    scanTemperature();
250         bool    scanPressure();
251         bool    scanRunwayReport();
252         bool    scanWindShear();
253         bool    scanTrendForecast();
254         bool    scanColorState();
255         bool    scanRemark();
256         bool    scanRemainder();
257
258         int     scanNumber(char **str, int *num, int min, int max = 0);
259         bool    scanBoundary(char **str);
260         const struct Token *scanToken(char **str, const struct Token *list);
261         char    *loadData(const char *id);
262         void    normalizeData();
263 };
264
265 #undef NaN
266 #endif // _METAR_HXX