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

NAG AD Library Introduction
Example description
    Program f08me_p0w_fe

!     F08ME_P0W_F Example Program Text

!     Mark 30.3 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use iso_c_binding, Only: c_ptr
      Use nagad_library, Only: f08me_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
      Integer                          :: i, ifail, ldc, ldu, ldvt, n
      Character (1)                    :: uplo
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: c(:,:), d(:), e(:), u(:,:), vt(:,:), &
                                          work(:)
!     .. Executable Statements ..
      Write (nout,*) 'F08ME_P0W_F Example Program Results'
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n
      ldc = 1
      ldu = n
      ldvt = n
      Allocate (c(ldc,1),d(n),e(n-1),u(ldu,n),vt(ldvt,n),work(4*n))

!     Read B from data file as d and e
      Read (nin,*) d(1:n)
      Read (nin,*) e(1:n-1)

      Read (nin,*) uplo

!     Initialize U and VT to be the unit matrix
      u = 0.0_nag_wp
      vt = 0.0_nag_wp
      Do i = 1, n
        u(i,i) = 1.0_nag_wp
        vt(i,i) = 1.0_nag_wp
      End Do

!     Calculate the SVD of B
      ifail = 0
      Call f08me_p0w_f(ad_handle,uplo,n,n,n,0,d,e,u,ldu,vt,ldvt,c,ldc,work,    &
        ifail)

      Write (nout,*)
!     Print singular values, left & right singular vectors

      Write (nout,*) 'Singular values'
      Write (nout,99999) d(1:n)
      Write (nout,*)
      Flush (nout)
      ifail = 0
      Call x04caf('General',' ',n,n,u,ldu,'Left singular vectors, by column',  &
        ifail)

      Write (nout,*)
      Flush (nout)
      ifail = 0
      Call x04caf('General',' ',n,n,vt,ldvt,'Right singular vectors, by row',  &
        ifail)

99999 Format (3X,(8F8.4))
    End Program f08me_p0w_fe