changeset 6543:1ca0688dddc7

issue1235: Prevent division by zeros leading to NaNs.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 08 Jul 2013 10:25:25 +0200 (2013-07-08)
parents c5945aca0c8d
children b24dc0320b75
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java
diffstat 1 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Fri Jul 05 12:16:46 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Mon Jul 08 10:25:25 2013 +0200
@@ -187,12 +187,28 @@
                 }
             }
             SedimentLoadFraction fr = resLoad.getFraction(km);
-            resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
-            resLoad.setFineMiddle(km, fr.getFineMiddle()/fmSum, fr.getFineMiddleRange());
-            resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
-            resLoad.setSuspSand(km, fr.getSuspSand()/ssSum, fr.getSuspSandRange());
-            resLoad.setSuspSandBed(km, fr.getSuspSandBed()/ssbSum, fr.getSuspSandBedRange());
-            resLoad.setSuspSediment(km, fr.getSuspSediment()/sseSum, fr.getSuspSedimentRange());
+            // Prevent divisions by zero, the fraction defaults to 0d.
+            if (cSum != 0) {
+                resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
+            }
+            if (fmSum != 0) {
+                resLoad.setFineMiddle(km, fr.getFineMiddle()/fmSum,
+                    fr.getFineMiddleRange());
+            }
+            if (sSum != 0) {
+                resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
+            }
+            if (ssSum != 0) {
+                resLoad.setSuspSand(km, fr.getSuspSand()/ssSum,
+                    fr.getSuspSandRange());
+            }
+            if (ssbSum != 0) {
+                resLoad.setSuspSandBed(km, fr.getSuspSandBed()/ssbSum,
+                    fr.getSuspSandBedRange());
+            }
+            if (sseSum != 0) {
+                resLoad.setSuspSediment(km, fr.getSuspSediment()/sseSum, fr.getSuspSedimentRange());
+            }
         }
         resLoad.setDescription("");
         resLoad.setEpoch(true);

http://dive4elements.wald.intevation.org