# HG changeset patch # User Sascha L. Teichmann # Date 1300877218 0 # Node ID 88048d4f6e4def822d9fb1831fc1e1fc99d86815 # Parent ed38839a6b081ecc1be8b5a261d2b9d1682c07e1 Add a hack to repair the units in WST files extraction. flys-backend/trunk@1542 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ed38839a6b08 -r 88048d4f6e4d flys-backend/ChangeLog --- a/flys-backend/ChangeLog Tue Mar 22 15:48:09 2011 +0000 +++ b/flys-backend/ChangeLog Wed Mar 23 10:46:58 2011 +0000 @@ -1,3 +1,10 @@ +2011-03-22 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/importer/WstParser.java: + The unit extraction in the WST parser of desktop FLYS + is broken! Add a hack here to repair this for our + importer. Desktop FLYS needs a fix, too! + 2011-03-22 Sascha L. Teichmann * src/main/java/de/intevation/flys/importer/WstParser.java: diff -r ed38839a6b08 -r 88048d4f6e4d flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java Tue Mar 22 15:48:09 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java Wed Mar 23 10:46:58 2011 +0000 @@ -16,6 +16,9 @@ import de.intevation.flys.utils.StringUtil; +import java.util.regex.Pattern; +import java.util.regex.Matcher; + public class WstParser { private static Logger log = Logger.getLogger(WstParser.class); @@ -29,6 +32,12 @@ public static final String ENCODING = "ISO-8859-1"; + public static final Pattern UNIT_COMMENT = + Pattern.compile("\\*\\s*[kK][mM]\\s+(.+)"); + + public static final Pattern UNIT = + Pattern.compile("[^\\[]*\\[([^]]+)\\].*"); + public WstParser() { } @@ -64,7 +73,7 @@ double lastKm = Double.MAX_VALUE; - String einheit = "Wassserstand [NN + m]"; + String einheit = "Wasserstand [NN + m]"; HashMap oldEscapeLine = null; @@ -167,13 +176,20 @@ continue; } + if (line.length() < 11) { + continue; + } + if (line.startsWith("*")) { - if (bFirstComment && line.length() >= 11) { - String yAxis = line.substring(10).trim(); - if (yAxis.length() > 0) { - einheit = yAxis; - } - bFirstComment = false; + Matcher m = UNIT_COMMENT.matcher(line); + if (m.matches()) { + log.debug("unit comment found"); + // XXX: This hack is needed because desktop + // FLYS is broken figuring out the unit + String [] units = m.group(1).split("\\s{2,}"); + m = UNIT.matcher(units[0]); + einheit = m.matches() ? m.group(1) : units[0]; + log.debug("unit: " + einheit); } continue; } @@ -187,14 +203,14 @@ double q = firstAbfluesse[i]; if (q < 0.001) { lsBezeichner[i] = - ""; + ""; ++unknownCount; } else { lsBezeichner[i] = "Q="+format(q); } } - lsHeader[i] = lsBezeichner[i] + " " + einheit; + lsHeader[i] = lsBezeichner[i]; } columnHeaderChecked = true; } @@ -276,10 +292,22 @@ double to, Map values ) { - log.debug("addInterval: " + from + " " + to); if (values == null) { return; } + if (log.isDebugEnabled()) { + log.debug("addInterval: " + from + " " + to); + StringBuilder sb = new StringBuilder(); + for (Map.Entry entry: values.entrySet()) { + if (sb.length() > 0) { + sb.append("; "); + } + sb.append('"').append(entry.getKey()) + .append("\": ") + .append(entry.getValue()); + } + log.debug("entries: " + sb.toString()); + } } private static final Double [] parseLineAsDouble(