|
26 | 26 | character(2048) :: name |
27 | 27 |
|
28 | 28 | 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" |
30 | 30 |
|
31 | 31 | id2name = name(:L) |
32 | 32 |
|
|
37 | 37 |
|
38 | 38 | character(:), allocatable :: laction |
39 | 39 | integer :: ier |
| 40 | +integer(HID_T) :: fapl !< file access property list |
| 41 | +integer :: file_mode |
40 | 42 |
|
41 | 43 | if(self%is_open()) then |
42 | 44 | write(stderr,*) 'h5fortran:open: file handle already open: '//self%filename |
43 | 45 | return |
44 | 46 | endif |
45 | 47 |
|
46 | | -laction = 'rw' |
47 | | -if(present(action)) laction = action |
| 48 | +laction = 'r' |
| 49 | +if (present(action)) laction = action |
48 | 50 |
|
49 | 51 | self%filename = filename |
50 | 52 |
|
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 |
54 | 54 |
|
| 55 | +!> compression parameter |
| 56 | +if(present(comp_lvl) .and. laction /= "r") self%comp_lvl = comp_lvl |
55 | 57 | if(self%comp_lvl > 0) then |
56 | 58 | self%shuffle = .true. |
57 | 59 | self%fletcher32 = .true. |
|
72 | 74 | call h5open_f(ier) |
73 | 75 | if (ier /= 0) error stop 'ERROR:h5fortran:open: HDF5 library initialize' |
74 | 76 |
|
75 | | -if(self%verbose) then |
| 77 | +if(self%debug) then |
76 | 78 | call h5eset_auto_f(1, ier) |
77 | 79 | else |
78 | 80 | call h5eset_auto_f(0, ier) |
79 | 81 | endif |
80 | 82 | if (ier /= 0) error stop 'ERROR:h5fortran:open: HDF5 library set traceback' |
81 | 83 |
|
| 84 | +fapl = H5P_DEFAULT_F |
| 85 | + |
82 | 86 | select case(laction) |
83 | 87 | 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 |
86 | 89 | 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 |
89 | 91 | case('rw', 'a') |
90 | 92 | 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 |
92 | 94 | else |
93 | | - call h5fcreate_f(filename, H5F_ACC_TRUNC_F, self%file_id, ier) |
| 95 | + file_mode = H5F_ACC_TRUNC_F |
94 | 96 | endif |
95 | 97 | case ('w') |
96 | | - call h5fcreate_f(filename, H5F_ACC_TRUNC_F, self%file_id, ier) |
| 98 | + file_mode = H5F_ACC_TRUNC_F |
97 | 99 | case default |
98 | | - error stop 'ERROR:h5fortran:open: Unsupported action: ' // laction |
| 100 | + error stop 'ERROR:h5fortran:open Unsupported action ' // laction // ' for ' // filename |
99 | 101 | end select |
100 | 102 |
|
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 |
102 | 113 |
|
103 | 114 | end procedure h5open |
104 | 115 |
|
|
298 | 309 |
|
299 | 310 | !> check for matching rank, else bad reads can occur--doesn't always crash without this check |
300 | 311 | 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 |
302 | 313 |
|
303 | 314 | if (drank == mrank) return |
304 | 315 |
|
305 | 316 | if (present(vector_scalar) .and. drank == 1 .and. mrank == 0) then |
306 | 317 | !! check if vector of length 1 |
307 | 318 | call h5ltget_dataset_info_f(self%file_id, dname, dims=ddims, & |
308 | 319 | 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 |
310 | 321 | if (ddims(1) == 1) then |
311 | 322 | vector_scalar = .true. |
312 | 323 | return |
|
0 commit comments