How to write a structure in HDF5 file?
using HDF5
mutable struct Foo
a::Int
b::Float64
end
vect = [1,2,3,4,5]
foo = Foo(1, 2.0)
foovect = [P(i, i/2) for i=1:5]
path = "/testfile.h5"
h5write(path, "/vect", vect)
h5write(path, "/foo", foo)
# > MethodError: no method matching write(::HDF5File, ::String, ::Foo)
h5write(path, "/foovec", foovect)
# > MethodError: no method matching write(::HDF5File, ::String, ::Array{P,1})
And how to read a compound type?
If I write some compound type into a hdf5 with c++ (Hello World!
into a byte fields named as field0
… field11
), then try to read it in Julia, it reads an array of HDF5Compound
type:
HDF5.HDF5Compound{12}
data -> (0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21),
membername -> ("0\xfd\xf6\x11field0", "0\xfd\xf6\x11field1", "0\xfd\xf6\x11field2", "0\xfd\xf6\x11field3", "0\xfd\xf6\x11field4", "0\xfd\xf6\x11field5", "0\xfd\xf6\x11field6", "0\xfd\xf6\x11field7", "0\xfd\xf6\x11field8", "0\xfd\xf6\x11field9", "0\xfd\xf6\x11field10", "0\xfd\xf6\x11field11"),
membertype -> (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8))
Can it be converted into a structure or named tuple or something?