* F02WEF Example Program Text * Mark 14 Revised. NAG Copyright 1989. * .. Parameters .. INTEGER NOUT PARAMETER (NOUT=6) * .. External Subroutines .. EXTERNAL EX1, EX2 * .. Executable Statements .. WRITE (NOUT,*) 'F02WEF Example Program Results' CALL EX1 CALL EX2 STOP END * SUBROUTINE EX1 * .. Parameters .. INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) INTEGER MMAX, NMAX, NCOLB PARAMETER (MMAX=20,NMAX=10,NCOLB=1) INTEGER LDA, LDB, LDPT PARAMETER (LDA=MMAX,LDB=MMAX,LDPT=NMAX) INTEGER LWORK PARAMETER (LWORK=NMAX**2+5*(NMAX-1)) * .. Local Scalars .. INTEGER I, IFAIL, J, M, N LOGICAL WANTP, WANTQ * .. Local Arrays .. DOUBLE PRECISION A(LDA,NMAX), B(LDB), DUMMY(1), PT(LDPT,NMAX), + SV(NMAX), WORK(LWORK) * .. External Subroutines .. EXTERNAL F02WEF * .. Executable Statements .. WRITE (NOUT,*) WRITE (NOUT,*) WRITE (NOUT,*) 'Example 1' WRITE (NOUT,*) * Skip heading in data file READ (NIN,*) READ (NIN,*) READ (NIN,*) READ (NIN,*) M, N IF ((M.GT.MMAX) .OR. (N.GT.NMAX)) THEN WRITE (NOUT,*) 'M or N is out of range.' WRITE (NOUT,99999) 'M = ', M, ' N = ', N ELSE READ (NIN,*) ((A(I,J),J=1,N),I=1,M) READ (NIN,*) (B(I),I=1,M) * Find the SVD of A. WANTQ = .TRUE. WANTP = .TRUE. IFAIL = 0 * CALL F02WEF(M,N,A,LDA,NCOLB,B,LDB,WANTQ,DUMMY,1,SV,WANTP,PT, + LDPT,WORK,IFAIL) * WRITE (NOUT,*) 'Singular value decomposition of A' WRITE (NOUT,*) WRITE (NOUT,*) 'Singular values' WRITE (NOUT,99998) (SV(I),I=1,N) WRITE (NOUT,*) WRITE (NOUT,*) 'Left-hand singular vectors, by column' DO 20 I = 1, M WRITE (NOUT,99998) (A(I,J),J=1,N) 20 CONTINUE WRITE (NOUT,*) WRITE (NOUT,*) 'Right-hand singular vectors, by column' DO 40 I = 1, N WRITE (NOUT,99998) (PT(J,I),J=1,N) 40 CONTINUE WRITE (NOUT,*) WRITE (NOUT,*) 'Vector Q''*B' WRITE (NOUT,99998) (B(I),I=1,M) END IF * 99999 FORMAT (1X,A,I5,A,I5) 99998 FORMAT (5(1X,F8.4)) END * SUBROUTINE EX2 * .. Parameters .. INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) INTEGER MMAX, NMAX PARAMETER (MMAX=10,NMAX=20) INTEGER LDA, LDQ PARAMETER (LDA=MMAX,LDQ=MMAX) INTEGER LWORK PARAMETER (LWORK=MMAX**2+5*(MMAX-1)) * .. Local Scalars .. INTEGER I, IFAIL, J, M, N, NCOLB LOGICAL WANTP, WANTQ * .. Local Arrays .. DOUBLE PRECISION A(LDA,NMAX), DUMMY(1), Q(LDQ,MMAX), SV(MMAX), + WORK(LWORK) * .. External Subroutines .. EXTERNAL F02WEF * .. Executable Statements .. WRITE (NOUT,*) WRITE (NOUT,*) WRITE (NOUT,*) 'Example 2' * Skip heading in data file READ (NIN,*) READ (NIN,*) READ (NIN,*) M, N WRITE (NOUT,*) IF ((M.GT.MMAX) .OR. (N.GT.NMAX)) THEN WRITE (NOUT,*) 'M or N is out of range.' WRITE (NOUT,99999) 'M = ', M, ' N = ', N ELSE READ (NIN,*) ((A(I,J),J=1,N),I=1,M) * Find the SVD of A. WANTQ = .TRUE. WANTP = .TRUE. NCOLB = 0 IFAIL = 0 * CALL F02WEF(M,N,A,LDA,NCOLB,DUMMY,1,WANTQ,Q,LDQ,SV,WANTP,DUMMY, + 1,WORK,IFAIL) * WRITE (NOUT,*) 'Singular value decomposition of A' WRITE (NOUT,*) WRITE (NOUT,*) 'Singular values' WRITE (NOUT,99998) (SV(I),I=1,M) WRITE (NOUT,*) WRITE (NOUT,*) 'Left-hand singular vectors, by column' DO 20 I = 1, M WRITE (NOUT,99998) (Q(I,J),J=1,M) 20 CONTINUE WRITE (NOUT,*) WRITE (NOUT,*) 'Right-hand singular vectors, by column' DO 40 I = 1, N WRITE (NOUT,99998) (A(J,I),J=1,M) 40 CONTINUE END IF * 99999 FORMAT (1X,A,I5,A,I5) 99998 FORMAT (5(1X,F8.4)) END