annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java @ 686:3dc61e00385e facets-slt

Merged with trunk and introduced hashing of computed values. flys-artifacts/branches/facets-slt@2126 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 15 Jun 2011 15:28:54 +0000
parents 60f24fca574a
children c09c9e05ecfa
rev   line source
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.math;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.List;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.io.Serializable;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import org.apache.commons.math.analysis.interpolation.SplineInterpolator;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import org.apache.commons.math.ArgumentOutsideDomainException;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
14 import org.apache.commons.math.exception.MathIllegalArgumentException;
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
15
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
18 import de.intevation.flys.artifacts.model.Calculation;
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
19
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public class BackJumpCorrector
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 implements Serializable
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 private static Logger log = Logger.getLogger(BackJumpCorrector.class);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 protected ArrayList<Double> backjumps;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 protected double [] corrected;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public BackJumpCorrector() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 backjumps = new ArrayList<Double>();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 public boolean hasBackJumps() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 return !backjumps.isEmpty();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 public List<Double> getBackJumps() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 return backjumps;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 public double [] getCorrected() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 return corrected;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
45 public boolean doCorrection(
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
46 double [] km,
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
47 double [] ws,
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
48 Calculation errors
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
49 ) {
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
50 boolean wsUp = isIncreasing(ws);
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
51
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
52 if (wsUp) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
53 km = swapClone(km);
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
54 ws = swapClone(ws);
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
55 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
56
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
57 boolean kmUp = isIncreasing(km);
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
58
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
59 if (!kmUp) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
60 km = sumDiffs(km);
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
61 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
62
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
63 if (log.isDebugEnabled()) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
64 log.debug("BackJumpCorrector.doCorrection ------- enter");
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
65 log.debug(" km increasing: " + isIncreasing(km));
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
66 log.debug(" ws increasing: " + isIncreasing(ws));
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
67 log.debug("BackJumpCorrector.doCorrection ------- leave");
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
68 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
69
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
70 boolean hasBackJumps = doCorrectionClean(km, ws, errors);
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
71
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
72 if (hasBackJumps && wsUp) {
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
73 // mirror back
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
74 swap(corrected);
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
75 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
76
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
77 return hasBackJumps;
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
78 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
79
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
80 protected boolean doCorrectionClean(
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
81 double [] km,
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
82 double [] ws,
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
83 Calculation errors
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
84 ) {
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 int N = km.length;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 if (N != ws.length) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 throw new IllegalArgumentException("km.length != ws.length");
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 if (N < 2) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 return false;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 SplineInterpolator interpolator = null;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 for (int i = 1; i < N; ++i) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 if (ws[i] <= ws[i-1]) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 // no back jump
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 continue;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 backjumps.add(km[i]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 if (corrected == null) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 // lazy cloning
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 ws = corrected = (double [])ws.clone();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 int back = i-2;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 double distance = Math.abs(km[i] - km[i-1]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 double rest = 0.0;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 double ikm = 0.0;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 while (back > -1) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 if (ws[back] < ws[i]) { // under water
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 // continue scanning backwards
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 distance += Math.abs(km[back+1] - km[back]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 --back;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 continue;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 if (ws[back] > ws[i]) { // over water
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 // need to calculate intersection
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 log.debug("intersection case");
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 double m = (km[back+1]-km[back])/(ws[back+1]-ws[back]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 double b = km[back]-ws[back]*m;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 ikm = m*ws[i] + b;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 distance += Math.abs(ikm - km[back+1]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 rest = Math.abs(km[back] - ikm);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 else {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 // equals height at ws[back]
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 log.debug("exact height match");
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 distance += Math.abs(km[back+1] - km[back]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 ikm = km[back];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 break;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
139 if (back <= 0) {
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
140 //log.debug("run over left border");
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 // fill with same as ws[i]
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 for (int j = 0; j < i; ++j) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 ws[j] = ws[i];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 continue;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 double quarterDistance = 0.25*distance;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 // Now further seek back for the max height
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 double restDistance = Math.max(0.0, quarterDistance - rest);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 --back;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 double mkmw = ws[i];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 double mkm = km[0];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 while (back > -1) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 double d = Math.abs(km[back+1] - km[back]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 restDistance -= d;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 if (restDistance > 0.0) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 --back;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 continue;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 if (restDistance < 0.0) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 // need to calculate intersection
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 if (km[back] == km[back+1]) { // should not happen
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 mkm = km[back];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 mkmw = 0.5*(ws[back] + ws[back+1]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 else {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 double m = (ws[back+1]-ws[back])/(km[back+1]-km[back]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 double b = ws[back] - km[back]*m;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 mkm = km[back] + restDistance;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 mkmw = m*mkm + b;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 else {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 // exact match
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 mkm = km[back];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 mkmw = ws[back];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 break;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 double factor = back >= 0 && Math.abs(restDistance) < 1e-4
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 ? 1.0
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 : 1.0 - Math.min(1, Math.max(0, restDistance/quarterDistance));
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 double ikmw = factor*0.25*(mkmw-ws[i]) + ws[i];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 double end = ikm + quarterDistance*factor;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 double [] x = { mkm, ikm, end };
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 double [] y = { mkmw, ikmw, ws[i] };
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 if (interpolator == null) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 interpolator = new SplineInterpolator();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
201 if (log.isDebugEnabled()) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
202 for (int j = 0; j < x.length; ++j) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
203 log.debug(" " + x[j] + " -> " + y[j]);
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
204 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
205 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
206
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
207 PolynomialSplineFunction spline;
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
208
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
209 try {
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
210 spline = interpolator.interpolate(x, y);
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
211 }
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
212 catch (MathIllegalArgumentException miae) {
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
213 // TODO: I18N
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
214 errors.addProblem("creating spline interpolation failed.");
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
215 log.error(miae);
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
216 continue;
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
217 }
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219 try {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220 if (log.isDebugEnabled()) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 log.debug("spline points:");
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 for (int j = 0; j < x.length; ++j) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 log.debug(x[j] + " " + y[j] + " " + spline.value(x[j]));
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227 for (back = Math.max(back, 0);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 back < i && km[back] < end;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 ++back
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230 ) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 // to 3/4 point fill with spline values
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 ws[back] = spline.value(km[back]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 while (back < i) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235 // fill the rest with ws[i]
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 ws[back++] = ws[i];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 catch (ArgumentOutsideDomainException aode) {
686
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
240 // TODO: I18N
3dc61e00385e Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 662
diff changeset
241 errors.addProblem("spline interpolation failed.");
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
242 log.error("spline interpolation failed", aode);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
244 } // for all km
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
245
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246 return !backjumps.isEmpty();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247 }
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
248
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
249 public static final boolean isIncreasing(double [] array) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
250 int inc = 0;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
251 int dec = 0;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
252 int sweet = (array.length-1)/2;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
253 for (int i = 1; i < array.length; ++i) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
254 if (array[i] > array[i-1]) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
255 if (++inc > sweet) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
256 return true;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
257 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
258 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
259 else if (++dec > sweet) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
260 return false;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
261 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
262 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
263 return inc > sweet;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
264 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
265
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
266 public static final double [] swap(double [] array) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
267 int lo = 0;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
268 int hi = array.length-1;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
269 while (hi > lo) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
270 double t = array[lo];
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
271 array[lo] = array[hi];
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
272 array[hi] = t;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
273 ++lo;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
274 --hi;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
275 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
276
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
277 return array;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
278 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
279
662
60f24fca574a BackJumpCorrector: Simpified array swapping.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 649
diff changeset
280 public static final double [] swapClone(double [] in) {
60f24fca574a BackJumpCorrector: Simpified array swapping.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 649
diff changeset
281 double [] out = new double[in.length];
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
282
662
60f24fca574a BackJumpCorrector: Simpified array swapping.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 649
diff changeset
283 for (int j = out.length-1, i = 0; j >= 0;) {
60f24fca574a BackJumpCorrector: Simpified array swapping.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 649
diff changeset
284 out[j--] = in[i++];
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
285 }
662
60f24fca574a BackJumpCorrector: Simpified array swapping.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 649
diff changeset
286
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
287 return out;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
288 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
289
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
290 public static final double [] sumDiffs(double [] in) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
291 double [] out = new double[in.length];
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
292
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
293 for (int i = 1; i < out.length; ++i) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
294 out[i] = out[i-1] + Math.abs(in[i-1] - in[i]);
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
295 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
296
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
297 return out;
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
298 }
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
299 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
300 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org