nom.tam.fits
Class BinaryTable

java.lang.Object
  extended by nom.tam.fits.Data
      extended by nom.tam.fits.BinaryTable

public class BinaryTable
extends Data

This class defines the methods for accessing FITS binary table data.


Field Summary
 
Fields inherited from class nom.tam.fits.Data
dataArray
 
Constructor Summary
BinaryTable()
          Create a null binary table data segment.
BinaryTable(Header myHeader)
          Create a binary table from given header information.
BinaryTable(java.lang.Object[][] data)
          Create a binary table from existing data in row order.
 
Method Summary
 void addColumn(java.lang.Object[] o)
          Add a column to the end of a table.
 void addFlattenedColumn(java.lang.Object o, int[] dims)
          Add a column where the data is already flattened.
 void addRow(java.lang.Object[] o)
          Add a row at the end of the table.
 Column addVarData(java.lang.Object[] data)
          Add a variable length column to the data.
protected  void expandHashArea(int need)
          This routine makes sure the hash area is large enough to fill a given request.
 java.lang.Class[] getBases()
           
 java.lang.Object[] getColumn(int col)
          Get a given column
 int[][] getDimens()
           
 java.lang.Object getElement(int i, int j)
          Get a particular element from the table.
 java.lang.Object getFlattenedColumn(int col)
          Get a column in flattened format.
 int getHeapSize()
           
 int getNcol()
          Get the number of columns in the table.
 int getNrow()
          Get the number of rows in the table
 java.lang.Object[] getRow(int row)
          Get a given row
 int[] getSizes()
           
 int getTrueSize()
          Get the size of the data in the HDU sans padding.
 char[] getTypes()
           
 java.lang.Object getVarData(int col, java.lang.Class baseClass, boolean complex)
          Get the data from a variable length column as a two-d primitive array.
 void read(BufferedDataInputStream i)
          Read a data array into the current object and if needed position to the beginning of the next FITS block.
protected  void readTrueData(BufferedDataInputStream i)
          Read in the actual data portion.
 void setColumn(int col, java.lang.Object[] xcol)
          Replace a column in the table.
 void setElement(int i, int j, java.lang.Object o)
          Replace a single element within the table.
 void setFlattenedColumn(int col, java.lang.Object data)
          Set a column with the data already flattened.
 void setRow(int row, java.lang.Object[] data)
          Replace a row in the table.
protected  int useModelRow(java.lang.Object[] model, int nrow)
          Use an example row to determine what the table should look like.
protected  boolean validColumn(int j)
          Check if the column number is valid.
protected  boolean validRow(int i)
          Check to see if this is a valid row.
 void write(BufferedDataOutputStream os)
          Write the data -- including any buffering needed
protected  void writeTrueData(BufferedDataOutputStream o)
          Write the data including any hash data.
 
Methods inherited from class nom.tam.fits.Data
getData, getPaddedSize, getPadding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryTable

public BinaryTable()
            throws FitsException
Create a null binary table data segment.

Throws:
FitsException

BinaryTable

public BinaryTable(Header myHeader)
            throws FitsException
Create a binary table from given header information.

Parameters:
header - A header describing what the binary table should look like.
Throws:
FitsException

BinaryTable

public BinaryTable(java.lang.Object[][] data)
            throws FitsException
Create a binary table from existing data in row order.

Parameters:
data - The data used to initialize the binary table.
Throws:
FitsException
Method Detail

useModelRow

protected int useModelRow(java.lang.Object[] model,
                          int nrow)
Use an example row to determine what the table should look like.

Parameters:
model - An example of a row. Each element of model should have the structure of the corresponding element of the row.
nrow - The number of rows in the table.
Returns:
The size of the table in bytes.

getRow

public java.lang.Object[] getRow(int row)
                          throws FitsException
Get a given row

Parameters:
row - The index of the row to be returned.
Returns:
A row of data.
Throws:
FitsException

setRow

public void setRow(int row,
                   java.lang.Object[] data)
            throws FitsException
Replace a row in the table.

Parameters:
row - The index of the row to be replaced.
data - The new values for the row.
Throws:
FitsException - Thrown if the new row cannot match the existing data.

setColumn

public void setColumn(int col,
                      java.lang.Object[] xcol)
               throws FitsException
Replace a column in the table.

Parameters:
col - The index of the column to be replaced.
xcol - The new data for the column
Throws:
FitsException - Thrown if the data does not match the current column description.

setFlattenedColumn

public void setFlattenedColumn(int col,
                               java.lang.Object data)
                        throws FitsException
Set a column with the data already flattened.

Parameters:
col - The index of the column to be replaced.
data - The new data array. This should be a one-d primitive array.
Throws:
FitsException - Thrown if the type of length of the replacement data differs from the original.

getColumn

public java.lang.Object[] getColumn(int col)
                             throws FitsException
Get a given column

Parameters:
col - The index of the column.
Throws:
FitsException

getFlattenedColumn

public java.lang.Object getFlattenedColumn(int col)
                                    throws FitsException
Get a column in flattened format. For large tables getting a column in standard format can be inefficient because a separate object is needed for each row. Leaving the data in flattened format means that only a single object is created.

Parameters:
col -
Throws:
FitsException

getElement

public java.lang.Object getElement(int i,
                                   int j)
                            throws FitsException
Get a particular element from the table.

Parameters:
i - The row of the element.
j - The column of the element.
Throws:
FitsException

addRow

public void addRow(java.lang.Object[] o)
            throws FitsException
Add a row at the end of the table.

Parameters:
o - An array of objects instantiating the data. These should have the same structure as any existing rows.
Throws:
FitsException

addColumn

public void addColumn(java.lang.Object[] o)
               throws FitsException
Add a column to the end of a table.

Parameters:
o - An array of identically structured objects with the same number of elements as other columns in the table.
Throws:
FitsException

addFlattenedColumn

public void addFlattenedColumn(java.lang.Object o,
                               int[] dims)
                        throws FitsException
Add a column where the data is already flattened.

Parameters:
o - The new column data. This should be a one-dimensional primitive array.
dimens - The dimensions of one row of the column.
Throws:
FitsException

getNrow

public int getNrow()
Get the number of rows in the table


getNcol

public int getNcol()
Get the number of columns in the table.


validRow

protected boolean validRow(int i)
Check to see if this is a valid row.

Parameters:
i - The Java index (first=0) of the row to check.

validColumn

protected boolean validColumn(int j)
Check if the column number is valid.

Parameters:
j - The Java index (first=0) of the column to check.

setElement

public void setElement(int i,
                       int j,
                       java.lang.Object o)
                throws FitsException
Replace a single element within the table.

Parameters:
i - The row of the data.
j - The column of the data.
o - The replacement data.
Throws:
FitsException

expandHashArea

protected void expandHashArea(int need)
This routine makes sure the hash area is large enough to fill a given request. If not it reallocates the hash area, and copies the old data into the new area.

Parameters:
need - The number of bytes needed for the current hash area request.

writeTrueData

protected void writeTrueData(BufferedDataOutputStream o)
                      throws FitsException
Write the data including any hash data.

Overrides:
writeTrueData in class Data
Parameters:
o - The output stream.
Throws:
FitsException

read

public void read(BufferedDataInputStream i)
          throws FitsException
Description copied from class: Data
Read a data array into the current object and if needed position to the beginning of the next FITS block.

Overrides:
read in class Data
Parameters:
i - The input data stream
Throws:
FitsException

readTrueData

protected void readTrueData(BufferedDataInputStream i)
                     throws FitsException
Description copied from class: Data
Read in the actual data portion. This method needs to be overriden for ASCII tables and for binary tables with variable length data.

Overrides:
readTrueData in class Data
Parameters:
i - The input stream.
Throws:
FitsException

getTrueSize

public int getTrueSize()
Get the size of the data in the HDU sans padding.

Overrides:
getTrueSize in class Data

addVarData

public Column addVarData(java.lang.Object[] data)
                  throws FitsException
Add a variable length column to the data.

Parameters:
data - The data comprising the variable length column. This should be a two dimensional primitive array (3D for complex data). Note that it is declared as a one dimensional object array to make access convenient. Any 2-d array can be cast to a 1-d array of objects.
Returns:
A column describing the variable format data. This column can then be added to the table using other functions.
Throws:
FitsException

getVarData

public java.lang.Object getVarData(int col,
                                   java.lang.Class baseClass,
                                   boolean complex)
                            throws FitsException
Get the data from a variable length column as a two-d primitive array.

Parameters:
col - The index of the column to be returned.
newArray - The array to be filled with variable length data. This is passed to the BinaryTable class rather than created here so that we can handle complex data properly. This will be a two or three dimensional array where the first dimension is the number of rows in the table.
baseClass - The base class of the array. It should be one of the primitive types, e.g, Integer.TYPE.
Throws:
FitsException

write

public void write(BufferedDataOutputStream os)
           throws FitsException
Description copied from class: Data
Write the data -- including any buffering needed

Overrides:
write in class Data
Parameters:
os - The output stream on which to write the data.
Throws:
FitsException

getHeapSize

public int getHeapSize()

getDimens

public int[][] getDimens()

getBases

public java.lang.Class[] getBases()

getTypes

public char[] getTypes()

getSizes

public int[] getSizes()