
 SUBROUTINE Print( A )
   IMPLICIT NONE

   REAL, DIMENSION(:,:) :: A 

   integer i, j

   print *

   DO i = 1, SIZE(A(:, 1))           !! # elements in row 1
     DO j = 1, SIZE(A(1, :))         !! # elements in column 1
       WRITE (6, '( F8.4 "   ")', ADVANCE="NO") A(i,j)
     END DO
     print *
   END DO
   print *
 END

! ========================================== Main program

 PROGRAM Main

  IMPLICIT NONE

  integer i, j, N
  REAL, DIMENSION(:, :), ALLOCATABLE :: A, B

  INTERFACE
   SUBROUTINE Print( A )
     REAL, DIMENSION(:,:) :: A
   END SUBROUTINE
  END INTERFACE

  INCLUDE 'pj6interface.h'    !! You must provide this file

  READ *, N		!! Read size of matrix

  ALLOCATE(A(N, N))	!! Allocate source
  ALLOCATE(B(N, N))	!! Allocate destination

  DO i = 1, N
    READ *, A(i,:)	!! Read in input matrix
  END DO

  CALL Print( A )	!! Print input matrix

  B = MatrixInvert(A)	!! Invert matrix

  print *, "The inverse matrix is:"
  CALL Print( B )	!! Print result

  END


