I need to create a Compound dataset using HDF in C#

Asked

Viewed 31 times

2

My application contains a list of Basicvariables and within each of the BV’s, I have a list of objects of class OPC_UA, which have 3 attributes, a datetime (which I will convert to a timestamp), a float and an int64, I need to write this list of OPC UA objects in an HDF5 file but, for that, I need to create a compound dataset and I’m not getting it because I can’t get the size of the object of the opc class for HDF5 allocation

Here is the method that creates HDF5:

 public void CriaHDF5Customizado(PackingConfigFile pf)
        {
            H5FileId fileId = H5F.create("pmdfq.h5", H5F.CreateMode.ACC_TRUNC);
        H5GroupId infoGroupId = H5G.create(fileId, "informations");
        H5G.close(infoGroupId);
        H5GroupId datasetGroupId = H5G.create(fileId, "datasets");

        long[] dims = new long[1];


        foreach(BasicVariable bv in pf.basicVariableList.bvList)
        {
            OPC_UA aux = new OPC_UA();
            var xx = bv.bvData;
            int tamanho = Marshal.SizeOf(typeof(OPC_UA));
            dims[0] = (long)bv.bvData.Count;
            // dims[1] = (long)4;
            H5DataSpaceId spaceId = H5S.create(H5S.H5SClass.SCALAR);
            H5DataTypeId dataTypeId = H5T.create(H5T.CreateClass.COMPOUND, Marshal.SizeOf(typeof(OPC_UA)));

            H5T.insert(dataTypeId, "TimeStamp", 0, new H5DataTypeId(H5T.H5Type.NATIVE_UINT));
            H5T.insert(dataTypeId, "Quality", Marshal.SizeOf(H5T.H5Type.NATIVE_UINT), new H5DataTypeId(H5T.H5Type.NATIVE_UINT));
            H5T.insert(dataTypeId, "Value", 2* Marshal.SizeOf(H5T.H5Type.NATIVE_UINT), new H5DataTypeId(H5T.H5Type.NATIVE_INT));

            H5DataSetId dataSetId = H5D.create(datasetGroupId, bv.bvTag, dataTypeId, spaceId);


            //H5D.write(dataSetId, new H5DataTypeId(H5T.H5Type.STD_REF_OBJ), new H5Array<OPC_UA>(bv.bvData.ToArray()));
            H5D.writeScalar(dataSetId, dataTypeId, ref xx);
            H5D.close(dataSetId);
        }
        H5G.close(datasetGroupId);


        H5F.close(fileId);
    }

And that’s the OPC_UA class

public class OPC_UA
{
    public DateTime timeStamp { get; set;  }
    public string data { get; set; }
    public Int64 quality { get; set; }

    public OPC_UA(DateTime? ts = null ,string dt = "",Int64 qlt = -99)
    {
        if (!ts.HasValue)
        {
            timeStamp = DateTime.Now;
        }
        data = dt;
        quality = qlt;
    }
}

1 answer

0


I managed to solve this, my code was right but forgot to give "Close" in dataspaceId and datasetId

Browser other questions tagged

You are not signed in. Login or sign up in order to post.