Main Content

Open FITS file (extended-filename syntax)


fptr = openFile(filename)
fptr = openFile(filename,mode)


fptr = openFile(filename) opens an existing FITS file in read-only mode and returns a file pointer, fptr, which references the primary array (first header data unit, or "HDU"). The openFile function supports the extended-filename syntax. Specify filename as a character vector or string scalar.

This function corresponds to the fits_open_file (ffopen) function in the CFITSIO library C API.

The openFile function is similar to the function openDiskFile. In addition to opening FITS files, the openFile function supports the extended-filename syntax in the input filename. If the filename (or folder path) contains square or curly brace characters that would confuse the extended-filename parser, then use openDiskFile.

fptr = openFile(filename,mode) opens an existing FITS file according to the mode, which describes the type of access. mode may be either 'readonly' or 'readwrite'.


collapse all

Open a file in read-only mode and read image data from the primary array.

fptr = fits.openFile('tst0012.fits');
imagedata = fits.readImg(fptr);

Open a file in read/write mode and add a comment to the primary array.

srcFile = fullfile(matlabroot,'toolbox','matlab','demos','tst0012.fits');
fptr = fits.openFile('myfile.fits','readwrite');
fits.writeComment(fptr,'This is just a comment.');