Samer, how are you? The problem is that the string in the file is a so-called 
‘variable-length string.’
(See https://www.hdfgroup.org/HDF5/doc/UG/UG_frame11Datatypes.html)
From an API perspective, the main difference is that the library allocates the 
buffer
for such string(s). You attempt (around line 52) to guestimate the string size 
is laudable but misguided.
Instead of passing a pointer to H5Aread, you should pass a pointer to a 
pointer, i.e.,
replace line 54 with just the definition “char* date;” and pass “(void*) &date” 
to H5Aread.
Does that work for you?

G.



From: Hdf-forum [mailto:[email protected]] On Behalf Of 
Samer Afach
Sent: Friday, July 10, 2015 3:22 PM
To: [email protected]
Subject: [Hdf-forum] Reading a string attribute in HDF5

Dear all:

A colleague of mine used labview to write an ASCII string as an attribute in an 
HDF5 file. I can see that the attribute exist, and read it, but I can't print 
it.

The attribute is, as shown in HDF Viewer: Date = 2015\07\09

So "Date" is its name.

I'm trying to read the attribute, and it's not working, and I'm getting a 
messed set of characters. I created a self-contained code and put it in the 
attachment together with the HDF5 file.

I tried changing the type to H5T_C_S1, but that throw an error and doesn't work.

Could you please tell me why my code isn't reading the date attribute?

Thanks,
Samer Afach


_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to