Read this rank's block of arrayName, elements elemOffset+1 .. elemOffset+nLocal, into hfArray(1:Np,1:Np,1:Np,1:nLocal). nLocal may be 0.
The dataset must have shape (Np,Np,Np,nGlobalElem), matching hfArray's nodal extents: a dataset written at another polynomial degree holds values at other nodes, so this stops rather than reading a sub-block of it. The check uses only the dataset's metadata, so every rank, including one with nLocal = 0, reaches the same decision.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=HID_T), | intent(in) | :: | fileId | |||
| character, | intent(in) | :: | arrayName | |||
| real(kind=prec), | intent(inout) | :: | hfArray(:,:,:,:) | |||
| integer, | intent(in) | :: | elemOffset | |||
| integer, | intent(in) | :: | nGlobalElem | |||
| logical, | intent(in) | :: | parallel |
subroutine ReadSetArray_HDF5(fileId,arrayName,hfArray,elemOffset,nGlobalElem,parallel)
!! Read this rank's block of arrayName, elements elemOffset+1 .. elemOffset+nLocal,
!! into hfArray(1:Np,1:Np,1:Np,1:nLocal). nLocal may be 0.
!!
!! The dataset must have shape (Np,Np,Np,nGlobalElem), matching hfArray's nodal
!! extents: a dataset written at another polynomial degree holds values at other
!! nodes, so this stops rather than reading a sub-block of it. The check uses only
!! the dataset's metadata, so every rank, including one with nLocal = 0, reaches the
!! same decision.
implicit none
integer(HID_T),intent(in) :: fileId
character(*),intent(in) :: arrayName
real(prec),intent(inout) :: hfArray(:,:,:,:)
integer,intent(in) :: elemOffset
integer,intent(in) :: nGlobalElem
logical,intent(in) :: parallel
! Local
integer(HID_T) :: dsetId,filespace,memspace,plistId,dtype
integer(HSIZE_T) :: dims(1:4),offset(1:4),fileDims(1:4),maxDims(1:4)
integer :: error,ndims
dtype = h5kind_to_type(prec,H5_REAL_KIND)
dims = shape(hfArray)
offset = (/0_hsize_t,0_hsize_t,0_hsize_t,int(elemOffset,HSIZE_T)/)
call h5dopen_f(fileId,trim(arrayName),dsetId,error)
if(error /= 0) then
print*,__FILE__," : failed to open ",trim(arrayName)
error stop "ReadSetArray_HDF5 : dataset open failed"
endif
call h5dget_space_f(dsetId,filespace,error)
call h5sget_simple_extent_ndims_f(filespace,ndims,error)
if(ndims /= 4) then
print*,__FILE__," : ",trim(arrayName)," has rank ",ndims,", expected 4"
error stop "ReadSetArray_HDF5 : dataset shape mismatch"
endif
call h5sget_simple_extent_dims_f(filespace,fileDims,maxDims,error)
if(any(fileDims(1:3) /= dims(1:3)) .or. fileDims(4) /= int(nGlobalElem,HSIZE_T)) then
print*,__FILE__," : ",trim(arrayName)," has shape ",fileDims, &
", expected ",dims(1:3),nGlobalElem
error stop "ReadSetArray_HDF5 : dataset shape mismatch"
endif
call h5screate_simple_f(4,dims,memspace,error)
if(dims(4) > 0) then
call h5sselect_hyperslab_f(filespace,H5S_SELECT_SET_F,offset,dims,error)
else
call h5sselect_none_f(filespace,error)
call h5sselect_none_f(memspace,error)
endif
call h5pcreate_f(H5P_DATASET_XFER_F,plistId,error)
if(parallel) call h5pset_dxpl_mpio_f(plistId,H5FD_MPIO_COLLECTIVE_F,error)
call h5dread_f(dsetId,dtype,hfArray,dims,error, &
mem_space_id=memspace,file_space_id=filespace,xfer_prp=plistId)
if(error /= 0) then
print*,__FILE__," : failed to read ",trim(arrayName)
error stop "ReadSetArray_HDF5 : read failed"
endif
call h5pclose_f(plistId,error)
call h5sclose_f(memspace,error)
call h5sclose_f(filespace,error)
call h5dclose_f(dsetId,error)
endsubroutine ReadSetArray_HDF5