rsave_to_hdf5 Subroutine

private subroutine rsave_to_hdf5(h5file_id, dset, rdatum, attr)

Arguments

Type IntentOptional AttributesName
integer(kind=HID_T), intent(in) :: h5file_id
character(len=MAX_STRING_LENGTH), intent(in) :: dset
real(kind=rp), intent(in) :: rdatum
character(len=MAX_STRING_LENGTH), intent(in), optional :: attr

Contents

Source Code


Source Code

  subroutine rsave_to_hdf5(h5file_id,dset,rdatum,attr)
    INTEGER(HID_T), INTENT(IN) 							:: h5file_id
    CHARACTER(MAX_STRING_LENGTH), INTENT(IN) 			:: dset
    REAL(rp), INTENT(IN) 								:: rdatum
    CHARACTER(MAX_STRING_LENGTH), OPTIONAL, INTENT(IN) 	:: attr
    CHARACTER(4) 										:: aname = "Info"
    INTEGER(HID_T) 										:: dset_id
    INTEGER(HID_T) 										:: dspace_id
    INTEGER(HID_T) 										:: aspace_id
    INTEGER(HID_T) 										:: attr_id
    INTEGER(HID_T) 										:: atype_id
    INTEGER(HSIZE_T), DIMENSION(1) 						:: dims = (/1/)
    INTEGER(HSIZE_T), DIMENSION(1) 						:: adims = (/1/)
    INTEGER 											:: rank = 1
    INTEGER 											:: arank = 1
    INTEGER(SIZE_T) 									:: attrlen
    INTEGER 											:: h5error

    ! * * * Write data to file * * *

    call h5screate_simple_f(rank,dims,dspace_id,h5error)
    call h5dcreate_f(h5file_id, TRIM(dset), KORC_HDF5_REAL, dspace_id, dset_id, h5error)

    if (rp .EQ. INT(rp_hdf5)) then
       call h5dwrite_f(dset_id, KORC_HDF5_REAL, rdatum, dims, h5error)
    else
       call h5dwrite_f(dset_id, KORC_HDF5_REAL, REAL(rdatum,4), dims, h5error)
    end if

    if (PRESENT(attr)) then
       ! * * * Write attribute of data to file * * *
       attrlen = LEN_TRIM(attr)
       call h5screate_simple_f(arank,adims,aspace_id,h5error)
       call h5tcopy_f(H5T_NATIVE_CHARACTER, atype_id, h5error)
       call h5tset_size_f(atype_id, attrlen, h5error)
       call h5acreate_f(dset_id, aname, atype_id, aspace_id, attr_id, h5error)
       call h5awrite_f(attr_id, atype_id, attr, adims, h5error)

       call h5aclose_f(attr_id, h5error)
       call h5sclose_f(aspace_id, h5error)
       ! * * * Write attribute of data to file * * *
    end if

    call h5sclose_f(dspace_id, h5error)
    call h5dclose_f(dset_id, h5error)
    ! * * * Write data to file * * *
  end subroutine rsave_to_hdf5