mschaefer@8971: /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde mschaefer@8971: * Software engineering by mschaefer@8971: * Björnsen Beratende Ingenieure GmbH mschaefer@8971: * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt mschaefer@8971: * mschaefer@8971: * This file is Free Software under the GNU AGPL (>=v3) mschaefer@8971: * and comes with ABSOLUTELY NO WARRANTY! Check out the mschaefer@8971: * documentation coming with Dive4Elements River for details. mschaefer@8971: */ mschaefer@8971: mschaefer@8971: package org.dive4elements.river.importer.sinfo.parsers; mschaefer@8971: mschaefer@8971: import java.io.File; mschaefer@8971: mschaefer@8971: import org.apache.log4j.Logger; mschaefer@8971: import org.dive4elements.river.importer.ImportRiver; mschaefer@8971: import org.dive4elements.river.importer.common.AbstractParser; mschaefer@8971: import org.dive4elements.river.importer.common.ParsingState; mschaefer@8971: import org.dive4elements.river.importer.sinfo.importitem.FlowDepthColumnSeriesImport; mschaefer@8971: import org.dive4elements.river.importer.sinfo.importitem.FlowDepthKmLineImport; mschaefer@8971: import org.dive4elements.river.importer.sinfo.importitem.FlowDepthSeriesImport; mschaefer@8971: import org.dive4elements.river.model.sinfo.FlowDepthColumn; mschaefer@8971: import org.dive4elements.river.model.sinfo.FlowDepthValue; mschaefer@8971: mschaefer@8971: /** mschaefer@8971: * Reads and parses a column of a flow depth file mschaefer@8971: * mschaefer@8971: * @author Matthias Schäfer mschaefer@8971: * mschaefer@8971: */ mschaefer@8971: public class FlowDepthColumnParser extends AbstractParser { mschaefer@8971: mschaefer@8971: /***** FIELDS *****/ mschaefer@8971: mschaefer@8971: private static final Logger log = Logger.getLogger(FlowDepthColumnParser.class); mschaefer@8971: mschaefer@8971: private final FlowDepthSeriesImport parent; mschaefer@8971: mschaefer@8971: private final int colIndex; mschaefer@8971: mschaefer@8971: private final String colName; mschaefer@8971: mschaefer@8971: mschaefer@8971: /***** CONSTRUCTORS *****/ mschaefer@8971: mschaefer@8971: public FlowDepthColumnParser(final File importPath, final File rootRelativePath, final ImportRiver river, final FlowDepthSeriesImport parent, mschaefer@8971: final int colIndex, mschaefer@8971: final String colName) { mschaefer@8971: super(importPath, rootRelativePath, river); mschaefer@8971: this.parent = parent; mschaefer@8971: this.colIndex = colIndex; mschaefer@8971: this.colName = colName; mschaefer@8971: } mschaefer@8971: mschaefer@8971: mschaefer@8971: /***** METHODS *****/ mschaefer@8971: mschaefer@8971: @Override mschaefer@8971: protected Logger getLog() { mschaefer@8971: return log; mschaefer@8971: } mschaefer@8971: mschaefer@8971: @Override mschaefer@8971: protected void logStartInfo() { mschaefer@8971: getLog().info(String.format("Start parsing column %d '%s':;'%s'", this.colIndex, this.colName, this.rootRelativePath)); mschaefer@8971: } mschaefer@8971: mschaefer@8971: @Override mschaefer@8971: protected boolean handleMetaOther() { mschaefer@8971: this.headerParsingState = ParsingState.IGNORE; mschaefer@8971: return false; mschaefer@8971: } mschaefer@8971: mschaefer@8971: @Override mschaefer@8971: protected FlowDepthColumnSeriesImport createSeriesImport(final String filename) { mschaefer@8971: return new FlowDepthColumnSeriesImport(filename, this.parent, this.colName, this.rootRelativePath); mschaefer@8971: } mschaefer@8971: mschaefer@8971: @Override mschaefer@8971: protected FlowDepthKmLineImport createKmLineImport(final Double km, final String[] values) { mschaefer@8971: final double tkheight = parseDoubleWithNull(values[this.colIndex]).doubleValue(); mschaefer@8971: return new FlowDepthKmLineImport(km, tkheight); mschaefer@8971: } mschaefer@8971: }