[PATCH] WstParser: Do not add Q-range for trailing Q-line

Wald Commits scm-commit at wald.intevation.org
Thu Oct 17 15:05:12 CEST 2013


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1382015108 -7200
# Node ID 82191d111130bea8c4f8c8ffa153d2e46a841c44
# Parent  793dfb2f4b7bc34aeba02c40ad84114cc5730148
WstParser: Do not add Q-range for trailing Q-line.

diff -r 793dfb2f4b7b -r 82191d111130 backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Thu Oct 17 12:14:10 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Thu Oct 17 15:05:08 2013 +0200
@@ -186,11 +186,12 @@
 
                 line = line.replace(',', '.');
 
+                // handle Q-lines
                 if (line.startsWith("*\u001f")) {
                     BigDecimal [] data =
                         parseLineAsDouble(line, columnCount, false, true);
 
-                    if (aktAbfluesse != null) {
+                    if (aktAbfluesse != null) { // add Q-ranges obtained from previous lines
                         if (kmHist1 != null && kmHist2 != null
                         && kmHist1.compareTo(kmHist2) < 0) { // stations descending in file
                             BigDecimal t = minKm; minKm = maxKm; maxKm = t;
@@ -200,6 +201,7 @@
                         maxKm = MIN_RANGE;
                     }
 
+                    // obtain Q-values from current line
                     aktAbfluesse = new BigDecimal[columnCount];
                     log.debug("new q range: " + columnCount);
                     for (int i = 0; i < Math.min(columnCount, data.length); ++i) {
@@ -215,6 +217,7 @@
                     continue;
                 }
 
+                // handle special column identifiers
                 if (line.startsWith("*!")) {
                     String spezial = line.substring(2).trim();
 
@@ -265,6 +268,7 @@
                     continue;
                 }
 
+                // handle comment lines to fetch unit
                 if (line.startsWith("*")) {
                     Matcher m = UNIT_COMMENT.matcher(line);
                     if (m.matches()) {
@@ -401,11 +405,16 @@
             }
             wst.setUnit(new ImportUnit(einheit));
 
-            if (kmHist1 != null && kmHist2 != null
-            && kmHist1.compareTo(kmHist2) < 0) { // stations descending in file
-                BigDecimal t = minKm; minKm = maxKm; maxKm = t;
-            }
-            addInterval(minKm, maxKm, aktAbfluesse);
+            // add Q-ranges obtained from previous lines 
+            // in case there was no further Q-line
+            // but only if there were values following the last Q-line
+            if (minKm != MAX_RANGE && maxKm != MIN_RANGE) {
+		if (kmHist1 != null && kmHist2 != null
+		&& kmHist1.compareTo(kmHist2) < 0) { // stations descending in file
+		    BigDecimal t = minKm; minKm = maxKm; maxKm = t;
+		}
+		addInterval(minKm, maxKm, aktAbfluesse);
+	    }
         }
         finally {
             in.close();


More information about the Dive4elements-commits mailing list