# HG changeset patch # User Felix Wolfsteller # Date 1379587890 -7200 # Node ID f4d6ef50665a3fd196848db63d7a0eee05df4a88 # Parent 3a55f49be15552bba2663cd3b25a834c45863331 issue1436: Repair sedimentload epoch calculation, get initial NaNs out of the way, they give a bad taste when building sums over them. diff -r 3a55f49be155 -r f4d6ef50665a artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java --- 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++; }