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

NAG FL Interface Introduction
Example description
!   F01JBF Example Program Text
!   Mark 28.3 Release. NAG Copyright 2022.

    Module f01jbfe_mod

!     .. Use Statements ..
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Accessibility Statements ..
      Private
      Public                           :: fcos2
    Contains
      Subroutine fcos2(iflag,nz,z,fz,iuser,ruser)

!       .. Scalar Arguments ..
        Integer, Intent (Inout)        :: iflag
        Integer, Intent (In)           :: nz
!       .. Array Arguments ..
        Complex (Kind=nag_wp), Intent (Out) :: fz(nz)
        Complex (Kind=nag_wp), Intent (In) :: z(nz)
        Real (Kind=nag_wp), Intent (Inout) :: ruser(*)
        Integer, Intent (Inout)        :: iuser(*)
!       .. Intrinsic Procedures ..
        Intrinsic                      :: cos
!       .. Executable Statements ..
        fz(1:nz) = cos((2.0E0_nag_wp,0.0E0_nag_wp)*z(1:nz))
!       Set iflag nonzero to terminate execution for any reason.
        iflag = 0
        Return
      End Subroutine fcos2
    End Module f01jbfe_mod
    Program f01jbfe

!     F01JBF Example Main Program

!     .. Use Statements ..
      Use f01jbfe_mod, Only: fcos2
      Use nag_library, Only: f01jbf, nag_wp, x02ajf, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: conda, cond_rel, eps, norma, normfa
      Integer                          :: i, ifail, iflag, lda, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:)
      Real (Kind=nag_wp)               :: ruser(1)
      Integer                          :: iuser(1)
!     .. Executable Statements ..
      Write (nout,*) 'F01JBF Example Program Results'
      Write (nout,*)
      Flush (nout)

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

      lda = n
      Allocate (a(lda,n))

!     Read A from data file
      Read (nin,*)(a(i,1:n),i=1,n)

!     Display A
      ifail = 0
      Call x04caf('G','N',n,n,a,lda,'A',ifail)

!     Find absolute condition number estimate
      ifail = 0
      Call f01jbf(n,a,lda,fcos2,iuser,ruser,iflag,conda,norma,normfa,ifail)

      If (ifail==0) Then
!       Print solution
        Write (nout,*)
        Write (nout,*) 'F(A) = cos(2A)'
        Write (nout,99999) 'Estimated absolute condition number is: ', conda

!       Find relative condition number estimate
        eps = x02ajf()
        If (normfa>eps) Then
          cond_rel = conda*norma/normfa
          Write (nout,99999) 'Estimated relative condition number is: ',       &
            cond_rel
        Else
          Write (nout,99998) 'The estimated norm of f(A) is effectively zero', &
            'and so the relative condition number is undefined.'
        End If

      End If

99999 Format (1X,A,F6.2)
99998 Format (/,1X,A,/,1X,A)
    End Program f01jbfe