Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/ATWriter.java @ 4939:c9d8b9b4895d
Renamed 'W fÃŒr ungleichwertigen ...' to 'W fÃŒr benutzerdefinierten...'
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 31 Jan 2013 14:32:51 +0100 |
parents | b878dce3a671 |
children | 450840751f1b 65059ad920c6 |
rev | line source |
---|---|
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.exports; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.IOException; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.io.Writer; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.io.PrintWriter; |
4938
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
6 import java.math.BigDecimal; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
4938
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
8 import java.text.DateFormat; |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
9 import java.util.Calendar; |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
10 import java.util.Date; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.Locale; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
13 import de.intevation.artifacts.CallMeta; |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
14 |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.flys.artifacts.model.WQ; |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
16 import de.intevation.flys.artifacts.resources.Resources; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
18 import org.apache.commons.math.analysis.UnivariateRealFunction; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
20 import org.apache.commons.math.analysis.interpolation.SplineInterpolator; |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
21 import org.apache.commons.math.analysis.interpolation.LinearInterpolator; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
23 import org.apache.commons.math.analysis.polynomials.PolynomialFunction; |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
24 |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
25 import org.apache.commons.math.FunctionEvaluationException; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 import org.apache.log4j.Logger; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public class ATWriter |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 { |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 private static Logger logger = Logger.getLogger(ATWriter.class); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public static final int COLUMNS = 10; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
35 public static final String I18N_AT_HEADER = |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
36 "export.discharge.curve.at.header"; |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
37 |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
38 public static final String EMPTY = " "; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 protected double minW; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 protected double maxW; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 protected double minQ; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 protected double maxQ; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
45 protected UnivariateRealFunction qFunc; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 public ATWriter() { |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 public ATWriter(WQ wq) throws IllegalArgumentException { |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
1033
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
52 int [] bounds = wq.longestIncreasingWRangeIndices(); |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
1033
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
54 if (logger.isDebugEnabled()) { |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
55 logger.debug("exporting w between indices " + |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
56 bounds[0] + " and " + bounds[1] + " (" + |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
57 wq.getW(bounds[0]) + ", " + wq.getW(bounds[1])); |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
58 } |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
59 |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
60 if (bounds[1]-bounds[0] < 1) { // Only first w can be written out. |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
61 minW = maxW = wq.getW(bounds[0]); |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
62 minQ = maxQ = wq.getQ(bounds[0]); |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
63 // constant function |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
64 qFunc = new PolynomialFunction(new double [] { minQ }); |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 return; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
1033
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
68 double [] ws = new double[bounds[1]-bounds[0]]; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 double [] qs = new double[ws.length]; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 for (int i = 0; i < ws.length; ++i) { |
1033
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
72 int idx = bounds[0]+i; |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
73 ws[i] = wq.getW(idx); |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
74 qs[i] = wq.getQ(idx); |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
77 qFunc = ws.length < 3 |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
78 ? new LinearInterpolator().interpolate(ws, qs) |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
79 : new SplineInterpolator().interpolate(ws, qs); |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
1033
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
81 minW = wq.getW(bounds[0]); |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
82 maxW = wq.getW(bounds[1]); |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
83 minQ = wq.getQ(bounds[0]); |
821aaceb2776
Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
747
diff
changeset
|
84 maxQ = wq.getQ(bounds[1]); |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 public double getQ(double w) { |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 try { |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 return qFunc.value(w); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
92 catch (FunctionEvaluationException aode) { |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 // should not happen |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 logger.warn("spline interpolation failed", aode); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 return w <= minW ? minQ : maxQ; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1682
diff
changeset
|
99 public static void printQ(PrintWriter out, double q) { |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 String format; |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
101 if (q < 1d) format = " % 8.3f"; |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
102 else if (q < 10d) format = " % 8.2f"; |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
103 else if (q < 100d) format = " % 8.1f"; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 else { |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 format = " % 8.0f"; |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
106 if (q > 1000d) q = Math.rint(q/10d)*10d; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 out.printf(Locale.US, format, q); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
112 protected static void printHeader( |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
113 PrintWriter out, |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
114 CallMeta callMeta, |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
115 String river, |
4938
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
116 double km, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
117 String gName, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
118 BigDecimal datum, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
119 Date date |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
120 ) { |
4938
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
121 DateFormat f = DateFormat.getDateInstance(); |
4911
da89bb3243d3
Fixed CR and LF in header of AT export.
Raimund Renkert <rrenkert@intevation.de>
parents:
4909
diff
changeset
|
122 out.print(Resources.getMsg( |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
123 callMeta, |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
124 I18N_AT_HEADER, |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
125 I18N_AT_HEADER, |
4938
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
126 new Object[] { river, gName, f.format(date), datum } )); |
4911
da89bb3243d3
Fixed CR and LF in header of AT export.
Raimund Renkert <rrenkert@intevation.de>
parents:
4909
diff
changeset
|
127 out.print("\r\n"); |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
128 } |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
129 |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
130 |
4938
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
131 public void write( |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
132 Writer writer, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
133 CallMeta meta, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
134 String river, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
135 double km, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
136 String gName, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
137 BigDecimal datum, |
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
138 Date date) |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
139 throws IOException |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
140 { |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 PrintWriter out = new PrintWriter(writer); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 |
1658
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
143 // a header is required, because the desktop version of FLYS will skip |
7d11ad5a52d5
Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1033
diff
changeset
|
144 // the first row. |
4938
b878dce3a671
Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents:
4911
diff
changeset
|
145 printHeader(out, meta, river, km, gName, datum, date); |
4911
da89bb3243d3
Fixed CR and LF in header of AT export.
Raimund Renkert <rrenkert@intevation.de>
parents:
4909
diff
changeset
|
146 |
1682
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
147 double rest = (minW * 100.0) % 10.0; |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
1682
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
149 double startW = Math.rint((minW - rest*0.01)*10.0)*0.1; |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
150 |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
151 if (logger.isDebugEnabled()) { |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
152 logger.debug("startW: " + startW); |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
153 logger.debug("rest: " + rest); |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 int col = 0; |
732
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
157 for (double w = startW; w <= maxW; w += 0.01) { |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
158 if (col == 0) { |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
159 out.printf(Locale.US, "%8d", (int)Math.round(w*100.0)); |
39d191f011dc
ATWriter: Results are now in cm. Made it more robust against corner cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
160 } |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 |
1682
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
162 if (w < minW) { |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
163 out.print(EMPTY); |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
164 } |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
165 else { |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
166 printQ(out, getQ(w)); |
394b7ac58fc9
ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1662
diff
changeset
|
167 } |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 if (++col >= COLUMNS) { |
4909
67bbcee26e21
Insert CR at the of each line in AT-extport.
Raimund Renkert <rrenkert@intevation.de>
parents:
3220
diff
changeset
|
170 out.print("\r"); |
729
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 out.println(); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 col = 0; |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 if (col > 0) { |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 out.println(); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 out.flush(); |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 } |
078934923acb
New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |