ESMF_InterArrayCreateDGConn Function

public function ESMF_InterArrayCreateDGConn(connectionList, initFlag, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_DistGridConnection), intent(in), optional :: connectionList(:)
logical, intent(in), optional :: initFlag
integer, intent(out), optional :: rc

Return Value type(ESMF_InterArray)


Source Code

  function ESMF_InterArrayCreateDGConn(connectionList, initFlag, rc)
!
! !ARGUMENTS:
    type(ESMF_DistGridConnection), intent(in),  optional :: connectionList(:)
    logical,                       intent(in),  optional :: initFlag
    integer,                       intent(out), optional :: rc
!         
! !RETURN VALUE:
    type(ESMF_InterArray) :: ESMF_InterArrayCreateDGConn
!
! !DESCRIPTION:
!   Create a compacted 2D {\tt ESMF\_InterArray} from a list of 
!   DistGridConnection objects. All of the DistGridConnection objects in
!   {\tt connectionLis} must have the same elementCount.
!
!   The arguments are:
!   \begin{description}
!   \item[{[connectionList}]]
!     List of DistGridConnection objects.
!   \item[{[initFlag}]]
!     Flag indicating initialization status of the {\tt connectionList}. A value
!     of {\tt .true.} indicates that the {\tt connectionList} has been
!     initialized, and the entries are valid for use. A value of {\tt .false.}
!     inidicates that the {\tt connectionList} has not been initialized, and
!     therefore an InterArray with maximum size elementCount must be created.
!     This option is for passing connection lists from the C++ layer back to the
!     Fortran layer. The default is {\tt .true.}.
!   \item[{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOPI
!------------------------------------------------------------------------------
    integer               :: localrc      ! local return code
    integer               :: i, elementCount, stat, connectionListSize
    integer, pointer      :: farray(:,:)
    type(ESMF_InterArray) :: array
    logical               :: initAux
    
    ! initialize return code; assume routine not implemented
    localrc = ESMF_RC_NOT_IMPL
    if (present(rc)) rc = ESMF_RC_NOT_IMPL
    
    ! set initAux
    initAux = .true.  ! default
    if (present(initFlag)) initAux = initFlag
    
    ! mark this InterArray as invalid
    call c_ESMC_InterArraySetInvalid(array, localrc)
    ESMF_InterArrayCreateDGConn = array
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    
    ! construction
    connectionListSize = 0
    if (present(connectionList)) connectionListSize = size(connectionList)
    if (connectionListSize > 0) then
      ! determine elementCount
      if (initAux) then
        ! incoming connections are valid, and assume all connections have same
        ! elementCount
        elementCount = connectionList(1)%elementCount
      else
        ! incoming connections are not valid -> must assume larges possible case
        elementCount = 2*7 + 2
      endif
      ! allocate 2D Fortran array to hold connectionList in the internal format
      allocate(farray(elementCount,size(connectionList)), stat=stat)
      if (ESMF_LogFoundAllocError(stat, msg="allocating farray", &
        ESMF_CONTEXT)) &
        return  ! bail out
      if (initAux) then
        ! incoming connections are valid
        do i=1, size(connectionList)
ESMF_INIT_CHECK_SHALLOW_SHORT(ESMF_DistGridConnectionGetInit, connectionList(i), rc)
          if (connectionList(i)%elementCount /= elementCount) then
            call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_BAD, &
              msg="elementCount mismatch between DistGridConnection elements.", &
              ESMF_CONTEXT, rcToReturn=rc)
            return
          endif
          ! copy the connection information
          farray(:,i) = connectionList(i)%connection(1:elementCount)
        enddo
      endif
      ! create InterArray for farray and transfer ownership
      array = ESMF_InterArrayCreate(farray2D=farray, &
        transferOwnership=.true., rc=localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
    else
      ! dummy InterArray
      array = ESMF_InterArrayCreate(rc=localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
    endif
 
    ! set return value
    ESMF_InterArrayCreateDGConn = array
    
    ! return successfully
    if (present(rc)) rc = ESMF_SUCCESS
 
  end function ESMF_InterArrayCreateDGConn