recursive subroutine MAPL_GenericRunChildren ( GC, IMPORT, EXPORT, CLOCK, RC)
!ARGUMENTS:
type(ESMF_GridComp), intent(INOUT) :: GC ! Gridded component
type(ESMF_State), intent(INOUT) :: IMPORT ! Import state
type(ESMF_State), intent(INOUT) :: EXPORT ! Export state
type(ESMF_Clock), intent(INOUT) :: CLOCK ! The clock
integer, optional, intent( OUT) :: RC ! Error code:
!EOPI
! ErrLog Variables
character(len=ESMF_MAXSTR) :: IAm
character(len=ESMF_MAXSTR) :: comp_name
integer :: status
integer :: userRC
! Local derived type aliases
type (MAPL_MetaComp),pointer :: STATE
character(len=ESMF_MAXSTR) :: CHILD_NAME
integer :: I, J
integer :: NC
integer :: PHASE
integer :: NUMPHASES
integer :: MAXPHASES
type (MAPL_MetaPtr), allocatable :: CHLDMAPL(:)
type(ESMF_GridComp), pointer :: gridcomp
type(ESMF_State), pointer :: child_import_state
type(ESMF_State), pointer :: child_export_state
!=============================================================================
! Begin...
_UNUSED_DUMMY(IMPORT)
_UNUSED_DUMMY(EXPORT)
! Get the target components name and set-up traceback handle.
! -----------------------------------------------------------
Iam = "MAPL_GenericRunChildren"
call ESMF_GridCompGet( GC, NAME=comp_name, RC=status )
_VERIFY(status)
Iam = trim(comp_name) // trim(Iam)
! Retrieve the pointer to the internal state. It comes in a wrapper.
! ------------------------------------------------------------------
call MAPL_InternalStateGet ( GC, STATE, RC=status)
_VERIFY(status)
!@ call MAPL_TimerOn (STATE,"GenRunTot")
! Run the children
! ----------------
NC = STATE%get_num_children()
allocate(CHLDMAPL(NC), stat=status)
MAXPHASES = 0
do I=1,NC
gridcomp => STATE%GET_CHILD_GRIDCOMP(I)
call MAPL_GetObjectFromGC(gridcomp, CHLDMAPL(I)%PTR, RC=status)
_VERIFY(status)
MAXPHASES = MAX(MAXPHASES, SIZE(CHLDMAPL(I)%PTR%PHASE_RUN))
end do
do PHASE = 1, MAXPHASES
do I=1,NC
NUMPHASES = SIZE(CHLDMAPL(I)%PTR%PHASE_RUN)
if (PHASE .le. NUMPHASES) then
gridcomp => STATE%GET_CHILD_GRIDCOMP(I)
call ESMF_GridCompGet( gridcomp, NAME=CHILD_NAME, RC=status )
_VERIFY(status)
call MAPL_TimerOn (STATE,trim(CHILD_NAME))
child_import_state => STATE%get_child_import_state(i)
child_export_state => STATE%get_child_export_state(i)
call ESMF_GridCompRun (gridcomp, &
importState=child_import_state, &
exportState=child_export_state, &
clock=CLOCK, PHASE=CHLDMAPL(I)%PTR%PHASE_RUN(PHASE), &
userRC=userRC, _RC )
_VERIFY(userRC)
call MAPL_TimerOff(STATE,trim(CHILD_NAME))
end if
!ALT question for Max - if user wants to run particular phase only, when should we run couplers
if (PHASE == NUMPHASES) then
do J=1,NC
if(STATE%CCcreated(I,J)) then
child_export_state => STATE%get_child_export_state(i)
child_import_state => STATE%get_child_import_state(j)
call ESMF_CplCompRun (STATE%CCS(I,J), &
importState=child_export_state, &
exportState=child_import_state, &
clock=CLOCK, userRC=userRC, _RC)
_VERIFY(userRC)
endif
enddo
end if
enddo
enddo
deallocate(CHLDMAPL)
!@ call MAPL_TimerOff(STATE,"GenRunTot")
_RETURN(ESMF_SUCCESS)
end subroutine MAPL_GenericRunChildren