user_final Subroutine

public subroutine user_final(comp, importState, exportState, clock, rc)

Arguments

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

Source Code

  subroutine user_final(comp, importState, exportState, clock, rc)
    type(ESMF_CplComp) :: comp
    type(ESMF_State) :: importState, exportState
    type(ESMF_Clock) :: clock
    integer, intent(out) :: rc

    character(len=ESMF_MAXSTR) :: stateItemNames(4)
    integer :: itemcount, i
    type(ESMF_Array) :: array
    type(ESMF_Distgrid) :: distgrid

    ! Initialize return code
    rc = ESMF_SUCCESS

    ! Get export state information
    call ESMF_StateGet(exportState, itemNameList=stateItemNames, itemcount=itemcount, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    ! Release resources stored for the ArrayRedist.
    do i=1,itemcount
       call ESMF_ArrayRedistRelease(routehandle=rhandle(i), rc=rc)
       if (rc/=ESMF_SUCCESS) return ! bail out

       ! destroy array and distgrid in the export state
       call ESMF_StateGet(exportState, stateItemNames(i), array, rc=rc)
       if (rc/=ESMF_SUCCESS) return ! bail out
       call ESMF_ArrayGet(array, distgrid=distgrid, rc=rc)
       if (rc/=ESMF_SUCCESS) return ! bail out
       call ESMF_ArrayDestroy(array, rc=rc)
       if (rc/=ESMF_SUCCESS) return ! bail out
       call ESMF_DistGridDestroy(distgrid, rc=rc)
       if (rc/=ESMF_SUCCESS) return ! bail out
    end do

  end subroutine user_final