Main Content

matlab.io.fits.insertATbl

Insert ASCII table after current HDU

Syntax

matlab.io.fits.insertATbl(fptr,rowlen,nrows,ttype,tbcol,tform,tunit,extname)

Description

matlab.io.fits.insertATbl(fptr,rowlen,nrows,ttype,tbcol,tform,tunit,extname) inserts a new ASCII table extension immediately following the current HDU. Any subsequent extensions are shifted down to make room for the new extension. If the FITS file is currently empty, then this function creates an empty primary array before appending the table extension to the file. The new extension becomes the current HDU. If you specify rowlen as 0, then the function calculates the default value for rowlen based on the values of the tbcol and ttype arguments.

Specify tform as a string array or cell array of character vectors in one of these forms.

tform Array ElementCorresponding FITS Data Type
"Iw"int16 column with width w
"Aw"ASCII column with width w
"Fww.dd"Fixed point with width ww and precision dd
"Eww.dd"Single precision with width ww and precision dd
"Dww.dd"Double precision with width ww and precision dd

Note

Binary tables are recommended over ASCII tables. To insert a binary table, use the matlab.io.fits.insertBTbl function.

Examples

collapse all

Create a new FITS file and add two images to it.

import matlab.io.*
fptr = fits.createFile("myfile.fits");
fits.createImg(fptr,"uint8",[20 30])
fits.createImg(fptr,"int16",[30 40])

Move the current HDU header back by one so that the fits.insertATbl function can insert a new table between the two images.

fits.movRelHDU(fptr,-1);

Create the table and write it to the FITS file. Then close the file.

ttype = ["Name","Short","Fix","Double"];
tbcol = [1 17 28 43];
tform = ["A15","I10","F14.2","D12.4"];
tunit = ["","m**2","cm","km/s"];
fits.insertATbl(fptr,0,0,ttype,tbcol,tform,tunit,"my-table")
fits.writeCol(fptr,1,1,['abracadabra','alacazam'])
fits.writeCol(fptr,2,1,int16([0; 1]))
fits.writeCol(fptr,3,1,[12.4; 4/3])
fits.writeCol(fptr,4,1,[12.4; 4e8/3])
fits.closeFile(fptr)

Examine the file metadata and then delete the file.

fitsdisp("myfile.fits",Mode="min")
HDU 1:  BYTE_IMG IMAGE_HDU [ 20 30 ]
HDU 2:  ASCII_TBL [ 2 4 ]
HDU 3:  SHORT_IMG IMAGE_HDU [ 30 40 ]
delete myfile.fits

Tips

  • This function corresponds to the fits_insert_atbl (ffitab) function in the CFITSIO library C API.

  • To use this function, you must be familiar with the CFITSIO C interface. You can access the CFITSIO documentation at the CFITSIO website.

Extended Capabilities

expand all

Version History

expand all