changeset 4226:cb9f22c3553f

DischargeTables: Added missing getWsForQ()
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 23 Oct 2012 15:05:17 +0200
parents f4cee1a74605
children 8138a90a674a
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java
diffstat 1 files changed, 60 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Tue Oct 23 13:29:13 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Tue Oct 23 15:05:17 2012 +0200
@@ -235,5 +235,65 @@
 
         return result;
     }
+
+    public static double [] getWsForQ(double [][] values, double q) {
+
+        boolean debug = log.isDebugEnabled();
+
+        if (debug) {
+            log.debug("getWsForQ: W = " + q);
+        }
+
+        double [] qs = values[0];
+        double [] ws = values[1];
+
+        int N = Math.min(qs.length, ws.length);
+
+        if (N == 0) {
+            if (debug) {
+                log.debug("W(" + q + ") = []");
+            }
+            return new double [0];
+        }
+
+        TDoubleArrayList outWs = new TDoubleArrayList();
+
+        if (epsEquals(qs[0], q)) {
+            outWs.add(ws[0]);
+        }
+
+        for (int i = 1; i < N; ++i) {
+            if (epsEquals(qs[i], q)) {
+                outWs.add(ws[i]);
+            }
+            else if (between(qs[i-1], qs[i], q)) {
+                double w1 = ws[i-1];
+                double w2 = ws[i];
+                double q1 = qs[i-1];
+                double q2 = qs[i];
+
+                // w1 = m*q1 + b
+                // w2 = m*q2 + b
+                // w2 - w1 = m*(q2 - q1)
+                // m = (w2 - w1)/(q2 - q1) # q2 != q1
+                // b = w1 - m*q1
+                // q1 != q2
+
+                double m = (w2 - w1)/(q2 - q1);
+                double b = w1 - m*q1;
+                double w = q*m + b;
+
+                outWs.add(w);
+            }
+        }
+
+        double [] result = outWs.toNativeArray();
+
+        if (debug) {
+            log.debug("W(" + q + ") = " + Arrays.toString(result));
+        }
+
+        return result;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org