Hi Landon:

Thanks for the response. Actually I'm not talking about file objects,
but /file images/, which is basically the whole file stored in some
buffer in memory. Imagine you use std::fstream::read() or the classic C
FILE's fread() to read the whole file into memory, and then wanting to
open it with the HDF5 library. This is why I'm using
"H5LTopen_file_image()", which doesn't take a file name or file path,
but takes a void* buffer, which is a pointer to the array where the file
is stored /in memory/.

Now after opening that using "H5LTopen_file_image()", we'll get an HDF5
file object (or file handle), the one you're talking about. My question
is: Now after we do the changes to the file under that object, and after
we H5Fflush(), that buffer may be changed. My question is: How do we
keep track of that buffer (and its size) to write it back to a file
eventually (using a std::fstream::write() or the classic C FILE's fwrite())?

I would appreciate the help of anyone who knows about this.

Best,
Samer Afach


On 27.12.2016 12:19 AM, Landon Clipp wrote:
> 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]
> <mailto:[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:
>
>     
> voidWriteStringAttribute(hid_tdataset_id,conststd::string&name,conststd::string&value)
>     {
>     hid_tAttributeType=H5Tcopy(H5T_C_S1);
>     H5Tset_size(AttributeType,value.length());
>     hid_tdataspaceHandle=H5Screate(H5S_SCALAR);
>     
> hid_tAttrHandle=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]
>     <mailto:[email protected]>
>     http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
>     <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
_______________________________________________
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