METAR parsing: parse more cloud covers

Parse cloud coverage with no coverage or height
SF-ID: https://sourceforge.net/p/flightgear/codetickets/2750/
This commit is contained in:
James Turner 2022-07-01 16:24:36 +02:00
parent a74181ded9
commit b1dbb9499c
2 changed files with 41 additions and 12 deletions

View File

@ -123,7 +123,7 @@ SGMetar::SGMetar(const string& m) :
while (scanVisibility()) ; while (scanVisibility()) ;
while (scanRwyVisRange()) ; while (scanRwyVisRange()) ;
while (scanWeather()) ; while (scanWeather()) ;
while (scanSkyCondition()) ; while (scanSkyCondition()) { }
if (!scanTemperature()) { if (!scanTemperature()) {
throw sg_io_exception("metar temperature data malformed or missing ", sg_location(_url)); throw sg_io_exception("metar temperature data malformed or missing ", sg_location(_url));
@ -1048,12 +1048,12 @@ bool SGMetar::scanSkyCondition()
SGMetarCloud cl; SGMetarCloud cl;
if (!strncmp(m, "//////", 6)) { if (!strncmp(m, "//////", 6)) {
m += 6; char* m2 = m+6;
if (!scanBoundary(&m)) if (scanBoundary(&m2)) {
return false; _m = m2;
_m = m;
return true; return true;
} }
}
if (!strncmp(m, "CLR", i = 3) // clear if (!strncmp(m, "CLR", i = 3) // clear
|| !strncmp(m, "SKC", i = 3) // sky clear || !strncmp(m, "SKC", i = 3) // sky clear
@ -1074,9 +1074,10 @@ bool SGMetar::scanSkyCondition()
return true; return true;
} }
if (!strncmp(m, "VV", i = 2)) // vertical visibility bool verticalVisibility = false;
; if (!strncmp(m, "VV", i = 2)) { // vertical visibility
else if (!strncmp(m, "FEW", i = 3)) verticalVisibility = true;
} else if (!strncmp(m, "FEW", i = 3))
cl._coverage = SGMetarCloud::COVERAGE_FEW; cl._coverage = SGMetarCloud::COVERAGE_FEW;
else if (!strncmp(m, "SCT", i = 3)) else if (!strncmp(m, "SCT", i = 3))
cl._coverage = SGMetarCloud::COVERAGE_SCATTERED; cl._coverage = SGMetarCloud::COVERAGE_SCATTERED;
@ -1084,6 +1085,8 @@ bool SGMetar::scanSkyCondition()
cl._coverage = SGMetarCloud::COVERAGE_BROKEN; cl._coverage = SGMetarCloud::COVERAGE_BROKEN;
else if (!strncmp(m, "OVC", i = 3)) else if (!strncmp(m, "OVC", i = 3))
cl._coverage = SGMetarCloud::COVERAGE_OVERCAST; cl._coverage = SGMetarCloud::COVERAGE_OVERCAST;
else if (!strncmp(m, "///", i = 3))
cl._coverage = SGMetarCloud::COVERAGE_NIL; // should we add 'unknown'?
else else
return false; return false;
m += i; m += i;
@ -1099,7 +1102,7 @@ bool SGMetar::scanSkyCondition()
} else if (!scanNumber(&m, &i, 3)) } else if (!scanNumber(&m, &i, 3))
i = -1; i = -1;
if (cl._coverage == SGMetarCloud::COVERAGE_NIL) { if (verticalVisibility) {
if (!scanBoundary(&m)) if (!scanBoundary(&m))
return false; return false;
if (i == -1) // 'VV///' if (i == -1) // 'VV///'

View File

@ -106,6 +106,29 @@ void test_wind_unit_not_specified()
SG_CHECK_EQUAL_EP2(m1.getGustSpeed_kt(), 14.0, TEST_EPSILON); SG_CHECK_EQUAL_EP2(m1.getGustSpeed_kt(), 14.0, TEST_EPSILON);
} }
void test_clouds_without_height()
{
// apparently EGPF has a faulty automated cloud sensor? :)
SGMetar m1("EGPF 111420Z AUTO 24013KT 9000 -RA SCT019/// BKN023/// BKN030/// //////TCU 13/11 Q1011 RERA");
}
void test_GLRB_failure()
{
// Haze entered backwards, genuinely invalid
#if 0
SGMetar m1("2022/04/04 11:00 GLRB 041100Z 29012KT 8000 HZVC NSC 29/21 Q1012 NOSIG");
#endif
}
void test_LOWK_failure()
{
// surface winds specification won't parse, looks invalid
#if 0
SGMetar m3("LOWK 051526Z AUTO 217G33KT 10SM VCTS FEW017 BKN023 OVC041 23/21 A2970 "
"RMK AO2 PK WND 21037/1458 LTG DSNT ALQDS RAE09 P0000 T02330206");
#endif
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
try { try {
@ -115,6 +138,9 @@ int main(int argc, char* argv[])
test_sensor_failure_wind(); test_sensor_failure_wind();
test_wind_unit_not_specified(); test_wind_unit_not_specified();
test_drizzle(); test_drizzle();
test_clouds_without_height();
test_GLRB_failure();
test_LOWK_failure();
} catch (sg_exception& e) { } catch (sg_exception& e) {
cerr << "got exception:" << e.getMessage() << endl; cerr << "got exception:" << e.getMessage() << endl;
return -1; return -1;