Main Content

matlab.io.fits.openFile

Open FITS file

Syntax

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

Description

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 file name 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 file name syntax in the input file name. 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'.

Examples

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

import matlab.io.*
fptr = fits.openFile('tst0012.fits');
imagedata = fits.readImg(fptr);
fits.closeFile(fptr);

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

import matlab.io.*
srcFile = fullfile(matlabroot,'toolbox','matlab','demos','tst0012.fits');
copyfile(srcFile,'myfile.fits'); 
fileattrib('myfile.fits','+w'); 
fptr = fits.openFile('myfile.fits','readwrite');
fits.writeComment(fptr,'This is just a comment.');
fits.closeFile(fptr);