Skip to content

Commit

Permalink
Improve quality of examples, add one
Browse files Browse the repository at this point in the history
  • Loading branch information
jzrake committed Jan 15, 2013
1 parent 3934166 commit 98d8b2e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
6 changes: 6 additions & 0 deletions LuaHDF5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ function BaseClass:close()
-- object is already closed
end
end
function BaseClass:class()
return self._type
end
function BaseClass:name()
return self._name
end


--------------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions alltests.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

dofile('LuaHDF5.lua')
dofile('run.lua')



dofile('array.lua')
25 changes: 25 additions & 0 deletions examples/ex1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

--------------------------------------------------------------------------------
-- Demonstrate the simplest use of the high-level HDF5 Lua bindings. Create an
-- HDF5 file with the following layout:
--
-- outfile.h5/
--
-- the_dataset (double array [16,32,64])
--
-- the_group/
--
-- the_message (string: "here is the message")
--
--------------------------------------------------------------------------------

local hdf5 = require 'LuaHDF5'
local buffer = require 'buffer'
local array = require 'array'

local the_array = array.array({16,32,64}, 'double')
local the_h5file = hdf5.File("outfile.h5", "w")
local the_group = the_h5file:require_group("the_group")
the_group["the_message"] = "here is the message"
the_h5file["the_dataset"] = the_array
the_h5file:close()
26 changes: 24 additions & 2 deletions examples/h5ls.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@

--------------------------------------------------------------------------------
-- Prints all the data sets and groups at the top level of a file
--------------------------------------------------------------------------------

local hdf5 = require 'LuaHDF5'

local function iterate_group(grp, indent)
local indent = indent or ''
for k,v in pairs(grp) do
if v:class() == 'data set' then
if v:get_type():type_class() == 'string' then
print(indent..'Dataset: '..indent..k, v)
elseif v:get_type():type_class() == 'float' then
print(indent..'Dataset: '..indent..k, v)
end
elseif v:class() == 'group' then
print(indent..'Group: '..v:name())
iterate_group(v, indent..'\t')
end
end
end

local fname = arg[2]
local h5f = hdf5.File(fname, 'r')

for k,v in pairs(h5f) do
print(k, v:value())
if not arg[2] then
print("usage: h5ls.lua infile.h5")
else
iterate_group(h5f)
end

0 comments on commit 98d8b2e

Please sign in to comment.