user_init Subroutine

public subroutine user_init(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_init(comp, importState, exportState, clock, rc)
        type(ESMF_CplComp) :: comp
        type(ESMF_State) :: importState, exportState
        type(ESMF_Clock) :: clock
        integer,intent(out) :: rc
  
        ! Local variables
        integer :: status = ESMF_SUCCESS
        integer :: itemcount
        type(ESMF_Array) :: sorted_data1, sorted_data2
        type(ESMF_VM) :: vm
        integer :: pet_id
  
        print *, "User Coupler Init starting"
        status = ESMF_FAILURE
  
        ! Get VM from coupler component
        call ESMF_CplCompGet(comp, vm=vm, rc=status)
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        call ESMF_VMGet(vm, localPET=pet_id, rc=status)
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
  
        ! Since the components we are coupling between are running concurrently,
        ! they have each separately created ESMF objects.   We are planning to
        ! use a communications call (Redist) here, so first we must make a new
        ! call to reconcile the object lists in all the import and export states.
  
        ! New routine:
        ! Must be called on each state which is going to be accessed from
        ! this coupler.  When the call returns all objects which were not
        ! in existence on all PETs now have an object which represents them.
        call ESMF_StateReconcile(importState, vm=vm, rc=status)
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        !call ESMF_StatePrint(importState, rc=status)
        !if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
        !    ESMF_CONTEXT, rcToReturn=rc)) return
  
        call ESMF_StateReconcile(exportState, vm=vm, rc=status)
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        !call ESMF_StatePrint(exportState, rc=status)
        !if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
        !    ESMF_CONTEXT, rcToReturn=rc)) return
  
        call ESMF_StateGet(importState, itemcount=itemcount, rc=status)
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        !print *, "Import State contains ", itemcount, " items."
        call ESMF_StateGet(exportState, itemcount=itemcount, rc=status)
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        !print *, "Export State contains ", itemcount, " items."

        ! Get the src and dst arrays
        call ESMF_StateGet(importState, "sorted_data1", sorted_data1, rc=status)       
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        call ESMF_StateGet(exportState, "sorted_data2", sorted_data2, rc=status)       
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        ! precompute redist handle
        call ESMF_ArrayRedistStore(sorted_data1, sorted_data2, redistRH12, &
            rc=status)
        if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        rc = status
  
    end subroutine user_init