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