ESMFL_GridDistBlockSet Subroutine

public subroutine ESMFL_GridDistBlockSet(Egrid, ist, jst, il, jl, rlons, rlats, rc)

ESMFL_GridDistBlockSet

History

-16Jun2006 Cruz Initial code.

Arguments

Type IntentOptional Attributes Name
type(ESMF_Grid), intent(inout) :: Egrid
integer, intent(in), dimension(:) :: ist
integer, intent(in), dimension(:) :: jst
integer, intent(in), dimension(:) :: il
integer, intent(in), dimension(:) :: jl
real(kind=REAL64), optional, dimension(:) :: rlons
real(kind=REAL64), optional, dimension(:) :: rlats
integer, intent(out), optional :: rc

return code


Source Code

   subroutine ESMFL_GridDistBlockSet (Egrid, ist, jst, il, jl, &
                                      rlons, rlats, rc)
!
  implicit NONE

! !ARGUMENTS:

   type(ESMF_Grid), intent(inout)            :: Egrid
   integer,         intent(in), dimension(:) :: ist, jst, il, jl
   real(kind=REAL64), optional, dimension(:) :: rlats
   real(kind=REAL64), optional, dimension(:) :: rlons
   integer,           optional, intent(out)  :: rc     !! return code

   _UNUSED_DUMMY(Egrid)
   _UNUSED_DUMMY(ist)
   _UNUSED_DUMMY(jst)
   _UNUSED_DUMMY(il)
   _UNUSED_DUMMY(jl)
   _UNUSED_DUMMY(rlats)
   _UNUSED_DUMMY(rlons)

#if 0
!
!-------------------------------------------------------------------------

   integer, allocatable, dimension(:) :: iAI
   integer :: ncnt,i,j,k,count,n,status,nDE,mype
   integer, allocatable, dimension(:,:) :: myindices
   type(ESMF_Logical) :: HasBlockSet
   type(ESMF_DELayout):: layout
   type(ESMF_VM):: vm
   type(ESMF_AxisIndex), allocatable, dimension(:,:) :: AI
   character(len=ESMF_MAXSTR), parameter :: IAm = 'ESMFL_GridDistBlockSet'

! start

   call ESMF_VMGetCurrent(vm)
   call ESMF_VMGet(vm, petCount=nDE, localPet=mype, rc=status)
   if (status /= ESMF_SUCCESS) &
   call ESMFL_FailedRC(mype,Iam//': ESMF_VMGet failed')

   allocate(myindices(il(mype+1)*jl(mype+1),2), stat=status)
   if (status /= ESMF_SUCCESS) &
   call ESMFL_FailedRC(mype,Iam//': allocate failed')

   ncnt=0
   do i=jst(mype+1),jst(mype+1)+jl(mype+1)-1
     do j=ist(mype+1),ist(mype+1)+il(mype+1)-1
       ncnt=ncnt+1
       myindices(ncnt,1) = i
       myindices(ncnt,2) = j
     end do
   end do
   !print *,mype,' ncnt = ',ncnt,shape(myindices),il(mype+1)*jl(mype+1)

   layout = ESMF_DELayoutCreate(vm, deCountList=(/1, 8/), rc=status)
   if (status /= ESMF_SUCCESS) &
   call ESMFL_FailedRC(mype,Iam//': ESMF_DELayoutCreate failed')

   call ESMF_GridDistribute(Egrid,               &
         deLayout=layout,                        &
         mycount=ncnt,                           &
         myindices=myindices,                    &
         rc=status)
   if (status /= ESMF_SUCCESS) &
   call ESMFL_FailedRC(mype,Iam//': ESMF_GridDistribute failed')

! Encode the AI information. Let's use the grid attributes to do that.
! First, serialize the AI object: create an integer 1D array to hold the
! AI information: 3D grids will be larger

   count = nDE*6
   allocate(iAI(count))
   iAI = 0
   k = 1
   do n = 1, nDE
     iAI(k) = ist(n); k=k+1
     iAI(k) = jst(n); k=k+1
     iAI(k) = il(k) ; k=k+1
     iAI(k) = jl(k) ; k=k+1
     iAI(k) = 0     ; k=k+1
     iAI(k) = 0     ; k=k+1
   end do

! Attach attributes to the grid:

   call ESMF_GridSetAttribute(Egrid, 'GlobalAxisIndex', count, iAI, rc=status)

   HasBlockSet = ESMF_TRUE
   call ESMF_GridSetAttribute(Egrid, 'HasBlockSet', HasBlockSet, rc)

! if rlons and rlats were present attach them to grid

   if(present(rlats)) &
   call ESMF_GridSetAttribute(Egrid, 'GSI rlats', size(rlats), rlats, rc)
   if(present(rlons)) &
   call ESMF_GridSetAttribute(Egrid, 'GSI rlons', size(rlons), rlons, rc)
!
   deallocate(iAI, myindices)
#endif

   if (present(rc)) then
      rc = 0
   end if
   end subroutine ESMFL_GridDistBlockSet