Skip to content

Commit

Permalink
High level wrappers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
musm committed Dec 10, 2020
1 parent 10aa29c commit 8f16943
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/api_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
###
3 changes: 3 additions & 0 deletions test/dataspace.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using HDF5
using Test

@testset "Dataspaces" begin
hsize_t = HDF5.hsize_t
# Reference objects without using high-level API
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include("external.jl")
include("swmr.jl")
include("mmap.jl")
include("properties.jl")
include("table.jl")

try
using MPI
Expand Down
37 changes: 37 additions & 0 deletions test/table.jl
Original file line number Diff line number Diff line change
@@ -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)

nfields, nrec = HDF5.h5tb_get_table_info(hf, name)
@test h5nfields == nfield
@test h5nrec == 6

0 comments on commit 8f16943

Please sign in to comment.