H5CREATE_GROUP create HDF5 group
Contents
Inputs
- file: HDF5 file (string or H5ML.id)
- hpath: HDF5 group/dataset -- ensure final character is '/' if hpath is only a group
Outputs
function fid = h5create_group(file, hpath)
if isa(file, 'H5ML.id')
fid = file;
else
dcpl = 'H5P_DEFAULT';
try
fid = H5F.open(file, 'H5F_ACC_RDWR', dcpl);
catch e
switch e.identifier
case {'MATLAB:imagesci:hdf5io:resourceNotFound', 'MATLAB:imagesci:hdf5lib:fileOpenErr'}
fid = H5F.create(file);
otherwise
rethrow(e)
end
end
end
grps = split(hpath, '/');
if length(grps) < 3
return
end
plist = 'H5P_DEFAULT';
groot = H5G.open(fid, '/');
for i = 0:length(grps) - 3
n = join(grps(1:i+2), '/');
n = n{1};
if ~H5L.exists(groot, n, plist)
gid = H5G.create(fid, n, plist, plist, plist);
H5G.close(gid)
end
end
H5G.close(groot)
if nargout == 0
H5F.close(fid);
clear('fid')
end
end