PROGRAM f08asfe ! F08ASF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : dznrm2, nag_wp, x04dbf, zgeqrf, ztrtrs, zunmqr ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nb = 64, nin = 5, nout = 6 ! .. Local Scalars .. INTEGER :: i, ifail, info, j, lda, ldb, lwork, & m, n, nrhs ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), tau(:), work(:) REAL (KIND=nag_wp), ALLOCATABLE :: rnorm(:) CHARACTER (1) :: clabs(1), rlabs(1) ! .. Executable Statements .. WRITE (nout,*) 'F08ASF Example Program Results' WRITE (nout,*) FLUSH (nout) ! Skip heading in data file READ (nin,*) READ (nin,*) m, n, nrhs lda = m ldb = m lwork = nb*n ALLOCATE (a(lda,n),b(ldb,nrhs),tau(n),work(lwork),rnorm(nrhs)) ! Read A and B from data file READ (nin,*) (a(i,1:n),i=1,m) READ (nin,*) (b(i,1:nrhs),i=1,m) ! Compute the QR factorization of A ! The NAG name equivalent of zgeqrf is f08asf CALL zgeqrf(m,n,a,lda,tau,work,lwork,info) ! Compute C = (C1) = (Q**H)*B, storing the result in B ! (C2) ! The NAG name equivalent of zunmqr is f08auf CALL zunmqr('Left','Conjugate transpose',m,nrhs,n,a,lda,tau,b,ldb,work, & lwork,info) ! Compute least-squares solutions by backsubstitution in ! R*X = C1 ! The NAG name equivalent of ztrtrs is f07tsf CALL ztrtrs('Upper','No transpose','Non-Unit',n,nrhs,a,lda,b,ldb,info) IF (info>0) THEN WRITE (nout,*) 'The upper triangular factor, R, of A is singular, ' WRITE (nout,*) 'the least squares solution could not be computed' ELSE ! Print least-squares solutions ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04dbf('General',' ',n,nrhs,b,ldb,'Bracketed','F7.4', & 'Least-squares solution(s)','Integer',rlabs,'Integer',clabs,80,0, & ifail) ! Compute and print estimates of the square roots of the residual ! sums of squares ! The NAG name equivalent of dznrm2 is f06jjf DO j = 1, nrhs rnorm(j) = dznrm2(m-n,b(n+1,j),1) END DO WRITE (nout,*) WRITE (nout,*) 'Square root(s) of the residual sum(s) of squares' WRITE (nout,99999) rnorm(1:nrhs) END IF 99999 FORMAT (3X,1P,7E11.2) END PROGRAM f08asfe