[PATCH] WST-Parser: revert the assumption of only complete columns

Wald Commits scm-commit at wald.intevation.org
Thu Oct 31 21:56:10 CET 2013


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1383252964 -3600
# Node ID 1890bd524d270434df3534c544909ff21c0f208a
# Parent  e327492ba9d00f0ce72bcfa19c8d133fd34e2a48
WST-Parser: revert the assumption of only complete columns.

diff -r e327492ba9d0 -r 1890bd524d27 backend/doc/documentation/de/importer-hydr-morph.tex
--- a/backend/doc/documentation/de/importer-hydr-morph.tex	Thu Oct 31 19:16:42 2013 +0100
+++ b/backend/doc/documentation/de/importer-hydr-morph.tex	Thu Oct 31 21:56:04 2013 +0100
@@ -403,10 +403,6 @@
 \\Die Stationen in einer WST-Datei sind nicht konsequent auf- oder 
 absteigend geordnet. Die Datei wird verworfen.
 
-\textbf{WST: number of columns is less than expected. File rejected.}
-\\Die Anzahl der Spalten in einer Zeile einer WST-Datei stimmt nicht
-mit der Angabe im Datei-Kopf überein. Die Datei wird verworfen.
-
 \textbf{File 'XYZ' is broken!}
 \\Die Datei XYZ ist inkonsistent und führt zu Fehlern.
 
diff -r e327492ba9d0 -r 1890bd524d27 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 31 19:16:42 2013 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Thu Oct 31 21:56:04 2013 +0100
@@ -188,8 +188,7 @@
 
                 // handle Q-lines
                 if (line.startsWith("*\u001f")) {
-                    BigDecimal [] data = null;
-                    data = parseLineAsDouble(line, columnCount, false, true);
+                    BigDecimal [] data = parseLineAsDouble(line, columnCount, false, true);
 
                     if (aktAbfluesse != null) { // add Q-ranges obtained from previous lines
                         if (kmHist1 != null && kmHist2 != null
@@ -202,15 +201,16 @@
                     }
 
                     // obtain Q-values from current line
-                    aktAbfluesse = new BigDecimal[columnCount];
+                    aktAbfluesse = new BigDecimal[data.length];
                     log.debug("new q range: " + columnCount);
-                    for (int i = 0; i < Math.min(columnCount, data.length); ++i) {
+                    for (int i = 0; i < data.length; ++i) {
                         if (data[i] != null) {
                             log.debug("  column: " + data[i]);
                             aktAbfluesse[i] = data[i];
                         }
                     }
 
+                    // remember Q-values from first Q-line for header generation
                     if (firstAbfluesse == null) {
                         firstAbfluesse = (BigDecimal [])aktAbfluesse.clone();
                     }
@@ -299,7 +299,8 @@
                             if (lsBezeichner[i] == null
                             || lsBezeichner[i].length() == 0) {
                                 // generate alternative column names
-                                double q = firstAbfluesse[i].doubleValue();
+                                double q = firstAbfluesse.length > i ?
+                                    firstAbfluesse[i].doubleValue() : 0d;
                                 if (q < 0.001) {
                                     lsBezeichner[i] =
                                         "<unbekannt #" + unknownCount + ">";
@@ -329,8 +330,7 @@
                         columnHeaderChecked = true;
                     }
 
-                    BigDecimal [] data = null;
-                    data = parseLineAsDouble(line, columnCount, true, false);
+                    BigDecimal [] data = parseLineAsDouble(line, columnCount, true, false);
 
                     BigDecimal kaem = data[0];
 
@@ -363,7 +363,7 @@
                     }
 
                     // extract values
-                    for (int i = 0; i < columnCount; ++i) {
+                    for (int i = 0; i < data.length - 1; ++i) {
                         addValue(kaem, data[i+1], i);
                     }
 
@@ -533,8 +533,7 @@
         for (int i = 0; i < tokenCount; ++i) {
             pos += 9;
             if (pos >= line.length()) {
-                throw new ParseException(
-                    "WST: number of columns is less than expected. File rejected.");
+                break;
             }
             strings.add(line.substring(pos, 
                 Math.min(pos + 8, line.length())));


More information about the Dive4elements-commits mailing list