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

NAG FL Interface Introduction
Example description
    Program g02ajfe

!     G02AJF Example Program Text

!     Mark 27.3 Release. NAG Copyright 2021.

!     .. Use Statements ..
      Use nag_library, Only: dsyev, g02ajf, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: alpha, errtol, norm
      Integer                          :: i, ifail, iter, ldg, ldh, ldx,       &
                                          lwork, maxit, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: eig(:), g(:,:), h(:,:), work(:),     &
                                          x(:,:)
!     .. Executable Statements ..
      Write (nout,*) 'G02AJF Example Program Results'
      Write (nout,*)
      Flush (nout)

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

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

      ldg = n
      ldh = n
      ldx = n
      lwork = 66*n
      Allocate (g(ldg,n),h(ldh,n),x(ldx,n),eig(n),work(lwork))

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

!     Read in the matrix H
      Read (nin,*)(h(i,1:n),i=1,n)

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

!     Calculate nearest correlation matrix
      ifail = 0

      Call g02ajf(g,ldg,n,alpha,h,ldh,errtol,maxit,x,ldx,iter,norm,ifail)

!     Display results
      ifail = 0
      Call x04caf('General',' ',n,n,h,ldh,'Returned H Matrix',ifail)
      Write (nout,*)
      Flush (nout)

      ifail = 0
      Call x04caf('General',' ',n,n,x,ldx,'Nearest Correlation Matrix X',      &
        ifail)
      Write (nout,*)

      Write (nout,99999) 'Number of iterations:', iter
      Write (nout,*)
      Write (nout,99998) 'Norm value:', norm
      Write (nout,*)
      Write (nout,99997) 'ALPHA: ', alpha

      ifail = 0
!     The NAG name equivalent of dsyev is f08faf
      Call dsyev('N','U',n,x,ldx,eig,work,lwork,ifail)
      Write (nout,*)
      Flush (nout)
      Call x04caf('General',' ',1,n,eig,1,'Eigenvalues of X',ifail)

99999 Format (1X,A,I11)
99998 Format (1X,A,F26.4)
99997 Format (1X,A,F30.4)

    End Program g02ajfe