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

NAG FL Interface Introduction
Example description
    Program g02akfe

!     G02AKF Example Program Text

!     Mark 30.3 Release. nAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: g02akf, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: errtol, f, rankerr, ranktol
      Integer                          :: i, ifail, ldg, ldx, maxit, maxits,   &
                                          n, nsub, rank
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: g(:,:), x(:,:)
!     .. Executable Statements ..

      Write (nout,*) 'G02AKF 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 rank constraint
      Read (nin,*) rank
!     read in the matrix G
      Read (nin,*)(g(i,1:n),i=1,n)

!     use te defaults for errtol, ranktol, maxits, maxit
      errtol = 0.0E0_nag_wp
      ranktol = 0.0E0_nag_wp
      maxits = 0
      maxit = 0
!     calculate rank constrained nearest correlation matrix
      ifail = 0
      Call g02akf(g,ldg,n,rank,errtol,ranktol,maxits,maxit,x,ldx,f,rankerr,    &
        nsub,ifail)
!     display results
      ifail = 0
      Call x04caf('General',' ',n,n,x,ldx,'NCM with rank constraint',ifail)
      Write (nout,*)
      Write (nout,99999) 'Number of subproblems solved:', nsub
      Write (nout,*)
      Write (nout,99998) 'Squared Frobenius norm of difference:', f
      Write (nout,*)
      Write (nout,99997) 'Rank error:', rankerr

99999 Format (1X,A,I12)
99998 Format (1X,A,F9.4)
99997 Format (1X,A,F35.4)
    End Program g02akfe