changeset 7687:f4b3861712a4

(issue1666) Calculate wRow after rounding the first value. This also fixes negative waterlevels in the export.
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 12 Dec 2013 16:01:40 +0100
parents 7484132b2fbb
children 9509359c8db8
files artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATWriter.java
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATWriter.java	Thu Dec 12 07:57:13 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATWriter.java	Thu Dec 12 16:01:40 2013 +0100
@@ -26,6 +26,7 @@
 import java.io.Writer;
 
 import java.util.Locale;
+import java.util.Arrays;
 
 import org.apache.log4j.Logger;
 
@@ -118,21 +119,24 @@
         double wMinCM = wMin * 100d - subtractPNP;
         double wMaxCM = wMax * 100d;
 
-        int wRow = ((int)wMinCM / 10) * 10;
-
         if ((wMinCM - (int)wMinCM) > 0d) {
             wMinCM = (int)wMinCM + 1d;
         }
 
+        int wRow = ((int)wMinCM / 10) * 10;
+
         double w = (wMinCM + subtractPNP) / 100.0;
 
         int wcm = ((int)wMinCM) % 10;
 
         if (log.isDebugEnabled()) {
+            log.debug("km: " + km);
             log.debug("wMinCM: " + wMinCM);
             log.debug("wMaxCM: " + wMaxCM);
             log.debug("wcm: " + wcm);
             log.debug("subtractPNP: " + subtractPNP);
+            log.debug("coeffs: " + Arrays.toString(coeffs));
+            log.debug("function description: " + inverse.getDescription());
         }
 
         out.printf(Locale.US, "%8d", wRow);
@@ -205,6 +209,11 @@
 
         for (int i = 0; i < MAX_ITERATIONS; ++i) {
             double w = lastW - stepWidth;
+
+            if (w <= 0) {
+                return 0;
+            }
+
             double q = function.value(w);
 
             if (Double.isNaN(q) || q > lastQ || q < MIN_Q) {

http://dive4elements.wald.intevation.org