annotate flys-artifacts/src/main/java/de/intevation/flys/exports/ATWriter.java @ 5510:d4bee6d5c866

merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 28 Mar 2013 16:51:32 +0100
parents a929d9a9fa1e
children
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
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4947
diff changeset
28 /** Write AT files. */
729
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
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
38 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
39 "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
40
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
41 public static final String EMPTY = " ";
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 protected double minW;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 protected double maxW;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 protected double minQ;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 protected double maxQ;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
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
48 protected UnivariateRealFunction qFunc;
729
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() {
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
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 public ATWriter(WQ wq) throws IllegalArgumentException {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
55 int [] bounds = wq.longestIncreasingWRangeIndices();
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
57 if (logger.isDebugEnabled()) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
58 logger.debug("exporting w between indices " +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
59 bounds[0] + " and " + bounds[1] + " (" +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
60 wq.getW(bounds[0]) + ", " + wq.getW(bounds[1]));
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
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
63 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
64 minW = maxW = wq.getW(bounds[0]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
65 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
66 // 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
67 qFunc = new PolynomialFunction(new double [] { minQ });
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 return;
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
71 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
72 double [] qs = new double[ws.length];
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 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
75 int idx = bounds[0]+i;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
76 ws[i] = wq.getW(idx);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
77 qs[i] = wq.getQ(idx);
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79
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
80 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
81 ? 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
82 : new SplineInterpolator().interpolate(ws, qs);
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
84 minW = wq.getW(bounds[0]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
85 maxW = wq.getW(bounds[1]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
86 minQ = wq.getQ(bounds[0]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 747
diff changeset
87 maxQ = wq.getQ(bounds[1]);
729
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
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 public double getQ(double w) {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 try {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 return qFunc.value(w);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
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
95 catch (FunctionEvaluationException aode) {
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 // should not happen
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 logger.warn("spline interpolation failed", aode);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 return w <= minW ? minQ : maxQ;
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 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101
3220
0c8a6145098b FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1682
diff changeset
102 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
103 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
104 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
105 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
106 else if (q < 100d) format = " % 8.1f";
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 else {
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 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
109 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
110 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 out.printf(Locale.US, format, q);
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
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
115 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
116 PrintWriter out,
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
117 CallMeta callMeta,
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
118 String river,
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
119 double km,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
120 String gName,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
121 BigDecimal datum,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
122 Date date
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
123 ) {
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
124 DateFormat f = DateFormat.getDateInstance();
4911
da89bb3243d3 Fixed CR and LF in header of AT export.
Raimund Renkert <rrenkert@intevation.de>
parents: 4909
diff changeset
125 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
126 callMeta,
4941
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,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
128 I18N_AT_GAUGE_HEADER,
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
129 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
130 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
131 }
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
132
4941
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
133 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
134 PrintWriter out,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
135 CallMeta callMeta,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
136 String river,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
137 double km
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
138 ) {
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
139 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
140 callMeta,
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 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
143 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
144 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
145 }
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
146
4938
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
147 public void write(
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
148 Writer writer,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
149 CallMeta meta,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
150 String river,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
151 double km,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
152 String gName,
b878dce3a671 Write some more metadata in AT-export header.
Raimund Renkert <rrenkert@intevation.de>
parents: 4911
diff changeset
153 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
154 Date date,
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
155 double scale)
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
156 throws IOException
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
157 {
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 PrintWriter out = new PrintWriter(writer);
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4947
diff changeset
160 // A header is required, because the desktop version of FLYS will skip
1658
7d11ad5a52d5 Bugfix: #332 Made AT-exports compatible with desktop FLYS.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1033
diff changeset
161 // 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
162 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
163 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
164 }
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
165 else {
65059ad920c6 Use different header in AT export files for gauges and at km.
Raimund Renkert <rrenkert@intevation.de>
parents: 4938
diff changeset
166 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
167 }
4911
da89bb3243d3 Fixed CR and LF in header of AT export.
Raimund Renkert <rrenkert@intevation.de>
parents: 4909
diff changeset
168
1682
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
169 double rest = (minW * 100.0) % 10.0;
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170
1682
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
171 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
172
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
173 if (logger.isDebugEnabled()) {
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
174 logger.debug("startW: " + startW);
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
175 logger.debug("rest: " + rest);
729
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
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 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
179 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
180 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
181 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
182 }
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183
1682
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
184 if (w < minW) {
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
185 out.print(EMPTY);
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
186 }
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
187 else {
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
188 printQ(out, getQ(w));
394b7ac58fc9 ATWriter: Get rid of buggy first line code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
189 }
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 if (++col >= COLUMNS) {
4947
7669747d22f2 Fix cr/nl in ATWriter.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4942
diff changeset
192 out.print("\r\n");
729
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 col = 0;
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
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 if (col > 0) {
4947
7669747d22f2 Fix cr/nl in ATWriter.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4942
diff changeset
198 out.print("\r\n");
729
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
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 out.flush();
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 }
078934923acb New AT writer for results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org