Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthUtils.java @ 9382:8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
author | mschaefer |
---|---|
date | Tue, 07 Aug 2018 14:06:49 +0200 |
parents | b194fa64506a |
children | 83e6acdf8fc6 |
rev | line source |
---|---|
8946 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.flowdepth; | |
11 | |
12 import org.dive4elements.river.artifacts.model.Calculation; | |
9382
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
13 import org.dive4elements.river.utils.Formatter; |
8946 | 14 |
15 /** | |
16 * @author Gernot Belger | |
17 */ | |
18 public final class FlowDepthUtils { | |
19 | |
20 private FlowDepthUtils() { | |
21 throw new UnsupportedOperationException(); | |
22 } | |
23 | |
24 /** | |
25 * Checks the year difference between waterlevels and sounding, and issues a warning if too big. | |
26 * | |
27 * Zeitraum Zeitliche Differenz [a] | |
28 * X ≥ 1998 ± 3 | |
29 * 1958 ≤ X < 1998 ± 6 | |
30 * 1918 ≤ X < 1958 ± 12 | |
31 * X < 1918 ± 25 | |
32 */ | |
8951 | 33 public static void checkYearDifference(final String label, final int wstYear, final int soundingYear, final Calculation problems) { |
8946 | 34 |
35 if (wstYear < 0) | |
36 return; | |
37 | |
38 final int maxDifference = getMaxDifferenceYears(soundingYear); | |
39 | |
40 final int difference = Math.abs(soundingYear - wstYear); | |
8980
b194fa64506a
SINFO - show results themes according to spec, either raw data or floating mean values.
gernotbelger
parents:
8951
diff
changeset
|
41 if (difference > maxDifference) |
b194fa64506a
SINFO - show results themes according to spec, either raw data or floating mean values.
gernotbelger
parents:
8951
diff
changeset
|
42 problems.addProblem("sinfo_calc_flow_depth.warning.year_difference", label, Integer.toString(wstYear), Integer.toString(soundingYear)); |
8946 | 43 } |
44 | |
45 public static int getMaxDifferenceYears(final int year) { | |
46 | |
47 if (year < 1918) | |
48 return 25; | |
49 | |
50 if (1918 <= year && year < 1958) | |
51 return 12; | |
52 | |
53 if (1958 <= year && year < 1998) | |
54 return 6; | |
55 | |
56 /* >= 1998 */ | |
57 return 3; | |
58 } | |
9382
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
59 |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
60 /** |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
61 * Calculates a flow depth, rounded to the active scale |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
62 */ |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
63 public static double calcFlowDepth(final double wst, final double bedHeight) { |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
64 if (Double.isNaN(wst) || Double.isInfinite(wst) || Double.isNaN(bedHeight) || Double.isInfinite(bedHeight)) |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
65 return Math.max(wst - bedHeight, 0.0); |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
66 return Math.max(Formatter.roundFlowDepth(wst).subtract(Formatter.roundFlowDepth(bedHeight)).doubleValue(), 0.0); |
8ae7137b67d7
Fixed: avoiding NaN exception in BigDecimal rounding
mschaefer
parents:
8980
diff
changeset
|
67 } |
8946 | 68 } |