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

NAG FL Interface Introduction
Example description
    Program m01nafe

!     M01NAF Example Program Text
!     Mark 30.3 Release. nAG Copyright 2024.

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

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

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

      m1 = 1

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

      first = .True.

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

        If (ioerr<0) Then
          Exit data
        End If

        ifail = 0
        index = m01naf(first,rv,m1,m2,item,ifail)

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

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

99999 Format (1X,8F7.1)
99998 Format (1X,'Search for item ',F7.1,' returned index: ',I4)
    End Program m01nafe