This file uses the linkage to .NET to set up definitions for constants such as ACC_EXCL in “DefinitionsForConstants.txt”. This file can then be read into Mathematica using Get[...].

Prepared 10 July 2011 by Scot Martin

This notebook is provided for informational purposes. That is, the user never need run it unless new constants needed to be added.

This file should be run with a fresh kernel, i.e., Quit[...] before running this file.

set up

user environment

SetDirectory[NotebookDirectory[]];

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

fileNameForDefinitions=FileNameJoin[{Directory[],"DefinitionsForConstants.txt"}];

initialization

Needs["NETLink`"];
LoadNETAssembly[$HDF5pathToDLL];

functions

retrieveNamesAndValuesOfAnEnumeration[enumName:_String]:=

With[
{
enumType=NETNew[enumName]@GetType[]
},

With[
{
enumNames=H5F`CreateMode`GetNames[enumType],
enumValues=NETObjectToExpression/@H5F`CreateMode`GetValues[enumType]
},

{enumNames,enumValues}
]
]

setUpNamesAsMathematicaExpressions[prefix:_String,enumNames:_List]:=

ToExpression@(StringReplace[#,"_"->"u"]&/@(StringJoin[prefix,"u",#]&/@enumNames))

setUpConstants[prefix:_String,enumName:_String]:=

With[
{
makeMathematicaExpressions=MapAt[setUpNamesAsMathematicaExpressions[prefix,#]&,#,1]&
},

Composition[
Apply[Set,#]&,
makeMathematicaExpressions,
retrieveNamesAndValuesOfAnEnumeration]
[enumName]
]

set up constants

one detailed example

retrieveNamesAndValuesOfAnEnumeration["HDF5DotNet.H5F+CreateMode"]

(* note that this function only works as intended prior to running setUpConstants[]*)
setUpNamesAsMathematicaExpressions["H5F",%[[1]]]

setUpConstants["H5F","HDF5DotNet.H5F+CreateMode"]

(* we can make unintended use of this function after running setUpConstants[] to see the created values *)
setUpNamesAsMathematicaExpressions["H5F",%%%[[1]]]

setting up the rest of the constants

setUpConstants["H5","HDF5DotNet.H5IterationOrder"]

setUpConstants["H5","HDF5DotNet.H5IndexType"]

setUpConstants["H5","HDF5DotNet.H5IterationResult"]

setUpConstants["H5","HDF5DotNet.H5ObjectType"]

setUpConstants["H5D","HDF5DotNet.H5D+Layout"]

setUpConstants["H5G","HDF5DotNet.H5GStorageType"]

setUpConstants["H5G","HDF5DotNet.H5GType"]

setUpConstants["H5I","HDF5DotNet.H5I+IdentifierType"]

setUpConstants["H5P","HDF5DotNet.H5P+Template"]

setUpConstants["H5P","HDF5DotNet.H5P+PropertyListClass"]

setUpConstants["H5S","HDF5DotNet.H5S+H5SType"]

setUpConstants["H5S","HDF5DotNet.H5S+H5SClass"]

setUpConstants["H5S","HDF5DotNet.H5S+SelectOperator"]

setUpConstants["H5T","HDF5DotNet.H5T+H5Type"]

setUpConstants["H5T","HDF5DotNet.H5T+H5TClass"]

setUpConstants["H5T","HDF5DotNet.H5T+Direction"]

see a list of all constants that were set up

?`H5u*

?`H5A*

?`H5D*

?`H5E*

?`H5F*

?`H5G*

?`H5I*

?`H5L*

?`H5O*

?`H5P*

?`H5R*

?`H5S*

?`H5T*

?`H5Z*

write out definitions to file

If[FileExistsQ[fileNameForDefinitions],DeleteFile[fileNameForDefinitions]]

Save[fileNameForDefinitions,{"H5u*","H5A*","H5D*","H5E*","H5F*","H5G*","H5I*","H5L*","H5O*","H5P*","H5R*","H5S*","H5T*","H5Z*"}]