NAG Library Manual, Mark 30
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program m01nbfe

!     M01NBF Example Program Text
!     Mark 30.0 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: m01nbf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, index, ioerr, item, m1, m2
      Logical                          :: first
!     .. Local Arrays ..
      Integer, Allocatable             :: iv(:)
!     .. Executable Statements ..
      Write (nout,*) 'M01NBF Example Program Results'

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

      Read (nin,*) m2
      Allocate (iv(m2))

      m1 = 1

      Read (nin,*)(iv(i),i=m1,m2)

      first = .True.

data: Do
        Read (nin,*,Iostat=ioerr) item

        If (ioerr<0) Then
          Exit data
        End If

        ifail = 0
        index = m01nbf(first,iv,m1,m2,item,ifail)

        If (first) Then
          Write (nout,*)
          Write (nout,*) 'Reference Vector is:'
          Write (nout,99999)(iv(i),i=m1,m2)
          first = .False.
        End If

        Write (nout,*)
        Write (nout,99998) item, index
      End Do data

99999 Format (1X,8I5)
99998 Format (1X,'Search for item ',I5,' returned index: ',I4)
    End Program m01nbfe