I want to save and load data with JLD.jl (or HDF5.jl or something) which is is a 1-dimensional array of large elements (themselves large arrays). I want to be able to work with one or a few of the array elements at a time. Something like this for example:
file = jldopen("mydata.jld", "w")
y["a"][1] = rand(5) # does not work
close(file)
A simple solution would be to use the dictionary-like access also for the index elements:
save("tmp/test.jld", "variable_$i", v)
load("tmp/test.jld", "variable_$i")
Is there a better solution? According to the HDF5.jl documentation, it is possible to save a subset of an array. Can this also be accomplished with JLD?
EDIT: the problems I had were because I tried to create and overwrite a dataset all at once. If I use the array syntax, it is possible to modify the contents of the dataset. This was unclear for me from the documentation, since there was no example showing this.
So this would not work:
using HDF5, JLD
jldopen("mydata.jld", "w") do file
g = g_create(file, "mygroup")
g["x"] = "foo"
end
jldopen("mydata.jld", "r+") do file
g = file["mygroup"]
g["x"] = "bar"
end
Nor does g["x”][1] = "bar"
… While this works:
using HDF5, JLD
jldopen("mydata.jld", "w") do file
g = g_create(file, "mygroup")
g["x"] = ["foo", "bar"]
end
jldopen("mydata.jld", "r+") do file
g = file["mygroup"]
g["x"][:] = ["baz", "boo"]
end
This is probably all in the documentation. I’m just leaving this here to reduce confusion for others.