Contenido principal

matlab.io.fits.writeKey

Add or update keyword in current HDU

Syntax

matlab.io.fits.writeKey(fptr,keyname,value)
matlab.io.fits.writeKey(fptr,keyname,value,comment)
matlab.io.fits.writeKey(fptr,keyname,value,comment,decimals)

Description

matlab.io.fits.writeKey(fptr,keyname,value) adds a new keyword and key value to the current HDU, or updates the key value if the keyword already exists.

matlab.io.fits.writeKey(fptr,keyname,value,comment) adds or updates the keyword with a comment.

matlab.io.fits.writeKey(fptr,keyname,value,comment,decimals) adds a new floating-point keyword in the current HDU, or updates the key value if the keyword already exists.

If value is longer than 68 characters, then the LONGWARN convention is automatically employed.

Examples

collapse all

Create a new FITS file and add an image to it.

import matlab.io.*
fptr = fits.createFile("myfile.fits");
fits.createImg(fptr,"byte_img",[100 200])

Write several keywords, including some with complex values, to the current HDU. Then close the file.

fits.writeKey(fptr,"mykey1","A character value","With a comment")
fits.writeKey(fptr,"mykey2",int32(1))
fits.writeKey(fptr,"mykey3",(5+7i)/8,"Complex value, implicitly rounded")
fits.writeKey(fptr,"mykey4",(5+7i)/8,"Complex value, explicitly rounded to three decimal places",3)
fits.writeKey(fptr,"mykey5",4/3,"Use two decimal places",2)
fits.closeFile(fptr)

Examine the file metadata and then delete the file.

fitsdisp("myfile.fits",Mode="full")
HDU:  1 (Primary HDU)
	SIMPLE  =                    T / file does conform to FITS standard
	BITPIX  =                    8 / number of bits per data pixel
	NAXIS   =                    2 / number of data axes
	NAXIS1  =                  200 / length of data axis 1
	NAXIS2  =                  100 / length of data axis 2
	EXTEND  =                    T / FITS dataset may contain extensions
	COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
	COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H
	MYKEY1  = 'A character value'  / With a comment
	MYKEY2  =                    1
	MYKEY3  =       (6E-01, 9E-01) / Complex value, implicitly rounded
	MYKEY4  = (6.250E-01, 8.750E-01) / Complex value, explicitly rounded to three de
	MYKEY5  =             1.33E+00 / Use two decimal places
delete myfile.fits

Tips

  • This function corresponds to the fits_write_key (ffpky) and fits_update_key (ffuky) family of functions 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