Main Content

matlab.io.fits.openFile

Open FITS file (extended-filename syntax)

Syntax

fptr = matlab.io.fits.openFile(filename)
fptr = matlab.io.fits.openFile(filename,fmode)

Description

fptr = matlab.io.fits.openFile(filename) opens an existing FITS file in read-only mode and returns a file pointer to the first header data unit (HDU).

The openFile function is similar to the matlab.io.fits.openDiskFile function. In addition to opening FITS files, the openFile function supports the extended-filename syntax in the input filename. Use the matlab.io.fits.openDiskFile function in cases where the filename (or folder path) contains square-bracket or curly-brace characters that the extended-filename parser cannot interpret.

fptr = matlab.io.fits.openFile(filename,fmode) opens an existing FITS file according to the type of access specified by fmode. Specify fmode as either "readonly" or "readwrite".

Examples

collapse all

Make a copy of a sample FITS file. Open the new file in read-write mode and add a comment to its primary array. Then close the file.

import matlab.io.*
copyfile("tst0012.fits","myfile.fits")
fptr = fits.openFile("myfile.fits","readwrite");
fits.writeComment(fptr,"Test comment.")
fits.closeFile(fptr)

Examine the file metadata for the two files. Then delete the new file.

fitsdisp("tst0012.fits",Index=1)
HDU:  1 (Primary HDU)
	SIMPLE  =                    T / Standard FITS file
	BITPIX  =                  -32 / No. of bits per pixel
	NAXIS   =                    2 / No. of axes in matrix
	NAXIS1  =                  102 / No. of pixels in X
	NAXIS2  =                  109 / No. of pixels in Y
	EXTEND  =                    T / There may be FITS extensions
	CDELT1  =                  3.1 / Coordinate increment
	CRVAL1  =               1299.1 / Coordinate of reference pixel
	CRPIX1  =                 12.3 / Reference pixel in X
	CDELT2  =                -0.17 / Coordinate increment
	CRVAL2  =               -102.4 / Coordinate of reference pixel
	CRPIX2  =              -2031.8 / Reference pixel in Y
	OBJECT  = 'Wave 32-bit FP'     / Name of image
	ORIGIN  = 'ESO     '           / File was prepared at ESO-Garching
	DATE    = '20/08/92'           / Creation data of this file
	COMMENT  This test file was created by P.Grosbol, ESO (pgrosbol@eso.org)
	COMMENT  Simple 32-bit FP sine wave pattern for testing of FITS readers
fitsdisp("myfile.fits",Index=1)
HDU:  1 (Primary HDU)
	SIMPLE  =                    T / Standard FITS file
	BITPIX  =                  -32 / No. of bits per pixel
	NAXIS   =                    2 / No. of axes in matrix
	NAXIS1  =                  102 / No. of pixels in X
	NAXIS2  =                  109 / No. of pixels in Y
	EXTEND  =                    T / There may be FITS extensions
	CDELT1  =                  3.1 / Coordinate increment
	CRVAL1  =               1299.1 / Coordinate of reference pixel
	CRPIX1  =                 12.3 / Reference pixel in X
	CDELT2  =                -0.17 / Coordinate increment
	CRVAL2  =               -102.4 / Coordinate of reference pixel
	CRPIX2  =              -2031.8 / Reference pixel in Y
	OBJECT  = 'Wave 32-bit FP'     / Name of image
	ORIGIN  = 'ESO     '           / File was prepared at ESO-Garching
	DATE    = '20/08/92'           / Creation data of this file
	COMMENT  This test file was created by P.Grosbol, ESO (pgrosbol@eso.org)
	COMMENT  Simple 32-bit FP sine wave pattern for testing of FITS readers
	COMMENT Test comment.
delete myfile.fits

Input Arguments

collapse all

Name of the file to open, specified as a string scalar or character vector.

The openFile function supports the extended-filename syntax. For example, if you specify filename as "tst0012.fits[3]", then the openFile function opens the file tst0012.fits and sets the current HDU number to 4.

File access type, specified as one of these values:

  • "readonly" — Open file for reading.

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

Data Types: string | char

Tips

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