Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
1032:abd2ab6dff4f | 1033:821aaceb2776 |
---|---|
37 public ATWriter() { | 37 public ATWriter() { |
38 } | 38 } |
39 | 39 |
40 public ATWriter(WQ wq) throws IllegalArgumentException { | 40 public ATWriter(WQ wq) throws IllegalArgumentException { |
41 | 41 |
42 int maxIndex = maxIncreasingWIndex(wq); | 42 int [] bounds = wq.longestIncreasingWRangeIndices(); |
43 | 43 |
44 if (maxIndex < 1) { // Only first w can be written out. | 44 if (logger.isDebugEnabled()) { |
45 minW = maxW = wq.getW(0); | 45 logger.debug("exporting w between indices " + |
46 minQ = maxQ = wq.getQ(0); | 46 bounds[0] + " and " + bounds[1] + " (" + |
47 wq.getW(bounds[0]) + ", " + wq.getW(bounds[1])); | |
48 } | |
49 | |
50 if (bounds[1]-bounds[0] < 1) { // Only first w can be written out. | |
51 minW = maxW = wq.getW(bounds[0]); | |
52 minQ = maxQ = wq.getQ(bounds[0]); | |
47 // constant function | 53 // constant function |
48 qFunc = new PolynomialFunction(new double [] { minQ }); | 54 qFunc = new PolynomialFunction(new double [] { minQ }); |
49 return; | 55 return; |
50 } | 56 } |
51 | 57 |
52 double [] ws = new double[maxIndex]; | 58 double [] ws = new double[bounds[1]-bounds[0]]; |
53 double [] qs = new double[ws.length]; | 59 double [] qs = new double[ws.length]; |
54 | 60 |
55 for (int i = 0; i < ws.length; ++i) { | 61 for (int i = 0; i < ws.length; ++i) { |
56 ws[i] = wq.getW(i); | 62 int idx = bounds[0]+i; |
57 qs[i] = wq.getQ(i); | 63 ws[i] = wq.getW(idx); |
64 qs[i] = wq.getQ(idx); | |
58 } | 65 } |
59 | 66 |
60 qFunc = ws.length < 3 | 67 qFunc = ws.length < 3 |
61 ? new LinearInterpolator().interpolate(ws, qs) | 68 ? new LinearInterpolator().interpolate(ws, qs) |
62 : new SplineInterpolator().interpolate(ws, qs); | 69 : new SplineInterpolator().interpolate(ws, qs); |
63 | 70 |
64 minW = wq.getW(0); | 71 minW = wq.getW(bounds[0]); |
65 maxW = wq.getW(maxIndex); | 72 maxW = wq.getW(bounds[1]); |
66 minQ = wq.getQ(0); | 73 minQ = wq.getQ(bounds[0]); |
67 maxQ = wq.getQ(maxIndex); | 74 maxQ = wq.getQ(bounds[1]); |
68 } | |
69 | |
70 public static int maxIncreasingWIndex(WQ wq) { | |
71 | |
72 int N = wq.size(); | |
73 | |
74 if (N < 2) { | |
75 return N-1; | |
76 } | |
77 | |
78 double last = wq.getW(0); | |
79 | |
80 for (int i = 1; i < N; ++i) { | |
81 double current = wq.getW(i); | |
82 if (current <= last) { | |
83 return i-1; | |
84 } | |
85 } | |
86 | |
87 return N-1; | |
88 } | 75 } |
89 | 76 |
90 public double getQ(double w) { | 77 public double getQ(double w) { |
91 | 78 |
92 try { | 79 try { |