In MetarParser around line 366.
Fractional visibilities that do not have a whole part
will fail. For example:
KGRF 230757Z 31001KT 1/2SM -RA BR FEW008 BKN018 OVCO25
02/02 A3039
The "1/2SM" will cause the parser to fail. Attached is
a JUnit test that will cause an exception.
Recommend this code to fix:
if (((String) tokens.get(index)).endsWith("SM")) {
// We have a fraction without a whole ( EX: 1/2SM)
if (((String) tokens.get(index)).indexOf('/')
!= -1) {
fraction =
((String) tokens.get(index)).substring(
0,
((String) tokens.get(index)).length() - 2);
}
else {
// no fractions to deal with (EX: 9SM)
whole =
((String) tokens.get(index)).substring(
0,
((String) tokens.get(index)).length() - 2);
}
}
else {
// combination of whole and fraction (EX: 2 1/2SM)
whole = ((String) tokens.get(index++));
fraction =
((String) tokens.get(index)).substring(
0,
((String) tokens.get(index)).length() - 2);
}
if (whole != null)
metar.setVisibility(new Float(whole));
if (whole != null)
metar.setVisibility(new Float(whole));
if (fraction != null) {
// we have a fraction to convert
ArrayList frac = new ArrayList();
try {
utility.split(frac, "/\\//", fraction);
}
catch (MalformedPerl5PatternException e) {
log.error("Metar: error spliting fraction on
/: " + e);
throw new JWeatherParseException(e);
}
float totalVis = 0;
if (metar.getVisibility() != null)
totalVis += metar.getVisibility().floatValue();
metar.setVisibility(
new Float(
totalVis
+ new Float((String)
frac.get(0)).floatValue()
/ new Float((String)
frac.get(1)).floatValue()));
}
MetarTest.java -- JUnit replacement (added visibility testcase)
Logged In: YES
user_id=71028
fixed in 0.2.2