Information

This package contains functions that provide one-to-one mapping to the H5 functions of the HDF5group.org: http://www.hdfgroup.org/HDF5/doc/RM/.

Prepared 14 July 2011 by Scot Martin for Windows 7, 64-bit, Mathematica version 8.0.1. Email: scot_martin@harvard.edu.

http://www.hdfgroup.org/HDF5/doc/RM/
http://www.hdfgroup.org/HDF5/doc/RM/RM_H5Front.html
Source code: http://www.hdfgroup.org/ftp/HDF5/current/src/unpacked/src/

Package

BeginPackage Context[...]

BeginPackage["HDF5`",{"NETLink`"}]

Definitions

$HDF5packageVersion="V1.00"

$pathToDefinitions=FileNameJoin[{Directory[],"DefinitionsForConstants.txt"}]

$pathToDLL=FileNameJoin[{Directory[],"HDF5DotNet-Net2.0-x86_64","hdf5dll.dll"}]

$pathToDotNet=FileNameJoin[{Directory[],"HDF5DotNet-Net2.0-x86_64","HDF5DotNet.dll"}]

Initialization

Get[$pathToDefinitions]

Something does not quite work with H5Tcopy to make a dataSpaceID from the fundamental types, i.e., “H5Tcopy[H5TuNATIVEuINT]” returns as -1 indicating an error code. The equivalent command is “H5T`copy[H5TuNATIVEuINT]@Id[]” in .NET formulation. I took my best look at source code but cannot quite figure it out. Therefore, mix and match with the DotNet. It is not pretty but it works. (The problem with using the DotNet code exclusively is that I could not coax functions such as H5D`read and H5D`write to work. It seems to have to do with the ‘generics’ format.) [H5Tcopy does work fine on objects that already have identifies, like datasets, etc.]

LoadNETAssembly[$pathToDotNet];
LoadNETType["HDF5DotNet.H5T"];
LoadNETType["HDF5DotNet.H5T+H5Type"];

Similar observation holds for H5P`create.

LoadNETType["HDF5DotNet.H5P"];
LoadNETType["HDF5DotNet.H5P+PropertyListClass"];

Wrappers

Conventions used for data types:
http://msdn.microsoft.com/en-us/library/hfa3fa08.aspx (accessed 10 July 2011).
Also “char*” of “C” is “String” of other languages.

H5

H5open=DefineDLLFunction["H5open",$pathToDLL,"Int32",{}]

H5getUlibversion=DefineDLLFunction["H5get_libversion",$pathToDLL,"Int32",{"Int32*","Int32*","Int32*"}]

H5close=DefineDLLFunction["H5close",$pathToDLL,"Int32",{}]

H5A

I could not get H5Aget_name_by_idx to work correctly. It has something to do with the return of “char *” in parameter 6. If this command is needed, a workaround might be to use the DotNet formulation, i.e., LoadNETType[“HDF5DotNet.H5A”]. Another workaround is to call H5AopenByIndex to get the attributeID followed by H5AExtendGetName using that attributeID, followed by closing all opened attributeID’s.

H5Acreate=DefineDLLFunction["H5Acreate2",$pathToDLL,"Int32",{"Int32","String","Int32","Int32","Int32","Int32"}]

H5Aopen=DefineDLLFunction["H5Aopen",$pathToDLL,"Int32",{"Int32","String","Int32"}]

H5AopenByName=DefineDLLFunction["H5Aopen_by_name",$pathToDLL,"Int32",{"Int32","String","String","Int32","Int32"}]

H5AopenByIndex=DefineDLLFunction["H5Aopen_by_idx",$pathToDLL,"Int32",{"Int32","String","Int32","Int32","Int64","Int32","Int32"}]

H5Aclose=DefineDLLFunction["H5Aclose",$pathToDLL,"Int32",{"Int32"}]

H5AgetNumAttrs=DefineDLLFunction["H5Aget_num_attrs",$pathToDLL,"Int32",{"Int32"}]

H5AgetName=DefineDLLFunction["H5Aget_name",$pathToDLL,"Int32",{"Int32","Int32","System.Text.StringBuilder"}]

H5AgetStorageSize=DefineDLLFunction["H5Aget_storage_size",$pathToDLL,"Int32",{"Int32"}]

H5AgetSpace=DefineDLLFunction["H5Aget_space",$pathToDLL,"Int32",{"Int32"}]

H5AgetType=DefineDLLFunction["H5Aget_type",$pathToDLL,"Int32",{"Int32"}]

H5Aread[Byte]=DefineDLLFunction["H5Aread",$pathToDLL,"Int32",{"Int32","Int32","Byte[]"}]

H5Awrite[Byte]=DefineDLLFunction["H5Awrite",$pathToDLL,"Int32",{"Int32","Int32","Byte[]"}]

H5Aread[Integer32]=DefineDLLFunction["H5Aread",$pathToDLL,"Int32",{"Int32","Int32","Int32[]"}]

H5Awrite[Integer32]=DefineDLLFunction["H5Awrite",$pathToDLL,"Int32",{"Int32","Int32","Int32[]"}]

H5Aread[Integer64]=DefineDLLFunction["H5Aread",$pathToDLL,"Int32",{"Int32","Int32","Int64[]"}]

H5Awrite[Integer64]=DefineDLLFunction["H5Awrite",$pathToDLL,"Int32",{"Int32","Int32","Int64[]"}]

H5Aread[SingleFloat]=DefineDLLFunction["H5Aread",$pathToDLL,"Int32",{"Int32","Int32","Single[]"}]

H5Awrite[SingleFloat]=DefineDLLFunction["H5Awrite",$pathToDLL,"Int32",{"Int32","Int32","Single[]"}]

H5Aread[DoubleFloat]=DefineDLLFunction["H5Aread",$pathToDLL,"Int32",{"Int32","Int32","Double[]"}]

H5Awrite[DoubleFloat]=DefineDLLFunction["H5Awrite",$pathToDLL,"Int32",{"Int32","Int32","Double[]"}]

H5D

H5Dcreate=DefineDLLFunction["H5Dcreate2",$pathToDLL,"Int32",{"Int32","String","Int32","Int32","Int32","Int32","Int32"}]

H5Dopen=DefineDLLFunction["H5Dopen2",$pathToDLL,"Int32",{"Int32","String","Int32"}]

H5Dclose=DefineDLLFunction["H5Dclose",$pathToDLL,"Int32",{"Int32"}]

H5DgetStorageSize=DefineDLLFunction["H5Dget_storage_size",$pathToDLL,"Int32",{"Int32"}]

H5DgetSpace=DefineDLLFunction["H5Dget_space",$pathToDLL,"Int32",{"Int32"}]

H5DgetType=DefineDLLFunction["H5Dget_type",$pathToDLL,"Int32",{"Int32"}]

H5DgetOffset=DefineDLLFunction["H5Dget_offset",$pathToDLL,"Int32",{"Int32"}]

H5DsetExtent=DefineDLLFunction["H5Dset_extent",$pathToDLL,"Int32",{"Int32","Int64[]"}]

H5DgetCreatePList=DefineDLLFunction["H5Dget_create_plist",$pathToDLL,"Int32",{"Int32"}]

H5Dread[Byte]=DefineDLLFunction["H5Dread",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Byte[]"}]

H5Dwrite[Byte]=DefineDLLFunction["H5Dwrite",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Byte[]"}]

H5Dread[Integer32]=DefineDLLFunction["H5Dread",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Int32[]"}]

H5Dwrite[Integer32]=DefineDLLFunction["H5Dwrite",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Int32[]"}]

H5Dread[Integer64]=DefineDLLFunction["H5Dread",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Int64[]"}]

H5Dwrite[Integer64]=DefineDLLFunction["H5Dwrite",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Int64[]"}]

H5Dread[SingleFloat]=DefineDLLFunction["H5Dread",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Single[]"}]

H5Dwrite[SingleFloat]=DefineDLLFunction["H5Dwrite",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Single[]"}]

H5Dread[DoubleFloat]=DefineDLLFunction["H5Dread",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Double[]"}]

H5Dwrite[DoubleFloat]=DefineDLLFunction["H5Dwrite",$pathToDLL,"Int32",{"Int32","Int32","Int32","Int32","Int32","Double[]"}]

H5E

H5F

H5Fcreate=DefineDLLFunction["H5Fcreate",$pathToDLL,"Int32",{"String","Int32","Int32","Int32"}]

H5Fopen=DefineDLLFunction["H5Fopen",$pathToDLL,"Int32",{"String","Int32","Int32"}]

H5Fclose=DefineDLLFunction["H5Fclose",$pathToDLL,"Int32",{"Int32"}]

H5G

H5Gcreate=DefineDLLFunction["H5Gcreate2",$pathToDLL,"Int32",{"Int32","String","Int32","Int32","Int32"}]

H5Gopen=DefineDLLFunction["H5Gopen2",$pathToDLL,"Int32",{"Int32","String","Int32"}]

H5Gclose=DefineDLLFunction["H5Gclose",$pathToDLL,"Int32",{"Int32"}]

H5GgetNumObjs=DefineDLLFunction["H5Gget_num_objs",$pathToDLL,"Int32",{"Int32","Int64*"}]

H5GgetObjNameByIndex=DefineDLLFunction["H5Gget_objname_by_idx",$pathToDLL,"Int32",{"Int32","Int64","System.Text.StringBuilder","Int32"}]

H5GgetObjTypeByIndex=DefineDLLFunction["H5Gget_objtype_by_idx",$pathToDLL,"Int32",{"Int32","Int64"}]

H5I

H5IgetType=DefineDLLFunction["H5Iget_type",$pathToDLL,"Int32",{"Int32"}]

H5L

H5O

H5Oopen=DefineDLLFunction["H5Oopen",$pathToDLL,"Int32",{"Int32","String","Int32"}]

H5Oclose=DefineDLLFunction["H5Oclose",$pathToDLL,"Int32",{"Int32"}]

H5P

H5Pcreate=DefineDLLFunction["H5Pcreate",$pathToDLL,"Int32",{"Int32"}]

H5PsetChunk=DefineDLLFunction["H5Pset_chunk",$pathToDLL,"Int32",{"Int32","Int32","Int64[]"}]

H5Pclose=DefineDLLFunction["H5Pclose",$pathToDLL,"Int32",{"Int32"}]

H5R

H5S

H5Screate=DefineDLLFunction["H5Screate",$pathToDLL,"Int32",{"Int32"}]

H5ScreateUsimple=DefineDLLFunction["H5Screate_simple",$pathToDLL,"Int32",{"Int32","Int64[]","Int64[]"}]

H5Sclose=DefineDLLFunction["H5Sclose",$pathToDLL,"Int32",{"Int32"}]

H5SgetSimpleExtentNDims=DefineDLLFunction["H5Sget_simple_extent_ndims",$pathToDLL,"Int32",{"Int32"}]

H5SgetSimpleExtentDims=DefineDLLFunction["H5Sget_simple_extent_dims",$pathToDLL,"Int32",{"Int32","Int64[]","Int64[]"}]

H5SgetSimpleExtentNPoints=DefineDLLFunction["H5Sget_simple_extent_npoints",$pathToDLL,"Int64",{"Int32"}]

H5SisSimple=DefineDLLFunction["H5Sis_simple",$pathToDLL,"Int32",{"Int32"}]

H5SselectHyperSlab=DefineDLLFunction["H5Sselect_hyperslab",$pathToDLL,"Int32",{"Int32","Int32","Int64[]","Int64[]","Int64[]","Int64[]"}]

H5SgetSelectElemNPoints=DefineDLLFunction["H5Sget_select_elem_npoints",$pathToDLL,"Int64",{"Int32"}]

H5SgetSelectHyperNBlocks=DefineDLLFunction["H5Sget_select_hyper_nblocks",$pathToDLL,"Int64",{"Int32"}]

H5SgetSelectNPoints=DefineDLLFunction["H5Sget_select_npoints",$pathToDLL,"Int64",{"Int32"}]

H5SgetSelectType=DefineDLLFunction["H5Sget_select_type",$pathToDLL,"Int32",{"Int32"}]

H5SselectAll=DefineDLLFunction["H5Sselect_all",$pathToDLL,"Int32",{"Int32"}]

H5SselectNone=DefineDLLFunction["H5Sselect_none",$pathToDLL,"Int32",{"Int32"}]

H5Scopy=DefineDLLFunction["H5Scopy",$pathToDLL,"Int32",{"Int32"}]

H5SextentCopy=DefineDLLFunction["H5Sextent_copy",$pathToDLL,"Int32",{"Int32","Int32"}]

H5T

H5Tclose=DefineDLLFunction["H5Tclose",$pathToDLL,"Int32",{"Int32"}]

H5TgetClass=DefineDLLFunction["H5Tget_class",$pathToDLL,"Int32",{"Int32"}]

H5TgetNativeType=DefineDLLFunction["H5Tget_native_type",$pathToDLL,"Int32",{"Int32","Int32"}]

H5TgetSize=DefineDLLFunction["H5Tget_size",$pathToDLL,"Int32",{"Int32"}]

H5Tcopy=DefineDLLFunction["H5Tcopy",$pathToDLL,"Int32",{"Int32"}]

H5TgetMemberClass=DefineDLLFunction["H5Tget_member_class",$pathToDLL,"Int32",{"Int32","Int32"}]

H5TgetNMembers=DefineDLLFunction["H5Tget_nmembers",$pathToDLL,"Int32",{"Int32"}]

H5TgetMemberIndex=DefineDLLFunction["H5Tget_member_index",$pathToDLL,"Int32",{"Int32","String"}]

(* HINT: get String's from pointer using LoadNETType["System.Runtime.InteropServices.Marshal"]; Marshal`PtrToStringAnsi[<<NETObject[System.IntPtr]>>. See further documentation: http://msdn.microsoft.com/en-us/library/atxe881w.aspx ]*)
H5TgetMemberName=DefineDLLFunction["H5Tget_member_name",$pathToDLL,"IntPtr",{"Int32","Int32"}]

H5TgetMemberOffset=DefineDLLFunction["H5Tget_member_offset",$pathToDLL,"Int32",{"Int32","Int32"}]

H5TgetMemberType=DefineDLLFunction["H5Tget_member_type",$pathToDLL,"Int32",{"Int32","Int32"}]

H5TisVariableStr=DefineDLLFunction["H5Tis_variable_str",$pathToDLL,"Int32",{"Int32"}]

H5Z

EndPackage Context[...]

EndPackage[]