changeset 7054:f4d6ef50665a

issue1436: Repair sedimentload epoch calculation, get initial NaNs out of the way, they give a bad taste when building sums over them.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 19 Sep 2013 12:51:30 +0200
parents 3a55f49be155
children 1f38656b68c4
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Thu Sep 19 10:39:15 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Thu Sep 19 12:51:30 2013 +0200
@@ -127,6 +127,14 @@
         return null;
     }
 
+
+    /** Returns val if not NaN, 0d otherwise. */
+    private static double makeNaN0(double val) {
+        return Double.isNaN(val)
+            ? 0d
+            : val;
+    }
+
     /**
      * Take Loads and build average of all fractions at given km.
      * The average fractions value is set in resLoad.
@@ -149,32 +157,32 @@
         for (SedimentLoad load : epochLoads) {
             SedimentLoadFraction f = load.getFraction(km);
             if (f.getCoarse() > 0d) {
-                double c = resLoad.getFraction(km).getCoarse();
+                double c = makeNaN0(resLoad.getFraction(km).getCoarse());
                 resLoad.setCoarse(km, c + f.getCoarse(), f.getCoarseRange());
                 cSum++;
             }
             if (f.getFineMiddle() > 0d) {
-                double fm = resLoad.getFraction(km).getFineMiddle();
+                double fm = makeNaN0(resLoad.getFraction(km).getFineMiddle());
                 resLoad.setFineMiddle(km, fm + f.getFineMiddle(), f.getFineMiddleRange());
                 fmSum++;
             }
             if (f.getSand() > 0d) {
-                double s = resLoad.getFraction(km).getSand();
+                double s = makeNaN0(resLoad.getFraction(km).getSand());
                 resLoad.setSand(km, s + f.getSand(), f.getSandRange());
                 sSum++;
             }
             if (f.getSuspSand() > 0d) {
-                double s = resLoad.getFraction(km).getSuspSand();
+                double s = makeNaN0(resLoad.getFraction(km).getSuspSand());
                 resLoad.setSuspSand(km, s + f.getSuspSand(), f.getSuspSandRange());
                 ssSum++;
             }
             if (f.getSuspSandBed() > 0d) {
-                double s = resLoad.getFraction(km).getSuspSandBed();
+                double s = makeNaN0(resLoad.getFraction(km).getSuspSandBed());
                 resLoad.setSuspSandBed(km, s + f.getSuspSandBed(), f.getSuspSandBedRange());
                 ssbSum++;
             }
             if (f.getSuspSediment() > 0d) {
-                double s = resLoad.getFraction(km).getSuspSediment();
+                double s = makeNaN0(resLoad.getFraction(km).getSuspSediment());
                 resLoad.setSuspSediment(km, s + f.getSuspSediment(), f.getSuspSedimentRange());
                 sseSum++;
             }

http://dive4elements.wald.intevation.org