Mercurial > dive4elements > river
changeset 378:20c3a5b36434
Repaired DischargeTables.getQForW()
flys-artifacts/trunk@1790 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 02 May 2011 13:42:02 +0000 |
parents | 0ccf7200fc51 |
children | c21fb8de54f8 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java |
diffstat | 2 files changed, 34 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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 <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java: + Repaired getQForW() by calculating indices on right dimension. + 2011-05-02 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: New
--- 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 :