Pavel, how are you? 

> -----Original Message-----
> From: [email protected]
[mailto:[email protected]] On Behalf Of Pavel Rudchenko
> Sent: Sunday, March 06, 2011 4:59 PM
> To: HDF Users Discussion List
> Subject: Re: [Hdf-forum] Read and wrote string attributes
>
> Hello, thank you!
>
>Now I can write string attributes.
>But can't read it back...

Here's another snippet of IronPython that will get you started.
The method iterates over a dataset's (dset) attributes and reads/prints
its fixed-length string attributes:

def findScalarFixedStringAttribute(dset):

    info = H5O.getInfo(dset)
    for i in range(info.nAttributes):
        attr = H5A.openByIndex(dset, '.', H5IndexType.CRT_ORDER,
                               H5IterationOrder.INCREASING, Int64(i)) 
        dtype = H5A.getType(attr)
        tclass = H5T.getClass(dtype)

        # ignore variable length strings
        if tclass == H5T.H5TClass.STRING and not
H5T.isVariableString(dtype):

            mtype = H5T.getNativeType(dtype, H5T.Direction.ASCEND)
            buffer = Array.CreateInstance(Byte, H5T.getSize(mtype))
            H5A.read(attr, mtype, H5Array[Byte](buffer))

            enc = System.Text.ASCIIEncoding()
            fmt = 'Found string attribute; its index is %d , value = %s'
            print fmt % (i, enc.GetString(buffer))

            H5T.close(mtype)

        H5T.close(dtype)
        H5A.close(attr)

    return None

Best, G.



_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to