ess-dmsc / h5cpp

C++ wrapper for the HDF5 C-library
https://ess-dmsc.github.io/h5cpp/
GNU Lesser General Public License v2.1
116 stars 19 forks source link

How to write data into an existing HDF5 dataset #633

Closed ZL-Su closed 1 year ago

ZL-Su commented 1 year ago

Hi, guys:

I have saved an HDF5 file, such as "x.h5", on the disk. I want to open an existing dataset, such as "data", from the file of x.h5 and replace some data in dataset "data". The code snippet is attached below, but it does not work -- the new data is not written successfully. So is there any way to make the above operation succeed ?

I am here looking for ur solution, thx.

auto group = m_file->root().get_group("g");
auto mask = group.get_dataset("data");
auto dims = dataspace::Simple(mask. Dataspace()).current_dimensions();
auto selec = dataspace::Hyperslab({ 0,0,0}, { dims[0],dims[1],1 }, { 1,1,1 });
mask.extent(2, 1);
selec.offset(2, m_summary->stage_index-options()->reference_idx);
mask. Write(cv::Mat1b(m_summary->qp_valmask), select);
yuelongyu commented 1 year ago

hi @ZL-Su ,

Your code snippet looks OK. Basically one needs

It would be good to show your full code or create a simple example to show your problem.

yuelongyu commented 1 year ago

hi @ZL-Su, have you resolved your problem?

ZL-Su commented 1 year ago

hi @yuelongyu, the problem has been solved, thx a lot.