diff --git a/doc/hdf5.md b/doc/hdf5.md index 9f2f43948..d3a0e0d6d 100644 --- a/doc/hdf5.md +++ b/doc/hdf5.md @@ -207,10 +207,7 @@ for obj in g println(data) end ``` -This gives you a straightforward way of recursively exploring an entire HDF5 file. A convenient way of examining the structure of an HDF5 file is the `dump` function, e.g., -```julia -dump(fid) -``` +This gives you a straightforward way of recursively exploring an entire HDF5 file. If you need to know whether group `g` has a dataset named `mydata`, you can test that with ```julia diff --git a/src/HDF5.jl b/src/HDF5.jl index 0d3945dd7..4a3bd3e14 100644 --- a/src/HDF5.jl +++ b/src/HDF5.jl @@ -6,7 +6,7 @@ using Compat using Compat: unsafe_convert, String import Base: - ==, close, convert, done, dump, eltype, endof, flush, getindex, + close, convert, done, eltype, endof, flush, getindex, ==, isempty, isvalid, length, names, ndims, next, parent, read, setindex!, show, size, sizeof, start, write, isopen @@ -316,7 +316,14 @@ type HDF5File <: DataFile end end convert(::Type{Hid}, f::HDF5File) = f.id -show(io::IO, fid::HDF5File) = isvalid(fid) ? print(io, "HDF5 data file: ", fid.filename) : print(io, "Closed HFD5 data file: ", fid.filename) +function show(io::IO, fid::HDF5File) + if isvalid(fid) + print(io, "HDF5 data file: ", fid.filename) + else + print(io, "HFD5 data file (closed): ", fid.filename) + end +end + type HDF5Group <: DataFile id::Hid @@ -329,7 +336,13 @@ type HDF5Group <: DataFile end end convert(::Type{Hid}, g::HDF5Group) = g.id -show(io::IO, g::HDF5Group) = isvalid(g) ? print(io, "HDF5 group: ", name(g), " (file: ", g.file.filename, ")") : print(io, "HDF5 group (invalid)") +function show(io::IO, g::HDF5Group) + if isvalid(g) + print(io, "HDF5 group: ", name(g), " (file: ", g.file.filename, ")") + else + print(io, "HFD5 group (invalid)") + end +end type HDF5Dataset id::Hid @@ -342,7 +355,13 @@ type HDF5Dataset end end convert(::Type{Hid}, dset::HDF5Dataset) = dset.id -show(io::IO, dset::HDF5Dataset) = isvalid(dset) ? print(io, "HDF5 dataset: ", name(dset), " (file: ", dset.file.filename, ")") : print(io, "HDF5 dataset (invalid)") +function show(io::IO, dset::HDF5Dataset) + if isvalid(dset) + print(io, "HDF5 dataset: ", name(dset), " (file: ", dset.file.filename, ")") + else + print(io, "HFD5 dataset (invalid)") + end +end type HDF5Datatype id::Hid @@ -1064,45 +1083,6 @@ function parent(obj::Union{HDF5File, HDF5Group, HDF5Dataset}) end end -# It would also be nice to print the first few elements. -# FIXME: strings and array of variable-length strings -function dump(io::IO, x::HDF5Dataset, n::Int, indent) - sz = size(x) - print(io, "HDF5Dataset $sz : ") - isshowall = isempty(sz) || prod(sz) == 1 - if !isshowall - dtype = datatype(x) - try - T = hdf5_to_julia_eltype(dtype) - isshowall |= !(T<:HDF5BitsKind) - finally - close(dtype) - end - end - isshowall ? print(io, read(x)) : - # the following is a bit kludgy, but there's no way to do x[1:3] for the multidimensional case - length(sz) == 1 ? Base.show_delim_array(io, x[1:min(5,size(x)[1])], '[', ',', ' ', true) : - length(sz) == 2 ? Base.show_delim_array(io, x[1,1:min(5,size(x)[2])], '[', ',', ' ', true) : "" - println(io,) -end -function dump(io::IO, x::Union{HDF5File, HDF5Group}, n::Int, indent) - println(io, typeof(x), " len ", length(x)) - if n > 0 - i = 1 - for k in names(x) - print(io, indent, " ", k, ": ") - v = o_open(x, k) - dump(io, v, n - 1, string(indent, " ")) - close(v) - if i > 10 - println(io, indent, " ...") - break - end - i += 1 - end - end -end - # Get the datatype of a dataset datatype(dset::HDF5Dataset) = HDF5Datatype(h5d_get_type(checkvalid(dset).id), file(dset)) # Get the datatype of an attribute @@ -1296,7 +1276,7 @@ function read{S<:String}(obj::DatasetOrAttribute, ::Type{S}) pad = h5t_get_strpad(objtype.id) buf = Vector{UInt8}(n) readarray(obj, objtype.id, buf) - pbuf = String(buf) + pbuf = String(buf) ret = unpad(pbuf, pad) end finally