annotate backend/src/main/java/org/dive4elements/river/importer/parsers/HYKParser.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
6 * documentation coming with Dive4Elements River for details.
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.importer.parsers;
1234
c5c48f52dc7b Removed FileTools that has been moved to artifacts-common module.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1225
diff changeset
10
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
11 import org.dive4elements.artifacts.common.utils.FileTools;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
12
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
13 import org.dive4elements.river.importer.ImportHYK;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
14 import org.dive4elements.river.importer.ImportHYKEntry;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
15 import org.dive4elements.river.importer.ImportHYKFormation;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
16 import org.dive4elements.river.importer.ImportHYKFlowZone;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
17 import org.dive4elements.river.importer.ImportHYKFlowZoneType;
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import java.io.File;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import java.io.IOException;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import java.io.FileInputStream;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 import java.io.InputStreamReader;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 import java.io.LineNumberReader;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 import java.util.HashMap;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 import java.util.Map;
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
27 import java.util.Date;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
28 import java.util.Calendar;
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 import java.math.BigDecimal;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
32 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
33 import org.apache.logging.log4j.LogManager;
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 public class HYKParser
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
37 private static Logger log = LogManager.getLogger(HYKParser.class);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
39 public interface Callback {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
40 boolean hykAccept(File file);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
41 void hykParsed(HYKParser parser);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
42 } // interface Callback
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
43
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public static enum State {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 LINE_1, LINE_2, LINE_3, LINE_4, LINE_5, LINE_6
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 };
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 private static final String ENCODING = "ISO-8859-1";
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 protected Map<String, ImportHYKFlowZoneType> flowZoneTypes;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
52 protected ImportHYK hyk;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
53
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public HYKParser() {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 flowZoneTypes = new HashMap<String, ImportHYKFlowZoneType>();
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
58 public ImportHYK getHYK() {
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
59 return hyk;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
60 }
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
61
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
62 private static Date yearToDate(Integer year) {
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
63 if (year == null) {
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
64 return null;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
65 }
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
66 Calendar cal = Calendar.getInstance();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
67 cal.set(year, 0, 1, 12, 0, 0);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
68 long ms = cal.getTimeInMillis();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
69 cal.setTimeInMillis(ms - ms%1000);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
70 return cal.getTime();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
71 }
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
72
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 public boolean parse(File file) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
75 boolean debug = log.isDebugEnabled();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
76
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 log.info("Parsing HYK file '" + file + "'");
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 LineNumberReader in = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
81 String description =
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
82 file.getParentFile().getName() + "/" + file.getName();
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
83
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
84 hyk = new ImportHYK(null, description);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
85
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 in =
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 new LineNumberReader(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 new InputStreamReader(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 new FileInputStream(file), ENCODING));
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 String line;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 State state = State.LINE_1;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 int numFormations = 0;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 BigDecimal km = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 BigDecimal top = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 BigDecimal bottom = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 BigDecimal distanceVL = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 BigDecimal distanceHF = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 BigDecimal distanceVR = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 Integer year = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 int numZones = 0;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 ImportHYKFlowZoneType [] fzts = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 BigDecimal [] coords = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 int coordPos = 0;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
112 ImportHYKEntry entry = null;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
113 ImportHYKFormation formation = null;
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
114
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
115 BigDecimal lastZoneEnd = null;
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
116
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 while ((line = in.readLine()) != null) {
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
118
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
119 if (line.startsWith("*") || line.startsWith("----")) {
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 continue;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
122
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
123 line = line.trim();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
124
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
125 if (state != State.LINE_5 && line.length() == 0) {
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 continue;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
128
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 String [] parts = line.split("\\s+");
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
131 if (debug) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
132 log.debug("'" + line + "': " + state);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
133 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
134
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 switch (state) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 case LINE_1:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 if (parts.length < 2) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
138 log.error("HYK 1: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 if (parts.length == 2) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 // no year given
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 year = null;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 else {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 year = Integer.valueOf(parts[1]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 catch (NumberFormatException nfe) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 log.error(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 "year is not an integer in line " +
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 km = new BigDecimal(parts[0]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 numFormations = Integer.parseInt(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 parts[parts.length > 2 ? 2 : 1]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 catch (NumberFormatException nfe) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 log.error(
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 "parsing number of formations " +
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 "or km failed in line " + in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
169 entry = new ImportHYKEntry(hyk, km, yearToDate(year));
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
170 hyk.addEntry(entry);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 state = State.LINE_2;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 case LINE_2:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 if (parts.length < 3) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
177 log.error("HYK 2: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 numZones = Integer.parseInt(parts[0]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 bottom = new BigDecimal(parts[1]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 top = new BigDecimal(parts[2]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 catch (NumberFormatException nfe) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 log.error(
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
188 "HYK: parsing num zones, bottom or top height "
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
189 + "failed in line " + in.getLineNumber());
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 }
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
192
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
193 if (parts.length > 3) {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
194 try {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
195 lastZoneEnd = new BigDecimal(parts[3]);
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
196 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
197 catch (NumberFormatException nfe) {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
198 log.error(
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
199 "HYK: parsing last flow zone end in " +
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
200 "failed in line " + in.getLineNumber());
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
201 return false;
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
202 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
203 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
204 else {
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
205 lastZoneEnd = null;
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
206 }
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
207
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
208 formation = new ImportHYKFormation();
1224
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
209 formation.setBottom(bottom);
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
210 formation.setTop(top);
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
211 entry.addFormation(formation);
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
212
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 state = State.LINE_3;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 case LINE_3:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 if (parts.length != numZones) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218 log.error(
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
219 "HYK: number of flow zones mismatches " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220 "in line " + in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 fzts = new ImportHYKFlowZoneType[parts.length];
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 for (int i = 0; i < fzts.length; ++i) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 fzts[i] = getFlowZoneType(parts[i]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
228 coords = new BigDecimal[numZones];
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 state = State.LINE_4;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 case LINE_4:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 int N = Math.min(parts.length, coords.length);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235 for (coordPos = 0; coordPos < N; ++coordPos) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 coords[coordPos] =
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 new BigDecimal(parts[coordPos]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240 catch (NumberFormatException nfe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
241 log.error("HYK: cannot parse number in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
242 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
244 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
245 state = State.LINE_5;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
248 case LINE_5:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
249 if (parts.length + coordPos < coords.length) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
250 log.error("HYK 5: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
251 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
253 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
254 try {
3334
2ae732e2c65c FLYS backend: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1234
diff changeset
255 for (int i = 0;
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256 i < parts.length && coordPos < coords.length;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
257 ++i, ++coordPos
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258 ) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
259 coords[coordPos] = new BigDecimal(parts[i]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
260 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
261 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
262 catch (NumberFormatException nfe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
263 log.error("HYK: cannot parse number in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
264 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
265 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
266 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
267 for (int i = 0; i < coords.length; ++i) {
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
268 BigDecimal a = coords[i];
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
269 BigDecimal b = i == coords.length-1
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
270 ? (lastZoneEnd != null
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
271 ? lastZoneEnd
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
272 : coords[i])
8020
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
273 : coords[i+1];
139b057a39dd Support the "new" HYK format which enables setting the end of the last flow zone.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
274
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
275 if (a.compareTo(b) > 0) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
276 log.warn(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8020
diff changeset
277 "HYK: zone coordinates swapped in line " +
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
278 in.getLineNumber());
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
279 BigDecimal c = a; a = b; b = c;
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
280 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
281 ImportHYKFlowZone zone = new ImportHYKFlowZone(
1225
d859c4bc6ace HYK Importer: Check if zone coordinates in HYKs are swapped and warn the user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
282 formation, fzts[i], a, b);
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
283 formation.addFlowZone(zone);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
284 }
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
285 state = State.LINE_6;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
286 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
287
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
288 case LINE_6:
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
289 if (parts.length < 3) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
290 log.error("HYK 6: not enough elements in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
294 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295 distanceVL = new BigDecimal(parts[0]);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
296 distanceHF = new BigDecimal(parts[1]);
1224
ca7d461a53f1 HYK importer: Various small fixes and some extra logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1219
diff changeset
297 distanceVR = new BigDecimal(parts[2]);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
298 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
299 catch (NumberFormatException nfe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
300 log.error("HYK: cannot parse number in line " +
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
301 in.getLineNumber());
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
302 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
303 }
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
304 formation.setDistanceVL(distanceVL);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
305 formation.setDistanceHF(distanceHF);
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
306 formation.setDistanceVR(distanceVR);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
307
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
308 // continue with next formation.
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
309 state = --numFormations > 0 // formations left?
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
310 ? State.LINE_2
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
311 : State.LINE_1;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
312 break;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
314 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
315 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
316 catch (IOException ioe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
317 log.error("HYK: Error reading file.", ioe);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
318 return false;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
319 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
320 finally {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
321 if (in != null) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
322 try {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
323 in.close();
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
324 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
325 catch (IOException ioe) {
3659
36edf9a71cbd backend: Mention backend errors in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3334
diff changeset
326 log.error("HYK: Error closing file.", ioe);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
327 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
328 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
329 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
330 return true;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
331 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
332
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
333 protected ImportHYKFlowZoneType getFlowZoneType(String name) {
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
334 name = name.toUpperCase();
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
335 ImportHYKFlowZoneType fzt = flowZoneTypes.get(name);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
336 if (fzt == null) {
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
337 log.info("New flow zone type: " + name);
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
338 fzt = new ImportHYKFlowZoneType(name);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
339 flowZoneTypes.put(name, fzt);
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
341 return fzt;
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
342 }
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
343
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
344 protected void reset() {
1219
d80997bd94ce HYKParser: Create data structures while parsing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1216
diff changeset
345 hyk = null;
1216
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
346 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
347
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
348 public void parseHYKs(File root, final Callback callback) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
349
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
350 FileTools.walkTree(root, new FileTools.FileVisitor() {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
351 @Override
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
352 public boolean visit(File file) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
353 if (file.isFile() && file.canRead()
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
354 && file.getName().toLowerCase().endsWith(".hyk")
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
355 && (callback == null || callback.hykAccept(file))) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
356 reset();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
357 boolean success = parse(file);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
358 log.info("parsing " + (success ? "succeeded" : "failed"));
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
359 if (success && callback != null) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
360 callback.hykParsed(HYKParser.this);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
361 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
362 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
363 return true;
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
364 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
365 });
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
366 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
367
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
368 public static void main(String [] args) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
369
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
370 HYKParser parser = new HYKParser();
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
371
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
372 for (String arg: args) {
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
373 parser.parseHYKs(new File(arg), null);
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
374 }
f8b5c37f15e4 Fixes for the HYK parser
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1215
diff changeset
375 }
1215
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
376 }
8aef353e54fb Initial version of the HYK parser. Not ready, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
377 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org