annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 4248:fc742c039f30

Add model for MeasurementStation client side Add a client mode representing the MeasurementStation
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 24 Oct 2012 16:57:53 +0200
parents 2b4f78ccfbaa
children 64528d2a89c4
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
4163
2b4f78ccfbaa Made DoubleUtil.explode() more robust against invalid result array sizes.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4052
diff changeset
46 if (num < 1) {
2b4f78ccfbaa Made DoubleUtil.explode() more robust against invalid result array sizes.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4052
diff changeset
47 return new double[0];
2b4f78ccfbaa Made DoubleUtil.explode() more robust against invalid result array sizes.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4052
diff changeset
48 }
2b4f78ccfbaa Made DoubleUtil.explode() more robust against invalid result array sizes.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4052
diff changeset
49
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 double [] values = new double[num];
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 if (from > to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 step = -step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
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
56 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
57
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 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
59 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
60 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
61 }
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
62
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 values[idx] = round(lower, precision);
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 lower += step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 return values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 }
1671
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
69
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
70 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
71 double [] xs,
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
72 double [] ys,
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
73 double x
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 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
76
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
77 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
78
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
79 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
80 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
81 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
82 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
83 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
84 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
85 }
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
86 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
87 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
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], 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
90 }
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
91 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
92 ? Double.NaN
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
93 : 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
94 }
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
95
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 return true;
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 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
107 return false;
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 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
110 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
111 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
112
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
113 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
114 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
115 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
116 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
117 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
118 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
119 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
120 ++lo;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
121 --hi;
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
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
124 return array;
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
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
127 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
128 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
129
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
130 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
131 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
132 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
133
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
134 return out;
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
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
137 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
138 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
139
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
140 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
141 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
142 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
143
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
144 return out;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
145 }
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
146
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 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
148 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
149 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
150 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
151 }
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
152
4052
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
153
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
154 /** Use with parseSegments. */
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
155 public interface SegmentCallback {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
156 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
157 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
158
4052
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
159
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
160 /** Call callback for every string split by colon.
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3785
diff changeset
161 * 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
162 public static final void parseSegments(
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
163 String input,
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
164 SegmentCallback callback
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
165 ) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
166 TDoubleArrayList vs = new TDoubleArrayList();
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
167
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
168 for (String segmentStr: input.split(":")) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
169 String [] parts = segmentStr.split(";");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
170 if (parts.length < 3) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
171 log.warn("invalid segment: '" + segmentStr + "'");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
172 continue;
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 try {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
175 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
176 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
177
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
178 vs.resetQuick();
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 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
181 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
182 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
183
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
184 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
185 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
186 catch (NumberFormatException nfe) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
187 log.warn("invalid segment: '" + segmentStr + "'");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
188 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
189 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
190 }
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
191
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 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
193 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
194 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
195 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
196 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
197 }
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
198 }
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
199 }
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3776
diff changeset
200 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
201 }
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org