Failed to add Group to h5 file via H5G.create

1 Ansicht (letzte 30 Tage)
raym
raym am 4 Aug. 2018
Beantwortet: Jeremiah Hess am 22 Aug. 2021
%%1st step: create a h5 file and close it
fn = 'D:\QMDownload\3\example.h5';
fid = H5F.create(fn);
gid = H5G.open(fid,'/');
plist = 'H5P_DEFAULT';
gid1 = H5G.create(gid,'group1',plist,plist,plist);
gid2 = H5G.create(gid1,'group11',plist,plist,plist);
gid3 = H5G.create(gid2,'group111',plist,plist,plist);
H5G.close(gid);
H5G.close(gid1);
H5G.close(gid2);
H5G.close(gid3);
H5F.close(fid);
h5disp(fn)
% now add another group
fid = H5F.open(fn);
gid = H5G.open(fid,'/group1');
plist = 'H5P_DEFAULT';
gid1 = H5G.create(gid,'group12',plist,plist,plist);
Error appears:
Error using hdf5lib2
The HDF5 library encountered an error and produced the following stack trace information:
H5G__obj_create_real no write intent on file
H5G__obj_create unable to create group
H5G__create unable to create group object header
H5O_group_create unable to create group
H5O_obj_create unable to open object
H5L_link_cb unable to create object
H5G_traverse_real traversal operator failed
H5G_traverse internal path traversal failed
H5L_create_real can't insert link
H5L_link_object unable to create new link to object
H5G__create_named unable to create and link to group
H5Gcreate2 unable to create group
Error in H5G.create (line 27)
group_id = H5ML.hdf5lib2('H5Gcreate', varargin{:});

Akzeptierte Antwort

Jeremiah Hess
Jeremiah Hess am 22 Aug. 2021
Hey! It's been a while since this question was asked, but I encountered the same problem and managed to figure out the solution, so I'm posting it here to help any future members.
The simple explanation for the error is that the low-level function H5F.open defaults to opening the file in read-only mode, making it impossible to create new groups or datasets in the file. A simple look at the H5F.open documentation yields the following solution:
% now add another group
plist = 'H5P_DEFAULT';
fid = H5F.open(fn,'H5F_ACC_RDWR',plist); % Opens the file in read-write mode
gid = H5G.open(fid,'/group1');
gid1 = H5G.create(gid,'group12',plist,plist,plist);

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by