We got a requirement to write and read the data into .h5 files by using Compound data type.
And i’m trying this in Windows Application for this we have taken two button click events i.e Insert to Write the data and Select to read the data.
We are using following code to Write the data to .h5 file and which is working fine and file size is 8 KB. (No issues in Writing the data).
Looking at the code snippet you have posted, it seems that member Weight (belonging to struct Data) is of type double (64 bit) while the corresponding member of HDF5 compound dataset guernica is of type float (32 bit). Therefore, you need to change this corresponding member to type double. In other words:
HDFql.Execute("CREATE DATASET picasso/guernica AS COMPOUND(age AS UNSIGNED INT, weight AS DOUBLE)(100)");
Alternatively, if you wish member Weight (belonging to struct Data) to be a float (32 bit), you need to 1) declare it as such type and 2) change the line that converts variable i and assigns the result to Weight as follows:
There is another issue with the code you posted, namely the lack of a space between keyword MEMORY and the result of calling method VariableTransientRegister. To fix the issue have the following instead:
HDFql.Execute("SELECT FROM picasso/guernica INTO MEMORY " + HDFql.VariableTransientRegister(readvalues));
As a pro-tip, to have your code as simple as possible, you may want to replace the following lines:
HDFql.Execute("USE FILE paint8.h5");
HDFql.Execute("SELECT FROM picasso/guernica INTO MEMORY " + HDFql.VariableTransientRegister(readvalues));
HDFql.Execute("CLOSE FILE");
with only this one (functionally equivalent):
HDFql.Execute("SELECT FROM paint8.h5 picasso/guernica INTO MEMORY " + HDFql.VariableTransientRegister(readvalues));
But there is still a issue we are able to read the data only from 0-49 out of 100 values (able to read only the half data) and from 50-99 (remaining half) we can’t able to see any data there.
The Screenshot is attached below for the refertence.
Would you mind to check with, e.g., HDFView dataset guernica and see if it stores all the expected values? Most likely the dataset is not storing all the values. Thanks!
Yes we already checked with dataset after writing the data to .h5 file. It is storing all the values[0-100]
and we need to read all the values[0-100] however we are able to read values only from[0-49] which i sent the screenshot of it in previous thread.
Attaching the Screenshot below in which we are able to store all the values from[0-100] (in dataset).
Yes , i’m attaching the paint8.h5 file below.Before that,
Also i would like to mention that in the dataset ‘guernica’ we are not able to see the data what are Writing in it i.e [0-100]. We are able to see some weird data when we open it with HDFView and why it’s happening don’t know really.
And adding the screenshot below for reference.
Please find the paint8.h5 file below i.e which you asked to share.
Thanks for sharing file paint8.h5 - it looks good!
We were able to read all the values stored in dataset guernica using HDFql with the following C# code:
using AS.HDFql;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 0)]
struct Data
{
public uint Age;
public float Weight;
}
public class Example
{
public static void Main(string []args)
{
Data[] values = new Data[100];
HDFql.Execute("SELECT FROM paint8.h5 picasso/guernica INTO MEMORY " + HDFql.VariableTransientRegister(values));
for(int i = 0; i < 100; i++)
{
System.Console.WriteLine("Row=" + i + " * Age=" + values[i].Age + " * Weight=" + values[i].Weight);
}
}
}
Could it be that you have more than one file named paint8.h5 and your C# code is picking a different file from the one you have shared? In addition, would you mind to share your C# struct Data? Thanks!
In a previous post, it was mentioned that member Weight should be of type float. The struct you have posted still has this member as of type double. In addition, please notice that the struct must be packed - see the example posted above to have an idea about this.