Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java @ 485:6b231041dc18
Importer: Try to extract time ranges from at files.
flys-backend/trunk@1811 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 03 May 2011 17:09:38 +0000 |
parents | d980e545ccab |
children | 8ea09ec7f0c8 |
rev | line source |
---|---|
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.io.BufferedReader; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.io.File; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.io.FileInputStream; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.io.InputStreamReader; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import java.io.IOException; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import java.math.BigDecimal; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import java.text.NumberFormat; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import java.text.ParseException; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import org.apache.log4j.Logger; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.importer.ImportDischargeTable; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.flys.importer.ImportDischargeTableValue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
17 import java.util.regex.Pattern; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
18 import java.util.regex.Matcher; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
19 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
20 import java.util.Date; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
21 import java.util.Calendar; |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public class AtFileParser { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 public static final String ENCODING = "ISO-8859-1"; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 private static Logger logger = Logger.getLogger(AtFileParser.class); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 private static NumberFormat nf = NumberFormat.getInstance(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
32 // regular expression from hell to find out time range |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
33 public static final Pattern DATE_LINE = Pattern.compile( |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
34 "^\\*\\s*Abflu[^t]+tafel?\\s*([^\\d]+)" + |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
35 "(\\d{1,2})?\\.?(\\d{1,2})?\\.?(\\d{2,4})\\s*(?:(?:bis)|-)?\\s*" + |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
36 "(?:(\\d{1,2})?\\.?(\\d{1,2})?\\.?(\\d{2,4}))?\\s*.*$"); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
37 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 public AtFileParser() { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 public ImportDischargeTable parse(ImportGauge gauge) throws IOException { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 File file = gauge.getAtFile(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 logger.info("parsing AT file: " + file); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 BufferedReader br = null; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 String line = null; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 boolean beginning = true; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 ImportDischargeTable dischargeTable = new ImportDischargeTable(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
56 Date from = null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
57 Date to = null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
58 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 try { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 br = new BufferedReader( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 new InputStreamReader( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 new FileInputStream(file), ENCODING)); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 while ((line = br.readLine()) != null) { |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
65 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 String tmp = line.trim(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 if (tmp.length() == 0) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
72 Matcher m = DATE_LINE.matcher(tmp); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
73 if (m.matches()) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
74 from = guessDate(m.group(1), m.group(2), m.group(3)); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
75 to = guessDate(m.group(4), m.group(5), m.group(6)); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
76 if (from == null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
77 Date t = from; from = to; to = t; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
78 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
79 continue; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
80 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
81 |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 if (tmp.startsWith("#! name=")) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 // XXX Skip the name, because we don't know where to save |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 // it at the moment |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 //String name = tmp.substring(8); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 if (tmp.startsWith("#") || tmp.startsWith("*")) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 String[] splits = tmp.replace(',', '.').split("\\s+"); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 if ((splits.length < 2) || (splits.length > 11)) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 logger.warn("Found an invalid row in the AT file."); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 continue; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 String strW = splits[0].trim(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 double W = nf.parse(strW).doubleValue(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 /* shift is used to differenciate between lines with |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 * exactly 10 Qs and lines with less than 10 Qs. The shift |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 * is only modified when it is the first line. |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 */ |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 int shift = 0; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 if (splits.length != 11 && beginning) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 shift = 11 - splits.length; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 for (int i = 1; i < splits.length; i++) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 double iW = W + shift + i; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 double iQ = nf.parse(splits[i].trim()).doubleValue(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 dischargeTable.addDischargeTableValue( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 new ImportDischargeTableValue( |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 new BigDecimal(iQ/100.0), |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 new BigDecimal(iW/100.0))); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 beginning = false; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 catch (ParseException pe) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 logger.warn(pe.getMessage()); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 finally { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 if (br != null) { |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 br.close(); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 logger.info("Finished parsing AT file: " + file); |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 return dischargeTable; |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 } |
485
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
141 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
142 public static Date guessDate(String day, String month, String year) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
143 if (day == null && month == null && year == null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
144 return null; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
145 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
146 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
147 int dayI = 15; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
148 if (day != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
149 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
150 dayI = Integer.parseInt(day.trim()); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
151 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
152 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
153 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
154 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
155 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
156 int monthI = 6; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
157 if (month != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
158 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
159 monthI = Integer.parseInt(month.trim()); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
160 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
161 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
162 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
163 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
164 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
165 int yearI = 1900; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
166 if (year != null) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
167 try { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
168 yearI = Integer.parseInt(year.trim()); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
169 if (yearI < 100) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
170 if (yearI < 20) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
171 yearI += 2000; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
172 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
173 else { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
174 yearI += 1900; |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
175 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
176 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
177 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
178 catch (NumberFormatException nfe) { |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
179 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
180 } |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
181 |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
182 Calendar cal = Calendar.getInstance(); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
183 cal.set(yearI, monthI-1, dayI); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
184 return cal.getTime(); |
6b231041dc18
Importer: Try to extract time ranges from at files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
198
diff
changeset
|
185 } |
198
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 } |
d980e545ccab
Added import code for importing discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |