Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/ATWriter.java @ 1033:821aaceb2776
Fix for flys/issue191
flys-artifacts/trunk@2494 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 15 Aug 2011 10:56:58 +0000 |
parents | 65dcb5891206 |
children | 7d11ad5a52d5 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ATWriter.java Fri Aug 12 12:54:19 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ATWriter.java Mon Aug 15 10:56:58 2011 +0000 @@ -39,52 +39,39 @@ public ATWriter(WQ wq) throws IllegalArgumentException { - int maxIndex = maxIncreasingWIndex(wq); + int [] bounds = wq.longestIncreasingWRangeIndices(); - if (maxIndex < 1) { // Only first w can be written out. - minW = maxW = wq.getW(0); - minQ = maxQ = wq.getQ(0); + if (logger.isDebugEnabled()) { + logger.debug("exporting w between indices " + + bounds[0] + " and " + bounds[1] + " (" + + wq.getW(bounds[0]) + ", " + wq.getW(bounds[1])); + } + + if (bounds[1]-bounds[0] < 1) { // Only first w can be written out. + minW = maxW = wq.getW(bounds[0]); + minQ = maxQ = wq.getQ(bounds[0]); // constant function qFunc = new PolynomialFunction(new double [] { minQ }); return; } - double [] ws = new double[maxIndex]; + double [] ws = new double[bounds[1]-bounds[0]]; double [] qs = new double[ws.length]; for (int i = 0; i < ws.length; ++i) { - ws[i] = wq.getW(i); - qs[i] = wq.getQ(i); + int idx = bounds[0]+i; + ws[i] = wq.getW(idx); + qs[i] = wq.getQ(idx); } qFunc = ws.length < 3 ? new LinearInterpolator().interpolate(ws, qs) : new SplineInterpolator().interpolate(ws, qs); - minW = wq.getW(0); - maxW = wq.getW(maxIndex); - minQ = wq.getQ(0); - maxQ = wq.getQ(maxIndex); - } - - public static int maxIncreasingWIndex(WQ wq) { - - int N = wq.size(); - - if (N < 2) { - return N-1; - } - - double last = wq.getW(0); - - for (int i = 1; i < N; ++i) { - double current = wq.getW(i); - if (current <= last) { - return i-1; - } - } - - return N-1; + minW = wq.getW(bounds[0]); + maxW = wq.getW(bounds[1]); + minQ = wq.getQ(bounds[0]); + maxQ = wq.getQ(bounds[1]); } public double getQ(double w) {