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
    integer               :: localPet
    type(ESMF_AttPack)    :: attpack
    type(ESMF_Field)      :: field
    type(ESMF_FieldBundle):: fieldbundle
    type(ESMF_Clock)      :: clockInternal
    
    ! Initialize user return code
    rc = ESMF_SUCCESS

    call ESMF_GridCompGet(comp, localPet=localPet, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    print *, localPet, "User Comp2 Init starting"

    call ESMF_AttributeAdd(comp, "CIM 1.5", "ModelComp", &
      attpack=attpack, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
    
    call ESMF_AttributeSet(comp, name="ShortName", value="ABC", &
      attpack=attpack, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
   
    field = ESMF_FieldEmptyCreate(name="myTestField", rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
   
    call ESMF_StateAdd(exportState, (/field/), rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
    
    fieldbundle = ESMF_FieldBundleCreate(name="myTestFieldBundle", rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    call ESMF_StateAdd(exportState, (/fieldbundle/), rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
    
    field = ESMF_FieldEmptyCreate(name="myTestField 1 in Bundle", rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
   
    call ESMF_FieldBundleAdd(fieldbundle, (/field/), rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
    
    field = ESMF_FieldEmptyCreate(name="myTestField 2 in Bundle", rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    call ESMF_FieldBundleAdd(fieldbundle, (/field/), rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out
    
    clockInternal = ESMF_ClockCreate(clock, rc=rc)  ! make a copy of incoming
    if (rc/=ESMF_SUCCESS) return ! bail out
    
    call ESMF_GridCompSet(comp, clock=clockInternal, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    print *, localPet, "User Comp2 Init returning"

  end subroutine user_init