diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java @ 2230:59af81364eb1

Improved the 'historical discharge' calculation: implemented findValueForW(). flys-artifacts/trunk@3872 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 01 Feb 2012 15:41:11 +0000
parents 6b0ae0f2cae6
children 899ca89f497e
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Wed Feb 01 15:00:13 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java	Wed Feb 01 15:41:11 2012 +0000
@@ -124,27 +124,10 @@
             // TODO: Filter by time interval
             DischargeTable table = tables.get(0);
 
-            List<DischargeTableValue> dtvs =
-                table.getDischargeTableValues();
-
-            final double [][] vs = new double[2][dtvs.size()];
-
             boolean qSorted = true;
 
-            double lastQ = -Double.MAX_VALUE;
-
-            int idx = 0;
-            for (DischargeTableValue dtv: dtvs) {
-                double q = dtv.getQ().doubleValue();
-                vs[0][idx] = q * scale;
-                vs[1][idx] = dtv.getW().doubleValue() * scale;
-                ++idx;
-
-                if (qSorted && lastQ > q) {
-                    qSorted = false;
-                }
-                lastQ = q;
-            }
+            final double[][] vs =
+                loadDischargeTableValues(table, scale, qSorted);
 
             if (!qSorted) {
                 log.debug("need to sort by q values");
@@ -182,6 +165,43 @@
         return values;
     }
 
+
+    /**
+     * @param table The discharge table
+     * @param scale The scale factor to adjust W and Q values.
+     * @param qSorted Boolean flag that is used to evaluate if the values should
+     * be sorted.
+     *
+     * @return the values of a discharge table.
+     */
+    public static double[][] loadDischargeTableValues(
+        DischargeTable table,
+        double         scale,
+        boolean        qSorted
+    ) {
+        List<DischargeTableValue> dtvs = table.getDischargeTableValues();
+
+        final double [][] vs = new double[2][dtvs.size()];
+
+        double lastQ = -Double.MAX_VALUE;
+
+        int idx = 0;
+        for (DischargeTableValue dtv: dtvs) {
+            double q = dtv.getQ().doubleValue();
+            vs[0][idx] = q * scale;
+            vs[1][idx] = dtv.getW().doubleValue() * scale;
+            ++idx;
+
+            if (qSorted && lastQ > q) {
+                qSorted = false;
+            }
+            lastQ = q;
+        }
+
+        return vs;
+    }
+
+
     public static double getQForW(double [][] values, double w) {
 
         boolean debug = log.isDebugEnabled();

http://dive4elements.wald.intevation.org