[PATCH] (issue1560) Fix off by one error in ATWriter causing the last value to be omitted

Wald Commits scm-commit at wald.intevation.org
Wed Nov 27 17:17:59 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1385569074 -3600
# Node ID f51c943c707a59feceaf948f30494a21acd80730
# Parent  05549a84ee83da55e7f103dd866a71767e15c587
(issue1560) Fix off by one error in ATWriter causing the last value to be omitted.

diff -r 05549a84ee83 -r f51c943c707a artifacts/src/main/java/org/dive4elements/river/exports/ATWriter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ATWriter.java	Wed Nov 27 16:21:00 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ATWriter.java	Wed Nov 27 17:17:54 2013 +0100
@@ -170,10 +170,13 @@
             return;
         }
 
-        double [] ws = new double[bounds[1]-bounds[0]];
+        /* example: bounds[0] = 0
+         * bounds[1] = 5 -> we need to store 6 values.*/
+
+        double [] ws = new double[bounds[1]-bounds[0] + 1];
         double [] qs = new double[ws.length];
 
-        for (int i = 0; i < ws.length; ++i) {
+        for (int i = 0; i < ws.length; i++) {
             int idx = bounds[0]+i;
             ws[i] = wq.getW(idx);
             qs[i] = wq.getQ(idx);
@@ -213,7 +216,7 @@
         }
 
         int col = 0;
-        for (int w = startW; w < maxW; w++) {
+        for (int w = startW; w <= maxW; w++) {
             if (col == 0) {
                 out.printf(Locale.US, "%8d", w);
             }


More information about the Dive4elements-commits mailing list