org.mbari.io
Class DelimitedFile

java.lang.Object
  extended byorg.mbari.io.DelimitedFile

public class DelimitedFile
extends java.lang.Object

Read a delimited text file into a double array. The text file should only contain values that can be converted to double values (i.e no columns of dates like 22-Sep-1968).


Use as:
// Construct it.
DelimitedFileReader reader = new DelimitedFileReader("c:\somedatafile.txt");

// ***Set optional arguments***
//If it contains commented columns set the coommentTag
reader.setCommentTag("#") // lines starting with # will be ignored

// Does it contain a row of strings specifying what each column name is
// For example is the first non-commented row something like:
// date, time, latitude, longitude
// If so you need to let the reader know with
reader.setHasColumnNames(true); // The default is false

// Set the delimiter...the default is any whitespace (space or tabs)
reader.setDelimiter(",") // Comma delimited file.

// Read the data
reader.readFile();
double[] data = reader.getData();
String[] columnNames = reader.getColumnNames();

// Some hints to use for looking at column names
List names = Arrays.asList(columnNames);
int timeColumn = name.indexOf("time") // -1 if missing, here it should be 1


Lines with the first charater of '#' or '%' are assumed to be comments

12 Jul 1999; Created FlatFileReader
27 Aug 1999; Fixed a bug (off by one type) in this.c which prevented data with the correct number of lines from being read 06 Dec 2001;

MBARI provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of the Monterey Bay Aquarium Research Institute to assist in its use, correction, modification, or enhancement. This information should not be published or distributed to third parties without specific written permission from MBARI.


Copyright 2002 MBARI.
MBARI Proprietary Information. All rights reserved.


$Log: DelimitedFile.java,v $ Revision 1.2 2002/11/22 17:19:24 brian no message Revision 1.1 2002/07/02 21:51:30 brian Coallating shared files into the mbari.jar project Revision 1.1 2002/04/17 21:48:34 brian Adding Vars Database support. Moving to IRovNavigationIterator as the common interface between disparate datasets Revision 1.9 2002/02/25 16:40:40 brian Modified tools to ignore eastings and northings columns. Revision 1.8 2002/02/09 00:07:19 brian Working tools to calculate ROV altitude. There's a glitch that occurs for a few files. Need to look into this Revision 1.7 2002/02/08 00:55:54 brian Wokring on creating a tool to add rov altitude. utm coords, bathymetry and depth to ROV navigation files. The tools can be used iteratively so that if the ROV data is outside a grid you, it will fill in what it can but allow the user to rerun the data on another grid. THen it just fills in values that are missing. Revision 1.6 2002/02/06 00:39:07 brian no message Revision 1.5 2002/01/30 00:23:56 brian Added comments to all classes and methods. Tested the accuracy of AsciiRasterGridReader and AsciiRasterGridWriter. Also checked the the GridUtil was populating the spatial grids correctly and accurately. The data files generated matched up perfectly with the orginal text files. Also implemented an RovAltitudeFilter class to encapsulate different filtering methods.


Version:
: $Revision: 1.2 $
Author:
: $Author: brian $

Field Summary
protected  java.lang.String[] columnNames
           
protected  double[][] data
           
 
Constructor Summary
DelimitedFile(java.io.File file)
          Create a DelimitedFileReader and intialize memory.
DelimitedFile(java.lang.String filename)
          Create a DelimitedFileReader.
 
Method Summary
 java.lang.String[] getColumnNames()
           
 java.lang.String getCommentTag()
           
 double[][] getData()
          Accesor method to access the data in the flat file
 double getDatum(int row, int column)
           
 java.lang.String getDelimiter()
           
 java.io.File getFile()
          Accesor method to get the file read by the FlatFileReader
 java.lang.String getFilename()
          Deprecated. 07 Feb 2002; use getFile() instead
 boolean getHasColumnNames()
           
 int getNumOfColumns()
          Method to get the number of columns in the data array
 int getNumOfRows()
          Method to get the number of rows in the data array
static void main(java.lang.String[] args)
          For debugging
 void read()
          This method does the actual reading of the data file.
 void readFile()
          Deprecated. 08 Feb 2002; use read() instead
 void setCommentTag(java.lang.String newCommentTag)
           
 void setDelimiter(java.lang.String newDelimiter)
           
 void setHasColumnNames(boolean newHasColumnNames)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected double[][] data

columnNames

protected java.lang.String[] columnNames
Constructor Detail

DelimitedFile

public DelimitedFile(java.lang.String filename)
              throws java.io.IOException
Create a DelimitedFileReader.

Parameters:
filename - Name of file to read

DelimitedFile

public DelimitedFile(java.io.File file)
              throws java.io.IOException
Create a DelimitedFileReader and intialize memory.

Parameters:
file - File object representing the file to be read
Method Detail

readFile

public void readFile()
              throws java.io.IOException
Deprecated. 08 Feb 2002; use read() instead

This method does the actual reading of the data file. It tokenizes the line by using white spaces

Throws:
java.io.IOException

read

public void read()
          throws java.io.IOException
This method does the actual reading of the data file. It tokenizes the line by using white spaces

Throws:
java.io.IOException

getData

public double[][] getData()
Accesor method to access the data in the flat file

Returns:
data A double array of the data contained in the flat file

getFilename

public java.lang.String getFilename()
Deprecated. 07 Feb 2002; use getFile() instead

Accesor method to get the filename of read by the FlatFileReader

Returns:
filename The name of the file used to construct a FlatFileReader instance.

getFile

public java.io.File getFile()
Accesor method to get the file read by the FlatFileReader

Returns:
file The the file used to construct a FlatFileReader instance.

getDatum

public double getDatum(int row,
                       int column)

getNumOfRows

public int getNumOfRows()
Method to get the number of rows in the data array

Returns:
The number of rows of data read.

getNumOfColumns

public int getNumOfColumns()
Method to get the number of columns in the data array

Returns:
The number of columns of data read.

setHasColumnNames

public void setHasColumnNames(boolean newHasColumnNames)

getHasColumnNames

public boolean getHasColumnNames()

setDelimiter

public void setDelimiter(java.lang.String newDelimiter)

getDelimiter

public java.lang.String getDelimiter()

getColumnNames

public java.lang.String[] getColumnNames()

setCommentTag

public void setCommentTag(java.lang.String newCommentTag)

getCommentTag

public java.lang.String getCommentTag()

main

public static void main(java.lang.String[] args)
For debugging