user_init Subroutine

public subroutine user_init(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_init(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_Field) :: humidity
        type(ESMF_LocStream) :: locstream
        type(ESMF_VM) :: vm
        type(ESMF_ArraySpec) :: arrayspec
        integer :: npets, de_id
        integer :: clb(1),cub(1),i
        integer(ESMF_KIND_I4), pointer :: mask(:)
        real(ESMF_KIND_R8), pointer :: lon(:),lat(:)
        real(ESMF_KIND_R8), pointer :: dstfptr(:)
        integer :: totalNumPoints=100

        ! Query component for VM and create a layout with the right breakdown
        call ESMF_GridCompGet(comp, vm=vm, rc=rc)
        if(rc/=ESMF_SUCCESS) return
        call ESMF_VMGet(vm, localPet=de_id, petCount=npets, rc=rc)
        if(rc/=ESMF_SUCCESS) return

        rc = ESMF_SUCCESS
        print *, de_id, "User Comp 2 Init starting"

        ! Create the LocStream:  Allocate space for the LocStream object,
        ! define the number and distribution of the locations.
        locstream=ESMF_LocStreamCreate(name="Equatorial Measurements", &
             maxIndex=totalNumPoints, &
             coordSys=ESMF_COORDSYS_SPH_DEG, &
             indexFlag=ESMF_INDEX_GLOBAL, &
             rc=rc)
        if (rc .ne. ESMF_SUCCESS) return
        
        ! Add key data (internally allocating memory).
        call ESMF_LocStreamAddKey(locstream,                 &
             keyName="ESMF:Lat",           &
             KeyTypeKind=ESMF_TYPEKIND_R8, &
             keyUnits="Degrees",           &
             keyLongName="Latitude", rc=rc)
        if (rc .ne. ESMF_SUCCESS) return

        call ESMF_LocStreamAddKey(locstream,                 &
             keyName="ESMF:Lon",           &
             KeyTypeKind=ESMF_TYPEKIND_R8, &
             keyUnits="Degrees",           &
             keyLongName="Longitude", rc=rc)
        if (rc .ne. ESMF_SUCCESS) return

        call ESMF_LocStreamAddKey(locstream,                 &
             keyName="ESMF:Mask",           &
             KeyTypeKind=ESMF_TYPEKIND_I4, &
             keyUnits="none",           &
             keyLongName="mask values", rc=rc)
        if (rc .ne. ESMF_SUCCESS) return


        ! Get coordinate memory
        call ESMF_LocStreamGetKey(locstream,                 &
             localDE=0,                    &
             keyName="ESMF:Lat",           &
             farray=lat,                   &
             rc=rc)
        if (rc .ne. ESMF_SUCCESS) return

        call ESMF_LocStreamGetKey(locstream,                 &
             localDE=0,                    &
             keyName="ESMF:Lon",           &
             farray=lon,                   &
             rc=rc)
        if (rc .ne. ESMF_SUCCESS) return

        ! Get mask memory
        call ESMF_LocStreamGetKey(locstream,                 &
             localDE=0,                    &
             keyName="ESMF:Mask",           &
             farray=mask,                   &
             rc=rc)
        if (rc .ne. ESMF_SUCCESS) return


        ! Create Field
        humidity = ESMF_FieldCreate(locstream, ESMF_TYPEKIND_R8, &
            name="humidity", rc=rc)
        if (rc .ne. ESMF_SUCCESS) return

        ! Get Field memory
        call ESMF_FieldGet(humidity, localDe=0, farrayPtr=dstfptr, &
             computationalLBound=clb, computationalUBound=cub, &
             rc=rc)
        if (rc .ne. ESMF_SUCCESS) return

        ! Set coordinate data and field data
        do i=clb(1),cub(1)
           lon(i)=(i-1)*360.0/REAL(totalNumPoints)
           lat(i)=0.1 ! Offset slighly, but just in lat, so get mapped to corresponding point in src. 
           dstfptr(i)=0.0 ! Init to 0.0
           mask(i)=0

           ! Mask out range 
           ! (Same range as in user_model1.F90)
           if ((lon(i) > 10.0) .and. (lon(i) < 20.0)) then
              mask(i)=2
           endif
        enddo
        
        call ESMF_StateAdd(importState, (/humidity/), rc=rc)
        if(rc/=ESMF_SUCCESS) return
        !   call ESMF_StatePrint(importState, rc=rc)
        
        print *, de_id, "User Comp 2 Init returning"


    end subroutine user_init