Package nom.tam.fits
Class AsciiTable
java.lang.Object
nom.tam.fits.Data
nom.tam.fits.AbstractTableData
nom.tam.fits.AsciiTable
- All Implemented Interfaces:
FitsElement
,TableData
This class represents the data in an ASCII table
-
Field Summary
Fields inherited from class nom.tam.fits.Data
dataSize, fileOffset, input
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty ASCII tableAsciiTable
(Header hdr) Create an ASCII table given a header -
Method Summary
Modifier and TypeMethodDescriptionint
Add a column to the table without any associated header information.int
This version of addColumn allows the user to override the default length associated with each column type.int
Add a row at the end of the table.void
deleteColumns
(int start, int len) Delete columns from the table.void
deleteRows
(int start, int len) Delete rows from a FITS tablevoid
fillHeader
(Header hdr) Fill in a header with information that points to this data.getColumn
(int col) Get a column of datagetData()
Get the ASCII table information.getElement
(int row, int col) Get a single element as a one-d array.int
getNCols()
Get the number of columns in the tableint
getNRows()
Get the number of rows in the tableObject[]
getRow
(int row) Get a row.int
Get the number of bytes in a rowprotected long
Return the size of the data sectionboolean
isNull
(int row, int col) See if an element is null.void
read
(ArrayDataInput str) Read in an ASCII table.void
Replace a column with new data.void
setElement
(int row, int col, Object newData) Modify an element in the tablevoid
setNull
(int row, int col, boolean flag) Mark (or unmark) an element as null.void
Modify a row in the tablevoid
updateAfterDelete
(int oldNCol, Header hdr) This is called after we delete columns.void
write
(ArrayDataOutput str) Write the data to an output stream.Methods inherited from class nom.tam.fits.Data
getFileOffset, getKernel, getSize, reset, rewrite, rewriteable, setFileOffset
-
Constructor Details
-
AsciiTable
public AsciiTable()Create an empty ASCII table -
AsciiTable
Create an ASCII table given a header- Parameters:
hdr
- The header describing the table- Throws:
FitsException
- if the operation failed
-
-
Method Details
-
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:
newCol
- 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
-
addColumn
This version of addColumn allows the user to override the default length associated with each column type.- Parameters:
newCol
- The new column datalength
- the requested length for the column- Returns:
- the number of columns after this one is added.
- Throws:
FitsException
- if the operation failed
-
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:
newRow
- 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 columns from the table.- Parameters:
start
- The first, 0-indexed, column to be deleted.len
- The number of columns to be deleted.- Throws:
FitsException
- if the operation failed
-
deleteRows
Delete rows from a FITS table- Parameters:
start
- The first (0-indexed) row to be deleted.len
- The number of rows to be deleted.- Throws:
FitsException
- if the operation failed
-
fillHeader
Fill in a header with information that points to this data.- Parameters:
hdr
- The header to be updated with information appropriate to the current table data.
-
getColumn
Get a column of data- Parameters:
col
- The 0-indexed column to be returned.- Returns:
- The column object -- typically as a 1-d array.
- Throws:
FitsException
- if the operation failed
-
getData
Get the ASCII table information. This will actually do the read if it had previously been deferred- Specified by:
getData
in classData
- Returns:
- The table data as an Object[] array.
- Throws:
FitsException
- if the operation failed
-
getElement
Get a single element as a one-d array. We return String's as arrays for consistency though they could be returned as a scalar.- Parameters:
row
- The 0-based rowcol
- The 0-based column- Returns:
- The requested cell data.
- Throws:
FitsException
- when unable to get the data.
-
getNCols
public int getNCols()Get the number of columns in the table- Returns:
- The number of columns
-
getNRows
public int getNRows()Get the number of rows in the table- Returns:
- The number of rows.
-
getRow
Get a row. If the data has not yet been read just read this row.- Parameters:
row
- The 0-indexed row to be returned.- Returns:
- A row of data.
- Throws:
FitsException
- if the operation failed
-
getRowLen
public int getRowLen()Get the number of bytes in a row- Returns:
- The number of bytes for a single row in the table.
-
getTrueSize
protected long getTrueSize()Return the size of the data section- Returns:
- The size in bytes of the data section, not includeing the padding.
-
isNull
public boolean isNull(int row, int col) See if an element is null.- Parameters:
row
- The 0-based rowcol
- The 0-based column- Returns:
- if the given element has been nulled.
-
read
Read in an ASCII table. Reading is deferred if we are reading from a random access device- Specified by:
read
in interfaceFitsElement
- Specified by:
read
in classData
- Parameters:
str
- the stream to read from- Throws:
FitsException
- if the operation failed
-
setColumn
Replace a column with new data.- Parameters:
col
- The 0-based index to the columnnewData
- The column data. This is typically a 1-d array.- Throws:
FitsException
- if the operation failed
-
setElement
Modify an element in the table- Parameters:
row
- the 0-based rowcol
- the 0-based columnnewData
- The new value for the column. Typically a primitive[1] array.- Throws:
FitsException
- if the operation failed
-
setNull
public void setNull(int row, int col, boolean flag) Mark (or unmark) an element as null. Note that if this FITS file is latter written out, a TNULL keyword needs to be defined in the corresponding header. This routine does not add an element for String columns.- Parameters:
row
- The 0-based row.col
- The 0-based column.flag
- True if the element is to be set to null.
-
setRow
Modify a row in the table- Parameters:
row
- The 0-based index of the rownewData
- The new data. Each element of this array is typically a primitive[1] array.- Throws:
FitsException
- if the operation failed
-
updateAfterDelete
This is called after we delete columns. The HDU doesn't know how to update the TBCOL entries.- Parameters:
oldNCol
- The number of columns we had before deletion.hdr
- The associated header. @throws FitsException if the operation failed- Throws:
FitsException
-
write
Write the data to an output stream.- Specified by:
write
in interfaceFitsElement
- Specified by:
write
in classData
- Parameters:
str
- The output stream to be written to- Throws:
FitsException
- if any IO exception is found or some inconsistency the FITS file arises.
-