WriteScalar writing just one row, and i need a list

Hi, i’ve created a compound dataset and it worked fine writing just one row, but i need to write a list inside that compound dataset, and it seems that everitime the “foreach” loop runs, it overwrite the row that was inserted on the previous loop, here is my code:

struct opcSt
public Int64 dt;
public Int64 qlt;
public float vl;

        public opcSt(Int64 i, Int64 q , float v)
            dt = i;
            qlt = q;
            vl = v;

    public void CriaHDF5Customizado(PackingConfigFile pf)
        H5FileId arquivoHDF5 = H5F.create("C:/Users/arthuro/Desktop/TagPort.h5", 
        H5GroupId datasetGroup = H5G.create(arquivoHDF5, "Datasets");
        H5GroupId infosGroup = H5G.create(arquivoHDF5, "Informations");

        opcSt opHelper = new opcSt();
        opHelper.dt = (Int64)DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
        opHelper.qlt = (Int64)DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
        opHelper.vl = 123456.7f;

        H5DataSpaceId myDataSpace = H5S.create(H5S.H5SClass.SCALAR);
        int structsize = Marshal.SizeOf(opHelper);
        H5DataTypeId myOPCType = H5T.create(H5T.CreateClass.COMPOUND, structsize);
        H5T.insert(myOPCType, "TimeStamp", 0, new H5DataTypeId(H5T.H5Type.NATIVE_LONG));
        H5T.insert(myOPCType, "Quality", 8, new H5DataTypeId(H5T.H5Type.NATIVE_LONG));
        H5T.insert(myOPCType, "Value", 16, new H5DataTypeId(H5T.H5Type.NATIVE_FLOAT));

        foreach (BasicVariable bv in pf.basicVariableList.bvList)
            H5DataSetId bvDset = H5D.create(datasetGroup, bv.bvTag, myOPCType, myDataSpace);                
            foreach(OPC_UA opc in bv.bvData)
                var aux = new opcSt(opc.timeStamp, opc.quality, (float)opc.data);
                H5D.writeScalar(bvDset, myOPCType, ref aux);

Hello Arthuro,

You will have to use hyperslab selection to specify a portion of a dataset to write to.
Is that what you are trying to do?

Attached is a C example that shows how to append to a compound dataset in a loop.
The example extends an unlimited dimension dataset, and appends data to the extended portion of the dataset.

There is also a tutorial on reading/writing subsets here. The dataset does not have a compound type, but subsetting is the same:


C Example:
cmploop.c (3.9 KB)


1 Like