changeset 6745:bd437771ea00 double-precision

Sediment density parser: fetch year from metaline and parse
author Tom Gottfried <tom.gottfried@intevation.de>
date Fri, 02 Aug 2013 11:36:33 +0200
parents 30c4276d09f8
children d3c609581313
files backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentDensityParser.java
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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,

http://dive4elements.wald.intevation.org