PROGRAM f04cjfe ! F04CJF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : f04cjf, nag_wp, x04dbf, x04ddf ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 CHARACTER (1), PARAMETER :: uplo = 'U' ! .. Local Scalars .. REAL (KIND=nag_wp) :: errbnd, rcond INTEGER :: i, ierr, ifail, j, ldb, n, nrhs ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: ap(:), b(:,:) INTEGER, ALLOCATABLE :: ipiv(:) CHARACTER (1) :: clabs(1), rlabs(1) ! .. Executable Statements .. WRITE (nout,*) 'F04CJF Example Program Results' WRITE (nout,*) FLUSH (nout) ! Skip heading in data file READ (nin,*) READ (nin,*) n, nrhs ldb = n ALLOCATE (ap((n*(n+1))/2),b(ldb,nrhs),ipiv(n)) ! Read the upper or lower triangular part of the matrix A from ! data file 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 ! Read B from data file READ (nin,*) (b(i,1:nrhs),i=1,n) ! Solve the equations AX = B for X ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 1 CALL f04cjf(uplo,n,nrhs,ap,ipiv,b,ldb,rcond,errbnd,ifail) IF (ifail==0) THEN ! Print solution, estimate of condition number and approximate ! error bound ierr = 0 CALL x04dbf('General',' ',n,nrhs,b,ldb,'Bracketed',' ','Solution', & 'Integer',rlabs,'Integer',clabs,80,0,ierr) WRITE (nout,*) WRITE (nout,*) 'Estimate of condition number' WRITE (nout,99999) 1.0E0_nag_wp/rcond WRITE (nout,*) WRITE (nout,*) 'Estimate of error bound for computed solutions' WRITE (nout,99999) errbnd ELSE IF (ifail==n+1) THEN ! Matrix A is numerically singular. Print estimate of ! reciprocal of condition number and solution WRITE (nout,*) WRITE (nout,*) 'Estimate of reciprocal of condition number' WRITE (nout,99999) rcond WRITE (nout,*) FLUSH (nout) ierr = 0 CALL x04dbf('General',' ',n,nrhs,b,ldb,'Bracketed',' ','Solution', & 'Integer',rlabs,'Integer',clabs,80,0,ierr) ELSE IF (ifail>0 .AND. ifail<=n) THEN ! The upper triangular matrix U is exactly singular. Print ! details of factorization WRITE (nout,*) FLUSH (nout) ierr = 0 CALL x04ddf(uplo,'Non-unit diagonal',n,ap,'Bracketed',' ', & 'Details of factorization','Integer',rlabs,'Integer',clabs,80,0, & ierr) ! Print pivot indices WRITE (nout,*) WRITE (nout,*) 'Pivot indices' WRITE (nout,99998) ipiv(1:n) ELSE WRITE (nout,99997) ifail END IF 99999 FORMAT (8X,1P,E9.1) 99998 FORMAT ((1X,7I11)) 99997 FORMAT (1X,' ** F04CJF returned with IFAIL = ',I5) END PROGRAM f04cjfe