changeset 7488:1890bd524d27

WST-Parser: revert the assumption of only complete columns.
author Tom Gottfried <tom@intevation.de>
date Thu, 31 Oct 2013 21:56:04 +0100
parents e327492ba9d0
children 3e9961dcbf9a
files backend/doc/documentation/de/importer-hydr-morph.tex backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
diffstat 2 files changed, 9 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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.
 
--- 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())));

http://dive4elements.wald.intevation.org