Package nom.tam.fits
Class BinaryTable
java.lang.Object
nom.tam.fits.Data
nom.tam.fits.AbstractTableData
nom.tam.fits.BinaryTable
- All Implemented Interfaces:
FitsElement
,TableData
- Direct Known Subclasses:
CompressedImageData
,CompressedTableData
This class defines the methods for accessing FITS binary table data.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Collect all of the information we are using to describe a column into a single object.protected static class
Opaque state to pass to ColumnTable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List
<BinaryTable.ColumnDesc> A list describing each of the columns in the tableprivate ArrayDataInput
The stream used to input the data.private final FitsHeap
This is the area in which variable length column data lives.private int
The number of bytes between the end of the data and the heapprivate boolean
Switched to an initial value of true TAM, 11/20/12, since the heap may be generated without any I/O.private static final Logger
private static final int
private static final long
private int
The number of rows in the table.private int
The length in bytes of each row.private ColumnTable
<BinaryTable.SaveState> Where the data is actually stored.private boolean
Fields inherited from class nom.tam.fits.Data
dataSize, fileOffset, input
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a null binary table data segment.BinaryTable
(Object[] o) Create a binary table from existing data in column order.BinaryTable
(Object[][] data) Create a binary table from existing data in row order.BinaryTable
(Header myHeader) Create a binary table from given header information.BinaryTable
(ColumnTable<?> tabIn) Create a binary table from an existing ColumnTable -
Method Summary
Modifier and TypeMethodDescriptionprotected void
int
Add a column to the table without any associated header information.int
addFlattenedColumn
(Object o, int[] dims) Add a column where the data is already flattened.(package private) int
addFlattenedColumn
(Object o, int[] dims, boolean allocated) This function is needed since we had made addFlattenedColumn public so in principle a user might have called it directly.int
Add a row at the end of the table.private Object
arrayToColumn
(BinaryTable.ColumnDesc added, Object o) Convert the external representation to the BinaryTable representation.private boolean
checkCompVary
(float[][][] o) private boolean
checkDCompVary
(double[][][] o) private Object
columnToArray
(BinaryTable.ColumnDesc colDesc, Object o, int rows) Convert data from binary table representation to external Java representation.private static Object[]
convertToColumns
(Object[][] data) Convert a two-d table to a table of columns.static void
createColumnDataFor
(BinaryTable table) TODO: this is only for internal access!protected ColumnTable
<BinaryTable.SaveState> createColumnTable
(Object[] arrCol, int[] sizes) private ColumnTable
<BinaryTable.SaveState> Create a column table given the number of rows and a model row.void
deleteColumns
(int start, int len) Delete a set of columns.void
deleteRows
(int row, int len) Delete rows from a table.private Object
private Object
private void
private void
(package private) void
fillForColumn
(Header h, int col, Cursor<String, HeaderCard> iter) Update the header to reflect the details of a given column.void
fillHeader
(Header h) Update a FITS header to reflect the current state of the data.Class<?>[]
getBases()
getColumn
(int col) Get a given columngetData()
(package private) BinaryTable.ColumnDesc
getDescriptor
(int column) int[][]
getElement
(int i, int j) Get a particular element from the table.private Object[]
getFileRow
(int row) Object[]
getFlattenedColumn
(int col) int
int
private Object[]
getMemoryRow
(int row) Get a row from memory.Object[]
int
getNCols()
Get the number of columns in the table.int
getNRows()
Get the number of rows in the tablegetRawElement
(int i, int j) Object[]
getRow
(int row) Get a given rowint[]
getSizes()
static int[]
Parse the TDIMS value.(package private) int
getTFORMLength
(String tform) Get the explicit or implied length of the TFORM field(package private) char
getTFORMType
(String tform) Get the type in the TFORM field(package private) char
getTFORMVarType
(String tform) Get the type in a varying length column TFORMlong
Get the size of the data in the HDU sans padding.char[]
getTypes()
private int
initialNumber
(String tform) Get an unsigned number at the beginning of a stringprivate boolean
Is this a variable length column? It is if it's a two-d primitive array and the second dimension is not constant.private boolean
(package private) void
pointToColumn
(int col, Header hdr) Update the header to reflect information about a given column.private int
processCol
(Header header, int col) Process one column from a FITS Header.void
Read the data -- or defer reading on random access.protected void
readHeap
(ArrayDataInput input) Read the heap which contains the data for variable length arrays.protected void
Read table, heap and paddingprivate void
void
Replace a column in the table.(package private) boolean
setComplexColumn
(int index) Convert a column from float/double to float complex/double complex.void
setElement
(int i, int j, Object o) Replace a single element within the table.void
setFlattenedColumn
(int col, Object data) Set a column with the data already flattened.void
Replace a row in the table.void
updateAfterDelete
(int oldNcol, Header hdr) Update the header after a deletion.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
(ArrayDataOutput os) Write the table, heap and padding.Methods inherited from class nom.tam.fits.Data
getFileOffset, getKernel, getSize, reset, rewrite, rewriteable, setFileOffset
-
Field Details
-
MAX_INTEGER_VALUE
private static final long MAX_INTEGER_VALUE- See Also:
-
MAX_EMPTY_BLOCK_SIZE
private static final int MAX_EMPTY_BLOCK_SIZE- See Also:
-
LOG
-
heap
This is the area in which variable length column data lives. -
heapOffset
private int heapOffsetThe number of bytes between the end of the data and the heap -
heapReadFromStream
private boolean heapReadFromStreamSwitched to an initial value of true TAM, 11/20/12, since the heap may be generated without any I/O. In that case it's valid. We set heapReadFromStream to false when we skip input. -
warnedOnVariableConversion
private boolean warnedOnVariableConversion -
columnList
A list describing each of the columns in the table -
nRow
private int nRowThe number of rows in the table. -
rowLen
private int rowLenThe length in bytes of each row. -
table
Where the data is actually stored. -
currInput
The stream used to input the data. This is saved so that we possibly skip reading the data if the user doesn't wish to read all or parts of this table.
-
-
Constructor Details
-
BinaryTable
public BinaryTable()Create a null binary table data segment. -
BinaryTable
Create a binary table from an existing ColumnTable- Parameters:
tabIn
- the column table to create the binary table from
-
BinaryTable
Create a binary table from given header information.- Parameters:
myHeader
- A header describing what the binary table should look like.- Throws:
FitsException
- if the specified header is not usable for a binary table
-
BinaryTable
Create a binary table from existing data in column order.- Parameters:
o
- array of columns- Throws:
FitsException
- if the data for the columns could not be used as coulumns
-
BinaryTable
Create a binary table from existing data in row order.- Parameters:
data
- The data used to initialize the binary table.- Throws:
FitsException
- if the data could not be converted to a binary table
-
-
Method Details
-
createColumnDataFor
TODO: this is only for internal access!- Parameters:
table
- the table to create the column data.- Throws:
FitsException
- if the data could not be created.
-
getTDims
Parse the TDIMS value. If the TDIMS value cannot be deciphered a one-d array with the size given in arrsiz is returned.- Parameters:
tdims
- The value of the TDIMSn card.- Returns:
- An int array of the desired dimensions. Note that the order of the tdims is the inverse of the order in the TDIMS key.
-
convertToColumns
Convert a two-d table to a table of columns. Handle String specially. Every other element of data should be a primitive array of some dimensionality. Basically the translates a table expressed as objects in row order to a table with objects in column order. -
addColumn
Description copied from interface:TableData
Add a column to the table without any associated header information. Users should be cautious of calling this routine directly rather than the corresponding routine in AsciiTableHDU since this routine knows nothing of the FITS header modifications required.- Parameters:
o
- the new column information. the newCol should be an Object[] where type of all of the constituents is identical. The length of data should match the other columns. Note: It is valid for data to be a 2 or higher dimensionality primitive array. In this case the column index is the first (in Java speak) index of the array. E.g., if called with int[30][20][10], the number of rows in the table should be 30 and this column will have elements which are 2-d integer arrays with TDIM = (10,20).- Returns:
- the number of columns in the adapted table
- Throws:
FitsException
- if the operation failed
-
addFlattenedColumn
Add a column where the data is already flattened.- Parameters:
o
- The new column data. This should be a one-dimensional primitive array.dims
- The dimensions of one row of the column.- Returns:
- the new column size
- Throws:
FitsException
- if the array could not be flattened
-
addRow
Description copied from interface:TableData
Add a row at the end of the table. Given the way the table is structured this will normally not be very efficient.Users should be cautious of calling this routine directly rather than the corresponding routine in AsciiTableHDU since this routine knows nothing of the FITS header modifications required.- Parameters:
o
- An array of elements to be added. Each element of o should be an array of primitives or a String.- Returns:
- the number of rows in the adapted table
- Throws:
FitsException
- if the operation failed
-
deleteColumns
Delete a set of columns. Note that this does not fix the header, so users should normally call the routine in TableHDU. * @throws FitsException if the operation failed- Throws:
FitsException
-
deleteRows
Delete rows from a table.- Parameters:
row
- The 0-indexed start of the rows to be deleted.len
- The number of rows to be deleted. * @throws FitsException if the operation failed- Throws:
FitsException
-
fillHeader
Update a FITS header to reflect the current state of the data. * @throws FitsException if the operation failed- Specified by:
fillHeader
in classData
- Parameters:
h
- header to fill with the data from the current data object- Throws:
FitsException
- if the operation fails
-
getBases
- Returns:
- the types in the table, not the underlying types (e.g., for varying length arrays or booleans).
-
getColumn
Get a given column- Parameters:
col
- The index of the column. * @throws FitsException if the operation failed- Throws:
FitsException
-
getData
- Specified by:
getData
in classData
- Returns:
- the data array object.
- Throws:
FitsException
- if the data could not be gathered .
-
getDimens
public int[][] getDimens() -
getElement
Get a particular element from the table.- Parameters:
i
- The row of the element.j
- The column of the element. * @throws FitsException if the operation failed- Throws:
FitsException
-
getFlatColumns
-
getFlattenedColumn
- Parameters:
col
- the column to flatten- Returns:
- 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.
- Throws:
FitsException
- if the column could not be flattened
-
getHeapOffset
public int getHeapOffset()- Returns:
- the offset to the heap
-
getHeapSize
public int getHeapSize()- Returns:
- the size of the heap -- including the offset from the end of the table data.
-
getModelRow
- Returns:
- a row that may be used for direct i/o to the table.
-
getNCols
public int getNCols()Get the number of columns in the table. -
getNRows
public int getNRows()Get the number of rows in the table -
getRawElement
- Parameters:
i
- The row of the element.j
- The column of the element.- Returns:
- a particular element from the table but do no processing of this element (e.g., dimension conversion or extraction of variable length array elements/)
- Throws:
FitsException
- if the operation failed
-
getRow
Get a given row- Parameters:
row
- The index of the row to be returned.- Returns:
- A row of data. * @throws FitsException if the operation failed
- Throws:
FitsException
-
getSizes
public int[] getSizes() -
getTrueSize
public long getTrueSize()Get the size of the data in the HDU sans padding.- Specified by:
getTrueSize
in classData
-
getTypes
public char[] getTypes() -
read
Read the data -- or defer reading on random access. * @throws FitsException if the operation failed- Specified by:
read
in interfaceFitsElement
- Specified by:
read
in classData
- Parameters:
i
- The input data stream- Throws:
FitsException
- if the read was unsuccessful.
-
setColumn
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.
-
setElement
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 if the operation failed- Throws:
FitsException
-
setFlattenedColumn
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.
-
setRow
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.
-
updateAfterDelete
Update the header after a deletion.- Throws:
FitsException
- if the operation failed
-
write
Write the table, heap and padding. * @throws FitsException if the operation failed- Specified by:
write
in interfaceFitsElement
- Specified by:
write
in classData
- Parameters:
os
- The output stream on which to write the data.- Throws:
FitsException
- if the write was unsuccessful.
-
arrayToColumn
Convert the external representation to the BinaryTable representation. Transformation include boolean -> T/F, Strings -> byte arrays, variable length arrays -> pointers (after writing data to heap).- Throws:
FitsException
- if the operation failed
-
checkCompVary
private boolean checkCompVary(float[][][] o) -
checkDCompVary
private boolean checkDCompVary(double[][][] o) -
columnToArray
private Object columnToArray(BinaryTable.ColumnDesc colDesc, Object o, int rows) throws FitsException Convert data from binary table representation to external Java representation. * @throws FitsException if the operation failed- Throws:
FitsException
-
createTable
Create a column table given the number of rows and a model row. This is used when we defer instantiation of the ColumnTable until the user requests data from the table. * @throws FitsException if the operation failed- Throws:
FitsException
-
encapsulate
-
encurl
-
ensureData
- Throws:
FitsException
-
ensureDataSilent
private void ensureDataSilent() -
getFileRow
- Returns:
- row from the file.
- Throws:
FitsException
- if the operation failed
-
getMemoryRow
Get a row from memory. * @throws FitsException if the operation failed- Throws:
FitsException
-
initialNumber
Get an unsigned number at the beginning of a string -
isVarying
Is this a variable length column? It is if it's a two-d primitive array and the second dimension is not constant. It may also be a 3-d array of type float or double where the last index is always 2 (when the second index is non-zero). In this case it can be a complex varying column. -
isVaryingComp
-
processCol
Process one column from a FITS Header. * @throws FitsException if the operation failed- Throws:
FitsException
-
saveExtraState
private void saveExtraState() -
addByteVaryingColumn
- Throws:
TableException
-
createColumnTable
protected ColumnTable<BinaryTable.SaveState> createColumnTable(Object[] arrCol, int[] sizes) throws TableException - Throws:
TableException
-
readHeap
Read the heap which contains the data for variable length arrays. A. Kovacs (4/1/08) Separated heap reading, s.t. the heap can be properly initialized even if in deferred read mode. columnToArray() checks and initializes the heap as necessary.- Parameters:
input
- stream to read from.- Throws:
FitsException
- if the heap could not be read from the stream
-
readTrueData
Read table, heap and padding- Parameters:
i
- the stream to read the data from.- Throws:
FitsException
- if the reading failed
-
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.- Returns:
true
if the column is valid
-
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.- Returns:
true
if the row is valid
-
addFlattenedColumn
This function is needed since we had made addFlattenedColumn public so in principle a user might have called it directly.- Parameters:
o
- The new column data. This should be a one-dimensional primitive array.dims
- The dimensions of one row of the column.allocated
- is it already in the columnList?- Returns:
- the new column size
- Throws:
FitsException
-
fillForColumn
Update the header to reflect the details of a given column. * @throws FitsException if the operation failed- Throws:
FitsException
-
getDescriptor
-
getTFORMLength
Get the explicit or implied length of the TFORM field -
getTFORMType
Get the type in the TFORM field -
getTFORMVarType
Get the type in a varying length column TFORM -
pointToColumn
Update the header to reflect information about a given column. This routine tries to ensure that the Header is organized by column. * @throws FitsException if the operation failed- Throws:
FitsException
-
setComplexColumn
Convert a column from float/double to float complex/double complex. This is only possible for certain columns. The return status indicates if the conversion is possible.- Parameters:
index
- The 0-based index of the column to be reset.- Returns:
- Whether the conversion is possible. * @throws FitsException if the operation failed
- Throws:
FitsException
-