Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompatHelper: add new compat entry for "Blosc" at version "0.5" #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ version = "0.12.5"
[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Blosc = "a74b3585-a348-5f62-a45c-50e91977d574"
CMakeWrapper = "d5fb7624-851a-54ee-a528-d3f3bac0b4a0"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
CMakeWrapper = "d5fb7624-851a-54ee-a528-d3f3bac0b4a0"

[compat]
Blosc = "0.5"
julia = "0.7, 1"

[extras]
Expand Down
29 changes: 28 additions & 1 deletion src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export
d_create, d_create_external, d_open, d_read, d_write,
dataspace, datatype, exists, file, filename,
g_create, g_open, get_chunk, get_create_properties, get_datasets,
h5open, h5read, h5rewrite, h5writeattr, h5readattr, h5write,
h5open, h5read, h5read_compound, h5rewrite, h5writeattr, h5readattr, h5write,
has, iscontiguous, ishdf5, ismmappable, name,
o_copy, o_delete, o_open, p_create,
readmmap, @read, @write, root, set_dims!, t_create, t_commit
Expand Down Expand Up @@ -733,6 +733,33 @@ function h5read(filename, name::String, indices::Tuple{Vararg{Union{AbstractRang
dat
end

"""
function h5read_compound(dset::HDF5.HDF5Dataset, T::DataType)

Reads a dataset directly using the given datatype and returns a `Vector{T}`.
The implementation is based on @damiendr's post in HDF5.jl Issue#408.
"""
function h5read_compound(dset::HDF5Dataset, T::DataType)
filetype = datatype(dset) # packed layout on disk
memtype_id = h5t_get_native_type(filetype.id) # padded layout in memory
@assert sizeof(T) == h5t_get_size(memtype_id) "Type sizes mismatch!"
out = Vector{T}(undef, length(dset))
h5d_read(dset.id, memtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, out)
h5t_close(memtype_id)
out
end

function h5read_compound(h5f::HDF5File, h5loc::AbstractString, T::DataType)
h5read_compound(h5f[h5loc], T)
end

function h5read_compound(filename::AbstractString, h5loc::AbstractString, T::DataType)
h5f = h5open(filename, "r")
out = h5read_compound(h5f[h5loc], T)
close(h5f)
out
end

function h5writeattr(filename, name::String, data::Dict)
fid = h5open(filename, "r+")
try
Expand Down
27 changes: 27 additions & 0 deletions test/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ using HDF5
using CRC32c
using Test

# Structures for the compound.h5 file
struct Vec3
a::Float64
b::Float64
c::Float64
end
struct Data
wgt::Float64
xyz::Vec3
uvw::Vec3
E::Float64
end


@testset "plain" begin

# Create a new file
Expand Down Expand Up @@ -390,6 +404,19 @@ if !isempty(HDF5.libhdf5_hl)
rm(fn)
end

# Test h5read_compound
function test_data(data)
@test 2 == length(data)
@test -2.45590412 ≈ data[1].xyz.a
end
fn = joinpath(test_files, "compound.h5")
test_data(HDF5.h5read_compound(fn, "/data", Data))
h5open(fn, "r") do f
test_data(HDF5.h5read_compound(f, "/data", Data))
test_data(HDF5.h5read_compound(f["/data"], Data))
end


# Test that switching time tracking off results in identical files
h5open("tt1.h5", "w") do f
f["x", "track_times", false] = [1, 2, 3]
Expand Down