! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 5.25. Connection matrix by Warshall's algorithm.
  program F25
    implicit none
    integer, parameter :: Nodes = 6
    logical, dimension(Nodes, Nodes) :: A
    integer :: I, J
! start program F25
    open (unit = 1, file = "f25.txt", status = "old", action = "read", position = "rewind")
    do I = 1, Nodes
      read (unit = 1, fmt = *) A(I, :)
    end do
    do I = 1, Nodes
      do J = 1, Nodes
        if (A(J, I)) then
          A(J, :) = A(J, :) .or. A(I, :)  ! Merge row I into row J.
        end if
      end do
    end do
    do I = 1, Nodes
      write (unit = *, fmt = *) A(I, :)
    end do
    stop
  end program F25
