Table Routines
There are two functions to create a new HDU table extension: fits_create_ascii_table
and fits_create_binary_table
. In general, one should pick the second as binary tables require less space on the disk and are more efficient to read and write. (Moreover, a few datatypes are not supported in ASCII tables). In order to create a table, the programmer must specify the characteristics of each column by passing an array of tuples. Here is an example:
f = fits_create_file("!new.fits")
coldefs = [("SPEED", "1D", "m/s"),
("MASS", "1E", "kg"),
("PARTICLE", "20A", "Name")]
fits_create_binary_tbl(f, 10, coldefs, "PARTICLE")
This example creates a table with room for 10 entries, each of them describing the characteristics of a particle: its speed, its mass, and its name (codified as a 20-character string). See the documentation of fits_create_ascii_tbl
for more details.
CFITSIO.fits_create_ascii_tbl
— Functionfits_create_ascii_tbl(f::FITSFile, numrows::Integer,
coldefs::Union{Array{NTuple{3,String}}, Array{NTuple{2,String}}},
extname::Union{String, Nothing} = nothing)
Append a new HDU containing an ASCII table.
The table will have numrows
rows (this parameter can be set to zero), each initialized with the default value. In order to create a table, the programmer must specify the characteristics of each column. The columns are specified by the coldefs
variable, which is an array of tuples. Each tuple must have two or three string fields:
- The name of the column.
- The data type and the repetition count. It must be a string made by a number (the repetition count) followed by a letter specifying the type (in the example above,
D
stands forFloat64
,E
stands forFloat32
,A
stands forChar
). Refer to the CFITSIO documentation for more information about the syntax of this parameter. - The unit of this field. This is used to set the corresponding
TUNITn
keywords. Ifcoldefs
is a two-tuple, the unit keywords are left unset. If the third field of a tuple is an empty string, the corresponding unit keyword is also left unset.
The value of extname
sets the "extended name" of the table, i.e., a string that in some situations can be used to refer to the HDU itself. This may be omitted by setting extname
to nothing
(which is the default behavior).
Note that, unlike for binary tables, CFITSIO puts some limitations to the types that can be used in an ASCII table column. Refer to the CFITSIO manual for further information.
See also fits_create_binary_tbl
for a similar function which creates binary tables. In general, one should pick this function for creating tables in a new HDU, as binary tables require less space on the disk and are more efficient to read and write. (Moreover, a few datatypes are not supported in ASCII tables).
CFITSIO.fits_create_binary_tbl
— Functionfits_create_binary_tbl(f::FITSFile, numrows::Integer,
coldefs::Union{Array{NTuple{3,String}}, Array{NTuple{2,String}}},
extname::Union{String, Nothing} = nothing)
Append a new HDU containing a binary table. The meaning of the parameters is the same as in a call to fits_create_ascii_tbl
.
In general, one should pick this function for creating tables in a new HDU, as binary tables require less space on the disk and are more efficient to read and write. (Moreover, a few datatypes are not supported in ASCII tables).
CFITSIO.fits_get_coltype
— Functionfits_get_coltype(f::FITSFile, colnum::Integer)
Provided that the current HDU contains either an ASCII or binary table, return information about the column at position colnum
(counting from 1).
Return is a tuple containing
typecode
: CFITSIO integer type code of the column.repcount
: Repetition count for the column.width
: Width of an individual element.
CFITSIO.fits_get_num_cols
— Functionfits_get_num_cols(f::FITSFile)
Return the number of columns in the current HDU.
CFITSIO.fits_get_rowsize
— Functionfits_get_rowsize(f::FITSFile)
Return the size of a row in the current HDU.
CFITSIO.fits_insert_rows
— Functionfits_insert_rows(f::FITSFile, firstrow::Integer, nrows::Integer)
Insert a number of rows equal to nrows
after the row number firstrow
.
The elements in each row are initialized to their default value: you can modify them later using fits_write_col
.
Since the first row is at position 1, in order to insert rows before the first one firstrow
must be equal to zero.
CFITSIO.fits_delete_rows
— Functionfits_delete_rows(f::FITSFile, firstrow::integer, nrows::Integer)
Delete nrows
rows, starting from the one at position firstrow
. The index of the first row is 1.
CFITSIO.fits_read_col
— Functionfits_read_col(f, colnum, firstrow, firstelem, data)
Read data from one column of an ASCII/binary table and convert the data into the specified type T
.
Arguments
f::FITSFile
: the file to be read.colnum::Integer
: the column number, where the value of the first column is1
.firstrow::Integer
: the elements to be read start from this row.firstelem::Integer
: specifies which is the first element to be read, when each cell contains more than one element (i.e., the "repetition count" of the field is greater than one).data::Array
: at the end of the call, this will be filled with the elements read
from the column. The length of the array gives the overall number of elements.
CFITSIO.fits_write_col
— Functionfits_write_col(f, colnum, firstrow, firstelem, data)
Write some data in one column of a ASCII/binary table.
If there is no room for the elements, new rows will be created. (It is therefore useless to call fits_insert_rows
if you only need to append elements to the end of a table.)
f::FITSFile
: the file in which data will be written.colnum::Integer
: the column number, where the value of the first column is1
.firstrow::Integer
: the data wil be written from this row onwards.firstelem::Integer
: specifies the position in the row where the first element will be written.data::Array
: contains the elements that are to be written to the column of the table.
CFITSIO.fits_read_atblhdr
— Functionfits_read_atblhdr(f::FITSFile, maxdim::Integer = 99)
Read the header of an ASCII table HDU, where maxdim
represents the maximum number of columns to read. The function returns the length of a row in bytes, the number of rows, the number of columns, the column names as a Vector{String}
, the byte offsets to each column, the TFORMn values as a Vector{String}
, the TUNITn values as a Vector{String}
, and the EXTNAME::String
keyword, if any.
CFITSIO.fits_read_btblhdr
— Functionfits_read_btblhdr(f::FITSFile, maxdim::Integer = 99)
Read the header of a binary table HDU, where maxdim
represents the maximum number of columns to read. The function returns the number of rows, the number of columns, the column names as a Vector{String}
, the TFORMn values as a Vector{String}
, the TUNITn values as a Vector{String}
, and the EXTNAME::String
and PCOUNT::Int
keywords.