subroutine create_lat_lon_grid(this, rc)
class (RegridSupport), intent(inout) :: this
integer, optional, intent(out) :: rc
real(kind=ESMF_KIND_R8), pointer :: centers(:,:)
integer :: status
integer :: i, j
integer, allocatable :: jms(:)
integer, allocatable :: ims(:)
integer :: np
integer :: npx
np = floor(sqrt(real(pet_count)))
do npx = np, 1, -1
! will always be true in the final iteration
if (mod(pet_count, npx) == 0) exit
end do
npy = pet_count / npx
!$$ npx = 2
!$$ npy = pet_count/2
npx = 1
npy = pet_count
if (local_pet == 0) print*,'Topology: ', npx, npy
ims = [((((j+1)*this%IM)/npx) - ((j*this%IM)/npx),j=0,npx-1)]
jms = [((((j+1)*this%JM)/npy) - ((j*this%JM)/npy),j=0,npy-1)]
this%grid_lat_lon = ESMF_GridCreate( &
& countsPerDEDim1 = ims, &
& countsPerDEDim2 = jms, &
& indexFlag=ESMF_INDEX_DELOCAL, &
& gridEdgeLWidth=[0,0], &
& gridEdgeUWidth=[0,0], &
& coordDep1=[1,2], &
& coordDep2=[1,2], &
& rc=status &
& )
call ESMF_GridAddCoord(this%grid_lat_lon, rc=status)
_VERIFY(status)
px = mod(local_pet, npx)
py = local_pet / npx
this%i_1 = 1 + (px*this%IM)/npx
this%i_n = ((px+1)*this%IM)/npx
this%j_1 = 1 + (py*this%JM)/npy
this%j_n = ((py+1)*this%JM)/npy
call ESMF_GridGetCoord(this%grid_lat_lon, coordDim=1, localDE=0, &
staggerloc=ESMF_STAGGERLOC_CENTER, &
farrayPtr=centers, rc=status)
_VERIFY(status)
this%longitudes = MAPL_RANGE(-180.d0, 180.d0 - (360.d0/this%IM), this%IM, rc=status)
_VERIFY(status)
centers(:,1) = this%longitudes(this%i_1:this%i_n)
do j = 2, size(centers,2)
centers(:,j) = centers(:,1)
end do
! Now latitudes
call ESMF_GridGetCoord(this%grid_lat_lon, coordDim=2, localDE=0, &
staggerloc=ESMF_STAGGERLOC_CENTER, &
farrayPtr=centers, rc=status)
_VERIFY(status)
this%latitudes = MAPL_RANGE(-90.d0, +90.d0, this%JM, rc=status)
_VERIFY(status)
centers(1,:) = this%latitudes(this%j_1:this%j_n)
do i = 2, size(centers,1)
centers(i,:) = centers(1,:)
end do
_RETURN(_SUCCESS)
end subroutine create_lat_lon_grid