    PROGRAM f01ckfe

!      F01CKF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01ckf, nag_wp, x04cbf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: indent = 0, iz = 1, ncols = 80,      &
                                          nin = 5, nout = 6, opt = 1
       CHARACTER (1), PARAMETER        :: diag =   'N',  matrix =   'G',       &
                                          nolabel =   'N'
       CHARACTER (4), PARAMETER        :: form = 'F7.1'
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, j, m, n, p
       CHARACTER (8)                   :: title
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), c(:,:)
       REAL (KIND=nag_wp)              :: z(iz)
       CHARACTER (1)                   :: dummy(1)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'F01CKF Example Program Results'
!      Skip heading in data file 
       READ (nin,*)
       READ (nin,*) n, p, m

       ALLOCATE (a(n,p),b(n,m),c(m,p))

!      Set up example B and C matrices
       DO i = 1, m
          DO j = 1, n
             b(j,i) = real(i+j-2,kind=nag_wp)
          END DO
          DO j = 1, p
             c(i,j) = real(i+j-2,kind=nag_wp)
          END DO
       END DO

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f01ckf(a,b,c,n,p,m,z,iz,opt,ifail)

!      Print the result matrix A
       title = 'Matrix A'
       WRITE (nout,*)
       FLUSH (nout)
       ifail = 0
       CALL x04cbf(matrix,diag,n,p,a,n,form,title,nolabel,dummy,nolabel,dummy, &
          ncols,indent,ifail)

    END PROGRAM f01ckfe
