Hello, thank you!
Now I can write string attributes.
But can't read it back.
My InPtr pointer is 0:
H5FileId fileId = H5F.open("temp.hdf", H5F.OpenMode.ACC_RDONLY);
H5DataSetId dsetIdGeo = H5D.open(fileId, DSET2_NAME);
H5DataTypeId typeAttrIdGeo = H5T.copy(H5T.H5Type.C_S1);
H5ObjectInfo oinfoGeo = H5O.getInfo(dsetIdGeo);
string sourceName = null;
H5AttributeId attrId = H5A.open(dsetIdGeo, ATTR2_1_NAME);
unsafe
{
Chararray[] carray = new Chararray[2];
H5A.read(attrId, typeAttrIdGeo, new
H5Array<Chararray>(carray));
IntPtr ipp = (IntPtr)carray[0].RecordedText;
sourceName = Marshal.PtrToStringAnsi(ipp);
}
H5A.close(attrId);
H5T.close(typeAttrIdGeo);
H5D.close(dsetIdGeo);
H5F.close(fileId);
if (sourceName != null)
System.Console.WriteLine("sourceName = " + sourceName);
Why?
I can read string datasets (as in primer Program.cs in 'string'
folder), but not string attributes of datasets.
2011/3/2 Gerd Heber <[email protected]>:
> Pavel, how are you? If you want to write a fixed-length string scalar
> attribute,
> here's a snippet of IronPython code that will get you started.
>
> def addScalarStringAttribute(dset):
>
> string ='ABCD'
>
> dspace = H5S.create(H5S.H5SClass.SCALAR)
> dtype = H5T.copy(H5T.H5Type.C_S1)
> H5T.setSize(dtype, 5)
> attr = H5A.create(dset, 'Character attribute', dtype, dspace);
>
> enc = System.Text.ASCIIEncoding()
> H5A.write(attr, dtype, H5Array[System.Byte](enc.GetBytes(string)))
>
> H5A.close(attr)
> H5T.close(dtype)
> H5S.close(dspace)
> return None
>
> Best, G.
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> On Behalf Of Pavel Rudchenko
> Sent: Tuesday, March 01, 2011 1:16 PM
> To: [email protected]
> Subject: [Hdf-forum] Read and wrote string attributes
>
> Hello!
>
> How may I read and wrote string attributes od dataset?
> I use HDF5DotNet and C# .net 2010.
> I can't find an example and string type on H5T.H5Type.
>
> Thank you.
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
>
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
>
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org