File access
CFITSIO.fits_assert_open
— Functionfits_assert_open(f::FITSFile)
Assert that the FITS file f
is open, otherwise throw an error.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_assert_open(f)
julia> fits_create_empty_img(f)
julia> close(f)
julia> fits_assert_open(f)
ERROR: ArgumentError: attempt to access a FITS file that has been closed previously
[...]
CFITSIO.fits_create_file
— Functionfits_create_file(filename::AbstractString)
Create and open a new empty output FITSFile
. This methods uses the extended file name syntax to create the file.
This function does not overwrite an existing file with the same name, and will throw an exception if this is the case. See fits_clobber_file
to delete existing files before creating one.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_file_mode(f) # opened in read-write mode
1
julia> fits_create_empty_img(f)
julia> close(f)
See also fits_create_diskfile
which does not use the extended filename parser.
CFITSIO.fits_create_diskfile
— Functionfits_create_diskfile(filename::AbstractString)
Create and open a new empty output FITSFile
. Unlike fits_create_file
, this function does not use an extended filename parser and treats the string as is as the filename.
This function does not overwrite an existing file with the same name, and will throw an exception if this is the case.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_diskfile(fname);
julia> fits_file_mode(f) # opened in read-write mode
1
julia> fits_create_empty_img(f)
julia> close(f)
CFITSIO.fits_clobber_file
— Functionfits_clobber_file(filename::AbstractString)
Like fits_create_file
, but overwrites filename
if it exists.
CFITSIO.fits_close_file
— Functionfits_close_file(f::FITSFile)
Close a previously opened FITS file. This is equivalent to calling close(f)
on the FITSFile
object.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_create_empty_img(f)
julia> fits_close_file(f)
julia> fits_assert_open(f)
ERROR: ArgumentError: attempt to access a FITS file that has been closed previously
[...]
CFITSIO.fits_delete_file
— Functionfits_delete_file(f::FITSFile)
Close an opened FITS file (like fits_close_file
) and removes it from the disk.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_create_empty_img(f)
julia> fits_delete_file(f)
julia> isfile(fname)
false
julia> fits_assert_open(f)
ERROR: ArgumentError: attempt to access a FITS file that has been closed previously
[...]
CFITSIO.fits_file_name
— Functionfits_file_name(f::FITSFile)::String
Return the name of the file associated with object f
.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_file_name(f) |> basename
"test.fits"
julia> fits_file_name(f) == fname
true
julia> fits_create_empty_img(f)
julia> close(f)
CFITSIO.fits_file_mode
— Functionfits_file_mode(f::FITSFile)
Return the I/O mode of the FITS file, where 0 indicates a read-only mode and 1 indicates a read-write mode.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_file_mode(f)
1
julia> fits_create_empty_img(f)
julia> close(f)
julia> f = fits_open_file(fname, CFITSIO.READONLY);
julia> fits_file_mode(f)
0
julia> close(f)
CFITSIO.fits_flush_buffer
— Functionfits_flush_buffer(f::FITSFile)
Flush the buffer to disk without updating and closing the current HDU. This is faster than fits_flush_file
, and may be used to write the state of the file to disk after each row of a table is written.
CFITSIO.fits_flush_file
— Functionfits_flush_file(f::FITSFile)
Flush the file to disk. This is equivalent to closing the file and reopening it.
In most cases, this function should not be needed, as the library automatically flushes the file when it is closed.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_create_binary_tbl(f, 0, [("col1", "1J", "units")])
julia> fits_write_col(f, 1, 1, 1, [1, 2, 3])
julia> CFITSIO.fits_flush_file(f) # flush the file to disk
julia> fits_read_col(f, 1, 1, 1, zeros(Int32, 3))
3-element Vector{Int32}:
1
2
3
julia> close(f)
CFITSIO.fits_open_file
— Functionfits_open_file(filename::String, [mode = 0])
Open an existing data file.
Modes:
- 0 : Read only (equivalently denoted by
CFITSIO.READONLY
orCFITSIO.R
) - 1 : Read-write (equivalently denoted by
CFITSIO.READWRITE
orCFITSIO.RW
)
This function uses the extended filename syntax to open the file. See also fits_open_diskfile
that does not use the extended filename parser and uses filename
as is as the name of the file.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_create_empty_img(f)
julia> close(f)
julia> f = fits_open_file(fname, CFITSIO.READONLY);
julia> fits_file_mode(f) # opened in read-only mode
0
julia> fits_movabs_hdu(f, 1) # move to primary HDU
:image_hdu
julia> fits_get_img_dim(f) # get image dimensions
0
julia> close(f)
CFITSIO.fits_open_diskfile
— Functionfits_open_diskfile(filename::String, [mode = 0])
Open an existing data file.
Modes:
- 0 : Read only (equivalently denoted by
CFITSIO.READONLY
orCFITSIO.R
) - 1 : Read-write (equivalently denoted by
CFITSIO.READWRITE
orCFITSIO.RW
)
This function does not use the extended filename parser, and uses filename
as is as the name of the file that is to be opened. See also fits_open_file
which uses the extended filename syntax.
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_diskfile(fname);
julia> fits_create_empty_img(f)
julia> close(f)
julia> f = fits_open_diskfile(fname, CFITSIO.READONLY);
julia> fits_file_mode(f) # opened in read-only mode
0
julia> fits_movabs_hdu(f, 1) # move to primary HDU
:image_hdu
julia> fits_get_img_dim(f) # get image dimensions
0
julia> close(f)
CFITSIO.fits_open_table
— Functionfits_open_table(filename::String, [mode = 0])
Open an existing data file (like fits_open_file
) and move to the first HDU containing either an ASCII or a binary table.
Modes:
- 0 : Read only (equivalently denoted by
CFITSIO.READONLY
orCFITSIO.R
) - 1 : Read-write (equivalently denoted by
CFITSIO.READWRITE
orCFITSIO.RW
)
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_create_binary_tbl(f, 0, [("col1", "1J"), ("col2", "1D")])
julia> close(f)
julia> f = fits_open_table(fname, CFITSIO.READONLY);
julia> fits_get_hdu_num(f)
2
julia> fits_get_num_rows(f)
0
julia> fits_get_num_cols(f)
2
julia> close(f)
CFITSIO.fits_open_image
— Functionfits_open_image(filename::String, [mode = 0])
Open an existing data file (like fits_open_file
) and move to the first HDU containing an image.
Modes:
- 0 : Read only (equivalently denoted by
CFITSIO.READONLY
orCFITSIO.R
) - 1 : Read-write (equivalently denoted by
CFITSIO.READWRITE
orCFITSIO.RW
)
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> fits_create_binary_tbl(f, 0, [("col1", "1J"), ("col2", "1D")])
julia> A = [1 2; 3 4];
julia> fits_create_img(f, A)
julia> fits_write_pix(f, A)
julia> close(f)
julia> f = fits_open_image(fname, CFITSIO.READONLY); # moves to the last HDU
julia> fits_get_hdu_num(f)
3
julia> B = similar(A);
julia> fits_read_pix(f, B);
julia> B == A
true
julia> close(f)
CFITSIO.fits_open_data
— Functionfits_open_data(filename::String, [mode = 0])
Open an existing data file (like fits_open_file
) and move to the first HDU containing either an image or a table.
Modes:
- 0 : Read only (equivalently denoted by
CFITSIO.READONLY
orCFITSIO.R
) - 1 : Read-write (equivalently denoted by
CFITSIO.READWRITE
orCFITSIO.RW
)
Example
julia> fname = joinpath(mktempdir(), "test.fits");
julia> f = fits_create_file(fname);
julia> A = [1 2; 3 4];
julia> fits_create_img(f, A)
julia> fits_write_pix(f, A)
julia> close(f)
julia> f = fits_open_data(fname, CFITSIO.READONLY);
julia> B = similar(A);
julia> fits_read_pix(f, B);
julia> B == A
true
julia> close(f)