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