annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 4065:9d404069f361

Added build script for FLYS release.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 09 Oct 2012 12:30:13 +0200
parents 6d8c7a00e74e
children 2b4f78ccfbaa
rev   line source
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.utils;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
3 import de.intevation.flys.artifacts.math.Linear;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
4
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
5 import gnu.trove.TDoubleArrayList;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
6
1666
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
7 import java.util.Arrays;
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
8
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
9 import org.apache.log4j.Logger;
1666
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
10
4052
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
11 /** Utils to deal with Double precision values. */
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 public class DoubleUtil
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 {
4052
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
14 /** Private logger. */
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
15 private static Logger log = Logger.getLogger(DoubleUtil.class);
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
16
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 public static final double DEFAULT_STEP_PRECISION = 1e6;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 private DoubleUtil() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public static final double [] explode(double from, double to, double step) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 return explode(from, to, step, DEFAULT_STEP_PRECISION);
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 public static final double round(double x, double precision) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 return Math.round(x * precision)/precision;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public static final double round(double x) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 return Math.round(x * DEFAULT_STEP_PRECISION)/DEFAULT_STEP_PRECISION;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public static final double [] explode(
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 double from,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 double to,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 double step,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 double precision
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 ) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 double lower = from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 double diff = to - from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 double tmp = diff / step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 int num = (int)Math.abs(Math.ceil(tmp)) + 1;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 double [] values = new double[num];
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 if (from > to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 step = -step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
1666
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
52 double max = Math.max(from, to);
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
53
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 for (int idx = 0; idx < num; idx++) {
1666
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
55 if (lower > max) {
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
56 return Arrays.copyOfRange(values, 0, idx);
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
57 }
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
58
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 values[idx] = round(lower, precision);
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 lower += step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 return values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
1671
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
65
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
66 public static final double interpolateSorted(
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
67 double [] xs,
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
68 double [] ys,
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
69 double x
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
70 ) {
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
71 int lo = 0, hi = xs.length-1;
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
72
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
73 int mid = -1;
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
74
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
75 while (lo <= hi) {
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
76 mid = (lo + hi) >> 1;
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
77 double mx = xs[mid];
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
78 if (x < mx) hi = mid - 1;
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
79 else if (x > mx) lo = mid + 1;
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
80 else return ys[mid];
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
81 }
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
82 if (mid < lo) {
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
83 return lo >= xs.length
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
84 ? Double.NaN
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
85 : Linear.linear(x, xs[mid], xs[mid+1], ys[mid], ys[mid+1]);
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
86 }
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
87 return hi < 0
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
88 ? Double.NaN
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
89 : Linear.linear(x, xs[mid-1], xs[mid], ys[mid-1], ys[mid]);
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
90 }
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
91
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
92 public static final boolean isIncreasing(double [] array) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
93 int inc = 0;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
94 int dec = 0;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
95 int sweet = (array.length-1)/2;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
96 for (int i = 1; i < array.length; ++i) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
97 if (array[i] > array[i-1]) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
98 if (++inc > sweet) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
99 return true;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
100 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
101 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
102 else if (++dec > sweet) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
103 return false;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
104 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
105 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
106 return inc > sweet;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
107 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
108
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
109 public static final double [] swap(double [] array) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
110 int lo = 0;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
111 int hi = array.length-1;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
112 while (hi > lo) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
113 double t = array[lo];
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
114 array[lo] = array[hi];
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
115 array[hi] = t;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
116 ++lo;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
117 --hi;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
118 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
119
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
120 return array;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
121 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
122
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
123 public static final double [] swapClone(double [] in) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
124 double [] out = new double[in.length];
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
125
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
126 for (int j = out.length-1, i = 0; j >= 0;) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
127 out[j--] = in[i++];
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
128 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
129
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
130 return out;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
131 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
132
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
133 public static final double [] sumDiffs(double [] in) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
134 double [] out = new double[in.length];
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
135
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
136 for (int i = 1; i < out.length; ++i) {
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
137 out[i] = out[i-1] + Math.abs(in[i-1] - in[i]);
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
138 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
139
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
140 return out;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
141 }
2569
0dd58ab7e118 Added functions to be used for fitting in the "Fixierungsanalyse" and "Extremwertermittlung".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
142
0dd58ab7e118 Added functions to be used for fitting in the "Fixierungsanalyse" and "Extremwertermittlung".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
143 public static final double [] fill(int N, double value) {
0dd58ab7e118 Added functions to be used for fitting in the "Fixierungsanalyse" and "Extremwertermittlung".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
144 double [] result = new double[N];
0dd58ab7e118 Added functions to be used for fitting in the "Fixierungsanalyse" and "Extremwertermittlung".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
145 Arrays.fill(result, value);
0dd58ab7e118 Added functions to be used for fitting in the "Fixierungsanalyse" and "Extremwertermittlung".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
146 return result;
0dd58ab7e118 Added functions to be used for fitting in the "Fixierungsanalyse" and "Extremwertermittlung".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
147 }
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
148
4052
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
149
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
150 /** Use with parseSegments. */
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
151 public interface SegmentCallback {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
152 void newSegment(double from, double to, double [] values);
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
153 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
154
4052
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
155
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
156 /** Call callback for every string split by colon.
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
157 * Expected format FROM:TO:VALUE1,VALUE2,VALUE3*/
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
158 public static final void parseSegments(
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
159 String input,
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
160 SegmentCallback callback
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
161 ) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
162 TDoubleArrayList vs = new TDoubleArrayList();
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
163
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
164 for (String segmentStr: input.split(":")) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
165 String [] parts = segmentStr.split(";");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
166 if (parts.length < 3) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
167 log.warn("invalid segment: '" + segmentStr + "'");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
168 continue;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
169 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
170 try {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
171 double from = Double.parseDouble(parts[0].trim());
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
172 double to = Double.parseDouble(parts[1].trim());
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
173
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
174 vs.resetQuick();
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
175
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
176 for (String valueStr: parts[2].split(",")) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
177 vs.add(round(Double.parseDouble(valueStr.trim())));
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
178 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
179
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
180 callback.newSegment(from, to, vs.toNativeArray());
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
181 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
182 catch (NumberFormatException nfe) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
183 log.warn("invalid segment: '" + segmentStr + "'");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
184 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
185 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
186 }
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
187
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
188 public static final boolean isValid(double [][] data) {
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
189 for (double [] ds: data) {
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
190 for (double d: ds) {
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
191 if (Double.isNaN(d)) {
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
192 return false;
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
193 }
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
194 }
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
195 }
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
196 return true;
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
197 }
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org