vec_math
Class FileMatrix

java.lang.Object
  extended by vec_math.Matrix
      extended by vec_math.FileMatrix
All Implemented Interfaces:
Cloneable

public class FileMatrix
extends Matrix

A class to convert an ascii file consisting of blocked data into a matrix consisting of doubles. Any line starting with '#' is ignored. Lines whose element number do not match the number of the first read valid line are ignored. Although the class name indicates that this class is mainly inended for reading a file, it is nevertheless possible to use it also with other readers, see the appropriate constructor section, FileMatrix(Reader).
Note that this may be an expensive class. Especially evaluating the columns doubles the amount of storage space needed.


Nested Class Summary
 
Nested classes/interfaces inherited from class vec_math.Matrix
Matrix.CloneTest
 
Field Summary
 
Fields inherited from class vec_math.Matrix
colValid, rowValid
 
Constructor Summary
FileMatrix(File infile)
          Constructs a new matrix from a ascii-file.
FileMatrix(Reader file)
          Constructs a new matrix from a reader stream.
 
Method Summary
static void main(String[] arg)
          Test purpose.
static void setFormat(NumberFormat use)
          Changes the decimal format to use when outputting the matrix data to a block data file.
 void toFile(File outfile)
          Writes the entire matrix data into a output file.
static void toFile(File outfile, Matrix m)
          Writes the entire matrix data into a output file.
protected static void toStream(Writer output, Matrix m)
          Writes the entire data into the given reader.
 
Methods inherited from class vec_math.Matrix
clone, columns, equals, evalCol, evalRow, exchangeCol, exchangeRow, getColumn, getElement, getRawColumn, getRawRow, getRow, mult, mult, multOneCol, multOneRow, rows, setCols, setElement, setOneCol, setOneRow, setRows, toString, transpose
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileMatrix

public FileMatrix(File infile)
           throws IOException
Constructs a new matrix from a ascii-file.

Throws:
IOException

FileMatrix

public FileMatrix(Reader file)
           throws IOException
Constructs a new matrix from a reader stream. All lines read are converted into vectors with the LineVector class. Lines starting with '#' are ignored. Lines whose element count does not match the number of elements read in from the first valid line are ignored.

Throws:
IOException
Method Detail

setFormat

public static void setFormat(NumberFormat use)
Changes the decimal format to use when outputting the matrix data to a block data file. Calls the LineVector.setFormat(java.text.NumberFormat) method.


toFile

public void toFile(File outfile)
            throws IOException
Writes the entire matrix data into a output file. The format of the decimal output can be changed either with the LineVector.setFormat(java.text.NumberFormat) or with this class's setFormat(java.text.NumberFormat) method.
No header or trailer can be writtn to the data file. If this is intended use the toStream(java.io.Writer, vec_math.Matrix) method instead.

Throws:
IOException

toFile

public static void toFile(File outfile,
                          Matrix m)
                   throws IOException
Writes the entire matrix data into a output file. The format of the decimal output can be changed either with the LineVector.setFormat(java.text.NumberFormat) or with this class's setFormat(java.text.NumberFormat) method.
No header or trailer can be writtn to the data file. If this is intended use the toStream(java.io.Writer, vec_math.Matrix) method instead.

Throws:
IOException

toStream

protected static void toStream(Writer output,
                               Matrix m)
                        throws IOException
Writes the entire data into the given reader. It is the user's responibility to ensure proper closing of the stream. For format issues of the output, see toFile(java.io.File).
This method is intended for users that want to write header/trailer data to the output file.

Throws:
IOException

main

public static void main(String[] arg)
                 throws IOException
Test purpose.

Throws:
IOException