subroutine get_esmf_grid_layout(grid,nx,ny,ims_out,jms_out,rc)
type(ESMF_Grid), intent(inout) :: grid
integer, intent(out) :: nx
integer, intent(out) :: ny
integer, intent(inout), allocatable :: ims_out(:)
integer, intent(inout), allocatable :: jms_out(:)
integer, optional, intent(out) :: rc
type(ESMF_VM) :: vm
integer :: status
type(ESMF_DistGrid) :: dist_grid
integer, allocatable :: minindex(:,:),maxindex(:,:)
integer :: dim_count, ndes
integer, pointer :: ims(:),jms(:)
call ESMF_VMGetCurrent(vm,_RC)
call ESMF_VMGet(vm,petCount=ndes,_RC)
call ESMF_GridGet(grid,distgrid=dist_grid,dimCOunt=dim_count,_RC)
allocate(minindex(dim_count,ndes),maxindex(dim_count,ndes))
call MAPL_DistGridGet(dist_grid,minIndex=minindex,maxIndex=maxindex,_RC)
call MAPL_GetImsJms(minindex(1,:),maxindex(1,:),minindex(2,:),maxindex(2,:),ims,jms,_RC)
nx = size(ims)
ny = size(jms)
allocate(ims_out(nx),jms_out(ny))
ims_out = ims
jms_out = jms
if (present(rc)) then
rc=_SUCCESS
endif
end subroutine get_esmf_grid_layout