[PATCH] Sediment density parser: fetch year from metaline and parse
Wald Commits
scm-commit at wald.intevation.org
Fri Aug 2 11:36:36 CEST 2013
# HG changeset patch
# User Tom Gottfried <tom.gottfried at intevation.de>
# Date 1375436193 -7200
# Branch double-precision
# Node ID bd437771ea0039d681aafd04dcfde4dbcc3a73a6
# Parent 30c4276d09f8e36774b92ae47a68fc769a05bc0f
Sediment density parser: fetch year from metaline and parse
diff -r 30c4276d09f8 -r bd437771ea00 backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentDensityParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentDensityParser.java Thu Aug 01 13:07:37 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentDensityParser.java Fri Aug 02 11:36:33 2013 +0200
@@ -39,12 +39,16 @@
public static final Pattern META_DEPTH =
Pattern.compile("^Tiefe: (\\w++)-(\\w++)( (\\w++))?.*");
+ public static final Pattern META_YEAR =
+ Pattern.compile("^Jahr: (\\d{4}).*");
+
protected List<ImportSedimentDensity> sedimentDensities;
protected ImportSedimentDensity current;
protected String currentDescription;
+ protected String yearString;
public SedimentDensityParser() {
sedimentDensities = new ArrayList<ImportSedimentDensity>();
@@ -88,6 +92,9 @@
if (handleMetaDepth(line)) {
return;
}
+ else if (handleMetaYear(line)) {
+ return;
+ }
else {
log.warn("Unknown meta line: '" + line + "'");
}
@@ -124,6 +131,23 @@
return false;
}
+ protected boolean handleMetaYear(String line) {
+ Matcher m = META_YEAR.matcher(line);
+
+ if (m.matches()) {
+ yearString = m.group(1);
+
+ log.info("Found sediment density year: " + yearString);
+
+ return true;
+ }
+ else {
+ log.debug("Meta line doesn't contain year: " + line);
+ }
+
+ return false;
+ }
+
protected void handleDataLine(String line) {
String[] vals = line.split(SEPERATOR_CHAR);
@@ -153,6 +177,12 @@
}
BigDecimal year = null;
+ try {
+ year = new BigDecimal(nf.parse(yearString).doubleValue());
+ }
+ catch (ParseException pe) {
+ log.warn("Unparseable year string");
+ }
current.addValue(new ImportSedimentDensityValue(
km,
More information about the Dive4elements-commits
mailing list