00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _METAR_HXX
00024 #define _METAR_HXX
00025
00026 #include <vector>
00027 #include <map>
00028 #include <string>
00029
00030 #include <simgear/constants.h>
00031
00032 using std::vector;
00033 using std::map;
00034 using std::string;
00035
00036 const double SGMetarNaN = -1E20;
00037 #define NaN SGMetarNaN
00038
00039 struct Token {
00040 const char *id;
00041 const char *text;
00042 };
00043
00044
00045 class SGMetar;
00046
00047 class SGMetarVisibility {
00048 friend class SGMetar;
00049 public:
00050 SGMetarVisibility() :
00051 _distance(NaN),
00052 _direction(-1),
00053 _modifier(EQUALS),
00054 _tendency(NONE) {}
00055
00056 enum Modifier {
00057 NOGO,
00058 EQUALS,
00059 LESS_THAN,
00060 GREATER_THAN
00061 };
00062
00063 enum Tendency {
00064 NONE,
00065 STABLE,
00066 INCREASING,
00067 DECREASING
00068 };
00069
00070 void set(double dist, int dir = -1, int mod = -1, int tend = -1);
00071
00072 inline double getVisibility_m() const { return _distance; }
00073 inline double getVisibility_ft() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_FEET; }
00074 inline double getVisibility_sm() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_SM; }
00075 inline int getDirection() const { return _direction; }
00076 inline int getModifier() const { return _modifier; }
00077 inline int getTendency() const { return _tendency; }
00078
00079 protected:
00080 double _distance;
00081 int _direction;
00082 int _modifier;
00083 int _tendency;
00084 };
00085
00086
00087
00088 class SGMetarRunway {
00089 friend class SGMetar;
00090 public:
00091 SGMetarRunway() :
00092 _deposit(-1),
00093 _deposit_string(0),
00094 _extent(-1),
00095 _extent_string(0),
00096 _depth(NaN),
00097 _friction(NaN),
00098 _friction_string(0),
00099 _comment(0),
00100 _wind_shear(false) {}
00101
00102 inline int getDeposit() const { return _deposit; }
00103 inline const char *getDepositString() const { return _deposit_string; }
00104 inline double getExtent() const { return _extent; }
00105 inline const char *getExtentString() const { return _extent_string; }
00106 inline double getDepth() const { return _depth; }
00107 inline double getFriction() const { return _friction; }
00108 inline const char *getFrictionString() const { return _friction_string; }
00109 inline const char *getComment() const { return _comment; }
00110 inline const bool getWindShear() const { return _wind_shear; }
00111 inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
00112 inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
00113
00114 protected:
00115 SGMetarVisibility _min_visibility;
00116 SGMetarVisibility _max_visibility;
00117 int _deposit;
00118 const char *_deposit_string;
00119 int _extent;
00120 const char *_extent_string;
00121 double _depth;
00122 double _friction;
00123 const char *_friction_string;
00124 const char *_comment;
00125 bool _wind_shear;
00126 };
00127
00128
00129
00130 class SGMetarCloud {
00131 friend class SGMetar;
00132 public:
00133 SGMetarCloud() : _coverage(-1), _altitude(NaN), _type(0), _type_long(0) {}
00134
00135 void set(double alt, int cov = -1);
00136
00137 inline int getCoverage() const { return _coverage; }
00138 inline double getAltitude_m() const { return _altitude; }
00139 inline double getAltitude_ft() const { return _altitude == NaN ? NaN : _altitude * SG_METER_TO_FEET; }
00140 inline const char *getTypeString() const { return _type; }
00141 inline const char *getTypeLongString() const { return _type_long; }
00142
00143 protected:
00144 int _coverage;
00145 double _altitude;
00146 const char *_type;
00147 const char *_type_long;
00148 };
00149
00150
00151 class SGMetar {
00152 public:
00153 SGMetar(const string& m, const string& proxy = "", const string& port = "",
00154 const string &auth = "", const time_t time = 0);
00155 ~SGMetar();
00156
00157 enum ReportType {
00158 NONE,
00159 AUTO,
00160 COR,
00161 RTD
00162 };
00163
00164 inline const char *getData() const { return _data; }
00165 inline const char *getUnusedData() const { return _m; }
00166 inline const bool getProxy() const { return _x_proxy; }
00167 inline const char *getId() const { return _icao; }
00168 inline int getYear() const { return _year; }
00169 inline int getMonth() const { return _month; }
00170 inline int getDay() const { return _day; }
00171 inline int getHour() const { return _hour; }
00172 inline int getMinute() const { return _minute; }
00173 inline int getReportType() const { return _report_type; }
00174
00175 inline int getWindDir() const { return _wind_dir; }
00176 inline double getWindSpeed_mps() const { return _wind_speed; }
00177 inline double getWindSpeed_kmh() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KMH; }
00178 inline double getWindSpeed_kt() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KT; }
00179 inline double getWindSpeed_mph() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_MPH; }
00180
00181 inline double getGustSpeed_mps() const { return _gust_speed; }
00182 inline double getGustSpeed_kmh() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KMH; }
00183 inline double getGustSpeed_kt() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KT; }
00184 inline double getGustSpeed_mph() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_MPH; }
00185
00186 inline int getWindRangeFrom() const { return _wind_range_from; }
00187 inline int getWindRangeTo() const { return _wind_range_to; }
00188
00189 inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; }
00190 inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; }
00191 inline const SGMetarVisibility& getVertVisibility() const { return _vert_visibility; }
00192 inline const SGMetarVisibility *getDirVisibility() const { return _dir_visibility; }
00193
00194 inline double getTemperature_C() const { return _temp; }
00195 inline double getTemperature_F() const { return _temp == NaN ? NaN : 1.8 * _temp + 32; }
00196 inline double getDewpoint_C() const { return _dewp; }
00197 inline double getDewpoint_F() const { return _dewp == NaN ? NaN : 1.8 * _dewp + 32; }
00198 inline double getPressure_hPa() const { return _pressure == NaN ? NaN : _pressure / 100; }
00199 inline double getPressure_inHg() const { return _pressure == NaN ? NaN : _pressure * SG_PA_TO_INHG; }
00200
00201 inline int getRain() const { return _rain; }
00202 inline int getHail() const { return _hail; }
00203 inline int getSnow() const { return _snow; }
00204 inline bool getCAVOK() const { return _cavok; }
00205
00206 double getRelHumidity() const;
00207
00208 inline const vector<SGMetarCloud>& getClouds() const { return _clouds; }
00209 inline const map<string, SGMetarRunway>& getRunways() const { return _runways; }
00210 inline const vector<string>& getWeather() const { return _weather; }
00211
00212 protected:
00213 string _url;
00214 int _grpcount;
00215 bool _x_proxy;
00216 char *_data;
00217 char *_m;
00218 char _icao[5];
00219 int _year;
00220 int _month;
00221 int _day;
00222 int _hour;
00223 int _minute;
00224 int _report_type;
00225 int _wind_dir;
00226 double _wind_speed;
00227 double _gust_speed;
00228 int _wind_range_from;
00229 int _wind_range_to;
00230 double _temp;
00231 double _dewp;
00232 double _pressure;
00233 int _rain;
00234 int _hail;
00235 int _snow;
00236 bool _cavok;
00237
00238 SGMetarVisibility _min_visibility;
00239 SGMetarVisibility _max_visibility;
00240 SGMetarVisibility _vert_visibility;
00241 SGMetarVisibility _dir_visibility[8];
00242 vector<SGMetarCloud> _clouds;
00243 map<string, SGMetarRunway> _runways;
00244 vector<string> _weather;
00245
00246 bool scanPreambleDate();
00247 bool scanPreambleTime();
00248 void useCurrentDate();
00249
00250 bool scanType();
00251 bool scanId();
00252 bool scanDate();
00253 bool scanModifier();
00254 bool scanWind();
00255 bool scanVariability();
00256 bool scanVisibility();
00257 bool scanRwyVisRange();
00258 bool scanSkyCondition();
00259 bool scanWeather();
00260 bool scanTemperature();
00261 bool scanPressure();
00262 bool scanRunwayReport();
00263 bool scanWindShear();
00264 bool scanTrendForecast();
00265 bool scanColorState();
00266 bool scanRemark();
00267 bool scanRemainder();
00268
00269 int scanNumber(char **str, int *num, int min, int max = 0);
00270 bool scanBoundary(char **str);
00271 const struct Token *scanToken(char **str, const struct Token *list);
00272 char *loadData(const char *id, const string& proxy, const string& port,
00273 const string &auth, time_t time);
00274 void normalizeData();
00275 };
00276
00277 #undef NaN
00278 #endif // _METAR_HXX