PROGRAM f08ggfe ! F08GGF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : dopmtr, dsptrd, dstebz, dstein, nag_wp, x04caf ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. REAL (KIND=nag_wp), PARAMETER :: zero = 0.0E0_nag_wp INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: vl, vu INTEGER :: i, ifail, info, j, ldc, m, n, nsplit CHARACTER (1) :: uplo ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: ap(:), c(:,:), d(:), e(:), tau(:), & w(:), work(:) INTEGER, ALLOCATABLE :: iblock(:), ifailv(:), isplit(:), & iwork(:) ! .. Executable Statements .. WRITE (nout,*) 'F08GGF Example Program Results' ! Skip heading in data file READ (nin,*) READ (nin,*) n ldc = n ALLOCATE (ap(n*(n+1)/2),c(ldc,n),d(n),e(n),tau(n),w(n),work(5*n),iblock & (n),ifailv(n),isplit(n),iwork(3*n)) ! Read A from data file READ (nin,*) uplo IF (uplo=='U') THEN READ (nin,*) ((ap(i+j*(j-1)/2),j=i,n),i=1,n) ELSE IF (uplo=='L') THEN READ (nin,*) ((ap(i+(2*n-j)*(j-1)/2),j=1,i),i=1,n) END IF ! Reduce A to tridiagonal form T = (Q**T)*A*Q ! The NAG name equivalent of dsptrd is f08gef CALL dsptrd(uplo,n,ap,d,e,tau,info) ! Calculate the two smallest eigenvalues of T (same as A) ! The NAG name equivalent of dstebz is f08jjf CALL dstebz('I','B',n,vl,vu,1,2,zero,d,e,m,nsplit,w,iblock,isplit,work, & iwork,info) WRITE (nout,*) IF (info>0) THEN WRITE (nout,*) 'Failure to converge.' ELSE WRITE (nout,*) 'Eigenvalues' WRITE (nout,99999) w(1:m) ! Calculate the eigenvectors of T, storing the result in C ! The NAG name equivalent of dstein is f08jkf CALL dstein(n,d,e,m,w,iblock,isplit,c,ldc,work,iwork,ifailv,info) IF (info>0) THEN WRITE (nout,*) 'Failure to converge.' ELSE ! Calculate the eigenvectors of A = Q * (eigenvectors of T) ! The NAG name equivalent of dopmtr is f08ggf CALL dopmtr('Left',uplo,'No transpose',n,m,ap,tau,c,ldc,work, & info) ! Print eigenvectors WRITE (nout,*) FLUSH (nout) ! Normalize the eigenvectors DO i = 1, m c(1:n,i) = c(1:n,i)/c(1,i) END DO ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04caf('General',' ',n,m,c,ldc,'Eigenvectors',ifail) END IF END IF 99999 FORMAT (3X,(9F8.4)) END PROGRAM f08ggfe