1 // Metar report implementation class code
3 #include <simgear/compiler.h>
7 #include "MetarReport.h"
11 SG_USING_STD(ostream);
13 CMetarReport::CMetarReport(
17 m_DecodedReport = new Decoded_METAR;
18 DcdMETAR( s, (Decoded_METAR *)m_DecodedReport );
22 CMetarReport::~CMetarReport()
26 static int DecodeDirChars( char* c )
32 if ( c[0] == 'E' ) r = 90;
33 else if ( c[0] == 'S' ) r = 180;
34 else if ( c[0] == 'W' ) r = 270;
38 if ( c[1] == 'E' ) r = 45;
39 else if ( c[1] == 'W' ) r = 315;
43 if ( c[1] == 'E' ) r = 135;
44 else if ( c[1] == 'W' ) r = 225;
50 char *CMetarReport::StationID()
52 return ((Decoded_METAR *)m_DecodedReport)->stnid;
55 int CMetarReport::Day()
57 return ((Decoded_METAR*)m_DecodedReport)->ob_date;
60 int CMetarReport::Hour()
62 return ((Decoded_METAR*)m_DecodedReport)->ob_hour;
65 int CMetarReport::Minutes()
67 return ((Decoded_METAR*)m_DecodedReport)->ob_minute;
70 int CMetarReport::WindDirection()
72 return ((Decoded_METAR *)m_DecodedReport)->winData.windDir;
75 int CMetarReport::WindSpeed()
77 return ((Decoded_METAR *)m_DecodedReport)->winData.windSpeed;
80 int CMetarReport::WindGustSpeed()
82 return ((Decoded_METAR *)m_DecodedReport)->winData.windGust;
85 int CMetarReport::LightningDirection()
87 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->LTG_DIR );
90 char CMetarReport::CloudLow()
92 return ((Decoded_METAR *)m_DecodedReport)->CloudLow;
95 char CMetarReport::CloudMedium()
97 return ((Decoded_METAR *)m_DecodedReport)->CloudMedium;
100 char CMetarReport::CloudHigh()
102 return ((Decoded_METAR *)m_DecodedReport)->CloudHigh;
105 int CMetarReport::VirgaDirection()
107 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->VIRGA_DIR );
110 int CMetarReport::TornadicDirection()
112 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TornadicDIR );
115 int CMetarReport::TornadicMovementDirection()
117 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TornadicMovDir );
120 int CMetarReport::ThunderStormDirection()
122 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TS_LOC );
125 int CMetarReport::ThunderStormMovementDirection()
127 return DecodeDirChars( ((Decoded_METAR *)m_DecodedReport)->TS_MOVMNT );
130 bool CMetarReport::Virga()
132 return ((Decoded_METAR *)m_DecodedReport)->VIRGA;
135 bool CMetarReport::VolcanicAsh()
137 return ((Decoded_METAR *)m_DecodedReport)->VOLCASH;
140 bool CMetarReport::Hail()
142 return ((Decoded_METAR *)m_DecodedReport)->GR;
145 bool CMetarReport::OccationalLightning()
147 return ((Decoded_METAR *)m_DecodedReport)->OCNL_LTG;
150 bool CMetarReport::FrequentLightning()
152 return ((Decoded_METAR *)m_DecodedReport)->FRQ_LTG;
155 bool CMetarReport::ContinuousLightning()
157 return ((Decoded_METAR *)m_DecodedReport)->CNS_LTG;
160 bool CMetarReport::CloudToGroundLightning()
162 return ((Decoded_METAR *)m_DecodedReport)->CG_LTG;
165 bool CMetarReport::InterCloudLightning()
167 return ((Decoded_METAR *)m_DecodedReport)->IC_LTG;
170 bool CMetarReport::CloudToCloudLightning()
172 return ((Decoded_METAR *)m_DecodedReport)->CC_LTG;
175 bool CMetarReport::CloudToAirLightning()
177 return ((Decoded_METAR *)m_DecodedReport)->CA_LTG;
180 bool CMetarReport::DistantLightning()
182 return ((Decoded_METAR *)m_DecodedReport)->DSNT_LTG;
185 bool CMetarReport::AirportLightning()
187 return ((Decoded_METAR *)m_DecodedReport)->AP_LTG;
190 bool CMetarReport::VicinityLightning()
192 return ((Decoded_METAR *)m_DecodedReport)->VcyStn_LTG;
195 bool CMetarReport::OverheadLightning()
197 return ((Decoded_METAR *)m_DecodedReport)->OVHD_LTG;
200 int CMetarReport::Temperature()
202 return ((Decoded_METAR *)m_DecodedReport)->temp;
205 int CMetarReport::DewpointTemperature()
207 return ((Decoded_METAR *)m_DecodedReport)->dew_pt_temp;
210 int CMetarReport::VerticalVisibility() // Meters
212 return ((Decoded_METAR *)m_DecodedReport)->VertVsby;
215 int CMetarReport::Ceiling()
218 (int)(SG_FEET_TO_METER*((Decoded_METAR *)m_DecodedReport)->Ceiling);
221 int CMetarReport::EstimatedCeiling()
224 (int)(SG_FEET_TO_METER
225 * ((Decoded_METAR *)m_DecodedReport)->Estimated_Ceiling);
228 int CMetarReport::VariableSkyLayerHeight()
231 (int)(SG_FEET_TO_METER
232 * ((Decoded_METAR *)m_DecodedReport)->VrbSkyLayerHgt);
235 int CMetarReport::SnowDepthInches()
237 return ((Decoded_METAR *)m_DecodedReport)->snow_depth;
242 operator << ( ostream& out, CMetarReport& p )
245 << "StationID " << p.StationID()
246 << " WindDirection " << p.WindDirection()
247 << " WindSpeed " << p.WindSpeed()
248 << " WindGustSpeed " << p.WindGustSpeed() << endl
249 << "CloudLow " << p.CloudLow()
250 << " CloudMedium " << p.CloudMedium()
251 << " CloudHigh " << p.CloudHigh() << endl
252 << "TornadicDirection " << p.TornadicDirection()
253 << " TornadicMovementDirection " << p.TornadicMovementDirection() << endl
254 << "ThunderStormDirection " << p.ThunderStormDirection()
255 << " ThunderStormMovementDirection " << p.ThunderStormMovementDirection() << endl
256 << "Virga " << p.Virga()
257 << " VirgaDirection " << p.VirgaDirection() << endl
258 << "VolcanicAsh " << p.VolcanicAsh() << endl
259 << "Hail " << p.Hail() << endl
260 << "LightningDirection " << p.LightningDirection()
261 << " OccationalLightning " << p.OccationalLightning()
262 << " FrequentLightning " << p.FrequentLightning()
263 << " ContinuousLightning " << p.ContinuousLightning() << endl
264 << "CloudToGroundLightning " << p.CloudToGroundLightning()
265 << " InterCloudLightning " << p.InterCloudLightning()
266 << " CloudToCloudLightning " << p.CloudToCloudLightning()
267 << " CloudToAirLightning " << p.CloudToAirLightning() << endl
268 << "DistantLightning " << p.DistantLightning()
269 << " AirportLightning " << p.AirportLightning()
270 << " VicinityLightning " << p.VicinityLightning()
271 << " OverheadLightning " << p.OverheadLightning() << endl
272 << "VerticalVisibility " << p.VerticalVisibility() << endl // Meters
273 << "Temperature " << p.Temperature()
274 << " DewpointTemperature " << p.DewpointTemperature() << endl
275 << "Ceiling " << p.Ceiling()
276 << " EstimatedCeiling " << p.EstimatedCeiling()
277 << " VariableSkyLayerHeight " << p.VariableSkyLayerHeight() << endl
278 << "SnowDepthInches " << p.SnowDepthInches() << endl
283 double CMetarReport::AirPressure()
285 return ((Decoded_METAR *)m_DecodedReport)->inches_altstng;
288 void CMetarReport::dump()
290 prtDMETR( (Decoded_METAR *)m_DecodedReport );
293 double CMetarReport::PrevailVisibility()
295 //Values from each visibility field converted to meters.
299 smiles = ((Decoded_METAR*) m_DecodedReport)->prevail_vsbySM * 1609.34;
300 km = ((Decoded_METAR*) m_DecodedReport)->prevail_vsbyKM * 1000;
301 meters = ((Decoded_METAR*) m_DecodedReport)->prevail_vsbyM;
303 /* Return the smallest one. If the field is specified it should have been
305 if(smiles < km && smiles < meters)
308 return km < meters ? km : meters;