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