changeset 334:b7c8df643dc4

Discharge table: we need a getQForW() and not a getWForQ(). flys-artifacts/trunk@1732 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Apr 2011 17:37:21 +0000
parents 67b3f54188aa
children 64cfbd631f29
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java
diffstat 2 files changed, 28 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Apr 19 14:48:28 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Apr 19 17:37:21 2011 +0000
@@ -1,3 +1,11 @@
+2011-04-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
+	  We need a getQForW() method and not getWForQ() because when
+	  doing a "Wasserstand/Wasserspiegellagen" calculation with given
+	  w values these values need to be translated to q values with
+	  the master discharge table.
+
 2011-04-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Tue Apr 19 14:48:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Tue Apr 19 17:37:21 2011 +0000
@@ -180,45 +180,41 @@
         return values;
     }
 
-    public static boolean getWForQ(
+    public static double getQForW(
         double [][] values, 
-        double      q,  
+        double      w,  
         double []   result
     ) {
-        int index = Arrays.binarySearch(values[1], q);
+        int index = Arrays.binarySearch(values[0], w);
         if (index >= 0) {
-            result[0] = values[1][index];
-            return true;
+            return values[0][index];
         }
 
         index = -index - 1; // insert position
 
-        if (index == 0 || index+1 >= values.length) {
+        if (index < 1 || index >= values.length) {
             // do not extraploate
-            return false;
+            return Double.NaN;
         }
 
-        double q1 = values[index  ][0];
-        double q2 = values[index+1][0];
-        double w1 = values[index  ][1];
-        double w2 = values[index+1][1];
+        double w1 = values[index-1][0];
+        double w2 = values[index  ][0];
+        double q1 = values[index-1][1];
+        double q2 = values[index  ][1];
 
-        // 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 = m*w1 + b
+        // q2 = m*w2 + b
+        // q2 - q1 = m*(w2 - w1)
+        // m = (q2 - q1)/(w2 - w1) # w2 != w1
+        // b = q1 - m*w1
 
-        if (q1 == q2) {
-            result[0] = 0.5*(w1 + w2);
-        }
-        else {
-            double m = (w2 - w1)/(q2 - q1);
-            double b = w1 - m*q1;
-            result[0] = q*m + b;
+        if (w1 == w2) {
+            return 0.5*(q1 + q2);
         }
 
-        return true;
+        double m = (q2 - q1)/(w2 - w1);
+        double b = q1 - m*w1;
+        return w*m + b;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org