All Downloads are FREE. Search and download functionalities are using the official Maven repository.

decodes.datasource.CsvPMParser Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!
/*
*  $Id$
*/
package decodes.datasource;

import java.util.Date;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.text.SimpleDateFormat;

import lrgs.common.DcpMsg;
import ilex.util.Logger;
import ilex.util.PropertiesUtil;
import ilex.var.Variable;

import decodes.db.Constants;

/**
 * Use this when parsing CSV (comma-separated-value) files where each
 * line of the file is to be considered a separate 'message'. This PMP
 * gets the medium ID and time from columns and sets the length from
 * the column you specify where the data starts.
 * Properties you can set in the routing spec include:
 * 
    *
  • idcol - The column (1=first column) where the ID is found.
  • *
  • datetimecol - The column where the date/time value starts * (note that the date/time may span several columns
  • *
  • datetimefmt - SimpleDateFormat spec for parsing the date/time
  • *
  • datacol - The column where the data starts
  • *
  • timezone - The time zone for parsing the date/time field
  • *
  • delim - The string delimiter to use for columns (default = comma)
  • *
* Example, for the line: * B2-WI,May,12,2010,06:00,-2.8,83,254,7.4,16,0,11.9,-3.5 * Set these properties: * idcol=1 (B2-WI is the ID) * datetimecol=2 * datetimefmt=MMM,dd,yyyy,HH:mm * timezone=UTC (or whatever time zone should be used) * datacol=6 (first data is -2.8 which is column 6) * delim=, */ public class CsvPMParser extends PMParser { private SimpleDateFormat sdf = null; public int idcol = 1; public int datetimecol = 2; public String datetimefmt = "MMM,dd,yyyy,HH:mm"; public String timezone = "UTC"; public int datacol = 7; public String delim = ","; public String mediumType = Constants.medium_Other; public String headerType = "csv"; private int hdrLength = 0; /** default constructor */ public CsvPMParser() { } public void setProperties(Properties props) { PropertiesUtil.loadFromProps(this, props); sdf = new SimpleDateFormat(datetimefmt); sdf.setTimeZone(TimeZone.getTimeZone(timezone)); Logger.instance().debug1("CsvPMParser delim='" + delim + "'"); } /** Parses the DOMSAT header. Sets the mediumID to the GOES DCP Address. @param msg the message to parse. */ public void parsePerformanceMeasurements(RawMessage msg) throws HeaderParseException { if (sdf == null) { Logger.instance().warning("CsvPMParser called without setting props."); setProperties(new Properties()); } DcpMsg origMsg = msg.getOrigDcpMsg(); String data = new String(msg.getData()); // Get the ID StringTokenizer st = new StringTokenizer(data, delim); for(int col=0; col




© 2015 - 2024 Weber Informatics LLC | Privacy Policy