Example:
Creation of a new file named 'test_write.h5' on the folder 'C:\temp'.
Add a new dataset sames 'some_name' in the root group /.
This datased is an unidimensional vector of a compound type, with this structure:
field name |
field type |
index |
unsigned integer |
v1 |
float |
v2 |
float |
v3 |
float |
and filled with an array with two values:
15 3.0 2.0 1.0
2 1.1 2.2 3.3
Add another dataset named 'other_name', with a bidimensional array of floats, in 2 columns, and filled with:
15.1 3.0
22.0 1.4
6.5 2.8
(then the number of rows is 3)
Datasets are compressed with maximum compression level=9
Finally the file is closed
package require hdf5
set h hdf2
hdf5 $h {C:\temp\test_write.h5}
set compress_level 9
$h set -vtype compound -fields {index uint v1 float v2 float v3 float} -compress $compress_level -ncolumns 1 /some_name {15 3.0 2.0 1.0 2 1.1 2.2 3.3}
$h set -vtype float -compress $compress_level -ncolumns 2 /other_name {15.1 3.0 22.0 1.4 6.5 2.8}
$h close
Example:
Open an existent file named'test_read.h5' for reading.
get the attribute named /mesh/ntc1_2/all and print all its names and values
get the attribute named /mesh/ntc1_2/all and print the value of the attribute named 'type'
get the dimensions of the dataset named /mesh/ntc1_2/all/selectorOnMesh/GC011 and print them
print the data stored in this datased
get all groups child ot the root group (named \ allways), and for each group get its datasets and print its data.
package require hdf5
set h hdf1
hdf5 $h {C:\temo\test_read.h5}
puts [$h get_attribute /mesh/ntc1_2/all]
puts [$h get_attribute /mesh/ntc1_2/all type]
set dataset /mesh/ntc1_2/all/selectorOnMesh/GC011
puts [$h get -dimensions $dataset] ;#get the dimensions only
puts [$h get $dataset] ;#get the data
set groups [$h glob -directory \ -types group *]
foreach group $groups {
set datasets [$h glob -directory \$group -types dataset *]
foreach dataset $datasets {
set data [$h get $dataset]
puts $data
}
}
$h close