Skip to content

Commit 7665cc2

Browse files
committed
open(verbose=) removed. Default action='r' (was 'rw' but not documented before)
1 parent 9e62a8d commit 7665cc2

12 files changed

+53
-40
lines changed

API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ call h%open(filename, action, comp_lvl)
3131
!! Opens hdf5 file
3232
3333
character(*), intent(in) :: filename
34-
character(*), intent(in), optional :: action !< r, w, rw
34+
character(*), intent(in), optional :: action !< 'r', 'r+', 'w', 'rw' (default 'r')
3535
integer, intent(in), optional :: comp_lvl !< 0: no compression. 1-9: ZLIB compression, higher is more compressior
3636
```
3737

Examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ call h5f%write_group('/scope/')
272272
call h5f%close()
273273
```
274274

275-
## verbose / debug
275+
## debug
276276

277-
set options debug and /or verbose for diagnostics
277+
for diagnostic prints:
278278

279279
```sh
280-
call h5f%open(..., verbose=.true., debug=.true.)
280+
call h5f%open(..., debug=.true.)
281281
```
282282

283283
## Permissive syntax

codemeta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"@type": "SoftwareSourceCode",
44
"codeRepository": "https://github.com/geospace-code/h5fortran",
55
"contIntegration": "https://github.com/geospace-code/h5fortran/actions",
6-
"dateModified": "2022-07-13",
6+
"dateModified": "2022-07-20",
77
"downloadUrl": "https://github.com/geospace-code/h5fortran/releases",
88
"issueTracker": "https://github.com/geospace-code/h5fortran/issues",
99
"name": "h5fortran",
10-
"version": "4.7.1",
10+
"version": "4.8.0",
1111
"identifier": "10.5281/zenodo.3757269",
1212
"description": "Lightweight object-oriented HDF5 Fortran interface",
1313
"applicationCategory": "file I/O",

src/interface.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module h5fortran
2121
character(:), allocatable :: filename
2222
integer(HID_T) :: file_id
2323

24-
logical :: verbose=.true.
2524
logical :: debug=.false.
2625
logical :: fletcher32 = .false.
2726
logical :: shuffle = .false.
@@ -307,7 +306,7 @@ module subroutine h5write_6d(self, dname, A, chunk_size, istart, iend, stride, c
307306
logical, intent(in), optional :: compact
308307
end subroutine
309308

310-
module subroutine h5write_7d(self,dname,A, chunk_size, istart, iend, stride, compact, dset_dims)
309+
module subroutine h5write_7d(self, dname, A, chunk_size, istart, iend, stride, compact, dset_dims)
311310
class(hdf5_file), intent(in) :: self
312311
character(*), intent(in) :: dname
313312
class(*), intent(in) :: A(:,:,:,:,:,:,:)
@@ -577,20 +576,21 @@ module function id2name(id)
577576
character(:), allocatable :: id2name
578577
end function
579578

580-
module subroutine h5open(self, filename, action, comp_lvl, shuffle, fletcher32, verbose, debug)
579+
module subroutine h5open(self, filename, action, comp_lvl, shuffle, fletcher32, debug)
581580
!! open/create file
582581
!!
583582
!! PARAMETERS:
584583
!! ----------
585584
!! filename
586585
!! action: "r", "w", "rw"
586+
587587
class(hdf5_file), intent(inout) :: self
588588
character(*), intent(in) :: filename
589589
character(*), intent(in), optional :: action !< r, r+, rw, w, a
590590
integer, intent(in), optional :: comp_lvl !< 0: no compression. 1-9: ZLIB compression, higher is more compressior
591591
logical, intent(in), optional :: shuffle
592592
logical, intent(in), optional :: fletcher32
593-
logical, intent(in), optional :: verbose, debug
593+
logical, intent(in), optional :: debug
594594
end subroutine
595595

596596
module subroutine h5close(self, close_hdf5_interface)

src/utils.f90

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
character(2048) :: name
2727

2828
call h5iget_name_f(id, name, len(name, SIZE_T), L, ierr)
29-
if(ierr /= 0) error stop "h5fortran:id2name:h5iget_name"
29+
if(ierr /= 0) error stop "ERROR:h5fortran:id2name:h5iget_name"
3030

3131
id2name = name(:L)
3232

@@ -37,21 +37,23 @@
3737

3838
character(:), allocatable :: laction
3939
integer :: ier
40+
integer(HID_T) :: fapl !< file access property list
41+
integer :: file_mode
4042

4143
if(self%is_open()) then
4244
write(stderr,*) 'h5fortran:open: file handle already open: '//self%filename
4345
return
4446
endif
4547

46-
laction = 'rw'
47-
if(present(action)) laction = action
48+
laction = 'r'
49+
if (present(action)) laction = action
4850

4951
self%filename = filename
5052

51-
if (present(comp_lvl) .and. laction /= "r") self%comp_lvl = comp_lvl
52-
if (present(verbose)) self%verbose = verbose
53-
if (present(debug)) self%debug = debug
53+
if(present(debug)) self%debug = debug
5454

55+
!> compression parameter
56+
if(present(comp_lvl) .and. laction /= "r") self%comp_lvl = comp_lvl
5557
if(self%comp_lvl > 0) then
5658
self%shuffle = .true.
5759
self%fletcher32 = .true.
@@ -72,33 +74,42 @@
7274
call h5open_f(ier)
7375
if (ier /= 0) error stop 'ERROR:h5fortran:open: HDF5 library initialize'
7476

75-
if(self%verbose) then
77+
if(self%debug) then
7678
call h5eset_auto_f(1, ier)
7779
else
7880
call h5eset_auto_f(0, ier)
7981
endif
8082
if (ier /= 0) error stop 'ERROR:h5fortran:open: HDF5 library set traceback'
8183

84+
fapl = H5P_DEFAULT_F
85+
8286
select case(laction)
8387
case('r')
84-
if(.not. is_hdf5(filename)) error stop "ERROR:h5fortran:open: file does not exist: "//filename
85-
call h5fopen_f(filename, H5F_ACC_RDONLY_F, self%file_id,ier)
88+
file_mode = H5F_ACC_RDONLY_F
8689
case('r+')
87-
if(.not. is_hdf5(filename)) error stop "ERROR:h5fortran:open: file does not exist: "//filename
88-
call h5fopen_f(filename, H5F_ACC_RDWR_F, self%file_id, ier)
90+
file_mode = H5F_ACC_RDWR_F
8991
case('rw', 'a')
9092
if(is_hdf5(filename)) then
91-
call h5fopen_f(filename, H5F_ACC_RDWR_F, self%file_id, ier)
93+
file_mode = H5F_ACC_RDWR_F
9294
else
93-
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, self%file_id, ier)
95+
file_mode = H5F_ACC_TRUNC_F
9496
endif
9597
case ('w')
96-
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, self%file_id, ier)
98+
file_mode = H5F_ACC_TRUNC_F
9799
case default
98-
error stop 'ERROR:h5fortran:open: Unsupported action: ' // laction
100+
error stop 'ERROR:h5fortran:open Unsupported action ' // laction // ' for ' // filename
99101
end select
100102

101-
if (ier /= 0) error stop "ERROR:h5fortran:open: HDF5 file open failed: "//filename
103+
if (file_mode == H5F_ACC_RDONLY_F .or. file_mode == H5F_ACC_RDWR_F) then
104+
if(.not. is_hdf5(filename)) error stop "ERROR:h5fortran:open: not an HDF5 file: "//filename
105+
call H5Fopen_f(filename, file_mode, self%file_id, ier, access_prp=fapl)
106+
if (ier /= 0) error stop "ERROR:h5fortran:open:H5Fopen: " // filename
107+
elseif(file_mode == H5F_ACC_TRUNC_F) then
108+
call H5Fcreate_f(filename, file_mode, self%file_id, ier, access_prp=fapl)
109+
if (ier /= 0) error stop "ERROR:h5fortran:open:H5Fcreate: " // filename
110+
else
111+
error stop "ERROR:h5fortran:open: Unsupported file mode: " // filename
112+
endif
102113

103114
end procedure h5open
104115

@@ -298,15 +309,15 @@
298309

299310
!> check for matching rank, else bad reads can occur--doesn't always crash without this check
300311
call h5ltget_dataset_ndims_f(self%file_id, dname, drank, ierr)
301-
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check: get_dataset_ndim ' // dname // ' read ' // self%filename
312+
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check:get_dataset_ndims: ' // dname // ' in ' // self%filename
302313

303314
if (drank == mrank) return
304315

305316
if (present(vector_scalar) .and. drank == 1 .and. mrank == 0) then
306317
!! check if vector of length 1
307318
call h5ltget_dataset_info_f(self%file_id, dname, dims=ddims, &
308319
type_class=type_class, type_size=type_size, errcode=ierr)
309-
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check: get_dataset_info ' // dname // ' read ' // self%filename
320+
if (ierr/=0) error stop 'ERROR:h5fortran:rank_check:get_dataset_info ' // dname // ' in ' // self%filename
310321
if (ddims(1) == 1) then
311322
vector_scalar = .true.
312323
return

src/write_scalar.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
integer(HSIZE_T) :: dims(0)
1414
integer :: ier, L
1515

16-
if(.not.self%is_open()) error stop 'h5fortran:write: file handle is not open'
16+
if(.not.self%is_open()) error stop 'ERROR:h5fortran:write: file handle is not open'
1717

1818
select type (A)
1919
type is (real(real32))
@@ -32,7 +32,7 @@
3232
L = len(A) !< workaround for GCC 8.3.0 bug
3333
call hdf_create(self, dname, H5T_NATIVE_CHARACTER, dims, dims, file_space_id, dset_id, dtype_id, charlen=L)
3434
call h5dwrite_f(dset_id, dtype_id, A, dims, ier)
35-
if (ier /= 0) error stop 'h5fortran:write:string: could not write ' // dname // ' to ' // self%filename
35+
if (ier /= 0) error stop 'ERROR:h5fortran:write:string: could not write ' // dname // ' to ' // self%filename
3636
call h5tclose_f(dtype_id, ier)
3737
class default
3838
error stop "ERROR:h5fortran:write: unsupported type for " // dname

src/writer.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type is (character(*))
2727
charlen = len(A)
2828
dtype = H5T_NATIVE_CHARACTER
2929
class default
30-
error stop "unknown variable type for " // dname
30+
error stop "ERROR:h5fortran:writer:unknown variable type for " // dname
3131
end select
3232

3333
call hdf_create(self, dname, dtype, mem_dims, dims_dset, file_space_id, dset_id, &

test/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ else()
3333
endif()
3434
set_tests_properties(${name} PROPERTIES
3535
FIXTURES_REQUIRED h5lib
36-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
3736
)
3837

3938
if(${name} MATCHES ".*fail.*")
@@ -179,4 +178,7 @@ DISABLED $<NOT:$<BOOL:${h5ls}>>
179178

180179
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
181180

182-
set_tests_properties(${test_names} PROPERTIES TIMEOUT 60)
181+
set_tests_properties(${test_names} PROPERTIES
182+
TIMEOUT 60
183+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
184+
)

test/test_array.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ program array_test
1515
call test_write_slice('test_array.h5')
1616
print *, 'PASSED: slice write'
1717

18-
call test_readwrite_array('test_group_array.f90', ng=69, nn=100, pn=5)
18+
call test_readwrite_array('test_group_array.h5', ng=69, nn=100, pn=5)
1919
print *,'PASSED: array write / read'
2020

2121

@@ -49,7 +49,7 @@ subroutine test_basic_array(filename)
4949
r1 = i1
5050
r2 = i2
5151

52-
call h%open(filename, action='w', comp_lvl=1, verbose=.False.)
52+
call h%open(filename, action='w', comp_lvl=1)
5353

5454
call h%write('/int32-1d', i1)
5555
call h%write('/test/group2/int32-2d', i2)
@@ -59,7 +59,7 @@ subroutine test_basic_array(filename)
5959
call h%close()
6060

6161
!! read
62-
call h%open(filename, action='r', verbose=.false.)
62+
call h%open(filename, action='r')
6363

6464
!> int32
6565
call h%read('/int32-1d', i1t)
@@ -146,7 +146,7 @@ subroutine test_write_slice(filename)
146146
integer(int32), dimension(4,4) :: i2t
147147

148148

149-
call h%open(filename, action='r+', verbose=.true., debug=.true.)
149+
call h%open(filename, action='r+', debug=.true.)
150150

151151
call h%create('/int32a-1d', dtype=H5T_NATIVE_INTEGER, dset_dims=int([3], hsize_t))
152152
call h%write('/int32a-1d', [1,3], istart=[1], iend=[2])

test/test_fail_nonexist_variable.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ program nonexistvar
77
type(hdf5_file) :: h
88
character(*), parameter :: filename = 'bad.h5'
99

10-
call h%open(filename, action='r', verbose=.false.)
10+
call h%open(filename, action='r')
1111
call h%read('/not-exist', u)
1212
call h%close()
1313

0 commit comments

Comments
 (0)