repo_name
stringlengths
7
81
path
stringlengths
4
224
copies
stringlengths
1
4
size
stringlengths
4
7
content
stringlengths
975
1.04M
license
stringclasses
15 values
apollos/Quantum-ESPRESSO
lapack-3.2/TESTING/EIG/dchkbd.f
1
34284
SUBROUTINE DCHKBD( NSIZES, MVAL, NVAL, NTYPES, DOTYPE, NRHS, $ ISEED, THRESH, A, LDA, BD, BE, S1, S2, X, LDX, $ Y, Z, Q, LDQ, PT, LDPT, U, VT, WORK, LWORK, $ IWORK, NOUT, INFO ) * * -- LAPACK test routine (version 3.1) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2006 * * .. Scalar Arguments .. INTEGER INFO, LDA, LDPT, LDQ, LDX, LWORK, NOUT, NRHS, $ NSIZES, NTYPES DOUBLE PRECISION THRESH * .. * .. Array Arguments .. LOGICAL DOTYPE( * ) INTEGER ISEED( 4 ), IWORK( * ), MVAL( * ), NVAL( * ) DOUBLE PRECISION A( LDA, * ), BD( * ), BE( * ), PT( LDPT, * ), $ Q( LDQ, * ), S1( * ), S2( * ), U( LDPT, * ), $ VT( LDPT, * ), WORK( * ), X( LDX, * ), $ Y( LDX, * ), Z( LDX, * ) * .. * * Purpose * ======= * * DCHKBD checks the singular value decomposition (SVD) routines. * * DGEBRD reduces a real general m by n matrix A to upper or lower * bidiagonal form B by an orthogonal transformation: Q' * A * P = B * (or A = Q * B * P'). The matrix B is upper bidiagonal if m >= n * and lower bidiagonal if m < n. * * DORGBR generates the orthogonal matrices Q and P' from DGEBRD. * Note that Q and P are not necessarily square. * * DBDSQR computes the singular value decomposition of the bidiagonal * matrix B as B = U S V'. It is called three times to compute * 1) B = U S1 V', where S1 is the diagonal matrix of singular * values and the columns of the matrices U and V are the left * and right singular vectors, respectively, of B. * 2) Same as 1), but the singular values are stored in S2 and the * singular vectors are not computed. * 3) A = (UQ) S (P'V'), the SVD of the original matrix A. * In addition, DBDSQR has an option to apply the left orthogonal matrix * U to a matrix X, useful in least squares applications. * * DBDSDC computes the singular value decomposition of the bidiagonal * matrix B as B = U S V' using divide-and-conquer. It is called twice * to compute * 1) B = U S1 V', where S1 is the diagonal matrix of singular * values and the columns of the matrices U and V are the left * and right singular vectors, respectively, of B. * 2) Same as 1), but the singular values are stored in S2 and the * singular vectors are not computed. * * For each pair of matrix dimensions (M,N) and each selected matrix * type, an M by N matrix A and an M by NRHS matrix X are generated. * The problem dimensions are as follows * A: M x N * Q: M x min(M,N) (but M x M if NRHS > 0) * P: min(M,N) x N * B: min(M,N) x min(M,N) * U, V: min(M,N) x min(M,N) * S1, S2 diagonal, order min(M,N) * X: M x NRHS * * For each generated matrix, 14 tests are performed: * * Test DGEBRD and DORGBR * * (1) | A - Q B PT | / ( |A| max(M,N) ulp ), PT = P' * * (2) | I - Q' Q | / ( M ulp ) * * (3) | I - PT PT' | / ( N ulp ) * * Test DBDSQR on bidiagonal matrix B * * (4) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V' * * (5) | Y - U Z | / ( |Y| max(min(M,N),k) ulp ), where Y = Q' X * and Z = U' Y. * (6) | I - U' U | / ( min(M,N) ulp ) * * (7) | I - VT VT' | / ( min(M,N) ulp ) * * (8) S1 contains min(M,N) nonnegative values in decreasing order. * (Return 0 if true, 1/ULP if false.) * * (9) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without * computing U and V. * * (10) 0 if the true singular values of B are within THRESH of * those in S1. 2*THRESH if they are not. (Tested using * DSVDCH) * * Test DBDSQR on matrix A * * (11) | A - (QU) S (VT PT) | / ( |A| max(M,N) ulp ) * * (12) | X - (QU) Z | / ( |X| max(M,k) ulp ) * * (13) | I - (QU)'(QU) | / ( M ulp ) * * (14) | I - (VT PT) (PT'VT') | / ( N ulp ) * * Test DBDSDC on bidiagonal matrix B * * (15) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V' * * (16) | I - U' U | / ( min(M,N) ulp ) * * (17) | I - VT VT' | / ( min(M,N) ulp ) * * (18) S1 contains min(M,N) nonnegative values in decreasing order. * (Return 0 if true, 1/ULP if false.) * * (19) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without * computing U and V. * The possible matrix types are * * (1) The zero matrix. * (2) The identity matrix. * * (3) A diagonal matrix with evenly spaced entries * 1, ..., ULP and random signs. * (ULP = (first number larger than 1) - 1 ) * (4) A diagonal matrix with geometrically spaced entries * 1, ..., ULP and random signs. * (5) A diagonal matrix with "clustered" entries 1, ULP, ..., ULP * and random signs. * * (6) Same as (3), but multiplied by SQRT( overflow threshold ) * (7) Same as (3), but multiplied by SQRT( underflow threshold ) * * (8) A matrix of the form U D V, where U and V are orthogonal and * D has evenly spaced entries 1, ..., ULP with random signs * on the diagonal. * * (9) A matrix of the form U D V, where U and V are orthogonal and * D has geometrically spaced entries 1, ..., ULP with random * signs on the diagonal. * * (10) A matrix of the form U D V, where U and V are orthogonal and * D has "clustered" entries 1, ULP,..., ULP with random * signs on the diagonal. * * (11) Same as (8), but multiplied by SQRT( overflow threshold ) * (12) Same as (8), but multiplied by SQRT( underflow threshold ) * * (13) Rectangular matrix with random entries chosen from (-1,1). * (14) Same as (13), but multiplied by SQRT( overflow threshold ) * (15) Same as (13), but multiplied by SQRT( underflow threshold ) * * Special case: * (16) A bidiagonal matrix with random entries chosen from a * logarithmic distribution on [ulp^2,ulp^(-2)] (I.e., each * entry is e^x, where x is chosen uniformly on * [ 2 log(ulp), -2 log(ulp) ] .) For *this* type: * (a) DGEBRD is not called to reduce it to bidiagonal form. * (b) the bidiagonal is min(M,N) x min(M,N); if M<N, the * matrix will be lower bidiagonal, otherwise upper. * (c) only tests 5--8 and 14 are performed. * * A subset of the full set of matrix types may be selected through * the logical array DOTYPE. * * Arguments * ========== * * NSIZES (input) INTEGER * The number of values of M and N contained in the vectors * MVAL and NVAL. The matrix sizes are used in pairs (M,N). * * MVAL (input) INTEGER array, dimension (NM) * The values of the matrix row dimension M. * * NVAL (input) INTEGER array, dimension (NM) * The values of the matrix column dimension N. * * NTYPES (input) INTEGER * The number of elements in DOTYPE. If it is zero, DCHKBD * does nothing. It must be at least zero. If it is MAXTYP+1 * and NSIZES is 1, then an additional type, MAXTYP+1 is * defined, which is to use whatever matrices are in A and B. * This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and * DOTYPE(MAXTYP+1) is .TRUE. . * * DOTYPE (input) LOGICAL array, dimension (NTYPES) * If DOTYPE(j) is .TRUE., then for each size (m,n), a matrix * of type j will be generated. If NTYPES is smaller than the * maximum number of types defined (PARAMETER MAXTYP), then * types NTYPES+1 through MAXTYP will not be generated. If * NTYPES is larger than MAXTYP, DOTYPE(MAXTYP+1) through * DOTYPE(NTYPES) will be ignored. * * NRHS (input) INTEGER * The number of columns in the "right-hand side" matrices X, Y, * and Z, used in testing DBDSQR. If NRHS = 0, then the * operations on the right-hand side will not be tested. * NRHS must be at least 0. * * ISEED (input/output) INTEGER array, dimension (4) * On entry ISEED specifies the seed of the random number * generator. The array elements should be between 0 and 4095; * if not they will be reduced mod 4096. Also, ISEED(4) must * be odd. The values of ISEED are changed on exit, and can be * used in the next call to DCHKBD to continue the same random * number sequence. * * THRESH (input) DOUBLE PRECISION * The threshold value for the test ratios. A result is * included in the output file if RESULT >= THRESH. To have * every test ratio printed, use THRESH = 0. Note that the * expected value of the test ratios is O(1), so THRESH should * be a reasonably small multiple of 1, e.g., 10 or 100. * * A (workspace) DOUBLE PRECISION array, dimension (LDA,NMAX) * where NMAX is the maximum value of N in NVAL. * * LDA (input) INTEGER * The leading dimension of the array A. LDA >= max(1,MMAX), * where MMAX is the maximum value of M in MVAL. * * BD (workspace) DOUBLE PRECISION array, dimension * (max(min(MVAL(j),NVAL(j)))) * * BE (workspace) DOUBLE PRECISION array, dimension * (max(min(MVAL(j),NVAL(j)))) * * S1 (workspace) DOUBLE PRECISION array, dimension * (max(min(MVAL(j),NVAL(j)))) * * S2 (workspace) DOUBLE PRECISION array, dimension * (max(min(MVAL(j),NVAL(j)))) * * X (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS) * * LDX (input) INTEGER * The leading dimension of the arrays X, Y, and Z. * LDX >= max(1,MMAX) * * Y (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS) * * Z (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS) * * Q (workspace) DOUBLE PRECISION array, dimension (LDQ,MMAX) * * LDQ (input) INTEGER * The leading dimension of the array Q. LDQ >= max(1,MMAX). * * PT (workspace) DOUBLE PRECISION array, dimension (LDPT,NMAX) * * LDPT (input) INTEGER * The leading dimension of the arrays PT, U, and V. * LDPT >= max(1, max(min(MVAL(j),NVAL(j)))). * * U (workspace) DOUBLE PRECISION array, dimension * (LDPT,max(min(MVAL(j),NVAL(j)))) * * V (workspace) DOUBLE PRECISION array, dimension * (LDPT,max(min(MVAL(j),NVAL(j)))) * * WORK (workspace) DOUBLE PRECISION array, dimension (LWORK) * * LWORK (input) INTEGER * The number of entries in WORK. This must be at least * 3(M+N) and M(M + max(M,N,k) + 1) + N*min(M,N) for all * pairs (M,N)=(MM(j),NN(j)) * * IWORK (workspace) INTEGER array, dimension at least 8*min(M,N) * * NOUT (input) INTEGER * The FORTRAN unit number for printing out error messages * (e.g., if a routine returns IINFO not equal to 0.) * * INFO (output) INTEGER * If 0, then everything ran OK. * -1: NSIZES < 0 * -2: Some MM(j) < 0 * -3: Some NN(j) < 0 * -4: NTYPES < 0 * -6: NRHS < 0 * -8: THRESH < 0 * -11: LDA < 1 or LDA < MMAX, where MMAX is max( MM(j) ). * -17: LDB < 1 or LDB < MMAX. * -21: LDQ < 1 or LDQ < MMAX. * -23: LDPT< 1 or LDPT< MNMAX. * -27: LWORK too small. * If DLATMR, SLATMS, DGEBRD, DORGBR, or DBDSQR, * returns an error code, the * absolute value of it is returned. * *----------------------------------------------------------------------- * * Some Local Variables and Parameters: * ---- ----- --------- --- ---------- * * ZERO, ONE Real 0 and 1. * MAXTYP The number of types defined. * NTEST The number of tests performed, or which can * be performed so far, for the current matrix. * MMAX Largest value in NN. * NMAX Largest value in NN. * MNMIN min(MM(j), NN(j)) (the dimension of the bidiagonal * matrix.) * MNMAX The maximum value of MNMIN for j=1,...,NSIZES. * NFAIL The number of tests which have exceeded THRESH * COND, IMODE Values to be passed to the matrix generators. * ANORM Norm of A; passed to matrix generators. * * OVFL, UNFL Overflow and underflow thresholds. * RTOVFL, RTUNFL Square roots of the previous 2 values. * ULP, ULPINV Finest relative precision and its inverse. * * The following four arrays decode JTYPE: * KTYPE(j) The general type (1-10) for type "j". * KMODE(j) The MODE value to be passed to the matrix * generator for type "j". * KMAGN(j) The order of magnitude ( O(1), * O(overflow^(1/2) ), O(underflow^(1/2) ) * * ====================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE, TWO, HALF PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0, $ HALF = 0.5D0 ) INTEGER MAXTYP PARAMETER ( MAXTYP = 16 ) * .. * .. Local Scalars .. LOGICAL BADMM, BADNN, BIDIAG CHARACTER UPLO CHARACTER*3 PATH INTEGER I, IINFO, IMODE, ITYPE, J, JCOL, JSIZE, JTYPE, $ LOG2UI, M, MINWRK, MMAX, MNMAX, MNMIN, MQ, $ MTYPES, N, NFAIL, NMAX, NTEST DOUBLE PRECISION AMNINV, ANORM, COND, OVFL, RTOVFL, RTUNFL, $ TEMP1, TEMP2, ULP, ULPINV, UNFL * .. * .. Local Arrays .. INTEGER IDUM( 1 ), IOLDSD( 4 ), KMAGN( MAXTYP ), $ KMODE( MAXTYP ), KTYPE( MAXTYP ) DOUBLE PRECISION DUM( 1 ), DUMMA( 1 ), RESULT( 19 ) * .. * .. External Functions .. DOUBLE PRECISION DLAMCH, DLARND EXTERNAL DLAMCH, DLARND * .. * .. External Subroutines .. EXTERNAL ALASUM, DBDSDC, DBDSQR, DBDT01, DBDT02, DBDT03, $ DCOPY, DGEBRD, DGEMM, DLABAD, DLACPY, DLAHD2, $ DLASET, DLATMR, DLATMS, DORGBR, DORT01, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, EXP, INT, LOG, MAX, MIN, SQRT * .. * .. Scalars in Common .. LOGICAL LERR, OK CHARACTER*32 SRNAMT INTEGER INFOT, NUNIT * .. * .. Common blocks .. COMMON / INFOC / INFOT, NUNIT, OK, LERR COMMON / SRNAMC / SRNAMT * .. * .. Data statements .. DATA KTYPE / 1, 2, 5*4, 5*6, 3*9, 10 / DATA KMAGN / 2*1, 3*1, 2, 3, 3*1, 2, 3, 1, 2, 3, 0 / DATA KMODE / 2*0, 4, 3, 1, 4, 4, 4, 3, 1, 4, 4, 0, $ 0, 0, 0 / * .. * .. Executable Statements .. * * Check for errors * INFO = 0 * BADMM = .FALSE. BADNN = .FALSE. MMAX = 1 NMAX = 1 MNMAX = 1 MINWRK = 1 DO 10 J = 1, NSIZES MMAX = MAX( MMAX, MVAL( J ) ) IF( MVAL( J ).LT.0 ) $ BADMM = .TRUE. NMAX = MAX( NMAX, NVAL( J ) ) IF( NVAL( J ).LT.0 ) $ BADNN = .TRUE. MNMAX = MAX( MNMAX, MIN( MVAL( J ), NVAL( J ) ) ) MINWRK = MAX( MINWRK, 3*( MVAL( J )+NVAL( J ) ), $ MVAL( J )*( MVAL( J )+MAX( MVAL( J ), NVAL( J ), $ NRHS )+1 )+NVAL( J )*MIN( NVAL( J ), MVAL( J ) ) ) 10 CONTINUE * * Check for errors * IF( NSIZES.LT.0 ) THEN INFO = -1 ELSE IF( BADMM ) THEN INFO = -2 ELSE IF( BADNN ) THEN INFO = -3 ELSE IF( NTYPES.LT.0 ) THEN INFO = -4 ELSE IF( NRHS.LT.0 ) THEN INFO = -6 ELSE IF( LDA.LT.MMAX ) THEN INFO = -11 ELSE IF( LDX.LT.MMAX ) THEN INFO = -17 ELSE IF( LDQ.LT.MMAX ) THEN INFO = -21 ELSE IF( LDPT.LT.MNMAX ) THEN INFO = -23 ELSE IF( MINWRK.GT.LWORK ) THEN INFO = -27 END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'DCHKBD', -INFO ) RETURN END IF * * Initialize constants * PATH( 1: 1 ) = 'Double precision' PATH( 2: 3 ) = 'BD' NFAIL = 0 NTEST = 0 UNFL = DLAMCH( 'Safe minimum' ) OVFL = DLAMCH( 'Overflow' ) CALL DLABAD( UNFL, OVFL ) ULP = DLAMCH( 'Precision' ) ULPINV = ONE / ULP LOG2UI = INT( LOG( ULPINV ) / LOG( TWO ) ) RTUNFL = SQRT( UNFL ) RTOVFL = SQRT( OVFL ) INFOT = 0 * * Loop over sizes, types * DO 200 JSIZE = 1, NSIZES M = MVAL( JSIZE ) N = NVAL( JSIZE ) MNMIN = MIN( M, N ) AMNINV = ONE / MAX( M, N, 1 ) * IF( NSIZES.NE.1 ) THEN MTYPES = MIN( MAXTYP, NTYPES ) ELSE MTYPES = MIN( MAXTYP+1, NTYPES ) END IF * DO 190 JTYPE = 1, MTYPES IF( .NOT.DOTYPE( JTYPE ) ) $ GO TO 190 * DO 20 J = 1, 4 IOLDSD( J ) = ISEED( J ) 20 CONTINUE * DO 30 J = 1, 14 RESULT( J ) = -ONE 30 CONTINUE * UPLO = ' ' * * Compute "A" * * Control parameters: * * KMAGN KMODE KTYPE * =1 O(1) clustered 1 zero * =2 large clustered 2 identity * =3 small exponential (none) * =4 arithmetic diagonal, (w/ eigenvalues) * =5 random symmetric, w/ eigenvalues * =6 nonsymmetric, w/ singular values * =7 random diagonal * =8 random symmetric * =9 random nonsymmetric * =10 random bidiagonal (log. distrib.) * IF( MTYPES.GT.MAXTYP ) $ GO TO 100 * ITYPE = KTYPE( JTYPE ) IMODE = KMODE( JTYPE ) * * Compute norm * GO TO ( 40, 50, 60 )KMAGN( JTYPE ) * 40 CONTINUE ANORM = ONE GO TO 70 * 50 CONTINUE ANORM = ( RTOVFL*ULP )*AMNINV GO TO 70 * 60 CONTINUE ANORM = RTUNFL*MAX( M, N )*ULPINV GO TO 70 * 70 CONTINUE * CALL DLASET( 'Full', LDA, N, ZERO, ZERO, A, LDA ) IINFO = 0 COND = ULPINV * BIDIAG = .FALSE. IF( ITYPE.EQ.1 ) THEN * * Zero matrix * IINFO = 0 * ELSE IF( ITYPE.EQ.2 ) THEN * * Identity * DO 80 JCOL = 1, MNMIN A( JCOL, JCOL ) = ANORM 80 CONTINUE * ELSE IF( ITYPE.EQ.4 ) THEN * * Diagonal Matrix, [Eigen]values Specified * CALL DLATMS( MNMIN, MNMIN, 'S', ISEED, 'N', WORK, IMODE, $ COND, ANORM, 0, 0, 'N', A, LDA, $ WORK( MNMIN+1 ), IINFO ) * ELSE IF( ITYPE.EQ.5 ) THEN * * Symmetric, eigenvalues specified * CALL DLATMS( MNMIN, MNMIN, 'S', ISEED, 'S', WORK, IMODE, $ COND, ANORM, M, N, 'N', A, LDA, $ WORK( MNMIN+1 ), IINFO ) * ELSE IF( ITYPE.EQ.6 ) THEN * * Nonsymmetric, singular values specified * CALL DLATMS( M, N, 'S', ISEED, 'N', WORK, IMODE, COND, $ ANORM, M, N, 'N', A, LDA, WORK( MNMIN+1 ), $ IINFO ) * ELSE IF( ITYPE.EQ.7 ) THEN * * Diagonal, random entries * CALL DLATMR( MNMIN, MNMIN, 'S', ISEED, 'N', WORK, 6, ONE, $ ONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE, $ WORK( 2*MNMIN+1 ), 1, ONE, 'N', IWORK, 0, 0, $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO ) * ELSE IF( ITYPE.EQ.8 ) THEN * * Symmetric, random entries * CALL DLATMR( MNMIN, MNMIN, 'S', ISEED, 'S', WORK, 6, ONE, $ ONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE, $ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N, $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO ) * ELSE IF( ITYPE.EQ.9 ) THEN * * Nonsymmetric, random entries * CALL DLATMR( M, N, 'S', ISEED, 'N', WORK, 6, ONE, ONE, $ 'T', 'N', WORK( MNMIN+1 ), 1, ONE, $ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N, $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO ) * ELSE IF( ITYPE.EQ.10 ) THEN * * Bidiagonal, random entries * TEMP1 = -TWO*LOG( ULP ) DO 90 J = 1, MNMIN BD( J ) = EXP( TEMP1*DLARND( 2, ISEED ) ) IF( J.LT.MNMIN ) $ BE( J ) = EXP( TEMP1*DLARND( 2, ISEED ) ) 90 CONTINUE * IINFO = 0 BIDIAG = .TRUE. IF( M.GE.N ) THEN UPLO = 'U' ELSE UPLO = 'L' END IF ELSE IINFO = 1 END IF * IF( IINFO.EQ.0 ) THEN * * Generate Right-Hand Side * IF( BIDIAG ) THEN CALL DLATMR( MNMIN, NRHS, 'S', ISEED, 'N', WORK, 6, $ ONE, ONE, 'T', 'N', WORK( MNMIN+1 ), 1, $ ONE, WORK( 2*MNMIN+1 ), 1, ONE, 'N', $ IWORK, MNMIN, NRHS, ZERO, ONE, 'NO', Y, $ LDX, IWORK, IINFO ) ELSE CALL DLATMR( M, NRHS, 'S', ISEED, 'N', WORK, 6, ONE, $ ONE, 'T', 'N', WORK( M+1 ), 1, ONE, $ WORK( 2*M+1 ), 1, ONE, 'N', IWORK, M, $ NRHS, ZERO, ONE, 'NO', X, LDX, IWORK, $ IINFO ) END IF END IF * * Error Exit * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'Generator', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) RETURN END IF * 100 CONTINUE * * Call DGEBRD and DORGBR to compute B, Q, and P, do tests. * IF( .NOT.BIDIAG ) THEN * * Compute transformations to reduce A to bidiagonal form: * B := Q' * A * P. * CALL DLACPY( ' ', M, N, A, LDA, Q, LDQ ) CALL DGEBRD( M, N, Q, LDQ, BD, BE, WORK, WORK( MNMIN+1 ), $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO ) * * Check error code from DGEBRD. * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'DGEBRD', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) RETURN END IF * CALL DLACPY( ' ', M, N, Q, LDQ, PT, LDPT ) IF( M.GE.N ) THEN UPLO = 'U' ELSE UPLO = 'L' END IF * * Generate Q * MQ = M IF( NRHS.LE.0 ) $ MQ = MNMIN CALL DORGBR( 'Q', M, MQ, N, Q, LDQ, WORK, $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO ) * * Check error code from DORGBR. * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'DORGBR(Q)', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) RETURN END IF * * Generate P' * CALL DORGBR( 'P', MNMIN, N, M, PT, LDPT, WORK( MNMIN+1 ), $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO ) * * Check error code from DORGBR. * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'DORGBR(P)', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) RETURN END IF * * Apply Q' to an M by NRHS matrix X: Y := Q' * X. * CALL DGEMM( 'Transpose', 'No transpose', M, NRHS, M, ONE, $ Q, LDQ, X, LDX, ZERO, Y, LDX ) * * Test 1: Check the decomposition A := Q * B * PT * 2: Check the orthogonality of Q * 3: Check the orthogonality of PT * CALL DBDT01( M, N, 1, A, LDA, Q, LDQ, BD, BE, PT, LDPT, $ WORK, RESULT( 1 ) ) CALL DORT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK, $ RESULT( 2 ) ) CALL DORT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK, $ RESULT( 3 ) ) END IF * * Use DBDSQR to form the SVD of the bidiagonal matrix B: * B := U * S1 * VT, and compute Z = U' * Y. * CALL DCOPY( MNMIN, BD, 1, S1, 1 ) IF( MNMIN.GT.0 ) $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 ) CALL DLACPY( ' ', M, NRHS, Y, LDX, Z, LDX ) CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, U, LDPT ) CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, VT, LDPT ) * CALL DBDSQR( UPLO, MNMIN, MNMIN, MNMIN, NRHS, S1, WORK, VT, $ LDPT, U, LDPT, Z, LDX, WORK( MNMIN+1 ), IINFO ) * * Check error code from DBDSQR. * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'DBDSQR(vects)', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) IF( IINFO.LT.0 ) THEN RETURN ELSE RESULT( 4 ) = ULPINV GO TO 170 END IF END IF * * Use DBDSQR to compute only the singular values of the * bidiagonal matrix B; U, VT, and Z should not be modified. * CALL DCOPY( MNMIN, BD, 1, S2, 1 ) IF( MNMIN.GT.0 ) $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 ) * CALL DBDSQR( UPLO, MNMIN, 0, 0, 0, S2, WORK, VT, LDPT, U, $ LDPT, Z, LDX, WORK( MNMIN+1 ), IINFO ) * * Check error code from DBDSQR. * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'DBDSQR(values)', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) IF( IINFO.LT.0 ) THEN RETURN ELSE RESULT( 9 ) = ULPINV GO TO 170 END IF END IF * * Test 4: Check the decomposition B := U * S1 * VT * 5: Check the computation Z := U' * Y * 6: Check the orthogonality of U * 7: Check the orthogonality of VT * CALL DBDT03( UPLO, MNMIN, 1, BD, BE, U, LDPT, S1, VT, LDPT, $ WORK, RESULT( 4 ) ) CALL DBDT02( MNMIN, NRHS, Y, LDX, Z, LDX, U, LDPT, WORK, $ RESULT( 5 ) ) CALL DORT01( 'Columns', MNMIN, MNMIN, U, LDPT, WORK, LWORK, $ RESULT( 6 ) ) CALL DORT01( 'Rows', MNMIN, MNMIN, VT, LDPT, WORK, LWORK, $ RESULT( 7 ) ) * * Test 8: Check that the singular values are sorted in * non-increasing order and are non-negative * RESULT( 8 ) = ZERO DO 110 I = 1, MNMIN - 1 IF( S1( I ).LT.S1( I+1 ) ) $ RESULT( 8 ) = ULPINV IF( S1( I ).LT.ZERO ) $ RESULT( 8 ) = ULPINV 110 CONTINUE IF( MNMIN.GE.1 ) THEN IF( S1( MNMIN ).LT.ZERO ) $ RESULT( 8 ) = ULPINV END IF * * Test 9: Compare DBDSQR with and without singular vectors * TEMP2 = ZERO * DO 120 J = 1, MNMIN TEMP1 = ABS( S1( J )-S2( J ) ) / $ MAX( SQRT( UNFL )*MAX( S1( 1 ), ONE ), $ ULP*MAX( ABS( S1( J ) ), ABS( S2( J ) ) ) ) TEMP2 = MAX( TEMP1, TEMP2 ) 120 CONTINUE * RESULT( 9 ) = TEMP2 * * Test 10: Sturm sequence test of singular values * Go up by factors of two until it succeeds * TEMP1 = THRESH*( HALF-ULP ) * DO 130 J = 0, LOG2UI * CALL DSVDCH( MNMIN, BD, BE, S1, TEMP1, IINFO ) IF( IINFO.EQ.0 ) $ GO TO 140 TEMP1 = TEMP1*TWO 130 CONTINUE * 140 CONTINUE RESULT( 10 ) = TEMP1 * * Use DBDSQR to form the decomposition A := (QU) S (VT PT) * from the bidiagonal form A := Q B PT. * IF( .NOT.BIDIAG ) THEN CALL DCOPY( MNMIN, BD, 1, S2, 1 ) IF( MNMIN.GT.0 ) $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 ) * CALL DBDSQR( UPLO, MNMIN, N, M, NRHS, S2, WORK, PT, LDPT, $ Q, LDQ, Y, LDX, WORK( MNMIN+1 ), IINFO ) * * Test 11: Check the decomposition A := Q*U * S2 * VT*PT * 12: Check the computation Z := U' * Q' * X * 13: Check the orthogonality of Q*U * 14: Check the orthogonality of VT*PT * CALL DBDT01( M, N, 0, A, LDA, Q, LDQ, S2, DUMMA, PT, $ LDPT, WORK, RESULT( 11 ) ) CALL DBDT02( M, NRHS, X, LDX, Y, LDX, Q, LDQ, WORK, $ RESULT( 12 ) ) CALL DORT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK, $ RESULT( 13 ) ) CALL DORT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK, $ RESULT( 14 ) ) END IF * * Use DBDSDC to form the SVD of the bidiagonal matrix B: * B := U * S1 * VT * CALL DCOPY( MNMIN, BD, 1, S1, 1 ) IF( MNMIN.GT.0 ) $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 ) CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, U, LDPT ) CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, VT, LDPT ) * CALL DBDSDC( UPLO, 'I', MNMIN, S1, WORK, U, LDPT, VT, LDPT, $ DUM, IDUM, WORK( MNMIN+1 ), IWORK, IINFO ) * * Check error code from DBDSDC. * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'DBDSDC(vects)', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) IF( IINFO.LT.0 ) THEN RETURN ELSE RESULT( 15 ) = ULPINV GO TO 170 END IF END IF * * Use DBDSDC to compute only the singular values of the * bidiagonal matrix B; U and VT should not be modified. * CALL DCOPY( MNMIN, BD, 1, S2, 1 ) IF( MNMIN.GT.0 ) $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 ) * CALL DBDSDC( UPLO, 'N', MNMIN, S2, WORK, DUM, 1, DUM, 1, $ DUM, IDUM, WORK( MNMIN+1 ), IWORK, IINFO ) * * Check error code from DBDSDC. * IF( IINFO.NE.0 ) THEN WRITE( NOUT, FMT = 9998 )'DBDSDC(values)', IINFO, M, N, $ JTYPE, IOLDSD INFO = ABS( IINFO ) IF( IINFO.LT.0 ) THEN RETURN ELSE RESULT( 18 ) = ULPINV GO TO 170 END IF END IF * * Test 15: Check the decomposition B := U * S1 * VT * 16: Check the orthogonality of U * 17: Check the orthogonality of VT * CALL DBDT03( UPLO, MNMIN, 1, BD, BE, U, LDPT, S1, VT, LDPT, $ WORK, RESULT( 15 ) ) CALL DORT01( 'Columns', MNMIN, MNMIN, U, LDPT, WORK, LWORK, $ RESULT( 16 ) ) CALL DORT01( 'Rows', MNMIN, MNMIN, VT, LDPT, WORK, LWORK, $ RESULT( 17 ) ) * * Test 18: Check that the singular values are sorted in * non-increasing order and are non-negative * RESULT( 18 ) = ZERO DO 150 I = 1, MNMIN - 1 IF( S1( I ).LT.S1( I+1 ) ) $ RESULT( 18 ) = ULPINV IF( S1( I ).LT.ZERO ) $ RESULT( 18 ) = ULPINV 150 CONTINUE IF( MNMIN.GE.1 ) THEN IF( S1( MNMIN ).LT.ZERO ) $ RESULT( 18 ) = ULPINV END IF * * Test 19: Compare DBDSQR with and without singular vectors * TEMP2 = ZERO * DO 160 J = 1, MNMIN TEMP1 = ABS( S1( J )-S2( J ) ) / $ MAX( SQRT( UNFL )*MAX( S1( 1 ), ONE ), $ ULP*MAX( ABS( S1( 1 ) ), ABS( S2( 1 ) ) ) ) TEMP2 = MAX( TEMP1, TEMP2 ) 160 CONTINUE * RESULT( 19 ) = TEMP2 * * End of Loop -- Check for RESULT(j) > THRESH * 170 CONTINUE DO 180 J = 1, 19 IF( RESULT( J ).GE.THRESH ) THEN IF( NFAIL.EQ.0 ) $ CALL DLAHD2( NOUT, PATH ) WRITE( NOUT, FMT = 9999 )M, N, JTYPE, IOLDSD, J, $ RESULT( J ) NFAIL = NFAIL + 1 END IF 180 CONTINUE IF( .NOT.BIDIAG ) THEN NTEST = NTEST + 19 ELSE NTEST = NTEST + 5 END IF * 190 CONTINUE 200 CONTINUE * * Summary * CALL ALASUM( PATH, NOUT, NFAIL, NTEST, 0 ) * RETURN * * End of DCHKBD * 9999 FORMAT( ' M=', I5, ', N=', I5, ', type ', I2, ', seed=', $ 4( I4, ',' ), ' test(', I2, ')=', G11.4 ) 9998 FORMAT( ' DCHKBD: ', A, ' returned INFO=', I6, '.', / 9X, 'M=', $ I6, ', N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ), $ I5, ')' ) * END
gpl-2.0
xianyi/OpenBLAS
lapack-netlib/TESTING/EIG/zsbmv.f
1
10675
*> \brief \b ZSBMV * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE ZSBMV( UPLO, N, K, ALPHA, A, LDA, X, INCX, BETA, Y, * INCY ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INCX, INCY, K, LDA, N * COMPLEX*16 ALPHA, BETA * .. * .. Array Arguments .. * COMPLEX*16 A( LDA, * ), X( * ), Y( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZSBMV performs the matrix-vector operation *> *> y := alpha*A*x + beta*y, *> *> where alpha and beta are scalars, x and y are n element vectors and *> A is an n by n symmetric band matrix, with k super-diagonals. *> \endverbatim * * Arguments: * ========== * *> \verbatim *> UPLO - CHARACTER*1 *> On entry, UPLO specifies whether the upper or lower *> triangular part of the band matrix A is being supplied as *> follows: *> *> UPLO = 'U' or 'u' The upper triangular part of A is *> being supplied. *> *> UPLO = 'L' or 'l' The lower triangular part of A is *> being supplied. *> *> Unchanged on exit. *> *> N - INTEGER *> On entry, N specifies the order of the matrix A. *> N must be at least zero. *> Unchanged on exit. *> *> K - INTEGER *> On entry, K specifies the number of super-diagonals of the *> matrix A. K must satisfy 0 .le. K. *> Unchanged on exit. *> *> ALPHA - COMPLEX*16 *> On entry, ALPHA specifies the scalar alpha. *> Unchanged on exit. *> *> A - COMPLEX*16 array, dimension( LDA, N ) *> Before entry with UPLO = 'U' or 'u', the leading ( k + 1 ) *> by n part of the array A must contain the upper triangular *> band part of the symmetric matrix, supplied column by *> column, with the leading diagonal of the matrix in row *> ( k + 1 ) of the array, the first super-diagonal starting at *> position 2 in row k, and so on. The top left k by k triangle *> of the array A is not referenced. *> The following program segment will transfer the upper *> triangular part of a symmetric band matrix from conventional *> full matrix storage to band storage: *> *> DO 20, J = 1, N *> M = K + 1 - J *> DO 10, I = MAX( 1, J - K ), J *> A( M + I, J ) = matrix( I, J ) *> 10 CONTINUE *> 20 CONTINUE *> *> Before entry with UPLO = 'L' or 'l', the leading ( k + 1 ) *> by n part of the array A must contain the lower triangular *> band part of the symmetric matrix, supplied column by *> column, with the leading diagonal of the matrix in row 1 of *> the array, the first sub-diagonal starting at position 1 in *> row 2, and so on. The bottom right k by k triangle of the *> array A is not referenced. *> The following program segment will transfer the lower *> triangular part of a symmetric band matrix from conventional *> full matrix storage to band storage: *> *> DO 20, J = 1, N *> M = 1 - J *> DO 10, I = J, MIN( N, J + K ) *> A( M + I, J ) = matrix( I, J ) *> 10 CONTINUE *> 20 CONTINUE *> *> Unchanged on exit. *> *> LDA - INTEGER *> On entry, LDA specifies the first dimension of A as declared *> in the calling (sub) program. LDA must be at least *> ( k + 1 ). *> Unchanged on exit. *> *> X - COMPLEX*16 array, dimension at least *> ( 1 + ( N - 1 )*abs( INCX ) ). *> Before entry, the incremented array X must contain the *> vector x. *> Unchanged on exit. *> *> INCX - INTEGER *> On entry, INCX specifies the increment for the elements of *> X. INCX must not be zero. *> Unchanged on exit. *> *> BETA - COMPLEX*16 *> On entry, BETA specifies the scalar beta. *> Unchanged on exit. *> *> Y - COMPLEX*16 array, dimension at least *> ( 1 + ( N - 1 )*abs( INCY ) ). *> Before entry, the incremented array Y must contain the *> vector y. On exit, Y is overwritten by the updated vector y. *> *> INCY - INTEGER *> On entry, INCY specifies the increment for the elements of *> Y. INCY must not be zero. *> Unchanged on exit. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup complex16_eig * * ===================================================================== SUBROUTINE ZSBMV( UPLO, N, K, ALPHA, A, LDA, X, INCX, BETA, Y, $ INCY ) * * -- LAPACK test routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INCX, INCY, K, LDA, N COMPLEX*16 ALPHA, BETA * .. * .. Array Arguments .. COMPLEX*16 A( LDA, * ), X( * ), Y( * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX*16 ONE PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) ) COMPLEX*16 ZERO PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) ) * .. * .. Local Scalars .. INTEGER I, INFO, IX, IY, J, JX, JY, KPLUS1, KX, KY, L COMPLEX*16 TEMP1, TEMP2 * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN INFO = 1 ELSE IF( N.LT.0 ) THEN INFO = 2 ELSE IF( K.LT.0 ) THEN INFO = 3 ELSE IF( LDA.LT.( K+1 ) ) THEN INFO = 6 ELSE IF( INCX.EQ.0 ) THEN INFO = 8 ELSE IF( INCY.EQ.0 ) THEN INFO = 11 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZSBMV ', INFO ) RETURN END IF * * Quick return if possible. * IF( ( N.EQ.0 ) .OR. ( ( ALPHA.EQ.ZERO ) .AND. ( BETA.EQ.ONE ) ) ) $ RETURN * * Set up the start points in X and Y. * IF( INCX.GT.0 ) THEN KX = 1 ELSE KX = 1 - ( N-1 )*INCX END IF IF( INCY.GT.0 ) THEN KY = 1 ELSE KY = 1 - ( N-1 )*INCY END IF * * Start the operations. In this version the elements of the array A * are accessed sequentially with one pass through A. * * First form y := beta*y. * IF( BETA.NE.ONE ) THEN IF( INCY.EQ.1 ) THEN IF( BETA.EQ.ZERO ) THEN DO 10 I = 1, N Y( I ) = ZERO 10 CONTINUE ELSE DO 20 I = 1, N Y( I ) = BETA*Y( I ) 20 CONTINUE END IF ELSE IY = KY IF( BETA.EQ.ZERO ) THEN DO 30 I = 1, N Y( IY ) = ZERO IY = IY + INCY 30 CONTINUE ELSE DO 40 I = 1, N Y( IY ) = BETA*Y( IY ) IY = IY + INCY 40 CONTINUE END IF END IF END IF IF( ALPHA.EQ.ZERO ) $ RETURN IF( LSAME( UPLO, 'U' ) ) THEN * * Form y when upper triangle of A is stored. * KPLUS1 = K + 1 IF( ( INCX.EQ.1 ) .AND. ( INCY.EQ.1 ) ) THEN DO 60 J = 1, N TEMP1 = ALPHA*X( J ) TEMP2 = ZERO L = KPLUS1 - J DO 50 I = MAX( 1, J-K ), J - 1 Y( I ) = Y( I ) + TEMP1*A( L+I, J ) TEMP2 = TEMP2 + A( L+I, J )*X( I ) 50 CONTINUE Y( J ) = Y( J ) + TEMP1*A( KPLUS1, J ) + ALPHA*TEMP2 60 CONTINUE ELSE JX = KX JY = KY DO 80 J = 1, N TEMP1 = ALPHA*X( JX ) TEMP2 = ZERO IX = KX IY = KY L = KPLUS1 - J DO 70 I = MAX( 1, J-K ), J - 1 Y( IY ) = Y( IY ) + TEMP1*A( L+I, J ) TEMP2 = TEMP2 + A( L+I, J )*X( IX ) IX = IX + INCX IY = IY + INCY 70 CONTINUE Y( JY ) = Y( JY ) + TEMP1*A( KPLUS1, J ) + ALPHA*TEMP2 JX = JX + INCX JY = JY + INCY IF( J.GT.K ) THEN KX = KX + INCX KY = KY + INCY END IF 80 CONTINUE END IF ELSE * * Form y when lower triangle of A is stored. * IF( ( INCX.EQ.1 ) .AND. ( INCY.EQ.1 ) ) THEN DO 100 J = 1, N TEMP1 = ALPHA*X( J ) TEMP2 = ZERO Y( J ) = Y( J ) + TEMP1*A( 1, J ) L = 1 - J DO 90 I = J + 1, MIN( N, J+K ) Y( I ) = Y( I ) + TEMP1*A( L+I, J ) TEMP2 = TEMP2 + A( L+I, J )*X( I ) 90 CONTINUE Y( J ) = Y( J ) + ALPHA*TEMP2 100 CONTINUE ELSE JX = KX JY = KY DO 120 J = 1, N TEMP1 = ALPHA*X( JX ) TEMP2 = ZERO Y( JY ) = Y( JY ) + TEMP1*A( 1, J ) L = 1 - J IX = JX IY = JY DO 110 I = J + 1, MIN( N, J+K ) IX = IX + INCX IY = IY + INCY Y( IY ) = Y( IY ) + TEMP1*A( L+I, J ) TEMP2 = TEMP2 + A( L+I, J )*X( IX ) 110 CONTINUE Y( JY ) = Y( JY ) + ALPHA*TEMP2 JX = JX + INCX JY = JY + INCY 120 CONTINUE END IF END IF * RETURN * * End of ZSBMV * END
bsd-3-clause
xianyi/OpenBLAS
lapack-netlib/TESTING/LIN/zlatsy.f
1
7131
*> \brief \b ZLATSY * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE ZLATSY( UPLO, N, X, LDX, ISEED ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER LDX, N * .. * .. Array Arguments .. * INTEGER ISEED( * ) * COMPLEX*16 X( LDX, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZLATSY generates a special test matrix for the complex symmetric *> (indefinite) factorization. The pivot blocks of the generated matrix *> will be in the following order: *> 2x2 pivot block, non diagonalizable *> 1x1 pivot block *> 2x2 pivot block, diagonalizable *> (cycle repeats) *> A row interchange is required for each non-diagonalizable 2x2 block. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER *> Specifies whether the generated matrix is to be upper or *> lower triangular. *> = 'U': Upper triangular *> = 'L': Lower triangular *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The dimension of the matrix to be generated. *> \endverbatim *> *> \param[out] X *> \verbatim *> X is COMPLEX*16 array, dimension (LDX,N) *> The generated matrix, consisting of 3x3 and 2x2 diagonal *> blocks which result in the pivot sequence given above. *> The matrix outside of these diagonal blocks is zero. *> \endverbatim *> *> \param[in] LDX *> \verbatim *> LDX is INTEGER *> The leading dimension of the array X. *> \endverbatim *> *> \param[in,out] ISEED *> \verbatim *> ISEED is INTEGER array, dimension (4) *> On entry, the seed for the random number generator. The last *> of the four integers must be odd. (modified on exit) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup complex16_lin * * ===================================================================== SUBROUTINE ZLATSY( UPLO, N, X, LDX, ISEED ) * * -- LAPACK test routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. CHARACTER UPLO INTEGER LDX, N * .. * .. Array Arguments .. INTEGER ISEED( * ) COMPLEX*16 X( LDX, * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX*16 EYE PARAMETER ( EYE = ( 0.0D0, 1.0D0 ) ) * .. * .. Local Scalars .. INTEGER I, J, N5 DOUBLE PRECISION ALPHA, ALPHA3, BETA COMPLEX*16 A, B, C, R * .. * .. External Functions .. COMPLEX*16 ZLARND EXTERNAL ZLARND * .. * .. Intrinsic Functions .. INTRINSIC ABS, SQRT * .. * .. Executable Statements .. * * Initialize constants * ALPHA = ( 1.D0+SQRT( 17.D0 ) ) / 8.D0 BETA = ALPHA - 1.D0 / 1000.D0 ALPHA3 = ALPHA*ALPHA*ALPHA * * UPLO = 'U': Upper triangular storage * IF( UPLO.EQ.'U' ) THEN * * Fill the upper triangle of the matrix with zeros. * DO 20 J = 1, N DO 10 I = 1, J X( I, J ) = 0.0D0 10 CONTINUE 20 CONTINUE N5 = N / 5 N5 = N - 5*N5 + 1 * DO 30 I = N, N5, -5 A = ALPHA3*ZLARND( 5, ISEED ) B = ZLARND( 5, ISEED ) / ALPHA C = A - 2.D0*B*EYE R = C / BETA X( I, I ) = A X( I-2, I ) = B X( I-2, I-1 ) = R X( I-2, I-2 ) = C X( I-1, I-1 ) = ZLARND( 2, ISEED ) X( I-3, I-3 ) = ZLARND( 2, ISEED ) X( I-4, I-4 ) = ZLARND( 2, ISEED ) IF( ABS( X( I-3, I-3 ) ).GT.ABS( X( I-4, I-4 ) ) ) THEN X( I-4, I-3 ) = 2.0D0*X( I-3, I-3 ) ELSE X( I-4, I-3 ) = 2.0D0*X( I-4, I-4 ) END IF 30 CONTINUE * * Clean-up for N not a multiple of 5. * I = N5 - 1 IF( I.GT.2 ) THEN A = ALPHA3*ZLARND( 5, ISEED ) B = ZLARND( 5, ISEED ) / ALPHA C = A - 2.D0*B*EYE R = C / BETA X( I, I ) = A X( I-2, I ) = B X( I-2, I-1 ) = R X( I-2, I-2 ) = C X( I-1, I-1 ) = ZLARND( 2, ISEED ) I = I - 3 END IF IF( I.GT.1 ) THEN X( I, I ) = ZLARND( 2, ISEED ) X( I-1, I-1 ) = ZLARND( 2, ISEED ) IF( ABS( X( I, I ) ).GT.ABS( X( I-1, I-1 ) ) ) THEN X( I-1, I ) = 2.0D0*X( I, I ) ELSE X( I-1, I ) = 2.0D0*X( I-1, I-1 ) END IF I = I - 2 ELSE IF( I.EQ.1 ) THEN X( I, I ) = ZLARND( 2, ISEED ) I = I - 1 END IF * * UPLO = 'L': Lower triangular storage * ELSE * * Fill the lower triangle of the matrix with zeros. * DO 50 J = 1, N DO 40 I = J, N X( I, J ) = 0.0D0 40 CONTINUE 50 CONTINUE N5 = N / 5 N5 = N5*5 * DO 60 I = 1, N5, 5 A = ALPHA3*ZLARND( 5, ISEED ) B = ZLARND( 5, ISEED ) / ALPHA C = A - 2.D0*B*EYE R = C / BETA X( I, I ) = A X( I+2, I ) = B X( I+2, I+1 ) = R X( I+2, I+2 ) = C X( I+1, I+1 ) = ZLARND( 2, ISEED ) X( I+3, I+3 ) = ZLARND( 2, ISEED ) X( I+4, I+4 ) = ZLARND( 2, ISEED ) IF( ABS( X( I+3, I+3 ) ).GT.ABS( X( I+4, I+4 ) ) ) THEN X( I+4, I+3 ) = 2.0D0*X( I+3, I+3 ) ELSE X( I+4, I+3 ) = 2.0D0*X( I+4, I+4 ) END IF 60 CONTINUE * * Clean-up for N not a multiple of 5. * I = N5 + 1 IF( I.LT.N-1 ) THEN A = ALPHA3*ZLARND( 5, ISEED ) B = ZLARND( 5, ISEED ) / ALPHA C = A - 2.D0*B*EYE R = C / BETA X( I, I ) = A X( I+2, I ) = B X( I+2, I+1 ) = R X( I+2, I+2 ) = C X( I+1, I+1 ) = ZLARND( 2, ISEED ) I = I + 3 END IF IF( I.LT.N ) THEN X( I, I ) = ZLARND( 2, ISEED ) X( I+1, I+1 ) = ZLARND( 2, ISEED ) IF( ABS( X( I, I ) ).GT.ABS( X( I+1, I+1 ) ) ) THEN X( I+1, I ) = 2.0D0*X( I, I ) ELSE X( I+1, I ) = 2.0D0*X( I+1, I+1 ) END IF I = I + 2 ELSE IF( I.EQ.N ) THEN X( I, I ) = ZLARND( 2, ISEED ) I = I + 1 END IF END IF * RETURN * * End of ZLATSY * END
bsd-3-clause
apollos/Quantum-ESPRESSO
PHonon/PH/set_int12_nc.f90
5
2924
! ! Copyright (C) 2007-2009 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . !---------------------------------------------------------------------------- SUBROUTINE set_int12_nc(iflag) !---------------------------------------------------------------------------- ! ! This is a driver to call the routines that rotate and multiply ! by the Pauli matrices the integrals. ! USE ions_base, ONLY : nat, ntyp => nsp, ityp USE spin_orb, ONLY : lspinorb USE uspp_param, only: upf USE phus, ONLY : int1, int2, int1_nc, int2_so IMPLICIT NONE INTEGER :: iflag INTEGER :: np, na int1_nc=(0.d0,0.d0) IF (lspinorb) int2_so=(0.d0,0.d0) DO np = 1, ntyp IF ( upf(np)%tvanp ) THEN DO na = 1, nat IF (ityp(na)==np) THEN IF (upf(np)%has_so) THEN CALL transform_int1_so(int1,na,iflag) CALL transform_int2_so(int2,na,iflag) ELSE CALL transform_int1_nc(int1,na,iflag) IF (lspinorb) CALL transform_int2_nc(int2,na,iflag) END IF END IF END DO END IF END DO END SUBROUTINE set_int12_nc !---------------------------------------------------------------------------- SUBROUTINE set_int3_nc(npe) !---------------------------------------------------------------------------- USE ions_base, ONLY : nat, ntyp => nsp, ityp USE uspp_param, only: upf USE phus, ONLY : int3, int3_nc IMPLICIT NONE INTEGER :: npe INTEGER :: np, na int3_nc=(0.d0,0.d0) DO np = 1, ntyp IF ( upf(np)%tvanp ) THEN DO na = 1, nat IF (ityp(na)==np) THEN IF (upf(np)%has_so) THEN CALL transform_int3_so(int3,na,npe) ELSE CALL transform_int3_nc(int3,na,npe) END IF END IF END DO END IF END DO END SUBROUTINE set_int3_nc ! !---------------------------------------------------------------------------- SUBROUTINE set_dbecsum_nc(dbecsum_nc, dbecsum, npe) !---------------------------------------------------------------------------- USE kinds, ONLY : DP USE ions_base, ONLY : nat, ntyp => nsp, ityp USE uspp_param, only: upf, nhm USE noncollin_module, ONLY : nspin_mag USE lsda_mod, ONLY : nspin IMPLICIT NONE INTEGER :: npe INTEGER :: np, na COMPLEX(DP), INTENT(IN) :: dbecsum_nc( nhm, nhm, nat, nspin, npe) COMPLEX(DP), INTENT(OUT) :: dbecsum( nhm*(nhm+1)/2, nat, nspin_mag, npe) DO np = 1, ntyp IF ( upf(np)%tvanp ) THEN DO na = 1, nat IF (ityp(na)==np) THEN IF (upf(np)%has_so) THEN CALL transform_dbecsum_so(dbecsum_nc,dbecsum,na, npe) ELSE CALL transform_dbecsum_nc(dbecsum_nc,dbecsum,na, npe) END IF END IF END DO END IF END DO RETURN END SUBROUTINE set_dbecsum_nc
gpl-2.0
braghiere/JULESv4.6_clump
extract/jules/src/science/snow/snowpack.F90
4
23649
! *****************************COPYRIGHT******************************* ! (c) [University of Edinburgh] [2009]. All rights reserved. ! This routine has been licensed to the Met Office for use and ! distribution under the JULES collaboration agreement, subject ! to the terms and conditions set out therein. ! [Met Office Ref SC237] ! *****************************COPYRIGHT******************************* ! SUBROUTINE SNOWPACK------------------------------------------------- ! Description: ! Snow thermodynamics and hydrology ! Subroutine Interface: MODULE snowpack_mod CHARACTER(LEN=*), PARAMETER, PRIVATE :: ModuleName='SNOWPACK_MOD' CONTAINS SUBROUTINE snowpack ( land_pts,surft_pts,timestep,cansnowtile, & nsnow,surft_index,csnow,ei_surft,hcaps,hcons, & infiltration, & ksnow,rho_snow_grnd,smcl1,snowfall,sthf1, & surf_htf_surft,tile_frac,v_sat1,ds, & melt_surft,sice,sliq,snomlt_sub_htf, & snowdepth,snowmass,tsnow,tsoil1,tsurf_elev_surft, & snow_soil_htf,rho_snow,rho0,sice0,tsnow0 ) USE tridag_mod, ONLY: tridag USE c_0_dg_c, ONLY : & ! imported scalar parameters tm ! Temperature at which fresh water freezes ! ! and ice melts (K) USE c_densty, ONLY : & ! imported scalar parameters rho_water ! density of pure water (kg/m3) USE c_lheat , ONLY : & ! imported scalar parameters lc & ! latent heat of condensation of water ! ! at 0degC (J kg-1) ,lf ! latent heat of fusion at 0degC (J kg-1) USE water_constants_mod, ONLY : & ! imported scalar parameters hcapi & ! Specific heat capacity of ice (J/kg/K) ,hcapw & ! Specific heat capacity of water (J/kg/K) ,rho_ice ! Specific density of solid ice (kg/m3) USE ancil_info, ONLY : l_lice_point USE jules_soil_mod, ONLY : dzsoil, dzsoil_elev USE jules_surface_mod, ONLY : l_elev_land_ice USE jules_snow_mod, ONLY : & nsmax & ! Maximum possible number of snow layers ,l_snow_infilt & ! Include infiltration of rain into snow ,rho_snow_const & ! constant density of lying snow (kg per m**3) ,rho_snow_fresh & ! density of fresh snow (kg per m**3) ,snowliqcap & ! Liquid water holding capacity of lying snow ! as a fraction of snow mass. ,snow_hcon & ! Conductivity of snow ,rho_firn_pore_restrict & ! Density at which ability of snowpack to hold/percolate ! water starts to be restricted ,rho_firn_pore_closure ! Density at which snowpack pores close off entirely and ! no additional melt can be held/percolated through USE parkind1, ONLY: jprb, jpim USE yomhook, ONLY: lhook, dr_hook IMPLICIT NONE ! Scalar parameters REAL, PARAMETER :: GAMMA = 0.5 ! Implicit timestep weighting ! Scalar arguments with intent(in) INTEGER, INTENT(IN) :: & land_pts & ! Total number of land points ,surft_pts ! Number of tile points REAL, INTENT(IN) :: & timestep ! Timestep (s) LOGICAL, INTENT(IN) :: & cansnowtile ! Switch for canopy snow model ! Array arguments with intent(in) INTEGER, INTENT(IN) :: & nsnow(land_pts) & ! Number of snow layers ,surft_index(land_pts) ! Index of tile points REAL, INTENT(IN) :: & csnow(land_pts,nsmax) & ! Areal heat capacity of layers (J/K/m2) ,ei_surft(land_pts) & ! Sublimation of snow (kg/m2/s) ,hcaps(land_pts) & ! Heat capacity of soil surface layer (J/K/m3) ,hcons(land_pts) & ! Thermal conductivity of top soil layer, ! ! including water and ice (W/m/K) ,ksnow(land_pts,nsmax) & ! Thermal conductivity of layers (W/m/K) ,rho_snow_grnd(land_pts) & ! Snowpack bulk density (kg/m3) ,smcl1(land_pts) & ! Moisture content of surface soil layer (kg/m2) ,snowfall(land_pts) & ! Snow reaching the ground (kg/m2) ,infiltration(land_pts) & ! Rainfall infiltrating into snowpack (kg/m2) ,sthf1(land_pts) & ! Frozen soil moisture content of surface layer ! ! as a fraction of saturation. ,surf_htf_surft(land_pts) & ! Snow surface heat flux (W/m2) ,tile_frac(land_pts) & ! Tile fractions ,v_sat1(land_pts) ! Surface soil layer volumetric ! ! moisture concentration at saturation ! Array arguments with intent(inout) REAL, INTENT(INOUT) :: & ds(land_pts,nsmax) & ! Snow layer depths (m) ,melt_surft(land_pts) & ! Surface snowmelt rate (kg/m2/s) ,sice(land_pts,nsmax) & ! Ice content of snow layers (kg/m2) ,sliq(land_pts,nsmax) & ! Liquid content of snow layers (kg/m2) ,snomlt_sub_htf(land_pts) & ! Sub-canopy snowmelt heat flux (W/m2) ,snowdepth(land_pts) & ! Snow depth (m) ,snowmass(land_pts) & ! Snow mass on the ground (kg/m2) ,tsnow(land_pts,nsmax) & ! Snow layer temperatures (K) ,tsoil1(land_pts) & ! Soil surface layer temperature(K) ,tsurf_elev_surft(land_pts) ! Temperature of elevated subsurface tiles (K) ! Array arguments with intent(out) REAL, INTENT(OUT) :: & snow_soil_htf(land_pts) & ! Heat flux into the uppermost subsurface layer ! ! (W/m2) ! ! i.e. snow to ground, or into snow/soil ! ! composite layer ,rho0(land_pts) & ! Density of fresh snow (kg/m3) ! ! Where NSNOW=0, rho0 is the density ! ! of the snowpack. ,sice0(land_pts) & ! Ice content of fresh snow (kg/m2) ! ! Where NSNOW=0, SICE0 is the mass of ! ! the snowpack. ,tsnow0(land_pts) & ! Temperature of fresh snow (K) ,rho_snow(land_pts,nsmax) ! Density of snow layers (kg/m3) ! Local scalars INTEGER :: & i & ! land point index ,k & ! Tile point index ,n ! Snow layer index REAL :: & asoil & ! 1 / (dz*hcap) for surface soil layer ,can_melt & ! Melt of snow on the canopy (kg/m2/s) ,coldsnow & ! layer cold content (J/m2) ,dsice & ! Change in layer ice content (kg/m2) ,g_snow_surf & ! Heat flux at the snow surface (W/m2) ,sliqmax & ! Maximum liquid content for layer (kg/m2) ,submelt & ! Melt of snow beneath canopy (kg/m2/s) ,smclf & ! Frozen soil moisture content of ! ! surface layer (kg/m2) ,win & ! Water entering layer (kg/m2) ,tsoilw & ,hconsw & ,dzsoilw ! working copies of tsoil, hcon and dzsoil for the loop ! Local arrays REAL :: & asnow(nsmax) & ! Effective thermal conductivity (W/m2/k) ,a(nsmax) & ! Below-diagonal matrix elements ,b(nsmax) & ! Diagonal matrix elements ,c(nsmax) & ! Above-diagonal matrix elements ,dt(nsmax) & ! Temperature increments (k) ,r(nsmax) ! Matrix equation rhs REAL :: rho_temp ! Temporary array for layer density INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0 INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1 REAL(KIND=jprb) :: zhook_handle CHARACTER(LEN=*), PARAMETER :: RoutineName='SNOWPACK' !----------------------------------------------------------------------- IF (lhook) CALL dr_hook(ModuleName//':'//RoutineName,zhook_in,zhook_handle) !Required for bit comparison in the UM to ensure all tile points are set to !zero regardless of fraction present rho_snow(:,:) = 0.0 snow_soil_htf(:)=0. DO k=1,surft_pts i = surft_index(k) IF (l_elev_land_ice .AND. l_lice_point(i)) THEN tsoilw=tsurf_elev_surft(i) hconsw=snow_hcon dzsoilw=dzsoil_elev ELSE tsoilw=tsoil1(i) hconsw=hcons(i) dzsoilw=dzsoil(1) END IF g_snow_surf = surf_htf_surft(i) !----------------------------------------------------------------------- ! Add melt to snow surface heat flux, unless using the snow canopy model !----------------------------------------------------------------------- IF ( .NOT. cansnowtile ) & g_snow_surf = g_snow_surf + lf*melt_surft(i) IF ( nsnow(i) == 0 ) THEN ! Add snowfall (including canopy unloading) to ground snowpack. snowmass(i) = snowmass(i) + snowfall(i) IF ( .NOT. cansnowtile ) THEN !----------------------------------------------------------------------- ! Remove sublimation and melt from snowpack. !----------------------------------------------------------------------- snowmass(i) = snowmass(i) - & ( ei_surft(i) + melt_surft(i) ) * timestep ELSE IF ( tsoilw > tm ) THEN !----------------------------------------------------------------------- ! For canopy model, calculate melt of snow on ground underneath canopy. !----------------------------------------------------------------------- smclf = rho_water * dzsoilw * v_sat1(i) * sthf1(i) asoil = 1./ ( dzsoilw * hcaps(i) + & hcapw * (smcl1(i) - smclf) + hcapi*smclf ) submelt = MIN( snowmass(i) / timestep, & (tsoilw - tm) / (lf * asoil * timestep) ) snowmass(i) = snowmass(i) - submelt * timestep tsoilw = tsoilw - & tile_frac(i) * asoil * timestep * lf * submelt melt_surft(i) = melt_surft(i) + submelt snomlt_sub_htf(i) = snomlt_sub_htf(i) + & tile_frac(i) * lf * submelt END IF ! Set flux into uppermost snow/soil layer (after melting). snow_soil_htf(i) = surf_htf_surft(i) ! Diagnose snow depth. snowdepth(i) = snowmass(i) / rho_snow_grnd(i) ! Set values for the surface layer. These are only needed for nsmax>0. IF ( nsmax > 0 ) THEN rho0(i) = rho_snow_grnd(i) sice0(i) = snowmass(i) tsnow0(i) = MIN( tsoilw, tm ) END IF ! Note with nsmax>0 the density of a shallow pack (nsnow=0) does not ! evolve with time (until it is exhausted). We could consider updating ! the density using a mass-weighted mean of the pack density and that ! of fresh snow, so that a growing pack would reach nsnow=1 more quickly. ! This would only affect a pack that grows from a non-zero state, and ! is not an issue if the pack grows from zero, because in that case the ! the density was previously set to the fresh snow value. ELSE !----------------------------------------------------------------------- ! There is at least one snow layer. Calculate heat conduction between ! layers and temperature increments. !----------------------------------------------------------------------- ! Save rate of melting of snow on the canopy. IF ( cansnowtile ) THEN can_melt = melt_surft(i) ELSE can_melt = 0.0 END IF IF ( nsnow(i) == 1 ) THEN ! Single layer of snow. asnow(1) = 2.0 / & ( snowdepth(i)/ksnow(i,1) + dzsoilw/hconsw ) snow_soil_htf(i) = asnow(1) * ( tsnow(i,1) - tsoilw ) dt(1) = ( g_snow_surf - snow_soil_htf(i) ) * timestep / & ( csnow(i,1) + GAMMA * asnow(1) * timestep ) snow_soil_htf(i) = asnow(1) * & ( tsnow(i,1) + GAMMA*dt(1) - tsoilw ) tsnow(i,1) = tsnow(i,1) + dt(1) ELSE ! Multiple snow layers. DO n=1,nsnow(i)-1 asnow(n) = 2.0 / & ( ds(i,n)/ksnow(i,n) + ds(i,n+1)/ksnow(i,n+1) ) END DO n = nsnow(i) asnow(n) = 2.0 / ( ds(i,n)/ksnow(i,n) + dzsoilw/hconsw ) a(1) = 0. b(1) = csnow(i,1) + GAMMA*asnow(1)*timestep c(1) = -GAMMA * asnow(1) * timestep r(1) = ( g_snow_surf - asnow(1)*(tsnow(i,1)-tsnow(i,2)) ) & * timestep DO n=2,nsnow(i)-1 a(n) = -GAMMA * asnow(n-1) * timestep b(n) = csnow(i,n) + GAMMA * ( asnow(n-1) + asnow(n) ) & * timestep c(n) = -GAMMA * asnow(n) * timestep r(n) = asnow(n-1)*(tsnow(i,n-1) - tsnow(i,n) ) * timestep & + asnow(n)*(tsnow(i,n+1) - tsnow(i,n)) * timestep END DO n = nsnow(i) a(n) = -GAMMA * asnow(n-1) * timestep b(n) = csnow(i,n) + GAMMA * (asnow(n-1)+asnow(n)) * timestep c(n) = 0. r(n) = asnow(n-1)*( tsnow(i,n-1) - tsnow(i,n) ) * timestep & + asnow(n) * ( tsoilw - tsnow(i,n) ) * timestep !----------------------------------------------------------------------- ! Call the tridiagonal solver. !----------------------------------------------------------------------- CALL tridag( nsnow(i),nsmax,a,b,c,r,dt ) n = nsnow(i) snow_soil_htf(i) = asnow(n) * & ( tsnow(i,n) + GAMMA*dt(n) - tsoilw ) DO n=1,nsnow(i) tsnow(i,n) = tsnow(i,n) + dt(n) END DO END IF ! NSNOW !----------------------------------------------------------------------- ! Melt snow in layers with temperature exceeding melting point !----------------------------------------------------------------------- DO n=1,nsnow(i) coldsnow = csnow(i,n)*(tm - tsnow(i,n)) IF ( coldsnow < 0 ) THEN tsnow(i,n) = tm dsice = -coldsnow / lf IF ( dsice > sice(i,n) ) dsice = sice(i,n) ds(i,n) = ( 1.0 - dsice/sice(i,n) ) * ds(i,n) sice(i,n) = sice(i,n) - dsice sliq(i,n) = sliq(i,n) + dsice END IF END DO ! Melt still > 0? - no snow left !----------------------------------------------------------------------- ! Remove snow by sublimation unless snow is beneath canopy !----------------------------------------------------------------------- IF ( .NOT. cansnowtile ) THEN dsice = MAX( ei_surft(i), 0. ) * timestep IF ( dsice > 0.0 ) THEN DO n=1,nsnow(i) IF ( dsice > sice(i,n) ) THEN ! Layer sublimates completely dsice = dsice - sice(i,n) sice(i,n) = 0. ds(i,n) = 0. ELSE ! Layer sublimates partially ds(i,n) = (1.0 - dsice/sice(i,n))*ds(i,n) sice(i,n) = sice(i,n) - dsice EXIT ! sublimation exhausted END IF END DO END IF ! DSICE>0 END IF ! CANSNOWTILE !----------------------------------------------------------------------- ! Move liquid water in excess of holding capacity downwards or refreeze. !----------------------------------------------------------------------- ! Optionally include infiltration of rainwater and melting from the ! canopy into the snowpack. IF (l_snow_infilt) THEN win = infiltration(i) + can_melt * timestep ELSE win = 0.0 END IF DO n=1,nsnow(i) sliq(i,n) = sliq(i,n) + win win = 0.0 sliqmax = snowliqcap * rho_water * ds(i,n) !construct a temporary rho here. Can't guarantee !sensible values of anything at ths point in the routine. If layer !has gone (ds=0), just feed everything down to the next layer IF ( ds(i,n) > EPSILON(0.0) ) THEN rho_temp = min(rho_ice,(sice(i,n) + sliq(i,n)) / ds(i,n)) ELSE rho_temp = rho_ice END IF !reduce pore density of pack as we approach solid ice IF (l_elev_land_ice .AND. l_lice_point(i)) THEN IF(rho_temp >= rho_firn_pore_closure) THEN sliqmax = 0.0 ELSE IF((rho_temp >= rho_firn_pore_restrict) .AND. & (rho_temp < rho_firn_pore_closure)) THEN sliqmax = sliqmax * (rho_firn_pore_closure - rho_temp) / & (rho_firn_pore_closure - rho_firn_pore_restrict) ENDIF ENDIF IF (sliq(i,n) > sliqmax) THEN ! Liquid capacity exceeded win = sliq(i,n) - sliqmax sliq(i,n) = sliqmax END IF coldsnow = csnow(i,n)*(tm - tsnow(i,n)) IF (coldsnow > 0) THEN ! Liquid can freeze dsice = MIN(sliq(i,n), coldsnow / lf) sliq(i,n) = sliq(i,n) - dsice sice(i,n) = sice(i,n) + dsice tsnow(i,n) = tsnow(i,n) + lf*dsice/csnow(i,n) END IF END DO !----------------------------------------------------------------------- ! The remaining liquid water flux is melt. ! Include any separate canopy melt in this diagnostic. !----------------------------------------------------------------------- IF ( l_snow_infilt ) THEN ! Canopy melting has already been added to infiltration. melt_surft(i) = ( win / timestep ) ELSE melt_surft(i) = ( win / timestep ) + can_melt END IF !----------------------------------------------------------------------- ! Diagnose layer densities !----------------------------------------------------------------------- DO n=1,nsnow(i) ! rho_snow(i,n) = 0.0 IF ( ds(i,n) > EPSILON(ds) ) & rho_snow(i,n) = (sice(i,n) + sliq(i,n)) / ds(i,n) END DO !----------------------------------------------------------------------- ! Add snowfall and frost as layer 0. !----------------------------------------------------------------------- sice0(i) = snowfall(i) IF ( .NOT. cansnowtile ) & sice0(i) = snowfall(i) - MIN(ei_surft(i), 0.) * timestep tsnow0(i) = tsnow(i,1) rho0(i) = rho_snow_fresh !----------------------------------------------------------------------- ! Diagnose total snow depth and mass !----------------------------------------------------------------------- snowdepth(i) = sice0(i) / rho0(i) snowmass(i) = sice0(i) DO n=1,nsnow(i) snowdepth(i) = snowdepth(i) + ds(i,n) snowmass(i) = snowmass(i) + sice(i,n) + sliq(i,n) END DO END IF ! NSNOW ! tsoil only modified for canopy snow tiles (and not land ice ones, ! although they shouldn't have this switch on anyway) IF (.NOT. l_elev_land_ice) THEN tsoil1(i)=tsoilw ELSE IF (.NOT. l_lice_point(i)) THEN tsoil1(i)=tsoilw END IF END DO ! k (points) IF (lhook) CALL dr_hook(ModuleName//':'//RoutineName,zhook_out,zhook_handle) RETURN END SUBROUTINE snowpack END MODULE snowpack_mod
gpl-2.0
apollos/Quantum-ESPRESSO
lapack-3.2/SRC/cpptri.f
1
3642
SUBROUTINE CPPTRI( UPLO, N, AP, INFO ) * * -- LAPACK routine (version 3.2) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2006 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, N * .. * .. Array Arguments .. COMPLEX AP( * ) * .. * * Purpose * ======= * * CPPTRI computes the inverse of a complex Hermitian positive definite * matrix A using the Cholesky factorization A = U**H*U or A = L*L**H * computed by CPPTRF. * * Arguments * ========= * * UPLO (input) CHARACTER*1 * = 'U': Upper triangular factor is stored in AP; * = 'L': Lower triangular factor is stored in AP. * * N (input) INTEGER * The order of the matrix A. N >= 0. * * AP (input/output) COMPLEX array, dimension (N*(N+1)/2) * On entry, the triangular factor U or L from the Cholesky * factorization A = U**H*U or A = L*L**H, packed columnwise as * a linear array. The j-th column of U or L is stored in the * array AP as follows: * if UPLO = 'U', AP(i + (j-1)*j/2) = U(i,j) for 1<=i<=j; * if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = L(i,j) for j<=i<=n. * * On exit, the upper or lower triangle of the (Hermitian) * inverse of A, overwriting the input factor U or L. * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value * > 0: if INFO = i, the (i,i) element of the factor U or L is * zero, and the inverse could not be computed. * * ===================================================================== * * .. Parameters .. REAL ONE PARAMETER ( ONE = 1.0E+0 ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER J, JC, JJ, JJN REAL AJJ * .. * .. External Functions .. LOGICAL LSAME COMPLEX CDOTC EXTERNAL LSAME, CDOTC * .. * .. External Subroutines .. EXTERNAL CHPR, CSSCAL, CTPMV, CTPTRI, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC REAL * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 UPPER = LSAME( UPLO, 'U' ) IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CPPTRI', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * Invert the triangular Cholesky factor U or L. * CALL CTPTRI( UPLO, 'Non-unit', N, AP, INFO ) IF( INFO.GT.0 ) $ RETURN IF( UPPER ) THEN * * Compute the product inv(U) * inv(U)'. * JJ = 0 DO 10 J = 1, N JC = JJ + 1 JJ = JJ + J IF( J.GT.1 ) $ CALL CHPR( 'Upper', J-1, ONE, AP( JC ), 1, AP ) AJJ = AP( JJ ) CALL CSSCAL( J, AJJ, AP( JC ), 1 ) 10 CONTINUE * ELSE * * Compute the product inv(L)' * inv(L). * JJ = 1 DO 20 J = 1, N JJN = JJ + N - J + 1 AP( JJ ) = REAL( CDOTC( N-J+1, AP( JJ ), 1, AP( JJ ), 1 ) ) IF( J.LT.N ) $ CALL CTPMV( 'Lower', 'Conjugate transpose', 'Non-unit', $ N-J, AP( JJN ), AP( JJ+1 ), 1 ) JJ = JJN 20 CONTINUE END IF * RETURN * * End of CPPTRI * END
gpl-2.0
xianyi/OpenBLAS
lapack-netlib/SRC/zgebal.f
1
10649
*> \brief \b ZGEBAL * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZGEBAL + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgebal.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgebal.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgebal.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO ) * * .. Scalar Arguments .. * CHARACTER JOB * INTEGER IHI, ILO, INFO, LDA, N * .. * .. Array Arguments .. * DOUBLE PRECISION SCALE( * ) * COMPLEX*16 A( LDA, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZGEBAL balances a general complex matrix A. This involves, first, *> permuting A by a similarity transformation to isolate eigenvalues *> in the first 1 to ILO-1 and last IHI+1 to N elements on the *> diagonal; and second, applying a diagonal similarity transformation *> to rows and columns ILO to IHI to make the rows and columns as *> close in norm as possible. Both steps are optional. *> *> Balancing may reduce the 1-norm of the matrix, and improve the *> accuracy of the computed eigenvalues and/or eigenvectors. *> \endverbatim * * Arguments: * ========== * *> \param[in] JOB *> \verbatim *> JOB is CHARACTER*1 *> Specifies the operations to be performed on A: *> = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0 *> for i = 1,...,N; *> = 'P': permute only; *> = 'S': scale only; *> = 'B': both permute and scale. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX*16 array, dimension (LDA,N) *> On entry, the input matrix A. *> On exit, A is overwritten by the balanced matrix. *> If JOB = 'N', A is not referenced. *> See Further Details. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[out] ILO *> \verbatim *> ILO is INTEGER *> \endverbatim *> *> \param[out] IHI *> \verbatim *> IHI is INTEGER *> ILO and IHI are set to INTEGER such that on exit *> A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N. *> If JOB = 'N' or 'S', ILO = 1 and IHI = N. *> \endverbatim *> *> \param[out] SCALE *> \verbatim *> SCALE is DOUBLE PRECISION array, dimension (N) *> Details of the permutations and scaling factors applied to *> A. If P(j) is the index of the row and column interchanged *> with row and column j and D(j) is the scaling factor *> applied to row and column j, then *> SCALE(j) = P(j) for j = 1,...,ILO-1 *> = D(j) for j = ILO,...,IHI *> = P(j) for j = IHI+1,...,N. *> The order in which the interchanges are made is N to IHI+1, *> then 1 to ILO-1. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit. *> < 0: if INFO = -i, the i-th argument had an illegal value. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup complex16GEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The permutations consist of row and column interchanges which put *> the matrix in the form *> *> ( T1 X Y ) *> P A P = ( 0 B Z ) *> ( 0 0 T2 ) *> *> where T1 and T2 are upper triangular matrices whose eigenvalues lie *> along the diagonal. The column indices ILO and IHI mark the starting *> and ending columns of the submatrix B. Balancing consists of applying *> a diagonal similarity transformation inv(D) * B * D to make the *> 1-norms of each row of B and its corresponding column nearly equal. *> The output matrix is *> *> ( T1 X*D Y ) *> ( 0 inv(D)*B*D inv(D)*Z ). *> ( 0 0 T2 ) *> *> Information about the permutations P and the diagonal matrix D is *> returned in the vector SCALE. *> *> This subroutine is based on the EISPACK routine CBAL. *> *> Modified by Tzu-Yi Chen, Computer Science Division, University of *> California at Berkeley, USA *> \endverbatim *> * ===================================================================== SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO ) * * -- LAPACK computational routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. CHARACTER JOB INTEGER IHI, ILO, INFO, LDA, N * .. * .. Array Arguments .. DOUBLE PRECISION SCALE( * ) COMPLEX*16 A( LDA, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) DOUBLE PRECISION SCLFAC PARAMETER ( SCLFAC = 2.0D+0 ) DOUBLE PRECISION FACTOR PARAMETER ( FACTOR = 0.95D+0 ) * .. * .. Local Scalars .. LOGICAL NOCONV INTEGER I, ICA, IEXC, IRA, J, K, L, M DOUBLE PRECISION C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1, $ SFMIN2 * .. * .. External Functions .. LOGICAL DISNAN, LSAME INTEGER IZAMAX DOUBLE PRECISION DLAMCH, DZNRM2 EXTERNAL DISNAN, LSAME, IZAMAX, DLAMCH, DZNRM2 * .. * .. External Subroutines .. EXTERNAL XERBLA, ZDSCAL, ZSWAP * .. * .. Intrinsic Functions .. INTRINSIC ABS, DBLE, DIMAG, MAX, MIN * * Test the input parameters * INFO = 0 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND. $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -4 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZGEBAL', -INFO ) RETURN END IF * K = 1 L = N * IF( N.EQ.0 ) $ GO TO 210 * IF( LSAME( JOB, 'N' ) ) THEN DO 10 I = 1, N SCALE( I ) = ONE 10 CONTINUE GO TO 210 END IF * IF( LSAME( JOB, 'S' ) ) $ GO TO 120 * * Permutation to isolate eigenvalues if possible * GO TO 50 * * Row and column exchange. * 20 CONTINUE SCALE( M ) = J IF( J.EQ.M ) $ GO TO 30 * CALL ZSWAP( L, A( 1, J ), 1, A( 1, M ), 1 ) CALL ZSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA ) * 30 CONTINUE GO TO ( 40, 80 )IEXC * * Search for rows isolating an eigenvalue and push them down. * 40 CONTINUE IF( L.EQ.1 ) $ GO TO 210 L = L - 1 * 50 CONTINUE DO 70 J = L, 1, -1 * DO 60 I = 1, L IF( I.EQ.J ) $ GO TO 60 IF( DBLE( A( J, I ) ).NE.ZERO .OR. DIMAG( A( J, I ) ).NE. $ ZERO )GO TO 70 60 CONTINUE * M = L IEXC = 1 GO TO 20 70 CONTINUE * GO TO 90 * * Search for columns isolating an eigenvalue and push them left. * 80 CONTINUE K = K + 1 * 90 CONTINUE DO 110 J = K, L * DO 100 I = K, L IF( I.EQ.J ) $ GO TO 100 IF( DBLE( A( I, J ) ).NE.ZERO .OR. DIMAG( A( I, J ) ).NE. $ ZERO )GO TO 110 100 CONTINUE * M = K IEXC = 2 GO TO 20 110 CONTINUE * 120 CONTINUE DO 130 I = K, L SCALE( I ) = ONE 130 CONTINUE * IF( LSAME( JOB, 'P' ) ) $ GO TO 210 * * Balance the submatrix in rows K to L. * * Iterative loop for norm reduction * SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' ) SFMAX1 = ONE / SFMIN1 SFMIN2 = SFMIN1*SCLFAC SFMAX2 = ONE / SFMIN2 140 CONTINUE NOCONV = .FALSE. * DO 200 I = K, L * C = DZNRM2( L-K+1, A( K, I ), 1 ) R = DZNRM2( L-K+1, A( I, K ), LDA ) ICA = IZAMAX( L, A( 1, I ), 1 ) CA = ABS( A( ICA, I ) ) IRA = IZAMAX( N-K+1, A( I, K ), LDA ) RA = ABS( A( I, IRA+K-1 ) ) * * Guard against zero C or R due to underflow. * IF( C.EQ.ZERO .OR. R.EQ.ZERO ) $ GO TO 200 G = R / SCLFAC F = ONE S = C + R 160 CONTINUE IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR. $ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170 IF( DISNAN( C+F+CA+R+G+RA ) ) THEN * * Exit if NaN to avoid infinite loop * INFO = -3 CALL XERBLA( 'ZGEBAL', -INFO ) RETURN END IF F = F*SCLFAC C = C*SCLFAC CA = CA*SCLFAC R = R / SCLFAC G = G / SCLFAC RA = RA / SCLFAC GO TO 160 * 170 CONTINUE G = C / SCLFAC 180 CONTINUE IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR. $ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190 F = F / SCLFAC C = C / SCLFAC G = G / SCLFAC CA = CA / SCLFAC R = R*SCLFAC RA = RA*SCLFAC GO TO 180 * * Now balance. * 190 CONTINUE IF( ( C+R ).GE.FACTOR*S ) $ GO TO 200 IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN IF( F*SCALE( I ).LE.SFMIN1 ) $ GO TO 200 END IF IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN IF( SCALE( I ).GE.SFMAX1 / F ) $ GO TO 200 END IF G = ONE / F SCALE( I ) = SCALE( I )*F NOCONV = .TRUE. * CALL ZDSCAL( N-K+1, G, A( I, K ), LDA ) CALL ZDSCAL( L, F, A( 1, I ), 1 ) * 200 CONTINUE * IF( NOCONV ) $ GO TO 140 * 210 CONTINUE ILO = K IHI = L * RETURN * * End of ZGEBAL * END
bsd-3-clause
apollos/Quantum-ESPRESSO
lapack-3.2/INSTALL/dlamchtst.f
2
1523
PROGRAM TEST3 * * -- LAPACK test routine (version 3.2) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2006 * * .. Local Scalars .. DOUBLE PRECISION BASE, EMAX, EMIN, EPS, PREC, RMAX, RMIN, RND, $ SFMIN, T * .. * .. External Functions .. DOUBLE PRECISION DLAMCH EXTERNAL DLAMCH * .. * .. Executable Statements .. * EPS = DLAMCH( 'Epsilon' ) SFMIN = DLAMCH( 'Safe minimum' ) BASE = DLAMCH( 'Base' ) PREC = DLAMCH( 'Precision' ) T = DLAMCH( 'Number of digits in mantissa' ) RND = DLAMCH( 'Rounding mode' ) EMIN = DLAMCH( 'Minimum exponent' ) RMIN = DLAMCH( 'Underflow threshold' ) EMAX = DLAMCH( 'Largest exponent' ) RMAX = DLAMCH( 'Overflow threshold' ) * WRITE( 6, * )' Epsilon = ', EPS WRITE( 6, * )' Safe minimum = ', SFMIN WRITE( 6, * )' Base = ', BASE WRITE( 6, * )' Precision = ', PREC WRITE( 6, * )' Number of digits in mantissa = ', T WRITE( 6, * )' Rounding mode = ', RND WRITE( 6, * )' Minimum exponent = ', EMIN WRITE( 6, * )' Underflow threshold = ', RMIN WRITE( 6, * )' Largest exponent = ', EMAX WRITE( 6, * )' Overflow threshold = ', RMAX WRITE( 6, * )' Reciprocal of safe minimum = ', 1 / SFMIN * END
gpl-2.0
apollos/Quantum-ESPRESSO
lapack-3.2/SRC/zptsv.f
1
3168
SUBROUTINE ZPTSV( N, NRHS, D, E, B, LDB, INFO ) * * -- LAPACK routine (version 3.2) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2006 * * .. Scalar Arguments .. INTEGER INFO, LDB, N, NRHS * .. * .. Array Arguments .. DOUBLE PRECISION D( * ) COMPLEX*16 B( LDB, * ), E( * ) * .. * * Purpose * ======= * * ZPTSV computes the solution to a complex system of linear equations * A*X = B, where A is an N-by-N Hermitian positive definite tridiagonal * matrix, and X and B are N-by-NRHS matrices. * * A is factored as A = L*D*L**H, and the factored form of A is then * used to solve the system of equations. * * Arguments * ========= * * N (input) INTEGER * The order of the matrix A. N >= 0. * * NRHS (input) INTEGER * The number of right hand sides, i.e., the number of columns * of the matrix B. NRHS >= 0. * * D (input/output) DOUBLE PRECISION array, dimension (N) * On entry, the n diagonal elements of the tridiagonal matrix * A. On exit, the n diagonal elements of the diagonal matrix * D from the factorization A = L*D*L**H. * * E (input/output) COMPLEX*16 array, dimension (N-1) * On entry, the (n-1) subdiagonal elements of the tridiagonal * matrix A. On exit, the (n-1) subdiagonal elements of the * unit bidiagonal factor L from the L*D*L**H factorization of * A. E can also be regarded as the superdiagonal of the unit * bidiagonal factor U from the U**H*D*U factorization of A. * * B (input/output) COMPLEX*16 array, dimension (LDB,N) * On entry, the N-by-NRHS right hand side matrix B. * On exit, if INFO = 0, the N-by-NRHS solution matrix X. * * LDB (input) INTEGER * The leading dimension of the array B. LDB >= max(1,N). * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value * > 0: if INFO = i, the leading minor of order i is not * positive definite, and the solution has not been * computed. The factorization has not been completed * unless i = N. * * ===================================================================== * * .. External Subroutines .. EXTERNAL XERBLA, ZPTTRF, ZPTTRS * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IF( N.LT.0 ) THEN INFO = -1 ELSE IF( NRHS.LT.0 ) THEN INFO = -2 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -6 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZPTSV ', -INFO ) RETURN END IF * * Compute the L*D*L' (or U'*D*U) factorization of A. * CALL ZPTTRF( N, D, E, INFO ) IF( INFO.EQ.0 ) THEN * * Solve the system A*X = B, overwriting B with X. * CALL ZPTTRS( 'Lower', N, NRHS, D, E, B, LDB, INFO ) END IF RETURN * * End of ZPTSV * END
gpl-2.0
rmcgibbo/scipy
scipy/linalg/src/id_dist/src/idz_sfft.f
139
5011
c this file contains the following user-callable routines: c c c routine idz_sffti initializes routine idz_sfft. c c routine idz_sfft rapidly computes a subset of the entries c of the DFT of a vector, composed with permutation matrices c both on input and on output. c c routine idz_ldiv finds the greatest integer less than or equal c to a specified integer, that is divisible by another (larger) c specified integer. c c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c c c subroutine idz_ldiv(l,n,m) c c finds the greatest integer less than or equal to l c that divides n. c c input: c l -- integer at least as great as m c n -- integer divisible by m c c output: c m -- greatest integer less than or equal to l that divides n c implicit none integer n,l,m c c m = l c 1000 continue if(m*(n/m) .eq. n) goto 2000 c m = m-1 goto 1000 c 2000 continue c c return end c c c c subroutine idz_sffti(l,ind,n,wsave) c c initializes wsave for use with routine idz_sfft. c c input: c l -- number of entries in the output of idz_sfft to compute c ind -- indices of the entries in the output of idz_sfft c to compute c n -- length of the vector to be transformed c c output: c wsave -- array needed by routine idz_sfft for processing c implicit none integer l,ind(l),n,nblock,ii,m,idivm,imodm,i,j,k real*8 r1,twopi,fact complex*16 wsave(2*l+15+3*n),ci,twopii c ci = (0,1) r1 = 1 twopi = 2*4*atan(r1) twopii = twopi*ci c c c Determine the block lengths for the FFTs. c call idz_ldiv(l,n,nblock) m = n/nblock c c c Initialize wsave for use with routine zfftf. c call zffti(nblock,wsave) c c c Calculate the coefficients in the linear combinations c needed for the direct portion of the calculation. c fact = 1/sqrt(r1*n) c ii = 2*l+15 c do j = 1,l c i = ind(j) c idivm = (i-1)/m imodm = (i-1)-m*idivm c do k = 1,m wsave(ii+m*(j-1)+k) = exp(-twopii*imodm*(k-1)/(r1*m)) 1 * exp(-twopii*(k-1)*idivm/(r1*n)) * fact enddo ! k c enddo ! j c c return end c c c c subroutine idz_sfft(l,ind,n,wsave,v) c c computes a subset of the entries of the DFT of v, c composed with permutation matrices both on input and on output, c via a two-stage procedure (routine zfftf2 is supposed c to calculate the full vector from which idz_sfft returns c a subset of the entries, when zfftf2 has the same parameter c nblock as in the present routine). c c input: c l -- number of entries in the output to compute c ind -- indices of the entries of the output to compute c n -- length of v c v -- vector to be transformed c wsave -- processing array initialized by routine idz_sffti c c output: c v -- entries indexed by ind are given their appropriate c transformed values c c _N.B._: The user has to boost the memory allocations c for wsave (and change iii accordingly) if s/he wishes c to use strange sizes of n; it's best to stick to powers c of 2. c c references: c Sorensen and Burrus, "Efficient computation of the DFT with c only a subset of input or output points," c IEEE Transactions on Signal Processing, 41 (3): 1184-1200, c 1993. c Woolfe, Liberty, Rokhlin, Tygert, "A fast randomized algorithm c for the approximation of matrices," Applied and c Computational Harmonic Analysis, 25 (3): 335-366, 2008; c Section 3.3. c implicit none integer n,m,l,k,j,ind(l),i,idivm,nblock,ii,iii real*8 r1,twopi complex*16 v(n),wsave(2*l+15+3*n),ci,sum c ci = (0,1) r1 = 1 twopi = 2*4*atan(r1) c c c Determine the block lengths for the FFTs. c call idz_ldiv(l,n,nblock) c c m = n/nblock c c c FFT each block of length nblock of v. c do k = 1,m call zfftf(nblock,v(nblock*(k-1)+1),wsave) enddo ! k c c c Transpose v to obtain wsave(2*l+15+2*n+1 : 2*l+15+3*n). c iii = 2*l+15+2*n c do k = 1,m do j = 1,nblock wsave(iii+m*(j-1)+k) = v(nblock*(k-1)+j) enddo ! j enddo ! k c c c Directly calculate the desired entries of v. c ii = 2*l+15 iii = 2*l+15+2*n c do j = 1,l c i = ind(j) c idivm = (i-1)/m c sum = 0 c do k = 1,m sum = sum + wsave(ii+m*(j-1)+k) * wsave(iii+m*idivm+k) enddo ! k c v(i) = sum c enddo ! j c c return end
bsd-3-clause
kolawoletech/ce-espresso
upftools/casino_pp.f90
2
17242
MODULE casino_pp ! ! All variables read from CASINO file format ! ! trailing underscore means that a variable with the same name ! is used in module 'upf' containing variables to be written ! USE kinds, ONLY : dp CHARACTER(len=20) :: dft_ CHARACTER(len=2) :: psd_ REAL(dp) :: zp_ INTEGER nlc, nnl, lmax_, lloc, nchi, rel_ LOGICAL :: numeric, bhstype, nlcc_ CHARACTER(len=2), ALLOCATABLE :: els_(:) REAL(dp) :: zmesh REAL(dp) :: xmin = -7.0_dp REAL(dp) :: dx = 20.0_dp/1500.0_dp REAL(dp) :: tn_prefac = 0.75E-6_dp LOGICAL :: tn_grid = .true. REAL(dp), ALLOCATABLE:: r_(:) INTEGER :: mesh_ REAL(dp), ALLOCATABLE:: vnl(:,:) INTEGER, ALLOCATABLE:: lchi_(:), nns_(:) REAL(dp), ALLOCATABLE:: chi_(:,:), oc_(:) CONTAINS ! ! ---------------------------------------------------------- SUBROUTINE read_casino(iunps,nofiles, waveunit) ! ---------------------------------------------------------- ! ! Reads in a CASINO tabulated pp file and it's associated ! awfn files. Some basic processing such as removing the ! r factors from the potentials is also performed. USE kinds, ONLY : dp IMPLICIT NONE TYPE :: wavfun_list INTEGER :: occ,eup,edwn, nquant, lquant CHARACTER(len=2) :: label #ifdef __STD_F95 REAL(dp), POINTER :: wavefunc(:) #else REAL(dp), ALLOCATABLE :: wavefunc(:) #endif TYPE (wavfun_list), POINTER :: p END TYPE wavfun_list TYPE :: channel_list INTEGER :: lquant #ifdef __STD_F95 REAL(dp), POINTER :: channel(:) #else REAL(dp), ALLOCATABLE :: channel(:) #endif TYPE (channel_list), POINTER :: p END TYPE channel_list TYPE (channel_list), POINTER :: phead TYPE (channel_list), POINTER :: pptr TYPE (channel_list), POINTER :: ptail TYPE (wavfun_list), POINTER :: mhead TYPE (wavfun_list), POINTER :: mptr TYPE (wavfun_list), POINTER :: mtail INTEGER :: iunps, nofiles, ios ! LOGICAL :: groundstate, found CHARACTER(len=2) :: label, rellab INTEGER :: l, i, ir, nb, gsorbs, j,k,m,tmp, lquant, orbs, nquant INTEGER, ALLOCATABLE :: gs(:,:) INTEGER, INTENT(in) :: waveunit(nofiles) NULLIFY ( mhead, mptr, mtail ) dft_ = 'HF' !Hardcoded at the moment should eventually be HF anyway nlc = 0 !These two values are always 0 for numeric pps nnl = 0 !so lets just hard code them nlcc_ = .false. !Again these two are alwas false for CASINO pps bhstype = .false. READ(iunps,'(a2,35x,a2)') rellab, psd_ READ(iunps,*) IF ( rellab == 'DF' ) THEN rel_=1 ELSE rel_=0 ENDIF READ(iunps,*) zmesh,zp_ !Here we are reading zmesh (atomic #) and DO i=1,3 !zp_ (pseudo charge) READ(iunps,*) ENDDO READ(iunps,*) lloc !reading in lloc IF ( zp_<=0d0 ) & CALL errore( 'read_casino','Wrong zp ',1 ) IF ( lloc>3.or.lloc<0 ) & CALL errore( 'read_casino','Wrong lloc ',1 ) ! ! compute the radial mesh ! DO i=1,3 READ(iunps,*) ENDDO READ(iunps,*) mesh_ !Reading in total no. of mesh points ALLOCATE( r_(mesh_)) READ(iunps,*) DO i=1,mesh_ READ(iunps,*) r_(i) ENDDO ! Read in the different channels of V_nl ALLOCATE(phead) ptail => phead pptr => phead ALLOCATE( pptr%channel(mesh_) ) READ(iunps, '(15x,I1,7x)') l pptr%lquant=l READ(iunps, *) (pptr%channel(ir),ir=1,mesh_) DO READ(iunps, '(15x,I1,7x)', IOSTAT=ios) l IF (ios /= 0 ) THEN exit ENDIF ALLOCATE(pptr%p) pptr=> pptr%p ptail=> pptr ALLOCATE( pptr%channel(mesh_) ) pptr%lquant=l READ(iunps, *) (pptr%channel(ir),ir=1,mesh_) ENDDO !Compute the number of channels read in. lmax_ =-1 pptr => phead DO IF ( .not. associated(pptr) )exit lmax_=lmax_+1 pptr =>pptr%p ENDDO ALLOCATE(vnl(mesh_,0:lmax_)) i=0 pptr => phead DO IF ( .not. associated(pptr) )exit ! lchi_(i) = pptr%lquant DO ir=1,mesh_ vnl(ir,i) = pptr%channel(ir) ENDDO DEALLOCATE( pptr%channel ) pptr =>pptr%p i=i+1 ENDDO !Clean up the linked list (deallocate it) DO IF ( .not. associated(phead) )exit pptr => phead phead => phead%p DEALLOCATE( pptr ) ENDDO DO l = 0, lmax_ DO ir = 1, mesh_ vnl(ir,l) = vnl(ir,l)/r_(ir) !Removing the factor of r CASINO has ENDDO ! correcting for possible divide by zero IF ( r_(1) == 0 ) THEN vnl(1,l) = 0 ENDIF ENDDO ALLOCATE(mhead) mtail => mhead mptr => mhead NULLIFY(mtail%p) groundstate=.true. DO j=1,nofiles DO i=1,4 READ(waveunit(j),*) ENDDO READ(waveunit(j),*) orbs IF ( groundstate ) THEN ALLOCATE( gs(orbs,3) ) gs = 0 gsorbs = orbs ENDIF DO i=1,2 READ(waveunit(j),*) ENDDO READ(waveunit(j),*) mtail%eup, mtail%edwn READ(waveunit(j),*) DO i=1,mtail%eup+mtail%edwn READ(waveunit(j),*) tmp, nquant, lquant IF ( groundstate ) THEN found = .true. DO m=1,orbs IF ( (nquant==gs(m,1) .and. lquant==gs(m,2)) ) THEN gs(m,3) = gs(m,3) + 1 exit ENDIF found = .false. ENDDO IF (.not. found ) THEN DO m=1,orbs IF ( gs(m,1) == 0 ) THEN gs(m,1) = nquant gs(m,2) = lquant gs(m,3) = 1 exit ENDIF ENDDO ENDIF ENDIF ENDDO READ(waveunit(j),*) READ(waveunit(j),*) DO i=1,mesh_ READ(waveunit(j),*) ENDDO DO k=1,orbs READ(waveunit(j),'(13x,a2)', err=300) label READ(waveunit(j),*) tmp, nquant, lquant IF ( .not. groundstate ) THEN found = .false. DO m = 1,gsorbs IF ( nquant == gs(m,1) .and. lquant == gs(m,2) ) THEN found = .true. exit ENDIF ENDDO mptr => mhead DO IF ( .not. associated(mptr) )exit IF ( nquant == mptr%nquant .and. lquant == mptr%lquant ) found = .true. mptr =>mptr%p ENDDO IF ( found ) THEN DO i=1,mesh_ READ(waveunit(j),*) ENDDO CYCLE ENDIF ENDIF #ifdef __STD_F95 IF ( associated(mtail%wavefunc) ) THEN #else IF ( allocated(mtail%wavefunc) ) THEN #endif ALLOCATE(mtail%p) mtail=>mtail%p NULLIFY(mtail%p) ALLOCATE( mtail%wavefunc(mesh_) ) ELSE ALLOCATE( mtail%wavefunc(mesh_) ) ENDIF mtail%label = label mtail%nquant = nquant mtail%lquant = lquant READ(waveunit(j), *, err=300) (mtail%wavefunc(ir),ir=1,mesh_) ENDDO groundstate = .false. ENDDO nchi =0 mptr => mhead DO IF ( .not. associated(mptr) )exit nchi=nchi+1 mptr =>mptr%p ENDDO ALLOCATE(lchi_(nchi), els_(nchi), nns_(nchi)) ALLOCATE(oc_(nchi)) ALLOCATE(chi_(mesh_,nchi)) oc_ = 0 !Sort out the occupation numbers DO i=1,gsorbs oc_(i)=gs(i,3) ENDDO DEALLOCATE( gs ) i=1 mptr => mhead DO IF ( .not. associated(mptr) )exit nns_(i) = mptr%nquant lchi_(i) = mptr%lquant els_(i) = mptr%label DO ir=1,mesh_ chi_(ir:,i) = mptr%wavefunc(ir) ENDDO DEALLOCATE( mptr%wavefunc ) mptr =>mptr%p i=i+1 ENDDO !Clean up the linked list (deallocate it) DO IF ( .not. associated(mhead) )exit mptr => mhead mhead => mhead%p DEALLOCATE( mptr ) ENDDO ! ---------------------------------------------------------- WRITE (0,'(a)') 'Pseudopotential successfully read' ! ---------------------------------------------------------- RETURN 300 CALL errore('read_casino','pseudo file is empty or wrong',1) END SUBROUTINE read_casino ! ---------------------------------------------------------- SUBROUTINE convert_casino(upf_out) ! ---------------------------------------------------------- USE kinds, ONLY : dp USE upf_module USE radial_grids, ONLY: radial_grid_type, deallocate_radial_grid USE funct, ONLY : set_dft_from_name, get_iexch, get_icorr, & get_igcx, get_igcc IMPLICIT NONE TYPE(pseudo_upf), INTENT(inout) :: upf_out REAL(dp), ALLOCATABLE :: aux(:) REAL(dp) :: vll INTEGER :: kkbeta, l, iv, ir, i, nb WRITE(upf_out%generated, '("From a Trail & Needs tabulated & &PP for CASINO")') WRITE(upf_out%author,'("unknown")') WRITE(upf_out%date,'("unknown")') upf_out%comment = 'Info: automatically converted from CASINO & &Tabulated format' IF (rel_== 0) THEN upf_out%rel = 'no' ELSEIF (rel_==1 ) THEN upf_out%rel = 'scalar' ELSE upf_out%rel = 'full' ENDIF IF (xmin == 0 ) THEN xmin= log(zmesh * r_(2) ) ENDIF ! Allocate and assign the raidal grid upf_out%mesh = mesh_ upf_out%zmesh = zmesh upf_out%dx = dx upf_out%xmin = xmin ALLOCATE(upf_out%rab(upf_out%mesh)) ALLOCATE( upf_out%r(upf_out%mesh)) upf_out%r = r_ DEALLOCATE( r_ ) upf_out%rmax = maxval(upf_out%r) ! ! subtract out the local part from the different ! potential channels ! DO l = 0, lmax_ IF ( l/=lloc ) vnl(:,l) = vnl(:,l) - vnl(:,lloc) ENDDO ALLOCATE (upf_out%vloc(upf_out%mesh)) upf_out%vloc(:) = vnl(:,lloc) ! Compute the derivatives of the grid. The Trail and Needs ! grids use r(i) = (tn_prefac / zmesh)*( exp(i*dx) - 1 ) so ! must be treated differently to standard QE grids. IF ( tn_grid ) THEN DO ir = 1, upf_out%mesh upf_out%rab(ir) = dx * ( upf_out%r(ir) + tn_prefac / zmesh ) ENDDO ELSE DO ir = 1, upf_out%mesh upf_out%rab(ir) = dx * upf_out%r(ir) ENDDO ENDIF ! ! compute the atomic charges ! ALLOCATE (upf_out%rho_at(upf_out%mesh)) upf_out%rho_at(:) = 0.d0 DO nb = 1, nchi IF( oc_(nb)/=0.d0) THEN upf_out%rho_at(:) = upf_out%rho_at(:) +& & oc_(nb)*chi_(:,nb)**2 ENDIF ENDDO ! This section deals with the pseudo wavefunctions. ! These values are just given directly to the pseudo_upf structure upf_out%nwfc = nchi ALLOCATE( upf_out%oc(upf_out%nwfc), upf_out%epseu(upf_out%nwfc) ) ALLOCATE( upf_out%lchi(upf_out%nwfc), upf_out%nchi(upf_out%nwfc) ) ALLOCATE( upf_out%els(upf_out%nwfc) ) ALLOCATE( upf_out%rcut_chi(upf_out%nwfc) ) ALLOCATE( upf_out%rcutus_chi (upf_out%nwfc) ) DO i=1, upf_out%nwfc upf_out%nchi(i) = nns_(i) upf_out%lchi(i) = lchi_(i) upf_out%rcut_chi(i) = 0.0d0 upf_out%rcutus_chi(i)= 0.0d0 upf_out%oc (i) = oc_(i) upf_out%els(i) = els_(i) upf_out%epseu(i) = 0.0d0 ENDDO DEALLOCATE (lchi_, oc_, nns_) upf_out%psd = psd_ upf_out%typ = 'NC' upf_out%nlcc = nlcc_ upf_out%zp = zp_ upf_out%etotps = 0.0d0 upf_out%ecutrho=0.0d0 upf_out%ecutwfc=0.0d0 upf_out%lloc=lloc IF ( lmax_ == lloc) THEN upf_out%lmax = lmax_-1 ELSE upf_out%lmax = lmax_ ENDIF upf_out%nbeta = lmax_ ALLOCATE ( upf_out%els_beta(upf_out%nbeta) ) ALLOCATE ( upf_out%rcut(upf_out%nbeta) ) ALLOCATE ( upf_out%rcutus(upf_out%nbeta) ) upf_out%rcut=0.0d0 upf_out%rcutus=0.0d0 upf_out%dft =dft_ IF (upf_out%nbeta > 0) THEN ALLOCATE(upf_out%kbeta(upf_out%nbeta), upf_out%lll(upf_out%nbeta)) upf_out%kkbeta=upf_out%mesh DO ir = 1,upf_out%mesh IF ( upf_out%r(ir) > upf_out%rmax ) THEN upf_out%kkbeta=ir exit ENDIF ENDDO ! make sure kkbeta is odd as required for simpson IF(mod(upf_out%kkbeta,2) == 0) upf_out%kkbeta=upf_out%kkbeta-1 upf_out%kbeta(:) = upf_out%kkbeta ALLOCATE(aux(upf_out%kkbeta)) ALLOCATE(upf_out%beta(upf_out%mesh,upf_out%nbeta)) ALLOCATE(upf_out%dion(upf_out%nbeta,upf_out%nbeta)) upf_out%dion(:,:) =0.d0 iv=0 DO i=1,upf_out%nwfc l=upf_out%lchi(i) IF (l/=upf_out%lloc) THEN iv=iv+1 upf_out%els_beta(iv)=upf_out%els(i) upf_out%lll(iv)=l DO ir=1,upf_out%kkbeta upf_out%beta(ir,iv)=chi_(ir,i)*vnl(ir,l) aux(ir) = chi_(ir,i)**2*vnl(ir,l) ENDDO CALL simpson(upf_out%kkbeta,aux,upf_out%rab,vll) upf_out%dion(iv,iv) = 1.0d0/vll ENDIF IF(iv >= upf_out%nbeta) exit ! skip additional pseudo wfns ENDDO DEALLOCATE (vnl, aux) ! ! redetermine ikk2 ! DO iv=1,upf_out%nbeta upf_out%kbeta(iv)=upf_out%kkbeta DO ir = upf_out%kkbeta,1,-1 IF ( abs(upf_out%beta(ir,iv)) > 1.d-12 ) THEN upf_out%kbeta(iv)=ir exit ENDIF ENDDO ENDDO ENDIF ALLOCATE (upf_out%chi(upf_out%mesh,upf_out%nwfc)) upf_out%chi = chi_ DEALLOCATE (chi_) RETURN END SUBROUTINE convert_casino SUBROUTINE write_casino_tab(upf_in, grid) USE upf_module USE radial_grids, ONLY: radial_grid_type, deallocate_radial_grid IMPLICIT NONE TYPE(pseudo_upf), INTENT(in) :: upf_in TYPE(radial_grid_type), INTENT(in) :: grid INTEGER :: i, lp1 INTEGER, EXTERNAL :: atomic_number WRITE(6,*) "Converted Pseudopotential in REAL space for ", upf_in%psd WRITE(6,*) "Atomic number and pseudo-charge" WRITE(6,"(I3,F8.2)") atomic_number( upf_in%psd ),upf_in%zp WRITE(6,*) "Energy units (rydberg/hartree/ev):" WRITE(6,*) "rydberg" WRITE(6,*) "Angular momentum of local component (0=s,1=p,2=d..)" WRITE(6,"(I2)") upf_in%lloc WRITE(6,*) "NLRULE override (1) VMC/DMC (2) config gen (0 ==> & &input/default VALUE)" WRITE(6,*) "0 0" WRITE(6,*) "Number of grid points" WRITE(6,*) grid%mesh WRITE(6,*) "R(i) in atomic units" WRITE(6, "(T4,E22.15)") grid%r(:) lp1 = size ( vnl, 2 ) DO i=1,lp1 WRITE(6, "(A,I1,A)") 'r*potential (L=',i-1,') in Ry' WRITE(6, "(T4,E22.15)") vnl(:,i) ENDDO END SUBROUTINE write_casino_tab SUBROUTINE conv_upf2casino(upf_in,grid) USE upf_module USE radial_grids, ONLY: radial_grid_type, deallocate_radial_grid IMPLICIT NONE TYPE(pseudo_upf), INTENT(in) :: upf_in TYPE(radial_grid_type), INTENT(in) :: grid INTEGER :: i, l, channels REAL(dp), PARAMETER :: offset=1E-20_dp !This is an offset added to the wavefunctions to !eliminate any divide by zeros that may be caused by !zeroed wavefunction terms. channels=upf_in%nbeta+1 ALLOCATE ( vnl(grid%mesh,channels) ) !Set up the local component of each channel DO i=1,channels vnl(:,i)=grid%r(:)*upf_in%vloc(:) ENDDO DO i=1,upf_in%nbeta l=upf_in%lll(i)+1 !Check if any wfc components have been zeroed !and apply the offset IF they have IF ( minval(abs(upf_in%chi(:,l))) /= 0 ) THEN vnl(:,l)= (upf_in%beta(:,l)/(upf_in%chi(:,l)) & *grid%r(:)) + vnl(:,l) ELSE WRITE(0,"(A,ES10.3,A)") 'Applying ',offset , ' offset to & &wavefunction to avoid divide by zero' vnl(:,l)= (upf_in%beta(:,l)/(upf_in%chi(:,l)+offset) & *grid%r(:)) + vnl(:,l) ENDIF ENDDO END SUBROUTINE conv_upf2casino END MODULE casino_pp
gpl-2.0
apollos/Quantum-ESPRESSO
lapack-3.2/TESTING/MATGEN/clarot.f
6
10109
SUBROUTINE CLAROT( LROWS, LLEFT, LRIGHT, NL, C, S, A, LDA, XLEFT, $ XRIGHT ) * * -- LAPACK auxiliary test routine (version 3.1) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2006 * * .. Scalar Arguments .. LOGICAL LLEFT, LRIGHT, LROWS INTEGER LDA, NL COMPLEX C, S, XLEFT, XRIGHT * .. * .. Array Arguments .. COMPLEX A( * ) * .. * * Purpose * ======= * * CLAROT applies a (Givens) rotation to two adjacent rows or * columns, where one element of the first and/or last column/row * for use on matrices stored in some format other than GE, so * that elements of the matrix may be used or modified for which * no array element is provided. * * One example is a symmetric matrix in SB format (bandwidth=4), for * which UPLO='L': Two adjacent rows will have the format: * * row j: * * * * * . . . . * row j+1: * * * * * . . . . * * '*' indicates elements for which storage is provided, * '.' indicates elements for which no storage is provided, but * are not necessarily zero; their values are determined by * symmetry. ' ' indicates elements which are necessarily zero, * and have no storage provided. * * Those columns which have two '*'s can be handled by SROT. * Those columns which have no '*'s can be ignored, since as long * as the Givens rotations are carefully applied to preserve * symmetry, their values are determined. * Those columns which have one '*' have to be handled separately, * by using separate variables "p" and "q": * * row j: * * * * * p . . . * row j+1: q * * * * * . . . . * * The element p would have to be set correctly, then that column * is rotated, setting p to its new value. The next call to * CLAROT would rotate columns j and j+1, using p, and restore * symmetry. The element q would start out being zero, and be * made non-zero by the rotation. Later, rotations would presumably * be chosen to zero q out. * * Typical Calling Sequences: rotating the i-th and (i+1)-st rows. * ------- ------- --------- * * General dense matrix: * * CALL CLAROT(.TRUE.,.FALSE.,.FALSE., N, C,S, * A(i,1),LDA, DUMMY, DUMMY) * * General banded matrix in GB format: * * j = MAX(1, i-KL ) * NL = MIN( N, i+KU+1 ) + 1-j * CALL CLAROT( .TRUE., i-KL.GE.1, i+KU.LT.N, NL, C,S, * A(KU+i+1-j,j),LDA-1, XLEFT, XRIGHT ) * * [ note that i+1-j is just MIN(i,KL+1) ] * * Symmetric banded matrix in SY format, bandwidth K, * lower triangle only: * * j = MAX(1, i-K ) * NL = MIN( K+1, i ) + 1 * CALL CLAROT( .TRUE., i-K.GE.1, .TRUE., NL, C,S, * A(i,j), LDA, XLEFT, XRIGHT ) * * Same, but upper triangle only: * * NL = MIN( K+1, N-i ) + 1 * CALL CLAROT( .TRUE., .TRUE., i+K.LT.N, NL, C,S, * A(i,i), LDA, XLEFT, XRIGHT ) * * Symmetric banded matrix in SB format, bandwidth K, * lower triangle only: * * [ same as for SY, except:] * . . . . * A(i+1-j,j), LDA-1, XLEFT, XRIGHT ) * * [ note that i+1-j is just MIN(i,K+1) ] * * Same, but upper triangle only: * . . . * A(K+1,i), LDA-1, XLEFT, XRIGHT ) * * Rotating columns is just the transpose of rotating rows, except * for GB and SB: (rotating columns i and i+1) * * GB: * j = MAX(1, i-KU ) * NL = MIN( N, i+KL+1 ) + 1-j * CALL CLAROT( .TRUE., i-KU.GE.1, i+KL.LT.N, NL, C,S, * A(KU+j+1-i,i),LDA-1, XTOP, XBOTTM ) * * [note that KU+j+1-i is just MAX(1,KU+2-i)] * * SB: (upper triangle) * * . . . . . . * A(K+j+1-i,i),LDA-1, XTOP, XBOTTM ) * * SB: (lower triangle) * * . . . . . . * A(1,i),LDA-1, XTOP, XBOTTM ) * * Arguments * ========= * * LROWS - LOGICAL * If .TRUE., then CLAROT will rotate two rows. If .FALSE., * then it will rotate two columns. * Not modified. * * LLEFT - LOGICAL * If .TRUE., then XLEFT will be used instead of the * corresponding element of A for the first element in the * second row (if LROWS=.FALSE.) or column (if LROWS=.TRUE.) * If .FALSE., then the corresponding element of A will be * used. * Not modified. * * LRIGHT - LOGICAL * If .TRUE., then XRIGHT will be used instead of the * corresponding element of A for the last element in the * first row (if LROWS=.FALSE.) or column (if LROWS=.TRUE.) If * .FALSE., then the corresponding element of A will be used. * Not modified. * * NL - INTEGER * The length of the rows (if LROWS=.TRUE.) or columns (if * LROWS=.FALSE.) to be rotated. If XLEFT and/or XRIGHT are * used, the columns/rows they are in should be included in * NL, e.g., if LLEFT = LRIGHT = .TRUE., then NL must be at * least 2. The number of rows/columns to be rotated * exclusive of those involving XLEFT and/or XRIGHT may * not be negative, i.e., NL minus how many of LLEFT and * LRIGHT are .TRUE. must be at least zero; if not, XERBLA * will be called. * Not modified. * * C, S - COMPLEX * Specify the Givens rotation to be applied. If LROWS is * true, then the matrix ( c s ) * ( _ _ ) * (-s c ) is applied from the left; * if false, then the transpose (not conjugated) thereof is * applied from the right. Note that in contrast to the * output of CROTG or to most versions of CROT, both C and S * are complex. For a Givens rotation, |C|**2 + |S|**2 should * be 1, but this is not checked. * Not modified. * * A - COMPLEX array. * The array containing the rows/columns to be rotated. The * first element of A should be the upper left element to * be rotated. * Read and modified. * * LDA - INTEGER * The "effective" leading dimension of A. If A contains * a matrix stored in GE, HE, or SY format, then this is just * the leading dimension of A as dimensioned in the calling * routine. If A contains a matrix stored in band (GB, HB, or * SB) format, then this should be *one less* than the leading * dimension used in the calling routine. Thus, if A were * dimensioned A(LDA,*) in CLAROT, then A(1,j) would be the * j-th element in the first of the two rows to be rotated, * and A(2,j) would be the j-th in the second, regardless of * how the array may be stored in the calling routine. [A * cannot, however, actually be dimensioned thus, since for * band format, the row number may exceed LDA, which is not * legal FORTRAN.] * If LROWS=.TRUE., then LDA must be at least 1, otherwise * it must be at least NL minus the number of .TRUE. values * in XLEFT and XRIGHT. * Not modified. * * XLEFT - COMPLEX * If LLEFT is .TRUE., then XLEFT will be used and modified * instead of A(2,1) (if LROWS=.TRUE.) or A(1,2) * (if LROWS=.FALSE.). * Read and modified. * * XRIGHT - COMPLEX * If LRIGHT is .TRUE., then XRIGHT will be used and modified * instead of A(1,NL) (if LROWS=.TRUE.) or A(NL,1) * (if LROWS=.FALSE.). * Read and modified. * * ===================================================================== * * .. Local Scalars .. INTEGER IINC, INEXT, IX, IY, IYT, J, NT COMPLEX TEMPX * .. * .. Local Arrays .. COMPLEX XT( 2 ), YT( 2 ) * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC CONJG * .. * .. Executable Statements .. * * Set up indices, arrays for ends * IF( LROWS ) THEN IINC = LDA INEXT = 1 ELSE IINC = 1 INEXT = LDA END IF * IF( LLEFT ) THEN NT = 1 IX = 1 + IINC IY = 2 + LDA XT( 1 ) = A( 1 ) YT( 1 ) = XLEFT ELSE NT = 0 IX = 1 IY = 1 + INEXT END IF * IF( LRIGHT ) THEN IYT = 1 + INEXT + ( NL-1 )*IINC NT = NT + 1 XT( NT ) = XRIGHT YT( NT ) = A( IYT ) END IF * * Check for errors * IF( NL.LT.NT ) THEN CALL XERBLA( 'CLAROT', 4 ) RETURN END IF IF( LDA.LE.0 .OR. ( .NOT.LROWS .AND. LDA.LT.NL-NT ) ) THEN CALL XERBLA( 'CLAROT', 8 ) RETURN END IF * * Rotate * * CROT( NL-NT, A(IX),IINC, A(IY),IINC, C, S ) with complex C, S * DO 10 J = 0, NL - NT - 1 TEMPX = C*A( IX+J*IINC ) + S*A( IY+J*IINC ) A( IY+J*IINC ) = -CONJG( S )*A( IX+J*IINC ) + $ CONJG( C )*A( IY+J*IINC ) A( IX+J*IINC ) = TEMPX 10 CONTINUE * * CROT( NT, XT,1, YT,1, C, S ) with complex C, S * DO 20 J = 1, NT TEMPX = C*XT( J ) + S*YT( J ) YT( J ) = -CONJG( S )*XT( J ) + CONJG( C )*YT( J ) XT( J ) = TEMPX 20 CONTINUE * * Stuff values back into XLEFT, XRIGHT, etc. * IF( LLEFT ) THEN A( 1 ) = XT( 1 ) XLEFT = YT( 1 ) END IF * IF( LRIGHT ) THEN XRIGHT = XT( NT ) A( IYT ) = YT( NT ) END IF * RETURN * * End of CLAROT * END
gpl-2.0
sargas/scipy
scipy/interpolate/fitpack/fprppo.f
148
1543
subroutine fprppo(nu,nv,if1,if2,cosi,ratio,c,f,ncoff) c given the coefficients of a constrained bicubic spline, as determined c in subroutine fppola, subroutine fprppo calculates the coefficients c in the standard b-spline representation of bicubic splines. c .. c ..scalar arguments.. real*8 ratio integer nu,nv,if1,if2,ncoff c ..array arguments real*8 c(ncoff),f(ncoff),cosi(5,nv) c ..local scalars.. integer i,iopt,ii,j,k,l,nu4,nvv c .. nu4 = nu-4 nvv = nv-7 iopt = if1+1 do 10 i=1,ncoff f(i) = 0. 10 continue i = 0 do 120 l=1,nu4 ii = i if(l.gt.iopt) go to 80 go to (20,40,60),l 20 do 30 k=1,nvv i = i+1 f(i) = c(1) 30 continue j = 1 go to 100 40 do 50 k=1,nvv i = i+1 f(i) = c(1)+c(2)*cosi(1,k)+c(3)*cosi(2,k) 50 continue j = 3 go to 100 60 do 70 k=1,nvv i = i+1 f(i) = c(1)+ratio*(c(2)*cosi(1,k)+c(3)*cosi(2,k))+ * c(4)*cosi(3,k)+c(5)*cosi(4,k)+c(6)*cosi(5,k) 70 continue j = 6 go to 100 80 if(l.eq.nu4 .and. if2.ne.0) go to 120 do 90 k=1,nvv i = i+1 j = j+1 f(i) = c(j) 90 continue 100 do 110 k=1,3 ii = ii+1 i = i+1 f(i) = f(ii) 110 continue 120 continue do 130 i=1,ncoff c(i) = f(i) 130 continue return end
bsd-3-clause
thewtex/ITK
Modules/ThirdParty/VNL/src/vxl/v3p/netlib/eispack/reduc.f
41
3555
subroutine reduc(nm,n,a,b,dl,ierr) c integer i,j,k,n,i1,j1,nm,nn,ierr double precision a(nm,n),b(nm,n),dl(n) double precision x,y c c this subroutine is a translation of the algol procedure reduc1, c num. math. 11, 99-110(1968) by martin and wilkinson. c handbook for auto. comp., vol.ii-linear algebra, 303-314(1971). c c this subroutine reduces the generalized symmetric eigenproblem c ax=(lambda)bx, where b is positive definite, to the standard c symmetric eigenproblem using the cholesky factorization of b. c c on input c c nm must be set to the row dimension of two-dimensional c array parameters as declared in the calling program c dimension statement. c c n is the order of the matrices a and b. if the cholesky c factor l of b is already available, n should be prefixed c with a minus sign. c c a and b contain the real symmetric input matrices. only the c full upper triangles of the matrices need be supplied. if c n is negative, the strict lower triangle of b contains, c instead, the strict lower triangle of its cholesky factor l. c c dl contains, if n is negative, the diagonal elements of l. c c on output c c a contains in its full lower triangle the full lower triangle c of the symmetric matrix derived from the reduction to the c standard form. the strict upper triangle of a is unaltered. c c b contains in its strict lower triangle the strict lower c triangle of its cholesky factor l. the full upper c triangle of b is unaltered. c c dl contains the diagonal elements of l. c c ierr is set to c zero for normal return, c 7*n+1 if b is not positive definite. c c questions and comments should be directed to burton s. garbow, c mathematics and computer science div, argonne national laboratory c c this version dated august 1983. c c ------------------------------------------------------------------ c ierr = 0 nn = iabs(n) if (n .lt. 0) go to 100 c .......... form l in the arrays b and dl .......... do 80 i = 1, n i1 = i - 1 c do 80 j = i, n x = b(i,j) if (i .eq. 1) go to 40 c do 20 k = 1, i1 20 x = x - b(i,k) * b(j,k) c 40 if (j .ne. i) go to 60 if (x .le. 0.0d0) go to 1000 y = dsqrt(x) dl(i) = y go to 80 60 b(j,i) = x / y 80 continue c .......... form the transpose of the upper triangle of inv(l)*a c in the lower triangle of the array a .......... 100 do 200 i = 1, nn i1 = i - 1 y = dl(i) c do 200 j = i, nn x = a(i,j) if (i .eq. 1) go to 180 c do 160 k = 1, i1 160 x = x - b(i,k) * a(j,k) c 180 a(j,i) = x / y 200 continue c .......... pre-multiply by inv(l) and overwrite .......... do 300 j = 1, nn j1 = j - 1 c do 300 i = j, nn x = a(i,j) if (i .eq. j) go to 240 i1 = i - 1 c do 220 k = j, i1 220 x = x - a(k,j) * b(i,k) c 240 if (j .eq. 1) go to 280 c do 260 k = 1, j1 260 x = x - a(j,k) * b(i,k) c 280 a(i,j) = x / dl(i) 300 continue c go to 1001 c .......... set error -- b is not positive definite .......... 1000 ierr = 7 * n + 1 1001 return end
apache-2.0
apollos/Quantum-ESPRESSO
PHonon/PH/addusdbec.f90
5
3393
! ! Copyright (C) 2001-2008 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !---------------------------------------------------------------------- subroutine addusdbec (ik, wgt, psi, dbecsum) !---------------------------------------------------------------------- ! ! This routine adds to dbecsum the contribution of this ! k point. It implements Eq. B15 of PRB 64, 235118 (2001). ! USE kinds, only : DP USE ions_base, ONLY : nat, ityp, ntyp => nsp USE becmod, ONLY : calbec USE wvfct, only: npw, npwx, nbnd USE uspp, only: nkb, vkb, okvan, ijtoh USE uspp_param, only: upf, nh, nhm USE phus, ONLY : becp1 USE qpoint, ONLY : npwq, ikks USE control_ph, ONLY : nbnd_occ ! USE mp_bands, ONLY : intra_bgrp_comm ! implicit none ! ! the dummy variables ! complex(DP) :: dbecsum (nhm*(nhm+1)/2, nat), psi(npwx,nbnd) ! inp/out: the sum kv of bec * ! input : contains delta psi integer :: ik ! input: the k point real(DP) :: wgt ! input: the weight of this k point ! ! here the local variables ! integer :: na, nt, ih, jh, ibnd, ikk, ikb, jkb, ijh, startb, & lastb, ijkb0 ! counter on atoms ! counter on atomic type ! counter on solid beta functions ! counter on solid beta functions ! counter on the bands ! the real k point ! counter on solid becp ! counter on solid becp ! composite index for dbecsum ! divide among processors the sum ! auxiliary variable for counting complex(DP), allocatable :: dbecq (:,:) ! the change of becq if (.not.okvan) return call start_clock ('addusdbec') allocate (dbecq( nkb, nbnd)) ikk = ikks(ik) ! ! First compute the product of psi and vkb ! call calbec (npwq, vkb, psi, dbecq) ! ! And then we add the product to becsum ! ! Band parallelization: each processor takes care of its slice of bands ! call divide (intra_bgrp_comm, nbnd_occ (ikk), startb, lastb) ! ijkb0 = 0 do nt = 1, ntyp if (upf(nt)%tvanp ) then do na = 1, nat if (ityp (na) .eq.nt) then ! ! And qgmq and becp and dbecq ! do ih = 1, nh(nt) ikb = ijkb0 + ih ijh=ijtoh(ih,ih,nt) do ibnd = startb, lastb dbecsum (ijh, na) = dbecsum (ijh, na) + & wgt * ( CONJG(becp1(ik)%k(ikb,ibnd)) * dbecq(ikb,ibnd) ) enddo do jh = ih + 1, nh (nt) ijh=ijtoh(ih,jh,nt) jkb = ijkb0 + jh do ibnd = startb, lastb dbecsum (ijh, na) = dbecsum (ijh, na) + & wgt*( CONJG(becp1(ik)%k(ikb,ibnd))*dbecq(jkb,ibnd) + & CONJG(becp1(ik)%k(jkb,ibnd))*dbecq(ikb,ibnd) ) enddo ijh = ijh + 1 enddo enddo ijkb0 = ijkb0 + nh (nt) endif enddo else do na = 1, nat if (ityp (na) .eq.nt) ijkb0 = ijkb0 + nh (nt) enddo endif enddo ! deallocate (dbecq) call stop_clock ('addusdbec') return end subroutine addusdbec
gpl-2.0
xianyi/OpenBLAS
lapack-netlib/SRC/dlasv2.f
4
8428
*> \brief \b DLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DLASV2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasv2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasv2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasv2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL ) * * .. Scalar Arguments .. * DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLASV2 computes the singular value decomposition of a 2-by-2 *> triangular matrix *> [ F G ] *> [ 0 H ]. *> On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the *> smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and *> right singular vectors for abs(SSMAX), giving the decomposition *> *> [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ] *> [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ]. *> \endverbatim * * Arguments: * ========== * *> \param[in] F *> \verbatim *> F is DOUBLE PRECISION *> The (1,1) element of the 2-by-2 matrix. *> \endverbatim *> *> \param[in] G *> \verbatim *> G is DOUBLE PRECISION *> The (1,2) element of the 2-by-2 matrix. *> \endverbatim *> *> \param[in] H *> \verbatim *> H is DOUBLE PRECISION *> The (2,2) element of the 2-by-2 matrix. *> \endverbatim *> *> \param[out] SSMIN *> \verbatim *> SSMIN is DOUBLE PRECISION *> abs(SSMIN) is the smaller singular value. *> \endverbatim *> *> \param[out] SSMAX *> \verbatim *> SSMAX is DOUBLE PRECISION *> abs(SSMAX) is the larger singular value. *> \endverbatim *> *> \param[out] SNL *> \verbatim *> SNL is DOUBLE PRECISION *> \endverbatim *> *> \param[out] CSL *> \verbatim *> CSL is DOUBLE PRECISION *> The vector (CSL, SNL) is a unit left singular vector for the *> singular value abs(SSMAX). *> \endverbatim *> *> \param[out] SNR *> \verbatim *> SNR is DOUBLE PRECISION *> \endverbatim *> *> \param[out] CSR *> \verbatim *> CSR is DOUBLE PRECISION *> The vector (CSR, SNR) is a unit right singular vector for the *> singular value abs(SSMAX). *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup OTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> Any input parameter may be aliased with any output parameter. *> *> Barring over/underflow and assuming a guard digit in subtraction, all *> output quantities are correct to within a few units in the last *> place (ulps). *> *> In IEEE arithmetic, the code works correctly if one matrix element is *> infinite. *> *> Overflow will not occur unless the largest singular value itself *> overflows or is within a few ulps of overflow. (On machines with *> partial overflow, like the Cray, overflow may occur if the largest *> singular value is within a factor of 2 of overflow.) *> *> Underflow is harmless if underflow is gradual. Otherwise, results *> may correspond to a matrix modified by perturbations of size near *> the underflow threshold. *> \endverbatim *> * ===================================================================== SUBROUTINE DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL ) * * -- LAPACK auxiliary routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D0 ) DOUBLE PRECISION HALF PARAMETER ( HALF = 0.5D0 ) DOUBLE PRECISION ONE PARAMETER ( ONE = 1.0D0 ) DOUBLE PRECISION TWO PARAMETER ( TWO = 2.0D0 ) DOUBLE PRECISION FOUR PARAMETER ( FOUR = 4.0D0 ) * .. * .. Local Scalars .. LOGICAL GASMAL, SWAP INTEGER PMAX DOUBLE PRECISION A, CLT, CRT, D, FA, FT, GA, GT, HA, HT, L, M, $ MM, R, S, SLT, SRT, T, TEMP, TSIGN, TT * .. * .. Intrinsic Functions .. INTRINSIC ABS, SIGN, SQRT * .. * .. External Functions .. DOUBLE PRECISION DLAMCH EXTERNAL DLAMCH * .. * .. Executable Statements .. * FT = F FA = ABS( FT ) HT = H HA = ABS( H ) * * PMAX points to the maximum absolute element of matrix * PMAX = 1 if F largest in absolute values * PMAX = 2 if G largest in absolute values * PMAX = 3 if H largest in absolute values * PMAX = 1 SWAP = ( HA.GT.FA ) IF( SWAP ) THEN PMAX = 3 TEMP = FT FT = HT HT = TEMP TEMP = FA FA = HA HA = TEMP * * Now FA .ge. HA * END IF GT = G GA = ABS( GT ) IF( GA.EQ.ZERO ) THEN * * Diagonal matrix * SSMIN = HA SSMAX = FA CLT = ONE CRT = ONE SLT = ZERO SRT = ZERO ELSE GASMAL = .TRUE. IF( GA.GT.FA ) THEN PMAX = 2 IF( ( FA / GA ).LT.DLAMCH( 'EPS' ) ) THEN * * Case of very large GA * GASMAL = .FALSE. SSMAX = GA IF( HA.GT.ONE ) THEN SSMIN = FA / ( GA / HA ) ELSE SSMIN = ( FA / GA )*HA END IF CLT = ONE SLT = HT / GT SRT = ONE CRT = FT / GT END IF END IF IF( GASMAL ) THEN * * Normal case * D = FA - HA IF( D.EQ.FA ) THEN * * Copes with infinite F or H * L = ONE ELSE L = D / FA END IF * * Note that 0 .le. L .le. 1 * M = GT / FT * * Note that abs(M) .le. 1/macheps * T = TWO - L * * Note that T .ge. 1 * MM = M*M TT = T*T S = SQRT( TT+MM ) * * Note that 1 .le. S .le. 1 + 1/macheps * IF( L.EQ.ZERO ) THEN R = ABS( M ) ELSE R = SQRT( L*L+MM ) END IF * * Note that 0 .le. R .le. 1 + 1/macheps * A = HALF*( S+R ) * * Note that 1 .le. A .le. 1 + abs(M) * SSMIN = HA / A SSMAX = FA*A IF( MM.EQ.ZERO ) THEN * * Note that M is very tiny * IF( L.EQ.ZERO ) THEN T = SIGN( TWO, FT )*SIGN( ONE, GT ) ELSE T = GT / SIGN( D, FT ) + M / T END IF ELSE T = ( M / ( S+T )+M / ( R+L ) )*( ONE+A ) END IF L = SQRT( T*T+FOUR ) CRT = TWO / L SRT = T / L CLT = ( CRT+SRT*M ) / A SLT = ( HT / FT )*SRT / A END IF END IF IF( SWAP ) THEN CSL = SRT SNL = CRT CSR = SLT SNR = CLT ELSE CSL = CLT SNL = SLT CSR = CRT SNR = SRT END IF * * Correct signs of SSMAX and SSMIN * IF( PMAX.EQ.1 ) $ TSIGN = SIGN( ONE, CSR )*SIGN( ONE, CSL )*SIGN( ONE, F ) IF( PMAX.EQ.2 ) $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, CSL )*SIGN( ONE, G ) IF( PMAX.EQ.3 ) $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, SNL )*SIGN( ONE, H ) SSMAX = SIGN( SSMAX, TSIGN ) SSMIN = SIGN( SSMIN, TSIGN*SIGN( ONE, F )*SIGN( ONE, H ) ) RETURN * * End of DLASV2 * END
bsd-3-clause
xianyi/OpenBLAS
lapack-netlib/SRC/dgges3.f
1
22639
*> \brief <b> DGGES3 computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors for GE matrices (blocked algorithm)</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGGES3 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgges3.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgges3.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgges3.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGGES3( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B, LDB, * SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, * LDVSR, WORK, LWORK, BWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER JOBVSL, JOBVSR, SORT * INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM * .. * .. Array Arguments .. * LOGICAL BWORK( * ) * DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ), * $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ), * $ VSR( LDVSR, * ), WORK( * ) * .. * .. Function Arguments .. * LOGICAL SELCTG * EXTERNAL SELCTG * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGGES3 computes for a pair of N-by-N real nonsymmetric matrices (A,B), *> the generalized eigenvalues, the generalized real Schur form (S,T), *> optionally, the left and/or right matrices of Schur vectors (VSL and *> VSR). This gives the generalized Schur factorization *> *> (A,B) = ( (VSL)*S*(VSR)**T, (VSL)*T*(VSR)**T ) *> *> Optionally, it also orders the eigenvalues so that a selected cluster *> of eigenvalues appears in the leading diagonal blocks of the upper *> quasi-triangular matrix S and the upper triangular matrix T.The *> leading columns of VSL and VSR then form an orthonormal basis for the *> corresponding left and right eigenspaces (deflating subspaces). *> *> (If only the generalized eigenvalues are needed, use the driver *> DGGEV instead, which is faster.) *> *> A generalized eigenvalue for a pair of matrices (A,B) is a scalar w *> or a ratio alpha/beta = w, such that A - w*B is singular. It is *> usually represented as the pair (alpha,beta), as there is a *> reasonable interpretation for beta=0 or both being zero. *> *> A pair of matrices (S,T) is in generalized real Schur form if T is *> upper triangular with non-negative diagonal and S is block upper *> triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond *> to real generalized eigenvalues, while 2-by-2 blocks of S will be *> "standardized" by making the corresponding elements of T have the *> form: *> [ a 0 ] *> [ 0 b ] *> *> and the pair of corresponding 2-by-2 blocks in S and T will have a *> complex conjugate pair of generalized eigenvalues. *> *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBVSL *> \verbatim *> JOBVSL is CHARACTER*1 *> = 'N': do not compute the left Schur vectors; *> = 'V': compute the left Schur vectors. *> \endverbatim *> *> \param[in] JOBVSR *> \verbatim *> JOBVSR is CHARACTER*1 *> = 'N': do not compute the right Schur vectors; *> = 'V': compute the right Schur vectors. *> \endverbatim *> *> \param[in] SORT *> \verbatim *> SORT is CHARACTER*1 *> Specifies whether or not to order the eigenvalues on the *> diagonal of the generalized Schur form. *> = 'N': Eigenvalues are not ordered; *> = 'S': Eigenvalues are ordered (see SELCTG); *> \endverbatim *> *> \param[in] SELCTG *> \verbatim *> SELCTG is a LOGICAL FUNCTION of three DOUBLE PRECISION arguments *> SELCTG must be declared EXTERNAL in the calling subroutine. *> If SORT = 'N', SELCTG is not referenced. *> If SORT = 'S', SELCTG is used to select eigenvalues to sort *> to the top left of the Schur form. *> An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if *> SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either *> one of a complex conjugate pair of eigenvalues is selected, *> then both complex eigenvalues are selected. *> *> Note that in the ill-conditioned case, a selected complex *> eigenvalue may no longer satisfy SELCTG(ALPHAR(j),ALPHAI(j), *> BETA(j)) = .TRUE. after ordering. INFO is to be set to N+2 *> in this case. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrices A, B, VSL, and VSR. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA, N) *> On entry, the first of the pair of matrices. *> On exit, A has been overwritten by its generalized Schur *> form S. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of A. LDA >= max(1,N). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is DOUBLE PRECISION array, dimension (LDB, N) *> On entry, the second of the pair of matrices. *> On exit, B has been overwritten by its generalized Schur *> form T. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] SDIM *> \verbatim *> SDIM is INTEGER *> If SORT = 'N', SDIM = 0. *> If SORT = 'S', SDIM = number of eigenvalues (after sorting) *> for which SELCTG is true. (Complex conjugate pairs for which *> SELCTG is true for either eigenvalue count as 2.) *> \endverbatim *> *> \param[out] ALPHAR *> \verbatim *> ALPHAR is DOUBLE PRECISION array, dimension (N) *> \endverbatim *> *> \param[out] ALPHAI *> \verbatim *> ALPHAI is DOUBLE PRECISION array, dimension (N) *> \endverbatim *> *> \param[out] BETA *> \verbatim *> BETA is DOUBLE PRECISION array, dimension (N) *> On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will *> be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i, *> and BETA(j),j=1,...,N are the diagonals of the complex Schur *> form (S,T) that would result if the 2-by-2 diagonal blocks of *> the real Schur form of (A,B) were further reduced to *> triangular form using 2-by-2 complex unitary transformations. *> If ALPHAI(j) is zero, then the j-th eigenvalue is real; if *> positive, then the j-th and (j+1)-st eigenvalues are a *> complex conjugate pair, with ALPHAI(j+1) negative. *> *> Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) *> may easily over- or underflow, and BETA(j) may even be zero. *> Thus, the user should avoid naively computing the ratio. *> However, ALPHAR and ALPHAI will be always less than and *> usually comparable with norm(A) in magnitude, and BETA always *> less than and usually comparable with norm(B). *> \endverbatim *> *> \param[out] VSL *> \verbatim *> VSL is DOUBLE PRECISION array, dimension (LDVSL,N) *> If JOBVSL = 'V', VSL will contain the left Schur vectors. *> Not referenced if JOBVSL = 'N'. *> \endverbatim *> *> \param[in] LDVSL *> \verbatim *> LDVSL is INTEGER *> The leading dimension of the matrix VSL. LDVSL >=1, and *> if JOBVSL = 'V', LDVSL >= N. *> \endverbatim *> *> \param[out] VSR *> \verbatim *> VSR is DOUBLE PRECISION array, dimension (LDVSR,N) *> If JOBVSR = 'V', VSR will contain the right Schur vectors. *> Not referenced if JOBVSR = 'N'. *> \endverbatim *> *> \param[in] LDVSR *> \verbatim *> LDVSR is INTEGER *> The leading dimension of the matrix VSR. LDVSR >= 1, and *> if JOBVSR = 'V', LDVSR >= N. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. *> *> If LWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal size of the WORK array, returns *> this value as the first entry of the WORK array, and no error *> message related to LWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] BWORK *> \verbatim *> BWORK is LOGICAL array, dimension (N) *> Not referenced if SORT = 'N'. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value. *> = 1,...,N: *> The QZ iteration failed. (A,B) are not in Schur *> form, but ALPHAR(j), ALPHAI(j), and BETA(j) should *> be correct for j=INFO+1,...,N. *> > N: =N+1: other than QZ iteration failed in DLAQZ0. *> =N+2: after reordering, roundoff changed values of *> some complex eigenvalues so that leading *> eigenvalues in the Generalized Schur form no *> longer satisfy SELCTG=.TRUE. This could also *> be caused due to scaling. *> =N+3: reordering failed in DTGSEN. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup doubleGEeigen * * ===================================================================== SUBROUTINE DGGES3( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B, $ LDB, SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL, $ VSR, LDVSR, WORK, LWORK, BWORK, INFO ) * * -- LAPACK driver routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. CHARACTER JOBVSL, JOBVSR, SORT INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM * .. * .. Array Arguments .. LOGICAL BWORK( * ) DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ), $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ), $ VSR( LDVSR, * ), WORK( * ) * .. * .. Function Arguments .. LOGICAL SELCTG EXTERNAL SELCTG * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL CURSL, ILASCL, ILBSCL, ILVSL, ILVSR, LASTSL, $ LQUERY, LST2SL, WANTST INTEGER I, ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, $ ILO, IP, IRIGHT, IROWS, ITAU, IWRK, LWKOPT DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PVSL, $ PVSR, SAFMAX, SAFMIN, SMLNUM * .. * .. Local Arrays .. INTEGER IDUM( 1 ) DOUBLE PRECISION DIF( 2 ) * .. * .. External Subroutines .. EXTERNAL DGEQRF, DGGBAK, DGGBAL, DGGHD3, DLAQZ0, DLABAD, $ DLACPY, DLASCL, DLASET, DORGQR, DORMQR, DTGSEN, $ XERBLA * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DLAMCH, DLANGE EXTERNAL LSAME, DLAMCH, DLANGE * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, SQRT * .. * .. Executable Statements .. * * Decode the input arguments * IF( LSAME( JOBVSL, 'N' ) ) THEN IJOBVL = 1 ILVSL = .FALSE. ELSE IF( LSAME( JOBVSL, 'V' ) ) THEN IJOBVL = 2 ILVSL = .TRUE. ELSE IJOBVL = -1 ILVSL = .FALSE. END IF * IF( LSAME( JOBVSR, 'N' ) ) THEN IJOBVR = 1 ILVSR = .FALSE. ELSE IF( LSAME( JOBVSR, 'V' ) ) THEN IJOBVR = 2 ILVSR = .TRUE. ELSE IJOBVR = -1 ILVSR = .FALSE. END IF * WANTST = LSAME( SORT, 'S' ) * * Test the input arguments * INFO = 0 LQUERY = ( LWORK.EQ.-1 ) IF( IJOBVL.LE.0 ) THEN INFO = -1 ELSE IF( IJOBVR.LE.0 ) THEN INFO = -2 ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN INFO = -3 ELSE IF( N.LT.0 ) THEN INFO = -5 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -7 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -9 ELSE IF( LDVSL.LT.1 .OR. ( ILVSL .AND. LDVSL.LT.N ) ) THEN INFO = -15 ELSE IF( LDVSR.LT.1 .OR. ( ILVSR .AND. LDVSR.LT.N ) ) THEN INFO = -17 ELSE IF( LWORK.LT.6*N+16 .AND. .NOT.LQUERY ) THEN INFO = -19 END IF * * Compute workspace * IF( INFO.EQ.0 ) THEN CALL DGEQRF( N, N, B, LDB, WORK, WORK, -1, IERR ) LWKOPT = MAX( 6*N+16, 3*N+INT( WORK ( 1 ) ) ) CALL DORMQR( 'L', 'T', N, N, N, B, LDB, WORK, A, LDA, WORK, $ -1, IERR ) LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) ) IF( ILVSL ) THEN CALL DORGQR( N, N, N, VSL, LDVSL, WORK, WORK, -1, IERR ) LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) ) END IF CALL DGGHD3( JOBVSL, JOBVSR, N, 1, N, A, LDA, B, LDB, VSL, $ LDVSL, VSR, LDVSR, WORK, -1, IERR ) LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) ) CALL DLAQZ0( 'S', JOBVSL, JOBVSR, N, 1, N, A, LDA, B, LDB, $ ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, $ WORK, -1, 0, IERR ) LWKOPT = MAX( LWKOPT, 2*N+INT( WORK ( 1 ) ) ) IF( WANTST ) THEN CALL DTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB, $ ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, $ SDIM, PVSL, PVSR, DIF, WORK, -1, IDUM, 1, $ IERR ) LWKOPT = MAX( LWKOPT, 2*N+INT( WORK ( 1 ) ) ) END IF WORK( 1 ) = LWKOPT END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGGES3 ', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) THEN SDIM = 0 RETURN END IF * * Get machine constants * EPS = DLAMCH( 'P' ) SAFMIN = DLAMCH( 'S' ) SAFMAX = ONE / SAFMIN CALL DLABAD( SAFMIN, SAFMAX ) SMLNUM = SQRT( SAFMIN ) / EPS BIGNUM = ONE / SMLNUM * * Scale A if max element outside range [SMLNUM,BIGNUM] * ANRM = DLANGE( 'M', N, N, A, LDA, WORK ) ILASCL = .FALSE. IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN ANRMTO = SMLNUM ILASCL = .TRUE. ELSE IF( ANRM.GT.BIGNUM ) THEN ANRMTO = BIGNUM ILASCL = .TRUE. END IF IF( ILASCL ) $ CALL DLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR ) * * Scale B if max element outside range [SMLNUM,BIGNUM] * BNRM = DLANGE( 'M', N, N, B, LDB, WORK ) ILBSCL = .FALSE. IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN BNRMTO = SMLNUM ILBSCL = .TRUE. ELSE IF( BNRM.GT.BIGNUM ) THEN BNRMTO = BIGNUM ILBSCL = .TRUE. END IF IF( ILBSCL ) $ CALL DLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR ) * * Permute the matrix to make it more nearly triangular * ILEFT = 1 IRIGHT = N + 1 IWRK = IRIGHT + N CALL DGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), WORK( IWRK ), IERR ) * * Reduce B to triangular form (QR decomposition of B) * IROWS = IHI + 1 - ILO ICOLS = N + 1 - ILO ITAU = IWRK IWRK = ITAU + IROWS CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ), $ WORK( IWRK ), LWORK+1-IWRK, IERR ) * * Apply the orthogonal transformation to matrix A * CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB, $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ), $ LWORK+1-IWRK, IERR ) * * Initialize VSL * IF( ILVSL ) THEN CALL DLASET( 'Full', N, N, ZERO, ONE, VSL, LDVSL ) IF( IROWS.GT.1 ) THEN CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB, $ VSL( ILO+1, ILO ), LDVSL ) END IF CALL DORGQR( IROWS, IROWS, IROWS, VSL( ILO, ILO ), LDVSL, $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR ) END IF * * Initialize VSR * IF( ILVSR ) $ CALL DLASET( 'Full', N, N, ZERO, ONE, VSR, LDVSR ) * * Reduce to generalized Hessenberg form * CALL DGGHD3( JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, VSL, $ LDVSL, VSR, LDVSR, WORK( IWRK ), LWORK+1-IWRK, $ IERR ) * * Perform QZ algorithm, computing Schur vectors if desired * IWRK = ITAU CALL DLAQZ0( 'S', JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, $ ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, $ WORK( IWRK ), LWORK+1-IWRK, 0, IERR ) IF( IERR.NE.0 ) THEN IF( IERR.GT.0 .AND. IERR.LE.N ) THEN INFO = IERR ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN INFO = IERR - N ELSE INFO = N + 1 END IF GO TO 50 END IF * * Sort eigenvalues ALPHA/BETA if desired * SDIM = 0 IF( WANTST ) THEN * * Undo scaling on eigenvalues before SELCTGing * IF( ILASCL ) THEN CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, $ IERR ) CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, $ IERR ) END IF IF( ILBSCL ) $ CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR ) * * Select eigenvalues * DO 10 I = 1, N BWORK( I ) = SELCTG( ALPHAR( I ), ALPHAI( I ), BETA( I ) ) 10 CONTINUE * CALL DTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB, ALPHAR, $ ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, SDIM, PVSL, $ PVSR, DIF, WORK( IWRK ), LWORK-IWRK+1, IDUM, 1, $ IERR ) IF( IERR.EQ.1 ) $ INFO = N + 3 * END IF * * Apply back-permutation to VSL and VSR * IF( ILVSL ) $ CALL DGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), N, VSL, LDVSL, IERR ) * IF( ILVSR ) $ CALL DGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), N, VSR, LDVSR, IERR ) * * Check if unscaling would cause over/underflow, if so, rescale * (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of * B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I) * IF( ILASCL ) THEN DO 20 I = 1, N IF( ALPHAI( I ).NE.ZERO ) THEN IF( ( ALPHAR( I ) / SAFMAX ).GT.( ANRMTO / ANRM ) .OR. $ ( SAFMIN / ALPHAR( I ) ).GT.( ANRM / ANRMTO ) ) THEN WORK( 1 ) = ABS( A( I, I ) / ALPHAR( I ) ) BETA( I ) = BETA( I )*WORK( 1 ) ALPHAR( I ) = ALPHAR( I )*WORK( 1 ) ALPHAI( I ) = ALPHAI( I )*WORK( 1 ) ELSE IF( ( ALPHAI( I ) / SAFMAX ).GT. $ ( ANRMTO / ANRM ) .OR. $ ( SAFMIN / ALPHAI( I ) ).GT.( ANRM / ANRMTO ) ) $ THEN WORK( 1 ) = ABS( A( I, I+1 ) / ALPHAI( I ) ) BETA( I ) = BETA( I )*WORK( 1 ) ALPHAR( I ) = ALPHAR( I )*WORK( 1 ) ALPHAI( I ) = ALPHAI( I )*WORK( 1 ) END IF END IF 20 CONTINUE END IF * IF( ILBSCL ) THEN DO 30 I = 1, N IF( ALPHAI( I ).NE.ZERO ) THEN IF( ( BETA( I ) / SAFMAX ).GT.( BNRMTO / BNRM ) .OR. $ ( SAFMIN / BETA( I ) ).GT.( BNRM / BNRMTO ) ) THEN WORK( 1 ) = ABS( B( I, I ) / BETA( I ) ) BETA( I ) = BETA( I )*WORK( 1 ) ALPHAR( I ) = ALPHAR( I )*WORK( 1 ) ALPHAI( I ) = ALPHAI( I )*WORK( 1 ) END IF END IF 30 CONTINUE END IF * * Undo scaling * IF( ILASCL ) THEN CALL DLASCL( 'H', 0, 0, ANRMTO, ANRM, N, N, A, LDA, IERR ) CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR ) CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR ) END IF * IF( ILBSCL ) THEN CALL DLASCL( 'U', 0, 0, BNRMTO, BNRM, N, N, B, LDB, IERR ) CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR ) END IF * IF( WANTST ) THEN * * Check if reordering is correct * LASTSL = .TRUE. LST2SL = .TRUE. SDIM = 0 IP = 0 DO 40 I = 1, N CURSL = SELCTG( ALPHAR( I ), ALPHAI( I ), BETA( I ) ) IF( ALPHAI( I ).EQ.ZERO ) THEN IF( CURSL ) $ SDIM = SDIM + 1 IP = 0 IF( CURSL .AND. .NOT.LASTSL ) $ INFO = N + 2 ELSE IF( IP.EQ.1 ) THEN * * Last eigenvalue of conjugate pair * CURSL = CURSL .OR. LASTSL LASTSL = CURSL IF( CURSL ) $ SDIM = SDIM + 2 IP = -1 IF( CURSL .AND. .NOT.LST2SL ) $ INFO = N + 2 ELSE * * First eigenvalue of conjugate pair * IP = 1 END IF END IF LST2SL = LASTSL LASTSL = CURSL 40 CONTINUE * END IF * 50 CONTINUE * WORK( 1 ) = LWKOPT * RETURN * * End of DGGES3 * END
bsd-3-clause
apollos/Quantum-ESPRESSO
lapack-3.2/SRC/chetrf.f
1
8886
SUBROUTINE CHETRF( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO ) * * -- LAPACK routine (version 3.2) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2006 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDA, LWORK, N * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX A( LDA, * ), WORK( * ) * .. * * Purpose * ======= * * CHETRF computes the factorization of a complex Hermitian matrix A * using the Bunch-Kaufman diagonal pivoting method. The form of the * factorization is * * A = U*D*U**H or A = L*D*L**H * * where U (or L) is a product of permutation and unit upper (lower) * triangular matrices, and D is Hermitian and block diagonal with * 1-by-1 and 2-by-2 diagonal blocks. * * This is the blocked version of the algorithm, calling Level 3 BLAS. * * Arguments * ========= * * UPLO (input) CHARACTER*1 * = 'U': Upper triangle of A is stored; * = 'L': Lower triangle of A is stored. * * N (input) INTEGER * The order of the matrix A. N >= 0. * * A (input/output) COMPLEX array, dimension (LDA,N) * On entry, the Hermitian matrix A. If UPLO = 'U', the leading * N-by-N upper triangular part of A contains the upper * triangular part of the matrix A, and the strictly lower * triangular part of A is not referenced. If UPLO = 'L', the * leading N-by-N lower triangular part of A contains the lower * triangular part of the matrix A, and the strictly upper * triangular part of A is not referenced. * * On exit, the block diagonal matrix D and the multipliers used * to obtain the factor U or L (see below for further details). * * LDA (input) INTEGER * The leading dimension of the array A. LDA >= max(1,N). * * IPIV (output) INTEGER array, dimension (N) * Details of the interchanges and the block structure of D. * If IPIV(k) > 0, then rows and columns k and IPIV(k) were * interchanged and D(k,k) is a 1-by-1 diagonal block. * If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and * columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) * is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = * IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were * interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. * * WORK (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) * On exit, if INFO = 0, WORK(1) returns the optimal LWORK. * * LWORK (input) INTEGER * The length of WORK. LWORK >=1. For best performance * LWORK >= N*NB, where NB is the block size returned by ILAENV. * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value * > 0: if INFO = i, D(i,i) is exactly zero. The factorization * has been completed, but the block diagonal matrix D is * exactly singular, and division by zero will occur if it * is used to solve a system of equations. * * Further Details * =============== * * If UPLO = 'U', then A = U*D*U', where * U = P(n)*U(n)* ... *P(k)U(k)* ..., * i.e., U is a product of terms P(k)*U(k), where k decreases from n to * 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 * and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as * defined by IPIV(k), and U(k) is a unit upper triangular matrix, such * that if the diagonal block D(k) is of order s (s = 1 or 2), then * * ( I v 0 ) k-s * U(k) = ( 0 I 0 ) s * ( 0 0 I ) n-k * k-s s n-k * * If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). * If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), * and A(k,k), and v overwrites A(1:k-2,k-1:k). * * If UPLO = 'L', then A = L*D*L', where * L = P(1)*L(1)* ... *P(k)*L(k)* ..., * i.e., L is a product of terms P(k)*L(k), where k increases from 1 to * n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 * and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as * defined by IPIV(k), and L(k) is a unit lower triangular matrix, such * that if the diagonal block D(k) is of order s (s = 1 or 2), then * * ( I 0 0 ) k-1 * L(k) = ( 0 I 0 ) s * ( 0 v I ) n-k-s+1 * k-1 s n-k-s+1 * * If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). * If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), * and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). * * ===================================================================== * * .. Local Scalars .. LOGICAL LQUERY, UPPER INTEGER IINFO, IWS, J, K, KB, LDWORK, LWKOPT, NB, NBMIN * .. * .. External Functions .. LOGICAL LSAME INTEGER ILAENV EXTERNAL LSAME, ILAENV * .. * .. External Subroutines .. EXTERNAL CHETF2, CLAHEF, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 UPPER = LSAME( UPLO, 'U' ) LQUERY = ( LWORK.EQ.-1 ) IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -4 ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN INFO = -7 END IF * IF( INFO.EQ.0 ) THEN * * Determine the block size * NB = ILAENV( 1, 'CHETRF', UPLO, N, -1, -1, -1 ) LWKOPT = N*NB WORK( 1 ) = LWKOPT END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'CHETRF', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * NBMIN = 2 LDWORK = N IF( NB.GT.1 .AND. NB.LT.N ) THEN IWS = LDWORK*NB IF( LWORK.LT.IWS ) THEN NB = MAX( LWORK / LDWORK, 1 ) NBMIN = MAX( 2, ILAENV( 2, 'CHETRF', UPLO, N, -1, -1, -1 ) ) END IF ELSE IWS = 1 END IF IF( NB.LT.NBMIN ) $ NB = N * IF( UPPER ) THEN * * Factorize A as U*D*U' using the upper triangle of A * * K is the main loop index, decreasing from N to 1 in steps of * KB, where KB is the number of columns factorized by CLAHEF; * KB is either NB or NB-1, or K for the last block * K = N 10 CONTINUE * * If K < 1, exit from loop * IF( K.LT.1 ) $ GO TO 40 * IF( K.GT.NB ) THEN * * Factorize columns k-kb+1:k of A and use blocked code to * update columns 1:k-kb * CALL CLAHEF( UPLO, K, NB, KB, A, LDA, IPIV, WORK, N, IINFO ) ELSE * * Use unblocked code to factorize columns 1:k of A * CALL CHETF2( UPLO, K, A, LDA, IPIV, IINFO ) KB = K END IF * * Set INFO on the first occurrence of a zero pivot * IF( INFO.EQ.0 .AND. IINFO.GT.0 ) $ INFO = IINFO * * Decrease K and return to the start of the main loop * K = K - KB GO TO 10 * ELSE * * Factorize A as L*D*L' using the lower triangle of A * * K is the main loop index, increasing from 1 to N in steps of * KB, where KB is the number of columns factorized by CLAHEF; * KB is either NB or NB-1, or N-K+1 for the last block * K = 1 20 CONTINUE * * If K > N, exit from loop * IF( K.GT.N ) $ GO TO 40 * IF( K.LE.N-NB ) THEN * * Factorize columns k:k+kb-1 of A and use blocked code to * update columns k+kb:n * CALL CLAHEF( UPLO, N-K+1, NB, KB, A( K, K ), LDA, IPIV( K ), $ WORK, N, IINFO ) ELSE * * Use unblocked code to factorize columns k:n of A * CALL CHETF2( UPLO, N-K+1, A( K, K ), LDA, IPIV( K ), IINFO ) KB = N - K + 1 END IF * * Set INFO on the first occurrence of a zero pivot * IF( INFO.EQ.0 .AND. IINFO.GT.0 ) $ INFO = IINFO + K - 1 * * Adjust IPIV * DO 30 J = K, K + KB - 1 IF( IPIV( J ).GT.0 ) THEN IPIV( J ) = IPIV( J ) + K - 1 ELSE IPIV( J ) = IPIV( J ) - K + 1 END IF 30 CONTINUE * * Increase K and return to the start of the main loop * K = K + KB GO TO 20 * END IF * 40 CONTINUE WORK( 1 ) = LWKOPT RETURN * * End of CHETRF * END
gpl-2.0

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
409
Add dataset card