    PROGRAM f01crfe

!      F01CRF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01crf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, lmove, m, mn, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:)
       INTEGER, ALLOCATABLE            :: move(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'F01CRF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n
       mn = m*n
       lmove = (m+n)/2
       ALLOCATE (a(mn),move(lmove))
       DO i = 1, mn
          a(i) = real(i,kind=nag_wp)
       END DO

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f01crf(a,m,n,mn,move,lmove,ifail)

       WRITE (nout,*)
       WRITE (nout,99999) a(1:mn)

99999  FORMAT (1X,7F7.1)
    END PROGRAM f01crfe
