teichmann@5844: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5844: * Software engineering by Intevation GmbH teichmann@5844: * teichmann@5992: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5844: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5992: * documentation coming with Dive4Elements River for details. teichmann@5844: */ teichmann@5844: teichmann@5829: package org.dive4elements.river.importer.parsers; ingo@2806: ingo@2808: import java.text.ParseException; ingo@2808: ingo@2806: import org.apache.log4j.Logger; ingo@2806: teichmann@5829: import org.dive4elements.river.importer.ImportBedHeight; teichmann@5829: import org.dive4elements.river.importer.ImportBedHeightSingle; teichmann@5829: import org.dive4elements.river.importer.ImportBedHeightSingleValue; ingo@2806: ingo@2806: ingo@2811: public class BedHeightSingleParser extends BedHeightParser { ingo@2806: ingo@2806: private static final Logger log = ingo@2806: Logger.getLogger(BedHeightSingleParser.class); ingo@2806: ingo@2806: ingo@2811: @Override ingo@2811: protected ImportBedHeight newImportBedHeight(String description) { ingo@2811: return new ImportBedHeightSingle(description); ingo@2808: } ingo@2808: ingo@2808: felix@3955: /** felix@3955: * Create ImportBedHeightSingleValue from a line of csv file, add felix@3955: * it to the ImportBedHeight. felix@3955: */ ingo@2811: @Override ingo@2811: protected void handleDataLine(ImportBedHeight obj, String line) { tom@7354: String[] values = line.split(SEPERATOR_CHAR, -1); ingo@2808: tom@7354: if (values == null) { tom@7354: log.warn("BSP: Error while parsing data line: '" + line + "'"); ingo@2808: return; ingo@2808: } ingo@2808: tom@6203: Double km; felix@3955: felix@3955: try { tom@6203: km = new Double(nf.parse(values[0]).doubleValue()); teichmann@7372: tom@6273: Double key = Double.valueOf(km); tom@6273: tom@6273: if (kmExists.contains(key)) { tom@6273: log.warn("duplicate station '" + km + "': -> ignored"); tom@6273: return; tom@6273: } tom@6273: tom@6273: kmExists.add(key); teichmann@7372: } felix@3955: catch (ParseException e) { felix@3955: // We expect a lot of ";;;;;;" lines. felix@3955: return; felix@3955: } felix@3955: felix@3955: // Handle gaps like "10,0;;;;;". tom@7417: if (values.length <= 2) { tom@6047: // Do not import line without useful data tom@7417: if (values.length < 2) { tom@7417: return; tom@7417: } tom@7417: if (values[1].length() == 0) { tom@7417: return; tom@7417: } felix@3955: } felix@3955: teichmann@7372: Double height = null; teichmann@7372: if (values[1].length() > 0) { teichmann@7372: try { teichmann@7372: height = new Double(nf.parse(values[1]).doubleValue()); teichmann@7372: } teichmann@7372: catch (ParseException e) { teichmann@7372: log.warn("BSP: unparseable height " + values[1]); teichmann@7372: } teichmann@7372: } tom@6298: teichmann@7372: Double uncertainty = null; teichmann@7372: if (values[2].length() > 0) { teichmann@7372: try { teichmann@7372: uncertainty = new Double(nf.parse(values[2]).doubleValue()); teichmann@7372: } teichmann@7372: catch (ParseException e) { teichmann@7372: log.warn("BSP: unparseable uncertainty value " + values[2]); teichmann@7372: } teichmann@7372: } tom@6298: teichmann@7372: Double dataGap = null; teichmann@7372: if (values[3].length() > 0) { teichmann@7372: try { teichmann@7372: dataGap = new Double(nf.parse(values[3]).doubleValue()); teichmann@7372: } teichmann@7372: catch (ParseException e) { teichmann@7372: log.warn("BSP: unparseable data gap " + values[3]); teichmann@7372: } teichmann@7372: } tom@6298: teichmann@7372: Double soundingWidth = null; teichmann@7372: if (values[4].length() > 0) { teichmann@7372: try { teichmann@7372: soundingWidth = new Double(nf.parse(values[4]).doubleValue()); teichmann@7372: } teichmann@7372: catch (ParseException e) { teichmann@7372: log.warn("BSP: unparseable sounding width " + values[4]); teichmann@7372: } teichmann@7372: } tom@6298: teichmann@7372: Double width = null; teichmann@7372: if (values[5].length() > 0) { teichmann@7372: try { teichmann@7372: width = new Double(nf.parse(values[5]).doubleValue()); teichmann@7372: } teichmann@7372: catch (ParseException e) { teichmann@7372: log.warn("BSP: unparseable width " + values[5]); teichmann@7372: } teichmann@7372: } teichmann@7372: teichmann@7372: ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( teichmann@7372: (ImportBedHeightSingle) obj, teichmann@7372: km, teichmann@7372: height, teichmann@7372: uncertainty, teichmann@7372: dataGap, teichmann@7372: soundingWidth, teichmann@7372: width); teichmann@7372: teichmann@7372: obj.addValue(value); ingo@2808: } ingo@2806: } ingo@2806: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :