]> git.mxchange.org Git - simgear.git/blob - simgear/metar/MetarReport.cpp
37b6a433e8fb7b50a55b5e9958ddcef5ba946629
[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 (FG_HAVE_NATIVE_SGI_COMPILERS)
11 FG_USING_STD(endl);
12 FG_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 FEET_TO_METER * ((Decoded_METAR *)m_DecodedReport)->Ceiling;
220 }
221
222 int CMetarReport::EstimatedCeiling()
223 {
224         return FEET_TO_METER * ((Decoded_METAR *)m_DecodedReport)->Estimated_Ceiling;
225 }
226
227 int CMetarReport::VariableSkyLayerHeight()
228 {
229         return FEET_TO_METER * ((Decoded_METAR *)m_DecodedReport)->VrbSkyLayerHgt;
230 }
231
232 int CMetarReport::SnowDepthInches()
233 {
234         return ((Decoded_METAR *)m_DecodedReport)->snow_depth;
235 }
236
237
238 ostream&
239 operator << ( ostream& out, CMetarReport& p )
240 {
241     return out 
242         << "StationID " << p.StationID()
243         << " WindDirection " << p.WindDirection()
244         << " WindSpeed " << p.WindSpeed()
245         << " WindGustSpeed " << p.WindGustSpeed() << endl
246         << "CloudLow " << p.CloudLow()
247         << " CloudMedium " << p.CloudMedium()
248         << " CloudHigh " << p.CloudHigh() << endl
249         << "TornadicDirection " << p.TornadicDirection()
250         << " TornadicMovementDirection " << p.TornadicMovementDirection() << endl
251         << "ThunderStormDirection " << p.ThunderStormDirection()
252         << " ThunderStormMovementDirection " << p.ThunderStormMovementDirection() << endl
253         << "Virga " << p.Virga()
254         << " VirgaDirection " << p.VirgaDirection() << endl
255         << "VolcanicAsh " << p.VolcanicAsh() << endl
256         << "Hail " << p.Hail() << endl
257         << "LightningDirection " << p.LightningDirection()
258         << " OccationalLightning " << p.OccationalLightning()
259         << " FrequentLightning " << p.FrequentLightning()
260         << " ContinuousLightning " << p.ContinuousLightning() << endl
261         << "CloudToGroundLightning " << p.CloudToGroundLightning()
262         << " InterCloudLightning " << p.InterCloudLightning()
263         << " CloudToCloudLightning " << p.CloudToCloudLightning()
264         << " CloudToAirLightning " << p.CloudToAirLightning() << endl
265         << "DistantLightning " << p.DistantLightning()
266         << " AirportLightning " << p.AirportLightning()
267         << " VicinityLightning " << p.VicinityLightning()
268         << " OverheadLightning " << p.OverheadLightning() << endl
269         << "VerticalVisibility " << p.VerticalVisibility() << endl // Meters
270         << "Temperature " << p.Temperature() 
271         << " DewpointTemperature " << p.DewpointTemperature() << endl
272         << "Ceiling " << p.Ceiling()
273         << " EstimatedCeiling " << p.EstimatedCeiling()
274         << " VariableSkyLayerHeight " << p.VariableSkyLayerHeight() << endl
275         << "SnowDepthInches " << p.SnowDepthInches() << endl
276         ;
277 }
278
279
280 double CMetarReport::AirPressure() 
281 {
282   return ((Decoded_METAR *)m_DecodedReport)->inches_altstng;
283 }
284
285 void CMetarReport::dump()
286 {
287         prtDMETR( (Decoded_METAR *)m_DecodedReport );
288 }
289
290 double CMetarReport::PrevailVisibility() {
291   //Values from each visibility field converted to meters.
292   double smiles;
293   double km;
294   double meters;
295   smiles = ((Decoded_METAR*) m_DecodedReport)->prevail_vsbySM  * 621 ;
296   km =  ((Decoded_METAR*) m_DecodedReport)->prevail_vsbyKM * 1000;
297   meters =  ((Decoded_METAR*) m_DecodedReport)->prevail_vsbyM;
298   
299   /* Return the smallest one. If the field is specified it should have been
300      set to MAX_INT */
301   if(smiles < km && smiles < meters) 
302     return smiles;
303   else 
304     return km < meters ? km : meters; 
305 }