ic_init Subroutine

private recursive subroutine ic_init(comp, importState, exportState, clock, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_GridComp) :: comp
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc

Source Code

  recursive subroutine ic_init(comp, importState, exportState, clock, rc)
    type(ESMF_GridComp)   :: comp
    type(ESMF_State)      :: importState, exportState
    type(ESMF_Clock)      :: clock
    integer, intent(out)  :: rc

    ! Local variables
    integer                 :: userrc
    character(ESMF_MAXSTR)  :: prefix
    character(ESMF_MAXSTR)  :: output
    type(ESMF_Clock)        :: clockCopy
    integer                 :: phase
    character(1024)         :: jsonString
    character(2)            :: phaseString
    character(ESMF_MAXSTR)  :: compName
    !type(ESMF_Clock)        :: clockInternal
    !character(64)           :: currTimeJSON
    !logical                 :: clockIsPresent
    
    ! Initialize user return code
    rc = ESMF_SUCCESS

    call prefixString(comp, prefix=prefix, rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out
    
    call ESMF_GridCompGet(comp, currentPhase=phase, name=compName, &
        rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    !---------------------------------------------------------------------------
    ! Start Compliance Checking: InitializePrologue
    if (ccfDepth <= maxDepth .or. maxDepth < 0) then
    
    if (outputJSON) then
        call JSON_LogCtrlFlow("start_prologue", comp, rc)
        if (ESMF_LogFoundError(rc, &
             line=__LINE__, file=FILENAME)) return  ! bail out
    endif
!    if (outputTrace) then
!       call ESMF_TracePhasePrologueEnter(comp, rc=rc)
!       if (ESMF_LogFoundError(rc, &
!            line=__LINE__, file=FILENAME)) return  ! bail out
!    endif

    write(output,*) ">START InitializePrologue for phase=", phase
    call Compliance_LogWrite(trim(prefix)//trim(output), &
      ESMF_LOGMSG_INFO, rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    if (outputText) then
      
       ! compliance check importState
       call checkState(prefix, referenceName="importState", state=importState, &
            rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! compliance check exportState
       call checkState(prefix, referenceName="exportState", state=exportState, &
            rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! compliance check clock usage
       call clockUsageIncoming(prefix, clock=clock, clockCopy=clockCopy, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! check Component statistics
       call checkComponentStatistics(prefix, comp=comp, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out

       ! compliance check Component metadata
       call checkComponentMetadata(prefix, comp=comp, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
    end if
    
    write(output,*) ">STOP InitializePrologue for phase=", phase
    call Compliance_LogWrite(trim(prefix)//trim(output), &
      ESMF_LOGMSG_INFO, rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    if (outputJSON) then
        call JSON_LogCtrlFlow("stop_prologue", comp, rc)
        if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return  ! bail out
        call JSON_LogCtrlFlow("start_phase", comp, rc)
        if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return  ! bail out
    endif
    if (outputTrace) then
       call ESMF_TracePhasePrologueEnter(comp, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return               
       call ESMF_TraceMemInfo(rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return                              
       if (ESMF_ClockIsCreated(clock)) then
          call ESMF_TraceClock(clock, rc=rc)
          if (ESMF_LogFoundError(rc, &
               line=__LINE__, file=FILENAME)) return                              
       endif
       !call ESMF_TraceComponentInfo(comp, rc=rc)
       !if (ESMF_LogFoundError(rc, &
       !     line=__LINE__, file=FILENAME)) return                              
       call ESMF_TracePhaseEnter(comp, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return                              
    endif
    endif
 
    ! Stop Compliance Checking: InitializePrologue
    !---------------------------------------------------------------------------
    ccfDepth = ccfDepth + 1

    ! Call the actual Initialize routine
    call ESMF_GridCompInitializeAct(comp, importState, exportState, clock, &
      phase=phase, userRc=userrc, rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out
   
    ccfDepth = ccfDepth - 1
    !---------------------------------------------------------------------------
    ! Start Compliance Checking: InitializeEpilogue
    if (ccfDepth <= maxDepth .or. maxDepth < 0) then

       if (outputTrace) then
          call ESMF_TracePhaseExit(comp, rc=rc)
          if (ESMF_LogFoundError(rc, &
               line=__LINE__, file=FILENAME)) return                              
          if (ESMF_ClockIsCreated(clock)) then
             call ESMF_TraceClock(clock, rc=rc)
             if (ESMF_LogFoundError(rc, &
                  line=__LINE__, file=FILENAME)) return                              
          endif
          call ESMF_TraceMemInfo(rc=rc)
          if (ESMF_LogFoundError(rc, &
               line=__LINE__, file=FILENAME)) return
          call ESMF_TracePhaseEpilogueExit(comp, rc=rc)
          if (ESMF_LogFoundError(rc, &
                   line=__LINE__, file=FILENAME)) return                              
       endif
    
    if (outputJSON) then
        call JSON_LogCtrlFlow("stop_phase", comp, rc)
        if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return  ! bail out
        call JSON_LogCtrlFlow("start_epilogue", comp, rc)
        if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return  ! bail out
    endif

    call prefixString(comp, prefix=prefix, forward=.false., rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out
    
    write(output,*) ">START InitializeEpilogue for phase=", phase
    call Compliance_LogWrite(trim(prefix)//trim(output), &
      ESMF_LOGMSG_INFO, rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out
    
    if (outputText) then
  
       ! check Component statistics
       call checkComponentStatistics(prefix, comp=comp, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! compliance check Component metadata
       call checkComponentMetadata(prefix, comp=comp, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! compliance check importState
       call checkState(prefix, referenceName="importState", state=importState, &
            rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! compliance check exportState
       call checkState(prefix, referenceName="exportState", state=exportState, &
            rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! compliance check clock usage
       call clockUsageOutgoing(prefix, clock=clock, clockCopy=clockCopy, rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
       
       ! compliance check internal Clock
       call checkInternalClock(prefix, comp=comp, clock=clock, &
            mustMatchCurr=.false., mustReachStop=.false., rc=rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, &
            file=FILENAME)) &
            return  ! bail out
    
    end if
    
    write(output,*) ">STOP InitializeEpilogue for phase=", phase
    call Compliance_LogWrite(trim(prefix)//trim(output), &
      ESMF_LOGMSG_INFO, rc=rc)
    if (ESMF_LogFoundError(rc, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    if (outputJSON) then
       call JSON_LogCtrlFlow("stop_epilogue", comp, rc)
       if (ESMF_LogFoundError(rc, &
            line=__LINE__, file=FILENAME)) return  ! bail out
    endif
    !if (outputTrace) then
    !   call ESMF_TraceComponentInfo(comp, "", rc=rc)
    !   if (ESMF_LogFoundError(rc, &
    !        line=__LINE__, file=FILENAME)) return  ! bail out
    !   call ESMF_TracePhaseEpilogueExit(comp, rc=rc)
    !   if (ESMF_LogFoundError(rc, &
    !        line=__LINE__, file=FILENAME)) return  ! bail out
    !endif
    
    endif  
    ! Stop Compliance Checking: InitializeEpilogue
    !---------------------------------------------------------------------------
    
    ! if not bailed for other reasons then pass back the actual userrc
    rc = userrc

  end subroutine ic_init