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