diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 3736:da1969b05292

WST tables: Added interpolation of tabulated values only. flys-artifacts/trunk@5411 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 09 Sep 2012 15:29:06 +0000
parents 4c4ec9e9650a
children 51f76225823b
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Sun Sep 09 13:07:06 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Sun Sep 09 15:29:06 2012 +0000
@@ -1217,5 +1217,40 @@
         double q2 = columns[index  ].getQRangeTree().findQ(km);
         return Linear.weight(weight, q1, q2);
     }
+
+    public double [][] interpolateTabulated(double km) {
+        return interpolateTabulated(km, new double[2][columns.length]);
+    }
+
+    public double [][] interpolateTabulated(double km, double [][] result) {
+
+        int rowIndex = Collections.binarySearch(rows, new Row(km));
+
+        if (rowIndex >= 0) {
+            // Direct hit -> copy ws.
+            Row row = rows.get(rowIndex);
+            System.arraycopy(
+                row.ws, 0, result[0], 0,
+                Math.min(row.ws.length, result[0].length));
+        }
+        else {
+            rowIndex = -rowIndex -1;
+            if (rowIndex < 1 || rowIndex >= rows.size()) {
+                // Out of bounds.
+                return null;
+            }
+            // Interpolate ws.
+            Row r1 = rows.get(rowIndex-1);
+            Row r2 = rows.get(rowIndex);
+            double factor = Linear.factor(km, r1.km, r2.km);
+            Linear.weight(factor, r1.ws, r2.ws, result[0]);
+        }
+
+        double [] qs = result[1];
+        for (int i = Math.min(qs.length, columns.length)-1; i >= 0; --i) {
+            qs[i] = columns[i].getQRangeTree().findQ(km);
+        }
+        return result;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org