comparison flys-backend/src/main/java/de/intevation/flys/importer/PegelGltParser.java @ 184:4ab2c3bd474c

Added parsing of PEGEL.GLT files. flys-backend/trunk@1501 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 17 Mar 2011 15:21:50 +0000
parents
children a60edcfe5f53
comparison
equal deleted inserted replaced
183:222f4db3430a 184:4ab2c3bd474c
1 package de.intevation.flys.importer;
2
3 import java.io.File;
4
5 import java.util.List;
6 import java.util.ArrayList;
7
8 import java.util.regex.Pattern;
9 import java.util.regex.Matcher;
10
11 import java.io.IOException;
12 import java.io.LineNumberReader;
13 import java.io.FileInputStream;
14 import java.io.InputStreamReader;
15
16 import org.apache.log4j.Logger;
17
18 import de.intevation.flys.utils.FileTools;
19
20 public class PegelGltParser
21 {
22 private static Logger log = Logger.getLogger(InfoGewParser.class);
23
24 public static final String ENCODING = "ISO-8859-1";
25
26 public static final String KM = "km:";
27
28 protected List<ImportGauge> gauges;
29
30 public PegelGltParser() {
31 gauges = new ArrayList<ImportGauge>();
32 }
33
34 public List<ImportGauge> getGauges() {
35 return gauges;
36 }
37
38 public void parse(File file) throws IOException {
39
40 File parent = file.getParentFile();
41
42 log.info("parsing GLT file '" + file + "'");
43 LineNumberReader in = null;
44 try {
45 in =
46 new LineNumberReader(
47 new InputStreamReader(
48 new FileInputStream(file), ENCODING));
49
50 String line = null;
51 while ((line = in.readLine()) != null) {
52 if ((line = line.trim()).length() == 0) {
53 continue;
54 }
55
56 int kmPos = line.indexOf(KM);
57 if (kmPos < 0) {
58 log.warn("no gauge found in line " + in.getLineNumber());
59 continue;
60 }
61
62 String gaugeName = line.substring(0, kmPos).trim();
63 log.info("Found gauge '" + gaugeName + "'");
64
65 line = line.substring(kmPos + KM.length()).trim();
66
67 String [] parts = line.split("\\s+");
68 if (parts.length < 4) {
69 log.warn("line " + in.getLineNumber()
70 + " has not enough columns");
71 continue;
72 }
73
74 double from = Double.parseDouble(parts[0].replace(",", "."));
75 double to = Double.parseDouble(parts[1].replace(",", "."));
76 if (to < from) { double t = from; from = to; to = t; }
77 File staFile = FileTools.repair(new File(parent, parts[2]));
78 File atFile = FileTools.repair(new File(parent, parts[3]));
79
80 if (log.isDebugEnabled()) {
81 log.debug("\tfrom: " + from);
82 log.debug("\tto: " + to);
83 log.debug("\tsta: " + staFile);
84 log.debug("\tat: " + atFile);
85 }
86
87 gauges.add(new ImportGauge(from, to, staFile, atFile));
88 }
89 }
90 finally {
91 if (in != null) {
92 in.close();
93 }
94 }
95 }
96
97 }
98 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org