    PROGRAM f11mdfe

!      F11MDF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f11mdf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ifail, n, nnz
       CHARACTER (1)                   :: spec
!      .. Local Arrays ..
       INTEGER, ALLOCATABLE            :: icolzp(:), iprm(:), irowix(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F11MDF Example Program Results'
!      Skip heading in data file
       READ (nin,*)

!      Read order of matrix

       READ (nin,*) n

       ALLOCATE (icolzp(n+1),iprm(7*n))

!      Read the matrix

       READ (nin,*) icolzp(1:n+1)
       nnz = icolzp(n+1) - 1

       ALLOCATE (irowix(nnz))

       READ (nin,*) irowix(1:nnz)

!      Calculate COLAMD permutation

       spec = 'M'

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f11mdf(spec,n,icolzp,irowix,iprm,ifail)

!      Output results

       WRITE (nout,*)
       WRITE (nout,*) 'COLAMD Permutation'
       WRITE (nout,'(10I6)') iprm(1:n)

!      Calculate user permutation

       spec = 'U'
       iprm(1) = 4
       iprm(2) = 3
       iprm(3) = 2
       iprm(4) = 1
       iprm(5) = 0

       ifail = 0
       CALL f11mdf(spec,n,icolzp,irowix,iprm,ifail)

!      Output results

       WRITE (nout,*)
       WRITE (nout,*) 'User Permutation'
       WRITE (nout,'(10I6)') iprm(1:n)

!      Calculate natural permutation

       spec = 'N'

       ifail = 0
       CALL f11mdf(spec,n,icolzp,irowix,iprm,ifail)

!      Output results

       WRITE (nout,*)
       WRITE (nout,*) 'Natural Permutation'
       WRITE (nout,'(10I6)') iprm(1:n)

    END PROGRAM f11mdfe
