Home > database >  Reading a h5 file in C# with the correct values
Reading a h5 file in C# with the correct values

Time:06-06

I am trying to read a h5 file for my Unity project and read the data from the file and use it in Unity. I opened the file first hith Python and h5py and the file contains of multiple arrays and data like this:

enter image description here

Now when I am trying to read the file in C# (Unity) I am getting this value for a single entry:

enter image description here

Has someone any recommendations (or sample code) on how to read the file properly so that the values match these from the h5py output. My guess is that the datatypes arent the same because an int in C# is presented as 32bit but I only need 16 Bits. I tried to convert the number in UInt16 but I got an outofrange exception. I used HDFPinvoke and other libraries but I couldnt fix the error.Couldnt I just directly use the Python Script with IronPython to get the data in runtime ?

CodePudding user response:

I'm not familiar with HDFPinvoke and friends but you could try HDFql to read an HDF5 dataset in C#. Based on the info provided, the reading could be done as follows:

ushort[,] values = new ushort[17189, 19];

HDFql.Execute("SELECT FROM myDataset INTO MEMORY "   HDFql.VariableRegister(values));

for(int i = 0; i < 17189; i  )
{
    for(int j = 0; j < 19; j  )
    {
        System.Console.WriteLine(values[i, j]);
    }
}

For additional information, see HDFql reference manual here and examples on how to use it in C# here.

  • Related