GeomUtilities.F90 Source File


This file depends on

sourcefile~~geomutilities.f90~~EfferentGraph sourcefile~geomutilities.f90 GeomUtilities.F90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~geomutilities.f90->sourcefile~errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~errorhandling.f90->sourcefile~mapl_throw.f90

Files dependent on this one

sourcefile~~geomutilities.f90~~AfferentGraph sourcefile~geomutilities.f90 GeomUtilities.F90 sourcefile~geom_mgr.f90 geom_mgr.F90 sourcefile~geom_mgr.f90->sourcefile~geomutilities.f90 sourcefile~componentspecparser.f90 ComponentSpecParser.F90 sourcefile~componentspecparser.f90->sourcefile~geom_mgr.f90 sourcefile~fieldspec.f90~2 FieldSpec.F90 sourcefile~fieldspec.f90~2->sourcefile~geom_mgr.f90 sourcefile~geom_pfio.f90 Geom_PFIO.F90 sourcefile~geom_pfio.f90->sourcefile~geom_mgr.f90 sourcefile~geometryspec.f90 GeometrySpec.F90 sourcefile~geometryspec.f90->sourcefile~geom_mgr.f90 sourcefile~historycollectiongridcomp.f90 HistoryCollectionGridComp.F90 sourcefile~historycollectiongridcomp.f90->sourcefile~geom_mgr.f90 sourcefile~historycollectiongridcomp_private.f90 HistoryCollectionGridComp_private.F90 sourcefile~historycollectiongridcomp_private.f90->sourcefile~geom_mgr.f90 sourcefile~outermetacomponent.f90 OuterMetaComponent.F90 sourcefile~outermetacomponent.f90->sourcefile~geom_mgr.f90 sourcefile~regridderspec.f90~2 RegridderSpec.F90 sourcefile~regridderspec.f90~2->sourcefile~geom_mgr.f90 sourcefile~restarthandler.f90 RestartHandler.F90 sourcefile~restarthandler.f90->sourcefile~geom_mgr.f90 sourcefile~routehandleparam.f90 RoutehandleParam.F90 sourcefile~routehandleparam.f90->sourcefile~geom_mgr.f90 sourcefile~routehandlespec.f90 RoutehandleSpec.F90 sourcefile~routehandlespec.f90->sourcefile~geom_mgr.f90 sourcefile~sharedio.f90 SharedIO.F90 sourcefile~sharedio.f90->sourcefile~geom_mgr.f90 sourcefile~test_bracketspec.pf Test_BracketSpec.pf sourcefile~test_bracketspec.pf->sourcefile~geom_mgr.f90 sourcefile~test_fieldspec.pf Test_FieldSpec.pf sourcefile~test_fieldspec.pf->sourcefile~geom_mgr.f90 sourcefile~test_geommanager.pf Test_GeomManager.pf sourcefile~test_geommanager.pf->sourcefile~geom_mgr.f90 sourcefile~test_modelverticalgrid.pf Test_ModelVerticalGrid.pf sourcefile~test_modelverticalgrid.pf->sourcefile~geom_mgr.f90 sourcefile~test_regriddermanager.pf Test_RegridderManager.pf sourcefile~test_regriddermanager.pf->sourcefile~geom_mgr.f90 sourcefile~test_routehandlemanager.pf Test_RouteHandleManager.pf sourcefile~test_routehandlemanager.pf->sourcefile~geom_mgr.f90

Source Code

#include "MAPL_ErrLog.h"

module mapl3g_GeomUtilities
   use esmf
   use mapl_ErrorHandlingMod
   implicit none
   private

   public :: MAPL_GeomSetId
   public :: MAPL_GeomGetId
   public :: MAPL_SameGeom

   character(len=*), parameter :: ID_INFO_KEY = 'mapl/geom/id'

   interface MAPL_SameGeom
      procedure :: same_geom
   end interface MAPL_SameGeom

contains
   
   subroutine MAPL_GeomSetId(geom, id, rc)
      type(ESMF_Geom), intent(inout) :: geom
      integer, intent(in) :: id
      integer, optional, intent(out) :: rc

      integer :: status
      type(ESMF_Info) :: info

      call ESMF_InfoGetFromHost(geom, info, _RC)
      call ESMF_InfoSet(info, ID_INFO_KEY, id, _RC)
      
      _RETURN(_SUCCESS)
   end subroutine MAPL_GeomSetId

   integer function MAPL_GeomGetId(geom, isPresent, rc) result(id)
      type(ESMF_Geom), intent(in) :: geom
      logical, optional, intent(out) :: isPresent
      integer, optional, intent(out) :: rc

      integer :: status
      type(ESMF_Info) :: info
      integer, parameter :: NOT_FOUND = -1

      call ESMF_InfoGetFromHost(geom, info, _RC)
      call ESMF_InfoGet(info, ID_INFO_KEY, id, default=NOT_FOUND, _RC)
      if (present(isPresent)) isPresent = (id /= NOT_FOUND)

      
      _RETURN(_SUCCESS)
   end function MAPL_GeomGetId

   ! For now, a grid that lacks an id is treated as different than all
   ! other grids.
   logical function same_geom(geom_a, geom_b)
      type(ESMF_Geom), intent(in) :: geom_a
      type(ESMF_Geom), intent(in) :: geom_b

      logical :: has_id_a
      logical :: has_id_b
      integer :: id_a
      integer :: id_b

      same_geom = .false. ! unless
      
      id_a = MAPL_GeomGetId(geom_a, isPresent=has_id_a)
      id_b = MAPL_GeomGetId(geom_b, isPresent=has_id_b)

      if (has_id_a .and. has_id_b) then
         same_geom = (id_a == id_b)
      end if

   end function same_geom

end module mapl3g_GeomUtilities