myRunInFortran Subroutine

public subroutine myRunInFortran(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 myRunInFortran(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_Array)                            :: array
    real(ESMF_KIND_R8), pointer, dimension(:,:) :: farrayPtr
    integer                                     :: i,j
    type(ESMF_Field)                            :: field

    ! Initialize return code
    rc = ESMF_SUCCESS

    print *, "In myRunInFortran routine"

    ! print data that was modified on the C side in "myInitInC"
    print *, "In Fortran Component Run, farray= ", farray

    ! get Array object from export State    
    call ESMF_StateGet(exportState, "array1", array, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    ! access Array data through farrayPtr
    call ESMF_ArrayGet(array, localDE=0, farrayPtr=farrayPtr, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    ! values must be as set in "myInitInC"
    do j=1,2
      do i=1,5
        if ( abs(farrayPtr(i,j)-float(j-1)) > 1.e-8 ) then
          print *, "ERROR! farrayPtr has wrong value at i,j=",i,j
          rc = ESMF_FAILURE ! indicate failure in return code
          return ! bail out
        end if
      end do
    end do 

    ! modify the Array data again 
    do j=1,2
      do i=1,5
        farrayPtr(i,j) = float(j*10+i)
      end do
    end do 
    
    ! get Field object from import State    
    call ESMF_StateGet(importState, "Field from C", field, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

    ! print Field object to test its health
    call ESMF_FieldPrint(field, rc=rc)
    if (rc/=ESMF_SUCCESS) return ! bail out

  end subroutine myRunInFortran