Contenu principal

matlab.io.fits.openDiskFile

Open FITS file

Description

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

The openDiskFile function is similar to the matlab.io.fits.openFile function, except that the openDiskFile function does not support the extended-filename syntax in the input filename. Use the openDiskFile function in cases where the filename (or folder path) contains square-bracket or curly-brace characters that the extended-filename parser cannot interpret.

example

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

example

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.openDiskFile("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 openDiskFile function does not support the extended-filename syntax. For example, if you specify filename as "temp(1)\tst0012.fits", then the openDiskFile function opens the file tst0012.fits from the folder temp(1).

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_diskfile (ffdkopen) 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

Introduced in R2018a

expand all