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

wrap a subset of H5TB #511

Closed
wants to merge 9 commits into from
Closed
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
28 changes: 28 additions & 0 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,34 @@ for (jlname, h5name, outtype, argtypes, argsyms, msg) in
end
end

for (jlname, h5name, outtype, argtypes, argsyms, msg) in
((:h5tb_make_table, :H5TBmake_table, Herr, (Cstring, Hid, Cstring, Hsize, Hsize, Hsize, Ptr{Ptr{Cchar}}, Ptr{Csize_t}, Ptr{Hid}, Hsize, Ptr{Cvoid}, Cint, Ptr{Cvoid}), (:table_title, :loc_id, :table_name, :nfields, :nrecords, :type_size, :field_names, :field_offset, :field_types, :chunk_size, :fill_data, :compress, :data), "Error making table."),
(:h5tb_append_records, :H5TBappend_records, Herr, (Hid, Cstring, Hsize, Csize_t, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Cvoid}), (:loc_id, :dset_name, :nrecords, :type_size, :field_offset, :field_sizes, :data), "Error appending records"),
(:h5tb_write_records, :H5TBwrite_records, Herr, (Hid, Cstring, Hsize, Hsize, Csize_t, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Cvoid}), (:loc_id, :table_name, :start, :nrecords, :type_size, :field_offset, :field_sizes, :data), "Error writing records."),
(:h5tb_read_table, :H5TBread_table, Herr, (Hid, Cstring, Csize_t, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Cvoid}), (:loc_id, :table_name, :dst_size, :dst_offset, :dst_sizes, :dst_buf), "Error reading table"),
(:h5tb_read_records, :H5TBread_records, Herr, (Hid, Cstring, Hsize, Hsize, Csize_t, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Cvoid}), (:loc_id, :table_name, :start, :nrecords, :type_size, :field_offset, :dst_sizes, :data), "Error reading records"),
(:h5tb_get_table_info, :H5TBget_table_info, Herr, (Hid, Cstring, Ptr{Hsize}, Ptr{Hsize}), (:loc_id, :table_name, :nfields, :nrecords), "Error getting table info"),
(:h5tb_get_field_info, :H5TBget_field_info, Herr, (Hid, Cstring, Ptr{Ptr{Cchar}}, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Csize_t}), (:loc_id, :table_name, :field_names, :field_sizes, :field_offsets, :type_size), "Error getting field info"),
)
ex_dec = funcdecexpr(jlname, length(argtypes), argsyms)
library = libhdf5_hl
if isempty(library)
# If the high-level library is not installed, then skip these functions
continue
end
ex_ccall = ccallexpr(library, h5name, outtype, argtypes, argsyms)
ex_body = quote
status = $ex_ccall
if status < 0
error($msg)
end
end
ex_func = Expr(:function, ex_dec, ex_body)
@eval begin
$ex_func
end
end

# Functions returning a single argument, and/or with more complex
# error messages
for (jlname, h5name, outtype, argtypes, argsyms, ex_error) in
Expand Down
51 changes: 51 additions & 0 deletions test/h5tb.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using HDF5
using Test

@testset "h5tb" begin
mktemp() do fname, io
h5open(fname, "w") do f
fv = 3.14
data = [1.,2.,3.,4.,5.,6.]
floatsize = sizeof(data[1])
h5t = datatype(data[1])
title = "lal"
name = "mym"
nfield = 2
nrec = 3
recsize = nfield * floatsize
colname = ["f1", "f2"]
offset = [0,floatsize]
tid = [h5t.id, h5t.id]
chunk = 7
fillvalue = [3.14, 2.71]
compress = 1
HDF5.h5tb_make_table(title, f.id, name, nfield, nrec, recsize, colname, offset, tid, chunk, fillvalue, compress, data)
fieldsize = [floatsize, floatsize]
HDF5.h5tb_append_records(f.id, name, nrec, recsize, offset, fieldsize, data)
HDF5.h5tb_write_records(f.id, name, 1, 4, recsize, offset, fieldsize, convert.(Float64,collect(1:8) .+ 20))
buf = fill(0., 100)
HDF5.h5tb_read_table(f.id, name, recsize, offset, fieldsize, buf)
@test buf[1:12] == [1.0, 2.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 5.0, 6.0]
buf .= 0
HDF5.h5tb_read_records(f.id, name, 2, 3, recsize, offset, fieldsize, buf)
@test buf[1:6] == collect(23:28)

_nfield = Ref{HDF5.Hsize}(0)
_nrec = Ref{HDF5.Hsize}(0)
HDF5.h5tb_get_table_info(f.id, name, _nfield, _nrec)
@test _nfield[] == nfield
@test _nrec[] == 6

_colnamebuf = [fill(0xff, 10), fill(0xff,10)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to determine the length of these strings from HDF5?

_fieldsize = Vector{Csize_t}(undef, _nfield[])
_offset = Vector{Csize_t}(undef, _nfield[])
_recsize = Ref{Csize_t}(0)
HDF5.h5tb_get_field_info(f.id, name, _colnamebuf, _fieldsize, _offset, _recsize)
_colname = [String(d[1:findfirst(isequal(0x00),d)-1]) for d in _colnamebuf]
@test _colname == colname
@test _fieldsize == fieldsize
@test _offset == offset
@test _recsize[] == recsize
end
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include("extend_test.jl")
include("gc.jl")
include("external.jl")
include("swmr.jl")
include("h5tb.jl")
include("mmap.jl")
if get(Pkg.installed(), "MPI", nothing) !== nothing
# basic MPI tests, for actual parallel tests we need to run in MPI mode
Expand Down