Skip to content

Commit

Permalink
Merge a173679 into 06df61a
Browse files Browse the repository at this point in the history
  • Loading branch information
emmt committed Oct 15, 2019
2 parents 06df61a + a173679 commit 892c6e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/FITSIO.jl
Expand Up @@ -23,6 +23,7 @@ import Base: getindex,
close,
ndims,
size,
getkey,
haskey,
keys,
values
Expand Down
3 changes: 3 additions & 0 deletions src/header.jl
Expand Up @@ -354,6 +354,9 @@ Array of values (not a copy).
"""
values(hdr::FITSHeader) = hdr.values

getkey(hdr::FITSHeader, key::String, def) =
(haskey(hdr, key) ? getindex(hdr, key) : def)

getindex(hdr::FITSHeader, key::String) = hdr.values[hdr.map[key]]
getindex(hdr::FITSHeader, i::Integer) = hdr.values[i]

Expand Down
15 changes: 10 additions & 5 deletions test/runtests.jl
Expand Up @@ -82,7 +82,7 @@ using Random # for `randstring`

# Read the entire array using read to compare with read!
a = read(f[1])

# Read the entire array
b = zeros(eltype(indata),size(indata))
read!(f[1],b)
Expand All @@ -94,16 +94,16 @@ using Random # for `randstring`
b = zeros(eltype(indata),2,2)
read!(f[1],b,1:2,1:2)
@test a[1:2,1:2] == b

# Read an entire 1D slice
b = zeros(eltype(indata),size(indata,1))
read!(f[1],b,:,1)
@test a[:,1] == b

b = zeros(eltype(indata),size(indata,2))
read!(f[1],b,1,:)
@test a[1,:] == b

# Read a part of a 1D slice
b = zeros(eltype(indata),1)
read!(f[1],b,1:1,1)
Expand Down Expand Up @@ -147,7 +147,7 @@ using Random # for `randstring`
@test a[:,ax2] == b[:,ax2]
end

# Non-contiguous views can not be read into
# Non-contiguous views can not be read into
b_view = view(b,1,:)
@test_throws MethodError read!(f[1],b_view,1,:)
end
Expand Down Expand Up @@ -313,6 +313,11 @@ HISTORY this is a history"""
inhdr[1] = 2.0 # test settting by index
set_comment!(inhdr, "INTKEY", "integer keyword") # test setting a comment

# Test reading possibly missing keyword
@test_throws KeyError inhdr["BADKEY"]
@test getkey(inhdr, "BADKEY", nothing) === nothing
@test getkey(inhdr, "INTKEY", nothing) == inhdr["INTKEY"]

indata = reshape(Float32[1:100;], 5, 20)
write(f, indata; header=inhdr)

Expand Down

0 comments on commit 892c6e5

Please sign in to comment.