findColumnIntersections Function

private pure function findColumnIntersections(array) result(intersections)

Finds intersections between elements of the first column and other columns in the input array.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: array(:,:)

Return Value integer, allocatable, (:)


Called by

proc~~findcolumnintersections~~CalledByGraph proc~findcolumnintersections findColumnIntersections proc~write Colormaps_info%write proc~write->proc~findcolumnintersections

Source Code

   pure function findColumnIntersections(array) result(intersections)
      integer, intent(in) :: array(:,:)
      integer, allocatable :: intersections(:)
      logical :: found(size(array, 1))
      integer :: i, j

      do i = 1, size(array, 1)
         found(i) = .true.
         do j = 2, size(array, 2)
            ! Check if all elements in the current column are non-zero
            if ( .not. all(array(:, j) == 0)) then
               ! Check if the current element in the first column exists in the current column
               found(i) = found(i) .and. any(array(i, 1) == array(:, j))
            end if
         end do
      end do

      ! Allocate and populate the intersections array
      allocate(intersections(size(pack(array(:, 1), mask=found))))
      intersections = pack(array(:, 1), mask=found)
   end function findColumnIntersections