1 // metar interface class
3 // Written by Melchior FRANZ, started January 2005.
5 // Copyright (C) 2005 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.
25 * Implements FGMetar class that inherits from SGMetar.
27 * o provide defaults for unset values
28 * o interpolate/randomize data (GREATER_THAN)
29 * o derive additional values (time, age, snow cover)
30 * o consider minimum identifier (CAVOK, mil. color codes)
33 * - NSC & mil. color codes
43 #include <simgear/math/sg_random.h>
44 #include <simgear/timing/sg_time.hxx>
45 #include <Main/fg_props.hxx>
47 #include "fgmetar.hxx"
50 FGMetar::FGMetar(const string& icao, const string& proxy, const string& port, const string& auth) :
51 SGMetar(icao, proxy, port, auth, _rq_time = globals->get_time_params()->get_cur_time()),
57 // CAVOK: visibility >= 10km; lowest cloud layer >= 5000 ft; any coverage
59 if (_min_visibility.getVisibility_m() == SGMetarNaN)
60 _min_visibility.set(12000.0);
62 if (_max_visibility.getVisibility_m() == SGMetarNaN)
63 _min_visibility.set(12000.0);
65 vector<SGMetarCloud> cv = _clouds;;
68 cl.set(5500 * SG_FEET_TO_METER, 2);
69 _clouds.push_back(cl);
74 d = _min_visibility.getVisibility_m();
77 if (_min_visibility.getModifier() == SGMetarVisibility::GREATER_THAN)
78 d += 15000.0;// * sg_random();
79 _min_visibility.set(d);
81 if (_max_visibility.getVisibility_m() == SGMetarNaN)
82 _max_visibility.set(d);
84 for (i = 0; i < 8; i++) {
85 d = _dir_visibility[i].getVisibility_m();
87 _dir_visibility[i].set(10000.0);
88 if (_dir_visibility[i].getModifier() == SGMetarVisibility::GREATER_THAN)
89 d += 15000.0;// * sg_random();
90 _dir_visibility[i].set(d);
94 if (_wind_dir == -1) {
95 if (_wind_range_from == -1) {
100 _wind_dir = (_wind_range_from + _wind_range_to) / 2;
102 } else if (_wind_range_from == -1) {
103 _wind_range_from = _wind_range_to = _wind_dir;
106 if (_gust_speed == SGMetarNaN)
110 vector<SGMetarCloud> cv = _clouds;
111 vector<SGMetarCloud>::iterator cloud;
113 for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {
114 int cov = cloud->getCoverage();
118 double alt = cloud->getAltitude_ft();
119 if (alt == SGMetarNaN)
122 cloud->set(alt, cov);
126 // temperature/pressure
127 if (_temp == SGMetarNaN)
130 if (_dewp == SGMetarNaN)
133 if (_pressure == SGMetarNaN)
134 _pressure = 30.0 * SG_INHG_TO_PA;
137 map<string, SGMetarRunway> rm = getRunways();
138 map<string, SGMetarRunway>::const_iterator runway;
139 for (runway = rm.begin(); runway != rm.end(); runway++) {
140 SGMetarRunway rwy = runway->second;
141 if (rwy.getDeposit() >= 3 ) {
146 if (_temp < 5.0 && _snow)
148 if (_temp < 1.0 && getRelHumidity() > 80)
151 _time = sgTimeGetGMT(_year - 1900, _month - 1, _day, _hour, _minute, 0);
153 SG_LOG(SG_GENERAL, SG_INFO, _data);
155 SG_LOG(SG_GENERAL, SG_INFO, "METAR from proxy");
157 SG_LOG(SG_GENERAL, SG_INFO, "METAR from weather.noaa.gov");
161 long FGMetar::getAge_min() const
163 time_t now = _x_proxy ? _rq_time : time(0);
164 return (now - _time) / 60;