Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java @ 504:ee693b8fbb55
Fixed flys/issue11 and flys51.
flys-backend/trunk@1890 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 10 May 2011 17:31:10 +0000 |
parents | b35c5dc0f8b7 |
children | 23fe9ac1c3b4 |
comparison
equal
deleted
inserted
replaced
503:bcc18293a547 | 504:ee693b8fbb55 |
---|---|
4 import java.io.File; | 4 import java.io.File; |
5 import java.io.FileInputStream; | 5 import java.io.FileInputStream; |
6 import java.io.InputStreamReader; | 6 import java.io.InputStreamReader; |
7 import java.io.IOException; | 7 import java.io.IOException; |
8 import java.math.BigDecimal; | 8 import java.math.BigDecimal; |
9 import java.text.NumberFormat; | |
10 import java.text.ParseException; | |
11 | 9 |
12 import org.apache.log4j.Logger; | 10 import org.apache.log4j.Logger; |
13 | 11 |
14 import de.intevation.flys.importer.ImportDischargeTable; | 12 import de.intevation.flys.importer.ImportDischargeTable; |
15 import de.intevation.flys.importer.ImportDischargeTableValue; | 13 import de.intevation.flys.importer.ImportDischargeTableValue; |
23 public class AtFileParser { | 21 public class AtFileParser { |
24 | 22 |
25 public static final String ENCODING = "ISO-8859-1"; | 23 public static final String ENCODING = "ISO-8859-1"; |
26 | 24 |
27 private static Logger logger = Logger.getLogger(AtFileParser.class); | 25 private static Logger logger = Logger.getLogger(AtFileParser.class); |
28 | |
29 private static NumberFormat nf = NumberFormat.getInstance(); | |
30 | 26 |
31 | 27 |
32 // regular expression from hell to find out time range | 28 // regular expression from hell to find out time range |
33 public static final Pattern DATE_LINE = Pattern.compile( | 29 public static final Pattern DATE_LINE = Pattern.compile( |
34 "^\\*\\s*Abflu[^t]+tafel?\\s*([^\\d]+)" + | 30 "^\\*\\s*Abflu[^t]+tafel?\\s*([^\\d]+)" + |
105 logger.warn("Found an invalid row in the AT file."); | 101 logger.warn("Found an invalid row in the AT file."); |
106 continue; | 102 continue; |
107 } | 103 } |
108 | 104 |
109 String strW = splits[0].trim(); | 105 String strW = splits[0].trim(); |
110 double W = nf.parse(strW).doubleValue(); | 106 double W = Double.parseDouble(strW); |
111 | 107 |
112 /* shift is used to differenciate between lines with | 108 /* shift is used to differenciate between lines with |
113 * exactly 10 Qs and lines with less than 10 Qs. The shift | 109 * exactly 10 Qs and lines with less than 10 Qs. The shift |
114 * is only modified when it is the first line. | 110 * is only modified when it is the first line. |
115 */ | 111 */ |
120 } | 116 } |
121 | 117 |
122 | 118 |
123 for (int i = 1; i < splits.length; i++) { | 119 for (int i = 1; i < splits.length; i++) { |
124 double iW = W + shift + i; | 120 double iW = W + shift + i; |
125 double iQ = nf.parse(splits[i].trim()).doubleValue(); | 121 double iQ = Double.parseDouble(splits[i].trim()); |
126 | 122 |
127 dischargeTable.addDischargeTableValue( | 123 dischargeTable.addDischargeTableValue( |
128 new ImportDischargeTableValue( | 124 new ImportDischargeTableValue( |
129 new BigDecimal(iQ/100.0), | 125 new BigDecimal(iQ/100.0), |
130 new BigDecimal(iW/100.0))); | 126 new BigDecimal(iW/100.0))); |
131 } | 127 } |
132 | 128 |
133 beginning = false; | 129 beginning = false; |
134 } | 130 } |
135 } | 131 } |
136 catch (ParseException pe) { | 132 catch (NumberFormatException pe) { |
137 logger.warn(pe.getMessage()); | 133 logger.warn(pe.getMessage()); |
138 } | 134 } |
139 finally { | 135 finally { |
140 if (br != null) { | 136 if (br != null) { |
141 br.close(); | 137 br.close(); |