function ESMF_LocStreamCreateIrreg(minIndex, countsPerDE, &
keywordEnforcer, indexflag, coordSys, name, rc)
!
! !RETURN VALUE:
type(ESMF_LocStream) :: ESMF_LocStreamCreateIrreg
!
! !ARGUMENTS:
integer, intent(in), optional :: minIndex
integer, intent(in) :: countsPerDE(:)
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
type(ESMF_Index_Flag), intent(in), optional :: indexflag
type(ESMF_CoordSys_Flag), intent(in), optional :: coordSys
character (len=*), intent(in), optional :: name
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Allocates memory for a new {\tt ESMF\_LocStream} object, constructs its
! internal derived types. The {\tt ESMF\_DistGrid} is set up, indicating
! how the LocStream is distributed.
!
! The arguments are:
! \begin{description}
! \item[{[minIndex]}]
! If indexflag={\tt ESMF\_INDEX\_DELOCAL}, this setting is used to indicate
! the number to start the index ranges at. If not present, defaults to 1.
! \item[{countsPerDE}]
! This array has an element for each DE, specifying the number of locations
! for that DE.
! \item[{[indexflag]}]
! Flag that indicates how the DE-local indices are to be defined.
! Defaults to {\tt ESMF\_INDEX\_DELOCAL}, which indicates
! that the index range on each DE starts at 1. See Section~\ref{const:indexflag}
! for the full range of options.
! \item[{[coordSys]}]
! The coordinate system of the location stream coordinate data.
! For a full list of options, please see Section~\ref{const:coordsys}.
! If not specified then defaults to ESMF\_COORDSYS\_SPH\_DEG.
! \item[{[name]}]
! Name of the location stream
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
integer :: localrc ! Error status
integer :: i, currMin
type(ESMF_DistGrid) :: distgrid
integer, pointer :: deBLockList(:,:,:)
integer :: minIndexLocal, maxIndexLocal
type(ESMF_Index_Flag) :: indexflagLocal
type(ESMF_CoordSys_Flag) :: coordSysLocal
integer :: numDEs
! Initialize return code; assume failure until success is certain
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Set defaults
if (present(indexflag)) then
indexflagLocal=indexflag
else
indexflagLocal=ESMF_INDEX_DELOCAL
endif
if (present(coordSys)) then
coordSysLocal=coordSys
else
coordSysLocal=ESMF_COORDSYS_SPH_DEG
endif
if (present(minIndex)) then
minIndexLocal=minIndex
else
minIndexLocal=1 ! default to 1
endif
! get number of DEs
numDEs=size(countsPerDE)
! make they've given us info
if (numDEs .eq. 0) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_SIZE, &
msg="- countsPerDE is of length 0", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Calc. maxIndexLocal
maxIndexLocal=minIndexLocal+sum(countsPerDE(:))-1
! Setup DistGrid
!! setup deBlockList
allocate(deBlockList(1,2,numDEs), stat=localrc)
if (ESMF_LogFoundAllocError(localrc, msg="Allocating deBlockList", &
ESMF_CONTEXT, rcToReturn=rc)) return
currMin=minIndexLocal
do i=1,numDEs
deBlockList(1,1,i)=currMin
deBlockList(1,2,i)=currMin+countsPerDE(i)-1
currMin=deBlockList(1,2,i)+1
enddo
!! Create DistGrid
distgrid=ESMF_DistGridCreate(minIndex=(/minIndexLocal/), &
maxIndex=(/maxIndexLocal/), &
deBlockList=deBlockList, &
indexflag=indexflagLocal, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! cleanup local allocations
deallocate(deBlockList)
! Create LocStream using CreateFromDistGrid version
ESMF_LocStreamCreateIrreg=ESMF_LocStreamCreateFromDG(name=name, &
distgrid=distgrid, &
indexflag=indexflagLocal, &
coordSys=coordSysLocal, &
rc=localrc )
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Set distgrid to be destroyed, since ESMF created it
ESMF_LocStreamCreateIrreg%lstypep%destroyDistgrid=.true.
! return successfully
if (present(rc)) rc = ESMF_SUCCESS
end function ESMF_LocStreamCreateIrreg