diff --git a/src/api_helpers.jl b/src/api_helpers.jl index 0bb5b3547..69e9b9e28 100644 --- a/src/api_helpers.jl +++ b/src/api_helpers.jl @@ -325,6 +325,23 @@ end ### Table Interface ### +function h5tb_get_table_info(loc_id, table_name) + nfields = Ref{hsize_t}() + nrecords = Ref{hsize_t}() + h5tb_get_table_info(loc_id, table_name, nfields, nrecords) + return nfields[], nrecords[] +end + +function h5tb_get_field_info(loc_id, table_name) + nfields, = h5tb_get_table_info(loc_id, table_name) + field_names = Vector{UInt8}[fill(0x00,255) for i in 1:2] + field_sizes = Vector{Csize_t}(undef,nfields) + field_offsets = Vector{Csize_t}(undef,nfields) + type_size = Ref{Csize_t}() + h5tb_get_field_info(loc_id, table_name, field_names, field_sizes, field_offsets, type_size) + return field_names, field_sizes, field_offsets, type_size +end + ### ### Filter Interface ### diff --git a/test/dataspace.jl b/test/dataspace.jl index 6103e0601..8891acb4f 100644 --- a/test/dataspace.jl +++ b/test/dataspace.jl @@ -1,3 +1,6 @@ +using HDF5 +using Test + @testset "Dataspaces" begin hsize_t = HDF5.hsize_t # Reference objects without using high-level API diff --git a/test/runtests.jl b/test/runtests.jl index e3fc7806c..4dbc398af 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,6 +19,7 @@ include("external.jl") include("swmr.jl") include("mmap.jl") include("properties.jl") +include("table.jl") try using MPI diff --git a/test/table.jl b/test/table.jl new file mode 100644 index 000000000..d33a10d0c --- /dev/null +++ b/test/table.jl @@ -0,0 +1,37 @@ +using HDF5 +using Test + + +hf = h5open(tempname(), "w") + +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, hf, name, nfield, nrec, recsize, colname, offset, tid, chunk, fillvalue, compress, data) +fieldsize = [floatsize, floatsize] +HDF5.h5tb_append_records(hf, name, nrec, recsize, offset, fieldsize, data) +HDF5.h5tb_write_records(hf, name, 1, 4, recsize, offset, fieldsize, collect(1:8) .+ 20.0) +buf = fill(0.0, 100) + +HDF5.h5tb_read_table(hf, 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.0 +HDF5.h5tb_read_records(hf, name, 2, 3, recsize, offset, fieldsize, buf) +@test buf[1:6] == collect(23:28) + +h5nfields, h5nrec = HDF5.h5tb_get_table_info(hf, name) +@test h5nfields == nfield +@test h5nrec == 6