parse_connections.F90 Source File


This file depends on

sourcefile~~parse_connections.f90~~EfferentGraph sourcefile~parse_connections.f90 parse_connections.F90 sourcefile~componentspecparser.f90 ComponentSpecParser.F90 sourcefile~parse_connections.f90->sourcefile~componentspecparser.f90 sourcefile~childspec.f90 ChildSpec.F90 sourcefile~componentspecparser.f90->sourcefile~childspec.f90 sourcefile~childspecmap.f90 ChildSpecMap.F90 sourcefile~componentspecparser.f90->sourcefile~childspecmap.f90 sourcefile~componentspec.f90 ComponentSpec.F90 sourcefile~componentspecparser.f90->sourcefile~componentspec.f90 sourcefile~connection.f90 Connection.F90 sourcefile~componentspecparser.f90->sourcefile~connection.f90 sourcefile~connectionpt.f90 ConnectionPt.F90 sourcefile~componentspecparser.f90->sourcefile~connectionpt.f90 sourcefile~connectionvector.f90 ConnectionVector.F90 sourcefile~componentspecparser.f90->sourcefile~connectionvector.f90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~componentspecparser.f90->sourcefile~errorhandling.f90 sourcefile~esmf_utilities.f90 ESMF_Utilities.F90 sourcefile~componentspecparser.f90->sourcefile~esmf_utilities.f90 sourcefile~geom_mgr.f90 geom_mgr.F90 sourcefile~componentspecparser.f90->sourcefile~geom_mgr.f90 sourcefile~geometryspec.f90 GeometrySpec.F90 sourcefile~componentspecparser.f90->sourcefile~geometryspec.f90 sourcefile~matchconnection.f90 MatchConnection.F90 sourcefile~componentspecparser.f90->sourcefile~matchconnection.f90 sourcefile~reexportconnection.f90 ReexportConnection.F90 sourcefile~componentspecparser.f90->sourcefile~reexportconnection.f90 sourcefile~simpleconnection.f90 SimpleConnection.F90 sourcefile~componentspecparser.f90->sourcefile~simpleconnection.f90 sourcefile~stateitem.f90 StateItem.F90 sourcefile~componentspecparser.f90->sourcefile~stateitem.f90 sourcefile~ungriddeddim.f90 UngriddedDim.F90 sourcefile~componentspecparser.f90->sourcefile~ungriddeddim.f90 sourcefile~ungriddeddims.f90 UngriddedDims.F90 sourcefile~componentspecparser.f90->sourcefile~ungriddeddims.f90 sourcefile~usersetservices.f90 UserSetServices.F90 sourcefile~componentspecparser.f90->sourcefile~usersetservices.f90 sourcefile~variablespec.f90 VariableSpec.F90 sourcefile~componentspecparser.f90->sourcefile~variablespec.f90 sourcefile~variablespecvector.f90 VariableSpecVector.F90 sourcefile~componentspecparser.f90->sourcefile~variablespecvector.f90 sourcefile~verticaldimspec.f90 VerticalDimSpec.F90 sourcefile~componentspecparser.f90->sourcefile~verticaldimspec.f90 sourcefile~virtualconnectionpt.f90 VirtualConnectionPt.F90 sourcefile~componentspecparser.f90->sourcefile~virtualconnectionpt.f90

Source Code

#include "MAPL_ErrLog.h"

submodule (mapl3g_ComponentSpecParser) parse_connections_smod
   
contains

   module function parse_connections(hconfig, rc) result(connections)
      type(ConnectionVector) :: connections
      type(ESMF_HConfig), optional, intent(in) :: hconfig
      integer, optional, intent(out) :: rc

      type(ESMF_HConfig) :: conn_specs, conn_spec
      class(Connection), allocatable :: conn
      integer :: status, i, num_specs
      logical :: has_connections

      has_connections = ESMF_HConfigIsDefined(hconfig,keyString=COMPONENT_CONNECTIONS_SECTION,_RC)
      _RETURN_UNLESS(has_connections)

      conn_specs = ESMF_HConfigCreateAt(hconfig, keyString=COMPONENT_CONNECTIONS_SECTION, _RC)

      num_specs = ESMF_HConfigGetSize(conn_specs, _RC)
      do i = 1, num_specs
         conn_spec = ESMF_HConfigCreateAt(conn_specs, index=i, _RC)
         allocate(conn, source=parse_connection(conn_spec, rc=status)); _VERIFY(status)
         call connections%push_back(conn)
         deallocate(conn)
      enddo 

      _RETURN(_SUCCESS)

   contains

      function parse_connection(config, rc) result(conn)
         class(Connection), allocatable :: conn
         type(ESMF_HConfig), optional, intent(in) :: config
         integer, optional, intent(out) :: rc

         integer :: status
         character(:), allocatable :: src_name, dst_name
         character(:), allocatable :: src_comp, dst_comp
         character(:), allocatable :: src_intent, dst_intent

         call get_comps(config, src_comp, dst_comp, _RC)

         if (ESMF_HConfigIsDefined(config,keyString='all_unsatisfied')) then
            conn = MatchConnection( &
                 ConnectionPt(src_comp, VirtualConnectionPt(state_intent='export', short_name='^.*$')), &
                 ConnectionPt(dst_comp, VirtualConnectionPt(state_intent='import', short_name='^.*$'))  &
                 )
            _RETURN(_SUCCESS)
         end if
            
         call get_names(config, src_name, dst_name, _RC)
         call get_intents(config, src_intent, dst_intent, _RC)

         associate ( &
              src_pt => VirtualConnectionPt(state_intent=src_intent, short_name=src_name), &
              dst_pt => VirtualConnectionPt(state_intent=dst_intent, short_name=dst_name) )

           if (dst_intent == 'export') then
              conn = ReexportConnection( &
                ConnectionPt(src_comp, src_pt), &
                ConnectionPt(dst_comp, dst_pt))
           else
              conn = SimpleConnection( &
                   ConnectionPt(src_comp, src_pt), &
                   ConnectionPt(dst_comp, dst_pt))
           end if

         end associate

         _RETURN(_SUCCESS)
      end function parse_connection

      subroutine get_names(config, src_name, dst_name, rc)
         type(ESMF_HConfig), intent(in) :: config
         character(:), allocatable :: src_name
         character(:), allocatable :: dst_name
         integer, optional, intent(out) :: rc

         integer :: status

         associate (provides_names => &
              ESMF_HConfigIsDefined(config,keyString='name') .or. &
              (ESMF_HConfigIsDefined(config,keyString='src_name') .and. ESMF_HConfigIsDefined(config,keyString='dst_name')) &
              )
           _ASSERT(provides_names, "Must specify 'name' or 'src_name' .and. 'dst_name' in connection.")
         end associate

         if (ESMF_HConfigIsDefined(Config,keystring='name')) then ! replicate for src and dst
            src_name = ESMF_HConfigAsString(config,keyString='name',_RC)
            dst_name = src_name
            _RETURN(_SUCCESS)
         end if

         src_name = ESMF_HConfigAsString(config,keyString='src_name',_RC)
         dst_name = ESMF_HConfigAsString(config,keyString='dst_name',_RC)

         _RETURN(_SUCCESS)
      end subroutine get_names

      subroutine get_comps(config, src_comp, dst_comp, rc)
         type(ESMF_HConfig), intent(in) :: config
         character(:), allocatable :: src_comp
         character(:), allocatable :: dst_comp
         integer, optional, intent(out) :: rc

         integer :: status
         
         _ASSERT(ESMF_HConfigIsDefined(config,keyString='src_comp'), 'Connection must specify a src component')
         _ASSERT(ESMF_HConfigIsDefined(config,keyString='dst_comp'), 'Connection must specify a dst component')
         src_comp = ESMF_HConfigAsString(config,keyString='src_comp',_RC)
         dst_comp = ESMF_HConfigAsString(config,keyString='dst_comp',_RC)
         _RETURN(_SUCCESS)
      end subroutine get_comps

      subroutine get_intents(config, src_intent, dst_intent, rc)
         type(ESMF_HConfig), intent(in) :: config
         character(:), allocatable :: src_intent
         character(:), allocatable :: dst_intent
         integer, optional, intent(out) :: rc

         integer :: status

         ! defaults
         src_intent = 'export'
         dst_intent = 'import'

         if (ESMF_HConfigIsDefined(config,keyString='src_intent')) then
            src_intent = ESMF_HConfigAsString(config,keyString='src_intent',_RC)
         end if
         if (ESMF_HConfigIsDefined(config,keyString='dst_intent')) then
            dst_intent = ESMF_HConfigAsString(config,keyString='dst_intent',_RC)
         end if

         _RETURN(_SUCCESS)
      end subroutine get_intents

   end function parse_connections

end submodule parse_connections_smod