Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java @ 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 | aa0889141b15 |
children | db68806e6563 |
comparison
equal
deleted
inserted
replaced
377:0ccf7200fc51 | 378:20c3a5b36434 |
---|---|
178 | 178 |
179 return values; | 179 return values; |
180 } | 180 } |
181 | 181 |
182 public static double getQForW(double [][] values, double w) { | 182 public static double getQForW(double [][] values, double w) { |
183 | |
184 boolean debug = log.isDebugEnabled(); | |
185 | |
186 if (debug) { | |
187 log.debug("calculating getQForW(" + w + ")"); | |
188 } | |
189 | |
183 int index = Arrays.binarySearch(values[0], w); | 190 int index = Arrays.binarySearch(values[0], w); |
184 if (index >= 0) { | 191 if (index >= 0) { |
185 return values[0][index]; | 192 return values[0][index]; |
186 } | 193 } |
187 | 194 |
188 index = -index - 1; // insert position | 195 index = -index - 1; // insert position |
189 | 196 |
190 if (index < 1 || index >= values.length) { | 197 if (index < 1 || index >= values[0].length) { |
191 // do not extraploate | 198 // do not extraploate |
199 if (debug) { | |
200 log.debug("we do not extrapolate: NaN"); | |
201 } | |
192 return Double.NaN; | 202 return Double.NaN; |
193 } | 203 } |
194 | 204 |
195 double w1 = values[index-1][0]; | 205 double w1 = values[0][index-1]; |
196 double w2 = values[index ][0]; | 206 double w2 = values[0][index ]; |
197 double q1 = values[index-1][1]; | 207 double q1 = values[1][index-1]; |
198 double q2 = values[index ][1]; | 208 double q2 = values[1][index ]; |
199 | 209 |
200 // q1 = m*w1 + b | 210 // q1 = m*w1 + b |
201 // q2 = m*w2 + b | 211 // q2 = m*w2 + b |
202 // q2 - q1 = m*(w2 - w1) | 212 // q2 - q1 = m*(w2 - w1) |
203 // m = (q2 - q1)/(w2 - w1) # w2 != w1 | 213 // m = (q2 - q1)/(w2 - w1) # w2 != w1 |
204 // b = q1 - m*w1 | 214 // b = q1 - m*w1 |
205 | 215 |
216 double q; | |
206 if (w1 == w2) { | 217 if (w1 == w2) { |
207 return 0.5*(q1 + q2); | 218 q = 0.5*(q1 + q2); |
208 } | 219 if (debug) { |
209 | 220 log.debug("same w1 and w1: " + w1); |
210 double m = (q2 - q1)/(w2 - w1); | 221 } |
211 double b = q1 - m*w1; | 222 } |
212 return w*m + b; | 223 else { |
224 double m = (q2 - q1)/(w2 - w1); | |
225 double b = q1 - m*w1; | |
226 q = w*m + b; | |
227 } | |
228 if (debug) { | |
229 log.debug("Q(" + w + ") = " + q); | |
230 } | |
231 return q; | |
213 } | 232 } |
214 } | 233 } |
215 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 234 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |