Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/WstWriter.java @ 8179:705f8b92fd66
Complete CSV-export and correct headers.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 03 Sep 2014 16:46:09 +0200 |
parents | 7c89a545617a |
children | e4606eae8ea5 |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3284
diff
changeset
|
9 package org.dive4elements.river.exports; |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
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.io.BufferedWriter; |
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.io.OutputStream; |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 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
|
14 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
|
15 |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
16 import java.util.ArrayList; |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 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
|
18 import java.util.HashMap; |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
19 import java.util.List; |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 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
|
21 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
|
22 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
|
23 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import org.apache.log4j.Logger; |
7615
edb323a4c286
(issue1620) join column names with two empty spaces
Andre Heinecke <aheinecke@intevation.de>
parents:
7604
diff
changeset
|
25 import org.apache.commons.lang.StringUtils; |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3284
diff
changeset
|
27 import org.dive4elements.river.artifacts.model.WstLine; |
446
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 /** |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 * 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
|
32 * |
7656
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
33 * Wst files follow this basic structure: |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
34 * |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
35 * HEADER |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
36 * Q-LINE |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
37 * W-LINES |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
38 * Q-LINE |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
39 * W-LINES |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
40 * ... |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
41 * |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
42 * where each *LINE consists of X columns that are specified in the header. |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
43 * |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 * @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
|
45 */ |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 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
|
47 |
3147
d9fb3a178be4
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
749
diff
changeset
|
48 /** The logger used in this class. */ |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 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
|
50 |
3147
d9fb3a178be4
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
749
diff
changeset
|
51 /** The default unit that is written into the header of the WST. */ |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 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
|
53 |
3147
d9fb3a178be4
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
749
diff
changeset
|
54 /** The lines that need to be included for the export. */ |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 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
|
56 |
3147
d9fb3a178be4
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
749
diff
changeset
|
57 /** The column names. */ |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
58 protected List<String> columnNames; |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
59 |
3147
d9fb3a178be4
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
749
diff
changeset
|
60 /** The locale used to format the values. */ |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 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
|
62 |
3147
d9fb3a178be4
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
749
diff
changeset
|
63 /** The number of discharge columns. */ |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 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
|
65 |
3147
d9fb3a178be4
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
749
diff
changeset
|
66 /** The last Q values. */ |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 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
|
68 |
7658
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
69 /** Workaround for one use of wrongly imported files: ignore the Qs at |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
70 * all. */ |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
71 protected boolean ignoreQs; |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 /** |
3284
d9af29a4bb85
Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3147
diff
changeset
|
74 * This constructor creates a new WstWriter with a number of Q columns. |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 * |
7656
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
76 * @param columns The number of columns of the resulting WST. |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 */ |
7656
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
78 public WstWriter(int columns) { |
7658
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
79 this(columns, false); |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
80 } |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
81 |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
82 /** |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
83 * This constructor creates a new WstWriter with a number of Q columns. |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
84 * |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
85 * @param columns The number of columns of the resulting WST. |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
86 * @param workaroundIgnoreQs do not write QLines to shadow broken data. |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
87 */ |
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
88 public WstWriter(int columns, boolean workaroundIgnoreQs) { |
7656
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
89 this.cols = columns; |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
90 this.columnNames = new ArrayList<String>(cols); |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
91 this.lines = new HashMap<Double, WstLine>(); |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
92 this.qs = new double[cols]; |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
93 this.locale = Locale.US; |
7658
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
94 this.ignoreQs = workaroundIgnoreQs; |
446
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 |
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 /** |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 * 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
|
100 * inserted using add(double[]) before. |
3284
d9af29a4bb85
Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3147
diff
changeset
|
101 * @param out Where to write to. |
446
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 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
|
104 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
|
105 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 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
|
107 new BufferedWriter( |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 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
|
109 |
749
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
110 this.qs = new double[cols]; |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
111 |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 writeHeader(writer); |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 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
|
115 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 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
|
117 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
|
118 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 writer.flush(); |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 writer.close(); |
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 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
|
127 * |
7656
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
128 * @param wqkms A 3dim double array with [W, Q, KM]. |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 */ |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 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
|
131 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
|
132 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 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
|
134 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 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
|
136 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
|
137 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
|
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 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
|
141 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 |
749
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
144 public void addCorrected(double[] wqckms) { |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
145 Double km = wqckms[2]; |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
146 |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
147 WstLine line = lines.get(km); |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
148 |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
149 if (line == null) { |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
150 line = new WstLine(km.doubleValue()); |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
151 lines.put(km, line); |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
152 } |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
153 |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
154 line.add(wqckms[3], wqckms[1]); |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
155 } |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
156 |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
157 |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 /** |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
159 * Adds a further column name. |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
160 * |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
161 * @param name The name of the new column. |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
162 */ |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
163 public void addColumn(String name) { |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
164 if (name != null) { |
749
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
165 cols++; |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
166 |
7654
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
167 int i = 0; |
749
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
168 String basename = name; |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
169 while (columnNames.contains(name)) { |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
170 name = basename + "_" + i++; |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
171 } |
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
172 |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
173 columnNames.add(name); |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
174 } |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
175 } |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
176 |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
177 |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
178 /** |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
179 * 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
|
180 * |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
181 * @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
|
182 */ |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
183 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
|
184 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
|
185 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 writer.println(cols); |
7654
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
187 |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
188 writer.print("*!column-bez-text "); |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
189 |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
190 List<String> quotedNames = new ArrayList<String>(columnNames.size()); |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
191 |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
192 for (String name: columnNames) { |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
193 if (name.contains(" ")) { |
7663
7c89a545617a
Use correct quotes for long names
Andre Heinecke <aheinecke@intevation.de>
parents:
7658
diff
changeset
|
194 name = '"' + name + '"'; |
7654
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
195 } |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
196 quotedNames.add(name); |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
197 } |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
198 writer.println(StringUtils.join(quotedNames, " ")); |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
199 writer.print(" "); |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
200 |
7654
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
201 for (String columnName: columnNames) { |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
202 if (columnName.length() > 9) { |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
203 writer.printf(locale, "%9s", |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
204 columnName.substring(columnName.length() - 9)); |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
205 } else { |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
206 writer.printf(locale, "%9s", columnName); |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
207 // This is weird but i was to lazy to lookup |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
208 // how to do this another way. |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
209 for (int i = 9 - columnName.length(); i > 0; i--) { |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
210 writer.print(" "); |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
211 } |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
212 } |
197bd0958cba
(issue1620) Fix WstWriter Column Header format.
Andre Heinecke <aheinecke@intevation.de>
parents:
7615
diff
changeset
|
213 } |
447
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
214 |
5606ba4139e0
WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
446
diff
changeset
|
215 writer.println(); |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 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
|
218 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
|
219 writer.println(); |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
220 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
221 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
222 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
223 /** |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
224 * 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
|
225 * |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
226 * @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
|
227 * @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
|
228 */ |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 |
7658
4fb5e89e7bd3
issue1020: WstWriter: Add flag to ignore Qs alltogether.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7656
diff
changeset
|
234 if (!ignoreQs && dischargesChanged(qs)) { |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
235 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
|
236 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
237 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
238 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
|
239 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
240 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
|
241 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
|
242 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
243 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
244 writer.println(); |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
245 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
246 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
247 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
248 /** |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
249 * 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
|
250 * |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
251 * @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
|
252 */ |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
253 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
|
254 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
|
255 |
749
72bcbc308501
The WST export contains the corrected W values now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
447
diff
changeset
|
256 for (int i = 0; i < qs.length; i++) { |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
257 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
|
258 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
259 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
|
260 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
261 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
262 writer.println(); |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
263 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
264 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
265 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
266 /** |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
267 * 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
|
268 * current one. |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
269 * |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
270 * @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
|
271 * |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
272 * @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
|
273 */ |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
274 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
|
275 // XXX maybe there is a way to do this faster |
7604
05549a84ee83
(issue1620) Add export of official lines in WST as specified
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
276 for (int i = 0; i < cols && i < qs.length && i < newQs.length; i++) { |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
277 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
|
278 return true; |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
279 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
280 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
281 |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
282 return false; |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
283 } |
7604
05549a84ee83
(issue1620) Add export of official lines in WST as specified
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
284 |
05549a84ee83
(issue1620) Add export of official lines in WST as specified
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
285 /** |
05549a84ee83
(issue1620) Add export of official lines in WST as specified
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
286 * Get the lines that have alreay been added to this writer |
7656
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
287 * lines are a map with km as the key and a wstline as value. |
ad5238e3e736
Cosmetics of WstWriter. Actually, a decent class now.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7654
diff
changeset
|
288 */ |
7604
05549a84ee83
(issue1620) Add export of official lines in WST as specified
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
289 public Map<Double, WstLine> getLines() { |
05549a84ee83
(issue1620) Add export of official lines in WST as specified
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
290 return lines; |
05549a84ee83
(issue1620) Add export of official lines in WST as specified
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
291 } |
446
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
292 } |
c0bec245f608
Implemented writer that creates WSTs and enabled the WaterlevelExporter to create those.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
293 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |