diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 393:befedd7629d5

Enabled the WINFO artifact to compute the data for discharge curves (computed) - ComputedDischargeCurveGenerator uses those values now to create the chart. flys-artifacts/trunk@1818 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 04 May 2011 08:24:50 +0000
parents 478940d06876
children eb22ffe4d74c
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed May 04 07:48:39 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed May 04 08:24:50 2011 +0000
@@ -376,5 +376,73 @@
 
         return wqday;
     }
+
+
+    /**
+     * Returns the data that is computed by a discharge curve computation.
+     *
+     * @return the data computed by a discharge curve computation.
+     */
+    public WQKms getComputedDischargeCurveData()
+    throws NullPointerException
+    {
+        logger.debug("WINFOArtifact.getComputedDischargeCurveData");
+
+        River r = getRiver();
+
+        if (r == null) {
+            throw new NullPointerException("Cannot determine river.");
+        }
+
+        double[] locations = getLocations();
+
+        if (locations == null) {
+            throw new NullPointerException("Cannot determine location.");
+        }
+
+        WstValueTable wst = WstValueTable.getTable(r);
+        if (wst == null) {
+            throw new NullPointerException("No Wst found for selected river.");
+        }
+
+        // TODO Introduce a caching mechanism here!
+
+        return computeDischargeCurveData(wst, locations[0]);
+    }
+
+
+    /**
+     * Computes the data used to create computed discharge curves.
+     *
+     * @param wst The WstValueTable that is used for the interpolation.
+     * @param location The location where the computation should be based on.
+     *
+     * @return an object that contains tuples of W/Q values at the specified
+     * location.
+     */
+    public static WQKms computeDischargeCurveData(
+        WstValueTable wst,
+        double location)
+    {
+        logger.info("WINFOArtifact.computeDischargeCurveData");
+
+        double[][] wqs = wst.interpolateWQ(location);
+
+        if (wqs == null) {
+            logger.error("Cannot compute discharge curve data.");
+            return null;
+        }
+
+        double[] ws = wqs[0];
+        double[] qs = wqs[1];
+
+        WQKms wqkms = new WQKms(ws.length);
+
+        for (int i = 0; i < ws.length; i++) {
+            wqkms.add(ws[i], qs[i], location);
+        }
+
+        return wqkms;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org