subroutine ESMF_LocStreamGetPntList(locstream, coordKeyNames, pntDim, pntCount, pntList, rc)
!
! !ARGUMENTS:
type(ESMF_LocStream), intent(in) :: locstream
character (len=*), intent(in) :: coordKeyNames
integer, intent(in) :: pntDim
integer, intent(in) :: pntCount
real(ESMF_KIND_R8), dimension(:), intent(out) :: pntList
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Get number of local entries.
!
! The arguments are:
! \begin{description}
! \item[locstream]
! Location stream from which the new location stream is to be created
! \item[coordKeyNames]
! Names of the keys used to determine the link to background Mesh.
! The first key in this list matches up with the first coordinate of the
! Mesh, the second key in this list matches up with the second coordinate
! of the Mesh, and so on. The key names should be separated by the : character.
! \item[pntList]
! Local list of points from locstream based on coordKeyNames
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOPI
type(ESMF_LocStreamType), pointer :: lstypep
type(ESMF_DistGrid) :: distgrid
integer :: localrc
integer :: localDECount, lDE
integer :: tmpLBnd, tmpUBnd
character(len=ESMF_MAXSTR) :: string
character(len=ESMF_MAXSTR) :: coordKeyList(3)
type(ESMF_TypeKind_Flag) :: coordTypeKindList(3)
real(ESMF_KIND_R8), pointer :: keyDataR8(:)
real(ESMF_KIND_R4), pointer :: keyDataR4(:)
integer (ESMF_KIND_I4), pointer :: keyDataI4(:)
integer :: dim
integer :: i,j,pos
type(ESMF_TypeKind_Flag) :: typekind
! Initialize return code; assume failure until success is certain
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Check Variables
ESMF_INIT_CHECK_DEEP(ESMF_LocStreamGetInit,locstream,rc)
! Get keynames
! Calculate pntDim
dim = 1
string = trim(coordKeyNames )
do while ( string /= '' )
! make sure that we aren't overwriting our array
if (dim >3) then
if (ESMF_LogFoundError(ESMF_RC_ARG_WRONG, &
msg=" - too many coordinate key names", &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
! Pull out coordinate name
call ESMF_StripKey( string, coordKeyList(dim))
! advance to next position
dim = dim + 1
enddo
! check pntDim
if (pntDim /= dim-1) then
if (ESMF_LogFoundError(ESMF_RC_ARG_WRONG, &
msg=" - number of coordinate key names doesn't match pnt dimension", &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
! Get number of localDEs
call ESMF_LocStreamGet(locstream, localDECount=localDECount, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Get pnt coordinates
!! TODO: this is doing a couple of internal subroutine searches to match the key with the name
!! at some point it might make sense to get rid of these
do i=1,pntDim
! Get typeKind
call ESMF_LocStreamGetKey(locstream,keyName=trim(coordKeyList(i)), typekind=typekind, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Copy data based on typekind
if (typekind .eq. ESMF_TYPEKIND_R8) then
pos=i
do lDE=0,localDECount-1
! Get data
call ESMF_LocStreamGetKey(locstream, localDE=lDE, keyName=trim(coordKeyList(i)), &
exclusiveLBound=tmpLBnd, exclusiveUBound=tmpUBnd, farray=keyDataR8, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! put into point list
do j=tmpLBnd,tmpUBnd
pntList(pos)=keyDataR8(j)
pos=pos+pntDim
enddo
enddo
else if (typekind .eq. ESMF_TYPEKIND_R4) then
pos=i
do lDE=0,localDECount-1
! Get data
call ESMF_LocStreamGetKey(locstream, localDE=lDE, keyName=trim(coordKeyList(i)), &
exclusiveLBound=tmpLBnd, exclusiveUBound=tmpUBnd, farray=keyDataR4, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! put into point list
do j=tmpLBnd,tmpUBnd
pntList(pos)=REAL(keyDataR4(j),ESMF_KIND_R8)
pos=pos+pntDim
enddo
enddo
else if (typekind .eq. ESMF_TYPEKIND_I4) then
pos=i
do lDE=0,localDECount-1
! Get data
call ESMF_LocStreamGetKey(locstream, localDE=lDE, keyName=trim(coordKeyList(i)), &
exclusiveLBound=tmpLBnd, exclusiveUBound=tmpUBnd, farray=keyDataI4, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! put into point list
do j=tmpLBnd,tmpUBnd
pntList(pos)=REAL(keyDataI4(j),ESMF_KIND_R8)
pos=pos+pntDim
enddo
enddo
else
if (ESMF_LogFoundError(ESMF_RC_ARG_WRONG, &
msg=" - unsupported coordinate data type", &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
enddo
! return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_LocStreamGetPntList