Main Content

matlab.io.fits.openDiskFile

Open FITS file

Description

example

fptr = openDiskFile(filename) opens an existing FITS file in read-only mode and returns a file pointer fptr, which is the first header data unit (HDU).. The openDiskFile function does not support the extended-file-name syntax.

This function corresponds to the fits_open_diskfile (ffdkopen) function in the CFITSIO library C API.

The openDiskFile function is similar to the openFile function, except that openDiskFile does not support the extended-file-name syntax in the input file name. Use openDiskFile in cases where the file name (or folder path) contains square or curly brace characters that would confuse the extended-file-name parser.

example

fptr = openDiskFile(filename,mode) opens an existing FITS file according to the type of access specified by mode.

Examples

Read and Write FITS Files

Open a FITS file to read image data, create a copy of the file, and then write a comment to the primary array.

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

import matlab.io.* 
fptr = fits.openDiskFile('tst0012.fits');
imagedata = fits.readImg(fptr); % read image from primary array
fits.closeFile(fptr);

Create a new file in read/write mode, copy data into the file, and then add a comment to the primary array.

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

Input Arguments

collapse all

Name of the file to read, specified as a character vector. The openDiskFile function does not support the extended file name syntax.

Example: If the filename is 'temp(1)\tst0012.fits', then openDiskFile writes the file 'tst0012.fits' to the folder temp(1).

Data Types: char

File access type, specified as a character vector containing 'readonly' or 'readwrite'.

  • 'readonly' — Open file for reading.

  • 'readwrite' — Open file for reading and writing.

Example: 'readwrite'

Data Types: char

Version History

Introduced in R2018a