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>
36 const double SGMetarNaN = -1E20;
37 #define NaN SGMetarNaN
47 class SGMetarVisibility {
70 void set(double dist, int dir = -1, int mod = -1, int tend = -1);
72 inline double getVisibility_m() const { return _distance; }
73 inline double getVisibility_ft() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_FEET; }
74 inline double getVisibility_sm() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_SM; }
75 inline int getDirection() const { return _direction; }
76 inline int getModifier() const { return _modifier; }
77 inline int getTendency() const { return _tendency; }
87 // runway condition (surface and visibility)
100 _wind_shear(false) {}
102 inline int getDeposit() const { return _deposit; }
103 inline const char *getDepositString() const { return _deposit_string; }
104 inline double getExtent() const { return _extent; }
105 inline const char *getExtentString() const { return _extent_string; }
106 inline double getDepth() const { return _depth; }
107 inline double getFriction() const { return _friction; }
108 inline const char *getFrictionString() const { return _friction_string; }
109 inline const char *getComment() const { return _comment; }
110 inline const bool getWindShear() const { return _wind_shear; }
111 inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
112 inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
115 SGMetarVisibility _min_visibility;
116 SGMetarVisibility _max_visibility;
118 const char *_deposit_string;
120 const char *_extent_string;
123 const char *_friction_string;
124 const char *_comment;
131 friend class SGMetar;
137 COVERAGE_SCATTERED = 2,
139 COVERAGE_OVERCAST = 4
142 SGMetarCloud() : _coverage(COVERAGE_NIL), _altitude(NaN), _type(0), _type_long(0) {}
144 void set(double alt, Coverage cov = COVERAGE_NIL );
146 inline Coverage getCoverage() const { return _coverage; }
147 inline double getAltitude_m() const { return _altitude; }
148 inline double getAltitude_ft() const { return _altitude == NaN ? NaN : _altitude * SG_METER_TO_FEET; }
149 inline const char *getTypeString() const { return _type; }
150 inline const char *getTypeLongString() const { return _type_long; }
153 Coverage _coverage; // quarters: 0 -> clear ... 4 -> overcast
154 double _altitude; // 1000 m
155 const char *_type; // CU
156 const char *_type_long; // cumulus
162 SGMetar(const string& m, const string& proxy = "", const string& port = "",
163 const string &auth = "", const time_t time = 0);
181 Weather() { intensity = NIL; vincinity = false; }
184 vector<string> descriptions;
185 vector<string> phenomena;
188 inline const char *getData() const { return _data; }
189 inline const char *getUnusedData() const { return _m; }
190 inline const bool getProxy() const { return _x_proxy; }
191 inline const char *getId() const { return _icao; }
192 inline int getYear() const { return _year; }
193 inline int getMonth() const { return _month; }
194 inline int getDay() const { return _day; }
195 inline int getHour() const { return _hour; }
196 inline int getMinute() const { return _minute; }
197 inline int getReportType() const { return _report_type; }
199 inline int getWindDir() const { return _wind_dir; }
200 inline double getWindSpeed_mps() const { return _wind_speed; }
201 inline double getWindSpeed_kmh() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KMH; }
202 inline double getWindSpeed_kt() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KT; }
203 inline double getWindSpeed_mph() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_MPH; }
205 inline double getGustSpeed_mps() const { return _gust_speed; }
206 inline double getGustSpeed_kmh() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KMH; }
207 inline double getGustSpeed_kt() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KT; }
208 inline double getGustSpeed_mph() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_MPH; }
210 inline int getWindRangeFrom() const { return _wind_range_from; }
211 inline int getWindRangeTo() const { return _wind_range_to; }
213 inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
214 inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
215 inline const SGMetarVisibility& getVertVisibility() const { return _vert_visibility; }
216 inline const SGMetarVisibility *getDirVisibility() const { return _dir_visibility; }
218 inline double getTemperature_C() const { return _temp; }
219 inline double getTemperature_F() const { return _temp == NaN ? NaN : 1.8 * _temp + 32; }
220 inline double getDewpoint_C() const { return _dewp; }
221 inline double getDewpoint_F() const { return _dewp == NaN ? NaN : 1.8 * _dewp + 32; }
222 inline double getPressure_hPa() const { return _pressure == NaN ? NaN : _pressure / 100; }
223 inline double getPressure_inHg() const { return _pressure == NaN ? NaN : _pressure * SG_PA_TO_INHG; }
225 inline int getRain() const { return _rain; }
226 inline int getHail() const { return _hail; }
227 inline int getSnow() const { return _snow; }
228 inline bool getCAVOK() const { return _cavok; }
230 double getRelHumidity() const;
232 inline const vector<SGMetarCloud>& getClouds() const { return _clouds; }
233 inline const map<string, SGMetarRunway>& getRunways() const { return _runways; }
234 inline const vector<string>& getWeather() const { return _weather; }
235 inline const vector<struct Weather> getWeather2() const { return _weather2; }
253 int _wind_range_from;
262 vector<struct Weather> _weather2;
264 SGMetarVisibility _min_visibility;
265 SGMetarVisibility _max_visibility;
266 SGMetarVisibility _vert_visibility;
267 SGMetarVisibility _dir_visibility[8];
268 vector<SGMetarCloud> _clouds;
269 map<string, SGMetarRunway> _runways;
270 vector<string> _weather;
272 bool scanPreambleDate();
273 bool scanPreambleTime();
274 void useCurrentDate();
281 bool scanVariability();
282 bool scanVisibility();
283 bool scanRwyVisRange();
284 bool scanSkyCondition();
286 bool scanTemperature();
288 bool scanRunwayReport();
289 bool scanWindShear();
290 bool scanTrendForecast();
291 bool scanColorState();
293 bool scanRemainder();
295 int scanNumber(char **str, int *num, int min, int max = 0);
296 bool scanBoundary(char **str);
297 const struct Token *scanToken(char **str, const struct Token *list);
298 char *loadData(const char *id, const string& proxy, const string& port,
299 const string &auth, time_t time);
300 void normalizeData();