matlab.io.fits.openFile
打开 FITS 文件
语法
fptr = openFile(filename)
fptr = openFile(filename,mode)
说明
fptr = openFile(filename)
以只读模式打开现有 FITS 文件,并返回一个引用主数组(第一个标头数据单元 (HDU))的文件指针 fptr
。openFile
函数支持扩展的文件名语法。以字符向量或字符串标量形式指定 filename
。
此函数对应于 CFITSIO 库 C API 中的 fits_open_file (ffopen)
函数。
openFile
函数与 openDiskFile
函数类似。除了打开 FITS 文件外,openFile
函数还支持在输入文件名中使用扩展的文件名语法。如果文件名(或文件夹路径)包含会让扩展的文件名解析器混淆的方括号或花括号字符,请使用 openDiskFile
。
fptr = openFile(filename,mode)
根据描述访问类型的 mode
打开现有 FITS 文件。mode
可以是 'readonly'
或 'readwrite'
。
示例
以只读模式打开文件,并从主数组中读取图像数据。
import matlab.io.* fptr = fits.openFile('tst0012.fits'); imagedata = fits.readImg(fptr); fits.closeFile(fptr);
以读/写模式打开文件,并向主数组中添加注释。
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);