# HG changeset patch # User Sascha L. Teichmann # Date 1304804042 0 # Node ID 663aa18bee7fa6e13602960161ab58cb22fb487f # Parent 55c2b0d9999e1f65da82b1381b4166a451ff8d63 Back jump correction should work now for both flow directions. flys-artifacts/trunk@1848 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 55c2b0d9999e -r 663aa18bee7f flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri May 06 16:49:31 2011 +0000 +++ b/flys-artifacts/ChangeLog Sat May 07 21:34:02 2011 +0000 @@ -1,3 +1,9 @@ +2011-05-07 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java: + Added code to make back jump correction work with both + potential flow directions. + 2011-05-06 Sascha L. Teichmann * src/main/resources/metadata/template.xml: diff -r 55c2b0d9999e -r 663aa18bee7f flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java Fri May 06 16:49:31 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java Sat May 07 21:34:02 2011 +0000 @@ -38,7 +38,47 @@ return corrected; } + private static final boolean isIncreasing(double [] ws) { + int inc = 0; + int dec = 0; + int sweet = (ws.length-1)/2; + for (int i = 1; i < ws.length; ++i) { + if (ws[i] > ws[i-1]) { + if (++inc > sweet) { + return true; + } + } + else if (++dec > sweet) { + return false; + } + } + return inc > sweet; + } + public boolean doCorrection(double [] km, double [] ws) { + boolean isIncreasing = isIncreasing(ws); + + if (isIncreasing) { + // mirror along x axis to simulate decreasing values + ws = (double [])ws.clone(); + for (int i = 0; i < ws.length; ++i) { + ws[i] = -ws[i]; + } + } + + boolean hasBackJumps = doCorrectionClean(km, ws); + + if (hasBackJumps && isIncreasing) { + // mirror back + for (int i = 0; i < corrected.length; ++i) { + corrected[i] = -corrected[i]; + } + } + + return hasBackJumps; + } + + protected boolean doCorrectionClean(double [] km, double [] ws) { int N = km.length; if (N != ws.length) {