annotate flys-artifacts/src/main/java/de/intevation/flys/exports/ATWriter.java @ 4962:6f6461e07854

Move classes to its own java file
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 04 Feb 2013 14:56:41 +0100
parents 7669747d22f2
children a929d9a9fa1e
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.Date;
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import java.util.Locale;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
12 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
13
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 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
15 import de.intevation.flys.artifacts.resources.Resources;
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
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
17 import org.apache.commons.math.analysis.UnivariateRealFunction;
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
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
19 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
20 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
21
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
22 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
23
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 import org.apache.commons.math.FunctionEvaluationException;
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 import org.apache.log4j.Logger;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 public class ATWriter
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 private static Logger logger = Logger.getLogger(ATWriter.class);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 public static final int COLUMNS = 10;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
34 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
35 "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
36
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
37 public static final String I18N_AT_GAUGE_HEADER =
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
38 "export.discharge.curve.at.gauge.header";
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
39
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
40 public static final String EMPTY = " ";
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 protected double minW;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 protected double maxW;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 protected double minQ;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 protected double maxQ;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
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
47 protected UnivariateRealFunction qFunc;
729
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 public ATWriter() {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 public ATWriter(WQ wq) throws IllegalArgumentException {
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 int [] bounds = wq.longestIncreasingWRangeIndices();
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
56 if (logger.isDebugEnabled()) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
57 logger.debug("exporting w between indices " +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
58 bounds[0] + " and " + bounds[1] + " (" +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
59 wq.getW(bounds[0]) + ", " + wq.getW(bounds[1]));
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
60 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
61
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
62 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
63 minW = maxW = wq.getW(bounds[0]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
64 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
65 // 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
66 qFunc = new PolynomialFunction(new double [] { minQ });
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 return;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
70 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
71 double [] qs = new double[ws.length];
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 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
74 int idx = bounds[0]+i;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
75 ws[i] = wq.getW(idx);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
76 qs[i] = wq.getQ(idx);
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
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
79 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
80 ? 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
81 : new SplineInterpolator().interpolate(ws, qs);
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
83 minW = wq.getW(bounds[0]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
84 maxW = wq.getW(bounds[1]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
85 minQ = wq.getQ(bounds[0]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
86 maxQ = wq.getQ(bounds[1]);
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 }
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 public double getQ(double w) {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 try {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 return qFunc.value(w);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
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
94 catch (FunctionEvaluationException aode) {
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 // should not happen
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 logger.warn("spline interpolation failed", aode);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 return w <= minW ? minQ : maxQ;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100
3220
0c8a6145098b FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1682
diff changeset
101 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
102 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
103 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
104 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
105 else if (q < 100d) format = " % 8.1f";
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 else {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 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
108 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
109 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 out.printf(Locale.US, format, q);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
114 protected static void printGaugeHeader(
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
115 PrintWriter out,
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
116 CallMeta callMeta,
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
117 String river,
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
118 double km,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
119 String gName,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
120 BigDecimal datum,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
121 Date date
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
122 ) {
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
123 DateFormat f = DateFormat.getDateInstance();
4911
da89bb3243d3 Fixed CR and LF in header of AT export.
Raimund Renkert <rrenkert@intevation.de>
parents: 4909
diff changeset
124 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
125 callMeta,
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
126 I18N_AT_GAUGE_HEADER,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
127 I18N_AT_GAUGE_HEADER,
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
128 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
129 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
130 }
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
131
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
132 protected static void printHeader(
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
133 PrintWriter out,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
134 CallMeta callMeta,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
135 String river,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
136 double km
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
137 ) {
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
138 out.print(Resources.getMsg(
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
139 callMeta,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
140 I18N_AT_HEADER,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
141 I18N_AT_HEADER,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
142 new Object[] { river, km } ));
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
143 out.print("\r\n");
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
144 }
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
145
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
146 public void write(
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
147 Writer writer,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
148 CallMeta meta,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
149 String river,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
150 double km,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
151 String gName,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
152 BigDecimal datum,
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
153 Date date,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
154 double scale)
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
155 throws IOException
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
156 {
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 PrintWriter out = new PrintWriter(writer);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
159 // 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
160 // the first row.
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
161 if (gName != null) {
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
162 printGaugeHeader(out, meta, river, km, gName, datum, date);
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
163 }
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
164 else {
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
165 printHeader(out, meta, river, km);
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
166 }
4911
da89bb3243d3 Fixed CR and LF in header of AT export.
Raimund Renkert <rrenkert@intevation.de>
parents: 4909
diff changeset
167
1682
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
168 double rest = (minW * 100.0) % 10.0;
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169
1682
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
170 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
171
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
172 if (logger.isDebugEnabled()) {
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
173 logger.debug("startW: " + startW);
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
174 logger.debug("rest: " + rest);
729
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
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 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
178 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
179 if (col == 0) {
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
180 out.printf(Locale.US, "%8d", (int)Math.round(w * scale));
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
181 }
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182
1682
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
183 if (w < minW) {
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
184 out.print(EMPTY);
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
185 }
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
186 else {
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
187 printQ(out, getQ(w));
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
188 }
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 if (++col >= COLUMNS) {
4947
7669747d22f2 Fix cr/nl in ATWriter.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4942
diff changeset
191 out.print("\r\n");
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 col = 0;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 if (col > 0) {
4947
7669747d22f2 Fix cr/nl in ATWriter.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4942
diff changeset
197 out.print("\r\n");
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 out.flush();
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org