    PROGRAM m01ncfe

!      M01NCF Example Program Test

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : m01ncf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, index, ioerr, m1, m2
       LOGICAL                         :: first
       CHARACTER (6)                   :: item
!      .. Local Arrays ..
       CHARACTER (6), ALLOCATABLE      :: ch(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'M01NCF Example Program Results'

!      Skip heading in data file
       READ (nin,*)

       READ (nin,*) m2
       ALLOCATE (ch(m2))

       m1 = 1

       READ (nin,*) (ch(i),i=m1,m2)

       first = .TRUE.

DATA:  DO
          READ (nin,'(A)',IOSTAT=ioerr) item

          IF (ioerr<0) THEN
             EXIT DATA
          END IF

          ifail = 0
          index = m01ncf(first,ch,m1,m2,item,ifail)

          IF (first) THEN
             WRITE (nout,*)
             WRITE (nout,*) 'Reference Vector is:'
             WRITE (nout,99999) (ch(i),i=m1,m2)
             first = .FALSE.
          END IF

          WRITE (nout,*)
          WRITE (nout,99998) item, index
       END DO DATA

99999  FORMAT (10(1X,A))
99998  FORMAT (1X,'Search for item ',A,' returned index: ',I4)
    END PROGRAM m01ncfe
