/* ================================================================
* Delft FEWS
* ================================================================
*
* Project Info: http://www.wldelft.nl/soft/fews/index.html
* Project Lead: Karel Heynert (karel.heynert@wldelft.nl)
*
* (C) Copyright 2003, by WL | Delft Hydraulics
* P.O. Box 177
* 2600 MH Delft
* The Netherlands
* http://www.wldelft.nl
*
* DELFT-FEWS is a sophisticated collection of modules designed
* for building a FEWS customised to the specific requirements
* of individual agencies. An open modelling approach allows users
* to add their own modules in an efficient way.
*
* ----------------------------------------------------------------
* LmwKnmiCsvTimeSeriesParser.java
* ----------------------------------------------------------------
* (C) Copyright 2003, by WL | Delft Hydraulics
*
* Original Author: pelgrim
* Contributor(s):
*
* Changes:
* --------
* 9/24/13 : Version 1 ();
*
*
*/
package nl.wldelft.timeseriesparsers;
import nl.wldelft.util.io.LineReader;
import nl.wldelft.util.io.TextParser;
import nl.wldelft.util.timeseries.DefaultTimeSeriesHeader;
import nl.wldelft.util.timeseries.TimeSeriesContentHandler;
import java.util.HashMap;
import java.util.Map;
public class LmwKnmiCsvTimeSeriesParser implements TextParser<TimeSeriesContentHandler> {
@Override
public void parse(LineReader reader, String virtualFileName, TimeSeriesContentHandler contentHandler) throws Exception {
Map<String, String> unitMap = new HashMap<String, String>();
String fileName = "LmwKnmiCsvParameterUnits.txt";
LineReader paramUnits = new LineReader(this.getClass().getResourceAsStream(fileName), fileName);
String[] paramUnitSet;
String line;
String unit;
while ((line = paramUnits.readLine()) != null) {
paramUnitSet = line.split("\t");
unit = paramUnitSet.length >=2 ? paramUnitSet[1] : "";
unitMap.put(paramUnitSet[0], unit);
}
DefaultTimeSeriesHeader header = new DefaultTimeSeriesHeader();
String[] buffer = new String[7];
while ( reader.readLine(',', buffer) != -1 ) {
contentHandler.setTime(contentHandler.getDefaultTimeZone(), "yyyyMMddHHmm", buffer[1].trim() + buffer[2].trim());
header.setLocationId(buffer[0]);
header.setParameterId(buffer[4]);
header.setUnit(unitMap.get(buffer[4].trim()));
contentHandler.setValue('.', buffer[5]);
contentHandler.setTimeSeriesHeader(header);
contentHandler.applyCurrentFields();
}
}
}
|