Skip to content

silkfire/LiteHDF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LiteHDF

logo

NuGet

A tiny high-level library that facilitates the reading of HDF5 files. Powered by HDF.PInvoke.NETStandard.

Usage

using var hdf = Hdf.Open(filepath);

if (file.FileIdentifier < 0L)
{
    // File not a valid HDF document
}

double energyValues = file.GetData<double>($"/entries/data/energies");

Listing the group structure

Getting the structure of a group (or the root) is done by calling the IterateGroup method. The first argument is a path to the group to list and the second argument is a GroupIterationCallback delegate:

void GroupIterationCallback(string objectName, ObjectType type, ulong creationTimeUnixSeconds)

On every iteration, it will return the name, type (group or dataset) and the creation time (if existent) of the object of the current iteration.

hdf.IterateGroup("/entries", (name, type, creationTime) => {
    // Action to perform on each iteration
}

The creation time is represented by the number of seconds since the UNIX epoch. Use DateTimeOffset.FromUnixTimeSeconds(creationTime) to convert it into a native date time object.

Reading data

Getting values from a dataset is done by the GetData<TValue> or GetString methods. The former returns an array of the specified data type (if it matches the data type of the dataset) and the latter is only used for datasets that contain string data.

The GetData method returns a HdfData<TValue> object:

class HdfObject<TValue> {
    string DatasetPath;
    ulong? ChangeTime;
    TValue[] Value;
}

If the dataset doesn't exist, a null object is returned.
For single values, simply use the LINQ method SingleOrDefault on the Value property.

About

Lightweight library for reading HDF5 files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages