diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 2557:adb8641f5b5d

WstValueTable: Added method to find the w extent for a given km. flys-artifacts/trunk@4076 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Feb 2012 11:29:14 +0000
parents 750cdcccb39c
children 33e4481933e2
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Feb 17 11:03:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Feb 17 11:29:14 2012 +0000
@@ -496,6 +496,27 @@
 
             return qs.toNativeArray();
         }
+
+        public double [] getMinMaxW() {
+            double minW =  Double.MAX_VALUE;
+            double maxW = -Double.MAX_VALUE;
+            for (int i = 0; i < ws.length; ++i) {
+                double w = ws[i];
+                if (w < minW) minW = w;
+                if (w > maxW) maxW = w;
+            }
+            return new double [] { minW, maxW };
+        }
+
+        public double [] getMinMaxW(Row other, double km) {
+            double [] m1 = this .getMinMaxW();
+            double [] m2 = other.getMinMaxW();
+            double factor = Linear.factor(km, this.km, other.km);
+            return new double [] {
+                Linear.weight(factor, m1[0], m2[0]),
+                Linear.weight(factor, m1[1], m2[1])
+            };
+        }
     } // class Row
 
     /** Rows in table. */
@@ -585,6 +606,27 @@
         return ws;
     }
 
+    public double [] getMinMaxW(double km) {
+        int rowIndex = Collections.binarySearch(rows, new Row(km));
+
+        if (rowIndex >= 0) {
+            return rows.get(rowIndex).getMinMaxW();
+        }
+
+        rowIndex = -rowIndex -1;
+
+        if (rowIndex < 1 || rowIndex >= rows.size()) {
+            // do not extrapolate
+            return null;
+        }
+
+        Row r1 = rows.get(rowIndex-1);
+        Row r2 = rows.get(rowIndex);
+
+        return r1.getMinMaxW(r2, km);
+    }
+
+
     /**
      * Interpolate W and Q values at a given km.
      */

http://dive4elements.wald.intevation.org