comparison backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java @ 7488:1890bd524d27

WST-Parser: revert the assumption of only complete columns.
author Tom Gottfried <tom@intevation.de>
date Thu, 31 Oct 2013 21:56:04 +0100
parents e327492ba9d0
children fc8d5b5f2c99
comparison
equal deleted inserted replaced
7487:e327492ba9d0 7488:1890bd524d27
186 186
187 line = line.replace(',', '.'); 187 line = line.replace(',', '.');
188 188
189 // handle Q-lines 189 // handle Q-lines
190 if (line.startsWith("*\u001f")) { 190 if (line.startsWith("*\u001f")) {
191 BigDecimal [] data = null; 191 BigDecimal [] data = parseLineAsDouble(line, columnCount, false, true);
192 data = parseLineAsDouble(line, columnCount, false, true);
193 192
194 if (aktAbfluesse != null) { // add Q-ranges obtained from previous lines 193 if (aktAbfluesse != null) { // add Q-ranges obtained from previous lines
195 if (kmHist1 != null && kmHist2 != null 194 if (kmHist1 != null && kmHist2 != null
196 && kmHist1.compareTo(kmHist2) < 0) { // stations descending in file 195 && kmHist1.compareTo(kmHist2) < 0) { // stations descending in file
197 BigDecimal t = minKm; minKm = maxKm; maxKm = t; 196 BigDecimal t = minKm; minKm = maxKm; maxKm = t;
200 minKm = MAX_RANGE; 199 minKm = MAX_RANGE;
201 maxKm = MIN_RANGE; 200 maxKm = MIN_RANGE;
202 } 201 }
203 202
204 // obtain Q-values from current line 203 // obtain Q-values from current line
205 aktAbfluesse = new BigDecimal[columnCount]; 204 aktAbfluesse = new BigDecimal[data.length];
206 log.debug("new q range: " + columnCount); 205 log.debug("new q range: " + columnCount);
207 for (int i = 0; i < Math.min(columnCount, data.length); ++i) { 206 for (int i = 0; i < data.length; ++i) {
208 if (data[i] != null) { 207 if (data[i] != null) {
209 log.debug(" column: " + data[i]); 208 log.debug(" column: " + data[i]);
210 aktAbfluesse[i] = data[i]; 209 aktAbfluesse[i] = data[i];
211 } 210 }
212 } 211 }
213 212
213 // remember Q-values from first Q-line for header generation
214 if (firstAbfluesse == null) { 214 if (firstAbfluesse == null) {
215 firstAbfluesse = (BigDecimal [])aktAbfluesse.clone(); 215 firstAbfluesse = (BigDecimal [])aktAbfluesse.clone();
216 } 216 }
217 continue; 217 continue;
218 } 218 }
297 } 297 }
298 for (int i = 0; i < lsBezeichner.length; ++i) { 298 for (int i = 0; i < lsBezeichner.length; ++i) {
299 if (lsBezeichner[i] == null 299 if (lsBezeichner[i] == null
300 || lsBezeichner[i].length() == 0) { 300 || lsBezeichner[i].length() == 0) {
301 // generate alternative column names 301 // generate alternative column names
302 double q = firstAbfluesse[i].doubleValue(); 302 double q = firstAbfluesse.length > i ?
303 firstAbfluesse[i].doubleValue() : 0d;
303 if (q < 0.001) { 304 if (q < 0.001) {
304 lsBezeichner[i] = 305 lsBezeichner[i] =
305 "<unbekannt #" + unknownCount + ">"; 306 "<unbekannt #" + unknownCount + ">";
306 ++unknownCount; 307 ++unknownCount;
307 } 308 }
327 iwc.setTimeInterval(guessDate(potentialDate)); 328 iwc.setTimeInterval(guessDate(potentialDate));
328 } 329 }
329 columnHeaderChecked = true; 330 columnHeaderChecked = true;
330 } 331 }
331 332
332 BigDecimal [] data = null; 333 BigDecimal [] data = parseLineAsDouble(line, columnCount, true, false);
333 data = parseLineAsDouble(line, columnCount, true, false);
334 334
335 BigDecimal kaem = data[0]; 335 BigDecimal kaem = data[0];
336 336
337 if (!kms.add(kaem)) { 337 if (!kms.add(kaem)) {
338 log.warn( 338 log.warn(
361 if (kaem.compareTo(maxKm) > 0) { 361 if (kaem.compareTo(maxKm) > 0) {
362 maxKm = kaem; 362 maxKm = kaem;
363 } 363 }
364 364
365 // extract values 365 // extract values
366 for (int i = 0; i < columnCount; ++i) { 366 for (int i = 0; i < data.length - 1; ++i) {
367 addValue(kaem, data[i+1], i); 367 addValue(kaem, data[i+1], i);
368 } 368 }
369 369
370 } 370 }
371 else { // firstAbfluesse == null 371 else { // firstAbfluesse == null
531 531
532 int pos = 0; 532 int pos = 0;
533 for (int i = 0; i < tokenCount; ++i) { 533 for (int i = 0; i < tokenCount; ++i) {
534 pos += 9; 534 pos += 9;
535 if (pos >= line.length()) { 535 if (pos >= line.length()) {
536 throw new ParseException( 536 break;
537 "WST: number of columns is less than expected. File rejected.");
538 } 537 }
539 strings.add(line.substring(pos, 538 strings.add(line.substring(pos,
540 Math.min(pos + 8, line.length()))); 539 Math.min(pos + 8, line.length())));
541 } 540 }
542 541

http://dive4elements.wald.intevation.org