create_lat_lon_grid Subroutine

public subroutine create_lat_lon_grid(this, rc)

Type Bound

RegridSupport

Arguments

Type IntentOptional Attributes Name
class(RegridSupport), intent(inout) :: this
integer, intent(out), optional :: rc

Calls

proc~~create_lat_lon_grid~~CallsGraph proc~create_lat_lon_grid RegridSupport%create_lat_lon_grid ESMF_GridAddCoord ESMF_GridAddCoord proc~create_lat_lon_grid->ESMF_GridAddCoord ESMF_GridCreate ESMF_GridCreate proc~create_lat_lon_grid->ESMF_GridCreate ESMF_GridGetCoord ESMF_GridGetCoord proc~create_lat_lon_grid->ESMF_GridGetCoord interface~mapl_range MAPL_Range proc~create_lat_lon_grid->interface~mapl_range proc~mapl_return MAPL_Return proc~create_lat_lon_grid->proc~mapl_return proc~mapl_verify MAPL_Verify proc~create_lat_lon_grid->proc~mapl_verify at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Called by

proc~~create_lat_lon_grid~~CalledByGraph proc~create_lat_lon_grid RegridSupport%create_lat_lon_grid proc~create_esmf_grids RegridSupport%create_esmf_grids proc~create_esmf_grids->proc~create_lat_lon_grid program~main~9 main program~main~9->proc~create_esmf_grids

Source Code

   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