Skip to content

Commit

Permalink
Merge 820b6f1 into 3d4a8b4
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Apr 27, 2018
2 parents 3d4a8b4 + 820b6f1 commit f1f97bf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
@@ -1,3 +1,10 @@
v0.12.0 (2018-??-??)
====================

- Column names in FITS files are now case sensitive by default. Functions
`read(hdu, colname)` and `Libcfitsio.fits_get_colnum` have a new optional
keyword, `case_sensitive`, which is `true` by default.

v0.11.0 (2017-09-28)
====================

Expand Down
4 changes: 2 additions & 2 deletions src/libcfitsio.jl
Expand Up @@ -929,15 +929,15 @@ for (a,b,T) in ((:fits_get_num_cols, "ffgncl", :Cint),
end
end

function fits_get_colnum(f::FITSFile, tmplt::String)
function fits_get_colnum(f::FITSFile, tmplt::String; case_sensitive::Bool=true)
result = Ref{Cint}(0)
status = Ref{Cint}(0)

# Second argument is case-sensitivity of search: 0 = case-insensitive
# 1 = case-sensitive
ccall(("ffgcno", libcfitsio), Cint,
(Ptr{Void}, Cint, Ptr{UInt8}, Ref{Cint}, Ref{Cint}),
f.ptr, 0, tmplt, result, status)
f.ptr, Int(case_sensitive), tmplt, result, status)
fits_assert_ok(status[])
return result[]
end
Expand Down
14 changes: 8 additions & 6 deletions src/table.jl
Expand Up @@ -447,12 +447,12 @@ function fits_read_var_col(f::FITSFile, colnum::Integer, data::Vector{String})
end

# Read a table column
function read(hdu::ASCIITableHDU, colname::String)
function read(hdu::ASCIITableHDU, colname::String, case_sensitive::Bool=true)
fits_assert_open(hdu.fitsfile)
fits_movabs_hdu(hdu.fitsfile, hdu.ext)

nrows = fits_get_num_rows(hdu.fitsfile)
colnum = fits_get_colnum(hdu.fitsfile, colname)
colnum = fits_get_colnum(hdu.fitsfile, colname, case_sensitive=case_sensitive)

typecode, repcnt, width = fits_get_eqcoltype(hdu.fitsfile, colnum)
T = CFITSIO_COLTYPE[typecode]
Expand All @@ -465,7 +465,7 @@ end


"""
read(hdu, colname)
read(hdu, colname; case_sensitive=true)
Read a column as an array from the given table HDU.
Expand All @@ -474,14 +474,16 @@ The column name may contain wild card characters (`*`, `?`, or
characters (including zero characters) and the `?` character
matches any single character. The `#` wildcard will match any
consecutive string of decimal digits (0-9). The string must match a
unique column.
unique column. The optional boolean keyword `case_sensitive`,
`true` by default, specifies whether the column name is to be
considered case sensitive.
"""
function read(hdu::TableHDU, colname::String)
function read(hdu::TableHDU, colname::String; case_sensitive::Bool=true)
fits_assert_open(hdu.fitsfile)
fits_movabs_hdu(hdu.fitsfile, hdu.ext)

nrows = fits_get_num_rows(hdu.fitsfile)
colnum = fits_get_colnum(hdu.fitsfile, colname)
colnum = fits_get_colnum(hdu.fitsfile, colname, case_sensitive=case_sensitive)

T, rowsize, isvariable = fits_get_col_info(hdu.fitsfile, colnum)

Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Expand Up @@ -87,11 +87,11 @@ end
indata["col$i"] = reshape([1:40;], (2, 20)) # vector Int64 column
i += 1
indata["col$i"] = [randstring(5) for j=1:2, k=1:20] # vector ASCIIString col
indata["vcol1"] = [randstring(j) for j=1:20] # variable length column
indata["vcol2"] = [collect(1.:j) for j=1.:20.] # variable length
indata["vcol"] = [randstring(j) for j=1:20] # variable length column
indata["VCOL"] = [collect(1.:j) for j=1.:20.] # variable length

# test writing
write(f, indata; varcols=["vcol1", "vcol2"])
write(f, indata; varcols=["vcol", "VCOL"])

# test reading
colnames = FITSIO.colnames(f[2])
Expand Down

0 comments on commit f1f97bf

Please sign in to comment.