Hello Samer, I think I get the gist of what you're asking. If you are writing to the object and then want to read from the updated file, you will need to call H5Fflush() in order to write your data buffers to the file on your disk. Modifying objects on your file does not actually immediately change the file itself. The changes are only made when the object and/or file is closed or flushed. I believe that should solve your problem.
Regards, Landon Clipp On Thu, Dec 22, 2016 at 2:39 AM, Samer Afach <[email protected]> wrote: > Hello guys: > > In a program, I use some relatively small HDF5 files multiple times and > transfer them then through TCP/IP, so I read them into memory as > `std::string`, and then read them as HDF5 using: > > fileHandle = H5LTopen_file_image((void*)&FileImage.front(),FileImage. > size(),H5LT_FILE_IMAGE_OPEN_RW); > *My question is:* Since I'm opening this as RW, how can I write an > attribute to it and retrieve the image back? > > The motivation behind my question is simple. I have a simple function that > can write an attribute to an object by its ID. Here it's: > > void WriteStringAttribute(hid_t dataset_id, const std::string& name, const > std::string& value) > { hid_t AttributeType = H5Tcopy(H5T_C_S1); H5Tset_size(AttributeType, > value.length()); hid_t dataspaceHandle = H5Screate(H5S_SCALAR); hid_t > AttrHandle = H5Acreate(dataset_id, name.c_str(), AttributeType, > dataspaceHandle, H5P_DEFAULT,H5P_DEFAULT); H5Awrite(AttrHandle, > AttributeType, &value.front()); > > H5Aclose (AttrHandle); H5Sclose (dataspaceHandle); > } > > > What I don't understand is that after writing the attribute using this > function (Is it right to do this? > > WriteStringAttribute(fileHandle, "MyAttr", "MyAttrValue"); > > ), the image size should've been changed. How can I get the new correct > image size and write it back to a file (or do anything else with it, for > that matter)? > > Thank you. > > Best, > 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 >
_______________________________________________ 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
