I need an HDF5 Dataset Attribute to be a string

Asked

Viewed 28 times

1

Good afternoon, I’m trying to create some attributes for my datasets, I was able to create the attributes but at the time of setting their values (strings) I’m not getting, I tried several different ways, and currently the string that appears seems to be bugged or in another format... The code I’m using is below:

I was able to create the attributes "Eng. Unit" and "Atrib2", but I cannot set their values as "Temperate" and "Test", respectively

        foreach (BasicVariable bv in pf.basicVariableList.bvList)
        {               
            H5DataSetId dataSetId = H5D.create(bvGroupId, bv.bvTag, typeId, spaceId);
            bv.atribList.Add(new Atribbs("Eng. Unit", "Temperatura"));
            bv.atribList.Add(new Atribbs("Atrib2", "Teste"));
            foreach(Atribbs a in bv.atribList )
            {


                H5DataTypeId auxDT = H5T.copy(H5T.H5Type.C_S1);
                H5T.setSize(auxDT, H5T.getSize(H5T.H5Type.C_S1));
                const int auxData = 2;
                long[] auxDim = new long[1];
                auxDim[0] = 1;
                H5DataSpaceId auxDS = H5S.create_simple(1, auxDim);


                var attr_id = H5A.create(dataSetId, a.attName, auxDT, auxDS);
                byte[] bytes = Encoding.UTF8.GetBytes(a.valueStr);
                var atrData = new string[] { Encoding.Default.GetString(bytes)};
                H5A.write<string>(attr_id, auxDT, new H5Array<string>(atrData));

                H5A.close(attr_id);
            }
            H5D.close(dataSetId);
        }
        H5F.close(fileId);

On the HDF View screen they appear like this

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

No answers

Browser other questions tagged

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