subroutine ESMF_LocStreamAddKeyAlloc(locstream, keyName, keywordEnforcer, &
keyTypeKind, keyUnits, keyLongName, rc)
!
! !ARGUMENTS:
type(ESMF_Locstream), intent(in) :: locstream
character (len=*), intent(in) :: keyName
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
type(ESMF_TypeKind_Flag), intent(in), optional :: keyTypeKind
character (len=*), intent(in), optional :: keyUnits
character (len=*), intent(in), optional :: keyLongName
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Add a key to a locstream with a required keyName. Once a key has
! been added, a pointer to its internally allocated memory can be
! retrieved and used to set key values.
!
! The arguments are:
! \begin{description}
! \item [locstream]
! The {\tt ESMF\_LocStream} object to add key to.
! \item [keyName]
! The name of the key to add.
! \item [{[keyTypeKind]}]
! The type/kind of the key data.
! If not specified then the type/kind will default to 8 byte reals.
! \item [{[keyUnits]}]
! The units of the key data.
! If not specified, then the item remains blank.
! \item [{[keyLongName]}]
! The long name of the key data.
! If not specified, then the item remains blank.
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!EOP
!------------------------------------------------------------------------------
type(ESMF_LocStreamType), pointer :: lstypep
type(ESMF_ArraySpec) :: arrayspec
type(ESMF_Array) :: array
type(ESMF_TypeKind_Flag) :: localKeyTypeKind
integer :: localrc
! Initialize
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! check variables
ESMF_INIT_CHECK_DEEP(ESMF_LocStreamGetInit,locstream,rc)
! set defaults
if (present(keyTypeKind)) then
localKeyTypeKind=keyTypeKind
else
localKeyTypeKind=ESMF_TYPEKIND_R8
endif
! get the pointer to the locstream
lstypep => locstream%lstypep
! Set ArraySpec
call ESMF_ArraySpecSet(arrayspec, rank=1, typekind=localKeyTypeKind, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Create Array
array=ESMF_ArrayCreate(lstypep%distgrid, arrayspec, &
indexflag=lstypep%indexflag, name=keyName, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Add key to structure
call ESMF_LocStreamAddKeyArray(locstream, keyName, keyArray=array, destroyKey=.true., &
keyUnits=keyUnits, keyLongName=keyLongName, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_LocStreamAddKeyAlloc