Dear Gerd, Dear experts in hdf:
The problem is even beyond reading the string (the string I
wrote is a scalar). Here I present the problem.
To make the problem clearer, I created a compilable minimal
example by truncating parts of my program and resorting it,
in order to show the problem's weird behavior. Please
compile the main.cpp file with
g++ main.cpp
-std=c++11 -lhdf5_hl -lhdf5 -lhdf5_hl_cpp -lhdf5_cpp
-lszip -lz -ldl -o exe
The program creates a data file, writes it, reads it again
to a string buffer, then opens it with
H5LTopen_file_image(). This will cause the program to crash
when trying to read attributes. Nothing works properly with
image opening for some reason. I even introduced
std::vector<char> to ensure contiguity in memory.
On the other hand, the provided Example.hdf5, which was
provided by a colleague, and produced with Labview, and is
only different that it uses a compound type, can be read by
my program with no problems at all. All you have to do, is
uncomment the part of the code that has the file name
Example.hdf5 in main.cpp, and see how attributes get printed
with no problems.
I really, really would appreciate your help. I'm so shocked
because my software was supposed to be ready today and I was
supposed to present it, and this problem suddenly happened.
Now I'm giving excuses to people on why it's not done. I've
been working on this for more than 8 hours with no result.
Thank you, and I really appreciate any efforts.
All the best,
Samer
On 23.07.2015 21:16, Gerd Heber
wrote:
Is the string a (1) fixed-length or (2) variable-length string?
(What does h5dump say? Or programmatically via "htri_t H5Tis_variable_str( hid_t dtype_id )"...)
Your code should work fine for (2) and a scalar attribute, but won't work with (1).
You'd have to allocate the buffer for the string(s) in (1) yourself.
G.
-----Original Message-----
From: Hdf-forum [mailto:[email protected]] On Behalf Of [email protected]
Sent: Thursday, July 23, 2015 11:55 AM
To: HDF Users Discussion List
Subject: [Hdf-forum] Weird H5Aread() error in HDF5 files - possibly a bug
Dear pros:
So a colleague of mine created an HDF5 for testing purposes using Labview, and I used my C++ program to read attributes from it, and that worked with the attached function with no problem.
Now I created my own HDF5 files with exactly the same structure, but with the difference that I'm using non-compound types. The attribute names are exactly the same. So I started my program and loaded my new files exactly like I do with the other files I got from my colleague, and got a crash. I pursued the issue with a debugger and found the situation attached in the image. It's a very weird situation that I can't understand. On the right, you'll find that all values are positive and read return is zero (so no error), and yet the assignment operator is throwing an error and the variable str, which is char*, is not accessible.
How could this happen? I could provide any additional information you require.
Thank you for any help you provide.
All the best,
Samer
_______________________________________________
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