    PROGRAM nag_mat_inv_ex06

      ! Example Program Text for nag_mat_inv
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_mat_inv, ONLY : nag_gen_mat_inv
      USE nag_examples_io, ONLY : nag_std_out, nag_std_in
      USE nag_write_mat, ONLY : nag_write_gen_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, n
      REAL (wp) :: rcond
      ! .. Local Arrays ..
      COMPLEX (wp), ALLOCATABLE :: a(:,:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_mat_inv_ex06'
      WRITE (nag_std_out,*)

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) n

      ALLOCATE (a(n,n))            ! Allocate storage

      READ (nag_std_in,*) (a(i,:),i=1,n)

      CALL nag_gen_mat_inv(a,rcond=rcond)

      CALL nag_write_gen_mat(a,format='F7.4',title='Inverse matrix')

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,A,1PE10.2)') 'Estimated condition number = ', &
       1.0_wp/rcond

      DEALLOCATE (a)               ! Deallocate storage

    END PROGRAM nag_mat_inv_ex06
