Is it possible to create a string attribute?

75 views
Skip to first unread message

Lorenzo Luengo

unread,
Dec 9, 2011, 12:55:39 PM12/9/11
to h5...@googlegroups.com
Hi, I would like to resemble a dataset containing an attribute like this

HDF5 "../data.mat" {
GROUP "/" {
DATASET "a" {
DATATYPE H5T_IEEE_F64LE
DATASPACE SIMPLE { ( 10, 10 ) / ( 10, 10 ) }
ATTRIBUTE "myattribute" {
DATATYPE H5T_STRING {
STRSIZE 6;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}
DATASPACE SCALAR
}
}
DATASET "b" {
...
}
}
}

But when I try to create a string type

strtype = h5t.create(h5t.STRING,6)

python complains "ValueError: Class must be COMPOUND or OPAQUE"...
Looking at
http://h5py.alfven.org/docs/low/h5t.html#datatype-class-codes, there
exists h5t.STRING, but it does not work. Is there something wrong with
my function calls?

Regards.

Andrew Collette

unread,
Dec 11, 2011, 5:57:07 PM12/11/11
to h5...@googlegroups.com
Hi,

> But when I try to create  a string type
>
> strtype = h5t.create(h5t.STRING,6)
>
> python complains "ValueError: Class must be COMPOUND or OPAQUE"... Looking
> at http://h5py.alfven.org/docs/low/h5t.html#datatype-class-codes, there
> exists h5t.STRING, but it does not work. Is there something wrong with my
> function calls?

It's a quirk of HDF5. You have to copy one of the existing low-level
string types. If you want a null-terminated fixed length C string,
you would do:

strtype = h5py.h5t.C_S1.copy()
strtype.set_size(6)

I agree this behavior is silly but it's exactly how the HDF5 C
interface works. :(

Andrew

Lorenzo Luengo

unread,
Dec 12, 2011, 11:39:47 AM12/12/11
to h5...@googlegroups.com
:S

Strange, but if it works, i will use it!

Thanks Andrew!


--
Lorenzo Luengo C.
Ingeniero Civil Electr�nico
Cel: 98270385

Reply all
Reply to author
Forward
0 new messages