user_run Subroutine

private subroutine user_run(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

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

    ! Local variables
    type(ESMF_Array)      :: array
    real(ESMF_KIND_R8), pointer :: farrayPtr(:,:)   ! matching F90 array pointer
    integer               :: i, j, l1, l2
    character(len=ESMF_MAXSTR) :: compName
    type(dataWrapper)  :: intStatePtr
    real(ESMF_KIND_R8) :: offset

    call ESMF_GridCompGet(comp, name=compName, rc=rc)
    call ESMF_GridCompGetInternalState(comp, intStatePtr, rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    offset = intStatePtr%p%offset

    ! Initialize return code
    rc = ESMF_SUCCESS

    ! Get the source Array from the export State
    call ESMF_StateGet(exportState, "array data", array, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    ! Gain access to actual data via F90 array pointer
    call ESMF_ArrayGet(array, localDe=0, farrayPtr=farrayPtr, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    ! increment each element by the offset set in the init routine and passed over using
    ! internal state
    do j = lbound(farrayPtr, 2), ubound(farrayPtr, 2)
        do i = lbound(farrayPtr, 1), ubound(farrayPtr, 1)
                        farrayPtr(i,j) = farrayPtr(i,j) + offset
      enddo
   enddo

#if 0
   l1=lbound(farrayPtr,1)
   l2=lbound(farrayPtr,2)
   print *, "User CompB Run returning ", trim(compName), farrayPtr(l1,l2)
#endif

   print *, "User CompB Run returning ", trim(compName)

  end subroutine user_run