user_init Subroutine

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

Arguments

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

Source Code

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

!   ! Local variables
      type(ESMF_Field) :: humidity
      type(ESMF_VM) :: vm
      type(ESMF_DELayout) :: delayout
      type(ESMF_FieldDataMap) :: datamap
      type(ESMF_IGrid) :: igrid1
      type(ESMF_ArraySpec) :: arrayspec
      real(ESMF_KIND_R8), dimension(:,:), pointer :: idata
      real(ESMF_KIND_R8) :: min(2)
      real(ESMF_KIND_R8) :: delta1(40), delta2(50)
      integer :: countsPerDE1(3), countsPerDE2(2)
      integer :: npets, de_id
      type(ESMF_IGridHorzStagger) :: horzStagger
      type(ESMF_CoordOrder) :: coordOrder
      integer :: status


      ! Query component for VM and create a layout with the right breakdown
      call ESMF_GridCompGet(comp, vm=vm, rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10
      call ESMF_VMGet(vm, petCount=npets, rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10 
      delayout = ESMF_DELayoutCreate(vm, (/ npets/2, 2 /), rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10
      
      ! and get our local de number
      call ESMF_DELayoutGetDeprecated(delayout, localDE=de_id, rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10
      
      print *, de_id, "User Comp 2 Init starting"

      ! Add a "humidity" field to the import state.
      countsPerDE1 = (/ 10, 18, 12 /)
      countsPerDE2 = (/ 22, 28 /)
      min(1) = 0.0
      delta1 = (/ 1.0, 1.0, 1.0, 1.1, 1.1, 1.1, 1.2, 1.2, 1.3, 1.4, &
                  1.4, 1.5, 1.6, 1.6, 1.6, 1.8, 1.8, 1.7, 1.7, 1.6, &
                  1.6, 1.6, 1.8, 1.8, 2.0, 2.0, 2.2, 2.2, 2.2, 2.2, &
                  2.0, 1.7, 1.5, 1.3, 1.2, 1.1, 1.0, 1.0, 1.0, 0.9 /)
      min(2) = 0.0
      delta2 = (/ 0.8, 0.8, 0.8, 0.8, 0.8, 0.7, 0.7, 0.6, 0.7, 0.8, &
                  0.9, 0.9, 0.9, 0.9, 1.0, 1.0, 1.0, 1.0, 0.9, 1.0, &
                  1.0, 1.0, 1.0, 1.1, 1.2, 1.3, 1.3, 1.3, 1.4, 1.4, &
                  1.4, 1.4, 1.4, 1.4, 1.4, 1.3, 1.3, 1.3, 1.2, 1.2, &
                  1.1, 1.0, 1.0, 0.9, 0.8, 0.7, 0.6, 0.6, 0.5, 0.5 /)

      horzStagger     = ESMF_IGRID_HORZ_STAGGER_D_NE
      coordOrder      = ESMF_COORD_ORDER_YXZ

      call ESMF_FieldDataMapSetDefault(datamap, ESMF_INDEX_IJ, rc=rc)
      if (status .ne. ESMF_SUCCESS) goto 10

      igrid1 = ESMF_IGridCreateHorzXY( minGlobalCoordPerDim=min, &
                                    delta1=delta1, delta2=delta2, &
                                    horzStagger=horzStagger, &
                                    coordOrder=coordOrder, &
                                    name="source igrid", rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10
      call ESMF_IGridDistribute(igrid1, delayout=delayout, &
                               countsPerDEDim1=countsPerDE1, &
                               countsPerDEDim2=countsPerDE2, &
                               rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10

      ! Set up a 2D real array
      call ESMF_ArraySpecSet(arrayspec, rank=2, &
                             typekind=ESMF_TYPEKIND_R8)

      ! Create the field and have it create the array internally
      humidity = ESMF_FieldCreate(igrid1, arrayspec, &
                                  horzRelloc=ESMF_CELL_NFACE, datamap=datamap, &
                                  haloWidth=0, name="humidity", rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10

      ! Get the allocated array back and get an F90 array pointer
      call ESMF_FieldGetDataPointer(humidity, idata, rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10

      call ESMF_StateAddField(importState, (/humidity/), rc=status)
      if (status .ne. ESMF_SUCCESS) goto 10

      print *, de_id, "User Comp 2 Init returning"
   
10 continue
      rc = status

    end subroutine user_init