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

NAG AD Library Introduction
Example description
    Program g02aa_p0w_fe

!     G02AA_P0W_F Example Program Text
!     Mark 28.5 Release. NAG Copyright 2022.

!     .. Use Statements ..
      Use iso_c_binding, Only: c_ptr
      Use nagad_library, Only: g02aa_p0w_f
      Use nag_library, Only: nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Type (c_ptr)                     :: ad_handle
      Real (Kind=nag_wp)               :: errtol, nrmgrd
      Integer                          :: feval, i, ifail, iter, ldg, ldx,     &
                                          maxit, maxits, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: g(:,:), x(:,:)
!     .. Executable Statements ..
      Write (nout,*) 'G02AA_P0W_F Example Program Results'
      Write (nout,*)
      Flush (nout)

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

!     Read in the problem size
      Read (nin,*) n

      ldg = n
      ldx = n
      Allocate (g(ldg,n),x(ldx,n))

!     Read in the matrix G
      Read (nin,*)(g(i,1:n),i=1,n)

!     Use the defaults for ERRTOL, MAXITS and MAXIT
      errtol = 0.0E0_nag_wp
      maxits = 0
      maxit = 0

!     Calculate nearest correlation matrix
      ifail = 0
      Call g02aa_p0w_f(ad_handle,g,ldg,n,errtol,maxits,maxit,x,ldx,iter,feval, &
        nrmgrd,ifail)

!     Display results
      ifail = 0
      Call x04caf('General',' ',n,n,x,ldx,'Nearest Correlation Matrix',ifail)
      Write (nout,*)
      Write (nout,99999) ' Number of Newton steps taken:', iter
      Write (nout,99998) ' Number of function evaluations:', feval

99999 Format (1X,A,I11)
99998 Format (1X,A,I9)
    End Program g02aa_p0w_fe