annotate flys-artifacts/src/main/java/de/intevation/flys/exports/WstWriter.java @ 446:c0bec245f608

Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those. flys-artifacts/trunk@1938 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 17 May 2011 16:31:07 +0000
parents
children 5606ba4139e0
rev   line source
446
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.exports;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.io.BufferedWriter;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.io.OutputStream;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.io.OutputStreamWriter;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import java.io.PrintWriter;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import java.util.Collection;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import java.util.HashMap;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import java.util.Locale;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import java.util.Map;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import java.util.TreeMap;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import org.apache.log4j.Logger;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.artifacts.model.WstLine;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 * A writer that creates WSTs.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 public class WstWriter {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 /** The logger used in this class.*/
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 private static Logger logger = Logger.getLogger(WstWriter.class);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 /** The default unit that is written into the header of the WST.*/
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 public static final String DEFAULT_UNIT = "Wassserstand [NN + m]";
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 /** The lines that need to be included for the export.*/
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 protected Map<Double, WstLine> lines;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 /** The locale used to format the values.*/
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 protected Locale locale;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 /** The number of discharge columns.*/
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 protected int cols;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 /** The last Q values.*/
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 protected double[] qs;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 * This constructor creates a new WstWriter with an OutputStream and a
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 * number of Q columns.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 * @param out The output stream where the WST is written to.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 * @param cols The number of columns of the resulting WST.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 public WstWriter(int cols) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 this.cols = cols;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 this.qs = new double[cols];
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 this.locale = Locale.US;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 this.lines = new HashMap<Double, WstLine>();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 * This method is used to create the WST from the data that has been
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 * inserted using add(double[]) before.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 public void write(OutputStream out) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 logger.info("WstWriter.write");
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 PrintWriter writer = new PrintWriter(
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 new BufferedWriter(
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 new OutputStreamWriter(out)));
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 writeHeader(writer);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 Collection<WstLine> collection = new TreeMap(lines).values();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 for (WstLine line: collection) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 writeWLine(writer, line);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 writer.flush();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 writer.close();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 * This method is used to add a new line to the WST.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 * @param wqkms A 3dim double array with [W,Q, KM].
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 public void add(double[] wqkms) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 Double km = wqkms[2];
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 WstLine line = lines.get(km);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 if (line == null) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 line = new WstLine(km.doubleValue());
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 lines.put(km, line);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 line.add(wqkms[0], wqkms[1]);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 * This method writes the header of the WST.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 * @param writer The PrintWriter that creates the output.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 protected void writeHeader(PrintWriter writer) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 logger.debug("WstWriter.writeHeader");
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 writer.println(cols);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 // TODO WRITE DISCHARGE COLUMNS
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 writer.write("* KM ");
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 writer.write(DEFAULT_UNIT);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 writer.println();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 * This method writes a line with W values and a certain kilometer.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 * @param writer The PrintWriter that is used to create the output.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 * @param line The WstLine that should be written to the output.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 protected void writeWLine(PrintWriter writer, WstLine line) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 double km = line.getKm();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 double[] qs = line.getQs();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 int num = line.getSize();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 if (dischargesChanged(qs)) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 writeQLine(writer, qs);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 writer.printf(locale, "%8.3f", km);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 for (int i = 0; i < num; i++) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 writer.printf(locale, "%9.2f", line.getW(i));
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 writer.println();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 * Writes a discharge line (Q values) into a WST.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 * @param qs the Q values for the next range.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 protected void writeQLine(PrintWriter writer, double[] qs) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 writer.write("*\u001f ");
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 for (int i = 0; i < cols; i++) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 this.qs[i] = qs[i];
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 writer.printf(locale, "%9.2f", qs[i]);
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 writer.println();
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 /**
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 * This method determines if a Q has changed from the last line to the
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 * current one.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 * @param newQs The Q values of the next line.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 *
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 * @return true, if a Q value have changed, otherwise false.
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 */
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 protected boolean dischargesChanged(double[] newQs) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 // XXX maybe there is a way to do this faster
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 for (int i = 0; i < cols; i++) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 if (Math.abs(newQs[i] - qs[i]) >= 0.001) {
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 return true;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 return false;
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 }
c0bec245f608 Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org