# HG changeset patch # User Sascha L. Teichmann # Date 1304343722 0 # Node ID 20c3a5b36434c6cec2bcffc87c332f7bea2401b6 # Parent 0ccf7200fc518c4e9ca70b9a9b0b95c4fe5c4633 Repaired DischargeTables.getQForW() flys-artifacts/trunk@1790 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 0ccf7200fc51 -r 20c3a5b36434 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon May 02 12:47:10 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon May 02 13:42:02 2011 +0000 @@ -1,3 +1,8 @@ +2011-05-02 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java: + Repaired getQForW() by calculating indices on right dimension. + 2011-05-02 Ingo Weinzierl * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: New diff -r 0ccf7200fc51 -r 20c3a5b36434 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java Mon May 02 12:47:10 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java Mon May 02 13:42:02 2011 +0000 @@ -180,6 +180,13 @@ } public static double getQForW(double [][] values, double w) { + + boolean debug = log.isDebugEnabled(); + + if (debug) { + log.debug("calculating getQForW(" + w + ")"); + } + int index = Arrays.binarySearch(values[0], w); if (index >= 0) { return values[0][index]; @@ -187,15 +194,18 @@ index = -index - 1; // insert position - if (index < 1 || index >= values.length) { + if (index < 1 || index >= values[0].length) { // do not extraploate + if (debug) { + log.debug("we do not extrapolate: NaN"); + } return Double.NaN; } - double w1 = values[index-1][0]; - double w2 = values[index ][0]; - double q1 = values[index-1][1]; - double q2 = values[index ][1]; + double w1 = values[0][index-1]; + double w2 = values[0][index ]; + double q1 = values[1][index-1]; + double q2 = values[1][index ]; // q1 = m*w1 + b // q2 = m*w2 + b @@ -203,13 +213,22 @@ // m = (q2 - q1)/(w2 - w1) # w2 != w1 // b = q1 - m*w1 + double q; if (w1 == w2) { - return 0.5*(q1 + q2); + q = 0.5*(q1 + q2); + if (debug) { + log.debug("same w1 and w1: " + w1); + } } - - double m = (q2 - q1)/(w2 - w1); - double b = q1 - m*w1; - return w*m + b; + else { + double m = (q2 - q1)/(w2 - w1); + double b = q1 - m*w1; + q = w*m + b; + } + if (debug) { + log.debug("Q(" + w + ") = " + q); + } + return q; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :