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

Calls

proc~~user_init~84~~CallsGraph proc~user_init~84 user_init esmf_stateget esmf_stateget proc~user_init~84->esmf_stateget interface~esmf_fieldsmmstore ESMF_FieldSMMStore proc~user_init~84->interface~esmf_fieldsmmstore interface~esmf_vmget ESMF_VMGet proc~user_init~84->interface~esmf_vmget proc~esmf_cplcompget ESMF_CplCompGet proc~user_init~84->proc~esmf_cplcompget proc~esmf_fieldsmmstorefromfile ESMF_FieldSMMStoreFromFile interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorefromfile proc~esmf_fieldsmmstorefromfiletr ESMF_FieldSMMStoreFromFileTR interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorefromfiletr proc~esmf_fieldsmmstorei4 ESMF_FieldSMMStoreI4 interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorei4 proc~esmf_fieldsmmstorei4tr ESMF_FieldSMMStoreI4TR interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorei4tr proc~esmf_fieldsmmstorei8 ESMF_FieldSMMStoreI8 interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorei8 proc~esmf_fieldsmmstorei8tr ESMF_FieldSMMStoreI8TR interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorei8tr proc~esmf_fieldsmmstorenf ESMF_FieldSMMStoreNF interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorenf proc~esmf_fieldsmmstorenftr ESMF_FieldSMMStoreNFTR interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorenftr proc~esmf_fieldsmmstorer4 ESMF_FieldSMMStoreR4 interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorer4 proc~esmf_fieldsmmstorer4tr ESMF_FieldSMMStoreR4TR interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorer4tr proc~esmf_fieldsmmstorer8 ESMF_FieldSMMStoreR8 interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorer8 proc~esmf_fieldsmmstorer8tr ESMF_FieldSMMStoreR8TR interface~esmf_fieldsmmstore->proc~esmf_fieldsmmstorer8tr proc~esmf_vmgetdefault ESMF_VMGetDefault interface~esmf_vmget->proc~esmf_vmgetdefault proc~esmf_vmgetpetspecific ESMF_VMGetPetSpecific interface~esmf_vmget->proc~esmf_vmgetpetspecific proc~esmf_compget ESMF_CompGet proc~esmf_cplcompget->proc~esmf_compget proc~esmf_compstatusget ESMF_CompStatusGet proc~esmf_cplcompget->proc~esmf_compstatusget proc~esmf_cplcompgetinit ESMF_CplCompGetInit proc~esmf_cplcompget->proc~esmf_cplcompgetinit proc~esmf_imerr ESMF_IMErr proc~esmf_cplcompget->proc~esmf_imerr proc~esmf_logfounderror ESMF_LogFoundError proc~esmf_cplcompget->proc~esmf_logfounderror

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 :: itemcount
      type(ESMF_Field) :: humidity1, humidity2
      type(ESMF_VM) :: vm
      integer(ESMF_KIND_I4), allocatable          :: factorList(:)
      integer, allocatable                        :: factorIndexList(:,:)
      integer       :: localPet

      rc = ESMF_SUCCESS
      print *, "User Coupler Init starting"

      call ESMF_CplCompGet(comp, vm=vm, rc=rc)
      call ESMF_VMGet(vm, localPET=localPet, rc=rc)

      ! uncomment the following when locstream supports reconcile

      ! 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 (SMM) here, so first we must make a new
      ! call to reconcile the object lists in all the import and export states.

      !call ESMF_StateReconcile(importState, vm=vm, rc=rc)
      !if(rc/=ESMF_SUCCESS) return

      !call ESMF_StateReconcile(exportState, vm=vm, rc=rc)
      !if(rc/=ESMF_SUCCESS) return

      call ESMF_StateGet(importState, itemcount=itemcount, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      print *, "Import State contains ", itemcount, " items."
      call ESMF_StateGet(exportState, itemcount=itemcount, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      print *, "Export State contains ", itemcount, " items."
       
      ! Get input data
      call ESMF_StateGet(importState, "humidity", humidity1, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      ! call ESMF_FieldPrint(humidity1, rc=rc)

      ! Get location of output data
      call ESMF_StateGet(exportState, "humidity", humidity2, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      ! call ESMF_FieldPrint(humidity2, rc=rc)

      ! Get VM from coupler component to send down to SMM Store routine
      call ESMF_CplCompGet(comp, vm=vm, rc=rc)
      if(rc/=ESMF_SUCCESS) return

      ! These are fields on different Grids - call SMMStore to set
      ! up the SMM structure

      ! initialize factorList and factorIndexList
      ! Nodal distribution of indices:
      ! 1 3 1
      ! 2 4 2
      ! 1 2 1
      ! src data = ((1 2 3 4) (1 2) (1 2) (1))
      ! the diagonal of the 9x9 diagonal matrix on 4 PETs is ((1 2 3) (1 2) (1 2) (1 4))
      ! result = ((1 4 9) (1 4) (1 4) (1 4))
      if (localPet == 0) then
          ! 4 -> 3
          allocate(factorList(3))
          allocate(factorIndexList(2,3))
          factorList = (/1,2,3/)
          factorIndexList(1,:) = (/1, 2, 4/)
          factorIndexList(2,:) = (/1, 2, 3/)
          call ESMF_FieldSMMStore(humidity1, humidity2, routehandle, &
              factorList, factorIndexList, rc=rc)
          if(rc/=ESMF_SUCCESS) return
          deallocate(factorList, factorIndexList)
      else if (localPet == 1) then
          ! 2 -> 2
          allocate(factorList(2))
          allocate(factorIndexList(2,2))
          factorList = (/1,2/)
          factorIndexList(1,:) = (/3, 6/)
          factorIndexList(2,:) = (/4, 5/)
          call ESMF_FieldSMMStore(humidity1, humidity2, routehandle, &
              factorList, factorIndexList, rc=rc)
          if(rc/=ESMF_SUCCESS) return
          deallocate(factorList, factorIndexList)
      else if (localPet == 2) then
          ! 2 -> 2
          allocate(factorList(2))
          allocate(factorIndexList(2,2))
          factorList = (/1,2/)
          factorIndexList(1,:) = (/7, 8/)
          factorIndexList(2,:) = (/6, 7/)
          call ESMF_FieldSMMStore(humidity1, humidity2, routehandle, &
              factorList, factorIndexList, rc=rc)
          if(rc/=ESMF_SUCCESS) return
          deallocate(factorList, factorIndexList)
      else if (localPet == 3) then
          ! 1 -> 2
          allocate(factorList(2))
          allocate(factorIndexList(2,2))
          factorList = (/1,4/)
          factorIndexList(1,:) = (/9,9/)
          factorIndexList(2,:) = (/8,9/)
          call ESMF_FieldSMMStore(humidity1, humidity2, routehandle, &
              factorList, factorIndexList, rc=rc)
          if(rc/=ESMF_SUCCESS) return
          deallocate(factorList, factorIndexList)
      endif

      print *, "User Coupler Init returning"
   
    end subroutine user_init