annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 3931:c79b98085096

Cosmetics, docs. flys-artifacts/trunk@5630 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Sep 2012 18:43:30 +0000
parents 00abcd3737f9
children 6d8c7a00e74e
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
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 public class DoubleUtil
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 {
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
13 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
14
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 public static final double DEFAULT_STEP_PRECISION = 1e6;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 private DoubleUtil() {
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 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
21 return explode(from, to, step, DEFAULT_STEP_PRECISION);
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 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
25 return Math.round(x * precision)/precision;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 public static final double round(double x) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 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
30 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 public static final double [] explode(
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 double from,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 double to,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 double step,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 double precision
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 ) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 double lower = from;
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 diff = to - from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 double tmp = diff / step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 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
43
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 double [] values = new double[num];
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 if (from > to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 step = -step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
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
50 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
51
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 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
53 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
54 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
55 }
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
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 values[idx] = round(lower, precision);
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 lower += step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 return values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 }
1671
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
63
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
64 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
65 double [] xs,
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
66 double [] ys,
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
67 double x
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
68 ) {
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
69 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
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 mid = -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 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
74 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
75 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
76 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
77 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
78 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
79 }
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
80 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
81 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
82 ? Double.NaN
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
83 : 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
84 }
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
85 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
86 ? Double.NaN
da872168a899 Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1666
diff changeset
87 : 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
88 }
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
89
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 return true;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
98 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
99 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
100 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
101 return false;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
102 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
103 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
104 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
105 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
106
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
107 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
108 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
109 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
110 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
111 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
112 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
113 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
114 ++lo;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
115 --hi;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
116 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
117
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
118 return array;
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
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
121 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
122 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
123
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
124 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
125 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
126 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
127
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
128 return out;
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
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
131 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
132 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
133
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
134 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
135 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
136 }
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
137
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
138 return out;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1671
diff changeset
139 }
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
140
0dd58ab7e118 Added functions to be used for fitting in the "Fixierungsanalyse" and "Extremwertermittlung".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
141 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
142 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
143 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
144 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
145 }
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
146
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
147 public interface SegmentCallback {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
148 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
149 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
150
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
151 public static final void parseSegments(
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
152 String input,
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
153 SegmentCallback callback
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
154 ) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
155 TDoubleArrayList vs = new TDoubleArrayList();
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
156
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
157 for (String segmentStr: input.split(":")) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
158 String [] parts = segmentStr.split(";");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
159 if (parts.length < 3) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
160 log.warn("invalid segment: '" + segmentStr + "'");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
161 continue;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
162 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
163 try {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
164 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
165 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
166
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
167 vs.resetQuick();
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
168
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
169 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
170 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
171 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
172
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
173 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
174 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
175 catch (NumberFormatException nfe) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
176 log.warn("invalid segment: '" + segmentStr + "'");
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 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2569
diff changeset
179 }
3877
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
180
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
181 public static final boolean isValid(double [][] data) {
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
182 for (double [] ds: data) {
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
183 for (double d: ds) {
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
184 if (Double.isNaN(d)) {
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
185 return false;
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
186 }
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
187 }
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
188 }
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
189 return true;
00abcd3737f9 Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3776
diff changeset
190 }
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org