comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/HYKParser.java @ 3659:36edf9a71cbd

backend: Mention backend errors in importer. flys-backend/trunk@5253 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 Aug 2012 16:20:45 +0000
parents 2ae732e2c65c
children
comparison
equal deleted inserted replaced
3658:55c4b7442236 3659:36edf9a71cbd
122 } 122 }
123 123
124 switch (state) { 124 switch (state) {
125 case LINE_1: 125 case LINE_1:
126 if (parts.length < 2) { 126 if (parts.length < 2) {
127 log.error("1: not enough elements in line " + 127 log.error("HYK 1: not enough elements in line " +
128 in.getLineNumber()); 128 in.getLineNumber());
129 return false; 129 return false;
130 } 130 }
131 131
132 if (parts.length == 2) { 132 if (parts.length == 2) {
161 state = State.LINE_2; 161 state = State.LINE_2;
162 break; 162 break;
163 163
164 case LINE_2: 164 case LINE_2:
165 if (parts.length < 3) { 165 if (parts.length < 3) {
166 log.error("2: not enough elements in line " + 166 log.error("HYK 2: not enough elements in line " +
167 in.getLineNumber()); 167 in.getLineNumber());
168 return false; 168 return false;
169 } 169 }
170 try { 170 try {
171 numZones = Integer.parseInt(parts[0]); 171 numZones = Integer.parseInt(parts[0]);
172 bottom = new BigDecimal(parts[1]); 172 bottom = new BigDecimal(parts[1]);
173 top = new BigDecimal(parts[2]); 173 top = new BigDecimal(parts[2]);
174 } 174 }
175 catch (NumberFormatException nfe) { 175 catch (NumberFormatException nfe) {
176 log.error( 176 log.error(
177 "parsing num zones, bottom or top height " + 177 "HYK: parsing num zones, bottom or top height " +
178 "failed in line " + in.getLineNumber()); 178 "failed in line " + in.getLineNumber());
179 return false; 179 return false;
180 } 180 }
181 formation = new ImportHYKFormation(); 181 formation = new ImportHYKFormation();
182 formation.setBottom(bottom); 182 formation.setBottom(bottom);
187 break; 187 break;
188 188
189 case LINE_3: 189 case LINE_3:
190 if (parts.length != numZones) { 190 if (parts.length != numZones) {
191 log.error( 191 log.error(
192 "number of flow zones mismatches " + 192 "HYK: number of flow zones mismatches " +
193 "in line " + in.getLineNumber()); 193 "in line " + in.getLineNumber());
194 return false; 194 return false;
195 } 195 }
196 196
197 fzts = new ImportHYKFlowZoneType[parts.length]; 197 fzts = new ImportHYKFlowZoneType[parts.length];
209 coords[coordPos] = 209 coords[coordPos] =
210 new BigDecimal(parts[coordPos]); 210 new BigDecimal(parts[coordPos]);
211 } 211 }
212 } 212 }
213 catch (NumberFormatException nfe) { 213 catch (NumberFormatException nfe) {
214 log.error("cannot parse number in line " + 214 log.error("HYK: cannot parse number in line " +
215 in.getLineNumber()); 215 in.getLineNumber());
216 return false; 216 return false;
217 } 217 }
218 state = State.LINE_5; 218 state = State.LINE_5;
219 break; 219 break;
220 220
221 case LINE_5: 221 case LINE_5:
222 if (parts.length + coordPos < coords.length) { 222 if (parts.length + coordPos < coords.length) {
223 log.error("5: not enough elements in line " + 223 log.error("HYK 5: not enough elements in line " +
224 in.getLineNumber()); 224 in.getLineNumber());
225 return false; 225 return false;
226 } 226 }
227 try { 227 try {
228 for (int i = 0; 228 for (int i = 0;
231 ) { 231 ) {
232 coords[coordPos] = new BigDecimal(parts[i]); 232 coords[coordPos] = new BigDecimal(parts[i]);
233 } 233 }
234 } 234 }
235 catch (NumberFormatException nfe) { 235 catch (NumberFormatException nfe) {
236 log.error("cannot parse number in line " + 236 log.error("HYK: cannot parse number in line " +
237 in.getLineNumber()); 237 in.getLineNumber());
238 return false; 238 return false;
239 } 239 }
240 for (int i = 0; i < coords.length; ++i) { 240 for (int i = 0; i < coords.length; ++i) {
241 BigDecimal a = coords[i]; 241 BigDecimal a = coords[i];
242 BigDecimal b = coords[i == coords.length-1 ? i : i+1]; 242 BigDecimal b = coords[i == coords.length-1 ? i : i+1];
243 if (a.compareTo(b) > 0) { 243 if (a.compareTo(b) > 0) {
244 log.warn("zone coordinates swapped in line " + 244 log.warn("HYK: zone coordinates swapped in line " +
245 in.getLineNumber()); 245 in.getLineNumber());
246 BigDecimal c = a; a = b; b = c; 246 BigDecimal c = a; a = b; b = c;
247 } 247 }
248 ImportHYKFlowZone zone = new ImportHYKFlowZone( 248 ImportHYKFlowZone zone = new ImportHYKFlowZone(
249 formation, fzts[i], a, b); 249 formation, fzts[i], a, b);
252 state = State.LINE_6; 252 state = State.LINE_6;
253 break; 253 break;
254 254
255 case LINE_6: 255 case LINE_6:
256 if (parts.length < 3) { 256 if (parts.length < 3) {
257 log.error("6: not enough elements in line " + 257 log.error("HYK 6: not enough elements in line " +
258 in.getLineNumber()); 258 in.getLineNumber());
259 return false; 259 return false;
260 } 260 }
261 try { 261 try {
262 distanceVL = new BigDecimal(parts[0]); 262 distanceVL = new BigDecimal(parts[0]);
263 distanceHF = new BigDecimal(parts[1]); 263 distanceHF = new BigDecimal(parts[1]);
264 distanceVR = new BigDecimal(parts[2]); 264 distanceVR = new BigDecimal(parts[2]);
265 } 265 }
266 catch (NumberFormatException nfe) { 266 catch (NumberFormatException nfe) {
267 log.error("cannot parse number in line " + 267 log.error("HYK: cannot parse number in line " +
268 in.getLineNumber()); 268 in.getLineNumber());
269 return false; 269 return false;
270 } 270 }
271 formation.setDistanceVL(distanceVL); 271 formation.setDistanceVL(distanceVL);
272 formation.setDistanceHF(distanceHF); 272 formation.setDistanceHF(distanceHF);
279 break; 279 break;
280 } 280 }
281 } 281 }
282 } 282 }
283 catch (IOException ioe) { 283 catch (IOException ioe) {
284 log.error(ioe); 284 log.error("HYK: Error reading file.", ioe);
285 return false; 285 return false;
286 } 286 }
287 finally { 287 finally {
288 if (in != null) { 288 if (in != null) {
289 try { 289 try {
290 in.close(); 290 in.close();
291 } 291 }
292 catch (IOException ioe) { 292 catch (IOException ioe) {
293 log.error(ioe); 293 log.error("HYK: Error closing file.", ioe);
294 } 294 }
295 } 295 }
296 } 296 }
297 return true; 297 return true;
298 } 298 }

http://dive4elements.wald.intevation.org