JuliaAstro / FITSIO.jl

Flexible Image Transport System (FITS) file support for Julia
http://juliaastro.org/FITSIO.jl/
MIT License
55 stars 29 forks source link

writemode with fits_open_file #107

Closed gulabdewangan closed 5 years ago

gulabdewangan commented 5 years ago

It seems writemode is not supported with fits_open_file. I get an error message when closing a fits file after writing a column to an existing file as follows.

julia> f=fits_open_file("test.fits")   
FITSFile(Ptr{Nothing} @0x0000000001885840)
julia> fits_write_col(f,24,1,1,dat)   
julia> fits_close_file(f)
ERROR: cannot write to readonly file

The function fits_open_file does not accept 0 or 1 for read/write mode as in cfitsio.

giordano commented 5 years ago

Actually it does accept a mode optional argument, but it isn't documented. This should do the trick:

fits_open_file("test.fits", 1)

Besides documenting the behavior, do we want to improve the user interface? The values 0 and 1 aren't really self-explanatory.

kbarbary commented 5 years ago

I suspect you're using the Libcfitsio interface instead of the higher-level interface because you want to write a single column to an existing table.

The high-level interface could use a method that writes a column to an existing table extension, such as

write(hdu::TableHDU, colname::String, [range,] data)

Then we could just use the main FITSIO interface for this, which already has easier-to-use names and keyword arguments, like f = FITS("test.fits", mode="r+") for read-write mode.

gulabdewangan commented 5 years ago

Actually it does accept a mode optional argument, but it isn't documented. This should do the trick:

fits_open_file("test.fits", 1)

Besides documenting the behavior, do we want to improve the user interface? The values 0 and 1 aren't really self-explanatory.

Thanks, I can write using the optional argument. I guess, just documenting the behavior is good enough as Libcfitsio functions should have the same parameters as the corresponding cfitsio functions.

gulabdewangan commented 5 years ago

As suggested by kbarbary, I am not able to write using the high-level interface.

julia> write(f[2], "test",ccdtemp2) ERROR: MethodError: no method matching write(::TableHDU, ::String, ::Array{Float32,1})

ccdtemp2 is a vector with length exactly the same as the number of rows in the table. Am I missing something?

kbarbary commented 5 years ago

No, you're not missing anything. I was suggesting that we add that method to FITSIO, as it doesn't currently exist.