1 // metar interface class
3 // Written by Melchior FRANZ, started December 2003.
5 // Copyright (C) 2003 Melchior FRANZ - mfranz@aon.at
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.
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.
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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <simgear/constants.h>
37 const double SGMetarNaN = -1E20;
41 class SGMetarVisibility {
45 _distance(SGMetarNaN),
64 void set(double dist, int dir = -1, int mod = -1, int tend = -1);
66 inline double getVisibility_m() const { return _distance; }
67 inline double getVisibility_ft() const { return _distance == SGMetarNaN ? SGMetarNaN : _distance * SG_METER_TO_FEET; }
68 inline double getVisibility_sm() const { return _distance == SGMetarNaN ? SGMetarNaN : _distance * SG_METER_TO_SM; }
69 inline int getDirection() const { return _direction; }
70 inline int getModifier() const { return _modifier; }
71 inline int getTendency() const { return _tendency; }
81 // runway condition (surface and visibility)
91 _friction(SGMetarNaN),
96 inline int getDeposit() const { return _deposit; }
97 inline const char *getDepositString() const { return _deposit_string; }
98 inline double getExtent() const { return _extent; }
99 inline const char *getExtentString() const { return _extent_string; }
100 inline double getDepth() const { return _depth; }
101 inline double getFriction() const { return _friction; }
102 inline const char *getFrictionString() const { return _friction_string; }
103 inline const char *getComment() const { return _comment; }
104 inline bool getWindShear() const { return _wind_shear; }
105 inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
106 inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
109 SGMetarVisibility _min_visibility;
110 SGMetarVisibility _max_visibility;
112 const char *_deposit_string;
114 const char *_extent_string;
117 const char *_friction_string;
118 const char *_comment;
125 friend class SGMetar;
131 COVERAGE_SCATTERED = 2,
133 COVERAGE_OVERCAST = 4
136 static const char * COVERAGE_NIL_STRING;
137 static const char * COVERAGE_CLEAR_STRING;
138 static const char * COVERAGE_FEW_STRING;
139 static const char * COVERAGE_SCATTERED_STRING;
140 static const char * COVERAGE_BROKEN_STRING;
141 static const char * COVERAGE_OVERCAST_STRING;
143 SGMetarCloud() : _coverage(COVERAGE_NIL), _altitude(SGMetarNaN), _type(0), _type_long(0) {}
145 void set(double alt, Coverage cov = COVERAGE_NIL );
147 inline Coverage getCoverage() const { return _coverage; }
148 static Coverage getCoverage( const std::string & coverage );
149 inline double getAltitude_m() const { return _altitude; }
150 inline double getAltitude_ft() const { return _altitude == SGMetarNaN ? SGMetarNaN : _altitude * SG_METER_TO_FEET; }
151 inline const char *getTypeString() const { return _type; }
152 inline const char *getTypeLongString() const { return _type_long; }
155 Coverage _coverage; // quarters: 0 -> clear ... 4 -> overcast
156 double _altitude; // 1000 m
157 const char *_type; // CU
158 const char *_type_long; // cumulus
164 SGMetar(const std::string& m);
182 Weather() { intensity = NIL; vincinity = false; }
185 std::vector<std::string> descriptions;
186 std::vector<std::string> phenomena;
189 inline const char *getData() const { return _data; }
190 inline const char *getUnusedData() const { return _m; }
191 inline bool getProxy() const { return _x_proxy; }
192 inline const char *getId() const { return _icao; }
193 inline int getYear() const { return _year; }
194 inline int getMonth() const { return _month; }
195 inline int getDay() const { return _day; }
196 inline int getHour() const { return _hour; }
197 inline int getMinute() const { return _minute; }
198 inline int getReportType() const { return _report_type; }
200 inline int getWindDir() const { return _wind_dir; }
201 inline double getWindSpeed_mps() const { return _wind_speed; }
202 inline double getWindSpeed_kmh() const { return _wind_speed == SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_KMH; }
203 inline double getWindSpeed_kt() const { return _wind_speed == SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_KT; }
204 inline double getWindSpeed_mph() const { return _wind_speed == SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_MPH; }
206 inline double getGustSpeed_mps() const { return _gust_speed; }
207 inline double getGustSpeed_kmh() const { return _gust_speed == SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_KMH; }
208 inline double getGustSpeed_kt() const { return _gust_speed == SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_KT; }
209 inline double getGustSpeed_mph() const { return _gust_speed == SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_MPH; }
211 inline int getWindRangeFrom() const { return _wind_range_from; }
212 inline int getWindRangeTo() const { return _wind_range_to; }
214 inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
215 inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
216 inline const SGMetarVisibility& getVertVisibility() const { return _vert_visibility; }
217 inline const SGMetarVisibility *getDirVisibility() const { return _dir_visibility; }
219 inline double getTemperature_C() const { return _temp; }
220 inline double getTemperature_F() const { return _temp == SGMetarNaN ? SGMetarNaN : 1.8 * _temp + 32; }
221 inline double getDewpoint_C() const { return _dewp; }
222 inline double getDewpoint_F() const { return _dewp == SGMetarNaN ? SGMetarNaN : 1.8 * _dewp + 32; }
223 inline double getPressure_hPa() const { return _pressure == SGMetarNaN ? SGMetarNaN : _pressure / 100; }
224 inline double getPressure_inHg() const { return _pressure == SGMetarNaN ? SGMetarNaN : _pressure * SG_PA_TO_INHG; }
226 inline int getRain() const { return _rain; }
227 inline int getHail() const { return _hail; }
228 inline int getSnow() const { return _snow; }
229 inline bool getCAVOK() const { return _cavok; }
231 double getRelHumidity() const;
233 inline const std::vector<SGMetarCloud>& getClouds() const { return _clouds; }
234 inline const std::map<std::string, SGMetarRunway>& getRunways() const { return _runways; }
235 inline const std::vector<std::string>& getWeather() const { return _weather; }
236 inline const std::vector<struct Weather> getWeather2() const { return _weather2; }
254 int _wind_range_from;
263 std::vector<struct Weather> _weather2;
265 SGMetarVisibility _min_visibility;
266 SGMetarVisibility _max_visibility;
267 SGMetarVisibility _vert_visibility;
268 SGMetarVisibility _dir_visibility[8];
269 std::vector<SGMetarCloud> _clouds;
270 std::map<std::string, SGMetarRunway> _runways;
271 std::vector<std::string> _weather;
273 bool scanPreambleDate();
274 bool scanPreambleTime();
275 void useCurrentDate();
282 bool scanVariability();
283 bool scanVisibility();
284 bool scanRwyVisRange();
285 bool scanSkyCondition();
287 bool scanTemperature();
289 bool scanRunwayReport();
290 bool scanWindShear();
291 bool scanTrendForecast();
292 bool scanColorState();
294 bool scanRemainder();
296 int scanNumber(char **str, int *num, int min, int max = 0);
297 bool scanBoundary(char **str);
298 const struct Token *scanToken(char **str, const struct Token *list);
299 void normalizeData();