CompareArray Function

public function CompareArray(arrayOne, arrayTwo, N) result(arraysMatch)

\addtogroup SELF_SupportRoutines @{ \fn CompareArray Compares to INTEGER arrays and determines if they are identical.

A logical is returned that specifies whether or not two arrays are identical. To determine if the two arrays are identical, the sum of the difference between each element in the input array is calculated. If the arrays are identical, each contribution to the sum is zero and hence the sum is zero. If the sum is non-zero, the arrays are distinct.

This routine is used in the \ref HexMeshClass module. A face of an element in an unstructured mesh is identified by its four corner nodes. When identifying unique faces in an unstructured mesh, we need to determine if two elements share a face. This can be accomplished by comparing the four corner nodes (from each element) that define each face.

Usage :

INTEGER :: N
INTEGER :: arrayOne(1:N)
INTEGER :: arrayTwo(1:N)
LOGICAL :: arraysMatch
....
arraysMatch = CompareArray( arrayOne, arrayTwo, N )

Parameters :

in arrayOne(1:N) INTEGER
in arrayTwo(1:N) INTEGER
in N INTEGER
out arraysMatch INTEGER

@}

Arguments

TypeIntentOptionalAttributesName
integer :: arrayOne(1:N)
integer :: arrayTwo(1:N)
integer :: N

Return Value logical


Contents

Source Code


Source Code

  function CompareArray(arrayOne,arrayTwo,N) result(arraysMatch)

    implicit none
    integer :: N
    integer :: arrayOne(1:N),arrayTwo(1:N)
    logical :: arraysMatch
    ! LOCAL
    integer :: i,theSumOfDiffs

    theSumOfDiffs = 0

    do i = 1,N
      theSumOfDiffs = theSumOfDiffs+abs(arrayOne(i)-arrayTwo(i))
    enddo

    if(theSumOfDiffs == 0) then
      arraysMatch = .true.
    else
      arraysMatch = .false.
    endif

  endfunction CompareArray