1 // Metar report implementation class code
3 #include <simgear/compiler.h>
7 #include "MetarReport.h"
10 #if !defined (SG_HAVE_NATIVE_SGI_COMPILERS)
12 SG_USING_STD(ostream);
15 CMetarReport::CMetarReport(
19 m_DecodedReport = new Decoded_METAR;
20 DcdMETAR( s, (Decoded_METAR *)m_DecodedReport );
24 CMetarReport::~CMetarReport()
28 static int DecodeDirChars( char* c )
34 if ( c[0] == 'E' ) r = 90;
35 else if ( c[0] == 'S' ) r = 180;
36 else if ( c[0] == 'W' ) r = 270;
40 if ( c[1] == 'E' ) r = 45;
41 else if ( c[1] == 'W' ) r = 315;
45 if ( c[1] == 'E' ) r = 135;
46 else if ( c[1] == 'W' ) r = 225;
52 char *CMetarReport::StationID()
54 return ((Decoded_METAR *)m_DecodedReport)->stnid;
57 int CMetarReport::Day()
59 return ((Decoded_METAR*)m_DecodedReport)->ob_date;
62 int CMetarReport::Hour()
64 return ((Decoded_METAR*)m_DecodedReport)->ob_hour;
67 int CMetarReport::Minutes()
69 return ((Decoded_METAR*)m_DecodedReport)->ob_minute;
72 int CMetarReport::WindDirection()
74 return ((Decoded_METAR *)m_DecodedReport)->winData.windDir;
77 int CMetarReport::WindSpeed()
79 return ((Decoded_METAR *)m_DecodedReport)->winData.windSpeed;
82 int CMetarReport::WindGustSpeed()
84 return ((Decoded_METAR *)m_DecodedReport)->winData.windGust;
87 int CMetarReport::LightningDirection()
89 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->LTG_DIR );
92 char CMetarReport::CloudLow()
94 return ((Decoded_METAR *)m_DecodedReport)->CloudLow;
97 char CMetarReport::CloudMedium()
99 return ((Decoded_METAR *)m_DecodedReport)->CloudMedium;
102 char CMetarReport::CloudHigh()
104 return ((Decoded_METAR *)m_DecodedReport)->CloudHigh;
107 int CMetarReport::VirgaDirection()
109 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->VIRGA_DIR );
112 int CMetarReport::TornadicDirection()
114 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TornadicDIR );
117 int CMetarReport::TornadicMovementDirection()
119 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TornadicMovDir );
122 int CMetarReport::ThunderStormDirection()
124 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TS_LOC );
127 int CMetarReport::ThunderStormMovementDirection()
129 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TS_MOVMNT );
132 bool CMetarReport::Virga()
134 return ((Decoded_METAR *)m_DecodedReport)->VIRGA;
137 bool CMetarReport::VolcanicAsh()
139 return ((Decoded_METAR *)m_DecodedReport)->VOLCASH;
142 bool CMetarReport::Hail()
144 return ((Decoded_METAR *)m_DecodedReport)->GR;
147 bool CMetarReport::OccationalLightning()
149 return ((Decoded_METAR *)m_DecodedReport)->OCNL_LTG;
152 bool CMetarReport::FrequentLightning()
154 return ((Decoded_METAR *)m_DecodedReport)->FRQ_LTG;
157 bool CMetarReport::ContinuousLightning()
159 return ((Decoded_METAR *)m_DecodedReport)->CNS_LTG;
162 bool CMetarReport::CloudToGroundLightning()
164 return ((Decoded_METAR *)m_DecodedReport)->CG_LTG;
167 bool CMetarReport::InterCloudLightning()
169 return ((Decoded_METAR *)m_DecodedReport)->IC_LTG;
172 bool CMetarReport::CloudToCloudLightning()
174 return ((Decoded_METAR *)m_DecodedReport)->CC_LTG;
177 bool CMetarReport::CloudToAirLightning()
179 return ((Decoded_METAR *)m_DecodedReport)->CA_LTG;
182 bool CMetarReport::DistantLightning()
184 return ((Decoded_METAR *)m_DecodedReport)->DSNT_LTG;
187 bool CMetarReport::AirportLightning()
189 return ((Decoded_METAR *)m_DecodedReport)->AP_LTG;
192 bool CMetarReport::VicinityLightning()
194 return ((Decoded_METAR *)m_DecodedReport)->VcyStn_LTG;
197 bool CMetarReport::OverheadLightning()
199 return ((Decoded_METAR *)m_DecodedReport)->OVHD_LTG;
202 int CMetarReport::Temperature()
204 return ((Decoded_METAR *)m_DecodedReport)->temp;
207 int CMetarReport::DewpointTemperature()
209 return ((Decoded_METAR *)m_DecodedReport)->dew_pt_temp;
212 int CMetarReport::VerticalVisibility() // Meters
214 return ((Decoded_METAR *)m_DecodedReport)->VertVsby;
217 int CMetarReport::Ceiling()
220 (int)(SG_FEET_TO_METER*((Decoded_METAR *)m_DecodedReport)->Ceiling);
223 int CMetarReport::EstimatedCeiling()
226 (int)(SG_FEET_TO_METER
227 * ((Decoded_METAR *)m_DecodedReport)->Estimated_Ceiling);
230 int CMetarReport::VariableSkyLayerHeight()
233 (int)(SG_FEET_TO_METER
234 * ((Decoded_METAR *)m_DecodedReport)->VrbSkyLayerHgt);
237 int CMetarReport::SnowDepthInches()
239 return ((Decoded_METAR *)m_DecodedReport)->snow_depth;
244 operator << ( ostream& out, CMetarReport& p )
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
285 double CMetarReport::AirPressure()
287 return ((Decoded_METAR *)m_DecodedReport)->inches_altstng;
290 void CMetarReport::dump()
292 prtDMETR( (Decoded_METAR *)m_DecodedReport );
295 double CMetarReport::PrevailVisibility()
297 //Values from each visibility field converted to 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;
305 /* Return the smallest one. If the field is specified it should have been
307 if(smiles < km && smiles < meters)
310 return km < meters ? km : meters;