Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/hdu/bintable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ struct BinaryField <: AbstractField
lmax::Union{AbstractFloat, Nothing}
end

function _parse_tdim(value)
dim_string = strip(String(value))
isempty(dim_string) && return nothing

dims = eval(Meta.parse(dim_string))
dims isa Integer ? (dims,) : dims
end

function Base.read(io::IO, ::Type{Bintable}, format::DataFormat,
fields::Vector{BinaryField}; record::Bool = false, kwds...)

Expand Down Expand Up @@ -187,7 +195,7 @@ function FieldFormat(::Type{Bintable}, mankeys::DataFormat, reskeys::Dict{S, V},
supp = form[:a]
unit_ = get(reskeys, "TUNIT$j", "")
disp = get(reskeys, "TDISP$j", "")
dims = eval(Meta.parse(get(reskeys, "TDIM$j", "")))
dims = _parse_tdim(get(reskeys, "TDIM$j", ""))
zero_ = least_float_type(get(reskeys, "TZERO$j",
type <: Union{Bool, BitVector, String} ? nothing : 0.0f0))
scale = least_float_type(get(reskeys, "TSCAL$j",
Expand Down Expand Up @@ -234,7 +242,7 @@ function FieldFormat(::Type{Bintable}, mankey::DataFormat, reskeys::Dict{S, V},
# get(reskeys, "TUNIT$j", "")
unit_ = get(reskeys, "TUNIT$j", "")
disp = get(reskeys, "TDISP$j", "")
dims = eval(Meta.parse(get(reskeys, "TDIM$j", "")))
dims = _parse_tdim(get(reskeys, "TDIM$j", ""))
zero_ = least_float_type(get(reskeys, "TZERO$j",
type <: Union{Bool, BitVector, String} ? nothing : 0.0f0))
scale = least_float_type(get(reskeys, "TSCAL$j",
Expand Down Expand Up @@ -283,7 +291,7 @@ function FieldFormat(::Type{Bintable}, mankey::DataFormat, reskeys::Dict{S, V},
# get(reskeys, "TUNIT$j", "")
unit_ = get(reskeys, "TUNIT$j", "")
disp = get(reskeys, "TDISP$j", "")
dims = eval(Meta.parse(get(reskeys, "TDIM$j", "")))
dims = _parse_tdim(get(reskeys, "TDIM$j", ""))
zero_ = least_float_type(get(reskeys, "TZERO$j",
type <: Union{Bool, BitVector, String} ? nothing : 0.0f0))
scale = least_float_type(get(reskeys, "TSCAL$j",
Expand Down
29 changes: 29 additions & 0 deletions test/bintable_hdu_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,35 @@
@test (length(hdu.data[1]) == 5 && length(hdu.data) == 3 &&
all([hdu.data[j][:par4] for j=1:3] .== [1.0, 2.0, 3.0]))

# test one-dimensional TDIM values
cards = [Card("XTENSION", "BINTABLE"),
Card("BITPIX", 8),
Card("NAXIS", 2),
Card("NAXIS1", 24),
Card("NAXIS2", 2),
Card("PCOUNT", 0),
Card("GCOUNT", 1),
Card("TFIELDS", 1),
Card("TFORM1", "3D"),
Card("TTYPE1", "values"),
Card("TDIM1", "(3)")]
hdu = HDU(Bintable, missing, cards; record=true)

@test length(hdu.data) == 2
@test hdu.data[1].values == zeros(3)

cards = Card[Card("TDIM1", "(3)")]
records = [(values=[1.0, 2.0, 3.0],),
(values=[4.0, 5.0, 6.0],)]
hdu = HDU(Bintable, records, cards)

@test hdu.data == records

columns = (values=[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],)
hdu = HDU(Bintable, columns, cards)

@test hdu.data == columns

rm(temppath)

end
Loading