Writes a scalar attribute.
| 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 label |
impure subroutine hdf5_obj_WriteAttributes0D(this,groupname,label,val) !> Writes a scalar attribute. 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(in), & target :: val !! Attribute label ! Work variables integer :: ierr integer(HID_T) :: obj integer, target :: 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) = 1 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 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 H5Acreate_f(obj, trim(adjustl(label)), dtype, sid, attrid, ierr) end if select type(val) type is (real(leapDP)) fptr = c_loc(val) type is (real(leapSP)) fptr = c_loc(val) type is (integer(leapI4)) fptr = c_loc(val) type is (integer(leapI8)) fptr = c_loc(val) type is (logical) ! Special treatment of FORTRAN logicals log2int = 0 if (val.eqv..true.) log2int = 1 fptr = c_loc(log2int) 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) ! Close group call this%CloseGroup(groupname) return end subroutine hdf5_obj_WriteAttributes0D