annotate backend/src/main/java/org/dive4elements/river/importer/parsers/W80Parser.java @ 9726:0a5239a1e46e 3.2.x

Upgrade to Log4j 2
author Tom Gottfried <tom@intevation.de>
date Wed, 02 Mar 2022 10:26:50 +0100
parents 5e38e2924c07
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;
4735
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
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;
4735
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
diff changeset
12
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
13 import org.dive4elements.river.importer.XY;
4735
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
diff changeset
14
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
15 import org.dive4elements.river.importer.parsers.tim.Coordinate;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
16
8187
3bb1c62ad732 Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
17 import org.dive4elements.river.backend.utils.DateGuesser;
3bb1c62ad732 Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
18 import org.dive4elements.river.backend.utils.EpsilonComparator;
4762
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
19
4735
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
diff changeset
20 import java.io.File;
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
diff changeset
21 import java.io.IOException;
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
diff changeset
22
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23 import java.util.ArrayList;
4761
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
24 import java.util.Calendar;
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
25 import java.util.Date;
4735
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
diff changeset
26 import java.util.List;
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27 import java.util.Map;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 import java.util.TreeMap;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
30 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
31 import org.apache.logging.log4j.LogManager;
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34 /**
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 * To create cross-sections, generate: Map<double,list<xy>> from files
4755
ba8c2147b4ff W80Parser: Correct c&p stuff in comments (da66->w80).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4751
diff changeset
36 * in w80 format.
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
37 */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
38 public class W80Parser extends LineParser implements CrossSectionParser
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39 {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
40 /** Private log. */
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
41 private static Logger log = LogManager.getLogger(W80Parser.class);
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44 /** The current line to which add points. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
45 private List<XY> currentLine;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 /** Data collected so far, last element will be currentLine. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49 protected Map<Double, List<XY>> data;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
50
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
51
4747
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
52 /** Anchor to project to. */
4768
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
53 private static class Anchor extends Coordinate {
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
54
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
55 private static final double EPSILON = 1e-5;
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
56
4747
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
57 private double station;
4768
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
58
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
59 public Anchor(double x, double y, double z, double station) {
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
60 super(x, y, z);
4747
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
61 this.station = station;
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
62 }
4768
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
63
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
64 public boolean sameStation(double station) {
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
65 return Math.abs(this.station - station) < EPSILON;
4747
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
66 }
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
67 }
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
68
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
69
4760
69bb2996ed19 W80Parser: Doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4759
diff changeset
70 /** Reference point for simple projection. */
4747
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
71 private Anchor anchor;
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
72
2a6d64a415e4 W80Parser: Put infrastructure for an anchor point in place.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4735
diff changeset
73
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
74 /**
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
75 * Reference point for distance calculations, introduced to
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
76 * deal with bends in the lines.
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
77 * Array has two entrys: first is GK-Right, second GK-High.
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
78 */
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
79 private double[] lastPointGK;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
80
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
81
4761
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
82 /** Measurement date of anchor as listed in w80 file. */
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
83 private Date anchorDate;
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
84
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
85
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
86 private double distanceToLastPoint(double gkr, double gkh) {
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
87 double dx = gkr - lastPointGK[0];
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
88 double dy = gkh - lastPointGK[1];
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
89 double d = dx*dx + dy*dy;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
90
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
91 return Math.sqrt(d);
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
92 }
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
93
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
94
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
95 /** Trivial constructor. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
96 public W80Parser() {
4735
94b39073f0f7 Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4733
diff changeset
97 data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP);
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
98 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
99
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
100
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
101 /** Get the description of the cross section parsed. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
102 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
103 public String getDescription() {
4729
0df1cac6c4b5 Removed removeExtension implementations, which have been moved to FileTools,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4728
diff changeset
104 return FileTools.removeExtension(getFileName());
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
106
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
107
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
108 /** Get the year of this cross sections measurement. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
109 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
110 public Integer getYear() {
4769
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
111 if (anchorDate == null) {
4777
34398f424cfd W80Parser: Return null if no year set to behave like other parsers and avoid
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4769
diff changeset
112 return null;
4769
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
113 }
4762
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
114 Calendar dateCalendar = Calendar.getInstance();
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
115 dateCalendar.setTime(anchorDate);
c6654a19b00f W80Parser: Use DateGuesser to set a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4761
diff changeset
116 return dateCalendar.get(Calendar.YEAR);
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
117 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
118
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
119
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
120 /**
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
121 * Return the data parsed.
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
122 * @return map of stations (km) to list of points.
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
123 */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
124 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
125 public Map<Double, List<XY>> getData() {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
126 return data;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
128
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
129
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
130 public void parseW80s(File root, final Callback callback) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
131
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
132 FileTools.walkTree(root, new FileTools.FileVisitor() {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
133 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
134 public boolean visit(File file) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
135 if (file.isFile() && file.canRead()
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
136 && file.getName().toLowerCase().endsWith(".w80")
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
137 && (callback == null || callback.accept(file))) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
138 reset();
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
139 try {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
140 parse(file);
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
141 log.info("parsing done");
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
142 if (callback != null) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
143 callback.parsed(W80Parser.this);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
144 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
145 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
146 catch (IOException ioe) {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
147 log.error("IOException while parsing file");
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
148 return false;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
149 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
150 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
151 return true;
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
152 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
153 });
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
154 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
155
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
156
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
157 /** Called before consuming first line of file. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
158 public void reset() {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
159 data.clear();
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
160 currentLine = new ArrayList<XY>();
4749
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
161 anchor = null;
4761
ab87408bb0d3 W80Parser: Added field to store a date.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4760
diff changeset
162 anchorDate = null;
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
163 lastPointGK = new double[] {0d,0d};
4749
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
164 }
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
165
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
166
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
167 /**
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
168 * Get the Index of the last cross-section lines point.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
169 * @return last points index, -1 if not available.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
170 */
4803
94cb955234ab W80Parser: Renamed lastPointIdx() to getLastPointIdx().
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4802
diff changeset
171 private int getLastPointIdx() {
4749
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
172 if (currentLine == null || currentLine.isEmpty()) {
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
173 return -1;
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
174 }
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
175 XY lastPoint = this.currentLine.get(currentLine.size()-1);
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
176 return lastPoint.getIndex();
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
177 }
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
178
4757
e965593eee57 W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4756
diff changeset
179
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
180 private double getLastPointX() {
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
181 if (currentLine == null || currentLine.isEmpty()) {
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
182 return 0d;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
183 }
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
184 XY lastPoint = this.currentLine.get(currentLine.size()-1);
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
185 return lastPoint.getX();
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
186 }
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
187
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
188
4749
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
189 /**
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
190 * Add a Point (YZ,Index) to the current cross section line.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
191 * @param y The y coordinate of new point.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
192 * @param z The z coordinate of new point.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
193 * @param idx Ignored, the parameter of new point.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
194 * @return true if point could been added, false otherwise (e.g. not
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
195 * parsable y or z values.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
196 */
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
197 private boolean addPoint(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
198 double gkr,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
199 double gkh,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
200 double height,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
201 String idx
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
202 ) {
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
203 // Calculate distance between this and lst point (add distances).
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
204 double d = distanceToLastPoint(gkr, gkh);
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
205 double totalX = getLastPointX() + d;
4751
ee6c0f246b28 W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4750
diff changeset
206
4749
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
207 // We ignore idx, and increment instead.
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
208 int index;
4803
94cb955234ab W80Parser: Renamed lastPointIdx() to getLastPointIdx().
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4802
diff changeset
209 int lastPointIdx = getLastPointIdx();
4749
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
210 if (lastPointIdx <= 0) {
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
211 index = 1;
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
212 } else {
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
213 index = lastPointIdx + 1;
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
214 }
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
215
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
216 this.lastPointGK[0] = gkr;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
217 this.lastPointGK[1] = gkh;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
218 currentLine.add(new XY(totalX, height/1000d, index));
4749
3028037c6293 W80Parser: addPoint and lastIdx functions to add a point and find last points index.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4747
diff changeset
219 return true;
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
221
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
222
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223 /**
4755
ba8c2147b4ff W80Parser: Correct c&p stuff in comments (da66->w80).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4751
diff changeset
224 * Called for each line. Try to extract info from a w80 line.
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
225 */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
226 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
227 protected void handleLine(int lineNum, String line) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
228 // The 'shore' field shows which side of the river
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
229 // the shore is measured.
4757
e965593eee57 W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4756
diff changeset
230 // Therefore, the points have to be added in the correct order (also
e965593eee57 W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4756
diff changeset
231 // because later distances are calculated which cannot be
e965593eee57 W80Parser: Whitespace-cosmetics and comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4756
diff changeset
232 // negative.
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
233 String pointId = line.substring(0,20);
4758
4db3a1509e90 W80Parser: Respect (ignore) 'shore' field of w80 files.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4757
diff changeset
234 String station = line.substring(9,15);
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
235 String shore = line.substring(15,16);
4751
ee6c0f246b28 W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4750
diff changeset
236 // TODO: There is 'station' and a 'shore'-code behind.
ee6c0f246b28 W80Parser: Added TODO/comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4750
diff changeset
237 // 1 = left, 2 = right. none = middle
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
238 String pointIndex = line.substring(16,21);
4750
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
239 // For GK, first seven digits are of interest.
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
240 String gkRight = line.substring(20,30);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
241 String gkHigh = line.substring(30,40);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
242 String date = line.substring(40,46);
4759
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
243 /* Fields not (yet?) of interest for FLYS
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
244 String locType = line.substring(46,47);
4759
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
245 */
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
246 String height = line.substring(47,54);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
247 String dateH = line.substring(54,60);
4759
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
248 /* Fields not (yet?) of interest for FLYS
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
249 String typeH = line.substring(60,61);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
250 String kindH = line.substring(61,64);
4759
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
251 */
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
252 String dateDec = line.substring(64,70);
4759
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
253 /* Fields not (yet?) of interest for FLYS
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
254 String note = line.substring(70,78);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
255 String actual = line.substring(78);
4759
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
256 */
35f4ece9562e W80Parser: Comment code that is not (yet?) used by FLYS.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4758
diff changeset
257
4750
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
258 double stationKm = Double.parseDouble(station) / 1000d;
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
259 double gkRightKm = Double.parseDouble(gkRight.substring(0,7));
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
260 double gkHighKm = Double.parseDouble(gkHigh.substring(0,7));
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
261 double heightM = Double.parseDouble(height);
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
262
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
263 // New (or first) line.
4768
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
264 if (anchor == null || !anchor.sameStation(stationKm)) {
99f9e371371b Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
265 anchor = new Anchor(gkRightKm, gkHighKm, heightM, stationKm);
4804
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
266 lastPointGK[0] = gkRightKm;
e9566109bd5b W80Parser: Implement linear cascading distance measurements.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4803
diff changeset
267 lastPointGK[1] = gkHighKm;
4750
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
268 currentLine = new ArrayList<XY>();
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
269 data.put(stationKm, currentLine);
4802
7dd5baca4f53 W80Parser: Cosmetics, whitespace, TODO resolved, logging improved.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4777
diff changeset
270 currentLine.add(new XY(0d, heightM, 0));
4769
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
271 try {
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
272 anchorDate = DateGuesser.guessDate(date);
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
273 }
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
274 catch (IllegalArgumentException iae) {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
275 log.warn("W80: Invalid date '" + date + "'.");
4769
92a08725bc63 Do not die in W80 parser id invalid date is given.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4768
diff changeset
276 }
4750
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
277 }
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
278 else {
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
279 addPoint(gkRightKm, gkHighKm, heightM, pointIndex);
60398ab6129a W80Parser: Actually add points while parsing w80 file.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4749
diff changeset
280 }
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
281 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
282
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
283
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
284 /** Called when file is fully consumed. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
285 @Override
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
286 protected void finish() {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
287 log.info("Parsed " + data.size() + " lines");
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
288 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
289
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
290
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
291 /** Parses files given as arguments. */
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
292 public static void main(String [] args) {
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
293
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
294 W80Parser parser = new W80Parser();
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
295
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
296 log.warn("Start parsing files.");
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
297 for (String arg: args) {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
298 log.warn("Parsing a file.");
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
299 parser.parseW80s(new File(arg), null);
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
300 }
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8187
diff changeset
301 log.error("Finished parsing files.");
4728
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
302 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
303 }
ccae8b43e527 Initial empty version of W80Parser.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
304 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org