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

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 write this list of OPC UA objects in an HDF5 file but for that I would need to create a compound dataset and I'm not getting it because I can not get the size of the opc class object for the HDF5 allocation

Here is the method that creates the 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 this is 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;
    }
}
    
asked by anonymous 11.06.2018 / 18:41

1 answer

0

I was able to resolve this, my code was right but I forgot to give Close in the dataspaceId and the datasetId

    
20.06.2018 / 20:36