Reads coordinates from HDF5 file. Only the root MPI rank does the reading, and then broadcasts to other MPI ranks.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hdf5_obj), | intent(inout) | :: | this |
A HDF5 object |
||
| character(len=*), | intent(in) | :: | groupname |
Groupname |
||
| character(len=*), | intent(in) | :: | name |
Variable name |
||
| class(*), | intent(out), | target | :: | Coord(:) |
1-D Coordinates |
impure subroutine hdf5_obj_ReadCoord(this,groupname,name,Coord) !> Reads coordinates from HDF5 file. ! Only the root MPI rank does the reading, and then broadcasts ! to other MPI ranks. use iso_c_binding implicit none class(hdf5_obj), intent(inout) :: this !! A HDF5 object character(len=*), intent(in) :: groupname !! Groupname character(len=*), intent(in) :: name !! Variable name class(*), intent(out), & target :: Coord(:) !! 1-D Coordinates ! Work variables integer :: ierr integer(HID_T) :: sidc,sidg integer(HID_T) :: did integer(HID_T) :: dtype integer(HSIZE_T) :: dims(1) integer(HSIZE_T) :: offset(1) integer :: ndim integer(HID_T) :: obj type(c_ptr) :: fptr = c_null_ptr ! Open group, if not already open call this%OpenGroup(groupname) ! Find parent object obj = this%GetGroupObject(groupname) ! Reading 1d array ndim = 1 ! Dimension dims = int(size(Coord),kind=HSIZE_T) ! Open dataset call H5Dopen_f(obj, trim(adjustl(name)), did, ierr) if (ierr.ne.0) & call this%parallel%Stop("Unable to open dataset "//trim(adjustl(name))//" under "//trim(adjustl(groupname))//" in HDF5 file "//this%filename) ! Get the global data space from file call H5Dget_space_f(did,sidg,ierr) ! Get datatype from file call H5Dget_type_f(did,dtype,ierr) ! Create the local data space call H5Screate_simple_f(ndim,dims,sidc,ierr) ! Select a subset of the global data space offset = int(0,kind=HSIZE_T) call H5Sselect_hyperslab_f(sidg,H5S_SELECT_SET_F,offset,dims,ierr) ! Select all elements from the local data space call H5Sselect_hyperslab_f(sidc,H5S_SELECT_SET_F,offset,dims,ierr) ! Read data set select type(Coord) type is (real(leapDP)) fptr = c_loc(Coord(1)) type is (real(leapSP)) fptr = c_loc(Coord(1)) type is (integer(leapI4)) fptr = c_loc(Coord(1)) type is (integer(leapI8)) fptr = c_loc(Coord(1)) end select call H5Dread_f(did,dtype,fptr,ierr,mem_space_id=sidc,file_space_id=sidg) ! Deallocate pointer fptr = c_null_ptr ! Close data spaces call H5Sclose_f(sidc,ierr) call H5Sclose_f(sidg,ierr) ! Close dataset call H5Dclose_f(did,ierr) ! Close datatype call H5Tclose_f(dtype,ierr) ! Close group call this%CloseGroup(groupname) return end subroutine hdf5_obj_ReadCoord