]> git.mxchange.org Git - simgear.git/blob - simgear/metar/MetarReport.cpp
MSVC warning fixes
[simgear.git] / simgear / metar / MetarReport.cpp
1 // Metar report implementation class code
2
3 #include <simgear/compiler.h>
4
5 #include STL_IOSTREAM
6
7 #include "MetarReport.h"
8 #include "Metar.h"
9
10 SG_USING_STD(endl);
11 SG_USING_STD(ostream);
12
13 CMetarReport::CMetarReport(
14    char *s ) :
15                 m_DecodedReport( 0 )
16 {
17         m_DecodedReport = new Decoded_METAR;
18         DcdMETAR( s, (Decoded_METAR *)m_DecodedReport );
19 }
20
21
22 CMetarReport::~CMetarReport()
23 {
24 }
25
26 static int DecodeDirChars( char* c )
27 {
28         int r = 0;
29
30         if ( c[0] )
31         {
32                 if ( c[0] == 'E' ) r = 90;
33                 else if ( c[0] == 'S' ) r = 180;
34                 else if ( c[0] == 'W' ) r = 270;
35
36                 if ( r == 0 )
37                 {
38                         if ( c[1] == 'E' ) r = 45;
39                         else if ( c[1] == 'W' ) r = 315;
40                 }
41                 else if ( r == 180 )
42                 {
43                         if ( c[1] == 'E' ) r = 135;
44                         else if ( c[1] == 'W' ) r = 225;
45                 }
46         }
47         return r;
48 }
49
50 char *CMetarReport::StationID()
51 {
52         return ((Decoded_METAR *)m_DecodedReport)->stnid;
53 }
54
55 int CMetarReport::Day() 
56 {
57   return ((Decoded_METAR*)m_DecodedReport)->ob_date;
58 }
59
60 int CMetarReport::Hour() 
61 {
62   return ((Decoded_METAR*)m_DecodedReport)->ob_hour;
63 }
64
65 int CMetarReport::Minutes() 
66 {
67   return ((Decoded_METAR*)m_DecodedReport)->ob_minute;
68 }
69
70 int CMetarReport::WindDirection()
71 {
72         return ((Decoded_METAR *)m_DecodedReport)->winData.windDir;
73 }
74
75 int CMetarReport::WindSpeed()
76 {
77         return ((Decoded_METAR *)m_DecodedReport)->winData.windSpeed;
78 }
79
80 int CMetarReport::WindGustSpeed()
81 {
82         return ((Decoded_METAR *)m_DecodedReport)->winData.windGust;
83 }
84
85 int CMetarReport::LightningDirection()
86 {
87         return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->LTG_DIR );
88 }
89
90 char CMetarReport::CloudLow()
91 {
92         return ((Decoded_METAR *)m_DecodedReport)->CloudLow;
93 }
94
95 char CMetarReport::CloudMedium()
96 {
97         return ((Decoded_METAR *)m_DecodedReport)->CloudMedium;
98 }
99
100 char CMetarReport::CloudHigh()
101 {
102         return ((Decoded_METAR *)m_DecodedReport)->CloudHigh;
103 }
104
105 int CMetarReport::VirgaDirection()
106 {
107         return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->VIRGA_DIR );
108 }
109
110 int CMetarReport::TornadicDirection()
111 {
112         return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TornadicDIR );
113 }
114
115 int CMetarReport::TornadicMovementDirection()
116 {
117         return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TornadicMovDir );
118 }
119
120 int CMetarReport::ThunderStormDirection()
121 {
122         return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TS_LOC );
123 }
124
125 int CMetarReport::ThunderStormMovementDirection()
126 {
127         return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TS_MOVMNT );
128 }
129
130 bool CMetarReport::Virga()
131 {
132         return ((Decoded_METAR *)m_DecodedReport)->VIRGA;
133 }
134
135 bool CMetarReport::VolcanicAsh()
136 {
137         return ((Decoded_METAR *)m_DecodedReport)->VOLCASH;
138 }
139
140 bool CMetarReport::Hail()
141 {
142         return ((Decoded_METAR *)m_DecodedReport)->GR;
143 }
144
145 bool CMetarReport::OccationalLightning()
146 {
147         return ((Decoded_METAR *)m_DecodedReport)->OCNL_LTG;
148 }
149
150 bool CMetarReport::FrequentLightning()
151 {
152         return ((Decoded_METAR *)m_DecodedReport)->FRQ_LTG;
153 }
154
155 bool CMetarReport::ContinuousLightning()
156 {
157         return ((Decoded_METAR *)m_DecodedReport)->CNS_LTG;
158 }
159
160 bool CMetarReport::CloudToGroundLightning()
161 {
162         return ((Decoded_METAR *)m_DecodedReport)->CG_LTG;
163 }
164
165 bool CMetarReport::InterCloudLightning()
166 {
167         return ((Decoded_METAR *)m_DecodedReport)->IC_LTG;
168 }
169
170 bool CMetarReport::CloudToCloudLightning()
171 {
172         return ((Decoded_METAR *)m_DecodedReport)->CC_LTG;
173 }
174
175 bool CMetarReport::CloudToAirLightning()
176 {
177         return ((Decoded_METAR *)m_DecodedReport)->CA_LTG;
178 }
179
180 bool CMetarReport::DistantLightning()
181 {
182         return ((Decoded_METAR *)m_DecodedReport)->DSNT_LTG;
183 }
184
185 bool CMetarReport::AirportLightning()
186 {
187         return ((Decoded_METAR *)m_DecodedReport)->AP_LTG;
188 }
189
190 bool CMetarReport::VicinityLightning()
191 {
192         return ((Decoded_METAR *)m_DecodedReport)->VcyStn_LTG;
193 }
194
195 bool CMetarReport::OverheadLightning()
196 {
197         return ((Decoded_METAR *)m_DecodedReport)->OVHD_LTG;
198 }
199
200 int CMetarReport::Temperature()
201 {
202         return ((Decoded_METAR *)m_DecodedReport)->temp;
203 }
204
205 int CMetarReport::DewpointTemperature()
206 {
207         return ((Decoded_METAR *)m_DecodedReport)->dew_pt_temp;
208 }
209
210 int CMetarReport::VerticalVisibility() // Meters
211 {
212         return ((Decoded_METAR *)m_DecodedReport)->VertVsby;
213 }
214
215 int CMetarReport::Ceiling()
216 {
217         return
218             (int)(SG_FEET_TO_METER*((Decoded_METAR *)m_DecodedReport)->Ceiling);
219 }
220
221 int CMetarReport::EstimatedCeiling()
222 {
223         return
224             (int)(SG_FEET_TO_METER
225                   * ((Decoded_METAR *)m_DecodedReport)->Estimated_Ceiling);
226 }
227
228 int CMetarReport::VariableSkyLayerHeight()
229 {
230         return
231             (int)(SG_FEET_TO_METER
232                   * ((Decoded_METAR *)m_DecodedReport)->VrbSkyLayerHgt);
233 }
234
235 int CMetarReport::SnowDepthInches()
236 {
237         return ((Decoded_METAR *)m_DecodedReport)->snow_depth;
238 }
239
240
241 ostream&
242 operator << ( ostream& out, CMetarReport& p )
243 {
244     return out 
245         << "StationID " << p.StationID()
246         << " WindDirection " << p.WindDirection()
247         << " WindSpeed " << p.WindSpeed()
248         << " WindGustSpeed " << p.WindGustSpeed() << endl
249         << "CloudLow " << p.CloudLow()
250         << " CloudMedium " << p.CloudMedium()
251         << " CloudHigh " << p.CloudHigh() << endl
252         << "TornadicDirection " << p.TornadicDirection()
253         << " TornadicMovementDirection " << p.TornadicMovementDirection() << endl
254         << "ThunderStormDirection " << p.ThunderStormDirection()
255         << " ThunderStormMovementDirection " << p.ThunderStormMovementDirection() << endl
256         << "Virga " << p.Virga()
257         << " VirgaDirection " << p.VirgaDirection() << endl
258         << "VolcanicAsh " << p.VolcanicAsh() << endl
259         << "Hail " << p.Hail() << endl
260         << "LightningDirection " << p.LightningDirection()
261         << " OccationalLightning " << p.OccationalLightning()
262         << " FrequentLightning " << p.FrequentLightning()
263         << " ContinuousLightning " << p.ContinuousLightning() << endl
264         << "CloudToGroundLightning " << p.CloudToGroundLightning()
265         << " InterCloudLightning " << p.InterCloudLightning()
266         << " CloudToCloudLightning " << p.CloudToCloudLightning()
267         << " CloudToAirLightning " << p.CloudToAirLightning() << endl
268         << "DistantLightning " << p.DistantLightning()
269         << " AirportLightning " << p.AirportLightning()
270         << " VicinityLightning " << p.VicinityLightning()
271         << " OverheadLightning " << p.OverheadLightning() << endl
272         << "VerticalVisibility " << p.VerticalVisibility() << endl // Meters
273         << "Temperature " << p.Temperature() 
274         << " DewpointTemperature " << p.DewpointTemperature() << endl
275         << "Ceiling " << p.Ceiling()
276         << " EstimatedCeiling " << p.EstimatedCeiling()
277         << " VariableSkyLayerHeight " << p.VariableSkyLayerHeight() << endl
278         << "SnowDepthInches " << p.SnowDepthInches() << endl
279         ;
280 }
281
282
283 double CMetarReport::AirPressure()
284 {
285     return ((Decoded_METAR *)m_DecodedReport)->inches_altstng;
286 }
287
288 void CMetarReport::dump()
289 {
290         prtDMETR( (Decoded_METAR *)m_DecodedReport );
291 }
292
293 double CMetarReport::PrevailVisibility()
294 {
295   //Values from each visibility field converted to meters.
296   double smiles;
297   double km;
298   double meters;
299   smiles = ((Decoded_METAR*) m_DecodedReport)->prevail_vsbySM * 1609.34;
300   km =  ((Decoded_METAR*) m_DecodedReport)->prevail_vsbyKM * 1000;
301   meters =  ((Decoded_METAR*) m_DecodedReport)->prevail_vsbyM;
302   
303   /* Return the smallest one. If the field is specified it should have been
304      set to MAX_INT */
305   if(smiles < km && smiles < meters) 
306     return smiles;
307   else 
308     return km < meters ? km : meters; 
309 }