comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java @ 674:d5f9ba1d055f

Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism. flys-artifacts/trunk@2098 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 10 Jun 2011 09:19:27 +0000
parents 60f24fca574a
children c09c9e05ecfa
comparison
equal deleted inserted replaced
673:b22f21b173a7 674:d5f9ba1d055f
12 import org.apache.commons.math.ArgumentOutsideDomainException; 12 import org.apache.commons.math.ArgumentOutsideDomainException;
13 13
14 import org.apache.commons.math.exception.MathIllegalArgumentException; 14 import org.apache.commons.math.exception.MathIllegalArgumentException;
15 15
16 import org.apache.log4j.Logger; 16 import org.apache.log4j.Logger;
17
18 import de.intevation.flys.artifacts.model.Calculation;
17 19
18 public class BackJumpCorrector 20 public class BackJumpCorrector
19 implements Serializable 21 implements Serializable
20 { 22 {
21 private static Logger log = Logger.getLogger(BackJumpCorrector.class); 23 private static Logger log = Logger.getLogger(BackJumpCorrector.class);
38 40
39 public double [] getCorrected() { 41 public double [] getCorrected() {
40 return corrected; 42 return corrected;
41 } 43 }
42 44
43 public boolean doCorrection(double [] km, double [] ws) { 45 public boolean doCorrection(
44 46 double [] km,
47 double [] ws,
48 Calculation errors
49 ) {
45 boolean wsUp = isIncreasing(ws); 50 boolean wsUp = isIncreasing(ws);
46 51
47 if (wsUp) { 52 if (wsUp) {
48 km = swapClone(km); 53 km = swapClone(km);
49 ws = swapClone(ws); 54 ws = swapClone(ws);
60 log.debug(" km increasing: " + isIncreasing(km)); 65 log.debug(" km increasing: " + isIncreasing(km));
61 log.debug(" ws increasing: " + isIncreasing(ws)); 66 log.debug(" ws increasing: " + isIncreasing(ws));
62 log.debug("BackJumpCorrector.doCorrection ------- leave"); 67 log.debug("BackJumpCorrector.doCorrection ------- leave");
63 } 68 }
64 69
65 boolean hasBackJumps = doCorrectionClean(km, ws); 70 boolean hasBackJumps = doCorrectionClean(km, ws, errors);
66 71
67 if (hasBackJumps && wsUp) { 72 if (hasBackJumps && wsUp) {
68 // mirror back 73 // mirror back
69 swap(corrected); 74 swap(corrected);
70 } 75 }
71 76
72 return hasBackJumps; 77 return hasBackJumps;
73 } 78 }
74 79
75 protected boolean doCorrectionClean(double [] km, double [] ws) { 80 protected boolean doCorrectionClean(
81 double [] km,
82 double [] ws,
83 Calculation errors
84 ) {
76 int N = km.length; 85 int N = km.length;
77 86
78 if (N != ws.length) { 87 if (N != ws.length) {
79 throw new IllegalArgumentException("km.length != ws.length"); 88 throw new IllegalArgumentException("km.length != ws.length");
80 } 89 }
199 208
200 try { 209 try {
201 spline = interpolator.interpolate(x, y); 210 spline = interpolator.interpolate(x, y);
202 } 211 }
203 catch (MathIllegalArgumentException miae) { 212 catch (MathIllegalArgumentException miae) {
213 // TODO: I18N
214 errors.addProblem("creating spline interpolation failed.");
204 log.error(miae); 215 log.error(miae);
205 continue; 216 continue;
206 } 217 }
207 218
208 try { 219 try {
224 // fill the rest with ws[i] 235 // fill the rest with ws[i]
225 ws[back++] = ws[i]; 236 ws[back++] = ws[i];
226 } 237 }
227 } 238 }
228 catch (ArgumentOutsideDomainException aode) { 239 catch (ArgumentOutsideDomainException aode) {
240 // TODO: I18N
241 errors.addProblem("spline interpolation failed.");
229 log.error("spline interpolation failed", aode); 242 log.error("spline interpolation failed", aode);
230 } 243 }
231 } // for all km 244 } // for all km
232 245
233 return !backjumps.isEmpty(); 246 return !backjumps.isEmpty();

http://dive4elements.wald.intevation.org