\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.
INTEGER :: N
INTEGER :: arrayOne(1:N)
INTEGER :: arrayTwo(1:N)
LOGICAL :: arraysMatch
....
arraysMatch = CompareArray( arrayOne, arrayTwo, N )
in | arrayOne(1:N) | INTEGER | |
---|---|---|---|
in | arrayTwo(1:N) | INTEGER | |
in | N | INTEGER | |
out | arraysMatch | INTEGER |
@}
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer | :: | arrayOne(1:N) | ||||
integer | :: | arrayTwo(1:N) | ||||
integer | :: | N |
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