Skip to content

Commit adca049

Browse files
committed
bugfix: handle unknown with not existing file
1 parent 0bbcae8 commit adca049

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/hdf5_interface.f90

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ subroutine hdf_initialize(self,filename,ierr, status,action,comp_lvl,chunk_size,
322322
endif
323323
call h5fopen_f(filename,H5F_ACC_RDONLY_F,self%lid,ierr)
324324
case('write','readwrite','w','rw', 'r+', 'append', 'a')
325-
call h5fopen_f(filename,H5F_ACC_RDWR_F,self%lid,ierr)
325+
inquire(file=filename, exist=exists)
326+
if(lstatus == 'unknown' .and. .not.exists) then
327+
call h5fopen_f(filename, H5F_ACC_TRUNC_F, self%lid,ierr)
328+
else
329+
call h5fopen_f(filename, H5F_ACC_RDWR_F, self%lid,ierr)
330+
endif
326331
if (check(ierr, 'ERROR: ' // filename // ' could not be opened')) return
327332
case default
328333
write(stderr,*) 'Unsupported action -> ' // laction

src/tests/test_hdf5_ifc.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ subroutine test_write_attributes(path)
215215
type(hdf5_file) :: h5f
216216
character(*), intent(in) :: path
217217

218-
call h5f%initialize(path//'/test_deflate.h5', ierr)
218+
call h5f%initialize(path//'/test.h5', ierr)
219219

220-
call h5f%writeattr('/little/','note','this is just a little number', ierr)
220+
call h5f%writeattr('/nan','note','this is just a little number', ierr)
221221
if (ierr /= 0) error stop 'write attribute string'
222222

223223
call h5f%finalize(ierr)

0 commit comments

Comments
 (0)