Writes an array of attributes.
| 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(in), | target | :: | val(:) |
Attribute labels |
impure subroutine hdf5_obj_WriteAttributes1D(this,groupname,label,val) !> Writes an array of attributes. 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(in), & target :: val(:) !! Attribute labels ! Work variables integer :: ierr integer(HID_T) :: obj integer, target, & allocatable :: log2int(:) type(c_ptr) :: fptr integer(HID_T) :: sid integer(HID_T) :: dtype integer(HID_T) :: attrid integer(HSIZE_T):: dims(1) integer :: ndim ! Open group call this%OpenGroup(groupname) select type(val) type is (real(leapDP)) dtype = H5T_NATIVE_DOUBLE type is (real(leapSP)) dtype = H5T_NATIVE_REAL type is (integer(leapI4)) dtype = H5T_NATIVE_INTEGER type is (integer(leapI8)) dtype = H5T_STD_I64LE type is (logical) dtype = H5T_NATIVE_INTEGER end select ! Create data space dims(1) = size(val) ndim = 1 call H5Screate_simple_f(ndim, dims, sid, ierr) ! Create Attribute ID if (trim(adjustl(groupname)).eq.'/') then call H5Acreate_f(this%fid, trim(adjustl(label)), dtype, sid, attrid, ierr) else ! get index of this group 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 H5Acreate_f(obj, trim(adjustl(label)), dtype, sid, attrid, ierr) end if 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) ! Special treatment of FORTRAN logicals allocate(log2int(size(val))); log2int = 0 where (val .eqv. .true.) log2int = 1 fptr = c_loc(log2int(1)) end select call H5Awrite_f(attrid,dtype,fptr,ierr) ! Remove attribute ID call H5Aclose_f(attrid, ierr) ! Close data space call H5Sclose_f(sid, ierr) if (allocated(log2int)) deallocate(log2int) ! Close group call this%CloseGroup(groupname) return end subroutine hdf5_obj_WriteAttributes1D