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, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
30 #include <simgear/constants.h>
36 const double SGMetarNaN = -1E20;
37 #define NaN SGMetarNaN
47 class SGMetarVisibility {
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; }
85 // runway condition (surface and visibility)
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; }
111 SGMetarVisibility _min_visibility;
112 SGMetarVisibility _max_visibility;
113 const char *_deposit;
115 const char *_extent_string;
118 const char *_friction_string;
119 const char *_comment;
126 friend class SGMetar;
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; }
141 int _coverage; // quarters: 0 -> clear ... 4 -> overcast
142 double _altitude; // 1000 m
144 char *_type_long; // cumulus
150 SGMetar(const string& m, const string& proxy = "", const string& port = "", const string &auth = "");
160 inline const char *getData() const { return _data; }
161 inline const char *getUnusedData() const { return _m; }
162 inline const char *getId() const { return _icao; }
163 inline int getYear() const { return _year; }
164 inline int getMonth() const { return _month; }
165 inline int getDay() const { return _day; }
166 inline int getHour() const { return _hour; }
167 inline int getMinute() const { return _minute; }
168 inline int getReportType() const { return _report_type; }
170 inline int getWindDir() const { return _wind_dir; }
171 inline double getWindSpeed_mps() const { return _wind_speed; }
172 inline double getWindSpeed_kmh() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KMH; }
173 inline double getWindSpeed_kt() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KT; }
174 inline double getWindSpeed_mph() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_MPH; }
176 inline double getGustSpeed_mps() const { return _gust_speed; }
177 inline double getGustSpeed_kmh() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KMH; }
178 inline double getGustSpeed_kt() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KT; }
179 inline double getGustSpeed_mph() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_MPH; }
181 inline int getWindRangeFrom() const { return _wind_range_from; }
182 inline int getWindRangeTo() const { return _wind_range_to; }
184 inline SGMetarVisibility& getMinVisibility() { return _min_visibility; }
185 inline SGMetarVisibility& getMaxVisibility() { return _max_visibility; }
186 inline SGMetarVisibility& getVertVisibility() { return _vert_visibility; }
187 inline SGMetarVisibility *getDirVisibility() { return _dir_visibility; }
189 inline double getTemperature_C() const { return _temp; }
190 inline double getTemperature_F() const { return _temp == NaN ? NaN : 1.8 * _temp + 32; }
191 inline double getDewpoint_C() const { return _dewp; }
192 inline double getDewpoint_F() const { return _dewp == NaN ? NaN : 1.8 * _dewp + 32; }
193 inline double getPressure_hPa() const { return _pressure == NaN ? NaN : _pressure / 100; }
194 inline double getPressure_inHg() const { return _pressure == NaN ? NaN : _pressure * SG_PA_TO_INHG; }
196 double getRelHumidity() const;
198 inline vector<SGMetarCloud>& getClouds() { return _clouds; }
199 inline map<string, SGMetarRunway>& getRunways() { return _runways; }
200 inline vector<string>& getWeather() { return _weather; }
217 int _wind_range_from;
223 SGMetarVisibility _min_visibility;
224 SGMetarVisibility _max_visibility;
225 SGMetarVisibility _vert_visibility;
226 SGMetarVisibility _dir_visibility[8];
227 vector<SGMetarCloud> _clouds;
228 map<string, SGMetarRunway> _runways;
229 vector<string> _weather;
231 bool scanPreambleDate();
232 bool scanPreambleTime();
239 bool scanVariability();
240 bool scanVisibility();
241 bool scanRwyVisRange();
242 bool scanSkyCondition();
244 bool scanTemperature();
246 bool scanRunwayReport();
247 bool scanWindShear();
248 bool scanTrendForecast();
249 bool scanColorState();
251 bool scanRemainder();
253 int scanNumber(char **str, int *num, int min, int max = 0);
254 bool scanBoundary(char **str);
255 const struct Token *scanToken(char **str, const struct Token *list);
256 char *loadData(const char *id, const string& proxy, const string& port, const string &auth);
257 void normalizeData();