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

decodes.snotel.SnotelPlatformSpecList 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!
package decodes.snotel;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.StringTokenizer;

import ilex.util.Logger;
import ilex.util.StderrLogger;
import lrgs.common.DcpAddress;

/**
 * This class maintains a collection of SnotelPlatformSpec that
 * are read from a designated file.
 */
public class SnotelPlatformSpecList
{
	private HashMap platformSpecs
		= new HashMap();
	private long lastLoadTime = 0L;
	
	public SnotelPlatformSpecList()
	{
	}
	
	/**
	 * Return the platform spec corresponding to the GOES address or null if
	 * there is none.
	 * @param addr the GOES DCP Address
	 * @return platform spec or null
	 */
	public SnotelPlatformSpec getPlatformSpec(DcpAddress addr)
	{
		
		return platformSpecs.get(addr);
	}
	
	public Collection getPlatformSpecs()
	{
		return platformSpecs.values();
	}

	public void loadFile(File specFile, Logger logger)
		throws IOException
	{
		platformSpecs.clear();
		
		// open filename with line number reader
		LineNumberReader lnr = new LineNumberReader(new FileReader(specFile));
		String line;
		while ((line = lnr.readLine()) != null)
		{
			//MJM 20201110 new format is: stationId|stationName|dcpAddr|formatFlag
			line = line.trim();
			if (line.startsWith("#") || line.length() == 0)
				continue;
			String delim = ",";
			if (line.contains("|"))
				delim = "|";
//System.out.println("Read line '" + line + "', delim=" + delim);

			String fields[] = new String[4];
			StringTokenizer st = new StringTokenizer(line, delim);
			int nt = 0;
			while(nt < 4 && st.hasMoreTokens())
				fields[nt++] = st.nextToken();
			
//			String fields[] = line.split(delim);
//			if (fields.length < 4)
			if (nt < 4)
			{
				logger.warning("Line " + lnr.getLineNumber() + " '" + line
					+ "' incorrect number of pipe-separated fields. 4 required. -- Skipped.");
				continue;
			}
//for(int idx=0;idx




© 2015 - 2024 Weber Informatics LLC | Privacy Policy