GridComp.F90 Source File


This file depends on

sourcefile~~gridcomp.f90~~EfferentGraph sourcefile~gridcomp.f90 GridComp.F90 sourcefile~mapl.f90 MAPL.F90 sourcefile~gridcomp.f90->sourcefile~mapl.f90 sourcefile~base.f90 Base.F90 sourcefile~mapl.f90->sourcefile~base.f90 sourcefile~esmf_cfiomod.f90 ESMF_CFIOMod.F90 sourcefile~mapl.f90->sourcefile~esmf_cfiomod.f90 sourcefile~fieldbundleread.f90 FieldBundleRead.F90 sourcefile~mapl.f90->sourcefile~fieldbundleread.f90 sourcefile~fieldbundlewrite.f90 FieldBundleWrite.F90 sourcefile~mapl.f90->sourcefile~fieldbundlewrite.f90 sourcefile~fieldutils.f90 FieldUtils.F90 sourcefile~mapl.f90->sourcefile~fieldutils.f90 sourcefile~mapl_generic.f90 MAPL_Generic.F90 sourcefile~mapl.f90->sourcefile~mapl_generic.f90 sourcefile~mapl_gridcomps.f90 MAPL_GridComps.F90 sourcefile~mapl.f90->sourcefile~mapl_gridcomps.f90 sourcefile~mapl_profiler.f90~2 MAPL_Profiler.F90 sourcefile~mapl.f90->sourcefile~mapl_profiler.f90~2 sourcefile~openmp_support.f90 OpenMP_Support.F90 sourcefile~mapl.f90->sourcefile~openmp_support.f90 sourcefile~pfio.f90 pFIO.F90 sourcefile~mapl.f90->sourcefile~pfio.f90 sourcefile~stateutils.f90 StateUtils.F90 sourcefile~mapl.f90->sourcefile~stateutils.f90 sourcefile~stubcomponent.f90 StubComponent.F90 sourcefile~mapl.f90->sourcefile~stubcomponent.f90 sourcefile~varspecmiscmod.f90 VarSpecMiscMod.F90 sourcefile~mapl.f90->sourcefile~varspecmiscmod.f90

Files dependent on this one

sourcefile~~gridcomp.f90~~AfferentGraph sourcefile~gridcomp.f90 GridComp.F90 sourcefile~driver.f90~2 driver.F90 sourcefile~driver.f90~2->sourcefile~gridcomp.f90

Source Code

#include "MAPL_Generic.h"
#include "MAPL_Exceptions.h"


module GridComp

  use ESMF
  use MAPL

  implicit none
  private

  public setservices

  contains

  subroutine setservices(gc,rc)

     type(ESMF_GridComp), intent(inout)  :: gc
     integer, optional :: rc

     type (MAPL_MetaComp),       pointer    :: MAPL
     type (ESMF_Config) :: cf
     integer :: status
     logical :: use_threads
     integer :: num_threads

     call MAPL_GetObjectFromGC (gc, MAPL, _RC)
     call ESMF_GridCompGet(gc, config=cf, _RC)
     call ESMF_ConfigGetAttribute(cf, use_threads, label='use_threads:', default=.FALSE., _RC)
     call MAPL%set_use_threads(use_threads)

     call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_INITIALIZE,  initialize, _RC)
     call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_RUN,  run, _RC)
     call MAPL_GenericSetServices(gc, _RC)

     _RETURN(_SUCCESS)

  end subroutine setservices


  subroutine initialize(gc, import, export, clock, rc)
     type(ESMF_GridComp), intent(inout) :: gc
     type(ESMF_State), intent(inout) :: import
     type(ESMF_State), intent(inout) :: export
     type(ESMF_Clock), intent(inout) :: clock
     integer, intent(out), optional :: rc

     type (MAPL_MetaComp),       pointer    :: MAPL
     integer :: status

     call MAPL_GridCreate(gc, _RC)
     call MAPL_GetObjectFromGC (gc, MAPL, _RC)
     print *, 'Num threads = ', MAPL_get_num_threads(), ' for this run'
     call MAPL_GenericInitialize(gc, import, export, clock, _RC)

     _RETURN(_SUCCESS)

  end subroutine initialize

  subroutine check_dim(grid, rc)
     type(ESMF_Grid), intent(in) :: grid
     integer, intent(out), optional :: rc

! locals
     integer :: status
     integer :: dims(3)

      call MAPL_GridGet(grid, globalCellCountPerDim=dims,_RC)

      _ASSERT(dims(1)*6 == dims(2), 'Mini grid should act as a cubed sphere grid for global extents')

     _RETURN(_SUCCESS)

  end subroutine check_dim

  subroutine check_expected_index(grid, rc)
     type(ESMF_Grid), intent(inout) :: grid
     integer, intent(out), optional :: rc

! locals
     integer :: status, i, j, II(1), JJ(1)
     real, dimension(:,:), pointer :: lats, lons
     real :: lon(1), lat(1)


      call ESMFL_GridCoordGet(   grid, LATS                      , &
                              Name     = "Latitude"              , &
                              Location = ESMF_STAGGERLOC_CENTER  , &
                              Units    = MAPL_UnitsRadians    , _RC)

      call ESMFL_GridCoordGet(   grid, LONS                      , &
                              Name     = "Longitude"             , &
                              Location = ESMF_STAGGERLOC_CENTER  , &
                              Units    = MAPL_UnitsRadians    , _RC)
      _ASSERT(all(shape(LATS) == shape(LONS)), 'LATS and LONS must have the same shape')

      do j = 1, size(LATS,2)
         do i = 1, size(LATS, 1)
            lon = lons(i,j)
            lat = lats(i,j)
            call MAPL_GetHorzIJIndex(1, II, JJ,  &
                grid=grid, lon=lon, lat=lat, _RC)
            _ASSERT(II(1) == i, 'I-index of cell center (i,j) should be i')
            _ASSERT(JJ(1) == j, 'J-index of cell center (i,j) should be j')
         end do
      end do

     _RETURN(_SUCCESS)

  end subroutine check_expected_index

  subroutine check_unexpected_index(grid, rc)
     type(ESMF_Grid), intent(inout) :: grid
     integer, intent(out), optional :: rc

! locals
     integer :: status, i, j, II(1), JJ(1)
     real, dimension(:,:), pointer :: lats, lons
     real :: lon(1), lat(1)


      call ESMFL_GridCoordGet(   grid, lats                      , &
                              Name     = "Latitude"              , &
                              Location = ESMF_STAGGERLOC_CENTER  , &
                              Units    = MAPL_UnitsRadians    , _RC)

      call ESMFL_GridCoordGet(   grid, lons                      , &
                              Name     = "Longitude"             , &
                              Location = ESMF_STAGGERLOC_CENTER  , &
                              Units    = MAPL_UnitsRadians    , _RC)
      ! centers of antipodal points
       lons = lons + MAPL_PI
       lats = -lats
      _ASSERT(all(shape(LATS) == shape(LONS)), 'LATS and LONS must have the same shape')

      do j = 1, size(lats,2)
         do i = 1, size(lats, 1)
            lon = lons(i,j)
            lat = lats(i,j)
            call MAPL_GetHorzIJIndex(1, II(1), JJ(1),  &
                grid=grid, lon=lon, lat=lat, _RC)
            _ASSERT(II(1) == -1, 'Expected -1 for point outside of domain')
            _ASSERT(JJ(1) == -1, 'Expected -1 for point outside of domain') 
         end do         
      end do

     _RETURN(_SUCCESS)

  end subroutine check_unexpected_index

  subroutine run(gc, import, export, clock, rc)
     type(ESMF_GridComp), intent(inout) :: gc
     type(ESMF_State), intent(inout) :: import
     type(ESMF_State), intent(inout) :: export
     type(ESMF_Clock), intent(inout) :: clock
     integer, intent(out), optional :: rc

! locals
     type (MAPL_MetaComp), pointer     :: mapl
     type (ESMF_Grid)                  :: grid
     integer :: status

      call MAPL_GetObjectFromGC (gc, MAPL, _RC)
      call MAPL_Get (MAPL, grid=grid, _RC)
      call ESMF_GridValidate(grid,_RC)

      call check_dim(grid, _RC)
      call check_expected_index(grid, _RC)
      call check_unexpected_index(grid, _RC)

     _UNUSED_DUMMY(import)
     _UNUSED_DUMMY(export)
     _UNUSED_DUMMY(clock)

     _RETURN(_SUCCESS)

  end subroutine run

end module GridComp