diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents b10f8415798c
children 45f1ad66560e
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java	Tue Mar 13 09:55:53 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java	Tue Mar 13 18:49:33 2018 +0100
@@ -46,14 +46,20 @@
 
     public DischargeValuesFinder(final QKms qKms) {
         this.qKms = qKms;
-        this.qInterpolator = qKms == null ? null : DoubleUtil.getLinearInterpolator(qKms.allKms(), qKms.allQs());
-
-        this.exactValues = new TDoubleDoubleHashMap(qKms.size());
 
-        for (int i = 0; i < qKms.size(); i++) {
-            final double station = qKms.getKm(i);
-            final double discharge = qKms.getQ(i);
-            this.exactValues.put(station, discharge);
+        if (qKms == null) {
+            this.qInterpolator = null;
+            this.exactValues = null;
+        } else {
+            this.qInterpolator = DoubleUtil.getLinearInterpolator(qKms.allKms(), qKms.allQs());
+
+            this.exactValues = new TDoubleDoubleHashMap(qKms.size());
+
+            for (int i = 0; i < qKms.size(); i++) {
+                final double station = qKms.getKm(i);
+                final double discharge = qKms.getQ(i);
+                this.exactValues.put(station, discharge);
+            }
         }
     }
 
@@ -68,14 +74,23 @@
         return new DoubleRange(this.qKms.allQs().min(), this.qKms.allQs().max());
     }
 
-    public double getDischarge(final double station) throws FunctionEvaluationException {
+    public double getDischarge(final double station) {
 
-        // IMPORTANT: we first try to retreive the exact value if it is present, to avoid rounding changes due to interpolation.
-        // This is important because in the WaterlevelExporter code, these values are double-compared (with '==' ...) in order
-        // to find the corresponding main-value.
-        if (this.exactValues.contains(station))
-            return this.exactValues.get(station);
+        try {
+            // IMPORTANT: we first try to retrieve the exact value if it is present, to avoid rounding changes due to interpolation.
+            // This is important because in the WaterlevelExporter code, these values are double-compared (with '==' ...) in order
+            // to find the corresponding main-value.
+            if (this.exactValues != null && this.exactValues.contains(station))
+                return this.exactValues.get(station);
 
-        return this.qInterpolator.value(station);
+            if (this.qInterpolator == null)
+                return Double.NaN;
+
+            return this.qInterpolator.value(station);
+        }
+        catch (final FunctionEvaluationException e) {
+            e.printStackTrace();
+            return Double.NaN;
+        }
     }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org