File access

CFITSIO.fits_assert_openFunction
fits_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
[...]
source
CFITSIO.fits_create_fileFunction
fits_create_file(filename::AbstractString)

Create and open a new empty output FITSFile. This methods uses the extended file name syntax to create the file.

Note

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.

source
CFITSIO.fits_create_diskfileFunction
fits_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.

Note

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)
source
CFITSIO.fits_close_fileFunction
fits_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
[...]
source
CFITSIO.fits_delete_fileFunction
fits_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
[...]
source
CFITSIO.fits_file_nameFunction
fits_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)
source
CFITSIO.fits_file_modeFunction
fits_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)
source
CFITSIO.fits_flush_bufferFunction
fits_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.

Note

In most cases, this function should not be needed, as the library automatically flushes the file when it is closed.

source
CFITSIO.fits_flush_fileFunction
fits_flush_file(f::FITSFile)

Flush the file to disk. This is equivalent to closing the file and reopening it.

Note

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)
source
CFITSIO.fits_open_fileFunction
fits_open_file(filename::String, [mode = 0])

Open an existing data file.

Modes:

  • 0 : Read only (equivalently denoted by CFITSIO.READONLY or CFITSIO.R)
  • 1 : Read-write (equivalently denoted by CFITSIO.READWRITE or CFITSIO.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)
source
CFITSIO.fits_open_diskfileFunction
fits_open_diskfile(filename::String, [mode = 0])

Open an existing data file.

Modes:

  • 0 : Read only (equivalently denoted by CFITSIO.READONLY or CFITSIO.R)
  • 1 : Read-write (equivalently denoted by CFITSIO.READWRITE or CFITSIO.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)
source
CFITSIO.fits_open_tableFunction
fits_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 or CFITSIO.R)
  • 1 : Read-write (equivalently denoted by CFITSIO.READWRITE or CFITSIO.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)
source
CFITSIO.fits_open_imageFunction
fits_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 or CFITSIO.R)
  • 1 : Read-write (equivalently denoted by CFITSIO.READWRITE or CFITSIO.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)
source
CFITSIO.fits_open_dataFunction
fits_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 or CFITSIO.R)
  • 1 : Read-write (equivalently denoted by CFITSIO.READWRITE or CFITSIO.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)
source