HDF5.jl icon indicating copy to clipboard operation
HDF5.jl copied to clipboard

generic function to get the contents, not the handle

Open tpapp opened this issue 4 years ago • 1 comments

Given a dataset, which may be a scalar or an array, I am wondering what the generic syntax is to get its contents, so that they remain valid after the file is closed. I settled on [] after experimenting, but can't find this in the docs. MWE:

using HDF5

file = tempname() * ".hdf5"

h5open(file, "w") do fid
    g = create_group(fid, "g")
    g["value"] = 1.0
end

h5open(file, "r") do fid
    s = fid["g"]["value"]
    s, s[] # invalid, 1.0
end

HDF.jl 0.15.4, Julia 1.6.

tpapp avatar Apr 14 '21 13:04 tpapp

The section that describes Reading and writing data does mention read, though I see why it'd be easy to skim over that and not notice.

h5open(file, "r") do fid
    s = fid["g"]["value"]
    read(s)
end

jmert avatar Apr 14 '21 13:04 jmert