|
39 | 39 |
|
40 | 40 | module procedure h5open
|
41 | 41 |
|
42 |
| -character(len=2) :: laction |
| 42 | +character(:), allocatable :: laction |
43 | 43 | integer :: ier
|
44 | 44 | integer(HID_T) :: fapl !< file access property list
|
| 45 | +integer :: file_mode |
45 | 46 |
|
46 | 47 | if(self%is_open()) then
|
47 | 48 | write(stderr,*) 'h5fortran:open: file handle already open: '//self%filename
|
48 | 49 | return
|
49 | 50 | endif
|
50 | 51 |
|
51 |
| -laction = 'rw' |
| 52 | +laction = 'r' |
52 | 53 | if (present(action)) laction = action
|
53 | 54 |
|
54 | 55 | self%filename = filename
|
|
103 | 104 |
|
104 | 105 | if(self%use_mpi) then
|
105 | 106 | !! collective: setup for MPI access
|
106 |
| - call h5pcreate_f(H5P_FILE_ACCESS_F, fapl, ier) |
| 107 | + call H5Pcreate_f(H5P_FILE_ACCESS_F, fapl, ier) |
107 | 108 | if(ier /= 0) error stop "ERROR:h5fortran:open:h5pcreate could not collective open property for " // filename
|
108 |
| - call h5pset_fapl_mpio_f(fapl, mpi_h5comm, mpi_h5info, ier) |
| 109 | + call H5Pset_fapl_mpio_f(fapl, mpi_h5comm, mpi_h5info, ier) |
109 | 110 | if(ier /= 0) error stop "ERROR:h5fortran:open:h5pset_fapl_mpio could not collective open file for " // filename
|
110 | 111 | else
|
111 | 112 | fapl = H5P_DEFAULT_F
|
112 | 113 | endif
|
113 | 114 |
|
114 | 115 | select case(laction)
|
115 | 116 | case('r')
|
116 |
| - if(.not. is_hdf5(filename)) error stop "ERROR:h5fortran:open: file does not exist: "//filename |
117 |
| - call h5fopen_f(filename, H5F_ACC_RDONLY_F, self%file_id, ier, access_prp=fapl) |
| 117 | + file_mode = H5F_ACC_RDONLY_F |
118 | 118 | case('r+')
|
119 |
| - if(.not. is_hdf5(filename)) error stop "ERROR:h5fortran:open: file does not exist: "//filename |
120 |
| - call h5fopen_f(filename, H5F_ACC_RDWR_F, self%file_id, ier, access_prp=fapl) |
| 119 | + file_mode = H5F_ACC_RDWR_F |
121 | 120 | case('rw', 'a')
|
122 | 121 | if(is_hdf5(filename)) then
|
123 |
| - call h5fopen_f(filename, H5F_ACC_RDWR_F, self%file_id, ier, access_prp=fapl) |
| 122 | + file_mode = H5F_ACC_RDWR_F |
124 | 123 | else
|
125 |
| - call h5fcreate_f(filename, H5F_ACC_TRUNC_F, self%file_id, ier, access_prp=fapl) |
| 124 | + file_mode = H5F_ACC_TRUNC_F |
126 | 125 | endif
|
127 | 126 | case ('w')
|
128 |
| - call h5fcreate_f(filename, H5F_ACC_TRUNC_F, self%file_id, ier, access_prp=fapl) |
| 127 | + file_mode = H5F_ACC_TRUNC_F |
129 | 128 | case default
|
130 | 129 | error stop 'ERROR:h5fortran:open Unsupported action ' // laction // ' for ' // filename
|
131 | 130 | end select
|
132 | 131 |
|
133 |
| -if (ier /= 0) error stop "ERROR:h5fortran:open: HDF5 file open failed: "//filename |
| 132 | +if (file_mode == H5F_ACC_RDONLY_F .or. file_mode == H5F_ACC_RDWR_F) then |
| 133 | + if(.not. is_hdf5(filename)) error stop "ERROR:h5fortran:open: not an HDF5 file: "//filename |
| 134 | + call H5Fopen_f(filename, file_mode, self%file_id, ier, access_prp=fapl) |
| 135 | + if (ier /= 0) error stop "ERROR:h5fortran:open:H5Fopen: " // filename |
| 136 | +elseif(file_mode == H5F_ACC_TRUNC_F) then |
| 137 | + call H5Fcreate_f(filename, file_mode, self%file_id, ier, access_prp=fapl) |
| 138 | + if (ier /= 0) error stop "ERROR:h5fortran:open:H5Fcreate: " // filename |
| 139 | +else |
| 140 | + error stop "ERROR:h5fortran:open: Unsupported file mode: " // filename |
| 141 | +endif |
134 | 142 |
|
135 | 143 | if(fapl /= H5P_DEFAULT_F) then
|
136 | 144 | call h5pclose_f(fapl, ier)
|
|
302 | 310 |
|
303 | 311 | !> check that all necessary filters to access dataset are available on the system.
|
304 | 312 | call h5dget_create_plist_f(dset_id, dcpl, ierr)
|
305 |
| -if (ierr/=0) error stop "h5fortran:mpi_hyperslab:h5dget_create_plist: " // dset_name |
| 313 | +if (ierr/=0) error stop "ERROR:h5fortran:mpi_hyperslab:h5dget_create_plist: " // dset_name |
306 | 314 |
|
307 | 315 | call h5pall_filters_avail_f(dcpl, filters_OK, ierr)
|
308 |
| -if (ierr/=0) error stop "h5fortran:mpi_hyperslab:h5pall_filters_avail: " // dset_name |
| 316 | +if (ierr/=0) error stop "ERROR:h5fortran:mpi_hyperslab:h5pall_filters_avail: " // dset_name |
309 | 317 | if (.not. filters_OK) then
|
310 | 318 | error stop "h5fortran: filter(s) missing necessary for dataset " // dset_name // " in parallel with MPI. This is " // &
|
311 | 319 | "typically caused by missing DEFLATE compression with HDF5-MPI."
|
312 | 320 | endif
|
313 | 321 |
|
314 | 322 | call h5pclose_f(dcpl, ierr)
|
315 |
| -if(ierr/=0) error stop "h5fortran:mpi_hyperslab:h5pclose: " // dset_name |
| 323 | +if(ierr/=0) error stop "ERROR:h5fortran:mpi_hyperslab:h5pclose: " // dset_name |
| 324 | + |
| 325 | +istride = 1 |
| 326 | +if(present(stride)) istride = int(stride, HSIZE_T) |
316 | 327 |
|
317 | 328 | if(filespace == H5S_ALL_F) then
|
318 | 329 | !> create dataspace
|
319 | 330 | call h5screate_simple_f(rank=size(dset_dims), dims=dset_dims, space_id=filespace, hdferr=ierr)
|
320 |
| - if (ierr/=0) error stop "h5fortran:mpi_hyperslab:h5screate_simple:filespace " // dset_name |
| 331 | + if (ierr/=0) error stop "ERROR:h5fortran:mpi_hyperslab:h5screate_simple:filespace " // dset_name |
321 | 332 | endif
|
322 | 333 |
|
323 | 334 | !> Select hyperslab in the file.
|
324 | 335 | call h5dget_space_f(dset_id, filespace, ierr)
|
325 |
| -if (ierr/=0) error stop "h5fortran:mpi_hyperslab:h5dget_space: " // dset_name |
| 336 | +if (ierr/=0) error stop "ERROR:h5fortran:mpi_hyperslab:h5dget_space: " // dset_name |
326 | 337 |
|
327 | 338 |
|
328 | 339 | ! blk(1) = 1
|
|
332 | 343 | i0 = istart - 1
|
333 | 344 | c_mem_dims = iend - i0
|
334 | 345 |
|
335 |
| -istride = 1 |
336 |
| -if(present(stride)) istride = int(stride, HSIZE_T) |
337 |
| - |
338 | 346 | if(any(c_mem_dims /= mem_dims)) then
|
339 | 347 | write(stderr,*) "ERROR:h5fortran:mpi_hyperslab: memory size /= dataset size: check variable slice (index). " // &
|
340 | 348 | " Dset_dims:", dset_dims, "C Mem_dims", c_mem_dims
|
|
343 | 351 |
|
344 | 352 | ! print *, 'TRACE:mpi_hyperslab: ' // dset_name //': istart', i0, 'C mem_dims: ', c_mem_dims, 'mem_dims', mem_dims
|
345 | 353 |
|
346 |
| -if(any(c_mem_dims < 1)) error stop "h5mpi:hyperslab:non-positive hyperslab: " // dset_name |
| 354 | +if(any(c_mem_dims < 1)) error stop "ERROR:h5mpi:hyperslab:non-positive hyperslab: " // dset_name |
347 | 355 |
|
348 | 356 | call h5sselect_hyperslab_f(filespace, H5S_SELECT_SET_F, &
|
349 | 357 | start=i0, &
|
|
352 | 360 | hdferr=ierr)
|
353 | 361 | ! block=blk !< would this help performance?
|
354 | 362 |
|
355 |
| -if (ierr/=0) error stop "g5fortran:mpi_hyperslab:h5sselect_hyperslab: " // dset_name |
| 363 | +if (ierr/=0) error stop "ERROR:h5fortran:mpi_hyperslab:h5sselect_hyperslab: " // dset_name |
356 | 364 |
|
357 | 365 | !> create memory dataspace
|
358 | 366 | call h5screate_simple_f(rank=size(c_mem_dims), dims=c_mem_dims, space_id=memspace, hdferr=ierr)
|
359 |
| -if (ierr/=0) error stop "h5fortran:mpi_hyperslab:h5screate_simple:memspace " // dset_name |
| 367 | +if (ierr/=0) error stop "ERROR:h5fortran:mpi_hyperslab:h5screate_simple:memspace " // dset_name |
360 | 368 |
|
361 | 369 | end procedure mpi_hyperslab
|
362 | 370 |
|
|
367 | 375 |
|
368 | 376 | !! Create property list for collective dataset operations
|
369 | 377 | call h5pcreate_f(H5P_DATASET_XFER_F, xfer_id, ierr)
|
370 |
| -if (ierr/=0) error stop "h5pcreate dataset xfer: " // dname |
| 378 | +if (ierr/=0) error stop "ERROR:h5fortran:h5pcreate dataset xfer: " // dname |
371 | 379 |
|
372 | 380 | call h5pset_dxpl_mpio_f(xfer_id, H5FD_MPIO_COLLECTIVE_F, ierr)
|
373 |
| -if (ierr/=0) error stop "h5pset_dxpl_mpio collective: " // dname |
| 381 | +if (ierr/=0) error stop "ERROR:h5fortran:h5pset_dxpl_mpio collective: " // dname |
374 | 382 |
|
375 | 383 | ! For independent dataset operations
|
376 | 384 | ! call h5pset_dxpl_mpio_f(xfer_id, H5FD_MPIO_INDEPENDENT_F, ierr)
|
|
0 commit comments