Read a 1-D array of attributes under a given group.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hdf5_obj), | intent(inout) | :: | this |
A HDF5 object |
||
| character(len=*), | intent(in) | :: | groupname |
Groupname |
||
| character(len=*), | intent(in) | :: | label |
Attribute label |
||
| class(*), | intent(out), | target | :: | val(:) |
Attribute values |
impure subroutine hdf5_obj_ReadAttributes1D(this,groupname,label,val) !> Read a 1-D array of attributes under a given group. 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) :: label !! Attribute label class(*), intent(out), & target :: val(:) !! Attribute values ! Work variables integer :: ierr integer(HID_T) :: obj integer, target, & allocatable :: int2log(:) type(c_ptr) :: fptr integer(HID_T) :: sid integer(HID_T) :: dtype integer(HID_T) :: attrid integer(HSIZE_T):: dims(1) integer(HSIZE_T):: maxdims(1) ! Open group call this%OpenGroup(groupname) ! Create Attribute ID if (trim(adjustl(groupname)).eq.'/') then call H5Aopen_f(this%fid, trim(adjustl(label)), attrid, ierr, aapl_id=H5P_DEFAULT_F) else ! Get this group's object obj = this%GetGroupObject(groupname) if (obj.eq.-1_HID_T) & call this%parallel%Stop("Unable to find group "//trim(adjustl(groupname))//" in hdf5 file "//this%filename) call H5Aopen_f(obj, trim(adjustl(label)), attrid, ierr, aapl_id=H5P_DEFAULT_F) end if ! Get datatype and spaceid call H5Aget_type_f(attrid,dtype,ierr) call H5Aget_space_f(attrid,sid,ierr) ! Check dimensions call H5Sget_simple_extent_dims_f(sid, dims, maxdims, ierr) if (size(val).ne.dims(1)) & call this%parallel%Stop("Size mismatch when reading attribute"//trim(adjustl(label))//" under "//trim(adjustl(groupname))//" in hdf5 file "//this%filename) select type(val) type is (real(leapDP)) fptr = c_loc(val(1)) type is (real(leapSP)) fptr = c_loc(val(1)) type is (integer(leapI4)) fptr = c_loc(val(1)) type is (integer(leapI8)) fptr = c_loc(val(1)) type is (logical) allocate(int2log(size(val))) fptr = c_loc(int2log(1)) end select call H5Aread_f(attrid, dtype,fptr, ierr) ! Special treatment of FORTRAN logicals select type(val) type is (logical) val = .false. where (int2log.eq.1) val =.true. end select ! Deallocate pointer fptr = c_null_ptr ! Remove attribute ID call H5Aclose_f(attrid, ierr) ! Close data space call H5Sclose_f(sid, ierr) if (allocated(int2log)) deallocate(int2log) ! Close group call this%CloseGroup(groupname) return end subroutine hdf5_obj_ReadAttributes1D