4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Weather/TAF.hpp"
25 #include "Weather/METAR.hpp"
26 #include "Weather/NOAAStore.hpp"
27 #include "Weather/NOAAUpdater.hpp"
28 #include "Net/Init.hpp"
29 #include "ConsoleJobRunner.hpp"
30 #include "Units/Units.hpp"
31 #include "Formatter/UserUnits.hpp"
32 #include "Formatter/GeoPointFormatter.hpp"
33 #include "Util/Macros.hpp"
38 DisplayParsedMETAR(const NOAAStore::Item
&station
)
40 if (!station
.parsed_metar_available
) {
41 printf("METAR parsing failed!\n");;
45 const ParsedMETAR
&parsed
= station
.parsed_metar
;
47 printf("Parsed Data:\n");
49 if (parsed
.name_available
)
50 _tprintf(_T("Name: %s\n"), parsed
.name
.c_str());
52 if (parsed
.location_available
) {
54 FormatGeoPoint(parsed
.location
, buffer
, ARRAY_SIZE(buffer
),
55 CoordinateFormat::DDMMSS
);
56 _tprintf(_T("Location: %s\n"), buffer
);
59 if (parsed
.qnh_available
) {
61 FormatUserPressure(parsed
.qnh
, buffer
, ARRAY_SIZE(buffer
));
62 _tprintf(_T("QNH: %s\n"), buffer
);
65 if (parsed
.wind_available
) {
67 FormatUserWindSpeed(parsed
.wind
.norm
, buffer
, ARRAY_SIZE(buffer
));
68 _tprintf(_T("Wind: %.0f" DEG
" %s\n"),
69 (double)parsed
.wind
.bearing
.Degrees(), buffer
);
72 if (parsed
.temperatures_available
) {
74 FormatUserTemperature(parsed
.temperature
, buffer
, ARRAY_SIZE(buffer
));
75 _tprintf(_T("Temperature: %s\n"), buffer
);
76 FormatUserTemperature(parsed
.dew_point
, buffer
, ARRAY_SIZE(buffer
));
77 _tprintf(_T("Dew point: %s\n"), buffer
);
80 if (parsed
.visibility_available
) {
82 if (parsed
.visibility
>= 9999)
83 _tcscpy(buffer
, _T("unlimited"));
85 fixed
visibility(parsed
.visibility
);
86 FormatUserDistanceSmart(visibility
, buffer
, ARRAY_SIZE(buffer
));
88 _tprintf(_T("Visibility: %s\n"), buffer
);
95 DisplayMETAR(const NOAAStore::Item
&station
)
97 if (!station
.metar_available
) {
98 printf("METAR Download failed!\n");;
102 const METAR
&metar
= station
.metar
;
104 printf("%02d.%02d.%04d %02d:%02d:%02d\n",
105 (unsigned)metar
.last_update
.day
,
106 (unsigned)metar
.last_update
.month
,
107 (unsigned)metar
.last_update
.year
,
108 (unsigned)metar
.last_update
.hour
,
109 (unsigned)metar
.last_update
.minute
,
110 (unsigned)metar
.last_update
.second
);
112 if (!metar
.content
.empty())
113 _tprintf(_T("%s\n\n"), metar
.content
.c_str());
115 if (!metar
.decoded
.empty())
116 _tprintf(_T("%s\n\n"), metar
.decoded
.c_str());
118 DisplayParsedMETAR(station
);
122 DisplayTAF(const NOAAStore::Item
&station
)
124 if (!station
.taf_available
) {
125 printf("TAF Download failed!\n");;
129 const TAF
&taf
= station
.taf
;
131 printf("%02d.%02d.%04d %02d:%02d:%02d\n",
132 (unsigned)taf
.last_update
.day
,
133 (unsigned)taf
.last_update
.month
,
134 (unsigned)taf
.last_update
.year
,
135 (unsigned)taf
.last_update
.hour
,
136 (unsigned)taf
.last_update
.minute
,
137 (unsigned)taf
.last_update
.second
);
139 if (!taf
.content
.empty())
140 _tprintf(_T("%s\n\n"), taf
.content
.c_str());
144 main(int argc
, char *argv
[])
147 printf("Usage: %s <code>[ <code> ...]\n", argv
[0]);
148 printf(" <code> is the four letter ICAO code (upper case)\n");
149 printf(" of the airport(s) you are requesting\n\n");
150 printf(" Example: %s EDDL\n", argv
[0]);
155 for (int i
= 1; i
< argc
; i
++) {
156 printf("Adding station %s\n", argv
[i
]);
157 store
.AddStation(argv
[i
]);
162 printf("Updating METAR and TAF ...\n");
163 ConsoleJobRunner runner
;
164 NOAAUpdater::Update(store
, runner
);
166 for (auto i
= store
.begin(), end
= store
.end(); i
!= end
; ++i
) {
168 printf("Station %s:\n\n", i
->code
);