Main Content

matlab.io.fits.deleteHDU

Delete current HDU in FITS file

Syntax

hduType = matlab.io.fits.deleteHDU(fptr)

Description

hduType = matlab.io.fits.deleteHDU(fptr) deletes the current HDU in a FITS file. Any subsequent HDUs are shifted forward in the file, filling the gap created by the deleted HDU. If you delete the first HDU in the file (the primary array), then the function replaces the current primary array with a null primary array containing the minimum set of required keywords and no data. If there is an HDU in the file that follows the deleted HDU, then the function redefines the current HDU to be that following HDU; if there is no such HDU, then the function redefines the current HDU to be the HDU that precedes the deleted HDU. The function returns the type of the new current HDU.

Examples

collapse all

Make a copy of a sample FITS file and examine the HDUs in the file. The file has five HDUs.

import matlab.io.*
copyfile("tst0012.fits","myfile.fits")
fitsdisp("myfile.fits",Mode="min")
HDU 1:  FLOAT_IMG IMAGE_HDU [ 109 102 ]
HDU 2:  BINARY_TBL [ 11 13 ]
HDU 3:  BYTE_IMG IMAGE_HDU [ 41 17 1 1 1 1 1 1 1 1 1 1 2 ]
HDU 4:  SHORT_IMG IMAGE_HDU [ 31 73 5 ]
HDU 5:  ASCII_TBL [ 53 8 ]

Delete the second HDU from the file. The file now has four HDUs.

fptr = fits.openFile("myfile.fits","readwrite");
fits.movAbsHDU(fptr,2);
hduType = fits.deleteHDU(fptr);
fits.closeFile(fptr)
fitsdisp("myfile.fits",Mode="min")
HDU 1:  FLOAT_IMG IMAGE_HDU [ 109 102 ]
HDU 2:  BYTE_IMG IMAGE_HDU [ 41 17 1 1 1 1 1 1 1 1 1 1 2 ]
HDU 3:  SHORT_IMG IMAGE_HDU [ 31 73 5 ]
HDU 4:  ASCII_TBL [ 53 8 ]

Delete the new file myfile.fits.

delete myfile.fits

Tips

  • This function corresponds to the fits_delete_hdu (ffdhdu) 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