H5F.close(fid) flush was delayed, and cause problem when calling h5create afterwards

8 Ansichten (letzte 30 Tage)
Hi, I am using low-level H5 commands to create a h5 file and do something on it, then close it. Then I use h5 high-level function h5create to create/write some numeric data into the file.
If I wrap all the codes into a single function, error take place when call h5create. I noticed that the file size is 0, thus not flushed immediately.
If I take the h5create out, and call the function 1st, the file is flushed as expected, and then call h5create with no problem.
If I run all the code in script but not wapped into function, the same error take place: the flushed still failed.
Thus it seems that the low-level codes need to be wrapped into a function to enable immediately flush and enable subsequent high-level function calling. Is there a way to enable the successive call of low-level and high-level command inside a single function? What code should I add in between to force the flush into disk? I tried "pause(5)" but it did not work.
Thanks.
%% Script-failed
afn = 'GSE51.h5';
fid = H5F.create(afn);
gid = H5G.open(fid,'/');
plist = 'H5P_DEFAULT';
gid = H5G.create(gid,'/group1',plist,plist,plist);
H5F.close(fid)
h5create(afn,['/matrix'],[Inf,Inf],'ChunkSize',[8,8],'Deflate',1);
Error using h5create>validate_options (line 133)
'GSE5.h5' is not an HDF5 file.
Error in h5create (line 67)
options = validate_options(p.Results);
%% function-failed
function test1_failed
afn = 'GSE52.h5';
fid = H5F.create(afn);
gid = H5G.open(fid,'/');
plist = 'H5P_DEFAULT';
gid = H5G.create(gid,'/group1',plist,plist,plist);
H5F.close(fid);pause(5);% pause not work
h5create(afn,['/matrix'],[Inf,Inf],'ChunkSize',[8,8],'Deflate',1);
end
test1_failed;
Error using h5create>validate_options (line 133)
'GSE52.h5' is not an HDF5 file.
Error in h5create (line 67)
options = validate_options(p.Results);
%% split, ok
function test2_then_call_succeed
afn = 'GSE53.h5';
fid = H5F.create(afn);
gid = H5G.open(fid,'/');
plist = 'H5P_DEFAULT';
gid = H5G.create(gid,'/group1',plist,plist,plist);
H5F.close(fid)
end
% move out the high-level function, ok
test2_then_call_succeed;
h5create(afn,['/matrix'],[Inf,Inf],'ChunkSize',[8,8],'Deflate',1);

Akzeptierte Antwort

raym
raym am 28 Jul. 2023
Bearbeitet: raym am 28 Jul. 2023
solved by
H5F.flush(fid,'H5F_SCOPE_GLOBAL')
H5F.close(fid)

Weitere Antworten (0)

Kategorien

Mehr zu Preprocessing Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by