user_run Subroutine

public subroutine user_run(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_run(comp, importState, exportState, clock, rc)
    type(ESMF_CplComp) :: comp
    type(ESMF_State) :: importState, exportState
    type(ESMF_Clock) :: clock
    integer, intent(out) :: rc

    ! Local variables
    type(ESMF_Array) :: srcArray, dstArray
    character(len=ESMF_MAXSTR) :: imStateName, exStateName, stateItemNames(4)
    integer :: itemcount1, itemcount2, i
    type(ESMF_State) :: state
    ! Initialize return code
    rc = ESMF_SUCCESS

    ! Get import State information
    call ESMF_StateGet(importState, name=imStateName, itemNameList=stateItemNames, itemcount=itemcount1, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
    ! Get export state information
    call ESMF_StateGet(exportState, name=exStateName, itemcount=itemcount2, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    if (itemcount1 .ne. itemcount2) then
       print *, 'Coupler: the import state and export state items do not match:', itemcount1, itemcount2
       rc=ESMF_FAILURE
       return
    end if

    ! Get the srcArray from the import state item and dstArray from the export state and do a regrid
    do i=1,itemcount1
        call ESMF_StateGet(importState, stateItemNames(i), state, rc=rc)
        if (rc/=ESMF_SUCCESS) return ! bail out
        ! Get source Array out of import state
        call ESMF_StateGet(state, "array data", srcArray, rc=rc)
        if (rc/=ESMF_SUCCESS) return ! bail out

        ! Get destination Array out of export state
        call ESMF_StateGet(exportState, stateItemNames(i), dstArray, rc=rc)
        if (rc/=ESMF_SUCCESS) return ! bail out

        ! Use ArrayRedist() to take data from srcArray to dstArray according to import state name
        call ESMF_ArrayRedist(srcArray=srcArray, dstArray=dstArray, &
                        routehandle=rhandle(i), rc=rc)
        if (rc/=ESMF_SUCCESS) return ! bail out
    end do

  end subroutine user_run