Skip to content

Commit

Permalink
Merge 200fa16 into 343b1ab
Browse files Browse the repository at this point in the history
  • Loading branch information
cnliao committed Sep 18, 2018
2 parents 343b1ab + 200fa16 commit 05073b7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,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
50 changes: 50 additions & 0 deletions test/h5tb.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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.]
h5t = datatype(data[1])
title = "lal"
name = "mym"
nfield = 2
nrec = 3
recsize = 16
colname = ["f1", "f2"]
offset = [0,8]
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 = [8,8]
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)]
_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")
if !Sys.iswindows() # Mmap needs to be fixed on windows
include("mmap.jl")
end
Expand Down

0 comments on commit 05073b7

Please sign in to comment.