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
aamaricci/SciFortran
src/lapack/zgesvxx.f
1
26624
SUBROUTINE ZGESVXX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, $ EQUED, R, C, B, LDB, X, LDX, RCOND, RPVGRW, $ BERR, N_ERR_BNDS, ERR_BNDS_NORM, $ ERR_BNDS_COMP, NPARAMS, PARAMS, WORK, RWORK, $ INFO ) * * -- LAPACK driver routine (version 3.2.1) -- * -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- * -- Jason Riedy of Univ. of California Berkeley. -- * -- April 2009 -- * * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley and NAG Ltd. -- * IMPLICIT NONE * .. * .. Scalar Arguments .. CHARACTER EQUED, FACT, TRANS INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, $ N_ERR_BNDS DOUBLE PRECISION RCOND, RPVGRW * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ), $ X( LDX , * ),WORK( * ) DOUBLE PRECISION R( * ), C( * ), PARAMS( * ), BERR( * ), $ ERR_BNDS_NORM( NRHS, * ), $ ERR_BNDS_COMP( NRHS, * ), RWORK( * ) * .. * * Purpose * ======= * * ZGESVXX uses the LU factorization to compute the solution to a * complex*16 system of linear equations A * X = B, where A is an * N-by-N matrix and X and B are N-by-NRHS matrices. * * If requested, both normwise and maximum componentwise error bounds * are returned. ZGESVXX will return a solution with a tiny * guaranteed error (O(eps) where eps is the working machine * precision) unless the matrix is very ill-conditioned, in which * case a warning is returned. Relevant condition numbers also are * calculated and returned. * * ZGESVXX accepts user-provided factorizations and equilibration * factors; see the definitions of the FACT and EQUED options. * Solving with refinement and using a factorization from a previous * ZGESVXX call will also produce a solution with either O(eps) * errors or warnings, but we cannot make that claim for general * user-provided factorizations and equilibration factors if they * differ from what ZGESVXX would itself produce. * * Description * =========== * * The following steps are performed: * * 1. If FACT = 'E', double precision scaling factors are computed to equilibrate * the system: * * TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B * TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B * TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B * * Whether or not the system will be equilibrated depends on the * scaling of the matrix A, but if equilibration is used, A is * overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N') * or diag(C)*B (if TRANS = 'T' or 'C'). * * 2. If FACT = 'N' or 'E', the LU decomposition is used to factor * the matrix A (after equilibration if FACT = 'E') as * * A = P * L * U, * * where P is a permutation matrix, L is a unit lower triangular * matrix, and U is upper triangular. * * 3. If some U(i,i)=0, so that U is exactly singular, then the * routine returns with INFO = i. Otherwise, the factored form of A * is used to estimate the condition number of the matrix A (see * argument RCOND). If the reciprocal of the condition number is less * than machine precision, the routine still goes on to solve for X * and compute error bounds as described below. * * 4. The system of equations is solved for X using the factored form * of A. * * 5. By default (unless PARAMS(LA_LINRX_ITREF_I) is set to zero), * the routine will use iterative refinement to try to get a small * error and error bounds. Refinement calculates the residual to at * least twice the working precision. * * 6. If equilibration was used, the matrix X is premultiplied by * diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so * that it solves the original system before equilibration. * * Arguments * ========= * * Some optional parameters are bundled in the PARAMS array. These * settings determine how refinement is performed, but often the * defaults are acceptable. If the defaults are acceptable, users * can pass NPARAMS = 0 which prevents the source code from accessing * the PARAMS argument. * * FACT (input) CHARACTER*1 * Specifies whether or not the factored form of the matrix A is * supplied on entry, and if not, whether the matrix A should be * equilibrated before it is factored. * = 'F': On entry, AF and IPIV contain the factored form of A. * If EQUED is not 'N', the matrix A has been * equilibrated with scaling factors given by R and C. * A, AF, and IPIV are not modified. * = 'N': The matrix A will be copied to AF and factored. * = 'E': The matrix A will be equilibrated if necessary, then * copied to AF and factored. * * TRANS (input) CHARACTER*1 * Specifies the form of the system of equations: * = 'N': A * X = B (No transpose) * = 'T': A**T * X = B (Transpose) * = 'C': A**H * X = B (Conjugate Transpose) * * N (input) INTEGER * The number of linear equations, i.e., 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 matrices B and X. NRHS >= 0. * * A (input/output) COMPLEX*16 array, dimension (LDA,N) * On entry, the N-by-N matrix A. If FACT = 'F' and EQUED is * not 'N', then A must have been equilibrated by the scaling * factors in R and/or C. A is not modified if FACT = 'F' or * 'N', or if FACT = 'E' and EQUED = 'N' on exit. * * On exit, if EQUED .ne. 'N', A is scaled as follows: * EQUED = 'R': A := diag(R) * A * EQUED = 'C': A := A * diag(C) * EQUED = 'B': A := diag(R) * A * diag(C). * * LDA (input) INTEGER * The leading dimension of the array A. LDA >= max(1,N). * * AF (input or output) COMPLEX*16 array, dimension (LDAF,N) * If FACT = 'F', then AF is an input argument and on entry * contains the factors L and U from the factorization * A = P*L*U as computed by ZGETRF. If EQUED .ne. 'N', then * AF is the factored form of the equilibrated matrix A. * * If FACT = 'N', then AF is an output argument and on exit * returns the factors L and U from the factorization A = P*L*U * of the original matrix A. * * If FACT = 'E', then AF is an output argument and on exit * returns the factors L and U from the factorization A = P*L*U * of the equilibrated matrix A (see the description of A for * the form of the equilibrated matrix). * * LDAF (input) INTEGER * The leading dimension of the array AF. LDAF >= max(1,N). * * IPIV (input or output) INTEGER array, dimension (N) * If FACT = 'F', then IPIV is an input argument and on entry * contains the pivot indices from the factorization A = P*L*U * as computed by ZGETRF; row i of the matrix was interchanged * with row IPIV(i). * * If FACT = 'N', then IPIV is an output argument and on exit * contains the pivot indices from the factorization A = P*L*U * of the original matrix A. * * If FACT = 'E', then IPIV is an output argument and on exit * contains the pivot indices from the factorization A = P*L*U * of the equilibrated matrix A. * * EQUED (input or output) CHARACTER*1 * Specifies the form of equilibration that was done. * = 'N': No equilibration (always true if FACT = 'N'). * = 'R': Row equilibration, i.e., A has been premultiplied by * diag(R). * = 'C': Column equilibration, i.e., A has been postmultiplied * by diag(C). * = 'B': Both row and column equilibration, i.e., A has been * replaced by diag(R) * A * diag(C). * EQUED is an input argument if FACT = 'F'; otherwise, it is an * output argument. * * R (input or output) DOUBLE PRECISION array, dimension (N) * The row scale factors for A. If EQUED = 'R' or 'B', A is * multiplied on the left by diag(R); if EQUED = 'N' or 'C', R * is not accessed. R is an input argument if FACT = 'F'; * otherwise, R is an output argument. If FACT = 'F' and * EQUED = 'R' or 'B', each element of R must be positive. * If R is output, each element of R is a power of the radix. * If R is input, each element of R should be a power of the radix * to ensure a reliable solution and error estimates. Scaling by * powers of the radix does not cause rounding errors unless the * result underflows or overflows. Rounding errors during scaling * lead to refining with a matrix that is not equivalent to the * input matrix, producing error estimates that may not be * reliable. * * C (input or output) DOUBLE PRECISION array, dimension (N) * The column scale factors for A. If EQUED = 'C' or 'B', A is * multiplied on the right by diag(C); if EQUED = 'N' or 'R', C * is not accessed. C is an input argument if FACT = 'F'; * otherwise, C is an output argument. If FACT = 'F' and * EQUED = 'C' or 'B', each element of C must be positive. * If C is output, each element of C is a power of the radix. * If C is input, each element of C should be a power of the radix * to ensure a reliable solution and error estimates. Scaling by * powers of the radix does not cause rounding errors unless the * result underflows or overflows. Rounding errors during scaling * lead to refining with a matrix that is not equivalent to the * input matrix, producing error estimates that may not be * reliable. * * B (input/output) COMPLEX*16 array, dimension (LDB,NRHS) * On entry, the N-by-NRHS right hand side matrix B. * On exit, * if EQUED = 'N', B is not modified; * if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by * diag(R)*B; * if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is * overwritten by diag(C)*B. * * LDB (input) INTEGER * The leading dimension of the array B. LDB >= max(1,N). * * X (output) COMPLEX*16 array, dimension (LDX,NRHS) * If INFO = 0, the N-by-NRHS solution matrix X to the original * system of equations. Note that A and B are modified on exit * if EQUED .ne. 'N', and the solution to the equilibrated system is * inv(diag(C))*X if TRANS = 'N' and EQUED = 'C' or 'B', or * inv(diag(R))*X if TRANS = 'T' or 'C' and EQUED = 'R' or 'B'. * * LDX (input) INTEGER * The leading dimension of the array X. LDX >= max(1,N). * * RCOND (output) DOUBLE PRECISION * Reciprocal scaled condition number. This is an estimate of the * reciprocal Skeel condition number of the matrix A after * equilibration (if done). If this is less than the machine * precision (in particular, if it is zero), the matrix is singular * to working precision. Note that the error may still be small even * if this number is very small and the matrix appears ill- * conditioned. * * RPVGRW (output) DOUBLE PRECISION * Reciprocal pivot growth. On exit, this contains the reciprocal * pivot growth factor norm(A)/norm(U). The "max absolute element" * norm is used. If this is much less than 1, then the stability of * the LU factorization of the (equilibrated) matrix A could be poor. * This also means that the solution X, estimated condition numbers, * and error bounds could be unreliable. If factorization fails with * 0<INFO<=N, then this contains the reciprocal pivot growth factor * for the leading INFO columns of A. In ZGESVX, this quantity is * returned in WORK(1). * * BERR (output) DOUBLE PRECISION array, dimension (NRHS) * Componentwise relative backward error. This is the * componentwise relative backward error of each solution vector X(j) * (i.e., the smallest relative change in any element of A or B that * makes X(j) an exact solution). * * N_ERR_BNDS (input) INTEGER * Number of error bounds to return for each right hand side * and each type (normwise or componentwise). See ERR_BNDS_NORM and * ERR_BNDS_COMP below. * * ERR_BNDS_NORM (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) * For each right-hand side, this array contains information about * various error bounds and condition numbers corresponding to the * normwise relative error, which is defined as follows: * * Normwise relative error in the ith solution vector: * max_j (abs(XTRUE(j,i) - X(j,i))) * ------------------------------ * max_j abs(X(j,i)) * * The array is indexed by the type of error information as described * below. There currently are up to three pieces of information * returned. * * The first index in ERR_BNDS_NORM(i,:) corresponds to the ith * right-hand side. * * The second index in ERR_BNDS_NORM(:,err) contains the following * three fields: * err = 1 "Trust/don't trust" boolean. Trust the answer if the * reciprocal condition number is less than the threshold * sqrt(n) * dlamch('Epsilon'). * * err = 2 "Guaranteed" error bound: The estimated forward error, * almost certainly within a factor of 10 of the true error * so long as the next entry is greater than the threshold * sqrt(n) * dlamch('Epsilon'). This error bound should only * be trusted if the previous boolean is true. * * err = 3 Reciprocal condition number: Estimated normwise * reciprocal condition number. Compared with the threshold * sqrt(n) * dlamch('Epsilon') to determine if the error * estimate is "guaranteed". These reciprocal condition * numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some * appropriately scaled matrix Z. * Let Z = S*A, where S scales each row by a power of the * radix so all absolute row sums of Z are approximately 1. * * See Lapack Working Note 165 for further details and extra * cautions. * * ERR_BNDS_COMP (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) * For each right-hand side, this array contains information about * various error bounds and condition numbers corresponding to the * componentwise relative error, which is defined as follows: * * Componentwise relative error in the ith solution vector: * abs(XTRUE(j,i) - X(j,i)) * max_j ---------------------- * abs(X(j,i)) * * The array is indexed by the right-hand side i (on which the * componentwise relative error depends), and the type of error * information as described below. There currently are up to three * pieces of information returned for each right-hand side. If * componentwise accuracy is not requested (PARAMS(3) = 0.0), then * ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most * the first (:,N_ERR_BNDS) entries are returned. * * The first index in ERR_BNDS_COMP(i,:) corresponds to the ith * right-hand side. * * The second index in ERR_BNDS_COMP(:,err) contains the following * three fields: * err = 1 "Trust/don't trust" boolean. Trust the answer if the * reciprocal condition number is less than the threshold * sqrt(n) * dlamch('Epsilon'). * * err = 2 "Guaranteed" error bound: The estimated forward error, * almost certainly within a factor of 10 of the true error * so long as the next entry is greater than the threshold * sqrt(n) * dlamch('Epsilon'). This error bound should only * be trusted if the previous boolean is true. * * err = 3 Reciprocal condition number: Estimated componentwise * reciprocal condition number. Compared with the threshold * sqrt(n) * dlamch('Epsilon') to determine if the error * estimate is "guaranteed". These reciprocal condition * numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some * appropriately scaled matrix Z. * Let Z = S*(A*diag(x)), where x is the solution for the * current right-hand side and S scales each row of * A*diag(x) by a power of the radix so all absolute row * sums of Z are approximately 1. * * See Lapack Working Note 165 for further details and extra * cautions. * * NPARAMS (input) INTEGER * Specifies the number of parameters set in PARAMS. If .LE. 0, the * PARAMS array is never referenced and default values are used. * * PARAMS (input / output) DOUBLE PRECISION array, dimension NPARAMS * Specifies algorithm parameters. If an entry is .LT. 0.0, then * that entry will be filled with default value used for that * parameter. Only positions up to NPARAMS are accessed; defaults * are used for higher-numbered parameters. * * PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative * refinement or not. * Default: 1.0D+0 * = 0.0 : No refinement is performed, and no error bounds are * computed. * = 1.0 : Use the extra-precise refinement algorithm. * (other values are reserved for future use) * * PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual * computations allowed for refinement. * Default: 10 * Aggressive: Set to 100 to permit convergence using approximate * factorizations or factorizations other than LU. If * the factorization uses a technique other than * Gaussian elimination, the guarantees in * err_bnds_norm and err_bnds_comp may no longer be * trustworthy. * * PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code * will attempt to find a solution with small componentwise * relative error in the double-precision algorithm. Positive * is true, 0.0 is false. * Default: 1.0 (attempt componentwise convergence) * * WORK (workspace) COMPLEX*16 array, dimension (2*N) * * RWORK (workspace) DOUBLE PRECISION array, dimension (2*N) * * INFO (output) INTEGER * = 0: Successful exit. The solution to every right-hand side is * guaranteed. * < 0: If INFO = -i, the i-th argument had an illegal value * > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization * has been completed, but the factor U is exactly singular, so * the solution and error bounds could not be computed. RCOND = 0 * is returned. * = N+J: The solution corresponding to the Jth right-hand side is * not guaranteed. The solutions corresponding to other right- * hand sides K with K > J may not be guaranteed as well, but * only the first such right-hand side is reported. If a small * componentwise error is not requested (PARAMS(3) = 0.0) then * the Jth right-hand side is the first with a normwise error * bound that is not guaranteed (the smallest J such * that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) * the Jth right-hand side is the first with either a normwise or * componentwise error bound that is not guaranteed (the smallest * J such that either ERR_BNDS_NORM(J,1) = 0.0 or * ERR_BNDS_COMP(J,1) = 0.0). See the definition of * ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information * about all of the right-hand sides check ERR_BNDS_NORM or * ERR_BNDS_COMP. * * ================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) INTEGER FINAL_NRM_ERR_I, FINAL_CMP_ERR_I, BERR_I INTEGER RCOND_I, NRM_RCOND_I, NRM_ERR_I, CMP_RCOND_I INTEGER CMP_ERR_I, PIV_GROWTH_I PARAMETER ( FINAL_NRM_ERR_I = 1, FINAL_CMP_ERR_I = 2, $ BERR_I = 3 ) PARAMETER ( RCOND_I = 4, NRM_RCOND_I = 5, NRM_ERR_I = 6 ) PARAMETER ( CMP_RCOND_I = 7, CMP_ERR_I = 8, $ PIV_GROWTH_I = 9 ) * .. * .. Local Scalars .. LOGICAL COLEQU, EQUIL, NOFACT, NOTRAN, ROWEQU INTEGER INFEQU, J DOUBLE PRECISION AMAX, BIGNUM, COLCND, RCMAX, RCMIN, $ ROWCND, SMLNUM * .. * .. External Functions .. EXTERNAL LSAME, DLAMCH, ZLA_RPVGRW LOGICAL LSAME DOUBLE PRECISION DLAMCH, ZLA_RPVGRW * .. * .. External Subroutines .. EXTERNAL ZGEEQUB, ZGETRF, ZGETRS, ZLACPY, ZLAQGE, $ XERBLA, ZLASCL2, ZGERFSX * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * INFO = 0 NOFACT = LSAME( FACT, 'N' ) EQUIL = LSAME( FACT, 'E' ) NOTRAN = LSAME( TRANS, 'N' ) SMLNUM = DLAMCH( 'Safe minimum' ) BIGNUM = ONE / SMLNUM IF( NOFACT .OR. EQUIL ) THEN EQUED = 'N' ROWEQU = .FALSE. COLEQU = .FALSE. ELSE ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' ) COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' ) END IF * * Default is failure. If an input parameter is wrong or * factorization fails, make everything look horrible. Only the * pivot growth is set here, the rest is initialized in ZGERFSX. * RPVGRW = ZERO * * Test the input parameters. PARAMS is not tested until ZGERFSX. * IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT. $ LSAME( FACT, 'F' ) ) THEN INFO = -1 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT. $ LSAME( TRANS, 'C' ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NRHS.LT.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -6 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN INFO = -8 ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT. $ ( ROWEQU .OR. COLEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN INFO = -10 ELSE IF( ROWEQU ) THEN RCMIN = BIGNUM RCMAX = ZERO DO 10 J = 1, N RCMIN = MIN( RCMIN, R( J ) ) RCMAX = MAX( RCMAX, R( J ) ) 10 CONTINUE IF( RCMIN.LE.ZERO ) THEN INFO = -11 ELSE IF( N.GT.0 ) THEN ROWCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM ) ELSE ROWCND = ONE END IF END IF IF( COLEQU .AND. INFO.EQ.0 ) THEN RCMIN = BIGNUM RCMAX = ZERO DO 20 J = 1, N RCMIN = MIN( RCMIN, C( J ) ) RCMAX = MAX( RCMAX, C( J ) ) 20 CONTINUE IF( RCMIN.LE.ZERO ) THEN INFO = -12 ELSE IF( N.GT.0 ) THEN COLCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM ) ELSE COLCND = ONE END IF END IF IF( INFO.EQ.0 ) THEN IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -14 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN INFO = -16 END IF END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZGESVXX', -INFO ) RETURN END IF * IF( EQUIL ) THEN * * Compute row and column scalings to equilibrate the matrix A. * CALL ZGEEQUB( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX, $ INFEQU ) IF( INFEQU.EQ.0 ) THEN * * Equilibrate the matrix. * CALL ZLAQGE( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX, $ EQUED ) ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' ) COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' ) END IF * * If the scaling factors are not applied, set them to 1.0. * IF ( .NOT.ROWEQU ) THEN DO J = 1, N R( J ) = 1.0D+0 END DO END IF IF ( .NOT.COLEQU ) THEN DO J = 1, N C( J ) = 1.0D+0 END DO END IF END IF * * Scale the right-hand side. * IF( NOTRAN ) THEN IF( ROWEQU ) CALL ZLASCL2( N, NRHS, R, B, LDB ) ELSE IF( COLEQU ) CALL ZLASCL2( N, NRHS, C, B, LDB ) END IF * IF( NOFACT .OR. EQUIL ) THEN * * Compute the LU factorization of A. * CALL ZLACPY( 'Full', N, N, A, LDA, AF, LDAF ) CALL ZGETRF( N, N, AF, LDAF, IPIV, INFO ) * * Return if INFO is non-zero. * IF( INFO.GT.0 ) THEN * * Pivot in column INFO is exactly 0 * Compute the reciprocal pivot growth factor of the * leading rank-deficient INFO columns of A. * RPVGRW = ZLA_RPVGRW( N, INFO, A, LDA, AF, LDAF ) RETURN END IF END IF * * Compute the reciprocal pivot growth factor RPVGRW. * RPVGRW = ZLA_RPVGRW( N, N, A, LDA, AF, LDAF ) * * Compute the solution matrix X. * CALL ZLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) CALL ZGETRS( TRANS, N, NRHS, AF, LDAF, IPIV, X, LDX, INFO ) * * Use iterative refinement to improve the computed solution and * compute error bounds and backward error estimates for it. * CALL ZGERFSX( TRANS, EQUED, N, NRHS, A, LDA, AF, LDAF, $ IPIV, R, C, B, LDB, X, LDX, RCOND, BERR, $ N_ERR_BNDS, ERR_BNDS_NORM, ERR_BNDS_COMP, NPARAMS, PARAMS, $ WORK, RWORK, INFO ) * * Scale solutions. * IF ( COLEQU .AND. NOTRAN ) THEN CALL ZLASCL2 ( N, NRHS, C, X, LDX ) ELSE IF ( ROWEQU .AND. .NOT.NOTRAN ) THEN CALL ZLASCL2 ( N, NRHS, R, X, LDX ) END IF * RETURN * * End of ZGESVXX * END
lgpl-3.0
OpenDA-Association/OpenDA
core/native/external/lapack/ztgsy2.f
2
12418
SUBROUTINE ZTGSY2( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D, $ LDD, E, LDE, F, LDF, SCALE, RDSUM, RDSCAL, $ INFO ) * * -- LAPACK auxiliary routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * June 30, 1999 * * .. Scalar Arguments .. CHARACTER TRANS INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF, M, N DOUBLE PRECISION RDSCAL, RDSUM, SCALE * .. * .. Array Arguments .. COMPLEX*16 A( LDA, * ), B( LDB, * ), C( LDC, * ), $ D( LDD, * ), E( LDE, * ), F( LDF, * ) * .. * * Purpose * ======= * * ZTGSY2 solves the generalized Sylvester equation * * A * R - L * B = scale * C (1) * D * R - L * E = scale * F * * using Level 1 and 2 BLAS, where R and L are unknown M-by-N matrices, * (A, D), (B, E) and (C, F) are given matrix pairs of size M-by-M, * N-by-N and M-by-N, respectively. A, B, D and E are upper triangular * (i.e., (A,D) and (B,E) in generalized Schur form). * * The solution (R, L) overwrites (C, F). 0 <= SCALE <= 1 is an output * scaling factor chosen to avoid overflow. * * In matrix notation solving equation (1) corresponds to solve * Zx = scale * b, where Z is defined as * * Z = [ kron(In, A) -kron(B', Im) ] (2) * [ kron(In, D) -kron(E', Im) ], * * Ik is the identity matrix of size k and X' is the transpose of X. * kron(X, Y) is the Kronecker product between the matrices X and Y. * * If TRANS = 'C', y in the conjugate transposed system Z'y = scale*b * is solved for, which is equivalent to solve for R and L in * * A' * R + D' * L = scale * C (3) * R * B' + L * E' = scale * -F * * This case is used to compute an estimate of Dif[(A, D), (B, E)] = * = sigma_min(Z) using reverse communicaton with ZLACON. * * ZTGSY2 also (IJOB >= 1) contributes to the computation in ZTGSYL * of an upper bound on the separation between to matrix pairs. Then * the input (A, D), (B, E) are sub-pencils of two matrix pairs in * ZTGSYL. * * Arguments * ========= * * TRANS (input) CHARACTER * = 'N', solve the generalized Sylvester equation (1). * = 'T': solve the 'transposed' system (3). * * IJOB (input) INTEGER * Specifies what kind of functionality to be performed. * =0: solve (1) only. * =1: A contribution from this subsystem to a Frobenius * norm-based estimate of the separation between two matrix * pairs is computed. (look ahead strategy is used). * =2: A contribution from this subsystem to a Frobenius * norm-based estimate of the separation between two matrix * pairs is computed. (DGECON on sub-systems is used.) * Not referenced if TRANS = 'T'. * * M (input) INTEGER * On entry, M specifies the order of A and D, and the row * dimension of C, F, R and L. * * N (input) INTEGER * On entry, N specifies the order of B and E, and the column * dimension of C, F, R and L. * * A (input) COMPLEX*16 array, dimension (LDA, M) * On entry, A contains an upper triangular matrix. * * LDA (input) INTEGER * The leading dimension of the matrix A. LDA >= max(1, M). * * B (input) COMPLEX*16 array, dimension (LDB, N) * On entry, B contains an upper triangular matrix. * * LDB (input) INTEGER * The leading dimension of the matrix B. LDB >= max(1, N). * * C (input/ output) COMPLEX*16 array, dimension (LDC, N) * On entry, C contains the right-hand-side of the first matrix * equation in (1). * On exit, if IJOB = 0, C has been overwritten by the solution * R. * * LDC (input) INTEGER * The leading dimension of the matrix C. LDC >= max(1, M). * * D (input) COMPLEX*16 array, dimension (LDD, M) * On entry, D contains an upper triangular matrix. * * LDD (input) INTEGER * The leading dimension of the matrix D. LDD >= max(1, M). * * E (input) COMPLEX*16 array, dimension (LDE, N) * On entry, E contains an upper triangular matrix. * * LDE (input) INTEGER * The leading dimension of the matrix E. LDE >= max(1, N). * * F (input/ output) COMPLEX*16 array, dimension (LDF, N) * On entry, F contains the right-hand-side of the second matrix * equation in (1). * On exit, if IJOB = 0, F has been overwritten by the solution * L. * * LDF (input) INTEGER * The leading dimension of the matrix F. LDF >= max(1, M). * * SCALE (output) DOUBLE PRECISION * On exit, 0 <= SCALE <= 1. If 0 < SCALE < 1, the solutions * R and L (C and F on entry) will hold the solutions to a * slightly perturbed system but the input matrices A, B, D and * E have not been changed. If SCALE = 0, R and L will hold the * solutions to the homogeneous system with C = F = 0. * Normally, SCALE = 1. * * RDSUM (input/output) DOUBLE PRECISION * On entry, the sum of squares of computed contributions to * the Dif-estimate under computation by ZTGSYL, where the * scaling factor RDSCAL (see below) has been factored out. * On exit, the corresponding sum of squares updated with the * contributions from the current sub-system. * If TRANS = 'T' RDSUM is not touched. * NOTE: RDSUM only makes sense when ZTGSY2 is called by * ZTGSYL. * * RDSCAL (input/output) DOUBLE PRECISION * On entry, scaling factor used to prevent overflow in RDSUM. * On exit, RDSCAL is updated w.r.t. the current contributions * in RDSUM. * If TRANS = 'T', RDSCAL is not touched. * NOTE: RDSCAL only makes sense when ZTGSY2 is called by * ZTGSYL. * * INFO (output) INTEGER * On exit, if INFO is set to * =0: Successful exit * <0: If INFO = -i, input argument number i is illegal. * >0: The matrix pairs (A, D) and (B, E) have common or very * close eigenvalues. * * Further Details * =============== * * Based on contributions by * Bo Kagstrom and Peter Poromaa, Department of Computing Science, * Umea University, S-901 87 Umea, Sweden. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE INTEGER LDZ PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, LDZ = 2 ) * .. * .. Local Scalars .. LOGICAL NOTRAN INTEGER I, IERR, J, K DOUBLE PRECISION SCALOC COMPLEX*16 ALPHA * .. * .. Local Arrays .. INTEGER IPIV( LDZ ), JPIV( LDZ ) COMPLEX*16 RHS( LDZ ), Z( LDZ, LDZ ) * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA, ZAXPY, ZGESC2, ZGETC2, ZLATDF, ZSCAL * .. * .. Intrinsic Functions .. INTRINSIC DCMPLX, DCONJG, MAX * .. * .. Executable Statements .. * * Decode and test input parameters * INFO = 0 IERR = 0 NOTRAN = LSAME( TRANS, 'N' ) IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'C' ) ) THEN INFO = -1 ELSE IF( ( IJOB.LT.0 ) .OR. ( IJOB.GT.2 ) ) THEN INFO = -2 ELSE IF( M.LE.0 ) THEN INFO = -3 ELSE IF( N.LE.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -5 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -8 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN INFO = -10 ELSE IF( LDD.LT.MAX( 1, M ) ) THEN INFO = -12 ELSE IF( LDE.LT.MAX( 1, N ) ) THEN INFO = -14 ELSE IF( LDF.LT.MAX( 1, M ) ) THEN INFO = -16 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZTGSY2', -INFO ) RETURN END IF * IF( NOTRAN ) THEN * * Solve (I, J) - system * A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J) * D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J) * for I = M, M - 1, ..., 1; J = 1, 2, ..., N * SCALE = ONE SCALOC = ONE DO 30 J = 1, N DO 20 I = M, 1, -1 * * Build 2 by 2 system * Z( 1, 1 ) = A( I, I ) Z( 2, 1 ) = D( I, I ) Z( 1, 2 ) = -B( J, J ) Z( 2, 2 ) = -E( J, J ) * * Set up right hand side(s) * RHS( 1 ) = C( I, J ) RHS( 2 ) = F( I, J ) * * Solve Z * x = RHS * CALL ZGETC2( LDZ, Z, LDZ, IPIV, JPIV, IERR ) IF( IERR.GT.0 ) $ INFO = IERR IF( IJOB.EQ.0 ) THEN CALL ZGESC2( LDZ, Z, LDZ, RHS, IPIV, JPIV, SCALOC ) IF( SCALOC.NE.ONE ) THEN DO 10 K = 1, N CALL ZSCAL( M, DCMPLX( SCALOC, ZERO ), $ C( 1, K ), 1 ) CALL ZSCAL( M, DCMPLX( SCALOC, ZERO ), $ F( 1, K ), 1 ) 10 CONTINUE SCALE = SCALE*SCALOC END IF ELSE CALL ZLATDF( IJOB, LDZ, Z, LDZ, RHS, RDSUM, RDSCAL, $ IPIV, JPIV ) END IF * * Unpack solution vector(s) * C( I, J ) = RHS( 1 ) F( I, J ) = RHS( 2 ) * * Substitute R(I, J) and L(I, J) into remaining equation. * IF( I.GT.1 ) THEN ALPHA = -RHS( 1 ) CALL ZAXPY( I-1, ALPHA, A( 1, I ), 1, C( 1, J ), 1 ) CALL ZAXPY( I-1, ALPHA, D( 1, I ), 1, F( 1, J ), 1 ) END IF IF( J.LT.N ) THEN CALL ZAXPY( N-J, RHS( 2 ), B( J, J+1 ), LDB, $ C( I, J+1 ), LDC ) CALL ZAXPY( N-J, RHS( 2 ), E( J, J+1 ), LDE, $ F( I, J+1 ), LDF ) END IF * 20 CONTINUE 30 CONTINUE ELSE * * Solve transposed (I, J) - system: * A(I, I)' * R(I, J) + D(I, I)' * L(J, J) = C(I, J) * R(I, I) * B(J, J) + L(I, J) * E(J, J) = -F(I, J) * for I = 1, 2, ..., M, J = N, N - 1, ..., 1 * SCALE = ONE SCALOC = ONE DO 80 I = 1, M DO 70 J = N, 1, -1 * * Build 2 by 2 system Z' * Z( 1, 1 ) = DCONJG( A( I, I ) ) Z( 2, 1 ) = -DCONJG( B( J, J ) ) Z( 1, 2 ) = DCONJG( D( I, I ) ) Z( 2, 2 ) = -DCONJG( E( J, J ) ) * * * Set up right hand side(s) * RHS( 1 ) = C( I, J ) RHS( 2 ) = F( I, J ) * * Solve Z' * x = RHS * CALL ZGETC2( LDZ, Z, LDZ, IPIV, JPIV, IERR ) IF( IERR.GT.0 ) $ INFO = IERR CALL ZGESC2( LDZ, Z, LDZ, RHS, IPIV, JPIV, SCALOC ) IF( SCALOC.NE.ONE ) THEN DO 40 K = 1, N CALL ZSCAL( M, DCMPLX( SCALOC, ZERO ), C( 1, K ), $ 1 ) CALL ZSCAL( M, DCMPLX( SCALOC, ZERO ), F( 1, K ), $ 1 ) 40 CONTINUE SCALE = SCALE*SCALOC END IF * * Unpack solution vector(s) * C( I, J ) = RHS( 1 ) F( I, J ) = RHS( 2 ) * * Substitute R(I, J) and L(I, J) into remaining equation. * DO 50 K = 1, J - 1 F( I, K ) = F( I, K ) + RHS( 1 )*DCONJG( B( K, J ) ) + $ RHS( 2 )*DCONJG( E( K, J ) ) 50 CONTINUE DO 60 K = I + 1, M C( K, J ) = C( K, J ) - DCONJG( A( I, K ) )*RHS( 1 ) - $ DCONJG( D( I, K ) )*RHS( 2 ) 60 CONTINUE * 70 CONTINUE 80 CONTINUE END IF RETURN * * End of ZTGSY2 * END
lgpl-3.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Blas/zher.f
3
6732
SUBROUTINE ZHER(UPLO,N,ALPHA,X,INCX,A,LDA) * .. Scalar Arguments .. DOUBLE PRECISION ALPHA INTEGER INCX,LDA,N CHARACTER UPLO * .. * .. Array Arguments .. DOUBLE COMPLEX A(LDA,*),X(*) * .. * * Purpose * ======= * * ZHER performs the hermitian rank 1 operation * * A := alpha*x*x**H + A, * * where alpha is a real scalar, x is an n element vector and A is an * n by n hermitian matrix. * * Arguments * ========== * * UPLO - CHARACTER*1. * On entry, UPLO specifies whether the upper or lower * triangular part of the array A is to be referenced as * follows: * * UPLO = 'U' or 'u' Only the upper triangular part of A * is to be referenced. * * UPLO = 'L' or 'l' Only the lower triangular part of A * is to be referenced. * * Unchanged on exit. * * N - INTEGER. * On entry, N specifies the order of the matrix A. * N must be at least zero. * Unchanged on exit. * * ALPHA - DOUBLE PRECISION. * On entry, ALPHA specifies the scalar alpha. * Unchanged on exit. * * X - COMPLEX*16 array of dimension at least * ( 1 + ( n - 1 )*abs( INCX ) ). * Before entry, the incremented array X must contain the n * element 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. * * A - COMPLEX*16 array of DIMENSION ( LDA, n ). * Before entry with UPLO = 'U' or 'u', the leading n by n * upper triangular part of the array A must contain the upper * triangular part of the hermitian matrix and the strictly * lower triangular part of A is not referenced. On exit, the * upper triangular part of the array A is overwritten by the * upper triangular part of the updated matrix. * Before entry with UPLO = 'L' or 'l', the leading n by n * lower triangular part of the array A must contain the lower * triangular part of the hermitian matrix and the strictly * upper triangular part of A is not referenced. On exit, the * lower triangular part of the array A is overwritten by the * lower triangular part of the updated matrix. * Note that the imaginary parts of the diagonal elements need * not be set, they are assumed to be zero, and on exit they * are set to zero. * * LDA - INTEGER. * On entry, LDA specifies the first dimension of A as declared * in the calling (sub) program. LDA must be at least * max( 1, n ). * Unchanged on exit. * * Further Details * =============== * * Level 2 Blas routine. * * -- Written on 22-October-1986. * Jack Dongarra, Argonne National Lab. * Jeremy Du Croz, Nag Central Office. * Sven Hammarling, Nag Central Office. * Richard Hanson, Sandia National Labs. * * ===================================================================== * * .. Parameters .. DOUBLE COMPLEX ZERO PARAMETER (ZERO= (0.0D+0,0.0D+0)) * .. * .. Local Scalars .. DOUBLE COMPLEX TEMP INTEGER I,INFO,IX,J,JX,KX * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC DBLE,DCONJG,MAX * .. * * 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 (INCX.EQ.0) THEN INFO = 5 ELSE IF (LDA.LT.MAX(1,N)) THEN INFO = 7 END IF IF (INFO.NE.0) THEN CALL XERBLA('ZHER ',INFO) RETURN END IF * * Quick return if possible. * IF ((N.EQ.0) .OR. (ALPHA.EQ.DBLE(ZERO))) RETURN * * Set the start point in X if the increment is not unity. * IF (INCX.LE.0) THEN KX = 1 - (N-1)*INCX ELSE IF (INCX.NE.1) THEN KX = 1 END IF * * Start the operations. In this version the elements of A are * accessed sequentially with one pass through the triangular part * of A. * IF (LSAME(UPLO,'U')) THEN * * Form A when A is stored in upper triangle. * IF (INCX.EQ.1) THEN DO 20 J = 1,N IF (X(J).NE.ZERO) THEN TEMP = ALPHA*DCONJG(X(J)) DO 10 I = 1,J - 1 A(I,J) = A(I,J) + X(I)*TEMP 10 CONTINUE A(J,J) = DBLE(A(J,J)) + DBLE(X(J)*TEMP) ELSE A(J,J) = DBLE(A(J,J)) END IF 20 CONTINUE ELSE JX = KX DO 40 J = 1,N IF (X(JX).NE.ZERO) THEN TEMP = ALPHA*DCONJG(X(JX)) IX = KX DO 30 I = 1,J - 1 A(I,J) = A(I,J) + X(IX)*TEMP IX = IX + INCX 30 CONTINUE A(J,J) = DBLE(A(J,J)) + DBLE(X(JX)*TEMP) ELSE A(J,J) = DBLE(A(J,J)) END IF JX = JX + INCX 40 CONTINUE END IF ELSE * * Form A when A is stored in lower triangle. * IF (INCX.EQ.1) THEN DO 60 J = 1,N IF (X(J).NE.ZERO) THEN TEMP = ALPHA*DCONJG(X(J)) A(J,J) = DBLE(A(J,J)) + DBLE(TEMP*X(J)) DO 50 I = J + 1,N A(I,J) = A(I,J) + X(I)*TEMP 50 CONTINUE ELSE A(J,J) = DBLE(A(J,J)) END IF 60 CONTINUE ELSE JX = KX DO 80 J = 1,N IF (X(JX).NE.ZERO) THEN TEMP = ALPHA*DCONJG(X(JX)) A(J,J) = DBLE(A(J,J)) + DBLE(TEMP*X(JX)) IX = JX DO 70 I = J + 1,N IX = IX + INCX A(I,J) = A(I,J) + X(IX)*TEMP 70 CONTINUE ELSE A(J,J) = DBLE(A(J,J)) END IF JX = JX + INCX 80 CONTINUE END IF END IF * RETURN * * End of ZHER . * END
apache-2.0
OpenDA-Association/OpenDA
core/native/external/lapack/dopgtr.f
3
4382
SUBROUTINE DOPGTR( UPLO, N, AP, TAU, Q, LDQ, WORK, INFO ) * * -- LAPACK routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * September 30, 1994 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDQ, N * .. * .. Array Arguments .. DOUBLE PRECISION AP( * ), Q( LDQ, * ), TAU( * ), WORK( * ) * .. * * Purpose * ======= * * DOPGTR generates a real orthogonal matrix Q which is defined as the * product of n-1 elementary reflectors H(i) of order n, as returned by * DSPTRD using packed storage: * * if UPLO = 'U', Q = H(n-1) . . . H(2) H(1), * * if UPLO = 'L', Q = H(1) H(2) . . . H(n-1). * * Arguments * ========= * * UPLO (input) CHARACTER*1 * = 'U': Upper triangular packed storage used in previous * call to DSPTRD; * = 'L': Lower triangular packed storage used in previous * call to DSPTRD. * * N (input) INTEGER * The order of the matrix Q. N >= 0. * * AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) * The vectors which define the elementary reflectors, as * returned by DSPTRD. * * TAU (input) DOUBLE PRECISION array, dimension (N-1) * TAU(i) must contain the scalar factor of the elementary * reflector H(i), as returned by DSPTRD. * * Q (output) DOUBLE PRECISION array, dimension (LDQ,N) * The N-by-N orthogonal matrix Q. * * LDQ (input) INTEGER * The leading dimension of the array Q. LDQ >= max(1,N). * * WORK (workspace) DOUBLE PRECISION array, dimension (N-1) * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER I, IINFO, IJ, J * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL DORG2L, DORG2R, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input arguments * 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 ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN INFO = -6 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DOPGTR', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * IF( UPPER ) THEN * * Q was determined by a call to DSPTRD with UPLO = 'U' * * Unpack the vectors which define the elementary reflectors and * set the last row and column of Q equal to those of the unit * matrix * IJ = 2 DO 20 J = 1, N - 1 DO 10 I = 1, J - 1 Q( I, J ) = AP( IJ ) IJ = IJ + 1 10 CONTINUE IJ = IJ + 2 Q( N, J ) = ZERO 20 CONTINUE DO 30 I = 1, N - 1 Q( I, N ) = ZERO 30 CONTINUE Q( N, N ) = ONE * * Generate Q(1:n-1,1:n-1) * CALL DORG2L( N-1, N-1, N-1, Q, LDQ, TAU, WORK, IINFO ) * ELSE * * Q was determined by a call to DSPTRD with UPLO = 'L'. * * Unpack the vectors which define the elementary reflectors and * set the first row and column of Q equal to those of the unit * matrix * Q( 1, 1 ) = ONE DO 40 I = 2, N Q( I, 1 ) = ZERO 40 CONTINUE IJ = 3 DO 60 J = 2, N Q( 1, J ) = ZERO DO 50 I = J + 1, N Q( I, J ) = AP( IJ ) IJ = IJ + 1 50 CONTINUE IJ = IJ + 2 60 CONTINUE IF( N.GT.1 ) THEN * * Generate Q(2:n,2:n) * CALL DORG2R( N-1, N-1, N-1, Q( 2, 2 ), LDQ, TAU, WORK, $ IINFO ) END IF END IF RETURN * * End of DOPGTR * END
lgpl-3.0
alberthdev/nclayer
nc_diag_write/ncdw_chaninfo.F90
1
136096
! nc_diag_write - NetCDF Layer Diag Writing Module ! Copyright 2015 Albert Huang - SSAI/NASA for NASA GSFC GMAO (610.1). ! ! Licensed under the Apache License, Version 2.0 (the "License"); ! you may not use this file except in compliance with the License. ! You may obtain a copy of the License at ! ! http://www.apache.org/licenses/LICENSE-2.0 ! ! Unless required by applicable law or agreed to in writing, software ! distributed under the License is distributed on an "AS IS" BASIS, ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or ! implied. See the License for the specific language governing ! permissions and limitations under the License. ! ! chaninfo module - ncdw_chaninfo ! module ncdw_chaninfo ! Module that provides chaninfo variable storage support. ! ! This module has all of the subroutines needed to store chaninfo ! data. It includes the chaninfo storing subroutine ! (nc_diag_chaninfo), subroutines for controlling chaninfo data ! (dimension setting, loading definitions, saving definitions, ! saving data, etc.), and preallocation subroutines. ! ! Background: ! chaninfo is a fixed storage variable, with dimensions of ! 1 x nchans, where nchans is a known integer. ! ! Because we can know nchans, we can constrain the dimensions and ! make a few assumptions: ! ! -> nchans won't change for the duration of the file being open; ! -> nchans will be the same for all chaninfo variables, for any ! type involved; ! -> because everything is fixed, we can store variables block ! by block! ! ! Because Fortran is a strongly typed language, we can't do silly ! tricks in C, like allocating some memory to a void pointer and ! just storing our byte, short, int, long, float, or double ! numeric data there, and later casting it back... ! ! (e.g. void **data_ref; data_ref = malloc(sizeof(void *) * 1000); ! float *f = malloc(sizeof(float)); *f = 1.2345; ! data_ref[0] = f; ...) ! ! No frets - we can work around this issue with some derived types ! and arrays! We create an array for each type we want to support. ! Since we're using kinds.F90, we support the following types: ! i_byte, i_short, i_long, r_single, r_double, character(len=*) ! ! The derived type used, diag_chaninfo, has these variables to ! help us keep track of everything: ! ! -> ci_* - these arrays have the types listed above, plus string ! support! These arrays are simply arrays that we throw our ! data in. However, don't mistaken "throw in" with ! "disorganized" - chaninfo uses a very structured format for ! these variables! Keep reading to find out how we structure ! it... ! ! -> nchans - the number of channels to use. Remember that ! chaninfo variables have dimensions 1 x nchans - basically, we ! need to store nchans values. We'll need this a LOT to do ! consistency checks, and to keep track of everything! ! ! -> names - all of the chaninfo variable names! We'll be using ! this array to store and lookup chaninfo variables, as well as ! storing them! ! ! -> types - all of the chaninfo variable types! These are byte ! integers that get compared to our NLAYER_* type constants ! (see: ncdw_types.F90). ! ! -> var_usage - the amount of entries we've stored in our ! chaninfo variable! For instance, if we called ! nc_diag_chaninfo("myvar", 1) three times, for that particular ! var_usage(i), we would have an entry of 3. ! ! -> var_rel_pos - the star of the show! This is an abbreviation ! of "variable relative positioning". Recall that we store ! our variable data in ci_* specific type arrays. We know ! the nchans amount, and we know the type. This variable stores ! the "block" that our data is in within the type array. ! ! Therefore, we can use the equation to find our starting ! position: 1 + [(REL_VAL - 1) * nchans] ! ! For instance, if var_rel_pos(1) for variable names(1) = "bla" ! is set to 2, nchans is 10, and the type is NLAYER_FLOAT, we ! can deduce that in ci_rsingle, our data can be found starting ! at 1 + (1 * 10) = 11. This makes sense, as seen with our mini ! diagram below: ! ! ci_rsingle: ! / ci_rsingle index \ ! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ! [ x, x, x, x, x, x, x, x, x, x, y, y, y, y, y, y, y, y, y, y] ! \ ci_rsingle array / ! ! Indeed, our second block does start at index 11! ! As a bonus, since our data is in blocks, things can be super ! fast since we're just cutting our big array into small ones! ! ! -> acount_v: Finally, we have dynamic allocation. We have in our ! type a variable called acount_v. This tells us how many ! variables are stored in each type. Using the same equation ! above, and combining with var_usage, we can figure out where ! to put our data! ! ! Assume var_usage(i) = 2, block starts at index 11 with the ! equation above. ! ! Again, with our fun little diagram: ! ! ci_rsingle: ! / ci_rsingle index \ ! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ! [ x, x, x, x, x, x, x, x, x, x, y, y, Y, y, y, y, y, y, y, y] ! [ BLOCK 1 SEEK = 1->10->11 ][var_u=2|--block 2 area 11->20] ! \ ci_rsingle array / ! ! The capital Y marks the place we store our data! ! ! For the non-data variables (e.g. variable names, types, etc.), ! they are indexed by variable insertion order. This allows for ! easy lookup by looking up the variable name, and using the ! resulting index for fetching other information. ! ! Example: ! names: [ 'asdf', 'ghjk', 'zxcv' ] ! types: [ BYTE, FLOAT, BYTE ] ! var_rel_pos: [ 1, 1, 2 ] ! ! Lookup: "ghjk", result index = 2 ! ! Therefore, the "ghjk" variable type is types(2) = FLOAT, and ! the var_rel_pos for "ghjk" variable is var_rel_pos(2) = 1. ! ! These variables are allocated and reallocated, as needed. ! ! For the variable metadata fields (variable names, types, ! relative indicies, etc.), these are reallocated incrementally ! when a new variable is added. ! ! For the data storage fields, these are reallocated incrementally ! when new data is added. ! ! Initial allocation and subsequent reallocation is done by ! chunks. Allocating one element and/or reallocating and adding ! just one element is inefficient, since it's likely that much ! more data (and variables) will be added. Thus, allocation and ! reallocation is done by (re-)allocating exponentially increasing ! chunk sizes. See nc_diag_chaninfo_allocmulti help for more ! details. ! ! Because (re-)allocation is done in chunks, we keep a count of ! how much of the memory we're using so that we know when it's ! time to (re-)allocate. Once we need to (re-)allocate, we ! perform it, and then update our total memory counter to keep ! track of the memory already allocated. ! ! With all of these variables (and a few more state variables), ! we can reliably store our chaninfo data quickly and ! efficiently! ! ! Load our numerical types from kinds ! Note that i_llong is not a type we store - it's just for keeping ! track of numeric indexes. (Maybe this is too excessive...) use kinds, only: i_byte, i_short, i_long, i_llong, r_single, & r_double ! Load state variables! We need to know: ! init_done - ...whether a file is currently loaded or ! not. ! ncid - ...the current NCID of our file. ! append_only - ...whether we are in append mode or not. ! enable_trim - ...whether we need to automatically trim ! our strings for chaninfo string storage or ! not. ! diag_chaninfo_store - ...chaninfo variable information. ! We pretty much do everything related to ! chaninfo here, so we're using everything ! inside this derived type! use ncdw_state, only: init_done, ncid, append_only, & enable_trim, & diag_chaninfo_store ! Load types! We need: ! NLAYER_* - nc_diag types. ! NLAYER_FILL_* - nc_diag type fill. This is pretty much ! equivalent to NF90_FILL_*. ! NLAYER_COMPRESSION - zlib (a la gzip) compression level setting. ! NLAYER_DEFAULT_ENT - default starting number of element entries. ! This is for the initial allocation of ! space for data storage arrays, e.g. ! the ci_* data arrays within diag_chaninfo. ! NLAYER_MULTI_BASE - the base number to use when exponentiating ! to allocate or reallocate data storage ! arrays. use ncdw_types, only: NLAYER_BYTE, NLAYER_SHORT, NLAYER_LONG, & NLAYER_FLOAT, NLAYER_DOUBLE, NLAYER_STRING, & NLAYER_FILL_BYTE, NLAYER_FILL_SHORT, NLAYER_FILL_LONG, & NLAYER_FILL_FLOAT, NLAYER_FILL_DOUBLE, NLAYER_FILL_CHAR, & NLAYER_COMPRESSION, NLAYER_DEFAULT_ENT, NLAYER_MULTI_BASE ! Load our varattr adder! We need this to store our new shiny ! variable in the varattr database so we can add variable attributes ! to our variables. use ncdw_varattr, only: nc_diag_varattr_add_var ! Load our function - given an array of strings, find ! max(len_trim(str_array)) - aka the maximum for len_trim()s on each ! variable. use ncdw_strarrutils, only: max_len_string_array use ncdw_climsg, only: & #ifdef ENABLE_ACTION_MSGS nclayer_enable_action, nclayer_actionm, & #endif nclayer_error, nclayer_warning, nclayer_info, nclayer_check ! Load our fun reallocation subroutine - we need this to reallocate ! a few things in our preallocation subroutines: use ncdw_realloc, only: nc_diag_realloc ! Load our chaninfo resizing subroutines - these resize our data ! storage arrays automatically when needed! use ncdw_ciresize, only: nc_diag_chaninfo_resize_byte, & nc_diag_chaninfo_resize_short, nc_diag_chaninfo_resize_long, & nc_diag_chaninfo_resize_rsingle, & nc_diag_chaninfo_resize_rdouble, nc_diag_chaninfo_resize_string use netcdf, only: nf90_inquire, nf90_inq_dimid, & nf90_inquire_dimension, nf90_inquire_variable, nf90_def_dim, & nf90_def_var, nf90_get_var, nf90_put_var, & nf90_def_var_deflate, nf90_def_var_chunking, & NF90_BYTE, NF90_SHORT, NF90_INT, NF90_FLOAT, NF90_DOUBLE, & NF90_CHAR, & NF90_EBADDIM, NF90_NOERR, NF90_MAX_NAME, NF90_CHUNKED implicit none ! Add a single chaninfo value to a new or existing chaninfo ! variable. ! ! Given the chaninfo variable name and value, add or update the ! variable with the corresponding value. ! ! If the variable doesn't already exist, this will automatically ! create it and store the value into it. ! ! If the variable does exist, it will simply append to the ! variable's existing values. ! ! Values are inserted in the order of the calls made. As such, ! this subroutine is best designed to be used in a loop, where ! for every channel iteration, a value is added using this ! subroutine. ! ! chaninfo is stored element by element - no arrays are accepted, ! only scalar values. The best way to call chaninfo is in a loop, ! where each channel is being accessed and stored. ! ! Once a value has been added, it may not be removed. Make sure you ! are certain that the value should be added! ! ! The number of values may not exceed the number of channels ! (nchans). If more values are added and nchans is exceeded, an ! error will occur. ! ! Data locking and definition locking will also affect adding ! chaninfo variables and value. If data locking is in effect, any ! variable or value adding will not work. If definition locking is ! in effect, adding variable values to existing variables will still ! work, but adding new variables will not. ! ! For strings, if the length of the string changes when trimming is ! disabled, or when the definitions have been locked, an error will ! occur as well. ! ! To see more details about what checks are made, see the ! corresponding called subroutine documentation for details. ! ! Valid data types (represented below as data_types): ! integer(i_byte), integer(i_short), integer(i_long), ! real(r_single), real(r_double), character(len=*) ! ! Args: ! name (character(len=*)): the name of the chaninfo variable to ! add or update. ! value (data_types): the value to add to chaninfo. ! ! Raises: ! If data writing is locked, this will result in an error. ! ! If the variable doesn't exist yet, and definitions are locked, ! this will result in an error. ! ! If the amount of data in the chaninfo variable is already at ! or exceeding nchans, this will result in an error. ! ! For string data, if the string length changes and the ! definitions have already been locked, this will result in an ! error. ! ! Also, for string data, if the string length changes and ! trimming is turned off, this will also result in an error. ! ! The following errors will trigger indirectly from other ! subroutines called here: ! ! If nchans has not been set yet, this will result in an error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! interface nc_diag_chaninfo module procedure nc_diag_chaninfo_byte, & nc_diag_chaninfo_short, nc_diag_chaninfo_long, & nc_diag_chaninfo_rsingle, nc_diag_chaninfo_rdouble, & nc_diag_chaninfo_string end interface nc_diag_chaninfo contains ! Set the number of channels (nchans) for chaninfo to use for ! variable storage and configuration. ! ! This set the number of channels (nchans) for all of the future ! chaninfo variables that will be added. nchans will be used ! as the number of elements to use for every chaninfo variable ! added. It will also be used as a bounds check for variable ! data amounts. ! ! Args: ! nchans (integer(i_long)): the number of channels to use ! for chaninfo. ! ! Raises: ! If nchans was already set, this will result in an error. ! (You can't change nchans arbitarily - otherwise, variable ! data amounts could become invalid!) ! ! If the nchans specified is invalid (<1), this will result ! in an error. If you have no chaninfo variables to write, ! don't call this subroutine at all. No chaninfo variables ! will be processed or written if you don't set anything! ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Although unlikely, other errors may indirectly occur. ! They may be general storage errors, or even a bug. ! See the called subroutines' documentation for details. ! subroutine nc_diag_chaninfo_dim_set(nchans) integer(i_long), intent(in) :: nchans #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, I0, A)") "nc_diag_chaninfo_dim_set(nchans = ", nchans, ")" call nclayer_actionm(trim(action_str)) end if #endif ! Check if everything is initialized / file is open if (init_done .AND. allocated(diag_chaninfo_store)) then ! nchans can't be less than 1! if (nchans < 1) then call nclayer_error("Critical error - specified a nchan < 1!") end if ! Is nchans already set? if (diag_chaninfo_store%nchans /= -1) & call nclayer_error("nchans already set!") ! Set nchans diag_chaninfo_store%nchans = nchans else call nclayer_error("NetCDF4 layer not initialized yet!") end if end subroutine nc_diag_chaninfo_dim_set ! Set the allocation multiplier for chaninfo variable storage ! allocation and reallocation. ! ! This sets the allocation multiplier (exponentiator?) for ! chaninfo variable storage allocation and reallocation. ! ! Reallocation looks like this: ! new_size = old_size + addl_num_entries + ! (NLAYER_DEFAULT_ENT * (NLAYER_MULTI_BASE ** ! diag_chaninfo_store%alloc_multi)) ! ! NLAYER_DEFAULT_ENT and NLAYER_MULTI_BASE are constants defined ! in ncdw_types. The alloc_multi part is set with this ! subroutine. ! ! As reallocation occurs, the alloc_multi continues to increase ! by one, causing subsequent reallocations to allocate ! exponentially more memory. ! ! You can use this subroutine to increase the initial amount of ! memory allocated/reallocated, or you can use it to prevent ! the reallocating counter from increasing by calling this ! every so often. ! ! If this is not set, it will be initially set to 0 and will ! increase from there. ! ! Args: ! multiplier (integer(i_long)): the multiplier to use when ! allocating or reallocating. ! ! Raises: ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Although unlikely, other errors may indirectly occur. ! They may be general storage errors, or even a bug. ! See the called subroutines' documentation for details. ! subroutine nc_diag_chaninfo_allocmulti(multiplier) integer(i_long), intent(in) :: multiplier #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, I0, A)") "nc_diag_chaninfo_allocmulti(multiplier = ", multiplier, ")" call nclayer_actionm(trim(action_str)) end if #endif if (init_done) then ! # of times we needed to realloc simple metadata ! also the multiplier factor for allocation (2^x) diag_chaninfo_store%alloc_multi = multiplier end if end subroutine nc_diag_chaninfo_allocmulti ! Load chaninfo variable definitions from an existing, already ! open NetCDF file. ! ! This will scan the currently open NetCDF file for chaninfo ! variables. If any exist, the metadata and last position will ! get loaded into the chaninfo variable data buffer. ! ! Basically, this scans for the "nchans" dimension. If it ! exists, we set our internal nchans to that dimension's value. ! Then we fetch the dimension names for all variables, and try ! to match them to "nchans". (This is slow... see TODO.txt for ! a better idea!) ! ! Once we find our chaninfo variable(s), we scan them for NetCDF ! fill bytes, starting at the end of the variable. When we find ! a spot that does NOT have a fill byte, we set our relative ! index at that spot, and set everything up to resume at that ! position. ! ! For string data, we also our maximum string length constraint ! so that we still keep additional variable data within bounds. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! ! ! Args: ! None ! ! Raises: ! If the chaninfo variable uses an unsupported type (e.g. ! not one of the types listed above), this will result in ! an error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. (NetCDF error here, since ! init_done is not being checked... see TODO.txt) ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_load_def integer(i_long) :: ndims, nvars, var_index, type_index integer(i_long) :: rel_index, i, j ! Temporary variables used when scanning variables and dimensions ! from our NetCDF file character(len=NF90_MAX_NAME) :: tmp_var_name integer(i_long) :: tmp_var_type, tmp_var_ndims integer(i_long), dimension(:), allocatable :: tmp_var_dimids, tmp_var_dim_sizes character(len=NF90_MAX_NAME) , allocatable :: tmp_var_dim_names(:) ! Is this a nchans var? logical :: is_nchans_var ! Data buffers - we need these to fetch our data and see where ! we left off... integer(i_byte), dimension(:), allocatable :: byte_buffer integer(i_short), dimension(:), allocatable :: short_buffer integer(i_long), dimension(:), allocatable :: long_buffer real(r_single), dimension(:), allocatable :: rsingle_buffer real(r_double), dimension(:), allocatable :: rdouble_buffer character(1), dimension(:,:), allocatable :: string_buffer ! Dimension checking NetCDF error storage integer(i_long) :: dim_nc_err ! Get top level info about the file! call nclayer_check(nf90_inquire(ncid, nDimensions = ndims, & nVariables = nvars)) ! Fetch nchans first! dim_nc_err = nf90_inq_dimid(ncid, "nchans", diag_chaninfo_store%nchans_dimid) ! Check if we found anything! ! If we got NF90_EBADDIM, then exit. if (dim_nc_err == NF90_EBADDIM) then return else if (dim_nc_err /= NF90_NOERR) then ! If an error besides not finding the dimension occurs, ! raise an exception. call nclayer_check(dim_nc_err) end if ! Then grab nchans value... call nclayer_check(nf90_inquire_dimension(ncid, diag_chaninfo_store%nchans_dimid, & len = diag_chaninfo_store%nchans)) ! Now search for variables that use nchans! ! Loop through each variable! do var_index = 1, nvars ! Grab number of dimensions and attributes first call nclayer_check(nf90_inquire_variable(ncid, var_index, name = tmp_var_name, ndims = tmp_var_ndims)) ! Allocate temporary variable dimids storage! allocate(tmp_var_dimids(tmp_var_ndims)) allocate(tmp_var_dim_names(tmp_var_ndims)) allocate(tmp_var_dim_sizes(tmp_var_ndims)) ! Grab the actual dimension IDs and attributes call nclayer_check(nf90_inquire_variable(ncid, var_index, dimids = tmp_var_dimids, & xtype = tmp_var_type)) if ((tmp_var_ndims == 1) .OR. & ((tmp_var_ndims == 2) .AND. (tmp_var_type == NF90_CHAR))) then ! Reset our is_nchans_var switch to FALSE! is_nchans_var = .FALSE. ! Fetch all dimension names for the dimensions in the ! variable, and check if the variable is a nchans ! variable. We do so by (slowly) checking all ! dimension names and seeing if they match "nchans". ! If they do, is_nchans_var is set to TRUE. do i = 1, tmp_var_ndims call nclayer_check(nf90_inquire_dimension(ncid, tmp_var_dimids(i), tmp_var_dim_names(i), & tmp_var_dim_sizes(i))) if (tmp_var_dim_names(i) == "nchans") is_nchans_var = .TRUE. end do if (is_nchans_var) then ! Expand variable metadata first! ! Make sure we have enough variable metadata storage ! (and if not, reallocate!) call nc_diag_chaninfo_expand ! Add to the total! diag_chaninfo_store%total = diag_chaninfo_store%total + 1 ! Store name and type! diag_chaninfo_store%names(diag_chaninfo_store%total) = trim(tmp_var_name) ! Reset relative index to zero... rel_index = 0 ! For the rest of the code, we basically do the following: ! -> We allocate a temporary data storage variable. ! -> We set the NLAYER variable type for the variable. ! -> We fetch all of the data for the variable. ! -> We search, starting at the end of the variable, for ! fill bytes. We keep going if we see filler bytes, and ! stop when we encounter a non-fill byte. ! -> Since the place we stop is where we last stored a value, ! we set our relative index to the stopped index variable. ! -> We deallocate our temporary data storage variable. ! -> We set our type_index to update our data storage array count. if (tmp_var_type == NF90_BYTE) then diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_BYTE call nc_diag_chaninfo_resize_byte(int8(diag_chaninfo_store%nchans), .FALSE.) allocate(byte_buffer(diag_chaninfo_store%nchans)) call nclayer_check(nf90_get_var(ncid, var_index, byte_buffer)) do j = diag_chaninfo_store%nchans, 1, -1 if (byte_buffer(j) /= NLAYER_FILL_BYTE) then exit end if end do rel_index = j deallocate(byte_buffer) type_index = 1 else if (tmp_var_type == NF90_SHORT) then diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_SHORT call nc_diag_chaninfo_resize_short(int8(diag_chaninfo_store%nchans), .FALSE.) allocate(short_buffer(diag_chaninfo_store%nchans)) call nclayer_check(nf90_get_var(ncid, var_index, short_buffer)) do j = diag_chaninfo_store%nchans, 1, -1 if (short_buffer(j) /= NLAYER_FILL_SHORT) then exit end if end do rel_index = j deallocate(short_buffer) type_index = 2 else if (tmp_var_type == NF90_INT) then diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_LONG call nc_diag_chaninfo_resize_long(int8(diag_chaninfo_store%nchans), .FALSE.) allocate(long_buffer(diag_chaninfo_store%nchans)) call nclayer_check(nf90_get_var(ncid, var_index, long_buffer)) do j = diag_chaninfo_store%nchans, 1, -1 if (long_buffer(j) /= NLAYER_FILL_LONG) then exit end if end do rel_index = j deallocate(long_buffer) type_index = 3 else if (tmp_var_type == NF90_FLOAT) then diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_FLOAT call nc_diag_chaninfo_resize_rsingle(int8(diag_chaninfo_store%nchans), .FALSE.) allocate(rsingle_buffer(diag_chaninfo_store%nchans)) call nclayer_check(nf90_get_var(ncid, var_index, rsingle_buffer)) do j = diag_chaninfo_store%nchans, 1, -1 if (rsingle_buffer(j) /= NLAYER_FILL_FLOAT) then exit end if end do rel_index = j deallocate(rsingle_buffer) type_index = 4 else if (tmp_var_type == NF90_DOUBLE) then diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_DOUBLE call nc_diag_chaninfo_resize_rdouble(int8(diag_chaninfo_store%nchans), .FALSE.) allocate(rdouble_buffer(diag_chaninfo_store%nchans)) call nclayer_check(nf90_get_var(ncid, var_index, rdouble_buffer)) do j = diag_chaninfo_store%nchans, 1, -1 if (rdouble_buffer(j) /= NLAYER_FILL_DOUBLE) then exit end if end do rel_index = j deallocate(rdouble_buffer) type_index = 5 else if (tmp_var_type == NF90_CHAR) then diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_STRING call nc_diag_chaninfo_resize_string(int8(diag_chaninfo_store%nchans), .FALSE.) allocate(string_buffer(diag_chaninfo_store%nchans, tmp_var_dim_sizes(1))) call nclayer_check(nf90_get_var(ncid, var_index, string_buffer)) do j = diag_chaninfo_store%nchans, 1, -1 if (string_buffer(j, 1) /= NLAYER_FILL_CHAR) then exit end if end do rel_index = j deallocate(string_buffer) ! Set max string length constraint diag_chaninfo_store%max_str_lens(diag_chaninfo_store%total) = tmp_var_dim_sizes(1) type_index = 6 else ! The type is not supported by chaninfo - error! call nclayer_error("NetCDF4 type invalid!") end if print *, trim(tmp_var_name), "rel index", rel_index ! Now add a relative position... based on the next position! ! First, increment the number of variables stored for this type: diag_chaninfo_store%acount_v(type_index) = diag_chaninfo_store%acount_v(type_index) + 1 ! Then, set the next variable's relative positioning, ! based on the number of variables stored for this type. diag_chaninfo_store%var_rel_pos(diag_chaninfo_store%total) = diag_chaninfo_store%acount_v(type_index) ! Initialize the amount of memory used to 0. diag_chaninfo_store%var_usage(diag_chaninfo_store%total) = 0 ! Set relative index! diag_chaninfo_store%rel_indexes(diag_chaninfo_store%total) = rel_index ! Set variable ID! Note that var_index here is the actual variable ID. diag_chaninfo_store%var_ids(diag_chaninfo_store%total) = var_index end if !call nc_diag_cat_metadata_add_var(trim(tmp_var_name), tmp_var_type, tmp_var_ndims, tmp_var_dim_names) end if ! Deallocate deallocate(tmp_var_dimids) deallocate(tmp_var_dim_names) deallocate(tmp_var_dim_sizes) end do ! Set our definition lock! diag_chaninfo_store%def_lock = .TRUE. end subroutine nc_diag_chaninfo_load_def ! Write out chaninfo variable dimensions and variable ! definitions to NetCDF via the NetCDF API. ! ! Commit the current variables and make them known to NetCDF to ! allow chaninfo variable data writing. If successfully written, ! this will always set the definition lock flag to prevent any ! further changes. ! ! Definitions are only written once for every file opened, and ! can not be modified or written again within the opened file. ! This is enforced with a definition lock (def_lock) that is ! set here and checked everywhere. ! ! If definitions are already locked, no additional definitions ! will be created. Depending on conditions, the following may ! occur: ! ! -> If the internal argument is defined and set to TRUE, no ! error will be triggered. This is used internally by ! nc_diag_write to prevent errors from occuring when the ! lock may have already been set elsewhere. ! ! -> Otherwise, an error will be triggered, since the ! definition write occurred when the definitions were ! already written and locked. ! ! The inner workings: ! ! -> First and foremost, it performs sanity checks to ensure ! that we have a file loaded. If the check fails, an error ! occurs. ! ! -> It then checks to make sure we have chaninfo variables to ! write in the first place. If we don't have any, we simply ! return. ! ! -> We then do another sanity check to ensure that nchans is ! defined. We probably shouldn't have any variables in the ! first place if nchans isn't defined, but it doesn't hurt ! to check! (If this check fails, we probably have a ! serious bug...) ! ! -> If necessary (aka not in append mode, where this might ! already exist), define the nchans dimension in NetCDF. ! ! -> For every variable, fetch the type and name of the ! variable. If the variable is a string type, we also ! figure out the maximum string length, and create an ! extra dimension for that as well. Finally, we can go and ! define the variable itself to NetCDF, with the variable's ! respective dimensions (and NetCDF dimension IDs). ! ! -> We then add the variable to the varattr list to allow ! variable attributes for the chaninfo variable. ! ! -> If we're not in append mode, we set the appropriate ! chunking and compression settings for the variable to ! make storing the data more efficient. ! ! -> After we've gone through all of the chaninfo variables, ! we lock the definitions. That's it! ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! ! ! Args: ! internal (logical, optional): whether or not to disable ! triggering an error when a definition lock is ! detected. This flag is used internally for the final ! nc_diag_write, where this flag is purposely set to ! avoid any errors with definition locking, since the ! lock could have already been set earlier by ! nc_diag_lock_def or others. ! ! Raises: ! If definitions are already locked, and the internal ! argument is not set or is not TRUE, this will result in an ! error. ! ! If the nchans dimension hasn't been defined yet, this will ! result in an error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_write_def(internal) logical, intent(in), optional :: internal ! Just write the definitions out! integer(i_llong) :: curdatindex integer(i_byte) :: data_type integer(i_long) :: data_type_index character(len=100) :: data_name integer(i_long) :: nc_data_type integer(i_long) :: tmp_dim_id character(len=120) :: data_dim_name character(len=:), allocatable :: string_arr(:) #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then if (present(internal)) then write(action_str, "(A, L, A)") "nc_diag_chaninfo_write_def(internal = ", internal, ")" else write(action_str, "(A)") "nc_diag_chaninfo_write_def(internal = (not specified))" end if call nclayer_actionm(trim(action_str)) end if #endif ! Ensure that we have a file open and that things are loaded! if (init_done .AND. allocated(diag_chaninfo_store)) then ! Ensure that we have at least one variable to store! ! Otherwise, just return and do nothing. if (diag_chaninfo_store%total > 0) then ! Make sure nchans is defined before doing anything! if (diag_chaninfo_store%nchans /= -1) then ! Finally, make sure definitions are not locked! if (.NOT. diag_chaninfo_store%def_lock) then ! First, set the dimensions... if necessary! if (.NOT. append_only) & call nclayer_check(nf90_def_dim(ncid, "nchans", diag_chaninfo_store%nchans, diag_chaninfo_store%nchans_dimid)) ! Once we have the dimension, we can start writing ! variable definitions! do curdatindex = 1, diag_chaninfo_store%total ! Fetch variable name and type: data_name = diag_chaninfo_store%names(curdatindex) data_type = diag_chaninfo_store%types(curdatindex) ! Figure out where our data is stored, given var_rel_pos ! and nchans... (see equation/discussion above for more ! details!) data_type_index = 1 + & ((diag_chaninfo_store%var_rel_pos(curdatindex) - 1) * diag_chaninfo_store%nchans) call nclayer_info("chaninfo: defining " // trim(data_name)) ! Map our NLAYER type to the NF90 NetCDF native type! if (data_type == NLAYER_BYTE) nc_data_type = NF90_BYTE if (data_type == NLAYER_SHORT) nc_data_type = NF90_SHORT if (data_type == NLAYER_LONG) nc_data_type = NF90_INT if (data_type == NLAYER_FLOAT) nc_data_type = NF90_FLOAT if (data_type == NLAYER_DOUBLE) nc_data_type = NF90_DOUBLE if (data_type == NLAYER_STRING) nc_data_type = NF90_CHAR #ifdef _DEBUG_MEM_ print *, "chaninfo part 1" #endif ! If our variable type is a string, we need to compute the maximum ! string length. ! ! If we're trimming, we take the maximum of the length of strings ! in the variable, and use that as our maximum string length. ! ! Otherwise, we simply use the previously defined fixed length, ! which is already stored as the maximum string length from the ! initial string add. ! ! Once we know our maximum string length, we add that as a ! dimension, and use it (along with our nchans dimension) to ! create our string chaninfo variable! if (data_type == NLAYER_STRING) then ! Figure out the dimension name for this chaninfo variable write (data_dim_name, "(A, A)") trim(data_name), "_maxstrlen" ! Assume that the maximum string length is 10000 ! Allocate an array of 10000, with a size of the ! variable's var_usage allocate(character(10000) :: string_arr(diag_chaninfo_store%var_usage(curdatindex))) ! Fetch the strings from our variable storage string_arr = diag_chaninfo_store%ci_string(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)) ! If trimming is enabled, we haven't found our max_str_len yet. ! Go find it! if (enable_trim) then ! Save the max string len diag_chaninfo_store%max_str_lens(curdatindex) = & max_len_string_array(string_arr, diag_chaninfo_store%var_usage(curdatindex)) end if ! Add our custom string dimension to NetCDF, if necessary if (.NOT. append_only) & call nclayer_check(nf90_def_dim(ncid, data_dim_name, & diag_chaninfo_store%max_str_lens(curdatindex), & tmp_dim_id)) #ifdef _DEBUG_MEM_ print *, "Defining char var type..." #endif ! Add our string variable to NetCDF! if (.NOT. append_only) & call nclayer_check(nf90_def_var(ncid, diag_chaninfo_store%names(curdatindex), & nc_data_type, (/ tmp_dim_id, diag_chaninfo_store%nchans_dimid /), & diag_chaninfo_store%var_ids(curdatindex))) #ifdef _DEBUG_MEM_ print *, "Done defining char var type..." #endif ! Deallocate temp string array deallocate(string_arr) else ! Nothing fancy here! ! Just add our non-string variable to NetCDF! if (.NOT. append_only) & call nclayer_check(nf90_def_var(ncid, diag_chaninfo_store%names(curdatindex), & nc_data_type, diag_chaninfo_store%nchans_dimid, & diag_chaninfo_store%var_ids(curdatindex))) end if #ifdef _DEBUG_MEM_ print *, "chaninfo part 2" #endif ! Make our variable known to varattr - add it to the varattr database! call nc_diag_varattr_add_var(diag_chaninfo_store%names(curdatindex), & diag_chaninfo_store%types(curdatindex), & diag_chaninfo_store%var_ids(curdatindex)) ! If we are not appending, make sure to also set chunking and ! compression for efficiency + optimization! if (.NOT. append_only) then ! If we're storing a string, we need to specify both dimensions ! for our chunking parameters. Otherwise, we just need to ! specify nchans... if (data_type == NLAYER_STRING) then call nclayer_check(nf90_def_var_chunking(ncid, diag_chaninfo_store%var_ids(curdatindex), & NF90_CHUNKED, (/ diag_chaninfo_store%max_str_lens(curdatindex), diag_chaninfo_store%nchans /))) else call nclayer_check(nf90_def_var_chunking(ncid, diag_chaninfo_store%var_ids(curdatindex), & NF90_CHUNKED, (/ diag_chaninfo_store%nchans /))) end if ! Enable zlib (gzip-like) compression based on our level settings call nclayer_check(nf90_def_var_deflate(ncid, diag_chaninfo_store%var_ids(curdatindex), & 1, 1, NLAYER_COMPRESSION)) end if end do ! Lock the definitions! diag_chaninfo_store%def_lock = .TRUE. else ! Show an error message if we didn't suppress errors on purpose if(.NOT. present(internal)) & call nclayer_error("Can't write definitions - definitions have already been written and locked!") end if else call nclayer_error("Can't write definitions - number of chans not set yet!") end if ! End: if (diag_chaninfo_store%total > 0) end if else call nclayer_error("Can't write definitions - NetCDF4 layer not initialized yet!") end if end subroutine nc_diag_chaninfo_write_def ! Write all of the currently stored chaninfo data to NetCDF via ! the NetCDF APIs ("put"). ! ! This will go through all of the variables stored in chaninfo, ! and write their data to NetCDF. ! ! Buffer flushing mode is enabled if flush_data_only is set and ! is TRUE. Otherwise, this will operate normally. ! ! For buffer flushing mode, data locking will not be performed. ! Instead, it "flushes" the variable storage buffer. For all ! of the variables stored, it increments the relative index of ! the variable with the amount of data currently stored in the ! variable. ! ! (Essentially, new_rel_index = old_rel_index + var_data_count) ! ! Recall that the relative index stores the position of the last ! data entered for the variable. This is set by write_data, as ! well as load_def for the data append mode. In turn, write_data ! also uses it to store at the correct position. ! ! We also reset the var_usage, or the variable memory usage ! counter, back to zero to allow data storage to start at the ! beginning again. We use var_usage in write_data and in the ! storage subroutines to keep track of how much data we're ! storing, and how much we need to "read" from the array to ! store the data in NetCDF4 efficiently and within bounds. ! ! A quick example: ! -> If we have 2 elements, var_usage (variable memory usage) ! is initially 2, and rel_index (variable relative index, ! or our starting position) is initially 0. ! ! -> We flush the buffer. Since we flushed our buffer, ! var_usage is reset to 0, and rel_index is now 2 since ! we stored 2 elements. ! ! -> If we add 3 elements, we get a var_usage of 3 (for 3 ! elements stored), and rel_index stays the same (2). ! ! -> When we finally flush or write, this time we know to ! start at element number 3 (rel_index), and we know to ! write 3 elements from there (var_usage). ! ! -> We now have a total of 5 elements! Indicies 1-2 were ! stored with the flush, and indicies 3-5 were stored ! afterwards - all thanks to buffer flushing! ! ! Finally, if data flushing mode is enabled, the data_lock is ! not set to allow additional data to be written in the future. ! ! However, if data flushing mode is not set, or it is disabled, ! we assume that we are writing only one more time (or once, ! depending on if buffer flushing was ever enabled or not). ! Therefore, we set the data_lock (data writing lock) to TRUE ! in this case, assuming data writing was successful. ! ! If data writing has already been locked, this will error. ! ! If data flushing mode is disabled, we will also check to see ! if each variable's data fills up the nchans dimension. ! ! Depending on the strictness (strict_check), if the data is ! not filled to the nchans dimension, it could either result in ! an error (if strict_check is TRUE), or a warning (if ! strict_check is FALSE). ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! ! ! Args: ! flush_data_only (logical, optional): whether to only flush ! the chaninfo data buffers or not. If we flush data, ! data locking will not be set. ! ! Raises: ! If data writing has already been locked, and the data ! flushing argument is not set or is not TRUE, this will ! result in an error. ! ! If the nchans dimension hasn't been defined yet, this will ! result in an error. ! ! If strict checking (strict_check) is enabled, and a ! variable's data doesn't fill to the nchans dimension, ! this will result in an error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_write_data(flush_data_only) ! Optional internal flag to only flush data - if this is ! true, data flushing will be performed, and the data will ! NOT be locked. logical, intent(in), optional :: flush_data_only integer(i_byte) :: data_type integer(i_long) :: data_type_index character(len=100) :: data_name character(len=1000) :: nchan_empty_msg integer(i_llong) :: curdatindex, j integer(i_long) :: string_arr_maxlen character(len=:), allocatable :: string_arr(:) #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then if (present(flush_data_only)) then write(action_str, "(A, L, A)") "nc_diag_chaninfo_write_data(flush_data_only = ", flush_data_only, ")" else write(action_str, "(A)") "nc_diag_chaninfo_write_data(flush_data_only = (not specified))" end if call nclayer_actionm(trim(action_str)) end if #endif ! Check to make sure a file is open / things are loaded! if (init_done .AND. allocated(diag_chaninfo_store)) then ! Check to see if we have any variables to write in the ! first place! if (diag_chaninfo_store%total > 0) then ! Check to make sure that we have nchans defined! if (diag_chaninfo_store%nchans /= -1) then ! Check if we can still write any data! if (.NOT. diag_chaninfo_store%data_lock) then ! Iterate through all of our variables! do curdatindex = 1, diag_chaninfo_store%total ! Fetch the variable's name and type! data_name = diag_chaninfo_store%names(curdatindex) data_type = diag_chaninfo_store%types(curdatindex) ! Figure out where our data is stored, given var_rel_pos ! and nchans... (see equation/discussion above for more ! details!) data_type_index = 1 + & ((diag_chaninfo_store%var_rel_pos(curdatindex) - 1) * diag_chaninfo_store%nchans) call nclayer_info("chaninfo: writing " // trim(data_name)) ! Warn about low data filling... but only if we are finishing ! our data write (or writing once) - basically, we're NOT in ! flushing data mode! if ((.NOT. (present(flush_data_only) .AND. flush_data_only)) .AND. & ((diag_chaninfo_store%var_usage(curdatindex) + & diag_chaninfo_store%rel_indexes(curdatindex)) < diag_chaninfo_store%nchans)) then ! NOTE - I0 and TRIM are Fortran 95 specs write (nchan_empty_msg, "(A, A, A, I0, A, I0, A)") "Amount of data written in ", & trim(data_name), " (", & diag_chaninfo_store%var_usage(curdatindex) + & diag_chaninfo_store%rel_indexes(curdatindex), & ")" // char(10) // & " is less than nchans (", diag_chaninfo_store%nchans, ")!" ! If we are set to strict checking mode, error. ! Otherwise, just show a warning. if (diag_chaninfo_store%strict_check) then call nclayer_error(trim(nchan_empty_msg)) else call nclayer_warning(trim(nchan_empty_msg)) end if end if #ifdef _DEBUG_MEM_ print *, "****** Processing ******" print *, "data_name:" print *, data_name print *, "data_type:" print *, data_type print *, "data_type_index:" print *, data_type_index print *, "diag_chaninfo_store%var_ids(curdatindex):" print *, diag_chaninfo_store%var_ids(curdatindex) print *, "diag_chaninfo_store%var_usage(curdatindex):" print *, diag_chaninfo_store%var_usage(curdatindex) print *, "Upper range (data_type_index + &" print *, " diag_chaninfo_store%var_usage(curdatindex) - 1):" print *, (data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1) #endif ! Make sure we have variable data to write in the first place! ! ! If we do, we essentially: ! ! -> Find the right type to save to. ! ! -> If we are NOT storing a string, we just store a subsection ! of our variable storage array at (1 + rel_index) in the ! NetCDF variable. ! ! -> If we are storing a string, we create our own array to ! store all of our strings in to standardize the length ! (e.g. a 3, 4, and 5 character string is expanded to ! a 5, 5, and 5 character string array). This is needed ! to store all strings at once and match the NetCDF bounds. ! Once done, the array is sent through the NetCDF API for ! data storage. We deallocate the array once we're done! ! if (diag_chaninfo_store%var_usage(curdatindex) > 0) then if (data_type == NLAYER_BYTE) then #ifdef _DEBUG_MEM_ print *, "Resulting data to be stored:" print *, diag_chaninfo_store%ci_byte(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)) #endif call nclayer_check(nf90_put_var(ncid, diag_chaninfo_store%var_ids(curdatindex), & diag_chaninfo_store%ci_byte(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)), & start = (/ 1 + diag_chaninfo_store%rel_indexes(curdatindex) /) & )) else if (data_type == NLAYER_SHORT) then call nclayer_check(nf90_put_var(ncid, diag_chaninfo_store%var_ids(curdatindex), & diag_chaninfo_store%ci_short(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)), & start = (/ 1 + diag_chaninfo_store%rel_indexes(curdatindex) /) & )) else if (data_type == NLAYER_LONG) then #ifdef _DEBUG_MEM_ print *, "Resulting data to be stored:" print *, diag_chaninfo_store%ci_long(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)) print *, "start index:" print *, 1 + diag_chaninfo_store%rel_indexes(curdatindex) #endif call nclayer_check(nf90_put_var(ncid, diag_chaninfo_store%var_ids(curdatindex), & diag_chaninfo_store%ci_long(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)), & start = (/ 1 + diag_chaninfo_store%rel_indexes(curdatindex) /) & )) else if (data_type == NLAYER_FLOAT) then call nclayer_check(nf90_put_var(ncid, diag_chaninfo_store%var_ids(curdatindex), & diag_chaninfo_store%ci_rsingle(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)), & start = (/ 1 + diag_chaninfo_store%rel_indexes(curdatindex) /) & )) else if (data_type == NLAYER_DOUBLE) then call nclayer_check(nf90_put_var(ncid, diag_chaninfo_store%var_ids(curdatindex), & diag_chaninfo_store%ci_rdouble(data_type_index:(data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1)), & start = (/ 1 + diag_chaninfo_store%rel_indexes(curdatindex) /) & )) else if (data_type == NLAYER_STRING) then ! Storing to another variable may seem silly, but it's necessary ! to avoid "undefined variable" errors, thanks to the compiler's ! super optimization insanity... string_arr_maxlen = diag_chaninfo_store%max_str_lens(curdatindex) allocate(character(string_arr_maxlen) :: & string_arr(diag_chaninfo_store%var_usage(curdatindex))) if (enable_trim) then do j = data_type_index, data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1 string_arr(j - data_type_index + 1) = & trim(diag_chaninfo_store%ci_string(j)) end do #ifdef _DEBUG_MEM_ do j = 1, diag_chaninfo_store%var_usage(curdatindex) write (*, "(A, A, A)") "String: '", string_arr(j), "'" end do write (*, "(A, I0)") "string_arr_maxlen = ", string_arr_maxlen write (*, "(A, I0)") "diag_chaninfo_store%var_usage(curdatindex) = ", diag_chaninfo_store%var_usage(curdatindex) #endif else do j = data_type_index, data_type_index + & diag_chaninfo_store%var_usage(curdatindex) - 1 string_arr(j - data_type_index + 1) = & diag_chaninfo_store%ci_string(j) end do end if call nclayer_check(nf90_put_var(ncid, diag_chaninfo_store%var_ids(curdatindex), & string_arr, & start = (/ 1, 1 + diag_chaninfo_store%rel_indexes(curdatindex) /), & count = (/ string_arr_maxlen, & diag_chaninfo_store%var_usage(curdatindex) /) )) deallocate(string_arr) else call nclayer_error("Critical error - unknown variable type!") end if ! Check for data flushing, and if so, update the relative indexes ! and set var_usage to 0. if (present(flush_data_only) .AND. flush_data_only) then diag_chaninfo_store%rel_indexes(curdatindex) = & diag_chaninfo_store%rel_indexes(curdatindex) + & diag_chaninfo_store%var_usage(curdatindex) diag_chaninfo_store%var_usage(curdatindex) = 0 #ifdef _DEBUG_MEM_ print *, "diag_chaninfo_store%rel_indexes(curdatindex) is now:" print *, diag_chaninfo_store%rel_indexes(curdatindex) #endif end if end if end do ! If we're flushing data, don't do anything... if (present(flush_data_only) .AND. flush_data_only) then #ifdef _DEBUG_MEM_ print *, "In buffer flush mode!" #endif else ! Otherwise, lock data writing! Note that we do this, ! even if we have no data! diag_chaninfo_store%data_lock = .TRUE. #ifdef _DEBUG_MEM_ print *, "In data lock mode!" #endif end if else call nclayer_error("Can't write data - data have already been written and locked!") end if else call nclayer_error("Can't write data - number of chans not set yet!") end if end if else call nclayer_error("Can't write data - NetCDF4 layer not initialized yet!") end if end subroutine nc_diag_chaninfo_write_data ! Set the strict mode for chaninfo variables. ! ! This sets the mode that determines how strict chaninfo's ! variable consistency checks will be. ! ! During the final data write (nc_diag_chaninfo_write_data, ! without the buffering flag), chaninfo will check to see if all ! of the variables are filled, e.g. all variables have been ! stored up to nchans dimension. ! ! If there are any variables that are not completely filled to ! the nchans dimension, one of the following may occur: ! ! -> If strict mode is enabled, a consistency check error will ! occur and the program will exit. ! ! -> If strict mode is disabled, this will only result in a ! consistency check warning. After the warning is ! displayed, normal operation will occur, including data ! writing. For values that are not in the variable (up to ! the nchans dimension), missing values will be placed. ! ! By default, strict mode is disabled. ! ! Since the strict mode is bound to the chaninfo type, it can ! only be set when a file is open and when diag_chaninfo_store ! is initialized. (It should be initialized if a file is open!) ! ! If there isn't a file open / diag_chaninfo_store isn't ! initialized, an error will occur. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! ! ! Args: ! enable_strict (logical): boolean indicating whether to ! enable strict mode or not. If set to TRUE, strict mode ! will be enabled. Otherwise, it will be disabled. ! ! Raises: ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Although unlikely, other errors may indirectly occur. ! They may be general storage errors, or even a bug. ! See the called subroutines' documentation for details. ! subroutine nc_diag_chaninfo_set_strict(enable_strict) logical, intent(in) :: enable_strict if (init_done .AND. allocated(diag_chaninfo_store)) then diag_chaninfo_store%strict_check = enable_strict else call nclayer_error("Can't set strictness level for chaninfo - NetCDF4 layer not initialized yet!") end if end subroutine nc_diag_chaninfo_set_strict ! Preallocate variable metadata storage (names, types, etc.). ! ! This preallocates variable metadata storage for a given number ! of variables. ! ! If properly defined, this can speed up chaninfo variable ! creation since reallocation will (hopefully) not be necessary ! for variable metadata storage, since it was preallocated here. ! ! Variable metadata includes storing the variables' names, ! types, indicies, usage counts, etc. The metadata pre-allocated ! here is essentially the variable indexed arrays within our ! specific storage type! ! ! Args: ! num_of_addl_vars (integer(i_llong)): the number of ! additional variables to preallocate metadata storage ! for. ! ! Raises: ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_prealloc_vars(num_of_addl_vars) integer(i_llong), intent(in) :: num_of_addl_vars #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, I0, A)") "nc_diag_chaninfo_prealloc_vars(num_of_addl_vars = ", num_of_addl_vars, ")" call nclayer_actionm(trim(action_str)) end if #endif if (init_done .AND. allocated(diag_chaninfo_store)) then ! For all variable metadata fields: ! -> Check if the field is allocated. ! -> If not, allocate it with the default initial ! size, plus the number of additional variables ! specified in the argument. ! -> If it's allocated, check to see if the total ! number of variables exceeds our field's allocated ! size. ! -> If the size is exceeded, reallocate the field ! with the number of additional variables specified ! in the argument. ! if (allocated(diag_chaninfo_store%names)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%names)) then call nc_diag_realloc(diag_chaninfo_store%names, num_of_addl_vars) end if else allocate(diag_chaninfo_store%names(NLAYER_DEFAULT_ENT + num_of_addl_vars)) end if if (allocated(diag_chaninfo_store%types)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%types)) then call nc_diag_realloc(diag_chaninfo_store%types, num_of_addl_vars) end if else allocate(diag_chaninfo_store%types(NLAYER_DEFAULT_ENT + num_of_addl_vars)) end if if (allocated(diag_chaninfo_store%var_rel_pos)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%var_rel_pos)) then call nc_diag_realloc(diag_chaninfo_store%var_rel_pos, num_of_addl_vars) end if else allocate(diag_chaninfo_store%var_rel_pos(NLAYER_DEFAULT_ENT + num_of_addl_vars)) diag_chaninfo_store%var_rel_pos = -1 end if if (allocated(diag_chaninfo_store%var_usage)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%var_usage)) then call nc_diag_realloc(diag_chaninfo_store%var_usage, num_of_addl_vars) end if else allocate(diag_chaninfo_store%var_usage(NLAYER_DEFAULT_ENT + num_of_addl_vars)) diag_chaninfo_store%var_usage = 0 end if if (allocated(diag_chaninfo_store%var_ids)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%var_ids)) then call nc_diag_realloc(diag_chaninfo_store%var_ids, num_of_addl_vars) end if else allocate(diag_chaninfo_store%var_ids(NLAYER_DEFAULT_ENT + num_of_addl_vars)) diag_chaninfo_store%var_ids = -1 end if if (allocated(diag_chaninfo_store%max_str_lens)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%max_str_lens)) then call nc_diag_realloc(diag_chaninfo_store%max_str_lens, num_of_addl_vars) end if else allocate(diag_chaninfo_store%max_str_lens(NLAYER_DEFAULT_ENT + num_of_addl_vars)) diag_chaninfo_store%max_str_lens = -1 end if if (allocated(diag_chaninfo_store%rel_indexes)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%rel_indexes)) then call nc_diag_realloc(diag_chaninfo_store%rel_indexes, num_of_addl_vars) end if else allocate(diag_chaninfo_store%rel_indexes(NLAYER_DEFAULT_ENT + num_of_addl_vars)) diag_chaninfo_store%rel_indexes = 0 end if else call nclayer_error("NetCDF4 layer not initialized yet!") endif end subroutine nc_diag_chaninfo_prealloc_vars ! Preallocate actual variable data storage - the data itself. ! ! This preallocates the variable data storage for a given ! variable type, and a given number of data elements or slots. ! ! If properly defined, this can speed up chaninfo variable ! data insertion since reallocation will (hopefully) not be ! necessary for variable data storage, since it was preallocated ! here. ! ! For example, if you have 10 float chaninfo variables, and ! nchans is 20, you can call: ! ! nc_diag_chaninfo_prealloc_vars_storage(NLAYER_FLOAT, 200) ! ! Assuming that no other float chaninfo variables get added, ! no reallocations should occur, therefore speeding up the ! variable data insertion process! ! ! Note that this is a state-based subroutine call - by design, ! it preallocates the largest amount provided. For instance, if ! you attempted to preallocate 10 floats, then 9000 floats, then ! 5 floats, 20 floats will be preallocated. ! ! Specifically, it looks like this: ! ! -> Preallocate 10 floats - nothing allocated, so 10 floats ! allocated. ! ! -> Preallocate 9000 floats - only 10 floats allocated, so ! reallocating to 9000. ! ! -> Preallocate 20 floats - 9000 floats already allocated, so ! no need to do anything. ! ! Args: ! nclayer_type (integer(i_byte)): the type of variable to ! preallocate data elements/slots for. ! num_of_addl_slots (integer(i_llong)): the number of ! additional variable data elements/slots to ! preallocate. ! ! Raises: ! If the variable type is invalid, this will result in an ! error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_prealloc_vars_storage(nclayer_type, num_of_addl_slots) integer(i_byte), intent(in) :: nclayer_type integer(i_llong), intent(in) :: num_of_addl_slots #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, I0, A, I0, A)") "nc_diag_chaninfo_prealloc_vars_storage(nclayer_type = ", nclayer_type, ", num_of_addl_slots = ", num_of_addl_slots, ")" call nclayer_actionm(trim(action_str)) end if #endif ! Find the type specified, and attempt to pre-allocate. ! Note that FALSE is specified as an argument to ensure that ! the actual variable data storage usage count isn't ! incremented, since we're just preallocating here. ! if (nclayer_type == NLAYER_BYTE) then call nc_diag_chaninfo_resize_byte(num_of_addl_slots, .FALSE.) else if (nclayer_type == NLAYER_SHORT) then call nc_diag_chaninfo_resize_short(num_of_addl_slots, .FALSE.) else if (nclayer_type == NLAYER_LONG) then call nc_diag_chaninfo_resize_long(num_of_addl_slots, .FALSE.) else if (nclayer_type == NLAYER_FLOAT) then call nc_diag_chaninfo_resize_rsingle(num_of_addl_slots, .FALSE.) else if (nclayer_type == NLAYER_DOUBLE) then call nc_diag_chaninfo_resize_rdouble(num_of_addl_slots, .FALSE.) else if (nclayer_type == NLAYER_STRING) then call nc_diag_chaninfo_resize_string(num_of_addl_slots, .FALSE.) else call nclayer_error("Invalid type specified for variable storage preallocation!") end if end subroutine nc_diag_chaninfo_prealloc_vars_storage ! Expand variable metadata storage (names, types, etc.) for one ! single variable. ! ! This ensures that there is enough variable metadata storage to ! add a single variable. If there isn't enough storage, it will ! reallocate as necessary. See this module's header for more ! information about how memory allocation works for variable ! metadata storage. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! ! ! Args: ! num_of_addl_vars (integer(i_llong)): the number of ! additional variables to preallocate metadata storage ! for. ! ! Raises: ! If nchans has not been set yet, this will result in an ! error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_expand integer(i_llong) :: addl_fields ! Did we realloc at all? logical :: meta_realloc meta_realloc = .FALSE. if (init_done .AND. allocated(diag_chaninfo_store)) then addl_fields = 1 + (NLAYER_DEFAULT_ENT * (NLAYER_MULTI_BASE ** diag_chaninfo_store%alloc_multi)) if (diag_chaninfo_store%nchans /= -1) then ! For all variable metadata fields: ! -> Check if the field is allocated. ! -> If not, allocate it with the default initial ! size, and initialize it with blank values! ! -> If it's allocated, check to see if the total ! number of variables exceeds our field's ! allocated size. ! -> If the size is exceeded, reallocate the ! field, and indicate that a reallocation has ! occurred. ! if (allocated(diag_chaninfo_store%names)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%names)) then call nc_diag_realloc(diag_chaninfo_store%names, addl_fields) meta_realloc = .TRUE. end if else allocate(diag_chaninfo_store%names(NLAYER_DEFAULT_ENT)) end if if (allocated(diag_chaninfo_store%types)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%types)) then call nc_diag_realloc(diag_chaninfo_store%types, addl_fields) meta_realloc = .TRUE. end if else allocate(diag_chaninfo_store%types(NLAYER_DEFAULT_ENT)) end if if (allocated(diag_chaninfo_store%var_rel_pos)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%var_rel_pos)) then call nc_diag_realloc(diag_chaninfo_store%var_rel_pos, addl_fields) meta_realloc = .TRUE. end if else allocate(diag_chaninfo_store%var_rel_pos(NLAYER_DEFAULT_ENT)) diag_chaninfo_store%var_rel_pos = -1 end if if (allocated(diag_chaninfo_store%var_usage)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%var_usage)) then call nc_diag_realloc(diag_chaninfo_store%var_usage, addl_fields) meta_realloc = .TRUE. end if else allocate(diag_chaninfo_store%var_usage(NLAYER_DEFAULT_ENT)) diag_chaninfo_store%var_usage = 0 end if if (allocated(diag_chaninfo_store%var_ids)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%var_ids)) then call nc_diag_realloc(diag_chaninfo_store%var_ids, addl_fields) meta_realloc = .TRUE. end if else allocate(diag_chaninfo_store%var_ids(NLAYER_DEFAULT_ENT)) diag_chaninfo_store%var_ids = -1 end if if (allocated(diag_chaninfo_store%max_str_lens)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%max_str_lens)) then call nc_diag_realloc(diag_chaninfo_store%max_str_lens, addl_fields) meta_realloc = .TRUE. end if else allocate(diag_chaninfo_store%max_str_lens(NLAYER_DEFAULT_ENT)) diag_chaninfo_store%max_str_lens = -1 end if if (allocated(diag_chaninfo_store%rel_indexes)) then if (diag_chaninfo_store%total >= size(diag_chaninfo_store%rel_indexes)) then call nc_diag_realloc(diag_chaninfo_store%rel_indexes, addl_fields) meta_realloc = .TRUE. end if else allocate(diag_chaninfo_store%rel_indexes(NLAYER_DEFAULT_ENT)) diag_chaninfo_store%rel_indexes = 0 end if ! If reallocation occurred, increment our multiplier ! to allocate more and speed things up in the ! future! if (meta_realloc) then diag_chaninfo_store%alloc_multi = diag_chaninfo_store%alloc_multi + 1 end if else call nclayer_error("Number of chans not set yet!") end if else call nclayer_error("NetCDF4 layer not initialized yet!") end if end subroutine nc_diag_chaninfo_expand ! Add a single scalar byte integer to the given chaninfo ! variable. ! ! This adds a single value to the specified chaninfo variable. ! ! If the variable does not already exist, it will be created, ! and the value will be inserted as the variable's first ! element. ! ! Otherwise, the value will be inserted to the next empty spot. ! ! Values are inserted in the order of the calls made. As such, ! this subroutine is best designed to be used in a loop, where ! for every channel iteration, a value is added using this ! subroutine. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! (You should use the generic nc_diag_chaninfo ! instead!) ! ! Args: ! chaninfo_name (character(len=*)): the chaninfo variable ! to store to. ! chaninfo_value (integer(i_byte)): the value to store. ! ! Raises: ! If the data has already been locked, this will result in ! an error. ! ! If definitions have already been locked, and a new ! variable is being created, this will result in an error. ! ! If the variable is already full (e.g. it has nchans number ! of elements), this will result in an error. ! ! The following errors will trigger indirectly from other ! subroutines called here: ! ! If nchans has not been set yet, this will result in an ! error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_byte(chaninfo_name, chaninfo_value) character(len=*), intent(in) :: chaninfo_name integer(i_byte), intent(in) :: chaninfo_value integer(i_long) :: i, var_index, var_rel_index, type_index #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, I0, A)") "nc_diag_chaninfo_byte(chaninfo_name = " // chaninfo_name // ", chaninfo_value = ", chaninfo_value, ")" call nclayer_actionm(trim(action_str)) end if #endif ! Make sure that data hasn't been locked if (diag_chaninfo_store%data_lock) then call nclayer_error("Can't add new data - data have already been written and locked!") end if ! For byte, type index is 1 type_index = 1 ! Default to -1 var_index = -1 ! Attempt to match the variable name + fetch the variable ! index first! do i = 1, diag_chaninfo_store%total if (diag_chaninfo_store%names(i) == chaninfo_name) then var_rel_index = diag_chaninfo_store%var_rel_pos(i) var_index = i exit end if end do if (var_index == -1) then ! Entry does not exist yet... ! First, check to make sure we can still define new variables. if (diag_chaninfo_store%def_lock) then call nclayer_error("Can't add new variable - definitions have already been written and locked!") end if ! Expand variable metadata first! ! Make sure we have enough variable metadata storage ! (and if not, reallocate!) call nc_diag_chaninfo_expand ! Add to the total! diag_chaninfo_store%total = diag_chaninfo_store%total + 1 ! Store name and type! diag_chaninfo_store%names(diag_chaninfo_store%total) = chaninfo_name diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_BYTE ! We just need to add one entry... ! Call resize subroutine to ensure we have enough space ! (and if not, realloc!) call nc_diag_chaninfo_resize_byte(int8(diag_chaninfo_store%nchans)) ! Now add a relative position... based on the next position! ! First, increment the number of variables stored for this type: diag_chaninfo_store%acount_v(type_index) = diag_chaninfo_store%acount_v(type_index) + 1 ! Then, set the next variable's relative positioning, ! based on the number of variables stored for this type. diag_chaninfo_store%var_rel_pos(diag_chaninfo_store%total) = diag_chaninfo_store%acount_v(type_index) ! Initialize the amount of memory used to 1. diag_chaninfo_store%var_usage(diag_chaninfo_store%total) = 1 ! Set var_index to the total var_index = diag_chaninfo_store%total else ! Variable already exists! ! Check to make sure we can fit more data! ! (# data < nchans) if (diag_chaninfo_store%var_usage(var_index) + & diag_chaninfo_store%rel_indexes(var_index) >= diag_chaninfo_store%nchans) then call nclayer_error("Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.") endif ! Increment current variable count diag_chaninfo_store%var_usage(var_index) = & diag_chaninfo_store%var_usage(var_index) + 1 end if ! Now add the actual entry! diag_chaninfo_store%ci_byte(1 + & ((diag_chaninfo_store%var_rel_pos(var_index) - 1) & * diag_chaninfo_store%nchans) & + (diag_chaninfo_store%var_usage(var_index) - 1)) = chaninfo_value end subroutine nc_diag_chaninfo_byte ! Add a single scalar short integer to the given chaninfo ! variable. ! ! This adds a single value to the specified chaninfo variable. ! ! If the variable does not already exist, it will be created, ! and the value will be inserted as the variable's first ! element. ! ! Otherwise, the value will be inserted to the next empty spot. ! ! Values are inserted in the order of the calls made. As such, ! this subroutine is best designed to be used in a loop, where ! for every channel iteration, a value is added using this ! subroutine. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! (You should use the generic nc_diag_chaninfo ! instead!) ! ! Args: ! chaninfo_name (character(len=*)): the chaninfo variable ! to store to. ! chaninfo_value (integer(i_short)): the value to store. ! ! Raises: ! If the data has already been locked, this will result in ! an error. ! ! If definitions have already been locked, and a new ! variable is being created, this will result in an error. ! ! If the variable is already full (e.g. it has nchans number ! of elements), this will result in an error. ! ! The following errors will trigger indirectly from other ! subroutines called here: ! ! If nchans has not been set yet, this will result in an ! error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_short(chaninfo_name, chaninfo_value) character(len=*), intent(in) :: chaninfo_name integer(i_short), intent(in) :: chaninfo_value integer(i_long) :: i, var_index, var_rel_index, type_index #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, I0, A)") "nc_diag_chaninfo_short(chaninfo_name = " // chaninfo_name // ", chaninfo_value = ", chaninfo_value, ")" call nclayer_actionm(trim(action_str)) end if #endif ! Make sure that data hasn't been locked if (diag_chaninfo_store%data_lock) then call nclayer_error("Can't add new data - data have already been written and locked!") end if ! For short, type index is 2 type_index = 2 ! Default to -1 var_index = -1 ! Attempt to match the variable name + fetch the variable ! index first! do i = 1, diag_chaninfo_store%total if (diag_chaninfo_store%names(i) == chaninfo_name) then var_rel_index = diag_chaninfo_store%var_rel_pos(i) var_index = i exit end if end do if (var_index == -1) then ! Entry does not exist yet... ! First, check to make sure we can still define new variables. if (diag_chaninfo_store%def_lock) then call nclayer_error("Can't add new variable - definitions have already been written and locked!") end if ! Expand variable metadata first! ! Make sure we have enough variable metadata storage ! (and if not, reallocate!) call nc_diag_chaninfo_expand ! Add to the total! diag_chaninfo_store%total = diag_chaninfo_store%total + 1 ! Store name and type! diag_chaninfo_store%names(diag_chaninfo_store%total) = chaninfo_name diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_SHORT ! We just need to add one entry... ! Call resize subroutine to ensure we have enough space ! (and if not, realloc!) call nc_diag_chaninfo_resize_short(int8(diag_chaninfo_store%nchans)) ! Now add a relative position... based on the next position! ! First, increment the number of variables stored for this type: diag_chaninfo_store%acount_v(type_index) = diag_chaninfo_store%acount_v(type_index) + 1 ! Then, set the next variable's relative positioning, ! based on the number of variables stored for this type. diag_chaninfo_store%var_rel_pos(diag_chaninfo_store%total) = diag_chaninfo_store%acount_v(type_index) ! Initialize the amount of memory used to 1. diag_chaninfo_store%var_usage(diag_chaninfo_store%total) = 1 ! Set var_index to the total var_index = diag_chaninfo_store%total else ! Variable already exists! ! Check to make sure we can fit more data! ! (# data < nchans) if (diag_chaninfo_store%var_usage(var_index) + & diag_chaninfo_store%rel_indexes(var_index) >= diag_chaninfo_store%nchans) then call nclayer_error("Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.") endif ! Increment current variable count diag_chaninfo_store%var_usage(var_index) = & diag_chaninfo_store%var_usage(var_index) + 1 end if ! Now add the actual entry! diag_chaninfo_store%ci_short(1 + & ((diag_chaninfo_store%var_rel_pos(var_index) - 1) & * diag_chaninfo_store%nchans) & + (diag_chaninfo_store%var_usage(var_index) - 1)) = chaninfo_value end subroutine nc_diag_chaninfo_short ! Add a single scalar long integer to the given chaninfo ! variable. (This is NOT a NetCDF "long", just a NetCDF "int".) ! ! This adds a single value to the specified chaninfo variable. ! ! If the variable does not already exist, it will be created, ! and the value will be inserted as the variable's first ! element. ! ! Otherwise, the value will be inserted to the next empty spot. ! ! Values are inserted in the order of the calls made. As such, ! this subroutine is best designed to be used in a loop, where ! for every channel iteration, a value is added using this ! subroutine. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! (You should use the generic nc_diag_chaninfo ! instead!) ! ! Args: ! chaninfo_name (character(len=*)): the chaninfo variable ! to store to. ! chaninfo_value (integer(i_long)): the value to store. ! ! Raises: ! If the data has already been locked, this will result in ! an error. ! ! If definitions have already been locked, and a new ! variable is being created, this will result in an error. ! ! If the variable is already full (e.g. it has nchans number ! of elements), this will result in an error. ! ! The following errors will trigger indirectly from other ! subroutines called here: ! ! If nchans has not been set yet, this will result in an ! error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_long(chaninfo_name, chaninfo_value) character(len=*), intent(in) :: chaninfo_name integer(i_long), intent(in) :: chaninfo_value integer(i_long) :: i, var_index, var_rel_index, type_index #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, I0, A)") "nc_diag_chaninfo_long(chaninfo_name = " // chaninfo_name // ", chaninfo_value = ", chaninfo_value, ")" call nclayer_actionm(trim(action_str)) end if #endif ! Make sure that data hasn't been locked if (diag_chaninfo_store%data_lock) then call nclayer_error("Can't add new data - data have already been written and locked!") end if ! For long, type index is 3 type_index = 3 ! Default to -1 var_index = -1 ! Attempt to match the variable name + fetch the variable ! index first! do i = 1, diag_chaninfo_store%total if (diag_chaninfo_store%names(i) == chaninfo_name) then var_rel_index = diag_chaninfo_store%var_rel_pos(i) var_index = i exit end if end do #ifdef _DEBUG_MEM_ print *, " *** chaninfo_name" print *, chaninfo_name print *, " *** var_index is set to:" print *, var_index #endif if (var_index == -1) then ! Entry does not exist yet... ! First, check to make sure we can still define new variables. if (diag_chaninfo_store%def_lock) then call nclayer_error("Can't add new variable - definitions have already been written and locked!") end if ! Expand variable metadata first! ! Make sure we have enough variable metadata storage ! (and if not, reallocate!) call nc_diag_chaninfo_expand ! Add to the total! diag_chaninfo_store%total = diag_chaninfo_store%total + 1 ! Store name and type! diag_chaninfo_store%names(diag_chaninfo_store%total) = chaninfo_name diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_LONG ! We just need to add one entry... ! Call resize subroutine to ensure we have enough space ! (and if not, realloc!) call nc_diag_chaninfo_resize_long(int8(diag_chaninfo_store%nchans)) ! Now add a relative position... based on the next position! ! First, increment the number of variables stored for this type: diag_chaninfo_store%acount_v(type_index) = diag_chaninfo_store%acount_v(type_index) + 1 ! Then, set the next variable's relative positioning, ! based on the number of variables stored for this type. diag_chaninfo_store%var_rel_pos(diag_chaninfo_store%total) = diag_chaninfo_store%acount_v(type_index) ! Initialize the amount of memory used to 1. diag_chaninfo_store%var_usage(diag_chaninfo_store%total) = 1 ! Set var_index to the total var_index = diag_chaninfo_store%total else ! Variable already exists! ! Check to make sure we can fit more data! ! (# data < nchans) if (diag_chaninfo_store%var_usage(var_index) + & diag_chaninfo_store%rel_indexes(var_index) >= diag_chaninfo_store%nchans) then #ifdef _DEBUG_MEM_ print *, "!!!! diag_chaninfo_store%var_usage(var_index)" print *, diag_chaninfo_store%var_usage(var_index) #endif call nclayer_error("Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.") endif ! Increment current variable count diag_chaninfo_store%var_usage(var_index) = & diag_chaninfo_store%var_usage(var_index) + 1 end if ! Now add the actual entry! #ifdef _DEBUG_MEM_ print *, "====================================" print *, "diag_chaninfo_store%total" print *, diag_chaninfo_store%total print *, "var_index" print *, var_index print *, "diag_chaninfo_store%var_rel_pos(var_index)" print *, diag_chaninfo_store%var_rel_pos(var_index) print *, "diag_chaninfo_store%nchans" print *, diag_chaninfo_store%nchans print *, "diag_chaninfo_store%var_usage(var_index)" print *, diag_chaninfo_store%var_usage(var_index) print *, "====================================" #endif diag_chaninfo_store%ci_long(1 + & ((diag_chaninfo_store%var_rel_pos(var_index) - 1) & * diag_chaninfo_store%nchans) & + (diag_chaninfo_store%var_usage(var_index) - 1)) = chaninfo_value end subroutine nc_diag_chaninfo_long ! Add a single scalar float to the given chaninfo variable. ! ! This adds a single value to the specified chaninfo variable. ! ! If the variable does not already exist, it will be created, ! and the value will be inserted as the variable's first ! element. ! ! Otherwise, the value will be inserted to the next empty spot. ! ! Values are inserted in the order of the calls made. As such, ! this subroutine is best designed to be used in a loop, where ! for every channel iteration, a value is added using this ! subroutine. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! (You should use the generic nc_diag_chaninfo ! instead!) ! ! Args: ! chaninfo_name (character(len=*)): the chaninfo variable ! to store to. ! chaninfo_value (real(r_single)): the value to store. ! ! Raises: ! If the data has already been locked, this will result in ! an error. ! ! If definitions have already been locked, and a new ! variable is being created, this will result in an error. ! ! If the variable is already full (e.g. it has nchans number ! of elements), this will result in an error. ! ! The following errors will trigger indirectly from other ! subroutines called here: ! ! If nchans has not been set yet, this will result in an ! error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_rsingle(chaninfo_name, chaninfo_value) character(len=*), intent(in) :: chaninfo_name real(r_single), intent(in) :: chaninfo_value integer(i_long) :: i, var_index, var_rel_index, type_index #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, F0.5, A)") "nc_diag_chaninfo_rsingle(chaninfo_name = " // chaninfo_name // ", chaninfo_value = ", chaninfo_value, ")" call nclayer_actionm(trim(action_str)) end if #endif ! Make sure that data hasn't been locked if (diag_chaninfo_store%data_lock) then call nclayer_error("Can't add new data - data have already been written and locked!") end if ! For rsingle, type index is 4 type_index = 4 ! Default to -1 var_index = -1 ! Attempt to match the variable name + fetch the variable ! index first! do i = 1, diag_chaninfo_store%total if (diag_chaninfo_store%names(i) == chaninfo_name) then var_rel_index = diag_chaninfo_store%var_rel_pos(i) var_index = i exit end if end do #ifdef _DEBUG_MEM_ print *, " *** chaninfo_name" print *, chaninfo_name print *, " *** var_index is set to:" print *, var_index #endif if (var_index == -1) then ! Entry does not exist yet... ! First, check to make sure we can still define new variables. if (diag_chaninfo_store%def_lock) then call nclayer_error("Can't add new variable - definitions have already been written and locked!") end if ! Expand variable metadata first! ! Make sure we have enough variable metadata storage ! (and if not, reallocate!) call nc_diag_chaninfo_expand ! Add to the total! diag_chaninfo_store%total = diag_chaninfo_store%total + 1 ! Store name and type! diag_chaninfo_store%names(diag_chaninfo_store%total) = chaninfo_name diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_FLOAT ! We just need to add one entry... ! Call resize subroutine to ensure we have enough space ! (and if not, realloc!) call nc_diag_chaninfo_resize_rsingle(int8(diag_chaninfo_store%nchans)) ! Now add a relative position... based on the next position! ! First, increment the number of variables stored for this type: diag_chaninfo_store%acount_v(type_index) = diag_chaninfo_store%acount_v(type_index) + 1 ! Then, set the next variable's relative positioning, ! based on the number of variables stored for this type. diag_chaninfo_store%var_rel_pos(diag_chaninfo_store%total) = diag_chaninfo_store%acount_v(type_index) ! Initialize the amount of memory used to 1. diag_chaninfo_store%var_usage(diag_chaninfo_store%total) = 1 ! Set var_index to the total var_index = diag_chaninfo_store%total else ! Variable already exists! ! Check to make sure we can fit more data! ! (# data < nchans) if (diag_chaninfo_store%var_usage(var_index) + & diag_chaninfo_store%rel_indexes(var_index) >= diag_chaninfo_store%nchans) then call nclayer_error("Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.") endif ! Increment current variable count diag_chaninfo_store%var_usage(var_index) = & diag_chaninfo_store%var_usage(var_index) + 1 end if #ifdef _DEBUG_MEM_ print *, "====================================" print *, "diag_chaninfo_store%total" print *, diag_chaninfo_store%total print *, "var_index" print *, var_index print *, "diag_chaninfo_store%var_rel_pos(var_index)" print *, diag_chaninfo_store%var_rel_pos(var_index) print *, "diag_chaninfo_store%nchans" print *, diag_chaninfo_store%nchans print *, "diag_chaninfo_store%var_usage(var_index)" print *, diag_chaninfo_store%var_usage(var_index) print *, "====================================" #endif ! Now add the actual entry! diag_chaninfo_store%ci_rsingle(1 + & ((diag_chaninfo_store%var_rel_pos(var_index) - 1) & * diag_chaninfo_store%nchans) & + (diag_chaninfo_store%var_usage(var_index) - 1)) = chaninfo_value end subroutine nc_diag_chaninfo_rsingle ! Add a single scalar double to the given chaninfo variable. ! ! This adds a single value to the specified chaninfo variable. ! ! If the variable does not already exist, it will be created, ! and the value will be inserted as the variable's first ! element. ! ! Otherwise, the value will be inserted to the next empty spot. ! ! Values are inserted in the order of the calls made. As such, ! this subroutine is best designed to be used in a loop, where ! for every channel iteration, a value is added using this ! subroutine. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! (You should use the generic nc_diag_chaninfo ! instead!) ! ! Args: ! chaninfo_name (character(len=*)): the chaninfo variable ! to store to. ! chaninfo_value (real(r_double)): the value to store. ! ! Raises: ! If the data has already been locked, this will result in ! an error. ! ! If definitions have already been locked, and a new ! variable is being created, this will result in an error. ! ! If the variable is already full (e.g. it has nchans number ! of elements), this will result in an error. ! ! The following errors will trigger indirectly from other ! subroutines called here: ! ! If nchans has not been set yet, this will result in an ! error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_rdouble(chaninfo_name, chaninfo_value) character(len=*), intent(in) :: chaninfo_name real(r_double), intent(in) :: chaninfo_value integer(i_long) :: i, var_index, var_rel_index, type_index #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A, F0.5, A)") "nc_diag_chaninfo_rdouble(chaninfo_name = " // chaninfo_name // ", chaninfo_value = ", chaninfo_value, ")" call nclayer_actionm(trim(action_str)) end if #endif ! Make sure that data hasn't been locked if (diag_chaninfo_store%data_lock) then call nclayer_error("Can't add new data - data have already been written and locked!") end if ! For rdouble, type index is 5 type_index = 5 ! Default to -1 var_index = -1 ! Attempt to match the variable name + fetch the variable ! index first! do i = 1, diag_chaninfo_store%total if (diag_chaninfo_store%names(i) == chaninfo_name) then var_rel_index = diag_chaninfo_store%var_rel_pos(i) var_index = i exit end if end do if (var_index == -1) then ! Entry does not exist yet... ! First, check to make sure we can still define new variables. if (diag_chaninfo_store%def_lock) then call nclayer_error("Can't add new variable - definitions have already been written and locked!") end if ! Expand variable metadata first! ! Make sure we have enough variable metadata storage ! (and if not, reallocate!) call nc_diag_chaninfo_expand ! Add to the total! diag_chaninfo_store%total = diag_chaninfo_store%total + 1 ! Store name and type! diag_chaninfo_store%names(diag_chaninfo_store%total) = chaninfo_name diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_DOUBLE ! We just need to add one entry... ! Call resize subroutine to ensure we have enough space ! (and if not, realloc!) call nc_diag_chaninfo_resize_rdouble(int8(diag_chaninfo_store%nchans)) ! Now add a relative position... based on the next position! ! First, increment the number of variables stored for this type: diag_chaninfo_store%acount_v(type_index) = diag_chaninfo_store%acount_v(type_index) + 1 ! Then, set the next variable's relative positioning, ! based on the number of variables stored for this type. diag_chaninfo_store%var_rel_pos(diag_chaninfo_store%total) = diag_chaninfo_store%acount_v(type_index) ! Initialize the amount of memory used to 1. diag_chaninfo_store%var_usage(diag_chaninfo_store%total) = 1 ! Set var_index to the total var_index = diag_chaninfo_store%total else ! Variable already exists! ! Check to make sure we can fit more data! ! (# data < nchans) if (diag_chaninfo_store%var_usage(var_index) + & diag_chaninfo_store%rel_indexes(var_index) >= diag_chaninfo_store%nchans) then call nclayer_error("Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.") endif ! Increment current variable count diag_chaninfo_store%var_usage(var_index) = & diag_chaninfo_store%var_usage(var_index) + 1 end if ! Now add the actual entry! diag_chaninfo_store%ci_rdouble(1 + & ((diag_chaninfo_store%var_rel_pos(var_index) - 1) & * diag_chaninfo_store%nchans) & + (diag_chaninfo_store%var_usage(var_index) - 1)) = chaninfo_value end subroutine nc_diag_chaninfo_rdouble ! Add a single scalar string to the given chaninfo variable. ! (This uses the NetCDF char type, stored internally as a 2D ! array of characters.) ! ! This adds a single value to the specified chaninfo variable. ! ! If the variable does not already exist, it will be created, ! and the value will be inserted as the variable's first ! element. ! ! Otherwise, the value will be inserted to the next empty spot. ! ! Values are inserted in the order of the calls made. As such, ! this subroutine is best designed to be used in a loop, where ! for every channel iteration, a value is added using this ! subroutine. ! ! This is an internal subroutine, and is NOT meant to be called ! outside of nc_diag_write. Calling this subroutine in your ! program may result in unexpected behavior and/or data ! corruption! (You should use the generic nc_diag_chaninfo ! instead!) ! ! Args: ! chaninfo_name (character(len=*)): the chaninfo variable ! to store to. ! chaninfo_value (character(len=*)): the value to store. ! ! Raises: ! If the data has already been locked, this will result in ! an error. ! ! If definitions have already been locked, and a new ! variable is being created, this will result in an error. ! ! If the variable is already full (e.g. it has nchans number ! of elements), this will result in an error. ! ! The following errors will trigger indirectly from other ! subroutines called here: ! ! If nchans has not been set yet, this will result in an ! error. ! ! If there is no file open (or the file is already closed), ! this will result in an error. ! ! Other errors may result from invalid data storage, NetCDF ! errors, or even a bug. See the called subroutines' ! documentation for details. ! subroutine nc_diag_chaninfo_string(chaninfo_name, chaninfo_value) character(len=*), intent(in) :: chaninfo_name character(len=*), intent(in) :: chaninfo_value integer(i_long) :: i, var_index, var_rel_index, type_index #ifdef ENABLE_ACTION_MSGS character(len=1000) :: action_str if (nclayer_enable_action) then write(action_str, "(A)") "nc_diag_chaninfo_string(chaninfo_name = " // chaninfo_name // ", chaninfo_value = " // trim(chaninfo_value) // ")" call nclayer_actionm(trim(action_str)) end if #endif ! Make sure that data hasn't been locked if (diag_chaninfo_store%data_lock) then call nclayer_error("Can't add new data - data have already been written and locked!") end if ! For string, type index is 6 type_index = 6 ! Default to -1 var_index = -1 ! Attempt to match the variable name + fetch the variable ! index first! do i = 1, diag_chaninfo_store%total if (diag_chaninfo_store%names(i) == chaninfo_name) then var_rel_index = diag_chaninfo_store%var_rel_pos(i) var_index = i exit end if end do if (var_index == -1) then ! Entry does not exist yet... ! First, check to make sure we can still define new variables. if (diag_chaninfo_store%def_lock) then call nclayer_error("Can't add new variable - definitions have already been written and locked!") end if ! Expand variable metadata first! ! Make sure we have enough variable metadata storage ! (and if not, reallocate!) call nc_diag_chaninfo_expand ! Add to the total! diag_chaninfo_store%total = diag_chaninfo_store%total + 1 ! Store name and type! diag_chaninfo_store%names(diag_chaninfo_store%total) = chaninfo_name diag_chaninfo_store%types(diag_chaninfo_store%total) = NLAYER_STRING ! We just need to add one entry... ! Call resize subroutine to ensure we have enough space ! (and if not, realloc!) call nc_diag_chaninfo_resize_string(int8(diag_chaninfo_store%nchans)) ! Now add a relative position... based on the next position! ! First, increment the number of variables stored for this type: diag_chaninfo_store%acount_v(type_index) = diag_chaninfo_store%acount_v(type_index) + 1 ! Then, set the next variable's relative positioning, ! based on the number of variables stored for this type. diag_chaninfo_store%var_rel_pos(diag_chaninfo_store%total) = diag_chaninfo_store%acount_v(type_index) ! Initialize the amount of memory used to 1. diag_chaninfo_store%var_usage(diag_chaninfo_store%total) = 1 ! Set var_index to the total var_index = diag_chaninfo_store%total else ! Variable already exists! ! Check to make sure we can fit more data! ! (# data < nchans) if (diag_chaninfo_store%var_usage(var_index) + & diag_chaninfo_store%rel_indexes(var_index) >= diag_chaninfo_store%nchans) then call nclayer_error("Can't add new data - data added is exceeding nchan! Data must fit within nchan constraint.") endif ! Check max string length if ((diag_chaninfo_store%def_lock) .AND. & (len_trim(chaninfo_value) > diag_chaninfo_store%max_str_lens(var_index))) & call nclayer_error("Cannot expand variable string length after locking variable definitions!") ! Increment current variable count diag_chaninfo_store%var_usage(var_index) = & diag_chaninfo_store%var_usage(var_index) + 1 end if ! If trim isn't enabled, set our maximum string length here! if (.NOT. enable_trim) then if (diag_chaninfo_store%max_str_lens(var_index) == -1) then diag_chaninfo_store%max_str_lens(var_index) = len(chaninfo_value) else ! Validate that our non-first value isn't different from ! the initial string length if (diag_chaninfo_store%max_str_lens(var_index) /= len(chaninfo_value)) & call nclayer_error("Cannot change string size when trimming is disabled!") end if end if ! Now add the actual entry! diag_chaninfo_store%ci_string(1 + & ((diag_chaninfo_store%var_rel_pos(var_index) - 1) & * diag_chaninfo_store%nchans) & + (diag_chaninfo_store%var_usage(var_index) - 1)) = chaninfo_value end subroutine nc_diag_chaninfo_string end module ncdw_chaninfo
apache-2.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Blas/ztbmv.f
3
12722
SUBROUTINE ZTBMV(UPLO,TRANS,DIAG,N,K,A,LDA,X,INCX) * .. Scalar Arguments .. INTEGER INCX,K,LDA,N CHARACTER DIAG,TRANS,UPLO * .. * .. Array Arguments .. DOUBLE COMPLEX A(LDA,*),X(*) * .. * * Purpose * ======= * * ZTBMV performs one of the matrix-vector operations * * x := A*x, or x := A**T*x, or x := A**H*x, * * where x is an n element vector and A is an n by n unit, or non-unit, * upper or lower triangular band matrix, with ( k + 1 ) diagonals. * * Arguments * ========== * * UPLO - CHARACTER*1. * On entry, UPLO specifies whether the matrix is an upper or * lower triangular matrix as follows: * * UPLO = 'U' or 'u' A is an upper triangular matrix. * * UPLO = 'L' or 'l' A is a lower triangular matrix. * * Unchanged on exit. * * TRANS - CHARACTER*1. * On entry, TRANS specifies the operation to be performed as * follows: * * TRANS = 'N' or 'n' x := A*x. * * TRANS = 'T' or 't' x := A**T*x. * * TRANS = 'C' or 'c' x := A**H*x. * * Unchanged on exit. * * DIAG - CHARACTER*1. * On entry, DIAG specifies whether or not A is unit * triangular as follows: * * DIAG = 'U' or 'u' A is assumed to be unit triangular. * * DIAG = 'N' or 'n' A is not assumed to be unit * triangular. * * 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 with UPLO = 'U' or 'u', K specifies the number of * super-diagonals of the matrix A. * On entry with UPLO = 'L' or 'l', K specifies the number of * sub-diagonals of the matrix A. * K must satisfy 0 .le. K. * Unchanged on exit. * * A - COMPLEX*16 array of 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 matrix of coefficients, 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 an upper * triangular 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 matrix of coefficients, 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 a lower * triangular 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 * * Note that when DIAG = 'U' or 'u' the elements of the array A * corresponding to the diagonal elements of the matrix are not * referenced, but are assumed to be unity. * 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 of dimension at least * ( 1 + ( n - 1 )*abs( INCX ) ). * Before entry, the incremented array X must contain the n * element vector x. On exit, X is overwritten with the * tranformed vector x. * * INCX - INTEGER. * On entry, INCX specifies the increment for the elements of * X. INCX must not be zero. * Unchanged on exit. * * Further Details * =============== * * Level 2 Blas routine. * The vector and matrix arguments are not referenced when N = 0, or M = 0 * * -- Written on 22-October-1986. * Jack Dongarra, Argonne National Lab. * Jeremy Du Croz, Nag Central Office. * Sven Hammarling, Nag Central Office. * Richard Hanson, Sandia National Labs. * * ===================================================================== * * .. Parameters .. DOUBLE COMPLEX ZERO PARAMETER (ZERO= (0.0D+0,0.0D+0)) * .. * .. Local Scalars .. DOUBLE COMPLEX TEMP INTEGER I,INFO,IX,J,JX,KPLUS1,KX,L LOGICAL NOCONJ,NOUNIT * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC DCONJG,MAX,MIN * .. * * Test the input parameters. * INFO = 0 IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN INFO = 1 ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND. + .NOT.LSAME(TRANS,'C')) THEN INFO = 2 ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN INFO = 3 ELSE IF (N.LT.0) THEN INFO = 4 ELSE IF (K.LT.0) THEN INFO = 5 ELSE IF (LDA.LT. (K+1)) THEN INFO = 7 ELSE IF (INCX.EQ.0) THEN INFO = 9 END IF IF (INFO.NE.0) THEN CALL XERBLA('ZTBMV ',INFO) RETURN END IF * * Quick return if possible. * IF (N.EQ.0) RETURN * NOCONJ = LSAME(TRANS,'T') NOUNIT = LSAME(DIAG,'N') * * Set up the start point in X if the increment is not unity. This * will be ( N - 1 )*INCX too small for descending loops. * IF (INCX.LE.0) THEN KX = 1 - (N-1)*INCX ELSE IF (INCX.NE.1) THEN KX = 1 END IF * * Start the operations. In this version the elements of A are * accessed sequentially with one pass through A. * IF (LSAME(TRANS,'N')) THEN * * Form x := A*x. * IF (LSAME(UPLO,'U')) THEN KPLUS1 = K + 1 IF (INCX.EQ.1) THEN DO 20 J = 1,N IF (X(J).NE.ZERO) THEN TEMP = X(J) L = KPLUS1 - J DO 10 I = MAX(1,J-K),J - 1 X(I) = X(I) + TEMP*A(L+I,J) 10 CONTINUE IF (NOUNIT) X(J) = X(J)*A(KPLUS1,J) END IF 20 CONTINUE ELSE JX = KX DO 40 J = 1,N IF (X(JX).NE.ZERO) THEN TEMP = X(JX) IX = KX L = KPLUS1 - J DO 30 I = MAX(1,J-K),J - 1 X(IX) = X(IX) + TEMP*A(L+I,J) IX = IX + INCX 30 CONTINUE IF (NOUNIT) X(JX) = X(JX)*A(KPLUS1,J) END IF JX = JX + INCX IF (J.GT.K) KX = KX + INCX 40 CONTINUE END IF ELSE IF (INCX.EQ.1) THEN DO 60 J = N,1,-1 IF (X(J).NE.ZERO) THEN TEMP = X(J) L = 1 - J DO 50 I = MIN(N,J+K),J + 1,-1 X(I) = X(I) + TEMP*A(L+I,J) 50 CONTINUE IF (NOUNIT) X(J) = X(J)*A(1,J) END IF 60 CONTINUE ELSE KX = KX + (N-1)*INCX JX = KX DO 80 J = N,1,-1 IF (X(JX).NE.ZERO) THEN TEMP = X(JX) IX = KX L = 1 - J DO 70 I = MIN(N,J+K),J + 1,-1 X(IX) = X(IX) + TEMP*A(L+I,J) IX = IX - INCX 70 CONTINUE IF (NOUNIT) X(JX) = X(JX)*A(1,J) END IF JX = JX - INCX IF ((N-J).GE.K) KX = KX - INCX 80 CONTINUE END IF END IF ELSE * * Form x := A**T*x or x := A**H*x. * IF (LSAME(UPLO,'U')) THEN KPLUS1 = K + 1 IF (INCX.EQ.1) THEN DO 110 J = N,1,-1 TEMP = X(J) L = KPLUS1 - J IF (NOCONJ) THEN IF (NOUNIT) TEMP = TEMP*A(KPLUS1,J) DO 90 I = J - 1,MAX(1,J-K),-1 TEMP = TEMP + A(L+I,J)*X(I) 90 CONTINUE ELSE IF (NOUNIT) TEMP = TEMP*DCONJG(A(KPLUS1,J)) DO 100 I = J - 1,MAX(1,J-K),-1 TEMP = TEMP + DCONJG(A(L+I,J))*X(I) 100 CONTINUE END IF X(J) = TEMP 110 CONTINUE ELSE KX = KX + (N-1)*INCX JX = KX DO 140 J = N,1,-1 TEMP = X(JX) KX = KX - INCX IX = KX L = KPLUS1 - J IF (NOCONJ) THEN IF (NOUNIT) TEMP = TEMP*A(KPLUS1,J) DO 120 I = J - 1,MAX(1,J-K),-1 TEMP = TEMP + A(L+I,J)*X(IX) IX = IX - INCX 120 CONTINUE ELSE IF (NOUNIT) TEMP = TEMP*DCONJG(A(KPLUS1,J)) DO 130 I = J - 1,MAX(1,J-K),-1 TEMP = TEMP + DCONJG(A(L+I,J))*X(IX) IX = IX - INCX 130 CONTINUE END IF X(JX) = TEMP JX = JX - INCX 140 CONTINUE END IF ELSE IF (INCX.EQ.1) THEN DO 170 J = 1,N TEMP = X(J) L = 1 - J IF (NOCONJ) THEN IF (NOUNIT) TEMP = TEMP*A(1,J) DO 150 I = J + 1,MIN(N,J+K) TEMP = TEMP + A(L+I,J)*X(I) 150 CONTINUE ELSE IF (NOUNIT) TEMP = TEMP*DCONJG(A(1,J)) DO 160 I = J + 1,MIN(N,J+K) TEMP = TEMP + DCONJG(A(L+I,J))*X(I) 160 CONTINUE END IF X(J) = TEMP 170 CONTINUE ELSE JX = KX DO 200 J = 1,N TEMP = X(JX) KX = KX + INCX IX = KX L = 1 - J IF (NOCONJ) THEN IF (NOUNIT) TEMP = TEMP*A(1,J) DO 180 I = J + 1,MIN(N,J+K) TEMP = TEMP + A(L+I,J)*X(IX) IX = IX + INCX 180 CONTINUE ELSE IF (NOUNIT) TEMP = TEMP*DCONJG(A(1,J)) DO 190 I = J + 1,MIN(N,J+K) TEMP = TEMP + DCONJG(A(L+I,J))*X(IX) IX = IX + INCX 190 CONTINUE END IF X(JX) = TEMP JX = JX + INCX 200 CONTINUE END IF END IF END IF * RETURN * * End of ZTBMV . * END
apache-2.0
aamaricci/SciFortran
src/lapack/zla_lin_berr.f
1
3314
SUBROUTINE ZLA_LIN_BERR ( N, NZ, NRHS, RES, AYB, BERR ) * * -- LAPACK routine (version 3.2.2) -- * -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- * -- Jason Riedy of Univ. of California Berkeley. -- * -- June 2010 -- * * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley and NAG Ltd. -- * IMPLICIT NONE * .. * .. Scalar Arguments .. INTEGER N, NZ, NRHS * .. * .. Array Arguments .. DOUBLE PRECISION AYB( N, NRHS ), BERR( NRHS ) COMPLEX*16 RES( N, NRHS ) * .. * * Purpose * ======= * * ZLA_LIN_BERR computes componentwise relative backward error from * the formula * max(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) ) * where abs(Z) is the componentwise absolute value of the matrix * or vector Z. * * N (input) INTEGER * The number of linear equations, i.e., the order of the * matrix A. N >= 0. * * NZ (input) INTEGER * We add (NZ+1)*SLAMCH( 'Safe minimum' ) to R(i) in the numerator to * guard against spuriously zero residuals. Default value is N. * * NRHS (input) INTEGER * The number of right hand sides, i.e., the number of columns * of the matrices AYB, RES, and BERR. NRHS >= 0. * * RES (input) DOUBLE PRECISION array, dimension (N,NRHS) * The residual matrix, i.e., the matrix R in the relative backward * error formula above. * * AYB (input) DOUBLE PRECISION array, dimension (N, NRHS) * The denominator in the relative backward error formula above, i.e., * the matrix abs(op(A_s))*abs(Y) + abs(B_s). The matrices A, Y, and B * are from iterative refinement (see zla_gerfsx_extended.f). * * BERR (output) COMPLEX*16 array, dimension (NRHS) * The componentwise relative backward error from the formula above. * * ===================================================================== * * .. Local Scalars .. DOUBLE PRECISION TMP INTEGER I, J COMPLEX*16 CDUM * .. * .. Intrinsic Functions .. INTRINSIC ABS, REAL, DIMAG, MAX * .. * .. External Functions .. EXTERNAL DLAMCH DOUBLE PRECISION DLAMCH DOUBLE PRECISION SAFE1 * .. * .. Statement Functions .. COMPLEX*16 CABS1 * .. * .. Statement Function Definitions .. CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) ) * .. * .. Executable Statements .. * * Adding SAFE1 to the numerator guards against spuriously zero * residuals. A similar safeguard is in the CLA_yyAMV routine used * to compute AYB. * SAFE1 = DLAMCH( 'Safe minimum' ) SAFE1 = (NZ+1)*SAFE1 DO J = 1, NRHS BERR(J) = 0.0D+0 DO I = 1, N IF (AYB(I,J) .NE. 0.0D+0) THEN TMP = (SAFE1 + CABS1(RES(I,J)))/AYB(I,J) BERR(J) = MAX( BERR(J), TMP ) END IF * * If AYB is exactly 0.0 (and if computed by CLA_yyAMV), then we know * the true residual also must be exactly 0.0. * END DO END DO END
lgpl-3.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack95/SRC/la_sstevx.f90
1
8979
! ! -- LAPACK95 interface driver routine (version 3.0) -- ! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK ! September, 2000 ! !---------------------------------------------------------------------- ! ! Purpose ! ======= ! ! LA_STEVX computes selected eigenvalues and, optionally, the ! corresponding eigenvectors of a real symmetric tridiagonal matrix A. ! Eigenvalues and eigenvectors can be selected by specifying either a ! range of values or a range of indices for the desired eigenvalues. ! ! ========= ! ! SUBROUTINE LA_STEVX( D, E, W, Z=z, VL=vl, VU=vu, & ! IL=il, IU=iu, M=m, IFAIL=ifail, & ! ABSTOL=abstol, INFO=info ) ! REAL(<wp>), INTENT(INOUT) :: D(:), E(:) ! REAL(<wp>), INTENT(OUT) :: W(:) ! REAL(<wp>), INTENT(OUT), OPTIONAL :: Z(:,:) ! REAL(<wp>), INTENT(IN), OPTIONAL :: VL, VU ! INTEGER, INTENT(IN), OPTIONAL :: IL, IU ! INTEGER, INTENT(OUT), OPTIONAL :: M ! INTEGER, INTENT(OUT), OPTIONAL :: IFAIL(:) ! REAL(<wp>), INTENT(IN), OPTIONAL :: ABSTOL ! INTEGER, INTENT(OUT), OPTIONAL :: INFO ! where ! <wp> ::= KIND(1.0) | KIND(1.0D0) ! ! Arguments ! ========= ! ! D (input/output) REAL array, shape (:) with size(D) = n, where n ! is the order of A. ! On entry, the diagonal elements of the matrix A. ! On exit, the original contents of D possibly multiplied by a ! constant factor to avoid over/underflow in computing the ! eigenvalues. ! E (input/output) REAL array, shape (:) with size(E) = n. ! On entry, the n-1 subdiagonal elements of A in E(1) to E(n-1). ! E(n) need not be set. ! On exit, the original contents of E possibly multiplied by a ! constant factor to avoid over/underflow in computing the ! eigenvalues. ! W (output) REAL array with size(W) = n. ! The first M elements contain the selected eigenvalues in ! ascending order. ! Z Optional (output) REAL or COMPLEX array, shape (:,:) with ! size(Z,1) = n and size(Z,2) = M. ! The first M columns of Z contain the orthonormal eigenvectors ! of A corresponding to the selected eigenvalues, with the i-th ! column of Z containing the eigenvector associated with the ! eigenvalue in W(i) . If an eigenvector fails to converge, then ! that column of Z contains the latest approximation to the ! eigenvector, and the index of the eigenvector is returned in ! IFAIL. ! Note: The user must ensure that at least M columns are ! supplied in the array Z. When the exact value of M is not ! known in advance, an upper bound must be used. In all cases ! M <= n. ! VL,VU Optional (input) REAL. ! The lower and upper bounds of the interval to be searched for ! eigenvalues. VL < VU. ! Default values: VL = -HUGE(<wp>) and VU = HUGE(<wp>), where ! <wp> ::= KIND(1.0) | KIND(1.0D0). ! Note: Neither VL nor VU may be present if IL and/or IU is ! present. ! IL,IU Optional (input) INTEGER. ! The indices of the smallest and largest eigenvalues to be ! returned. The IL-th through IU-th eigenvalues will be found. ! 1 <= IL <= IU <= n. ! Default values: IL = 1 and IU = n. ! Note: Neither IL nor IU may be present if VL and/or VU is ! present. ! Note: All eigenvalues are calculated if none of the arguments ! VL, VU, IL and IU are present. ! M Optional (output) INTEGER. ! The total number of eigenvalues found. 0 <= M <= n. ! Note: If IL and IU are present then M = IU - IL + 1. ! IFAIL Optional (output) INTEGER array, shape (:) with ! size(IFAIL) = n. ! If INFO = 0, the first M elements of IFAIL are zero. ! If INFO > 0, then IFAIL contains the indices of the ! eigenvectors that failed to converge. ! Note: If Z is present then IFAIL should also be present. ! ABSTOL Optional (input) REAL. ! The absolute error tolerance for the eigenvalues. An ! approximate eigenvalue is accepted as converged when it is ! determined to lie in an interval [a,b] of width less than or ! equal to ABSTOL + EPSILON(1.0_<wp>) * max(|a|,|b|), ! where <wp> is the working precision. If ABSTOL <= 0, then ! EPSILON(1.0_<wp>) * ||A||1 will be used in its place. ! Eigenvalues will be computed most accurately when ABSTOL is ! set to twice the underflow threshold ! 2 * LA_LAMCH(1.0_<wp>, 'Safe minimum'), not zero. ! Default value: 0.0_<wp>. ! Note: If this routine returns with INFO > 0, then some ! eigenvectors did not converge. Try setting ABSTOL to ! 2 * LA_LAMCH(1.0_<wp>, 'Safe minimum'). ! INFO Optional (output) INTEGER ! = 0: successful exit. ! < 0: if INFO = -i, the i-th argument had an illegal value. ! > 0: if INFO = i, then i eigenvectors failed to converge. ! Their indices are stored in array IFAIL. ! If INFO is not present and an error occurs, then the program ! is terminated with an error message. !---------------------------------------------------------------------- SUBROUTINE SSTEVX_F95( D, E, W, Z, VL, VU, IL, IU, M, & IFAIL, ABSTOL, INFO ) ! .. USE STATEMENTS .. USE LA_PRECISION, ONLY: WP => SP USE LA_AUXMOD, ONLY: ERINFO USE F77_LAPACK, ONLY: STEVX_F77 => LA_STEVX, LAMCH_F77 => SLAMCH ! .. IMPLICIT STATEMENT .. IMPLICIT NONE ! .. SCALAR ARGUMENTS .. INTEGER, INTENT(IN), OPTIONAL :: IL, IU INTEGER, INTENT(OUT), OPTIONAL :: INFO, M REAL(WP), INTENT(IN), OPTIONAL :: ABSTOL, VL, VU ! .. ARRAY ARGUMENTS .. INTEGER, INTENT(OUT), OPTIONAL, TARGET :: IFAIL(:) REAL(WP), INTENT(OUT), OPTIONAL, TARGET :: Z(:,:) REAL(WP), INTENT(INOUT) :: D(:), E(:) REAL(WP), INTENT(OUT) :: W(:) ! .. LOCAL PARAMETERS .. CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_STEVX' ! .. LOCAL SCALARS .. CHARACTER(LEN=1) :: LJOBZ, LRANGE INTEGER :: N, LD, LIL, LIU, LM, SIFAIL, S1Z, S2Z INTEGER :: LINFO, ISTAT INTEGER, TARGET :: ISTAT1(1) REAL(WP), TARGET :: LLZ(1,1) REAL(WP) :: LABSTOL, LVL, LVU ! .. LOCAL ARRAYS .. INTEGER, POINTER :: IWORK(:), LIFAIL(:) REAL(WP), POINTER :: WORK(:) ! .. INTRINSIC FUNCTIONS .. INTRINSIC HUGE, PRESENT, SIZE ! .. EXECUTABLE STATEMENTS .. LINFO = 0; ISTAT = 0; N = SIZE(D); LD = MAX(1,N) IF( PRESENT(M)) M = 0 IF( PRESENT(IFAIL) )THEN; SIFAIL = SIZE(IFAIL); ELSE; SIFAIL = N; END IF IF( PRESENT(VL) )THEN; LVL = VL; ELSE; LVL = -HUGE(LVL); ENDIF IF( PRESENT(VU) )THEN; LVU = VU; ELSE; LVU = HUGE(LVU); ENDIF IF( PRESENT(IL) )THEN; LIL = IL; ELSE; LIL = 1; ENDIF IF( PRESENT(IU) )THEN; LIU = IU; ELSE; LIU = N; ENDIF IF( PRESENT(Z) )THEN; S1Z = SIZE(Z,1); S2Z = SIZE(Z,2) ELSE; S1Z = 1; S2Z = 1; ENDIF ! .. TEST THE ARGUMENTS IF( N < 0 ) THEN; LINFO = -1 ELSE IF( SIZE( E ) /= N .AND. N > 0 )THEN; LINFO = -2 ELSE IF( SIZE( W ) /= N )THEN; LINFO = -3 ELSE IF( PRESENT(Z) .AND. ( S1Z /= LD .OR. S2Z /= N ) )THEN; LINFO = -4 ELSE IF( LVU < LVL )THEN; LINFO = -5 ELSE IF( (PRESENT(VL) .OR. PRESENT(VU)) .AND. & & (PRESENT(IL) .OR. PRESENT(IU)) )THEN; LINFO = -6 ELSE IF(( LIU < LIL .OR. LIL < 1) .AND. N>0 )THEN; LINFO = -7 ELSE IF( N < LIU )THEN; LINFO = -8 ELSE IF( SIFAIL /= N .OR. PRESENT(IFAIL).AND..NOT.PRESENT(Z) )THEN; LINFO = -10 ELSE IF( N > 0 )THEN IF( PRESENT(VL) .OR. PRESENT(VU) )THEN; LRANGE = 'V'; LM = N ELSE IF( PRESENT(IL) .OR. PRESENT(IU) )THEN; LRANGE = 'I'; LM = LIU-LIL+1 ELSE; LRANGE = 'A'; LM = N; END IF IF( PRESENT(Z) ) THEN; LJOBZ = 'V' IF( PRESENT(IFAIL) )THEN; LIFAIL => IFAIL ELSE; ALLOCATE( LIFAIL(N), STAT=ISTAT ); END IF ELSE; LJOBZ = 'N' LIFAIL => ISTAT1; ENDIF ! .. DETERMINE THE WORKSPACE IF( ISTAT == 0 ) THEN ALLOCATE(IWORK(5*N), WORK(5*N), STAT=ISTAT) IF( ISTAT == 0 )THEN IF( PRESENT(ABSTOL) )THEN; LABSTOL = ABSTOL ELSE; LABSTOL = 2*LAMCH_F77('Safe minimum'); ENDIF IF (PRESENT(Z)) THEN CALL STEVX_F77( LJOBZ, LRANGE, N, D, E, LVL, LVU, LIL, LIU, & LABSTOL, LM, W, Z, S1Z, WORK, IWORK, LIFAIL, LINFO ) ELSE CALL STEVX_F77( LJOBZ, LRANGE, N, D, E, LVL, LVU, LIL, LIU, & LABSTOL, LM, W, LLZ, S1Z, WORK, IWORK, LIFAIL, LINFO ) ENDIF IF( PRESENT(M) ) M = LM W(LM+1:N) = 0.0_WP ELSE; LINFO = -100; END IF END IF IF( PRESENT(Z) .AND. .NOT.PRESENT(IFAIL) ) DEALLOCATE( LIFAIL, STAT=ISTAT1(1) ) DEALLOCATE(IWORK, WORK, STAT=ISTAT1(1)) END IF CALL ERINFO(LINFO,SRNAME,INFO,ISTAT) END SUBROUTINE SSTEVX_F95
apache-2.0
stanmoore1/lammps
lib/linalg/zlarfg.f
4
5360
*> \brief \b ZLARFG generates an elementary reflector (Householder matrix). * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZLARFG + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlarfg.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlarfg.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlarfg.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZLARFG( N, ALPHA, X, INCX, TAU ) * * .. Scalar Arguments .. * INTEGER INCX, N * COMPLEX*16 ALPHA, TAU * .. * .. Array Arguments .. * COMPLEX*16 X( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZLARFG generates a complex elementary reflector H of order n, such *> that *> *> H**H * ( alpha ) = ( beta ), H**H * H = I. *> ( x ) ( 0 ) *> *> where alpha and beta are scalars, with beta real, and x is an *> (n-1)-element complex vector. H is represented in the form *> *> H = I - tau * ( 1 ) * ( 1 v**H ) , *> ( v ) *> *> where tau is a complex scalar and v is a complex (n-1)-element *> vector. Note that H is not hermitian. *> *> If the elements of x are all zero and alpha is real, then tau = 0 *> and H is taken to be the unit matrix. *> *> Otherwise 1 <= real(tau) <= 2 and abs(tau-1) <= 1 . *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the elementary reflector. *> \endverbatim *> *> \param[in,out] ALPHA *> \verbatim *> ALPHA is COMPLEX*16 *> On entry, the value alpha. *> On exit, it is overwritten with the value beta. *> \endverbatim *> *> \param[in,out] X *> \verbatim *> X is COMPLEX*16 array, dimension *> (1+(N-2)*abs(INCX)) *> On entry, the vector x. *> On exit, it is overwritten with the vector v. *> \endverbatim *> *> \param[in] INCX *> \verbatim *> INCX is INTEGER *> The increment between elements of X. INCX > 0. *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is COMPLEX*16 *> The value tau. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup complex16OTHERauxiliary * * ===================================================================== SUBROUTINE ZLARFG( N, ALPHA, X, INCX, TAU ) * * -- 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 .. INTEGER INCX, N COMPLEX*16 ALPHA, TAU * .. * .. Array Arguments .. COMPLEX*16 X( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) * .. * .. Local Scalars .. INTEGER J, KNT DOUBLE PRECISION ALPHI, ALPHR, BETA, RSAFMN, SAFMIN, XNORM * .. * .. External Functions .. DOUBLE PRECISION DLAMCH, DLAPY3, DZNRM2 COMPLEX*16 ZLADIV EXTERNAL DLAMCH, DLAPY3, DZNRM2, ZLADIV * .. * .. Intrinsic Functions .. INTRINSIC ABS, DBLE, DCMPLX, DIMAG, SIGN * .. * .. External Subroutines .. EXTERNAL ZDSCAL, ZSCAL * .. * .. Executable Statements .. * IF( N.LE.0 ) THEN TAU = ZERO RETURN END IF * XNORM = DZNRM2( N-1, X, INCX ) ALPHR = DBLE( ALPHA ) ALPHI = DIMAG( ALPHA ) * IF( XNORM.EQ.ZERO .AND. ALPHI.EQ.ZERO ) THEN * * H = I * TAU = ZERO ELSE * * general case * BETA = -SIGN( DLAPY3( ALPHR, ALPHI, XNORM ), ALPHR ) SAFMIN = DLAMCH( 'S' ) / DLAMCH( 'E' ) RSAFMN = ONE / SAFMIN * KNT = 0 IF( ABS( BETA ).LT.SAFMIN ) THEN * * XNORM, BETA may be inaccurate; scale X and recompute them * 10 CONTINUE KNT = KNT + 1 CALL ZDSCAL( N-1, RSAFMN, X, INCX ) BETA = BETA*RSAFMN ALPHI = ALPHI*RSAFMN ALPHR = ALPHR*RSAFMN IF( (ABS( BETA ).LT.SAFMIN) .AND. (KNT .LT. 20) ) $ GO TO 10 * * New BETA is at most 1, at least SAFMIN * XNORM = DZNRM2( N-1, X, INCX ) ALPHA = DCMPLX( ALPHR, ALPHI ) BETA = -SIGN( DLAPY3( ALPHR, ALPHI, XNORM ), ALPHR ) END IF TAU = DCMPLX( ( BETA-ALPHR ) / BETA, -ALPHI / BETA ) ALPHA = ZLADIV( DCMPLX( ONE ), ALPHA-BETA ) CALL ZSCAL( N-1, ALPHA, X, INCX ) * * If ALPHA is subnormal, it may lose relative accuracy * DO 20 J = 1, KNT BETA = BETA*SAFMIN 20 CONTINUE ALPHA = BETA END IF * RETURN * * End of ZLARFG * END
gpl-2.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/dlasy2.f
24
14556
*> \brief \b DLASY2 solves the Sylvester matrix equation where the matrices are of order 1 or 2. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DLASY2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasy2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasy2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasy2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DLASY2( LTRANL, LTRANR, ISGN, N1, N2, TL, LDTL, TR, * LDTR, B, LDB, SCALE, X, LDX, XNORM, INFO ) * * .. Scalar Arguments .. * LOGICAL LTRANL, LTRANR * INTEGER INFO, ISGN, LDB, LDTL, LDTR, LDX, N1, N2 * DOUBLE PRECISION SCALE, XNORM * .. * .. Array Arguments .. * DOUBLE PRECISION B( LDB, * ), TL( LDTL, * ), TR( LDTR, * ), * $ X( LDX, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLASY2 solves for the N1 by N2 matrix X, 1 <= N1,N2 <= 2, in *> *> op(TL)*X + ISGN*X*op(TR) = SCALE*B, *> *> where TL is N1 by N1, TR is N2 by N2, B is N1 by N2, and ISGN = 1 or *> -1. op(T) = T or T**T, where T**T denotes the transpose of T. *> \endverbatim * * Arguments: * ========== * *> \param[in] LTRANL *> \verbatim *> LTRANL is LOGICAL *> On entry, LTRANL specifies the op(TL): *> = .FALSE., op(TL) = TL, *> = .TRUE., op(TL) = TL**T. *> \endverbatim *> *> \param[in] LTRANR *> \verbatim *> LTRANR is LOGICAL *> On entry, LTRANR specifies the op(TR): *> = .FALSE., op(TR) = TR, *> = .TRUE., op(TR) = TR**T. *> \endverbatim *> *> \param[in] ISGN *> \verbatim *> ISGN is INTEGER *> On entry, ISGN specifies the sign of the equation *> as described before. ISGN may only be 1 or -1. *> \endverbatim *> *> \param[in] N1 *> \verbatim *> N1 is INTEGER *> On entry, N1 specifies the order of matrix TL. *> N1 may only be 0, 1 or 2. *> \endverbatim *> *> \param[in] N2 *> \verbatim *> N2 is INTEGER *> On entry, N2 specifies the order of matrix TR. *> N2 may only be 0, 1 or 2. *> \endverbatim *> *> \param[in] TL *> \verbatim *> TL is DOUBLE PRECISION array, dimension (LDTL,2) *> On entry, TL contains an N1 by N1 matrix. *> \endverbatim *> *> \param[in] LDTL *> \verbatim *> LDTL is INTEGER *> The leading dimension of the matrix TL. LDTL >= max(1,N1). *> \endverbatim *> *> \param[in] TR *> \verbatim *> TR is DOUBLE PRECISION array, dimension (LDTR,2) *> On entry, TR contains an N2 by N2 matrix. *> \endverbatim *> *> \param[in] LDTR *> \verbatim *> LDTR is INTEGER *> The leading dimension of the matrix TR. LDTR >= max(1,N2). *> \endverbatim *> *> \param[in] B *> \verbatim *> B is DOUBLE PRECISION array, dimension (LDB,2) *> On entry, the N1 by N2 matrix B contains the right-hand *> side of the equation. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the matrix B. LDB >= max(1,N1). *> \endverbatim *> *> \param[out] SCALE *> \verbatim *> SCALE is DOUBLE PRECISION *> On exit, SCALE contains the scale factor. SCALE is chosen *> less than or equal to 1 to prevent the solution overflowing. *> \endverbatim *> *> \param[out] X *> \verbatim *> X is DOUBLE PRECISION array, dimension (LDX,2) *> On exit, X contains the N1 by N2 solution. *> \endverbatim *> *> \param[in] LDX *> \verbatim *> LDX is INTEGER *> The leading dimension of the matrix X. LDX >= max(1,N1). *> \endverbatim *> *> \param[out] XNORM *> \verbatim *> XNORM is DOUBLE PRECISION *> On exit, XNORM is the infinity-norm of the solution. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> On exit, INFO is set to *> 0: successful exit. *> 1: TL and TR have too close eigenvalues, so TL or *> TR is perturbed to get a nonsingular equation. *> NOTE: In the interests of speed, this routine does not *> check the inputs for errors. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup doubleSYauxiliary * * ===================================================================== SUBROUTINE DLASY2( LTRANL, LTRANR, ISGN, N1, N2, TL, LDTL, TR, $ LDTR, B, LDB, SCALE, X, LDX, XNORM, INFO ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. LOGICAL LTRANL, LTRANR INTEGER INFO, ISGN, LDB, LDTL, LDTR, LDX, N1, N2 DOUBLE PRECISION SCALE, XNORM * .. * .. Array Arguments .. DOUBLE PRECISION B( LDB, * ), TL( LDTL, * ), TR( LDTR, * ), $ X( LDX, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) DOUBLE PRECISION TWO, HALF, EIGHT PARAMETER ( TWO = 2.0D+0, HALF = 0.5D+0, EIGHT = 8.0D+0 ) * .. * .. Local Scalars .. LOGICAL BSWAP, XSWAP INTEGER I, IP, IPIV, IPSV, J, JP, JPSV, K DOUBLE PRECISION BET, EPS, GAM, L21, SGN, SMIN, SMLNUM, TAU1, $ TEMP, U11, U12, U22, XMAX * .. * .. Local Arrays .. LOGICAL BSWPIV( 4 ), XSWPIV( 4 ) INTEGER JPIV( 4 ), LOCL21( 4 ), LOCU12( 4 ), $ LOCU22( 4 ) DOUBLE PRECISION BTMP( 4 ), T16( 4, 4 ), TMP( 4 ), X2( 2 ) * .. * .. External Functions .. INTEGER IDAMAX DOUBLE PRECISION DLAMCH EXTERNAL IDAMAX, DLAMCH * .. * .. External Subroutines .. EXTERNAL DCOPY, DSWAP * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX * .. * .. Data statements .. DATA LOCU12 / 3, 4, 1, 2 / , LOCL21 / 2, 1, 4, 3 / , $ LOCU22 / 4, 3, 2, 1 / DATA XSWPIV / .FALSE., .FALSE., .TRUE., .TRUE. / DATA BSWPIV / .FALSE., .TRUE., .FALSE., .TRUE. / * .. * .. Executable Statements .. * * Do not check the input parameters for errors * INFO = 0 * * Quick return if possible * IF( N1.EQ.0 .OR. N2.EQ.0 ) $ RETURN * * Set constants to control overflow * EPS = DLAMCH( 'P' ) SMLNUM = DLAMCH( 'S' ) / EPS SGN = ISGN * K = N1 + N1 + N2 - 2 GO TO ( 10, 20, 30, 50 )K * * 1 by 1: TL11*X + SGN*X*TR11 = B11 * 10 CONTINUE TAU1 = TL( 1, 1 ) + SGN*TR( 1, 1 ) BET = ABS( TAU1 ) IF( BET.LE.SMLNUM ) THEN TAU1 = SMLNUM BET = SMLNUM INFO = 1 END IF * SCALE = ONE GAM = ABS( B( 1, 1 ) ) IF( SMLNUM*GAM.GT.BET ) $ SCALE = ONE / GAM * X( 1, 1 ) = ( B( 1, 1 )*SCALE ) / TAU1 XNORM = ABS( X( 1, 1 ) ) RETURN * * 1 by 2: * TL11*[X11 X12] + ISGN*[X11 X12]*op[TR11 TR12] = [B11 B12] * [TR21 TR22] * 20 CONTINUE * SMIN = MAX( EPS*MAX( ABS( TL( 1, 1 ) ), ABS( TR( 1, 1 ) ), $ ABS( TR( 1, 2 ) ), ABS( TR( 2, 1 ) ), ABS( TR( 2, 2 ) ) ), $ SMLNUM ) TMP( 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 ) TMP( 4 ) = TL( 1, 1 ) + SGN*TR( 2, 2 ) IF( LTRANR ) THEN TMP( 2 ) = SGN*TR( 2, 1 ) TMP( 3 ) = SGN*TR( 1, 2 ) ELSE TMP( 2 ) = SGN*TR( 1, 2 ) TMP( 3 ) = SGN*TR( 2, 1 ) END IF BTMP( 1 ) = B( 1, 1 ) BTMP( 2 ) = B( 1, 2 ) GO TO 40 * * 2 by 1: * op[TL11 TL12]*[X11] + ISGN* [X11]*TR11 = [B11] * [TL21 TL22] [X21] [X21] [B21] * 30 CONTINUE SMIN = MAX( EPS*MAX( ABS( TR( 1, 1 ) ), ABS( TL( 1, 1 ) ), $ ABS( TL( 1, 2 ) ), ABS( TL( 2, 1 ) ), ABS( TL( 2, 2 ) ) ), $ SMLNUM ) TMP( 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 ) TMP( 4 ) = TL( 2, 2 ) + SGN*TR( 1, 1 ) IF( LTRANL ) THEN TMP( 2 ) = TL( 1, 2 ) TMP( 3 ) = TL( 2, 1 ) ELSE TMP( 2 ) = TL( 2, 1 ) TMP( 3 ) = TL( 1, 2 ) END IF BTMP( 1 ) = B( 1, 1 ) BTMP( 2 ) = B( 2, 1 ) 40 CONTINUE * * Solve 2 by 2 system using complete pivoting. * Set pivots less than SMIN to SMIN. * IPIV = IDAMAX( 4, TMP, 1 ) U11 = TMP( IPIV ) IF( ABS( U11 ).LE.SMIN ) THEN INFO = 1 U11 = SMIN END IF U12 = TMP( LOCU12( IPIV ) ) L21 = TMP( LOCL21( IPIV ) ) / U11 U22 = TMP( LOCU22( IPIV ) ) - U12*L21 XSWAP = XSWPIV( IPIV ) BSWAP = BSWPIV( IPIV ) IF( ABS( U22 ).LE.SMIN ) THEN INFO = 1 U22 = SMIN END IF IF( BSWAP ) THEN TEMP = BTMP( 2 ) BTMP( 2 ) = BTMP( 1 ) - L21*TEMP BTMP( 1 ) = TEMP ELSE BTMP( 2 ) = BTMP( 2 ) - L21*BTMP( 1 ) END IF SCALE = ONE IF( ( TWO*SMLNUM )*ABS( BTMP( 2 ) ).GT.ABS( U22 ) .OR. $ ( TWO*SMLNUM )*ABS( BTMP( 1 ) ).GT.ABS( U11 ) ) THEN SCALE = HALF / MAX( ABS( BTMP( 1 ) ), ABS( BTMP( 2 ) ) ) BTMP( 1 ) = BTMP( 1 )*SCALE BTMP( 2 ) = BTMP( 2 )*SCALE END IF X2( 2 ) = BTMP( 2 ) / U22 X2( 1 ) = BTMP( 1 ) / U11 - ( U12 / U11 )*X2( 2 ) IF( XSWAP ) THEN TEMP = X2( 2 ) X2( 2 ) = X2( 1 ) X2( 1 ) = TEMP END IF X( 1, 1 ) = X2( 1 ) IF( N1.EQ.1 ) THEN X( 1, 2 ) = X2( 2 ) XNORM = ABS( X( 1, 1 ) ) + ABS( X( 1, 2 ) ) ELSE X( 2, 1 ) = X2( 2 ) XNORM = MAX( ABS( X( 1, 1 ) ), ABS( X( 2, 1 ) ) ) END IF RETURN * * 2 by 2: * op[TL11 TL12]*[X11 X12] +ISGN* [X11 X12]*op[TR11 TR12] = [B11 B12] * [TL21 TL22] [X21 X22] [X21 X22] [TR21 TR22] [B21 B22] * * Solve equivalent 4 by 4 system using complete pivoting. * Set pivots less than SMIN to SMIN. * 50 CONTINUE SMIN = MAX( ABS( TR( 1, 1 ) ), ABS( TR( 1, 2 ) ), $ ABS( TR( 2, 1 ) ), ABS( TR( 2, 2 ) ) ) SMIN = MAX( SMIN, ABS( TL( 1, 1 ) ), ABS( TL( 1, 2 ) ), $ ABS( TL( 2, 1 ) ), ABS( TL( 2, 2 ) ) ) SMIN = MAX( EPS*SMIN, SMLNUM ) BTMP( 1 ) = ZERO CALL DCOPY( 16, BTMP, 0, T16, 1 ) T16( 1, 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 ) T16( 2, 2 ) = TL( 2, 2 ) + SGN*TR( 1, 1 ) T16( 3, 3 ) = TL( 1, 1 ) + SGN*TR( 2, 2 ) T16( 4, 4 ) = TL( 2, 2 ) + SGN*TR( 2, 2 ) IF( LTRANL ) THEN T16( 1, 2 ) = TL( 2, 1 ) T16( 2, 1 ) = TL( 1, 2 ) T16( 3, 4 ) = TL( 2, 1 ) T16( 4, 3 ) = TL( 1, 2 ) ELSE T16( 1, 2 ) = TL( 1, 2 ) T16( 2, 1 ) = TL( 2, 1 ) T16( 3, 4 ) = TL( 1, 2 ) T16( 4, 3 ) = TL( 2, 1 ) END IF IF( LTRANR ) THEN T16( 1, 3 ) = SGN*TR( 1, 2 ) T16( 2, 4 ) = SGN*TR( 1, 2 ) T16( 3, 1 ) = SGN*TR( 2, 1 ) T16( 4, 2 ) = SGN*TR( 2, 1 ) ELSE T16( 1, 3 ) = SGN*TR( 2, 1 ) T16( 2, 4 ) = SGN*TR( 2, 1 ) T16( 3, 1 ) = SGN*TR( 1, 2 ) T16( 4, 2 ) = SGN*TR( 1, 2 ) END IF BTMP( 1 ) = B( 1, 1 ) BTMP( 2 ) = B( 2, 1 ) BTMP( 3 ) = B( 1, 2 ) BTMP( 4 ) = B( 2, 2 ) * * Perform elimination * DO 100 I = 1, 3 XMAX = ZERO DO 70 IP = I, 4 DO 60 JP = I, 4 IF( ABS( T16( IP, JP ) ).GE.XMAX ) THEN XMAX = ABS( T16( IP, JP ) ) IPSV = IP JPSV = JP END IF 60 CONTINUE 70 CONTINUE IF( IPSV.NE.I ) THEN CALL DSWAP( 4, T16( IPSV, 1 ), 4, T16( I, 1 ), 4 ) TEMP = BTMP( I ) BTMP( I ) = BTMP( IPSV ) BTMP( IPSV ) = TEMP END IF IF( JPSV.NE.I ) $ CALL DSWAP( 4, T16( 1, JPSV ), 1, T16( 1, I ), 1 ) JPIV( I ) = JPSV IF( ABS( T16( I, I ) ).LT.SMIN ) THEN INFO = 1 T16( I, I ) = SMIN END IF DO 90 J = I + 1, 4 T16( J, I ) = T16( J, I ) / T16( I, I ) BTMP( J ) = BTMP( J ) - T16( J, I )*BTMP( I ) DO 80 K = I + 1, 4 T16( J, K ) = T16( J, K ) - T16( J, I )*T16( I, K ) 80 CONTINUE 90 CONTINUE 100 CONTINUE IF( ABS( T16( 4, 4 ) ).LT.SMIN ) $ T16( 4, 4 ) = SMIN SCALE = ONE IF( ( EIGHT*SMLNUM )*ABS( BTMP( 1 ) ).GT.ABS( T16( 1, 1 ) ) .OR. $ ( EIGHT*SMLNUM )*ABS( BTMP( 2 ) ).GT.ABS( T16( 2, 2 ) ) .OR. $ ( EIGHT*SMLNUM )*ABS( BTMP( 3 ) ).GT.ABS( T16( 3, 3 ) ) .OR. $ ( EIGHT*SMLNUM )*ABS( BTMP( 4 ) ).GT.ABS( T16( 4, 4 ) ) ) THEN SCALE = ( ONE / EIGHT ) / MAX( ABS( BTMP( 1 ) ), $ ABS( BTMP( 2 ) ), ABS( BTMP( 3 ) ), ABS( BTMP( 4 ) ) ) BTMP( 1 ) = BTMP( 1 )*SCALE BTMP( 2 ) = BTMP( 2 )*SCALE BTMP( 3 ) = BTMP( 3 )*SCALE BTMP( 4 ) = BTMP( 4 )*SCALE END IF DO 120 I = 1, 4 K = 5 - I TEMP = ONE / T16( K, K ) TMP( K ) = BTMP( K )*TEMP DO 110 J = K + 1, 4 TMP( K ) = TMP( K ) - ( TEMP*T16( K, J ) )*TMP( J ) 110 CONTINUE 120 CONTINUE DO 130 I = 1, 3 IF( JPIV( 4-I ).NE.4-I ) THEN TEMP = TMP( 4-I ) TMP( 4-I ) = TMP( JPIV( 4-I ) ) TMP( JPIV( 4-I ) ) = TEMP END IF 130 CONTINUE X( 1, 1 ) = TMP( 1 ) X( 2, 1 ) = TMP( 2 ) X( 1, 2 ) = TMP( 3 ) X( 2, 2 ) = TMP( 4 ) XNORM = MAX( ABS( TMP( 1 ) )+ABS( TMP( 3 ) ), $ ABS( TMP( 2 ) )+ABS( TMP( 4 ) ) ) RETURN * * End of DLASY2 * END
apache-2.0
stanmoore1/lammps
lib/linalg/ilazlr.f
4
2981
*> \brief \b ILAZLR scans a matrix for its last non-zero row. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ILAZLR + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ilazlr.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ilazlr.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ilazlr.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * INTEGER FUNCTION ILAZLR( M, N, A, LDA ) * * .. Scalar Arguments .. * INTEGER M, N, LDA * .. * .. Array Arguments .. * COMPLEX*16 A( LDA, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ILAZLR scans A for its last non-zero row. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is COMPLEX*16 array, dimension (LDA,N) *> The m by n matrix A. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup complex16OTHERauxiliary * * ===================================================================== INTEGER FUNCTION ILAZLR( M, N, A, LDA ) * * -- 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 .. INTEGER M, N, LDA * .. * .. Array Arguments .. COMPLEX*16 A( LDA, * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX*16 ZERO PARAMETER ( ZERO = (0.0D+0, 0.0D+0) ) * .. * .. Local Scalars .. INTEGER I, J * .. * .. Executable Statements .. * * Quick test for the common case where one corner is non-zero. IF( M.EQ.0 ) THEN ILAZLR = M ELSE IF( A(M, 1).NE.ZERO .OR. A(M, N).NE.ZERO ) THEN ILAZLR = M ELSE * Scan up each column tracking the last zero row seen. ILAZLR = 0 DO J = 1, N I=M DO WHILE((A(MAX(I,1),J).EQ.ZERO).AND.(I.GE.1)) I=I-1 ENDDO ILAZLR = MAX( ILAZLR, I ) END DO END IF RETURN END
gpl-2.0
aamaricci/SciFortran
src/lapack/dlarrc.f
5
4517
SUBROUTINE DLARRC( JOBT, N, VL, VU, D, E, PIVMIN, $ EIGCNT, LCNT, RCNT, INFO ) * * -- LAPACK auxiliary routine (version 3.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2006 * * .. Scalar Arguments .. CHARACTER JOBT INTEGER EIGCNT, INFO, LCNT, N, RCNT DOUBLE PRECISION PIVMIN, VL, VU * .. * .. Array Arguments .. DOUBLE PRECISION D( * ), E( * ) * .. * * Purpose * ======= * * Find the number of eigenvalues of the symmetric tridiagonal matrix T * that are in the interval (VL,VU] if JOBT = 'T', and of L D L^T * if JOBT = 'L'. * * Arguments * ========= * * JOBT (input) CHARACTER*1 * = 'T': Compute Sturm count for matrix T. * = 'L': Compute Sturm count for matrix L D L^T. * * N (input) INTEGER * The order of the matrix. N > 0. * * VL (input) DOUBLE PRECISION * VU (input) DOUBLE PRECISION * The lower and upper bounds for the eigenvalues. * * D (input) DOUBLE PRECISION array, dimension (N) * JOBT = 'T': The N diagonal elements of the tridiagonal matrix T. * JOBT = 'L': The N diagonal elements of the diagonal matrix D. * * E (input) DOUBLE PRECISION array, dimension (N) * JOBT = 'T': The N-1 offdiagonal elements of the matrix T. * JOBT = 'L': The N-1 offdiagonal elements of the matrix L. * * PIVMIN (input) DOUBLE PRECISION * The minimum pivot in the Sturm sequence for T. * * EIGCNT (output) INTEGER * The number of eigenvalues of the symmetric tridiagonal matrix T * that are in the interval (VL,VU] * * LCNT (output) INTEGER * RCNT (output) INTEGER * The left and right negcounts of the interval. * * INFO (output) INTEGER * * Further Details * =============== * * Based on contributions by * Beresford Parlett, University of California, Berkeley, USA * Jim Demmel, University of California, Berkeley, USA * Inderjit Dhillon, University of Texas, Austin, USA * Osni Marques, LBNL/NERSC, USA * Christof Voemel, University of California, Berkeley, USA * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D0 ) * .. * .. Local Scalars .. INTEGER I LOGICAL MATT DOUBLE PRECISION LPIVOT, RPIVOT, SL, SU, TMP, TMP2 * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Executable Statements .. * INFO = 0 LCNT = 0 RCNT = 0 EIGCNT = 0 MATT = LSAME( JOBT, 'T' ) IF (MATT) THEN * Sturm sequence count on T LPIVOT = D( 1 ) - VL RPIVOT = D( 1 ) - VU IF( LPIVOT.LE.ZERO ) THEN LCNT = LCNT + 1 ENDIF IF( RPIVOT.LE.ZERO ) THEN RCNT = RCNT + 1 ENDIF DO 10 I = 1, N-1 TMP = E(I)**2 LPIVOT = ( D( I+1 )-VL ) - TMP/LPIVOT RPIVOT = ( D( I+1 )-VU ) - TMP/RPIVOT IF( LPIVOT.LE.ZERO ) THEN LCNT = LCNT + 1 ENDIF IF( RPIVOT.LE.ZERO ) THEN RCNT = RCNT + 1 ENDIF 10 CONTINUE ELSE * Sturm sequence count on L D L^T SL = -VL SU = -VU DO 20 I = 1, N - 1 LPIVOT = D( I ) + SL RPIVOT = D( I ) + SU IF( LPIVOT.LE.ZERO ) THEN LCNT = LCNT + 1 ENDIF IF( RPIVOT.LE.ZERO ) THEN RCNT = RCNT + 1 ENDIF TMP = E(I) * D(I) * E(I) * TMP2 = TMP / LPIVOT IF( TMP2.EQ.ZERO ) THEN SL = TMP - VL ELSE SL = SL*TMP2 - VL END IF * TMP2 = TMP / RPIVOT IF( TMP2.EQ.ZERO ) THEN SU = TMP - VU ELSE SU = SU*TMP2 - VU END IF 20 CONTINUE LPIVOT = D( N ) + SL RPIVOT = D( N ) + SU IF( LPIVOT.LE.ZERO ) THEN LCNT = LCNT + 1 ENDIF IF( RPIVOT.LE.ZERO ) THEN RCNT = RCNT + 1 ENDIF ENDIF EIGCNT = RCNT - LCNT RETURN * * end of DLARRC * END
lgpl-3.0
aamaricci/SciFortran
src/lapack/chetri2x.f
1
14568
SUBROUTINE CHETRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, INFO ) * * -- LAPACK routine (version 3.3.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * -- April 2011 -- * * -- Written by Julie Langou of the Univ. of TN -- * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDA, N, NB * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX A( LDA, * ), WORK( N+NB+1,* ) * .. * * Purpose * ======= * * CHETRI2X computes the inverse of a complex Hermitian indefinite matrix * A using the factorization A = U*D*U**H or A = L*D*L**H computed by * CHETRF. * * Arguments * ========= * * UPLO (input) CHARACTER*1 * Specifies whether the details of the factorization are stored * as an upper or lower triangular matrix. * = 'U': Upper triangular, form is A = U*D*U**H; * = 'L': Lower triangular, form is A = L*D*L**H. * * N (input) INTEGER * The order of the matrix A. N >= 0. * * A (input/output) COMPLEX array, dimension (LDA,N) * On entry, the NNB diagonal matrix D and the multipliers * used to obtain the factor U or L as computed by CHETRF. * * On exit, if INFO = 0, the (symmetric) inverse of the original * matrix. If UPLO = 'U', the upper triangular part of the * inverse is formed and the part of A below the diagonal is not * referenced; if UPLO = 'L' the lower triangular part of the * inverse is formed and the part of A above the diagonal is * not referenced. * * LDA (input) INTEGER * The leading dimension of the array A. LDA >= max(1,N). * * IPIV (input) INTEGER array, dimension (N) * Details of the interchanges and the NNB structure of D * as determined by CHETRF. * * WORK (workspace) COMPLEX array, dimension (N+NNB+1,NNB+3) * * NB (input) INTEGER * Block size * * 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) = 0; the matrix is singular and its * inverse could not be computed. * * ===================================================================== * * .. Parameters .. REAL ONE COMPLEX CONE, ZERO PARAMETER ( ONE = 1.0E+0, $ CONE = ( 1.0E+0, 0.0E+0 ), $ ZERO = ( 0.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER I, IINFO, IP, K, CUT, NNB INTEGER COUNT INTEGER J, U11, INVD COMPLEX AK, AKKP1, AKP1, D, T COMPLEX U01_I_J, U01_IP1_J COMPLEX U11_I_J, U11_IP1_J * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL CSYCONV, XERBLA, CTRTRI EXTERNAL CGEMM, CTRMM, CHESWAPR * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. 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 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -4 END IF * * Quick return if possible * * IF( INFO.NE.0 ) THEN CALL XERBLA( 'CHETRI2X', -INFO ) RETURN END IF IF( N.EQ.0 ) $ RETURN * * Convert A * Workspace got Non-diag elements of D * CALL CSYCONV( UPLO, 'C', N, A, LDA, IPIV, WORK, IINFO ) * * Check that the diagonal matrix D is nonsingular. * IF( UPPER ) THEN * * Upper triangular storage: examine D from bottom to top * DO INFO = N, 1, -1 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO ) $ RETURN END DO ELSE * * Lower triangular storage: examine D from top to bottom. * DO INFO = 1, N IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO ) $ RETURN END DO END IF INFO = 0 * * Splitting Workspace * U01 is a block (N,NB+1) * The first element of U01 is in WORK(1,1) * U11 is a block (NB+1,NB+1) * The first element of U11 is in WORK(N+1,1) U11 = N * INVD is a block (N,2) * The first element of INVD is in WORK(1,INVD) INVD = NB+2 IF( UPPER ) THEN * * invA = P * inv(U**H)*inv(D)*inv(U)*P**H. * CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO ) * * inv(D) and inv(D)*inv(U) * K=1 DO WHILE ( K .LE. N ) IF( IPIV( K ).GT.0 ) THEN * 1 x 1 diagonal NNB WORK(K,INVD) = ONE / REAL ( A( K, K ) ) WORK(K,INVD+1) = 0 K=K+1 ELSE * 2 x 2 diagonal NNB T = ABS ( WORK(K+1,1) ) AK = REAL ( A( K, K ) ) / T AKP1 = REAL ( A( K+1, K+1 ) ) / T AKKP1 = WORK(K+1,1) / T D = T*( AK*AKP1-ONE ) WORK(K,INVD) = AKP1 / D WORK(K+1,INVD+1) = AK / D WORK(K,INVD+1) = -AKKP1 / D WORK(K+1,INVD) = CONJG (WORK(K,INVD+1) ) K=K+2 END IF END DO * * inv(U**H) = (inv(U))**H * * inv(U**H)*inv(D)*inv(U) * CUT=N DO WHILE (CUT .GT. 0) NNB=NB IF (CUT .LE. NNB) THEN NNB=CUT ELSE COUNT = 0 * count negative elements, DO I=CUT+1-NNB,CUT IF (IPIV(I) .LT. 0) COUNT=COUNT+1 END DO * need a even number for a clear cut IF (MOD(COUNT,2) .EQ. 1) NNB=NNB+1 END IF CUT=CUT-NNB * * U01 Block * DO I=1,CUT DO J=1,NNB WORK(I,J)=A(I,CUT+J) END DO END DO * * U11 Block * DO I=1,NNB WORK(U11+I,I)=CONE DO J=1,I-1 WORK(U11+I,J)=ZERO END DO DO J=I+1,NNB WORK(U11+I,J)=A(CUT+I,CUT+J) END DO END DO * * invD*U01 * I=1 DO WHILE (I .LE. CUT) IF (IPIV(I) > 0) THEN DO J=1,NNB WORK(I,J)=WORK(I,INVD)*WORK(I,J) END DO I=I+1 ELSE DO J=1,NNB U01_I_J = WORK(I,J) U01_IP1_J = WORK(I+1,J) WORK(I,J)=WORK(I,INVD)*U01_I_J+ $ WORK(I,INVD+1)*U01_IP1_J WORK(I+1,J)=WORK(I+1,INVD)*U01_I_J+ $ WORK(I+1,INVD+1)*U01_IP1_J END DO I=I+2 END IF END DO * * invD1*U11 * I=1 DO WHILE (I .LE. NNB) IF (IPIV(CUT+I) > 0) THEN DO J=I,NNB WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) END DO I=I+1 ELSE DO J=I,NNB U11_I_J = WORK(U11+I,J) U11_IP1_J = WORK(U11+I+1,J) WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) + $ WORK(CUT+I,INVD+1)*WORK(U11+I+1,J) WORK(U11+I+1,J)=WORK(CUT+I+1,INVD)*U11_I_J+ $ WORK(CUT+I+1,INVD+1)*U11_IP1_J END DO I=I+2 END IF END DO * * U11**H*invD1*U11->U11 * CALL CTRMM('L','U','C','U',NNB, NNB, $ CONE,A(CUT+1,CUT+1),LDA,WORK(U11+1,1),N+NB+1) * DO I=1,NNB DO J=I,NNB A(CUT+I,CUT+J)=WORK(U11+I,J) END DO END DO * * U01**H*invD*U01->A(CUT+I,CUT+J) * CALL CGEMM('C','N',NNB,NNB,CUT,CONE,A(1,CUT+1),LDA, $ WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1) * * U11 = U11**H*invD1*U11 + U01**H*invD*U01 * DO I=1,NNB DO J=I,NNB A(CUT+I,CUT+J)=A(CUT+I,CUT+J)+WORK(U11+I,J) END DO END DO * * U01 = U00**H*invD0*U01 * CALL CTRMM('L',UPLO,'C','U',CUT, NNB, $ CONE,A,LDA,WORK,N+NB+1) * * Update U01 * DO I=1,CUT DO J=1,NNB A(I,CUT+J)=WORK(I,J) END DO END DO * * Next Block * END DO * * Apply PERMUTATIONS P and P**H: P * inv(U**H)*inv(D)*inv(U) *P**H * I=1 DO WHILE ( I .LE. N ) IF( IPIV(I) .GT. 0 ) THEN IP=IPIV(I) IF (I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP ) IF (I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I ) ELSE IP=-IPIV(I) I=I+1 IF ( (I-1) .LT. IP) $ CALL CHESWAPR( UPLO, N, A, LDA, I-1 ,IP ) IF ( (I-1) .GT. IP) $ CALL CHESWAPR( UPLO, N, A, LDA, IP ,I-1 ) ENDIF I=I+1 END DO ELSE * * LOWER... * * invA = P * inv(U**H)*inv(D)*inv(U)*P**H. * CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO ) * * inv(D) and inv(D)*inv(U) * K=N DO WHILE ( K .GE. 1 ) IF( IPIV( K ).GT.0 ) THEN * 1 x 1 diagonal NNB WORK(K,INVD) = ONE / REAL ( A( K, K ) ) WORK(K,INVD+1) = 0 K=K-1 ELSE * 2 x 2 diagonal NNB T = ABS ( WORK(K-1,1) ) AK = REAL ( A( K-1, K-1 ) ) / T AKP1 = REAL ( A( K, K ) ) / T AKKP1 = WORK(K-1,1) / T D = T*( AK*AKP1-ONE ) WORK(K-1,INVD) = AKP1 / D WORK(K,INVD) = AK / D WORK(K,INVD+1) = -AKKP1 / D WORK(K-1,INVD+1) = CONJG (WORK(K,INVD+1) ) K=K-2 END IF END DO * * inv(U**H) = (inv(U))**H * * inv(U**H)*inv(D)*inv(U) * CUT=0 DO WHILE (CUT .LT. N) NNB=NB IF (CUT + NNB .GE. N) THEN NNB=N-CUT ELSE COUNT = 0 * count negative elements, DO I=CUT+1,CUT+NNB IF (IPIV(I) .LT. 0) COUNT=COUNT+1 END DO * need a even number for a clear cut IF (MOD(COUNT,2) .EQ. 1) NNB=NNB+1 END IF * L21 Block DO I=1,N-CUT-NNB DO J=1,NNB WORK(I,J)=A(CUT+NNB+I,CUT+J) END DO END DO * L11 Block DO I=1,NNB WORK(U11+I,I)=CONE DO J=I+1,NNB WORK(U11+I,J)=ZERO END DO DO J=1,I-1 WORK(U11+I,J)=A(CUT+I,CUT+J) END DO END DO * * invD*L21 * I=N-CUT-NNB DO WHILE (I .GE. 1) IF (IPIV(CUT+NNB+I) > 0) THEN DO J=1,NNB WORK(I,J)=WORK(CUT+NNB+I,INVD)*WORK(I,J) END DO I=I-1 ELSE DO J=1,NNB U01_I_J = WORK(I,J) U01_IP1_J = WORK(I-1,J) WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+ $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+ $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J END DO I=I-2 END IF END DO * * invD1*L11 * I=NNB DO WHILE (I .GE. 1) IF (IPIV(CUT+I) > 0) THEN DO J=1,NNB WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) END DO I=I-1 ELSE DO J=1,NNB U11_I_J = WORK(U11+I,J) U11_IP1_J = WORK(U11+I-1,J) WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) + $ WORK(CUT+I,INVD+1)*U11_IP1_J WORK(U11+I-1,J)=WORK(CUT+I-1,INVD+1)*U11_I_J+ $ WORK(CUT+I-1,INVD)*U11_IP1_J END DO I=I-2 END IF END DO * * L11**H*invD1*L11->L11 * CALL CTRMM('L',UPLO,'C','U',NNB, NNB, $ CONE,A(CUT+1,CUT+1),LDA,WORK(U11+1,1),N+NB+1) * DO I=1,NNB DO J=1,I A(CUT+I,CUT+J)=WORK(U11+I,J) END DO END DO * IF ( (CUT+NNB) .LT. N ) THEN * * L21**H*invD2*L21->A(CUT+I,CUT+J) * CALL CGEMM('C','N',NNB,NNB,N-NNB-CUT,CONE,A(CUT+NNB+1,CUT+1) $ ,LDA,WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1) * * L11 = L11**H*invD1*L11 + U01**H*invD*U01 * DO I=1,NNB DO J=1,I A(CUT+I,CUT+J)=A(CUT+I,CUT+J)+WORK(U11+I,J) END DO END DO * * L01 = L22**H*invD2*L21 * CALL CTRMM('L',UPLO,'C','U', N-NNB-CUT, NNB, $ CONE,A(CUT+NNB+1,CUT+NNB+1),LDA,WORK,N+NB+1) * Update L21 DO I=1,N-CUT-NNB DO J=1,NNB A(CUT+NNB+I,CUT+J)=WORK(I,J) END DO END DO ELSE * * L11 = L11**H*invD1*L11 * DO I=1,NNB DO J=1,I A(CUT+I,CUT+J)=WORK(U11+I,J) END DO END DO END IF * * Next Block * CUT=CUT+NNB END DO * * Apply PERMUTATIONS P and P**H: P * inv(U**H)*inv(D)*inv(U) *P**H * I=N DO WHILE ( I .GE. 1 ) IF( IPIV(I) .GT. 0 ) THEN IP=IPIV(I) IF (I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP ) IF (I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I ) ELSE IP=-IPIV(I) IF ( I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP ) IF ( I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I ) I=I-1 ENDIF I=I-1 END DO END IF * RETURN * * End of CHETRI2X * END
lgpl-3.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/cgetri.f
29
7421
*> \brief \b CGETRI * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CGETRI + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgetri.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgetri.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgetri.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CGETRI( N, A, LDA, IPIV, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LWORK, N * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX A( LDA, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CGETRI computes the inverse of a matrix using the LU factorization *> computed by CGETRF. *> *> This method inverts U and then computes inv(A) by solving the system *> inv(A)*L = inv(U) for inv(A). *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> On entry, the factors L and U from the factorization *> A = P*L*U as computed by CGETRF. *> On exit, if INFO = 0, the inverse of the original matrix A. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> The pivot indices from CGETRF; for 1<=i<=N, row i of the *> matrix was interchanged with row IPIV(i). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (MAX(1,LWORK)) *> On exit, if INFO=0, then WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. LWORK >= max(1,N). *> For optimal performance LWORK >= N*NB, where NB is *> the optimal blocksize returned by ILAENV. *> *> 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] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = i, U(i,i) is exactly zero; the matrix is *> singular and its inverse could not be computed. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complexGEcomputational * * ===================================================================== SUBROUTINE CGETRI( N, A, LDA, IPIV, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, LWORK, N * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX A( LDA, * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX ZERO, ONE PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ), $ ONE = ( 1.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. LOGICAL LQUERY INTEGER I, IWS, J, JB, JJ, JP, LDWORK, LWKOPT, NB, $ NBMIN, NN * .. * .. External Functions .. INTEGER ILAENV EXTERNAL ILAENV * .. * .. External Subroutines .. EXTERNAL CGEMM, CGEMV, CSWAP, CTRSM, CTRTRI, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 NB = ILAENV( 1, 'CGETRI', ' ', N, -1, -1, -1 ) LWKOPT = N*NB WORK( 1 ) = LWKOPT LQUERY = ( LWORK.EQ.-1 ) IF( N.LT.0 ) THEN INFO = -1 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -3 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN INFO = -6 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CGETRI', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * Form inv(U). If INFO > 0 from CTRTRI, then U is singular, * and the inverse is not computed. * CALL CTRTRI( 'Upper', 'Non-unit', N, A, LDA, INFO ) IF( INFO.GT.0 ) $ RETURN * NBMIN = 2 LDWORK = N IF( NB.GT.1 .AND. NB.LT.N ) THEN IWS = MAX( LDWORK*NB, 1 ) IF( LWORK.LT.IWS ) THEN NB = LWORK / LDWORK NBMIN = MAX( 2, ILAENV( 2, 'CGETRI', ' ', N, -1, -1, -1 ) ) END IF ELSE IWS = N END IF * * Solve the equation inv(A)*L = inv(U) for inv(A). * IF( NB.LT.NBMIN .OR. NB.GE.N ) THEN * * Use unblocked code. * DO 20 J = N, 1, -1 * * Copy current column of L to WORK and replace with zeros. * DO 10 I = J + 1, N WORK( I ) = A( I, J ) A( I, J ) = ZERO 10 CONTINUE * * Compute current column of inv(A). * IF( J.LT.N ) $ CALL CGEMV( 'No transpose', N, N-J, -ONE, A( 1, J+1 ), $ LDA, WORK( J+1 ), 1, ONE, A( 1, J ), 1 ) 20 CONTINUE ELSE * * Use blocked code. * NN = ( ( N-1 ) / NB )*NB + 1 DO 50 J = NN, 1, -NB JB = MIN( NB, N-J+1 ) * * Copy current block column of L to WORK and replace with * zeros. * DO 40 JJ = J, J + JB - 1 DO 30 I = JJ + 1, N WORK( I+( JJ-J )*LDWORK ) = A( I, JJ ) A( I, JJ ) = ZERO 30 CONTINUE 40 CONTINUE * * Compute current block column of inv(A). * IF( J+JB.LE.N ) $ CALL CGEMM( 'No transpose', 'No transpose', N, JB, $ N-J-JB+1, -ONE, A( 1, J+JB ), LDA, $ WORK( J+JB ), LDWORK, ONE, A( 1, J ), LDA ) CALL CTRSM( 'Right', 'Lower', 'No transpose', 'Unit', N, JB, $ ONE, WORK( J ), LDWORK, A( 1, J ), LDA ) 50 CONTINUE END IF * * Apply column interchanges. * DO 60 J = N - 1, 1, -1 JP = IPIV( J ) IF( JP.NE.J ) $ CALL CSWAP( N, A( 1, J ), 1, A( 1, JP ), 1 ) 60 CONTINUE * WORK( 1 ) = IWS RETURN * * End of CGETRI * END
apache-2.0
OpenDA-Association/OpenDA
core/native/external/lapack/cpoequ.f
2
3896
SUBROUTINE CPOEQU( N, A, LDA, S, SCOND, AMAX, INFO ) * * -- LAPACK routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * March 31, 1993 * * .. Scalar Arguments .. INTEGER INFO, LDA, N REAL AMAX, SCOND * .. * .. Array Arguments .. REAL S( * ) COMPLEX A( LDA, * ) * .. * * Purpose * ======= * * CPOEQU computes row and column scalings intended to equilibrate a * Hermitian positive definite matrix A and reduce its condition number * (with respect to the two-norm). S contains the scale factors, * S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with * elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This * choice of S puts the condition number of B within a factor N of the * smallest possible condition number over all possible diagonal * scalings. * * Arguments * ========= * * N (input) INTEGER * The order of the matrix A. N >= 0. * * A (input) COMPLEX array, dimension (LDA,N) * The N-by-N Hermitian positive definite matrix whose scaling * factors are to be computed. Only the diagonal elements of A * are referenced. * * LDA (input) INTEGER * The leading dimension of the array A. LDA >= max(1,N). * * S (output) REAL array, dimension (N) * If INFO = 0, S contains the scale factors for A. * * SCOND (output) REAL * If INFO = 0, S contains the ratio of the smallest S(i) to * the largest S(i). If SCOND >= 0.1 and AMAX is neither too * large nor too small, it is not worth scaling by S. * * AMAX (output) REAL * Absolute value of largest matrix element. If AMAX is very * close to overflow or very close to underflow, the matrix * should be scaled. * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value * > 0: if INFO = i, the i-th diagonal element is nonpositive. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) * .. * .. Local Scalars .. INTEGER I REAL SMIN * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN, REAL, SQRT * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IF( N.LT.0 ) THEN INFO = -1 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -3 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CPOEQU', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) THEN SCOND = ONE AMAX = ZERO RETURN END IF * * Find the minimum and maximum diagonal elements. * S( 1 ) = REAL( A( 1, 1 ) ) SMIN = S( 1 ) AMAX = S( 1 ) DO 10 I = 2, N S( I ) = REAL( A( I, I ) ) SMIN = MIN( SMIN, S( I ) ) AMAX = MAX( AMAX, S( I ) ) 10 CONTINUE * IF( SMIN.LE.ZERO ) THEN * * Find the first non-positive diagonal element and return. * DO 20 I = 1, N IF( S( I ).LE.ZERO ) THEN INFO = I RETURN END IF 20 CONTINUE ELSE * * Set the scale factors to the reciprocals * of the diagonal elements. * DO 30 I = 1, N S( I ) = ONE / SQRT( S( I ) ) 30 CONTINUE * * Compute SCOND = min(S(I)) / max(S(I)) * SCOND = SQRT( SMIN ) / SQRT( AMAX ) END IF RETURN * * End of CPOEQU * END
lgpl-3.0
OpenDA-Association/OpenDA
core/native/external/lapack/dlaqsp.f
2
4007
SUBROUTINE DLAQSP( UPLO, N, AP, S, SCOND, AMAX, EQUED ) * * -- LAPACK auxiliary routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * February 29, 1992 * * .. Scalar Arguments .. CHARACTER EQUED, UPLO INTEGER N DOUBLE PRECISION AMAX, SCOND * .. * .. Array Arguments .. DOUBLE PRECISION AP( * ), S( * ) * .. * * Purpose * ======= * * DLAQSP equilibrates a symmetric matrix A using the scaling factors * in the vector S. * * Arguments * ========= * * UPLO (input) CHARACTER*1 * Specifies whether the upper or lower triangular part of the * symmetric matrix A is stored. * = 'U': Upper triangular * = 'L': Lower triangular * * N (input) INTEGER * The order of the matrix A. N >= 0. * * AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) * On entry, the upper or lower triangle of the symmetric matrix * A, packed columnwise in a linear array. The j-th column of A * is stored in the array AP as follows: * if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; * if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. * * On exit, the equilibrated matrix: diag(S) * A * diag(S), in * the same storage format as A. * * S (input) DOUBLE PRECISION array, dimension (N) * The scale factors for A. * * SCOND (input) DOUBLE PRECISION * Ratio of the smallest S(i) to the largest S(i). * * AMAX (input) DOUBLE PRECISION * Absolute value of largest matrix entry. * * EQUED (output) CHARACTER*1 * Specifies whether or not equilibration was done. * = 'N': No equilibration. * = 'Y': Equilibration was done, i.e., A has been replaced by * diag(S) * A * diag(S). * * Internal Parameters * =================== * * THRESH is a threshold value used to decide if scaling should be done * based on the ratio of the scaling factors. If SCOND < THRESH, * scaling is done. * * LARGE and SMALL are threshold values used to decide if scaling should * be done based on the absolute size of the largest matrix element. * If AMAX > LARGE or AMAX < SMALL, scaling is done. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, THRESH PARAMETER ( ONE = 1.0D+0, THRESH = 0.1D+0 ) * .. * .. Local Scalars .. INTEGER I, J, JC DOUBLE PRECISION CJ, LARGE, SMALL * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DLAMCH EXTERNAL LSAME, DLAMCH * .. * .. Executable Statements .. * * Quick return if possible * IF( N.LE.0 ) THEN EQUED = 'N' RETURN END IF * * Initialize LARGE and SMALL. * SMALL = DLAMCH( 'Safe minimum' ) / DLAMCH( 'Precision' ) LARGE = ONE / SMALL * IF( SCOND.GE.THRESH .AND. AMAX.GE.SMALL .AND. AMAX.LE.LARGE ) THEN * * No equilibration * EQUED = 'N' ELSE * * Replace A by diag(S) * A * diag(S). * IF( LSAME( UPLO, 'U' ) ) THEN * * Upper triangle of A is stored. * JC = 1 DO 20 J = 1, N CJ = S( J ) DO 10 I = 1, J AP( JC+I-1 ) = CJ*S( I )*AP( JC+I-1 ) 10 CONTINUE JC = JC + J 20 CONTINUE ELSE * * Lower triangle of A is stored. * JC = 1 DO 40 J = 1, N CJ = S( J ) DO 30 I = J, N AP( JC+I-J ) = CJ*S( I )*AP( JC+I-J ) 30 CONTINUE JC = JC + N - J + 1 40 CONTINUE END IF EQUED = 'Y' END IF * RETURN * * End of DLAQSP * END
lgpl-3.0
stanmoore1/lammps
lib/linalg/dorgql.f
4
8137
*> \brief \b DORGQL * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DORGQL + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dorgql.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dorgql.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dorgql.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DORGQL( M, N, K, A, LDA, TAU, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, K, LDA, LWORK, M, N * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DORGQL generates an M-by-N real matrix Q with orthonormal columns, *> which is defined as the last N columns of a product of K elementary *> reflectors of order M *> *> Q = H(k) . . . H(2) H(1) *> *> as returned by DGEQLF. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix Q. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix Q. M >= N >= 0. *> \endverbatim *> *> \param[in] K *> \verbatim *> K is INTEGER *> The number of elementary reflectors whose product defines the *> matrix Q. N >= K >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On entry, the (n-k+i)-th column must contain the vector which *> defines the elementary reflector H(i), for i = 1,2,...,k, as *> returned by DGEQLF in the last k columns of its array *> argument A. *> On exit, the M-by-N matrix Q. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The first dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[in] TAU *> \verbatim *> TAU is DOUBLE PRECISION array, dimension (K) *> TAU(i) must contain the scalar factor of the elementary *> reflector H(i), as returned by DGEQLF. *> \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. LWORK >= max(1,N). *> For optimum performance LWORK >= N*NB, where NB is the *> optimal blocksize. *> *> 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] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument has an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup doubleOTHERcomputational * * ===================================================================== SUBROUTINE DORGQL( M, N, K, A, LDA, TAU, WORK, LWORK, 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 .. INTEGER INFO, K, LDA, LWORK, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D+0 ) * .. * .. Local Scalars .. LOGICAL LQUERY INTEGER I, IB, IINFO, IWS, J, KK, L, LDWORK, LWKOPT, $ NB, NBMIN, NX * .. * .. External Subroutines .. EXTERNAL DLARFB, DLARFT, DORG2L, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. External Functions .. INTEGER ILAENV EXTERNAL ILAENV * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 LQUERY = ( LWORK.EQ.-1 ) IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 .OR. N.GT.M ) THEN INFO = -2 ELSE IF( K.LT.0 .OR. K.GT.N ) THEN INFO = -3 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -5 END IF * IF( INFO.EQ.0 ) THEN IF( N.EQ.0 ) THEN LWKOPT = 1 ELSE NB = ILAENV( 1, 'DORGQL', ' ', M, N, K, -1 ) LWKOPT = N*NB END IF WORK( 1 ) = LWKOPT * IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN INFO = -8 END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'DORGQL', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( N.LE.0 ) THEN RETURN END IF * NBMIN = 2 NX = 0 IWS = N IF( NB.GT.1 .AND. NB.LT.K ) THEN * * Determine when to cross over from blocked to unblocked code. * NX = MAX( 0, ILAENV( 3, 'DORGQL', ' ', M, N, K, -1 ) ) IF( NX.LT.K ) THEN * * Determine if workspace is large enough for blocked code. * LDWORK = N IWS = LDWORK*NB IF( LWORK.LT.IWS ) THEN * * Not enough workspace to use optimal NB: reduce NB and * determine the minimum value of NB. * NB = LWORK / LDWORK NBMIN = MAX( 2, ILAENV( 2, 'DORGQL', ' ', M, N, K, -1 ) ) END IF END IF END IF * IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN * * Use blocked code after the first block. * The last kk columns are handled by the block method. * KK = MIN( K, ( ( K-NX+NB-1 ) / NB )*NB ) * * Set A(m-kk+1:m,1:n-kk) to zero. * DO 20 J = 1, N - KK DO 10 I = M - KK + 1, M A( I, J ) = ZERO 10 CONTINUE 20 CONTINUE ELSE KK = 0 END IF * * Use unblocked code for the first or only block. * CALL DORG2L( M-KK, N-KK, K-KK, A, LDA, TAU, WORK, IINFO ) * IF( KK.GT.0 ) THEN * * Use blocked code * DO 50 I = K - KK + 1, K, NB IB = MIN( NB, K-I+1 ) IF( N-K+I.GT.1 ) THEN * * Form the triangular factor of the block reflector * H = H(i+ib-1) . . . H(i+1) H(i) * CALL DLARFT( 'Backward', 'Columnwise', M-K+I+IB-1, IB, $ A( 1, N-K+I ), LDA, TAU( I ), WORK, LDWORK ) * * Apply H to A(1:m-k+i+ib-1,1:n-k+i-1) from the left * CALL DLARFB( 'Left', 'No transpose', 'Backward', $ 'Columnwise', M-K+I+IB-1, N-K+I-1, IB, $ A( 1, N-K+I ), LDA, WORK, LDWORK, A, LDA, $ WORK( IB+1 ), LDWORK ) END IF * * Apply H to rows 1:m-k+i+ib-1 of current block * CALL DORG2L( M-K+I+IB-1, IB, IB, A( 1, N-K+I ), LDA, $ TAU( I ), WORK, IINFO ) * * Set rows m-k+i+ib:m of current block to zero * DO 40 J = N - K + I, N - K + I + IB - 1 DO 30 L = M - K + I + IB, M A( L, J ) = ZERO 30 CONTINUE 40 CONTINUE 50 CONTINUE END IF * WORK( 1 ) = IWS RETURN * * End of DORGQL * END
gpl-2.0
huard/scipy-work
scipy/interpolate/fitpack/fpcuro.f
148
2492
subroutine fpcuro(a,b,c,d,x,n) c subroutine fpcuro finds the real zeros of a cubic polynomial c p(x) = a*x**3+b*x**2+c*x+d. c c calling sequence: c call fpcuro(a,b,c,d,x,n) c c input parameters: c a,b,c,d: real values, containing the coefficients of p(x). c c output parameters: c x : real array,length 3, which contains the real zeros of p(x) c n : integer, giving the number of real zeros of p(x). c .. c ..scalar arguments.. real*8 a,b,c,d integer n c ..array argument.. real*8 x(3) c ..local scalars.. integer i real*8 a1,b1,c1,df,disc,d1,e3,f,four,half,ovfl,pi3,p3,q,r, * step,tent,three,two,u,u1,u2,y c ..function references.. real*8 abs,max,datan,atan2,cos,sign,sqrt c set constants two = 0.2d+01 three = 0.3d+01 four = 0.4d+01 ovfl =0.1d+05 half = 0.5d+0 tent = 0.1d+0 e3 = tent/0.3d0 pi3 = datan(0.1d+01)/0.75d0 a1 = abs(a) b1 = abs(b) c1 = abs(c) d1 = abs(d) c test whether p(x) is a third degree polynomial. if(max(b1,c1,d1).lt.a1*ovfl) go to 300 c test whether p(x) is a second degree polynomial. if(max(c1,d1).lt.b1*ovfl) go to 200 c test whether p(x) is a first degree polynomial. if(d1.lt.c1*ovfl) go to 100 c p(x) is a constant function. n = 0 go to 800 c p(x) is a first degree polynomial. 100 n = 1 x(1) = -d/c go to 500 c p(x) is a second degree polynomial. 200 disc = c*c-four*b*d n = 0 if(disc.lt.0.) go to 800 n = 2 u = sqrt(disc) b1 = b+b x(1) = (-c+u)/b1 x(2) = (-c-u)/b1 go to 500 c p(x) is a third degree polynomial. 300 b1 = b/a*e3 c1 = c/a d1 = d/a q = c1*e3-b1*b1 r = b1*b1*b1+(d1-b1*c1)*half disc = q*q*q+r*r if(disc.gt.0.) go to 400 u = sqrt(abs(q)) if(r.lt.0.) u = -u p3 = atan2(sqrt(-disc),abs(r))*e3 u2 = u+u n = 3 x(1) = -u2*cos(p3)-b1 x(2) = u2*cos(pi3-p3)-b1 x(3) = u2*cos(pi3+p3)-b1 go to 500 400 u = sqrt(disc) u1 = -r+u u2 = -r-u n = 1 x(1) = sign(abs(u1)**e3,u1)+sign(abs(u2)**e3,u2)-b1 c apply a newton iteration to improve the accuracy of the roots. 500 do 700 i=1,n y = x(i) f = ((a*y+b)*y+c)*y+d df = (three*a*y+two*b)*y+c step = 0. if(abs(f).lt.abs(df)*tent) step = f/df x(i) = y-step 700 continue 800 return end
bsd-3-clause
OpenDA-Association/OpenDA
core/native/external/lapack/dbdsqr.f
17
23201
SUBROUTINE DBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, $ LDU, C, LDC, WORK, INFO ) * * -- LAPACK routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * October 31, 1999 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU * .. * .. Array Arguments .. DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ), $ VT( LDVT, * ), WORK( * ) * .. * * Purpose * ======= * * DBDSQR computes the singular value decomposition (SVD) of a real * N-by-N (upper or lower) bidiagonal matrix B: B = Q * S * P' (P' * denotes the transpose of P), where S is a diagonal matrix with * non-negative diagonal elements (the singular values of B), and Q * and P are orthogonal matrices. * * The routine computes S, and optionally computes U * Q, P' * VT, * or Q' * C, for given real input matrices U, VT, and C. * * See "Computing Small Singular Values of Bidiagonal Matrices With * Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan, * LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11, * no. 5, pp. 873-912, Sept 1990) and * "Accurate singular values and differential qd algorithms," by * B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics * Department, University of California at Berkeley, July 1992 * for a detailed description of the algorithm. * * Arguments * ========= * * UPLO (input) CHARACTER*1 * = 'U': B is upper bidiagonal; * = 'L': B is lower bidiagonal. * * N (input) INTEGER * The order of the matrix B. N >= 0. * * NCVT (input) INTEGER * The number of columns of the matrix VT. NCVT >= 0. * * NRU (input) INTEGER * The number of rows of the matrix U. NRU >= 0. * * NCC (input) INTEGER * The number of columns of the matrix C. NCC >= 0. * * D (input/output) DOUBLE PRECISION array, dimension (N) * On entry, the n diagonal elements of the bidiagonal matrix B. * On exit, if INFO=0, the singular values of B in decreasing * order. * * E (input/output) DOUBLE PRECISION array, dimension (N) * On entry, the elements of E contain the * offdiagonal elements of the bidiagonal matrix whose SVD * is desired. On normal exit (INFO = 0), E is destroyed. * If the algorithm does not converge (INFO > 0), D and E * will contain the diagonal and superdiagonal elements of a * bidiagonal matrix orthogonally equivalent to the one given * as input. E(N) is used for workspace. * * VT (input/output) DOUBLE PRECISION array, dimension (LDVT, NCVT) * On entry, an N-by-NCVT matrix VT. * On exit, VT is overwritten by P' * VT. * VT is not referenced if NCVT = 0. * * LDVT (input) INTEGER * The leading dimension of the array VT. * LDVT >= max(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0. * * U (input/output) DOUBLE PRECISION array, dimension (LDU, N) * On entry, an NRU-by-N matrix U. * On exit, U is overwritten by U * Q. * U is not referenced if NRU = 0. * * LDU (input) INTEGER * The leading dimension of the array U. LDU >= max(1,NRU). * * C (input/output) DOUBLE PRECISION array, dimension (LDC, NCC) * On entry, an N-by-NCC matrix C. * On exit, C is overwritten by Q' * C. * C is not referenced if NCC = 0. * * LDC (input) INTEGER * The leading dimension of the array C. * LDC >= max(1,N) if NCC > 0; LDC >=1 if NCC = 0. * * WORK (workspace) DOUBLE PRECISION array, dimension (4*N) * * INFO (output) INTEGER * = 0: successful exit * < 0: If INFO = -i, the i-th argument had an illegal value * > 0: the algorithm did not converge; D and E contain the * elements of a bidiagonal matrix which is orthogonally * similar to the input matrix B; if INFO = i, i * elements of E have not converged to zero. * * Internal Parameters * =================== * * TOLMUL DOUBLE PRECISION, default = max(10,min(100,EPS**(-1/8))) * TOLMUL controls the convergence criterion of the QR loop. * If it is positive, TOLMUL*EPS is the desired relative * precision in the computed singular values. * If it is negative, abs(TOLMUL*EPS*sigma_max) is the * desired absolute accuracy in the computed singular * values (corresponds to relative accuracy * abs(TOLMUL*EPS) in the largest singular value. * abs(TOLMUL) should be between 1 and 1/EPS, and preferably * between 10 (for fast convergence) and .1/EPS * (for there to be some accuracy in the results). * Default is to lose at either one eighth or 2 of the * available decimal digits in each computed singular value * (whichever is smaller). * * MAXITR INTEGER, default = 6 * MAXITR controls the maximum number of passes of the * algorithm through its inner loop. The algorithms stops * (and so fails to converge) if the number of passes * through the inner loop exceeds MAXITR*N**2. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D0 ) DOUBLE PRECISION ONE PARAMETER ( ONE = 1.0D0 ) DOUBLE PRECISION NEGONE PARAMETER ( NEGONE = -1.0D0 ) DOUBLE PRECISION HNDRTH PARAMETER ( HNDRTH = 0.01D0 ) DOUBLE PRECISION TEN PARAMETER ( TEN = 10.0D0 ) DOUBLE PRECISION HNDRD PARAMETER ( HNDRD = 100.0D0 ) DOUBLE PRECISION MEIGTH PARAMETER ( MEIGTH = -0.125D0 ) INTEGER MAXITR PARAMETER ( MAXITR = 6 ) * .. * .. Local Scalars .. LOGICAL LOWER, ROTATE INTEGER I, IDIR, ISUB, ITER, J, LL, LLL, M, MAXIT, NM1, $ NM12, NM13, OLDLL, OLDM DOUBLE PRECISION ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU, $ OLDCS, OLDSN, R, SHIFT, SIGMN, SIGMX, SINL, $ SINR, SLL, SMAX, SMIN, SMINL, SMINLO, SMINOA, $ SN, THRESH, TOL, TOLMUL, UNFL * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DLAMCH EXTERNAL LSAME, DLAMCH * .. * .. External Subroutines .. EXTERNAL DLARTG, DLAS2, DLASQ1, DLASR, DLASV2, DROT, $ DSCAL, DSWAP, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, DBLE, MAX, MIN, SIGN, SQRT * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 LOWER = LSAME( UPLO, 'L' ) IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LOWER ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( NCVT.LT.0 ) THEN INFO = -3 ELSE IF( NRU.LT.0 ) THEN INFO = -4 ELSE IF( NCC.LT.0 ) THEN INFO = -5 ELSE IF( ( NCVT.EQ.0 .AND. LDVT.LT.1 ) .OR. $ ( NCVT.GT.0 .AND. LDVT.LT.MAX( 1, N ) ) ) THEN INFO = -9 ELSE IF( LDU.LT.MAX( 1, NRU ) ) THEN INFO = -11 ELSE IF( ( NCC.EQ.0 .AND. LDC.LT.1 ) .OR. $ ( NCC.GT.0 .AND. LDC.LT.MAX( 1, N ) ) ) THEN INFO = -13 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DBDSQR', -INFO ) RETURN END IF IF( N.EQ.0 ) $ RETURN IF( N.EQ.1 ) $ GO TO 160 * * ROTATE is true if any singular vectors desired, false otherwise * ROTATE = ( NCVT.GT.0 ) .OR. ( NRU.GT.0 ) .OR. ( NCC.GT.0 ) * * If no singular vectors desired, use qd algorithm * IF( .NOT.ROTATE ) THEN CALL DLASQ1( N, D, E, WORK, INFO ) RETURN END IF * NM1 = N - 1 NM12 = NM1 + NM1 NM13 = NM12 + NM1 IDIR = 0 * * Get machine constants * EPS = DLAMCH( 'Epsilon' ) UNFL = DLAMCH( 'Safe minimum' ) * * If matrix lower bidiagonal, rotate to be upper bidiagonal * by applying Givens rotations on the left * IF( LOWER ) THEN DO 10 I = 1, N - 1 CALL DLARTG( D( I ), E( I ), CS, SN, R ) D( I ) = R E( I ) = SN*D( I+1 ) D( I+1 ) = CS*D( I+1 ) WORK( I ) = CS WORK( NM1+I ) = SN 10 CONTINUE * * Update singular vectors if desired * IF( NRU.GT.0 ) $ CALL DLASR( 'R', 'V', 'F', NRU, N, WORK( 1 ), WORK( N ), U, $ LDU ) IF( NCC.GT.0 ) $ CALL DLASR( 'L', 'V', 'F', N, NCC, WORK( 1 ), WORK( N ), C, $ LDC ) END IF * * Compute singular values to relative accuracy TOL * (By setting TOL to be negative, algorithm will compute * singular values to absolute accuracy ABS(TOL)*norm(input matrix)) * TOLMUL = MAX( TEN, MIN( HNDRD, EPS**MEIGTH ) ) TOL = TOLMUL*EPS * * Compute approximate maximum, minimum singular values * SMAX = ZERO DO 20 I = 1, N SMAX = MAX( SMAX, ABS( D( I ) ) ) 20 CONTINUE DO 30 I = 1, N - 1 SMAX = MAX( SMAX, ABS( E( I ) ) ) 30 CONTINUE SMINL = ZERO IF( TOL.GE.ZERO ) THEN * * Relative accuracy desired * SMINOA = ABS( D( 1 ) ) IF( SMINOA.EQ.ZERO ) $ GO TO 50 MU = SMINOA DO 40 I = 2, N MU = ABS( D( I ) )*( MU / ( MU+ABS( E( I-1 ) ) ) ) SMINOA = MIN( SMINOA, MU ) IF( SMINOA.EQ.ZERO ) $ GO TO 50 40 CONTINUE 50 CONTINUE SMINOA = SMINOA / SQRT( DBLE( N ) ) THRESH = MAX( TOL*SMINOA, MAXITR*N*N*UNFL ) ELSE * * Absolute accuracy desired * THRESH = MAX( ABS( TOL )*SMAX, MAXITR*N*N*UNFL ) END IF * * Prepare for main iteration loop for the singular values * (MAXIT is the maximum number of passes through the inner * loop permitted before nonconvergence signalled.) * MAXIT = MAXITR*N*N ITER = 0 OLDLL = -1 OLDM = -1 * * M points to last element of unconverged part of matrix * M = N * * Begin main iteration loop * 60 CONTINUE * * Check for convergence or exceeding iteration count * IF( M.LE.1 ) $ GO TO 160 IF( ITER.GT.MAXIT ) $ GO TO 200 * * Find diagonal block of matrix to work on * IF( TOL.LT.ZERO .AND. ABS( D( M ) ).LE.THRESH ) $ D( M ) = ZERO SMAX = ABS( D( M ) ) SMIN = SMAX DO 70 LLL = 1, M - 1 LL = M - LLL ABSS = ABS( D( LL ) ) ABSE = ABS( E( LL ) ) IF( TOL.LT.ZERO .AND. ABSS.LE.THRESH ) $ D( LL ) = ZERO IF( ABSE.LE.THRESH ) $ GO TO 80 SMIN = MIN( SMIN, ABSS ) SMAX = MAX( SMAX, ABSS, ABSE ) 70 CONTINUE LL = 0 GO TO 90 80 CONTINUE E( LL ) = ZERO * * Matrix splits since E(LL) = 0 * IF( LL.EQ.M-1 ) THEN * * Convergence of bottom singular value, return to top of loop * M = M - 1 GO TO 60 END IF 90 CONTINUE LL = LL + 1 * * E(LL) through E(M-1) are nonzero, E(LL-1) is zero * IF( LL.EQ.M-1 ) THEN * * 2 by 2 block, handle separately * CALL DLASV2( D( M-1 ), E( M-1 ), D( M ), SIGMN, SIGMX, SINR, $ COSR, SINL, COSL ) D( M-1 ) = SIGMX E( M-1 ) = ZERO D( M ) = SIGMN * * Compute singular vectors, if desired * IF( NCVT.GT.0 ) $ CALL DROT( NCVT, VT( M-1, 1 ), LDVT, VT( M, 1 ), LDVT, COSR, $ SINR ) IF( NRU.GT.0 ) $ CALL DROT( NRU, U( 1, M-1 ), 1, U( 1, M ), 1, COSL, SINL ) IF( NCC.GT.0 ) $ CALL DROT( NCC, C( M-1, 1 ), LDC, C( M, 1 ), LDC, COSL, $ SINL ) M = M - 2 GO TO 60 END IF * * If working on new submatrix, choose shift direction * (from larger end diagonal element towards smaller) * IF( LL.GT.OLDM .OR. M.LT.OLDLL ) THEN IF( ABS( D( LL ) ).GE.ABS( D( M ) ) ) THEN * * Chase bulge from top (big end) to bottom (small end) * IDIR = 1 ELSE * * Chase bulge from bottom (big end) to top (small end) * IDIR = 2 END IF END IF * * Apply convergence tests * IF( IDIR.EQ.1 ) THEN * * Run convergence test in forward direction * First apply standard test to bottom of matrix * IF( ABS( E( M-1 ) ).LE.ABS( TOL )*ABS( D( M ) ) .OR. $ ( TOL.LT.ZERO .AND. ABS( E( M-1 ) ).LE.THRESH ) ) THEN E( M-1 ) = ZERO GO TO 60 END IF * IF( TOL.GE.ZERO ) THEN * * If relative accuracy desired, * apply convergence criterion forward * MU = ABS( D( LL ) ) SMINL = MU DO 100 LLL = LL, M - 1 IF( ABS( E( LLL ) ).LE.TOL*MU ) THEN E( LLL ) = ZERO GO TO 60 END IF SMINLO = SMINL MU = ABS( D( LLL+1 ) )*( MU / ( MU+ABS( E( LLL ) ) ) ) SMINL = MIN( SMINL, MU ) 100 CONTINUE END IF * ELSE * * Run convergence test in backward direction * First apply standard test to top of matrix * IF( ABS( E( LL ) ).LE.ABS( TOL )*ABS( D( LL ) ) .OR. $ ( TOL.LT.ZERO .AND. ABS( E( LL ) ).LE.THRESH ) ) THEN E( LL ) = ZERO GO TO 60 END IF * IF( TOL.GE.ZERO ) THEN * * If relative accuracy desired, * apply convergence criterion backward * MU = ABS( D( M ) ) SMINL = MU DO 110 LLL = M - 1, LL, -1 IF( ABS( E( LLL ) ).LE.TOL*MU ) THEN E( LLL ) = ZERO GO TO 60 END IF SMINLO = SMINL MU = ABS( D( LLL ) )*( MU / ( MU+ABS( E( LLL ) ) ) ) SMINL = MIN( SMINL, MU ) 110 CONTINUE END IF END IF OLDLL = LL OLDM = M * * Compute shift. First, test if shifting would ruin relative * accuracy, and if so set the shift to zero. * IF( TOL.GE.ZERO .AND. N*TOL*( SMINL / SMAX ).LE. $ MAX( EPS, HNDRTH*TOL ) ) THEN * * Use a zero shift to avoid loss of relative accuracy * SHIFT = ZERO ELSE * * Compute the shift from 2-by-2 block at end of matrix * IF( IDIR.EQ.1 ) THEN SLL = ABS( D( LL ) ) CALL DLAS2( D( M-1 ), E( M-1 ), D( M ), SHIFT, R ) ELSE SLL = ABS( D( M ) ) CALL DLAS2( D( LL ), E( LL ), D( LL+1 ), SHIFT, R ) END IF * * Test if shift negligible, and if so set to zero * IF( SLL.GT.ZERO ) THEN IF( ( SHIFT / SLL )**2.LT.EPS ) $ SHIFT = ZERO END IF END IF * * Increment iteration count * ITER = ITER + M - LL * * If SHIFT = 0, do simplified QR iteration * IF( SHIFT.EQ.ZERO ) THEN IF( IDIR.EQ.1 ) THEN * * Chase bulge from top to bottom * Save cosines and sines for later singular vector updates * CS = ONE OLDCS = ONE DO 120 I = LL, M - 1 CALL DLARTG( D( I )*CS, E( I ), CS, SN, R ) IF( I.GT.LL ) $ E( I-1 ) = OLDSN*R CALL DLARTG( OLDCS*R, D( I+1 )*SN, OLDCS, OLDSN, D( I ) ) WORK( I-LL+1 ) = CS WORK( I-LL+1+NM1 ) = SN WORK( I-LL+1+NM12 ) = OLDCS WORK( I-LL+1+NM13 ) = OLDSN 120 CONTINUE H = D( M )*CS D( M ) = H*OLDCS E( M-1 ) = H*OLDSN * * Update singular vectors * IF( NCVT.GT.0 ) $ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCVT, WORK( 1 ), $ WORK( N ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL DLASR( 'R', 'V', 'F', NRU, M-LL+1, WORK( NM12+1 ), $ WORK( NM13+1 ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCC, WORK( NM12+1 ), $ WORK( NM13+1 ), C( LL, 1 ), LDC ) * * Test convergence * IF( ABS( E( M-1 ) ).LE.THRESH ) $ E( M-1 ) = ZERO * ELSE * * Chase bulge from bottom to top * Save cosines and sines for later singular vector updates * CS = ONE OLDCS = ONE DO 130 I = M, LL + 1, -1 CALL DLARTG( D( I )*CS, E( I-1 ), CS, SN, R ) IF( I.LT.M ) $ E( I ) = OLDSN*R CALL DLARTG( OLDCS*R, D( I-1 )*SN, OLDCS, OLDSN, D( I ) ) WORK( I-LL ) = CS WORK( I-LL+NM1 ) = -SN WORK( I-LL+NM12 ) = OLDCS WORK( I-LL+NM13 ) = -OLDSN 130 CONTINUE H = D( LL )*CS D( LL ) = H*OLDCS E( LL ) = H*OLDSN * * Update singular vectors * IF( NCVT.GT.0 ) $ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCVT, WORK( NM12+1 ), $ WORK( NM13+1 ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL DLASR( 'R', 'V', 'B', NRU, M-LL+1, WORK( 1 ), $ WORK( N ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCC, WORK( 1 ), $ WORK( N ), C( LL, 1 ), LDC ) * * Test convergence * IF( ABS( E( LL ) ).LE.THRESH ) $ E( LL ) = ZERO END IF ELSE * * Use nonzero shift * IF( IDIR.EQ.1 ) THEN * * Chase bulge from top to bottom * Save cosines and sines for later singular vector updates * F = ( ABS( D( LL ) )-SHIFT )* $ ( SIGN( ONE, D( LL ) )+SHIFT / D( LL ) ) G = E( LL ) DO 140 I = LL, M - 1 CALL DLARTG( F, G, COSR, SINR, R ) IF( I.GT.LL ) $ E( I-1 ) = R F = COSR*D( I ) + SINR*E( I ) E( I ) = COSR*E( I ) - SINR*D( I ) G = SINR*D( I+1 ) D( I+1 ) = COSR*D( I+1 ) CALL DLARTG( F, G, COSL, SINL, R ) D( I ) = R F = COSL*E( I ) + SINL*D( I+1 ) D( I+1 ) = COSL*D( I+1 ) - SINL*E( I ) IF( I.LT.M-1 ) THEN G = SINL*E( I+1 ) E( I+1 ) = COSL*E( I+1 ) END IF WORK( I-LL+1 ) = COSR WORK( I-LL+1+NM1 ) = SINR WORK( I-LL+1+NM12 ) = COSL WORK( I-LL+1+NM13 ) = SINL 140 CONTINUE E( M-1 ) = F * * Update singular vectors * IF( NCVT.GT.0 ) $ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCVT, WORK( 1 ), $ WORK( N ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL DLASR( 'R', 'V', 'F', NRU, M-LL+1, WORK( NM12+1 ), $ WORK( NM13+1 ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCC, WORK( NM12+1 ), $ WORK( NM13+1 ), C( LL, 1 ), LDC ) * * Test convergence * IF( ABS( E( M-1 ) ).LE.THRESH ) $ E( M-1 ) = ZERO * ELSE * * Chase bulge from bottom to top * Save cosines and sines for later singular vector updates * F = ( ABS( D( M ) )-SHIFT )*( SIGN( ONE, D( M ) )+SHIFT / $ D( M ) ) G = E( M-1 ) DO 150 I = M, LL + 1, -1 CALL DLARTG( F, G, COSR, SINR, R ) IF( I.LT.M ) $ E( I ) = R F = COSR*D( I ) + SINR*E( I-1 ) E( I-1 ) = COSR*E( I-1 ) - SINR*D( I ) G = SINR*D( I-1 ) D( I-1 ) = COSR*D( I-1 ) CALL DLARTG( F, G, COSL, SINL, R ) D( I ) = R F = COSL*E( I-1 ) + SINL*D( I-1 ) D( I-1 ) = COSL*D( I-1 ) - SINL*E( I-1 ) IF( I.GT.LL+1 ) THEN G = SINL*E( I-2 ) E( I-2 ) = COSL*E( I-2 ) END IF WORK( I-LL ) = COSR WORK( I-LL+NM1 ) = -SINR WORK( I-LL+NM12 ) = COSL WORK( I-LL+NM13 ) = -SINL 150 CONTINUE E( LL ) = F * * Test convergence * IF( ABS( E( LL ) ).LE.THRESH ) $ E( LL ) = ZERO * * Update singular vectors if desired * IF( NCVT.GT.0 ) $ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCVT, WORK( NM12+1 ), $ WORK( NM13+1 ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL DLASR( 'R', 'V', 'B', NRU, M-LL+1, WORK( 1 ), $ WORK( N ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCC, WORK( 1 ), $ WORK( N ), C( LL, 1 ), LDC ) END IF END IF * * QR iteration finished, go back and check convergence * GO TO 60 * * All singular values converged, so make them positive * 160 CONTINUE DO 170 I = 1, N IF( D( I ).LT.ZERO ) THEN D( I ) = -D( I ) * * Change sign of singular vectors, if desired * IF( NCVT.GT.0 ) $ CALL DSCAL( NCVT, NEGONE, VT( I, 1 ), LDVT ) END IF 170 CONTINUE * * Sort the singular values into decreasing order (insertion sort on * singular values, but only one transposition per singular vector) * DO 190 I = 1, N - 1 * * Scan for smallest D(I) * ISUB = 1 SMIN = D( 1 ) DO 180 J = 2, N + 1 - I IF( D( J ).LE.SMIN ) THEN ISUB = J SMIN = D( J ) END IF 180 CONTINUE IF( ISUB.NE.N+1-I ) THEN * * Swap singular values and vectors * D( ISUB ) = D( N+1-I ) D( N+1-I ) = SMIN IF( NCVT.GT.0 ) $ CALL DSWAP( NCVT, VT( ISUB, 1 ), LDVT, VT( N+1-I, 1 ), $ LDVT ) IF( NRU.GT.0 ) $ CALL DSWAP( NRU, U( 1, ISUB ), 1, U( 1, N+1-I ), 1 ) IF( NCC.GT.0 ) $ CALL DSWAP( NCC, C( ISUB, 1 ), LDC, C( N+1-I, 1 ), LDC ) END IF 190 CONTINUE GO TO 220 * * Maximum number of iterations exceeded, failure to converge * 200 CONTINUE INFO = 0 DO 210 I = 1, N - 1 IF( E( I ).NE.ZERO ) $ INFO = INFO + 1 210 CONTINUE 220 CONTINUE RETURN * * End of DBDSQR * END
lgpl-3.0
bryantabaird/cs6660
Include/eigen/lapack/zlarf.f
281
6278
*> \brief \b ZLARF * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZLARF + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlarf.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlarf.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlarf.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZLARF( SIDE, M, N, V, INCV, TAU, C, LDC, WORK ) * * .. Scalar Arguments .. * CHARACTER SIDE * INTEGER INCV, LDC, M, N * COMPLEX*16 TAU * .. * .. Array Arguments .. * COMPLEX*16 C( LDC, * ), V( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZLARF applies a complex elementary reflector H to a complex M-by-N *> matrix C, from either the left or the right. H is represented in the *> form *> *> H = I - tau * v * v**H *> *> where tau is a complex scalar and v is a complex vector. *> *> If tau = 0, then H is taken to be the unit matrix. *> *> To apply H**H, supply conjg(tau) instead *> tau. *> \endverbatim * * Arguments: * ========== * *> \param[in] SIDE *> \verbatim *> SIDE is CHARACTER*1 *> = 'L': form H * C *> = 'R': form C * H *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix C. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix C. *> \endverbatim *> *> \param[in] V *> \verbatim *> V is COMPLEX*16 array, dimension *> (1 + (M-1)*abs(INCV)) if SIDE = 'L' *> or (1 + (N-1)*abs(INCV)) if SIDE = 'R' *> The vector v in the representation of H. V is not used if *> TAU = 0. *> \endverbatim *> *> \param[in] INCV *> \verbatim *> INCV is INTEGER *> The increment between elements of v. INCV <> 0. *> \endverbatim *> *> \param[in] TAU *> \verbatim *> TAU is COMPLEX*16 *> The value tau in the representation of H. *> \endverbatim *> *> \param[in,out] C *> \verbatim *> C is COMPLEX*16 array, dimension (LDC,N) *> On entry, the M-by-N matrix C. *> On exit, C is overwritten by the matrix H * C if SIDE = 'L', *> or C * H if SIDE = 'R'. *> \endverbatim *> *> \param[in] LDC *> \verbatim *> LDC is INTEGER *> The leading dimension of the array C. LDC >= max(1,M). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX*16 array, dimension *> (N) if SIDE = 'L' *> or (M) if SIDE = 'R' *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex16OTHERauxiliary * * ===================================================================== SUBROUTINE ZLARF( SIDE, M, N, V, INCV, TAU, C, LDC, WORK ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER SIDE INTEGER INCV, LDC, M, N COMPLEX*16 TAU * .. * .. Array Arguments .. COMPLEX*16 C( LDC, * ), V( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX*16 ONE, ZERO PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ), $ ZERO = ( 0.0D+0, 0.0D+0 ) ) * .. * .. Local Scalars .. LOGICAL APPLYLEFT INTEGER I, LASTV, LASTC * .. * .. External Subroutines .. EXTERNAL ZGEMV, ZGERC * .. * .. External Functions .. LOGICAL LSAME INTEGER ILAZLR, ILAZLC EXTERNAL LSAME, ILAZLR, ILAZLC * .. * .. Executable Statements .. * APPLYLEFT = LSAME( SIDE, 'L' ) LASTV = 0 LASTC = 0 IF( TAU.NE.ZERO ) THEN * Set up variables for scanning V. LASTV begins pointing to the end * of V. IF( APPLYLEFT ) THEN LASTV = M ELSE LASTV = N END IF IF( INCV.GT.0 ) THEN I = 1 + (LASTV-1) * INCV ELSE I = 1 END IF * Look for the last non-zero row in V. DO WHILE( LASTV.GT.0 .AND. V( I ).EQ.ZERO ) LASTV = LASTV - 1 I = I - INCV END DO IF( APPLYLEFT ) THEN * Scan for the last non-zero column in C(1:lastv,:). LASTC = ILAZLC(LASTV, N, C, LDC) ELSE * Scan for the last non-zero row in C(:,1:lastv). LASTC = ILAZLR(M, LASTV, C, LDC) END IF END IF * Note that lastc.eq.0 renders the BLAS operations null; no special * case is needed at this level. IF( APPLYLEFT ) THEN * * Form H * C * IF( LASTV.GT.0 ) THEN * * w(1:lastc,1) := C(1:lastv,1:lastc)**H * v(1:lastv,1) * CALL ZGEMV( 'Conjugate transpose', LASTV, LASTC, ONE, $ C, LDC, V, INCV, ZERO, WORK, 1 ) * * C(1:lastv,1:lastc) := C(...) - v(1:lastv,1) * w(1:lastc,1)**H * CALL ZGERC( LASTV, LASTC, -TAU, V, INCV, WORK, 1, C, LDC ) END IF ELSE * * Form C * H * IF( LASTV.GT.0 ) THEN * * w(1:lastc,1) := C(1:lastc,1:lastv) * v(1:lastv,1) * CALL ZGEMV( 'No transpose', LASTC, LASTV, ONE, C, LDC, $ V, INCV, ZERO, WORK, 1 ) * * C(1:lastc,1:lastv) := C(...) - w(1:lastc,1) * v(1:lastv,1)**H * CALL ZGERC( LASTC, LASTV, -TAU, WORK, 1, V, INCV, C, LDC ) END IF END IF RETURN * * End of ZLARF * END
mpl-2.0
aamaricci/SciFortran
src/fftpack/sint1i.f90
1
2723
subroutine sint1i ( n, wsave, lensav, ier ) !*****************************************************************************80 ! !! SINT1I: initialization for SINT1B and SINT1F. ! ! Discussion: ! ! SINT1I initializes array WSAVE for use in its companion routines ! SINT1F and SINT1B. The prime factorization of N together with a ! tabulation of the trigonometric functions are computed and stored ! in array WSAVE. Separate WSAVE arrays are required for different ! values of N. ! ! License: ! ! Licensed under the GNU General Public License (GPL). ! Copyright (C) 1995-2004, Scientific Computing Division, ! University Corporation for Atmospheric Research ! ! Modified: ! ! 15 November 2011 ! ! Author: ! ! Original FORTRAN77 version by Paul Swarztrauber, Richard Valent. ! FORTRAN90 version by John Burkardt. ! ! Reference: ! ! Paul Swarztrauber, ! Vectorizing the Fast Fourier Transforms, ! in Parallel Computations, ! edited by G. Rodrigue, ! Academic Press, 1982. ! ! Paul Swarztrauber, ! Fast Fourier Transform Algorithms for Vector Computers, ! Parallel Computing, pages 45-63, 1984. ! ! Parameters: ! ! Input, integer ( kind = 4 ) N, the length of the sequence to be ! transformed. The transform is most efficient when N+1 is a product ! of small primes. ! ! Input, integer ( kind = 4 ) LENSAV, the dimension of the WSAVE array. ! LENSAV must be at least N/2 + N + INT(LOG(REAL(N))) + 4. ! ! Output, real ( kind = 8 ) WSAVE(LENSAV), containing the prime factors ! of N and also containing certain trigonometric values which will be used ! in routines SINT1B or SINT1F. ! ! Output, integer ( kind = 4 ) IER, error flag. ! 0, successful exit; ! 2, input parameter LENSAV not big enough; ! 20, input error returned by lower level routine. ! implicit none integer ( kind = 4 ) lensav real ( kind = 8 ) dt integer ( kind = 4 ) ier integer ( kind = 4 ) ier1 integer ( kind = 4 ) k integer ( kind = 4 ) lnsv integer ( kind = 4 ) n integer ( kind = 4 ) np1 integer ( kind = 4 ) ns2 real ( kind = 8 ) pi real ( kind = 8 ) wsave(lensav) ier = 0 if (lensav < n/2 + n + int(log( real ( n, kind = 8 ) ) & /log( 2.0D+00 )) +4) then ier = 2 call xerfft ('sint1i', 3) return end if pi = 4.0D+00 * atan ( 1.0D+00 ) if (n <= 1) then return end if ns2 = n/2 np1 = n+1 dt = pi / real ( np1, kind = 8 ) do k=1,ns2 wsave(k) = 2.0D+00 *sin(k*dt) end do lnsv = np1 + int(log( real ( np1, kind = 8 ))/log( 2.0D+00 )) +4 call rfft1i (np1, wsave(ns2+1), lnsv, ier1) if (ier1 /= 0) then ier = 20 call xerfft ('sint1i',-5) end if return end
lgpl-3.0
huard/scipy-work
scipy/integrate/odepack/cntnzu.f
18
1223
subroutine cntnzu (n, ia, ja, nzsut) integer n, ia, ja, nzsut dimension ia(1), ja(1) c----------------------------------------------------------------------- c this routine counts the number of nonzero elements in the strict c upper triangle of the matrix m + m(transpose), where the sparsity c structure of m is given by pointer arrays ia and ja. c this is needed to compute the storage requirements for the c sparse matrix reordering operation in odrv. c----------------------------------------------------------------------- integer ii, jj, j, jmin, jmax, k, kmin, kmax, num c num = 0 do 50 ii = 1,n jmin = ia(ii) jmax = ia(ii+1) - 1 if (jmin .gt. jmax) go to 50 do 40 j = jmin,jmax if (ja(j).lt.ii) go to 10 if (ja(j).eq.ii) go to 40 go to 30 10 jj =ja(j) kmin = ia(jj) kmax = ia(jj+1) - 1 if (kmin .gt. kmax) go to 30 do 20 k = kmin,kmax if (ja(k) .eq. ii) go to 40 20 continue 30 num = num + 1 40 continue 50 continue nzsut = num return c----------------------- end of subroutine cntnzu ---------------------- end
bsd-3-clause
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/dgesc2.f
24
5451
*> \brief \b DGESC2 solves a system of linear equations using the LU factorization with complete pivoting computed by sgetc2. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGESC2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgesc2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgesc2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgesc2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGESC2( N, A, LDA, RHS, IPIV, JPIV, SCALE ) * * .. Scalar Arguments .. * INTEGER LDA, N * DOUBLE PRECISION SCALE * .. * .. Array Arguments .. * INTEGER IPIV( * ), JPIV( * ) * DOUBLE PRECISION A( LDA, * ), RHS( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGESC2 solves a system of linear equations *> *> A * X = scale* RHS *> *> with a general N-by-N matrix A using the LU factorization with *> complete pivoting computed by DGETC2. *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On entry, the LU part of the factorization of the n-by-n *> matrix A computed by DGETC2: A = P * L * U * Q *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1, N). *> \endverbatim *> *> \param[in,out] RHS *> \verbatim *> RHS is DOUBLE PRECISION array, dimension (N). *> On entry, the right hand side vector b. *> On exit, the solution vector X. *> \endverbatim *> *> \param[in] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N). *> The pivot indices; for 1 <= i <= N, row i of the *> matrix has been interchanged with row IPIV(i). *> \endverbatim *> *> \param[in] JPIV *> \verbatim *> JPIV is INTEGER array, dimension (N). *> The pivot indices; for 1 <= j <= N, column j of the *> matrix has been interchanged with column JPIV(j). *> \endverbatim *> *> \param[out] SCALE *> \verbatim *> SCALE is DOUBLE PRECISION *> On exit, SCALE contains the scale factor. SCALE is chosen *> 0 <= SCALE <= 1 to prevent owerflow in the solution. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup doubleGEauxiliary * *> \par Contributors: * ================== *> *> Bo Kagstrom and Peter Poromaa, Department of Computing Science, *> Umea University, S-901 87 Umea, Sweden. * * ===================================================================== SUBROUTINE DGESC2( N, A, LDA, RHS, IPIV, JPIV, SCALE ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER LDA, N DOUBLE PRECISION SCALE * .. * .. Array Arguments .. INTEGER IPIV( * ), JPIV( * ) DOUBLE PRECISION A( LDA, * ), RHS( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, TWO PARAMETER ( ONE = 1.0D+0, TWO = 2.0D+0 ) * .. * .. Local Scalars .. INTEGER I, J DOUBLE PRECISION BIGNUM, EPS, SMLNUM, TEMP * .. * .. External Subroutines .. EXTERNAL DLASWP, DSCAL * .. * .. External Functions .. INTEGER IDAMAX DOUBLE PRECISION DLAMCH EXTERNAL IDAMAX, DLAMCH * .. * .. Intrinsic Functions .. INTRINSIC ABS * .. * .. Executable Statements .. * * Set constant to control owerflow * EPS = DLAMCH( 'P' ) SMLNUM = DLAMCH( 'S' ) / EPS BIGNUM = ONE / SMLNUM CALL DLABAD( SMLNUM, BIGNUM ) * * Apply permutations IPIV to RHS * CALL DLASWP( 1, RHS, LDA, 1, N-1, IPIV, 1 ) * * Solve for L part * DO 20 I = 1, N - 1 DO 10 J = I + 1, N RHS( J ) = RHS( J ) - A( J, I )*RHS( I ) 10 CONTINUE 20 CONTINUE * * Solve for U part * SCALE = ONE * * Check for scaling * I = IDAMAX( N, RHS, 1 ) IF( TWO*SMLNUM*ABS( RHS( I ) ).GT.ABS( A( N, N ) ) ) THEN TEMP = ( ONE / TWO ) / ABS( RHS( I ) ) CALL DSCAL( N, TEMP, RHS( 1 ), 1 ) SCALE = SCALE*TEMP END IF * DO 40 I = N, 1, -1 TEMP = ONE / A( I, I ) RHS( I ) = RHS( I )*TEMP DO 30 J = I + 1, N RHS( I ) = RHS( I ) - RHS( J )*( A( I, J )*TEMP ) 30 CONTINUE 40 CONTINUE * * Apply permutations JPIV to the solution (RHS) * CALL DLASWP( 1, RHS, LDA, 1, N-1, JPIV, -1 ) RETURN * * End of DGESC2 * END
apache-2.0
leo-butler/Maxima-CAS
share/lapack/lapack/fortran/dlaexc.f
11
10799
SUBROUTINE DLAEXC( WANTQ, N, T, LDT, Q, LDQ, J1, N1, N2, WORK, $ INFO ) * * -- LAPACK auxiliary routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * February 29, 1992 * * .. Scalar Arguments .. LOGICAL WANTQ INTEGER INFO, J1, LDQ, LDT, N, N1, N2 * .. * .. Array Arguments .. DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WORK( * ) * .. * * Purpose * ======= * * DLAEXC swaps adjacent diagonal blocks T11 and T22 of order 1 or 2 in * an upper quasi-triangular matrix T by an orthogonal similarity * transformation. * * T must be in Schur canonical form, that is, block upper triangular * with 1-by-1 and 2-by-2 diagonal blocks; each 2-by-2 diagonal block * has its diagonal elemnts equal and its off-diagonal elements of * opposite sign. * * Arguments * ========= * * WANTQ (input) LOGICAL * = .TRUE. : accumulate the transformation in the matrix Q; * = .FALSE.: do not accumulate the transformation. * * N (input) INTEGER * The order of the matrix T. N >= 0. * * T (input/output) DOUBLE PRECISION array, dimension (LDT,N) * On entry, the upper quasi-triangular matrix T, in Schur * canonical form. * On exit, the updated matrix T, again in Schur canonical form. * * LDT (input) INTEGER * The leading dimension of the array T. LDT >= max(1,N). * * Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N) * On entry, if WANTQ is .TRUE., the orthogonal matrix Q. * On exit, if WANTQ is .TRUE., the updated matrix Q. * If WANTQ is .FALSE., Q is not referenced. * * LDQ (input) INTEGER * The leading dimension of the array Q. * LDQ >= 1; and if WANTQ is .TRUE., LDQ >= N. * * J1 (input) INTEGER * The index of the first row of the first block T11. * * N1 (input) INTEGER * The order of the first block T11. N1 = 0, 1 or 2. * * N2 (input) INTEGER * The order of the second block T22. N2 = 0, 1 or 2. * * WORK (workspace) DOUBLE PRECISION array, dimension (N) * * INFO (output) INTEGER * = 0: successful exit * = 1: the transformed matrix T would be too far from Schur * form; the blocks are not swapped and T and Q are * unchanged. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) DOUBLE PRECISION TEN PARAMETER ( TEN = 1.0D+1 ) INTEGER LDD, LDX PARAMETER ( LDD = 4, LDX = 2 ) * .. * .. Local Scalars .. INTEGER IERR, J2, J3, J4, K, ND DOUBLE PRECISION CS, DNORM, EPS, SCALE, SMLNUM, SN, T11, T22, $ T33, TAU, TAU1, TAU2, TEMP, THRESH, WI1, WI2, $ WR1, WR2, XNORM * .. * .. Local Arrays .. DOUBLE PRECISION D( LDD, 4 ), U( 3 ), U1( 3 ), U2( 3 ), $ X( LDX, 2 ) * .. * .. External Functions .. DOUBLE PRECISION DLAMCH, DLANGE EXTERNAL DLAMCH, DLANGE * .. * .. External Subroutines .. EXTERNAL DLACPY, DLANV2, DLARFG, DLARFX, DLARTG, DLASY2, $ DROT * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX * .. * .. Executable Statements .. * INFO = 0 * * Quick return if possible * IF( N.EQ.0 .OR. N1.EQ.0 .OR. N2.EQ.0 ) $ RETURN IF( J1+N1.GT.N ) $ RETURN * J2 = J1 + 1 J3 = J1 + 2 J4 = J1 + 3 * IF( N1.EQ.1 .AND. N2.EQ.1 ) THEN * * Swap two 1-by-1 blocks. * T11 = T( J1, J1 ) T22 = T( J2, J2 ) * * Determine the transformation to perform the interchange. * CALL DLARTG( T( J1, J2 ), T22-T11, CS, SN, TEMP ) * * Apply transformation to the matrix T. * IF( J3.LE.N ) $ CALL DROT( N-J1-1, T( J1, J3 ), LDT, T( J2, J3 ), LDT, CS, $ SN ) CALL DROT( J1-1, T( 1, J1 ), 1, T( 1, J2 ), 1, CS, SN ) * T( J1, J1 ) = T22 T( J2, J2 ) = T11 * IF( WANTQ ) THEN * * Accumulate transformation in the matrix Q. * CALL DROT( N, Q( 1, J1 ), 1, Q( 1, J2 ), 1, CS, SN ) END IF * ELSE * * Swapping involves at least one 2-by-2 block. * * Copy the diagonal block of order N1+N2 to the local array D * and compute its norm. * ND = N1 + N2 CALL DLACPY( 'Full', ND, ND, T( J1, J1 ), LDT, D, LDD ) DNORM = DLANGE( 'Max', ND, ND, D, LDD, WORK ) * * Compute machine-dependent threshold for test for accepting * swap. * EPS = DLAMCH( 'P' ) SMLNUM = DLAMCH( 'S' ) / EPS THRESH = MAX( TEN*EPS*DNORM, SMLNUM ) * * Solve T11*X - X*T22 = scale*T12 for X. * CALL DLASY2( .FALSE., .FALSE., -1, N1, N2, D, LDD, $ D( N1+1, N1+1 ), LDD, D( 1, N1+1 ), LDD, SCALE, X, $ LDX, XNORM, IERR ) * * Swap the adjacent diagonal blocks. * K = N1 + N1 + N2 - 3 GO TO ( 10, 20, 30 )K * 10 CONTINUE * * N1 = 1, N2 = 2: generate elementary reflector H so that: * * ( scale, X11, X12 ) H = ( 0, 0, * ) * U( 1 ) = SCALE U( 2 ) = X( 1, 1 ) U( 3 ) = X( 1, 2 ) CALL DLARFG( 3, U( 3 ), U, 1, TAU ) U( 3 ) = ONE T11 = T( J1, J1 ) * * Perform swap provisionally on diagonal block in D. * CALL DLARFX( 'L', 3, 3, U, TAU, D, LDD, WORK ) CALL DLARFX( 'R', 3, 3, U, TAU, D, LDD, WORK ) * * Test whether to reject swap. * IF( MAX( ABS( D( 3, 1 ) ), ABS( D( 3, 2 ) ), ABS( D( 3, $ 3 )-T11 ) ).GT.THRESH )GO TO 50 * * Accept swap: apply transformation to the entire matrix T. * CALL DLARFX( 'L', 3, N-J1+1, U, TAU, T( J1, J1 ), LDT, WORK ) CALL DLARFX( 'R', J2, 3, U, TAU, T( 1, J1 ), LDT, WORK ) * T( J3, J1 ) = ZERO T( J3, J2 ) = ZERO T( J3, J3 ) = T11 * IF( WANTQ ) THEN * * Accumulate transformation in the matrix Q. * CALL DLARFX( 'R', N, 3, U, TAU, Q( 1, J1 ), LDQ, WORK ) END IF GO TO 40 * 20 CONTINUE * * N1 = 2, N2 = 1: generate elementary reflector H so that: * * H ( -X11 ) = ( * ) * ( -X21 ) = ( 0 ) * ( scale ) = ( 0 ) * U( 1 ) = -X( 1, 1 ) U( 2 ) = -X( 2, 1 ) U( 3 ) = SCALE CALL DLARFG( 3, U( 1 ), U( 2 ), 1, TAU ) U( 1 ) = ONE T33 = T( J3, J3 ) * * Perform swap provisionally on diagonal block in D. * CALL DLARFX( 'L', 3, 3, U, TAU, D, LDD, WORK ) CALL DLARFX( 'R', 3, 3, U, TAU, D, LDD, WORK ) * * Test whether to reject swap. * IF( MAX( ABS( D( 2, 1 ) ), ABS( D( 3, 1 ) ), ABS( D( 1, $ 1 )-T33 ) ).GT.THRESH )GO TO 50 * * Accept swap: apply transformation to the entire matrix T. * CALL DLARFX( 'R', J3, 3, U, TAU, T( 1, J1 ), LDT, WORK ) CALL DLARFX( 'L', 3, N-J1, U, TAU, T( J1, J2 ), LDT, WORK ) * T( J1, J1 ) = T33 T( J2, J1 ) = ZERO T( J3, J1 ) = ZERO * IF( WANTQ ) THEN * * Accumulate transformation in the matrix Q. * CALL DLARFX( 'R', N, 3, U, TAU, Q( 1, J1 ), LDQ, WORK ) END IF GO TO 40 * 30 CONTINUE * * N1 = 2, N2 = 2: generate elementary reflectors H(1) and H(2) so * that: * * H(2) H(1) ( -X11 -X12 ) = ( * * ) * ( -X21 -X22 ) ( 0 * ) * ( scale 0 ) ( 0 0 ) * ( 0 scale ) ( 0 0 ) * U1( 1 ) = -X( 1, 1 ) U1( 2 ) = -X( 2, 1 ) U1( 3 ) = SCALE CALL DLARFG( 3, U1( 1 ), U1( 2 ), 1, TAU1 ) U1( 1 ) = ONE * TEMP = -TAU1*( X( 1, 2 )+U1( 2 )*X( 2, 2 ) ) U2( 1 ) = -TEMP*U1( 2 ) - X( 2, 2 ) U2( 2 ) = -TEMP*U1( 3 ) U2( 3 ) = SCALE CALL DLARFG( 3, U2( 1 ), U2( 2 ), 1, TAU2 ) U2( 1 ) = ONE * * Perform swap provisionally on diagonal block in D. * CALL DLARFX( 'L', 3, 4, U1, TAU1, D, LDD, WORK ) CALL DLARFX( 'R', 4, 3, U1, TAU1, D, LDD, WORK ) CALL DLARFX( 'L', 3, 4, U2, TAU2, D( 2, 1 ), LDD, WORK ) CALL DLARFX( 'R', 4, 3, U2, TAU2, D( 1, 2 ), LDD, WORK ) * * Test whether to reject swap. * IF( MAX( ABS( D( 3, 1 ) ), ABS( D( 3, 2 ) ), ABS( D( 4, 1 ) ), $ ABS( D( 4, 2 ) ) ).GT.THRESH )GO TO 50 * * Accept swap: apply transformation to the entire matrix T. * CALL DLARFX( 'L', 3, N-J1+1, U1, TAU1, T( J1, J1 ), LDT, WORK ) CALL DLARFX( 'R', J4, 3, U1, TAU1, T( 1, J1 ), LDT, WORK ) CALL DLARFX( 'L', 3, N-J1+1, U2, TAU2, T( J2, J1 ), LDT, WORK ) CALL DLARFX( 'R', J4, 3, U2, TAU2, T( 1, J2 ), LDT, WORK ) * T( J3, J1 ) = ZERO T( J3, J2 ) = ZERO T( J4, J1 ) = ZERO T( J4, J2 ) = ZERO * IF( WANTQ ) THEN * * Accumulate transformation in the matrix Q. * CALL DLARFX( 'R', N, 3, U1, TAU1, Q( 1, J1 ), LDQ, WORK ) CALL DLARFX( 'R', N, 3, U2, TAU2, Q( 1, J2 ), LDQ, WORK ) END IF * 40 CONTINUE * IF( N2.EQ.2 ) THEN * * Standardize new 2-by-2 block T11 * CALL DLANV2( T( J1, J1 ), T( J1, J2 ), T( J2, J1 ), $ T( J2, J2 ), WR1, WI1, WR2, WI2, CS, SN ) CALL DROT( N-J1-1, T( J1, J1+2 ), LDT, T( J2, J1+2 ), LDT, $ CS, SN ) CALL DROT( J1-1, T( 1, J1 ), 1, T( 1, J2 ), 1, CS, SN ) IF( WANTQ ) $ CALL DROT( N, Q( 1, J1 ), 1, Q( 1, J2 ), 1, CS, SN ) END IF * IF( N1.EQ.2 ) THEN * * Standardize new 2-by-2 block T22 * J3 = J1 + N2 J4 = J3 + 1 CALL DLANV2( T( J3, J3 ), T( J3, J4 ), T( J4, J3 ), $ T( J4, J4 ), WR1, WI1, WR2, WI2, CS, SN ) IF( J3+2.LE.N ) $ CALL DROT( N-J3-1, T( J3, J3+2 ), LDT, T( J4, J3+2 ), $ LDT, CS, SN ) CALL DROT( J3-1, T( 1, J3 ), 1, T( 1, J4 ), 1, CS, SN ) IF( WANTQ ) $ CALL DROT( N, Q( 1, J3 ), 1, Q( 1, J4 ), 1, CS, SN ) END IF * END IF RETURN * * Exit with INFO = 1 if swap was rejected. * 50 CONTINUE INFO = 1 RETURN * * End of DLAEXC * END
gpl-2.0
aamaricci/SciFortran
src/arpack/parpack/src/pcnaitr.f
1
32119
c\BeginDoc c c\Name: pcnaitr c c Message Passing Layer: MPI c c\Description: c Reverse communication interface for applying NP additional steps to c a K step nonsymmetric Arnoldi factorization. c c Input: OP*V_{k} - V_{k}*H = r_{k}*e_{k}^T c c with (V_{k}^T)*B*V_{k} = I, (V_{k}^T)*B*r_{k} = 0. c c Output: OP*V_{k+p} - V_{k+p}*H = r_{k+p}*e_{k+p}^T c c with (V_{k+p}^T)*B*V_{k+p} = I, (V_{k+p}^T)*B*r_{k+p} = 0. c c where OP and B are as in pcnaupd. The B-norm of r_{k+p} is also c computed and returned. c c\Usage: c call pcnaitr c ( COMM, IDO, BMAT, N, K, NP, NB, RESID, RNORM, V, LDV, H, LDH, c IPNTR, WORKD, WORKL, INFO ) c c\Arguments c COMM MPI Communicator for the processor grid. (INPUT) c c IDO Integer. (INPUT/OUTPUT) c Reverse communication flag. c ------------------------------------------------------------- c IDO = 0: first call to the reverse communication interface c IDO = -1: compute Y = OP * X where c IPNTR(1) is the pointer into WORK for X, c IPNTR(2) is the pointer into WORK for Y. c This is for the restart phase to force the new c starting vector into the range of OP. c IDO = 1: compute Y = OP * X where c IPNTR(1) is the pointer into WORK for X, c IPNTR(2) is the pointer into WORK for Y, c IPNTR(3) is the pointer into WORK for B * X. c IDO = 2: compute Y = B * X where c IPNTR(1) is the pointer into WORK for X, c IPNTR(2) is the pointer into WORK for Y. c IDO = 99: done c ------------------------------------------------------------- c When the routine is used in the "shift-and-invert" mode, the c vector B * Q is already available and do not need to be c recomputed in forming OP * Q. c c BMAT Character*1. (INPUT) c BMAT specifies the type of the matrix B that defines the c semi-inner product for the operator OP. See pcnaupd. c B = 'I' -> standard eigenvalue problem A*x = lambda*x c B = 'G' -> generalized eigenvalue problem A*x = lambda*M**x c c N Integer. (INPUT) c Dimension of the eigenproblem. c c K Integer. (INPUT) c Current size of V and H. c c NP Integer. (INPUT) c Number of additional Arnoldi steps to take. c c NB Integer. (INPUT) c Blocksize to be used in the recurrence. c Only work for NB = 1 right now. The goal is to have a c program that implement both the block and non-block method. c c RESID Complex array of length N. (INPUT/OUTPUT) c On INPUT: RESID contains the residual vector r_{k}. c On OUTPUT: RESID contains the residual vector r_{k+p}. c c RNORM Real scalar. (INPUT/OUTPUT) c B-norm of the starting residual on input. c B-norm of the updated residual r_{k+p} on output. c c V Complex N by K+NP array. (INPUT/OUTPUT) c On INPUT: V contains the Arnoldi vectors in the first K c columns. c On OUTPUT: V contains the new NP Arnoldi vectors in the next c NP columns. The first K columns are unchanged. c c LDV Integer. (INPUT) c Leading dimension of V exactly as declared in the calling c program. c c H Complex (K+NP) by (K+NP) array. (INPUT/OUTPUT) c H is used to store the generated upper Hessenberg matrix. c c LDH Integer. (INPUT) c Leading dimension of H exactly as declared in the calling c program. c c IPNTR Integer array of length 3. (OUTPUT) c Pointer to mark the starting locations in the WORK for c vectors used by the Arnoldi iteration. c ------------------------------------------------------------- c IPNTR(1): pointer to the current operand vector X. c IPNTR(2): pointer to the current result vector Y. c IPNTR(3): pointer to the vector B * X when used in the c shift-and-invert mode. X is the current operand. c ------------------------------------------------------------- c c WORKD Complex work array of length 3*N. (REVERSE COMMUNICATION) c Distributed array to be used in the basic Arnoldi iteration c for reverse communication. The calling program should not c use WORKD as temporary workspace during the iteration !!!!!! c On input, WORKD(1:N) = B*RESID and is used to save some c computation at the first step. c c WORKL Complex work space used for Gram Schmidt orthogonalization c c INFO Integer. (OUTPUT) c = 0: Normal exit. c > 0: Size of the spanning invariant subspace of OP found. c c\EndDoc c c----------------------------------------------------------------------- c c\BeginLib c c\Local variables: c xxxxxx Complex c c\References: c 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in c a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), c pp 357-385. c 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly c Restarted Arnoldi Iteration", Rice University Technical Report c TR95-13, Department of Computational and Applied Mathematics. c c\Routines called: c pcgetv0 Parallel ARPACK routine to generate the initial vector. c pivout Parallel ARPACK utility routine that prints integers. c arscnd ARPACK utility routine for timing. c pcmout Parallel ARPACK utility routine that prints matrices c pcvout Parallel ARPACK utility routine that prints vectors. c clanhs LAPACK routine that computes various norms of a matrix. c clascl LAPACK routine for careful scaling of a matrix. c slabad LAPACK routine for defining the underflow and overflow c limits c pslamch10 ScaLAPACK routine that determines machine constants. c slapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully. c cgemv Level 2 BLAS routine for matrix vector multiplication. c caxpy Level 1 BLAS that computes a vector triad. c ccopy Level 1 BLAS that copies one vector to another . c cdotc Level 1 BLAS that computes the scalar product of c two vectors. c cscal Level 1 BLAS that scales a vector. c csscal Level 1 BLAS that scales a complex vector by a real number. c pscnorm2 Parallel version of Level 1 BLAS that computes the c norm of a vector. c c\Author c Danny Sorensen Phuong Vu c Richard Lehoucq CRPC / Rice University c Dept. of Computational & Houston, Texas c Applied Mathematics c Rice University c Houston, Texas c c\Parallel Modifications c Kristi Maschhoff c c\Revision history: c Starting Point: Complex Code FILE: naitr.F SID: 2.1 c c\SCCS Information: c FILE: naitr.F SID: 1.3 DATE OF SID: 3/19/97 c c\Remarks c The algorithm implemented is: c c restart = .false. c Given V_{k} = [v_{1}, ..., v_{k}], r_{k}; c r_{k} contains the initial residual vector even for k = 0; c Also assume that rnorm = || B*r_{k} || and B*r_{k} are already c computed by the calling program. c c betaj = rnorm ; p_{k+1} = B*r_{k} ; c For j = k+1, ..., k+np Do c 1) if ( betaj < tol ) stop or restart depending on j. c ( At present tol is zero ) c if ( restart ) generate a new starting vector. c 2) v_{j} = r(j-1)/betaj; V_{j} = [V_{j-1}, v_{j}]; c p_{j} = p_{j}/betaj c 3) r_{j} = OP*v_{j} where OP is defined as in pcnaupd c For shift-invert mode p_{j} = B*v_{j} is already available. c wnorm = || OP*v_{j} || c 4) Compute the j-th step residual vector. c w_{j} = V_{j}^T * B * OP * v_{j} c r_{j} = OP*v_{j} - V_{j} * w_{j} c H(:,j) = w_{j}; c H(j,j-1) = rnorm c rnorm = || r_(j) || c If (rnorm > 0.717*wnorm) accept step and go back to 1) c 5) Re-orthogonalization step: c s = V_{j}'*B*r_{j} c r_{j} = r_{j} - V_{j}*s; rnorm1 = || r_{j} || c alphaj = alphaj + s_{j}; c 6) Iterative refinement step: c If (rnorm1 > 0.717*rnorm) then c rnorm = rnorm1 c accept step and go back to 1) c Else c rnorm = rnorm1 c If this is the first time in step 6), go to 5) c Else r_{j} lies in the span of V_{j} numerically. c Set r_{j} = 0 and rnorm = 0; go to 1) c EndIf c End Do c c\EndLib c c----------------------------------------------------------------------- c subroutine pcnaitr & (comm, ido, bmat, n, k, np, nb, resid, rnorm, v, ldv, h, ldh, & ipntr, workd, workl, info) c include 'pcontext.h' include 'mpif.h' c c %---------------% c | MPI Variables | c %---------------% c integer comm c c %----------------------------------------------------% c | Include files for debugging and timing information | c %----------------------------------------------------% c include 'debug.h' include 'stat.h' c c %------------------% c | Scalar Arguments | c %------------------% c character bmat*1 integer ido, info, k, ldh, ldv, n, nb, np Real & rnorm c c %-----------------% c | Array Arguments | c %-----------------% c integer ipntr(3) Complex & h(ldh,k+np), resid(n), v(ldv,k+np), workd(3*n), & workl(2*ldh) c c %------------% c | Parameters | c %------------% c Complex & one, zero Real & rone, rzero parameter (one = (1.0, 0.0), zero = (0.0, 0.0), & rone = 1.0, rzero = 0.0) c c %--------------% c | Local Arrays | c %--------------% c Real & rtemp(2) c c %---------------% c | Local Scalars | c %---------------% c logical orth1, orth2, rstart, step3, step4 integer ierr, i, infol, ipj, irj, ivj, iter, itry, j, msglvl, & jj Real & ovfl, smlnum, tst1, ulp, unfl, betaj, & temp1, rnorm1, wnorm Complex & cnorm c save orth1, orth2, rstart, step3, step4, & ierr, ipj, irj, ivj, iter, itry, j, msglvl, ovfl, & betaj, rnorm1, smlnum, ulp, unfl, wnorm c Complex & cnorm_buf c c %----------------------% c | External Subroutines | c %----------------------% c external caxpy, ccopy, cscal, cgemv, pcgetv0, slabad, & csscal, pcvout, pcmout, pivout, arscnd c c %--------------------% c | External Functions | c %--------------------% c Complex & cdotc Real & pslamch10, pscnorm2, clanhs, slapy2 external cdotc, pscnorm2, clanhs, pslamch10, slapy2 c c %---------------------% c | Intrinsic Functions | c %---------------------% c intrinsic aimag, real, max, sqrt c c %-----------------% c | Data statements | c %-----------------% c c c %-----------------------% c | Executable Statements | c %-----------------------% c if (aitr_first) then c c %-----------------------------------------% c | Set machine-dependent constants for the | c | the splitting and deflation criterion. | c | If norm(H) <= sqrt(OVFL), | c | overflow should not occur. | c | REFERENCE: LAPACK subroutine clahqr | c %-----------------------------------------% c unfl = pslamch10(comm, 'safe minimum' ) ovfl = real(one / unfl) call slabad( unfl, ovfl ) ulp = pslamch10( comm, 'precision' ) smlnum = unfl*( n / ulp ) aitr_first = .false. end if c if (ido .eq. 0) then c c %-------------------------------% c | Initialize timing statistics | c | & message level for debugging | c %-------------------------------% c call arscnd (t0) msglvl = mcaitr c c %------------------------------% c | Initial call to this routine | c %------------------------------% c info = 0 step3 = .false. step4 = .false. rstart = .false. orth1 = .false. orth2 = .false. j = k + 1 ipj = 1 irj = ipj + n ivj = irj + n end if c c %-------------------------------------------------% c | When in reverse communication mode one of: | c | STEP3, STEP4, ORTH1, ORTH2, RSTART | c | will be .true. when .... | c | STEP3: return from computing OP*v_{j}. | c | STEP4: return from computing B-norm of OP*v_{j} | c | ORTH1: return from computing B-norm of r_{j+1} | c | ORTH2: return from computing B-norm of | c | correction to the residual vector. | c | RSTART: return from OP computations needed by | c | pcgetv0. | c %-------------------------------------------------% c if (step3) go to 50 if (step4) go to 60 if (orth1) go to 70 if (orth2) go to 90 if (rstart) go to 30 c c %-----------------------------% c | Else this is the first step | c %-----------------------------% c c %--------------------------------------------------------------% c | | c | A R N O L D I I T E R A T I O N L O O P | c | | c | Note: B*r_{j-1} is already in WORKD(1:N)=WORKD(IPJ:IPJ+N-1) | c %--------------------------------------------------------------% 1000 continue c if (msglvl .gt. 1) then call pivout (comm, logfil, 1, j, ndigit, & '_naitr: generating Arnoldi vector number') call pcvout (comm, logfil, 1, rnorm, ndigit, & '_naitr: B-norm of the current residual is') end if c c %---------------------------------------------------% c | STEP 1: Check if the B norm of j-th residual | c | vector is zero. Equivalent to determine whether | c | an exact j-step Arnoldi factorization is present. | c %---------------------------------------------------% c betaj = rnorm if (rnorm .gt. rzero) go to 40 c c %---------------------------------------------------% c | Invariant subspace found, generate a new starting | c | vector which is orthogonal to the current Arnoldi | c | basis and continue the iteration. | c %---------------------------------------------------% c if (msglvl .gt. 0) then call pivout (comm, logfil, 1, j, ndigit, & '_naitr: ****** RESTART AT STEP ******') end if c c %---------------------------------------------% c | ITRY is the loop variable that controls the | c | maximum amount of times that a restart is | c | attempted. NRSTRT is used by stat.h | c %---------------------------------------------% c betaj = rzero nrstrt = nrstrt + 1 itry = 1 20 continue rstart = .true. ido = 0 30 continue c c %--------------------------------------% c | If in reverse communication mode and | c | RSTART = .true. flow returns here. | c %--------------------------------------% c call pcgetv0 (comm, ido, bmat, itry, .false., n, j, v, ldv, & resid, rnorm, ipntr, workd, workl, ierr) if (ido .ne. 99) go to 9000 if (ierr .lt. 0) then itry = itry + 1 if (itry .le. 3) go to 20 c c %------------------------------------------------% c | Give up after several restart attempts. | c | Set INFO to the size of the invariant subspace | c | which spans OP and exit. | c %------------------------------------------------% c info = j - 1 call arscnd (t1) tcaitr = tcaitr + (t1 - t0) ido = 99 go to 9000 end if c 40 continue c c %---------------------------------------------------------% c | STEP 2: v_{j} = r_{j-1}/rnorm and p_{j} = p_{j}/rnorm | c | Note that p_{j} = B*r_{j-1}. In order to avoid overflow | c | when reciprocating a small RNORM, test against lower | c | machine bound. | c %---------------------------------------------------------% c call ccopy (n, resid, 1, v(1,j), 1) if ( rnorm .ge. unfl) then temp1 = rone / rnorm call csscal (n, temp1, v(1,j), 1) call csscal (n, temp1, workd(ipj), 1) else c c %-----------------------------------------% c | To scale both v_{j} and p_{j} carefully | c | use LAPACK routine clascl | c %-----------------------------------------% c call clascl ('General', i, i, rnorm, rone, & n, 1, v(1,j), n, infol) call clascl ('General', i, i, rnorm, rone, & n, 1, workd(ipj), n, infol) end if c c %------------------------------------------------------% c | STEP 3: r_{j} = OP*v_{j}; Note that p_{j} = B*v_{j} | c | Note that this is not quite yet r_{j}. See STEP 4 | c %------------------------------------------------------% c step3 = .true. nopx = nopx + 1 call arscnd (t2) call ccopy (n, v(1,j), 1, workd(ivj), 1) ipntr(1) = ivj ipntr(2) = irj ipntr(3) = ipj ido = 1 c c %-----------------------------------% c | Exit in order to compute OP*v_{j} | c %-----------------------------------% c go to 9000 50 continue c c %----------------------------------% c | Back from reverse communication; | c | WORKD(IRJ:IRJ+N-1) := OP*v_{j} | c | if step3 = .true. | c %----------------------------------% c call arscnd (t3) tmvopx = tmvopx + (t3 - t2) step3 = .false. c c %------------------------------------------% c | Put another copy of OP*v_{j} into RESID. | c %------------------------------------------% c call ccopy (n, workd(irj), 1, resid, 1) c c %---------------------------------------% c | STEP 4: Finish extending the Arnoldi | c | factorization to length j. | c %---------------------------------------% c call arscnd (t2) if (bmat .eq. 'G') then nbx = nbx + 1 step4 = .true. ipntr(1) = irj ipntr(2) = ipj ido = 2 c c %-------------------------------------% c | Exit in order to compute B*OP*v_{j} | c %-------------------------------------% c go to 9000 else if (bmat .eq. 'I') then call ccopy (n, resid, 1, workd(ipj), 1) end if 60 continue c c %----------------------------------% c | Back from reverse communication; | c | WORKD(IPJ:IPJ+N-1) := B*OP*v_{j} | c | if step4 = .true. | c %----------------------------------% c if (bmat .eq. 'G') then call arscnd (t3) tmvbx = tmvbx + (t3 - t2) end if c step4 = .false. c c %-------------------------------------% c | The following is needed for STEP 5. | c | Compute the B-norm of OP*v_{j}. | c %-------------------------------------% c if (bmat .eq. 'G') then cnorm_buf = cdotc (n, resid, 1, workd(ipj), 1) call MPI_ALLREDUCE( cnorm_buf, cnorm, 1, & MPI_COMPLEX, MPI_SUM, comm, ierr ) wnorm = sqrt( slapy2(real(cnorm),aimag(cnorm)) ) else if (bmat .eq. 'I') then wnorm = pscnorm2(comm, n, resid, 1) end if c c %-----------------------------------------% c | Compute the j-th residual corresponding | c | to the j step factorization. | c | Use Classical Gram Schmidt and compute: | c | w_{j} <- V_{j}^T * B * OP * v_{j} | c | r_{j} <- OP*v_{j} - V_{j} * w_{j} | c %-----------------------------------------% c c c %------------------------------------------% c | Compute the j Fourier coefficients w_{j} | c | WORKD(IPJ:IPJ+N-1) contains B*OP*v_{j}. | c %------------------------------------------% c call cgemv ('C', n, j, one, v, ldv, workd(ipj), 1, & zero, workl, 1) call MPI_ALLREDUCE( workl, h(1,j), j, & MPI_COMPLEX, MPI_SUM, comm, ierr) c c %--------------------------------------% c | Orthogonalize r_{j} against V_{j}. | c | RESID contains OP*v_{j}. See STEP 3. | c %--------------------------------------% c call cgemv ('N', n, j, -one, v, ldv, h(1,j), 1, & one, resid, 1) c if (j .gt. 1) h(j,j-1) = cmplx(betaj, rzero) c call arscnd (t4) c orth1 = .true. c call arscnd (t2) if (bmat .eq. 'G') then nbx = nbx + 1 call ccopy (n, resid, 1, workd(irj), 1) ipntr(1) = irj ipntr(2) = ipj ido = 2 c c %----------------------------------% c | Exit in order to compute B*r_{j} | c %----------------------------------% c go to 9000 else if (bmat .eq. 'I') then call ccopy (n, resid, 1, workd(ipj), 1) end if 70 continue c c %---------------------------------------------------% c | Back from reverse communication if ORTH1 = .true. | c | WORKD(IPJ:IPJ+N-1) := B*r_{j}. | c %---------------------------------------------------% c if (bmat .eq. 'G') then call arscnd (t3) tmvbx = tmvbx + (t3 - t2) end if c orth1 = .false. c c %------------------------------% c | Compute the B-norm of r_{j}. | c %------------------------------% c if (bmat .eq. 'G') then cnorm_buf = cdotc (n, resid, 1, workd(ipj), 1) call MPI_ALLREDUCE( cnorm_buf, cnorm, 1, & MPI_COMPLEX, MPI_SUM, comm, ierr ) rnorm = sqrt( slapy2(real(cnorm),aimag(cnorm)) ) else if (bmat .eq. 'I') then rnorm = pscnorm2(comm, n, resid, 1) end if c c %-----------------------------------------------------------% c | STEP 5: Re-orthogonalization / Iterative refinement phase | c | Maximum NITER_ITREF tries. | c | | c | s = V_{j}^T * B * r_{j} | c | r_{j} = r_{j} - V_{j}*s | c | alphaj = alphaj + s_{j} | c | | c | The stopping criteria used for iterative refinement is | c | discussed in Parlett's book SEP, page 107 and in Gragg & | c | Reichel ACM TOMS paper; Algorithm 686, Dec. 1990. | c | Determine if we need to correct the residual. The goal is | c | to enforce ||v(:,1:j)^T * r_{j}|| .le. eps * || r_{j} || | c | The following test determines whether the sine of the | c | angle between OP*x and the computed residual is less | c | than or equal to 0.717. | c %-----------------------------------------------------------% c if ( rnorm .gt. 0.717*wnorm ) go to 100 c iter = 0 nrorth = nrorth + 1 c c %---------------------------------------------------% c | Enter the Iterative refinement phase. If further | c | refinement is necessary, loop back here. The loop | c | variable is ITER. Perform a step of Classical | c | Gram-Schmidt using all the Arnoldi vectors V_{j} | c %---------------------------------------------------% c 80 continue c if (msglvl .gt. 2) then rtemp(1) = wnorm rtemp(2) = rnorm call psvout (comm, logfil, 2, rtemp, ndigit, & '_naitr: re-orthogonalization; wnorm and rnorm are') call pcvout (comm, logfil, j, h(1,j), ndigit, & '_naitr: j-th column of H') end if c c %----------------------------------------------------% c | Compute V_{j}^T * B * r_{j}. | c | WORKD(IRJ:IRJ+J-1) = v(:,1:J)'*WORKD(IPJ:IPJ+N-1). | c %----------------------------------------------------% c call cgemv ('C', n, j, one, v, ldv, workd(ipj), 1, & zero, workl(j+1), 1) call MPI_ALLREDUCE( workl(j+1), workl(1), j, & MPI_COMPLEX, MPI_SUM, comm, ierr) c c %---------------------------------------------% c | Compute the correction to the residual: | c | r_{j} = r_{j} - V_{j} * WORKD(IRJ:IRJ+J-1). | c | The correction to H is v(:,1:J)*H(1:J,1:J) | c | + v(:,1:J)*WORKD(IRJ:IRJ+J-1)*e'_j. | c %---------------------------------------------% c call cgemv ('N', n, j, -one, v, ldv, workl(1), 1, & one, resid, 1) call caxpy (j, one, workl(1), 1, h(1,j), 1) c orth2 = .true. call arscnd (t2) if (bmat .eq. 'G') then nbx = nbx + 1 call ccopy (n, resid, 1, workd(irj), 1) ipntr(1) = irj ipntr(2) = ipj ido = 2 c c %-----------------------------------% c | Exit in order to compute B*r_{j}. | c | r_{j} is the corrected residual. | c %-----------------------------------% c go to 9000 else if (bmat .eq. 'I') then call ccopy (n, resid, 1, workd(ipj), 1) end if 90 continue c c %---------------------------------------------------% c | Back from reverse communication if ORTH2 = .true. | c %---------------------------------------------------% c if (bmat .eq. 'G') then call arscnd (t3) tmvbx = tmvbx + (t3 - t2) end if c c %-----------------------------------------------------% c | Compute the B-norm of the corrected residual r_{j}. | c %-----------------------------------------------------% c if (bmat .eq. 'G') then cnorm_buf = cdotc (n, resid, 1, workd(ipj), 1) call MPI_ALLREDUCE( cnorm_buf, cnorm, 1, & MPI_COMPLEX, MPI_SUM, comm, ierr ) rnorm1 = sqrt( slapy2(real(cnorm),aimag(cnorm)) ) else if (bmat .eq. 'I') then rnorm1 = pscnorm2(comm, n, resid, 1) end if c if (msglvl .gt. 0 .and. iter .gt. 0 ) then call pivout (comm, logfil, 1, j, ndigit, & '_naitr: Iterative refinement for Arnoldi residual') if (msglvl .gt. 2) then rtemp(1) = rnorm rtemp(2) = rnorm1 call psvout (comm, logfil, 2, rtemp, ndigit, & '_naitr: iterative refinement ; rnorm and rnorm1 are') end if end if c c %-----------------------------------------% c | Determine if we need to perform another | c | step of re-orthogonalization. | c %-----------------------------------------% c if ( rnorm1 .gt. 0.717*rnorm ) then c c %---------------------------------------% c | No need for further refinement. | c | The cosine of the angle between the | c | corrected residual vector and the old | c | residual vector is greater than 0.717 | c | In other words the corrected residual | c | and the old residual vector share an | c | angle of less than arcCOS(0.717) | c %---------------------------------------% c rnorm = rnorm1 c else c c %-------------------------------------------% c | Another step of iterative refinement step | c | is required. NITREF is used by stat.h | c %-------------------------------------------% c nitref = nitref + 1 rnorm = rnorm1 iter = iter + 1 if (iter .le. 1) go to 80 c c %-------------------------------------------------% c | Otherwise RESID is numerically in the span of V | c %-------------------------------------------------% c do 95 jj = 1, n resid(jj) = zero 95 continue rnorm = rzero end if c c %----------------------------------------------% c | Branch here directly if iterative refinement | c | wasn't necessary or after at most NITER_REF | c | steps of iterative refinement. | c %----------------------------------------------% c 100 continue c rstart = .false. orth2 = .false. c call arscnd (t5) titref = titref + (t5 - t4) c c %------------------------------------% c | STEP 6: Update j = j+1; Continue | c %------------------------------------% c j = j + 1 if (j .gt. k+np) then call arscnd (t1) tcaitr = tcaitr + (t1 - t0) ido = 99 do 110 i = max(1,k), k+np-1 c c %--------------------------------------------% c | Check for splitting and deflation. | c | Use a standard test as in the QR algorithm | c | REFERENCE: LAPACK subroutine clahqr | c %--------------------------------------------% c tst1 = slapy2(real(h(i,i)),aimag(h(i,i))) & + slapy2(real(h(i+1,i+1)), aimag(h(i+1,i+1))) if( tst1.eq.real(zero) ) & tst1 = clanhs( '1', k+np, h, ldh, workd(n+1) ) if( slapy2(real(h(i+1,i)),aimag(h(i+1,i))) .le. & max( ulp*tst1, smlnum ) ) & h(i+1,i) = zero 110 continue c if (msglvl .gt. 2) then call pcmout (comm, logfil, k+np, k+np, h, ldh, ndigit, & '_naitr: Final upper Hessenberg matrix H of order K+NP') end if c go to 9000 end if c c %--------------------------------------------------------% c | Loop back to extend the factorization by another step. | c %--------------------------------------------------------% c go to 1000 c c %---------------------------------------------------------------% c | | c | E N D O F M A I N I T E R A T I O N L O O P | c | | c %---------------------------------------------------------------% c 9000 continue return c c %----------------% c | End of pcnaitr | c %----------------% c end
lgpl-3.0
rajeshb/SelfDrivingCar-Term2
T2P5-MPC/src/Eigen-3.3/lapack/ilaslc.f
272
2941
*> \brief \b ILASLC * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ILASLC + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ilaslc.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ilaslc.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ilaslc.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * INTEGER FUNCTION ILASLC( M, N, A, LDA ) * * .. Scalar Arguments .. * INTEGER M, N, LDA * .. * .. Array Arguments .. * REAL A( LDA, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ILASLC scans A for its last non-zero column. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is REAL array, dimension (LDA,N) *> The m by n matrix A. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup realOTHERauxiliary * * ===================================================================== INTEGER FUNCTION ILASLC( M, N, A, LDA ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER M, N, LDA * .. * .. Array Arguments .. REAL A( LDA, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0D+0 ) * .. * .. Local Scalars .. INTEGER I * .. * .. Executable Statements .. * * Quick test for the common case where one corner is non-zero. IF( N.EQ.0 ) THEN ILASLC = N ELSE IF( A(1, N).NE.ZERO .OR. A(M, N).NE.ZERO ) THEN ILASLC = N ELSE * Now scan each column from the end, returning with the first non-zero. DO ILASLC = N, 1, -1 DO I = 1, M IF( A(I, ILASLC).NE.ZERO ) RETURN END DO END DO END IF RETURN END
mit
aamaricci/SciFortran
src/lapack/chpgv.f
1
6509
SUBROUTINE CHPGV( ITYPE, JOBZ, UPLO, N, AP, BP, W, Z, LDZ, WORK, $ RWORK, INFO ) * * -- LAPACK driver routine (version 3.3.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * -- April 2011 -- * * .. Scalar Arguments .. CHARACTER JOBZ, UPLO INTEGER INFO, ITYPE, LDZ, N * .. * .. Array Arguments .. REAL RWORK( * ), W( * ) COMPLEX AP( * ), BP( * ), WORK( * ), Z( LDZ, * ) * .. * * Purpose * ======= * * CHPGV computes all the eigenvalues and, optionally, the eigenvectors * of a complex generalized Hermitian-definite eigenproblem, of the form * A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. * Here A and B are assumed to be Hermitian, stored in packed format, * and B is also positive definite. * * Arguments * ========= * * ITYPE (input) INTEGER * Specifies the problem type to be solved: * = 1: A*x = (lambda)*B*x * = 2: A*B*x = (lambda)*x * = 3: B*A*x = (lambda)*x * * JOBZ (input) CHARACTER*1 * = 'N': Compute eigenvalues only; * = 'V': Compute eigenvalues and eigenvectors. * * UPLO (input) CHARACTER*1 * = 'U': Upper triangles of A and B are stored; * = 'L': Lower triangles of A and B are stored. * * N (input) INTEGER * The order of the matrices A and B. N >= 0. * * AP (input/output) COMPLEX array, dimension (N*(N+1)/2) * On entry, the upper or lower triangle of the Hermitian matrix * A, packed columnwise in a linear array. The j-th column of A * is stored in the array AP as follows: * if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; * if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. * * On exit, the contents of AP are destroyed. * * BP (input/output) COMPLEX array, dimension (N*(N+1)/2) * On entry, the upper or lower triangle of the Hermitian matrix * B, packed columnwise in a linear array. The j-th column of B * is stored in the array BP as follows: * if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; * if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. * * On exit, the triangular factor U or L from the Cholesky * factorization B = U**H*U or B = L*L**H, in the same storage * format as B. * * W (output) REAL array, dimension (N) * If INFO = 0, the eigenvalues in ascending order. * * Z (output) COMPLEX array, dimension (LDZ, N) * If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of * eigenvectors. The eigenvectors are normalized as follows: * if ITYPE = 1 or 2, Z**H*B*Z = I; * if ITYPE = 3, Z**H*inv(B)*Z = I. * If JOBZ = 'N', then Z is not referenced. * * LDZ (input) INTEGER * The leading dimension of the array Z. LDZ >= 1, and if * JOBZ = 'V', LDZ >= max(1,N). * * WORK (workspace) COMPLEX array, dimension (max(1, 2*N-1)) * * RWORK (workspace) REAL array, dimension (max(1, 3*N-2)) * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value * > 0: CPPTRF or CHPEV returned an error code: * <= N: if INFO = i, CHPEV failed to converge; * i off-diagonal elements of an intermediate * tridiagonal form did not convergeto zero; * > N: if INFO = N + i, for 1 <= i <= n, then the leading * minor of order i of B is not positive definite. * The factorization of B could not be completed and * no eigenvalues or eigenvectors were computed. * * ===================================================================== * * .. Local Scalars .. LOGICAL UPPER, WANTZ CHARACTER TRANS INTEGER J, NEIG * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL CHPEV, CHPGST, CPPTRF, CTPMV, CTPSV, XERBLA * .. * .. Executable Statements .. * * Test the input parameters. * WANTZ = LSAME( JOBZ, 'V' ) UPPER = LSAME( UPLO, 'U' ) * INFO = 0 IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN INFO = -1 ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN INFO = -2 ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN INFO = -3 ELSE IF( N.LT.0 ) THEN INFO = -4 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN INFO = -9 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CHPGV ', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * Form a Cholesky factorization of B. * CALL CPPTRF( UPLO, N, BP, INFO ) IF( INFO.NE.0 ) THEN INFO = N + INFO RETURN END IF * * Transform problem to standard eigenvalue problem and solve. * CALL CHPGST( ITYPE, UPLO, N, AP, BP, INFO ) CALL CHPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, RWORK, INFO ) * IF( WANTZ ) THEN * * Backtransform eigenvectors to the original problem. * NEIG = N IF( INFO.GT.0 ) $ NEIG = INFO - 1 IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN * * For A*x=(lambda)*B*x and A*B*x=(lambda)*x; * backtransform eigenvectors: x = inv(L)**H*y or inv(U)*y * IF( UPPER ) THEN TRANS = 'N' ELSE TRANS = 'C' END IF * DO 10 J = 1, NEIG CALL CTPSV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ), $ 1 ) 10 CONTINUE * ELSE IF( ITYPE.EQ.3 ) THEN * * For B*A*x=(lambda)*x; * backtransform eigenvectors: x = L*y or U**H*y * IF( UPPER ) THEN TRANS = 'C' ELSE TRANS = 'N' END IF * DO 20 J = 1, NEIG CALL CTPMV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ), $ 1 ) 20 CONTINUE END IF END IF RETURN * * End of CHPGV * END
lgpl-3.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/sgtsvx.f
25
13817
*> \brief <b> SGTSVX computes the solution to system of linear equations A * X = B for GT matrices <b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SGTSVX + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgtsvx.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgtsvx.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgtsvx.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SGTSVX( FACT, TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, * DU2, IPIV, B, LDB, X, LDX, RCOND, FERR, BERR, * WORK, IWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER FACT, TRANS * INTEGER INFO, LDB, LDX, N, NRHS * REAL RCOND * .. * .. Array Arguments .. * INTEGER IPIV( * ), IWORK( * ) * REAL B( LDB, * ), BERR( * ), D( * ), DF( * ), * $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ), * $ FERR( * ), WORK( * ), X( LDX, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SGTSVX uses the LU factorization to compute the solution to a real *> system of linear equations A * X = B or A**T * X = B, *> where A is a tridiagonal matrix of order N and X and B are N-by-NRHS *> matrices. *> *> Error bounds on the solution and a condition estimate are also *> provided. *> \endverbatim * *> \par Description: * ================= *> *> \verbatim *> *> The following steps are performed: *> *> 1. If FACT = 'N', the LU decomposition is used to factor the matrix A *> as A = L * U, where L is a product of permutation and unit lower *> bidiagonal matrices and U is upper triangular with nonzeros in *> only the main diagonal and first two superdiagonals. *> *> 2. If some U(i,i)=0, so that U is exactly singular, then the routine *> returns with INFO = i. Otherwise, the factored form of A is used *> to estimate the condition number of the matrix A. If the *> reciprocal of the condition number is less than machine precision, *> INFO = N+1 is returned as a warning, but the routine still goes on *> to solve for X and compute error bounds as described below. *> *> 3. The system of equations is solved for X using the factored form *> of A. *> *> 4. Iterative refinement is applied to improve the computed solution *> matrix and calculate error bounds and backward error estimates *> for it. *> \endverbatim * * Arguments: * ========== * *> \param[in] FACT *> \verbatim *> FACT is CHARACTER*1 *> Specifies whether or not the factored form of A has been *> supplied on entry. *> = 'F': DLF, DF, DUF, DU2, and IPIV contain the factored *> form of A; DL, D, DU, DLF, DF, DUF, DU2 and IPIV *> will not be modified. *> = 'N': The matrix will be copied to DLF, DF, and DUF *> and factored. *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> Specifies the form of the system of equations: *> = 'N': A * X = B (No transpose) *> = 'T': A**T * X = B (Transpose) *> = 'C': A**H * X = B (Conjugate transpose = Transpose) *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrix B. NRHS >= 0. *> \endverbatim *> *> \param[in] DL *> \verbatim *> DL is REAL array, dimension (N-1) *> The (n-1) subdiagonal elements of A. *> \endverbatim *> *> \param[in] D *> \verbatim *> D is REAL array, dimension (N) *> The n diagonal elements of A. *> \endverbatim *> *> \param[in] DU *> \verbatim *> DU is REAL array, dimension (N-1) *> The (n-1) superdiagonal elements of A. *> \endverbatim *> *> \param[in,out] DLF *> \verbatim *> DLF is REAL array, dimension (N-1) *> If FACT = 'F', then DLF is an input argument and on entry *> contains the (n-1) multipliers that define the matrix L from *> the LU factorization of A as computed by SGTTRF. *> *> If FACT = 'N', then DLF is an output argument and on exit *> contains the (n-1) multipliers that define the matrix L from *> the LU factorization of A. *> \endverbatim *> *> \param[in,out] DF *> \verbatim *> DF is REAL array, dimension (N) *> If FACT = 'F', then DF is an input argument and on entry *> contains the n diagonal elements of the upper triangular *> matrix U from the LU factorization of A. *> *> If FACT = 'N', then DF is an output argument and on exit *> contains the n diagonal elements of the upper triangular *> matrix U from the LU factorization of A. *> \endverbatim *> *> \param[in,out] DUF *> \verbatim *> DUF is REAL array, dimension (N-1) *> If FACT = 'F', then DUF is an input argument and on entry *> contains the (n-1) elements of the first superdiagonal of U. *> *> If FACT = 'N', then DUF is an output argument and on exit *> contains the (n-1) elements of the first superdiagonal of U. *> \endverbatim *> *> \param[in,out] DU2 *> \verbatim *> DU2 is REAL array, dimension (N-2) *> If FACT = 'F', then DU2 is an input argument and on entry *> contains the (n-2) elements of the second superdiagonal of *> U. *> *> If FACT = 'N', then DU2 is an output argument and on exit *> contains the (n-2) elements of the second superdiagonal of *> U. *> \endverbatim *> *> \param[in,out] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> If FACT = 'F', then IPIV is an input argument and on entry *> contains the pivot indices from the LU factorization of A as *> computed by SGTTRF. *> *> If FACT = 'N', then IPIV is an output argument and on exit *> contains the pivot indices from the LU factorization of A; *> row i of the matrix was interchanged with row IPIV(i). *> IPIV(i) will always be either i or i+1; IPIV(i) = i indicates *> a row interchange was not required. *> \endverbatim *> *> \param[in] B *> \verbatim *> B is REAL array, dimension (LDB,NRHS) *> The N-by-NRHS right hand side matrix B. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] X *> \verbatim *> X is REAL array, dimension (LDX,NRHS) *> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. *> \endverbatim *> *> \param[in] LDX *> \verbatim *> LDX is INTEGER *> The leading dimension of the array X. LDX >= max(1,N). *> \endverbatim *> *> \param[out] RCOND *> \verbatim *> RCOND is REAL *> The estimate of the reciprocal condition number of the matrix *> A. If RCOND is less than the machine precision (in *> particular, if RCOND = 0), the matrix is singular to working *> precision. This condition is indicated by a return code of *> INFO > 0. *> \endverbatim *> *> \param[out] FERR *> \verbatim *> FERR is REAL array, dimension (NRHS) *> The estimated forward error bound for each solution vector *> X(j) (the j-th column of the solution matrix X). *> If XTRUE is the true solution corresponding to X(j), FERR(j) *> is an estimated upper bound for the magnitude of the largest *> element in (X(j) - XTRUE) divided by the magnitude of the *> largest element in X(j). The estimate is as reliable as *> the estimate for RCOND, and is almost always a slight *> overestimate of the true error. *> \endverbatim *> *> \param[out] BERR *> \verbatim *> BERR is REAL array, dimension (NRHS) *> The componentwise relative backward error of each solution *> vector X(j) (i.e., the smallest relative change in *> any element of A or B that makes X(j) an exact solution). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (3*N) *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = i, and i is *> <= N: U(i,i) is exactly zero. The factorization *> has not been completed unless i = N, but the *> factor U is exactly singular, so the solution *> and error bounds could not be computed. *> RCOND = 0 is returned. *> = N+1: U is nonsingular, but RCOND is less than machine *> precision, meaning that the matrix is singular *> to working precision. Nevertheless, the *> solution and error bounds are computed because *> there are a number of situations where the *> computed solution can be more accurate than the *> value of RCOND would suggest. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup realGTsolve * * ===================================================================== SUBROUTINE SGTSVX( FACT, TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, $ DU2, IPIV, B, LDB, X, LDX, RCOND, FERR, BERR, $ WORK, IWORK, INFO ) * * -- LAPACK driver routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER FACT, TRANS INTEGER INFO, LDB, LDX, N, NRHS REAL RCOND * .. * .. Array Arguments .. INTEGER IPIV( * ), IWORK( * ) REAL B( LDB, * ), BERR( * ), D( * ), DF( * ), $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ), $ FERR( * ), WORK( * ), X( LDX, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0E+0 ) * .. * .. Local Scalars .. LOGICAL NOFACT, NOTRAN CHARACTER NORM REAL ANORM * .. * .. External Functions .. LOGICAL LSAME REAL SLAMCH, SLANGT EXTERNAL LSAME, SLAMCH, SLANGT * .. * .. External Subroutines .. EXTERNAL SCOPY, SGTCON, SGTRFS, SGTTRF, SGTTRS, SLACPY, $ XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * INFO = 0 NOFACT = LSAME( FACT, 'N' ) NOTRAN = LSAME( TRANS, 'N' ) IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN INFO = -1 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT. $ LSAME( TRANS, 'C' ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NRHS.LT.0 ) THEN INFO = -4 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -14 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN INFO = -16 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'SGTSVX', -INFO ) RETURN END IF * IF( NOFACT ) THEN * * Compute the LU factorization of A. * CALL SCOPY( N, D, 1, DF, 1 ) IF( N.GT.1 ) THEN CALL SCOPY( N-1, DL, 1, DLF, 1 ) CALL SCOPY( N-1, DU, 1, DUF, 1 ) END IF CALL SGTTRF( N, DLF, DF, DUF, DU2, IPIV, INFO ) * * Return if INFO is non-zero. * IF( INFO.GT.0 )THEN RCOND = ZERO RETURN END IF END IF * * Compute the norm of the matrix A. * IF( NOTRAN ) THEN NORM = '1' ELSE NORM = 'I' END IF ANORM = SLANGT( NORM, N, DL, D, DU ) * * Compute the reciprocal of the condition number of A. * CALL SGTCON( NORM, N, DLF, DF, DUF, DU2, IPIV, ANORM, RCOND, WORK, $ IWORK, INFO ) * * Compute the solution vectors X. * CALL SLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) CALL SGTTRS( TRANS, N, NRHS, DLF, DF, DUF, DU2, IPIV, X, LDX, $ INFO ) * * Use iterative refinement to improve the computed solutions and * compute error bounds and backward error estimates for them. * CALL SGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2, IPIV, $ B, LDB, X, LDX, FERR, BERR, WORK, IWORK, INFO ) * * Set INFO = N+1 if the matrix is singular to working precision. * IF( RCOND.LT.SLAMCH( 'Epsilon' ) ) $ INFO = N + 1 * RETURN * * End of SGTSVX * END
apache-2.0
aamaricci/SciFortran
src/lapack/dpbequ.f
1
4872
SUBROUTINE DPBEQU( UPLO, N, KD, AB, LDAB, S, SCOND, AMAX, INFO ) * * -- LAPACK routine (version 3.2.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * June 2010 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, KD, LDAB, N DOUBLE PRECISION AMAX, SCOND * .. * .. Array Arguments .. DOUBLE PRECISION AB( LDAB, * ), S( * ) * .. * * Purpose * ======= * * DPBEQU computes row and column scalings intended to equilibrate a * symmetric positive definite band matrix A and reduce its condition * number (with respect to the two-norm). S contains the scale factors, * S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with * elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This * choice of S puts the condition number of B within a factor N of the * smallest possible condition number over all possible diagonal * scalings. * * Arguments * ========= * * UPLO (input) CHARACTER*1 * = 'U': Upper triangular of A is stored; * = 'L': Lower triangular of A is stored. * * N (input) INTEGER * The order of the matrix A. N >= 0. * * KD (input) INTEGER * The number of superdiagonals of the matrix A if UPLO = 'U', * or the number of subdiagonals if UPLO = 'L'. KD >= 0. * * AB (input) DOUBLE PRECISION array, dimension (LDAB,N) * The upper or lower triangle of the symmetric band matrix A, * stored in the first KD+1 rows of the array. The j-th column * of A is stored in the j-th column of the array AB as follows: * if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; * if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). * * LDAB (input) INTEGER * The leading dimension of the array A. LDAB >= KD+1. * * S (output) DOUBLE PRECISION array, dimension (N) * If INFO = 0, S contains the scale factors for A. * * SCOND (output) DOUBLE PRECISION * If INFO = 0, S contains the ratio of the smallest S(i) to * the largest S(i). If SCOND >= 0.1 and AMAX is neither too * large nor too small, it is not worth scaling by S. * * AMAX (output) DOUBLE PRECISION * Absolute value of largest matrix element. If AMAX is very * close to overflow or very close to underflow, the matrix * should be scaled. * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value. * > 0: if INFO = i, the i-th diagonal element is nonpositive. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER I, J DOUBLE PRECISION SMIN * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN, SQRT * .. * .. 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 ELSE IF( KD.LT.0 ) THEN INFO = -3 ELSE IF( LDAB.LT.KD+1 ) THEN INFO = -5 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DPBEQU', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) THEN SCOND = ONE AMAX = ZERO RETURN END IF * IF( UPPER ) THEN J = KD + 1 ELSE J = 1 END IF * * Initialize SMIN and AMAX. * S( 1 ) = AB( J, 1 ) SMIN = S( 1 ) AMAX = S( 1 ) * * Find the minimum and maximum diagonal elements. * DO 10 I = 2, N S( I ) = AB( J, I ) SMIN = MIN( SMIN, S( I ) ) AMAX = MAX( AMAX, S( I ) ) 10 CONTINUE * IF( SMIN.LE.ZERO ) THEN * * Find the first non-positive diagonal element and return. * DO 20 I = 1, N IF( S( I ).LE.ZERO ) THEN INFO = I RETURN END IF 20 CONTINUE ELSE * * Set the scale factors to the reciprocals * of the diagonal elements. * DO 30 I = 1, N S( I ) = ONE / SQRT( S( I ) ) 30 CONTINUE * * Compute SCOND = min(S(I)) / max(S(I)) * SCOND = SQRT( SMIN ) / SQRT( AMAX ) END IF RETURN * * End of DPBEQU * END
lgpl-3.0
aamaricci/SciFortran
src/lapack/slaqr1.f
2
3114
SUBROUTINE SLAQR1( N, H, LDH, SR1, SI1, SR2, SI2, V ) * * -- LAPACK auxiliary routine (version 3.2) -- * Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. * November 2006 * * .. Scalar Arguments .. REAL SI1, SI2, SR1, SR2 INTEGER LDH, N * .. * .. Array Arguments .. REAL H( LDH, * ), V( * ) * .. * * Given a 2-by-2 or 3-by-3 matrix H, SLAQR1 sets v to a * scalar multiple of the first column of the product * * (*) K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I) * * scaling to avoid overflows and most underflows. It * is assumed that either * * 1) sr1 = sr2 and si1 = -si2 * or * 2) si1 = si2 = 0. * * This is useful for starting double implicit shift bulges * in the QR algorithm. * * * N (input) integer * Order of the matrix H. N must be either 2 or 3. * * H (input) REAL array of dimension (LDH,N) * The 2-by-2 or 3-by-3 matrix H in (*). * * LDH (input) integer * The leading dimension of H as declared in * the calling procedure. LDH.GE.N * * SR1 (input) REAL * SI1 The shifts in (*). * SR2 * SI2 * * V (output) REAL array of dimension N * A scalar multiple of the first column of the * matrix K in (*). * * ================================================================ * Based on contributions by * Karen Braman and Ralph Byers, Department of Mathematics, * University of Kansas, USA * * ================================================================ * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0e0 ) * .. * .. Local Scalars .. REAL H21S, H31S, S * .. * .. Intrinsic Functions .. INTRINSIC ABS * .. * .. Executable Statements .. IF( N.EQ.2 ) THEN S = ABS( H( 1, 1 )-SR2 ) + ABS( SI2 ) + ABS( H( 2, 1 ) ) IF( S.EQ.ZERO ) THEN V( 1 ) = ZERO V( 2 ) = ZERO ELSE H21S = H( 2, 1 ) / S V( 1 ) = H21S*H( 1, 2 ) + ( H( 1, 1 )-SR1 )* $ ( ( H( 1, 1 )-SR2 ) / S ) - SI1*( SI2 / S ) V( 2 ) = H21S*( H( 1, 1 )+H( 2, 2 )-SR1-SR2 ) END IF ELSE S = ABS( H( 1, 1 )-SR2 ) + ABS( SI2 ) + ABS( H( 2, 1 ) ) + $ ABS( H( 3, 1 ) ) IF( S.EQ.ZERO ) THEN V( 1 ) = ZERO V( 2 ) = ZERO V( 3 ) = ZERO ELSE H21S = H( 2, 1 ) / S H31S = H( 3, 1 ) / S V( 1 ) = ( H( 1, 1 )-SR1 )*( ( H( 1, 1 )-SR2 ) / S ) - $ SI1*( SI2 / S ) + H( 1, 2 )*H21S + H( 1, 3 )*H31S V( 2 ) = H21S*( H( 1, 1 )+H( 2, 2 )-SR1-SR2 ) + $ H( 2, 3 )*H31S V( 3 ) = H31S*( H( 1, 1 )+H( 3, 3 )-SR1-SR2 ) + $ H21S*H( 3, 2 ) END IF END IF END
lgpl-3.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/dstegr.f
25
9821
*> \brief \b DSTEGR * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DSTEGR + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dstegr.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dstegr.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dstegr.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DSTEGR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, * ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK, IWORK, * LIWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER JOBZ, RANGE * INTEGER IL, INFO, IU, LDZ, LIWORK, LWORK, M, N * DOUBLE PRECISION ABSTOL, VL, VU * .. * .. Array Arguments .. * INTEGER ISUPPZ( * ), IWORK( * ) * DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * ) * DOUBLE PRECISION Z( LDZ, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DSTEGR computes selected eigenvalues and, optionally, eigenvectors *> of a real symmetric tridiagonal matrix T. Any such unreduced matrix has *> a well defined set of pairwise different real eigenvalues, the corresponding *> real eigenvectors are pairwise orthogonal. *> *> The spectrum may be computed either completely or partially by specifying *> either an interval (VL,VU] or a range of indices IL:IU for the desired *> eigenvalues. *> *> DSTEGR is a compatability wrapper around the improved DSTEMR routine. *> See DSTEMR for further details. *> *> One important change is that the ABSTOL parameter no longer provides any *> benefit and hence is no longer used. *> *> Note : DSTEGR and DSTEMR work only on machines which follow *> IEEE-754 floating-point standard in their handling of infinities and *> NaNs. Normal execution may create these exceptiona values and hence *> may abort due to a floating point exception in environments which *> do not conform to the IEEE-754 standard. *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBZ *> \verbatim *> JOBZ is CHARACTER*1 *> = 'N': Compute eigenvalues only; *> = 'V': Compute eigenvalues and eigenvectors. *> \endverbatim *> *> \param[in] RANGE *> \verbatim *> RANGE is CHARACTER*1 *> = 'A': all eigenvalues will be found. *> = 'V': all eigenvalues in the half-open interval (VL,VU] *> will be found. *> = 'I': the IL-th through IU-th eigenvalues will be found. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix. N >= 0. *> \endverbatim *> *> \param[in,out] D *> \verbatim *> D is DOUBLE PRECISION array, dimension (N) *> On entry, the N diagonal elements of the tridiagonal matrix *> T. On exit, D is overwritten. *> \endverbatim *> *> \param[in,out] E *> \verbatim *> E is DOUBLE PRECISION array, dimension (N) *> On entry, the (N-1) subdiagonal elements of the tridiagonal *> matrix T in elements 1 to N-1 of E. E(N) need not be set on *> input, but is used internally as workspace. *> On exit, E is overwritten. *> \endverbatim *> *> \param[in] VL *> \verbatim *> VL is DOUBLE PRECISION *> \endverbatim *> *> \param[in] VU *> \verbatim *> VU is DOUBLE PRECISION *> *> If RANGE='V', the lower and upper bounds of the interval to *> be searched for eigenvalues. VL < VU. *> Not referenced if RANGE = 'A' or 'I'. *> \endverbatim *> *> \param[in] IL *> \verbatim *> IL is INTEGER *> \endverbatim *> *> \param[in] IU *> \verbatim *> IU is INTEGER *> *> If RANGE='I', the indices (in ascending order) of the *> smallest and largest eigenvalues to be returned. *> 1 <= IL <= IU <= N, if N > 0. *> Not referenced if RANGE = 'A' or 'V'. *> \endverbatim *> *> \param[in] ABSTOL *> \verbatim *> ABSTOL is DOUBLE PRECISION *> Unused. Was the absolute error tolerance for the *> eigenvalues/eigenvectors in previous versions. *> \endverbatim *> *> \param[out] M *> \verbatim *> M is INTEGER *> The total number of eigenvalues found. 0 <= M <= N. *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. *> \endverbatim *> *> \param[out] W *> \verbatim *> W is DOUBLE PRECISION array, dimension (N) *> The first M elements contain the selected eigenvalues in *> ascending order. *> \endverbatim *> *> \param[out] Z *> \verbatim *> Z is DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) *> If JOBZ = 'V', and if INFO = 0, then the first M columns of Z *> contain the orthonormal eigenvectors of the matrix T *> corresponding to the selected eigenvalues, with the i-th *> column of Z holding the eigenvector associated with W(i). *> If JOBZ = 'N', then Z is not referenced. *> Note: the user must ensure that at least max(1,M) columns are *> supplied in the array Z; if RANGE = 'V', the exact value of M *> is not known in advance and an upper bound must be used. *> Supplying N columns is always safe. *> \endverbatim *> *> \param[in] LDZ *> \verbatim *> LDZ is INTEGER *> The leading dimension of the array Z. LDZ >= 1, and if *> JOBZ = 'V', then LDZ >= max(1,N). *> \endverbatim *> *> \param[out] ISUPPZ *> \verbatim *> ISUPPZ is INTEGER ARRAY, dimension ( 2*max(1,M) ) *> The support of the eigenvectors in Z, i.e., the indices *> indicating the nonzero elements in Z. The i-th computed eigenvector *> is nonzero only in elements ISUPPZ( 2*i-1 ) through *> ISUPPZ( 2*i ). This is relevant in the case when the matrix *> is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (LWORK) *> On exit, if INFO = 0, WORK(1) returns the optimal *> (and minimal) LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. LWORK >= max(1,18*N) *> if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'. *> 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] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (LIWORK) *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. *> \endverbatim *> *> \param[in] LIWORK *> \verbatim *> LIWORK is INTEGER *> The dimension of the array IWORK. LIWORK >= max(1,10*N) *> if the eigenvectors are desired, and LIWORK >= max(1,8*N) *> if only the eigenvalues are to be computed. *> If LIWORK = -1, then a workspace query is assumed; the *> routine only calculates the optimal size of the IWORK array, *> returns this value as the first entry of the IWORK array, and *> no error message related to LIWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> On exit, INFO *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = 1X, internal error in DLARRE, *> if INFO = 2X, internal error in DLARRV. *> Here, the digit X = ABS( IINFO ) < 10, where IINFO is *> the nonzero error code returned by DLARRE or *> DLARRV, respectively. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup doubleOTHERcomputational * *> \par Contributors: * ================== *> *> Inderjit Dhillon, IBM Almaden, USA \n *> Osni Marques, LBNL/NERSC, USA \n *> Christof Voemel, LBNL/NERSC, USA \n * * ===================================================================== SUBROUTINE DSTEGR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, $ ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK, IWORK, $ LIWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER JOBZ, RANGE INTEGER IL, INFO, IU, LDZ, LIWORK, LWORK, M, N DOUBLE PRECISION ABSTOL, VL, VU * .. * .. Array Arguments .. INTEGER ISUPPZ( * ), IWORK( * ) DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * ) DOUBLE PRECISION Z( LDZ, * ) * .. * * ===================================================================== * * .. Local Scalars .. LOGICAL TRYRAC * .. * .. External Subroutines .. EXTERNAL DSTEMR * .. * .. Executable Statements .. INFO = 0 TRYRAC = .FALSE. CALL DSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, $ M, W, Z, LDZ, N, ISUPPZ, TRYRAC, WORK, LWORK, $ IWORK, LIWORK, INFO ) * * End of DSTEGR * END
apache-2.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/cgeqrt.f
22
6144
*> \brief \b CGEQRT * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CGEQRT + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeqrt.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeqrt.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeqrt.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CGEQRT( M, N, NB, A, LDA, T, LDT, WORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LDT, M, N, NB * .. * .. Array Arguments .. * COMPLEX A( LDA, * ), T( LDT, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CGEQRT computes a blocked QR factorization of a complex M-by-N matrix A *> using the compact WY representation of Q. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] NB *> \verbatim *> NB is INTEGER *> The block size to be used in the blocked QR. MIN(M,N) >= NB >= 1. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> On entry, the M-by-N matrix A. *> On exit, the elements on and above the diagonal of the array *> contain the min(M,N)-by-N upper trapezoidal matrix R (R is *> upper triangular if M >= N); the elements below the diagonal *> are the columns of V. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] T *> \verbatim *> T is COMPLEX array, dimension (LDT,MIN(M,N)) *> The upper triangular block reflectors stored in compact form *> as a sequence of upper triangular blocks. See below *> for further details. *> \endverbatim *> *> \param[in] LDT *> \verbatim *> LDT is INTEGER *> The leading dimension of the array T. LDT >= NB. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (NB*N) *> \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. * *> \date November 2013 * *> \ingroup complexGEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix V stores the elementary reflectors H(i) in the i-th column *> below the diagonal. For example, if M=5 and N=3, the matrix V is *> *> V = ( 1 ) *> ( v1 1 ) *> ( v1 v2 1 ) *> ( v1 v2 v3 ) *> ( v1 v2 v3 ) *> *> where the vi's represent the vectors which define H(i), which are returned *> in the matrix A. The 1's along the diagonal of V are not stored in A. *> *> Let K=MIN(M,N). The number of blocks is B = ceiling(K/NB), where each *> block is of order NB except for the last block, which is of order *> IB = K - (B-1)*NB. For each of the B blocks, a upper triangular block *> reflector factor is computed: T1, T2, ..., TB. The NB-by-NB (and IB-by-IB *> for the last block) T's are stored in the NB-by-N matrix T as *> *> T = (T1 T2 ... TB). *> \endverbatim *> * ===================================================================== SUBROUTINE CGEQRT( M, N, NB, A, LDA, T, LDT, WORK, INFO ) * * -- LAPACK computational routine (version 3.5.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2013 * * .. Scalar Arguments .. INTEGER INFO, LDA, LDT, M, N, NB * .. * .. Array Arguments .. COMPLEX A( LDA, * ), T( LDT, * ), WORK( * ) * .. * * ===================================================================== * * .. * .. Local Scalars .. INTEGER I, IB, IINFO, K LOGICAL USE_RECURSIVE_QR PARAMETER( USE_RECURSIVE_QR=.TRUE. ) * .. * .. External Subroutines .. EXTERNAL CGEQRT2, CGEQRT3, CLARFB, XERBLA * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( NB.LT.1 .OR. ( NB.GT.MIN(M,N) .AND. MIN(M,N).GT.0 ) )THEN INFO = -3 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -5 ELSE IF( LDT.LT.NB ) THEN INFO = -7 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CGEQRT', -INFO ) RETURN END IF * * Quick return if possible * K = MIN( M, N ) IF( K.EQ.0 ) RETURN * * Blocked loop of length K * DO I = 1, K, NB IB = MIN( K-I+1, NB ) * * Compute the QR factorization of the current block A(I:M,I:I+IB-1) * IF( USE_RECURSIVE_QR ) THEN CALL CGEQRT3( M-I+1, IB, A(I,I), LDA, T(1,I), LDT, IINFO ) ELSE CALL CGEQRT2( M-I+1, IB, A(I,I), LDA, T(1,I), LDT, IINFO ) END IF IF( I+IB.LE.N ) THEN * * Update by applying H**H to A(I:M,I+IB:N) from the left * CALL CLARFB( 'L', 'C', 'F', 'C', M-I+1, N-I-IB+1, IB, $ A( I, I ), LDA, T( 1, I ), LDT, $ A( I, I+IB ), LDA, WORK , N-I-IB+1 ) END IF END DO RETURN * * End of CGEQRT * END
apache-2.0
ALICEHLT/AliRoot
HIJING/hijing1_36/vegas.F
7
5885
* $Id$ C******************************************************************* C C C C C******************************************************************* C SUBROUTINE PERFORMS N-DIMENSIONAL MONTE CARLO INTEG'N C - BY G.P. LEPAGE SEPT 1976/(REV)APR 1978 C******************************************************************* C SUBROUTINE VEGAS(FXN,AVGI,SD,CHI2A) IMPLICIT REAL*8(A-H,O-Z) #define BLANKET_SAVE #include "bveg1_hijing.inc" #include "bveg2_hijing.inc" #include "bveg3_hijing.inc" EXTERNAL FXN DIMENSION D(50,10),DI(50,10),XIN(50),R(50),DX(10),DT(10),X(10) 1 ,KG(10),IA(10) REAL*4 QRAN(10) DATA NDMX/50/,ALPH/1.5D0/,ONE/1.D0/,MDS/-1/ SAVE C NDO=1 DO 1 J=1,NDIM 1 XI(1,J)=ONE C ENTRY VEGAS1(FXN,AVGI,SD,CHI2A) C - INITIALIZES CUMMULATIVE VARIABLES, BUT NOT GRID IT=0 SI=0. SI2=SI SWGT=SI SCHI=SI C ENTRY VEGAS2(FXN,AVGI,SD,CHI2A) C - NO INITIALIZATION ND=NDMX NG=1 IF(MDS.EQ.0) GO TO 2 NG=(NCALL/2.)**(1./NDIM) MDS=1 IF((2*NG-NDMX).LT.0) GO TO 2 MDS=-1 NPG=NG/NDMX+1 ND=NG/NPG NG=NPG*ND 2 K=NG**NDIM NPG=NCALL/K IF(NPG.LT.2) NPG=2 CALLS=NPG*K DXG=ONE/NG DV2G=(CALLS*DXG**NDIM)**2/NPG/NPG/(NPG-ONE) XND=ND NDM=ND-1 DXG=DXG*XND XJAC=ONE/CALLS DO 3 J=1,NDIM c***this is the line 50 DX(J)=XU(J)-XL(J) 3 XJAC=XJAC*DX(J) C C REBIN PRESERVING BIN DENSITY C IF(ND.EQ.NDO) GO TO 8 RC=NDO/XND DO 7 J=1,NDIM K=0 XN=0. DR=XN I=K 4 K=K+1 DR=DR+ONE XO=XN XN=XI(K,J) 5 IF(RC.GT.DR) GO TO 4 I=I+1 DR=DR-RC XIN(I)=XN-(XN-XO)*DR IF(I.LT.NDM) GO TO 5 DO 6 I=1,NDM 6 XI(I,J)=XIN(I) 7 XI(ND,J)=ONE NDO=ND C 8 CONTINUE c IF(NPRN.NE.0) WRITE(16,200) NDIM,CALLS,IT,ITMX,ACC,MDS,ND c 1 ,(XL(J),XU(J),J=1,NDIM) C ENTRY VEGAS3(FXN,AVGI,SD,CHI2A) C - MAIN INTEGRATION LOOP 9 IT=IT+1 TI=0. TSI=TI DO 10 J=1,NDIM KG(J)=1 DO 10 I=1,ND D(I,J)=TI 10 DI(I,J)=TI C 11 FB=0. F2B=FB K=0 12 K=K+1 CALL ARAN9(QRAN,NDIM) WGT=XJAC DO 15 J=1,NDIM XN=(KG(J)-QRAN(J))*DXG+ONE c*****this is the line 100 IA(J)=XN IF(IA(J).GT.1) GO TO 13 XO=XI(IA(J),J) RC=(XN-IA(J))*XO GO TO 14 13 XO=XI(IA(J),J)-XI(IA(J)-1,J) RC=XI(IA(J)-1,J)+(XN-IA(J))*XO 14 X(J)=XL(J)+RC*DX(J) WGT=WGT*XO*XND 15 CONTINUE C F=WGT F=F*FXN(X,WGT) F2=F*F FB=FB+F F2B=F2B+F2 DO 16 J=1,NDIM DI(IA(J),J)=DI(IA(J),J)+F 16 IF(MDS.GE.0) D(IA(J),J)=D(IA(J),J)+F2 IF(K.LT.NPG) GO TO 12 C F2B=DSQRT(F2B*NPG) F2B=(F2B-FB)*(F2B+FB) TI=TI+FB TSI=TSI+F2B IF(MDS.GE.0) GO TO 18 DO 17 J=1,NDIM 17 D(IA(J),J)=D(IA(J),J)+F2B 18 K=NDIM 19 KG(K)=MOD(KG(K),NG)+1 IF(KG(K).NE.1) GO TO 11 K=K-1 IF(K.GT.0) GO TO 19 C C FINAL RESULTS FOR THIS ITERATION C TSI=TSI*DV2G TI2=TI*TI WGT=TI2/(TSI+1.0d-37) SI=SI+TI*WGT SI2=SI2+TI2 SWGT=SWGT+WGT SWGT=SWGT+1.0D-37 SI2=SI2+1.0D-37 SCHI=SCHI+TI2*WGT AVGI=SI/(SWGT) SD=SWGT*IT/(SI2) CHI2A=SD*(SCHI/SWGT-AVGI*AVGI)/(IT-.999) SD=DSQRT(ONE/SD) C****this is the line 150 IF(NPRN.EQ.0) GO TO 21 TSI=DSQRT(TSI) c WRITE(16,201) IT,TI,TSI,AVGI,SD,CHI2A IF(NPRN.GE.0) GO TO 21 c DO 20 J=1,NDIM c20 WRITE(16,202) J,(XI(I,J),DI(I,J),D(I,J),I=1,ND) C C REFINE GRID C 21 DO 23 J=1,NDIM XO=D(1,J) XN=D(2,J) D(1,J)=(XO+XN)/2. DT(J)=D(1,J) DO 22 I=2,NDM D(I,J)=XO+XN XO=XN XN=D(I+1,J) D(I,J)=(D(I,J)+XN)/3. 22 DT(J)=DT(J)+D(I,J) D(ND,J)=(XN+XO)/2. 23 DT(J)=DT(J)+D(ND,J) C DO 28 J=1,NDIM RC=0. DO 24 I=1,ND R(I)=0. IF (DT(J).GE.1.0D18) THEN WRITE(6,*) '************** A SINGULARITY >1.0D18' C WRITE(5,1111) C1111 FORMAT(1X,'**************IMPORTANT NOTICE***************') C WRITE(5,1112) C1112 FORMAT(1X,'THE INTEGRAND GIVES RISE A SINGULARITY >1.0D18') C WRITE(5,1113) C1113 FORMAT(1X,'PLEASE CHECK THE INTEGRAND AND THE LIMITS') C WRITE(5,1114) C1114 FORMAT(1X,'**************END NOTICE*************') END IF IF(D(I,J).LE.1.0D-18) GO TO 24 XO=DT(J)/D(I,J) C R(I)=((XO-ONE)/XO/DLOG(XO))**ALPH C The line above doesn't work on Opteron, probably because ALPH is C used in DATA. As a temporary solution we use 1.5D0 directly (PH) R(I)=((XO-ONE)/XO/DLOG(XO))**(1.5D0) 24 RC=RC+R(I) RC=RC/XND K=0 XN=0. DR=XN I=K 25 K=K+1 DR=DR+R(K) XO=XN c****this is the line 200 XN=XI(K,J) 26 IF(RC.GT.DR) GO TO 25 I=I+1 DR=DR-RC XIN(I)=XN-(XN-XO)*DR/(R(K)+1.0d-30) IF(I.LT.NDM) GO TO 26 DO 27 I=1,NDM 27 XI(I,J)=XIN(I) 28 XI(ND,J)=ONE C IF(IT.LT.ITMX.AND.ACC*DABS(AVGI).LT.SD) GO TO 9 200 FORMAT('0INPUT PARAMETERS FOR VEGAS: NDIM=',I3,' NCALL=',F8.0 1 /28X,' IT=',I5,' ITMX=',I5/28X,' ACC=',G9.3 2 /28X,' MDS=',I3,' ND=',I4/28X,' (XL,XU)=', 3 (T40,'( ',G12.6,' , ',G12.6,' )')) 201 FORMAT(///' INTEGRATION BY VEGAS' / '0ITERATION NO.',I3, 1 ': INTEGRAL =',G14.8/21X,'STD DEV =',G10.4 / 2 ' ACCUMULATED RESULTS: INTEGRAL =',G14.8 / 3 24X,'STD DEV =',G10.4 / 24X,'CHI**2 PER IT''N =',G10.4) 202 FORMAT('0DATA FOR AXIS',I2 / ' ',6X,'X',7X,' DELT I ', 1 2X,' CONV''CE ',11X,'X',7X,' DELT I ',2X,' CONV''CE ' 2 ,11X,'X',7X,' DELT I ',2X,' CONV''CE ' / 2 (' ',3G12.4,5X,3G12.4,5X,3G12.4)) RETURN END
bsd-3-clause
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/dlassq.f
130
4358
*> \brief \b DLASSQ updates a sum of squares represented in scaled form. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DLASSQ + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlassq.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlassq.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlassq.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DLASSQ( N, X, INCX, SCALE, SUMSQ ) * * .. Scalar Arguments .. * INTEGER INCX, N * DOUBLE PRECISION SCALE, SUMSQ * .. * .. Array Arguments .. * DOUBLE PRECISION X( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLASSQ returns the values scl and smsq such that *> *> ( scl**2 )*smsq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq, *> *> where x( i ) = X( 1 + ( i - 1 )*INCX ). The value of sumsq is *> assumed to be non-negative and scl returns the value *> *> scl = max( scale, abs( x( i ) ) ). *> *> scale and sumsq must be supplied in SCALE and SUMSQ and *> scl and smsq are overwritten on SCALE and SUMSQ respectively. *> *> The routine makes only one pass through the vector x. *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The number of elements to be used from the vector X. *> \endverbatim *> *> \param[in] X *> \verbatim *> X is DOUBLE PRECISION array, dimension (N) *> The vector for which a scaled sum of squares is computed. *> x( i ) = X( 1 + ( i - 1 )*INCX ), 1 <= i <= n. *> \endverbatim *> *> \param[in] INCX *> \verbatim *> INCX is INTEGER *> The increment between successive values of the vector X. *> INCX > 0. *> \endverbatim *> *> \param[in,out] SCALE *> \verbatim *> SCALE is DOUBLE PRECISION *> On entry, the value scale in the equation above. *> On exit, SCALE is overwritten with scl , the scaling factor *> for the sum of squares. *> \endverbatim *> *> \param[in,out] SUMSQ *> \verbatim *> SUMSQ is DOUBLE PRECISION *> On entry, the value sumsq in the equation above. *> On exit, SUMSQ is overwritten with smsq , the basic sum of *> squares from which scl has been factored out. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup auxOTHERauxiliary * * ===================================================================== SUBROUTINE DLASSQ( N, X, INCX, SCALE, SUMSQ ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INCX, N DOUBLE PRECISION SCALE, SUMSQ * .. * .. Array Arguments .. DOUBLE PRECISION X( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D+0 ) * .. * .. Local Scalars .. INTEGER IX DOUBLE PRECISION ABSXI * .. * .. External Functions .. LOGICAL DISNAN EXTERNAL DISNAN * .. * .. Intrinsic Functions .. INTRINSIC ABS * .. * .. Executable Statements .. * IF( N.GT.0 ) THEN DO 10 IX = 1, 1 + ( N-1 )*INCX, INCX ABSXI = ABS( X( IX ) ) IF( ABSXI.GT.ZERO.OR.DISNAN( ABSXI ) ) THEN IF( SCALE.LT.ABSXI ) THEN SUMSQ = 1 + SUMSQ*( SCALE / ABSXI )**2 SCALE = ABSXI ELSE SUMSQ = SUMSQ + ( ABSXI / SCALE )**2 END IF END IF 10 CONTINUE END IF RETURN * * End of DLASSQ * END
apache-2.0
leo-butler/Maxima-CAS
share/lapack/lapack/fortran/dgebak.f
16
5399
SUBROUTINE DGEBAK( JOB, SIDE, N, ILO, IHI, SCALE, M, V, LDV, $ INFO ) * * -- LAPACK routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * September 30, 1994 * * .. Scalar Arguments .. CHARACTER JOB, SIDE INTEGER IHI, ILO, INFO, LDV, M, N * .. * .. Array Arguments .. DOUBLE PRECISION SCALE( * ), V( LDV, * ) * .. * * Purpose * ======= * * DGEBAK forms the right or left eigenvectors of a real general matrix * by backward transformation on the computed eigenvectors of the * balanced matrix output by DGEBAL. * * Arguments * ========= * * JOB (input) CHARACTER*1 * Specifies the type of backward transformation required: * = 'N', do nothing, return immediately; * = 'P', do backward transformation for permutation only; * = 'S', do backward transformation for scaling only; * = 'B', do backward transformations for both permutation and * scaling. * JOB must be the same as the argument JOB supplied to DGEBAL. * * SIDE (input) CHARACTER*1 * = 'R': V contains right eigenvectors; * = 'L': V contains left eigenvectors. * * N (input) INTEGER * The number of rows of the matrix V. N >= 0. * * ILO (input) INTEGER * IHI (input) INTEGER * The integers ILO and IHI determined by DGEBAL. * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. * * SCALE (input) DOUBLE PRECISION array, dimension (N) * Details of the permutation and scaling factors, as returned * by DGEBAL. * * M (input) INTEGER * The number of columns of the matrix V. M >= 0. * * V (input/output) DOUBLE PRECISION array, dimension (LDV,M) * On entry, the matrix of right or left eigenvectors to be * transformed, as returned by DHSEIN or DTREVC. * On exit, V is overwritten by the transformed eigenvectors. * * LDV (input) INTEGER * The leading dimension of the array V. LDV >= max(1,N). * * INFO (output) INTEGER * = 0: successful exit * < 0: if INFO = -i, the i-th argument had an illegal value. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE PARAMETER ( ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL LEFTV, RIGHTV INTEGER I, II, K DOUBLE PRECISION S * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL DSCAL, DSWAP, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * * Decode and Test the input parameters * RIGHTV = LSAME( SIDE, 'R' ) LEFTV = LSAME( SIDE, 'L' ) * 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( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN INFO = -4 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN INFO = -5 ELSE IF( M.LT.0 ) THEN INFO = -7 ELSE IF( LDV.LT.MAX( 1, N ) ) THEN INFO = -9 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGEBAK', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN IF( M.EQ.0 ) $ RETURN IF( LSAME( JOB, 'N' ) ) $ RETURN * IF( ILO.EQ.IHI ) $ GO TO 30 * * Backward balance * IF( LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'B' ) ) THEN * IF( RIGHTV ) THEN DO 10 I = ILO, IHI S = SCALE( I ) CALL DSCAL( M, S, V( I, 1 ), LDV ) 10 CONTINUE END IF * IF( LEFTV ) THEN DO 20 I = ILO, IHI S = ONE / SCALE( I ) CALL DSCAL( M, S, V( I, 1 ), LDV ) 20 CONTINUE END IF * END IF * * Backward permutation * * For I = ILO-1 step -1 until 1, * IHI+1 step 1 until N do -- * 30 CONTINUE IF( LSAME( JOB, 'P' ) .OR. LSAME( JOB, 'B' ) ) THEN IF( RIGHTV ) THEN DO 40 II = 1, N I = II IF( I.GE.ILO .AND. I.LE.IHI ) $ GO TO 40 IF( I.LT.ILO ) $ I = ILO - II K = SCALE( I ) IF( K.EQ.I ) $ GO TO 40 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV ) 40 CONTINUE END IF * IF( LEFTV ) THEN DO 50 II = 1, N I = II IF( I.GE.ILO .AND. I.LE.IHI ) $ GO TO 50 IF( I.LT.ILO ) $ I = ILO - II K = SCALE( I ) IF( K.EQ.I ) $ GO TO 50 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV ) 50 CONTINUE END IF END IF * RETURN * * End of DGEBAK * END
gpl-2.0
huard/scipy-work
scipy/special/cdflib/devlpl.f
151
1209
DOUBLE PRECISION FUNCTION devlpl(a,n,x) C********************************************************************** C C DOUBLE PRECISION FUNCTION DEVLPL(A,N,X) C Double precision EVALuate a PoLynomial at X C C C Function C C C returns C A(1) + A(2)*X + ... + A(N)*X**(N-1) C C C Arguments C C C A --> Array of coefficients of the polynomial. C A is DOUBLE PRECISION(N) C C N --> Length of A, also degree of polynomial - 1. C N is INTEGER C C X --> Point at which the polynomial is to be evaluated. C X is DOUBLE PRECISION C C********************************************************************** C C .. Scalar Arguments .. DOUBLE PRECISION x INTEGER n C .. C .. Array Arguments .. DOUBLE PRECISION a(n) C .. C .. Local Scalars .. DOUBLE PRECISION term INTEGER i C .. C .. Executable Statements .. term = a(n) DO 10,i = n - 1,1,-1 term = a(i) + term*x 10 CONTINUE devlpl = term RETURN END
bsd-3-clause
OpenDA-Association/OpenDA
core/native/external/lapack/dlasd2.f
14
16765
SUBROUTINE DLASD2( NL, NR, SQRE, K, D, Z, ALPHA, BETA, U, LDU, VT, $ LDVT, DSIGMA, U2, LDU2, VT2, LDVT2, IDXP, IDX, $ IDXC, IDXQ, COLTYP, INFO ) * * -- LAPACK auxiliary routine (version 3.0) -- * Univ. of Tennessee, Oak Ridge National Lab, Argonne National Lab, * Courant Institute, NAG Ltd., and Rice University * October 31, 1999 * * .. Scalar Arguments .. INTEGER INFO, K, LDU, LDU2, LDVT, LDVT2, NL, NR, SQRE DOUBLE PRECISION ALPHA, BETA * .. * .. Array Arguments .. INTEGER COLTYP( * ), IDX( * ), IDXC( * ), IDXP( * ), $ IDXQ( * ) DOUBLE PRECISION D( * ), DSIGMA( * ), U( LDU, * ), $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ), $ Z( * ) * .. * * Purpose * ======= * * DLASD2 merges the two sets of singular values together into a single * sorted set. Then it tries to deflate the size of the problem. * There are two ways in which deflation can occur: when two or more * singular values are close together or if there is a tiny entry in the * Z vector. For each such occurrence the order of the related secular * equation problem is reduced by one. * * DLASD2 is called from DLASD1. * * Arguments * ========= * * NL (input) INTEGER * The row dimension of the upper block. NL >= 1. * * NR (input) INTEGER * The row dimension of the lower block. NR >= 1. * * SQRE (input) INTEGER * = 0: the lower block is an NR-by-NR square matrix. * = 1: the lower block is an NR-by-(NR+1) rectangular matrix. * * The bidiagonal matrix has N = NL + NR + 1 rows and * M = N + SQRE >= N columns. * * K (output) INTEGER * Contains the dimension of the non-deflated matrix, * This is the order of the related secular equation. 1 <= K <=N. * * D (input/output) DOUBLE PRECISION array, dimension(N) * On entry D contains the singular values of the two submatrices * to be combined. On exit D contains the trailing (N-K) updated * singular values (those which were deflated) sorted into * increasing order. * * ALPHA (input) DOUBLE PRECISION * Contains the diagonal element associated with the added row. * * BETA (input) DOUBLE PRECISION * Contains the off-diagonal element associated with the added * row. * * U (input/output) DOUBLE PRECISION array, dimension(LDU,N) * On entry U contains the left singular vectors of two * submatrices in the two square blocks with corners at (1,1), * (NL, NL), and (NL+2, NL+2), (N,N). * On exit U contains the trailing (N-K) updated left singular * vectors (those which were deflated) in its last N-K columns. * * LDU (input) INTEGER * The leading dimension of the array U. LDU >= N. * * Z (output) DOUBLE PRECISION array, dimension(N) * On exit Z contains the updating row vector in the secular * equation. * * DSIGMA (output) DOUBLE PRECISION array, dimension (N) * Contains a copy of the diagonal elements (K-1 singular values * and one zero) in the secular equation. * * U2 (output) DOUBLE PRECISION array, dimension(LDU2,N) * Contains a copy of the first K-1 left singular vectors which * will be used by DLASD3 in a matrix multiply (DGEMM) to solve * for the new left singular vectors. U2 is arranged into four * blocks. The first block contains a column with 1 at NL+1 and * zero everywhere else; the second block contains non-zero * entries only at and above NL; the third contains non-zero * entries only below NL+1; and the fourth is dense. * * LDU2 (input) INTEGER * The leading dimension of the array U2. LDU2 >= N. * * VT (input/output) DOUBLE PRECISION array, dimension(LDVT,M) * On entry VT' contains the right singular vectors of two * submatrices in the two square blocks with corners at (1,1), * (NL+1, NL+1), and (NL+2, NL+2), (M,M). * On exit VT' contains the trailing (N-K) updated right singular * vectors (those which were deflated) in its last N-K columns. * In case SQRE =1, the last row of VT spans the right null * space. * * LDVT (input) INTEGER * The leading dimension of the array VT. LDVT >= M. * * VT2 (output) DOUBLE PRECISION array, dimension(LDVT2,N) * VT2' contains a copy of the first K right singular vectors * which will be used by DLASD3 in a matrix multiply (DGEMM) to * solve for the new right singular vectors. VT2 is arranged into * three blocks. The first block contains a row that corresponds * to the special 0 diagonal element in SIGMA; the second block * contains non-zeros only at and before NL +1; the third block * contains non-zeros only at and after NL +2. * * LDVT2 (input) INTEGER * The leading dimension of the array VT2. LDVT2 >= M. * * IDXP (workspace) INTEGER array, dimension(N) * This will contain the permutation used to place deflated * values of D at the end of the array. On output IDXP(2:K) * points to the nondeflated D-values and IDXP(K+1:N) * points to the deflated singular values. * * IDX (workspace) INTEGER array, dimension(N) * This will contain the permutation used to sort the contents of * D into ascending order. * * IDXC (output) INTEGER array, dimension(N) * This will contain the permutation used to arrange the columns * of the deflated U matrix into three groups: the first group * contains non-zero entries only at and above NL, the second * contains non-zero entries only below NL+2, and the third is * dense. * * COLTYP (workspace/output) INTEGER array, dimension(N) * As workspace, this will contain a label which will indicate * which of the following types a column in the U2 matrix or a * row in the VT2 matrix is: * 1 : non-zero in the upper half only * 2 : non-zero in the lower half only * 3 : dense * 4 : deflated * * On exit, it is an array of dimension 4, with COLTYP(I) being * the dimension of the I-th type columns. * * IDXQ (input) INTEGER array, dimension(N) * This contains the permutation which separately sorts the two * sub-problems in D into ascending order. Note that entries in * the first hlaf of this permutation must first be moved one * position backward; and entries in the second half * must first have NL+1 added to their values. * * INFO (output) INTEGER * = 0: successful exit. * < 0: if INFO = -i, the i-th argument had an illegal value. * * Further Details * =============== * * Based on contributions by * Ming Gu and Huan Ren, Computer Science Division, University of * California at Berkeley, USA * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE, TWO, EIGHT PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0, $ EIGHT = 8.0D+0 ) * .. * .. Local Arrays .. INTEGER CTOT( 4 ), PSM( 4 ) * .. * .. Local Scalars .. INTEGER CT, I, IDXI, IDXJ, IDXJP, J, JP, JPREV, K2, M, $ N, NLP1, NLP2 DOUBLE PRECISION C, EPS, HLFTOL, S, TAU, TOL, Z1 * .. * .. External Functions .. DOUBLE PRECISION DLAMCH, DLAPY2 EXTERNAL DLAMCH, DLAPY2 * .. * .. External Subroutines .. EXTERNAL DCOPY, DLACPY, DLAMRG, DLASET, DROT, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 * IF( NL.LT.1 ) THEN INFO = -1 ELSE IF( NR.LT.1 ) THEN INFO = -2 ELSE IF( ( SQRE.NE.1 ) .AND. ( SQRE.NE.0 ) ) THEN INFO = -3 END IF * N = NL + NR + 1 M = N + SQRE * IF( LDU.LT.N ) THEN INFO = -10 ELSE IF( LDVT.LT.M ) THEN INFO = -12 ELSE IF( LDU2.LT.N ) THEN INFO = -15 ELSE IF( LDVT2.LT.M ) THEN INFO = -17 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DLASD2', -INFO ) RETURN END IF * NLP1 = NL + 1 NLP2 = NL + 2 * * Generate the first part of the vector Z; and move the singular * values in the first part of D one position backward. * Z1 = ALPHA*VT( NLP1, NLP1 ) Z( 1 ) = Z1 DO 10 I = NL, 1, -1 Z( I+1 ) = ALPHA*VT( I, NLP1 ) D( I+1 ) = D( I ) IDXQ( I+1 ) = IDXQ( I ) + 1 10 CONTINUE * * Generate the second part of the vector Z. * DO 20 I = NLP2, M Z( I ) = BETA*VT( I, NLP2 ) 20 CONTINUE * * Initialize some reference arrays. * DO 30 I = 2, NLP1 COLTYP( I ) = 1 30 CONTINUE DO 40 I = NLP2, N COLTYP( I ) = 2 40 CONTINUE * * Sort the singular values into increasing order * DO 50 I = NLP2, N IDXQ( I ) = IDXQ( I ) + NLP1 50 CONTINUE * * DSIGMA, IDXC, IDXC, and the first column of U2 * are used as storage space. * DO 60 I = 2, N DSIGMA( I ) = D( IDXQ( I ) ) U2( I, 1 ) = Z( IDXQ( I ) ) IDXC( I ) = COLTYP( IDXQ( I ) ) 60 CONTINUE * CALL DLAMRG( NL, NR, DSIGMA( 2 ), 1, 1, IDX( 2 ) ) * DO 70 I = 2, N IDXI = 1 + IDX( I ) D( I ) = DSIGMA( IDXI ) Z( I ) = U2( IDXI, 1 ) COLTYP( I ) = IDXC( IDXI ) 70 CONTINUE * * Calculate the allowable deflation tolerance * EPS = DLAMCH( 'Epsilon' ) TOL = MAX( ABS( ALPHA ), ABS( BETA ) ) TOL = EIGHT*EPS*MAX( ABS( D( N ) ), TOL ) * * There are 2 kinds of deflation -- first a value in the z-vector * is small, second two (or more) singular values are very close * together (their difference is small). * * If the value in the z-vector is small, we simply permute the * array so that the corresponding singular value is moved to the * end. * * If two values in the D-vector are close, we perform a two-sided * rotation designed to make one of the corresponding z-vector * entries zero, and then permute the array so that the deflated * singular value is moved to the end. * * If there are multiple singular values then the problem deflates. * Here the number of equal singular values are found. As each equal * singular value is found, an elementary reflector is computed to * rotate the corresponding singular subspace so that the * corresponding components of Z are zero in this new basis. * K = 1 K2 = N + 1 DO 80 J = 2, N IF( ABS( Z( J ) ).LE.TOL ) THEN * * Deflate due to small z component. * K2 = K2 - 1 IDXP( K2 ) = J COLTYP( J ) = 4 IF( J.EQ.N ) $ GO TO 120 ELSE JPREV = J GO TO 90 END IF 80 CONTINUE 90 CONTINUE J = JPREV 100 CONTINUE J = J + 1 IF( J.GT.N ) $ GO TO 110 IF( ABS( Z( J ) ).LE.TOL ) THEN * * Deflate due to small z component. * K2 = K2 - 1 IDXP( K2 ) = J COLTYP( J ) = 4 ELSE * * Check if singular values are close enough to allow deflation. * IF( ABS( D( J )-D( JPREV ) ).LE.TOL ) THEN * * Deflation is possible. * S = Z( JPREV ) C = Z( J ) * * Find sqrt(a**2+b**2) without overflow or * destructive underflow. * TAU = DLAPY2( C, S ) C = C / TAU S = -S / TAU Z( J ) = TAU Z( JPREV ) = ZERO * * Apply back the Givens rotation to the left and right * singular vector matrices. * IDXJP = IDXQ( IDX( JPREV )+1 ) IDXJ = IDXQ( IDX( J )+1 ) IF( IDXJP.LE.NLP1 ) THEN IDXJP = IDXJP - 1 END IF IF( IDXJ.LE.NLP1 ) THEN IDXJ = IDXJ - 1 END IF CALL DROT( N, U( 1, IDXJP ), 1, U( 1, IDXJ ), 1, C, S ) CALL DROT( M, VT( IDXJP, 1 ), LDVT, VT( IDXJ, 1 ), LDVT, C, $ S ) IF( COLTYP( J ).NE.COLTYP( JPREV ) ) THEN COLTYP( J ) = 3 END IF COLTYP( JPREV ) = 4 K2 = K2 - 1 IDXP( K2 ) = JPREV JPREV = J ELSE K = K + 1 U2( K, 1 ) = Z( JPREV ) DSIGMA( K ) = D( JPREV ) IDXP( K ) = JPREV JPREV = J END IF END IF GO TO 100 110 CONTINUE * * Record the last singular value. * K = K + 1 U2( K, 1 ) = Z( JPREV ) DSIGMA( K ) = D( JPREV ) IDXP( K ) = JPREV * 120 CONTINUE * * Count up the total number of the various types of columns, then * form a permutation which positions the four column types into * four groups of uniform structure (although one or more of these * groups may be empty). * DO 130 J = 1, 4 CTOT( J ) = 0 130 CONTINUE DO 140 J = 2, N CT = COLTYP( J ) CTOT( CT ) = CTOT( CT ) + 1 140 CONTINUE * * PSM(*) = Position in SubMatrix (of types 1 through 4) * PSM( 1 ) = 2 PSM( 2 ) = 2 + CTOT( 1 ) PSM( 3 ) = PSM( 2 ) + CTOT( 2 ) PSM( 4 ) = PSM( 3 ) + CTOT( 3 ) * * Fill out the IDXC array so that the permutation which it induces * will place all type-1 columns first, all type-2 columns next, * then all type-3's, and finally all type-4's, starting from the * second column. This applies similarly to the rows of VT. * DO 150 J = 2, N JP = IDXP( J ) CT = COLTYP( JP ) IDXC( PSM( CT ) ) = J PSM( CT ) = PSM( CT ) + 1 150 CONTINUE * * Sort the singular values and corresponding singular vectors into * DSIGMA, U2, and VT2 respectively. The singular values/vectors * which were not deflated go into the first K slots of DSIGMA, U2, * and VT2 respectively, while those which were deflated go into the * last N - K slots, except that the first column/row will be treated * separately. * DO 160 J = 2, N JP = IDXP( J ) DSIGMA( J ) = D( JP ) IDXJ = IDXQ( IDX( IDXP( IDXC( J ) ) )+1 ) IF( IDXJ.LE.NLP1 ) THEN IDXJ = IDXJ - 1 END IF CALL DCOPY( N, U( 1, IDXJ ), 1, U2( 1, J ), 1 ) CALL DCOPY( M, VT( IDXJ, 1 ), LDVT, VT2( J, 1 ), LDVT2 ) 160 CONTINUE * * Determine DSIGMA(1), DSIGMA(2) and Z(1) * DSIGMA( 1 ) = ZERO HLFTOL = TOL / TWO IF( ABS( DSIGMA( 2 ) ).LE.HLFTOL ) $ DSIGMA( 2 ) = HLFTOL IF( M.GT.N ) THEN Z( 1 ) = DLAPY2( Z1, Z( M ) ) IF( Z( 1 ).LE.TOL ) THEN C = ONE S = ZERO Z( 1 ) = TOL ELSE C = Z1 / Z( 1 ) S = Z( M ) / Z( 1 ) END IF ELSE IF( ABS( Z1 ).LE.TOL ) THEN Z( 1 ) = TOL ELSE Z( 1 ) = Z1 END IF END IF * * Move the rest of the updating row to Z. * CALL DCOPY( K-1, U2( 2, 1 ), 1, Z( 2 ), 1 ) * * Determine the first column of U2, the first row of VT2 and the * last row of VT. * CALL DLASET( 'A', N, 1, ZERO, ZERO, U2, LDU2 ) U2( NLP1, 1 ) = ONE IF( M.GT.N ) THEN DO 170 I = 1, NLP1 VT( M, I ) = -S*VT( NLP1, I ) VT2( 1, I ) = C*VT( NLP1, I ) 170 CONTINUE DO 180 I = NLP2, M VT2( 1, I ) = S*VT( M, I ) VT( M, I ) = C*VT( M, I ) 180 CONTINUE ELSE CALL DCOPY( M, VT( NLP1, 1 ), LDVT, VT2( 1, 1 ), LDVT2 ) END IF IF( M.GT.N ) THEN CALL DCOPY( M, VT( M, 1 ), LDVT, VT2( M, 1 ), LDVT2 ) END IF * * The deflated singular values and their corresponding vectors go * into the back of D, U, and V respectively. * IF( N.GT.K ) THEN CALL DCOPY( N-K, DSIGMA( K+1 ), 1, D( K+1 ), 1 ) CALL DLACPY( 'A', N, N-K, U2( 1, K+1 ), LDU2, U( 1, K+1 ), $ LDU ) CALL DLACPY( 'A', N-K, M, VT2( K+1, 1 ), LDVT2, VT( K+1, 1 ), $ LDVT ) END IF * * Copy CTOT into COLTYP for referencing in DLASD3. * DO 190 J = 1, 4 COLTYP( J ) = CTOT( J ) 190 CONTINUE * RETURN * * End of DLASD2 * END
lgpl-3.0
aamaricci/SciFortran
src/arpack/src/znaitr.f
1
30911
c\BeginDoc c c\Name: znaitr c c\Description: c Reverse communication interface for applying NP additional steps to c a K step nonsymmetric Arnoldi factorization. c c Input: OP*V_{k} - V_{k}*H = r_{k}*e_{k}^T c c with (V_{k}^T)*B*V_{k} = I, (V_{k}^T)*B*r_{k} = 0. c c Output: OP*V_{k+p} - V_{k+p}*H = r_{k+p}*e_{k+p}^T c c with (V_{k+p}^T)*B*V_{k+p} = I, (V_{k+p}^T)*B*r_{k+p} = 0. c c where OP and B are as in znaupd. The B-norm of r_{k+p} is also c computed and returned. c c\Usage: c call znaitr c ( IDO, BMAT, N, K, NP, NB, RESID, RNORM, V, LDV, H, LDH, c IPNTR, WORKD, INFO ) c c\Arguments c IDO Integer. (INPUT/OUTPUT) c Reverse communication flag. c ------------------------------------------------------------- c IDO = 0: first call to the reverse communication interface c IDO = -1: compute Y = OP * X where c IPNTR(1) is the pointer into WORK for X, c IPNTR(2) is the pointer into WORK for Y. c This is for the restart phase to force the new c starting vector into the range of OP. c IDO = 1: compute Y = OP * X where c IPNTR(1) is the pointer into WORK for X, c IPNTR(2) is the pointer into WORK for Y, c IPNTR(3) is the pointer into WORK for B * X. c IDO = 2: compute Y = B * X where c IPNTR(1) is the pointer into WORK for X, c IPNTR(2) is the pointer into WORK for Y. c IDO = 99: done c ------------------------------------------------------------- c When the routine is used in the "shift-and-invert" mode, the c vector B * Q is already available and do not need to be c recomputed in forming OP * Q. c c BMAT Character*1. (INPUT) c BMAT specifies the type of the matrix B that defines the c semi-inner product for the operator OP. See znaupd. c B = 'I' -> standard eigenvalue problem A*x = lambda*x c B = 'G' -> generalized eigenvalue problem A*x = lambda*M**x c c N Integer. (INPUT) c Dimension of the eigenproblem. c c K Integer. (INPUT) c Current size of V and H. c c NP Integer. (INPUT) c Number of additional Arnoldi steps to take. c c NB Integer. (INPUT) c Blocksize to be used in the recurrence. c Only work for NB = 1 right now. The goal is to have a c program that implement both the block and non-block method. c c RESID Complex*16 array of length N. (INPUT/OUTPUT) c On INPUT: RESID contains the residual vector r_{k}. c On OUTPUT: RESID contains the residual vector r_{k+p}. c c RNORM Double precision scalar. (INPUT/OUTPUT) c B-norm of the starting residual on input. c B-norm of the updated residual r_{k+p} on output. c c V Complex*16 N by K+NP array. (INPUT/OUTPUT) c On INPUT: V contains the Arnoldi vectors in the first K c columns. c On OUTPUT: V contains the new NP Arnoldi vectors in the next c NP columns. The first K columns are unchanged. c c LDV Integer. (INPUT) c Leading dimension of V exactly as declared in the calling c program. c c H Complex*16 (K+NP) by (K+NP) array. (INPUT/OUTPUT) c H is used to store the generated upper Hessenberg matrix. c c LDH Integer. (INPUT) c Leading dimension of H exactly as declared in the calling c program. c c IPNTR Integer array of length 3. (OUTPUT) c Pointer to mark the starting locations in the WORK for c vectors used by the Arnoldi iteration. c ------------------------------------------------------------- c IPNTR(1): pointer to the current operand vector X. c IPNTR(2): pointer to the current result vector Y. c IPNTR(3): pointer to the vector B * X when used in the c shift-and-invert mode. X is the current operand. c ------------------------------------------------------------- c c WORKD Complex*16 work array of length 3*N. (REVERSE COMMUNICATION) c Distributed array to be used in the basic Arnoldi iteration c for reverse communication. The calling program should not c use WORKD as temporary workspace during the iteration !!!!!! c On input, WORKD(1:N) = B*RESID and is used to save some c computation at the first step. c c INFO Integer. (OUTPUT) c = 0: Normal exit. c > 0: Size of the spanning invariant subspace of OP found. c c\EndDoc c c----------------------------------------------------------------------- c c\BeginLib c c\Local variables: c xxxxxx Complex*16 c c\References: c 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in c a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), c pp 357-385. c 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly c Restarted Arnoldi Iteration", Rice University Technical Report c TR95-13, Department of Computational and Applied Mathematics. c c\Routines called: c zgetv0 ARPACK routine to generate the initial vector. c ivout ARPACK utility routine that prints integers. c arscnd ARPACK utility routine for timing. c zmout ARPACK utility routine that prints matrices c zvout ARPACK utility routine that prints vectors. c zlanhs LAPACK routine that computes various norms of a matrix. c zlascl LAPACK routine for careful scaling of a matrix. c dlabad LAPACK routine for defining the underflow and overflow c limits. c dlamch LAPACK routine that determines machine constants. c dlapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully. c zgemv Level 2 BLAS routine for matrix vector multiplication. c zaxpy Level 1 BLAS that computes a vector triad. c zcopy Level 1 BLAS that copies one vector to another . c zdotc Level 1 BLAS that computes the scalar product of two vectors. c zscal Level 1 BLAS that scales a vector. c zdscal Level 1 BLAS that scales a complex vector by a real number. c dznrm2 Level 1 BLAS that computes the norm of a vector. c c\Author c Danny Sorensen Phuong Vu c Richard Lehoucq CRPC / Rice University c Dept. of Computational & Houston, Texas c Applied Mathematics c Rice University c Houston, Texas c c\SCCS Information: @(#) c FILE: naitr.F SID: 2.3 DATE OF SID: 8/27/96 RELEASE: 2 c c\Remarks c The algorithm implemented is: c c restart = .false. c Given V_{k} = [v_{1}, ..., v_{k}], r_{k}; c r_{k} contains the initial residual vector even for k = 0; c Also assume that rnorm = || B*r_{k} || and B*r_{k} are already c computed by the calling program. c c betaj = rnorm ; p_{k+1} = B*r_{k} ; c For j = k+1, ..., k+np Do c 1) if ( betaj < tol ) stop or restart depending on j. c ( At present tol is zero ) c if ( restart ) generate a new starting vector. c 2) v_{j} = r(j-1)/betaj; V_{j} = [V_{j-1}, v_{j}]; c p_{j} = p_{j}/betaj c 3) r_{j} = OP*v_{j} where OP is defined as in znaupd c For shift-invert mode p_{j} = B*v_{j} is already available. c wnorm = || OP*v_{j} || c 4) Compute the j-th step residual vector. c w_{j} = V_{j}^T * B * OP * v_{j} c r_{j} = OP*v_{j} - V_{j} * w_{j} c H(:,j) = w_{j}; c H(j,j-1) = rnorm c rnorm = || r_(j) || c If (rnorm > 0.717*wnorm) accept step and go back to 1) c 5) Re-orthogonalization step: c s = V_{j}'*B*r_{j} c r_{j} = r_{j} - V_{j}*s; rnorm1 = || r_{j} || c alphaj = alphaj + s_{j}; c 6) Iterative refinement step: c If (rnorm1 > 0.717*rnorm) then c rnorm = rnorm1 c accept step and go back to 1) c Else c rnorm = rnorm1 c If this is the first time in step 6), go to 5) c Else r_{j} lies in the span of V_{j} numerically. c Set r_{j} = 0 and rnorm = 0; go to 1) c EndIf c End Do c c\EndLib c c----------------------------------------------------------------------- c subroutine znaitr & (ido, bmat, n, k, np, nb, resid, rnorm, v, ldv, h, ldh, & ipntr, workd, info) c c %----------------------------------------------------% c | Include files for debugging and timing information | c %----------------------------------------------------% c include 'debug.h' include 'stat.h' c c %------------------% c | Scalar Arguments | c %------------------% c character bmat*1 integer ido, info, k, ldh, ldv, n, nb, np Double precision & rnorm c c %-----------------% c | Array Arguments | c %-----------------% c integer ipntr(3) Complex*16 & h(ldh,k+np), resid(n), v(ldv,k+np), workd(3*n) c c %------------% c | Parameters | c %------------% c Complex*16 & one, zero Double precision & rone, rzero parameter (one = (1.0D+0, 0.0D+0), zero = (0.0D+0, 0.0D+0), & rone = 1.0D+0, rzero = 0.0D+0) c c %--------------% c | Local Arrays | c %--------------% c Double precision & rtemp(2) c c %---------------% c | Local Scalars | c %---------------% c logical first, orth1, orth2, rstart, step3, step4 integer ierr, i, infol, ipj, irj, ivj, iter, itry, j, msglvl, & jj Double precision & ovfl, smlnum, tst1, ulp, unfl, betaj, & temp1, rnorm1, wnorm Complex*16 & cnorm c save first, orth1, orth2, rstart, step3, step4, & ierr, ipj, irj, ivj, iter, itry, j, msglvl, ovfl, & betaj, rnorm1, smlnum, ulp, unfl, wnorm c c %----------------------% c | External Subroutines | c %----------------------% c external zaxpy, zcopy, zscal, zdscal, zgemv, zgetv0, & dlabad, zvout, zmout, ivout, arscnd c c %--------------------% c | External Functions | c %--------------------% c Double precision & dlamch, dznrm2, zlanhs, dlapy2 external dznrm2, zlanhs, dlamch, dlapy2 c c %---------------------% c | Intrinsic Functions | c %---------------------% c intrinsic dimag, dble, max, sqrt c c %-----------------% c | Data statements | c %-----------------% c data first / .true. / c c %-----------------------% c | Executable Statements | c %-----------------------% c if (first) then c c %-----------------------------------------% c | Set machine-dependent constants for the | c | the splitting and deflation criterion. | c | If norm(H) <= sqrt(OVFL), | c | overflow should not occur. | c | REFERENCE: LAPACK subroutine zlahqr | c %-----------------------------------------% c unfl = dlamch( 'safe minimum' ) ovfl = dble(one / unfl) call dlabad( unfl, ovfl ) ulp = dlamch( 'precision' ) smlnum = unfl*( n / ulp ) first = .false. end if c if (ido .eq. 0) then c c %-------------------------------% c | Initialize timing statistics | c | & message level for debugging | c %-------------------------------% c call arscnd (t0) msglvl = mcaitr c c %------------------------------% c | Initial call to this routine | c %------------------------------% c info = 0 step3 = .false. step4 = .false. rstart = .false. orth1 = .false. orth2 = .false. j = k + 1 ipj = 1 irj = ipj + n ivj = irj + n end if c c %-------------------------------------------------% c | When in reverse communication mode one of: | c | STEP3, STEP4, ORTH1, ORTH2, RSTART | c | will be .true. when .... | c | STEP3: return from computing OP*v_{j}. | c | STEP4: return from computing B-norm of OP*v_{j} | c | ORTH1: return from computing B-norm of r_{j+1} | c | ORTH2: return from computing B-norm of | c | correction to the residual vector. | c | RSTART: return from OP computations needed by | c | zgetv0. | c %-------------------------------------------------% c if (step3) go to 50 if (step4) go to 60 if (orth1) go to 70 if (orth2) go to 90 if (rstart) go to 30 c c %-----------------------------% c | Else this is the first step | c %-----------------------------% c c %--------------------------------------------------------------% c | | c | A R N O L D I I T E R A T I O N L O O P | c | | c | Note: B*r_{j-1} is already in WORKD(1:N)=WORKD(IPJ:IPJ+N-1) | c %--------------------------------------------------------------% 1000 continue c if (msglvl .gt. 1) then call ivout (logfil, 1, j, ndigit, & '_naitr: generating Arnoldi vector number') call dvout (logfil, 1, rnorm, ndigit, & '_naitr: B-norm of the current residual is') end if c c %---------------------------------------------------% c | STEP 1: Check if the B norm of j-th residual | c | vector is zero. Equivalent to determine whether | c | an exact j-step Arnoldi factorization is present. | c %---------------------------------------------------% c betaj = rnorm if (rnorm .gt. rzero) go to 40 c c %---------------------------------------------------% c | Invariant subspace found, generate a new starting | c | vector which is orthogonal to the current Arnoldi | c | basis and continue the iteration. | c %---------------------------------------------------% c if (msglvl .gt. 0) then call ivout (logfil, 1, j, ndigit, & '_naitr: ****** RESTART AT STEP ******') end if c c %---------------------------------------------% c | ITRY is the loop variable that controls the | c | maximum amount of times that a restart is | c | attempted. NRSTRT is used by stat.h | c %---------------------------------------------% c betaj = rzero nrstrt = nrstrt + 1 itry = 1 20 continue rstart = .true. ido = 0 30 continue c c %--------------------------------------% c | If in reverse communication mode and | c | RSTART = .true. flow returns here. | c %--------------------------------------% c call zgetv0 (ido, bmat, itry, .false., n, j, v, ldv, & resid, rnorm, ipntr, workd, ierr) if (ido .ne. 99) go to 9000 if (ierr .lt. 0) then itry = itry + 1 if (itry .le. 3) go to 20 c c %------------------------------------------------% c | Give up after several restart attempts. | c | Set INFO to the size of the invariant subspace | c | which spans OP and exit. | c %------------------------------------------------% c info = j - 1 call arscnd (t1) tcaitr = tcaitr + (t1 - t0) ido = 99 go to 9000 end if c 40 continue c c %---------------------------------------------------------% c | STEP 2: v_{j} = r_{j-1}/rnorm and p_{j} = p_{j}/rnorm | c | Note that p_{j} = B*r_{j-1}. In order to avoid overflow | c | when reciprocating a small RNORM, test against lower | c | machine bound. | c %---------------------------------------------------------% c call zcopy (n, resid, 1, v(1,j), 1) if ( rnorm .ge. unfl) then temp1 = rone / rnorm call zdscal (n, temp1, v(1,j), 1) call zdscal (n, temp1, workd(ipj), 1) else c c %-----------------------------------------% c | To scale both v_{j} and p_{j} carefully | c | use LAPACK routine zlascl | c %-----------------------------------------% c call zlascl ('General', i, i, rnorm, rone, & n, 1, v(1,j), n, infol) call zlascl ('General', i, i, rnorm, rone, & n, 1, workd(ipj), n, infol) end if c c %------------------------------------------------------% c | STEP 3: r_{j} = OP*v_{j}; Note that p_{j} = B*v_{j} | c | Note that this is not quite yet r_{j}. See STEP 4 | c %------------------------------------------------------% c step3 = .true. nopx = nopx + 1 call arscnd (t2) call zcopy (n, v(1,j), 1, workd(ivj), 1) ipntr(1) = ivj ipntr(2) = irj ipntr(3) = ipj ido = 1 c c %-----------------------------------% c | Exit in order to compute OP*v_{j} | c %-----------------------------------% c go to 9000 50 continue c c %----------------------------------% c | Back from reverse communication; | c | WORKD(IRJ:IRJ+N-1) := OP*v_{j} | c | if step3 = .true. | c %----------------------------------% c call arscnd (t3) tmvopx = tmvopx + (t3 - t2) step3 = .false. c c %------------------------------------------% c | Put another copy of OP*v_{j} into RESID. | c %------------------------------------------% c call zcopy (n, workd(irj), 1, resid, 1) c c %---------------------------------------% c | STEP 4: Finish extending the Arnoldi | c | factorization to length j. | c %---------------------------------------% c call arscnd (t2) if (bmat .eq. 'G') then nbx = nbx + 1 step4 = .true. ipntr(1) = irj ipntr(2) = ipj ido = 2 c c %-------------------------------------% c | Exit in order to compute B*OP*v_{j} | c %-------------------------------------% c go to 9000 else if (bmat .eq. 'I') then call zcopy (n, resid, 1, workd(ipj), 1) end if 60 continue c c %----------------------------------% c | Back from reverse communication; | c | WORKD(IPJ:IPJ+N-1) := B*OP*v_{j} | c | if step4 = .true. | c %----------------------------------% c if (bmat .eq. 'G') then call arscnd (t3) tmvbx = tmvbx + (t3 - t2) end if c step4 = .false. c c %-------------------------------------% c | The following is needed for STEP 5. | c | Compute the B-norm of OP*v_{j}. | c %-------------------------------------% c if (bmat .eq. 'G') then call zdotc (cnorm, n, resid, 1, workd(ipj), 1) wnorm = sqrt( dlapy2(dble(cnorm),dimag(cnorm)) ) else if (bmat .eq. 'I') then wnorm = dznrm2(n, resid, 1) end if c c %-----------------------------------------% c | Compute the j-th residual corresponding | c | to the j step factorization. | c | Use Classical Gram Schmidt and compute: | c | w_{j} <- V_{j}^T * B * OP * v_{j} | c | r_{j} <- OP*v_{j} - V_{j} * w_{j} | c %-----------------------------------------% c c c %------------------------------------------% c | Compute the j Fourier coefficients w_{j} | c | WORKD(IPJ:IPJ+N-1) contains B*OP*v_{j}. | c %------------------------------------------% c call zgemv ('C', n, j, one, v, ldv, workd(ipj), 1, & zero, h(1,j), 1) c c %--------------------------------------% c | Orthogonalize r_{j} against V_{j}. | c | RESID contains OP*v_{j}. See STEP 3. | c %--------------------------------------% c call zgemv ('N', n, j, -one, v, ldv, h(1,j), 1, & one, resid, 1) c if (j .gt. 1) h(j,j-1) = dcmplx(betaj, rzero) c call arscnd (t4) c orth1 = .true. c call arscnd (t2) if (bmat .eq. 'G') then nbx = nbx + 1 call zcopy (n, resid, 1, workd(irj), 1) ipntr(1) = irj ipntr(2) = ipj ido = 2 c c %----------------------------------% c | Exit in order to compute B*r_{j} | c %----------------------------------% c go to 9000 else if (bmat .eq. 'I') then call zcopy (n, resid, 1, workd(ipj), 1) end if 70 continue c c %---------------------------------------------------% c | Back from reverse communication if ORTH1 = .true. | c | WORKD(IPJ:IPJ+N-1) := B*r_{j}. | c %---------------------------------------------------% c if (bmat .eq. 'G') then call arscnd (t3) tmvbx = tmvbx + (t3 - t2) end if c orth1 = .false. c c %------------------------------% c | Compute the B-norm of r_{j}. | c %------------------------------% c if (bmat .eq. 'G') then call zdotc (cnorm, n, resid, 1, workd(ipj), 1) rnorm = sqrt( dlapy2(dble(cnorm),dimag(cnorm)) ) else if (bmat .eq. 'I') then rnorm = dznrm2(n, resid, 1) end if c c %-----------------------------------------------------------% c | STEP 5: Re-orthogonalization / Iterative refinement phase | c | Maximum NITER_ITREF tries. | c | | c | s = V_{j}^T * B * r_{j} | c | r_{j} = r_{j} - V_{j}*s | c | alphaj = alphaj + s_{j} | c | | c | The stopping criteria used for iterative refinement is | c | discussed in Parlett's book SEP, page 107 and in Gragg & | c | Reichel ACM TOMS paper; Algorithm 686, Dec. 1990. | c | Determine if we need to correct the residual. The goal is | c | to enforce ||v(:,1:j)^T * r_{j}|| .le. eps * || r_{j} || | c | The following test determines whether the sine of the | c | angle between OP*x and the computed residual is less | c | than or equal to 0.717. | c %-----------------------------------------------------------% c if ( rnorm .gt. 0.717*wnorm ) go to 100 c iter = 0 nrorth = nrorth + 1 c c %---------------------------------------------------% c | Enter the Iterative refinement phase. If further | c | refinement is necessary, loop back here. The loop | c | variable is ITER. Perform a step of Classical | c | Gram-Schmidt using all the Arnoldi vectors V_{j} | c %---------------------------------------------------% c 80 continue c if (msglvl .gt. 2) then rtemp(1) = wnorm rtemp(2) = rnorm call dvout (logfil, 2, rtemp, ndigit, & '_naitr: re-orthogonalization; wnorm and rnorm are') call zvout (logfil, j, h(1,j), ndigit, & '_naitr: j-th column of H') end if c c %----------------------------------------------------% c | Compute V_{j}^T * B * r_{j}. | c | WORKD(IRJ:IRJ+J-1) = v(:,1:J)'*WORKD(IPJ:IPJ+N-1). | c %----------------------------------------------------% c call zgemv ('C', n, j, one, v, ldv, workd(ipj), 1, & zero, workd(irj), 1) c c %---------------------------------------------% c | Compute the correction to the residual: | c | r_{j} = r_{j} - V_{j} * WORKD(IRJ:IRJ+J-1). | c | The correction to H is v(:,1:J)*H(1:J,1:J) | c | + v(:,1:J)*WORKD(IRJ:IRJ+J-1)*e'_j. | c %---------------------------------------------% c call zgemv ('N', n, j, -one, v, ldv, workd(irj), 1, & one, resid, 1) call zaxpy (j, one, workd(irj), 1, h(1,j), 1) c orth2 = .true. call arscnd (t2) if (bmat .eq. 'G') then nbx = nbx + 1 call zcopy (n, resid, 1, workd(irj), 1) ipntr(1) = irj ipntr(2) = ipj ido = 2 c c %-----------------------------------% c | Exit in order to compute B*r_{j}. | c | r_{j} is the corrected residual. | c %-----------------------------------% c go to 9000 else if (bmat .eq. 'I') then call zcopy (n, resid, 1, workd(ipj), 1) end if 90 continue c c %---------------------------------------------------% c | Back from reverse communication if ORTH2 = .true. | c %---------------------------------------------------% c if (bmat .eq. 'G') then call arscnd (t3) tmvbx = tmvbx + (t3 - t2) end if c c %-----------------------------------------------------% c | Compute the B-norm of the corrected residual r_{j}. | c %-----------------------------------------------------% c if (bmat .eq. 'G') then call zdotc (cnorm, n, resid, 1, workd(ipj), 1) rnorm1 = sqrt( dlapy2(dble(cnorm),dimag(cnorm)) ) else if (bmat .eq. 'I') then rnorm1 = dznrm2(n, resid, 1) end if c if (msglvl .gt. 0 .and. iter .gt. 0 ) then call ivout (logfil, 1, j, ndigit, & '_naitr: Iterative refinement for Arnoldi residual') if (msglvl .gt. 2) then rtemp(1) = rnorm rtemp(2) = rnorm1 call dvout (logfil, 2, rtemp, ndigit, & '_naitr: iterative refinement ; rnorm and rnorm1 are') end if end if c c %-----------------------------------------% c | Determine if we need to perform another | c | step of re-orthogonalization. | c %-----------------------------------------% c if ( rnorm1 .gt. 0.717*rnorm ) then c c %---------------------------------------% c | No need for further refinement. | c | The cosine of the angle between the | c | corrected residual vector and the old | c | residual vector is greater than 0.717 | c | In other words the corrected residual | c | and the old residual vector share an | c | angle of less than arcCOS(0.717) | c %---------------------------------------% c rnorm = rnorm1 c else c c %-------------------------------------------% c | Another step of iterative refinement step | c | is required. NITREF is used by stat.h | c %-------------------------------------------% c nitref = nitref + 1 rnorm = rnorm1 iter = iter + 1 if (iter .le. 1) go to 80 c c %-------------------------------------------------% c | Otherwise RESID is numerically in the span of V | c %-------------------------------------------------% c do 95 jj = 1, n resid(jj) = zero 95 continue rnorm = rzero end if c c %----------------------------------------------% c | Branch here directly if iterative refinement | c | wasn't necessary or after at most NITER_REF | c | steps of iterative refinement. | c %----------------------------------------------% c 100 continue c rstart = .false. orth2 = .false. c call arscnd (t5) titref = titref + (t5 - t4) c c %------------------------------------% c | STEP 6: Update j = j+1; Continue | c %------------------------------------% c j = j + 1 if (j .gt. k+np) then call arscnd (t1) tcaitr = tcaitr + (t1 - t0) ido = 99 do 110 i = max(1,k), k+np-1 c c %--------------------------------------------% c | Check for splitting and deflation. | c | Use a standard test as in the QR algorithm | c | REFERENCE: LAPACK subroutine zlahqr | c %--------------------------------------------% c tst1 = dlapy2(dble(h(i,i)),dimag(h(i,i))) & + dlapy2(dble(h(i+1,i+1)), dimag(h(i+1,i+1))) if( tst1.eq.dble(zero) ) & tst1 = zlanhs( '1', k+np, h, ldh, workd(n+1) ) if( dlapy2(dble(h(i+1,i)),dimag(h(i+1,i))) .le. & max( ulp*tst1, smlnum ) ) & h(i+1,i) = zero 110 continue c if (msglvl .gt. 2) then call zmout (logfil, k+np, k+np, h, ldh, ndigit, & '_naitr: Final upper Hessenberg matrix H of order K+NP') end if c go to 9000 end if c c %--------------------------------------------------------% c | Loop back to extend the factorization by another step. | c %--------------------------------------------------------% c go to 1000 c c %---------------------------------------------------------------% c | | c | E N D O F M A I N I T E R A T I O N L O O P | c | | c %---------------------------------------------------------------% c 9000 continue return c c %---------------% c | End of znaitr | c %---------------% c end
lgpl-3.0
sradanov/flyingpigeon
flyingpigeon/Fsrc/Lapack/SRC/dgghd3.f
5
32001
*> \brief \b DGGHD3 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGGHD3 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgghd3.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgghd3.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgghd3.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGGHD3( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q, * LDQ, Z, LDZ, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER COMPQ, COMPZ * INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N, LWORK * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ), * $ Z( LDZ, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGGHD3 reduces a pair of real matrices (A,B) to generalized upper *> Hessenberg form using orthogonal transformations, where A is a *> general matrix and B is upper triangular. The form of the *> generalized eigenvalue problem is *> A*x = lambda*B*x, *> and B is typically made upper triangular by computing its QR *> factorization and moving the orthogonal matrix Q to the left side *> of the equation. *> *> This subroutine simultaneously reduces A to a Hessenberg matrix H: *> Q**T*A*Z = H *> and transforms B to another upper triangular matrix T: *> Q**T*B*Z = T *> in order to reduce the problem to its standard form *> H*y = lambda*T*y *> where y = Z**T*x. *> *> The orthogonal matrices Q and Z are determined as products of Givens *> rotations. They may either be formed explicitly, or they may be *> postmultiplied into input matrices Q1 and Z1, so that *> *> Q1 * A * Z1**T = (Q1*Q) * H * (Z1*Z)**T *> *> Q1 * B * Z1**T = (Q1*Q) * T * (Z1*Z)**T *> *> If Q1 is the orthogonal matrix from the QR factorization of B in the *> original equation A*x = lambda*B*x, then DGGHD3 reduces the original *> problem to generalized Hessenberg form. *> *> This is a blocked variant of DGGHRD, using matrix-matrix *> multiplications for parts of the computation to enhance performance. *> \endverbatim * * Arguments: * ========== * *> \param[in] COMPQ *> \verbatim *> COMPQ is CHARACTER*1 *> = 'N': do not compute Q; *> = 'I': Q is initialized to the unit matrix, and the *> orthogonal matrix Q is returned; *> = 'V': Q must contain an orthogonal matrix Q1 on entry, *> and the product Q1*Q is returned. *> \endverbatim *> *> \param[in] COMPZ *> \verbatim *> COMPZ is CHARACTER*1 *> = 'N': do not compute Z; *> = 'I': Z is initialized to the unit matrix, and the *> orthogonal matrix Z is returned; *> = 'V': Z must contain an orthogonal matrix Z1 on entry, *> and the product Z1*Z is returned. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrices A and B. N >= 0. *> \endverbatim *> *> \param[in] ILO *> \verbatim *> ILO is INTEGER *> \endverbatim *> *> \param[in] IHI *> \verbatim *> IHI is INTEGER *> *> ILO and IHI mark the rows and columns of A which are to be *> reduced. It is assumed that A is already upper triangular *> in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are *> normally set by a previous call to DGGBAL; otherwise they *> should be set to 1 and N respectively. *> 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA, N) *> On entry, the N-by-N general matrix to be reduced. *> On exit, the upper triangle and the first subdiagonal of A *> are overwritten with the upper Hessenberg matrix H, and the *> rest is set to zero. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is DOUBLE PRECISION array, dimension (LDB, N) *> On entry, the N-by-N upper triangular matrix B. *> On exit, the upper triangular matrix T = Q**T B Z. The *> elements below the diagonal are set to zero. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[in,out] Q *> \verbatim *> Q is DOUBLE PRECISION array, dimension (LDQ, N) *> On entry, if COMPQ = 'V', the orthogonal matrix Q1, *> typically from the QR factorization of B. *> On exit, if COMPQ='I', the orthogonal matrix Q, and if *> COMPQ = 'V', the product Q1*Q. *> Not referenced if COMPQ='N'. *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of the array Q. *> LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. *> \endverbatim *> *> \param[in,out] Z *> \verbatim *> Z is DOUBLE PRECISION array, dimension (LDZ, N) *> On entry, if COMPZ = 'V', the orthogonal matrix Z1. *> On exit, if COMPZ='I', the orthogonal matrix Z, and if *> COMPZ = 'V', the product Z1*Z. *> Not referenced if COMPZ='N'. *> \endverbatim *> *> \param[in] LDZ *> \verbatim *> LDZ is INTEGER *> The leading dimension of the array Z. *> LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (LWORK) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The length of the array WORK. LWORK >= 1. *> For optimum performance LWORK >= 6*N*NB, where NB is the *> optimal blocksize. *> *> 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] 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. * *> \date January 2015 * *> \ingroup doubleOTHERcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> This routine reduces A to Hessenberg form and maintains B in *> using a blocked variant of Moler and Stewart's original algorithm, *> as described by Kagstrom, Kressner, Quintana-Orti, and Quintana-Orti *> (BIT 2008). *> \endverbatim *> * ===================================================================== SUBROUTINE DGGHD3( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q, $ LDQ, Z, LDZ, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.6.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * January 2015 * IMPLICIT NONE * * .. Scalar Arguments .. CHARACTER COMPQ, COMPZ INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N, LWORK * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ), $ Z( LDZ, * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL BLK22, INITQ, INITZ, LQUERY, WANTQ, WANTZ CHARACTER*1 COMPQ2, COMPZ2 INTEGER COLA, I, IERR, J, J0, JCOL, JJ, JROW, K, $ KACC22, LEN, LWKOPT, N2NB, NB, NBLST, NBMIN, $ NH, NNB, NX, PPW, PPWO, PW, TOP, TOPQ DOUBLE PRECISION C, C1, C2, S, S1, S2, TEMP, TEMP1, TEMP2, TEMP3 * .. * .. External Functions .. LOGICAL LSAME INTEGER ILAENV EXTERNAL ILAENV, LSAME * .. * .. External Subroutines .. EXTERNAL DGGHRD, DLARTG, DLASET, DORM22, DROT, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC DBLE, MAX * .. * .. Executable Statements .. * * Decode and test the input parameters. * INFO = 0 NB = ILAENV( 1, 'DGGHD3', ' ', N, ILO, IHI, -1 ) LWKOPT = 6*N*NB WORK( 1 ) = DBLE( LWKOPT ) INITQ = LSAME( COMPQ, 'I' ) WANTQ = INITQ .OR. LSAME( COMPQ, 'V' ) INITZ = LSAME( COMPZ, 'I' ) WANTZ = INITZ .OR. LSAME( COMPZ, 'V' ) LQUERY = ( LWORK.EQ.-1 ) * IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN INFO = -1 ELSE IF( .NOT.LSAME( COMPZ, 'N' ) .AND. .NOT.WANTZ ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( ILO.LT.1 ) THEN INFO = -4 ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) 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( ( WANTQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN INFO = -11 ELSE IF( ( WANTZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN INFO = -13 ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN INFO = -15 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGGHD3', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Initialize Q and Z if desired. * IF( INITQ ) $ CALL DLASET( 'All', N, N, ZERO, ONE, Q, LDQ ) IF( INITZ ) $ CALL DLASET( 'All', N, N, ZERO, ONE, Z, LDZ ) * * Zero out lower triangle of B. * IF( N.GT.1 ) $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, B(2, 1), LDB ) * * Quick return if possible * NH = IHI - ILO + 1 IF( NH.LE.1 ) THEN WORK( 1 ) = ONE RETURN END IF * * Determine the blocksize. * NBMIN = ILAENV( 2, 'DGGHD3', ' ', N, ILO, IHI, -1 ) IF( NB.GT.1 .AND. NB.LT.NH ) THEN * * Determine when to use unblocked instead of blocked code. * NX = MAX( NB, ILAENV( 3, 'DGGHD3', ' ', N, ILO, IHI, -1 ) ) IF( NX.LT.NH ) THEN * * Determine if workspace is large enough for blocked code. * IF( LWORK.LT.LWKOPT ) THEN * * Not enough workspace to use optimal NB: determine the * minimum value of NB, and reduce NB or force use of * unblocked code. * NBMIN = MAX( 2, ILAENV( 2, 'DGGHD3', ' ', N, ILO, IHI, $ -1 ) ) IF( LWORK.GE.6*N*NBMIN ) THEN NB = LWORK / ( 6*N ) ELSE NB = 1 END IF END IF END IF END IF * IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN * * Use unblocked code below * JCOL = ILO * ELSE * * Use blocked code * KACC22 = ILAENV( 16, 'DGGHD3', ' ', N, ILO, IHI, -1 ) BLK22 = KACC22.EQ.2 DO JCOL = ILO, IHI-2, NB NNB = MIN( NB, IHI-JCOL-1 ) * * Initialize small orthogonal factors that will hold the * accumulated Givens rotations in workspace. * N2NB denotes the number of 2*NNB-by-2*NNB factors * NBLST denotes the (possibly smaller) order of the last * factor. * N2NB = ( IHI-JCOL-1 ) / NNB - 1 NBLST = IHI - JCOL - N2NB*NNB CALL DLASET( 'All', NBLST, NBLST, ZERO, ONE, WORK, NBLST ) PW = NBLST * NBLST + 1 DO I = 1, N2NB CALL DLASET( 'All', 2*NNB, 2*NNB, ZERO, ONE, $ WORK( PW ), 2*NNB ) PW = PW + 4*NNB*NNB END DO * * Reduce columns JCOL:JCOL+NNB-1 of A to Hessenberg form. * DO J = JCOL, JCOL+NNB-1 * * Reduce Jth column of A. Store cosines and sines in Jth * column of A and B, respectively. * DO I = IHI, J+2, -1 TEMP = A( I-1, J ) CALL DLARTG( TEMP, A( I, J ), C, S, A( I-1, J ) ) A( I, J ) = C B( I, J ) = S END DO * * Accumulate Givens rotations into workspace array. * PPW = ( NBLST + 1 )*( NBLST - 2 ) - J + JCOL + 1 LEN = 2 + J - JCOL JROW = J + N2NB*NNB + 2 DO I = IHI, JROW, -1 C = A( I, J ) S = B( I, J ) DO JJ = PPW, PPW+LEN-1 TEMP = WORK( JJ + NBLST ) WORK( JJ + NBLST ) = C*TEMP - S*WORK( JJ ) WORK( JJ ) = S*TEMP + C*WORK( JJ ) END DO LEN = LEN + 1 PPW = PPW - NBLST - 1 END DO * PPWO = NBLST*NBLST + ( NNB+J-JCOL-1 )*2*NNB + NNB J0 = JROW - NNB DO JROW = J0, J+2, -NNB PPW = PPWO LEN = 2 + J - JCOL DO I = JROW+NNB-1, JROW, -1 C = A( I, J ) S = B( I, J ) DO JJ = PPW, PPW+LEN-1 TEMP = WORK( JJ + 2*NNB ) WORK( JJ + 2*NNB ) = C*TEMP - S*WORK( JJ ) WORK( JJ ) = S*TEMP + C*WORK( JJ ) END DO LEN = LEN + 1 PPW = PPW - 2*NNB - 1 END DO PPWO = PPWO + 4*NNB*NNB END DO * * TOP denotes the number of top rows in A and B that will * not be updated during the next steps. * IF( JCOL.LE.2 ) THEN TOP = 0 ELSE TOP = JCOL END IF * * Propagate transformations through B and replace stored * left sines/cosines by right sines/cosines. * DO JJ = N, J+1, -1 * * Update JJth column of B. * DO I = MIN( JJ+1, IHI ), J+2, -1 C = A( I, J ) S = B( I, J ) TEMP = B( I, JJ ) B( I, JJ ) = C*TEMP - S*B( I-1, JJ ) B( I-1, JJ ) = S*TEMP + C*B( I-1, JJ ) END DO * * Annihilate B( JJ+1, JJ ). * IF( JJ.LT.IHI ) THEN TEMP = B( JJ+1, JJ+1 ) CALL DLARTG( TEMP, B( JJ+1, JJ ), C, S, $ B( JJ+1, JJ+1 ) ) B( JJ+1, JJ ) = ZERO CALL DROT( JJ-TOP, B( TOP+1, JJ+1 ), 1, $ B( TOP+1, JJ ), 1, C, S ) A( JJ+1, J ) = C B( JJ+1, J ) = -S END IF END DO * * Update A by transformations from right. * Explicit loop unrolling provides better performance * compared to DLASR. * CALL DLASR( 'Right', 'Variable', 'Backward', IHI-TOP, * $ IHI-J, A( J+2, J ), B( J+2, J ), * $ A( TOP+1, J+1 ), LDA ) * JJ = MOD( IHI-J-1, 3 ) DO I = IHI-J-3, JJ+1, -3 C = A( J+1+I, J ) S = -B( J+1+I, J ) C1 = A( J+2+I, J ) S1 = -B( J+2+I, J ) C2 = A( J+3+I, J ) S2 = -B( J+3+I, J ) * DO K = TOP+1, IHI TEMP = A( K, J+I ) TEMP1 = A( K, J+I+1 ) TEMP2 = A( K, J+I+2 ) TEMP3 = A( K, J+I+3 ) A( K, J+I+3 ) = C2*TEMP3 + S2*TEMP2 TEMP2 = -S2*TEMP3 + C2*TEMP2 A( K, J+I+2 ) = C1*TEMP2 + S1*TEMP1 TEMP1 = -S1*TEMP2 + C1*TEMP1 A( K, J+I+1 ) = C*TEMP1 + S*TEMP A( K, J+I ) = -S*TEMP1 + C*TEMP END DO END DO * IF( JJ.GT.0 ) THEN DO I = JJ, 1, -1 CALL DROT( IHI-TOP, A( TOP+1, J+I+1 ), 1, $ A( TOP+1, J+I ), 1, A( J+1+I, J ), $ -B( J+1+I, J ) ) END DO END IF * * Update (J+1)th column of A by transformations from left. * IF ( J .LT. JCOL + NNB - 1 ) THEN LEN = 1 + J - JCOL * * Multiply with the trailing accumulated orthogonal * matrix, which takes the form * * [ U11 U12 ] * U = [ ], * [ U21 U22 ] * * where U21 is a LEN-by-LEN matrix and U12 is lower * triangular. * JROW = IHI - NBLST + 1 CALL DGEMV( 'Transpose', NBLST, LEN, ONE, WORK, $ NBLST, A( JROW, J+1 ), 1, ZERO, $ WORK( PW ), 1 ) PPW = PW + LEN DO I = JROW, JROW+NBLST-LEN-1 WORK( PPW ) = A( I, J+1 ) PPW = PPW + 1 END DO CALL DTRMV( 'Lower', 'Transpose', 'Non-unit', $ NBLST-LEN, WORK( LEN*NBLST + 1 ), NBLST, $ WORK( PW+LEN ), 1 ) CALL DGEMV( 'Transpose', LEN, NBLST-LEN, ONE, $ WORK( (LEN+1)*NBLST - LEN + 1 ), NBLST, $ A( JROW+NBLST-LEN, J+1 ), 1, ONE, $ WORK( PW+LEN ), 1 ) PPW = PW DO I = JROW, JROW+NBLST-1 A( I, J+1 ) = WORK( PPW ) PPW = PPW + 1 END DO * * Multiply with the other accumulated orthogonal * matrices, which take the form * * [ U11 U12 0 ] * [ ] * U = [ U21 U22 0 ], * [ ] * [ 0 0 I ] * * where I denotes the (NNB-LEN)-by-(NNB-LEN) identity * matrix, U21 is a LEN-by-LEN upper triangular matrix * and U12 is an NNB-by-NNB lower triangular matrix. * PPWO = 1 + NBLST*NBLST J0 = JROW - NNB DO JROW = J0, JCOL+1, -NNB PPW = PW + LEN DO I = JROW, JROW+NNB-1 WORK( PPW ) = A( I, J+1 ) PPW = PPW + 1 END DO PPW = PW DO I = JROW+NNB, JROW+NNB+LEN-1 WORK( PPW ) = A( I, J+1 ) PPW = PPW + 1 END DO CALL DTRMV( 'Upper', 'Transpose', 'Non-unit', LEN, $ WORK( PPWO + NNB ), 2*NNB, WORK( PW ), $ 1 ) CALL DTRMV( 'Lower', 'Transpose', 'Non-unit', NNB, $ WORK( PPWO + 2*LEN*NNB ), $ 2*NNB, WORK( PW + LEN ), 1 ) CALL DGEMV( 'Transpose', NNB, LEN, ONE, $ WORK( PPWO ), 2*NNB, A( JROW, J+1 ), 1, $ ONE, WORK( PW ), 1 ) CALL DGEMV( 'Transpose', LEN, NNB, ONE, $ WORK( PPWO + 2*LEN*NNB + NNB ), 2*NNB, $ A( JROW+NNB, J+1 ), 1, ONE, $ WORK( PW+LEN ), 1 ) PPW = PW DO I = JROW, JROW+LEN+NNB-1 A( I, J+1 ) = WORK( PPW ) PPW = PPW + 1 END DO PPWO = PPWO + 4*NNB*NNB END DO END IF END DO * * Apply accumulated orthogonal matrices to A. * COLA = N - JCOL - NNB + 1 J = IHI - NBLST + 1 CALL DGEMM( 'Transpose', 'No Transpose', NBLST, $ COLA, NBLST, ONE, WORK, NBLST, $ A( J, JCOL+NNB ), LDA, ZERO, WORK( PW ), $ NBLST ) CALL DLACPY( 'All', NBLST, COLA, WORK( PW ), NBLST, $ A( J, JCOL+NNB ), LDA ) PPWO = NBLST*NBLST + 1 J0 = J - NNB DO J = J0, JCOL+1, -NNB IF ( BLK22 ) THEN * * Exploit the structure of * * [ U11 U12 ] * U = [ ] * [ U21 U22 ], * * where all blocks are NNB-by-NNB, U21 is upper * triangular and U12 is lower triangular. * CALL DORM22( 'Left', 'Transpose', 2*NNB, COLA, NNB, $ NNB, WORK( PPWO ), 2*NNB, $ A( J, JCOL+NNB ), LDA, WORK( PW ), $ LWORK-PW+1, IERR ) ELSE * * Ignore the structure of U. * CALL DGEMM( 'Transpose', 'No Transpose', 2*NNB, $ COLA, 2*NNB, ONE, WORK( PPWO ), 2*NNB, $ A( J, JCOL+NNB ), LDA, ZERO, WORK( PW ), $ 2*NNB ) CALL DLACPY( 'All', 2*NNB, COLA, WORK( PW ), 2*NNB, $ A( J, JCOL+NNB ), LDA ) END IF PPWO = PPWO + 4*NNB*NNB END DO * * Apply accumulated orthogonal matrices to Q. * IF( WANTQ ) THEN J = IHI - NBLST + 1 IF ( INITQ ) THEN TOPQ = MAX( 2, J - JCOL + 1 ) NH = IHI - TOPQ + 1 ELSE TOPQ = 1 NH = N END IF CALL DGEMM( 'No Transpose', 'No Transpose', NH, $ NBLST, NBLST, ONE, Q( TOPQ, J ), LDQ, $ WORK, NBLST, ZERO, WORK( PW ), NH ) CALL DLACPY( 'All', NH, NBLST, WORK( PW ), NH, $ Q( TOPQ, J ), LDQ ) PPWO = NBLST*NBLST + 1 J0 = J - NNB DO J = J0, JCOL+1, -NNB IF ( INITQ ) THEN TOPQ = MAX( 2, J - JCOL + 1 ) NH = IHI - TOPQ + 1 END IF IF ( BLK22 ) THEN * * Exploit the structure of U. * CALL DORM22( 'Right', 'No Transpose', NH, 2*NNB, $ NNB, NNB, WORK( PPWO ), 2*NNB, $ Q( TOPQ, J ), LDQ, WORK( PW ), $ LWORK-PW+1, IERR ) ELSE * * Ignore the structure of U. * CALL DGEMM( 'No Transpose', 'No Transpose', NH, $ 2*NNB, 2*NNB, ONE, Q( TOPQ, J ), LDQ, $ WORK( PPWO ), 2*NNB, ZERO, WORK( PW ), $ NH ) CALL DLACPY( 'All', NH, 2*NNB, WORK( PW ), NH, $ Q( TOPQ, J ), LDQ ) END IF PPWO = PPWO + 4*NNB*NNB END DO END IF * * Accumulate right Givens rotations if required. * IF ( WANTZ .OR. TOP.GT.0 ) THEN * * Initialize small orthogonal factors that will hold the * accumulated Givens rotations in workspace. * CALL DLASET( 'All', NBLST, NBLST, ZERO, ONE, WORK, $ NBLST ) PW = NBLST * NBLST + 1 DO I = 1, N2NB CALL DLASET( 'All', 2*NNB, 2*NNB, ZERO, ONE, $ WORK( PW ), 2*NNB ) PW = PW + 4*NNB*NNB END DO * * Accumulate Givens rotations into workspace array. * DO J = JCOL, JCOL+NNB-1 PPW = ( NBLST + 1 )*( NBLST - 2 ) - J + JCOL + 1 LEN = 2 + J - JCOL JROW = J + N2NB*NNB + 2 DO I = IHI, JROW, -1 C = A( I, J ) A( I, J ) = ZERO S = B( I, J ) B( I, J ) = ZERO DO JJ = PPW, PPW+LEN-1 TEMP = WORK( JJ + NBLST ) WORK( JJ + NBLST ) = C*TEMP - S*WORK( JJ ) WORK( JJ ) = S*TEMP + C*WORK( JJ ) END DO LEN = LEN + 1 PPW = PPW - NBLST - 1 END DO * PPWO = NBLST*NBLST + ( NNB+J-JCOL-1 )*2*NNB + NNB J0 = JROW - NNB DO JROW = J0, J+2, -NNB PPW = PPWO LEN = 2 + J - JCOL DO I = JROW+NNB-1, JROW, -1 C = A( I, J ) A( I, J ) = ZERO S = B( I, J ) B( I, J ) = ZERO DO JJ = PPW, PPW+LEN-1 TEMP = WORK( JJ + 2*NNB ) WORK( JJ + 2*NNB ) = C*TEMP - S*WORK( JJ ) WORK( JJ ) = S*TEMP + C*WORK( JJ ) END DO LEN = LEN + 1 PPW = PPW - 2*NNB - 1 END DO PPWO = PPWO + 4*NNB*NNB END DO END DO ELSE * CALL DLASET( 'Lower', IHI - JCOL - 1, NNB, ZERO, ZERO, $ A( JCOL + 2, JCOL ), LDA ) CALL DLASET( 'Lower', IHI - JCOL - 1, NNB, ZERO, ZERO, $ B( JCOL + 2, JCOL ), LDB ) END IF * * Apply accumulated orthogonal matrices to A and B. * IF ( TOP.GT.0 ) THEN J = IHI - NBLST + 1 CALL DGEMM( 'No Transpose', 'No Transpose', TOP, $ NBLST, NBLST, ONE, A( 1, J ), LDA, $ WORK, NBLST, ZERO, WORK( PW ), TOP ) CALL DLACPY( 'All', TOP, NBLST, WORK( PW ), TOP, $ A( 1, J ), LDA ) PPWO = NBLST*NBLST + 1 J0 = J - NNB DO J = J0, JCOL+1, -NNB IF ( BLK22 ) THEN * * Exploit the structure of U. * CALL DORM22( 'Right', 'No Transpose', TOP, 2*NNB, $ NNB, NNB, WORK( PPWO ), 2*NNB, $ A( 1, J ), LDA, WORK( PW ), $ LWORK-PW+1, IERR ) ELSE * * Ignore the structure of U. * CALL DGEMM( 'No Transpose', 'No Transpose', TOP, $ 2*NNB, 2*NNB, ONE, A( 1, J ), LDA, $ WORK( PPWO ), 2*NNB, ZERO, $ WORK( PW ), TOP ) CALL DLACPY( 'All', TOP, 2*NNB, WORK( PW ), TOP, $ A( 1, J ), LDA ) END IF PPWO = PPWO + 4*NNB*NNB END DO * J = IHI - NBLST + 1 CALL DGEMM( 'No Transpose', 'No Transpose', TOP, $ NBLST, NBLST, ONE, B( 1, J ), LDB, $ WORK, NBLST, ZERO, WORK( PW ), TOP ) CALL DLACPY( 'All', TOP, NBLST, WORK( PW ), TOP, $ B( 1, J ), LDB ) PPWO = NBLST*NBLST + 1 J0 = J - NNB DO J = J0, JCOL+1, -NNB IF ( BLK22 ) THEN * * Exploit the structure of U. * CALL DORM22( 'Right', 'No Transpose', TOP, 2*NNB, $ NNB, NNB, WORK( PPWO ), 2*NNB, $ B( 1, J ), LDB, WORK( PW ), $ LWORK-PW+1, IERR ) ELSE * * Ignore the structure of U. * CALL DGEMM( 'No Transpose', 'No Transpose', TOP, $ 2*NNB, 2*NNB, ONE, B( 1, J ), LDB, $ WORK( PPWO ), 2*NNB, ZERO, $ WORK( PW ), TOP ) CALL DLACPY( 'All', TOP, 2*NNB, WORK( PW ), TOP, $ B( 1, J ), LDB ) END IF PPWO = PPWO + 4*NNB*NNB END DO END IF * * Apply accumulated orthogonal matrices to Z. * IF( WANTZ ) THEN J = IHI - NBLST + 1 IF ( INITQ ) THEN TOPQ = MAX( 2, J - JCOL + 1 ) NH = IHI - TOPQ + 1 ELSE TOPQ = 1 NH = N END IF CALL DGEMM( 'No Transpose', 'No Transpose', NH, $ NBLST, NBLST, ONE, Z( TOPQ, J ), LDZ, $ WORK, NBLST, ZERO, WORK( PW ), NH ) CALL DLACPY( 'All', NH, NBLST, WORK( PW ), NH, $ Z( TOPQ, J ), LDZ ) PPWO = NBLST*NBLST + 1 J0 = J - NNB DO J = J0, JCOL+1, -NNB IF ( INITQ ) THEN TOPQ = MAX( 2, J - JCOL + 1 ) NH = IHI - TOPQ + 1 END IF IF ( BLK22 ) THEN * * Exploit the structure of U. * CALL DORM22( 'Right', 'No Transpose', NH, 2*NNB, $ NNB, NNB, WORK( PPWO ), 2*NNB, $ Z( TOPQ, J ), LDZ, WORK( PW ), $ LWORK-PW+1, IERR ) ELSE * * Ignore the structure of U. * CALL DGEMM( 'No Transpose', 'No Transpose', NH, $ 2*NNB, 2*NNB, ONE, Z( TOPQ, J ), LDZ, $ WORK( PPWO ), 2*NNB, ZERO, WORK( PW ), $ NH ) CALL DLACPY( 'All', NH, 2*NNB, WORK( PW ), NH, $ Z( TOPQ, J ), LDZ ) END IF PPWO = PPWO + 4*NNB*NNB END DO END IF END DO END IF * * Use unblocked code to reduce the rest of the matrix * Avoid re-initialization of modified Q and Z. * COMPQ2 = COMPQ COMPZ2 = COMPZ IF ( JCOL.NE.ILO ) THEN IF ( WANTQ ) $ COMPQ2 = 'V' IF ( WANTZ ) $ COMPZ2 = 'V' END IF * IF ( JCOL.LT.IHI ) $ CALL DGGHRD( COMPQ2, COMPZ2, N, JCOL, IHI, A, LDA, B, LDB, Q, $ LDQ, Z, LDZ, IERR ) WORK( 1 ) = DBLE( LWKOPT ) * RETURN * * End of DGGHD3 * END
apache-2.0
nvarini/espresso_iohpc
West/Tools/do_setup.f90
1
3536
! ! Copyright (C) 2015 M. Govoni ! 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 . ! ! Contributors to this file: ! Marco Govoni ! !----------------------------------------------------------------------- SUBROUTINE do_setup !----------------------------------------------------------------------- ! USE pwcom, ONLY : npw,nbnd,nkstot,nspin,nelec,nelup,neldw,et,wk,wg,lspinorb,domag,lsda, & isk,nks,two_fermi_energies USE fixed_occ, ONLY : tfixed_occ,f_inp USE kinds, ONLY : DP USE mp, ONLY : mp_sum USE mp_global, ONLY : intra_bgrp_comm USE io_global, ONLY : stdout USE lsda_mod, ONLY : current_spin,lsda USE constants, ONLY : rytoev USE control_flags, ONLY : gamma_only USE noncollin_module, ONLY : noncolin,npol USE cell_base, ONLY : omega,celldm,at USE fft_base, ONLY : dfftp,dffts USE gvecs, ONLY : ngms_g, ngms USE gvect, ONLY : ngm_g, ngm USE gvecw, ONLY : ecutwfc USE io_push ! IMPLICIT NONE ! INTEGER :: auxi,ib REAL(DP) :: alat INTEGER :: iks,spin ! CALL start_clock('do_setup') ! ! INIT PW ! CALL init_pw_arrays(nbnd) CALL set_iks_l2g() ! ! IF ( lsda ) THEN IF ( INT( nelup ) == 0 .AND. INT( neldw ) == 0 ) THEN !IF ( .NOT. two_fermi_energies ) THEN DO iks = 1, nks spin = isk(iks) ! SELECT CASE(spin) CASE(1) nelup = SUM( f_inp(:,1) ) CASE(2) neldw = SUM( f_inp(:,2) ) END SELECT ! ENDDO ENDIF IF ( INT( nelup ) == 0 .AND. INT( neldw ) == 0 ) THEN CALL errore( 'do_setup','nelup = 0 and neldw = 0 ',1) ENDIF ENDIF ! ! SYSTEM OVERVIEW ! CALL io_push_title('System Overview') CALL io_push_value('gamma_only',gamma_only,20) CALL io_push_value('ecutwfc [Ry]',ecutwfc,20) CALL io_push_es0('omega [au^3]',omega,20) auxi = npw CALL mp_sum(auxi,intra_bgrp_comm) CALL io_push_value('glob. #G',auxi,20) CALL io_push_value('nbnd',nbnd,20) CALL io_push_value('nkstot',nkstot,20) CALL io_push_value('nspin',nspin,20) CALL io_push_value('nelec',nelec,20) IF(nspin == 2) THEN CALL io_push_value('nelup',nelup,20) CALL io_push_value('neldw',neldw,20) ENDIF CALL io_push_value('npol',npol,20) CALL io_push_value('lsda',lsda,20) CALL io_push_value('noncolin',noncolin,20) CALL io_push_value('lspinorb',lspinorb,20) CALL io_push_value('domag',domag,20) CALL io_push_bar ! alat = celldm(1) ! WRITE( stdout, '(/5x,"sFFT G-space: ",i8," G-vectors", 5x, & & "R-space: (",i4,",",i4,",",i4,")")') & & ngms_g, dffts%nr1, dffts%nr2, dffts%nr3 WRITE( stdout, '( 5x,"dFFT G-space: ",i8," G-vectors", 5x, & & "R-space: (",i4,",",i4,",",i4,")")') & & ngm_g, dfftp%nr1, dfftp%nr2, dfftp%nr3 WRITE( stdout, '(/5x,"Cell [a.u.] = ",3f14.6)') alat*at(1,1:3) WRITE( stdout, '( 5x," = ",3f14.6)') alat*at(2,1:3) WRITE( stdout, '( 5x," = ",3f14.6)') alat*at(3,1:3) WRITE( stdout, '( 5x," ")') ! CALL stop_clock('do_setup') ! END SUBROUTINE
gpl-2.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/slahr2.f
24
10173
*> \brief \b SLAHR2 reduces the specified number of first columns of a general rectangular matrix A so that elements below the specified subdiagonal are zero, and returns auxiliary matrices which are needed to apply the transformation to the unreduced part of A. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SLAHR2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slahr2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slahr2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slahr2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SLAHR2( N, K, NB, A, LDA, TAU, T, LDT, Y, LDY ) * * .. Scalar Arguments .. * INTEGER K, LDA, LDT, LDY, N, NB * .. * .. Array Arguments .. * REAL A( LDA, * ), T( LDT, NB ), TAU( NB ), * $ Y( LDY, NB ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SLAHR2 reduces the first NB columns of A real general n-BY-(n-k+1) *> matrix A so that elements below the k-th subdiagonal are zero. The *> reduction is performed by an orthogonal similarity transformation *> Q**T * A * Q. The routine returns the matrices V and T which determine *> Q as a block reflector I - V*T*V**T, and also the matrix Y = A * V * T. *> *> This is an auxiliary routine called by SGEHRD. *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. *> \endverbatim *> *> \param[in] K *> \verbatim *> K is INTEGER *> The offset for the reduction. Elements below the k-th *> subdiagonal in the first NB columns are reduced to zero. *> K < N. *> \endverbatim *> *> \param[in] NB *> \verbatim *> NB is INTEGER *> The number of columns to be reduced. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is REAL array, dimension (LDA,N-K+1) *> On entry, the n-by-(n-k+1) general matrix A. *> On exit, the elements on and above the k-th subdiagonal in *> the first NB columns are overwritten with the corresponding *> elements of the reduced matrix; the elements below the k-th *> subdiagonal, with the array TAU, represent the matrix Q as a *> product of elementary reflectors. The other columns of A are *> unchanged. 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] TAU *> \verbatim *> TAU is REAL array, dimension (NB) *> The scalar factors of the elementary reflectors. See Further *> Details. *> \endverbatim *> *> \param[out] T *> \verbatim *> T is REAL array, dimension (LDT,NB) *> The upper triangular matrix T. *> \endverbatim *> *> \param[in] LDT *> \verbatim *> LDT is INTEGER *> The leading dimension of the array T. LDT >= NB. *> \endverbatim *> *> \param[out] Y *> \verbatim *> Y is REAL array, dimension (LDY,NB) *> The n-by-nb matrix Y. *> \endverbatim *> *> \param[in] LDY *> \verbatim *> LDY is INTEGER *> The leading dimension of the array Y. LDY >= N. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup realOTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix Q is represented as a product of nb elementary reflectors *> *> Q = H(1) H(2) . . . H(nb). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**T *> *> where tau is a real scalar, and v is a real vector with *> v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in *> A(i+k+1:n,i), and tau in TAU(i). *> *> The elements of the vectors v together form the (n-k+1)-by-nb matrix *> V which is needed, with T and Y, to apply the transformation to the *> unreduced part of the matrix, using an update of the form: *> A := (I - V*T*V**T) * (A - Y*V**T). *> *> The contents of A on exit are illustrated by the following example *> with n = 7, k = 3 and nb = 2: *> *> ( a a a a a ) *> ( a a a a a ) *> ( a a a a a ) *> ( h h a a a ) *> ( v1 h a a a ) *> ( v1 v2 a a a ) *> ( v1 v2 a a a ) *> *> where a denotes an element of the original matrix A, h denotes a *> modified element of the upper Hessenberg matrix H, and vi denotes an *> element of the vector defining H(i). *> *> This subroutine is a slight modification of LAPACK-3.0's DLAHRD *> incorporating improvements proposed by Quintana-Orti and Van de *> Gejin. Note that the entries of A(1:K,2:NB) differ from those *> returned by the original LAPACK-3.0's DLAHRD routine. (This *> subroutine is not backward compatible with LAPACK-3.0's DLAHRD.) *> \endverbatim * *> \par References: * ================ *> *> Gregorio Quintana-Orti and Robert van de Geijn, "Improving the *> performance of reduction to Hessenberg form," ACM Transactions on *> Mathematical Software, 32(2):180-194, June 2006. *> * ===================================================================== SUBROUTINE SLAHR2( N, K, NB, A, LDA, TAU, T, LDT, Y, LDY ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER K, LDA, LDT, LDY, N, NB * .. * .. Array Arguments .. REAL A( LDA, * ), T( LDT, NB ), TAU( NB ), $ Y( LDY, NB ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, $ ONE = 1.0E+0 ) * .. * .. Local Scalars .. INTEGER I REAL EI * .. * .. External Subroutines .. EXTERNAL SAXPY, SCOPY, SGEMM, SGEMV, SLACPY, $ SLARFG, SSCAL, STRMM, STRMV * .. * .. Intrinsic Functions .. INTRINSIC MIN * .. * .. Executable Statements .. * * Quick return if possible * IF( N.LE.1 ) $ RETURN * DO 10 I = 1, NB IF( I.GT.1 ) THEN * * Update A(K+1:N,I) * * Update I-th column of A - Y * V**T * CALL SGEMV( 'NO TRANSPOSE', N-K, I-1, -ONE, Y(K+1,1), LDY, $ A( K+I-1, 1 ), LDA, ONE, A( K+1, I ), 1 ) * * Apply I - V * T**T * V**T to this column (call it b) from the * left, using the last column of T as workspace * * Let V = ( V1 ) and b = ( b1 ) (first I-1 rows) * ( V2 ) ( b2 ) * * where V1 is unit lower triangular * * w := V1**T * b1 * CALL SCOPY( I-1, A( K+1, I ), 1, T( 1, NB ), 1 ) CALL STRMV( 'Lower', 'Transpose', 'UNIT', $ I-1, A( K+1, 1 ), $ LDA, T( 1, NB ), 1 ) * * w := w + V2**T * b2 * CALL SGEMV( 'Transpose', N-K-I+1, I-1, $ ONE, A( K+I, 1 ), $ LDA, A( K+I, I ), 1, ONE, T( 1, NB ), 1 ) * * w := T**T * w * CALL STRMV( 'Upper', 'Transpose', 'NON-UNIT', $ I-1, T, LDT, $ T( 1, NB ), 1 ) * * b2 := b2 - V2*w * CALL SGEMV( 'NO TRANSPOSE', N-K-I+1, I-1, -ONE, $ A( K+I, 1 ), $ LDA, T( 1, NB ), 1, ONE, A( K+I, I ), 1 ) * * b1 := b1 - V1*w * CALL STRMV( 'Lower', 'NO TRANSPOSE', $ 'UNIT', I-1, $ A( K+1, 1 ), LDA, T( 1, NB ), 1 ) CALL SAXPY( I-1, -ONE, T( 1, NB ), 1, A( K+1, I ), 1 ) * A( K+I-1, I-1 ) = EI END IF * * Generate the elementary reflector H(I) to annihilate * A(K+I+1:N,I) * CALL SLARFG( N-K-I+1, A( K+I, I ), A( MIN( K+I+1, N ), I ), 1, $ TAU( I ) ) EI = A( K+I, I ) A( K+I, I ) = ONE * * Compute Y(K+1:N,I) * CALL SGEMV( 'NO TRANSPOSE', N-K, N-K-I+1, $ ONE, A( K+1, I+1 ), $ LDA, A( K+I, I ), 1, ZERO, Y( K+1, I ), 1 ) CALL SGEMV( 'Transpose', N-K-I+1, I-1, $ ONE, A( K+I, 1 ), LDA, $ A( K+I, I ), 1, ZERO, T( 1, I ), 1 ) CALL SGEMV( 'NO TRANSPOSE', N-K, I-1, -ONE, $ Y( K+1, 1 ), LDY, $ T( 1, I ), 1, ONE, Y( K+1, I ), 1 ) CALL SSCAL( N-K, TAU( I ), Y( K+1, I ), 1 ) * * Compute T(1:I,I) * CALL SSCAL( I-1, -TAU( I ), T( 1, I ), 1 ) CALL STRMV( 'Upper', 'No Transpose', 'NON-UNIT', $ I-1, T, LDT, $ T( 1, I ), 1 ) T( I, I ) = TAU( I ) * 10 CONTINUE A( K+NB, NB ) = EI * * Compute Y(1:K,1:NB) * CALL SLACPY( 'ALL', K, NB, A( 1, 2 ), LDA, Y, LDY ) CALL STRMM( 'RIGHT', 'Lower', 'NO TRANSPOSE', $ 'UNIT', K, NB, $ ONE, A( K+1, 1 ), LDA, Y, LDY ) IF( N.GT.K+NB ) $ CALL SGEMM( 'NO TRANSPOSE', 'NO TRANSPOSE', K, $ NB, N-K-NB, ONE, $ A( 1, 2+NB ), LDA, A( K+1+NB, 1 ), LDA, ONE, Y, $ LDY ) CALL STRMM( 'RIGHT', 'Upper', 'NO TRANSPOSE', $ 'NON-UNIT', K, NB, $ ONE, T, LDT, Y, LDY ) * RETURN * * End of SLAHR2 * END
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/slaswp.f
24
5041
*> \brief \b SLASWP performs a series of row interchanges on a general rectangular matrix. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SLASWP + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaswp.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaswp.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaswp.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SLASWP( N, A, LDA, K1, K2, IPIV, INCX ) * * .. Scalar Arguments .. * INTEGER INCX, K1, K2, LDA, N * .. * .. Array Arguments .. * INTEGER IPIV( * ) * REAL A( LDA, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SLASWP performs a series of row interchanges on the matrix A. *> One row interchange is initiated for each of rows K1 through K2 of A. *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is REAL array, dimension (LDA,N) *> On entry, the matrix of column dimension N to which the row *> interchanges will be applied. *> On exit, the permuted matrix. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. *> \endverbatim *> *> \param[in] K1 *> \verbatim *> K1 is INTEGER *> The first element of IPIV for which a row interchange will *> be done. *> \endverbatim *> *> \param[in] K2 *> \verbatim *> K2 is INTEGER *> The last element of IPIV for which a row interchange will *> be done. *> \endverbatim *> *> \param[in] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (K2*abs(INCX)) *> The vector of pivot indices. Only the elements in positions *> K1 through K2 of IPIV are accessed. *> IPIV(K) = L implies rows K and L are to be interchanged. *> \endverbatim *> *> \param[in] INCX *> \verbatim *> INCX is INTEGER *> The increment between successive values of IPIV. If IPIV *> is negative, the pivots are applied in reverse order. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup realOTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> Modified by *> R. C. Whaley, Computer Science Dept., Univ. of Tenn., Knoxville, USA *> \endverbatim *> * ===================================================================== SUBROUTINE SLASWP( N, A, LDA, K1, K2, IPIV, INCX ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INCX, K1, K2, LDA, N * .. * .. Array Arguments .. INTEGER IPIV( * ) REAL A( LDA, * ) * .. * * ===================================================================== * * .. Local Scalars .. INTEGER I, I1, I2, INC, IP, IX, IX0, J, K, N32 REAL TEMP * .. * .. Executable Statements .. * * Interchange row I with row IPIV(I) for each of rows K1 through K2. * IF( INCX.GT.0 ) THEN IX0 = K1 I1 = K1 I2 = K2 INC = 1 ELSE IF( INCX.LT.0 ) THEN IX0 = 1 + ( 1-K2 )*INCX I1 = K2 I2 = K1 INC = -1 ELSE RETURN END IF * N32 = ( N / 32 )*32 IF( N32.NE.0 ) THEN DO 30 J = 1, N32, 32 IX = IX0 DO 20 I = I1, I2, INC IP = IPIV( IX ) IF( IP.NE.I ) THEN DO 10 K = J, J + 31 TEMP = A( I, K ) A( I, K ) = A( IP, K ) A( IP, K ) = TEMP 10 CONTINUE END IF IX = IX + INCX 20 CONTINUE 30 CONTINUE END IF IF( N32.NE.N ) THEN N32 = N32 + 1 IX = IX0 DO 50 I = I1, I2, INC IP = IPIV( IX ) IF( IP.NE.I ) THEN DO 40 K = N32, N TEMP = A( I, K ) A( I, K ) = A( IP, K ) A( IP, K ) = TEMP 40 CONTINUE END IF IX = IX + INCX 50 CONTINUE END IF * RETURN * * End of SLASWP * END
bsd-3-clause
nvarini/espresso_iohpc
PW/src/multable.f90
21
1521
! ! Copyright (C) 2001-2010 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 multable (nsym, s, table) !----------------------------------------------------------------------- ! ! Checks that {S} is a group and calculates multiplication table ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: nsym, s(3,3,nsym) ! nsym = number of symmetry operations ! s = rotation matrix (in crystal axis, represented by integers) INTEGER, INTENT(OUT) :: table (48, 48) ! multiplication table: S(n)*S(m) = S (table(n,m) ) ! INTEGER :: isym, jsym, ksym, ss (3, 3) LOGICAL :: found, smn ! DO isym = 1, nsym DO jsym = 1, nsym ! ss = MATMUL (s(:,:,jsym),s(:,:,isym)) ! ! here we check that the input matrices really form a group ! and we set the multiplication table ! found = .false. DO ksym = 1, nsym smn = ALL ( s(:,:,ksym) == ss(:,:) ) IF (smn) THEN IF (found) CALL errore ('multable', 'Not a group', 1) found = .true. table (jsym, isym) = ksym END IF END DO IF ( .NOT.found) CALL errore ('multable', ' Not a group', 2) END DO END DO RETURN ! END SUBROUTINE multable
gpl-2.0
aarchiba/scipy
scipy/integrate/quadpack/dqagp.f
32
10517
subroutine dqagp(f,a,b,npts2,points,epsabs,epsrel,result,abserr, * neval,ier,leniw,lenw,last,iwork,work) c***begin prologue dqagp c***date written 800101 (yymmdd) c***revision date 830518 (yymmdd) c***category no. h2a2a1 c***keywords automatic integrator, general-purpose, c singularities at user specified points, c extrapolation, globally adaptive c***author piessens,robert,appl. math. & progr. div - k.u.leuven c de doncker,elise,appl. math. & progr. div. - k.u.leuven c***purpose the routine calculates an approximation result to a given c definite integral i = integral of f over (a,b), c hopefully satisfying following claim for accuracy c break points of the integration interval, where local c difficulties of the integrand may occur (e.g. c singularities, discontinuities), are provided by the user. c***description c c computation of a definite integral c standard fortran subroutine c double precision version c c parameters c on entry c f - double precision c function subprogram defining the integrand c function f(x). the actual name for f needs to be c declared e x t e r n a l in the driver program. c c a - double precision c lower limit of integration c c b - double precision c upper limit of integration c c npts2 - integer c number equal to two more than the number of c user-supplied break points within the integration c range, npts.ge.2. c if npts2.lt.2, the routine will end with ier = 6. c c points - double precision c vector of dimension npts2, the first (npts2-2) c elements of which are the user provided break c points. if these points do not constitute an c ascending sequence there will be an automatic c sorting. c c epsabs - double precision c absolute accuracy requested c epsrel - double precision c relative accuracy requested c if epsabs.le.0 c and epsrel.lt.max(50*rel.mach.acc.,0.5d-28), c the routine will end with ier = 6. c c on return c result - double precision c approximation to the integral c c abserr - double precision c estimate of the modulus of the absolute error, c which should equal or exceed abs(i-result) c c neval - integer c number of integrand evaluations c c ier - integer c ier = 0 normal and reliable termination of the c routine. it is assumed that the requested c accuracy has been achieved. c ier.gt.0 abnormal termination of the routine. c the estimates for integral and error are c less reliable. it is assumed that the c requested accuracy has not been achieved. c error messages c ier = 1 maximum number of subdivisions allowed c has been achieved. one can allow more c subdivisions by increasing the value of c limit (and taking the according dimension c adjustments into account). however, if c this yields no improvement it is advised c to analyze the integrand in order to c determine the integration difficulties. if c the position of a local difficulty can be c determined (i.e. singularity, c discontinuity within the interval), it c should be supplied to the routine as an c element of the vector points. if necessary c an appropriate special-purpose integrator c must be used, which is designed for c handling the type of difficulty involved. c = 2 the occurrence of roundoff error is c detected, which prevents the requested c tolerance from being achieved. c the error may be under-estimated. c = 3 extremely bad integrand behaviour occurs c at some points of the integration c interval. c = 4 the algorithm does not converge. c roundoff error is detected in the c extrapolation table. c it is presumed that the requested c tolerance cannot be achieved, and that c the returned result is the best which c can be obtained. c = 5 the integral is probably divergent, or c slowly convergent. it must be noted that c divergence can occur with any other value c of ier.gt.0. c = 6 the input is invalid because c npts2.lt.2 or c break points are specified outside c the integration range or c (epsabs.le.0 and c epsrel.lt.max(50*rel.mach.acc.,0.5d-28)) c result, abserr, neval, last are set to c zero. except when leniw or lenw or npts2 is c invalid, iwork(1), iwork(limit+1), c work(limit*2+1) and work(limit*3+1) c are set to zero. c work(1) is set to a and work(limit+1) c to b (where limit = (leniw-npts2)/2). c c dimensioning parameters c leniw - integer c dimensioning parameter for iwork c leniw determines limit = (leniw-npts2)/2, c which is the maximum number of subintervals in the c partition of the given integration interval (a,b), c leniw.ge.(3*npts2-2). c if leniw.lt.(3*npts2-2), the routine will end with c ier = 6. c c lenw - integer c dimensioning parameter for work c lenw must be at least leniw*2-npts2. c if lenw.lt.leniw*2-npts2, the routine will end c with ier = 6. c c last - integer c on return, last equals the number of subintervals c produced in the subdivision process, which c determines the number of significant elements c actually in the work arrays. c c work arrays c iwork - integer c vector of dimension at least leniw. on return, c the first k elements of which contain c pointers to the error estimates over the c subintervals, such that work(limit*3+iwork(1)),..., c work(limit*3+iwork(k)) form a decreasing c sequence, with k = last if last.le.(limit/2+2), and c k = limit+1-last otherwise c iwork(limit+1), ...,iwork(limit+last) contain the c subdivision levels of the subintervals, i.e. c if (aa,bb) is a subinterval of (p1,p2) c where p1 as well as p2 is a user-provided c break point or integration limit, then (aa,bb) has c level l if abs(bb-aa) = abs(p2-p1)*2**(-l), c iwork(limit*2+1), ..., iwork(limit*2+npts2) have c no significance for the user, c note that limit = (leniw-npts2)/2. c c work - double precision c vector of dimension at least lenw c on return c work(1), ..., work(last) contain the left c end points of the subintervals in the c partition of (a,b), c work(limit+1), ..., work(limit+last) contain c the right end points, c work(limit*2+1), ..., work(limit*2+last) contain c the integral approximations over the subintervals, c work(limit*3+1), ..., work(limit*3+last) c contain the corresponding error estimates, c work(limit*4+1), ..., work(limit*4+npts2) c contain the integration limits and the c break points sorted in an ascending sequence. c note that limit = (leniw-npts2)/2. c c***references (none) c***routines called dqagpe,xerror c***end prologue dqagp c double precision a,abserr,b,epsabs,epsrel,f,points,result,work integer ier,iwork,last,leniw,lenw,limit,lvl,l1,l2,l3,l4,neval, * npts2 c dimension iwork(leniw),points(npts2),work(lenw) c external f c c check validity of limit and lenw. c c***first executable statement dqagp ier = 6 neval = 0 last = 0 result = 0.0d+00 abserr = 0.0d+00 if(leniw.lt.(3*npts2-2).or.lenw.lt.(leniw*2-npts2).or.npts2.lt.2) * go to 10 c c prepare call for dqagpe. c limit = (leniw-npts2)/2 l1 = limit+1 l2 = limit+l1 l3 = limit+l2 l4 = limit+l3 c call dqagpe(f,a,b,npts2,points,epsabs,epsrel,limit,result,abserr, * neval,ier,work(1),work(l1),work(l2),work(l3),work(l4), * iwork(1),iwork(l1),iwork(l2),last) c c call error handler if necessary. c lvl = 0 10 if(ier.eq.6) lvl = 1 if(ier.ne.0) call xerror('abnormal return from dqagp',26,ier,lvl) return end
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/dgerfsx.f
28
27955
*> \brief \b DGERFSX * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGERFSX + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgerfsx.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgerfsx.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgerfsx.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGERFSX( TRANS, EQUED, N, NRHS, A, LDA, AF, LDAF, IPIV, * R, C, B, LDB, X, LDX, RCOND, BERR, N_ERR_BNDS, * ERR_BNDS_NORM, ERR_BNDS_COMP, NPARAMS, PARAMS, * WORK, IWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER TRANS, EQUED * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, * $ N_ERR_BNDS * DOUBLE PRECISION RCOND * .. * .. Array Arguments .. * INTEGER IPIV( * ), IWORK( * ) * DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ), * $ X( LDX , * ), WORK( * ) * DOUBLE PRECISION R( * ), C( * ), PARAMS( * ), BERR( * ), * $ ERR_BNDS_NORM( NRHS, * ), * $ ERR_BNDS_COMP( NRHS, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGERFSX improves the computed solution to a system of linear *> equations and provides error bounds and backward error estimates *> for the solution. In addition to normwise error bound, the code *> provides maximum componentwise error bound if possible. See *> comments for ERR_BNDS_NORM and ERR_BNDS_COMP for details of the *> error bounds. *> *> The original system of linear equations may have been equilibrated *> before calling this routine, as described by arguments EQUED, R *> and C below. In this case, the solution and error bounds returned *> are for the original unequilibrated system. *> \endverbatim * * Arguments: * ========== * *> \verbatim *> Some optional parameters are bundled in the PARAMS array. These *> settings determine how refinement is performed, but often the *> defaults are acceptable. If the defaults are acceptable, users *> can pass NPARAMS = 0 which prevents the source code from accessing *> the PARAMS argument. *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> Specifies the form of the system of equations: *> = 'N': A * X = B (No transpose) *> = 'T': A**T * X = B (Transpose) *> = 'C': A**H * X = B (Conjugate transpose = Transpose) *> \endverbatim *> *> \param[in] EQUED *> \verbatim *> EQUED is CHARACTER*1 *> Specifies the form of equilibration that was done to A *> before calling this routine. This is needed to compute *> the solution and error bounds correctly. *> = 'N': No equilibration *> = 'R': Row equilibration, i.e., A has been premultiplied by *> diag(R). *> = 'C': Column equilibration, i.e., A has been postmultiplied *> by diag(C). *> = 'B': Both row and column equilibration, i.e., A has been *> replaced by diag(R) * A * diag(C). *> The right hand side B has been changed accordingly. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrices B and X. NRHS >= 0. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> The original N-by-N matrix A. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in] AF *> \verbatim *> AF is DOUBLE PRECISION array, dimension (LDAF,N) *> The factors L and U from the factorization A = P*L*U *> as computed by DGETRF. *> \endverbatim *> *> \param[in] LDAF *> \verbatim *> LDAF is INTEGER *> The leading dimension of the array AF. LDAF >= max(1,N). *> \endverbatim *> *> \param[in] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> The pivot indices from DGETRF; for 1<=i<=N, row i of the *> matrix was interchanged with row IPIV(i). *> \endverbatim *> *> \param[in] R *> \verbatim *> R is DOUBLE PRECISION array, dimension (N) *> The row scale factors for A. If EQUED = 'R' or 'B', A is *> multiplied on the left by diag(R); if EQUED = 'N' or 'C', R *> is not accessed. *> If R is accessed, each element of R should be a power of the radix *> to ensure a reliable solution and error estimates. Scaling by *> powers of the radix does not cause rounding errors unless the *> result underflows or overflows. Rounding errors during scaling *> lead to refining with a matrix that is not equivalent to the *> input matrix, producing error estimates that may not be *> reliable. *> \endverbatim *> *> \param[in] C *> \verbatim *> C is DOUBLE PRECISION array, dimension (N) *> The column scale factors for A. If EQUED = 'C' or 'B', A is *> multiplied on the right by diag(C); if EQUED = 'N' or 'R', C *> is not accessed. *> If C is accessed, each element of C should be a power of the radix *> to ensure a reliable solution and error estimates. Scaling by *> powers of the radix does not cause rounding errors unless the *> result underflows or overflows. Rounding errors during scaling *> lead to refining with a matrix that is not equivalent to the *> input matrix, producing error estimates that may not be *> reliable. *> \endverbatim *> *> \param[in] B *> \verbatim *> B is DOUBLE PRECISION array, dimension (LDB,NRHS) *> The right hand side matrix B. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[in,out] X *> \verbatim *> X is DOUBLE PRECISION array, dimension (LDX,NRHS) *> On entry, the solution matrix X, as computed by DGETRS. *> On exit, the improved solution matrix X. *> \endverbatim *> *> \param[in] LDX *> \verbatim *> LDX is INTEGER *> The leading dimension of the array X. LDX >= max(1,N). *> \endverbatim *> *> \param[out] RCOND *> \verbatim *> RCOND is DOUBLE PRECISION *> Reciprocal scaled condition number. This is an estimate of the *> reciprocal Skeel condition number of the matrix A after *> equilibration (if done). If this is less than the machine *> precision (in particular, if it is zero), the matrix is singular *> to working precision. Note that the error may still be small even *> if this number is very small and the matrix appears ill- *> conditioned. *> \endverbatim *> *> \param[out] BERR *> \verbatim *> BERR is DOUBLE PRECISION array, dimension (NRHS) *> Componentwise relative backward error. This is the *> componentwise relative backward error of each solution vector X(j) *> (i.e., the smallest relative change in any element of A or B that *> makes X(j) an exact solution). *> \endverbatim *> *> \param[in] N_ERR_BNDS *> \verbatim *> N_ERR_BNDS is INTEGER *> Number of error bounds to return for each right hand side *> and each type (normwise or componentwise). See ERR_BNDS_NORM and *> ERR_BNDS_COMP below. *> \endverbatim *> *> \param[out] ERR_BNDS_NORM *> \verbatim *> ERR_BNDS_NORM is DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) *> For each right-hand side, this array contains information about *> various error bounds and condition numbers corresponding to the *> normwise relative error, which is defined as follows: *> *> Normwise relative error in the ith solution vector: *> max_j (abs(XTRUE(j,i) - X(j,i))) *> ------------------------------ *> max_j abs(X(j,i)) *> *> The array is indexed by the type of error information as described *> below. There currently are up to three pieces of information *> returned. *> *> The first index in ERR_BNDS_NORM(i,:) corresponds to the ith *> right-hand side. *> *> The second index in ERR_BNDS_NORM(:,err) contains the following *> three fields: *> err = 1 "Trust/don't trust" boolean. Trust the answer if the *> reciprocal condition number is less than the threshold *> sqrt(n) * dlamch('Epsilon'). *> *> err = 2 "Guaranteed" error bound: The estimated forward error, *> almost certainly within a factor of 10 of the true error *> so long as the next entry is greater than the threshold *> sqrt(n) * dlamch('Epsilon'). This error bound should only *> be trusted if the previous boolean is true. *> *> err = 3 Reciprocal condition number: Estimated normwise *> reciprocal condition number. Compared with the threshold *> sqrt(n) * dlamch('Epsilon') to determine if the error *> estimate is "guaranteed". These reciprocal condition *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some *> appropriately scaled matrix Z. *> Let Z = S*A, where S scales each row by a power of the *> radix so all absolute row sums of Z are approximately 1. *> *> See Lapack Working Note 165 for further details and extra *> cautions. *> \endverbatim *> *> \param[out] ERR_BNDS_COMP *> \verbatim *> ERR_BNDS_COMP is DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) *> For each right-hand side, this array contains information about *> various error bounds and condition numbers corresponding to the *> componentwise relative error, which is defined as follows: *> *> Componentwise relative error in the ith solution vector: *> abs(XTRUE(j,i) - X(j,i)) *> max_j ---------------------- *> abs(X(j,i)) *> *> The array is indexed by the right-hand side i (on which the *> componentwise relative error depends), and the type of error *> information as described below. There currently are up to three *> pieces of information returned for each right-hand side. If *> componentwise accuracy is not requested (PARAMS(3) = 0.0), then *> ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most *> the first (:,N_ERR_BNDS) entries are returned. *> *> The first index in ERR_BNDS_COMP(i,:) corresponds to the ith *> right-hand side. *> *> The second index in ERR_BNDS_COMP(:,err) contains the following *> three fields: *> err = 1 "Trust/don't trust" boolean. Trust the answer if the *> reciprocal condition number is less than the threshold *> sqrt(n) * dlamch('Epsilon'). *> *> err = 2 "Guaranteed" error bound: The estimated forward error, *> almost certainly within a factor of 10 of the true error *> so long as the next entry is greater than the threshold *> sqrt(n) * dlamch('Epsilon'). This error bound should only *> be trusted if the previous boolean is true. *> *> err = 3 Reciprocal condition number: Estimated componentwise *> reciprocal condition number. Compared with the threshold *> sqrt(n) * dlamch('Epsilon') to determine if the error *> estimate is "guaranteed". These reciprocal condition *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some *> appropriately scaled matrix Z. *> Let Z = S*(A*diag(x)), where x is the solution for the *> current right-hand side and S scales each row of *> A*diag(x) by a power of the radix so all absolute row *> sums of Z are approximately 1. *> *> See Lapack Working Note 165 for further details and extra *> cautions. *> \endverbatim *> *> \param[in] NPARAMS *> \verbatim *> NPARAMS is INTEGER *> Specifies the number of parameters set in PARAMS. If .LE. 0, the *> PARAMS array is never referenced and default values are used. *> \endverbatim *> *> \param[in,out] PARAMS *> \verbatim *> PARAMS is DOUBLE PRECISION array, dimension (NPARAMS) *> Specifies algorithm parameters. If an entry is .LT. 0.0, then *> that entry will be filled with default value used for that *> parameter. Only positions up to NPARAMS are accessed; defaults *> are used for higher-numbered parameters. *> *> PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative *> refinement or not. *> Default: 1.0D+0 *> = 0.0 : No refinement is performed, and no error bounds are *> computed. *> = 1.0 : Use the double-precision refinement algorithm, *> possibly with doubled-single computations if the *> compilation environment does not support DOUBLE *> PRECISION. *> (other values are reserved for future use) *> *> PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual *> computations allowed for refinement. *> Default: 10 *> Aggressive: Set to 100 to permit convergence using approximate *> factorizations or factorizations other than LU. If *> the factorization uses a technique other than *> Gaussian elimination, the guarantees in *> err_bnds_norm and err_bnds_comp may no longer be *> trustworthy. *> *> PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code *> will attempt to find a solution with small componentwise *> relative error in the double-precision algorithm. Positive *> is true, 0.0 is false. *> Default: 1.0 (attempt componentwise convergence) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (4*N) *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: Successful exit. The solution to every right-hand side is *> guaranteed. *> < 0: If INFO = -i, the i-th argument had an illegal value *> > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization *> has been completed, but the factor U is exactly singular, so *> the solution and error bounds could not be computed. RCOND = 0 *> is returned. *> = N+J: The solution corresponding to the Jth right-hand side is *> not guaranteed. The solutions corresponding to other right- *> hand sides K with K > J may not be guaranteed as well, but *> only the first such right-hand side is reported. If a small *> componentwise error is not requested (PARAMS(3) = 0.0) then *> the Jth right-hand side is the first with a normwise error *> bound that is not guaranteed (the smallest J such *> that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) *> the Jth right-hand side is the first with either a normwise or *> componentwise error bound that is not guaranteed (the smallest *> J such that either ERR_BNDS_NORM(J,1) = 0.0 or *> ERR_BNDS_COMP(J,1) = 0.0). See the definition of *> ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information *> about all of the right-hand sides check ERR_BNDS_NORM or *> ERR_BNDS_COMP. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup doubleGEcomputational * * ===================================================================== SUBROUTINE DGERFSX( TRANS, EQUED, N, NRHS, A, LDA, AF, LDAF, IPIV, $ R, C, B, LDB, X, LDX, RCOND, BERR, N_ERR_BNDS, $ ERR_BNDS_NORM, ERR_BNDS_COMP, NPARAMS, PARAMS, $ WORK, IWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER TRANS, EQUED INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, $ N_ERR_BNDS DOUBLE PRECISION RCOND * .. * .. Array Arguments .. INTEGER IPIV( * ), IWORK( * ) DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ), $ X( LDX , * ), WORK( * ) DOUBLE PRECISION R( * ), C( * ), PARAMS( * ), BERR( * ), $ ERR_BNDS_NORM( NRHS, * ), $ ERR_BNDS_COMP( NRHS, * ) * .. * * ================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) DOUBLE PRECISION ITREF_DEFAULT, ITHRESH_DEFAULT DOUBLE PRECISION COMPONENTWISE_DEFAULT, RTHRESH_DEFAULT DOUBLE PRECISION DZTHRESH_DEFAULT PARAMETER ( ITREF_DEFAULT = 1.0D+0 ) PARAMETER ( ITHRESH_DEFAULT = 10.0D+0 ) PARAMETER ( COMPONENTWISE_DEFAULT = 1.0D+0 ) PARAMETER ( RTHRESH_DEFAULT = 0.5D+0 ) PARAMETER ( DZTHRESH_DEFAULT = 0.25D+0 ) INTEGER LA_LINRX_ITREF_I, LA_LINRX_ITHRESH_I, $ LA_LINRX_CWISE_I PARAMETER ( LA_LINRX_ITREF_I = 1, $ LA_LINRX_ITHRESH_I = 2 ) PARAMETER ( LA_LINRX_CWISE_I = 3 ) INTEGER LA_LINRX_TRUST_I, LA_LINRX_ERR_I, $ LA_LINRX_RCOND_I PARAMETER ( LA_LINRX_TRUST_I = 1, LA_LINRX_ERR_I = 2 ) PARAMETER ( LA_LINRX_RCOND_I = 3 ) * .. * .. Local Scalars .. CHARACTER(1) NORM LOGICAL ROWEQU, COLEQU, NOTRAN INTEGER J, TRANS_TYPE, PREC_TYPE, REF_TYPE INTEGER N_NORMS DOUBLE PRECISION ANORM, RCOND_TMP DOUBLE PRECISION ILLRCOND_THRESH, ERR_LBND, CWISE_WRONG LOGICAL IGNORE_CWISE INTEGER ITHRESH DOUBLE PRECISION RTHRESH, UNSTABLE_THRESH * .. * .. External Subroutines .. EXTERNAL XERBLA, DGECON, DLA_GERFSX_EXTENDED * .. * .. Intrinsic Functions .. INTRINSIC MAX, SQRT * .. * .. External Functions .. EXTERNAL LSAME, BLAS_FPINFO_X, ILATRANS, ILAPREC EXTERNAL DLAMCH, DLANGE, DLA_GERCOND DOUBLE PRECISION DLAMCH, DLANGE, DLA_GERCOND LOGICAL LSAME INTEGER BLAS_FPINFO_X INTEGER ILATRANS, ILAPREC * .. * .. Executable Statements .. * * Check the input parameters. * INFO = 0 TRANS_TYPE = ILATRANS( TRANS ) REF_TYPE = INT( ITREF_DEFAULT ) IF ( NPARAMS .GE. LA_LINRX_ITREF_I ) THEN IF ( PARAMS( LA_LINRX_ITREF_I ) .LT. 0.0D+0 ) THEN PARAMS( LA_LINRX_ITREF_I ) = ITREF_DEFAULT ELSE REF_TYPE = PARAMS( LA_LINRX_ITREF_I ) END IF END IF * * Set default parameters. * ILLRCOND_THRESH = DBLE( N ) * DLAMCH( 'Epsilon' ) ITHRESH = INT( ITHRESH_DEFAULT ) RTHRESH = RTHRESH_DEFAULT UNSTABLE_THRESH = DZTHRESH_DEFAULT IGNORE_CWISE = COMPONENTWISE_DEFAULT .EQ. 0.0D+0 * IF ( NPARAMS.GE.LA_LINRX_ITHRESH_I ) THEN IF ( PARAMS( LA_LINRX_ITHRESH_I ).LT.0.0D+0 ) THEN PARAMS( LA_LINRX_ITHRESH_I ) = ITHRESH ELSE ITHRESH = INT( PARAMS( LA_LINRX_ITHRESH_I ) ) END IF END IF IF ( NPARAMS.GE.LA_LINRX_CWISE_I ) THEN IF ( PARAMS( LA_LINRX_CWISE_I ).LT.0.0D+0 ) THEN IF ( IGNORE_CWISE ) THEN PARAMS( LA_LINRX_CWISE_I ) = 0.0D+0 ELSE PARAMS( LA_LINRX_CWISE_I ) = 1.0D+0 END IF ELSE IGNORE_CWISE = PARAMS( LA_LINRX_CWISE_I ) .EQ. 0.0D+0 END IF END IF IF ( REF_TYPE .EQ. 0 .OR. N_ERR_BNDS .EQ. 0 ) THEN N_NORMS = 0 ELSE IF ( IGNORE_CWISE ) THEN N_NORMS = 1 ELSE N_NORMS = 2 END IF * NOTRAN = LSAME( TRANS, 'N' ) ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' ) COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' ) * * Test input parameters. * IF( TRANS_TYPE.EQ.-1 ) THEN INFO = -1 ELSE IF( .NOT.ROWEQU .AND. .NOT.COLEQU .AND. $ .NOT.LSAME( EQUED, 'N' ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NRHS.LT.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -6 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN INFO = -8 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -13 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN INFO = -15 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGERFSX', -INFO ) RETURN END IF * * Quick return if possible. * IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN RCOND = 1.0D+0 DO J = 1, NRHS BERR( J ) = 0.0D+0 IF ( N_ERR_BNDS .GE. 1 ) THEN ERR_BNDS_NORM( J, LA_LINRX_TRUST_I) = 1.0D+0 ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0D+0 END IF IF ( N_ERR_BNDS .GE. 2 ) THEN ERR_BNDS_NORM( J, LA_LINRX_ERR_I) = 0.0D+0 ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 0.0D+0 END IF IF ( N_ERR_BNDS .GE. 3 ) THEN ERR_BNDS_NORM( J, LA_LINRX_RCOND_I) = 1.0D+0 ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 1.0D+0 END IF END DO RETURN END IF * * Default to failure. * RCOND = 0.0D+0 DO J = 1, NRHS BERR( J ) = 1.0D+0 IF ( N_ERR_BNDS .GE. 1 ) THEN ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0D+0 ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0D+0 END IF IF ( N_ERR_BNDS .GE. 2 ) THEN ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0D+0 ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0D+0 END IF IF ( N_ERR_BNDS .GE. 3 ) THEN ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = 0.0D+0 ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 0.0D+0 END IF END DO * * Compute the norm of A and the reciprocal of the condition * number of A. * IF( NOTRAN ) THEN NORM = 'I' ELSE NORM = '1' END IF ANORM = DLANGE( NORM, N, N, A, LDA, WORK ) CALL DGECON( NORM, N, AF, LDAF, ANORM, RCOND, WORK, IWORK, INFO ) * * Perform refinement on each right-hand side * IF ( REF_TYPE .NE. 0 ) THEN PREC_TYPE = ILAPREC( 'E' ) IF ( NOTRAN ) THEN CALL DLA_GERFSX_EXTENDED( PREC_TYPE, TRANS_TYPE, N, $ NRHS, A, LDA, AF, LDAF, IPIV, COLEQU, C, B, $ LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM, $ ERR_BNDS_COMP, WORK(N+1), WORK(1), WORK(2*N+1), $ WORK(1), RCOND, ITHRESH, RTHRESH, UNSTABLE_THRESH, $ IGNORE_CWISE, INFO ) ELSE CALL DLA_GERFSX_EXTENDED( PREC_TYPE, TRANS_TYPE, N, $ NRHS, A, LDA, AF, LDAF, IPIV, ROWEQU, R, B, $ LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM, $ ERR_BNDS_COMP, WORK(N+1), WORK(1), WORK(2*N+1), $ WORK(1), RCOND, ITHRESH, RTHRESH, UNSTABLE_THRESH, $ IGNORE_CWISE, INFO ) END IF END IF ERR_LBND = MAX( 10.0D+0, SQRT( DBLE( N ) ) ) * DLAMCH( 'Epsilon' ) IF ( N_ERR_BNDS .GE. 1 .AND. N_NORMS .GE. 1 ) THEN * * Compute scaled normwise condition number cond(A*C). * IF ( COLEQU .AND. NOTRAN ) THEN RCOND_TMP = DLA_GERCOND( TRANS, N, A, LDA, AF, LDAF, IPIV, $ -1, C, INFO, WORK, IWORK ) ELSE IF ( ROWEQU .AND. .NOT. NOTRAN ) THEN RCOND_TMP = DLA_GERCOND( TRANS, N, A, LDA, AF, LDAF, IPIV, $ -1, R, INFO, WORK, IWORK ) ELSE RCOND_TMP = DLA_GERCOND( TRANS, N, A, LDA, AF, LDAF, IPIV, $ 0, R, INFO, WORK, IWORK ) END IF DO J = 1, NRHS * * Cap the error at 1.0. * IF ( N_ERR_BNDS .GE. LA_LINRX_ERR_I $ .AND. ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) .GT. 1.0D+0 ) $ ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0D+0 * * Threshold the error (see LAWN). * IF ( RCOND_TMP .LT. ILLRCOND_THRESH ) THEN ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0D+0 ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 0.0D+0 IF ( INFO .LE. N ) INFO = N + J ELSE IF ( ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) .LT. ERR_LBND ) $ THEN ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = ERR_LBND ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0D+0 END IF * * Save the condition number. * IF ( N_ERR_BNDS .GE. LA_LINRX_RCOND_I ) THEN ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = RCOND_TMP END IF END DO END IF IF ( N_ERR_BNDS .GE. 1 .AND. N_NORMS .GE. 2 ) THEN * * Compute componentwise condition number cond(A*diag(Y(:,J))) for * each right-hand side using the current solution as an estimate of * the true solution. If the componentwise error estimate is too * large, then the solution is a lousy estimate of truth and the * estimated RCOND may be too optimistic. To avoid misleading users, * the inverse condition number is set to 0.0 when the estimated * cwise error is at least CWISE_WRONG. * CWISE_WRONG = SQRT( DLAMCH( 'Epsilon' ) ) DO J = 1, NRHS IF ( ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) .LT. CWISE_WRONG ) $ THEN RCOND_TMP = DLA_GERCOND( TRANS, N, A, LDA, AF, LDAF, $ IPIV, 1, X(1,J), INFO, WORK, IWORK ) ELSE RCOND_TMP = 0.0D+0 END IF * * Cap the error at 1.0. * IF ( N_ERR_BNDS .GE. LA_LINRX_ERR_I $ .AND. ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) .GT. 1.0D+0 ) $ ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0D+0 * * Threshold the error (see LAWN). * IF ( RCOND_TMP .LT. ILLRCOND_THRESH ) THEN ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0D+0 ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 0.0D+0 IF ( PARAMS( LA_LINRX_CWISE_I ) .EQ. 1.0D+0 $ .AND. INFO.LT.N + J ) INFO = N + J ELSE IF ( ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) $ .LT. ERR_LBND ) THEN ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = ERR_LBND ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0D+0 END IF * * Save the condition number. * IF ( N_ERR_BNDS .GE. LA_LINRX_RCOND_I ) THEN ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = RCOND_TMP END IF END DO END IF * RETURN * * End of DGERFSX * END
bsd-3-clause
hlokavarapu/calypso
src/Fortran_libraries/MHD_src/IO/sph_mhd_rms_IO.f90
3
3043
!>@file sph_mhd_rms_IO.f90 !!@brief module sph_mhd_rms_IO !! !!@author H. Matsui !!@date Programmed in 2009 ! !>@brief I/O routines for mean square and averaga data !! !!@verbatim !! subroutine open_sph_vol_rms_file_mhd !! subroutine output_rms_sph_mhd_control !!@endverbatim ! module sph_mhd_rms_IO ! use m_precision ! use calypso_mpi use m_machine_parameter use m_spheric_parameter use m_gauss_coefs_monitor_data use m_pickup_sph_spectr_data use pickup_sph_coefs use pickup_gauss_coefficients use output_sph_m_square_file ! implicit none ! ! -------------------------------------------------------------------- ! contains ! ! -------------------------------------------------------------------- ! subroutine open_sph_vol_rms_file_mhd ! use m_sph_spectr_data use m_rms_4_sph_spectr use cal_rms_fields_by_sph ! ! if ( iflag_debug.gt.0 ) write(*,*) 'init_rms_4_sph_spectr' call init_rms_4_sph_spectr ! if ( iflag_debug.gt.0 ) write(*,*) 'init_gauss_coefs_4_monitor' call init_gauss_coefs_4_monitor if ( iflag_debug.gt.0 ) write(*,*) 'init_sph_spec_4_monitor' call init_sph_spec_4_monitor ! end subroutine open_sph_vol_rms_file_mhd ! ! -------------------------------------------------------------------- ! subroutine output_rms_sph_mhd_control ! use m_machine_parameter use m_t_step_parameter use m_boundary_params_sph_MHD use set_exit_flag_4_visualizer use cal_rms_fields_by_sph use m_no_heat_Nusselt_num use volume_average_4_sph ! integer (kind = kint) :: i_flag ! ! call set_output_flag(i_flag, istep_max_dt, i_step_check) ! if (i_flag .ne. 0) return ! if(iflag_debug.gt.0) write(*,*) 'cal_rms_sph_outer_core' call cal_rms_sph_outer_core if(iflag_debug.gt.0) write(*,*) 'cal_gauss_coefficients' call cal_gauss_coefficients if(iflag_debug.gt.0) write(*,*) 'pickup_sph_spec_4_monitor' call pickup_sph_spec_4_monitor if(iflag_debug.gt.0) write(*,*) 'cal_no_heat_source_Nu' call cal_no_heat_source_Nu(sph_bc_U%kr_in, sph_bc_U%kr_out, & & sph_bc_U%r_ICB(0), sph_bc_U%r_CMB(0) ) ! if(iflag_debug.gt.0) write(*,*) 'write_total_energy_to_screen' call write_total_energy_to_screen(my_rank, i_step_MHD, time) ! call write_sph_vol_ave_file(i_step_MHD, time) call write_sph_vol_ms_file(my_rank, i_step_MHD, time) call write_sph_vol_ms_spectr_file(my_rank, i_step_MHD, time) call write_sph_layer_ms_file(my_rank, i_step_MHD, time) ! call write_gauss_coefs_4_monitor(my_rank, istep_max_dt, time) call write_sph_spec_4_monitor(my_rank, istep_max_dt, time) ! call write_no_heat_source_Nu(idx_rj_degree_zero, & & istep_max_dt, time) ! end subroutine output_rms_sph_mhd_control ! ! -------------------------------------------------------------------- ! end module sph_mhd_rms_IO
gpl-3.0
jakevdp/scipy
scipy/optimize/cobyla/cobyla2.f
116
18900
C------------------------------------------------------------------------ C SUBROUTINE COBYLA (CALCFC, N,M,X,RHOBEG,RHOEND,IPRINT,MAXFUN, & W,IACT, DINFO) IMPLICIT DOUBLE PRECISION (A-H,O-Z) EXTERNAL CALCFC DIMENSION X(*),W(*),IACT(*), DINFO(*) C C This subroutine minimizes an objective function F(X) subject to M C inequality constraints on X, where X is a vector of variables that has C N components. The algorithm employs linear approximations to the C objective and constraint functions, the approximations being formed by C linear interpolation at N+1 points in the space of the variables. C We regard these interpolation points as vertices of a simplex. The C parameter RHO controls the size of the simplex and it is reduced C automatically from RHOBEG to RHOEND. For each RHO the subroutine tries C to achieve a good vector of variables for the current size, and then C RHO is reduced until the value RHOEND is reached. Therefore RHOBEG and C RHOEND should be set to reasonable initial changes to and the required C accuracy in the variables respectively, but this accuracy should be C viewed as a subject for experimentation because it is not guaranteed. C The subroutine has an advantage over many of its competitors, however, C which is that it treats each constraint individually when calculating C a change to the variables, instead of lumping the constraints together C into a single penalty function. The name of the subroutine is derived C from the phrase Constrained Optimization BY Linear Approximations. C C The user must set the values of N, M, RHOBEG and RHOEND, and must C provide an initial vector of variables in X. Further, the value of C IPRINT should be set to 0, 1, 2 or 3, which controls the amount of C printing during the calculation. Specifically, there is no output if C IPRINT=0 and there is output only at the end of the calculation if C IPRINT=1. Otherwise each new value of RHO and SIGMA is printed. C Further, the vector of variables and some function information are C given either when RHO is reduced or when each new value of F(X) is C computed in the cases IPRINT=2 or IPRINT=3 respectively. Here SIGMA C is a penalty parameter, it being assumed that a change to X is an C improvement if it reduces the merit function C F(X)+SIGMA*MAX(0.0,-C1(X),-C2(X),...,-CM(X)), C where C1,C2,...,CM denote the constraint functions that should become C nonnegative eventually, at least to the precision of RHOEND. In the C printed output the displayed term that is multiplied by SIGMA is C called MAXCV, which stands for 'MAXimum Constraint Violation'. The C argument MAXFUN is an integer variable that must be set by the user to a C limit on the number of calls of CALCFC, the purpose of this routine being C given below. The value of MAXFUN will be altered to the number of calls C of CALCFC that are made. The arguments W and IACT provide real and C integer arrays that are used as working space. Their lengths must be at C least N*(3*N+2*M+11)+4*M+6 and M+1 respectively. C C In order to define the objective and constraint functions, we require C a subroutine that has the name and arguments C SUBROUTINE CALCFC (N,M,X,F,CON) C DIMENSION X(*),CON(*) . C The values of N and M are fixed and have been defined already, while C X is now the current vector of variables. The subroutine should return C the objective and constraint functions at X in F and CON(1),CON(2), C ...,CON(M). Note that we are trying to adjust X so that F(X) is as C small as possible subject to the constraint functions being nonnegative. C C Partition the working space array W to provide the storage that is needed C for the main calculation. C MPP=M+2 ICON=1 ISIM=ICON+MPP ISIMI=ISIM+N*N+N IDATM=ISIMI+N*N IA=IDATM+N*MPP+MPP IVSIG=IA+M*N+N IVETA=IVSIG+N ISIGB=IVETA+N IDX=ISIGB+N IWORK=IDX+N CALL COBYLB (CALCFC,N,M,MPP,X,RHOBEG,RHOEND,IPRINT,MAXFUN,W(ICON), 1 W(ISIM),W(ISIMI),W(IDATM),W(IA),W(IVSIG),W(IVETA),W(ISIGB), 2 W(IDX),W(IWORK),IACT,DINFO) RETURN END C------------------------------------------------------------------------------ SUBROUTINE COBYLB (CALCFC,N,M,MPP,X,RHOBEG,RHOEND,IPRINT,MAXFUN, 1 CON,SIM,SIMI,DATMAT,A,VSIG,VETA,SIGBAR,DX,W,IACT,DINFO) IMPLICIT DOUBLE PRECISION (A-H,O-Z) DIMENSION X(*),CON(*),SIM(N,*),SIMI(N,*),DATMAT(MPP,*), 1 A(N,*),VSIG(*),VETA(*),SIGBAR(*),DX(*),W(*),IACT(*),DINFO(*) EXTERNAL CALCFC C C Set the initial values of some parameters. The last column of SIM holds C the optimal vertex of the current simplex, and the preceding N columns C hold the displacements from the optimal vertex to the other vertices. C Further, SIMI holds the inverse of the matrix that is contained in the C first N columns of SIM. C ITOTAL=N*(3*N+2*M+11)+4*M+6 IPTEM=MIN0(N,5) IPTEMP=IPTEM+1 NP=N+1 MP=M+1 ALPHA=0.25d0 BETA=2.1d0 GAMMA=0.5d0 DELTA=1.1d0 RHO=RHOBEG PARMU=0.0d0 C Set the STATUS value of DINFO to 1.0 to start. C IF an error occurs it will get set to 0.0 DINFO(1)=1.0d0 C Fix compiler warnings IFLAG=1 PARSIG=0 SUM=0 PREREC=0 PREREM=0 CMIN=0 CMAX=0 IF (IPRINT .GE. 2) PRINT 10, RHO 10 FORMAT (/3X,'The initial value of RHO is',1PE13.6,2X, 1 'and PARMU is set to zero.') NFVALS=0 TEMP=1.0d0/RHO DO 30 I=1,N SIM(I,NP)=X(I) DO 20 J=1,N SIM(I,J)=0.0d0 20 SIMI(I,J)=0.0d0 SIM(I,I)=RHO 30 SIMI(I,I)=TEMP JDROP=NP IBRNCH=0 C C Make the next call of the user-supplied subroutine CALCFC. These C instructions are also used for calling CALCFC during the iterations of C the algorithm. C 40 IF (NFVALS .GE. MAXFUN .AND. NFVALS .GT. 0) THEN IF (IPRINT .GE. 1) PRINT 50 50 FORMAT (/3X,'Return from subroutine COBYLA because the ', 1 'MAXFUN limit has been reached.') DINFO(1)=2.0d0 GOTO 600 END IF NFVALS=NFVALS+1 IF (IPRINT .EQ. 3) THEN PRINT *, ' SIM = ', (SIM(J,NP),J=1,N) PRINT *, ' DX = ', (DX(I),I=1,N) PRINT *, ' BEFORE: ', N, M, (X(I),I=1,N), F, (CON(I),I=1,M) END IF CALL CALCFC (N,M,X,F,CON) IF (IPRINT .EQ. 3) THEN PRINT *, ' AFTER: ', N, M, (X(I),I=1,N), F, (CON(I),I=1,M) END IF RESMAX=0.0d0 IF (M .GT. 0) THEN DO 60 K=1,M 60 RESMAX=DMAX1(RESMAX,-CON(K)) END IF IF (NFVALS .EQ. IPRINT-1 .OR. IPRINT .EQ. 3) THEN PRINT 70, NFVALS,F,RESMAX,(X(I),I=1,IPTEM) 70 FORMAT (/3X,'NFVALS =',I5,3X,'F =',1PE13.6,4X,'MAXCV =', 1 1PE13.6/3X,'X =',1PE13.6,1P4E15.6) IF (IPTEM .LT. N) PRINT 80, (X(I),I=IPTEMP,N) 80 FORMAT (1PE19.6,1P4E15.6) END IF CON(MP)=F CON(MPP)=RESMAX IF (IBRNCH .EQ. 1) GOTO 440 C C Set the recently calculated function values in a column of DATMAT. This C array has a column for each vertex of the current simplex, the entries of C each column being the values of the constraint functions (if any) C followed by the objective function and the greatest constraint violation C at the vertex. C DO 90 K=1,MPP 90 DATMAT(K,JDROP)=CON(K) IF (NFVALS .GT. NP) GOTO 130 C C Exchange the new vertex of the initial simplex with the optimal vertex if C necessary. Then, if the initial simplex is not complete, pick its next C vertex and calculate the function values there. C IF (JDROP .LE. N) THEN IF (DATMAT(MP,NP) .LE. F) THEN X(JDROP)=SIM(JDROP,NP) ELSE SIM(JDROP,NP)=X(JDROP) DO 100 K=1,MPP DATMAT(K,JDROP)=DATMAT(K,NP) 100 DATMAT(K,NP)=CON(K) DO 120 K=1,JDROP SIM(JDROP,K)=-RHO TEMP=0.0 DO 110 I=K,JDROP 110 TEMP=TEMP-SIMI(I,K) 120 SIMI(JDROP,K)=TEMP END IF END IF IF (NFVALS .LE. N) THEN JDROP=NFVALS X(JDROP)=X(JDROP)+RHO GOTO 40 END IF 130 IBRNCH=1 C C Identify the optimal vertex of the current simplex. C 140 PHIMIN=DATMAT(MP,NP)+PARMU*DATMAT(MPP,NP) NBEST=NP DO 150 J=1,N TEMP=DATMAT(MP,J)+PARMU*DATMAT(MPP,J) IF (TEMP .LT. PHIMIN) THEN NBEST=J PHIMIN=TEMP ELSE IF (TEMP .EQ. PHIMIN .AND. PARMU .EQ. 0.0d0) THEN IF (DATMAT(MPP,J) .LT. DATMAT(MPP,NBEST)) NBEST=J END IF 150 CONTINUE C C Switch the best vertex into pole position if it is not there already, C and also update SIM, SIMI and DATMAT. C IF (NBEST .LE. N) THEN DO 160 I=1,MPP TEMP=DATMAT(I,NP) DATMAT(I,NP)=DATMAT(I,NBEST) 160 DATMAT(I,NBEST)=TEMP DO 180 I=1,N TEMP=SIM(I,NBEST) SIM(I,NBEST)=0.0d0 SIM(I,NP)=SIM(I,NP)+TEMP TEMPA=0.0d0 DO 170 K=1,N SIM(I,K)=SIM(I,K)-TEMP 170 TEMPA=TEMPA-SIMI(K,I) 180 SIMI(NBEST,I)=TEMPA END IF C C Make an error return if SIGI is a poor approximation to the inverse of C the leading N by N submatrix of SIG. C ERROR=0.0d0 DO 200 I=1,N DO 200 J=1,N TEMP=0.0d0 IF (I .EQ. J) TEMP=TEMP-1.0d0 DO 190 K=1,N 190 TEMP=TEMP+SIMI(I,K)*SIM(K,J) 200 ERROR=DMAX1(ERROR,ABS(TEMP)) IF (ERROR .GT. 0.1d0) THEN IF (IPRINT .GE. 1) PRINT 210 210 FORMAT (/3X,'Return from subroutine COBYLA because ', 1 'rounding errors are becoming damaging.') DINFO(1)=3.0d0 GOTO 600 END IF C C Calculate the coefficients of the linear approximations to the objective C and constraint functions, placing minus the objective function gradient C after the constraint gradients in the array A. The vector W is used for C working space. C DO 240 K=1,MP CON(K)=-DATMAT(K,NP) DO 220 J=1,N 220 W(J)=DATMAT(K,J)+CON(K) DO 240 I=1,N TEMP=0.0d0 DO 230 J=1,N 230 TEMP=TEMP+W(J)*SIMI(J,I) IF (K .EQ. MP) TEMP=-TEMP 240 A(I,K)=TEMP C C Calculate the values of sigma and eta, and set IFLAG=0 if the current C simplex is not acceptable. C IFLAG=1 PARSIG=ALPHA*RHO PARETA=BETA*RHO DO 260 J=1,N WSIG=0.0d0 WETA=0.0d0 DO 250 I=1,N WSIG=WSIG+SIMI(J,I)**2 250 WETA=WETA+SIM(I,J)**2 VSIG(J)=1.0d0/SQRT(WSIG) VETA(J)=SQRT(WETA) IF (VSIG(J) .LT. PARSIG .OR. VETA(J) .GT. PARETA) IFLAG=0 260 CONTINUE IF (IPRINT .EQ. 3) THEN print *, ' SIMI = ', ((SIMI(I,J),I=1,N),J=1,N) print *, ' SIM = ', ((SIM(I,J),I=1,N),J=1,N) PRINT *, ' VSIG = ', (VSIG(J),J=1,N), ' -- ', PARSIG PRINT *, ' VETA = ', (VETA(J),J=1,N), ' -- ', PARETA PRINT *, ' IBRNCH, IFLAG = ', IBRNCH, IFLAG PRINT *, ' A = ', ((A(I,J),I=1,N),J=1,MP) END IF C C If a new vertex is needed to improve acceptability, then decide which C vertex to drop from the simplex. C IF (IBRNCH .EQ. 1 .OR. IFLAG .EQ. 1) GOTO 370 JDROP=0 TEMP=PARETA DO 270 J=1,N IF (VETA(J) .GT. TEMP) THEN JDROP=J TEMP=VETA(J) END IF 270 CONTINUE IF (JDROP .EQ. 0) THEN DO 280 J=1,N IF (VSIG(J) .LT. TEMP) THEN JDROP=J TEMP=VSIG(J) END IF 280 CONTINUE END IF C C Calculate the step to the new vertex and its sign. C TEMP=GAMMA*RHO*VSIG(JDROP) IF (IPRINT .EQ. 3) THEN PRINT *, ' SIMI =', (SIMI(JDROP,I),I=1,N) END IF DO 290 I=1,N 290 DX(I)=TEMP*SIMI(JDROP,I) IF (IPRINT .EQ. 3) THEN PRINT *, ' DX =', (DX(I),I=1,N) END IF CVMAXP=0.0d0 CVMAXM=0.0d0 DO 310 K=1,MP SUM=0.0d0 DO 300 I=1,N 300 SUM=SUM+A(I,K)*DX(I) IF (K .LT. MP) THEN TEMP=DATMAT(K,NP) CVMAXP=DMAX1(CVMAXP,-SUM-TEMP) CVMAXM=DMAX1(CVMAXM,SUM-TEMP) END IF 310 CONTINUE DXSIGN=1.0d0 IF (PARMU*(CVMAXP-CVMAXM) .GT. SUM+SUM) DXSIGN=-1.0d0 C C Update the elements of SIM and SIMI, and set the next X. C TEMP=0.0d0 DO 320 I=1,N DX(I)=DXSIGN*DX(I) SIM(I,JDROP)=DX(I) 320 TEMP=TEMP+SIMI(JDROP,I)*DX(I) DO 330 I=1,N 330 SIMI(JDROP,I)=SIMI(JDROP,I)/TEMP DO 360 J=1,N IF (J .NE. JDROP) THEN TEMP=0.0d0 DO 340 I=1,N 340 TEMP=TEMP+SIMI(J,I)*DX(I) DO 350 I=1,N 350 SIMI(J,I)=SIMI(J,I)-TEMP*SIMI(JDROP,I) END IF 360 X(J)=SIM(J,NP)+DX(J) GOTO 40 C C Calculate DX=x(*)-x(0). Branch if the length of DX is less than 0.5*RHO. C 370 IZ=1 IZDOTA=IZ+N*N IVMC=IZDOTA+N ISDIRN=IVMC+MP IDXNEW=ISDIRN+N IVMD=IDXNEW+N CALL TRSTLP (N,M,A,CON,RHO,DX,IFULL,IACT,W(IZ),W(IZDOTA), 1 W(IVMC),W(ISDIRN),W(IDXNEW),W(IVMD),IPRINT) IF (IFULL .EQ. 0) THEN TEMP=0.0d0 DO 380 I=1,N 380 TEMP=TEMP+DX(I)**2 IF (TEMP .LT. 0.25d0*RHO*RHO) THEN IBRNCH=1 GOTO 550 END IF END IF C C Predict the change to F and the new maximum constraint violation if the C variables are altered from x(0) to x(0)+DX. C RESNEW=0.0d0 CON(MP)=0.0d0 DO 400 K=1,MP SUM=CON(K) DO 390 I=1,N 390 SUM=SUM-A(I,K)*DX(I) IF (K .LT. MP) RESNEW=DMAX1(RESNEW,SUM) 400 CONTINUE C C Increase PARMU if necessary and branch back if this change alters the C optimal vertex. Otherwise PREREM and PREREC will be set to the predicted C reductions in the merit function and the maximum constraint violation C respectively. C BARMU=0.0d0 PREREC=DATMAT(MPP,NP)-RESNEW IF (PREREC .GT. 0.0d0) BARMU=SUM/PREREC IF (PARMU .LT. 1.5d0*BARMU) THEN PARMU=2.0d0*BARMU IF (IPRINT .GE. 2) PRINT 410, PARMU 410 FORMAT (/3X,'Increase in PARMU to',1PE13.6) PHI=DATMAT(MP,NP)+PARMU*DATMAT(MPP,NP) DO 420 J=1,N TEMP=DATMAT(MP,J)+PARMU*DATMAT(MPP,J) IF (TEMP .LT. PHI) GOTO 140 IF (TEMP .EQ. PHI .AND. PARMU .EQ. 0.0) THEN IF (DATMAT(MPP,J) .LT. DATMAT(MPP,NP)) GOTO 140 END IF 420 CONTINUE END IF PREREM=PARMU*PREREC-SUM C C Calculate the constraint and objective functions at x(*). Then find the C actual reduction in the merit function. C DO 430 I=1,N 430 X(I)=SIM(I,NP)+DX(I) IBRNCH=1 GOTO 40 440 VMOLD=DATMAT(MP,NP)+PARMU*DATMAT(MPP,NP) VMNEW=F+PARMU*RESMAX TRURED=VMOLD-VMNEW IF (PARMU .EQ. 0.0d0 .AND. F .EQ. DATMAT(MP,NP)) THEN PREREM=PREREC TRURED=DATMAT(MPP,NP)-RESMAX END IF C C Begin the operations that decide whether x(*) should replace one of the C vertices of the current simplex, the change being mandatory if TRURED is C positive. Firstly, JDROP is set to the index of the vertex that is to be C replaced. C RATIO=0.0d0 IF (TRURED .LE. 0.0) RATIO=1.0 JDROP=0 DO 460 J=1,N TEMP=0.0d0 DO 450 I=1,N 450 TEMP=TEMP+SIMI(J,I)*DX(I) TEMP=ABS(TEMP) IF (TEMP .GT. RATIO) THEN JDROP=J RATIO=TEMP END IF 460 SIGBAR(J)=TEMP*VSIG(J) C C Calculate the value of ell. C EDGMAX=DELTA*RHO L=0 DO 480 J=1,N IF (SIGBAR(J) .GE. PARSIG .OR. SIGBAR(J) .GE. VSIG(J)) THEN TEMP=VETA(J) IF (TRURED .GT. 0.0d0) THEN TEMP=0.0d0 DO 470 I=1,N 470 TEMP=TEMP+(DX(I)-SIM(I,J))**2 TEMP=SQRT(TEMP) END IF IF (TEMP .GT. EDGMAX) THEN L=J EDGMAX=TEMP END IF END IF 480 CONTINUE IF (L .GT. 0) JDROP=L IF (JDROP .EQ. 0) GOTO 550 C C Revise the simplex by updating the elements of SIM, SIMI and DATMAT. C TEMP=0.0d0 DO 490 I=1,N SIM(I,JDROP)=DX(I) 490 TEMP=TEMP+SIMI(JDROP,I)*DX(I) DO 500 I=1,N 500 SIMI(JDROP,I)=SIMI(JDROP,I)/TEMP DO 530 J=1,N IF (J .NE. JDROP) THEN TEMP=0.0d0 DO 510 I=1,N 510 TEMP=TEMP+SIMI(J,I)*DX(I) DO 520 I=1,N 520 SIMI(J,I)=SIMI(J,I)-TEMP*SIMI(JDROP,I) END IF 530 CONTINUE DO 540 K=1,MPP 540 DATMAT(K,JDROP)=CON(K) C C Branch back for further iterations with the current RHO. C IF (TRURED .GT. 0.0d0 .AND. TRURED .GE. 0.1d0*PREREM) GOTO 140 550 IF (IFLAG .EQ. 0) THEN IBRNCH=0 GOTO 140 END IF C C Otherwise reduce RHO if it is not at its least value and reset PARMU. C IF (RHO .GT. RHOEND) THEN RHO=0.5d0*RHO IF (RHO .LE. 1.5d0*RHOEND) RHO=RHOEND IF (PARMU .GT. 0.0d0) THEN DENOM=0.0d0 DO 570 K=1,MP CMIN=DATMAT(K,NP) CMAX=CMIN DO 560 I=1,N CMIN=DMIN1(CMIN,DATMAT(K,I)) 560 CMAX=DMAX1(CMAX,DATMAT(K,I)) IF (K .LE. M .AND. CMIN .LT. 0.5d0*CMAX) THEN TEMP=DMAX1(CMAX,0.0d0)-CMIN IF (DENOM .LE. 0.0d0) THEN DENOM=TEMP ELSE DENOM=DMIN1(DENOM,TEMP) END IF END IF 570 CONTINUE IF (DENOM .EQ. 0.0d0) THEN PARMU=0.0d0 ELSE IF (CMAX-CMIN .LT. PARMU*DENOM) THEN PARMU=(CMAX-CMIN)/DENOM END IF END IF IF (IPRINT .GE. 2) PRINT 580, RHO,PARMU 580 FORMAT (/3X,'Reduction in RHO to',1PE13.6,' and PARMU =', 1 1PE13.6) IF (IPRINT .EQ. 2) THEN PRINT 70, NFVALS,DATMAT(MP,NP),DATMAT(MPP,NP), 1 (SIM(I,NP),I=1,IPTEM) IF (IPTEM .LT. N) PRINT 80, (X(I),I=IPTEMP,N) END IF GOTO 140 END IF C C Return the best calculated values of the variables. C IF (IPRINT .GE. 1) PRINT 590 590 FORMAT (/3X,'Normal return from subroutine COBYLA') IF (IFULL .EQ. 1) GOTO 620 600 DO 610 I=1,N 610 X(I)=SIM(I,NP) F=DATMAT(MP,NP) RESMAX=DATMAT(MPP,NP) 620 IF (IPRINT .GE. 1) THEN PRINT 70, NFVALS,F,RESMAX,(X(I),I=1,IPTEM) IF (IPTEM .LT. N) PRINT 80, (X(I),I=IPTEMP,N) END IF MAXFUN=NFVALS DINFO(2)=DBLE(NFVALS) DINFO(3)=DBLE(F) DINFO(4)=DBLE(RESMAX) RETURN END
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/cunbdb5.f
22
7323
*> \brief \b CUNBDB5 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CUNBDB5 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cunbdb5.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cunbdb5.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cunbdb5.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CUNBDB5( M1, M2, N, X1, INCX1, X2, INCX2, Q1, LDQ1, Q2, * LDQ2, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * INTEGER INCX1, INCX2, INFO, LDQ1, LDQ2, LWORK, M1, M2, * $ N * .. * .. Array Arguments .. * COMPLEX Q1(LDQ1,*), Q2(LDQ2,*), WORK(*), X1(*), X2(*) * .. * * *> \par Purpose: *> ============= *> *>\verbatim *> *> CUNBDB5 orthogonalizes the column vector *> X = [ X1 ] *> [ X2 ] *> with respect to the columns of *> Q = [ Q1 ] . *> [ Q2 ] *> The columns of Q must be orthonormal. *> *> If the projection is zero according to Kahan's "twice is enough" *> criterion, then some other vector from the orthogonal complement *> is returned. This vector is chosen in an arbitrary but deterministic *> way. *> *>\endverbatim * * Arguments: * ========== * *> \param[in] M1 *> \verbatim *> M1 is INTEGER *> The dimension of X1 and the number of rows in Q1. 0 <= M1. *> \endverbatim *> *> \param[in] M2 *> \verbatim *> M2 is INTEGER *> The dimension of X2 and the number of rows in Q2. 0 <= M2. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns in Q1 and Q2. 0 <= N. *> \endverbatim *> *> \param[in,out] X1 *> \verbatim *> X1 is COMPLEX array, dimension (M1) *> On entry, the top part of the vector to be orthogonalized. *> On exit, the top part of the projected vector. *> \endverbatim *> *> \param[in] INCX1 *> \verbatim *> INCX1 is INTEGER *> Increment for entries of X1. *> \endverbatim *> *> \param[in,out] X2 *> \verbatim *> X2 is COMPLEX array, dimension (M2) *> On entry, the bottom part of the vector to be *> orthogonalized. On exit, the bottom part of the projected *> vector. *> \endverbatim *> *> \param[in] INCX2 *> \verbatim *> INCX2 is INTEGER *> Increment for entries of X2. *> \endverbatim *> *> \param[in] Q1 *> \verbatim *> Q1 is COMPLEX array, dimension (LDQ1, N) *> The top part of the orthonormal basis matrix. *> \endverbatim *> *> \param[in] LDQ1 *> \verbatim *> LDQ1 is INTEGER *> The leading dimension of Q1. LDQ1 >= M1. *> \endverbatim *> *> \param[in] Q2 *> \verbatim *> Q2 is COMPLEX array, dimension (LDQ2, N) *> The bottom part of the orthonormal basis matrix. *> \endverbatim *> *> \param[in] LDQ2 *> \verbatim *> LDQ2 is INTEGER *> The leading dimension of Q2. LDQ2 >= M2. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (LWORK) *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. LWORK >= N. *> \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. * *> \date July 2012 * *> \ingroup complexOTHERcomputational * * ===================================================================== SUBROUTINE CUNBDB5( M1, M2, N, X1, INCX1, X2, INCX2, Q1, LDQ1, Q2, $ LDQ2, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.5.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * July 2012 * * .. Scalar Arguments .. INTEGER INCX1, INCX2, INFO, LDQ1, LDQ2, LWORK, M1, M2, $ N * .. * .. Array Arguments .. COMPLEX Q1(LDQ1,*), Q2(LDQ2,*), WORK(*), X1(*), X2(*) * .. * * ===================================================================== * * .. Parameters .. COMPLEX ONE, ZERO PARAMETER ( ONE = (1.0E0,0.0E0), ZERO = (0.0E0,0.0E0) ) * .. * .. Local Scalars .. INTEGER CHILDINFO, I, J * .. * .. External Subroutines .. EXTERNAL CUNBDB6, XERBLA * .. * .. External Functions .. REAL SCNRM2 EXTERNAL SCNRM2 * .. * .. Intrinsic Function .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test input arguments * INFO = 0 IF( M1 .LT. 0 ) THEN INFO = -1 ELSE IF( M2 .LT. 0 ) THEN INFO = -2 ELSE IF( N .LT. 0 ) THEN INFO = -3 ELSE IF( INCX1 .LT. 1 ) THEN INFO = -5 ELSE IF( INCX2 .LT. 1 ) THEN INFO = -7 ELSE IF( LDQ1 .LT. MAX( 1, M1 ) ) THEN INFO = -9 ELSE IF( LDQ2 .LT. MAX( 1, M2 ) ) THEN INFO = -11 ELSE IF( LWORK .LT. N ) THEN INFO = -13 END IF * IF( INFO .NE. 0 ) THEN CALL XERBLA( 'CUNBDB5', -INFO ) RETURN END IF * * Project X onto the orthogonal complement of Q * CALL CUNBDB6( M1, M2, N, X1, INCX1, X2, INCX2, Q1, LDQ1, Q2, LDQ2, $ WORK, LWORK, CHILDINFO ) * * If the projection is nonzero, then return * IF( SCNRM2(M1,X1,INCX1) .NE. ZERO $ .OR. SCNRM2(M2,X2,INCX2) .NE. ZERO ) THEN RETURN END IF * * Project each standard basis vector e_1,...,e_M1 in turn, stopping * when a nonzero projection is found * DO I = 1, M1 DO J = 1, M1 X1(J) = ZERO END DO X1(I) = ONE DO J = 1, M2 X2(J) = ZERO END DO CALL CUNBDB6( M1, M2, N, X1, INCX1, X2, INCX2, Q1, LDQ1, Q2, $ LDQ2, WORK, LWORK, CHILDINFO ) IF( SCNRM2(M1,X1,INCX1) .NE. ZERO $ .OR. SCNRM2(M2,X2,INCX2) .NE. ZERO ) THEN RETURN END IF END DO * * Project each standard basis vector e_(M1+1),...,e_(M1+M2) in turn, * stopping when a nonzero projection is found * DO I = 1, M2 DO J = 1, M1 X1(J) = ZERO END DO DO J = 1, M2 X2(J) = ZERO END DO X2(I) = ONE CALL CUNBDB6( M1, M2, N, X1, INCX1, X2, INCX2, Q1, LDQ1, Q2, $ LDQ2, WORK, LWORK, CHILDINFO ) IF( SCNRM2(M1,X1,INCX1) .NE. ZERO $ .OR. SCNRM2(M2,X2,INCX2) .NE. ZERO ) THEN RETURN END IF END DO * RETURN * * End of CUNBDB5 * END
bsd-3-clause
buaasun/grappa
applications/NPB/MPI/BT/x_solve.f
6
29283
c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_solve c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c c Performs line solves in X direction by first factoring c the block-tridiagonal matrix into an upper triangular matrix, c and then performing back substitution to solve for the unknow c vectors of each line. c c Make sure we treat elements zero to cell_size in the direction c of the sweep. c c--------------------------------------------------------------------- include 'header.h' include 'mpinpb.h' integer c, istart, stage, > first, last, recv_id, error, r_status(MPI_STATUS_SIZE), > isize,jsize,ksize,send_id istart = 0 if (timeron) call timer_start(t_xsolve) c--------------------------------------------------------------------- c in our terminology stage is the number of the cell in the x-direction c i.e. stage = 1 means the start of the line stage=ncells means end c--------------------------------------------------------------------- do stage = 1,ncells c = slice(1,stage) isize = cell_size(1,c) - 1 jsize = cell_size(2,c) - 1 ksize = cell_size(3,c) - 1 c--------------------------------------------------------------------- c set last-cell flag c--------------------------------------------------------------------- if (stage .eq. ncells) then last = 1 else last = 0 endif if (stage .eq. 1) then c--------------------------------------------------------------------- c This is the first cell, so solve without receiving data c--------------------------------------------------------------------- first = 1 c call lhsx(c) call x_solve_cell(first,last,c) else c--------------------------------------------------------------------- c Not the first cell of this line, so receive info from c processor working on preceeding cell c--------------------------------------------------------------------- first = 0 if (timeron) call timer_start(t_xcomm) call x_receive_solve_info(recv_id,c) c--------------------------------------------------------------------- c overlap computations and communications c--------------------------------------------------------------------- c call lhsx(c) c--------------------------------------------------------------------- c wait for completion c--------------------------------------------------------------------- call mpi_wait(send_id,r_status,error) call mpi_wait(recv_id,r_status,error) if (timeron) call timer_stop(t_xcomm) c--------------------------------------------------------------------- c install C'(istart) and rhs'(istart) to be used in this cell c--------------------------------------------------------------------- call x_unpack_solve_info(c) call x_solve_cell(first,last,c) endif if (last .eq. 0) call x_send_solve_info(send_id,c) enddo c--------------------------------------------------------------------- c now perform backsubstitution in reverse direction c--------------------------------------------------------------------- do stage = ncells, 1, -1 c = slice(1,stage) first = 0 last = 0 if (stage .eq. 1) first = 1 if (stage .eq. ncells) then last = 1 c--------------------------------------------------------------------- c last cell, so perform back substitute without waiting c--------------------------------------------------------------------- call x_backsubstitute(first, last,c) else if (timeron) call timer_start(t_xcomm) call x_receive_backsub_info(recv_id,c) call mpi_wait(send_id,r_status,error) call mpi_wait(recv_id,r_status,error) if (timeron) call timer_stop(t_xcomm) call x_unpack_backsub_info(c) call x_backsubstitute(first,last,c) endif if (first .eq. 0) call x_send_backsub_info(send_id,c) enddo if (timeron) call timer_stop(t_xsolve) return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_unpack_solve_info(c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c unpack C'(-1) and rhs'(-1) for c all j and k c--------------------------------------------------------------------- include 'header.h' integer j,k,m,n,ptr,c,istart istart = 0 ptr = 0 do k=0,KMAX-1 do j=0,JMAX-1 do m=1,BLOCK_SIZE do n=1,BLOCK_SIZE lhsc(m,n,istart-1,j,k,c) = out_buffer(ptr+n) enddo ptr = ptr+BLOCK_SIZE enddo do n=1,BLOCK_SIZE rhs(n,istart-1,j,k,c) = out_buffer(ptr+n) enddo ptr = ptr+BLOCK_SIZE enddo enddo return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_send_solve_info(send_id,c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c pack up and send C'(iend) and rhs'(iend) for c all j and k c--------------------------------------------------------------------- include 'header.h' include 'mpinpb.h' integer j,k,m,n,isize,ptr,c,jp,kp integer error,send_id,buffer_size isize = cell_size(1,c)-1 jp = cell_coord(2,c) - 1 kp = cell_coord(3,c) - 1 buffer_size=MAX_CELL_DIM*MAX_CELL_DIM* > (BLOCK_SIZE*BLOCK_SIZE + BLOCK_SIZE) c--------------------------------------------------------------------- c pack up buffer c--------------------------------------------------------------------- ptr = 0 do k=0,KMAX-1 do j=0,JMAX-1 do m=1,BLOCK_SIZE do n=1,BLOCK_SIZE in_buffer(ptr+n) = lhsc(m,n,isize,j,k,c) enddo ptr = ptr+BLOCK_SIZE enddo do n=1,BLOCK_SIZE in_buffer(ptr+n) = rhs(n,isize,j,k,c) enddo ptr = ptr+BLOCK_SIZE enddo enddo c--------------------------------------------------------------------- c send buffer c--------------------------------------------------------------------- if (timeron) call timer_start(t_xcomm) call mpi_isend(in_buffer, buffer_size, > dp_type, successor(1), > WEST+jp+kp*NCELLS, comm_solve, > send_id,error) if (timeron) call timer_stop(t_xcomm) return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_send_backsub_info(send_id,c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c pack up and send U(istart) for all j and k c--------------------------------------------------------------------- include 'header.h' include 'mpinpb.h' integer j,k,n,ptr,c,istart,jp,kp integer error,send_id,buffer_size c--------------------------------------------------------------------- c Send element 0 to previous processor c--------------------------------------------------------------------- istart = 0 jp = cell_coord(2,c)-1 kp = cell_coord(3,c)-1 buffer_size=MAX_CELL_DIM*MAX_CELL_DIM*BLOCK_SIZE ptr = 0 do k=0,KMAX-1 do j=0,JMAX-1 do n=1,BLOCK_SIZE in_buffer(ptr+n) = rhs(n,istart,j,k,c) enddo ptr = ptr+BLOCK_SIZE enddo enddo if (timeron) call timer_start(t_xcomm) call mpi_isend(in_buffer, buffer_size, > dp_type, predecessor(1), > EAST+jp+kp*NCELLS, comm_solve, > send_id,error) if (timeron) call timer_stop(t_xcomm) return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_unpack_backsub_info(c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c unpack U(isize) for all j and k c--------------------------------------------------------------------- include 'header.h' integer j,k,n,ptr,c ptr = 0 do k=0,KMAX-1 do j=0,JMAX-1 do n=1,BLOCK_SIZE backsub_info(n,j,k,c) = out_buffer(ptr+n) enddo ptr = ptr+BLOCK_SIZE enddo enddo return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_receive_backsub_info(recv_id,c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c post mpi receives c--------------------------------------------------------------------- include 'header.h' include 'mpinpb.h' integer error,recv_id,jp,kp,c,buffer_size jp = cell_coord(2,c) - 1 kp = cell_coord(3,c) - 1 buffer_size=MAX_CELL_DIM*MAX_CELL_DIM*BLOCK_SIZE call mpi_irecv(out_buffer, buffer_size, > dp_type, successor(1), > EAST+jp+kp*NCELLS, comm_solve, > recv_id, error) return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_receive_solve_info(recv_id,c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c post mpi receives c--------------------------------------------------------------------- include 'header.h' include 'mpinpb.h' integer jp,kp,recv_id,error,c,buffer_size jp = cell_coord(2,c) - 1 kp = cell_coord(3,c) - 1 buffer_size=MAX_CELL_DIM*MAX_CELL_DIM* > (BLOCK_SIZE*BLOCK_SIZE + BLOCK_SIZE) call mpi_irecv(out_buffer, buffer_size, > dp_type, predecessor(1), > WEST+jp+kp*NCELLS, comm_solve, > recv_id, error) return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_backsubstitute(first, last, c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c back solve: if last cell, then generate U(isize)=rhs(isize) c else assume U(isize) is loaded in un pack backsub_info c so just use it c after call u(istart) will be sent to next cell c--------------------------------------------------------------------- include 'header.h' integer first, last, c, i, j, k integer m,n,isize,jsize,ksize,istart istart = 0 isize = cell_size(1,c)-1 jsize = cell_size(2,c)-end(2,c)-1 ksize = cell_size(3,c)-end(3,c)-1 if (last .eq. 0) then do k=start(3,c),ksize do j=start(2,c),jsize c--------------------------------------------------------------------- c U(isize) uses info from previous cell if not last cell c--------------------------------------------------------------------- do m=1,BLOCK_SIZE do n=1,BLOCK_SIZE rhs(m,isize,j,k,c) = rhs(m,isize,j,k,c) > - lhsc(m,n,isize,j,k,c)* > backsub_info(n,j,k,c) c--------------------------------------------------------------------- c rhs(m,isize,j,k,c) = rhs(m,isize,j,k,c) c $ - lhsc(m,n,isize,j,k,c)*rhs(n,isize+1,j,k,c) c--------------------------------------------------------------------- enddo enddo enddo enddo endif do k=start(3,c),ksize do j=start(2,c),jsize do i=isize-1,istart,-1 do m=1,BLOCK_SIZE do n=1,BLOCK_SIZE rhs(m,i,j,k,c) = rhs(m,i,j,k,c) > - lhsc(m,n,i,j,k,c)*rhs(n,i+1,j,k,c) enddo enddo enddo enddo enddo return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine x_solve_cell(first,last,c) c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c performs guaussian elimination on this cell. c c assumes that unpacking routines for non-first cells c preload C' and rhs' from previous cell. c c assumed send happens outside this routine, but that c c'(IMAX) and rhs'(IMAX) will be sent to next cell c--------------------------------------------------------------------- include 'header.h' include 'work_lhs.h' integer first,last,c integer i,j,k,isize,ksize,jsize,istart istart = 0 isize = cell_size(1,c)-1 jsize = cell_size(2,c)-end(2,c)-1 ksize = cell_size(3,c)-end(3,c)-1 call lhsabinit(lhsa, lhsb, isize) do k=start(3,c),ksize do j=start(2,c),jsize c--------------------------------------------------------------------- c This function computes the left hand side in the xi-direction c--------------------------------------------------------------------- c--------------------------------------------------------------------- c determine a (labeled f) and n jacobians for cell c c--------------------------------------------------------------------- do i = start(1,c)-1, cell_size(1,c) - end(1,c) tmp1 = rho_i(i,j,k,c) tmp2 = tmp1 * tmp1 tmp3 = tmp1 * tmp2 c--------------------------------------------------------------------- c c--------------------------------------------------------------------- fjac(1,1,i) = 0.0d+00 fjac(1,2,i) = 1.0d+00 fjac(1,3,i) = 0.0d+00 fjac(1,4,i) = 0.0d+00 fjac(1,5,i) = 0.0d+00 fjac(2,1,i) = -(u(2,i,j,k,c) * tmp2 * > u(2,i,j,k,c)) > + c2 * qs(i,j,k,c) fjac(2,2,i) = ( 2.0d+00 - c2 ) > * ( u(2,i,j,k,c) * tmp1 ) fjac(2,3,i) = - c2 * ( u(3,i,j,k,c) * tmp1 ) fjac(2,4,i) = - c2 * ( u(4,i,j,k,c) * tmp1 ) fjac(2,5,i) = c2 fjac(3,1,i) = - ( u(2,i,j,k,c)*u(3,i,j,k,c) ) * tmp2 fjac(3,2,i) = u(3,i,j,k,c) * tmp1 fjac(3,3,i) = u(2,i,j,k,c) * tmp1 fjac(3,4,i) = 0.0d+00 fjac(3,5,i) = 0.0d+00 fjac(4,1,i) = - ( u(2,i,j,k,c)*u(4,i,j,k,c) ) * tmp2 fjac(4,2,i) = u(4,i,j,k,c) * tmp1 fjac(4,3,i) = 0.0d+00 fjac(4,4,i) = u(2,i,j,k,c) * tmp1 fjac(4,5,i) = 0.0d+00 fjac(5,1,i) = ( c2 * 2.0d0 * qs(i,j,k,c) > - c1 * ( u(5,i,j,k,c) * tmp1 ) ) > * ( u(2,i,j,k,c) * tmp1 ) fjac(5,2,i) = c1 * u(5,i,j,k,c) * tmp1 > - c2 > * ( u(2,i,j,k,c)*u(2,i,j,k,c) * tmp2 > + qs(i,j,k,c) ) fjac(5,3,i) = - c2 * ( u(3,i,j,k,c)*u(2,i,j,k,c) ) > * tmp2 fjac(5,4,i) = - c2 * ( u(4,i,j,k,c)*u(2,i,j,k,c) ) > * tmp2 fjac(5,5,i) = c1 * ( u(2,i,j,k,c) * tmp1 ) njac(1,1,i) = 0.0d+00 njac(1,2,i) = 0.0d+00 njac(1,3,i) = 0.0d+00 njac(1,4,i) = 0.0d+00 njac(1,5,i) = 0.0d+00 njac(2,1,i) = - con43 * c3c4 * tmp2 * u(2,i,j,k,c) njac(2,2,i) = con43 * c3c4 * tmp1 njac(2,3,i) = 0.0d+00 njac(2,4,i) = 0.0d+00 njac(2,5,i) = 0.0d+00 njac(3,1,i) = - c3c4 * tmp2 * u(3,i,j,k,c) njac(3,2,i) = 0.0d+00 njac(3,3,i) = c3c4 * tmp1 njac(3,4,i) = 0.0d+00 njac(3,5,i) = 0.0d+00 njac(4,1,i) = - c3c4 * tmp2 * u(4,i,j,k,c) njac(4,2,i) = 0.0d+00 njac(4,3,i) = 0.0d+00 njac(4,4,i) = c3c4 * tmp1 njac(4,5,i) = 0.0d+00 njac(5,1,i) = - ( con43 * c3c4 > - c1345 ) * tmp3 * (u(2,i,j,k,c)**2) > - ( c3c4 - c1345 ) * tmp3 * (u(3,i,j,k,c)**2) > - ( c3c4 - c1345 ) * tmp3 * (u(4,i,j,k,c)**2) > - c1345 * tmp2 * u(5,i,j,k,c) njac(5,2,i) = ( con43 * c3c4 > - c1345 ) * tmp2 * u(2,i,j,k,c) njac(5,3,i) = ( c3c4 - c1345 ) * tmp2 * u(3,i,j,k,c) njac(5,4,i) = ( c3c4 - c1345 ) * tmp2 * u(4,i,j,k,c) njac(5,5,i) = ( c1345 ) * tmp1 enddo c--------------------------------------------------------------------- c now jacobians set, so form left hand side in x direction c--------------------------------------------------------------------- do i = start(1,c), isize - end(1,c) tmp1 = dt * tx1 tmp2 = dt * tx2 lhsa(1,1,i) = - tmp2 * fjac(1,1,i-1) > - tmp1 * njac(1,1,i-1) > - tmp1 * dx1 lhsa(1,2,i) = - tmp2 * fjac(1,2,i-1) > - tmp1 * njac(1,2,i-1) lhsa(1,3,i) = - tmp2 * fjac(1,3,i-1) > - tmp1 * njac(1,3,i-1) lhsa(1,4,i) = - tmp2 * fjac(1,4,i-1) > - tmp1 * njac(1,4,i-1) lhsa(1,5,i) = - tmp2 * fjac(1,5,i-1) > - tmp1 * njac(1,5,i-1) lhsa(2,1,i) = - tmp2 * fjac(2,1,i-1) > - tmp1 * njac(2,1,i-1) lhsa(2,2,i) = - tmp2 * fjac(2,2,i-1) > - tmp1 * njac(2,2,i-1) > - tmp1 * dx2 lhsa(2,3,i) = - tmp2 * fjac(2,3,i-1) > - tmp1 * njac(2,3,i-1) lhsa(2,4,i) = - tmp2 * fjac(2,4,i-1) > - tmp1 * njac(2,4,i-1) lhsa(2,5,i) = - tmp2 * fjac(2,5,i-1) > - tmp1 * njac(2,5,i-1) lhsa(3,1,i) = - tmp2 * fjac(3,1,i-1) > - tmp1 * njac(3,1,i-1) lhsa(3,2,i) = - tmp2 * fjac(3,2,i-1) > - tmp1 * njac(3,2,i-1) lhsa(3,3,i) = - tmp2 * fjac(3,3,i-1) > - tmp1 * njac(3,3,i-1) > - tmp1 * dx3 lhsa(3,4,i) = - tmp2 * fjac(3,4,i-1) > - tmp1 * njac(3,4,i-1) lhsa(3,5,i) = - tmp2 * fjac(3,5,i-1) > - tmp1 * njac(3,5,i-1) lhsa(4,1,i) = - tmp2 * fjac(4,1,i-1) > - tmp1 * njac(4,1,i-1) lhsa(4,2,i) = - tmp2 * fjac(4,2,i-1) > - tmp1 * njac(4,2,i-1) lhsa(4,3,i) = - tmp2 * fjac(4,3,i-1) > - tmp1 * njac(4,3,i-1) lhsa(4,4,i) = - tmp2 * fjac(4,4,i-1) > - tmp1 * njac(4,4,i-1) > - tmp1 * dx4 lhsa(4,5,i) = - tmp2 * fjac(4,5,i-1) > - tmp1 * njac(4,5,i-1) lhsa(5,1,i) = - tmp2 * fjac(5,1,i-1) > - tmp1 * njac(5,1,i-1) lhsa(5,2,i) = - tmp2 * fjac(5,2,i-1) > - tmp1 * njac(5,2,i-1) lhsa(5,3,i) = - tmp2 * fjac(5,3,i-1) > - tmp1 * njac(5,3,i-1) lhsa(5,4,i) = - tmp2 * fjac(5,4,i-1) > - tmp1 * njac(5,4,i-1) lhsa(5,5,i) = - tmp2 * fjac(5,5,i-1) > - tmp1 * njac(5,5,i-1) > - tmp1 * dx5 lhsb(1,1,i) = 1.0d+00 > + tmp1 * 2.0d+00 * njac(1,1,i) > + tmp1 * 2.0d+00 * dx1 lhsb(1,2,i) = tmp1 * 2.0d+00 * njac(1,2,i) lhsb(1,3,i) = tmp1 * 2.0d+00 * njac(1,3,i) lhsb(1,4,i) = tmp1 * 2.0d+00 * njac(1,4,i) lhsb(1,5,i) = tmp1 * 2.0d+00 * njac(1,5,i) lhsb(2,1,i) = tmp1 * 2.0d+00 * njac(2,1,i) lhsb(2,2,i) = 1.0d+00 > + tmp1 * 2.0d+00 * njac(2,2,i) > + tmp1 * 2.0d+00 * dx2 lhsb(2,3,i) = tmp1 * 2.0d+00 * njac(2,3,i) lhsb(2,4,i) = tmp1 * 2.0d+00 * njac(2,4,i) lhsb(2,5,i) = tmp1 * 2.0d+00 * njac(2,5,i) lhsb(3,1,i) = tmp1 * 2.0d+00 * njac(3,1,i) lhsb(3,2,i) = tmp1 * 2.0d+00 * njac(3,2,i) lhsb(3,3,i) = 1.0d+00 > + tmp1 * 2.0d+00 * njac(3,3,i) > + tmp1 * 2.0d+00 * dx3 lhsb(3,4,i) = tmp1 * 2.0d+00 * njac(3,4,i) lhsb(3,5,i) = tmp1 * 2.0d+00 * njac(3,5,i) lhsb(4,1,i) = tmp1 * 2.0d+00 * njac(4,1,i) lhsb(4,2,i) = tmp1 * 2.0d+00 * njac(4,2,i) lhsb(4,3,i) = tmp1 * 2.0d+00 * njac(4,3,i) lhsb(4,4,i) = 1.0d+00 > + tmp1 * 2.0d+00 * njac(4,4,i) > + tmp1 * 2.0d+00 * dx4 lhsb(4,5,i) = tmp1 * 2.0d+00 * njac(4,5,i) lhsb(5,1,i) = tmp1 * 2.0d+00 * njac(5,1,i) lhsb(5,2,i) = tmp1 * 2.0d+00 * njac(5,2,i) lhsb(5,3,i) = tmp1 * 2.0d+00 * njac(5,3,i) lhsb(5,4,i) = tmp1 * 2.0d+00 * njac(5,4,i) lhsb(5,5,i) = 1.0d+00 > + tmp1 * 2.0d+00 * njac(5,5,i) > + tmp1 * 2.0d+00 * dx5 lhsc(1,1,i,j,k,c) = tmp2 * fjac(1,1,i+1) > - tmp1 * njac(1,1,i+1) > - tmp1 * dx1 lhsc(1,2,i,j,k,c) = tmp2 * fjac(1,2,i+1) > - tmp1 * njac(1,2,i+1) lhsc(1,3,i,j,k,c) = tmp2 * fjac(1,3,i+1) > - tmp1 * njac(1,3,i+1) lhsc(1,4,i,j,k,c) = tmp2 * fjac(1,4,i+1) > - tmp1 * njac(1,4,i+1) lhsc(1,5,i,j,k,c) = tmp2 * fjac(1,5,i+1) > - tmp1 * njac(1,5,i+1) lhsc(2,1,i,j,k,c) = tmp2 * fjac(2,1,i+1) > - tmp1 * njac(2,1,i+1) lhsc(2,2,i,j,k,c) = tmp2 * fjac(2,2,i+1) > - tmp1 * njac(2,2,i+1) > - tmp1 * dx2 lhsc(2,3,i,j,k,c) = tmp2 * fjac(2,3,i+1) > - tmp1 * njac(2,3,i+1) lhsc(2,4,i,j,k,c) = tmp2 * fjac(2,4,i+1) > - tmp1 * njac(2,4,i+1) lhsc(2,5,i,j,k,c) = tmp2 * fjac(2,5,i+1) > - tmp1 * njac(2,5,i+1) lhsc(3,1,i,j,k,c) = tmp2 * fjac(3,1,i+1) > - tmp1 * njac(3,1,i+1) lhsc(3,2,i,j,k,c) = tmp2 * fjac(3,2,i+1) > - tmp1 * njac(3,2,i+1) lhsc(3,3,i,j,k,c) = tmp2 * fjac(3,3,i+1) > - tmp1 * njac(3,3,i+1) > - tmp1 * dx3 lhsc(3,4,i,j,k,c) = tmp2 * fjac(3,4,i+1) > - tmp1 * njac(3,4,i+1) lhsc(3,5,i,j,k,c) = tmp2 * fjac(3,5,i+1) > - tmp1 * njac(3,5,i+1) lhsc(4,1,i,j,k,c) = tmp2 * fjac(4,1,i+1) > - tmp1 * njac(4,1,i+1) lhsc(4,2,i,j,k,c) = tmp2 * fjac(4,2,i+1) > - tmp1 * njac(4,2,i+1) lhsc(4,3,i,j,k,c) = tmp2 * fjac(4,3,i+1) > - tmp1 * njac(4,3,i+1) lhsc(4,4,i,j,k,c) = tmp2 * fjac(4,4,i+1) > - tmp1 * njac(4,4,i+1) > - tmp1 * dx4 lhsc(4,5,i,j,k,c) = tmp2 * fjac(4,5,i+1) > - tmp1 * njac(4,5,i+1) lhsc(5,1,i,j,k,c) = tmp2 * fjac(5,1,i+1) > - tmp1 * njac(5,1,i+1) lhsc(5,2,i,j,k,c) = tmp2 * fjac(5,2,i+1) > - tmp1 * njac(5,2,i+1) lhsc(5,3,i,j,k,c) = tmp2 * fjac(5,3,i+1) > - tmp1 * njac(5,3,i+1) lhsc(5,4,i,j,k,c) = tmp2 * fjac(5,4,i+1) > - tmp1 * njac(5,4,i+1) lhsc(5,5,i,j,k,c) = tmp2 * fjac(5,5,i+1) > - tmp1 * njac(5,5,i+1) > - tmp1 * dx5 enddo c--------------------------------------------------------------------- c outer most do loops - sweeping in i direction c--------------------------------------------------------------------- if (first .eq. 1) then c--------------------------------------------------------------------- c multiply c(istart,j,k) by b_inverse and copy back to c c multiply rhs(istart) by b_inverse(istart) and copy to rhs c--------------------------------------------------------------------- call binvcrhs( lhsb(1,1,istart), > lhsc(1,1,istart,j,k,c), > rhs(1,istart,j,k,c) ) endif c--------------------------------------------------------------------- c begin inner most do loop c do all the elements of the cell unless last c--------------------------------------------------------------------- do i=istart+first,isize-last c--------------------------------------------------------------------- c rhs(i) = rhs(i) - A*rhs(i-1) c--------------------------------------------------------------------- call matvec_sub(lhsa(1,1,i), > rhs(1,i-1,j,k,c),rhs(1,i,j,k,c)) c--------------------------------------------------------------------- c B(i) = B(i) - C(i-1)*A(i) c--------------------------------------------------------------------- call matmul_sub(lhsa(1,1,i), > lhsc(1,1,i-1,j,k,c), > lhsb(1,1,i)) c--------------------------------------------------------------------- c multiply c(i,j,k) by b_inverse and copy back to c c multiply rhs(1,j,k) by b_inverse(1,j,k) and copy to rhs c--------------------------------------------------------------------- call binvcrhs( lhsb(1,1,i), > lhsc(1,1,i,j,k,c), > rhs(1,i,j,k,c) ) enddo c--------------------------------------------------------------------- c Now finish up special cases for last cell c--------------------------------------------------------------------- if (last .eq. 1) then c--------------------------------------------------------------------- c rhs(isize) = rhs(isize) - A*rhs(isize-1) c--------------------------------------------------------------------- call matvec_sub(lhsa(1,1,isize), > rhs(1,isize-1,j,k,c),rhs(1,isize,j,k,c)) c--------------------------------------------------------------------- c B(isize) = B(isize) - C(isize-1)*A(isize) c--------------------------------------------------------------------- call matmul_sub(lhsa(1,1,isize), > lhsc(1,1,isize-1,j,k,c), > lhsb(1,1,isize)) c--------------------------------------------------------------------- c multiply rhs() by b_inverse() and copy to rhs c--------------------------------------------------------------------- call binvrhs( lhsb(1,1,isize), > rhs(1,isize,j,k,c) ) endif enddo enddo return end
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/ssptri.f
29
11729
*> \brief \b SSPTRI * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SSPTRI + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssptri.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssptri.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssptri.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SSPTRI( UPLO, N, AP, IPIV, WORK, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, N * .. * .. Array Arguments .. * INTEGER IPIV( * ) * REAL AP( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SSPTRI computes the inverse of a real symmetric indefinite matrix *> A in packed storage using the factorization A = U*D*U**T or *> A = L*D*L**T computed by SSPTRF. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies whether the details of the factorization are stored *> as an upper or lower triangular matrix. *> = 'U': Upper triangular, form is A = U*D*U**T; *> = 'L': Lower triangular, form is A = L*D*L**T. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] AP *> \verbatim *> AP is REAL array, dimension (N*(N+1)/2) *> On entry, the block diagonal matrix D and the multipliers *> used to obtain the factor U or L as computed by SSPTRF, *> stored as a packed triangular matrix. *> *> On exit, if INFO = 0, the (symmetric) inverse of the original *> matrix, stored as a packed triangular matrix. The j-th column *> of inv(A) is stored in the array AP as follows: *> if UPLO = 'U', AP(i + (j-1)*j/2) = inv(A)(i,j) for 1<=i<=j; *> if UPLO = 'L', *> AP(i + (j-1)*(2n-j)/2) = inv(A)(i,j) for j<=i<=n. *> \endverbatim *> *> \param[in] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> Details of the interchanges and the block structure of D *> as determined by SSPTRF. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its *> inverse could not be computed. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup realOTHERcomputational * * ===================================================================== SUBROUTINE SSPTRI( UPLO, N, AP, IPIV, WORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, N * .. * .. Array Arguments .. INTEGER IPIV( * ) REAL AP( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ONE, ZERO PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER J, K, KC, KCNEXT, KP, KPC, KSTEP, KX, NPP REAL AK, AKKP1, AKP1, D, T, TEMP * .. * .. External Functions .. LOGICAL LSAME REAL SDOT EXTERNAL LSAME, SDOT * .. * .. External Subroutines .. EXTERNAL SCOPY, SSPMV, SSWAP, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS * .. * .. 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( 'SSPTRI', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * Check that the diagonal matrix D is nonsingular. * IF( UPPER ) THEN * * Upper triangular storage: examine D from bottom to top * KP = N*( N+1 ) / 2 DO 10 INFO = N, 1, -1 IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO ) $ RETURN KP = KP - INFO 10 CONTINUE ELSE * * Lower triangular storage: examine D from top to bottom. * KP = 1 DO 20 INFO = 1, N IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO ) $ RETURN KP = KP + N - INFO + 1 20 CONTINUE END IF INFO = 0 * IF( UPPER ) THEN * * Compute inv(A) from the factorization A = U*D*U**T. * * K is the main loop index, increasing from 1 to N in steps of * 1 or 2, depending on the size of the diagonal blocks. * K = 1 KC = 1 30 CONTINUE * * If K > N, exit from loop. * IF( K.GT.N ) $ GO TO 50 * KCNEXT = KC + K IF( IPIV( K ).GT.0 ) THEN * * 1 x 1 diagonal block * * Invert the diagonal block. * AP( KC+K-1 ) = ONE / AP( KC+K-1 ) * * Compute column K of the inverse. * IF( K.GT.1 ) THEN CALL SCOPY( K-1, AP( KC ), 1, WORK, 1 ) CALL SSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO, AP( KC ), $ 1 ) AP( KC+K-1 ) = AP( KC+K-1 ) - $ SDOT( K-1, WORK, 1, AP( KC ), 1 ) END IF KSTEP = 1 ELSE * * 2 x 2 diagonal block * * Invert the diagonal block. * T = ABS( AP( KCNEXT+K-1 ) ) AK = AP( KC+K-1 ) / T AKP1 = AP( KCNEXT+K ) / T AKKP1 = AP( KCNEXT+K-1 ) / T D = T*( AK*AKP1-ONE ) AP( KC+K-1 ) = AKP1 / D AP( KCNEXT+K ) = AK / D AP( KCNEXT+K-1 ) = -AKKP1 / D * * Compute columns K and K+1 of the inverse. * IF( K.GT.1 ) THEN CALL SCOPY( K-1, AP( KC ), 1, WORK, 1 ) CALL SSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO, AP( KC ), $ 1 ) AP( KC+K-1 ) = AP( KC+K-1 ) - $ SDOT( K-1, WORK, 1, AP( KC ), 1 ) AP( KCNEXT+K-1 ) = AP( KCNEXT+K-1 ) - $ SDOT( K-1, AP( KC ), 1, AP( KCNEXT ), $ 1 ) CALL SCOPY( K-1, AP( KCNEXT ), 1, WORK, 1 ) CALL SSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO, $ AP( KCNEXT ), 1 ) AP( KCNEXT+K ) = AP( KCNEXT+K ) - $ SDOT( K-1, WORK, 1, AP( KCNEXT ), 1 ) END IF KSTEP = 2 KCNEXT = KCNEXT + K + 1 END IF * KP = ABS( IPIV( K ) ) IF( KP.NE.K ) THEN * * Interchange rows and columns K and KP in the leading * submatrix A(1:k+1,1:k+1) * KPC = ( KP-1 )*KP / 2 + 1 CALL SSWAP( KP-1, AP( KC ), 1, AP( KPC ), 1 ) KX = KPC + KP - 1 DO 40 J = KP + 1, K - 1 KX = KX + J - 1 TEMP = AP( KC+J-1 ) AP( KC+J-1 ) = AP( KX ) AP( KX ) = TEMP 40 CONTINUE TEMP = AP( KC+K-1 ) AP( KC+K-1 ) = AP( KPC+KP-1 ) AP( KPC+KP-1 ) = TEMP IF( KSTEP.EQ.2 ) THEN TEMP = AP( KC+K+K-1 ) AP( KC+K+K-1 ) = AP( KC+K+KP-1 ) AP( KC+K+KP-1 ) = TEMP END IF END IF * K = K + KSTEP KC = KCNEXT GO TO 30 50 CONTINUE * ELSE * * Compute inv(A) from the factorization A = L*D*L**T. * * K is the main loop index, increasing from 1 to N in steps of * 1 or 2, depending on the size of the diagonal blocks. * NPP = N*( N+1 ) / 2 K = N KC = NPP 60 CONTINUE * * If K < 1, exit from loop. * IF( K.LT.1 ) $ GO TO 80 * KCNEXT = KC - ( N-K+2 ) IF( IPIV( K ).GT.0 ) THEN * * 1 x 1 diagonal block * * Invert the diagonal block. * AP( KC ) = ONE / AP( KC ) * * Compute column K of the inverse. * IF( K.LT.N ) THEN CALL SCOPY( N-K, AP( KC+1 ), 1, WORK, 1 ) CALL SSPMV( UPLO, N-K, -ONE, AP( KC+N-K+1 ), WORK, 1, $ ZERO, AP( KC+1 ), 1 ) AP( KC ) = AP( KC ) - SDOT( N-K, WORK, 1, AP( KC+1 ), 1 ) END IF KSTEP = 1 ELSE * * 2 x 2 diagonal block * * Invert the diagonal block. * T = ABS( AP( KCNEXT+1 ) ) AK = AP( KCNEXT ) / T AKP1 = AP( KC ) / T AKKP1 = AP( KCNEXT+1 ) / T D = T*( AK*AKP1-ONE ) AP( KCNEXT ) = AKP1 / D AP( KC ) = AK / D AP( KCNEXT+1 ) = -AKKP1 / D * * Compute columns K-1 and K of the inverse. * IF( K.LT.N ) THEN CALL SCOPY( N-K, AP( KC+1 ), 1, WORK, 1 ) CALL SSPMV( UPLO, N-K, -ONE, AP( KC+( N-K+1 ) ), WORK, 1, $ ZERO, AP( KC+1 ), 1 ) AP( KC ) = AP( KC ) - SDOT( N-K, WORK, 1, AP( KC+1 ), 1 ) AP( KCNEXT+1 ) = AP( KCNEXT+1 ) - $ SDOT( N-K, AP( KC+1 ), 1, $ AP( KCNEXT+2 ), 1 ) CALL SCOPY( N-K, AP( KCNEXT+2 ), 1, WORK, 1 ) CALL SSPMV( UPLO, N-K, -ONE, AP( KC+( N-K+1 ) ), WORK, 1, $ ZERO, AP( KCNEXT+2 ), 1 ) AP( KCNEXT ) = AP( KCNEXT ) - $ SDOT( N-K, WORK, 1, AP( KCNEXT+2 ), 1 ) END IF KSTEP = 2 KCNEXT = KCNEXT - ( N-K+3 ) END IF * KP = ABS( IPIV( K ) ) IF( KP.NE.K ) THEN * * Interchange rows and columns K and KP in the trailing * submatrix A(k-1:n,k-1:n) * KPC = NPP - ( N-KP+1 )*( N-KP+2 ) / 2 + 1 IF( KP.LT.N ) $ CALL SSWAP( N-KP, AP( KC+KP-K+1 ), 1, AP( KPC+1 ), 1 ) KX = KC + KP - K DO 70 J = K + 1, KP - 1 KX = KX + N - J + 1 TEMP = AP( KC+J-K ) AP( KC+J-K ) = AP( KX ) AP( KX ) = TEMP 70 CONTINUE TEMP = AP( KC ) AP( KC ) = AP( KPC ) AP( KPC ) = TEMP IF( KSTEP.EQ.2 ) THEN TEMP = AP( KC-N+K-1 ) AP( KC-N+K-1 ) = AP( KC-N+KP-1 ) AP( KC-N+KP-1 ) = TEMP END IF END IF * K = K - KSTEP KC = KCNEXT GO TO 60 80 CONTINUE END IF * RETURN * * End of SSPTRI * END
bsd-3-clause
sophAi/ptmd
src/bac/usr_score_file.f
1
3244
*======================================================================== * File Name : usr_score_file.f * Copyright (C) 2008-2011 Po-Jen Hsu <xanadu8850@pchome.com.tw> * Creation Date : 19-04-2010 * Last Modified : 2010年10月21日 (週四) 09時25分08秒 * License : GPL (see bottom) * Encoding : utf-8 * Project : sophAi * Description : * ======================================================================== subroutine usr_score_file implicit none include "../../include/global_common.h" include "../../include/common.h" include "../../include/file.h" include "../../include/job.h" include "../../include/tools/score.h" include "../../include/tester/tester.h" job_skip=.false. if(source_file_flag.eq.0)then !default input file name score_target_file_name="target.mom" score_result_file_name="result_mean.scr" moment_result_file_name="result.mom" score_time_file_name="result.scr" score_source_file_name=source_file(:index(source_file," ")-1) else call file_assignment score_source_file_name= &source_path(:index(source_path," ")-1)//simulation_type//"_"// &source_type//"_"//pes_file_name(:index(pes_file_name," ")-1)// &"."//source_type moment_result_file_name= &result_root_path(:index(result_root_path," ")-1)// &mom_path(:index(mom_path," ")-1)//simulation_type//"_"// &source_type//"_"//pes_file_name(:index(pes_file_name," ")-1)// &".mom" write(*,*) moment_result_file_name score_target_file_name= &result_root_path(:index(result_root_path," ")-1)// &mom_path(:index(mom_path," ")-1)// &"target.mom" moment_result_file_name= &result_root_path(:index(result_root_path," ")-1)// &mom_path(:index(usr_path," ")-1)// &simulation_type//"_"//source_type//"_"// &pes_file_name(:index(pes_file_name," ")-1)//"."//source_type score_result_file_name= &result_root_path(:index(result_root_path," ")-1)// &scr_path(:index(scr_path," ")-1)// &"result_mean.scr" score_time_file_name= &result_root_path(:index(result_root_path," ")-1)// &scr_path(:index(scr_path," ")-1)//simulation_type//"_"// &source_type//"_"//pes_file_name(:index(pes_file_name," ")-1)// &".scr" endif return end * ======================GNU General Public License======================= * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * =======================================================================
gpl-2.0
aarchiba/scipy
scipy/integrate/quadpack/dqagpe.f
146
21286
subroutine dqagpe(f,a,b,npts2,points,epsabs,epsrel,limit,result, * abserr,neval,ier,alist,blist,rlist,elist,pts,iord,level,ndin, * last) c***begin prologue dqagpe c***date written 800101 (yymmdd) c***revision date 830518 (yymmdd) c***category no. h2a2a1 c***keywords automatic integrator, general-purpose, c singularities at user specified points, c extrapolation, globally adaptive. c***author piessens,robert ,appl. math. & progr. div. - k.u.leuven c de doncker,elise,appl. math. & progr. div. - k.u.leuven c***purpose the routine calculates an approximation result to a given c definite integral i = integral of f over (a,b), hopefully c satisfying following claim for accuracy abs(i-result).le. c max(epsabs,epsrel*abs(i)). break points of the integration c interval, where local difficulties of the integrand may c occur(e.g. singularities,discontinuities),provided by user. c***description c c computation of a definite integral c standard fortran subroutine c double precision version c c parameters c on entry c f - double precision c function subprogram defining the integrand c function f(x). the actual name for f needs to be c declared e x t e r n a l in the driver program. c c a - double precision c lower limit of integration c c b - double precision c upper limit of integration c c npts2 - integer c number equal to two more than the number of c user-supplied break points within the integration c range, npts2.ge.2. c if npts2.lt.2, the routine will end with ier = 6. c c points - double precision c vector of dimension npts2, the first (npts2-2) c elements of which are the user provided break c points. if these points do not constitute an c ascending sequence there will be an automatic c sorting. c c epsabs - double precision c absolute accuracy requested c epsrel - double precision c relative accuracy requested c if epsabs.le.0 c and epsrel.lt.max(50*rel.mach.acc.,0.5d-28), c the routine will end with ier = 6. c c limit - integer c gives an upper bound on the number of subintervals c in the partition of (a,b), limit.ge.npts2 c if limit.lt.npts2, the routine will end with c ier = 6. c c on return c result - double precision c approximation to the integral c c abserr - double precision c estimate of the modulus of the absolute error, c which should equal or exceed abs(i-result) c c neval - integer c number of integrand evaluations c c ier - integer c ier = 0 normal and reliable termination of the c routine. it is assumed that the requested c accuracy has been achieved. c ier.gt.0 abnormal termination of the routine. c the estimates for integral and error are c less reliable. it is assumed that the c requested accuracy has not been achieved. c error messages c ier = 1 maximum number of subdivisions allowed c has been achieved. one can allow more c subdivisions by increasing the value of c limit (and taking the according dimension c adjustments into account). however, if c this yields no improvement it is advised c to analyze the integrand in order to c determine the integration difficulties. if c the position of a local difficulty can be c determined (i.e. singularity, c discontinuity within the interval), it c should be supplied to the routine as an c element of the vector points. if necessary c an appropriate special-purpose integrator c must be used, which is designed for c handling the type of difficulty involved. c = 2 the occurrence of roundoff error is c detected, which prevents the requested c tolerance from being achieved. c the error may be under-estimated. c = 3 extremely bad integrand behaviour occurs c at some points of the integration c interval. c = 4 the algorithm does not converge. c roundoff error is detected in the c extrapolation table. it is presumed that c the requested tolerance cannot be c achieved, and that the returned result is c the best which can be obtained. c = 5 the integral is probably divergent, or c slowly convergent. it must be noted that c divergence can occur with any other value c of ier.gt.0. c = 6 the input is invalid because c npts2.lt.2 or c break points are specified outside c the integration range or c (epsabs.le.0 and c epsrel.lt.max(50*rel.mach.acc.,0.5d-28)) c or limit.lt.npts2. c result, abserr, neval, last, rlist(1), c and elist(1) are set to zero. alist(1) and c blist(1) are set to a and b respectively. c c alist - double precision c vector of dimension at least limit, the first c last elements of which are the left end points c of the subintervals in the partition of the given c integration range (a,b) c c blist - double precision c vector of dimension at least limit, the first c last elements of which are the right end points c of the subintervals in the partition of the given c integration range (a,b) c c rlist - double precision c vector of dimension at least limit, the first c last elements of which are the integral c approximations on the subintervals c c elist - double precision c vector of dimension at least limit, the first c last elements of which are the moduli of the c absolute error estimates on the subintervals c c pts - double precision c vector of dimension at least npts2, containing the c integration limits and the break points of the c interval in ascending sequence. c c level - integer c vector of dimension at least limit, containing the c subdivision levels of the subinterval, i.e. if c (aa,bb) is a subinterval of (p1,p2) where p1 as c well as p2 is a user-provided break point or c integration limit, then (aa,bb) has level l if c abs(bb-aa) = abs(p2-p1)*2**(-l). c c ndin - integer c vector of dimension at least npts2, after first c integration over the intervals (pts(i)),pts(i+1), c i = 0,1, ..., npts2-2, the error estimates over c some of the intervals may have been increased c artificially, in order to put their subdivision c forward. if this happens for the subinterval c numbered k, ndin(k) is put to 1, otherwise c ndin(k) = 0. c c iord - integer c vector of dimension at least limit, the first k c elements of which are pointers to the c error estimates over the subintervals, c such that elist(iord(1)), ..., elist(iord(k)) c form a decreasing sequence, with k = last c if last.le.(limit/2+2), and k = limit+1-last c otherwise c c last - integer c number of subintervals actually produced in the c subdivisions process c c***references (none) c***routines called d1mach,dqelg,dqk21,dqpsrt c***end prologue dqagpe double precision a,abseps,abserr,alist,area,area1,area12,area2,a1, * a2,b,blist,b1,b2,correc,dabs,defabs,defab1,defab2,dmax1,dmin1, * dres,d1mach,elist,epmach,epsabs,epsrel,erlarg,erlast,errbnd, * errmax,error1,erro12,error2,errsum,ertest,f,oflow,points,pts, * resa,resabs,reseps,result,res3la,rlist,rlist2,sign,temp,uflow integer i,id,ier,ierro,ind1,ind2,iord,ip1,iroff1,iroff2,iroff3,j, * jlow,jupbnd,k,ksgn,ktmin,last,levcur,level,levmax,limit,maxerr, * ndin,neval,nint,nintp1,npts,npts2,nres,nrmax,numrl2 logical extrap,noext c c dimension alist(limit),blist(limit),elist(limit),iord(limit), * level(limit),ndin(npts2),points(npts2),pts(npts2),res3la(3), * rlist(limit),rlist2(52) c external f c c the dimension of rlist2 is determined by the value of c limexp in subroutine epsalg (rlist2 should be of dimension c (limexp+2) at least). c c c list of major variables c ----------------------- c c alist - list of left end points of all subintervals c considered up to now c blist - list of right end points of all subintervals c considered up to now c rlist(i) - approximation to the integral over c (alist(i),blist(i)) c rlist2 - array of dimension at least limexp+2 c containing the part of the epsilon table which c is still needed for further computations c elist(i) - error estimate applying to rlist(i) c maxerr - pointer to the interval with largest error c estimate c errmax - elist(maxerr) c erlast - error on the interval currently subdivided c (before that subdivision has taken place) c area - sum of the integrals over the subintervals c errsum - sum of the errors over the subintervals c errbnd - requested accuracy max(epsabs,epsrel* c abs(result)) c *****1 - variable for the left subinterval c *****2 - variable for the right subinterval c last - index for subdivision c nres - number of calls to the extrapolation routine c numrl2 - number of elements in rlist2. if an appropriate c approximation to the compounded integral has c been obtained, it is put in rlist2(numrl2) after c numrl2 has been increased by one. c erlarg - sum of the errors over the intervals larger c than the smallest interval considered up to now c extrap - logical variable denoting that the routine c is attempting to perform extrapolation. i.e. c before subdividing the smallest interval we c try to decrease the value of erlarg. c noext - logical variable denoting that extrapolation is c no longer allowed (true-value) c c machine dependent constants c --------------------------- c c epmach is the largest relative spacing. c uflow is the smallest positive magnitude. c oflow is the largest positive magnitude. c c***first executable statement dqagpe epmach = d1mach(4) c c test on validity of parameters c ----------------------------- c ier = 0 neval = 0 last = 0 result = 0.0d+00 abserr = 0.0d+00 alist(1) = a blist(1) = b rlist(1) = 0.0d+00 elist(1) = 0.0d+00 iord(1) = 0 level(1) = 0 npts = npts2-2 if(npts2.lt.2.or.limit.le.npts.or.(epsabs.le.0.0d+00.and. * epsrel.lt.dmax1(0.5d+02*epmach,0.5d-28))) ier = 6 if(ier.eq.6) go to 999 c c if any break points are provided, sort them into an c ascending sequence. c sign = 1.0d+00 if(a.gt.b) sign = -1.0d+00 pts(1) = dmin1(a,b) if(npts.eq.0) go to 15 do 10 i = 1,npts pts(i+1) = points(i) 10 continue 15 pts(npts+2) = dmax1(a,b) nint = npts+1 a1 = pts(1) if(npts.eq.0) go to 40 nintp1 = nint+1 do 20 i = 1,nint ip1 = i+1 do 20 j = ip1,nintp1 if(pts(i).le.pts(j)) go to 20 temp = pts(i) pts(i) = pts(j) pts(j) = temp 20 continue if(pts(1).ne.dmin1(a,b).or.pts(nintp1).ne.dmax1(a,b)) ier = 6 if(ier.eq.6) go to 999 c c compute first integral and error approximations. c ------------------------------------------------ c 40 resabs = 0.0d+00 do 50 i = 1,nint b1 = pts(i+1) call dqk21(f,a1,b1,area1,error1,defabs,resa) abserr = abserr+error1 result = result+area1 ndin(i) = 0 if(error1.eq.resa.and.error1.ne.0.0d+00) ndin(i) = 1 resabs = resabs+defabs level(i) = 0 elist(i) = error1 alist(i) = a1 blist(i) = b1 rlist(i) = area1 iord(i) = i a1 = b1 50 continue errsum = 0.0d+00 do 55 i = 1,nint if(ndin(i).eq.1) elist(i) = abserr errsum = errsum+elist(i) 55 continue c c test on accuracy. c last = nint neval = 21*nint dres = dabs(result) errbnd = dmax1(epsabs,epsrel*dres) if(abserr.le.0.1d+03*epmach*resabs.and.abserr.gt.errbnd) ier = 2 if(nint.eq.1) go to 80 do 70 i = 1,npts jlow = i+1 ind1 = iord(i) do 60 j = jlow,nint ind2 = iord(j) if(elist(ind1).gt.elist(ind2)) go to 60 ind1 = ind2 k = j 60 continue if(ind1.eq.iord(i)) go to 70 iord(k) = iord(i) iord(i) = ind1 70 continue if(limit.lt.npts2) ier = 1 80 if(ier.ne.0.or.abserr.le.errbnd) go to 210 c c initialization c -------------- c rlist2(1) = result maxerr = iord(1) errmax = elist(maxerr) area = result nrmax = 1 nres = 0 numrl2 = 1 ktmin = 0 extrap = .false. noext = .false. erlarg = errsum ertest = errbnd levmax = 1 iroff1 = 0 iroff2 = 0 iroff3 = 0 ierro = 0 uflow = d1mach(1) oflow = d1mach(2) abserr = oflow ksgn = -1 if(dres.ge.(0.1d+01-0.5d+02*epmach)*resabs) ksgn = 1 c c main do-loop c ------------ c do 160 last = npts2,limit c c bisect the subinterval with the nrmax-th largest error c estimate. c levcur = level(maxerr)+1 a1 = alist(maxerr) b1 = 0.5d+00*(alist(maxerr)+blist(maxerr)) a2 = b1 b2 = blist(maxerr) erlast = errmax call dqk21(f,a1,b1,area1,error1,resa,defab1) call dqk21(f,a2,b2,area2,error2,resa,defab2) c c improve previous approximations to integral c and error and test for accuracy. c neval = neval+42 area12 = area1+area2 erro12 = error1+error2 errsum = errsum+erro12-errmax area = area+area12-rlist(maxerr) if(defab1.eq.error1.or.defab2.eq.error2) go to 95 if(dabs(rlist(maxerr)-area12).gt.0.1d-04*dabs(area12) * .or.erro12.lt.0.99d+00*errmax) go to 90 if(extrap) iroff2 = iroff2+1 if(.not.extrap) iroff1 = iroff1+1 90 if(last.gt.10.and.erro12.gt.errmax) iroff3 = iroff3+1 95 level(maxerr) = levcur level(last) = levcur rlist(maxerr) = area1 rlist(last) = area2 errbnd = dmax1(epsabs,epsrel*dabs(area)) c c test for roundoff error and eventually set error flag. c if(iroff1+iroff2.ge.10.or.iroff3.ge.20) ier = 2 if(iroff2.ge.5) ierro = 3 c c set error flag in the case that the number of c subintervals equals limit. c if(last.eq.limit) ier = 1 c c set error flag in the case of bad integrand behaviour c at a point of the integration range c if(dmax1(dabs(a1),dabs(b2)).le.(0.1d+01+0.1d+03*epmach)* * (dabs(a2)+0.1d+04*uflow)) ier = 4 c c append the newly-created intervals to the list. c if(error2.gt.error1) go to 100 alist(last) = a2 blist(maxerr) = b1 blist(last) = b2 elist(maxerr) = error1 elist(last) = error2 go to 110 100 alist(maxerr) = a2 alist(last) = a1 blist(last) = b1 rlist(maxerr) = area2 rlist(last) = area1 elist(maxerr) = error2 elist(last) = error1 c c call subroutine dqpsrt to maintain the descending ordering c in the list of error estimates and select the subinterval c with nrmax-th largest error estimate (to be bisected next). c 110 call dqpsrt(limit,last,maxerr,errmax,elist,iord,nrmax) c ***jump out of do-loop if(errsum.le.errbnd) go to 190 c ***jump out of do-loop if(ier.ne.0) go to 170 if(noext) go to 160 erlarg = erlarg-erlast if(levcur+1.le.levmax) erlarg = erlarg+erro12 if(extrap) go to 120 c c test whether the interval to be bisected next is the c smallest interval. c if(level(maxerr)+1.le.levmax) go to 160 extrap = .true. nrmax = 2 120 if(ierro.eq.3.or.erlarg.le.ertest) go to 140 c c the smallest interval has the largest error. c before bisecting decrease the sum of the errors over c the larger intervals (erlarg) and perform extrapolation. c id = nrmax jupbnd = last if(last.gt.(2+limit/2)) jupbnd = limit+3-last do 130 k = id,jupbnd maxerr = iord(nrmax) errmax = elist(maxerr) c ***jump out of do-loop if(level(maxerr)+1.le.levmax) go to 160 nrmax = nrmax+1 130 continue c c perform extrapolation. c 140 numrl2 = numrl2+1 rlist2(numrl2) = area if(numrl2.le.2) go to 155 call dqelg(numrl2,rlist2,reseps,abseps,res3la,nres) ktmin = ktmin+1 if(ktmin.gt.5.and.abserr.lt.0.1d-02*errsum) ier = 5 if(abseps.ge.abserr) go to 150 ktmin = 0 abserr = abseps result = reseps correc = erlarg ertest = dmax1(epsabs,epsrel*dabs(reseps)) c ***jump out of do-loop if(abserr.lt.ertest) go to 170 c c prepare bisection of the smallest interval. c 150 if(numrl2.eq.1) noext = .true. if(ier.ge.5) go to 170 155 maxerr = iord(1) errmax = elist(maxerr) nrmax = 1 extrap = .false. levmax = levmax+1 erlarg = errsum 160 continue c c set the final result. c --------------------- c c 170 if(abserr.eq.oflow) go to 190 if((ier+ierro).eq.0) go to 180 if(ierro.eq.3) abserr = abserr+correc if(ier.eq.0) ier = 3 if(result.ne.0.0d+00.and.area.ne.0.0d+00)go to 175 if(abserr.gt.errsum)go to 190 if(area.eq.0.0d+00) go to 210 go to 180 175 if(abserr/dabs(result).gt.errsum/dabs(area))go to 190 c c test on divergence. c 180 if(ksgn.eq.(-1).and.dmax1(dabs(result),dabs(area)).le. * resabs*0.1d-01) go to 210 if(0.1d-01.gt.(result/area).or.(result/area).gt.0.1d+03.or. * errsum.gt.dabs(area)) ier = 6 go to 210 c c compute global integral sum. c 190 result = 0.0d+00 do 200 k = 1,last result = result+rlist(k) 200 continue abserr = errsum 210 if(ier.gt.2) ier = ier-1 result = result*sign 999 return end
bsd-3-clause
buaasun/grappa
applications/NPB/MPI/LU/setbv.f
7
2519
c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine setbv c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c set the boundary values of dependent variables c--------------------------------------------------------------------- implicit none include 'applu.incl' c--------------------------------------------------------------------- c local variables c--------------------------------------------------------------------- integer i, j, k integer iglob, jglob c--------------------------------------------------------------------- c set the dependent variable values along the top and bottom faces c--------------------------------------------------------------------- do j = 1, ny jglob = jpt + j do i = 1, nx iglob = ipt + i call exact( iglob, jglob, 1, u( 1, i, j, 1 ) ) call exact( iglob, jglob, nz, u( 1, i, j, nz ) ) end do end do c--------------------------------------------------------------------- c set the dependent variable values along north and south faces c--------------------------------------------------------------------- IF (west.eq.-1) then do k = 1, nz do i = 1, nx iglob = ipt + i call exact( iglob, 1, k, u( 1, i, 1, k ) ) end do end do END IF IF (east.eq.-1) then do k = 1, nz do i = 1, nx iglob = ipt + i call exact( iglob, ny0, k, u( 1, i, ny, k ) ) end do end do END IF c--------------------------------------------------------------------- c set the dependent variable values along east and west faces c--------------------------------------------------------------------- IF (north.eq.-1) then do k = 1, nz do j = 1, ny jglob = jpt + j call exact( 1, jglob, k, u( 1, 1, j, k ) ) end do end do END IF IF (south.eq.-1) then do k = 1, nz do j = 1, ny jglob = jpt + j call exact( nx0, jglob, k, u( 1, nx, j, k ) ) end do end do END IF return end
bsd-3-clause
armnlib/librmn
base/moduledate.f90
1
57594
!/* RMNLIB - Library of useful routines for C and FORTRAN programming ! * Copyright (C) 1975-2001 Division de Recherche en Prevision Numerique ! * Environnement Canada ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation, ! * version 2.1 of the License. ! * ! * This library is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the ! * Free Software Foundation, Inc., 59 Temple Place - Suite 330, ! * Boston, MA 02111-1307, USA. ! */ !============================================================================ ! THREAD SAFE ROUTINES ! (they call the original ones inside a OpenMP critical region) ! the original routine names have been deliberately mangled !============================================================================ ! M.Valin 2016/12/08 initial release of the thread safe cover routines ! subroutine date_thread_lock(lock) ! .true. attempt to acquire lock, .false. release lock IMPLICIT NONE logical, intent(IN) :: lock integer, save :: owner_thread = 0 call set_user_lock(owner_thread,lock) return end subroutine date_thread_lock subroutine INCDATi(idate1,idate2,nhours) IMPLICIT NONE integer :: idate1,idate2 real *8 :: nhours call date_thread_lock(.true.) call IDNACTi(idate1,idate2,nhours) call date_thread_lock(.false.) end subroutine INCDATi subroutine INCDATr(idate1,idate2,nhours) IMPLICIT NONE integer :: idate1,idate2 real *8 :: nhours call date_thread_lock(.true.) call IDNACTr(idate1,idate2,nhours) call date_thread_lock(.false.) end subroutine INCDATr subroutine DIFDATi(idate1,idate2,nhours) IMPLICIT NONE integer :: idate1,idate2 real *8 :: nhours call date_thread_lock(.true.) call DDIAFTi(idate1,idate2,nhours) call date_thread_lock(.false.) end subroutine DIFDATi subroutine DIFDATr(idate1,idate2,nhours) IMPLICIT NONE integer :: idate1,idate2 real *8 :: nhours call date_thread_lock(.true.) call DDIAFTr(idate1,idate2,nhours) call date_thread_lock(.false.) end subroutine DIFDATr INTEGER FUNCTION newdate(DAT1,DAT2,DAT3,MODE) IMPLICIT NONE integer :: DAT1,DAT2(*),DAT3,MODE integer, external :: naetwed call date_thread_lock(.true.) newdate = naetwed(DAT1,DAT2,DAT3,MODE) call date_thread_lock(.false.) end FUNCTION newdate INTEGER FUNCTION IDATMG2(IDATE) IMPLICIT NONE integer idate(14) integer, external :: itdmag2 call date_thread_lock(.true.) IDATMG2 = itdmag2(IDATE) call date_thread_lock(.false.) end function IDATMG2 subroutine DATMGP2(IDATE) IMPLICIT NONE integer idate(14) call date_thread_lock(.true.) call dmagtp2(IDATE) call date_thread_lock(.false.) end subroutine DATMGP2 subroutine NewDate_Options( value,command ) IMPLICIT NONE character*(*) value,command call date_thread_lock(.true.) call NewDate_Options_int( value,command ) call date_thread_lock(.false.) end subroutine NewDate_Options subroutine Get_Calendar_Status( NoLeapYears,CcclxDays ) IMPLICIT NONE logical :: NoLeapYears,CcclxDays call date_thread_lock(.true.) call Get_Calendar_Status_int( NoLeapYears,CcclxDays ) call date_thread_lock(.false.) end subroutine Get_Calendar_Status integer function Calendar_Adjust(tdate1,tdate2,true_date_mode,adding) IMPLICIT NONE integer, external :: Calendar_Adjust_int integer :: tdate1,tdate2 character(len=1) true_date_mode logical :: adding call date_thread_lock(.true.) Calendar_Adjust = Calendar_Adjust_int(tdate1,tdate2,true_date_mode,adding) call date_thread_lock(.false.) end function Calendar_Adjust integer function CcclxDays_Adjust(tdate1,tdate2,true_date_mode,adding) IMPLICIT NONE integer, external :: CcclxDays_Adjust_int integer :: tdate1,tdate2 ! input TrueDates character(len=1) true_date_mode ! (B)asic or (E)xtended TrueDates logical :: adding ! operating mode (T=incadtr, F=difdatr) call date_thread_lock(.true.) CcclxDays_Adjust = CcclxDays_Adjust_int(tdate1,tdate2,true_date_mode,adding) call date_thread_lock(.false.) end function CcclxDays_Adjust integer function LeapYear_Adjust(tdate1,tdate2,true_date_mode,adding) IMPLICIT NONE integer, external :: LeapYear_Adjust_int logical :: adding character(len=1) true_date_mode ! (B)asic or (E)xtended true dates integer :: tdate1,tdate2 call date_thread_lock(.true.) LeapYear_Adjust = LeapYear_Adjust_int(tdate1,tdate2,true_date_mode,adding) call date_thread_lock(.false.) end function LeapYear_Adjust subroutine Ignore_LeapYear() IMPLICIT NONE call date_thread_lock(.true.) call Ignore_LeapYear_int call date_thread_lock(.false.) end subroutine Ignore_LeapYear subroutine Accept_LeapYear() IMPLICIT NONE call date_thread_lock(.true.) call Accept_LeapYear_int call date_thread_lock(.false.) end subroutine Accept_LeapYear subroutine Get_LeapYear_Status(no_leap_year_status) IMPLICIT NONE logical :: no_leap_year_status call date_thread_lock(.true.) call Get_LeapYear_Status_int(no_leap_year_status) call date_thread_lock(.false.) end subroutine Get_LeapYear_Status !============================================================================ ! END OF THREAD SAFE ROUTINES !============================================================================ ! the original names of the following routines have been altered because of ! the above mentioned thread safe routines ! internal calls use the mangled internal names !============================================================================ ! environment variable NEWDATE_OPTIONS usage syntax ! ! export NEWDATE_OPTIONS="[debug][,][year=360_day|365_day|gregorian][,][debug]" ! ! examples of usage: ! ! export NEWDATE_OPTIONS="debug" ! export NEWDATE_OPTIONS="year=360_day" ! export NEWDATE_OPTIONS="debug,year=360_day" ! export NEWDATE_OPTIONS="year=365_day" ! export NEWDATE_OPTIONS="year=365_day,debug" ! ! main function NEWDATE documentation !USAGE - CALL NEWDATE(DAT1,DAT2,DAT3,MODE) ! !ARGUMENTS ! MODE CAN TAKE THE FOLLOWING VALUES:-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7 ! MODE=1 : STAMP TO (TRUE_DATE AND RUN_NUMBER) ! OUT - DAT1 - THE TRUEDATE CORRESPONDING TO DAT2 ! IN - DAT2 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! OUT - DAT3 - RUN NUMBER OF THE DATE-TIME STAMP ! IN - MODE - SET TO 1 ! MODE=-1 : (TRUE_DATE AND RUN_NUMBER) TO STAMP ! IN - DAT1 - TRUEDATE TO BE CONVERTED ! OUT - DAT2 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! IN - DAT3 - RUN NUMBER OF THE DATE-TIME STAMP ! IN - MODE - SET TO -1 ! MODE=2 : PRINTABLE TO TRUE_DATE ! OUT - DAT1 - TRUE_DATE ! IN - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! IN - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO 2 ! MODE=-2 : TRUE_DATE TO PRINTABLE ! IN - DAT1 - TRUE_DATE ! OUT - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! OUT - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO -2 ! MODE=3 : PRINTABLE TO STAMP ! OUT - DAT1 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! IN - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! IN - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO 3 ! MODE=-3 : STAMP TO PRINTABLE ! IN - DAT1 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! OUT - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! OUT - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO -3 ! MODE=4 : 14 word old style DATE array TO STAMP and array(14) ! OUT - DAT1 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! IN - DAT2 - 14 word old style DATE array ! IN - DAT3 - UNUSED ! IN - MODE - SET TO 4 ! MODE=-4 : STAMP TO 14 word old style DATE array ! IN - DAT1 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! OUT - DAT2 - 14 word old style DATE array ! IN - DAT3 - UNUSED ! IN - MODE - SET TO -4 ! MODE=5 PRINTABLE TO EXTENDED STAMP (year 0 to 10,000) ! OUT - DAT1 - EXTENDED DATE-TIME STAMP (NEW STYLE only) ! IN - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! IN - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO 5 ! MODE=-5 EXTENDED STAMP (year 0 to 10,000) TO PRINTABLE ! IN - DAT1 - EXTENDED DATE-TIME STAMP (NEW STYLE only) ! OUT - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! OUT - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO -5 ! MODE=6 : EXTENDED STAMP TO EXTENDED TRUE_DATE (in hours) ! OUT - DAT1 - THE TRUEDATE CORRESPONDING TO DAT2 ! IN - DAT2 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! OUT - DAT3 - RUN NUMBER, UNUSED (0) ! IN - MODE - SET TO 6 ! MODE=-6 : EXTENDED TRUE_DATE (in hours) TO EXTENDED STAMP ! IN - DAT1 - TRUEDATE TO BE CONVERTED ! OUT - DAT2 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! IN - DAT3 - RUN NUMBER, UNUSED ! IN - MODE - SET TO -6 ! MODE=7 - PRINTABLE TO EXTENDED TRUE_DATE (in hours) ! OUT - DAT1 - EXTENDED TRUE_DATE ! IN - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! IN - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO 7 ! MODE=-7 : EXTENDED TRUE_DATE (in hours) TO PRINTABLE ! IN - DAT1 - EXTENDED TRUE_DATE ! OUT - DAT2 - DATE OF THE PRINTABLE DATE (YYYYMMDD) ! OUT - DAT3 - TIME OF THE PRINTABLE DATE (HHMMSSHH) ! IN - MODE - SET TO -7 !NOTES - IT IS RECOMMENDED TO ALWAYS USE THIS FUNCTION TO ! MANIPULATE DATES ! - IF MODE ISN'T IN THESE VALUES(-7,..,-2,-1,1,2,...,7) OR IF ! ARGUMENTS AREN'T VALID, NEWDATE HAS A RETURN VALUE OF 1 ! - A TRUE DATE IS AN INTEGER (POSSIBLY NEGATIVE) THAT ! CONTAINS THE NUMBER OF 5 SECONDS INTERVALS SINCE ! 1980/01/01 00H00. NEGATIVE VALUES ARISE AS ! THIS CONCEPT APPLIES FROM 1900/01/01. ! - AN EXTENDED TRUE DATE IS AN INTEGER THAT CONTAINS ! THE NUMBER OF 3 HOURLY INTERVALS SINCE YEAR 00/01/01 ! - SEE INCDATR FOR DETAIL ON CMC DATE-TIME STAMP !**S/R INCDATR - INCREASE IDATE2 BY NHOURS ! SUBROUTINE IDNACTr (IDATE1,IDATE2,NHOURS) ! INCDATR IMPLICIT NONE ! ! ENTRY INCDATI - SAME AS INCDATR BUT IDATE2 AND NHOURS ARE ROUNDED ! ENTRY DIFDATI - SAME AS DIFDATR BUT DATE-TIME STAMPS ARE ROUNDED ! ENTRY DIFDATR - COMPUTES THE DIFFERENCE IN HOURS BETWEEN ! IDATE1 AND IDATE2. ! !AUTHOR - G. ALEXANDER - APR 75 ! !REVISION 001 C. THIBEAULT - NOV 79 DOCUMENTATION !REVISION 002 E. BEAUCHESNE - JUN 96 NEW STYLE DATE !REVISION 003 M. Lepine, B. Dugas - Aout 2009 ! Dates etendues, + tenir compte ou non des annees ! bissextiles dans les calculs de dates !REVISION 004 B. Dugas - Novembre 2010 ! Correction au mode non-bissextile pour les ! calculs mettant en cause de grands intervals !REVISION 005 B. Dugas - Janvier 2012 ! Utiliser Get_calendar_Status et Calendar_Adjust ! pour supporter les calculs effectues avec des ! calendriers alternatifs (i.e. 360 ou 365 jours) !REVISION 006 B. Dugas - Fevrier 2016 ! 1) Correction a la routine LeapYear_Adjust, ! laquelle est appellee par Calendar_Adjust ! 2) Correction aux appels internes a NEWDATE ! pour lesquels DAT2 doit etre un vecteur. ! Ceci elimine plusieurs avertissements a ! la compilation (GFORTRAN). ! !LANGUAGE - fortran ! !OBJECT - INCDATR COMPUTES IDATE1=IDATE2+NHOURS ! - DIFDATR COMPUTES NHOURS=IDATE1-IDATE2 ! - INCDATI COMPUTES IDATE1=IDATE2+NHOURS ! (IDATE2 AND NHOURS ROUNDED TO NEAREST HOUR) ! - DIFDATI COMPUTES NHOURS=IDATE1-IDATE2 ! (IDATE1 AND IDATE2 ROUNDED TO NEAREST HOUR) ! !USAGE - CALL INCDATR(IDATE1,IDATE2,NHOURS) ! - CALL DIFDATR(IDATE1,IDATE2,NHOURS) ! - CALL INCDATI(IDATE1,IDATE2,NHOURS) ! - CALL DIFDATI(IDATE1,IDATE2,NHOURS) ! !ARGUMENTS ! - IDATE1 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! - IDATE2 - CMC DATE-TIME STAMP (OLD OR NEW STYLE) ! - NHOURS - NUMBER OF HOURS(REAL*8) ! !NOTES - IT IS RECOMMENDED TO ALWAYS USE NEWDATE TO MANIPULATE ! DATES ! - IF INCDATR OR INCDATI RECEIVE BAD ARGUMENTS, THEY SEND ! BACK IDATE1=101010101 (1910/10/10 10Z RUN 1) ! - IF DIFDATR OR DIFDATI RECEIVE BAD ARGUMENTS, THEY SEND ! BACK NHOURS=2**30 ! - THERE ARE THREE STYLES OF DATES (ALL USE INTEGERS): ! -OLD: AN INTEGER(.LT.123 200 000) OF THE FOLLOWING ! FORM: MMDDYYZZR ! MM = MONTH OF THE YEAR (1-12) ! DD = DAY OF THE MONTH (1-31) ! YY = YEAR(00-99)=>OLD STYLE ONLY GOOD BEFORE 2000/1/1 ! ZZ = HOUR(00-23) ! R = RUN (0-9) KEPT FOR BACKWARD COMPATIBILITY ! -NEW: AN INTEGER(.GE.123 200 000) THAT CONTAINS THE ! TRUE DATE(NUMBER OF 5 SECONDS INTERVALS SINCE 1980/1/1 ! 00H00), COMPUTED LIKE THIS: ! FALSE_DATE=NEW_DATE_TIME_STAMP-123 200 000 ! TRUE_DATE=(FALSE_DATE/10)*8+MOD(FALSE_DATE,10) ! -EXTENDED: AN UNSIGNED INTEGER(.GE.3 000 000 000) THAT ! CONTAINS THE EXTENDED TRUE DATE (NUMBER OF HOURS SINCE ! 0000/1/1 00H), COMPUTED LIKE THIS: ! EXT_FALSE_DATE=EXT_DATE_TIME_STAMP-3 000 000 000 ! EXT_TRUE_DATE=(EXT_FALSE_DATE/10)*8+MOD(EXT_FALSE_DATE,10) ! AS THIS EXTENDED DATE IS STORED IN A SIGNED INTEGER, ! THE STORED VALUE WILL BE A LARGE NEGATIVE ONE. ! - td2235 = truedate of dec 31, 2235, 23h59 ! - td1900 = -504904320 = truedate of jan 1, 1900 !-------------------------------------------------------------------- ! integer idate1,idate2 real*8 nhours logical adding,rounding integer, external :: Calendar_Adjust_int, naetwed external Get_Calendar_Status_int integer result logical :: no_leap_years,ccclx_days,goextend integer(8) addit integer tdate1,tdate2,runnum,ndays,pdate2 integer idate(2),pdate1(2) integer td1900, td2235 data td1900 /-504904320/, td2235 /1615714548/ rounding=.false. goto 4 entry IDNACTi(idate1,idate2,nhours) ! INCDATI rounding=.true. 4 adding=.true. goto 1 ! ! difdat computes nhours = idate1 - idate2 ! entry DDIAFTi(idate1,idate2,nhours) ! DIFDATI rounding=.true. goto 3 entry DDIAFTr(idate1,idate2,nhours) ! DIFDATR rounding=.false. 3 adding=.false. ! print *,'Debug+ difdat ',idate1,idate2 if (idate2 .lt. -1 .or. idate1 .lt. -1) then if (idate1 .gt. -1) then result=naetwed(idate1,pdate1,pdate2,-3) if(result.ne.0) then print *,'label 1,idate1:',idate1 goto 2 endif result=naetwed(tdate1,pdate1,pdate2,+7) if(result.ne.0) then print *,'label 2,pdate1,pdate2:',pdate1(1),pdate2 goto 2 endif else idate(1)=idate1 ; result=naetwed(tdate1,idate,runnum,6) endif else idate(1)=idate1 ; result=naetwed(tdate1,idate,runnum,1) endif if(result.ne.0) then print *,'label 3,idate1:',idate1 goto 2 endif 1 continue call Get_calendar_Status_int( no_leap_years,ccclx_days ) if (idate2 .lt. -1 .or. & (idate1 .lt. -1 .and. .not.adding)) then if (idate2 .gt.-1) then result=naetwed(idate2,pdate1,pdate2,-3) if(result.ne.0) then print *,'label 4,idate2:',idate2 goto 2 endif result=naetwed(tdate2,pdate1,pdate2,+7) if(result.ne.0) then print *,'label 5,pdate1,pdate2:',pdate1(1),pdate2 goto 2 endif else idate(1)=idate2 ; result=naetwed(tdate2,idate,runnum,6) endif if(result.ne.0) then print *,'label 6,idate2:',idate2 goto 2 endif if (adding) then tdate1=tdate2+nint(nhours) if (no_leap_years .or. ccclx_days) then ndays = Calendar_Adjust_int(tdate1,tdate2,'E',adding) tdate1 = tdate1 + (ndays*24) endif result=naetwed(tdate1,idate,runnum,-6) ; idate1=idate(1) if (result.ne.0) then print *,'after if adding,if rounding',tdate1 goto 2 endif else nhours=(tdate1-tdate2) if (no_leap_years .or. ccclx_days) then ndays = Calendar_Adjust_int(tdate1,tdate2,'E',adding) nhours = nhours - (ndays*24) endif endif else idate(1)=idate2 ; result=naetwed(tdate2,idate,runnum,1) if(result.ne.0) then print *,'label 1,idate2:',idate2 goto 2 endif if (adding) then goextend=.false. rounding=rounding.or.(tdate2.lt.0) if (rounding) then tdate2=(tdate2+sign(360,tdate2))/720*720 addit = 720*nint(nhours,8) else addit = nint(720*nhours,8) endif if ((td1900-tdate2)*1_8 <= addit .and. & ! tdate2 + addit >= td1900 and (td2235-tdate2)*1_8 >= addit) then ! tdate2 + addit <= td2235, where tdate1=tdate2+addit ! addit can be a very large if (no_leap_years.or.ccclx_days) then ! integer*8 number ndays = Calendar_Adjust_int(tdate1,tdate2,'B',adding) tdate1 = tdate1 + (ndays*24*720) endif if ((tdate1 > td2235) & .or. (tdate1 < td1900)) goextend = .true. else goextend = .true. endif if (goextend) then ! exiting regular date range for extended range result=naetwed(idate2,pdate1,pdate2,-3) if(result.ne.0) then print *,'label 7,idate2:',idate2 goto 2 endif result=naetwed(tdate2,pdate1,pdate2,+7) if(result.ne.0) then print *,'label 8,pdate1,pdate2:',pdate1(1),pdate2 goto 2 endif tdate1=tdate2+nint(nhours) if (no_leap_years .or. ccclx_days) then ndays = Calendar_Adjust_int(tdate1,tdate2,'E',adding) tdate1 = tdate1 + (ndays*24) endif result=naetwed(tdate1,idate,runnum,-6) ; idate1=idate(1) else result=naetwed(tdate1,idate,runnum,-1) ; idate1=idate(1) endif if (result.ne.0) then print *,'after if adding,if rounding',tdate1 goto 2 endif else if (rounding) then tdate1=(tdate1+sign(360,tdate1))/720*720 tdate2=(tdate2+sign(360,tdate2))/720*720 nhours=nint((tdate1-tdate2)/720.0) else nhours=(tdate1-tdate2) nhours=nhours/720.0 endif if (no_leap_years .or. ccclx_days) then ndays = Calendar_Adjust_int(tdate1,tdate2,'B',adding) nhours = nhours - (ndays*24) endif endif endif return 2 if (adding) then idate1=101010101 else nhours=2.0**30 endif return end !**FUNCTION IDATMG2 - CONSTRUCTS A CANADIAN METEOROLOGICAL CENTRE DATE- ! TIME STAMP USING THE OPERATIONAL CMC DATE-TIME ! GROUP. ! INTEGER FUNCTION itdmag2(IDATE) ! IDATMG2 IMPLICIT NONE ! !AUTHOR - M. VALIN - MAR 79 ! !REVISION 001 C. THIBEAULT - NOV 79 DOCUMENTATION ! 002 P. CADIEUX - FEV 83 VERSION CORRIGEE, PLUS EFFICACE ! 003 E. BEAUCHESNE - JUN 96 NEW DATE-TIME STAMP ! !LANGUAGE - fortran ! !OBJECT(IDATMG2) ! - CONSTRUCTS A CMC DATE-TIME STAMP USING THE OPERATIONAL ! CMC DATE-TIME GROUP (WORDS 1-6) AND RETURNING THE STAMP ! IN WORD 14 AS WELL AS IN THE FUNCTION VALUE. ! !USAGE - IDAT = IDATMG2(IDATE) ! !ARGUMENTS ! IN - IDATE(1 TO 6) - ARRAY OF 14 WORDS WHICH HAS IN WORDS 1-6 ! THE INFORMATION NEEDED TO RECONSTRUCT THE ! STAMP WHICH IS THEN PUT IN WORD 14 AS WELL ! AS IN THE FUNCTION VALUE(SEE NOTES) ! OUT - IDATE(14) - CMC DATE-TIME STAMP (NEW, OLD or EXTENDED) !NOTES ! - RETURNS IDATE(14)=101010101 IF INPUTS ARE INVALID ! - IDATE(1)=DAY OF THE WEEK(1-7,SUNDAY=1) (OPTIONAL) ! - IDATE(2)=MONTH (1-12) ! - IDATE(3)=DAY (1-31) ! - IDATE(4)=YEAR (0-99,100-10000) Note: can not work for extended dates between 0-99 ! - IDATE(5)=ZULU (0-23) ! - IDATE(6)=HUNDREDTHS OF SECOND SINCE LAST HOUR (0-359 999) ! !--------------------------------------------------------------------- ! integer idate(14) integer, external :: naetwed integer dtpr(2),tmpr,year,result year=idate(4) if ((year.ge.0) .and. (year.le.99)) then year=year+1900 endif dtpr(1)=year*10000+idate(2)*100+idate(3) tmpr=idate(5)*1000000+(idate(6)/6000)*10000+ & mod(idate(6)/100,60)*100 result=naetwed(idate(14),dtpr,tmpr,3) if(result.ne.0) idate(14)=101010101 itdmag2 = idate(14) return end !**S/R DATMGP2 - CREATES A DATE TIME GROUP. ! SUBROUTINE dmagtp2 (IDATE) ! DATMGP2 IMPLICIT NONE ! !AUTHOR - D. SHANTZ ! !REVISION 001 C. THIBEAULT - NOV 79 DOCUMENTATION ! 002 E. BEAUCHESNE - JUN 96 NEW DATE-TIME STAMP ! 003 M. Lepine - Avril 98 - Retourner l'annee a 4 chiffres ! 004 B. Dugas - fevrier 2016 - Supprimer constantes holorith ! !LANGUAGE - fortran ! !OBJECT(DATMGP2) ! - CREATES A CANADIAN METEOROLOGICAL CENTRE DATE TIME GROUP ! IN THE OPERATIONAL CMC FORMAT USING THE CMC DATE TIME STAMP ! !USAGE - CALL DATMGP2(IDATE) ! !ALGORITHM ! - CALLS NEWDATE TO CONVERT A DATE-TIME STAMP TO A PRINTABLE ! STAMP ! - EXTRACTS INFORMATION OF IT ! - IT THEN USES A TABLE LOOKUP TO CONSTRUCT THE MONTH AND ! DAY OF THE WEEK CHARACTER STRINGS. ! - ENCODE AND DECODE ARE THEN USED TO FORMAT THE CHARACTER ! PART OF THE DATE TIME GROUP. ! !ARGUMENTS ! IN/OUT - IDATE - 14 WORDS INTEGER ARRAY. ON INPUT, WORD 14 IS SET ! TO THE DATE TIME STAMP. ON OUTPUT ALL 14 WORDS OF IDATE ! ARE SET TO THE DATE TIME GROUP WHICH CORRESPONDS TO THAT ! DATE TIME STAMP. ! !NOTES ! - IF IDATE(14) IS INVALID, THE OUTPUTS WILL CORRESPOND ! TO 1910/10/10 10Z ! - IDATE(1)=DAY OF THE WEEK (1-7,SUNDAY=1) ! - IDATE(2)=MONTH (1-12) ! - IDATE(3)=DAY (1-31) ! - IDATE(4)=YEAR (0-10000) ! - IDATE(5)=ZULU (0-23) ! - IDATE(6)=100*NUMBER_OF_SECOND_SINCE_LAST_HOUR (0,359 999) ! - IDATE(7-13)=DATE-TIME GROUP IN CHARACTER FORMAT (7A4) ! - IDATE(14)=DATE-TIME STAMP(OLD, NEW OR EXTENDED) ! !-------------------------------------------------------------------- ! integer idate(14),dtpr,tmpr,result,tpr(2) integer i,j,k,iday,idt,mon,jd character * 3 xmonth(12),xday(7), amonth,aday character * 128 wrk integer, external :: naetwed data xmonth / 'JAN','FEB','MAR','APR','MAY','JUN', & 'JUL','AUG','SEP','OCT','NOV','DEC' / data xday / 'SUN','MON','TUE','WED','THU', & 'FRI','SAT' / ! !--------------------------------------------------------------------- ! jd(i,j,k) =k-32075+1461*(i+4800+(j-14)/12)/4 & +367*(j-2-(j-14)/12*12)/12 & -3*((i+4900+(j-14)/12)/100)/4 ! idt = idate(14) ! ! tpr(1) = dtpr result=naetwed(idt,tpr,tmpr,-3) dtpr = tpr(1) if (result.ne.0) then idt=101010101 dtpr=19101010 tmpr=10000000 endif idate(2) = mod(dtpr/100,100) idate(3) = mod(dtpr,100) idate(4) = mod(dtpr/10000,10000) idate(5) = mod(tmpr/1000000,100) idate(6) = mod(tmpr/10000,100)*6000+mod(tmpr/100,100)*100+mod(tmpr,100) mon = idate(2) amonth = xmonth(mon) idate(1) = jd(idate(4),idate(2),idate(3)) idate(1) = 1 + mod(idate(1)+1,7) iday = idate(1) aday = xday(iday) write(wrk,601) aday,amonth,(idate(i),i=3,5),idate(6)/6000, & mod(idate(6)/100,60),mod(idate(6),100) read (wrk,501) (idate(i),i=7,13) 501 format (7a4) 601 format (1x,a,1x,a,i3.2,1x,i4.2,i3.2,'Z',i2.2,':',i2.2,'.',i2.2) ! !--------------------------------------------------------------------- ! return end subroutine Ignore_LeapYear_int() character(len=512) :: value logical :: no_leap_year_status call NewDate_Options_int( 'year=365_day','set' ) return entry Accept_LeapYear_int() call NewDate_Options_int( 'year=gregorian','set' ) return entry Get_LeapYear_Status_int( no_leap_year_status ) value='year' ; call NewDate_Options_int( value,'get' ) if (value == '365_day' .or. value == '360_day') then no_leap_year_status = .true. else no_leap_year_status = .false. endif return end subroutine NewDate_Options_int( value,command ) ! NewDate_Options ! A) Permits alternative calendar options, via either ! the NEWDATE_OPTIONS environment variable (which ! has precedence) or via appropriate "set" commands ! B) Also, returns calendar status via the "get" command ! C) The Get_Calendar_Status entry also return this ! The known calendars options are currently: gregorian, ! 365_day (no leap years) and 360_day implicit none character*(*) value,command integer ii logical NoLeapYears,CcclxDays logical, save :: called_newdate_options=.false. logical, save :: no_newdate_env_options=.true. logical, save :: no_leap_years=.false. logical, save :: ccclx_days=.false. logical, save :: debug=.false. character(512) :: evalue,string if (.not.called_newdate_options) then ! check environment once call getenvc( 'NEWDATE_OPTIONS',evalue ) called_newdate_options = .true. if (evalue /= ' ') then ! variable was set call up2low( evalue,evalue ) ii = index( evalue,'debug' ) if (ii > 0) debug = .true. ii = index( evalue,'year=' ) if (ii > 0) then ! found known option. check its value if (evalue(ii+5:ii+11) == '365_day' .or. & evalue(ii+5:ii+11) == '360_day') then no_newdate_env_options = .false. no_leap_years = .true. if (evalue(ii+5:ii+11) == '360_day') & ccclx_days = .true. else if (evalue(ii+5:ii+13) == 'gregorian') then no_newdate_env_options = .false. no_leap_years = .false. ccclx_days = .false. endif if (debug) & write(6,"(/' Debug no_leap_years,ccclx_days=',L1,1x,L1/)") & no_leap_years,ccclx_days endif endif endif evalue = value ; call up2low( evalue,evalue ) string = command ; call up2low( string,string ) if (string == 'get') then ! check for value of defined options if (evalue == 'year') then if (ccclx_days) then value = '360_day' else if (no_leap_years) then value = '365_day' else value = 'gregorian' endif endif else if (string == 'set' .and. & ! try to set known options, but no_newdate_env_options) then ! environment has precedence ii = index( evalue,'year=' ) if (ii > 0) then if (evalue(ii+5:ii+11) == '365_day' .or. & evalue(ii+5:ii+11) == '360_day') then no_leap_years = .true. ccclx_days = .false. if (evalue(ii+5:ii+11) == '360_day') & ccclx_days = .true. else if (evalue(ii+5:ii+13) == 'gregorian') then no_leap_years = .false. ccclx_days = .false. endif endif else if (string == 'unset' .and. & ! try to unset known options, but no_newdate_env_options) then ! environment has precedence ii = index( evalue,'year=' ) if (ii > 0) then if (evalue(ii+5:ii+11) == '365_day') & no_leap_years = .false. if (evalue(ii+5:ii+11) == '360_day') & ccclx_days = .false. if (evalue(ii+5:ii+13) == 'gregorian') & no_leap_years = .true. if (no_leap_years) ccclx_days = .false. endif endif return entry Get_Calendar_Status_int( NoLeapYears,CcclxDays ) if (.not.called_newdate_options) then ! check environment once call getenvc( 'NEWDATE_OPTIONS',evalue ) called_newdate_options = .true. if (evalue /= ' ') then ! variable was set call up2low( evalue,evalue ) ii = index( evalue,'debug' ) if (ii > 0) debug = .true. ii = index( evalue,'year=' ) if (ii > 0) then ! found known option. check its value if (evalue(ii+5:ii+11) == '365_day' .or. & evalue(ii+5:ii+11) == '360_day') then no_newdate_env_options = .false. no_leap_years = .true. if (evalue(ii+5:ii+11) == '360_day') & ccclx_days = .true. else if (evalue(ii+5:ii+13) == 'gregorian') then no_newdate_env_options = .false. no_leap_years = .false. ccclx_days = .false. endif if (debug) & write(6,"(/' Debug no_leap_years,ccclx_days=',L1,1x,L1/)") & no_leap_years,ccclx_days endif endif endif NoLeapYears = no_leap_years ; CcclxDays = ccclx_days return end integer function Calendar_Adjust_int(tdate1,tdate2, & true_date_mode,adding) ! Calls CcclxDays_Adjust or LeapYear_Adjust if the ! CcclxDays or NoLeapYears options are true, respectively implicit none integer :: tdate1,tdate2 character(len=1) true_date_mode logical :: adding integer Adjust logical NoLeapYears,CcclxDays integer, external :: LeapYear_Adjust_int,CcclxDays_Adjust_int call Get_Calendar_Status_int( NoLeapYears,CcclxDays ) Adjust = 0 if (CcclxDays) then Adjust = CcclxDays_Adjust_int(tdate1,tdate2, & true_date_mode,adding) else if (NoLeapYears) then Adjust = LeapYear_Adjust_int(tdate1,tdate2, & true_date_mode,adding) endif Calendar_Adjust_int = Adjust return end integer function LeapYear_Adjust_int(tdate1,tdate2, & true_date_mode,adding) implicit none logical :: adding character(len=1) true_date_mode ! (B)asic or (E)xtended true dates integer, parameter :: limite = 23595500 ! 23h 59m 55s integer :: true2print,print2true integer :: ier,tdate1,tdate2,inc,m1,m2,dat(2) integer :: year,annee,y1,y1L,y2,p1a(2),p1b,p2a(2),p2b integer :: ndays,tdate1L,tdate28f,tdate29f,addit logical :: bissextile integer :: naetwed external naetwed bissextile(year) = ( ( (MOD(year,4) == 0) & .and.(MOD(year,100) /= 0) ) & .or. (MOD(year,400) == 0) ) addit=0 ! If adding, will hold a day in units of True Dates if (true_date_mode == 'B') then ! Basic true date mode true2print=-2 print2true=+2 if (adding) addit=17280 elseif (true_date_mode == 'E') then ! Extended true date mode true2print=-7 print2true=+7 if (adding) addit=24 endif tdate1L = tdate1 ! Local value of tdat1; if adding, it will gradually ! evolve to its real value as leap days are found ier = naetwed(tdate1,p1a,p1b,true2print) ! true date to printable, but this y1 = p1a(1) / 10000 ! may still accounts for leap days m1 = mod( p1a(1) / 100 , 100 ) ier = naetwed(tdate2,p2a,p2b,true2print) y2 = p2a(1) / 10000 m2 = mod( p2a(1) / 100 , 100 ) !!! print *,'Dans LeapYear_Adjust...' !CC print *,'Debut=',mod(p2a,100),mod(p2a/100,100),y2 !CC print *,'Fin =',mod(p1a,100),mod(p1a/100,100),y1 ndays = 0 ; inc = 1 if (y2 > y1 .or. (y1 == y2 .and. m2 > m1)) inc=-1 do annee = y2,y1,inc if (bissextile(annee)) then dat(1) = annee*10000+0228 ; ier = naetwed(tdate28f,dat,limite,print2true) dat(1) = annee*10000+0229 if (inc > 0) then ier = naetwed(tdate29f,dat,0,print2true) if (tdate29f <= tdate28f) print *,'Error tdate29f < tdate28f' if ((tdate2 <= tdate28f) .and. (tdate1L >= tdate29f)) then ndays = ndays+inc tdate1L = tdate1L+addit*inc !CC write(6,*) annee, ' ndays=',ndays else !CC print *,annee,' exclue' endif else ier = naetwed(tdate29f,dat,limite,print2true) if (tdate29f <= tdate28f) print *,'Error tdate29f < tdate28f' if ((tdate2 >= tdate28f) .and. (tdate1L <= tdate29f)) then ndays = ndays+inc tdate1L = tdate1L+addit*inc endif endif endif enddo ier = naetwed(tdate1L,p1a,p1b,true2print) y1L = p1a(1) / 10000 !!! print *,'FinL =',mod(p1a,100),mod(p1a/100,100),y1L do annee = y1+inc,y1L,inc if (bissextile(annee)) then dat(1) = annee*10000+0228 ; ier = naetwed(tdate28f,dat,limite,print2true) dat(1) = annee*10000+0229 if (inc > 0) then ier = naetwed(tdate29f,dat,0,print2true) if (tdate29f <= tdate28f) print *,'Error tdate29f < tdate28f' if ((tdate2 <= tdate28f) .and. (tdate1L >= tdate29f)) then ndays = ndays+inc tdate1L = tdate1L+addit*inc endif else ier = naetwed(tdate29f,dat,limite,print2true) if (tdate29f <= tdate28f) print *,'Error tdate29f < tdate28f' if ((tdate2 >= tdate28f) .and. (tdate1L <= tdate29f)) then ndays = ndays+inc tdate1L = tdate1L+addit*inc endif endif endif enddo LeapYear_Adjust_int = ndays return end integer function CcclxDays_Adjust_int(tdate1,tdate2, & true_date_mode,adding) ! Calculate correction (in days) to account for "360-day ! calendar" difdatr and incdatr calculation errors, which ! are by default always done with the gregorian calendar. implicit none ! arguments integer :: tdate1,tdate2 ! input TrueDates character(len=1) true_date_mode ! (B)asic or (E)xtended TrueDates logical :: adding ! operating mode (T=incadtr, F=difdatr) ! local variables real(8) :: nhours,nhoursi,td2h integer :: true2print,print2true,ier integer :: ye1,mo1,da1,ho1,mi1,se1,p1a(2),p1b integer :: ye2,mo2,da2,ho2,mi2,se2,p2a(2),p2b integer :: addit,tdateL integer, external :: naetwed addit=0 ! Holds a day in units of TrueDates td2h=0 ! Holds the True Dates to hours conversion factor if (true_date_mode == 'B') then ! Basic TrueDates mode true2print=-2 print2true=+2 addit=17280 td2h=720. elseif (true_date_mode == 'E') then ! Extended TrueDates mode true2print=-7 print2true=+7 addit=24 td2h=1. endif ier = naetwed( tdate2, p2a,p2b, true2print ) ! decode p2a and p2b ye2 = p2a(1) / 10000 mo2 = mod( p2a(1) / 100 , 100 ) da2 = mod( p2a(1) , 100 ) if ((da2 > 28 .and. mo2 == 2) .or. & ! sanity check: make sure that (da2 > 30 .and. mo2 > 4)) then ! tdate2 conforms to a 360-day print *,'Illegal date for 360-day calendar ', & ! calendar p2a(1),' in CcclxDays_Adjust' CcclxDays_Adjust_int = 89478485 ! * 24 = 2^31 - 8, a LARGE number if (.not.adding) CcclxDays_Adjust_int = -CcclxDays_Adjust_int return ! and should cause a quick abort endif if (mo2 == 1 .and. da2 == 31) then ! Convert to 30-day months da2 = 1 ; mo2 = 2 else if (mo2 == 2) then da2 = da2+1 else if (mo2 == 3) then if (da2 == 1) then da2 = 30 ; mo2 = 2 else da2 = da2 -1 endif endif da2 = ( mo2 - 1) * 30 + da2 ! Work with 360 days in a year (12*30) ho2 = p2b / 1000000 mi2 = mod( p2b / 10000 , 100 ) se2 = mod( p2b / 100 , 100 ) if (adding) then ! incdatr mode ! nhours is the interval (in hours) we ! are trying to add/substract to tdate2 nhours = (tdate1 - tdate2) / td2h ho1 = int( abs( nhours ) ) se1 = nint( (abs( nhours ) - ho1)*3600 ) mi1 = se1 / 60 se1 = mod( se1 ,60 ) ye1 = ho1 / (360*24) ho1 = mod( ho1 , (360*24) ) da1 = ho1 / 24 ho1 = mod( ho1 , 24 ) if (nhours < 0) then ! substracting ... se1 = se2 - se1 if (se1 < 0) then se1 = se1 + 60 ; mi2 = mi2 - 1 endif mi1 = mi2 - mi1 if (mi1 < 0) then mi1 = mi1 + 60 ; ho2 = ho2 - 1 endif ho1 = ho2 - ho1 if (ho1 < 0) then ho1 = ho1 + 24 ; da2 = da2 - 1 endif da1 = da2 - da1 if (da1 < 1) then da1 = da1 + 360 ; ye2 = ye2 - 1 endif ye1 = ye2 - ye1 else ! ... adding se1 = se2 + se1 if (se1 > 59) then se1 = se1 - 60 ; mi2 = mi2 + 1 endif mi1 = mi2 + mi1 if (mi1 > 59) then mi1 = mi1 - 60 ; ho2 = ho2 + 1 endif ho1 = ho2 + ho1 if (ho1 > 23) then ho1 = ho1 - 24 ; da2 = da2 + 1 endif da1 = da2 + da1 if (da1 > 360) then da1 = da1 - 360 ; ye2 = ye2 + 1 endif ye1 = ye2 + ye1 endif mo1 = (da1 - 1) / 30 + 1 ; da1 = da1 - (mo1 - 1) * 30 ! reverse the previous constant 30-day months conversion if (mo1 == 2 .and. da1 == 1) then da1 = 31 ; mo1 = 1 else if (mo1 == 2) then if (da1 == 30) then da1 = 1 ; mo1 = 3 else da1 = da1 - 1 endif else if (mo1 == 3) then da1 = da1 + 1 endif ! calculate the real TrueDate p1a(1) = (ye1*100+mo1)*100+da1 p1b = ((ho1*100+mi1)*100+se1)*100 ier = naetwed( tdateL, p1a,p1b, print2true ) ! ensure that tdate1 + CcclxDays_Adjust = tdateL CcclxDays_Adjust_int = ( tdateL - tdate1 ) / addit ier = mod( tdateL - tdate1 , addit ) if (ier /= 0) print *,'probleme 1 dans CcclxDays_Adjust' else ! difdatr mode ier = naetwed( tdate1, p1a,p1b, true2print ) ! decode p1a and p1b ye1 = p1a(1) / 10000 mo1 = mod( p1a(1) / 100 , 100 ) da1 = mod( p1a(1) , 100 ) if ((da1 > 28 .and. mo1 == 2) .or. & ! sanity check: make sure that (da1 > 30 .and. mo1 > 4)) then ! tdate1 conforms to a 360-day print *,'Illegal date for 360-day calendar ', & ! calendar p1a(1),' in CcclxDays_Adjust' CcclxDays_Adjust_int = 89478485 ! * 24 = 2^31 - 8, a LARGE number return ! and should cause a quick abort endif if (mo1 == 1 .and. da1 == 31) then ! Convert to 30-day months da1 = 1 ; mo1 = 2 else if (mo1 == 2) then da1 = da1+1 else if (mo1 == 3) then if (da1 == 1) then da1 = 30 ; mo1 = 2 else da1 = da1 -1 endif endif da1 = ( mo1 - 1) * 30 + da1 ! Work with 360 days in a year (12*30) ho1 = p1b / 1000000 mi1 = mod( p1b / 10000 , 100 ) se1 = mod( p1b / 100 , 100 ) ! calculate the difference between the decoded tdate1 ! and tdate2 in hours in this 360-day calendar nhours = (se1 - se2) / 3600.0_8 nhours = nhours + (mi1 - mi2) / 60.0_8 nhours = nhours + (ho1 - ho2) nhours = nhours + (da1 - da2) * 24.0_8 nhours = nhours + (ye1 - ye2) * 8640.0_8 ! 24*360 ! ensure that nhours = nhours(I) - ( correction * 24 ) nhoursi = ( tdate1 - tdate2 ) / td2h CcclxDays_Adjust_int = nint( (nhoursi - nhours) / 24.0 ) ier = mod( nint( (nhoursi - nhours)*10000.0, 8 ),240000_8 ) if (ier /= 0) print *,'probleme 2 dans CcclxDays_Adjust' endif return end !**FUNCTION NEWDATE : CONVERTS DATES BETWEEN TWO OF THE FOLLOWING !FORMATS: PRINTABLE DATE, CMC DATE-TIME STAMP, TRUE DATE ! INTEGER FUNCTION naetwed(DAT1,DAT2,DAT3,MODE) ! NEWDATE IMPLICIT NONE INTEGER DAT1,DAT2(*),DAT3,MODE ! !AUTHOR - E. BEAUCHESNE - JUN 96 ! !REVISION 001 M. Lepine, B.dugas - automne 2009/janvier 2010 - ! Ajouter le support des dates etendues (annees 0 ! a 10000) via les nouveaux modes +- 5, 6 et 7. !REVISION 002 B.dugas - novembre 2010 - Correction au mode -7. !REVISION 003 B.Dugas, M.Valin - fevrier 2016 - ! Supprimer les usages d'enonces EQUIVALENCE ! !LANGUAGE - fortran ! !OBJECT(NEWDATE) ! - CONVERTS A DATE BETWEEN TWO OF THE FOLLOWING FORMATS: ! PRINTABLE DATE, CMC DATE-TIME STAMP(OLD OR NEW), TRUE DATE ! !NOTE: see top of file for usage documentation ! ! useful constants ! 17280 = nb of 5 sec intervals in a day ! 288 = nb of 5 min intervals in a day ! jd1900 = julian day for jan 1, 1900 (2415021) ! jd1980 = julian day for jan 1, 1980 (2444240) ! jd2236 = julian day for jan 1, 2236 (2537742) ! jd0 = julian day for jan 1, 0 (1721060) ! jd10k = julian day for jan 1, 10,000 (5373485) ! td1900 = truedate for jan 1, 1900 , 00Z (-504904320) ! td2000 = truedate for jan 1, 2000 , 00Z (+126230400) ! tdstart = base for newdates ( jan 1, 1980, 00Z) ! max_offset = (((jd10k-jd0)*24)/8)*10 (109572750) ! exception = extended truedate for jan 1, 1901, 01Z ! troisg = 3 000 000 000 (Integer*8, Z'B2D05E00') !WARNING - IF NEWDATE RETURNS 1, OUTPUTS CAN TAKE ANY VALUE ! !* integer tdate,runnb,stamp,tmpr,dtpr,td1900,td2000 integer year,month,day,zulu,second,minute, max_offset integer tdstart,jd2236,jd1980,jd1900,jd0,jd10k,exception integer , dimension(12) :: mdays integer(8) date_unsigned,stamp8,masque32 integer(8), save :: troisg=3000000000_8 !!! integer(8), save :: troisg=transfer(Z'B2D05E00',1_8) !!! equivalence (stamp,stamp8) external itdmag2, dmagtp2 integer itdmag2 data tdstart /123200000/,jd1980 /2444240/,jd1900 /2415021/ data jd0 /1721060/,jd10k /5373485/, max_offset /109572750/ data jd2236 /2537742/, exception /16663825/ data td2000 /126230400/, td1900 /-504904320/ data mdays /31,29,31,30,31,30,31,31,30,31,30,31/ ! integer :: jd logical :: bissextile,validtd,validtm,validtme ! !!! integer(4), save :: w32=1 !!! integer(2) w16(2) !!! equivalence ( w16(1) , w32 ) !!! data w32/1/ ! ! calculates julian calendar day ! see CACM letter to editor by Fliegel and Flandern 1968 ! page 657 ! jd(year,month,day)=day-32075+1461*(year+4800+(month-14)/12)/4 & +367*(month-2-(month-14)/12*12)/12 & -3*((year+4900+(month-14)/12)/100)/4 ! ! check that date > jan 1, 1980 if 5 sec interval, else > jan 1,1900 ! validtd(tdate)=((tdate.ge.0) .or. ((tdate.lt.0) .and. & (tdate >= td1900).and.(mod(tdate-td1900,720) == 0))) ! ! check that year,month,day,zulu have valid values ! validtm(year,month,day,zulu)=( & (year.ge.1900) .and. (year.lt.2236) .and. & (month.le.12) .and. (day.le.mdays(month)) & .and. (zulu.le.23) .and. & (month.gt.0) .and. (day.gt.0) .and. (zulu.ge.0)) ! validtme(year,month,day,zulu)=( & (year >= 0) .and. (year < 10000) .and. & (month > 0) .and. (month <= 12) .and. & (day > 0) .and. (day <= mdays(month)) .and. & (zulu >= 0) .and. (zulu <= 23) ) ! bissextile(year) = ( ( (MOD(year,4) == 0) & .and.(MOD(year,100) /= 0) ) & .or. (MOD(year,400) == 0) ) ! masque32=ishft(-1_8,-32) ! = Z'00000000FFFFFFFF' ! if (abs(mode).gt.7 .or. mode.eq.0) goto 4 naetwed=0 ; stamp8 = 0 ; stamp = 0 goto (106,104,103,101,1,2,3,4,5,6,7,100,102,105,107),(mode+8) ! ! mode=-3 : from stamp(old or new) to printable ! 1 stamp=dat1 ! stamp .lt. -1 means extended stamp if (stamp.lt.-1) goto 103 dat2(1)=0 dat3=0 if (stamp.ge.tdstart) then ! stamp is a new date-time stamp tdate=(stamp-tdstart)/10*8+mod(stamp-tdstart,10) call datec(jd1900+(tdate-td1900)/17280,year,month,day) zulu=mod(tdate-td1900,17280)/720 second=(mod(tdate-td1900,17280)-zulu*720)*5 dtpr=year*10000+month*100+day tmpr=zulu*1000000+(second/60)*10000+mod(second,60)*100 else ! stamp is an old date-time stamp zulu=mod(stamp/10,100) year=mod(stamp/1000,100)+1900 day=mod(stamp/100000,100) month=mod(stamp/10000000,100) dtpr=year*10000+month*100+day tmpr=zulu*1000000 endif if (.not.validtm(year,month,day,zulu)) goto 4 if ((month .eq. 2) .and. (day .eq. 29)) then if (.not. bissextile(year)) goto 4 endif dat2(1)=dtpr dat3=tmpr return ! ! mode=3 : from printable to stamp ! 7 dtpr=dat2(1) tmpr=dat3 dat1=0 year=mod(dtpr/10000,10000) ! dtpr,tmpr=19010101,01000000 will be encoded extended stamp ! as the corresponding old date-time stamp is used as an ! error indicator by INCDATR/IDATMG2/DATMGP2 if (dtpr == 19010101 .and. tmpr == 01000000) goto 102 ! years not in [ 1900,2235 ] will be encoded extended stamp if (year < 1900 .or. year > 2235) goto 102 month=mod(dtpr/100,100) day=mod(dtpr,100) zulu=mod(tmpr/1000000,100) second=mod(tmpr/10000,100)*60+mod(tmpr/100,100) if (.not.validtm(year,month,day,zulu)) goto 4 if ((month .eq. 2) .and. (day .eq. 29)) then if (.not. bissextile(year)) goto 4 endif tdate=(jd(year,month,day)-jd1980)*17280+zulu*720+second/5 if (year.ge.2000 .or. (year.ge.1980 .and. second.ne.0)) then ! encode it in a new date-time stamp stamp=tdstart+(tdate/8)*10+mod(tdate,8) else ! encode it in an old date-time stamp tdate=(tdate-td1900)/720*720+td1900 call datec(jd1900+(tdate-td1900)/17280,year,month,day) zulu=mod(tdate-td1900,17280)/720 stamp=month*10000000+day*100000+(year-1900)*1000+zulu*10 endif dat1=stamp return ! ! mode=-2 : from true_date to printable ! 2 tdate=dat1 if (.not.validtd(tdate)) goto 4 call datec(jd1900+(tdate-td1900)/17280,year,month,day) zulu=mod(tdate-td1900,17280)/720 second=(mod(tdate-td1900,17280)-zulu*720)*5 dat2(1)=year*10000+month*100+day dat3=zulu*1000000+second/60*10000+mod(second,60)*100 return ! ! mode=2 : from printable to true_date ! 6 dtpr=dat2(1) tmpr=dat3 ! dtpr,tmpr=19010101,01000000 will be encoded extended true_date ! as the corresponding old date-time stamp is used as an ! error indicator by INCDATR/IDATMG2/DATMGP2 if (dtpr == 19010101 .and. tmpr == 01000000) goto 107 year=mod(dtpr/10000,10000) month=mod(dtpr/100,100) day=mod(dtpr,100) zulu=mod(tmpr/1000000,100) second=mod(tmpr/10000,100)*60+mod(tmpr/100,100) if (.not.validtm(year,month,day,zulu)) goto 4 if ((month .eq. 2) .and. (day .eq. 29)) then if (.not. bissextile(year)) goto 4 endif dat1=(jd(year,month,day)-jd1980)*17280+zulu*720+second/5 return ! ! mode=-1 : from (true_date and run_number) to stamp ! 3 tdate=dat1 runnb=dat3 33 if((runnb.gt.9) .or. (.not.validtd(tdate))) goto 4 ! use new stamp if > jan 1, 2000 or fractional hour if (tdate.ge.td2000 .or. mod(tdate,720).ne.0) then ! encode it in a new date-time stamp, ignore run nb stamp=tdstart+(tdate/8)*10+mod(tdate,8) else ! encode it in an old date-time stamp call datec(jd1900+(tdate-td1900)/17280,year,month,day) tdate=(tdate-td1900)/720*720+td1900 zulu=mod(tdate-td1900,17280)/720 stamp=month*10000000+day*100000+(year-1900)*1000+zulu*10 & +runnb endif dat2(1)=stamp return ! ! mode=1 : from stamp(old or new) to (true_date and run_number) ! 5 stamp=dat2(1) if (stamp.ge.tdstart) then ! stamp is a new date-time stamp tdate=(stamp-tdstart)/10*8+mod(stamp-tdstart,10) runnb=0 else if (stamp .lt. -1) then print *,'newdate error: mode 1, negative stamp' goto 4 else ! stamp is an old date-time stamp runnb=mod(stamp,10) zulu=mod(stamp/10,100) year=mod(stamp/1000,100)+1900 day=mod(stamp/100000,100) month=mod(stamp/10000000,100) tdate=(jd(year,month,day)-jd1980)*17280+zulu*720 endif if (.not.validtd(tdate)) goto 4 dat1=tdate dat3=runnb return ! ! mode=4 : from 14 word old style DATE array TO STAMP and array(14) ! 100 dat1=itdmag2(dat2) return ! ! mode=-4 : from STAMP TO 14 word old style DATE array ! 101 dat2(14)=dat1 call dmagtp2(dat2) return ! ! mode=5 : from printable to extended stamp ! 102 continue dtpr=dat2(1) tmpr=dat3 dat1=0 year=mod(dtpr/10000,10000) month=mod(dtpr/100,100) day=mod(dtpr,100) zulu=mod(tmpr/1000000,100) minute=mod(tmpr/10000,100) if (.not.validtme(year,month,day,zulu)) goto 4 if ((month .eq. 2) .and. (day .eq. 29)) then if (.not. bissextile(year)) goto 4 endif tdate=jd(year,month,day) if (tdate < jd0 .or. tdate >= jd10k) then print *,'newdate error: date outside of supported range, ', & 'date =',dtpr goto 4 endif tdate=(tdate-jd0)*24+zulu+minute/60 ! encode it in a new date-time stamp stamp=(tdate/8)*10+mod(tdate,8) date_unsigned=stamp + troisg ! implicit INTEGER(8) to INTEGER(4) transfer dat1=date_unsigned return ! ! mode=-5 : from extended stamp to printable ! 103 continue stamp8=dat1 ; stamp8=and(masque32,stamp8) dat2(1)= 0 ; dat3=0 date_unsigned = stamp8 !!! if (w16(1).eq.0) date_unsigned = ishft(stamp8,-32) if (date_unsigned < troisg .or. & date_unsigned >= troisg + max_offset) then print *,'newdate error: invalid stamp for mode -5, stamp=',stamp goto 4 endif stamp=date_unsigned - troisg tdate=stamp/10*8+mod(stamp,10) call datec(jd0+tdate/24,year,month,day) zulu=mod(tdate,24) minute=0 if (.not.validtme(year,month,day,zulu)) goto 4 if ((month .eq. 2) .and. (day .eq. 29)) then if (.not. bissextile(year)) goto 4 endif dat2(1)=year*10000+month*100+day dat3=zulu*1000000+minute*10000 return ! ! mode=-6 : from extended true date to stamp ! 104 continue tdate=dat1 if (tdate == exception .or. & ! 1901010101 (tdate/24+jd0) < jd1900 .or. & (tdate/24+jd0) >= jd2236) then ! extended stamp stamp=(tdate/8)*10+mod(tdate,8) date_unsigned=stamp + troisg ! implicit INTEGER(8) to INTEGER(4) transfer dat2(1)=date_unsigned else ! (new or old) stamp runnb=0 zulu=mod(tdate,24) tdate=(tdate/24+jd0-jd1980)*17280+zulu*720 goto 33 endif return ! ! mode=6 : from stamp to extended true date ! 105 continue stamp=dat2(1) if (stamp .lt. -1) then stamp8=stamp ; stamp8=and(masque32,stamp8) dat1=0 dat3=0 date_unsigned = stamp8 !!! if (w16(1).eq.0) date_unsigned = ishft(stamp8,-32) if (date_unsigned < troisg .or. & date_unsigned > troisg + max_offset) then print *,'newdate error: invalid stamp for mode -6, ', & 'stamp=',stamp goto 4 endif stamp=date_unsigned - troisg tdate=stamp/10*8+mod(stamp,10) dat1=tdate dat3=0 else if (stamp.ge.tdstart) then ! stamp is a new date-time stamp tdate=(stamp-tdstart)/10*8+mod(stamp-tdstart,10) call datec(jd1900+(tdate-td1900)/17280,year,month,day) zulu=mod(tdate-td1900,17280)/720 runnb=0 tdate=(jd(year,month,day)-jd0)*24+zulu ! print *,'Debug stamp > tdstart tdate=',tdate, ! % ' zulu=',zulu else ! stamp is an old date-time stamp runnb=mod(stamp,10) zulu=mod(stamp/10,100) year=mod(stamp/1000,100)+1900 day=mod(stamp/100000,100) month=mod(stamp/10000000,100) tdate=(jd(year,month,day)-jd0)*24+zulu ! print *,'Debug old date stamp tdate=',tdate endif if (.not.validtd(tdate)) goto 4 dat1=tdate dat3=runnb endif return ! ! mode=-7 : from extended true_date to printable ! 106 tdate=dat1 if (.not.validtd(tdate)) goto 4 call datec(jd0+tdate/24,year,month,day) zulu=mod(tdate,24) if (.not.validtme(year,month,day,zulu)) goto 4 if ((month .eq. 2) .and. (day .eq. 29)) then if (.not. bissextile(year)) goto 4 endif minute=0 dat2(1)=year*10000+month*100+day dat3=zulu*1000000+minute*10000 return ! ! mode=7 : from printable to extended true_date ! 107 dtpr=dat2(1) tmpr=dat3 year=mod(dtpr/10000,10000) if (year < 0 .or. year >= 10000) then print *,'newdate error: date outside of supported range, ', & 'date =',dtpr goto 4 endif month=mod(dtpr/100,100) day=mod(dtpr,100) zulu=mod(tmpr/1000000,100) second=mod(tmpr/10000,100)*60+mod(tmpr/100,100) if (.not.validtme(year,month,day,zulu)) goto 4 if ((month .eq. 2) .and. (day .eq. 29)) then if (.not. bissextile(year)) goto 4 endif dat1=(jd(year,month,day)-jd0)*24+zulu return ! ! error: bad mode or bad arguments ! 4 naetwed=1 return end
lgpl-2.1
hlokavarapu/calypso
src/Fortran_libraries/SERIAL_src/SPH_SPECTR_src/copy_rj_spec_name_to_node.f90
3
1642
!> @file copy_rj_spec_name_to_node.f90 !! module copy_rj_spec_name_to_node !! !! @author H. Matsui !! @date Programmed in Feb., 2008 ! !> @brief Copy spectr fields name to nodal field name !! !!@verbatim !! subroutine copy_rj_spec_name_to_nod_fld !!@endverbatim ! module copy_rj_spec_name_to_node ! use m_precision ! implicit none ! ! ----------------------------------------------------------------------- ! contains ! ! ----------------------------------------------------------------------- ! subroutine copy_rj_spec_name_to_nod_fld(nod_fld) ! use t_phys_data use m_sph_spectr_data ! type(phys_data),intent(inout) :: nod_fld ! ! nod_fld%num_phys = num_phys_rj nod_fld%ntot_phys = ntot_phys_rj ! nod_fld%num_phys_viz = num_phys_rj_vis nod_fld%ntot_phys_viz = ntot_comp_rj_vis ! call alloc_phys_name_type(nod_fld) ! nod_fld%num_component(1:nod_fld%num_phys) & & = num_phys_comp_rj(1:nod_fld%num_phys) nod_fld%phys_name(1:nod_fld%num_phys) & & = phys_name_rj(1:nod_fld%num_phys) nod_fld%iflag_monitor(1:nod_fld%num_phys) & & = iflag_monitor_rj(1:nod_fld%num_phys) nod_fld%istack_component(0:nod_fld%num_phys) & & = istack_phys_comp_rj(0:nod_fld%num_phys) ! end subroutine copy_rj_spec_name_to_nod_fld ! ! ----------------------------------------------------------------------- ! end module copy_rj_spec_name_to_node
gpl-3.0
nvarini/espresso_iohpc
S3DE/iotk/src/iotk_dat+COMPLEX1_3.f90
5
73094
! Input/Output Tool Kit (IOTK) ! Copyright (C) 2004-2006 Giovanni Bussi ! ! This library is free software; you can redistribute it and/or ! modify it under the terms of the GNU Lesser General Public ! License as published by the Free Software Foundation; either ! version 2.1 of the License, or (at your option) any later version. ! ! This library is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! Lesser General Public License for more details. ! ! You should have received a copy of the GNU Lesser General Public ! License along with this library; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA !------------------------------------------------------------------------------! ! Inclusion of configuration file #include "iotk_config.h" !------------------------------------------------------------------------------! #include "iotk_auxmacros.h" #ifdef __IOTK_COMPLEX1 #if 3 <= __IOTK_MAXRANK subroutine iotk_write_dat_COMPLEX1_3(unit,name,dat,dummy,attr,columns,sep,fmt,ierr) use iotk_base use iotk_error_interf use iotk_attr_interf, only : iotk_write_attr use iotk_write_interf use iotk_fmt_interf use iotk_str_interf use iotk_unit_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit character(len=*), intent(in) :: name COMPLEX (kind=this_kind), intent(in) :: dat (:,:,:) type(iotk_dummytype), optional :: dummy character(len=*), optional, intent(in) :: attr integer, optional, intent(in) :: columns character(len=*), optional, intent(in) :: sep character(len=*), optional, intent(in) :: fmt integer, optional, intent(out) :: ierr integer :: ierrl,lunit,iostat logical :: binary,raw,stream integer :: lcolumns !-< integer :: dat_rank,i integer, dimension(:), allocatable :: dat_shape logical :: qe_syntax !-> integer(iotk_header_kind), parameter :: idummy=0 character(100) :: lsep character(300) :: usefmt character(iotk_attlenx) :: lattr character(iotk_attlenx) :: attr_tmp !-< character(len=10) :: tmpstr !-> type (iotk_unit), pointer :: this COMPLEX (kind=this_kind),allocatable :: dattmp(:) integer :: itmp ierrl = 0 iostat = 0 lcolumns = 1 lsep(1:2) = " "//iotk_eos if(present(columns)) lcolumns = columns if(present(sep)) then call iotk_strcpy(lsep,sep,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if lunit = iotk_phys_unit(unit) call iotk_unit_get(lunit,pointer=this) !-< qe_syntax = .false. if (associated(this)) then qe_syntax = this%qe_syntax end if !-> raw = .false. if(associated(this)) then raw = this%raw end if call iotk_inquire(lunit,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(usefmt,"!",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(present(fmt) .and. .not. raw) call iotk_strcpy(usefmt,iotk_strtrim(fmt),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strscan(usefmt,"<>&")/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Special characters (<>&) found in fmt string') call iotk_error_write(ierrl,"unit",unit) call iotk_error_write(ierrl,"name",trim(name)) call iotk_error_write(ierrl,"fmt",trim(fmt)) goto 1 end if !-< if (.not.qe_syntax) then !-> call iotk_write_attr(lattr,"type",iotk_tolower("COMPLEX"),first=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_attr(lattr,"size",size(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< end if !-> !-< if (qe_syntax) then lattr(1:1) = iotk_eos dat_rank = size(shape(dat)) if (dat_rank>0) then allocate(dat_shape(dat_rank)) dat_shape = shape(dat) call iotk_write_attr(lattr,"rank",dat_rank,ierr=ierrl,first=.true.) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do i=1,dat_rank write(tmpstr,'(i10)') i tmpstr = adjustl(tmpstr) call iotk_write_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),dat_shape(i),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end do deallocate(dat_shape) end if end if !-> if(binary) then call iotk_write_attr(lattr,"kind",kind(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if if(.not.iotk_strcomp(usefmt,"!") .and. .not.qe_syntax) call iotk_write_attr(lattr,"fmt",iotk_strtrim(usefmt),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(lcolumns/=1) call iotk_write_attr(lattr,"columns",lcolumns,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-> if(present(attr)) then attr_tmp(1:1)=iotk_eos call iotk_strcpy(attr_tmp,attr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"type",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"kind",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"size",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"fmt",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"columns",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"len",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strlen_trim(attr_tmp)>0) call iotk_strcat(lattr,iotk_strtrim(attr_tmp),ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,name,lattr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< else if(present(attr)) then call iotk_write_begin(unit,name,attr,ierr=ierrl) else call iotk_write_begin(unit,name,ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,iotk_tolower("COMPLEX"),lattr,ierr=ierrl,new_line=.true.) end if !-> allocate(dattmp(size(dat))) #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dattmp,dat,size(dattmp),1) #else dattmp = pack(dat,mask=.true.) #endif if(binary) then if(raw) then write(lunit,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,iostat=iostat) idummy,(dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if else if(raw) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"*")) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"!")) then !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> else !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> end if end if !-< if (qe_syntax) then call iotk_write_end(unit,iotk_tolower("COMPLEX"),indentation=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> call iotk_write_end(unit,name,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if 1 continue if(allocated(dattmp)) deallocate(dattmp) if(present(ierr)) then ierr = ierrl else if(ierrl/=0) call iotk_error_handler(ierrl) end if end subroutine iotk_write_dat_COMPLEX1_3 subroutine iotk_scan_dat_COMPLEX1_3(unit,name,dat,dummy,attr,found,default,ierr) use iotk_base !-< use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr !-> use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit character(len=*), intent(in) :: name #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:) #endif type(iotk_dummytype), optional :: dummy #ifdef __IOTK_WORKAROUND6 character(len=*), optional :: attr #else character(len=*), optional, intent(out) :: attr #endif logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr !-< ! ... necessary because i need the syntax to use type (iotk_unit), pointer :: this ! ... necessary to read the tag describing the type character(iotk_taglenx) :: ltag character(iotk_namlenx) :: r_name character(iotk_attlenx) :: lattr2 character(len=20) :: tmpstr ! ... necessary for scan_tag logical :: binary,stream,qe_syntax integer :: r_control,rrank integer :: rshape,i !-> integer :: columns logical :: inside,foundl !-< call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .false. if (associated(this)) THEN qe_syntax = this%qe_syntax end if !-> inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. call iotk_scan_begin(unit,name,lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(present(attr)) call iotk_strcpy(attr,lattr,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-< call iotk_parse_dat(lattr,rtype,rkind,rsize,rlen,fmt,columns,ierrl) ! Note that columns is not effectively used if(ierrl/=0) goto 1 !-< else call iotk_inquire(iotk_phys_unit(unit),binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do call iotk_scan_tag(unit,+1,r_control,ltag,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if (r_control==4) then cycle else exit end if end do call iotk_tag_parse(ltag,r_name,lattr2,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(rtype,r_name,ierrl) rtype = iotk_toupper(rtype) rlen = -1 if (rtype(1:iotk_strlen(rtype))/="STRING") then call iotk_scan_attr(lattr2,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr2,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if else call iotk_strcpy(rtype,"CHARACTER",ierrl) rsize = -1 end if call iotk_scan_attr(lattr2,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if end if !-> if(.not. (iotk_strcomp(rtype,iotk_eos) .or. iotk_strcomp(rtype,"COMPLEX") ) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,' ') call iotk_error_write(ierrl,"rtype",rtype(1:iotk_strlen(rtype))) call iotk_error_write(ierrl,"type","COMPLEX") goto 1 end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"name",name) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif 1 continue !-< if ( allocated(tmpdat) ) deallocate(tmpdat) !-> if(inside) then !-< if (qe_syntax) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if !-> call iotk_scan_end(unit,name,ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"name",name) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_COMPLEX1_3 !-< ! ... new procedure: scan dat when you are already inside the data tag subroutine iotk_scan_dat_inside_COMPLEX1_3(unit,dat,dummy,found,default,ierr) use iotk_base use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:) #endif type(iotk_dummytype), optional :: dummy logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) character(len=20) :: tmpstr integer :: rrank integer :: rshape,i integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr character(iotk_namlenx) :: rname type (iotk_unit), pointer :: this integer :: columns logical :: inside,foundl,qe_syntax call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .true. IF (associated(this)) then qe_syntax = this%qe_syntax END IF inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. if (.not.qe_syntax) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rname = iotk_tolower("COMPLEX") call iotk_scan_begin(unit,iotk_tolower("COMPLEX"),lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rlen = -1 call iotk_scan_attr(lattr,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if call iotk_scan_attr(lattr,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"rname",rname) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif deallocate(tmpdat) 1 continue if(inside) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"rname",rname) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_inside_COMPLEX1_3 !-> #endif #endif subroutine iotk_dat_dummy_COMPLEX1_3 write(0,*) end subroutine iotk_dat_dummy_COMPLEX1_3 !------------------------------------------------------------------------------! ! Inclusion of configuration file #include "iotk_config.h" !------------------------------------------------------------------------------! #include "iotk_auxmacros.h" #ifdef __IOTK_COMPLEX1 #if 4 <= __IOTK_MAXRANK subroutine iotk_write_dat_COMPLEX1_4(unit,name,dat,dummy,attr,columns,sep,fmt,ierr) use iotk_base use iotk_error_interf use iotk_attr_interf, only : iotk_write_attr use iotk_write_interf use iotk_fmt_interf use iotk_str_interf use iotk_unit_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit character(len=*), intent(in) :: name COMPLEX (kind=this_kind), intent(in) :: dat (:,:,:,:) type(iotk_dummytype), optional :: dummy character(len=*), optional, intent(in) :: attr integer, optional, intent(in) :: columns character(len=*), optional, intent(in) :: sep character(len=*), optional, intent(in) :: fmt integer, optional, intent(out) :: ierr integer :: ierrl,lunit,iostat logical :: binary,raw,stream integer :: lcolumns !-< integer :: dat_rank,i integer, dimension(:), allocatable :: dat_shape logical :: qe_syntax !-> integer(iotk_header_kind), parameter :: idummy=0 character(100) :: lsep character(300) :: usefmt character(iotk_attlenx) :: lattr character(iotk_attlenx) :: attr_tmp !-< character(len=10) :: tmpstr !-> type (iotk_unit), pointer :: this COMPLEX (kind=this_kind),allocatable :: dattmp(:) integer :: itmp ierrl = 0 iostat = 0 lcolumns = 1 lsep(1:2) = " "//iotk_eos if(present(columns)) lcolumns = columns if(present(sep)) then call iotk_strcpy(lsep,sep,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if lunit = iotk_phys_unit(unit) call iotk_unit_get(lunit,pointer=this) !-< qe_syntax = .false. if (associated(this)) then qe_syntax = this%qe_syntax end if !-> raw = .false. if(associated(this)) then raw = this%raw end if call iotk_inquire(lunit,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(usefmt,"!",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(present(fmt) .and. .not. raw) call iotk_strcpy(usefmt,iotk_strtrim(fmt),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strscan(usefmt,"<>&")/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Special characters (<>&) found in fmt string') call iotk_error_write(ierrl,"unit",unit) call iotk_error_write(ierrl,"name",trim(name)) call iotk_error_write(ierrl,"fmt",trim(fmt)) goto 1 end if !-< if (.not.qe_syntax) then !-> call iotk_write_attr(lattr,"type",iotk_tolower("COMPLEX"),first=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_attr(lattr,"size",size(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< end if !-> !-< if (qe_syntax) then lattr(1:1) = iotk_eos dat_rank = size(shape(dat)) if (dat_rank>0) then allocate(dat_shape(dat_rank)) dat_shape = shape(dat) call iotk_write_attr(lattr,"rank",dat_rank,ierr=ierrl,first=.true.) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do i=1,dat_rank write(tmpstr,'(i10)') i tmpstr = adjustl(tmpstr) call iotk_write_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),dat_shape(i),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end do deallocate(dat_shape) end if end if !-> if(binary) then call iotk_write_attr(lattr,"kind",kind(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if if(.not.iotk_strcomp(usefmt,"!") .and. .not.qe_syntax) call iotk_write_attr(lattr,"fmt",iotk_strtrim(usefmt),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(lcolumns/=1) call iotk_write_attr(lattr,"columns",lcolumns,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-> if(present(attr)) then attr_tmp(1:1)=iotk_eos call iotk_strcpy(attr_tmp,attr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"type",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"kind",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"size",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"fmt",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"columns",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"len",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strlen_trim(attr_tmp)>0) call iotk_strcat(lattr,iotk_strtrim(attr_tmp),ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,name,lattr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< else if(present(attr)) then call iotk_write_begin(unit,name,attr,ierr=ierrl) else call iotk_write_begin(unit,name,ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,iotk_tolower("COMPLEX"),lattr,ierr=ierrl,new_line=.true.) end if !-> allocate(dattmp(size(dat))) #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dattmp,dat,size(dattmp),1) #else dattmp = pack(dat,mask=.true.) #endif if(binary) then if(raw) then write(lunit,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,iostat=iostat) idummy,(dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if else if(raw) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"*")) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"!")) then !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> else !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> end if end if !-< if (qe_syntax) then call iotk_write_end(unit,iotk_tolower("COMPLEX"),indentation=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> call iotk_write_end(unit,name,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if 1 continue if(allocated(dattmp)) deallocate(dattmp) if(present(ierr)) then ierr = ierrl else if(ierrl/=0) call iotk_error_handler(ierrl) end if end subroutine iotk_write_dat_COMPLEX1_4 subroutine iotk_scan_dat_COMPLEX1_4(unit,name,dat,dummy,attr,found,default,ierr) use iotk_base !-< use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr !-> use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit character(len=*), intent(in) :: name #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:) #endif type(iotk_dummytype), optional :: dummy #ifdef __IOTK_WORKAROUND6 character(len=*), optional :: attr #else character(len=*), optional, intent(out) :: attr #endif logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr !-< ! ... necessary because i need the syntax to use type (iotk_unit), pointer :: this ! ... necessary to read the tag describing the type character(iotk_taglenx) :: ltag character(iotk_namlenx) :: r_name character(iotk_attlenx) :: lattr2 character(len=20) :: tmpstr ! ... necessary for scan_tag logical :: binary,stream,qe_syntax integer :: r_control,rrank integer :: rshape,i !-> integer :: columns logical :: inside,foundl !-< call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .false. if (associated(this)) THEN qe_syntax = this%qe_syntax end if !-> inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. call iotk_scan_begin(unit,name,lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(present(attr)) call iotk_strcpy(attr,lattr,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-< call iotk_parse_dat(lattr,rtype,rkind,rsize,rlen,fmt,columns,ierrl) ! Note that columns is not effectively used if(ierrl/=0) goto 1 !-< else call iotk_inquire(iotk_phys_unit(unit),binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do call iotk_scan_tag(unit,+1,r_control,ltag,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if (r_control==4) then cycle else exit end if end do call iotk_tag_parse(ltag,r_name,lattr2,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(rtype,r_name,ierrl) rtype = iotk_toupper(rtype) rlen = -1 if (rtype(1:iotk_strlen(rtype))/="STRING") then call iotk_scan_attr(lattr2,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr2,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if else call iotk_strcpy(rtype,"CHARACTER",ierrl) rsize = -1 end if call iotk_scan_attr(lattr2,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if end if !-> if(.not. (iotk_strcomp(rtype,iotk_eos) .or. iotk_strcomp(rtype,"COMPLEX") ) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,' ') call iotk_error_write(ierrl,"rtype",rtype(1:iotk_strlen(rtype))) call iotk_error_write(ierrl,"type","COMPLEX") goto 1 end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"name",name) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif 1 continue !-< if ( allocated(tmpdat) ) deallocate(tmpdat) !-> if(inside) then !-< if (qe_syntax) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if !-> call iotk_scan_end(unit,name,ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"name",name) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_COMPLEX1_4 !-< ! ... new procedure: scan dat when you are already inside the data tag subroutine iotk_scan_dat_inside_COMPLEX1_4(unit,dat,dummy,found,default,ierr) use iotk_base use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:) #endif type(iotk_dummytype), optional :: dummy logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) character(len=20) :: tmpstr integer :: rrank integer :: rshape,i integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr character(iotk_namlenx) :: rname type (iotk_unit), pointer :: this integer :: columns logical :: inside,foundl,qe_syntax call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .true. IF (associated(this)) then qe_syntax = this%qe_syntax END IF inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. if (.not.qe_syntax) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rname = iotk_tolower("COMPLEX") call iotk_scan_begin(unit,iotk_tolower("COMPLEX"),lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rlen = -1 call iotk_scan_attr(lattr,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if call iotk_scan_attr(lattr,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"rname",rname) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif deallocate(tmpdat) 1 continue if(inside) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"rname",rname) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_inside_COMPLEX1_4 !-> #endif #endif subroutine iotk_dat_dummy_COMPLEX1_4 write(0,*) end subroutine iotk_dat_dummy_COMPLEX1_4 !------------------------------------------------------------------------------! ! Inclusion of configuration file #include "iotk_config.h" !------------------------------------------------------------------------------! #include "iotk_auxmacros.h" #ifdef __IOTK_COMPLEX1 #if 5 <= __IOTK_MAXRANK subroutine iotk_write_dat_COMPLEX1_5(unit,name,dat,dummy,attr,columns,sep,fmt,ierr) use iotk_base use iotk_error_interf use iotk_attr_interf, only : iotk_write_attr use iotk_write_interf use iotk_fmt_interf use iotk_str_interf use iotk_unit_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit character(len=*), intent(in) :: name COMPLEX (kind=this_kind), intent(in) :: dat (:,:,:,:,:) type(iotk_dummytype), optional :: dummy character(len=*), optional, intent(in) :: attr integer, optional, intent(in) :: columns character(len=*), optional, intent(in) :: sep character(len=*), optional, intent(in) :: fmt integer, optional, intent(out) :: ierr integer :: ierrl,lunit,iostat logical :: binary,raw,stream integer :: lcolumns !-< integer :: dat_rank,i integer, dimension(:), allocatable :: dat_shape logical :: qe_syntax !-> integer(iotk_header_kind), parameter :: idummy=0 character(100) :: lsep character(300) :: usefmt character(iotk_attlenx) :: lattr character(iotk_attlenx) :: attr_tmp !-< character(len=10) :: tmpstr !-> type (iotk_unit), pointer :: this COMPLEX (kind=this_kind),allocatable :: dattmp(:) integer :: itmp ierrl = 0 iostat = 0 lcolumns = 1 lsep(1:2) = " "//iotk_eos if(present(columns)) lcolumns = columns if(present(sep)) then call iotk_strcpy(lsep,sep,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if lunit = iotk_phys_unit(unit) call iotk_unit_get(lunit,pointer=this) !-< qe_syntax = .false. if (associated(this)) then qe_syntax = this%qe_syntax end if !-> raw = .false. if(associated(this)) then raw = this%raw end if call iotk_inquire(lunit,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(usefmt,"!",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(present(fmt) .and. .not. raw) call iotk_strcpy(usefmt,iotk_strtrim(fmt),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strscan(usefmt,"<>&")/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Special characters (<>&) found in fmt string') call iotk_error_write(ierrl,"unit",unit) call iotk_error_write(ierrl,"name",trim(name)) call iotk_error_write(ierrl,"fmt",trim(fmt)) goto 1 end if !-< if (.not.qe_syntax) then !-> call iotk_write_attr(lattr,"type",iotk_tolower("COMPLEX"),first=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_attr(lattr,"size",size(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< end if !-> !-< if (qe_syntax) then lattr(1:1) = iotk_eos dat_rank = size(shape(dat)) if (dat_rank>0) then allocate(dat_shape(dat_rank)) dat_shape = shape(dat) call iotk_write_attr(lattr,"rank",dat_rank,ierr=ierrl,first=.true.) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do i=1,dat_rank write(tmpstr,'(i10)') i tmpstr = adjustl(tmpstr) call iotk_write_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),dat_shape(i),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end do deallocate(dat_shape) end if end if !-> if(binary) then call iotk_write_attr(lattr,"kind",kind(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if if(.not.iotk_strcomp(usefmt,"!") .and. .not.qe_syntax) call iotk_write_attr(lattr,"fmt",iotk_strtrim(usefmt),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(lcolumns/=1) call iotk_write_attr(lattr,"columns",lcolumns,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-> if(present(attr)) then attr_tmp(1:1)=iotk_eos call iotk_strcpy(attr_tmp,attr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"type",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"kind",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"size",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"fmt",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"columns",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"len",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strlen_trim(attr_tmp)>0) call iotk_strcat(lattr,iotk_strtrim(attr_tmp),ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,name,lattr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< else if(present(attr)) then call iotk_write_begin(unit,name,attr,ierr=ierrl) else call iotk_write_begin(unit,name,ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,iotk_tolower("COMPLEX"),lattr,ierr=ierrl,new_line=.true.) end if !-> allocate(dattmp(size(dat))) #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dattmp,dat,size(dattmp),1) #else dattmp = pack(dat,mask=.true.) #endif if(binary) then if(raw) then write(lunit,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,iostat=iostat) idummy,(dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if else if(raw) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"*")) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"!")) then !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> else !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> end if end if !-< if (qe_syntax) then call iotk_write_end(unit,iotk_tolower("COMPLEX"),indentation=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> call iotk_write_end(unit,name,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if 1 continue if(allocated(dattmp)) deallocate(dattmp) if(present(ierr)) then ierr = ierrl else if(ierrl/=0) call iotk_error_handler(ierrl) end if end subroutine iotk_write_dat_COMPLEX1_5 subroutine iotk_scan_dat_COMPLEX1_5(unit,name,dat,dummy,attr,found,default,ierr) use iotk_base !-< use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr !-> use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit character(len=*), intent(in) :: name #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:,:) #endif type(iotk_dummytype), optional :: dummy #ifdef __IOTK_WORKAROUND6 character(len=*), optional :: attr #else character(len=*), optional, intent(out) :: attr #endif logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr !-< ! ... necessary because i need the syntax to use type (iotk_unit), pointer :: this ! ... necessary to read the tag describing the type character(iotk_taglenx) :: ltag character(iotk_namlenx) :: r_name character(iotk_attlenx) :: lattr2 character(len=20) :: tmpstr ! ... necessary for scan_tag logical :: binary,stream,qe_syntax integer :: r_control,rrank integer :: rshape,i !-> integer :: columns logical :: inside,foundl !-< call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .false. if (associated(this)) THEN qe_syntax = this%qe_syntax end if !-> inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. call iotk_scan_begin(unit,name,lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(present(attr)) call iotk_strcpy(attr,lattr,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-< call iotk_parse_dat(lattr,rtype,rkind,rsize,rlen,fmt,columns,ierrl) ! Note that columns is not effectively used if(ierrl/=0) goto 1 !-< else call iotk_inquire(iotk_phys_unit(unit),binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do call iotk_scan_tag(unit,+1,r_control,ltag,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if (r_control==4) then cycle else exit end if end do call iotk_tag_parse(ltag,r_name,lattr2,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(rtype,r_name,ierrl) rtype = iotk_toupper(rtype) rlen = -1 if (rtype(1:iotk_strlen(rtype))/="STRING") then call iotk_scan_attr(lattr2,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr2,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if else call iotk_strcpy(rtype,"CHARACTER",ierrl) rsize = -1 end if call iotk_scan_attr(lattr2,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if end if !-> if(.not. (iotk_strcomp(rtype,iotk_eos) .or. iotk_strcomp(rtype,"COMPLEX") ) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,' ') call iotk_error_write(ierrl,"rtype",rtype(1:iotk_strlen(rtype))) call iotk_error_write(ierrl,"type","COMPLEX") goto 1 end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"name",name) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif 1 continue !-< if ( allocated(tmpdat) ) deallocate(tmpdat) !-> if(inside) then !-< if (qe_syntax) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if !-> call iotk_scan_end(unit,name,ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"name",name) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_COMPLEX1_5 !-< ! ... new procedure: scan dat when you are already inside the data tag subroutine iotk_scan_dat_inside_COMPLEX1_5(unit,dat,dummy,found,default,ierr) use iotk_base use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX1 integer, intent(in) :: unit #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:,:) #endif type(iotk_dummytype), optional :: dummy logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) character(len=20) :: tmpstr integer :: rrank integer :: rshape,i integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr character(iotk_namlenx) :: rname type (iotk_unit), pointer :: this integer :: columns logical :: inside,foundl,qe_syntax call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .true. IF (associated(this)) then qe_syntax = this%qe_syntax END IF inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. if (.not.qe_syntax) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rname = iotk_tolower("COMPLEX") call iotk_scan_begin(unit,iotk_tolower("COMPLEX"),lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rlen = -1 call iotk_scan_attr(lattr,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if call iotk_scan_attr(lattr,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"rname",rname) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX1(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif deallocate(tmpdat) 1 continue if(inside) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"rname",rname) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_inside_COMPLEX1_5 !-> #endif #endif subroutine iotk_dat_dummy_COMPLEX1_5 write(0,*) end subroutine iotk_dat_dummy_COMPLEX1_5
gpl-2.0
ROCmSoftwarePlatform/hipeigen
blas/testing/sblat3.f
133
104172
*> \brief \b SBLAT3 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * PROGRAM SBLAT3 * * *> \par Purpose: * ============= *> *> \verbatim *> *> Test program for the REAL Level 3 Blas. *> *> The program must be driven by a short data file. The first 14 records *> of the file are read using list-directed input, the last 6 records *> are read using the format ( A6, L2 ). An annotated example of a data *> file can be obtained by deleting the first 3 characters from the *> following 20 lines: *> 'sblat3.out' NAME OF SUMMARY OUTPUT FILE *> 6 UNIT NUMBER OF SUMMARY FILE *> 'SBLAT3.SNAP' NAME OF SNAPSHOT OUTPUT FILE *> -1 UNIT NUMBER OF SNAPSHOT FILE (NOT USED IF .LT. 0) *> F LOGICAL FLAG, T TO REWIND SNAPSHOT FILE AFTER EACH RECORD. *> F LOGICAL FLAG, T TO STOP ON FAILURES. *> T LOGICAL FLAG, T TO TEST ERROR EXITS. *> 16.0 THRESHOLD VALUE OF TEST RATIO *> 6 NUMBER OF VALUES OF N *> 0 1 2 3 5 9 VALUES OF N *> 3 NUMBER OF VALUES OF ALPHA *> 0.0 1.0 0.7 VALUES OF ALPHA *> 3 NUMBER OF VALUES OF BETA *> 0.0 1.0 1.3 VALUES OF BETA *> SGEMM T PUT F FOR NO TEST. SAME COLUMNS. *> SSYMM T PUT F FOR NO TEST. SAME COLUMNS. *> STRMM T PUT F FOR NO TEST. SAME COLUMNS. *> STRSM T PUT F FOR NO TEST. SAME COLUMNS. *> SSYRK T PUT F FOR NO TEST. SAME COLUMNS. *> SSYR2K T PUT F FOR NO TEST. SAME COLUMNS. *> *> Further Details *> =============== *> *> See: *> *> Dongarra J. J., Du Croz J. J., Duff I. S. and Hammarling S. *> A Set of Level 3 Basic Linear Algebra Subprograms. *> *> Technical Memorandum No.88 (Revision 1), Mathematics and *> Computer Science Division, Argonne National Laboratory, 9700 *> South Cass Avenue, Argonne, Illinois 60439, US. *> *> -- Written on 8-February-1989. *> Jack Dongarra, Argonne National Laboratory. *> Iain Duff, AERE Harwell. *> Jeremy Du Croz, Numerical Algorithms Group Ltd. *> Sven Hammarling, Numerical Algorithms Group Ltd. *> *> 10-9-00: Change STATUS='NEW' to 'UNKNOWN' so that the testers *> can be run multiple times without deleting generated *> output files (susan) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date April 2012 * *> \ingroup single_blas_testing * * ===================================================================== PROGRAM SBLAT3 * * -- Reference BLAS test routine (version 3.4.1) -- * -- Reference BLAS is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * April 2012 * * ===================================================================== * * .. Parameters .. INTEGER NIN PARAMETER ( NIN = 5 ) INTEGER NSUBS PARAMETER ( NSUBS = 6 ) REAL ZERO, ONE PARAMETER ( ZERO = 0.0, ONE = 1.0 ) INTEGER NMAX PARAMETER ( NMAX = 65 ) INTEGER NIDMAX, NALMAX, NBEMAX PARAMETER ( NIDMAX = 9, NALMAX = 7, NBEMAX = 7 ) * .. Local Scalars .. REAL EPS, ERR, THRESH INTEGER I, ISNUM, J, N, NALF, NBET, NIDIM, NOUT, NTRA LOGICAL FATAL, LTESTT, REWI, SAME, SFATAL, TRACE, $ TSTERR CHARACTER*1 TRANSA, TRANSB CHARACTER*6 SNAMET CHARACTER*32 SNAPS, SUMMRY * .. Local Arrays .. REAL AA( NMAX*NMAX ), AB( NMAX, 2*NMAX ), $ ALF( NALMAX ), AS( NMAX*NMAX ), $ BB( NMAX*NMAX ), BET( NBEMAX ), $ BS( NMAX*NMAX ), C( NMAX, NMAX ), $ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ), $ G( NMAX ), W( 2*NMAX ) INTEGER IDIM( NIDMAX ) LOGICAL LTEST( NSUBS ) CHARACTER*6 SNAMES( NSUBS ) * .. External Functions .. REAL SDIFF LOGICAL LSE EXTERNAL SDIFF, LSE * .. External Subroutines .. EXTERNAL SCHK1, SCHK2, SCHK3, SCHK4, SCHK5, SCHKE, SMMCH * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. Scalars in Common .. INTEGER INFOT, NOUTC LOGICAL LERR, OK CHARACTER*6 SRNAMT * .. Common blocks .. COMMON /INFOC/INFOT, NOUTC, OK, LERR COMMON /SRNAMC/SRNAMT * .. Data statements .. DATA SNAMES/'SGEMM ', 'SSYMM ', 'STRMM ', 'STRSM ', $ 'SSYRK ', 'SSYR2K'/ * .. Executable Statements .. * * Read name and unit number for summary output file and open file. * READ( NIN, FMT = * )SUMMRY READ( NIN, FMT = * )NOUT OPEN( NOUT, FILE = SUMMRY ) NOUTC = NOUT * * Read name and unit number for snapshot output file and open file. * READ( NIN, FMT = * )SNAPS READ( NIN, FMT = * )NTRA TRACE = NTRA.GE.0 IF( TRACE )THEN OPEN( NTRA, FILE = SNAPS ) END IF * Read the flag that directs rewinding of the snapshot file. READ( NIN, FMT = * )REWI REWI = REWI.AND.TRACE * Read the flag that directs stopping on any failure. READ( NIN, FMT = * )SFATAL * Read the flag that indicates whether error exits are to be tested. READ( NIN, FMT = * )TSTERR * Read the threshold value of the test ratio READ( NIN, FMT = * )THRESH * * Read and check the parameter values for the tests. * * Values of N READ( NIN, FMT = * )NIDIM IF( NIDIM.LT.1.OR.NIDIM.GT.NIDMAX )THEN WRITE( NOUT, FMT = 9997 )'N', NIDMAX GO TO 220 END IF READ( NIN, FMT = * )( IDIM( I ), I = 1, NIDIM ) DO 10 I = 1, NIDIM IF( IDIM( I ).LT.0.OR.IDIM( I ).GT.NMAX )THEN WRITE( NOUT, FMT = 9996 )NMAX GO TO 220 END IF 10 CONTINUE * Values of ALPHA READ( NIN, FMT = * )NALF IF( NALF.LT.1.OR.NALF.GT.NALMAX )THEN WRITE( NOUT, FMT = 9997 )'ALPHA', NALMAX GO TO 220 END IF READ( NIN, FMT = * )( ALF( I ), I = 1, NALF ) * Values of BETA READ( NIN, FMT = * )NBET IF( NBET.LT.1.OR.NBET.GT.NBEMAX )THEN WRITE( NOUT, FMT = 9997 )'BETA', NBEMAX GO TO 220 END IF READ( NIN, FMT = * )( BET( I ), I = 1, NBET ) * * Report values of parameters. * WRITE( NOUT, FMT = 9995 ) WRITE( NOUT, FMT = 9994 )( IDIM( I ), I = 1, NIDIM ) WRITE( NOUT, FMT = 9993 )( ALF( I ), I = 1, NALF ) WRITE( NOUT, FMT = 9992 )( BET( I ), I = 1, NBET ) IF( .NOT.TSTERR )THEN WRITE( NOUT, FMT = * ) WRITE( NOUT, FMT = 9984 ) END IF WRITE( NOUT, FMT = * ) WRITE( NOUT, FMT = 9999 )THRESH WRITE( NOUT, FMT = * ) * * Read names of subroutines and flags which indicate * whether they are to be tested. * DO 20 I = 1, NSUBS LTEST( I ) = .FALSE. 20 CONTINUE 30 READ( NIN, FMT = 9988, END = 60 )SNAMET, LTESTT DO 40 I = 1, NSUBS IF( SNAMET.EQ.SNAMES( I ) ) $ GO TO 50 40 CONTINUE WRITE( NOUT, FMT = 9990 )SNAMET STOP 50 LTEST( I ) = LTESTT GO TO 30 * 60 CONTINUE CLOSE ( NIN ) * * Compute EPS (the machine precision). * EPS = EPSILON(ZERO) WRITE( NOUT, FMT = 9998 )EPS * * Check the reliability of SMMCH using exact data. * N = MIN( 32, NMAX ) DO 100 J = 1, N DO 90 I = 1, N AB( I, J ) = MAX( I - J + 1, 0 ) 90 CONTINUE AB( J, NMAX + 1 ) = J AB( 1, NMAX + J ) = J C( J, 1 ) = ZERO 100 CONTINUE DO 110 J = 1, N CC( J ) = J*( ( J + 1 )*J )/2 - ( ( J + 1 )*J*( J - 1 ) )/3 110 CONTINUE * CC holds the exact result. On exit from SMMCH CT holds * the result computed by SMMCH. TRANSA = 'N' TRANSB = 'N' CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX, $ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC, $ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. ) SAME = LSE( CC, CT, N ) IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR STOP END IF TRANSB = 'T' CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX, $ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC, $ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. ) SAME = LSE( CC, CT, N ) IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR STOP END IF DO 120 J = 1, N AB( J, NMAX + 1 ) = N - J + 1 AB( 1, NMAX + J ) = N - J + 1 120 CONTINUE DO 130 J = 1, N CC( N - J + 1 ) = J*( ( J + 1 )*J )/2 - $ ( ( J + 1 )*J*( J - 1 ) )/3 130 CONTINUE TRANSA = 'T' TRANSB = 'N' CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX, $ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC, $ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. ) SAME = LSE( CC, CT, N ) IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR STOP END IF TRANSB = 'T' CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX, $ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC, $ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. ) SAME = LSE( CC, CT, N ) IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR STOP END IF * * Test each subroutine in turn. * DO 200 ISNUM = 1, NSUBS WRITE( NOUT, FMT = * ) IF( .NOT.LTEST( ISNUM ) )THEN * Subprogram is not to be tested. WRITE( NOUT, FMT = 9987 )SNAMES( ISNUM ) ELSE SRNAMT = SNAMES( ISNUM ) * Test error exits. IF( TSTERR )THEN CALL SCHKE( ISNUM, SNAMES( ISNUM ), NOUT ) WRITE( NOUT, FMT = * ) END IF * Test computations. INFOT = 0 OK = .TRUE. FATAL = .FALSE. GO TO ( 140, 150, 160, 160, 170, 180 )ISNUM * Test SGEMM, 01. 140 CALL SCHK1( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE, $ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, $ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C, $ CC, CS, CT, G ) GO TO 190 * Test SSYMM, 02. 150 CALL SCHK2( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE, $ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, $ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C, $ CC, CS, CT, G ) GO TO 190 * Test STRMM, 03, STRSM, 04. 160 CALL SCHK3( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE, $ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NMAX, AB, $ AA, AS, AB( 1, NMAX + 1 ), BB, BS, CT, G, C ) GO TO 190 * Test SSYRK, 05. 170 CALL SCHK4( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE, $ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, $ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C, $ CC, CS, CT, G ) GO TO 190 * Test SSYR2K, 06. 180 CALL SCHK5( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE, $ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, $ NMAX, AB, AA, AS, BB, BS, C, CC, CS, CT, G, W ) GO TO 190 * 190 IF( FATAL.AND.SFATAL ) $ GO TO 210 END IF 200 CONTINUE WRITE( NOUT, FMT = 9986 ) GO TO 230 * 210 CONTINUE WRITE( NOUT, FMT = 9985 ) GO TO 230 * 220 CONTINUE WRITE( NOUT, FMT = 9991 ) * 230 CONTINUE IF( TRACE ) $ CLOSE ( NTRA ) CLOSE ( NOUT ) STOP * 9999 FORMAT( ' ROUTINES PASS COMPUTATIONAL TESTS IF TEST RATIO IS LES', $ 'S THAN', F8.2 ) 9998 FORMAT( ' RELATIVE MACHINE PRECISION IS TAKEN TO BE', 1P, E9.1 ) 9997 FORMAT( ' NUMBER OF VALUES OF ', A, ' IS LESS THAN 1 OR GREATER ', $ 'THAN ', I2 ) 9996 FORMAT( ' VALUE OF N IS LESS THAN 0 OR GREATER THAN ', I2 ) 9995 FORMAT( ' TESTS OF THE REAL LEVEL 3 BLAS', //' THE F', $ 'OLLOWING PARAMETER VALUES WILL BE USED:' ) 9994 FORMAT( ' FOR N ', 9I6 ) 9993 FORMAT( ' FOR ALPHA ', 7F6.1 ) 9992 FORMAT( ' FOR BETA ', 7F6.1 ) 9991 FORMAT( ' AMEND DATA FILE OR INCREASE ARRAY SIZES IN PROGRAM', $ /' ******* TESTS ABANDONED *******' ) 9990 FORMAT( ' SUBPROGRAM NAME ', A6, ' NOT RECOGNIZED', /' ******* T', $ 'ESTS ABANDONED *******' ) 9989 FORMAT( ' ERROR IN SMMCH - IN-LINE DOT PRODUCTS ARE BEING EVALU', $ 'ATED WRONGLY.', /' SMMCH WAS CALLED WITH TRANSA = ', A1, $ ' AND TRANSB = ', A1, /' AND RETURNED SAME = ', L1, ' AND ', $ 'ERR = ', F12.3, '.', /' THIS MAY BE DUE TO FAULTS IN THE ', $ 'ARITHMETIC OR THE COMPILER.', /' ******* TESTS ABANDONED ', $ '*******' ) 9988 FORMAT( A6, L2 ) 9987 FORMAT( 1X, A6, ' WAS NOT TESTED' ) 9986 FORMAT( /' END OF TESTS' ) 9985 FORMAT( /' ******* FATAL ERROR - TESTS ABANDONED *******' ) 9984 FORMAT( ' ERROR-EXITS WILL NOT BE TESTED' ) * * End of SBLAT3. * END SUBROUTINE SCHK1( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI, $ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX, $ A, AA, AS, B, BB, BS, C, CC, CS, CT, G ) * * Tests SGEMM. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0 ) * .. Scalar Arguments .. REAL EPS, THRESH INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA LOGICAL FATAL, REWI, TRACE CHARACTER*6 SNAME * .. Array Arguments .. REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ), $ AS( NMAX*NMAX ), B( NMAX, NMAX ), $ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ), $ C( NMAX, NMAX ), CC( NMAX*NMAX ), $ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX ) INTEGER IDIM( NIDIM ) * .. Local Scalars .. REAL ALPHA, ALS, BETA, BLS, ERR, ERRMAX INTEGER I, IA, IB, ICA, ICB, IK, IM, IN, K, KS, LAA, $ LBB, LCC, LDA, LDAS, LDB, LDBS, LDC, LDCS, M, $ MA, MB, MS, N, NA, NARGS, NB, NC, NS LOGICAL NULL, RESET, SAME, TRANA, TRANB CHARACTER*1 TRANAS, TRANBS, TRANSA, TRANSB CHARACTER*3 ICH * .. Local Arrays .. LOGICAL ISAME( 13 ) * .. External Functions .. LOGICAL LSE, LSERES EXTERNAL LSE, LSERES * .. External Subroutines .. EXTERNAL SGEMM, SMAKE, SMMCH * .. Intrinsic Functions .. INTRINSIC MAX * .. Scalars in Common .. INTEGER INFOT, NOUTC LOGICAL LERR, OK * .. Common blocks .. COMMON /INFOC/INFOT, NOUTC, OK, LERR * .. Data statements .. DATA ICH/'NTC'/ * .. Executable Statements .. * NARGS = 13 NC = 0 RESET = .TRUE. ERRMAX = ZERO * DO 110 IM = 1, NIDIM M = IDIM( IM ) * DO 100 IN = 1, NIDIM N = IDIM( IN ) * Set LDC to 1 more than minimum value if room. LDC = M IF( LDC.LT.NMAX ) $ LDC = LDC + 1 * Skip tests if not enough room. IF( LDC.GT.NMAX ) $ GO TO 100 LCC = LDC*N NULL = N.LE.0.OR.M.LE.0 * DO 90 IK = 1, NIDIM K = IDIM( IK ) * DO 80 ICA = 1, 3 TRANSA = ICH( ICA: ICA ) TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C' * IF( TRANA )THEN MA = K NA = M ELSE MA = M NA = K END IF * Set LDA to 1 more than minimum value if room. LDA = MA IF( LDA.LT.NMAX ) $ LDA = LDA + 1 * Skip tests if not enough room. IF( LDA.GT.NMAX ) $ GO TO 80 LAA = LDA*NA * * Generate the matrix A. * CALL SMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA, $ RESET, ZERO ) * DO 70 ICB = 1, 3 TRANSB = ICH( ICB: ICB ) TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C' * IF( TRANB )THEN MB = N NB = K ELSE MB = K NB = N END IF * Set LDB to 1 more than minimum value if room. LDB = MB IF( LDB.LT.NMAX ) $ LDB = LDB + 1 * Skip tests if not enough room. IF( LDB.GT.NMAX ) $ GO TO 70 LBB = LDB*NB * * Generate the matrix B. * CALL SMAKE( 'GE', ' ', ' ', MB, NB, B, NMAX, BB, $ LDB, RESET, ZERO ) * DO 60 IA = 1, NALF ALPHA = ALF( IA ) * DO 50 IB = 1, NBET BETA = BET( IB ) * * Generate the matrix C. * CALL SMAKE( 'GE', ' ', ' ', M, N, C, NMAX, $ CC, LDC, RESET, ZERO ) * NC = NC + 1 * * Save every datum before calling the * subroutine. * TRANAS = TRANSA TRANBS = TRANSB MS = M NS = N KS = K ALS = ALPHA DO 10 I = 1, LAA AS( I ) = AA( I ) 10 CONTINUE LDAS = LDA DO 20 I = 1, LBB BS( I ) = BB( I ) 20 CONTINUE LDBS = LDB BLS = BETA DO 30 I = 1, LCC CS( I ) = CC( I ) 30 CONTINUE LDCS = LDC * * Call the subroutine. * IF( TRACE ) $ WRITE( NTRA, FMT = 9995 )NC, SNAME, $ TRANSA, TRANSB, M, N, K, ALPHA, LDA, LDB, $ BETA, LDC IF( REWI ) $ REWIND NTRA CALL SGEMM( TRANSA, TRANSB, M, N, K, ALPHA, $ AA, LDA, BB, LDB, BETA, CC, LDC ) * * Check if error-exit was taken incorrectly. * IF( .NOT.OK )THEN WRITE( NOUT, FMT = 9994 ) FATAL = .TRUE. GO TO 120 END IF * * See what data changed inside subroutines. * ISAME( 1 ) = TRANSA.EQ.TRANAS ISAME( 2 ) = TRANSB.EQ.TRANBS ISAME( 3 ) = MS.EQ.M ISAME( 4 ) = NS.EQ.N ISAME( 5 ) = KS.EQ.K ISAME( 6 ) = ALS.EQ.ALPHA ISAME( 7 ) = LSE( AS, AA, LAA ) ISAME( 8 ) = LDAS.EQ.LDA ISAME( 9 ) = LSE( BS, BB, LBB ) ISAME( 10 ) = LDBS.EQ.LDB ISAME( 11 ) = BLS.EQ.BETA IF( NULL )THEN ISAME( 12 ) = LSE( CS, CC, LCC ) ELSE ISAME( 12 ) = LSERES( 'GE', ' ', M, N, CS, $ CC, LDC ) END IF ISAME( 13 ) = LDCS.EQ.LDC * * If data was incorrectly changed, report * and return. * SAME = .TRUE. DO 40 I = 1, NARGS SAME = SAME.AND.ISAME( I ) IF( .NOT.ISAME( I ) ) $ WRITE( NOUT, FMT = 9998 )I 40 CONTINUE IF( .NOT.SAME )THEN FATAL = .TRUE. GO TO 120 END IF * IF( .NOT.NULL )THEN * * Check the result. * CALL SMMCH( TRANSA, TRANSB, M, N, K, $ ALPHA, A, NMAX, B, NMAX, BETA, $ C, NMAX, CT, G, CC, LDC, EPS, $ ERR, FATAL, NOUT, .TRUE. ) ERRMAX = MAX( ERRMAX, ERR ) * If got really bad answer, report and * return. IF( FATAL ) $ GO TO 120 END IF * 50 CONTINUE * 60 CONTINUE * 70 CONTINUE * 80 CONTINUE * 90 CONTINUE * 100 CONTINUE * 110 CONTINUE * * Report result. * IF( ERRMAX.LT.THRESH )THEN WRITE( NOUT, FMT = 9999 )SNAME, NC ELSE WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX END IF GO TO 130 * 120 CONTINUE WRITE( NOUT, FMT = 9996 )SNAME WRITE( NOUT, FMT = 9995 )NC, SNAME, TRANSA, TRANSB, M, N, K, $ ALPHA, LDA, LDB, BETA, LDC * 130 CONTINUE RETURN * 9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL', $ 'S)' ) 9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH', $ 'ANGED INCORRECTLY *******' ) 9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C', $ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2, $ ' - SUSPECT *******' ) 9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' ) 9995 FORMAT( 1X, I6, ': ', A6, '(''', A1, ''',''', A1, ''',', $ 3( I3, ',' ), F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', ', $ 'C,', I3, ').' ) 9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *', $ '******' ) * * End of SCHK1. * END SUBROUTINE SCHK2( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI, $ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX, $ A, AA, AS, B, BB, BS, C, CC, CS, CT, G ) * * Tests SSYMM. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0 ) * .. Scalar Arguments .. REAL EPS, THRESH INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA LOGICAL FATAL, REWI, TRACE CHARACTER*6 SNAME * .. Array Arguments .. REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ), $ AS( NMAX*NMAX ), B( NMAX, NMAX ), $ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ), $ C( NMAX, NMAX ), CC( NMAX*NMAX ), $ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX ) INTEGER IDIM( NIDIM ) * .. Local Scalars .. REAL ALPHA, ALS, BETA, BLS, ERR, ERRMAX INTEGER I, IA, IB, ICS, ICU, IM, IN, LAA, LBB, LCC, $ LDA, LDAS, LDB, LDBS, LDC, LDCS, M, MS, N, NA, $ NARGS, NC, NS LOGICAL LEFT, NULL, RESET, SAME CHARACTER*1 SIDE, SIDES, UPLO, UPLOS CHARACTER*2 ICHS, ICHU * .. Local Arrays .. LOGICAL ISAME( 13 ) * .. External Functions .. LOGICAL LSE, LSERES EXTERNAL LSE, LSERES * .. External Subroutines .. EXTERNAL SMAKE, SMMCH, SSYMM * .. Intrinsic Functions .. INTRINSIC MAX * .. Scalars in Common .. INTEGER INFOT, NOUTC LOGICAL LERR, OK * .. Common blocks .. COMMON /INFOC/INFOT, NOUTC, OK, LERR * .. Data statements .. DATA ICHS/'LR'/, ICHU/'UL'/ * .. Executable Statements .. * NARGS = 12 NC = 0 RESET = .TRUE. ERRMAX = ZERO * DO 100 IM = 1, NIDIM M = IDIM( IM ) * DO 90 IN = 1, NIDIM N = IDIM( IN ) * Set LDC to 1 more than minimum value if room. LDC = M IF( LDC.LT.NMAX ) $ LDC = LDC + 1 * Skip tests if not enough room. IF( LDC.GT.NMAX ) $ GO TO 90 LCC = LDC*N NULL = N.LE.0.OR.M.LE.0 * * Set LDB to 1 more than minimum value if room. LDB = M IF( LDB.LT.NMAX ) $ LDB = LDB + 1 * Skip tests if not enough room. IF( LDB.GT.NMAX ) $ GO TO 90 LBB = LDB*N * * Generate the matrix B. * CALL SMAKE( 'GE', ' ', ' ', M, N, B, NMAX, BB, LDB, RESET, $ ZERO ) * DO 80 ICS = 1, 2 SIDE = ICHS( ICS: ICS ) LEFT = SIDE.EQ.'L' * IF( LEFT )THEN NA = M ELSE NA = N END IF * Set LDA to 1 more than minimum value if room. LDA = NA IF( LDA.LT.NMAX ) $ LDA = LDA + 1 * Skip tests if not enough room. IF( LDA.GT.NMAX ) $ GO TO 80 LAA = LDA*NA * DO 70 ICU = 1, 2 UPLO = ICHU( ICU: ICU ) * * Generate the symmetric matrix A. * CALL SMAKE( 'SY', UPLO, ' ', NA, NA, A, NMAX, AA, LDA, $ RESET, ZERO ) * DO 60 IA = 1, NALF ALPHA = ALF( IA ) * DO 50 IB = 1, NBET BETA = BET( IB ) * * Generate the matrix C. * CALL SMAKE( 'GE', ' ', ' ', M, N, C, NMAX, CC, $ LDC, RESET, ZERO ) * NC = NC + 1 * * Save every datum before calling the * subroutine. * SIDES = SIDE UPLOS = UPLO MS = M NS = N ALS = ALPHA DO 10 I = 1, LAA AS( I ) = AA( I ) 10 CONTINUE LDAS = LDA DO 20 I = 1, LBB BS( I ) = BB( I ) 20 CONTINUE LDBS = LDB BLS = BETA DO 30 I = 1, LCC CS( I ) = CC( I ) 30 CONTINUE LDCS = LDC * * Call the subroutine. * IF( TRACE ) $ WRITE( NTRA, FMT = 9995 )NC, SNAME, SIDE, $ UPLO, M, N, ALPHA, LDA, LDB, BETA, LDC IF( REWI ) $ REWIND NTRA CALL SSYMM( SIDE, UPLO, M, N, ALPHA, AA, LDA, $ BB, LDB, BETA, CC, LDC ) * * Check if error-exit was taken incorrectly. * IF( .NOT.OK )THEN WRITE( NOUT, FMT = 9994 ) FATAL = .TRUE. GO TO 110 END IF * * See what data changed inside subroutines. * ISAME( 1 ) = SIDES.EQ.SIDE ISAME( 2 ) = UPLOS.EQ.UPLO ISAME( 3 ) = MS.EQ.M ISAME( 4 ) = NS.EQ.N ISAME( 5 ) = ALS.EQ.ALPHA ISAME( 6 ) = LSE( AS, AA, LAA ) ISAME( 7 ) = LDAS.EQ.LDA ISAME( 8 ) = LSE( BS, BB, LBB ) ISAME( 9 ) = LDBS.EQ.LDB ISAME( 10 ) = BLS.EQ.BETA IF( NULL )THEN ISAME( 11 ) = LSE( CS, CC, LCC ) ELSE ISAME( 11 ) = LSERES( 'GE', ' ', M, N, CS, $ CC, LDC ) END IF ISAME( 12 ) = LDCS.EQ.LDC * * If data was incorrectly changed, report and * return. * SAME = .TRUE. DO 40 I = 1, NARGS SAME = SAME.AND.ISAME( I ) IF( .NOT.ISAME( I ) ) $ WRITE( NOUT, FMT = 9998 )I 40 CONTINUE IF( .NOT.SAME )THEN FATAL = .TRUE. GO TO 110 END IF * IF( .NOT.NULL )THEN * * Check the result. * IF( LEFT )THEN CALL SMMCH( 'N', 'N', M, N, M, ALPHA, A, $ NMAX, B, NMAX, BETA, C, NMAX, $ CT, G, CC, LDC, EPS, ERR, $ FATAL, NOUT, .TRUE. ) ELSE CALL SMMCH( 'N', 'N', M, N, N, ALPHA, B, $ NMAX, A, NMAX, BETA, C, NMAX, $ CT, G, CC, LDC, EPS, ERR, $ FATAL, NOUT, .TRUE. ) END IF ERRMAX = MAX( ERRMAX, ERR ) * If got really bad answer, report and * return. IF( FATAL ) $ GO TO 110 END IF * 50 CONTINUE * 60 CONTINUE * 70 CONTINUE * 80 CONTINUE * 90 CONTINUE * 100 CONTINUE * * Report result. * IF( ERRMAX.LT.THRESH )THEN WRITE( NOUT, FMT = 9999 )SNAME, NC ELSE WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX END IF GO TO 120 * 110 CONTINUE WRITE( NOUT, FMT = 9996 )SNAME WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, M, N, ALPHA, LDA, $ LDB, BETA, LDC * 120 CONTINUE RETURN * 9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL', $ 'S)' ) 9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH', $ 'ANGED INCORRECTLY *******' ) 9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C', $ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2, $ ' - SUSPECT *******' ) 9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' ) 9995 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ), $ F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', C,', I3, ') ', $ ' .' ) 9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *', $ '******' ) * * End of SCHK2. * END SUBROUTINE SCHK3( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI, $ FATAL, NIDIM, IDIM, NALF, ALF, NMAX, A, AA, AS, $ B, BB, BS, CT, G, C ) * * Tests STRMM and STRSM. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0, ONE = 1.0 ) * .. Scalar Arguments .. REAL EPS, THRESH INTEGER NALF, NIDIM, NMAX, NOUT, NTRA LOGICAL FATAL, REWI, TRACE CHARACTER*6 SNAME * .. Array Arguments .. REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ), $ AS( NMAX*NMAX ), B( NMAX, NMAX ), $ BB( NMAX*NMAX ), BS( NMAX*NMAX ), $ C( NMAX, NMAX ), CT( NMAX ), G( NMAX ) INTEGER IDIM( NIDIM ) * .. Local Scalars .. REAL ALPHA, ALS, ERR, ERRMAX INTEGER I, IA, ICD, ICS, ICT, ICU, IM, IN, J, LAA, LBB, $ LDA, LDAS, LDB, LDBS, M, MS, N, NA, NARGS, NC, $ NS LOGICAL LEFT, NULL, RESET, SAME CHARACTER*1 DIAG, DIAGS, SIDE, SIDES, TRANAS, TRANSA, UPLO, $ UPLOS CHARACTER*2 ICHD, ICHS, ICHU CHARACTER*3 ICHT * .. Local Arrays .. LOGICAL ISAME( 13 ) * .. External Functions .. LOGICAL LSE, LSERES EXTERNAL LSE, LSERES * .. External Subroutines .. EXTERNAL SMAKE, SMMCH, STRMM, STRSM * .. Intrinsic Functions .. INTRINSIC MAX * .. Scalars in Common .. INTEGER INFOT, NOUTC LOGICAL LERR, OK * .. Common blocks .. COMMON /INFOC/INFOT, NOUTC, OK, LERR * .. Data statements .. DATA ICHU/'UL'/, ICHT/'NTC'/, ICHD/'UN'/, ICHS/'LR'/ * .. Executable Statements .. * NARGS = 11 NC = 0 RESET = .TRUE. ERRMAX = ZERO * Set up zero matrix for SMMCH. DO 20 J = 1, NMAX DO 10 I = 1, NMAX C( I, J ) = ZERO 10 CONTINUE 20 CONTINUE * DO 140 IM = 1, NIDIM M = IDIM( IM ) * DO 130 IN = 1, NIDIM N = IDIM( IN ) * Set LDB to 1 more than minimum value if room. LDB = M IF( LDB.LT.NMAX ) $ LDB = LDB + 1 * Skip tests if not enough room. IF( LDB.GT.NMAX ) $ GO TO 130 LBB = LDB*N NULL = M.LE.0.OR.N.LE.0 * DO 120 ICS = 1, 2 SIDE = ICHS( ICS: ICS ) LEFT = SIDE.EQ.'L' IF( LEFT )THEN NA = M ELSE NA = N END IF * Set LDA to 1 more than minimum value if room. LDA = NA IF( LDA.LT.NMAX ) $ LDA = LDA + 1 * Skip tests if not enough room. IF( LDA.GT.NMAX ) $ GO TO 130 LAA = LDA*NA * DO 110 ICU = 1, 2 UPLO = ICHU( ICU: ICU ) * DO 100 ICT = 1, 3 TRANSA = ICHT( ICT: ICT ) * DO 90 ICD = 1, 2 DIAG = ICHD( ICD: ICD ) * DO 80 IA = 1, NALF ALPHA = ALF( IA ) * * Generate the matrix A. * CALL SMAKE( 'TR', UPLO, DIAG, NA, NA, A, $ NMAX, AA, LDA, RESET, ZERO ) * * Generate the matrix B. * CALL SMAKE( 'GE', ' ', ' ', M, N, B, NMAX, $ BB, LDB, RESET, ZERO ) * NC = NC + 1 * * Save every datum before calling the * subroutine. * SIDES = SIDE UPLOS = UPLO TRANAS = TRANSA DIAGS = DIAG MS = M NS = N ALS = ALPHA DO 30 I = 1, LAA AS( I ) = AA( I ) 30 CONTINUE LDAS = LDA DO 40 I = 1, LBB BS( I ) = BB( I ) 40 CONTINUE LDBS = LDB * * Call the subroutine. * IF( SNAME( 4: 5 ).EQ.'MM' )THEN IF( TRACE ) $ WRITE( NTRA, FMT = 9995 )NC, SNAME, $ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, $ LDA, LDB IF( REWI ) $ REWIND NTRA CALL STRMM( SIDE, UPLO, TRANSA, DIAG, M, $ N, ALPHA, AA, LDA, BB, LDB ) ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN IF( TRACE ) $ WRITE( NTRA, FMT = 9995 )NC, SNAME, $ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, $ LDA, LDB IF( REWI ) $ REWIND NTRA CALL STRSM( SIDE, UPLO, TRANSA, DIAG, M, $ N, ALPHA, AA, LDA, BB, LDB ) END IF * * Check if error-exit was taken incorrectly. * IF( .NOT.OK )THEN WRITE( NOUT, FMT = 9994 ) FATAL = .TRUE. GO TO 150 END IF * * See what data changed inside subroutines. * ISAME( 1 ) = SIDES.EQ.SIDE ISAME( 2 ) = UPLOS.EQ.UPLO ISAME( 3 ) = TRANAS.EQ.TRANSA ISAME( 4 ) = DIAGS.EQ.DIAG ISAME( 5 ) = MS.EQ.M ISAME( 6 ) = NS.EQ.N ISAME( 7 ) = ALS.EQ.ALPHA ISAME( 8 ) = LSE( AS, AA, LAA ) ISAME( 9 ) = LDAS.EQ.LDA IF( NULL )THEN ISAME( 10 ) = LSE( BS, BB, LBB ) ELSE ISAME( 10 ) = LSERES( 'GE', ' ', M, N, BS, $ BB, LDB ) END IF ISAME( 11 ) = LDBS.EQ.LDB * * If data was incorrectly changed, report and * return. * SAME = .TRUE. DO 50 I = 1, NARGS SAME = SAME.AND.ISAME( I ) IF( .NOT.ISAME( I ) ) $ WRITE( NOUT, FMT = 9998 )I 50 CONTINUE IF( .NOT.SAME )THEN FATAL = .TRUE. GO TO 150 END IF * IF( .NOT.NULL )THEN IF( SNAME( 4: 5 ).EQ.'MM' )THEN * * Check the result. * IF( LEFT )THEN CALL SMMCH( TRANSA, 'N', M, N, M, $ ALPHA, A, NMAX, B, NMAX, $ ZERO, C, NMAX, CT, G, $ BB, LDB, EPS, ERR, $ FATAL, NOUT, .TRUE. ) ELSE CALL SMMCH( 'N', TRANSA, M, N, N, $ ALPHA, B, NMAX, A, NMAX, $ ZERO, C, NMAX, CT, G, $ BB, LDB, EPS, ERR, $ FATAL, NOUT, .TRUE. ) END IF ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN * * Compute approximation to original * matrix. * DO 70 J = 1, N DO 60 I = 1, M C( I, J ) = BB( I + ( J - 1 )* $ LDB ) BB( I + ( J - 1 )*LDB ) = ALPHA* $ B( I, J ) 60 CONTINUE 70 CONTINUE * IF( LEFT )THEN CALL SMMCH( TRANSA, 'N', M, N, M, $ ONE, A, NMAX, C, NMAX, $ ZERO, B, NMAX, CT, G, $ BB, LDB, EPS, ERR, $ FATAL, NOUT, .FALSE. ) ELSE CALL SMMCH( 'N', TRANSA, M, N, N, $ ONE, C, NMAX, A, NMAX, $ ZERO, B, NMAX, CT, G, $ BB, LDB, EPS, ERR, $ FATAL, NOUT, .FALSE. ) END IF END IF ERRMAX = MAX( ERRMAX, ERR ) * If got really bad answer, report and * return. IF( FATAL ) $ GO TO 150 END IF * 80 CONTINUE * 90 CONTINUE * 100 CONTINUE * 110 CONTINUE * 120 CONTINUE * 130 CONTINUE * 140 CONTINUE * * Report result. * IF( ERRMAX.LT.THRESH )THEN WRITE( NOUT, FMT = 9999 )SNAME, NC ELSE WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX END IF GO TO 160 * 150 CONTINUE WRITE( NOUT, FMT = 9996 )SNAME WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, TRANSA, DIAG, M, $ N, ALPHA, LDA, LDB * 160 CONTINUE RETURN * 9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL', $ 'S)' ) 9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH', $ 'ANGED INCORRECTLY *******' ) 9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C', $ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2, $ ' - SUSPECT *******' ) 9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' ) 9995 FORMAT( 1X, I6, ': ', A6, '(', 4( '''', A1, ''',' ), 2( I3, ',' ), $ F4.1, ', A,', I3, ', B,', I3, ') .' ) 9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *', $ '******' ) * * End of SCHK3. * END SUBROUTINE SCHK4( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI, $ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX, $ A, AA, AS, B, BB, BS, C, CC, CS, CT, G ) * * Tests SSYRK. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0 ) * .. Scalar Arguments .. REAL EPS, THRESH INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA LOGICAL FATAL, REWI, TRACE CHARACTER*6 SNAME * .. Array Arguments .. REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ), $ AS( NMAX*NMAX ), B( NMAX, NMAX ), $ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ), $ C( NMAX, NMAX ), CC( NMAX*NMAX ), $ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX ) INTEGER IDIM( NIDIM ) * .. Local Scalars .. REAL ALPHA, ALS, BETA, BETS, ERR, ERRMAX INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, K, KS, $ LAA, LCC, LDA, LDAS, LDC, LDCS, LJ, MA, N, NA, $ NARGS, NC, NS LOGICAL NULL, RESET, SAME, TRAN, UPPER CHARACTER*1 TRANS, TRANSS, UPLO, UPLOS CHARACTER*2 ICHU CHARACTER*3 ICHT * .. Local Arrays .. LOGICAL ISAME( 13 ) * .. External Functions .. LOGICAL LSE, LSERES EXTERNAL LSE, LSERES * .. External Subroutines .. EXTERNAL SMAKE, SMMCH, SSYRK * .. Intrinsic Functions .. INTRINSIC MAX * .. Scalars in Common .. INTEGER INFOT, NOUTC LOGICAL LERR, OK * .. Common blocks .. COMMON /INFOC/INFOT, NOUTC, OK, LERR * .. Data statements .. DATA ICHT/'NTC'/, ICHU/'UL'/ * .. Executable Statements .. * NARGS = 10 NC = 0 RESET = .TRUE. ERRMAX = ZERO * DO 100 IN = 1, NIDIM N = IDIM( IN ) * Set LDC to 1 more than minimum value if room. LDC = N IF( LDC.LT.NMAX ) $ LDC = LDC + 1 * Skip tests if not enough room. IF( LDC.GT.NMAX ) $ GO TO 100 LCC = LDC*N NULL = N.LE.0 * DO 90 IK = 1, NIDIM K = IDIM( IK ) * DO 80 ICT = 1, 3 TRANS = ICHT( ICT: ICT ) TRAN = TRANS.EQ.'T'.OR.TRANS.EQ.'C' IF( TRAN )THEN MA = K NA = N ELSE MA = N NA = K END IF * Set LDA to 1 more than minimum value if room. LDA = MA IF( LDA.LT.NMAX ) $ LDA = LDA + 1 * Skip tests if not enough room. IF( LDA.GT.NMAX ) $ GO TO 80 LAA = LDA*NA * * Generate the matrix A. * CALL SMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA, $ RESET, ZERO ) * DO 70 ICU = 1, 2 UPLO = ICHU( ICU: ICU ) UPPER = UPLO.EQ.'U' * DO 60 IA = 1, NALF ALPHA = ALF( IA ) * DO 50 IB = 1, NBET BETA = BET( IB ) * * Generate the matrix C. * CALL SMAKE( 'SY', UPLO, ' ', N, N, C, NMAX, CC, $ LDC, RESET, ZERO ) * NC = NC + 1 * * Save every datum before calling the subroutine. * UPLOS = UPLO TRANSS = TRANS NS = N KS = K ALS = ALPHA DO 10 I = 1, LAA AS( I ) = AA( I ) 10 CONTINUE LDAS = LDA BETS = BETA DO 20 I = 1, LCC CS( I ) = CC( I ) 20 CONTINUE LDCS = LDC * * Call the subroutine. * IF( TRACE ) $ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO, $ TRANS, N, K, ALPHA, LDA, BETA, LDC IF( REWI ) $ REWIND NTRA CALL SSYRK( UPLO, TRANS, N, K, ALPHA, AA, LDA, $ BETA, CC, LDC ) * * Check if error-exit was taken incorrectly. * IF( .NOT.OK )THEN WRITE( NOUT, FMT = 9993 ) FATAL = .TRUE. GO TO 120 END IF * * See what data changed inside subroutines. * ISAME( 1 ) = UPLOS.EQ.UPLO ISAME( 2 ) = TRANSS.EQ.TRANS ISAME( 3 ) = NS.EQ.N ISAME( 4 ) = KS.EQ.K ISAME( 5 ) = ALS.EQ.ALPHA ISAME( 6 ) = LSE( AS, AA, LAA ) ISAME( 7 ) = LDAS.EQ.LDA ISAME( 8 ) = BETS.EQ.BETA IF( NULL )THEN ISAME( 9 ) = LSE( CS, CC, LCC ) ELSE ISAME( 9 ) = LSERES( 'SY', UPLO, N, N, CS, $ CC, LDC ) END IF ISAME( 10 ) = LDCS.EQ.LDC * * If data was incorrectly changed, report and * return. * SAME = .TRUE. DO 30 I = 1, NARGS SAME = SAME.AND.ISAME( I ) IF( .NOT.ISAME( I ) ) $ WRITE( NOUT, FMT = 9998 )I 30 CONTINUE IF( .NOT.SAME )THEN FATAL = .TRUE. GO TO 120 END IF * IF( .NOT.NULL )THEN * * Check the result column by column. * JC = 1 DO 40 J = 1, N IF( UPPER )THEN JJ = 1 LJ = J ELSE JJ = J LJ = N - J + 1 END IF IF( TRAN )THEN CALL SMMCH( 'T', 'N', LJ, 1, K, ALPHA, $ A( 1, JJ ), NMAX, $ A( 1, J ), NMAX, BETA, $ C( JJ, J ), NMAX, CT, G, $ CC( JC ), LDC, EPS, ERR, $ FATAL, NOUT, .TRUE. ) ELSE CALL SMMCH( 'N', 'T', LJ, 1, K, ALPHA, $ A( JJ, 1 ), NMAX, $ A( J, 1 ), NMAX, BETA, $ C( JJ, J ), NMAX, CT, G, $ CC( JC ), LDC, EPS, ERR, $ FATAL, NOUT, .TRUE. ) END IF IF( UPPER )THEN JC = JC + LDC ELSE JC = JC + LDC + 1 END IF ERRMAX = MAX( ERRMAX, ERR ) * If got really bad answer, report and * return. IF( FATAL ) $ GO TO 110 40 CONTINUE END IF * 50 CONTINUE * 60 CONTINUE * 70 CONTINUE * 80 CONTINUE * 90 CONTINUE * 100 CONTINUE * * Report result. * IF( ERRMAX.LT.THRESH )THEN WRITE( NOUT, FMT = 9999 )SNAME, NC ELSE WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX END IF GO TO 130 * 110 CONTINUE IF( N.GT.1 ) $ WRITE( NOUT, FMT = 9995 )J * 120 CONTINUE WRITE( NOUT, FMT = 9996 )SNAME WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, ALPHA, $ LDA, BETA, LDC * 130 CONTINUE RETURN * 9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL', $ 'S)' ) 9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH', $ 'ANGED INCORRECTLY *******' ) 9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C', $ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2, $ ' - SUSPECT *******' ) 9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' ) 9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 ) 9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ), $ F4.1, ', A,', I3, ',', F4.1, ', C,', I3, ') .' ) 9993 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *', $ '******' ) * * End of SCHK4. * END SUBROUTINE SCHK5( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI, $ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX, $ AB, AA, AS, BB, BS, C, CC, CS, CT, G, W ) * * Tests SSYR2K. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0 ) * .. Scalar Arguments .. REAL EPS, THRESH INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA LOGICAL FATAL, REWI, TRACE CHARACTER*6 SNAME * .. Array Arguments .. REAL AA( NMAX*NMAX ), AB( 2*NMAX*NMAX ), $ ALF( NALF ), AS( NMAX*NMAX ), BB( NMAX*NMAX ), $ BET( NBET ), BS( NMAX*NMAX ), C( NMAX, NMAX ), $ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ), $ G( NMAX ), W( 2*NMAX ) INTEGER IDIM( NIDIM ) * .. Local Scalars .. REAL ALPHA, ALS, BETA, BETS, ERR, ERRMAX INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, JJAB, $ K, KS, LAA, LBB, LCC, LDA, LDAS, LDB, LDBS, $ LDC, LDCS, LJ, MA, N, NA, NARGS, NC, NS LOGICAL NULL, RESET, SAME, TRAN, UPPER CHARACTER*1 TRANS, TRANSS, UPLO, UPLOS CHARACTER*2 ICHU CHARACTER*3 ICHT * .. Local Arrays .. LOGICAL ISAME( 13 ) * .. External Functions .. LOGICAL LSE, LSERES EXTERNAL LSE, LSERES * .. External Subroutines .. EXTERNAL SMAKE, SMMCH, SSYR2K * .. Intrinsic Functions .. INTRINSIC MAX * .. Scalars in Common .. INTEGER INFOT, NOUTC LOGICAL LERR, OK * .. Common blocks .. COMMON /INFOC/INFOT, NOUTC, OK, LERR * .. Data statements .. DATA ICHT/'NTC'/, ICHU/'UL'/ * .. Executable Statements .. * NARGS = 12 NC = 0 RESET = .TRUE. ERRMAX = ZERO * DO 130 IN = 1, NIDIM N = IDIM( IN ) * Set LDC to 1 more than minimum value if room. LDC = N IF( LDC.LT.NMAX ) $ LDC = LDC + 1 * Skip tests if not enough room. IF( LDC.GT.NMAX ) $ GO TO 130 LCC = LDC*N NULL = N.LE.0 * DO 120 IK = 1, NIDIM K = IDIM( IK ) * DO 110 ICT = 1, 3 TRANS = ICHT( ICT: ICT ) TRAN = TRANS.EQ.'T'.OR.TRANS.EQ.'C' IF( TRAN )THEN MA = K NA = N ELSE MA = N NA = K END IF * Set LDA to 1 more than minimum value if room. LDA = MA IF( LDA.LT.NMAX ) $ LDA = LDA + 1 * Skip tests if not enough room. IF( LDA.GT.NMAX ) $ GO TO 110 LAA = LDA*NA * * Generate the matrix A. * IF( TRAN )THEN CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB, 2*NMAX, AA, $ LDA, RESET, ZERO ) ELSE CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB, NMAX, AA, LDA, $ RESET, ZERO ) END IF * * Generate the matrix B. * LDB = LDA LBB = LAA IF( TRAN )THEN CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB( K + 1 ), $ 2*NMAX, BB, LDB, RESET, ZERO ) ELSE CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB( K*NMAX + 1 ), $ NMAX, BB, LDB, RESET, ZERO ) END IF * DO 100 ICU = 1, 2 UPLO = ICHU( ICU: ICU ) UPPER = UPLO.EQ.'U' * DO 90 IA = 1, NALF ALPHA = ALF( IA ) * DO 80 IB = 1, NBET BETA = BET( IB ) * * Generate the matrix C. * CALL SMAKE( 'SY', UPLO, ' ', N, N, C, NMAX, CC, $ LDC, RESET, ZERO ) * NC = NC + 1 * * Save every datum before calling the subroutine. * UPLOS = UPLO TRANSS = TRANS NS = N KS = K ALS = ALPHA DO 10 I = 1, LAA AS( I ) = AA( I ) 10 CONTINUE LDAS = LDA DO 20 I = 1, LBB BS( I ) = BB( I ) 20 CONTINUE LDBS = LDB BETS = BETA DO 30 I = 1, LCC CS( I ) = CC( I ) 30 CONTINUE LDCS = LDC * * Call the subroutine. * IF( TRACE ) $ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO, $ TRANS, N, K, ALPHA, LDA, LDB, BETA, LDC IF( REWI ) $ REWIND NTRA CALL SSYR2K( UPLO, TRANS, N, K, ALPHA, AA, LDA, $ BB, LDB, BETA, CC, LDC ) * * Check if error-exit was taken incorrectly. * IF( .NOT.OK )THEN WRITE( NOUT, FMT = 9993 ) FATAL = .TRUE. GO TO 150 END IF * * See what data changed inside subroutines. * ISAME( 1 ) = UPLOS.EQ.UPLO ISAME( 2 ) = TRANSS.EQ.TRANS ISAME( 3 ) = NS.EQ.N ISAME( 4 ) = KS.EQ.K ISAME( 5 ) = ALS.EQ.ALPHA ISAME( 6 ) = LSE( AS, AA, LAA ) ISAME( 7 ) = LDAS.EQ.LDA ISAME( 8 ) = LSE( BS, BB, LBB ) ISAME( 9 ) = LDBS.EQ.LDB ISAME( 10 ) = BETS.EQ.BETA IF( NULL )THEN ISAME( 11 ) = LSE( CS, CC, LCC ) ELSE ISAME( 11 ) = LSERES( 'SY', UPLO, N, N, CS, $ CC, LDC ) END IF ISAME( 12 ) = LDCS.EQ.LDC * * If data was incorrectly changed, report and * return. * SAME = .TRUE. DO 40 I = 1, NARGS SAME = SAME.AND.ISAME( I ) IF( .NOT.ISAME( I ) ) $ WRITE( NOUT, FMT = 9998 )I 40 CONTINUE IF( .NOT.SAME )THEN FATAL = .TRUE. GO TO 150 END IF * IF( .NOT.NULL )THEN * * Check the result column by column. * JJAB = 1 JC = 1 DO 70 J = 1, N IF( UPPER )THEN JJ = 1 LJ = J ELSE JJ = J LJ = N - J + 1 END IF IF( TRAN )THEN DO 50 I = 1, K W( I ) = AB( ( J - 1 )*2*NMAX + K + $ I ) W( K + I ) = AB( ( J - 1 )*2*NMAX + $ I ) 50 CONTINUE CALL SMMCH( 'T', 'N', LJ, 1, 2*K, $ ALPHA, AB( JJAB ), 2*NMAX, $ W, 2*NMAX, BETA, $ C( JJ, J ), NMAX, CT, G, $ CC( JC ), LDC, EPS, ERR, $ FATAL, NOUT, .TRUE. ) ELSE DO 60 I = 1, K W( I ) = AB( ( K + I - 1 )*NMAX + $ J ) W( K + I ) = AB( ( I - 1 )*NMAX + $ J ) 60 CONTINUE CALL SMMCH( 'N', 'N', LJ, 1, 2*K, $ ALPHA, AB( JJ ), NMAX, W, $ 2*NMAX, BETA, C( JJ, J ), $ NMAX, CT, G, CC( JC ), LDC, $ EPS, ERR, FATAL, NOUT, $ .TRUE. ) END IF IF( UPPER )THEN JC = JC + LDC ELSE JC = JC + LDC + 1 IF( TRAN ) $ JJAB = JJAB + 2*NMAX END IF ERRMAX = MAX( ERRMAX, ERR ) * If got really bad answer, report and * return. IF( FATAL ) $ GO TO 140 70 CONTINUE END IF * 80 CONTINUE * 90 CONTINUE * 100 CONTINUE * 110 CONTINUE * 120 CONTINUE * 130 CONTINUE * * Report result. * IF( ERRMAX.LT.THRESH )THEN WRITE( NOUT, FMT = 9999 )SNAME, NC ELSE WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX END IF GO TO 160 * 140 CONTINUE IF( N.GT.1 ) $ WRITE( NOUT, FMT = 9995 )J * 150 CONTINUE WRITE( NOUT, FMT = 9996 )SNAME WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, ALPHA, $ LDA, LDB, BETA, LDC * 160 CONTINUE RETURN * 9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL', $ 'S)' ) 9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH', $ 'ANGED INCORRECTLY *******' ) 9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C', $ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2, $ ' - SUSPECT *******' ) 9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' ) 9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 ) 9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ), $ F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', C,', I3, ') ', $ ' .' ) 9993 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *', $ '******' ) * * End of SCHK5. * END SUBROUTINE SCHKE( ISNUM, SRNAMT, NOUT ) * * Tests the error exits from the Level 3 Blas. * Requires a special version of the error-handling routine XERBLA. * A, B and C should not need to be defined. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * 3-19-92: Initialize ALPHA and BETA (eca) * 3-19-92: Fix argument 12 in calls to SSYMM with INFOT = 9 (eca) * * .. Scalar Arguments .. INTEGER ISNUM, NOUT CHARACTER*6 SRNAMT * .. Scalars in Common .. INTEGER INFOT, NOUTC LOGICAL LERR, OK * .. Parameters .. REAL ONE, TWO PARAMETER ( ONE = 1.0E0, TWO = 2.0E0 ) * .. Local Scalars .. REAL ALPHA, BETA * .. Local Arrays .. REAL A( 2, 1 ), B( 2, 1 ), C( 2, 1 ) * .. External Subroutines .. EXTERNAL CHKXER, SGEMM, SSYMM, SSYR2K, SSYRK, STRMM, $ STRSM * .. Common blocks .. COMMON /INFOC/INFOT, NOUTC, OK, LERR * .. Executable Statements .. * OK is set to .FALSE. by the special version of XERBLA or by CHKXER * if anything is wrong. OK = .TRUE. * LERR is set to .TRUE. by the special version of XERBLA each time * it is called, and is then tested and re-set by CHKXER. LERR = .FALSE. * * Initialize ALPHA and BETA. * ALPHA = ONE BETA = TWO * GO TO ( 10, 20, 30, 40, 50, 60 )ISNUM 10 INFOT = 1 CALL SGEMM( '/', 'N', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 1 CALL SGEMM( '/', 'T', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 2 CALL SGEMM( 'N', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 2 CALL SGEMM( 'T', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SGEMM( 'N', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SGEMM( 'N', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SGEMM( 'T', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SGEMM( 'T', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SGEMM( 'N', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SGEMM( 'N', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SGEMM( 'T', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SGEMM( 'T', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL SGEMM( 'N', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL SGEMM( 'N', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL SGEMM( 'T', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL SGEMM( 'T', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 8 CALL SGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 8 CALL SGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 8 CALL SGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 1, B, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 8 CALL SGEMM( 'T', 'T', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SGEMM( 'N', 'N', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SGEMM( 'N', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SGEMM( 'T', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 13 CALL SGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 13 CALL SGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 13 CALL SGEMM( 'T', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 13 CALL SGEMM( 'T', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) GO TO 70 20 INFOT = 1 CALL SSYMM( '/', 'U', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 2 CALL SSYMM( 'L', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYMM( 'L', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYMM( 'R', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYMM( 'L', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYMM( 'R', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYMM( 'L', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYMM( 'R', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYMM( 'L', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYMM( 'R', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYMM( 'L', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYMM( 'R', 'U', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYMM( 'L', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYMM( 'R', 'L', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) GO TO 70 30 INFOT = 1 CALL STRMM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 2 CALL STRMM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL STRMM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL STRMM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRMM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRMM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRMM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRMM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) GO TO 70 40 INFOT = 1 CALL STRSM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 2 CALL STRSM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL STRSM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL STRSM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 5 CALL STRSM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 6 CALL STRSM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL STRSM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 11 CALL STRSM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) GO TO 70 50 INFOT = 1 CALL SSYRK( '/', 'N', 0, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 2 CALL SSYRK( 'U', '/', 0, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYRK( 'U', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYRK( 'U', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYRK( 'L', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYRK( 'L', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYRK( 'U', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYRK( 'U', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYRK( 'L', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYRK( 'L', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYRK( 'U', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYRK( 'U', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYRK( 'L', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYRK( 'L', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SSYRK( 'U', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SSYRK( 'U', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SSYRK( 'L', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 10 CALL SSYRK( 'L', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) GO TO 70 60 INFOT = 1 CALL SSYR2K( '/', 'N', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 2 CALL SSYR2K( 'U', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYR2K( 'U', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYR2K( 'U', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYR2K( 'L', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 3 CALL SSYR2K( 'L', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYR2K( 'U', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYR2K( 'U', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYR2K( 'L', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 4 CALL SSYR2K( 'L', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYR2K( 'U', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYR2K( 'U', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYR2K( 'L', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 7 CALL SSYR2K( 'L', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYR2K( 'U', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 9 CALL SSYR2K( 'L', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYR2K( 'U', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) INFOT = 12 CALL SSYR2K( 'L', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 ) CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) * 70 IF( OK )THEN WRITE( NOUT, FMT = 9999 )SRNAMT ELSE WRITE( NOUT, FMT = 9998 )SRNAMT END IF RETURN * 9999 FORMAT( ' ', A6, ' PASSED THE TESTS OF ERROR-EXITS' ) 9998 FORMAT( ' ******* ', A6, ' FAILED THE TESTS OF ERROR-EXITS *****', $ '**' ) * * End of SCHKE. * END SUBROUTINE SMAKE( TYPE, UPLO, DIAG, M, N, A, NMAX, AA, LDA, RESET, $ TRANSL ) * * Generates values for an M by N matrix A. * Stores the values in the array AA in the data structure required * by the routine, with unwanted elements set to rogue value. * * TYPE is 'GE', 'SY' or 'TR'. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0, ONE = 1.0 ) REAL ROGUE PARAMETER ( ROGUE = -1.0E10 ) * .. Scalar Arguments .. REAL TRANSL INTEGER LDA, M, N, NMAX LOGICAL RESET CHARACTER*1 DIAG, UPLO CHARACTER*2 TYPE * .. Array Arguments .. REAL A( NMAX, * ), AA( * ) * .. Local Scalars .. INTEGER I, IBEG, IEND, J LOGICAL GEN, LOWER, SYM, TRI, UNIT, UPPER * .. External Functions .. REAL SBEG EXTERNAL SBEG * .. Executable Statements .. GEN = TYPE.EQ.'GE' SYM = TYPE.EQ.'SY' TRI = TYPE.EQ.'TR' UPPER = ( SYM.OR.TRI ).AND.UPLO.EQ.'U' LOWER = ( SYM.OR.TRI ).AND.UPLO.EQ.'L' UNIT = TRI.AND.DIAG.EQ.'U' * * Generate data in array A. * DO 20 J = 1, N DO 10 I = 1, M IF( GEN.OR.( UPPER.AND.I.LE.J ).OR.( LOWER.AND.I.GE.J ) ) $ THEN A( I, J ) = SBEG( RESET ) + TRANSL IF( I.NE.J )THEN * Set some elements to zero IF( N.GT.3.AND.J.EQ.N/2 ) $ A( I, J ) = ZERO IF( SYM )THEN A( J, I ) = A( I, J ) ELSE IF( TRI )THEN A( J, I ) = ZERO END IF END IF END IF 10 CONTINUE IF( TRI ) $ A( J, J ) = A( J, J ) + ONE IF( UNIT ) $ A( J, J ) = ONE 20 CONTINUE * * Store elements in array AS in data structure required by routine. * IF( TYPE.EQ.'GE' )THEN DO 50 J = 1, N DO 30 I = 1, M AA( I + ( J - 1 )*LDA ) = A( I, J ) 30 CONTINUE DO 40 I = M + 1, LDA AA( I + ( J - 1 )*LDA ) = ROGUE 40 CONTINUE 50 CONTINUE ELSE IF( TYPE.EQ.'SY'.OR.TYPE.EQ.'TR' )THEN DO 90 J = 1, N IF( UPPER )THEN IBEG = 1 IF( UNIT )THEN IEND = J - 1 ELSE IEND = J END IF ELSE IF( UNIT )THEN IBEG = J + 1 ELSE IBEG = J END IF IEND = N END IF DO 60 I = 1, IBEG - 1 AA( I + ( J - 1 )*LDA ) = ROGUE 60 CONTINUE DO 70 I = IBEG, IEND AA( I + ( J - 1 )*LDA ) = A( I, J ) 70 CONTINUE DO 80 I = IEND + 1, LDA AA( I + ( J - 1 )*LDA ) = ROGUE 80 CONTINUE 90 CONTINUE END IF RETURN * * End of SMAKE. * END SUBROUTINE SMMCH( TRANSA, TRANSB, M, N, KK, ALPHA, A, LDA, B, LDB, $ BETA, C, LDC, CT, G, CC, LDCC, EPS, ERR, FATAL, $ NOUT, MV ) * * Checks the results of the computational tests. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0, ONE = 1.0 ) * .. Scalar Arguments .. REAL ALPHA, BETA, EPS, ERR INTEGER KK, LDA, LDB, LDC, LDCC, M, N, NOUT LOGICAL FATAL, MV CHARACTER*1 TRANSA, TRANSB * .. Array Arguments .. REAL A( LDA, * ), B( LDB, * ), C( LDC, * ), $ CC( LDCC, * ), CT( * ), G( * ) * .. Local Scalars .. REAL ERRI INTEGER I, J, K LOGICAL TRANA, TRANB * .. Intrinsic Functions .. INTRINSIC ABS, MAX, SQRT * .. Executable Statements .. TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C' TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C' * * Compute expected result, one column at a time, in CT using data * in A, B and C. * Compute gauges in G. * DO 120 J = 1, N * DO 10 I = 1, M CT( I ) = ZERO G( I ) = ZERO 10 CONTINUE IF( .NOT.TRANA.AND..NOT.TRANB )THEN DO 30 K = 1, KK DO 20 I = 1, M CT( I ) = CT( I ) + A( I, K )*B( K, J ) G( I ) = G( I ) + ABS( A( I, K ) )*ABS( B( K, J ) ) 20 CONTINUE 30 CONTINUE ELSE IF( TRANA.AND..NOT.TRANB )THEN DO 50 K = 1, KK DO 40 I = 1, M CT( I ) = CT( I ) + A( K, I )*B( K, J ) G( I ) = G( I ) + ABS( A( K, I ) )*ABS( B( K, J ) ) 40 CONTINUE 50 CONTINUE ELSE IF( .NOT.TRANA.AND.TRANB )THEN DO 70 K = 1, KK DO 60 I = 1, M CT( I ) = CT( I ) + A( I, K )*B( J, K ) G( I ) = G( I ) + ABS( A( I, K ) )*ABS( B( J, K ) ) 60 CONTINUE 70 CONTINUE ELSE IF( TRANA.AND.TRANB )THEN DO 90 K = 1, KK DO 80 I = 1, M CT( I ) = CT( I ) + A( K, I )*B( J, K ) G( I ) = G( I ) + ABS( A( K, I ) )*ABS( B( J, K ) ) 80 CONTINUE 90 CONTINUE END IF DO 100 I = 1, M CT( I ) = ALPHA*CT( I ) + BETA*C( I, J ) G( I ) = ABS( ALPHA )*G( I ) + ABS( BETA )*ABS( C( I, J ) ) 100 CONTINUE * * Compute the error ratio for this result. * ERR = ZERO DO 110 I = 1, M ERRI = ABS( CT( I ) - CC( I, J ) )/EPS IF( G( I ).NE.ZERO ) $ ERRI = ERRI/G( I ) ERR = MAX( ERR, ERRI ) IF( ERR*SQRT( EPS ).GE.ONE ) $ GO TO 130 110 CONTINUE * 120 CONTINUE * * If the loop completes, all results are at least half accurate. GO TO 150 * * Report fatal error. * 130 FATAL = .TRUE. WRITE( NOUT, FMT = 9999 ) DO 140 I = 1, M IF( MV )THEN WRITE( NOUT, FMT = 9998 )I, CT( I ), CC( I, J ) ELSE WRITE( NOUT, FMT = 9998 )I, CC( I, J ), CT( I ) END IF 140 CONTINUE IF( N.GT.1 ) $ WRITE( NOUT, FMT = 9997 )J * 150 CONTINUE RETURN * 9999 FORMAT( ' ******* FATAL ERROR - COMPUTED RESULT IS LESS THAN HAL', $ 'F ACCURATE *******', /' EXPECTED RESULT COMPU', $ 'TED RESULT' ) 9998 FORMAT( 1X, I7, 2G18.6 ) 9997 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 ) * * End of SMMCH. * END LOGICAL FUNCTION LSE( RI, RJ, LR ) * * Tests if two arrays are identical. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Scalar Arguments .. INTEGER LR * .. Array Arguments .. REAL RI( * ), RJ( * ) * .. Local Scalars .. INTEGER I * .. Executable Statements .. DO 10 I = 1, LR IF( RI( I ).NE.RJ( I ) ) $ GO TO 20 10 CONTINUE LSE = .TRUE. GO TO 30 20 CONTINUE LSE = .FALSE. 30 RETURN * * End of LSE. * END LOGICAL FUNCTION LSERES( TYPE, UPLO, M, N, AA, AS, LDA ) * * Tests if selected elements in two arrays are equal. * * TYPE is 'GE' or 'SY'. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Scalar Arguments .. INTEGER LDA, M, N CHARACTER*1 UPLO CHARACTER*2 TYPE * .. Array Arguments .. REAL AA( LDA, * ), AS( LDA, * ) * .. Local Scalars .. INTEGER I, IBEG, IEND, J LOGICAL UPPER * .. Executable Statements .. UPPER = UPLO.EQ.'U' IF( TYPE.EQ.'GE' )THEN DO 20 J = 1, N DO 10 I = M + 1, LDA IF( AA( I, J ).NE.AS( I, J ) ) $ GO TO 70 10 CONTINUE 20 CONTINUE ELSE IF( TYPE.EQ.'SY' )THEN DO 50 J = 1, N IF( UPPER )THEN IBEG = 1 IEND = J ELSE IBEG = J IEND = N END IF DO 30 I = 1, IBEG - 1 IF( AA( I, J ).NE.AS( I, J ) ) $ GO TO 70 30 CONTINUE DO 40 I = IEND + 1, LDA IF( AA( I, J ).NE.AS( I, J ) ) $ GO TO 70 40 CONTINUE 50 CONTINUE END IF * LSERES = .TRUE. GO TO 80 70 CONTINUE LSERES = .FALSE. 80 RETURN * * End of LSERES. * END REAL FUNCTION SBEG( RESET ) * * Generates random numbers uniformly distributed between -0.5 and 0.5. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Scalar Arguments .. LOGICAL RESET * .. Local Scalars .. INTEGER I, IC, MI * .. Save statement .. SAVE I, IC, MI * .. Executable Statements .. IF( RESET )THEN * Initialize local variables. MI = 891 I = 7 IC = 0 RESET = .FALSE. END IF * * The sequence of values of I is bounded between 1 and 999. * If initial I = 1,2,3,6,7 or 9, the period will be 50. * If initial I = 4 or 8, the period will be 25. * If initial I = 5, the period will be 10. * IC is used to break up the period by skipping 1 value of I in 6. * IC = IC + 1 10 I = I*MI I = I - 1000*( I/1000 ) IF( IC.GE.5 )THEN IC = 0 GO TO 10 END IF SBEG = ( I - 500 )/1001.0 RETURN * * End of SBEG. * END REAL FUNCTION SDIFF( X, Y ) * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Scalar Arguments .. REAL X, Y * .. Executable Statements .. SDIFF = X - Y RETURN * * End of SDIFF. * END SUBROUTINE CHKXER( SRNAMT, INFOT, NOUT, LERR, OK ) * * Tests whether XERBLA has detected an error when it should. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Scalar Arguments .. INTEGER INFOT, NOUT LOGICAL LERR, OK CHARACTER*6 SRNAMT * .. Executable Statements .. IF( .NOT.LERR )THEN WRITE( NOUT, FMT = 9999 )INFOT, SRNAMT OK = .FALSE. END IF LERR = .FALSE. RETURN * 9999 FORMAT( ' ***** ILLEGAL VALUE OF PARAMETER NUMBER ', I2, ' NOT D', $ 'ETECTED BY ', A6, ' *****' ) * * End of CHKXER. * END SUBROUTINE XERBLA( SRNAME, INFO ) * * This is a special version of XERBLA to be used only as part of * the test program for testing error exits from the Level 3 BLAS * routines. * * XERBLA is an error handler for the Level 3 BLAS routines. * * It is called by the Level 3 BLAS routines if an input parameter is * invalid. * * Auxiliary routine for test program for Level 3 Blas. * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * .. Scalar Arguments .. INTEGER INFO CHARACTER*6 SRNAME * .. Scalars in Common .. INTEGER INFOT, NOUT LOGICAL LERR, OK CHARACTER*6 SRNAMT * .. Common blocks .. COMMON /INFOC/INFOT, NOUT, OK, LERR COMMON /SRNAMC/SRNAMT * .. Executable Statements .. LERR = .TRUE. IF( INFO.NE.INFOT )THEN IF( INFOT.NE.0 )THEN WRITE( NOUT, FMT = 9999 )INFO, INFOT ELSE WRITE( NOUT, FMT = 9997 )INFO END IF OK = .FALSE. END IF IF( SRNAME.NE.SRNAMT )THEN WRITE( NOUT, FMT = 9998 )SRNAME, SRNAMT OK = .FALSE. END IF RETURN * 9999 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6, ' INSTEAD', $ ' OF ', I2, ' *******' ) 9998 FORMAT( ' ******* XERBLA WAS CALLED WITH SRNAME = ', A6, ' INSTE', $ 'AD OF ', A6, ' *******' ) 9997 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6, $ ' *******' ) * * End of XERBLA * END
bsd-3-clause
nvarini/espresso_iohpc
PW/src/cdiagh.f90
2
2545
! ! Copyright (C) 2001-2007 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 cdiagh( n, h, ldh, e, v ) !---------------------------------------------------------------------------- ! ! ... calculates all the eigenvalues and eigenvectors of a complex ! ... hermitean matrix H. On output, the matrix is unchanged ! USE kinds, ONLY : DP USE mp_bands, ONLY : nbgrp, me_bgrp, root_bgrp, intra_bgrp_comm USE mp, ONLY : mp_bcast ! IMPLICIT NONE ! ! ... on INPUT ! INTEGER :: n, ldh ! dimension of the matrix to be diagonalized ! leading dimension of h, as declared in the calling pgm unit COMPLEX(DP) :: h(ldh,n) ! matrix to be diagonalized ! ! ... on OUTPUT ! REAL(DP) :: e(n) ! eigenvalues COMPLEX(DP) :: v(ldh,n) ! eigenvectors (column-wise) ! ! ... local variables for LAPACK ! INTEGER :: lwork, nb, info REAL(DP), ALLOCATABLE :: rwork(:) COMPLEX(DP), ALLOCATABLE :: work(:) INTEGER, EXTERNAL :: ILAENV ! ILAENV returns optimal block size "nb" ! CALL start_clock( 'diagh' ) ! ! ... check for the block size ! nb = ILAENV( 1, 'ZHETRD', 'U', n, - 1, - 1, - 1 ) IF ( nb < 1 .OR. nb >= n ) THEN lwork = 2*n ELSE lwork = ( nb + 1 )*n END IF ! ! ... only the first processor diagonalize the matrix ! IF ( me_bgrp == root_bgrp ) THEN ! ! ... allocate workspace ! #ifdef __PGI ! workaround for PGI compiler bug ! v(1:ldh,1:n) = h(1:ldh,1:n) #else v = h #endif ! ALLOCATE( work( lwork ) ) ALLOCATE( rwork( 3 * n - 2 ) ) ! CALL ZHEEV( 'V', 'U', n, v, ldh, e, work, lwork, rwork, info ) ! CALL errore( 'cdiagh', 'diagonalization (ZHEEV) failed', ABS( info ) ) ! ! ... deallocate workspace ! DEALLOCATE( rwork ) DEALLOCATE( work ) ! END IF ! #ifdef __PGI ! workaround for PGI compiler bug ! CALL mp_bcast( e(1:n), root_bgrp, intra_bgrp_comm ) CALL mp_bcast( v(1:ldh,1:n), root_bgrp, intra_bgrp_comm ) #else CALL mp_bcast( e, root_bgrp, intra_bgrp_comm ) CALL mp_bcast( v, root_bgrp, intra_bgrp_comm ) #endif ! CALL stop_clock( 'diagh' ) ! RETURN ! END SUBROUTINE cdiagh
gpl-2.0
jakevdp/scipy
scipy/_build_utils/src/wrap_dummy_g77_abi.f
139
1282
COMPLEX FUNCTION WCDOTC( N, CX, INCX, CY, INCY ) INTEGER INCX, INCY, N COMPLEX CX(*), CY(*) EXTERNAL CDOTC COMPLEX CDOTC WCDOTC = CDOTC( N, CX, INCX, CY, INCY ) END FUNCTION COMPLEX FUNCTION WCDOTU( N, CX, INCX, CY, INCY ) INTEGER INCX, INCY, N COMPLEX CX(*), CY(*) EXTERNAL CDOTU COMPLEX CDOTU WCDOTU = CDOTU( N, CX, INCX, CY, INCY ) END FUNCTION DOUBLE COMPLEX FUNCTION WZDOTC( N, CX, INCX, CY, INCY ) INTEGER INCX, INCY, N DOUBLE COMPLEX CX(*), CY(*) EXTERNAL ZDOTC DOUBLE COMPLEX ZDOTC WZDOTC = ZDOTC( N, CX, INCX, CY, INCY ) END FUNCTION DOUBLE COMPLEX FUNCTION WZDOTU( N, CX, INCX, CY, INCY ) INTEGER INCX, INCY, N DOUBLE COMPLEX CX(*), CY(*) EXTERNAL ZDOTU DOUBLE COMPLEX ZDOTU WZDOTU = ZDOTU( N, CX, INCX, CY, INCY ) END FUNCTION COMPLEX FUNCTION WCLADIV( X, Y ) COMPLEX X, Y EXTERNAL CLADIV COMPLEX CLADIV WCLADIV = CLADIV( X, Y) END FUNCTION DOUBLE COMPLEX FUNCTION WZLADIV( X, Y ) DOUBLE COMPLEX X, Y EXTERNAL ZLADIV DOUBLE COMPLEX ZLADIV WZLADIV = ZLADIV( X, Y) END FUNCTION
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/VARIANTS/lu/CR/dgetrf.f
23
6104
C> \brief \b DGETRF VARIANT: Crout Level 3 BLAS version of the algorithm. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DGETRF ( M, N, A, LDA, IPIV, INFO) * * .. Scalar Arguments .. * INTEGER INFO, LDA, M, N * .. * .. Array Arguments .. * INTEGER IPIV( * ) * DOUBLE PRECISION A( LDA, * ) * .. * * Purpose * ======= * C>\details \b Purpose: C>\verbatim C> C> DGETRF computes an LU factorization of a general M-by-N matrix A C> using partial pivoting with row interchanges. C> C> The factorization has the form C> A = P * L * U C> where P is a permutation matrix, L is lower triangular with unit C> diagonal elements (lower trapezoidal if m > n), and U is upper C> triangular (upper trapezoidal if m < n). C> C> This is the Crout Level 3 BLAS version of the algorithm. C> C>\endverbatim * * Arguments: * ========== * C> \param[in] M C> \verbatim C> M is INTEGER C> The number of rows of the matrix A. M >= 0. C> \endverbatim C> C> \param[in] N C> \verbatim C> N is INTEGER C> The number of columns of the matrix A. N >= 0. C> \endverbatim C> C> \param[in,out] A C> \verbatim C> A is DOUBLE PRECISION array, dimension (LDA,N) C> On entry, the M-by-N matrix to be factored. C> On exit, the factors L and U from the factorization C> A = P*L*U; the unit diagonal elements of L are not stored. C> \endverbatim C> C> \param[in] LDA C> \verbatim C> LDA is INTEGER C> The leading dimension of the array A. LDA >= max(1,M). C> \endverbatim C> C> \param[out] IPIV C> \verbatim C> IPIV is INTEGER array, dimension (min(M,N)) C> The pivot indices; for 1 <= i <= min(M,N), row i of the C> matrix was interchanged with row IPIV(i). C> \endverbatim C> C> \param[out] INFO C> \verbatim C> INFO is INTEGER C> = 0: successful exit C> < 0: if INFO = -i, the i-th argument had an illegal value C> > 0: if INFO = i, U(i,i) is exactly zero. The factorization C> has been completed, but the factor U is exactly C> singular, and division by zero will occur if it is used C> to solve a system of equations. C> \endverbatim C> * * Authors: * ======== * C> \author Univ. of Tennessee C> \author Univ. of California Berkeley C> \author Univ. of Colorado Denver C> \author NAG Ltd. * C> \date November 2011 * C> \ingroup variantsGEcomputational * * ===================================================================== SUBROUTINE DGETRF ( M, N, A, LDA, IPIV, INFO) * * -- LAPACK computational routine (version 3.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, M, N * .. * .. Array Arguments .. INTEGER IPIV( * ) DOUBLE PRECISION A( LDA, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE PARAMETER ( ONE = 1.0D+0 ) * .. * .. Local Scalars .. INTEGER I, IINFO, J, JB, NB * .. * .. External Subroutines .. EXTERNAL DGEMM, DGETF2, DLASWP, DTRSM, XERBLA * .. * .. External Functions .. INTEGER ILAENV EXTERNAL ILAENV * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -4 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGETRF', -INFO ) RETURN END IF * * Quick return if possible * IF( M.EQ.0 .OR. N.EQ.0 ) $ RETURN * * Determine the block size for this environment. * NB = ILAENV( 1, 'DGETRF', ' ', M, N, -1, -1 ) IF( NB.LE.1 .OR. NB.GE.MIN( M, N ) ) THEN * * Use unblocked code. * CALL DGETF2( M, N, A, LDA, IPIV, INFO ) ELSE * * Use blocked code. * DO 20 J = 1, MIN( M, N ), NB JB = MIN( MIN( M, N )-J+1, NB ) * * Update current block. * CALL DGEMM( 'No transpose', 'No transpose', $ M-J+1, JB, J-1, -ONE, $ A( J, 1 ), LDA, A( 1, J ), LDA, ONE, $ A( J, J ), LDA ) * * Factor diagonal and subdiagonal blocks and test for exact * singularity. * CALL DGETF2( M-J+1, JB, A( J, J ), LDA, IPIV( J ), IINFO ) * * Adjust INFO and the pivot indices. * IF( INFO.EQ.0 .AND. IINFO.GT.0 ) $ INFO = IINFO + J - 1 DO 10 I = J, MIN( M, J+JB-1 ) IPIV( I ) = J - 1 + IPIV( I ) 10 CONTINUE * * Apply interchanges to column 1:J-1 * CALL DLASWP( J-1, A, LDA, J, J+JB-1, IPIV, 1 ) * IF ( J+JB.LE.N ) THEN * * Apply interchanges to column J+JB:N * CALL DLASWP( N-J-JB+1, A( 1, J+JB ), LDA, J, J+JB-1, $ IPIV, 1 ) * CALL DGEMM( 'No transpose', 'No transpose', $ JB, N-J-JB+1, J-1, -ONE, $ A( J, 1 ), LDA, A( 1, J+JB ), LDA, ONE, $ A( J, J+JB ), LDA ) * * Compute block row of U. * CALL DTRSM( 'Left', 'Lower', 'No transpose', 'Unit', $ JB, N-J-JB+1, ONE, A( J, J ), LDA, $ A( J, J+JB ), LDA ) END IF 20 CONTINUE END IF RETURN * * End of DGETRF * END
bsd-3-clause
vfonov/ITK
Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/double/dggbak.f
43
6192
SUBROUTINE DGGBAK( JOB, SIDE, N, ILO, IHI, LSCALE, RSCALE, M, V, $ LDV, INFO ) * * -- LAPACK routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * September 30, 1994 * * .. Scalar Arguments .. CHARACTER JOB, SIDE INTEGER IHI, ILO, INFO, LDV, M, N * .. * .. Array Arguments .. DOUBLE PRECISION LSCALE( * ), RSCALE( * ), V( LDV, * ) * .. * * Purpose * ======= * * DGGBAK forms the right or left eigenvectors of a real generalized * eigenvalue problem A*x = lambda*B*x, by backward transformation on * the computed eigenvectors of the balanced pair of matrices output by * DGGBAL. * * Arguments * ========= * * JOB (input) CHARACTER*1 * Specifies the type of backward transformation required: * = 'N': do nothing, return immediately; * = 'P': do backward transformation for permutation only; * = 'S': do backward transformation for scaling only; * = 'B': do backward transformations for both permutation and * scaling. * JOB must be the same as the argument JOB supplied to DGGBAL. * * SIDE (input) CHARACTER*1 * = 'R': V contains right eigenvectors; * = 'L': V contains left eigenvectors. * * N (input) INTEGER * The number of rows of the matrix V. N >= 0. * * ILO (input) INTEGER * IHI (input) INTEGER * The integers ILO and IHI determined by DGGBAL. * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. * * LSCALE (input) DOUBLE PRECISION array, dimension (N) * Details of the permutations and/or scaling factors applied * to the left side of A and B, as returned by DGGBAL. * * RSCALE (input) DOUBLE PRECISION array, dimension (N) * Details of the permutations and/or scaling factors applied * to the right side of A and B, as returned by DGGBAL. * * M (input) INTEGER * The number of columns of the matrix V. M >= 0. * * V (input/output) DOUBLE PRECISION array, dimension (LDV,M) * On entry, the matrix of right or left eigenvectors to be * transformed, as returned by DTGEVC. * On exit, V is overwritten by the transformed eigenvectors. * * LDV (input) INTEGER * The leading dimension of the matrix V. LDV >= max(1,N). * * INFO (output) INTEGER * = 0: successful exit. * < 0: if INFO = -i, the i-th argument had an illegal value. * * Further Details * =============== * * See R.C. Ward, Balancing the generalized eigenvalue problem, * SIAM J. Sci. Stat. Comp. 2 (1981), 141-152. * * ===================================================================== * * .. Local Scalars .. LOGICAL LEFTV, RIGHTV INTEGER I, K * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL DSCAL, DSWAP, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters * RIGHTV = LSAME( SIDE, 'R' ) LEFTV = LSAME( SIDE, 'L' ) * 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( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( ILO.LT.1 ) THEN INFO = -4 ELSE IF( IHI.LT.ILO .OR. IHI.GT.MAX( 1, N ) ) THEN INFO = -5 ELSE IF( M.LT.0 ) THEN INFO = -6 ELSE IF( LDV.LT.MAX( 1, N ) ) THEN INFO = -10 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGGBAK', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN IF( M.EQ.0 ) $ RETURN IF( LSAME( JOB, 'N' ) ) $ RETURN * IF( ILO.EQ.IHI ) $ GO TO 30 * * Backward balance * IF( LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'B' ) ) THEN * * Backward transformation on right eigenvectors * IF( RIGHTV ) THEN DO 10 I = ILO, IHI CALL DSCAL( M, RSCALE( I ), V( I, 1 ), LDV ) 10 CONTINUE END IF * * Backward transformation on left eigenvectors * IF( LEFTV ) THEN DO 20 I = ILO, IHI CALL DSCAL( M, LSCALE( I ), V( I, 1 ), LDV ) 20 CONTINUE END IF END IF * * Backward permutation * 30 CONTINUE IF( LSAME( JOB, 'P' ) .OR. LSAME( JOB, 'B' ) ) THEN * * Backward permutation on right eigenvectors * IF( RIGHTV ) THEN IF( ILO.EQ.1 ) $ GO TO 50 * DO 40 I = ILO - 1, 1, -1 K = RSCALE( I ) IF( K.EQ.I ) $ GO TO 40 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV ) 40 CONTINUE * 50 CONTINUE IF( IHI.EQ.N ) $ GO TO 70 DO 60 I = IHI + 1, N K = RSCALE( I ) IF( K.EQ.I ) $ GO TO 60 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV ) 60 CONTINUE END IF * * Backward permutation on left eigenvectors * 70 CONTINUE IF( LEFTV ) THEN IF( ILO.EQ.1 ) $ GO TO 90 DO 80 I = ILO - 1, 1, -1 K = LSCALE( I ) IF( K.EQ.I ) $ GO TO 80 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV ) 80 CONTINUE * 90 CONTINUE IF( IHI.EQ.N ) $ GO TO 110 DO 100 I = IHI + 1, N K = LSCALE( I ) IF( K.EQ.I ) $ GO TO 100 CALL DSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV ) 100 CONTINUE END IF END IF * 110 CONTINUE * RETURN * * End of DGGBAK * END
apache-2.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/TESTING/EIG/cdrvgg.f
29
34277
*> \brief \b CDRVGG * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE CDRVGG( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH, * THRSHN, NOUNIT, A, LDA, B, S, T, S2, T2, Q, * LDQ, Z, ALPHA1, BETA1, ALPHA2, BETA2, VL, VR, * WORK, LWORK, RWORK, RESULT, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LDQ, LWORK, NOUNIT, NSIZES, NTYPES * REAL THRESH, THRSHN * .. * .. Array Arguments .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CDRVGG checks the nonsymmetric generalized eigenvalue driver *> routines. *> T T T *> CGEGS factors A and B as Q S Z and Q T Z , where means *> transpose, T is upper triangular, S is in generalized Schur form *> (upper triangular), and Q and Z are unitary. It also *> computes the generalized eigenvalues (alpha(1),beta(1)), ..., *> (alpha(n),beta(n)), where alpha(j)=S(j,j) and beta(j)=T(j,j) -- *> thus, w(j) = alpha(j)/beta(j) is a root of the generalized *> eigenvalue problem *> *> det( A - w(j) B ) = 0 *> *> and m(j) = beta(j)/alpha(j) is a root of the essentially equivalent *> problem *> *> det( m(j) A - B ) = 0 *> *> CGEGV computes the generalized eigenvalues (alpha(1),beta(1)), ..., *> (alpha(n),beta(n)), the matrix L whose columns contain the *> generalized left eigenvectors l, and the matrix R whose columns *> contain the generalized right eigenvectors r for the pair (A,B). *> *> When CDRVGG is called, a number of matrix "sizes" ("n's") and a *> number of matrix "types" are specified. For each size ("n") *> and each type of matrix, one matrix will be generated and used *> to test the nonsymmetric eigenroutines. For each matrix, 7 *> tests will be performed and compared with the threshhold THRESH: *> *> Results from CGEGS: *> *> H *> (1) | A - Q S Z | / ( |A| n ulp ) *> *> H *> (2) | B - Q T Z | / ( |B| n ulp ) *> *> H *> (3) | I - QQ | / ( n ulp ) *> *> H *> (4) | I - ZZ | / ( n ulp ) *> *> (5) maximum over j of D(j) where: *> *> |alpha(j) - S(j,j)| |beta(j) - T(j,j)| *> D(j) = ------------------------ + ----------------------- *> max(|alpha(j)|,|S(j,j)|) max(|beta(j)|,|T(j,j)|) *> *> Results from CGEGV: *> *> (6) max over all left eigenvalue/-vector pairs (beta/alpha,l) of *> *> | l**H * (beta A - alpha B) | / ( ulp max( |beta A|, |alpha B| ) ) *> *> where l**H is the conjugate tranpose of l. *> *> (7) max over all right eigenvalue/-vector pairs (beta/alpha,r) of *> *> | (beta A - alpha B) r | / ( ulp max( |beta A|, |alpha B| ) ) *> *> Test Matrices *> ---- -------- *> *> The sizes of the test matrices are specified by an array *> NN(1:NSIZES); the value of each element NN(j) specifies one size. *> The "types" are specified by a logical array DOTYPE( 1:NTYPES ); if *> DOTYPE(j) is .TRUE., then matrix type "j" will be generated. *> Currently, the list of possible types is: *> *> (1) ( 0, 0 ) (a pair of zero matrices) *> *> (2) ( I, 0 ) (an identity and a zero matrix) *> *> (3) ( 0, I ) (an identity and a zero matrix) *> *> (4) ( I, I ) (a pair of identity matrices) *> *> t t *> (5) ( J , J ) (a pair of transposed Jordan blocks) *> *> t ( I 0 ) *> (6) ( X, Y ) where X = ( J 0 ) and Y = ( t ) *> ( 0 I ) ( 0 J ) *> and I is a k x k identity and J a (k+1)x(k+1) *> Jordan block; k=(N-1)/2 *> *> (7) ( D, I ) where D is diag( 0, 1,..., N-1 ) (a diagonal *> matrix with those diagonal entries.) *> (8) ( I, D ) *> *> (9) ( big*D, small*I ) where "big" is near overflow and small=1/big *> *> (10) ( small*D, big*I ) *> *> (11) ( big*I, small*D ) *> *> (12) ( small*I, big*D ) *> *> (13) ( big*D, big*I ) *> *> (14) ( small*D, small*I ) *> *> (15) ( D1, D2 ) where D1 is diag( 0, 0, 1, ..., N-3, 0 ) and *> D2 is diag( 0, N-3, N-4,..., 1, 0, 0 ) *> t t *> (16) Q ( J , J ) Z where Q and Z are random unitary matrices. *> *> (17) Q ( T1, T2 ) Z where T1 and T2 are upper triangular matrices *> with random O(1) entries above the diagonal *> and diagonal entries diag(T1) = *> ( 0, 0, 1, ..., N-3, 0 ) and diag(T2) = *> ( 0, N-3, N-4,..., 1, 0, 0 ) *> *> (18) Q ( T1, T2 ) Z diag(T1) = ( 0, 0, 1, 1, s, ..., s, 0 ) *> diag(T2) = ( 0, 1, 0, 1,..., 1, 0 ) *> s = machine precision. *> *> (19) Q ( T1, T2 ) Z diag(T1)=( 0,0,1,1, 1-d, ..., 1-(N-5)*d=s, 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0 ) *> *> N-5 *> (20) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, 1, a, ..., a =s, 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 ) *> *> (21) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, r1, r2, ..., r(N-4), 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 ) *> where r1,..., r(N-4) are random. *> *> (22) Q ( big*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (23) Q ( small*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (24) Q ( small*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (25) Q ( big*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (26) Q ( T1, T2 ) Z where T1 and T2 are random upper-triangular *> matrices. *> \endverbatim * * Arguments: * ========== * *> \param[in] NSIZES *> \verbatim *> NSIZES is INTEGER *> The number of sizes of matrices to use. If it is zero, *> CDRVGG does nothing. It must be at least zero. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER array, dimension (NSIZES) *> An array containing the sizes to be used for the matrices. *> Zero values will be skipped. The values must be at least *> zero. *> \endverbatim *> *> \param[in] NTYPES *> \verbatim *> NTYPES is INTEGER *> The number of elements in DOTYPE. If it is zero, CDRVGG *> 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 matrix is in A. This *> is only useful if DOTYPE(1:MAXTYP) is .FALSE. and *> DOTYPE(MAXTYP+1) is .TRUE. . *> \endverbatim *> *> \param[in] DOTYPE *> \verbatim *> DOTYPE is LOGICAL array, dimension (NTYPES) *> If DOTYPE(j) is .TRUE., then for each size in NN a *> matrix of that size and 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. *> \endverbatim *> *> \param[in,out] ISEED *> \verbatim *> ISEED is 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 random number generator uses a linear *> congruential sequence limited to small integers, and so *> should produce machine independent random numbers. The *> values of ISEED are changed on exit, and can be used in the *> next call to CDRVGG to continue the same random number *> sequence. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is REAL *> A test will count as "failed" if the "error", computed as *> described above, exceeds THRESH. Note that the error is *> scaled to be O(1), so THRESH should be a reasonably small *> multiple of 1, e.g., 10 or 100. In particular, it should *> not depend on the precision (single vs. double) or the size *> of the matrix. It must be at least zero. *> \endverbatim *> *> \param[in] THRSHN *> \verbatim *> THRSHN is REAL *> Threshhold for reporting eigenvector normalization error. *> If the normalization of any eigenvector differs from 1 by *> more than THRSHN*ulp, then a special error message will be *> printed. (This is handled separately from the other tests, *> since only a compiler or programming error should cause an *> error message, at least if THRSHN is at least 5--10.) *> \endverbatim *> *> \param[in] NOUNIT *> \verbatim *> NOUNIT is INTEGER *> The FORTRAN unit number for printing out error messages *> (e.g., if a routine returns IINFO not equal to 0.) *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA, max(NN)) *> Used to hold the original A matrix. Used as input only *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and *> DOTYPE(MAXTYP+1)=.TRUE. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of A, B, S, T, S2, and T2. *> It must be at least 1 and at least max( NN ). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is COMPLEX array, dimension (LDA, max(NN)) *> Used to hold the original B matrix. Used as input only *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and *> DOTYPE(MAXTYP+1)=.TRUE. *> \endverbatim *> *> \param[out] S *> \verbatim *> S is COMPLEX array, dimension (LDA, max(NN)) *> The upper triangular matrix computed from A by CGEGS. *> \endverbatim *> *> \param[out] T *> \verbatim *> T is COMPLEX array, dimension (LDA, max(NN)) *> The upper triangular matrix computed from B by CGEGS. *> \endverbatim *> *> \param[out] S2 *> \verbatim *> S2 is COMPLEX array, dimension (LDA, max(NN)) *> The matrix computed from A by CGEGV. This will be the *> Schur (upper triangular) form of some matrix related to A, *> but will not, in general, be the same as S. *> \endverbatim *> *> \param[out] T2 *> \verbatim *> T2 is COMPLEX array, dimension (LDA, max(NN)) *> The matrix computed from B by CGEGV. This will be the *> Schur form of some matrix related to B, but will not, in *> general, be the same as T. *> \endverbatim *> *> \param[out] Q *> \verbatim *> Q is COMPLEX array, dimension (LDQ, max(NN)) *> The (left) unitary matrix computed by CGEGS. *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of Q, Z, VL, and VR. It must *> be at least 1 and at least max( NN ). *> \endverbatim *> *> \param[out] Z *> \verbatim *> Z is COMPLEX array, dimension (LDQ, max(NN)) *> The (right) unitary matrix computed by CGEGS. *> \endverbatim *> *> \param[out] ALPHA1 *> \verbatim *> ALPHA1 is COMPLEX array, dimension (max(NN)) *> \endverbatim *> *> \param[out] BETA1 *> \verbatim *> BETA1 is COMPLEX array, dimension (max(NN)) *> *> The generalized eigenvalues of (A,B) computed by CGEGS. *> ALPHA1(k) / BETA1(k) is the k-th generalized eigenvalue of *> the matrices in A and B. *> \endverbatim *> *> \param[out] ALPHA2 *> \verbatim *> ALPHA2 is COMPLEX array, dimension (max(NN)) *> \endverbatim *> *> \param[out] BETA2 *> \verbatim *> BETA2 is COMPLEX array, dimension (max(NN)) *> *> The generalized eigenvalues of (A,B) computed by CGEGV. *> ALPHA2(k) / BETA2(k) is the k-th generalized eigenvalue of *> the matrices in A and B. *> \endverbatim *> *> \param[out] VL *> \verbatim *> VL is COMPLEX array, dimension (LDQ, max(NN)) *> The (lower triangular) left eigenvector matrix for the *> matrices in A and B. *> \endverbatim *> *> \param[out] VR *> \verbatim *> VR is COMPLEX array, dimension (LDQ, max(NN)) *> The (upper triangular) right eigenvector matrix for the *> matrices in A and B. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (LWORK) *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The number of entries in WORK. This must be at least *> MAX( 2*N, N*(NB+1), (k+1)*(2*k+N+1) ), where "k" is the *> sum of the blocksize and number-of-shifts for CHGEQZ, and *> NB is the greatest of the blocksizes for CGEQRF, CUNMQR, *> and CUNGQR. (The blocksizes and the number-of-shifts are *> retrieved through calls to ILAENV.) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension (8*N) *> \endverbatim *> *> \param[out] RESULT *> \verbatim *> RESULT is REAL array, dimension (7) *> The values computed by the tests described above. *> The values are currently limited to 1/ulp, to avoid *> overflow. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value. *> > 0: A routine returned an error code. INFO is the *> absolute value of the INFO value returned. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex_eig * * ===================================================================== SUBROUTINE CDRVGG( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH, $ THRSHN, NOUNIT, A, LDA, B, S, T, S2, T2, Q, $ LDQ, Z, ALPHA1, BETA1, ALPHA2, BETA2, VL, VR, $ WORK, LWORK, RWORK, RESULT, INFO ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, LDQ, LWORK, NOUNIT, NSIZES, NTYPES REAL THRESH, THRSHN * .. * .. Array Arguments .. * * ===================================================================== * LOGICAL DOTYPE( * ) INTEGER ISEED( 4 ), NN( * ) REAL RESULT( * ), RWORK( * ) COMPLEX A( LDA, * ), ALPHA1( * ), ALPHA2( * ), $ B( LDA, * ), BETA1( * ), BETA2( * ), $ Q( LDQ, * ), S( LDA, * ), S2( LDA, * ), $ T( LDA, * ), T2( LDA, * ), VL( LDQ, * ), $ VR( LDQ, * ), WORK( * ), Z( LDQ, * ) * .. * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) COMPLEX CZERO, CONE PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ), $ CONE = ( 1.0E+0, 0.0E+0 ) ) INTEGER MAXTYP PARAMETER ( MAXTYP = 26 ) * .. * .. Local Scalars .. LOGICAL BADNN INTEGER I1, IADD, IINFO, IN, J, JC, JR, JSIZE, JTYPE, $ LWKOPT, MTYPES, N, N1, NB, NBZ, NERRS, NMATS, $ NMAX, NS, NTEST, NTESTT REAL SAFMAX, SAFMIN, TEMP1, TEMP2, ULP, ULPINV COMPLEX CTEMP, X * .. * .. Local Arrays .. LOGICAL LASIGN( MAXTYP ), LBSIGN( MAXTYP ) INTEGER IOLDSD( 4 ), KADD( 6 ), KAMAGN( MAXTYP ), $ KATYPE( MAXTYP ), KAZERO( MAXTYP ), $ KBMAGN( MAXTYP ), KBTYPE( MAXTYP ), $ KBZERO( MAXTYP ), KCLASS( MAXTYP ), $ KTRIAN( MAXTYP ), KZ1( 6 ), KZ2( 6 ) REAL DUMMA( 4 ), RMAGN( 0: 3 ) * .. * .. External Functions .. INTEGER ILAENV REAL SLAMCH COMPLEX CLARND EXTERNAL ILAENV, SLAMCH, CLARND * .. * .. External Subroutines .. EXTERNAL ALASVM, CGEGS, CGEGV, CGET51, CGET52, CLACPY, $ CLARFG, CLASET, CLATM4, CUNM2R, SLABAD, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, AIMAG, CONJG, MAX, MIN, REAL, SIGN * .. * .. Statement Functions .. REAL ABS1 * .. * .. Statement Function definitions .. ABS1( X ) = ABS( REAL( X ) ) + ABS( AIMAG( X ) ) * .. * .. Data statements .. DATA KCLASS / 15*1, 10*2, 1*3 / DATA KZ1 / 0, 1, 2, 1, 3, 3 / DATA KZ2 / 0, 0, 1, 2, 1, 1 / DATA KADD / 0, 0, 0, 0, 3, 2 / DATA KATYPE / 0, 1, 0, 1, 2, 3, 4, 1, 4, 4, 1, 1, 4, $ 4, 4, 2, 4, 5, 8, 7, 9, 4*4, 0 / DATA KBTYPE / 0, 0, 1, 1, 2, -3, 1, 4, 1, 1, 4, 4, $ 1, 1, -4, 2, -4, 8*8, 0 / DATA KAZERO / 6*1, 2, 1, 2*2, 2*1, 2*2, 3, 1, 3, $ 4*5, 4*3, 1 / DATA KBZERO / 6*1, 1, 2, 2*1, 2*2, 2*1, 4, 1, 4, $ 4*6, 4*4, 1 / DATA KAMAGN / 8*1, 2, 3, 2, 3, 2, 3, 7*1, 2, 3, 3, $ 2, 1 / DATA KBMAGN / 8*1, 3, 2, 3, 2, 2, 3, 7*1, 3, 2, 3, $ 2, 1 / DATA KTRIAN / 16*0, 10*1 / DATA LASIGN / 6*.FALSE., .TRUE., .FALSE., 2*.TRUE., $ 2*.FALSE., 3*.TRUE., .FALSE., .TRUE., $ 3*.FALSE., 5*.TRUE., .FALSE. / DATA LBSIGN / 7*.FALSE., .TRUE., 2*.FALSE., $ 2*.TRUE., 2*.FALSE., .TRUE., .FALSE., .TRUE., $ 9*.FALSE. / * .. * .. Executable Statements .. * * Check for errors * INFO = 0 * BADNN = .FALSE. NMAX = 1 DO 10 J = 1, NSIZES NMAX = MAX( NMAX, NN( J ) ) IF( NN( J ).LT.0 ) $ BADNN = .TRUE. 10 CONTINUE * * Maximum blocksize and shift -- we assume that blocksize and number * of shifts are monotone increasing functions of N. * NB = MAX( 1, ILAENV( 1, 'CGEQRF', ' ', NMAX, NMAX, -1, -1 ), $ ILAENV( 1, 'CUNMQR', 'LC', NMAX, NMAX, NMAX, -1 ), $ ILAENV( 1, 'CUNGQR', ' ', NMAX, NMAX, NMAX, -1 ) ) NBZ = ILAENV( 1, 'CHGEQZ', 'SII', NMAX, 1, NMAX, 0 ) NS = ILAENV( 4, 'CHGEQZ', 'SII', NMAX, 1, NMAX, 0 ) I1 = NBZ + NS LWKOPT = MAX( 2*NMAX, NMAX*( NB+1 ), ( 2*I1+NMAX+1 )*( I1+1 ) ) * * Check for errors * IF( NSIZES.LT.0 ) THEN INFO = -1 ELSE IF( BADNN ) THEN INFO = -2 ELSE IF( NTYPES.LT.0 ) THEN INFO = -3 ELSE IF( THRESH.LT.ZERO ) THEN INFO = -6 ELSE IF( LDA.LE.1 .OR. LDA.LT.NMAX ) THEN INFO = -10 ELSE IF( LDQ.LE.1 .OR. LDQ.LT.NMAX ) THEN INFO = -19 ELSE IF( LWKOPT.GT.LWORK ) THEN INFO = -30 END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'CDRVGG', -INFO ) RETURN END IF * * Quick return if possible * IF( NSIZES.EQ.0 .OR. NTYPES.EQ.0 ) $ RETURN * ULP = SLAMCH( 'Precision' ) SAFMIN = SLAMCH( 'Safe minimum' ) SAFMIN = SAFMIN / ULP SAFMAX = ONE / SAFMIN CALL SLABAD( SAFMIN, SAFMAX ) ULPINV = ONE / ULP * * The values RMAGN(2:3) depend on N, see below. * RMAGN( 0 ) = ZERO RMAGN( 1 ) = ONE * * Loop over sizes, types * NTESTT = 0 NERRS = 0 NMATS = 0 * DO 160 JSIZE = 1, NSIZES N = NN( JSIZE ) N1 = MAX( 1, N ) RMAGN( 2 ) = SAFMAX*ULP / REAL( N1 ) RMAGN( 3 ) = SAFMIN*ULPINV*N1 * IF( NSIZES.NE.1 ) THEN MTYPES = MIN( MAXTYP, NTYPES ) ELSE MTYPES = MIN( MAXTYP+1, NTYPES ) END IF * DO 150 JTYPE = 1, MTYPES IF( .NOT.DOTYPE( JTYPE ) ) $ GO TO 150 NMATS = NMATS + 1 NTEST = 0 * * Save ISEED in case of an error. * DO 20 J = 1, 4 IOLDSD( J ) = ISEED( J ) 20 CONTINUE * * Initialize RESULT * DO 30 J = 1, 7 RESULT( J ) = ZERO 30 CONTINUE * * Compute A and B * * Description of control parameters: * * KCLASS: =1 means w/o rotation, =2 means w/ rotation, * =3 means random. * KATYPE: the "type" to be passed to CLATM4 for computing A. * KAZERO: the pattern of zeros on the diagonal for A: * =1: ( xxx ), =2: (0, xxx ) =3: ( 0, 0, xxx, 0 ), * =4: ( 0, xxx, 0, 0 ), =5: ( 0, 0, 1, xxx, 0 ), * =6: ( 0, 1, 0, xxx, 0 ). (xxx means a string of * non-zero entries.) * KAMAGN: the magnitude of the matrix: =0: zero, =1: O(1), * =2: large, =3: small. * LASIGN: .TRUE. if the diagonal elements of A are to be * multiplied by a random magnitude 1 number. * KBTYPE, KBZERO, KBMAGN, IBSIGN: the same, but for B. * KTRIAN: =0: don't fill in the upper triangle, =1: do. * KZ1, KZ2, KADD: used to implement KAZERO and KBZERO. * RMAGN: used to implement KAMAGN and KBMAGN. * IF( MTYPES.GT.MAXTYP ) $ GO TO 110 IINFO = 0 IF( KCLASS( JTYPE ).LT.3 ) THEN * * Generate A (w/o rotation) * IF( ABS( KATYPE( JTYPE ) ).EQ.3 ) THEN IN = 2*( ( N-1 ) / 2 ) + 1 IF( IN.NE.N ) $ CALL CLASET( 'Full', N, N, CZERO, CZERO, A, LDA ) ELSE IN = N END IF CALL CLATM4( KATYPE( JTYPE ), IN, KZ1( KAZERO( JTYPE ) ), $ KZ2( KAZERO( JTYPE ) ), LASIGN( JTYPE ), $ RMAGN( KAMAGN( JTYPE ) ), ULP, $ RMAGN( KTRIAN( JTYPE )*KAMAGN( JTYPE ) ), 2, $ ISEED, A, LDA ) IADD = KADD( KAZERO( JTYPE ) ) IF( IADD.GT.0 .AND. IADD.LE.N ) $ A( IADD, IADD ) = RMAGN( KAMAGN( JTYPE ) ) * * Generate B (w/o rotation) * IF( ABS( KBTYPE( JTYPE ) ).EQ.3 ) THEN IN = 2*( ( N-1 ) / 2 ) + 1 IF( IN.NE.N ) $ CALL CLASET( 'Full', N, N, CZERO, CZERO, B, LDA ) ELSE IN = N END IF CALL CLATM4( KBTYPE( JTYPE ), IN, KZ1( KBZERO( JTYPE ) ), $ KZ2( KBZERO( JTYPE ) ), LBSIGN( JTYPE ), $ RMAGN( KBMAGN( JTYPE ) ), ONE, $ RMAGN( KTRIAN( JTYPE )*KBMAGN( JTYPE ) ), 2, $ ISEED, B, LDA ) IADD = KADD( KBZERO( JTYPE ) ) IF( IADD.NE.0 .AND. IADD.LE.N ) $ B( IADD, IADD ) = RMAGN( KBMAGN( JTYPE ) ) * IF( KCLASS( JTYPE ).EQ.2 .AND. N.GT.0 ) THEN * * Include rotations * * Generate Q, Z as Householder transformations times * a diagonal matrix. * DO 50 JC = 1, N - 1 DO 40 JR = JC, N Q( JR, JC ) = CLARND( 3, ISEED ) Z( JR, JC ) = CLARND( 3, ISEED ) 40 CONTINUE CALL CLARFG( N+1-JC, Q( JC, JC ), Q( JC+1, JC ), 1, $ WORK( JC ) ) WORK( 2*N+JC ) = SIGN( ONE, REAL( Q( JC, JC ) ) ) Q( JC, JC ) = CONE CALL CLARFG( N+1-JC, Z( JC, JC ), Z( JC+1, JC ), 1, $ WORK( N+JC ) ) WORK( 3*N+JC ) = SIGN( ONE, REAL( Z( JC, JC ) ) ) Z( JC, JC ) = CONE 50 CONTINUE CTEMP = CLARND( 3, ISEED ) Q( N, N ) = CONE WORK( N ) = CZERO WORK( 3*N ) = CTEMP / ABS( CTEMP ) CTEMP = CLARND( 3, ISEED ) Z( N, N ) = CONE WORK( 2*N ) = CZERO WORK( 4*N ) = CTEMP / ABS( CTEMP ) * * Apply the diagonal matrices * DO 70 JC = 1, N DO 60 JR = 1, N A( JR, JC ) = WORK( 2*N+JR )* $ CONJG( WORK( 3*N+JC ) )* $ A( JR, JC ) B( JR, JC ) = WORK( 2*N+JR )* $ CONJG( WORK( 3*N+JC ) )* $ B( JR, JC ) 60 CONTINUE 70 CONTINUE CALL CUNM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, A, $ LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 CALL CUNM2R( 'R', 'C', N, N, N-1, Z, LDQ, WORK( N+1 ), $ A, LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 CALL CUNM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, B, $ LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 CALL CUNM2R( 'R', 'C', N, N, N-1, Z, LDQ, WORK( N+1 ), $ B, LDA, WORK( 2*N+1 ), IINFO ) IF( IINFO.NE.0 ) $ GO TO 100 END IF ELSE * * Random matrices * DO 90 JC = 1, N DO 80 JR = 1, N A( JR, JC ) = RMAGN( KAMAGN( JTYPE ) )* $ CLARND( 4, ISEED ) B( JR, JC ) = RMAGN( KBMAGN( JTYPE ) )* $ CLARND( 4, ISEED ) 80 CONTINUE 90 CONTINUE END IF * 100 CONTINUE * IF( IINFO.NE.0 ) THEN WRITE( NOUNIT, FMT = 9999 )'Generator', IINFO, N, JTYPE, $ IOLDSD INFO = ABS( IINFO ) RETURN END IF * 110 CONTINUE * * Call CGEGS to compute H, T, Q, Z, alpha, and beta. * CALL CLACPY( ' ', N, N, A, LDA, S, LDA ) CALL CLACPY( ' ', N, N, B, LDA, T, LDA ) NTEST = 1 RESULT( 1 ) = ULPINV * CALL CGEGS( 'V', 'V', N, S, LDA, T, LDA, ALPHA1, BETA1, Q, $ LDQ, Z, LDQ, WORK, LWORK, RWORK, IINFO ) IF( IINFO.NE.0 ) THEN WRITE( NOUNIT, FMT = 9999 )'CGEGS', IINFO, N, JTYPE, $ IOLDSD INFO = ABS( IINFO ) GO TO 130 END IF * NTEST = 4 * * Do tests 1--4 * CALL CGET51( 1, N, A, LDA, S, LDA, Q, LDQ, Z, LDQ, WORK, $ RWORK, RESULT( 1 ) ) CALL CGET51( 1, N, B, LDA, T, LDA, Q, LDQ, Z, LDQ, WORK, $ RWORK, RESULT( 2 ) ) CALL CGET51( 3, N, B, LDA, T, LDA, Q, LDQ, Q, LDQ, WORK, $ RWORK, RESULT( 3 ) ) CALL CGET51( 3, N, B, LDA, T, LDA, Z, LDQ, Z, LDQ, WORK, $ RWORK, RESULT( 4 ) ) * * Do test 5: compare eigenvalues with diagonals. * TEMP1 = ZERO * DO 120 J = 1, N TEMP2 = ( ABS1( ALPHA1( J )-S( J, J ) ) / $ MAX( SAFMIN, ABS1( ALPHA1( J ) ), ABS1( S( J, $ J ) ) )+ABS1( BETA1( J )-T( J, J ) ) / $ MAX( SAFMIN, ABS1( BETA1( J ) ), ABS1( T( J, $ J ) ) ) ) / ULP TEMP1 = MAX( TEMP1, TEMP2 ) 120 CONTINUE RESULT( 5 ) = TEMP1 * * Call CGEGV to compute S2, T2, VL, and VR, do tests. * * Eigenvalues and Eigenvectors * CALL CLACPY( ' ', N, N, A, LDA, S2, LDA ) CALL CLACPY( ' ', N, N, B, LDA, T2, LDA ) NTEST = 6 RESULT( 6 ) = ULPINV * CALL CGEGV( 'V', 'V', N, S2, LDA, T2, LDA, ALPHA2, BETA2, $ VL, LDQ, VR, LDQ, WORK, LWORK, RWORK, IINFO ) IF( IINFO.NE.0 ) THEN WRITE( NOUNIT, FMT = 9999 )'CGEGV', IINFO, N, JTYPE, $ IOLDSD INFO = ABS( IINFO ) GO TO 130 END IF * NTEST = 7 * * Do Tests 6 and 7 * CALL CGET52( .TRUE., N, A, LDA, B, LDA, VL, LDQ, ALPHA2, $ BETA2, WORK, RWORK, DUMMA( 1 ) ) RESULT( 6 ) = DUMMA( 1 ) IF( DUMMA( 2 ).GT.THRSHN ) THEN WRITE( NOUNIT, FMT = 9998 )'Left', 'CGEGV', DUMMA( 2 ), $ N, JTYPE, IOLDSD END IF * CALL CGET52( .FALSE., N, A, LDA, B, LDA, VR, LDQ, ALPHA2, $ BETA2, WORK, RWORK, DUMMA( 1 ) ) RESULT( 7 ) = DUMMA( 1 ) IF( DUMMA( 2 ).GT.THRESH ) THEN WRITE( NOUNIT, FMT = 9998 )'Right', 'CGEGV', DUMMA( 2 ), $ N, JTYPE, IOLDSD END IF * * End of Loop -- Check for RESULT(j) > THRESH * 130 CONTINUE * NTESTT = NTESTT + NTEST * * Print out tests which fail. * DO 140 JR = 1, NTEST IF( RESULT( JR ).GE.THRESH ) THEN * * If this is the first test to fail, * print a header to the data file. * IF( NERRS.EQ.0 ) THEN WRITE( NOUNIT, FMT = 9997 )'CGG' * * Matrix types * WRITE( NOUNIT, FMT = 9996 ) WRITE( NOUNIT, FMT = 9995 ) WRITE( NOUNIT, FMT = 9994 )'Unitary' * * Tests performed * WRITE( NOUNIT, FMT = 9993 )'unitary', '*', $ 'conjugate transpose', ( '*', J = 1, 5 ) * END IF NERRS = NERRS + 1 IF( RESULT( JR ).LT.10000.0 ) THEN WRITE( NOUNIT, FMT = 9992 )N, JTYPE, IOLDSD, JR, $ RESULT( JR ) ELSE WRITE( NOUNIT, FMT = 9991 )N, JTYPE, IOLDSD, JR, $ RESULT( JR ) END IF END IF 140 CONTINUE * 150 CONTINUE 160 CONTINUE * * Summary * CALL ALASVM( 'CGG', NOUNIT, NERRS, NTESTT, 0 ) RETURN * 9999 FORMAT( ' CDRVGG: ', A, ' returned INFO=', I6, '.', / 9X, 'N=', $ I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ), I5, ')' ) * 9998 FORMAT( ' CDRVGG: ', A, ' Eigenvectors from ', A, ' incorrectly ', $ 'normalized.', / ' Bits of error=', 0P, G10.3, ',', 9X, $ 'N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ), I5, $ ')' ) * 9997 FORMAT( / 1X, A3, $ ' -- Complex Generalized eigenvalue problem driver' ) * 9996 FORMAT( ' Matrix types (see CDRVGG for details): ' ) * 9995 FORMAT( ' Special Matrices:', 23X, $ '(J''=transposed Jordan block)', $ / ' 1=(0,0) 2=(I,0) 3=(0,I) 4=(I,I) 5=(J'',J'') ', $ '6=(diag(J'',I), diag(I,J''))', / ' Diagonal Matrices: ( ', $ 'D=diag(0,1,2,...) )', / ' 7=(D,I) 9=(large*D, small*I', $ ') 11=(large*I, small*D) 13=(large*D, large*I)', / $ ' 8=(I,D) 10=(small*D, large*I) 12=(small*I, large*D) ', $ ' 14=(small*D, small*I)', / ' 15=(D, reversed D)' ) 9994 FORMAT( ' Matrices Rotated by Random ', A, ' Matrices U, V:', $ / ' 16=Transposed Jordan Blocks 19=geometric ', $ 'alpha, beta=0,1', / ' 17=arithm. alpha&beta ', $ ' 20=arithmetic alpha, beta=0,1', / ' 18=clustered ', $ 'alpha, beta=0,1 21=random alpha, beta=0,1', $ / ' Large & Small Matrices:', / ' 22=(large, small) ', $ '23=(small,large) 24=(small,small) 25=(large,large)', $ / ' 26=random O(1) matrices.' ) * 9993 FORMAT( / ' Tests performed: (S is Schur, T is triangular, ', $ 'Q and Z are ', A, ',', / 20X, $ 'l and r are the appropriate left and right', / 19X, $ 'eigenvectors, resp., a is alpha, b is beta, and', / 19X, A, $ ' means ', A, '.)', / ' 1 = | A - Q S Z', A, $ ' | / ( |A| n ulp ) 2 = | B - Q T Z', A, $ ' | / ( |B| n ulp )', / ' 3 = | I - QQ', A, $ ' | / ( n ulp ) 4 = | I - ZZ', A, $ ' | / ( n ulp )', / $ ' 5 = difference between (alpha,beta) and diagonals of', $ ' (S,T)', / ' 6 = max | ( b A - a B )', A, $ ' l | / const. 7 = max | ( b A - a B ) r | / const.', $ / 1X ) 9992 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=', $ 4( I4, ',' ), ' result ', I3, ' is', 0P, F8.2 ) 9991 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=', $ 4( I4, ',' ), ' result ', I3, ' is', 1P, E10.3 ) * * End of CDRVGG * END
bsd-3-clause
aarchiba/scipy
scipy/linalg/src/id_dist/src/idz_frm.f
133
10151
c this file contains the following user-callable routines: c c c routine idz_frm transforms a vector via a composition c of Rokhlin's random transform, random subselection, and an FFT. c c routine idz_sfrm transforms a vector into a vector c of specified length via a composition c of Rokhlin's random transform, random subselection, and an FFT. c c routine idz_frmi initializes routine idz_frm. c c routine idz_sfrmi initializes routine idz_sfrm. c c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c c c subroutine idz_frm(m,n,w,x,y) c c transforms x into y via a composition c of Rokhlin's random transform, random subselection, and an FFT. c In contrast to routine idz_sfrm, the present routine works best c when the length of the transformed vector is the integer n c output by routine idz_frmi, or when the length c is not specified, but instead determined a posteriori c using the output of the present routine. The transformed vector c output by the present routine is randomly permuted. c c input: c m -- length of x c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m, as obtained c from the routine idz_frmi; n is the length of y c w -- initialization array constructed by routine idz_frmi c x -- vector to be transformed c c output: c y -- transform of x c c reference: c Halko, Martinsson, Tropp, "Finding structure with randomness: c probabilistic algorithms for constructing approximate c matrix decompositions," SIAM Review, 53 (2): 217-288, c 2011. c implicit none integer m,iw,n,k complex*16 w(17*m+70),x(m),y(n) c c c Apply Rokhlin's random transformation to x, obtaining c w(16*m+71 : 17*m+70). c iw = w(3+m+n) call idz_random_transf(x,w(16*m+70+1),w(iw)) c c c Subselect from w(16*m+71 : 17*m+70) to obtain y. c call idz_subselect(n,w(3),m,w(16*m+70+1),y) c c c Copy y into w(16*m+71 : 16*m+n+70). c do k = 1,n w(16*m+70+k) = y(k) enddo ! k c c c Fourier transform w(16*m+71 : 16*m+n+70). c call zfftf(n,w(16*m+70+1),w(4+m+n)) c c c Permute w(16*m+71 : 16*m+n+70) to obtain y. c call idz_permute(n,w(3+m),w(16*m+70+1),y) c c return end c c c c subroutine idz_sfrm(l,m,n,w,x,y) c c transforms x into y via a composition c of Rokhlin's random transform, random subselection, and an FFT. c In contrast to routine idz_frm, the present routine works best c when the length l of the transformed vector is known a priori. c c input: c l -- length of y; l must be less than or equal to n c m -- length of x c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m, as obtained c from the routine idz_frmi c w -- initialization array constructed by routine idz_sfrmi c x -- vector to be transformed c c output: c y -- transform of x c c _N.B._: l must be less than or equal to n. c c reference: c Halko, Martinsson, Tropp, "Finding structure with randomness: c probabilistic algorithms for constructing approximate c matrix decompositions," SIAM Review, 53 (2): 217-288, c 2011. c implicit none integer m,iw,n,l complex*16 w(21*m+70),x(m),y(l) c c c Apply Rokhlin's random transformation to x, obtaining c w(19*m+71 : 20*m+70). c iw = w(4+m+l) call idz_random_transf(x,w(19*m+70+1),w(iw)) c c c Subselect from w(19*m+71 : 20*m+70) to obtain c w(20*m+71 : 20*m+n+70). c call idz_subselect(n,w(4),m,w(19*m+70+1),w(20*m+70+1)) c c c Fourier transform w(20*m+71 : 20*m+n+70). c call idz_sfft(l,w(4+m),n,w(5+m+l),w(20*m+70+1)) c c c Copy the desired entries from w(20*m+71 : 20*m+n+70) c to y. c call idz_subselect(l,w(4+m),n,w(20*m+70+1),y) c c return end c c c c subroutine idz_permute(n,ind,x,y) c c copy the entries of x into y, rearranged according c to the permutation specified by ind. c c input: c n -- length of ind, x, and y c ind -- permutation of n objects c x -- vector to be permuted c c output: c y -- permutation of x c implicit none integer n,ind(n),k complex*16 x(n),y(n) c c do k = 1,n y(k) = x(ind(k)) enddo ! k c c return end c c c c subroutine idz_subselect(n,ind,m,x,y) c c copies into y the entries of x indicated by ind. c c input: c n -- number of entries of x to copy into y c ind -- indices of the entries in x to copy into y c m -- length of x c x -- vector whose entries are to be copied c c output: c y -- collection of entries of x specified by ind c implicit none integer n,ind(n),m,k complex*16 x(m),y(n) c c do k = 1,n y(k) = x(ind(k)) enddo ! k c c return end c c c c subroutine idz_frmi(m,n,w) c c initializes data for the routine idz_frm. c c input: c m -- length of the vector to be transformed c c output: c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m c w -- initialization array to be used by routine idz_frm c c c glossary for the fully initialized w: c c w(1) = m c w(2) = n c w(3:2+m) stores a permutation of m objects c w(3+m:2+m+n) stores a permutation of n objects c w(3+m+n) = address in w of the initialization array c for idz_random_transf c w(4+m+n:int(w(3+m+n))-1) stores the initialization array c for zfft c w(int(w(3+m+n)):16*m+70) stores the initialization array c for idz_random_transf c c c _N.B._: n is an output of the present routine; c this routine changes n. c c implicit none integer m,n,l,nsteps,keep,lw,ia complex*16 w(17*m+70) c c c Find the greatest integer less than or equal to m c which is a power of two. c call idz_poweroftwo(m,l,n) c c c Store m and n in w. c w(1) = m w(2) = n c c c Store random permutations of m and n objects in w. c call id_randperm(m,w(3)) call id_randperm(n,w(3+m)) c c c Store the address within w of the idz_random_transf_init c initialization data. c ia = 4+m+n+2*n+15 w(3+m+n) = ia c c c Store the initialization data for zfft in w. c call zffti(n,w(4+m+n)) c c c Store the initialization data for idz_random_transf_init in w. c nsteps = 3 call idz_random_transf_init(nsteps,m,w(ia),keep) c c c Calculate the total number of elements used in w. c lw = 3+m+n+2*n+15 + 3*nsteps*m+2*m+m/4+50 c if(16*m+70 .lt. lw) then call prinf('lw = *',lw,1) call prinf('16m+70 = *',16*m+70,1) stop endif c c return end c c c c subroutine idz_sfrmi(l,m,n,w) c c initializes data for the routine idz_sfrm. c c input: c l -- length of the transformed (output) vector c m -- length of the vector to be transformed c c output: c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m c w -- initialization array to be used by routine idz_sfrm c c c glossary for the fully initialized w: c c w(1) = m c w(2) = n c w(3) is unused c w(4:3+m) stores a permutation of m objects c w(4+m:3+m+l) stores the indices of the l outputs which idz_sfft c calculates c w(4+m+l) = address in w of the initialization array c for idz_random_transf c w(5+m+l:int(w(4+m+l))-1) stores the initialization array c for idz_sfft c w(int(w(4+m+l)):19*m+70) stores the initialization array c for idz_random_transf c c c _N.B._: n is an output of the present routine; c this routine changes n. c c implicit none integer l,m,n,idummy,nsteps,keep,lw,ia complex*16 w(21*m+70) c c c Find the greatest integer less than or equal to m c which is a power of two. c call idz_poweroftwo(m,idummy,n) c c c Store m and n in w. c w(1) = m w(2) = n w(3) = 0 c c c Store random permutations of m and n objects in w. c call id_randperm(m,w(4)) call id_randperm(n,w(4+m)) c c c Store the address within w of the idz_random_transf_init c initialization data. c ia = 5+m+l+2*l+15+3*n w(4+m+l) = ia c c c Store the initialization data for idz_sfft in w. c call idz_sffti(l,w(4+m),n,w(5+m+l)) c c c Store the initialization data for idz_random_transf_init in w. c nsteps = 3 call idz_random_transf_init(nsteps,m,w(ia),keep) c c c Calculate the total number of elements used in w. c lw = 4+m+l+2*l+15+3*n + 3*nsteps*m+2*m+m/4+50 c if(19*m+70 .lt. lw) then call prinf('lw = *',lw,1) call prinf('19m+70 = *',19*m+70,1) stop endif c c return end c c c c subroutine idz_poweroftwo(m,l,n) c c computes l = floor(log_2(m)) and n = 2**l. c c input: c m -- integer whose log_2 is to be taken c c output: c l -- floor(log_2(m)) c n -- 2**l c implicit none integer l,m,n c c l = 0 n = 1 c 1000 continue l = l+1 n = n*2 if(n .le. m) goto 1000 c l = l-1 n = n/2 c c return end
bsd-3-clause
jakevdp/scipy
scipy/linalg/src/id_dist/src/idz_frm.f
133
10151
c this file contains the following user-callable routines: c c c routine idz_frm transforms a vector via a composition c of Rokhlin's random transform, random subselection, and an FFT. c c routine idz_sfrm transforms a vector into a vector c of specified length via a composition c of Rokhlin's random transform, random subselection, and an FFT. c c routine idz_frmi initializes routine idz_frm. c c routine idz_sfrmi initializes routine idz_sfrm. c c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c c c subroutine idz_frm(m,n,w,x,y) c c transforms x into y via a composition c of Rokhlin's random transform, random subselection, and an FFT. c In contrast to routine idz_sfrm, the present routine works best c when the length of the transformed vector is the integer n c output by routine idz_frmi, or when the length c is not specified, but instead determined a posteriori c using the output of the present routine. The transformed vector c output by the present routine is randomly permuted. c c input: c m -- length of x c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m, as obtained c from the routine idz_frmi; n is the length of y c w -- initialization array constructed by routine idz_frmi c x -- vector to be transformed c c output: c y -- transform of x c c reference: c Halko, Martinsson, Tropp, "Finding structure with randomness: c probabilistic algorithms for constructing approximate c matrix decompositions," SIAM Review, 53 (2): 217-288, c 2011. c implicit none integer m,iw,n,k complex*16 w(17*m+70),x(m),y(n) c c c Apply Rokhlin's random transformation to x, obtaining c w(16*m+71 : 17*m+70). c iw = w(3+m+n) call idz_random_transf(x,w(16*m+70+1),w(iw)) c c c Subselect from w(16*m+71 : 17*m+70) to obtain y. c call idz_subselect(n,w(3),m,w(16*m+70+1),y) c c c Copy y into w(16*m+71 : 16*m+n+70). c do k = 1,n w(16*m+70+k) = y(k) enddo ! k c c c Fourier transform w(16*m+71 : 16*m+n+70). c call zfftf(n,w(16*m+70+1),w(4+m+n)) c c c Permute w(16*m+71 : 16*m+n+70) to obtain y. c call idz_permute(n,w(3+m),w(16*m+70+1),y) c c return end c c c c subroutine idz_sfrm(l,m,n,w,x,y) c c transforms x into y via a composition c of Rokhlin's random transform, random subselection, and an FFT. c In contrast to routine idz_frm, the present routine works best c when the length l of the transformed vector is known a priori. c c input: c l -- length of y; l must be less than or equal to n c m -- length of x c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m, as obtained c from the routine idz_frmi c w -- initialization array constructed by routine idz_sfrmi c x -- vector to be transformed c c output: c y -- transform of x c c _N.B._: l must be less than or equal to n. c c reference: c Halko, Martinsson, Tropp, "Finding structure with randomness: c probabilistic algorithms for constructing approximate c matrix decompositions," SIAM Review, 53 (2): 217-288, c 2011. c implicit none integer m,iw,n,l complex*16 w(21*m+70),x(m),y(l) c c c Apply Rokhlin's random transformation to x, obtaining c w(19*m+71 : 20*m+70). c iw = w(4+m+l) call idz_random_transf(x,w(19*m+70+1),w(iw)) c c c Subselect from w(19*m+71 : 20*m+70) to obtain c w(20*m+71 : 20*m+n+70). c call idz_subselect(n,w(4),m,w(19*m+70+1),w(20*m+70+1)) c c c Fourier transform w(20*m+71 : 20*m+n+70). c call idz_sfft(l,w(4+m),n,w(5+m+l),w(20*m+70+1)) c c c Copy the desired entries from w(20*m+71 : 20*m+n+70) c to y. c call idz_subselect(l,w(4+m),n,w(20*m+70+1),y) c c return end c c c c subroutine idz_permute(n,ind,x,y) c c copy the entries of x into y, rearranged according c to the permutation specified by ind. c c input: c n -- length of ind, x, and y c ind -- permutation of n objects c x -- vector to be permuted c c output: c y -- permutation of x c implicit none integer n,ind(n),k complex*16 x(n),y(n) c c do k = 1,n y(k) = x(ind(k)) enddo ! k c c return end c c c c subroutine idz_subselect(n,ind,m,x,y) c c copies into y the entries of x indicated by ind. c c input: c n -- number of entries of x to copy into y c ind -- indices of the entries in x to copy into y c m -- length of x c x -- vector whose entries are to be copied c c output: c y -- collection of entries of x specified by ind c implicit none integer n,ind(n),m,k complex*16 x(m),y(n) c c do k = 1,n y(k) = x(ind(k)) enddo ! k c c return end c c c c subroutine idz_frmi(m,n,w) c c initializes data for the routine idz_frm. c c input: c m -- length of the vector to be transformed c c output: c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m c w -- initialization array to be used by routine idz_frm c c c glossary for the fully initialized w: c c w(1) = m c w(2) = n c w(3:2+m) stores a permutation of m objects c w(3+m:2+m+n) stores a permutation of n objects c w(3+m+n) = address in w of the initialization array c for idz_random_transf c w(4+m+n:int(w(3+m+n))-1) stores the initialization array c for zfft c w(int(w(3+m+n)):16*m+70) stores the initialization array c for idz_random_transf c c c _N.B._: n is an output of the present routine; c this routine changes n. c c implicit none integer m,n,l,nsteps,keep,lw,ia complex*16 w(17*m+70) c c c Find the greatest integer less than or equal to m c which is a power of two. c call idz_poweroftwo(m,l,n) c c c Store m and n in w. c w(1) = m w(2) = n c c c Store random permutations of m and n objects in w. c call id_randperm(m,w(3)) call id_randperm(n,w(3+m)) c c c Store the address within w of the idz_random_transf_init c initialization data. c ia = 4+m+n+2*n+15 w(3+m+n) = ia c c c Store the initialization data for zfft in w. c call zffti(n,w(4+m+n)) c c c Store the initialization data for idz_random_transf_init in w. c nsteps = 3 call idz_random_transf_init(nsteps,m,w(ia),keep) c c c Calculate the total number of elements used in w. c lw = 3+m+n+2*n+15 + 3*nsteps*m+2*m+m/4+50 c if(16*m+70 .lt. lw) then call prinf('lw = *',lw,1) call prinf('16m+70 = *',16*m+70,1) stop endif c c return end c c c c subroutine idz_sfrmi(l,m,n,w) c c initializes data for the routine idz_sfrm. c c input: c l -- length of the transformed (output) vector c m -- length of the vector to be transformed c c output: c n -- greatest integer expressible as a positive integer power c of 2 that is less than or equal to m c w -- initialization array to be used by routine idz_sfrm c c c glossary for the fully initialized w: c c w(1) = m c w(2) = n c w(3) is unused c w(4:3+m) stores a permutation of m objects c w(4+m:3+m+l) stores the indices of the l outputs which idz_sfft c calculates c w(4+m+l) = address in w of the initialization array c for idz_random_transf c w(5+m+l:int(w(4+m+l))-1) stores the initialization array c for idz_sfft c w(int(w(4+m+l)):19*m+70) stores the initialization array c for idz_random_transf c c c _N.B._: n is an output of the present routine; c this routine changes n. c c implicit none integer l,m,n,idummy,nsteps,keep,lw,ia complex*16 w(21*m+70) c c c Find the greatest integer less than or equal to m c which is a power of two. c call idz_poweroftwo(m,idummy,n) c c c Store m and n in w. c w(1) = m w(2) = n w(3) = 0 c c c Store random permutations of m and n objects in w. c call id_randperm(m,w(4)) call id_randperm(n,w(4+m)) c c c Store the address within w of the idz_random_transf_init c initialization data. c ia = 5+m+l+2*l+15+3*n w(4+m+l) = ia c c c Store the initialization data for idz_sfft in w. c call idz_sffti(l,w(4+m),n,w(5+m+l)) c c c Store the initialization data for idz_random_transf_init in w. c nsteps = 3 call idz_random_transf_init(nsteps,m,w(ia),keep) c c c Calculate the total number of elements used in w. c lw = 4+m+l+2*l+15+3*n + 3*nsteps*m+2*m+m/4+50 c if(19*m+70 .lt. lw) then call prinf('lw = *',lw,1) call prinf('19m+70 = *',19*m+70,1) stop endif c c return end c c c c subroutine idz_poweroftwo(m,l,n) c c computes l = floor(log_2(m)) and n = 2**l. c c input: c m -- integer whose log_2 is to be taken c c output: c l -- floor(log_2(m)) c n -- 2**l c implicit none integer l,m,n c c l = 0 n = 1 c 1000 continue l = l+1 n = n*2 if(n .le. m) goto 1000 c l = l-1 n = n/2 c c return end
bsd-3-clause
buaasun/grappa
applications/NPB/SERIAL/BT/initialize.f
5
7585
c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine initialize c--------------------------------------------------------------------- c--------------------------------------------------------------------- c--------------------------------------------------------------------- c This subroutine initializes the field variable u using c tri-linear transfinite interpolation of the boundary values c--------------------------------------------------------------------- include 'header.h' integer i, j, k, m, ix, iy, iz double precision xi, eta, zeta, Pface(5,3,2), Pxi, Peta, > Pzeta, temp(5) c--------------------------------------------------------------------- c Later (in compute_rhs) we compute 1/u for every element. A few of c the corner elements are not used, but it convenient (and faster) c to compute the whole thing with a simple loop. Make sure those c values are nonzero by initializing the whole thing here. c--------------------------------------------------------------------- do k = 0, grid_points(3)-1 do j = 0, grid_points(2)-1 do i = 0, grid_points(1)-1 do m = 1, 5 u(m,i,j,k) = 1.0 end do end do end do end do c--------------------------------------------------------------------- c--------------------------------------------------------------------- c first store the "interpolated" values everywhere on the grid c--------------------------------------------------------------------- do k = 0, grid_points(3)-1 zeta = dble(k) * dnzm1 do j = 0, grid_points(2)-1 eta = dble(j) * dnym1 do i = 0, grid_points(1)-1 xi = dble(i) * dnxm1 do ix = 1, 2 call exact_solution(dble(ix-1), eta, zeta, > Pface(1,1,ix)) enddo do iy = 1, 2 call exact_solution(xi, dble(iy-1) , zeta, > Pface(1,2,iy)) enddo do iz = 1, 2 call exact_solution(xi, eta, dble(iz-1), > Pface(1,3,iz)) enddo do m = 1, 5 Pxi = xi * Pface(m,1,2) + > (1.0d0-xi) * Pface(m,1,1) Peta = eta * Pface(m,2,2) + > (1.0d0-eta) * Pface(m,2,1) Pzeta = zeta * Pface(m,3,2) + > (1.0d0-zeta) * Pface(m,3,1) u(m,i,j,k) = Pxi + Peta + Pzeta - > Pxi*Peta - Pxi*Pzeta - Peta*Pzeta + > Pxi*Peta*Pzeta enddo enddo enddo enddo c--------------------------------------------------------------------- c now store the exact values on the boundaries c--------------------------------------------------------------------- c--------------------------------------------------------------------- c west face c--------------------------------------------------------------------- i = 0 xi = 0.0d0 do k = 0, grid_points(3)-1 zeta = dble(k) * dnzm1 do j = 0, grid_points(2)-1 eta = dble(j) * dnym1 call exact_solution(xi, eta, zeta, temp) do m = 1, 5 u(m,i,j,k) = temp(m) enddo enddo enddo c--------------------------------------------------------------------- c east face c--------------------------------------------------------------------- i = grid_points(1)-1 xi = 1.0d0 do k = 0, grid_points(3)-1 zeta = dble(k) * dnzm1 do j = 0, grid_points(2)-1 eta = dble(j) * dnym1 call exact_solution(xi, eta, zeta, temp) do m = 1, 5 u(m,i,j,k) = temp(m) enddo enddo enddo c--------------------------------------------------------------------- c south face c--------------------------------------------------------------------- j = 0 eta = 0.0d0 do k = 0, grid_points(3)-1 zeta = dble(k) * dnzm1 do i = 0, grid_points(1)-1 xi = dble(i) * dnxm1 call exact_solution(xi, eta, zeta, temp) do m = 1, 5 u(m,i,j,k) = temp(m) enddo enddo enddo c--------------------------------------------------------------------- c north face c--------------------------------------------------------------------- j = grid_points(2)-1 eta = 1.0d0 do k = 0, grid_points(3)-1 zeta = dble(k) * dnzm1 do i = 0, grid_points(1)-1 xi = dble(i) * dnxm1 call exact_solution(xi, eta, zeta, temp) do m = 1, 5 u(m,i,j,k) = temp(m) enddo enddo enddo c--------------------------------------------------------------------- c bottom face c--------------------------------------------------------------------- k = 0 zeta = 0.0d0 do j = 0, grid_points(2)-1 eta = dble(j) * dnym1 do i =0, grid_points(1)-1 xi = dble(i) *dnxm1 call exact_solution(xi, eta, zeta, temp) do m = 1, 5 u(m,i,j,k) = temp(m) enddo enddo enddo c--------------------------------------------------------------------- c top face c--------------------------------------------------------------------- k = grid_points(3)-1 zeta = 1.0d0 do j = 0, grid_points(2)-1 eta = dble(j) * dnym1 do i =0, grid_points(1)-1 xi = dble(i) * dnxm1 call exact_solution(xi, eta, zeta, temp) do m = 1, 5 u(m,i,j,k) = temp(m) enddo enddo enddo return end c--------------------------------------------------------------------- c--------------------------------------------------------------------- subroutine lhsinit(lhs, size) implicit none integer size double precision lhs(5,5,3,0:size) c--------------------------------------------------------------------- c--------------------------------------------------------------------- integer i, m, n i = size c--------------------------------------------------------------------- c zero the whole left hand side for starters c--------------------------------------------------------------------- do m = 1, 5 do n = 1, 5 lhs(m,n,1,0) = 0.0d0 lhs(m,n,2,0) = 0.0d0 lhs(m,n,3,0) = 0.0d0 lhs(m,n,1,i) = 0.0d0 lhs(m,n,2,i) = 0.0d0 lhs(m,n,3,i) = 0.0d0 enddo enddo c--------------------------------------------------------------------- c next, set all diagonal values to 1. This is overkill, but convenient c--------------------------------------------------------------------- do m = 1, 5 lhs(m,m,2,0) = 1.0d0 lhs(m,m,2,i) = 1.0d0 enddo return end
bsd-3-clause
nvarini/espresso_iohpc
CPV/src/pres_ai_mod.f90
21
2696
! ! Copyright (C) 2002 FPMD 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 . ! !=----------------------------------------------------------------------------=! MODULE pres_ai_mod !=----------------------------------------------------------------------------=! use kinds, only: dp use parameters, only: nsx IMPLICIT NONE ! SAVE ! logical :: abivol, abisur, pvar, fill_vac, scale_at, t_gauss, jellium logical :: cntr(nsx) real(dp), allocatable:: rho_gaus(:), posv(:,:), v_vol(:), f_vol(:,:,:) real(dp) :: P_ext, P_in, P_fin, rho_thr, step_rad(nsx) real(dp) :: Surf_t, dthr, volclu, surfclu, n_ele, nelect real(dp) :: R_j, e_j, h_j real(dp) :: stress_vol(3,3) real(dp) :: delta_eps, delta_sigma real(dp) :: xc0(500), weight(500) integer :: n_cntr, axis CONTAINS !---------------------------------------------------------------------- SUBROUTINE pres_ai_init (abivol_, abisur_, pvar_, fill_vac_, & scale_at_, t_gauss_, jellium_, cntr_, & P_ext_, P_in_, P_fin_, rho_thr_, & step_rad_, Surf_t_, dthr_, R_j_, h_j_, & delta_eps_, delta_sigma_, n_cntr_, axis_) !---------------------------------------------------------------------- ! USE constants, ONLY : au_gpa ! IMPLICIT NONE ! LOGICAL :: abivol_, abisur_, pvar_, fill_vac_, scale_at_, & t_gauss_, jellium_, cntr_(nsx) REAL(dp) :: P_ext_, P_in_, P_fin_, rho_thr_, step_rad_(nsx), & Surf_t_, dthr_, R_j_, h_j_, delta_eps_, delta_sigma_ INTEGER :: n_cntr_, axis_ ! ! Copy variables read from input into module ! abivol = abivol_ abisur = abisur_ pvar = pvar_ fill_vac = fill_vac_ scale_at = scale_at_ t_gauss = t_gauss_ cntr_(:) = cntr_(:) jellium = .false. ! provvisorio rho_thr = rho_thr_ step_rad(:) = step_rad_(:) Surf_t = Surf_t_ dthr = dthr_ R_j = R_j_ h_j = h_j_ delta_eps = delta_eps_ delta_sigma = delta_sigma_ n_cntr = n_cntr_ axis = axis_ ! ! Correct (a.u.) units to pressure ! P_ext = P_ext_ / au_gpa P_in = P_in_ / au_gpa P_fin = P_fin_ / au_gpa if (pvar) P_ext = P_in ! END SUBROUTINE pres_ai_init !=----------------------------------------------------------------------------=! END MODULE pres_ai_mod !=----------------------------------------------------------------------------=!
gpl-2.0
hlokavarapu/calypso
src/Fortran_libraries/MHD_src/sph_MHD/set_sph_scalar_mat_bc.f90
3
7710
!>@file set_sph_scalar_mat_bc.f90 !!@brief module set_sph_scalar_mat_bc !! !!@author H. Matsui !!@date Programmed in Oct., 2009 ! !>@brief Construct matrix for scalar fields at boundaries !! !!@verbatim !! subroutine set_fix_fld_icb_poisson_mat(nri, jmax, kr_in, & !! & evo_mat) !! subroutine add_fix_flux_icb_poisson_mat(nri, jmax, kr_in, & !! & r_ICB, fdm2_fix_dr_ICB, coef_p, evo_mat) !! subroutine add_icb_scalar_poisson_mat(nri, jmax, kr_in, & !! & r_ICB, fdm2_fix_dr_ICB, coef_p, p_mat) !! !! subroutine set_fix_fld_cmb_poisson_mat(nri, jmax, kr_out, & !! & evo_mat) !! subroutine add_fix_flux_cmb_poisson_mat(nri, jmax, kr_out, & !! & r_CMB, fdm2_fix_dr_CMB, coef_p, evo_mat) !! subroutine add_cmb_scalar_poisson_mat(nri, jmax, kr_out, r_CMB, & !! & fdm2_fix_dr_CMB, coef_p, p_mat) !!@endverbatim !! !!@n @param nri Number of radial points !!@n @param jmax Number of spherical harmonics modes !!@n @param j0 Local harmonics mode address for l = m = 0 !!@n @param kr_in Radial ID for inner boundary !!@n @param kr_out Radial ID for outer boundary !!@n @param r_ICB(0:2) Radius at ICB !!@n @param r_CMB(0:2) Radius at CMB !!@n @param coef_imp Coefficient for contribution of implicit term !!@n @param coef_d Coefficient of diffusiotn term !!@n @param fdm2_fix_dr_ICB(-1:1,3) !! Matrix to evaluate field at ICB with fixed radial derivative !!@n @param fdm2_fix_dr_CMB(-1:1,3) !! Matrix to evaluate field at CMB with fixed radial derivative !! !!@n @param evo_mat(3,nri,jmax) Band matrix for time evolution ! module set_sph_scalar_mat_bc ! use m_precision ! use m_constants use m_t_int_parameter use m_spheric_parameter use m_schmidt_poly_on_rtm use m_radial_matrices_sph ! implicit none ! ! ----------------------------------------------------------------------- ! contains ! ! ----------------------------------------------------------------------- ! subroutine set_fix_fld_icb_poisson_mat(nri, jmax, kr_in, & & evo_mat) ! integer(kind = kint), intent(in) :: jmax, nri, kr_in real(kind = kreal), intent(inout) :: evo_mat(3,nri,jmax) ! integer(kind = kint) :: j ! ! do j = 1, jmax ! evo_mat(3,kr_in-1,j) = zero evo_mat(2,kr_in, j) = one evo_mat(1,kr_in+1,j) = zero end do ! end subroutine set_fix_fld_icb_poisson_mat ! ! ----------------------------------------------------------------------- ! subroutine add_fix_flux_icb_poisson_mat(nri, jmax, kr_in, & & r_ICB, fdm2_fix_dr_ICB, coef_p, evo_mat) ! integer(kind = kint), intent(in) :: jmax, nri, kr_in real(kind = kreal), intent(in) :: coef_p real(kind = kreal), intent(in) :: r_ICB(0:2) real(kind = kreal), intent(in) :: fdm2_fix_dr_ICB(-1:1,3) ! real(kind = kreal), intent(inout) :: evo_mat(3,nri,jmax) ! integer(kind = kint) :: j ! ! do j = 1, jmax ! evo_mat(3,kr_in-1,j) = evo_mat(3,kr_in-1,j) & ! & - coef_p * fdm2_fix_dr_ICB(-1,3) evo_mat(2,kr_in, j) = evo_mat(2,kr_in, j) & & - coef_p * (fdm2_fix_dr_ICB( 0,3) & & - g_sph_rj(j,3)*r_ICB(2)) evo_mat(1,kr_in+1,j) = evo_mat(1,kr_in+1,j) & & - coef_p * fdm2_fix_dr_ICB( 1,3) end do ! end subroutine add_fix_flux_icb_poisson_mat ! ! ----------------------------------------------------------------------- ! subroutine add_icb_scalar_poisson_mat(nri, jmax, kr_in, & & r_ICB, fdm2_fix_dr_ICB, coef_p, p_mat) ! integer(kind = kint), intent(in) :: nri, jmax, kr_in real(kind = kreal), intent(in) :: r_ICB(0:2) real(kind = kreal), intent(in) :: fdm2_fix_dr_ICB(-1:1,3) real(kind = kreal), intent(in) :: coef_p ! real(kind = kreal), intent(inout) :: p_mat(3,nri,jmax) ! integer(kind = kint) :: j ! ! do j = 1, jmax p_mat(2,kr_in, j) = p_mat(2,kr_in, j) & & - coef_p * (fdm2_fix_dr_ICB( 0,3) & & + two * r_ICB(1) * fdm2_fix_dr_ICB( 0,2) & & - g_sph_rj(j,3)*r_ICB(2)) p_mat(1,kr_in+1,j) = p_mat(1,kr_in+1,j) & & - coef_p * (fdm2_fix_dr_ICB( 1,3) & & + two * r_ICB(1) * fdm2_fix_dr_ICB( 1,2) ) end do ! end subroutine add_icb_scalar_poisson_mat ! ! ----------------------------------------------------------------------- ! ----------------------------------------------------------------------- ! subroutine set_fix_fld_cmb_poisson_mat(nri, jmax, kr_out, & & evo_mat) ! integer(kind = kint), intent(in) :: jmax, nri, kr_out real(kind = kreal), intent(inout) :: evo_mat(3,nri,jmax) ! integer(kind = kint) :: j ! ! do j = 1, jmax evo_mat(3,kr_out-1,j) = zero evo_mat(2,kr_out, j) = one ! evo_mat(1,kr_out+1,j) = zero end do ! end subroutine set_fix_fld_cmb_poisson_mat ! ! ----------------------------------------------------------------------- ! subroutine add_fix_flux_cmb_poisson_mat(nri, jmax, kr_out, & & r_CMB, fdm2_fix_dr_CMB, coef_p, evo_mat) ! integer(kind = kint), intent(in) :: jmax, nri, kr_out real(kind = kreal), intent(in) :: coef_p real(kind = kreal), intent(in) :: r_CMB(0:2) real(kind = kreal), intent(in) :: fdm2_fix_dr_CMB(-1:1,3) ! real(kind = kreal), intent(inout) :: evo_mat(3,nri,jmax) ! integer(kind = kint) :: j ! ! do j = 1, jmax evo_mat(3,kr_out-1,j) = evo_mat(3,kr_out-1,j) & & - coef_p * fdm2_fix_dr_CMB(-1,3) evo_mat(2,kr_out, j) = evo_mat(2,kr_out, j) & & - coef_p * (fdm2_fix_dr_CMB( 0,3) & & - g_sph_rj(j,3)*r_CMB(2)) ! evo_mat(1,kr_out+1,j) = evo_mat(1,kr_out+1,j) & ! - coef_p * fdm2_fix_dr_CMB(1,3) end do ! end subroutine add_fix_flux_cmb_poisson_mat ! ! ----------------------------------------------------------------------- ! subroutine add_cmb_scalar_poisson_mat(nri, jmax, kr_out, r_CMB, & & fdm2_fix_dr_CMB, coef_p, p_mat) ! integer(kind = kint), intent(in) :: nri, jmax, kr_out real(kind = kreal), intent(in) :: r_CMB(0:2) real(kind = kreal), intent(in) :: fdm2_fix_dr_CMB(-1:1,3) real(kind = kreal), intent(in) :: coef_p ! real(kind = kreal), intent(inout) :: p_mat(3,nri,jmax) ! integer(kind = kint) :: j ! ! do j = 1, jmax p_mat(3,kr_out-1,j) = p_mat(3,kr_out-1,j) & & - coef_p * (fdm2_fix_dr_CMB(-1,3) & & + two*r_CMB(1) * fdm2_fix_dr_CMB(-1,2)) p_mat(2,kr_out, j) = p_mat(2,kr_out, j) & & - coef_p * (fdm2_fix_dr_CMB( 0,3) & & + two*r_CMB(1) * fdm2_fix_dr_CMB( 0,2) & & - g_sph_rj(j,3)*r_CMB(2)) end do ! end subroutine add_cmb_scalar_poisson_mat ! ! ----------------------------------------------------------------------- ! end module set_sph_scalar_mat_bc
gpl-3.0
glotter/psims
models/pdssat45/source/csm45/Source045/PHOTO.f90
1
23010
C======================================================================= C PHOTO, Subroutine, K.J.Boote, J.W.Jones, G. Hoogenboom C Compute daily photosynthetic using canopy (C) method. C----------------------------------------------------------------------- C REVISION HISTORY C 01/01/1989 KJB Written. C 06/02/1993 NBP Made into subroutine. C 02/11/1994 NBP Corrected dimension (15) for XPGSLW, YPGSLW C 04/24/1994 NBP Replaced TAIRHR, TAVG with TGRO, TGROAV. C 09/25/1995 KJB Light interception for ET the same for canopy and leaf C models C 11/11/1999 CHP Modified for modular format C 01/13/2000 NBP Added SWFAC effect on PG C 06/11/2002 GH Modified for Y2K C 08/12/2003 CHP Added I/O error checking C 03/24/2004 CHP Added P stress based on Bostick model C 07/30/2004 CHP Added KC_SLOPE to SPE file and KC_ECO to ECO file. ! 06/11/2007 CHP PStres1 affects photosynthesis !----------------------------------------------------------------------- ! Called from: Main ! Calls: PHOTIP C======================================================================= SUBROUTINE PHOTO(CONTROL, & BETN, CO2, DXR57, EXCESS, KCAN, KC_SLOPE, !Input & NR5, PAR, PStres1, SLPF, RNITP, SLAAD, !Input & SWFAC, TDAY, XHLAI, XPOD, !Input & AGEFAC, PG) !Output !----------------------------------------------------------------------- USE ModuleDefs !Definitions of constructed variable types, ! which contain control information, soil ! parameters, hourly weather data. IMPLICIT NONE SAVE CHARACTER*3 TYPPGN, TYPPGT CHARACTER*30 FILEIO INTEGER DYNAMIC INTEGER DAS, NR5 REAL AGEFAC, AGEFCC, AGEREF, A0, BETN, CCEFF, CCK, CCMAX, & CCMP, CO2, COLDSTR, CUMSTR, CURV, DXR57, EXCESS, & KCAN, KCANR, KC_SLOPE, LMXSTD, LNREF, PAR, PARMAX, PG, PGFAC, & SLPF, PGLFMX, PGREF, PGSLW, PHTHRS10, PHTMAX, PRATIO, & PTSMAX, RNITP, ROWSPC, SLAAD, SLW, SPACNG, SWFAC, & TABEX, TDAY, TPGFAC, XHLAI, XPOD REAL E_FAC REAL FNPGN(4), FNPGT(4) REAL XPGSLW(15), YPGSLW(15) ! Added with P module REAL PStres1 !----------------------------------------------------------------------- ! Define constructed variable types based on definitions in ! ModuleDefs.for. ! The variable "CONTROL" is of type "ControlType". TYPE (ControlType) CONTROL ! Transfer values from constructed data types into local variables. DAS = CONTROL % DAS DYNAMIC = CONTROL % DYNAMIC FILEIO = CONTROL % FILEIO C*********************************************************************** C*********************************************************************** C Run Initialization - Called once per simulation C*********************************************************************** IF (DYNAMIC .EQ. RUNINIT) THEN C----------------------------------------------------------------------- CALL PHOTIP(FILEIO, & CCEFF, CCMAX, CCMP, FNPGN, FNPGT, LMXSTD, LNREF, PARMAX, & PGREF, PHTHRS10, PHTMAX, ROWSPC, TYPPGN, TYPPGT, XPGSLW, YPGSLW) C----------------------------------------------------------------------- C Adjust canopy photosynthesis for GENETIC input value of C maximum leaf photosyntheses (LMXSTD). Exponential curve from C from the hedgerow photosynthesis model (Boote et al, 199?). C----------------------------------------------------------------------- IF (PGREF .GT. 0.) THEN PGLFMX = (1. - EXP(-1.6 * LMXSTD)) / (1. - EXP(-1.6 * PGREF)) ELSE PGLFMX = 1.0 ENDIF C*********************************************************************** C*********************************************************************** C Seasonal initialization - run once per season C*********************************************************************** ELSEIF (DYNAMIC .EQ. SEASINIT) THEN C----------------------------------------------------------------------- AGEFAC = 1.0 CUMSTR = 0.0 COLDSTR = 0.0 PG = 0.0 C*********************************************************************** C*********************************************************************** C Daily rate calculations C*********************************************************************** ELSEIF (DYNAMIC .EQ. RATE) THEN C----------------------------------------------------------------------- C Calculate maximum photosynthesis as function of PAR, g CH2O/m2 C----------------------------------------------------------------------- PTSMAX = PHTMAX * (1.0 - EXP(-(1.0 / PARMAX) * PAR)) C----------------------------------------------------------------------- C Calculate reduction in photosynthesis due to incomplete canopy. C----------------------------------------------------------------------- IF (BETN .LE. ROWSPC) THEN SPACNG = BETN / ROWSPC ELSE SPACNG = ROWSPC / BETN ENDIF !chp per CDM: KCANR = KCAN - (1. - SPACNG) * 0.1 KCANR = KCAN - (1. - SPACNG) * KC_SLOPE PGFAC = 1. - EXP(-KCANR * XHLAI) C----------------------------------------------------------------------- C Compute reduction in PG based on the average daylight temperature. C----------------------------------------------------------------------- TPGFAC = CURV(TYPPGT,FNPGT(1),FNPGT(2),FNPGT(3),FNPGT(4),TDAY) C----------------------------------------------------------------------- C Compute reduction in PG as a function of leaf N concentration. C----------------------------------------------------------------------- AGEFAC = CURV(TYPPGN,FNPGN(1),FNPGN(2),FNPGN(3),FNPGN(4),RNITP) AGEREF = CURV(TYPPGN,FNPGN(1),FNPGN(2),FNPGN(3),FNPGN(4),LNREF) AGEFAC = AGEFAC / AGEREF C----------------------------------------------------------------------- C 9/24/95 KJB,JWJ Decrease sensitivity of canopy PG to N function C to mimic behavior of leaf version. AGEFAC corresponds to leaf C PG vs. leaf N. Function does not act strongly on QE, thus, we C need to scale effect back on daily canopy version. C----------------------------------------------------------------------- AGEFCC = (1.0 - EXP(-2.0 * AGEFAC)) / (1. - EXP(-2.0 * 1.0)) C----------------------------------------------------------------------- C Compute canopy pg response to changes in specific leaf weight. C (Dornhoff and Shibles, 197?). C----------------------------------------------------------------------- IF (SLAAD .GT. 0.0) THEN SLW = 1. / SLAAD ELSE SLW = 0.0099 ENDIF PGSLW = TABEX(YPGSLW, XPGSLW, SLW, 10) C----------------------------------------------------------------------- C Adjust canopy photosynthesis for CO2 concentration assuming a C reference value of CO2 of 330 ppmv. C----------------------------------------------------------------------- CCK = CCEFF / CCMAX A0 = -CCMAX * (1. - EXP(-CCK * CCMP)) PRATIO = A0 + CCMAX * (1. - EXP(-CCK * CO2)) !*********************************************************************** !*********************************************************************** ! Daily integration !*********************************************************************** ! ELSEIF (DYNAMIC .EQ. INTEGR) THEN !----------------------------------------------------------------------- C Effect of daylength on daily gross PG, computer by KJB with C stand alone model, and used by Ernie Piper in his dissertation C see page 127 for the equation and conditions. Nornamized to C about 13 hours where the function is 1.00. Actually C normalized to a bit higher between 13 and 14 hours. C C DLFAC = 1.0 + 0.6128 - 0.01786*DAYL + 0.006875*DAYL*DAYL C & - 0.000247*DAYL*DAYL*DAYL C C Compute daily gross photosynthesis (g CH2O/m2/d) C----------------------------------------------------------------------- ! PG = PTSMAX * SLPF * PGFAC * TPGFAC * AGEFCC * PGSLW ! PG = PTSMAX * SLPF * PGFAC * TPGFAC * MIN(AGEFCC, PSTRES2) * ! & PGSLW * PRATIO * PGLFMX * SWFAC ! CHP 05/07/2004 ! AGEFCC can be > 1.0, so don't want to use minimum of ! PStres1 and AGEFCC. (PStres1 is always 1.0 or below). IF (AGEFCC .GE. 1.0) THEN E_FAC = AGEFCC * PStres1 ELSE E_FAC = MIN(AGEFCC, PStres1) ENDIF PG = PTSMAX * SLPF * PGFAC * TPGFAC * E_FAC * & PGSLW * PRATIO * PGLFMX * SWFAC !From WDB (chp 10/21/03): ! PG = PG * MIN(SWFAC ,2*(1-SATFAC) ) ! PGN = PGN * MIN(SWFAC,2*(1-SATFAC) ) C----------------------------------------------------------------------- C 9/27/95 KJB added cumulative water stress effect on PG after R5. C CUMULATIVE STRESS (WATER, TEMP) UPON PG CAPACITY. REDUCE FROM POT. C PG AFTER R5, WITH TWO FUNCTIONS. ONE DEPENDING ON THE PRIMARY C STRESS AND THE OTHER DEPENDING ON DISTANCE FROM R5 TO R7, DXR57 C INITIALLY THE STRESS IS SOIL WATER, BUT THIS MAY WORK FOR COLD TEMP. C 0.5 IS A SCALAR, POSSIBLY COULD GO HIGHER. MAX CUMSTR IS 0.2856 C FOR 78-RF, 0.1858 FOR EGLIN-88, THEN 0.528 FOR 84-RF. DECREASES C YIELD 77, 52, 50, AND 16 kg/ha FOR 78RF, EGLIN-88, 84RF, AND 81REP C MINOR DECREASE IN SEED SIZE. C 1/19/96, USING XPOD CAUSES IT TO BE LESS EFFECTIVE EARLY UNTIL FULL C PARTITIONING TO POD OCCURS (MAYBE JUST SEED, SEE XPOD CALCULATION). C 12/19/95 Changed scalar to 0.4. Too strong for peanut. Also, C 2/6/96 Changed scalar to 0.3. Too strong for 78RF too. Also, C the problem is really with seed growth potential, not as much on PG. C----------------------------------------------------------------------- C NEEDS A FUNCTION. SEE TMIN AND CHILL IN LEAF SUBROUTINE C AND THEN ADD A SCALAR? C COLDSTR = COLDSTR + DXR57 * (F(TMIN?)*XPOD / PHTHRS(10) C PG = PG * (1.0 - MAX(0.4*CUMSTR,1.0*COLDSTR)) C----------------------------------------------------------------------- IF (DAS .GT. NR5) THEN CUMSTR = CUMSTR + DXR57 * (1.0 - SWFAC) * XPOD / PHTHRS10 COLDSTR = 0.0 PG = PG * (1.0 - 0.3 * CUMSTR) ELSE CUMSTR = 0.0 COLDSTR = 0.0 ENDIF PG = PG * EXCESS !*********************************************************************** !*********************************************************************** ! END OF DYNAMIC IF CONSTRUCT !*********************************************************************** ENDIF !*********************************************************************** RETURN END !SUBROUTINE PHOTO C======================================================================= C PHOTIP, Subroutine, N.B. Pickering C Read input parameters for daily photosynthesis. C----------------------------------------------------------------------- C REVISION HISTORY C 09/25/99 Written. !----------------------------------------------------------------------- C Output: C Local : !----------------------------------------------------------------------- ! Called: PG ! Calls : None C======================================================================= SUBROUTINE PHOTIP(FILEIO, & CCEFF, CCMAX, CCMP, FNPGN, FNPGT, LMXSTD, LNREF, PARMAX, & PGREF, PHTHRS10, PHTMAX, ROWSPC, TYPPGN, TYPPGT, XPGSLW, YPGSLW) !----------------------------------------------------------------------- IMPLICIT NONE CHARACTER*1 BLANK CHARACTER*3 TYPPGN, TYPPGT CHARACTER*6 ERRKEY, SECTION CHARACTER*12 FILEC CHARACTER*30 FILEIO CHARACTER*80 PATHCR,CHAR CHARACTER*92 FILECC INTEGER LUNIO, LINC, LNUM, FOUND INTEGER II, PATHL, LUNCRP, ERR, ISECT REAL CCEFF, CCMAX, CCMP, LMXSTD, LNREF, & PARMAX, PGREF, PHTHRS10, PHTMAX, ROWSPC, XPGSLW(15) REAL FNPGN(4),FNPGT(4) REAL YPGSLW(15) PARAMETER (BLANK = ' ') PARAMETER (ERRKEY = 'PHOTIP') !----------------------------------------------------------------------- ! Open and read FILEIO !----------------------------------------------------------------------- CALL GETLUN('FILEIO', LUNIO) OPEN (LUNIO, FILE = FILEIO,STATUS = 'OLD',IOSTAT=ERR) IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILEIO,0) !----------------------------------------------------------------------- READ(LUNIO,50,IOSTAT=ERR) FILEC, PATHCR; LNUM = 7 50 FORMAT(//////,15X,A12,1X,A80) IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILEIO,LNUM) !----------------------------------------------------------------------- C Read Planting Details Section !----------------------------------------------------------------------- SECTION = '*PLANT' CALL FIND(LUNIO, SECTION, LINC, FOUND) ; LNUM = LNUM + LINC IF (FOUND .EQ. 0) THEN CALL ERROR(SECTION, 42, FILEIO, LNUM) ELSE READ(LUNIO,'(42X,F6.0)',IOSTAT=ERR) ROWSPC ; LNUM = LNUM + 1 IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILEIO,LNUM) ENDIF C CROPGRO uses ROWSPC as m ROWSPC = ROWSPC / 100. !----------------------------------------------------------------------- C Read Cultivars Section !----------------------------------------------------------------------- SECTION = '*CULTI' CALL FIND(LUNIO, SECTION, LINC, FOUND) ; LNUM = LNUM + LINC IF (FOUND .EQ. 0) THEN CALL ERROR(SECTION, 42, FILEIO, LNUM) ELSE READ(LUNIO,'(60X,F6.0,6X,F6.0)',IOSTAT=ERR) PHTHRS10, LMXSTD LNUM = LNUM + 1 IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILEIO,LNUM) ENDIF C----------------------------------------------------------------------- CLOSE (LUNIO) C----------------------------------------------------------------------- LNUM = 0 PATHL = INDEX(PATHCR,BLANK) IF (PATHL .LE. 1) THEN FILECC = FILEC ELSE FILECC = PATHCR(1:(PATHL-1)) // FILEC ENDIF CALL GETLUN('FILEC', LUNCRP) OPEN (LUNCRP,FILE = FILECC, STATUS = 'OLD',IOSTAT=ERR) IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,0) C----------------------------------------------------------------------- C READ PHOTOSYNTHESIS PARAMETERS ******************* C----------------------------------------------------------------------- 5 CONTINUE CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) IF (ISECT .EQ. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) IF (ISECT .EQ. 2) GO TO 5 READ(CHAR,'(5F6.2)',IOSTAT=ERR) PARMAX, PHTMAX IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) READ(CHAR,'(3F6.1)',IOSTAT=ERR) CCMP, CCMAX, CCEFF IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) READ(CHAR,'(4F6.0,3X,A3)',IOSTAT=ERR) (FNPGN(II),II=1,4), TYPPGN IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) READ(CHAR,'(4F6.0,3X,A3)',IOSTAT=ERR) (FNPGT(II),II=1,4), TYPPGT IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) READ(CHAR,'(18X,2F6.0)',IOSTAT=ERR) LNREF, PGREF IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) READ(CHAR,'(10F6.0)',IOSTAT=ERR) (XPGSLW(II),II = 1,10) IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) CALL IGNORE(LUNCRP,LNUM,ISECT,CHAR) READ(CHAR,'(10F6.0)',IOSTAT=ERR) (YPGSLW(II),II = 1,10) IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILECC,LNUM) C----------------------------------------------------------------------- CLOSE (LUNCRP) END !SUBROUTINE PHOTIP !======================================================================= ! Variable definitions for PHOTO and PHOTIP !======================================================================= ! AGEFAC Relative effect of current leaf N on canopy photosynthesis (0-1) ! (fraction) ! AGEFCC Effect of AGEFAC on photosynthesis ! AGEREF Reference value calculated at reference leaf N value to ! normalize the effect of N for different plant species ! BETN Spacing between plants along a row (m / plant) ! BLANK Blank character ! CCEFF Relative efficiency of CO2 assimilation used in equation to ! adjust canopy photosynthesis with CO2 concentrations ! CCK Computed exponent for relationship between CO2 and canopy ! photosynthesis (=CCEFF / CCMAX) ! CCMAX Maximum daily canopy photosynthesis relative to photosynthesis ! at a CO2 concentration of 330 vpm ! CCMP Canopy CO2 compensation point (CO2 at which daily PG is 0.0) ! CHAR Contains the contents of last record read ! CO2 Atmospheric carbon dioxide concentration (µmol[CO2] / mol[air]) ! COLDSTR Cold weather stress factor for photosynthesis (not currently ! used) ! CUMSTR Cumulative stress factor for photosynthesis after start of seed ! production ! CURV Function subroutine ! DAS Days after start of simulation (d) ! DXR57 Relative time between first seed (NR5) and physiological ! maturity (NR7) ! ERR Error code for file operation ! ERRKEY Subroutine name for error file ! EXCESS Factor based on excess PG used to affect tomorrow's PG ! calculation ! FILEC Filename for SPE file (e.g., SBGRO980.SPE) ! FILECC Path plus filename for species file (*.spe) ! FILEIO Filename for input file (e.g., IBSNAT35.INP) ! FNPGN(I) Critical leaf N concentration for function to reduce ! photosynthesis due to low leaf N levels (4 values for function ! CURV) ! FNPGT(I) Critical values of temperature for the functions to reduce ! canopy PG under non-optimal temperatures (in function CURV) ! FOUND Indicator that good data was read from file by subroutine FIND ! (0 - End-of-file encountered, 1 - NAME was found) ! ISECT Indicator of completion of IGNORE routine: 0 - End of file ! encountered, 1 - Found a good line to read, 2 - End of Section ! in file encountered denoted by * in column 1. ! KCAN Canopy light extinction coefficient for daily PAR, for ! equidistant plant spacing, modified when in-row and between ! row spacing are not equal ! KCANR Canopy light extinction coefficient, reduced for incomplete ! canopy ! LMXSTD Maximum leaf photosyntheses for standard cultivar ! LNREF Value of leaf N above which canopy PG is maximum (for standard ! cultivar) ! LNUM Current line number of input file ! LUNCRP Logical unit number for FILEC (*.spe file) ! LUNIO Logical unit number for FILEIO ! NR5 Day when 50% of plants have pods with beginning seeds (days) ! PAR Daily photosynthetically active radiation or photon flux density ! (moles[quanta]/m2-d) ! PARMAX Value of PAR at which photosynthesis is 63% of the maximum value ! (PHTMAX). Used in daily canopy photosynthesis calculations ! (moles[quanta]/m2-d) ! PATHCR Pathname for SPE file or FILEE. ! PATHL Number of characters in path name (path plus filename for FILEC) ! ! PG Daily gross photosynthesis (g[CH2O] / m2 / d) ! PGFAC Multiplier to compute daily canoy PG as a function of leaf area ! index (LAI) ! PGLFMX Multiplier for daily canopy photosynthesis to account for ! cultivar differences in leaf photosynthesis capabilities ! PGREF Reference value for leaf level photosynthesis used in canopy ! light response curve (µmol[CO2] / m2-s) ! PGSLW Relative effect of leaf thickness (SLW) on daily canopy PG ! PHTHRS10 Threshold time that must accumulate in phase 10 for the next ! stage to occur. Equivalent to PHTHRS(10) in Subroutine ! PHENOLOG. ! PHTMAX Maximum amount of CH20 which can be produced if ! photosynthetically active radiation (PAR) is very high (3 ! times PARMAX) and all other factors are optimal (g[CH2O]/m2-d) ! PRATIO Relative effect of CO2 on canopy PG, for multiplying by PG ! computed for 330 vpm ! PTSMAX Potential amount of CH20 which can be produced at the specified ! PAR for full canopy (LAI>8), all other factors optimal ! (g[CH2O]/m2-d) ! RNITP True nitrogen concentration in leaf tissue for photosynthesis ! reduction. (%) ! ROWSPC Row spacing (m) ! SECTION Section name in input file ! SLAAD Specific leaf area, excluding weight of C stored in leaves ! (cm2[leaf] / g[leaf]) ! SLPF Empirical multiplier to adjust daily canopy PG due to unknown ! soil or environmental factors that persist in a given location ! SLW Specific leaf weight (g[leaf] / m2[leaf]) ! SPACNG Ratio of distance between plants in a row to distance between ! rows (or vice versa - always < 1) ! SWFAC Effect of soil-water stress on photosynthesis, 1.0=no stress, ! 0.0=max stress ! TABEX Function subroutine - Lookup utility ! TDAY Average temperature during daylight hours (°C) ! TIMDIF Integer function which calculates the number of days between two ! Julian dates (da) ! TPGFAC Reduction in specific leaf area due to daytime temperature being ! less than optimal (0-1) ! TYPPGN Type of function for the leaf N effects on PG ! TYPPGT Character variable specifying the type of function to use for ! the relationship between temperature and PG (for use in ! function subroutine CURV) ! XHLAI Leaf area index (m2[leaf] / m2[ground]) ! XPGSLW(I) Array of SLW values for table look-up function, used with YPGSLW ! (g[leaf] / m2[leaf]) ! XPOD Growth partitioning to pods which slows node appearance ! (fraction) ! YPGSLW(I) Array of PG values corresponding to SLW values in array XPGSLW ! (g[CH2O] / m2 / d) !======================================================================= ! END SUBROUTINE PHOTO !=======================================================================
agpl-3.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/zhpev.f
29
8119
*> \brief <b> ZHPEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for OTHER matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZHPEV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhpev.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhpev.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhpev.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZHPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, RWORK, * INFO ) * * .. Scalar Arguments .. * CHARACTER JOBZ, UPLO * INTEGER INFO, LDZ, N * .. * .. Array Arguments .. * DOUBLE PRECISION RWORK( * ), W( * ) * COMPLEX*16 AP( * ), WORK( * ), Z( LDZ, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZHPEV computes all the eigenvalues and, optionally, eigenvectors of a *> complex Hermitian matrix in packed storage. *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBZ *> \verbatim *> JOBZ is CHARACTER*1 *> = 'N': Compute eigenvalues only; *> = 'V': Compute eigenvalues and eigenvectors. *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of A is stored; *> = 'L': Lower triangle of A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] AP *> \verbatim *> AP is COMPLEX*16 array, dimension (N*(N+1)/2) *> On entry, the upper or lower triangle of the Hermitian matrix *> A, packed columnwise in a linear array. The j-th column of A *> is stored in the array AP as follows: *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. *> *> On exit, AP is overwritten by values generated during the *> reduction to tridiagonal form. If UPLO = 'U', the diagonal *> and first superdiagonal of the tridiagonal matrix T overwrite *> the corresponding elements of A, and if UPLO = 'L', the *> diagonal and first subdiagonal of T overwrite the *> corresponding elements of A. *> \endverbatim *> *> \param[out] W *> \verbatim *> W is DOUBLE PRECISION array, dimension (N) *> If INFO = 0, the eigenvalues in ascending order. *> \endverbatim *> *> \param[out] Z *> \verbatim *> Z is COMPLEX*16 array, dimension (LDZ, N) *> If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal *> eigenvectors of the matrix A, with the i-th column of Z *> holding the eigenvector associated with W(i). *> If JOBZ = 'N', then Z is not referenced. *> \endverbatim *> *> \param[in] LDZ *> \verbatim *> LDZ is INTEGER *> The leading dimension of the array Z. LDZ >= 1, and if *> JOBZ = 'V', LDZ >= max(1,N). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX*16 array, dimension (max(1, 2*N-1)) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is DOUBLE PRECISION array, dimension (max(1, 3*N-2)) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit. *> < 0: if INFO = -i, the i-th argument had an illegal value. *> > 0: if INFO = i, the algorithm failed to converge; i *> off-diagonal elements of an intermediate tridiagonal *> form did not converge to zero. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex16OTHEReigen * * ===================================================================== SUBROUTINE ZHPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, RWORK, $ INFO ) * * -- LAPACK driver routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER JOBZ, UPLO INTEGER INFO, LDZ, N * .. * .. Array Arguments .. DOUBLE PRECISION RWORK( * ), W( * ) COMPLEX*16 AP( * ), WORK( * ), Z( LDZ, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 ) * .. * .. Local Scalars .. LOGICAL WANTZ INTEGER IINFO, IMAX, INDE, INDRWK, INDTAU, INDWRK, $ ISCALE DOUBLE PRECISION ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA, $ SMLNUM * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DLAMCH, ZLANHP EXTERNAL LSAME, DLAMCH, ZLANHP * .. * .. External Subroutines .. EXTERNAL DSCAL, DSTERF, XERBLA, ZDSCAL, ZHPTRD, ZSTEQR, $ ZUPGTR * .. * .. Intrinsic Functions .. INTRINSIC SQRT * .. * .. Executable Statements .. * * Test the input parameters. * WANTZ = LSAME( JOBZ, 'V' ) * INFO = 0 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN INFO = -1 ELSE IF( .NOT.( LSAME( UPLO, 'L' ) .OR. LSAME( UPLO, 'U' ) ) ) $ THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN INFO = -7 END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZHPEV ', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * IF( N.EQ.1 ) THEN W( 1 ) = AP( 1 ) RWORK( 1 ) = 1 IF( WANTZ ) $ Z( 1, 1 ) = ONE RETURN END IF * * Get machine constants. * SAFMIN = DLAMCH( 'Safe minimum' ) EPS = DLAMCH( 'Precision' ) SMLNUM = SAFMIN / EPS BIGNUM = ONE / SMLNUM RMIN = SQRT( SMLNUM ) RMAX = SQRT( BIGNUM ) * * Scale matrix to allowable range, if necessary. * ANRM = ZLANHP( 'M', UPLO, N, AP, RWORK ) ISCALE = 0 IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN ISCALE = 1 SIGMA = RMIN / ANRM ELSE IF( ANRM.GT.RMAX ) THEN ISCALE = 1 SIGMA = RMAX / ANRM END IF IF( ISCALE.EQ.1 ) THEN CALL ZDSCAL( ( N*( N+1 ) ) / 2, SIGMA, AP, 1 ) END IF * * Call ZHPTRD to reduce Hermitian packed matrix to tridiagonal form. * INDE = 1 INDTAU = 1 CALL ZHPTRD( UPLO, N, AP, W, RWORK( INDE ), WORK( INDTAU ), $ IINFO ) * * For eigenvalues only, call DSTERF. For eigenvectors, first call * ZUPGTR to generate the orthogonal matrix, then call ZSTEQR. * IF( .NOT.WANTZ ) THEN CALL DSTERF( N, W, RWORK( INDE ), INFO ) ELSE INDWRK = INDTAU + N CALL ZUPGTR( UPLO, N, AP, WORK( INDTAU ), Z, LDZ, $ WORK( INDWRK ), IINFO ) INDRWK = INDE + N CALL ZSTEQR( JOBZ, N, W, RWORK( INDE ), Z, LDZ, $ RWORK( INDRWK ), INFO ) END IF * * If matrix was scaled, then rescale eigenvalues appropriately. * IF( ISCALE.EQ.1 ) THEN IF( INFO.EQ.0 ) THEN IMAX = N ELSE IMAX = INFO - 1 END IF CALL DSCAL( IMAX, ONE / SIGMA, W, 1 ) END IF * RETURN * * End of ZHPEV * END
bsd-3-clause
aarchiba/scipy
scipy/integrate/quadpack/dqng.f
143
17670
subroutine dqng(f,a,b,epsabs,epsrel,result,abserr,neval,ier) c***begin prologue dqng c***date written 800101 (yymmdd) c***revision date 810101 (yymmdd) c***category no. h2a1a1 c***keywords automatic integrator, smooth integrand, c non-adaptive, gauss-kronrod(patterson) c***author piessens,robert,appl. math. & progr. div. - k.u.leuven c de doncker,elise,appl math & progr. div. - k.u.leuven c kahaner,david,nbs - modified (2/82) c***purpose the routine calculates an approximation result to a c given definite integral i = integral of f over (a,b), c hopefully satisfying following claim for accuracy c abs(i-result).le.max(epsabs,epsrel*abs(i)). c***description c c non-adaptive integration c standard fortran subroutine c double precision version c c f - double precision c function subprogram defining the integrand function c f(x). the actual name for f needs to be declared c e x t e r n a l in the driver program. c c a - double precision c lower limit of integration c c b - double precision c upper limit of integration c c epsabs - double precision c absolute accuracy requested c epsrel - double precision c relative accuracy requested c if epsabs.le.0 c and epsrel.lt.max(50*rel.mach.acc.,0.5d-28), c the routine will end with ier = 6. c c on return c result - double precision c approximation to the integral i c result is obtained by applying the 21-point c gauss-kronrod rule (res21) obtained by optimal c addition of abscissae to the 10-point gauss rule c (res10), or by applying the 43-point rule (res43) c obtained by optimal addition of abscissae to the c 21-point gauss-kronrod rule, or by applying the c 87-point rule (res87) obtained by optimal addition c of abscissae to the 43-point rule. c c abserr - double precision c estimate of the modulus of the absolute error, c which should equal or exceed abs(i-result) c c neval - integer c number of integrand evaluations c c ier - ier = 0 normal and reliable termination of the c routine. it is assumed that the requested c accuracy has been achieved. c ier.gt.0 abnormal termination of the routine. it is c assumed that the requested accuracy has c not been achieved. c error messages c ier = 1 the maximum number of steps has been c executed. the integral is probably too c difficult to be calculated by dqng. c = 6 the input is invalid, because c epsabs.le.0 and c epsrel.lt.max(50*rel.mach.acc.,0.5d-28). c result, abserr and neval are set to zero. c c***references (none) c***routines called d1mach,xerror c***end prologue dqng c double precision a,absc,abserr,b,centr,dabs,dhlgth,dmax1,dmin1, * d1mach,epmach,epsabs,epsrel,f,fcentr,fval,fval1,fval2,fv1,fv2, * fv3,fv4,hlgth,result,res10,res21,res43,res87,resabs,resasc, * reskh,savfun,uflow,w10,w21a,w21b,w43a,w43b,w87a,w87b,x1,x2,x3,x4 integer ier,ipx,k,l,neval external f c dimension fv1(5),fv2(5),fv3(5),fv4(5),x1(5),x2(5),x3(11),x4(22), * w10(5),w21a(5),w21b(6),w43a(10),w43b(12),w87a(21),w87b(23), * savfun(21) c c the following data statements contain the c abscissae and weights of the integration rules used. c c x1 abscissae common to the 10-, 21-, 43- and 87- c point rule c x2 abscissae common to the 21-, 43- and 87-point rule c x3 abscissae common to the 43- and 87-point rule c x4 abscissae of the 87-point rule c w10 weights of the 10-point formula c w21a weights of the 21-point formula for abscissae x1 c w21b weights of the 21-point formula for abscissae x2 c w43a weights of the 43-point formula for abscissae x1, x3 c w43b weights of the 43-point formula for abscissae x3 c w87a weights of the 87-point formula for abscissae x1, c x2, x3 c w87b weights of the 87-point formula for abscissae x4 c c c gauss-kronrod-patterson quadrature coefficients for use in c quadpack routine qng. these coefficients were calculated with c 101 decimal digit arithmetic by l. w. fullerton, bell labs, nov 1981. c data x1 ( 1) / 0.9739065285 1717172007 7964012084 452 d0 / data x1 ( 2) / 0.8650633666 8898451073 2096688423 493 d0 / data x1 ( 3) / 0.6794095682 9902440623 4327365114 874 d0 / data x1 ( 4) / 0.4333953941 2924719079 9265943165 784 d0 / data x1 ( 5) / 0.1488743389 8163121088 4826001129 720 d0 / data w10 ( 1) / 0.0666713443 0868813759 3568809893 332 d0 / data w10 ( 2) / 0.1494513491 5058059314 5776339657 697 d0 / data w10 ( 3) / 0.2190863625 1598204399 5534934228 163 d0 / data w10 ( 4) / 0.2692667193 0999635509 1226921569 469 d0 / data w10 ( 5) / 0.2955242247 1475287017 3892994651 338 d0 / c data x2 ( 1) / 0.9956571630 2580808073 5527280689 003 d0 / data x2 ( 2) / 0.9301574913 5570822600 1207180059 508 d0 / data x2 ( 3) / 0.7808177265 8641689706 3717578345 042 d0 / data x2 ( 4) / 0.5627571346 6860468333 9000099272 694 d0 / data x2 ( 5) / 0.2943928627 0146019813 1126603103 866 d0 / data w21a ( 1) / 0.0325581623 0796472747 8818972459 390 d0 / data w21a ( 2) / 0.0750396748 1091995276 7043140916 190 d0 / data w21a ( 3) / 0.1093871588 0229764189 9210590325 805 d0 / data w21a ( 4) / 0.1347092173 1147332592 8054001771 707 d0 / data w21a ( 5) / 0.1477391049 0133849137 4841515972 068 d0 / data w21b ( 1) / 0.0116946388 6737187427 8064396062 192 d0 / data w21b ( 2) / 0.0547558965 7435199603 1381300244 580 d0 / data w21b ( 3) / 0.0931254545 8369760553 5065465083 366 d0 / data w21b ( 4) / 0.1234919762 6206585107 7958109831 074 d0 / data w21b ( 5) / 0.1427759385 7706008079 7094273138 717 d0 / data w21b ( 6) / 0.1494455540 0291690566 4936468389 821 d0 / c data x3 ( 1) / 0.9993333609 0193208139 4099323919 911 d0 / data x3 ( 2) / 0.9874334029 0808886979 5961478381 209 d0 / data x3 ( 3) / 0.9548079348 1426629925 7919200290 473 d0 / data x3 ( 4) / 0.9001486957 4832829362 5099494069 092 d0 / data x3 ( 5) / 0.8251983149 8311415084 7066732588 520 d0 / data x3 ( 6) / 0.7321483889 8930498261 2354848755 461 d0 / data x3 ( 7) / 0.6228479705 3772523864 1159120344 323 d0 / data x3 ( 8) / 0.4994795740 7105649995 2214885499 755 d0 / data x3 ( 9) / 0.3649016613 4658076804 3989548502 644 d0 / data x3 ( 10) / 0.2222549197 7660129649 8260928066 212 d0 / data x3 ( 11) / 0.0746506174 6138332204 3914435796 506 d0 / data w43a ( 1) / 0.0162967342 8966656492 4281974617 663 d0 / data w43a ( 2) / 0.0375228761 2086950146 1613795898 115 d0 / data w43a ( 3) / 0.0546949020 5825544214 7212685465 005 d0 / data w43a ( 4) / 0.0673554146 0947808607 5553166302 174 d0 / data w43a ( 5) / 0.0738701996 3239395343 2140695251 367 d0 / data w43a ( 6) / 0.0057685560 5976979618 4184327908 655 d0 / data w43a ( 7) / 0.0273718905 9324884208 1276069289 151 d0 / data w43a ( 8) / 0.0465608269 1042883074 3339154433 824 d0 / data w43a ( 9) / 0.0617449952 0144256449 6240336030 883 d0 / data w43a ( 10) / 0.0713872672 6869339776 8559114425 516 d0 / data w43b ( 1) / 0.0018444776 4021241410 0389106552 965 d0 / data w43b ( 2) / 0.0107986895 8589165174 0465406741 293 d0 / data w43b ( 3) / 0.0218953638 6779542810 2523123075 149 d0 / data w43b ( 4) / 0.0325974639 7534568944 3882222526 137 d0 / data w43b ( 5) / 0.0421631379 3519181184 7627924327 955 d0 / data w43b ( 6) / 0.0507419396 0018457778 0189020092 084 d0 / data w43b ( 7) / 0.0583793955 4261924837 5475369330 206 d0 / data w43b ( 8) / 0.0647464049 5144588554 4689259517 511 d0 / data w43b ( 9) / 0.0695661979 1235648452 8633315038 405 d0 / data w43b ( 10) / 0.0728244414 7183320815 0939535192 842 d0 / data w43b ( 11) / 0.0745077510 1417511827 3571813842 889 d0 / data w43b ( 12) / 0.0747221475 1740300559 4425168280 423 d0 / c data x4 ( 1) / 0.9999029772 6272923449 0529830591 582 d0 / data x4 ( 2) / 0.9979898959 8667874542 7496322365 960 d0 / data x4 ( 3) / 0.9921754978 6068722280 8523352251 425 d0 / data x4 ( 4) / 0.9813581635 7271277357 1916941623 894 d0 / data x4 ( 5) / 0.9650576238 5838461912 8284110607 926 d0 / data x4 ( 6) / 0.9431676131 3367059681 6416634507 426 d0 / data x4 ( 7) / 0.9158064146 8550720959 1826430720 050 d0 / data x4 ( 8) / 0.8832216577 7131650137 2117548744 163 d0 / data x4 ( 9) / 0.8457107484 6241566660 5902011504 855 d0 / data x4 ( 10) / 0.8035576580 3523098278 8739474980 964 d0 / data x4 ( 11) / 0.7570057306 8549555832 8942793432 020 d0 / data x4 ( 12) / 0.7062732097 8732181982 4094274740 840 d0 / data x4 ( 13) / 0.6515894665 0117792253 4422205016 736 d0 / data x4 ( 14) / 0.5932233740 5796108887 5273770349 144 d0 / data x4 ( 15) / 0.5314936059 7083193228 5268948562 671 d0 / data x4 ( 16) / 0.4667636230 4202284487 1966781659 270 d0 / data x4 ( 17) / 0.3994248478 5921880473 2101665817 923 d0 / data x4 ( 18) / 0.3298748771 0618828826 5053371824 597 d0 / data x4 ( 19) / 0.2585035592 0216155180 2280975429 025 d0 / data x4 ( 20) / 0.1856953965 6834665201 5917141167 606 d0 / data x4 ( 21) / 0.1118422131 7990746817 2398359241 362 d0 / data x4 ( 22) / 0.0373521233 9461987081 4998165437 704 d0 / data w87a ( 1) / 0.0081483773 8414917290 0002878448 190 d0 / data w87a ( 2) / 0.0187614382 0156282224 3935059003 794 d0 / data w87a ( 3) / 0.0273474510 5005228616 1582829741 283 d0 / data w87a ( 4) / 0.0336777073 1163793004 6581056957 588 d0 / data w87a ( 5) / 0.0369350998 2042790761 4589586742 499 d0 / data w87a ( 6) / 0.0028848724 3021153050 1334156248 695 d0 / data w87a ( 7) / 0.0136859460 2271270188 8950035273 128 d0 / data w87a ( 8) / 0.0232804135 0288831112 3409291030 404 d0 / data w87a ( 9) / 0.0308724976 1171335867 5466394126 442 d0 / data w87a ( 10) / 0.0356936336 3941877071 9351355457 044 d0 / data w87a ( 11) / 0.0009152833 4520224136 0843392549 948 d0 / data w87a ( 12) / 0.0053992802 1930047136 7738743391 053 d0 / data w87a ( 13) / 0.0109476796 0111893113 4327826856 808 d0 / data w87a ( 14) / 0.0162987316 9678733526 2665703223 280 d0 / data w87a ( 15) / 0.0210815688 8920383511 2433060188 190 d0 / data w87a ( 16) / 0.0253709697 6925382724 3467999831 710 d0 / data w87a ( 17) / 0.0291896977 5647575250 1446154084 920 d0 / data w87a ( 18) / 0.0323732024 6720278968 5788194889 595 d0 / data w87a ( 19) / 0.0347830989 5036514275 0781997949 596 d0 / data w87a ( 20) / 0.0364122207 3135178756 2801163687 577 d0 / data w87a ( 21) / 0.0372538755 0304770853 9592001191 226 d0 / data w87b ( 1) / 0.0002741455 6376207235 0016527092 881 d0 / data w87b ( 2) / 0.0018071241 5505794294 8341311753 254 d0 / data w87b ( 3) / 0.0040968692 8275916486 4458070683 480 d0 / data w87b ( 4) / 0.0067582900 5184737869 9816577897 424 d0 / data w87b ( 5) / 0.0095499576 7220164653 6053581325 377 d0 / data w87b ( 6) / 0.0123294476 5224485369 4626639963 780 d0 / data w87b ( 7) / 0.0150104473 4638895237 6697286041 943 d0 / data w87b ( 8) / 0.0175489679 8624319109 9665352925 900 d0 / data w87b ( 9) / 0.0199380377 8644088820 2278192730 714 d0 / data w87b ( 10) / 0.0221949359 6101228679 6332102959 499 d0 / data w87b ( 11) / 0.0243391471 2600080547 0360647041 454 d0 / data w87b ( 12) / 0.0263745054 1483920724 1503786552 615 d0 / data w87b ( 13) / 0.0282869107 8877120065 9968002987 960 d0 / data w87b ( 14) / 0.0300525811 2809269532 2521110347 341 d0 / data w87b ( 15) / 0.0316467513 7143992940 4586051078 883 d0 / data w87b ( 16) / 0.0330504134 1997850329 0785944862 689 d0 / data w87b ( 17) / 0.0342550997 0422606178 7082821046 821 d0 / data w87b ( 18) / 0.0352624126 6015668103 3782717998 428 d0 / data w87b ( 19) / 0.0360769896 2288870118 5500318003 895 d0 / data w87b ( 20) / 0.0366986044 9845609449 8018047441 094 d0 / data w87b ( 21) / 0.0371205492 6983257611 4119958413 599 d0 / data w87b ( 22) / 0.0373342287 5193504032 1235449094 698 d0 / data w87b ( 23) / 0.0373610737 6267902341 0321241766 599 d0 / c c list of major variables c ----------------------- c c centr - mid point of the integration interval c hlgth - half-length of the integration interval c fcentr - function value at mid point c absc - abscissa c fval - function value c savfun - array of function values which have already been c computed c res10 - 10-point gauss result c res21 - 21-point kronrod result c res43 - 43-point result c res87 - 87-point result c resabs - approximation to the integral of abs(f) c resasc - approximation to the integral of abs(f-i/(b-a)) c c machine dependent constants c --------------------------- c c epmach is the largest relative spacing. c uflow is the smallest positive magnitude. c c***first executable statement dqng epmach = d1mach(4) uflow = d1mach(1) c c test on validity of parameters c ------------------------------ c result = 0.0d+00 abserr = 0.0d+00 neval = 0 ier = 6 if(epsabs.le.0.0d+00.and.epsrel.lt.dmax1(0.5d+02*epmach,0.5d-28)) * go to 80 hlgth = 0.5d+00*(b-a) dhlgth = dabs(hlgth) centr = 0.5d+00*(b+a) fcentr = f(centr) neval = 21 ier = 1 c c compute the integral using the 10- and 21-point formula. c do 70 l = 1,3 go to (5,25,45),l 5 res10 = 0.0d+00 res21 = w21b(6)*fcentr resabs = w21b(6)*dabs(fcentr) do 10 k=1,5 absc = hlgth*x1(k) fval1 = f(centr+absc) fval2 = f(centr-absc) fval = fval1+fval2 res10 = res10+w10(k)*fval res21 = res21+w21a(k)*fval resabs = resabs+w21a(k)*(dabs(fval1)+dabs(fval2)) savfun(k) = fval fv1(k) = fval1 fv2(k) = fval2 10 continue ipx = 5 do 15 k=1,5 ipx = ipx+1 absc = hlgth*x2(k) fval1 = f(centr+absc) fval2 = f(centr-absc) fval = fval1+fval2 res21 = res21+w21b(k)*fval resabs = resabs+w21b(k)*(dabs(fval1)+dabs(fval2)) savfun(ipx) = fval fv3(k) = fval1 fv4(k) = fval2 15 continue c c test for convergence. c result = res21*hlgth resabs = resabs*dhlgth reskh = 0.5d+00*res21 resasc = w21b(6)*dabs(fcentr-reskh) do 20 k = 1,5 resasc = resasc+w21a(k)*(dabs(fv1(k)-reskh)+dabs(fv2(k)-reskh)) * +w21b(k)*(dabs(fv3(k)-reskh)+dabs(fv4(k)-reskh)) 20 continue abserr = dabs((res21-res10)*hlgth) resasc = resasc*dhlgth go to 65 c c compute the integral using the 43-point formula. c 25 res43 = w43b(12)*fcentr neval = 43 do 30 k=1,10 res43 = res43+savfun(k)*w43a(k) 30 continue do 40 k=1,11 ipx = ipx+1 absc = hlgth*x3(k) fval = f(absc+centr)+f(centr-absc) res43 = res43+fval*w43b(k) savfun(ipx) = fval 40 continue c c test for convergence. c result = res43*hlgth abserr = dabs((res43-res21)*hlgth) go to 65 c c compute the integral using the 87-point formula. c 45 res87 = w87b(23)*fcentr neval = 87 do 50 k=1,21 res87 = res87+savfun(k)*w87a(k) 50 continue do 60 k=1,22 absc = hlgth*x4(k) res87 = res87+w87b(k)*(f(absc+centr)+f(centr-absc)) 60 continue result = res87*hlgth abserr = dabs((res87-res43)*hlgth) 65 if(resasc.ne.0.0d+00.and.abserr.ne.0.0d+00) * abserr = resasc*dmin1(0.1d+01,(0.2d+03*abserr/resasc)**1.5d+00) if (resabs.gt.uflow/(0.5d+02*epmach)) abserr = dmax1 * ((epmach*0.5d+02)*resabs,abserr) if (abserr.le.dmax1(epsabs,epsrel*dabs(result))) ier = 0 c ***jump out of do-loop if (ier.eq.0) go to 999 70 continue 80 call xerror('abnormal return from dqng ',26,ier,0) 999 return end
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/dsptrd.f
28
8832
*> \brief \b DSPTRD * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DSPTRD + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsptrd.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsptrd.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsptrd.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DSPTRD( UPLO, N, AP, D, E, TAU, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, N * .. * .. Array Arguments .. * DOUBLE PRECISION AP( * ), D( * ), E( * ), TAU( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DSPTRD reduces a real symmetric matrix A stored in packed form to *> symmetric tridiagonal form T by an orthogonal similarity *> transformation: Q**T * A * Q = T. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of A is stored; *> = 'L': Lower triangle of A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] AP *> \verbatim *> AP is DOUBLE PRECISION array, dimension (N*(N+1)/2) *> On entry, the upper or lower triangle of the symmetric matrix *> A, packed columnwise in a linear array. The j-th column of A *> is stored in the array AP as follows: *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. *> On exit, if UPLO = 'U', the diagonal and first superdiagonal *> of A are overwritten by the corresponding elements of the *> tridiagonal matrix T, and the elements above the first *> superdiagonal, with the array TAU, represent the orthogonal *> matrix Q as a product of elementary reflectors; if UPLO *> = 'L', the diagonal and first subdiagonal of A are over- *> written by the corresponding elements of the tridiagonal *> matrix T, and the elements below the first subdiagonal, with *> the array TAU, represent the orthogonal matrix Q as a product *> of elementary reflectors. See Further Details. *> \endverbatim *> *> \param[out] D *> \verbatim *> D is DOUBLE PRECISION array, dimension (N) *> The diagonal elements of the tridiagonal matrix T: *> D(i) = A(i,i). *> \endverbatim *> *> \param[out] E *> \verbatim *> E is DOUBLE PRECISION array, dimension (N-1) *> The off-diagonal elements of the tridiagonal matrix T: *> E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is DOUBLE PRECISION array, dimension (N-1) *> The scalar factors of the elementary reflectors (see Further *> Details). *> \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. * *> \date November 2011 * *> \ingroup doubleOTHERcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> If UPLO = 'U', the matrix Q is represented as a product of elementary *> reflectors *> *> Q = H(n-1) . . . H(2) H(1). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**T *> *> where tau is a real scalar, and v is a real vector with *> v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in AP, *> overwriting A(1:i-1,i+1), and tau is stored in TAU(i). *> *> If UPLO = 'L', the matrix Q is represented as a product of elementary *> reflectors *> *> Q = H(1) H(2) . . . H(n-1). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**T *> *> where tau is a real scalar, and v is a real vector with *> v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in AP, *> overwriting A(i+2:n,i), and tau is stored in TAU(i). *> \endverbatim *> * ===================================================================== SUBROUTINE DSPTRD( UPLO, N, AP, D, E, TAU, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, N * .. * .. Array Arguments .. DOUBLE PRECISION AP( * ), D( * ), E( * ), TAU( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO, HALF PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0, $ HALF = 1.0D0 / 2.0D0 ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER I, I1, I1I1, II DOUBLE PRECISION ALPHA, TAUI * .. * .. External Subroutines .. EXTERNAL DAXPY, DLARFG, DSPMV, DSPR2, XERBLA * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DDOT EXTERNAL LSAME, DDOT * .. * .. 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( 'DSPTRD', -INFO ) RETURN END IF * * Quick return if possible * IF( N.LE.0 ) $ RETURN * IF( UPPER ) THEN * * Reduce the upper triangle of A. * I1 is the index in AP of A(1,I+1). * I1 = N*( N-1 ) / 2 + 1 DO 10 I = N - 1, 1, -1 * * Generate elementary reflector H(i) = I - tau * v * v**T * to annihilate A(1:i-1,i+1) * CALL DLARFG( I, AP( I1+I-1 ), AP( I1 ), 1, TAUI ) E( I ) = AP( I1+I-1 ) * IF( TAUI.NE.ZERO ) THEN * * Apply H(i) from both sides to A(1:i,1:i) * AP( I1+I-1 ) = ONE * * Compute y := tau * A * v storing y in TAU(1:i) * CALL DSPMV( UPLO, I, TAUI, AP, AP( I1 ), 1, ZERO, TAU, $ 1 ) * * Compute w := y - 1/2 * tau * (y**T *v) * v * ALPHA = -HALF*TAUI*DDOT( I, TAU, 1, AP( I1 ), 1 ) CALL DAXPY( I, ALPHA, AP( I1 ), 1, TAU, 1 ) * * Apply the transformation as a rank-2 update: * A := A - v * w**T - w * v**T * CALL DSPR2( UPLO, I, -ONE, AP( I1 ), 1, TAU, 1, AP ) * AP( I1+I-1 ) = E( I ) END IF D( I+1 ) = AP( I1+I ) TAU( I ) = TAUI I1 = I1 - I 10 CONTINUE D( 1 ) = AP( 1 ) ELSE * * Reduce the lower triangle of A. II is the index in AP of * A(i,i) and I1I1 is the index of A(i+1,i+1). * II = 1 DO 20 I = 1, N - 1 I1I1 = II + N - I + 1 * * Generate elementary reflector H(i) = I - tau * v * v**T * to annihilate A(i+2:n,i) * CALL DLARFG( N-I, AP( II+1 ), AP( II+2 ), 1, TAUI ) E( I ) = AP( II+1 ) * IF( TAUI.NE.ZERO ) THEN * * Apply H(i) from both sides to A(i+1:n,i+1:n) * AP( II+1 ) = ONE * * Compute y := tau * A * v storing y in TAU(i:n-1) * CALL DSPMV( UPLO, N-I, TAUI, AP( I1I1 ), AP( II+1 ), 1, $ ZERO, TAU( I ), 1 ) * * Compute w := y - 1/2 * tau * (y**T *v) * v * ALPHA = -HALF*TAUI*DDOT( N-I, TAU( I ), 1, AP( II+1 ), $ 1 ) CALL DAXPY( N-I, ALPHA, AP( II+1 ), 1, TAU( I ), 1 ) * * Apply the transformation as a rank-2 update: * A := A - v * w**T - w * v**T * CALL DSPR2( UPLO, N-I, -ONE, AP( II+1 ), 1, TAU( I ), 1, $ AP( I1I1 ) ) * AP( II+1 ) = E( I ) END IF D( I ) = AP( II ) TAU( I ) = TAUI II = I1I1 20 CONTINUE D( N ) = AP( II ) END IF * RETURN * * End of DSPTRD * END
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/dsytrf.f
31
11120
*> \brief \b DSYTRF * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DSYTRF + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytrf.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytrf.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytrf.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DSYTRF( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, LDA, LWORK, N * .. * .. Array Arguments .. * INTEGER IPIV( * ) * DOUBLE PRECISION A( LDA, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DSYTRF computes the factorization of a real symmetric matrix A using *> the Bunch-Kaufman diagonal pivoting method. The form of the *> factorization is *> *> A = U*D*U**T or A = L*D*L**T *> *> where U (or L) is a product of permutation and unit upper (lower) *> triangular matrices, and D is symmetric 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. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of A is stored; *> = 'L': Lower triangle of A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On entry, the symmetric 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). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[out] IPIV *> \verbatim *> IPIV is 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. *> \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 length of WORK. LWORK >=1. For best performance *> LWORK >= N*NB, where NB is the block size returned by ILAENV. *> *> 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] INFO *> \verbatim *> INFO is 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. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup doubleSYcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> If UPLO = 'U', then A = U*D*U**T, 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**T, 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). *> \endverbatim *> * ===================================================================== SUBROUTINE DSYTRF( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDA, LWORK, N * .. * .. Array Arguments .. INTEGER IPIV( * ) DOUBLE PRECISION A( LDA, * ), WORK( * ) * .. * * ===================================================================== * * .. 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 DLASYF, DSYTF2, 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, 'DSYTRF', UPLO, N, -1, -1, -1 ) LWKOPT = N*NB WORK( 1 ) = LWKOPT END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'DSYTRF', -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, 'DSYTRF', 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**T 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 DLASYF; * 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 DLASYF( UPLO, K, NB, KB, A, LDA, IPIV, WORK, LDWORK, $ IINFO ) ELSE * * Use unblocked code to factorize columns 1:k of A * CALL DSYTF2( 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**T 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 DLASYF; * 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 DLASYF( UPLO, N-K+1, NB, KB, A( K, K ), LDA, IPIV( K ), $ WORK, LDWORK, IINFO ) ELSE * * Use unblocked code to factorize columns k:n of A * CALL DSYTF2( 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 DSYTRF * END
bsd-3-clause
UPenn-RoboCup/OpenBLAS
interface/netlib/zgemv.f
49
8185
SUBROUTINE ZGEMV(TRANS,M,N,ALPHA,A,LDA,X,INCX,BETA,Y,INCY) * .. Scalar Arguments .. DOUBLE COMPLEX ALPHA,BETA INTEGER INCX,INCY,LDA,M,N CHARACTER TRANS * .. * .. Array Arguments .. DOUBLE COMPLEX A(LDA,*),X(*),Y(*) * .. * * Purpose * ======= * * ZGEMV performs one of the matrix-vector operations * * y := alpha*A*x + beta*y, or y := alpha*A**T*x + beta*y, or * * y := alpha*A**H*x + beta*y, * * where alpha and beta are scalars, x and y are vectors and A is an * m by n matrix. * * Arguments * ========== * * TRANS - CHARACTER*1. * On entry, TRANS specifies the operation to be performed as * follows: * * TRANS = 'N' or 'n' y := alpha*A*x + beta*y. * * TRANS = 'T' or 't' y := alpha*A**T*x + beta*y. * * TRANS = 'C' or 'c' y := alpha*A**H*x + beta*y. * * Unchanged on exit. * * M - INTEGER. * On entry, M specifies the number of rows of the matrix A. * M must be at least zero. * Unchanged on exit. * * N - INTEGER. * On entry, N specifies the number of columns of the matrix A. * N must be at least zero. * Unchanged on exit. * * ALPHA - COMPLEX*16 . * On entry, ALPHA specifies the scalar alpha. * Unchanged on exit. * * A - COMPLEX*16 array of DIMENSION ( LDA, n ). * Before entry, the leading m by n part of the array A must * contain the matrix of coefficients. * 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 * max( 1, m ). * Unchanged on exit. * * X - COMPLEX*16 array of DIMENSION at least * ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n' * and at least * ( 1 + ( m - 1 )*abs( INCX ) ) otherwise. * 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. When BETA is * supplied as zero then Y need not be set on input. * Unchanged on exit. * * Y - COMPLEX*16 array of DIMENSION at least * ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n' * and at least * ( 1 + ( n - 1 )*abs( INCY ) ) otherwise. * Before entry with BETA non-zero, 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. * * Further Details * =============== * * Level 2 Blas routine. * The vector and matrix arguments are not referenced when N = 0, or M = 0 * * -- Written on 22-October-1986. * Jack Dongarra, Argonne National Lab. * Jeremy Du Croz, Nag Central Office. * Sven Hammarling, Nag Central Office. * Richard Hanson, Sandia National Labs. * * ===================================================================== * * .. Parameters .. DOUBLE COMPLEX ONE PARAMETER (ONE= (1.0D+0,0.0D+0)) DOUBLE COMPLEX ZERO PARAMETER (ZERO= (0.0D+0,0.0D+0)) * .. * .. Local Scalars .. DOUBLE COMPLEX TEMP INTEGER I,INFO,IX,IY,J,JX,JY,KX,KY,LENX,LENY LOGICAL NOCONJ * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC DCONJG,MAX * .. * * Test the input parameters. * INFO = 0 IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND. + .NOT.LSAME(TRANS,'C')) THEN INFO = 1 ELSE IF (M.LT.0) THEN INFO = 2 ELSE IF (N.LT.0) THEN INFO = 3 ELSE IF (LDA.LT.MAX(1,M)) 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('ZGEMV ',INFO) RETURN END IF * * Quick return if possible. * IF ((M.EQ.0) .OR. (N.EQ.0) .OR. + ((ALPHA.EQ.ZERO).AND. (BETA.EQ.ONE))) RETURN * NOCONJ = LSAME(TRANS,'T') * * Set LENX and LENY, the lengths of the vectors x and y, and set * up the start points in X and Y. * IF (LSAME(TRANS,'N')) THEN LENX = N LENY = M ELSE LENX = M LENY = N END IF IF (INCX.GT.0) THEN KX = 1 ELSE KX = 1 - (LENX-1)*INCX END IF IF (INCY.GT.0) THEN KY = 1 ELSE KY = 1 - (LENY-1)*INCY END IF * * Start the operations. In this version the elements of 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,LENY Y(I) = ZERO 10 CONTINUE ELSE DO 20 I = 1,LENY Y(I) = BETA*Y(I) 20 CONTINUE END IF ELSE IY = KY IF (BETA.EQ.ZERO) THEN DO 30 I = 1,LENY Y(IY) = ZERO IY = IY + INCY 30 CONTINUE ELSE DO 40 I = 1,LENY Y(IY) = BETA*Y(IY) IY = IY + INCY 40 CONTINUE END IF END IF END IF IF (ALPHA.EQ.ZERO) RETURN IF (LSAME(TRANS,'N')) THEN * * Form y := alpha*A*x + y. * JX = KX IF (INCY.EQ.1) THEN DO 60 J = 1,N IF (X(JX).NE.ZERO) THEN TEMP = ALPHA*X(JX) DO 50 I = 1,M Y(I) = Y(I) + TEMP*A(I,J) 50 CONTINUE END IF JX = JX + INCX 60 CONTINUE ELSE DO 80 J = 1,N IF (X(JX).NE.ZERO) THEN TEMP = ALPHA*X(JX) IY = KY DO 70 I = 1,M Y(IY) = Y(IY) + TEMP*A(I,J) IY = IY + INCY 70 CONTINUE END IF JX = JX + INCX 80 CONTINUE END IF ELSE * * Form y := alpha*A**T*x + y or y := alpha*A**H*x + y. * JY = KY IF (INCX.EQ.1) THEN DO 110 J = 1,N TEMP = ZERO IF (NOCONJ) THEN DO 90 I = 1,M TEMP = TEMP + A(I,J)*X(I) 90 CONTINUE ELSE DO 100 I = 1,M TEMP = TEMP + DCONJG(A(I,J))*X(I) 100 CONTINUE END IF Y(JY) = Y(JY) + ALPHA*TEMP JY = JY + INCY 110 CONTINUE ELSE DO 140 J = 1,N TEMP = ZERO IX = KX IF (NOCONJ) THEN DO 120 I = 1,M TEMP = TEMP + A(I,J)*X(IX) IX = IX + INCX 120 CONTINUE ELSE DO 130 I = 1,M TEMP = TEMP + DCONJG(A(I,J))*X(IX) IX = IX + INCX 130 CONTINUE END IF Y(JY) = Y(JY) + ALPHA*TEMP JY = JY + INCY 140 CONTINUE END IF END IF * RETURN * * End of ZGEMV . * END
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/dgerqf.f
25
8110
*> \brief \b DGERQF * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGERQF + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgerqf.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgerqf.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgerqf.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGERQF( M, N, A, LDA, TAU, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LWORK, M, N * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGERQF computes an RQ factorization of a real M-by-N matrix A: *> A = R * Q. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On entry, the M-by-N matrix A. *> On exit, *> if m <= n, the upper triangle of the subarray *> A(1:m,n-m+1:n) contains the M-by-M upper triangular matrix R; *> if m >= n, the elements on and above the (m-n)-th subdiagonal *> contain the M-by-N upper trapezoidal matrix R; *> the remaining elements, with the array TAU, represent the *> orthogonal matrix Q as a product of min(m,n) elementary *> reflectors (see Further Details). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is DOUBLE PRECISION array, dimension (min(M,N)) *> The scalar factors of the elementary reflectors (see Further *> Details). *> \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. LWORK >= max(1,M). *> For optimum performance LWORK >= M*NB, where NB is *> the optimal blocksize. *> *> 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] 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. * *> \date November 2011 * *> \ingroup doubleGEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix Q is represented as a product of elementary reflectors *> *> Q = H(1) H(2) . . . H(k), where k = min(m,n). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**T *> *> where tau is a real scalar, and v is a real vector with *> v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in *> A(m-k+i,1:n-k+i-1), and tau in TAU(i). *> \endverbatim *> * ===================================================================== SUBROUTINE DGERQF( M, N, A, LDA, TAU, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, LWORK, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Local Scalars .. LOGICAL LQUERY INTEGER I, IB, IINFO, IWS, K, KI, KK, LDWORK, LWKOPT, $ MU, NB, NBMIN, NU, NX * .. * .. External Subroutines .. EXTERNAL DGERQ2, DLARFB, DLARFT, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. External Functions .. INTEGER ILAENV EXTERNAL ILAENV * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 LQUERY = ( LWORK.EQ.-1 ) IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -4 END IF * IF( INFO.EQ.0 ) THEN K = MIN( M, N ) IF( K.EQ.0 ) THEN LWKOPT = 1 ELSE NB = ILAENV( 1, 'DGERQF', ' ', M, N, -1, -1 ) LWKOPT = M*NB END IF WORK( 1 ) = LWKOPT * IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN INFO = -7 END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGERQF', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( K.EQ.0 ) THEN RETURN END IF * NBMIN = 2 NX = 1 IWS = M IF( NB.GT.1 .AND. NB.LT.K ) THEN * * Determine when to cross over from blocked to unblocked code. * NX = MAX( 0, ILAENV( 3, 'DGERQF', ' ', M, N, -1, -1 ) ) IF( NX.LT.K ) THEN * * Determine if workspace is large enough for blocked code. * LDWORK = M IWS = LDWORK*NB IF( LWORK.LT.IWS ) THEN * * Not enough workspace to use optimal NB: reduce NB and * determine the minimum value of NB. * NB = LWORK / LDWORK NBMIN = MAX( 2, ILAENV( 2, 'DGERQF', ' ', M, N, -1, $ -1 ) ) END IF END IF END IF * IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN * * Use blocked code initially. * The last kk rows are handled by the block method. * KI = ( ( K-NX-1 ) / NB )*NB KK = MIN( K, KI+NB ) * DO 10 I = K - KK + KI + 1, K - KK + 1, -NB IB = MIN( K-I+1, NB ) * * Compute the RQ factorization of the current block * A(m-k+i:m-k+i+ib-1,1:n-k+i+ib-1) * CALL DGERQ2( IB, N-K+I+IB-1, A( M-K+I, 1 ), LDA, TAU( I ), $ WORK, IINFO ) IF( M-K+I.GT.1 ) THEN * * Form the triangular factor of the block reflector * H = H(i+ib-1) . . . H(i+1) H(i) * CALL DLARFT( 'Backward', 'Rowwise', N-K+I+IB-1, IB, $ A( M-K+I, 1 ), LDA, TAU( I ), WORK, LDWORK ) * * Apply H to A(1:m-k+i-1,1:n-k+i+ib-1) from the right * CALL DLARFB( 'Right', 'No transpose', 'Backward', $ 'Rowwise', M-K+I-1, N-K+I+IB-1, IB, $ A( M-K+I, 1 ), LDA, WORK, LDWORK, A, LDA, $ WORK( IB+1 ), LDWORK ) END IF 10 CONTINUE MU = M - K + I + NB - 1 NU = N - K + I + NB - 1 ELSE MU = M NU = N END IF * * Use unblocked code to factor the last or only block * IF( MU.GT.0 .AND. NU.GT.0 ) $ CALL DGERQ2( MU, NU, A, LDA, TAU, WORK, IINFO ) * WORK( 1 ) = IWS RETURN * * End of DGERQF * END
bsd-3-clause
vfonov/ITK
Modules/ThirdParty/Netlib/src/netlib/slatec/dgamr.f
48
1343
*DECK DGAMR DOUBLE PRECISION FUNCTION DGAMR (X) C***BEGIN PROLOGUE DGAMR C***PURPOSE Compute the reciprocal of the Gamma function. C***LIBRARY SLATEC (FNLIB) C***CATEGORY C7A C***TYPE DOUBLE PRECISION (GAMR-S, DGAMR-D, CGAMR-C) C***KEYWORDS FNLIB, RECIPROCAL GAMMA FUNCTION, SPECIAL FUNCTIONS C***AUTHOR Fullerton, W., (LANL) C***DESCRIPTION C C DGAMR(X) calculates the double precision reciprocal of the C complete Gamma function for double precision argument X. C C***REFERENCES (NONE) C***ROUTINES CALLED DGAMMA, DLGAMS, XERCLR, XGETF, XSETF C***REVISION HISTORY (YYMMDD) C 770701 DATE WRITTEN C 890531 Changed all specific intrinsics to generic. (WRB) C 890531 REVISION DATE from Version 3.2 C 891214 Prologue converted to Version 4.0 format. (BAB) C 900727 Added EXTERNAL statement. (WRB) C***END PROLOGUE DGAMR DOUBLE PRECISION X, ALNGX, SGNGX, DGAMMA EXTERNAL DGAMMA C***FIRST EXECUTABLE STATEMENT DGAMR DGAMR = 0.0D0 IF (X.LE.0.0D0 .AND. AINT(X).EQ.X) RETURN C CALL XGETF (IROLD) CALL XSETF (1) IF (ABS(X).GT.10.0D0) GO TO 10 DGAMR = 1.0D0/DGAMMA(X) CALL XERCLR CALL XSETF (IROLD) RETURN C 10 CALL DLGAMS (X, ALNGX, SGNGX) CALL XERCLR CALL XSETF (IROLD) DGAMR = SGNGX * EXP(-ALNGX) RETURN C END
apache-2.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/VARIANTS/qr/LL/sceil.f
24
1786
C> \brief \b SCEIL * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * REAL FUNCTION SCEIL( A ) * * .. Scalar Arguments .. * REAL A * .. * * ===================================================================== * * .. Intrinsic Functions .. * INTRINSIC INT * .. * .. Executable Statements ..* * * IF (A-INT(A).EQ.0) THEN * SCEIL = A * ELSE IF (A.GT.0) THEN * SCEIL = INT(A)+1; * ELSE * SCEIL = INT(A) * END IF * * RETURN * * END * Purpose * ======= * C>\details \b Purpose: C>\verbatim C>\endverbatim * * Arguments: * ========== * * * Authors: * ======== * C> \author Univ. of Tennessee C> \author Univ. of California Berkeley C> \author Univ. of Colorado Denver C> \author NAG Ltd. * C> \date November 2011 * C> \ingroup variantsOTHERcomputational * * ===================================================================== REAL FUNCTION SCEIL( A ) * * -- LAPACK computational routine (version 3.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments ..* REAL A * .. * * ===================================================================== * * .. Intrinsic Functions .. INTRINSIC INT * .. * .. Executable Statements ..* * IF (A-INT(A).EQ.0) THEN SCEIL = A ELSE IF (A.GT.0) THEN SCEIL = INT(A)+1; ELSE SCEIL = INT(A) END IF RETURN * END
bsd-3-clause
nvarini/espresso_iohpc
CPV/src/init.f90
6
17150
! ! Copyright (C) 2002-2010 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 . ! !=----------------------------------------------------------------------=! ! ! CP90 / FPMD common init subroutine ! !=----------------------------------------------------------------------=! subroutine init_dimensions( ) ! ! initialize G-vectors and related quantities ! USE kinds, ONLY: dp USE constants, ONLY: tpi use io_global, only: stdout, ionode use control_flags, only: gamma_only, iverbosity use cell_base, only: ainv, at, omega, alat use small_box, only: small_box_set use smallbox_grid_dim, only: smallbox_grid_init,smallbox_grid_info USE fft_types, ONLY: fft_type_allocate, fft_type_init use ions_base, only: nat USE recvec_subs, ONLY: ggen USE gvect, ONLY: mill_g, eigts1,eigts2,eigts3, gg, & ecutrho, gcutm, gvect_init use gvecs, only: gcutms, gvecs_init use gvecw, only: gkcut, gvecw_init, g2kin_init USE smallbox_subs, ONLY: ggenb USE fft_base, ONLY: dfftp, dffts, dfftb, dfft3d, dtgs, fft_base_info USE fft_smallbox, ONLY: cft_b_omp_init USE fft_base, ONLY: smap USE control_flags, ONLY: gamma_only, smallmem USE electrons_module, ONLY: bmeshset USE electrons_base, ONLY: distribute_bands USE problem_size, ONLY: cpsizes USE mp_bands, ONLY: me_bgrp, root_bgrp, nproc_bgrp, nbgrp, & my_bgrp_id, intra_bgrp_comm, ntask_groups USE uspp, ONLY: okvan, nlcc_any USE input_parameters, ONLY: ref_cell, ref_alat use cell_base, ONLY: ref_at, ref_bg USE exx_module, ONLY: h_init USE task_groups, ONLY: task_groups_init implicit none ! integer :: i real(dp) :: rat1, rat2, rat3 real(dp) :: bg(3,3), tpiba2 integer :: ng_, ngs_, ngm_ , ngw_ #if defined(__MPI) LOGICAL :: lpara = .true. #else LOGICAL :: lpara = .false. #endif CALL start_clock( 'init_dim' ) tpiba2 = ( tpi / alat ) ** 2 IF( ionode ) THEN WRITE( stdout, 100 ) 100 FORMAT( //, & 3X,'Simulation dimensions initialization',/, & 3X,'------------------------------------' ) END IF ! ! ... Initialize bands indexes for parallel linear algebra ! ... (distribute bands to processors) ! CALL bmeshset( ) ! ! ... cell dimensions and lattice vectors ! ... note that at are in alat units call recips( at(1,1), at(1,2), at(1,3), bg(1,1), bg(1,2), bg(1,3) ) ! bg(:,1), bg(:,2), bg(:,3) are the basis vectors, in ! 2pi/alat units, generating the reciprocal lattice ! Store the cell parameter from the input file. Used in exx_module ... h_init=at*alat ! ... Initialize FFT real-space grids and small box grid ! IF ( ref_cell ) THEN ! CALL recips( ref_at(1,1), ref_at(1,2), ref_at(1,3), ref_bg(1,1), ref_bg(1,2), ref_bg(1,3) ) ! WRITE( stdout,'(3X,"Reference Cell is Used to Initialize FFT Real-space Grids")' ) WRITE( stdout,'(3X,"Reference Cell alat =",F14.8,1X,"A.U.")' ) ref_alat WRITE( stdout,'(3X,"ref_cell_a1 =",1X,3f14.8,3x,"ref_cell_b1 =",3f14.8)') ref_at(:,1)*ref_alat,ref_bg(:,1)/ref_alat WRITE( stdout,'(3X,"ref_cell_a2 =",1X,3f14.8,3x,"ref_cell_b2 =",3f14.8)') ref_at(:,2)*ref_alat,ref_bg(:,2)/ref_alat WRITE( stdout,'(3X,"ref_cell_a3 =",1X,3f14.8,3x,"ref_cell_b3 =",3f14.8)') ref_at(:,3)*ref_alat,ref_bg(:,3)/ref_alat ! ! CALL fft_type_init( dffts, smap, "wave", gamma_only, lpara, intra_bgrp_comm, ref_at, ref_bg, gkcut ) CALL fft_type_init( dfftp, smap, "rho", gamma_only, lpara, intra_bgrp_comm, ref_at, ref_bg, gcutm ) CALL fft_type_init( dfft3d, smap, "wave", gamma_only, .false., intra_bgrp_comm, ref_at, ref_bg, gkcut) ! ELSE ! CALL fft_type_init( dffts, smap, "wave", gamma_only, lpara, intra_bgrp_comm, at, bg, gkcut ) CALL fft_type_init( dfftp, smap, "rho", gamma_only, lpara, intra_bgrp_comm, at, bg, gcutm ) CALL fft_type_init( dfft3d, smap, "wave", gamma_only, .false., intra_bgrp_comm, at, bg, gkcut) ! END IF ! ! CALL smallbox_grid_init( dfftp, dfftb ) IF( ionode ) THEN WRITE( stdout,210) 210 format(/,3X,'unit vectors of full simulation cell',& &/,3X,'in real space:',25x,'in reciprocal space (units 2pi/alat):') WRITE( stdout,'(3X,I1,1X,3f10.4,10x,3f10.4)') 1,at(:,1)*alat,bg(:,1) WRITE( stdout,'(3X,I1,1X,3f10.4,10x,3f10.4)') 2,at(:,2)*alat,bg(:,2) WRITE( stdout,'(3X,I1,1X,3f10.4,10x,3f10.4)') 3,at(:,3)*alat,bg(:,3) END IF ! do i=1,3 ainv(1,i)=bg(i,1)/alat ainv(2,i)=bg(i,2)/alat ainv(3,i)=bg(i,3)/alat end do ! ! ainv is transformation matrix from cartesian to crystal coordinates ! if r=x1*a1+x2*a2+x3*a3 => x(i)=sum_j ainv(i,j)r(j) ! Note that ainv is really the inverse of a=(a1,a2,a3) ! (but only if the axis triplet is right-handed, otherwise ! for a left-handed triplet, ainv is minus the inverse of a) ! CALL task_groups_init( dffts, dtgs, ntask_groups ) CALL fft_base_info( ionode, stdout ) ngw_ = dffts%nwl( dffts%mype + 1 ) ngs_ = dffts%ngl( dffts%mype + 1 ) ngm_ = dfftp%ngl( dfftp%mype + 1 ) IF( gamma_only ) THEN ngw_ = (ngw_ + 1)/2 ngs_ = (ngs_ + 1)/2 ngm_ = (ngm_ + 1)/2 END IF ! ! ... Initialize reciprocal space local and global dimensions ! NOTE in a parallel run ngm_ , ngw_ , ngs_ here are the ! local number of reciprocal vectors ! CALL gvect_init ( ngm_ , intra_bgrp_comm ) CALL gvecs_init ( ngs_ , intra_bgrp_comm ) ! ! ... Print real-space grid dimensions ! CALL realspace_grids_info ( dfftp, dffts ) CALL smallbox_grid_info ( dfftb ) ! ! ... generate g-space vectors (dense and smooth grid) ! ... call to gshells generates gl, igtongl used in vdW-DF functional ! IF ( ref_cell ) THEN ! WRITE( stdout,'(/,3X,"Reference Cell is Used to Initialize Reciprocal Space Mesh")' ) WRITE( stdout,'(3X,"Reference Cell alat =",F14.8,1X,"A.U.")' ) ref_alat ! IF( smallmem ) THEN CALL ggen( gamma_only, ref_at, ref_bg, intra_bgrp_comm, no_global_sort = .TRUE. ) ELSE CALL ggen( gamma_only, ref_at, ref_bg ) END IF ! ELSE ! IF( smallmem ) THEN CALL ggen( gamma_only, at, bg, intra_bgrp_comm, no_global_sort = .TRUE. ) ELSE CALL ggen( gamma_only, at, bg ) END IF ! END IF CALL gshells (.TRUE.) ! ! ... allocate and generate (modified) kinetic energy ! CALL gvecw_init ( ngw_ , intra_bgrp_comm ) CALL g2kin_init ( gg, tpiba2 ) ! ! global arrays are no more needed ! if( allocated( mill_g ) ) deallocate( mill_g ) ! ! allocate spaces for phases e^{-iG*tau_s} ! allocate( eigts1(-dfftp%nr1:dfftp%nr1,nat) ) allocate( eigts2(-dfftp%nr2:dfftp%nr2,nat) ) allocate( eigts3(-dfftp%nr3:dfftp%nr3,nat) ) ! ! small boxes ! IF ( dfftb%nr1 > 0 .AND. dfftb%nr2 > 0 .AND. dfftb%nr3 > 0 ) THEN ! set the small box parameters rat1 = DBLE( dfftb%nr1 ) / DBLE( dfftp%nr1 ) rat2 = DBLE( dfftb%nr2 ) / DBLE( dfftp%nr2 ) rat3 = DBLE( dfftb%nr3 ) / DBLE( dfftp%nr3 ) ! CALL small_box_set( alat, omega, at, rat1, rat2, rat3, tprint = .TRUE. ) ! ! generate small-box G-vectors, initialize FFT tables ! CALL ggenb ( ecutrho, iverbosity ) ! #if defined __OPENMP CALL cft_b_omp_init( dfftb%nr1, dfftb%nr2, dfftb%nr3 ) #endif ELSE IF( okvan .OR. nlcc_any ) THEN CALL errore( ' init_dimensions ', ' nr1b, nr2b, nr3b must be given for ultrasoft and core corrected pp ', 1 ) END IF ! ... distribute bands CALL distribute_bands( nbgrp, my_bgrp_id ) ! ... printout g vector distribution summary ! CALL gmeshinfo() ! ! CALL cpsizes( ) Maybe useful ! ! Flush stdout ! FLUSH( stdout ) ! CALL stop_clock( 'init_dim' ) ! return end subroutine init_dimensions !----------------------------------------------------------------------- subroutine init_geometry ( ) !----------------------------------------------------------------------- ! USE kinds, ONLY: DP use control_flags, only: iprint, thdyn, ndr, nbeg, tbeg use io_global, only: stdout, ionode use mp_global, only: nproc_bgrp, me_bgrp, intra_bgrp_comm, root_bgrp USE io_files, ONLY: tmp_dir use ions_base, only: na, nsp, nat, tau_srt, ind_srt, if_pos use cell_base, only: at, alat, r_to_s, cell_init, deth use cell_base, only: ibrav, ainv, h, hold, tcell_base_init USE ions_positions, ONLY: allocate_ions_positions, tau0, taus use cp_restart, only: cp_read_cell USE fft_base, ONLY: dfftb USE fft_smallbox_type, ONLY: fft_box_allocate USE cp_main_variables,ONLY: ht0, htm, taub USE cp_interfaces, ONLY: newinit USE constants, ONLY: amu_au USE matrix_inversion implicit none ! ! local ! integer :: i, j real(DP) :: gvel(3,3), ht(3,3) real(DP) :: xnhh0(3,3), xnhhm(3,3), vnhh(3,3), velh(3,3) REAL(DP), ALLOCATABLE :: pmass(:), taus_srt( :, : ) IF( .NOT. tcell_base_init ) & CALL errore( ' init_geometry ', ' cell_base_init has not been call yet! ', 1 ) IF( ionode ) THEN WRITE( stdout, 100 ) 100 FORMAT( //, & 3X,'System geometry initialization',/, & 3X,'------------------------------' ) END IF ! Set ht0 and htm, cell at time t and t-dt ! CALL cell_init( alat, at, ht0 ) CALL cell_init( alat, at, htm ) CALL allocate_ions_positions( nsp, nat ) ! ! tau0 = initial positions, sorted wrt order read from input ! taus = initial positions, scaled with the cell read from input ! tau0(:,:) = tau_srt(:,:) CALL r_to_s( tau_srt, taus, na, nsp, ainv ) ! ! Allocate box descriptor ! ALLOCATE( taub( 3, nat ) ) ! CALL fft_box_allocate( dfftb, me_bgrp, root_bgrp, nproc_bgrp, intra_bgrp_comm, nat ) ! ! if tbeg = .true. the geometry is given in the standard input even if ! we are restarting a previous run ! if( ( nbeg > -1 ) .and. ( .not. tbeg ) ) then ! ! read only h and hold from restart file "ndr" ! CALL cp_read_cell( ndr, tmp_dir, .TRUE., ht, hold, velh, gvel, xnhh0, xnhhm, vnhh ) CALL cell_init( 't', ht0, ht ) CALL cell_init( 't', htm, hold ) ht0%hvel = velh ! set cell velocity ht0%gvel = gvel h = TRANSPOSE( ht ) ht = TRANSPOSE( hold ) hold = ht ht = TRANSPOSE( velh ) velh = ht ! BS ... additional printing hold WRITE(stdout, '(3X,"cell parameters read from restart file")') WRITE( stdout,344) ibrav WRITE(stdout, '(/,3X,"cell at current step : h(t)")') do i=1,3 WRITE( stdout,345) (h(i,j),j=1,3) enddo WRITE(stdout, '(/,3X,"cell at previous step : h(t-dt)")') do i=1,3 WRITE( stdout,345) (hold(i,j),j=1,3) enddo WRITE( stdout,*) else ! ! geometry is set to the cell parameters read from stdin ! WRITE(stdout, '(3X,"ibrav = ",i4," cell parameters read from input file")') ibrav do i = 1, 3 h(i,1) = at(i,1)*alat h(i,2) = at(i,2)*alat h(i,3) = at(i,3)*alat enddo hold = h end if ! ! generate true g-space ! call newinit( ht0%hmat, iverbosity = 1 ) ! CALL invmat( 3, h, ainv, deth ) ! 344 format(3X,'ibrav = ',i4,' cell parameters ',/) 345 format(3(4x,f10.5)) return end subroutine init_geometry !----------------------------------------------------------------------- subroutine newinit_x( h, iverbosity ) ! ! re-initialization of lattice parameters and g-space vectors. ! Note that direct and reciprocal lattice primitive vectors ! at, ainv, and corresponding quantities for small boxes ! are recalculated according to the value of cell parameter h ! USE kinds, ONLY : DP USE constants, ONLY : tpi USE cell_base, ONLY : at, bg, omega, alat, tpiba2, & cell_base_reinit USE gvecw, ONLY : g2kin_init USE gvect, ONLY : g, gg, ngm, mill USE fft_base, ONLY : dfftp, dfftb USE small_box, ONLY : small_box_set USE smallbox_subs, ONLY : gcalb USE io_global, ONLY : stdout, ionode ! implicit none ! REAL(DP), INTENT(IN) :: h(3,3) INTEGER, INTENT(IN) :: iverbosity ! REAL(DP) :: rat1, rat2, rat3 INTEGER :: ig, i1, i2, i3 ! !WRITE( stdout, "(4x,'h from newinit')" ) !do i=1,3 ! WRITE( stdout, '(3(4x,f12.7)' ) (h(i,j),j=1,3) !enddo ! ! re-initialize the cell base module with the new geometry ! CALL cell_base_reinit( TRANSPOSE( h ) ) ! ! re-calculate G-vectors and kinetic energy ! do ig=1,ngm i1=mill(1,ig) i2=mill(2,ig) i3=mill(3,ig) g(:,ig)=i1*bg(:,1)+i2*bg(:,2)+i3*bg(:,3) gg(ig)=g(1,ig)**2 + g(2,ig)**2 + g(3,ig)**2 enddo ! call g2kin_init ( gg, tpiba2 ) ! IF ( dfftb%nr1 == 0 .OR. dfftb%nr2 == 0 .OR. dfftb%nr3 == 0 ) RETURN ! ! generation of little box g-vectors ! rat1 = DBLE( dfftb%nr1 ) / DBLE( dfftp%nr1 ) rat2 = DBLE( dfftb%nr2 ) / DBLE( dfftp%nr2 ) rat3 = DBLE( dfftb%nr3 ) / DBLE( dfftp%nr3 ) CALL small_box_set( alat, omega, at, rat1, rat2, rat3, tprint = ( iverbosity > 0 ) ) ! call gcalb ( ) ! ! pass new cell parameters to plugins ! CALL plugin_init_cell( ) ! return end subroutine newinit_x SUBROUTINE realspace_grids_info ( dfftp, dffts ) ! Print info on local and global dimensions for real space grids USE fft_types, ONLY: fft_type_descriptor use io_global, only: stdout, ionode IMPLICIT NONE TYPE(fft_type_descriptor), INTENT(IN) :: dfftp, dffts INTEGER :: i IF(ionode) THEN WRITE( stdout,*) WRITE( stdout,*) ' Real Mesh' WRITE( stdout,*) ' ---------' WRITE( stdout,1000) dfftp%nr1, dfftp%nr2, dfftp%nr3, dfftp%nr1, dfftp%nr2, dfftp%npl, 1, 1, dfftp%nproc WRITE( stdout,1010) dfftp%nr1x, dfftp%nr2x, dfftp%nr3x WRITE( stdout,1020) dfftp%nnr WRITE( stdout,*) ' Number of x-y planes for each processors: ' WRITE( stdout, fmt = '( 3X, "nr3l = ", 10I5 )' ) & ( dfftp%npp( i ), i = 1, dfftp%nproc ) WRITE( stdout,*) WRITE( stdout,*) ' Smooth Real Mesh' WRITE( stdout,*) ' ----------------' WRITE( stdout,1000) dffts%nr1, dffts%nr2, dffts%nr3, dffts%nr1, dffts%nr2, dffts%npl,1,1, dfftp%nproc WRITE( stdout,1010) dffts%nr1x, dffts%nr2x, dffts%nr3x WRITE( stdout,1020) dffts%nnr WRITE( stdout,*) ' Number of x-y planes for each processors: ' WRITE( stdout, fmt = '( 3X, "nr3sl = ", 10I5 )' ) & ( dffts%npp( i ), i = 1, dfftp%nproc ) END IF 1000 FORMAT(3X, & 'Global Dimensions Local Dimensions Processor Grid',/,3X, & '.X. .Y. .Z. .X. .Y. .Z. .X. .Y. .Z.',/, & 3(1X,I5),2X,3(1X,I5),2X,3(1X,I5) ) 1010 FORMAT(3X, 'Array leading dimensions ( nr1x, nr2x, nr3x ) = ', 3(1X,I5)) 1020 FORMAT(3X, 'Local number of cell to store the grid ( nrxx ) = ', 1X, I9 ) RETURN END SUBROUTINE realspace_grids_info
gpl-2.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/TESTING/EIG/sbdt01.f
32
8309
*> \brief \b SBDT01 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE SBDT01( M, N, KD, A, LDA, Q, LDQ, D, E, PT, LDPT, WORK, * RESID ) * * .. Scalar Arguments .. * INTEGER KD, LDA, LDPT, LDQ, M, N * REAL RESID * .. * .. Array Arguments .. * REAL A( LDA, * ), D( * ), E( * ), PT( LDPT, * ), * $ Q( LDQ, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SBDT01 reconstructs a general matrix A from its bidiagonal form *> A = Q * B * P' *> where Q (m by min(m,n)) and P' (min(m,n) by n) are orthogonal *> matrices and B is bidiagonal. *> *> The test ratio to test the reduction is *> RESID = norm( A - Q * B * PT ) / ( n * norm(A) * EPS ) *> where PT = P' and EPS is the machine precision. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrices A and Q. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrices A and P'. *> \endverbatim *> *> \param[in] KD *> \verbatim *> KD is INTEGER *> If KD = 0, B is diagonal and the array E is not referenced. *> If KD = 1, the reduction was performed by xGEBRD; B is upper *> bidiagonal if M >= N, and lower bidiagonal if M < N. *> If KD = -1, the reduction was performed by xGBBRD; B is *> always upper bidiagonal. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is REAL array, dimension (LDA,N) *> The m by n matrix A. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[in] Q *> \verbatim *> Q is REAL array, dimension (LDQ,N) *> The m by min(m,n) orthogonal matrix Q in the reduction *> A = Q * B * P'. *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of the array Q. LDQ >= max(1,M). *> \endverbatim *> *> \param[in] D *> \verbatim *> D is REAL array, dimension (min(M,N)) *> The diagonal elements of the bidiagonal matrix B. *> \endverbatim *> *> \param[in] E *> \verbatim *> E is REAL array, dimension (min(M,N)-1) *> The superdiagonal elements of the bidiagonal matrix B if *> m >= n, or the subdiagonal elements of B if m < n. *> \endverbatim *> *> \param[in] PT *> \verbatim *> PT is REAL array, dimension (LDPT,N) *> The min(m,n) by n orthogonal matrix P' in the reduction *> A = Q * B * P'. *> \endverbatim *> *> \param[in] LDPT *> \verbatim *> LDPT is INTEGER *> The leading dimension of the array PT. *> LDPT >= max(1,min(M,N)). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (M+N) *> \endverbatim *> *> \param[out] RESID *> \verbatim *> RESID is REAL *> The test ratio: norm(A - Q * B * P') / ( n * norm(A) * EPS ) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup single_eig * * ===================================================================== SUBROUTINE SBDT01( M, N, KD, A, LDA, Q, LDQ, D, E, PT, LDPT, WORK, $ RESID ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER KD, LDA, LDPT, LDQ, M, N REAL RESID * .. * .. Array Arguments .. REAL A( LDA, * ), D( * ), E( * ), PT( LDPT, * ), $ Q( LDQ, * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) * .. * .. Local Scalars .. INTEGER I, J REAL ANORM, EPS * .. * .. External Functions .. REAL SASUM, SLAMCH, SLANGE EXTERNAL SASUM, SLAMCH, SLANGE * .. * .. External Subroutines .. EXTERNAL SCOPY, SGEMV * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN, REAL * .. * .. Executable Statements .. * * Quick return if possible * IF( M.LE.0 .OR. N.LE.0 ) THEN RESID = ZERO RETURN END IF * * Compute A - Q * B * P' one column at a time. * RESID = ZERO IF( KD.NE.0 ) THEN * * B is bidiagonal. * IF( KD.NE.0 .AND. M.GE.N ) THEN * * B is upper bidiagonal and M >= N. * DO 20 J = 1, N CALL SCOPY( M, A( 1, J ), 1, WORK, 1 ) DO 10 I = 1, N - 1 WORK( M+I ) = D( I )*PT( I, J ) + E( I )*PT( I+1, J ) 10 CONTINUE WORK( M+N ) = D( N )*PT( N, J ) CALL SGEMV( 'No transpose', M, N, -ONE, Q, LDQ, $ WORK( M+1 ), 1, ONE, WORK, 1 ) RESID = MAX( RESID, SASUM( M, WORK, 1 ) ) 20 CONTINUE ELSE IF( KD.LT.0 ) THEN * * B is upper bidiagonal and M < N. * DO 40 J = 1, N CALL SCOPY( M, A( 1, J ), 1, WORK, 1 ) DO 30 I = 1, M - 1 WORK( M+I ) = D( I )*PT( I, J ) + E( I )*PT( I+1, J ) 30 CONTINUE WORK( M+M ) = D( M )*PT( M, J ) CALL SGEMV( 'No transpose', M, M, -ONE, Q, LDQ, $ WORK( M+1 ), 1, ONE, WORK, 1 ) RESID = MAX( RESID, SASUM( M, WORK, 1 ) ) 40 CONTINUE ELSE * * B is lower bidiagonal. * DO 60 J = 1, N CALL SCOPY( M, A( 1, J ), 1, WORK, 1 ) WORK( M+1 ) = D( 1 )*PT( 1, J ) DO 50 I = 2, M WORK( M+I ) = E( I-1 )*PT( I-1, J ) + $ D( I )*PT( I, J ) 50 CONTINUE CALL SGEMV( 'No transpose', M, M, -ONE, Q, LDQ, $ WORK( M+1 ), 1, ONE, WORK, 1 ) RESID = MAX( RESID, SASUM( M, WORK, 1 ) ) 60 CONTINUE END IF ELSE * * B is diagonal. * IF( M.GE.N ) THEN DO 80 J = 1, N CALL SCOPY( M, A( 1, J ), 1, WORK, 1 ) DO 70 I = 1, N WORK( M+I ) = D( I )*PT( I, J ) 70 CONTINUE CALL SGEMV( 'No transpose', M, N, -ONE, Q, LDQ, $ WORK( M+1 ), 1, ONE, WORK, 1 ) RESID = MAX( RESID, SASUM( M, WORK, 1 ) ) 80 CONTINUE ELSE DO 100 J = 1, N CALL SCOPY( M, A( 1, J ), 1, WORK, 1 ) DO 90 I = 1, M WORK( M+I ) = D( I )*PT( I, J ) 90 CONTINUE CALL SGEMV( 'No transpose', M, M, -ONE, Q, LDQ, $ WORK( M+1 ), 1, ONE, WORK, 1 ) RESID = MAX( RESID, SASUM( M, WORK, 1 ) ) 100 CONTINUE END IF END IF * * Compute norm(A - Q * B * P') / ( n * norm(A) * EPS ) * ANORM = SLANGE( '1', M, N, A, LDA, WORK ) EPS = SLAMCH( 'Precision' ) * IF( ANORM.LE.ZERO ) THEN IF( RESID.NE.ZERO ) $ RESID = ONE / EPS ELSE IF( ANORM.GE.RESID ) THEN RESID = ( RESID / ANORM ) / ( REAL( N )*EPS ) ELSE IF( ANORM.LT.ONE ) THEN RESID = ( MIN( RESID, REAL( N )*ANORM ) / ANORM ) / $ ( REAL( N )*EPS ) ELSE RESID = MIN( RESID / ANORM, REAL( N ) ) / $ ( REAL( N )*EPS ) END IF END IF END IF * RETURN * * End of SBDT01 * END
bsd-3-clause
nvarini/espresso_iohpc
GWW/bse/sdescent.f90
8
3119
subroutine sdescent(i_state,vstatesd,vstate_rsd,cstate,cstate_r,fc,en) use exciton use bse_basic_structures USE fft_custom_gwl USE io_global, ONLY : stdout,ionode USE wvfct, ONLY : npw use bse_wannier, ONLY:num_nbndv,eps,lambda,eps_eig USE mp, ONLY :mp_barrier USE mp_world, ONLY : world_comm USE constants, ONLY: RYTOEV implicit none type(exc) :: a_in type(exc) :: a_out type(v_state) :: vstatesd type(v_state_r) :: vstate_rsd type(c_state) :: cstate type(c_state_r) :: cstate_r type(fft_cus) :: fc real(kind=DP), intent(out) :: en real(kind=DP) :: eigout real(kind=DP) :: eig real(kind=DP) ::delta,delta_eig,hsquare integer :: it,is,i,i_state call start_clock('sdescent') !create a random excitonic wavefunction vector a_exc !and normalize it call initialize_exc(a_in) a_in%label=50 a_in%npw=npw a_in%numb_v=num_nbndv(1) allocate(a_in%a(a_in%npw,a_in%numb_v)) call random_exc(a_in) !project into the conduction manifold do is = 1,vstatesd%nspin call pc_operator_exc(a_in,vstatesd,is) enddo !project out all the previous found state call pout_operator_exc(a_in,i_state) call normalize_exc(a_in) CALL mp_barrier(world_comm) call initialize_exc(a_out) a_out%label=1 a_out%npw=npw a_out%numb_v=num_nbndv(1) allocate(a_out%a(a_out%npw,a_out%numb_v)) eig=0.d0 eigout=100.d0 delta_eig=100.d0 delta=100.d0 if(ionode) write(stdout,*) 'Steepest descent started.' if(ionode) write(stdout,*) 'lambda=',lambda if(ionode) write(stdout,*) 'eps',eps it=0 !do while(((abs(delta))>=eps)) do while(((abs(delta))>=eps).or.(abs(delta_eig)>eps_eig)) ! write(*,*) 's descent, iteration, delta=',it,delta ! |a_out>=H|a_in> call exc_h_a(a_in,a_out,vstatesd,vstate_rsd,cstate,cstate_r,fc) call mp_barrier(world_comm) ! call normalize_exc(a_out) ! eigout= <psi_(it)|H|psi_(it)>/<psi_(it)|psi_(it)> call sproduct_exc(a_out,a_in,eigout) eigout=eigout*RYTOEV write(*,*) 'sd. eig# =',i_state, 'it=', it, 'E(eV)=', eigout ! check how good it is as an eigenstate call sproduct_exc(a_out,a_out,hsquare) hsquare=hsquare*RYTOEV*RYTOEV delta_eig=hsquare-eigout**2 eigout=eigout*RYTOEV ! compute |psi_(it+1)> a_out%a(1:a_out%npw,1:a_out%numb_v)=(1.d0+lambda*eigout)*a_in%a(1:a_in%npw,1:a_in%numb_v)& -lambda*a_out%a(1:a_out%npw,1:a_out%numb_v) !project into the conduction manifold do is = 1,vstatesd%nspin call pc_operator_exc(a_out,vstatesd,is) enddo !project out all the previous found state call pout_operator_exc(a_out,i_state) call normalize_exc(a_out) a_in%a(1:a_out%npw,1:a_out%numb_v)= a_out%a(1:a_out%npw,1:a_out%numb_v) call mp_barrier(world_comm) it=it+1 delta=eig-eigout eig=eigout enddo bse_spectrum(i_state)%a(1:bse_spectrum(i_state)%npw,1:bse_spectrum(i_state)%numb_v)=& a_out%a(1:a_out%npw,1:a_out%numb_v) bse_spectrum(i_state)%e=eigout en=eigout !if(ionode) write(stdout,*) 'Lowest eigenvalue=',eig !free memory call free_memory_exc_a(a_out) call free_memory_exc_a(a_in) call stop_clock('sdescent') return end subroutine sdescent
gpl-2.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/cgbtf2.f
24
8137
*> \brief \b CGBTF2 computes the LU factorization of a general band matrix using the unblocked version of the algorithm. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CGBTF2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgbtf2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgbtf2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgbtf2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CGBTF2( M, N, KL, KU, AB, LDAB, IPIV, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, KL, KU, LDAB, M, N * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX AB( LDAB, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CGBTF2 computes an LU factorization of a complex m-by-n band matrix *> A using partial pivoting with row interchanges. *> *> This is the unblocked version of the algorithm, calling Level 2 BLAS. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] KL *> \verbatim *> KL is INTEGER *> The number of subdiagonals within the band of A. KL >= 0. *> \endverbatim *> *> \param[in] KU *> \verbatim *> KU is INTEGER *> The number of superdiagonals within the band of A. KU >= 0. *> \endverbatim *> *> \param[in,out] AB *> \verbatim *> AB is COMPLEX array, dimension (LDAB,N) *> On entry, the matrix A in band storage, in rows KL+1 to *> 2*KL+KU+1; rows 1 to KL of the array need not be set. *> The j-th column of A is stored in the j-th column of the *> array AB as follows: *> AB(kl+ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl) *> *> On exit, details of the factorization: U is stored as an *> upper triangular band matrix with KL+KU superdiagonals in *> rows 1 to KL+KU+1, and the multipliers used during the *> factorization are stored in rows KL+KU+2 to 2*KL+KU+1. *> See below for further details. *> \endverbatim *> *> \param[in] LDAB *> \verbatim *> LDAB is INTEGER *> The leading dimension of the array AB. LDAB >= 2*KL+KU+1. *> \endverbatim *> *> \param[out] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (min(M,N)) *> The pivot indices; for 1 <= i <= min(M,N), row i of the *> matrix was interchanged with row IPIV(i). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = +i, U(i,i) is exactly zero. The factorization *> has been completed, but the factor U is exactly *> singular, and division by zero will occur if it is used *> to solve a system of equations. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complexGBcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The band storage scheme is illustrated by the following example, when *> M = N = 6, KL = 2, KU = 1: *> *> On entry: On exit: *> *> * * * + + + * * * u14 u25 u36 *> * * + + + + * * u13 u24 u35 u46 *> * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 *> a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 *> a21 a32 a43 a54 a65 * m21 m32 m43 m54 m65 * *> a31 a42 a53 a64 * * m31 m42 m53 m64 * * *> *> Array elements marked * are not used by the routine; elements marked *> + need not be set on entry, but are required by the routine to store *> elements of U, because of fill-in resulting from the row *> interchanges. *> \endverbatim *> * ===================================================================== SUBROUTINE CGBTF2( M, N, KL, KU, AB, LDAB, IPIV, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INFO, KL, KU, LDAB, M, N * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX AB( LDAB, * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX ONE, ZERO PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ), $ ZERO = ( 0.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. INTEGER I, J, JP, JU, KM, KV * .. * .. External Functions .. INTEGER ICAMAX EXTERNAL ICAMAX * .. * .. External Subroutines .. EXTERNAL CGERU, CSCAL, CSWAP, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * * KV is the number of superdiagonals in the factor U, allowing for * fill-in. * KV = KU + KL * * Test the input parameters. * INFO = 0 IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( KL.LT.0 ) THEN INFO = -3 ELSE IF( KU.LT.0 ) THEN INFO = -4 ELSE IF( LDAB.LT.KL+KV+1 ) THEN INFO = -6 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CGBTF2', -INFO ) RETURN END IF * * Quick return if possible * IF( M.EQ.0 .OR. N.EQ.0 ) $ RETURN * * Gaussian elimination with partial pivoting * * Set fill-in elements in columns KU+2 to KV to zero. * DO 20 J = KU + 2, MIN( KV, N ) DO 10 I = KV - J + 2, KL AB( I, J ) = ZERO 10 CONTINUE 20 CONTINUE * * JU is the index of the last column affected by the current stage * of the factorization. * JU = 1 * DO 40 J = 1, MIN( M, N ) * * Set fill-in elements in column J+KV to zero. * IF( J+KV.LE.N ) THEN DO 30 I = 1, KL AB( I, J+KV ) = ZERO 30 CONTINUE END IF * * Find pivot and test for singularity. KM is the number of * subdiagonal elements in the current column. * KM = MIN( KL, M-J ) JP = ICAMAX( KM+1, AB( KV+1, J ), 1 ) IPIV( J ) = JP + J - 1 IF( AB( KV+JP, J ).NE.ZERO ) THEN JU = MAX( JU, MIN( J+KU+JP-1, N ) ) * * Apply interchange to columns J to JU. * IF( JP.NE.1 ) $ CALL CSWAP( JU-J+1, AB( KV+JP, J ), LDAB-1, $ AB( KV+1, J ), LDAB-1 ) IF( KM.GT.0 ) THEN * * Compute multipliers. * CALL CSCAL( KM, ONE / AB( KV+1, J ), AB( KV+2, J ), 1 ) * * Update trailing submatrix within the band. * IF( JU.GT.J ) $ CALL CGERU( KM, JU-J, -ONE, AB( KV+2, J ), 1, $ AB( KV, J+1 ), LDAB-1, AB( KV+1, J+1 ), $ LDAB-1 ) END IF ELSE * * If pivot is zero, set INFO to the index of the pivot * unless a zero pivot has already been found. * IF( INFO.EQ.0 ) $ INFO = J END IF 40 CONTINUE RETURN * * End of CGBTF2 * END
bsd-3-clause
nvarini/espresso_iohpc
GWW/gww/para_gww.f90
12
3927
! ! Copyright (C) 2001-2013 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 . ! ! MODULE para_gww !this modules contains arrays indicating if the !processor should perform the task SAVE LOGICAL, ALLOCATABLE :: is_my_time(:) !for 2n+1 times and frequencies LOGICAL :: is_my_last!for extra 0 time calculation LOGICAL, ALLOCATABLE :: is_my_pola(:) !for 0 to n calculations LOGICAL, ALLOCATABLE :: is_my_state(:)!for KS states considered 1 to n_max LOGICAL, ALLOCATABLE :: is_my_state_range(:)!for KS states considered i_min to i_max CONTAINS subroutine free_memory_para_gww implicit none if(allocated(is_my_time)) deallocate(is_my_time) if(allocated(is_my_pola)) deallocate(is_my_pola) if(allocated(is_my_state)) deallocate(is_my_state) if(allocated(is_my_state_range)) deallocate(is_my_state_range) return end subroutine free_memory_para_gww SUBROUTINE setup_para_gww(ntimes,nstates, i_min, i_max) !this subroutine initialize the para variables for the gww !calculation, parallelization is achieved on imaginary times !and frequencies USE mp_world, ONLY : mpime, nproc USE io_global, ONLY : stdout implicit none INTEGER, INTENT(in) :: ntimes!number of time samples INTEGER, INTENT(in) :: nstates!max number of states INTEGER, INTENT(in) :: i_min!lowest state for which the self-energy is calculated INTEGER, INTENT(in) :: i_max!upper state for which the self-energy is calculated INTEGER :: ndelta, it, ip, iqq !allocates arrays allocate(is_my_time(-ntimes:ntimes)) allocate(is_my_pola(0:ntimes)) allocate(is_my_state(nstates)) allocate(is_my_state_range(i_min:i_max)) is_my_time(:)=.false. is_my_pola(:)=.false. is_my_state(:)=.false. is_my_state_range(:)=.false. ndelta=(2*ntimes+1)/nproc if(ndelta*nproc < (2*ntimes+1)) ndelta=ndelta+1 iqq=-ntimes do ip=0,nproc-1 do it=1,ndelta if(iqq <= ntimes.and.(mpime==ip)) then is_my_time(iqq)=.true. endif if(it==1.and.(mpime==ip)) write(stdout,*) 'min', iqq, ip,it,ndelta if(it==ndelta.and.(mpime==ip)) write(stdout,*) 'max', iqq, ip,it,ndelta iqq=iqq+1 enddo enddo if((mpime+1)==nproc) then is_my_last=.true. else is_my_last=.false. endif ndelta=(ntimes+1)/nproc if(ndelta*nproc < (ntimes+1)) ndelta=ndelta+1 iqq=0 do ip=0,nproc-1 do it=1,ndelta if(iqq <= ntimes.and.(mpime==ip)) then is_my_pola(iqq)=.true. endif if(it==1.and.(mpime==ip)) write(stdout,*) 'min pola', iqq if(it==ndelta.and.(mpime==ip)) write(stdout,*) 'max pola', iqq iqq=iqq+1 enddo enddo ndelta=(nstates)/nproc if(ndelta*nproc < nstates) ndelta=ndelta+1 iqq=1 do ip=0,nproc-1 do it=1,ndelta if(iqq <= nstates.and.(mpime==ip)) then is_my_state(iqq)=.true. endif if(it==1.and.(mpime==ip)) write(stdout,*) 'min state', iqq if(it==ndelta.and.(mpime==ip)) write(stdout,*) 'max state', iqq iqq=iqq+1 enddo enddo ndelta=(i_max-i_min+1)/nproc if(ndelta*nproc < (i_max-i_min+1)) ndelta=ndelta+1 iqq=1 do ip=0,nproc-1 do it=1,ndelta if(iqq <= (i_max-i_min+1).and.(mpime==ip)) then is_my_state_range(iqq+i_min-1)=.true. endif if(it==1.and.(mpime==ip)) write(stdout,*) 'min state range', iqq +i_min-1 if(it==ndelta.and.(mpime==ip)) write(stdout,*) 'max state range', iqq+i_min-1 iqq=iqq+1 enddo enddo return END SUBROUTINE setup_para_gww END MODULE para_gww
gpl-2.0
buaasun/grappa
applications/NPB/OMP/UA/verify.f
10
2498
subroutine verify(class, verified) include 'header.h' double precision norm, calc_norm, epsilon, norm_dif, norm_ref external calc_norm character class logical verified c.....tolerance level epsilon = 1.0d-08 c.....compute the temperature integral over the whole domain norm = calc_norm() verified = .true. if ( class .eq. 'S' ) then norm_ref = 0.1890013110962D-02 elseif ( class .eq. 'W' ) then norm_ref = 0.2569794837076D-04 elseif ( class .eq. 'A' ) then norm_ref = 0.8939996281443D-04 elseif ( class .eq. 'B' ) then norm_ref = 0.4507561922901D-04 elseif ( class .eq. 'C' ) then norm_ref = 0.1544736587100D-04 elseif ( class .eq. 'D' ) then norm_ref = 0.1577586272355D-05 else class = 'U' norm_ref = 1.d0 verified = .false. endif norm_dif = dabs((norm - norm_ref)/norm_ref) c--------------------------------------------------------------------- c Output the comparison of computed results to known cases. c--------------------------------------------------------------------- print * if (class .ne. 'U') then write(*, 1990) class 1990 format(' Verification being performed for class ', a) write (*,2000) epsilon 2000 format(' accuracy setting for epsilon = ', E20.13) else write(*, 1995) 1995 format(' Unknown class') endif if (class .ne. 'U') then write (*,2001) else write (*, 2005) endif 2001 format(' Comparison of temperature integrals') 2005 format(' Temperature integral') if (class .eq. 'U') then write(*, 2015) norm else if (norm_dif .le. epsilon) then write (*,2011) norm, norm_ref, norm_dif else verified = .false. write (*,2010) norm, norm_ref, norm_dif endif 2010 format(' FAILURE: ', E20.13, E20.13, E20.13) 2011 format(' ', E20.13, E20.13, E20.13) 2015 format(' ', E20.13) if (class .eq. 'U') then write(*, 2022) write(*, 2023) 2022 format(' No reference values provided') 2023 format(' No verification performed') else if (verified) then write(*, 2020) 2020 format(' Verification Successful') else write(*, 2021) 2021 format(' Verification failed') endif return end
bsd-3-clause
nvarini/espresso_iohpc
PHonon/D3/d3_setup.f90
1
10812
! ! Copyright (C) 2001-2008 Quantm-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 d3_setup() !----------------------------------------------------------------------- ! ! This subroutine prepares several variables which are needed in the ! d3toten program: ! 1) computes the total local potential (external+scf) on the smoot ! grid to be used in h_psi and similia ! 2) computes dmuxc 3.1) with GC if needed ! 3) for metals sets the occupated bands ! 4) computes alpha_pv ! 5.1) computes the variables needed to pass to the pattern representat ! of the small group of q ! u the patterns ! t the matrices of the small group of q on the pattern basis ! tmq the matrix of the symmetry which sends q -> -q + G ! gi the G associated to each symmetry operation ! gimq the G of the q -> -q+G symmetry ! irgq the small group indices ! nsymq the order of the small group of q ! irotmq the index of the q->-q+G symmetry ! nirr the number of irreducible representation ! npert the dimension of each irreducible representation ! nmodes the number of modes ! minus_q true if there is a symmetry sending q -> -q+G ! 5.2) computes the variables needed to pass to the pattern representat ! of the group of the crystal ! ug0 the patterns ! tg0 the matrices of the group on the pattern basis ! nsymg0 the order of the group of the crystal ! nirrg0 the number of irreducible representation ! npertg0 the dimension of each irreducible representation ! 6) set the variables needed to deal with nlcc ! 7) set the variables needed to distribute one loop between pools ! 8) set the variables needed to calculate only selected q=0 modes ! USE ions_base, ONLY : nat, ityp, ntyp => nsp, tau USE io_global, ONLY : stdout, ionode, ionode_id USE io_files, ONLY : tmp_dir USE kinds, ONLY : DP USE pwcom USE fft_base, ONLY : dfftp USE scf, only : rho, rho_core, v, vltot, vrs, kedtau USE symm_base, ONLY : nrot, nsym, s, ftau, irt, invs, inverse_s, & s_axis_to_cart, find_sym, copy_sym, s_axis_to_cart USE uspp_param, ONLY : upf USE uspp, ONLY : nlcc_any USE control_flags, ONLY : iverbosity, modenum USE constants, ONLY : degspin USE qpoint, ONLY : xq, ikks, ikqs, nksq USE phcom USE d3com, ONLY : q0mode, wrmode, nsymg0, npertg0, nirrg0, & npert_i, npert_f, q0mode_todo, allmodes, ug0, & fild0rho USE mp_global, ONLY : npool, my_pool_id, inter_pool_comm, intra_image_comm USE mp, ONLY : mp_max, mp_min, mp_bcast USE funct, ONLY : dmxc, dmxc_spin USE lr_symm_base, ONLY : nsymq, irotmq, irgq, gi, gimq, minus_q, rtau USE control_lr, ONLY : alpha_pv, nbnd_occ, lgamma ! IMPLICIT NONE ! REAL (DP) :: rhotot, rhoup, rhodw, TARGET, small, fac, xmax, emin, & emax, wrk, xqck(3) ! total charge ! total up charge ! total down charge ! auxiliary variables used ! to set nbnd_occ in the metallic case ! minimum band energy ! maximum band energy ! working array INTEGER :: ir, isym, jsym, iinv, irot, jrot, ik, & ibnd, ipol, mu, nu, imode0, irr, ipert, nt, ii, nu_i ! counters LOGICAL :: sym (48), magnetic_sym ! the symmetry operations REAL (DP) :: mdum(3) CHARACTER(LEN=256) :: tmp_dir_save #ifdef __MPI INTEGER :: nlength_w, nlength (npool), nresto #endif CALL start_clock ('d3_setup') ! ! 1) Computes the total local potential (external+scf) on the smoot grid ! CALL set_vrs (vrs, vltot, v%of_r, kedtau, v%kin_r, dfftp%nnr, nspin, doublegrid) ! ! 2) Computes the derivative of the xc potential ! dmuxc (:,:,:) = 0.d0 IF (lsda) THEN DO ir = 1, dfftp%nnr rhoup = rho%of_r (ir, 1) + 0.5d0 * rho_core (ir) rhodw = rho%of_r (ir, 2) + 0.5d0 * rho_core (ir) CALL dmxc_spin (rhoup, rhodw, dmuxc (ir, 1, 1), & dmuxc (ir, 2, 1), dmuxc (ir, 1, 2), dmuxc (ir, 2, 2) ) ENDDO ELSE DO ir = 1, dfftp%nnr rhotot = rho%of_r (ir, nspin) + rho_core (ir) IF (rhotot > 1.d-30) dmuxc (ir, 1, 1) = dmxc (rhotot) IF (rhotot < - 1.d-30) dmuxc (ir, 1, 1) = - dmxc ( - rhotot) ENDDO ENDIF ! ! 3) Computes the number of occupated bands for each k point ! call setup_nbnd_occ() ! ! 4) Computes alpha_pv ! emin = et (1, 1) DO ik = 1, nks DO ibnd = 1, nbnd emin = MIN (emin, et (ibnd, ik) ) ENDDO ENDDO ! find the minimum across pools CALL mp_min( emin, inter_pool_comm ) emax = et (1, 1) DO ik = 1, nks DO ibnd = 1, nbnd emax = MAX (emax, et (ibnd, ik) ) ENDDO ENDDO ! find the maximum across pools CALL mp_max( emax, inter_pool_comm ) alpha_pv = 2.d0 * (emax - emin) ! avoid zero value for alpha_pv alpha_pv = MAX (alpha_pv, 1.0d-2) ! ! 5) set all the variables needed to use the pattern representation ! ! 5.0) Computes the inverse of each matrix ! ! TEMP TEMP TEMP TEMP: this should not be needed any longer ! modenum = 0 magnetic_sym = .false. CALL find_sym ( nat, tau, ityp, dfftp%nr1, dfftp%nr2, dfftp%nr3, & magnetic_sym, mdum ) sym(:) =.false. sym(1:nsym)=.true. ! ! Here we re-order all rotations in such a way that true sym.ops. ! are the first nsymq; rotations that are not sym.ops. follow ! call smallg_q (xq, modenum, at, bg, nsym, s, ftau, sym, minus_q) nsymq = copy_sym ( nsym, sym ) ! nsymg0 = nsym CALL inverse_s ( ) CALL s_axis_to_cart ( ) nsym = nsymq ! ! the first nsymq matrices are symmetries of the small group of q ! ! 5.1) Finds the variables needeed for the pattern representation ! of the small group of q ! sym(1:nsymg0)=.true. CALL sgam_ph (at, bg, nsymg0, s, irt, tau, rtau, nat, sym) nmodes = 3 * nat ! if minus_q=.t. set_irr will search for ! Sq=-q+G symmetry. On output minus_q=.t. ! if such a symmetry has been found minus_q = (modenum .eq. 0) ! ! BEWARE: In set_irr, smallgq is called ! ! FIXME: workaround for filename mess - needed to find where ! the patterns are tmp_dir_save=tmp_dir if ( lgamma ) tmp_dir=TRIM(tmp_dir)//'_ph0/' ! FIXME END IF (modenum .ne. 0) THEN npertx=1 CALL allocate_pert_d3() CALL set_irr_mode (nat, at, bg, xq, s, invs, nsym, rtau, irt, & irgq, nsymq, minus_q, irotmq, t, tmq, npertx, u, & npert, nirr, gi, gimq, iverbosity, modenum) ELSE IF(ionode) CALL io_pattern ( nat, fildrho, nirr, npert, u, xqck, tmp_dir, -1 ) call mp_bcast(u, ionode_id, intra_image_comm) call mp_bcast(nirr, ionode_id, intra_image_comm) call mp_bcast(npert, ionode_id, intra_image_comm) call mp_bcast(xqck, ionode_id, intra_image_comm) IF(SUM(ABS(xqck(:)-xq(:))) > 1.d-4) CALL errore('d3_setup', 'Wrong drho for q', 1) npertx = 0 DO irr = 1, nirr npertx = max (npertx, npert (irr) ) ENDDO IF (.not.lgamma) THEN IF(ionode) call io_pattern ( nat, fild0rho, nirrg0, npertg0, ug0, xqck, tmp_dir, -1 ) call mp_bcast(ug0, ionode_id, intra_image_comm) call mp_bcast(nirrg0, ionode_id, intra_image_comm) call mp_bcast(npertg0, ionode_id, intra_image_comm) call mp_bcast(xqck, ionode_id, intra_image_comm) IF(SUM(ABS(xqck(:))) > 1.d-4) CALL errore('d3_setup', 'Wrong drho for Gamma', 2) DO irr = 1, nirrg0 npertx = max (npertx, npertg0 (irr) ) ENDDO ENDIF CALL allocate_pert_d3() CALL set_sym_irr (nat, at, bg, xq, s, invs, nsym, rtau, irt, & irgq, nsymq, minus_q, irotmq, t, tmq, npertx, u, & npert, nirr, gi, gimq, iverbosity) ENDIF IF ( lgamma ) THEN ! nksq = nks ALLOCATE(ikks(nksq), ikqs(nksq)) DO ik=1,nksq ikks(ik) = ik ikqs(ik) = ik ENDDO ! ELSE ! nksq = nks / 2 ALLOCATE(ikks(nksq), ikqs(nksq)) DO ik=1,nksq ikks(ik) = 2 * ik - 1 ikqs(ik) = 2 * ik ENDDO ! END IF ! ! 5.2) Finds the variables needeed for the pattern representation ! of the small group of the crystal ! IF (lgamma) THEN nirrg0 = nirr ELSE ! ! Calculates the variables need for the pattern representation ! for the q=0 symmetries ! CALL set_d3irr ( ) ! ENDIF ! ! FIXME: workaround for filename mess - needed to find where ! the patterns are tmp_dir=tmp_dir_save ! FIXME END npertx = 0 do irr = 1, nirr npertx = max (npertx, npert (irr) ) enddo do irr = 1, nirrg0 npertx = max (npertx, npertg0 (irr) ) enddo ! ! 6) Set non linear core correction stuff ! nlcc_any = ANY ( upf(1:ntyp)%nlcc ) ! IF (nlcc_any) ALLOCATE (drc( ngm, ntyp)) ! ! 7) Sets up variables needed to distribute one loop between pools ! npert_i = 1 npert_f = 3 * nat #ifdef __MPI nlength_w = (3 * nat) / npool nresto = 3 * nat - nlength_w * npool DO ii = 1, npool IF (ii <= nresto) THEN nlength (ii) = nlength_w + 1 ELSE nlength (ii) = nlength_w ENDIF ENDDO npert_i = 1 DO ii = 1, my_pool_id npert_i = npert_i + nlength (ii) ENDDO npert_f = npert_i - 1 + nlength (my_pool_id+1) #endif ! ! 8) Sets up variables needed to calculate only selected ! modes at q=0 --the first index of the third order matrix-- ! IF (q0mode_todo (1) <= 0) THEN DO ii = 1, 3 * nat q0mode (ii) = .TRUE. ENDDO ELSE DO ii = 1, 3 * nat q0mode (ii) = .FALSE. ENDDO ii = 1 DO WHILE (q0mode_todo (ii) > 0) q0mode (q0mode_todo (ii) ) = .TRUE. ii = ii + 1 ENDDO ENDIF ! ! if you want to compute all the modes; and lgamma=.true. ! the calculation can be simplyfied, in this case allmodes ! is set .true. ! allmodes = lgamma .AND. (q0mode_todo (1) <= 0) ! ! Sets up variables needed to write only selected ! modes at q=0 --the first index of the third order matrix-- ! DO ii = 1, 3 * nat wrk = 0.d0 DO nu_i = 1, 3 * nat IF (q0mode (nu_i) ) THEN wrk = wrk + ug0 (ii, nu_i) * CONJG (ug0 (ii, nu_i) ) ENDIF ENDDO wrmode (ii) = .FALSE. IF (wrk > 1.d-8) wrmode (ii) = .TRUE. ENDDO CALL stop_clock ('d3_setup') RETURN END SUBROUTINE d3_setup
gpl-2.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/cla_gbrpvgrw.f
24
4971
*> \brief \b CLA_GBRPVGRW computes the reciprocal pivot growth factor norm(A)/norm(U) for a general banded matrix. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CLA_GBRPVGRW + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cla_gbrpvgrw.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cla_gbrpvgrw.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cla_gbrpvgrw.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * REAL FUNCTION CLA_GBRPVGRW( N, KL, KU, NCOLS, AB, LDAB, AFB, * LDAFB ) * * .. Scalar Arguments .. * INTEGER N, KL, KU, NCOLS, LDAB, LDAFB * .. * .. Array Arguments .. * COMPLEX AB( LDAB, * ), AFB( LDAFB, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CLA_GBRPVGRW computes the reciprocal pivot growth factor *> norm(A)/norm(U). The "max absolute element" norm is used. If this is *> much less than 1, the stability of the LU factorization of the *> (equilibrated) matrix A could be poor. This also means that the *> solution X, estimated condition numbers, and error bounds could be *> unreliable. *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The number of linear equations, i.e., the order of the *> matrix A. N >= 0. *> \endverbatim *> *> \param[in] KL *> \verbatim *> KL is INTEGER *> The number of subdiagonals within the band of A. KL >= 0. *> \endverbatim *> *> \param[in] KU *> \verbatim *> KU is INTEGER *> The number of superdiagonals within the band of A. KU >= 0. *> \endverbatim *> *> \param[in] NCOLS *> \verbatim *> NCOLS is INTEGER *> The number of columns of the matrix A. NCOLS >= 0. *> \endverbatim *> *> \param[in] AB *> \verbatim *> AB is COMPLEX array, dimension (LDAB,N) *> On entry, the matrix A in band storage, in rows 1 to KL+KU+1. *> The j-th column of A is stored in the j-th column of the *> array AB as follows: *> AB(KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+kl) *> \endverbatim *> *> \param[in] LDAB *> \verbatim *> LDAB is INTEGER *> The leading dimension of the array AB. LDAB >= KL+KU+1. *> \endverbatim *> *> \param[in] AFB *> \verbatim *> AFB is COMPLEX array, dimension (LDAFB,N) *> Details of the LU factorization of the band matrix A, as *> computed by CGBTRF. U is stored as an upper triangular *> band matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, *> and the multipliers used during the factorization are stored *> in rows KL+KU+2 to 2*KL+KU+1. *> \endverbatim *> *> \param[in] LDAFB *> \verbatim *> LDAFB is INTEGER *> The leading dimension of the array AFB. LDAFB >= 2*KL+KU+1. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complexGBcomputational * * ===================================================================== REAL FUNCTION CLA_GBRPVGRW( N, KL, KU, NCOLS, AB, LDAB, AFB, $ LDAFB ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER N, KL, KU, NCOLS, LDAB, LDAFB * .. * .. Array Arguments .. COMPLEX AB( LDAB, * ), AFB( LDAFB, * ) * .. * * ===================================================================== * * .. Local Scalars .. INTEGER I, J, KD REAL AMAX, UMAX, RPVGRW COMPLEX ZDUM * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN, REAL, AIMAG * .. * .. Statement Functions .. REAL CABS1 * .. * .. Statement Function Definitions .. CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) ) * .. * .. Executable Statements .. * RPVGRW = 1.0 KD = KU + 1 DO J = 1, NCOLS AMAX = 0.0 UMAX = 0.0 DO I = MAX( J-KU, 1 ), MIN( J+KL, N ) AMAX = MAX( CABS1( AB( KD+I-J, J ) ), AMAX ) END DO DO I = MAX( J-KU, 1 ), J UMAX = MAX( CABS1( AFB( KD+I-J, J ) ), UMAX ) END DO IF ( UMAX /= 0.0 ) THEN RPVGRW = MIN( AMAX / UMAX, RPVGRW ) END IF END DO CLA_GBRPVGRW = RPVGRW END
bsd-3-clause
james-monkeyshines/rna-phase-3
lapack/dgesvd.f
14
134664
SUBROUTINE DGESVD( JOBU, JOBVT, M, N, A, LDA, S, U, LDU, VT, LDVT, $ WORK, LWORK, INFO ) * * -- LAPACK driver routine (version 3.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * October 31, 1999 * * .. Scalar Arguments .. CHARACTER JOBU, JOBVT INTEGER INFO, LDA, LDU, LDVT, LWORK, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), S( * ), U( LDU, * ), $ VT( LDVT, * ), WORK( * ) * .. * * Purpose * ======= * * DGESVD computes the singular value decomposition (SVD) of a real * M-by-N matrix A, optionally computing the left and/or right singular * vectors. The SVD is written * * A = U * SIGMA * transpose(V) * * where SIGMA is an M-by-N matrix which is zero except for its * min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and * V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA * are the singular values of A; they are real and non-negative, and * are returned in descending order. The first min(m,n) columns of * U and V are the left and right singular vectors of A. * * Note that the routine returns V**T, not V. * * Arguments * ========= * * JOBU (input) CHARACTER*1 * Specifies options for computing all or part of the matrix U: * = 'A': all M columns of U are returned in array U: * = 'S': the first min(m,n) columns of U (the left singular * vectors) are returned in the array U; * = 'O': the first min(m,n) columns of U (the left singular * vectors) are overwritten on the array A; * = 'N': no columns of U (no left singular vectors) are * computed. * * JOBVT (input) CHARACTER*1 * Specifies options for computing all or part of the matrix * V**T: * = 'A': all N rows of V**T are returned in the array VT; * = 'S': the first min(m,n) rows of V**T (the right singular * vectors) are returned in the array VT; * = 'O': the first min(m,n) rows of V**T (the right singular * vectors) are overwritten on the array A; * = 'N': no rows of V**T (no right singular vectors) are * computed. * * JOBVT and JOBU cannot both be 'O'. * * M (input) INTEGER * The number of rows of the input matrix A. M >= 0. * * N (input) INTEGER * The number of columns of the input matrix A. N >= 0. * * A (input/output) DOUBLE PRECISION array, dimension (LDA,N) * On entry, the M-by-N matrix A. * On exit, * if JOBU = 'O', A is overwritten with the first min(m,n) * columns of U (the left singular vectors, * stored columnwise); * if JOBVT = 'O', A is overwritten with the first min(m,n) * rows of V**T (the right singular vectors, * stored rowwise); * if JOBU .ne. 'O' and JOBVT .ne. 'O', the contents of A * are destroyed. * * LDA (input) INTEGER * The leading dimension of the array A. LDA >= max(1,M). * * S (output) DOUBLE PRECISION array, dimension (min(M,N)) * The singular values of A, sorted so that S(i) >= S(i+1). * * U (output) DOUBLE PRECISION array, dimension (LDU,UCOL) * (LDU,M) if JOBU = 'A' or (LDU,min(M,N)) if JOBU = 'S'. * If JOBU = 'A', U contains the M-by-M orthogonal matrix U; * if JOBU = 'S', U contains the first min(m,n) columns of U * (the left singular vectors, stored columnwise); * if JOBU = 'N' or 'O', U is not referenced. * * LDU (input) INTEGER * The leading dimension of the array U. LDU >= 1; if * JOBU = 'S' or 'A', LDU >= M. * * VT (output) DOUBLE PRECISION array, dimension (LDVT,N) * If JOBVT = 'A', VT contains the N-by-N orthogonal matrix * V**T; * if JOBVT = 'S', VT contains the first min(m,n) rows of * V**T (the right singular vectors, stored rowwise); * if JOBVT = 'N' or 'O', VT is not referenced. * * LDVT (input) INTEGER * The leading dimension of the array VT. LDVT >= 1; if * JOBVT = 'A', LDVT >= N; if JOBVT = 'S', LDVT >= min(M,N). * * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) * On exit, if INFO = 0, WORK(1) returns the optimal LWORK; * if INFO > 0, WORK(2:MIN(M,N)) contains the unconverged * superdiagonal elements of an upper bidiagonal matrix B * whose diagonal is in S (not necessarily sorted). B * satisfies A = U * B * VT, so it has the same singular values * as A, and singular vectors related by U and VT. * * LWORK (input) INTEGER * The dimension of the array WORK. LWORK >= 1. * LWORK >= MAX(3*MIN(M,N)+MAX(M,N),5*MIN(M,N)). * For good performance, LWORK should generally be larger. * * 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. * * INFO (output) INTEGER * = 0: successful exit. * < 0: if INFO = -i, the i-th argument had an illegal value. * > 0: if DBDSQR did not converge, INFO specifies how many * superdiagonals of an intermediate bidiagonal form B * did not converge to zero. See the description of WORK * above for details. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 ) * .. * .. Local Scalars .. LOGICAL LQUERY, WNTUA, WNTUAS, WNTUN, WNTUO, WNTUS, $ WNTVA, WNTVAS, WNTVN, WNTVO, WNTVS INTEGER BDSPAC, BLK, CHUNK, I, IE, IERR, IR, ISCL, $ ITAU, ITAUP, ITAUQ, IU, IWORK, LDWRKR, LDWRKU, $ MAXWRK, MINMN, MINWRK, MNTHR, NCU, NCVT, NRU, $ NRVT, WRKBL DOUBLE PRECISION ANRM, BIGNUM, EPS, SMLNUM * .. * .. Local Arrays .. DOUBLE PRECISION DUM( 1 ) * .. * .. External Subroutines .. EXTERNAL DBDSQR, DGEBRD, DGELQF, DGEMM, DGEQRF, DLACPY, $ DLASCL, DLASET, DORGBR, DORGLQ, DORGQR, DORMBR, $ XERBLA * .. * .. External Functions .. LOGICAL LSAME INTEGER ILAENV DOUBLE PRECISION DLAMCH, DLANGE EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN, SQRT * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 MINMN = MIN( M, N ) MNTHR = ILAENV( 6, 'DGESVD', JOBU // JOBVT, M, N, 0, 0 ) WNTUA = LSAME( JOBU, 'A' ) WNTUS = LSAME( JOBU, 'S' ) WNTUAS = WNTUA .OR. WNTUS WNTUO = LSAME( JOBU, 'O' ) WNTUN = LSAME( JOBU, 'N' ) WNTVA = LSAME( JOBVT, 'A' ) WNTVS = LSAME( JOBVT, 'S' ) WNTVAS = WNTVA .OR. WNTVS WNTVO = LSAME( JOBVT, 'O' ) WNTVN = LSAME( JOBVT, 'N' ) MINWRK = 1 LQUERY = ( LWORK.EQ.-1 ) * IF( .NOT.( WNTUA .OR. WNTUS .OR. WNTUO .OR. WNTUN ) ) THEN INFO = -1 ELSE IF( .NOT.( WNTVA .OR. WNTVS .OR. WNTVO .OR. WNTVN ) .OR. $ ( WNTVO .AND. WNTUO ) ) THEN INFO = -2 ELSE IF( M.LT.0 ) THEN INFO = -3 ELSE IF( N.LT.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -6 ELSE IF( LDU.LT.1 .OR. ( WNTUAS .AND. LDU.LT.M ) ) THEN INFO = -9 ELSE IF( LDVT.LT.1 .OR. ( WNTVA .AND. LDVT.LT.N ) .OR. $ ( WNTVS .AND. LDVT.LT.MINMN ) ) THEN INFO = -11 END IF * * Compute workspace * (Note: Comments in the code beginning "Workspace:" describe the * minimal amount of workspace needed at that point in the code, * as well as the preferred amount for good performance. * NB refers to the optimal block size for the immediately * following subroutine, as returned by ILAENV.) * IF( INFO.EQ.0 .AND. ( LWORK.GE.1 .OR. LQUERY ) .AND. M.GT.0 .AND. $ N.GT.0 ) THEN IF( M.GE.N ) THEN * * Compute space needed for DBDSQR * BDSPAC = 5*N IF( M.GE.MNTHR ) THEN IF( WNTUN ) THEN * * Path 1 (M much larger than N, JOBU='N') * MAXWRK = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, $ -1 ) MAXWRK = MAX( MAXWRK, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) IF( WNTVO .OR. WNTVAS ) $ MAXWRK = MAX( MAXWRK, 3*N+( N-1 )* $ ILAENV( 1, 'DORGBR', 'P', N, N, N, -1 ) ) MAXWRK = MAX( MAXWRK, BDSPAC ) MINWRK = MAX( 4*N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUO .AND. WNTVN ) THEN * * Path 2 (M much larger than N, JOBU='O', JOBVT='N') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+N*ILAENV( 1, 'DORGQR', ' ', M, $ N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = MAX( N*N+WRKBL, N*N+M*N+N ) MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUO .AND. WNTVAS ) THEN * * Path 3 (M much larger than N, JOBU='O', JOBVT='S' or * 'A') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+N*ILAENV( 1, 'DORGQR', ' ', M, $ N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+( N-1 )* $ ILAENV( 1, 'DORGBR', 'P', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = MAX( N*N+WRKBL, N*N+M*N+N ) MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUS .AND. WNTVN ) THEN * * Path 4 (M much larger than N, JOBU='S', JOBVT='N') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+N*ILAENV( 1, 'DORGQR', ' ', M, $ N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = N*N + WRKBL MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUS .AND. WNTVO ) THEN * * Path 5 (M much larger than N, JOBU='S', JOBVT='O') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+N*ILAENV( 1, 'DORGQR', ' ', M, $ N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+( N-1 )* $ ILAENV( 1, 'DORGBR', 'P', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = 2*N*N + WRKBL MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUS .AND. WNTVAS ) THEN * * Path 6 (M much larger than N, JOBU='S', JOBVT='S' or * 'A') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+N*ILAENV( 1, 'DORGQR', ' ', M, $ N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+( N-1 )* $ ILAENV( 1, 'DORGBR', 'P', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = N*N + WRKBL MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUA .AND. WNTVN ) THEN * * Path 7 (M much larger than N, JOBU='A', JOBVT='N') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+M*ILAENV( 1, 'DORGQR', ' ', M, $ M, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = N*N + WRKBL MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUA .AND. WNTVO ) THEN * * Path 8 (M much larger than N, JOBU='A', JOBVT='O') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+M*ILAENV( 1, 'DORGQR', ' ', M, $ M, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+( N-1 )* $ ILAENV( 1, 'DORGBR', 'P', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = 2*N*N + WRKBL MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTUA .AND. WNTVAS ) THEN * * Path 9 (M much larger than N, JOBU='A', JOBVT='S' or * 'A') * WRKBL = N + N*ILAENV( 1, 'DGEQRF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, N+M*ILAENV( 1, 'DORGQR', ' ', M, $ M, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+2*N* $ ILAENV( 1, 'DGEBRD', ' ', N, N, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, 3*N+( N-1 )* $ ILAENV( 1, 'DORGBR', 'P', N, N, N, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = N*N + WRKBL MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) END IF ELSE * * Path 10 (M at least N, but not much larger) * MAXWRK = 3*N + ( M+N )*ILAENV( 1, 'DGEBRD', ' ', M, N, $ -1, -1 ) IF( WNTUS .OR. WNTUO ) $ MAXWRK = MAX( MAXWRK, 3*N+N* $ ILAENV( 1, 'DORGBR', 'Q', M, N, N, -1 ) ) IF( WNTUA ) $ MAXWRK = MAX( MAXWRK, 3*N+M* $ ILAENV( 1, 'DORGBR', 'Q', M, M, N, -1 ) ) IF( .NOT.WNTVN ) $ MAXWRK = MAX( MAXWRK, 3*N+( N-1 )* $ ILAENV( 1, 'DORGBR', 'P', N, N, N, -1 ) ) MAXWRK = MAX( MAXWRK, BDSPAC ) MINWRK = MAX( 3*N+M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) END IF ELSE * * Compute space needed for DBDSQR * BDSPAC = 5*M IF( N.GE.MNTHR ) THEN IF( WNTVN ) THEN * * Path 1t(N much larger than M, JOBVT='N') * MAXWRK = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, $ -1 ) MAXWRK = MAX( MAXWRK, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) IF( WNTUO .OR. WNTUAS ) $ MAXWRK = MAX( MAXWRK, 3*M+M* $ ILAENV( 1, 'DORGBR', 'Q', M, M, M, -1 ) ) MAXWRK = MAX( MAXWRK, BDSPAC ) MINWRK = MAX( 4*M, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVO .AND. WNTUN ) THEN * * Path 2t(N much larger than M, JOBU='N', JOBVT='O') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+M*ILAENV( 1, 'DORGLQ', ' ', M, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = MAX( M*M+WRKBL, M*M+M*N+M ) MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVO .AND. WNTUAS ) THEN * * Path 3t(N much larger than M, JOBU='S' or 'A', * JOBVT='O') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+M*ILAENV( 1, 'DORGLQ', ' ', M, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+M* $ ILAENV( 1, 'DORGBR', 'Q', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = MAX( M*M+WRKBL, M*M+M*N+M ) MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVS .AND. WNTUN ) THEN * * Path 4t(N much larger than M, JOBU='N', JOBVT='S') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+M*ILAENV( 1, 'DORGLQ', ' ', M, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = M*M + WRKBL MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVS .AND. WNTUO ) THEN * * Path 5t(N much larger than M, JOBU='O', JOBVT='S') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+M*ILAENV( 1, 'DORGLQ', ' ', M, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+M* $ ILAENV( 1, 'DORGBR', 'Q', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = 2*M*M + WRKBL MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVS .AND. WNTUAS ) THEN * * Path 6t(N much larger than M, JOBU='S' or 'A', * JOBVT='S') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+M*ILAENV( 1, 'DORGLQ', ' ', M, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+M* $ ILAENV( 1, 'DORGBR', 'Q', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = M*M + WRKBL MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVA .AND. WNTUN ) THEN * * Path 7t(N much larger than M, JOBU='N', JOBVT='A') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+N*ILAENV( 1, 'DORGLQ', ' ', N, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = M*M + WRKBL MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVA .AND. WNTUO ) THEN * * Path 8t(N much larger than M, JOBU='O', JOBVT='A') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+N*ILAENV( 1, 'DORGLQ', ' ', N, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+M* $ ILAENV( 1, 'DORGBR', 'Q', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = 2*M*M + WRKBL MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) ELSE IF( WNTVA .AND. WNTUAS ) THEN * * Path 9t(N much larger than M, JOBU='S' or 'A', * JOBVT='A') * WRKBL = M + M*ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) WRKBL = MAX( WRKBL, M+N*ILAENV( 1, 'DORGLQ', ' ', N, $ N, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+2*M* $ ILAENV( 1, 'DGEBRD', ' ', M, M, -1, -1 ) ) WRKBL = MAX( WRKBL, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'P', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, 3*M+M* $ ILAENV( 1, 'DORGBR', 'Q', M, M, M, -1 ) ) WRKBL = MAX( WRKBL, BDSPAC ) MAXWRK = M*M + WRKBL MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) END IF ELSE * * Path 10t(N greater than M, but not much larger) * MAXWRK = 3*M + ( M+N )*ILAENV( 1, 'DGEBRD', ' ', M, N, $ -1, -1 ) IF( WNTVS .OR. WNTVO ) $ MAXWRK = MAX( MAXWRK, 3*M+M* $ ILAENV( 1, 'DORGBR', 'P', M, N, M, -1 ) ) IF( WNTVA ) $ MAXWRK = MAX( MAXWRK, 3*M+N* $ ILAENV( 1, 'DORGBR', 'P', N, N, M, -1 ) ) IF( .NOT.WNTUN ) $ MAXWRK = MAX( MAXWRK, 3*M+( M-1 )* $ ILAENV( 1, 'DORGBR', 'Q', M, M, M, -1 ) ) MAXWRK = MAX( MAXWRK, BDSPAC ) MINWRK = MAX( 3*M+N, BDSPAC ) MAXWRK = MAX( MAXWRK, MINWRK ) END IF END IF WORK( 1 ) = MAXWRK END IF * IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN INFO = -13 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGESVD', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( M.EQ.0 .OR. N.EQ.0 ) THEN IF( LWORK.GE.1 ) $ WORK( 1 ) = ONE RETURN END IF * * Get machine constants * EPS = DLAMCH( 'P' ) SMLNUM = SQRT( DLAMCH( 'S' ) ) / EPS BIGNUM = ONE / SMLNUM * * Scale A if max element outside range [SMLNUM,BIGNUM] * ANRM = DLANGE( 'M', M, N, A, LDA, DUM ) ISCL = 0 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN ISCL = 1 CALL DLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, IERR ) ELSE IF( ANRM.GT.BIGNUM ) THEN ISCL = 1 CALL DLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, IERR ) END IF * IF( M.GE.N ) THEN * * A has at least as many rows as columns. If A has sufficiently * more rows than columns, first reduce using the QR * decomposition (if sufficient workspace available) * IF( M.GE.MNTHR ) THEN * IF( WNTUN ) THEN * * Path 1 (M much larger than N, JOBU='N') * No left singular vectors to be computed * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Zero out below R * CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ), LDA ) IE = 1 ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in A * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, A, LDA, S, WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1, $ IERR ) NCVT = 0 IF( WNTVO .OR. WNTVAS ) THEN * * If right singular vectors desired, generate P'. * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) NCVT = N END IF IWORK = IE + N * * Perform bidiagonal QR iteration, computing right * singular vectors of A in A if desired * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, NCVT, 0, 0, S, WORK( IE ), A, LDA, $ DUM, 1, DUM, 1, WORK( IWORK ), INFO ) * * If right singular vectors desired in VT, copy them there * IF( WNTVAS ) $ CALL DLACPY( 'F', N, N, A, LDA, VT, LDVT ) * ELSE IF( WNTUO .AND. WNTVN ) THEN * * Path 2 (M much larger than N, JOBU='O', JOBVT='N') * N left singular vectors to be overwritten on A and * no right singular vectors to be computed * IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+LDA*N ) THEN * * WORK(IU) is LDA by N, WORK(IR) is LDA by N * LDWRKU = LDA LDWRKR = LDA ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+N*N ) THEN * * WORK(IU) is LDA by N, WORK(IR) is N by N * LDWRKU = LDA LDWRKR = N ELSE * * WORK(IU) is LDWRKU by N, WORK(IR) is N by N * LDWRKU = ( LWORK-N*N-N ) / N LDWRKR = N END IF ITAU = IR + LDWRKR*N IWORK = ITAU + N * * Compute A=Q*R * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to WORK(IR) and zero out below it * CALL DLACPY( 'U', N, N, A, LDA, WORK( IR ), LDWRKR ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, WORK( IR+1 ), $ LDWRKR ) * * Generate Q in A * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in WORK(IR) * (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, WORK( IR ), LDWRKR, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate left vectors bidiagonalizing R * (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IR) * (Workspace: need N*N+BDSPAC) * CALL DBDSQR( 'U', N, 0, N, 0, S, WORK( IE ), DUM, 1, $ WORK( IR ), LDWRKR, DUM, 1, $ WORK( IWORK ), INFO ) IU = IE + N * * Multiply Q in A by left singular vectors of R in * WORK(IR), storing result in WORK(IU) and copying to A * (Workspace: need N*N+2*N, prefer N*N+M*N+N) * DO 10 I = 1, M, LDWRKU CHUNK = MIN( M-I+1, LDWRKU ) CALL DGEMM( 'N', 'N', CHUNK, N, N, ONE, A( I, 1 ), $ LDA, WORK( IR ), LDWRKR, ZERO, $ WORK( IU ), LDWRKU ) CALL DLACPY( 'F', CHUNK, N, WORK( IU ), LDWRKU, $ A( I, 1 ), LDA ) 10 CONTINUE * ELSE * * Insufficient workspace for a fast algorithm * IE = 1 ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize A * (Workspace: need 3*N+M, prefer 3*N+(M+N)*NB) * CALL DGEBRD( M, N, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate left vectors bidiagonalizing A * (Workspace: need 4*N, prefer 3*N+N*NB) * CALL DORGBR( 'Q', M, N, N, A, LDA, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in A * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, 0, M, 0, S, WORK( IE ), DUM, 1, $ A, LDA, DUM, 1, WORK( IWORK ), INFO ) * END IF * ELSE IF( WNTUO .AND. WNTVAS ) THEN * * Path 3 (M much larger than N, JOBU='O', JOBVT='S' or 'A') * N left singular vectors to be overwritten on A and * N right singular vectors to be computed in VT * IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+LDA*N ) THEN * * WORK(IU) is LDA by N and WORK(IR) is LDA by N * LDWRKU = LDA LDWRKR = LDA ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+N*N ) THEN * * WORK(IU) is LDA by N and WORK(IR) is N by N * LDWRKU = LDA LDWRKR = N ELSE * * WORK(IU) is LDWRKU by N and WORK(IR) is N by N * LDWRKU = ( LWORK-N*N-N ) / N LDWRKR = N END IF ITAU = IR + LDWRKR*N IWORK = ITAU + N * * Compute A=Q*R * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to VT, zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, VT( 2, 1 ), $ LDVT ) * * Generate Q in A * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in VT, copying result to WORK(IR) * (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', N, N, VT, LDVT, WORK( IR ), LDWRKR ) * * Generate left vectors bidiagonalizing R in WORK(IR) * (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right vectors bidiagonalizing R in VT * (Workspace: need N*N+4*N-1, prefer N*N+3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IR) and computing right * singular vectors of R in VT * (Workspace: need N*N+BDSPAC) * CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), VT, LDVT, $ WORK( IR ), LDWRKR, DUM, 1, $ WORK( IWORK ), INFO ) IU = IE + N * * Multiply Q in A by left singular vectors of R in * WORK(IR), storing result in WORK(IU) and copying to A * (Workspace: need N*N+2*N, prefer N*N+M*N+N) * DO 20 I = 1, M, LDWRKU CHUNK = MIN( M-I+1, LDWRKU ) CALL DGEMM( 'N', 'N', CHUNK, N, N, ONE, A( I, 1 ), $ LDA, WORK( IR ), LDWRKR, ZERO, $ WORK( IU ), LDWRKU ) CALL DLACPY( 'F', CHUNK, N, WORK( IU ), LDWRKU, $ A( I, 1 ), LDA ) 20 CONTINUE * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to VT, zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, VT( 2, 1 ), $ LDVT ) * * Generate Q in A * (Workspace: need 2*N, prefer N+N*NB) * CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in VT * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply Q in A by left vectors bidiagonalizing R * (Workspace: need 3*N+M, prefer 3*N+M*NB) * CALL DORMBR( 'Q', 'R', 'N', M, N, N, VT, LDVT, $ WORK( ITAUQ ), A, LDA, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right vectors bidiagonalizing R in VT * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in A and computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), VT, LDVT, $ A, LDA, DUM, 1, WORK( IWORK ), INFO ) * END IF * ELSE IF( WNTUS ) THEN * IF( WNTVN ) THEN * * Path 4 (M much larger than N, JOBU='S', JOBVT='N') * N left singular vectors to be computed in U and * no right singular vectors to be computed * IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.WRKBL+LDA*N ) THEN * * WORK(IR) is LDA by N * LDWRKR = LDA ELSE * * WORK(IR) is N by N * LDWRKR = N END IF ITAU = IR + LDWRKR*N IWORK = ITAU + N * * Compute A=Q*R * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to WORK(IR), zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, WORK( IR ), $ LDWRKR ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, $ WORK( IR+1 ), LDWRKR ) * * Generate Q in A * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in WORK(IR) * (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, WORK( IR ), LDWRKR, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left vectors bidiagonalizing R in WORK(IR) * (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IR) * (Workspace: need N*N+BDSPAC) * CALL DBDSQR( 'U', N, 0, N, 0, S, WORK( IE ), DUM, $ 1, WORK( IR ), LDWRKR, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply Q in A by left singular vectors of R in * WORK(IR), storing result in U * (Workspace: need N*N) * CALL DGEMM( 'N', 'N', M, N, N, ONE, A, LDA, $ WORK( IR ), LDWRKR, ZERO, U, LDU ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need 2*N, prefer N+N*NB) * CALL DORGQR( M, N, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Zero out below R in A * CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ), $ LDA ) * * Bidiagonalize R in A * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply Q in U by left vectors bidiagonalizing R * (Workspace: need 3*N+M, prefer 3*N+M*NB) * CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA, $ WORK( ITAUQ ), U, LDU, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, 0, M, 0, S, WORK( IE ), DUM, $ 1, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTVO ) THEN * * Path 5 (M much larger than N, JOBU='S', JOBVT='O') * N left singular vectors to be computed in U and * N right singular vectors to be overwritten on A * IF( LWORK.GE.2*N*N+MAX( 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+2*LDA*N ) THEN * * WORK(IU) is LDA by N and WORK(IR) is LDA by N * LDWRKU = LDA IR = IU + LDWRKU*N LDWRKR = LDA ELSE IF( LWORK.GE.WRKBL+( LDA+N )*N ) THEN * * WORK(IU) is LDA by N and WORK(IR) is N by N * LDWRKU = LDA IR = IU + LDWRKU*N LDWRKR = N ELSE * * WORK(IU) is N by N and WORK(IR) is N by N * LDWRKU = N IR = IU + LDWRKU*N LDWRKR = N END IF ITAU = IR + LDWRKR*N IWORK = ITAU + N * * Compute A=Q*R * (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to WORK(IU), zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, $ WORK( IU+1 ), LDWRKU ) * * Generate Q in A * (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB) * CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in WORK(IU), copying result to * WORK(IR) * (Workspace: need 2*N*N+4*N, * prefer 2*N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU, $ WORK( IR ), LDWRKR ) * * Generate left bidiagonalizing vectors in WORK(IU) * (Workspace: need 2*N*N+4*N, prefer 2*N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in WORK(IR) * (Workspace: need 2*N*N+4*N-1, * prefer 2*N*N+3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, WORK( IR ), LDWRKR, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IU) and computing * right singular vectors of R in WORK(IR) * (Workspace: need 2*N*N+BDSPAC) * CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), $ WORK( IR ), LDWRKR, WORK( IU ), $ LDWRKU, DUM, 1, WORK( IWORK ), INFO ) * * Multiply Q in A by left singular vectors of R in * WORK(IU), storing result in U * (Workspace: need N*N) * CALL DGEMM( 'N', 'N', M, N, N, ONE, A, LDA, $ WORK( IU ), LDWRKU, ZERO, U, LDU ) * * Copy right singular vectors of R to A * (Workspace: need N*N) * CALL DLACPY( 'F', N, N, WORK( IR ), LDWRKR, A, $ LDA ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need 2*N, prefer N+N*NB) * CALL DORGQR( M, N, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Zero out below R in A * CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ), $ LDA ) * * Bidiagonalize R in A * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply Q in U by left vectors bidiagonalizing R * (Workspace: need 3*N+M, prefer 3*N+M*NB) * CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA, $ WORK( ITAUQ ), U, LDU, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right vectors bidiagonalizing R in A * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U and computing right * singular vectors of A in A * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), A, $ LDA, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTVAS ) THEN * * Path 6 (M much larger than N, JOBU='S', JOBVT='S' * or 'A') * N left singular vectors to be computed in U and * N right singular vectors to be computed in VT * IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+LDA*N ) THEN * * WORK(IU) is LDA by N * LDWRKU = LDA ELSE * * WORK(IU) is N by N * LDWRKU = N END IF ITAU = IU + LDWRKU*N IWORK = ITAU + N * * Compute A=Q*R * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to WORK(IU), zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, $ WORK( IU+1 ), LDWRKU ) * * Generate Q in A * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in WORK(IU), copying result to VT * (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU, VT, $ LDVT ) * * Generate left bidiagonalizing vectors in WORK(IU) * (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in VT * (Workspace: need N*N+4*N-1, * prefer N*N+3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IU) and computing * right singular vectors of R in VT * (Workspace: need N*N+BDSPAC) * CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), VT, $ LDVT, WORK( IU ), LDWRKU, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply Q in A by left singular vectors of R in * WORK(IU), storing result in U * (Workspace: need N*N) * CALL DGEMM( 'N', 'N', M, N, N, ONE, A, LDA, $ WORK( IU ), LDWRKU, ZERO, U, LDU ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need 2*N, prefer N+N*NB) * CALL DORGQR( M, N, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to VT, zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, VT( 2, 1 ), $ LDVT ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in VT * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply Q in U by left bidiagonalizing vectors * in VT * (Workspace: need 3*N+M, prefer 3*N+M*NB) * CALL DORMBR( 'Q', 'R', 'N', M, N, N, VT, LDVT, $ WORK( ITAUQ ), U, LDU, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in VT * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U and computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), VT, $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * END IF * ELSE IF( WNTUA ) THEN * IF( WNTVN ) THEN * * Path 7 (M much larger than N, JOBU='A', JOBVT='N') * M left singular vectors to be computed in U and * no right singular vectors to be computed * IF( LWORK.GE.N*N+MAX( N+M, 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.WRKBL+LDA*N ) THEN * * WORK(IR) is LDA by N * LDWRKR = LDA ELSE * * WORK(IR) is N by N * LDWRKR = N END IF ITAU = IR + LDWRKR*N IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Copy R to WORK(IR), zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, WORK( IR ), $ LDWRKR ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, $ WORK( IR+1 ), LDWRKR ) * * Generate Q in U * (Workspace: need N*N+N+M, prefer N*N+N+M*NB) * CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in WORK(IR) * (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, WORK( IR ), LDWRKR, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in WORK(IR) * (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IR) * (Workspace: need N*N+BDSPAC) * CALL DBDSQR( 'U', N, 0, N, 0, S, WORK( IE ), DUM, $ 1, WORK( IR ), LDWRKR, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply Q in U by left singular vectors of R in * WORK(IR), storing result in A * (Workspace: need N*N) * CALL DGEMM( 'N', 'N', M, N, N, ONE, U, LDU, $ WORK( IR ), LDWRKR, ZERO, A, LDA ) * * Copy left singular vectors of A from A to U * CALL DLACPY( 'F', M, N, A, LDA, U, LDU ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need N+M, prefer N+M*NB) * CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Zero out below R in A * CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ), $ LDA ) * * Bidiagonalize R in A * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply Q in U by left bidiagonalizing vectors * in A * (Workspace: need 3*N+M, prefer 3*N+M*NB) * CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA, $ WORK( ITAUQ ), U, LDU, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, 0, M, 0, S, WORK( IE ), DUM, $ 1, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTVO ) THEN * * Path 8 (M much larger than N, JOBU='A', JOBVT='O') * M left singular vectors to be computed in U and * N right singular vectors to be overwritten on A * IF( LWORK.GE.2*N*N+MAX( N+M, 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+2*LDA*N ) THEN * * WORK(IU) is LDA by N and WORK(IR) is LDA by N * LDWRKU = LDA IR = IU + LDWRKU*N LDWRKR = LDA ELSE IF( LWORK.GE.WRKBL+( LDA+N )*N ) THEN * * WORK(IU) is LDA by N and WORK(IR) is N by N * LDWRKU = LDA IR = IU + LDWRKU*N LDWRKR = N ELSE * * WORK(IU) is N by N and WORK(IR) is N by N * LDWRKU = N IR = IU + LDWRKU*N LDWRKR = N END IF ITAU = IR + LDWRKR*N IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need 2*N*N+N+M, prefer 2*N*N+N+M*NB) * CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to WORK(IU), zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, $ WORK( IU+1 ), LDWRKU ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in WORK(IU), copying result to * WORK(IR) * (Workspace: need 2*N*N+4*N, * prefer 2*N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU, $ WORK( IR ), LDWRKR ) * * Generate left bidiagonalizing vectors in WORK(IU) * (Workspace: need 2*N*N+4*N, prefer 2*N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in WORK(IR) * (Workspace: need 2*N*N+4*N-1, * prefer 2*N*N+3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, WORK( IR ), LDWRKR, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IU) and computing * right singular vectors of R in WORK(IR) * (Workspace: need 2*N*N+BDSPAC) * CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), $ WORK( IR ), LDWRKR, WORK( IU ), $ LDWRKU, DUM, 1, WORK( IWORK ), INFO ) * * Multiply Q in U by left singular vectors of R in * WORK(IU), storing result in A * (Workspace: need N*N) * CALL DGEMM( 'N', 'N', M, N, N, ONE, U, LDU, $ WORK( IU ), LDWRKU, ZERO, A, LDA ) * * Copy left singular vectors of A from A to U * CALL DLACPY( 'F', M, N, A, LDA, U, LDU ) * * Copy right singular vectors of R from WORK(IR) to A * CALL DLACPY( 'F', N, N, WORK( IR ), LDWRKR, A, $ LDA ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need N+M, prefer N+M*NB) * CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Zero out below R in A * CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ), $ LDA ) * * Bidiagonalize R in A * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply Q in U by left bidiagonalizing vectors * in A * (Workspace: need 3*N+M, prefer 3*N+M*NB) * CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA, $ WORK( ITAUQ ), U, LDU, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in A * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U and computing right * singular vectors of A in A * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), A, $ LDA, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTVAS ) THEN * * Path 9 (M much larger than N, JOBU='A', JOBVT='S' * or 'A') * M left singular vectors to be computed in U and * N right singular vectors to be computed in VT * IF( LWORK.GE.N*N+MAX( N+M, 4*N, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+LDA*N ) THEN * * WORK(IU) is LDA by N * LDWRKU = LDA ELSE * * WORK(IU) is N by N * LDWRKU = N END IF ITAU = IU + LDWRKU*N IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need N*N+2*N, prefer N*N+N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need N*N+N+M, prefer N*N+N+M*NB) * CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R to WORK(IU), zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, $ WORK( IU+1 ), LDWRKU ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in WORK(IU), copying result to VT * (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB) * CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU, VT, $ LDVT ) * * Generate left bidiagonalizing vectors in WORK(IU) * (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB) * CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in VT * (Workspace: need N*N+4*N-1, * prefer N*N+3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of R in WORK(IU) and computing * right singular vectors of R in VT * (Workspace: need N*N+BDSPAC) * CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), VT, $ LDVT, WORK( IU ), LDWRKU, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply Q in U by left singular vectors of R in * WORK(IU), storing result in A * (Workspace: need N*N) * CALL DGEMM( 'N', 'N', M, N, N, ONE, U, LDU, $ WORK( IU ), LDWRKU, ZERO, A, LDA ) * * Copy left singular vectors of A from A to U * CALL DLACPY( 'F', M, N, A, LDA, U, LDU ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + N * * Compute A=Q*R, copying result to U * (Workspace: need 2*N, prefer N+N*NB) * CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) * * Generate Q in U * (Workspace: need N+M, prefer N+M*NB) * CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy R from A to VT, zeroing out below it * CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT ) CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, VT( 2, 1 ), $ LDVT ) IE = ITAU ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize R in VT * (Workspace: need 4*N, prefer 3*N+2*N*NB) * CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply Q in U by left bidiagonalizing vectors * in VT * (Workspace: need 3*N+M, prefer 3*N+M*NB) * CALL DORMBR( 'Q', 'R', 'N', M, N, N, VT, LDVT, $ WORK( ITAUQ ), U, LDU, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in VT * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + N * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U and computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), VT, $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * END IF * END IF * ELSE * * M .LT. MNTHR * * Path 10 (M at least N, but not much larger) * Reduce to bidiagonal form without QR decomposition * IE = 1 ITAUQ = IE + N ITAUP = ITAUQ + N IWORK = ITAUP + N * * Bidiagonalize A * (Workspace: need 3*N+M, prefer 3*N+(M+N)*NB) * CALL DGEBRD( M, N, A, LDA, S, WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1, $ IERR ) IF( WNTUAS ) THEN * * If left singular vectors desired in U, copy result to U * and generate left bidiagonalizing vectors in U * (Workspace: need 3*N+NCU, prefer 3*N+NCU*NB) * CALL DLACPY( 'L', M, N, A, LDA, U, LDU ) IF( WNTUS ) $ NCU = N IF( WNTUA ) $ NCU = M CALL DORGBR( 'Q', M, NCU, N, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IF( WNTVAS ) THEN * * If right singular vectors desired in VT, copy result to * VT and generate right bidiagonalizing vectors in VT * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT ) CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IF( WNTUO ) THEN * * If left singular vectors desired in A, generate left * bidiagonalizing vectors in A * (Workspace: need 4*N, prefer 3*N+N*NB) * CALL DORGBR( 'Q', M, N, N, A, LDA, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IF( WNTVO ) THEN * * If right singular vectors desired in A, generate right * bidiagonalizing vectors in A * (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB) * CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IWORK = IE + N IF( WNTUAS .OR. WNTUO ) $ NRU = M IF( WNTUN ) $ NRU = 0 IF( WNTVAS .OR. WNTVO ) $ NCVT = N IF( WNTVN ) $ NCVT = 0 IF( ( .NOT.WNTUO ) .AND. ( .NOT.WNTVO ) ) THEN * * Perform bidiagonal QR iteration, if desired, computing * left singular vectors in U and computing right singular * vectors in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, NCVT, NRU, 0, S, WORK( IE ), VT, $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), INFO ) ELSE IF( ( .NOT.WNTUO ) .AND. WNTVO ) THEN * * Perform bidiagonal QR iteration, if desired, computing * left singular vectors in U and computing right singular * vectors in A * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, NCVT, NRU, 0, S, WORK( IE ), A, LDA, $ U, LDU, DUM, 1, WORK( IWORK ), INFO ) ELSE * * Perform bidiagonal QR iteration, if desired, computing * left singular vectors in A and computing right singular * vectors in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', N, NCVT, NRU, 0, S, WORK( IE ), VT, $ LDVT, A, LDA, DUM, 1, WORK( IWORK ), INFO ) END IF * END IF * ELSE * * A has more columns than rows. If A has sufficiently more * columns than rows, first reduce using the LQ decomposition (if * sufficient workspace available) * IF( N.GE.MNTHR ) THEN * IF( WNTVN ) THEN * * Path 1t(N much larger than M, JOBVT='N') * No right singular vectors to be computed * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Zero out above L * CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ), LDA ) IE = 1 ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in A * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, A, LDA, S, WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1, $ IERR ) IF( WNTUO .OR. WNTUAS ) THEN * * If left singular vectors desired, generate Q * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, A, LDA, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IWORK = IE + M NRU = 0 IF( WNTUO .OR. WNTUAS ) $ NRU = M * * Perform bidiagonal QR iteration, computing left singular * vectors of A in A if desired * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, 0, NRU, 0, S, WORK( IE ), DUM, 1, A, $ LDA, DUM, 1, WORK( IWORK ), INFO ) * * If left singular vectors desired in U, copy them there * IF( WNTUAS ) $ CALL DLACPY( 'F', M, M, A, LDA, U, LDU ) * ELSE IF( WNTVO .AND. WNTUN ) THEN * * Path 2t(N much larger than M, JOBU='N', JOBVT='O') * M right singular vectors to be overwritten on A and * no left singular vectors to be computed * IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+LDA*M ) THEN * * WORK(IU) is LDA by N and WORK(IR) is LDA by M * LDWRKU = LDA CHUNK = N LDWRKR = LDA ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+M*M ) THEN * * WORK(IU) is LDA by N and WORK(IR) is M by M * LDWRKU = LDA CHUNK = N LDWRKR = M ELSE * * WORK(IU) is M by CHUNK and WORK(IR) is M by M * LDWRKU = M CHUNK = ( LWORK-M*M-M ) / M LDWRKR = M END IF ITAU = IR + LDWRKR*M IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to WORK(IR) and zero out above it * CALL DLACPY( 'L', M, M, A, LDA, WORK( IR ), LDWRKR ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, $ WORK( IR+LDWRKR ), LDWRKR ) * * Generate Q in A * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in WORK(IR) * (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, WORK( IR ), LDWRKR, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate right vectors bidiagonalizing L * (Workspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing right * singular vectors of L in WORK(IR) * (Workspace: need M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, 0, 0, S, WORK( IE ), $ WORK( IR ), LDWRKR, DUM, 1, DUM, 1, $ WORK( IWORK ), INFO ) IU = IE + M * * Multiply right singular vectors of L in WORK(IR) by Q * in A, storing result in WORK(IU) and copying to A * (Workspace: need M*M+2*M, prefer M*M+M*N+M) * DO 30 I = 1, N, CHUNK BLK = MIN( N-I+1, CHUNK ) CALL DGEMM( 'N', 'N', M, BLK, M, ONE, WORK( IR ), $ LDWRKR, A( 1, I ), LDA, ZERO, $ WORK( IU ), LDWRKU ) CALL DLACPY( 'F', M, BLK, WORK( IU ), LDWRKU, $ A( 1, I ), LDA ) 30 CONTINUE * ELSE * * Insufficient workspace for a fast algorithm * IE = 1 ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize A * (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB) * CALL DGEBRD( M, N, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate right vectors bidiagonalizing A * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'P', M, N, M, A, LDA, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing right * singular vectors of A in A * (Workspace: need BDSPAC) * CALL DBDSQR( 'L', M, N, 0, 0, S, WORK( IE ), A, LDA, $ DUM, 1, DUM, 1, WORK( IWORK ), INFO ) * END IF * ELSE IF( WNTVO .AND. WNTUAS ) THEN * * Path 3t(N much larger than M, JOBU='S' or 'A', JOBVT='O') * M right singular vectors to be overwritten on A and * M left singular vectors to be computed in U * IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+LDA*M ) THEN * * WORK(IU) is LDA by N and WORK(IR) is LDA by M * LDWRKU = LDA CHUNK = N LDWRKR = LDA ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+M*M ) THEN * * WORK(IU) is LDA by N and WORK(IR) is M by M * LDWRKU = LDA CHUNK = N LDWRKR = M ELSE * * WORK(IU) is M by CHUNK and WORK(IR) is M by M * LDWRKU = M CHUNK = ( LWORK-M*M-M ) / M LDWRKR = M END IF ITAU = IR + LDWRKR*M IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to U, zeroing about above it * CALL DLACPY( 'L', M, M, A, LDA, U, LDU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ), $ LDU ) * * Generate Q in A * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in U, copying result to WORK(IR) * (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, U, LDU, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, M, U, LDU, WORK( IR ), LDWRKR ) * * Generate right vectors bidiagonalizing L in WORK(IR) * (Workspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left vectors bidiagonalizing L in U * (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of L in U, and computing right * singular vectors of L in WORK(IR) * (Workspace: need M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ), $ WORK( IR ), LDWRKR, U, LDU, DUM, 1, $ WORK( IWORK ), INFO ) IU = IE + M * * Multiply right singular vectors of L in WORK(IR) by Q * in A, storing result in WORK(IU) and copying to A * (Workspace: need M*M+2*M, prefer M*M+M*N+M)) * DO 40 I = 1, N, CHUNK BLK = MIN( N-I+1, CHUNK ) CALL DGEMM( 'N', 'N', M, BLK, M, ONE, WORK( IR ), $ LDWRKR, A( 1, I ), LDA, ZERO, $ WORK( IU ), LDWRKU ) CALL DLACPY( 'F', M, BLK, WORK( IU ), LDWRKU, $ A( 1, I ), LDA ) 40 CONTINUE * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to U, zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, U, LDU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ), $ LDU ) * * Generate Q in A * (Workspace: need 2*M, prefer M+M*NB) * CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in U * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, U, LDU, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply right vectors bidiagonalizing L by Q in A * (Workspace: need 3*M+N, prefer 3*M+N*NB) * CALL DORMBR( 'P', 'L', 'T', M, N, M, U, LDU, $ WORK( ITAUP ), A, LDA, WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left vectors bidiagonalizing L in U * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U and computing right * singular vectors of A in A * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), A, LDA, $ U, LDU, DUM, 1, WORK( IWORK ), INFO ) * END IF * ELSE IF( WNTVS ) THEN * IF( WNTUN ) THEN * * Path 4t(N much larger than M, JOBU='N', JOBVT='S') * M right singular vectors to be computed in VT and * no left singular vectors to be computed * IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.WRKBL+LDA*M ) THEN * * WORK(IR) is LDA by M * LDWRKR = LDA ELSE * * WORK(IR) is M by M * LDWRKR = M END IF ITAU = IR + LDWRKR*M IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to WORK(IR), zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, WORK( IR ), $ LDWRKR ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, $ WORK( IR+LDWRKR ), LDWRKR ) * * Generate Q in A * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in WORK(IR) * (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, WORK( IR ), LDWRKR, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right vectors bidiagonalizing L in * WORK(IR) * (Workspace: need M*M+4*M, prefer M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing right * singular vectors of L in WORK(IR) * (Workspace: need M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, 0, 0, S, WORK( IE ), $ WORK( IR ), LDWRKR, DUM, 1, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply right singular vectors of L in WORK(IR) by * Q in A, storing result in VT * (Workspace: need M*M) * CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IR ), $ LDWRKR, A, LDA, ZERO, VT, LDVT ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy result to VT * CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DORGLQ( M, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Zero out above L in A * CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ), $ LDA ) * * Bidiagonalize L in A * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply right vectors bidiagonalizing L by Q in VT * (Workspace: need 3*M+N, prefer 3*M+N*NB) * CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA, $ WORK( ITAUP ), VT, LDVT, $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, N, 0, 0, S, WORK( IE ), VT, $ LDVT, DUM, 1, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTUO ) THEN * * Path 5t(N much larger than M, JOBU='O', JOBVT='S') * M right singular vectors to be computed in VT and * M left singular vectors to be overwritten on A * IF( LWORK.GE.2*M*M+MAX( 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+2*LDA*M ) THEN * * WORK(IU) is LDA by M and WORK(IR) is LDA by M * LDWRKU = LDA IR = IU + LDWRKU*M LDWRKR = LDA ELSE IF( LWORK.GE.WRKBL+( LDA+M )*M ) THEN * * WORK(IU) is LDA by M and WORK(IR) is M by M * LDWRKU = LDA IR = IU + LDWRKU*M LDWRKR = M ELSE * * WORK(IU) is M by M and WORK(IR) is M by M * LDWRKU = M IR = IU + LDWRKU*M LDWRKR = M END IF ITAU = IR + LDWRKR*M IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to WORK(IU), zeroing out below it * CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, $ WORK( IU+LDWRKU ), LDWRKU ) * * Generate Q in A * (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB) * CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in WORK(IU), copying result to * WORK(IR) * (Workspace: need 2*M*M+4*M, * prefer 2*M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU, $ WORK( IR ), LDWRKR ) * * Generate right bidiagonalizing vectors in WORK(IU) * (Workspace: need 2*M*M+4*M-1, * prefer 2*M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in WORK(IR) * (Workspace: need 2*M*M+4*M, prefer 2*M*M+3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, WORK( IR ), LDWRKR, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of L in WORK(IR) and computing * right singular vectors of L in WORK(IU) * (Workspace: need 2*M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ), $ WORK( IU ), LDWRKU, WORK( IR ), $ LDWRKR, DUM, 1, WORK( IWORK ), INFO ) * * Multiply right singular vectors of L in WORK(IU) by * Q in A, storing result in VT * (Workspace: need M*M) * CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ), $ LDWRKU, A, LDA, ZERO, VT, LDVT ) * * Copy left singular vectors of L to A * (Workspace: need M*M) * CALL DLACPY( 'F', M, M, WORK( IR ), LDWRKR, A, $ LDA ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DORGLQ( M, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Zero out above L in A * CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ), $ LDA ) * * Bidiagonalize L in A * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply right vectors bidiagonalizing L by Q in VT * (Workspace: need 3*M+N, prefer 3*M+N*NB) * CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA, $ WORK( ITAUP ), VT, LDVT, $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors of L in A * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, A, LDA, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, compute left * singular vectors of A in A and compute right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT, $ LDVT, A, LDA, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTUAS ) THEN * * Path 6t(N much larger than M, JOBU='S' or 'A', * JOBVT='S') * M right singular vectors to be computed in VT and * M left singular vectors to be computed in U * IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+LDA*M ) THEN * * WORK(IU) is LDA by N * LDWRKU = LDA ELSE * * WORK(IU) is LDA by M * LDWRKU = M END IF ITAU = IU + LDWRKU*M IWORK = ITAU + M * * Compute A=L*Q * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to WORK(IU), zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, $ WORK( IU+LDWRKU ), LDWRKU ) * * Generate Q in A * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in WORK(IU), copying result to U * (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU, U, $ LDU ) * * Generate right bidiagonalizing vectors in WORK(IU) * (Workspace: need M*M+4*M-1, * prefer M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in U * (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of L in U and computing right * singular vectors of L in WORK(IU) * (Workspace: need M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ), $ WORK( IU ), LDWRKU, U, LDU, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply right singular vectors of L in WORK(IU) by * Q in A, storing result in VT * (Workspace: need M*M) * CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ), $ LDWRKU, A, LDA, ZERO, VT, LDVT ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DORGLQ( M, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to U, zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, U, LDU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ), $ LDU ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in U * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, U, LDU, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply right bidiagonalizing vectors in U by Q * in VT * (Workspace: need 3*M+N, prefer 3*M+N*NB) * CALL DORMBR( 'P', 'L', 'T', M, N, M, U, LDU, $ WORK( ITAUP ), VT, LDVT, $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in U * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U and computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT, $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * END IF * ELSE IF( WNTVA ) THEN * IF( WNTUN ) THEN * * Path 7t(N much larger than M, JOBU='N', JOBVT='A') * N right singular vectors to be computed in VT and * no left singular vectors to be computed * IF( LWORK.GE.M*M+MAX( N+M, 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IR = 1 IF( LWORK.GE.WRKBL+LDA*M ) THEN * * WORK(IR) is LDA by M * LDWRKR = LDA ELSE * * WORK(IR) is M by M * LDWRKR = M END IF ITAU = IR + LDWRKR*M IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Copy L to WORK(IR), zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, WORK( IR ), $ LDWRKR ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, $ WORK( IR+LDWRKR ), LDWRKR ) * * Generate Q in VT * (Workspace: need M*M+M+N, prefer M*M+M+N*NB) * CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in WORK(IR) * (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, WORK( IR ), LDWRKR, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate right bidiagonalizing vectors in WORK(IR) * (Workspace: need M*M+4*M-1, * prefer M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing right * singular vectors of L in WORK(IR) * (Workspace: need M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, 0, 0, S, WORK( IE ), $ WORK( IR ), LDWRKR, DUM, 1, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply right singular vectors of L in WORK(IR) by * Q in VT, storing result in A * (Workspace: need M*M) * CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IR ), $ LDWRKR, VT, LDVT, ZERO, A, LDA ) * * Copy right singular vectors of A from A to VT * CALL DLACPY( 'F', M, N, A, LDA, VT, LDVT ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need M+N, prefer M+N*NB) * CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Zero out above L in A * CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ), $ LDA ) * * Bidiagonalize L in A * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply right bidiagonalizing vectors in A by Q * in VT * (Workspace: need 3*M+N, prefer 3*M+N*NB) * CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA, $ WORK( ITAUP ), VT, LDVT, $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, N, 0, 0, S, WORK( IE ), VT, $ LDVT, DUM, 1, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTUO ) THEN * * Path 8t(N much larger than M, JOBU='O', JOBVT='A') * N right singular vectors to be computed in VT and * M left singular vectors to be overwritten on A * IF( LWORK.GE.2*M*M+MAX( N+M, 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+2*LDA*M ) THEN * * WORK(IU) is LDA by M and WORK(IR) is LDA by M * LDWRKU = LDA IR = IU + LDWRKU*M LDWRKR = LDA ELSE IF( LWORK.GE.WRKBL+( LDA+M )*M ) THEN * * WORK(IU) is LDA by M and WORK(IR) is M by M * LDWRKU = LDA IR = IU + LDWRKU*M LDWRKR = M ELSE * * WORK(IU) is M by M and WORK(IR) is M by M * LDWRKU = M IR = IU + LDWRKU*M LDWRKR = M END IF ITAU = IR + LDWRKR*M IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need 2*M*M+M+N, prefer 2*M*M+M+N*NB) * CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to WORK(IU), zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, $ WORK( IU+LDWRKU ), LDWRKU ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in WORK(IU), copying result to * WORK(IR) * (Workspace: need 2*M*M+4*M, * prefer 2*M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU, $ WORK( IR ), LDWRKR ) * * Generate right bidiagonalizing vectors in WORK(IU) * (Workspace: need 2*M*M+4*M-1, * prefer 2*M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in WORK(IR) * (Workspace: need 2*M*M+4*M, prefer 2*M*M+3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, WORK( IR ), LDWRKR, $ WORK( ITAUQ ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of L in WORK(IR) and computing * right singular vectors of L in WORK(IU) * (Workspace: need 2*M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ), $ WORK( IU ), LDWRKU, WORK( IR ), $ LDWRKR, DUM, 1, WORK( IWORK ), INFO ) * * Multiply right singular vectors of L in WORK(IU) by * Q in VT, storing result in A * (Workspace: need M*M) * CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ), $ LDWRKU, VT, LDVT, ZERO, A, LDA ) * * Copy right singular vectors of A from A to VT * CALL DLACPY( 'F', M, N, A, LDA, VT, LDVT ) * * Copy left singular vectors of A from WORK(IR) to A * CALL DLACPY( 'F', M, M, WORK( IR ), LDWRKR, A, $ LDA ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need M+N, prefer M+N*NB) * CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Zero out above L in A * CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ), $ LDA ) * * Bidiagonalize L in A * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, A, LDA, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply right bidiagonalizing vectors in A by Q * in VT * (Workspace: need 3*M+N, prefer 3*M+N*NB) * CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA, $ WORK( ITAUP ), VT, LDVT, $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in A * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, A, LDA, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of A in A and computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT, $ LDVT, A, LDA, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * ELSE IF( WNTUAS ) THEN * * Path 9t(N much larger than M, JOBU='S' or 'A', * JOBVT='A') * N right singular vectors to be computed in VT and * M left singular vectors to be computed in U * IF( LWORK.GE.M*M+MAX( N+M, 4*M, BDSPAC ) ) THEN * * Sufficient workspace for a fast algorithm * IU = 1 IF( LWORK.GE.WRKBL+LDA*M ) THEN * * WORK(IU) is LDA by M * LDWRKU = LDA ELSE * * WORK(IU) is M by M * LDWRKU = M END IF ITAU = IU + LDWRKU*M IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need M*M+2*M, prefer M*M+M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need M*M+M+N, prefer M*M+M+N*NB) * CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to WORK(IU), zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ), $ LDWRKU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, $ WORK( IU+LDWRKU ), LDWRKU ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in WORK(IU), copying result to U * (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB) * CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S, $ WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU, U, $ LDU ) * * Generate right bidiagonalizing vectors in WORK(IU) * (Workspace: need M*M+4*M, prefer M*M+3*M+(M-1)*NB) * CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU, $ WORK( ITAUP ), WORK( IWORK ), $ LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in U * (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of L in U and computing right * singular vectors of L in WORK(IU) * (Workspace: need M*M+BDSPAC) * CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ), $ WORK( IU ), LDWRKU, U, LDU, DUM, 1, $ WORK( IWORK ), INFO ) * * Multiply right singular vectors of L in WORK(IU) by * Q in VT, storing result in A * (Workspace: need M*M) * CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ), $ LDWRKU, VT, LDVT, ZERO, A, LDA ) * * Copy right singular vectors of A from A to VT * CALL DLACPY( 'F', M, N, A, LDA, VT, LDVT ) * ELSE * * Insufficient workspace for a fast algorithm * ITAU = 1 IWORK = ITAU + M * * Compute A=L*Q, copying result to VT * (Workspace: need 2*M, prefer M+M*NB) * CALL DGELQF( M, N, A, LDA, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) * * Generate Q in VT * (Workspace: need M+N, prefer M+N*NB) * CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Copy L to U, zeroing out above it * CALL DLACPY( 'L', M, M, A, LDA, U, LDU ) CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ), $ LDU ) IE = ITAU ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize L in U * (Workspace: need 4*M, prefer 3*M+2*M*NB) * CALL DGEBRD( M, M, U, LDU, S, WORK( IE ), $ WORK( ITAUQ ), WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Multiply right bidiagonalizing vectors in U by Q * in VT * (Workspace: need 3*M+N, prefer 3*M+N*NB) * CALL DORMBR( 'P', 'L', 'T', M, N, M, U, LDU, $ WORK( ITAUP ), VT, LDVT, $ WORK( IWORK ), LWORK-IWORK+1, IERR ) * * Generate left bidiagonalizing vectors in U * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) IWORK = IE + M * * Perform bidiagonal QR iteration, computing left * singular vectors of A in U and computing right * singular vectors of A in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT, $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), $ INFO ) * END IF * END IF * END IF * ELSE * * N .LT. MNTHR * * Path 10t(N greater than M, but not much larger) * Reduce to bidiagonal form without LQ decomposition * IE = 1 ITAUQ = IE + M ITAUP = ITAUQ + M IWORK = ITAUP + M * * Bidiagonalize A * (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB) * CALL DGEBRD( M, N, A, LDA, S, WORK( IE ), WORK( ITAUQ ), $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1, $ IERR ) IF( WNTUAS ) THEN * * If left singular vectors desired in U, copy result to U * and generate left bidiagonalizing vectors in U * (Workspace: need 4*M-1, prefer 3*M+(M-1)*NB) * CALL DLACPY( 'L', M, M, A, LDA, U, LDU ) CALL DORGBR( 'Q', M, M, N, U, LDU, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IF( WNTVAS ) THEN * * If right singular vectors desired in VT, copy result to * VT and generate right bidiagonalizing vectors in VT * (Workspace: need 3*M+NRVT, prefer 3*M+NRVT*NB) * CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT ) IF( WNTVA ) $ NRVT = N IF( WNTVS ) $ NRVT = M CALL DORGBR( 'P', NRVT, N, M, VT, LDVT, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IF( WNTUO ) THEN * * If left singular vectors desired in A, generate left * bidiagonalizing vectors in A * (Workspace: need 4*M-1, prefer 3*M+(M-1)*NB) * CALL DORGBR( 'Q', M, M, N, A, LDA, WORK( ITAUQ ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IF( WNTVO ) THEN * * If right singular vectors desired in A, generate right * bidiagonalizing vectors in A * (Workspace: need 4*M, prefer 3*M+M*NB) * CALL DORGBR( 'P', M, N, M, A, LDA, WORK( ITAUP ), $ WORK( IWORK ), LWORK-IWORK+1, IERR ) END IF IWORK = IE + M IF( WNTUAS .OR. WNTUO ) $ NRU = M IF( WNTUN ) $ NRU = 0 IF( WNTVAS .OR. WNTVO ) $ NCVT = N IF( WNTVN ) $ NCVT = 0 IF( ( .NOT.WNTUO ) .AND. ( .NOT.WNTVO ) ) THEN * * Perform bidiagonal QR iteration, if desired, computing * left singular vectors in U and computing right singular * vectors in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'L', M, NCVT, NRU, 0, S, WORK( IE ), VT, $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), INFO ) ELSE IF( ( .NOT.WNTUO ) .AND. WNTVO ) THEN * * Perform bidiagonal QR iteration, if desired, computing * left singular vectors in U and computing right singular * vectors in A * (Workspace: need BDSPAC) * CALL DBDSQR( 'L', M, NCVT, NRU, 0, S, WORK( IE ), A, LDA, $ U, LDU, DUM, 1, WORK( IWORK ), INFO ) ELSE * * Perform bidiagonal QR iteration, if desired, computing * left singular vectors in A and computing right singular * vectors in VT * (Workspace: need BDSPAC) * CALL DBDSQR( 'L', M, NCVT, NRU, 0, S, WORK( IE ), VT, $ LDVT, A, LDA, DUM, 1, WORK( IWORK ), INFO ) END IF * END IF * END IF * * If DBDSQR failed to converge, copy unconverged superdiagonals * to WORK( 2:MINMN ) * IF( INFO.NE.0 ) THEN IF( IE.GT.2 ) THEN DO 50 I = 1, MINMN - 1 WORK( I+1 ) = WORK( I+IE-1 ) 50 CONTINUE END IF IF( IE.LT.2 ) THEN DO 60 I = MINMN - 1, 1, -1 WORK( I+1 ) = WORK( I+IE-1 ) 60 CONTINUE END IF END IF * * Undo scaling if necessary * IF( ISCL.EQ.1 ) THEN IF( ANRM.GT.BIGNUM ) $ CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN, 1, S, MINMN, $ IERR ) IF( INFO.NE.0 .AND. ANRM.GT.BIGNUM ) $ CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN-1, 1, WORK( 2 ), $ MINMN, IERR ) IF( ANRM.LT.SMLNUM ) $ CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN, 1, S, MINMN, $ IERR ) IF( INFO.NE.0 .AND. ANRM.LT.SMLNUM ) $ CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN-1, 1, WORK( 2 ), $ MINMN, IERR ) END IF * * Return optimal workspace in WORK(1) * WORK( 1 ) = MAXWRK * RETURN * * End of DGESVD * END
gpl-3.0
nvarini/espresso_iohpc
S3DE/iotk/src/iotk_dat+COMPLEX4_3.f90
5
73094
! Input/Output Tool Kit (IOTK) ! Copyright (C) 2004-2006 Giovanni Bussi ! ! This library is free software; you can redistribute it and/or ! modify it under the terms of the GNU Lesser General Public ! License as published by the Free Software Foundation; either ! version 2.1 of the License, or (at your option) any later version. ! ! This library is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! Lesser General Public License for more details. ! ! You should have received a copy of the GNU Lesser General Public ! License along with this library; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA !------------------------------------------------------------------------------! ! Inclusion of configuration file #include "iotk_config.h" !------------------------------------------------------------------------------! #include "iotk_auxmacros.h" #ifdef __IOTK_COMPLEX4 #if 3 <= __IOTK_MAXRANK subroutine iotk_write_dat_COMPLEX4_3(unit,name,dat,dummy,attr,columns,sep,fmt,ierr) use iotk_base use iotk_error_interf use iotk_attr_interf, only : iotk_write_attr use iotk_write_interf use iotk_fmt_interf use iotk_str_interf use iotk_unit_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit character(len=*), intent(in) :: name COMPLEX (kind=this_kind), intent(in) :: dat (:,:,:) type(iotk_dummytype), optional :: dummy character(len=*), optional, intent(in) :: attr integer, optional, intent(in) :: columns character(len=*), optional, intent(in) :: sep character(len=*), optional, intent(in) :: fmt integer, optional, intent(out) :: ierr integer :: ierrl,lunit,iostat logical :: binary,raw,stream integer :: lcolumns !-< integer :: dat_rank,i integer, dimension(:), allocatable :: dat_shape logical :: qe_syntax !-> integer(iotk_header_kind), parameter :: idummy=0 character(100) :: lsep character(300) :: usefmt character(iotk_attlenx) :: lattr character(iotk_attlenx) :: attr_tmp !-< character(len=10) :: tmpstr !-> type (iotk_unit), pointer :: this COMPLEX (kind=this_kind),allocatable :: dattmp(:) integer :: itmp ierrl = 0 iostat = 0 lcolumns = 1 lsep(1:2) = " "//iotk_eos if(present(columns)) lcolumns = columns if(present(sep)) then call iotk_strcpy(lsep,sep,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if lunit = iotk_phys_unit(unit) call iotk_unit_get(lunit,pointer=this) !-< qe_syntax = .false. if (associated(this)) then qe_syntax = this%qe_syntax end if !-> raw = .false. if(associated(this)) then raw = this%raw end if call iotk_inquire(lunit,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(usefmt,"!",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(present(fmt) .and. .not. raw) call iotk_strcpy(usefmt,iotk_strtrim(fmt),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strscan(usefmt,"<>&")/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Special characters (<>&) found in fmt string') call iotk_error_write(ierrl,"unit",unit) call iotk_error_write(ierrl,"name",trim(name)) call iotk_error_write(ierrl,"fmt",trim(fmt)) goto 1 end if !-< if (.not.qe_syntax) then !-> call iotk_write_attr(lattr,"type",iotk_tolower("COMPLEX"),first=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_attr(lattr,"size",size(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< end if !-> !-< if (qe_syntax) then lattr(1:1) = iotk_eos dat_rank = size(shape(dat)) if (dat_rank>0) then allocate(dat_shape(dat_rank)) dat_shape = shape(dat) call iotk_write_attr(lattr,"rank",dat_rank,ierr=ierrl,first=.true.) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do i=1,dat_rank write(tmpstr,'(i10)') i tmpstr = adjustl(tmpstr) call iotk_write_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),dat_shape(i),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end do deallocate(dat_shape) end if end if !-> if(binary) then call iotk_write_attr(lattr,"kind",kind(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if if(.not.iotk_strcomp(usefmt,"!") .and. .not.qe_syntax) call iotk_write_attr(lattr,"fmt",iotk_strtrim(usefmt),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(lcolumns/=1) call iotk_write_attr(lattr,"columns",lcolumns,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-> if(present(attr)) then attr_tmp(1:1)=iotk_eos call iotk_strcpy(attr_tmp,attr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"type",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"kind",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"size",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"fmt",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"columns",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"len",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strlen_trim(attr_tmp)>0) call iotk_strcat(lattr,iotk_strtrim(attr_tmp),ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,name,lattr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< else if(present(attr)) then call iotk_write_begin(unit,name,attr,ierr=ierrl) else call iotk_write_begin(unit,name,ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,iotk_tolower("COMPLEX"),lattr,ierr=ierrl,new_line=.true.) end if !-> allocate(dattmp(size(dat))) #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dattmp,dat,size(dattmp),1) #else dattmp = pack(dat,mask=.true.) #endif if(binary) then if(raw) then write(lunit,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,iostat=iostat) idummy,(dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if else if(raw) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"*")) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"!")) then !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> else !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> end if end if !-< if (qe_syntax) then call iotk_write_end(unit,iotk_tolower("COMPLEX"),indentation=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> call iotk_write_end(unit,name,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if 1 continue if(allocated(dattmp)) deallocate(dattmp) if(present(ierr)) then ierr = ierrl else if(ierrl/=0) call iotk_error_handler(ierrl) end if end subroutine iotk_write_dat_COMPLEX4_3 subroutine iotk_scan_dat_COMPLEX4_3(unit,name,dat,dummy,attr,found,default,ierr) use iotk_base !-< use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr !-> use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit character(len=*), intent(in) :: name #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:) #endif type(iotk_dummytype), optional :: dummy #ifdef __IOTK_WORKAROUND6 character(len=*), optional :: attr #else character(len=*), optional, intent(out) :: attr #endif logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr !-< ! ... necessary because i need the syntax to use type (iotk_unit), pointer :: this ! ... necessary to read the tag describing the type character(iotk_taglenx) :: ltag character(iotk_namlenx) :: r_name character(iotk_attlenx) :: lattr2 character(len=20) :: tmpstr ! ... necessary for scan_tag logical :: binary,stream,qe_syntax integer :: r_control,rrank integer :: rshape,i !-> integer :: columns logical :: inside,foundl !-< call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .false. if (associated(this)) THEN qe_syntax = this%qe_syntax end if !-> inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. call iotk_scan_begin(unit,name,lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(present(attr)) call iotk_strcpy(attr,lattr,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-< call iotk_parse_dat(lattr,rtype,rkind,rsize,rlen,fmt,columns,ierrl) ! Note that columns is not effectively used if(ierrl/=0) goto 1 !-< else call iotk_inquire(iotk_phys_unit(unit),binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do call iotk_scan_tag(unit,+1,r_control,ltag,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if (r_control==4) then cycle else exit end if end do call iotk_tag_parse(ltag,r_name,lattr2,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(rtype,r_name,ierrl) rtype = iotk_toupper(rtype) rlen = -1 if (rtype(1:iotk_strlen(rtype))/="STRING") then call iotk_scan_attr(lattr2,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr2,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if else call iotk_strcpy(rtype,"CHARACTER",ierrl) rsize = -1 end if call iotk_scan_attr(lattr2,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if end if !-> if(.not. (iotk_strcomp(rtype,iotk_eos) .or. iotk_strcomp(rtype,"COMPLEX") ) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,' ') call iotk_error_write(ierrl,"rtype",rtype(1:iotk_strlen(rtype))) call iotk_error_write(ierrl,"type","COMPLEX") goto 1 end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"name",name) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif 1 continue !-< if ( allocated(tmpdat) ) deallocate(tmpdat) !-> if(inside) then !-< if (qe_syntax) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if !-> call iotk_scan_end(unit,name,ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"name",name) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_COMPLEX4_3 !-< ! ... new procedure: scan dat when you are already inside the data tag subroutine iotk_scan_dat_inside_COMPLEX4_3(unit,dat,dummy,found,default,ierr) use iotk_base use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:) #endif type(iotk_dummytype), optional :: dummy logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) character(len=20) :: tmpstr integer :: rrank integer :: rshape,i integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr character(iotk_namlenx) :: rname type (iotk_unit), pointer :: this integer :: columns logical :: inside,foundl,qe_syntax call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .true. IF (associated(this)) then qe_syntax = this%qe_syntax END IF inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. if (.not.qe_syntax) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rname = iotk_tolower("COMPLEX") call iotk_scan_begin(unit,iotk_tolower("COMPLEX"),lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rlen = -1 call iotk_scan_attr(lattr,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if call iotk_scan_attr(lattr,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"rname",rname) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif deallocate(tmpdat) 1 continue if(inside) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"rname",rname) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_inside_COMPLEX4_3 !-> #endif #endif subroutine iotk_dat_dummy_COMPLEX4_3 write(0,*) end subroutine iotk_dat_dummy_COMPLEX4_3 !------------------------------------------------------------------------------! ! Inclusion of configuration file #include "iotk_config.h" !------------------------------------------------------------------------------! #include "iotk_auxmacros.h" #ifdef __IOTK_COMPLEX4 #if 4 <= __IOTK_MAXRANK subroutine iotk_write_dat_COMPLEX4_4(unit,name,dat,dummy,attr,columns,sep,fmt,ierr) use iotk_base use iotk_error_interf use iotk_attr_interf, only : iotk_write_attr use iotk_write_interf use iotk_fmt_interf use iotk_str_interf use iotk_unit_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit character(len=*), intent(in) :: name COMPLEX (kind=this_kind), intent(in) :: dat (:,:,:,:) type(iotk_dummytype), optional :: dummy character(len=*), optional, intent(in) :: attr integer, optional, intent(in) :: columns character(len=*), optional, intent(in) :: sep character(len=*), optional, intent(in) :: fmt integer, optional, intent(out) :: ierr integer :: ierrl,lunit,iostat logical :: binary,raw,stream integer :: lcolumns !-< integer :: dat_rank,i integer, dimension(:), allocatable :: dat_shape logical :: qe_syntax !-> integer(iotk_header_kind), parameter :: idummy=0 character(100) :: lsep character(300) :: usefmt character(iotk_attlenx) :: lattr character(iotk_attlenx) :: attr_tmp !-< character(len=10) :: tmpstr !-> type (iotk_unit), pointer :: this COMPLEX (kind=this_kind),allocatable :: dattmp(:) integer :: itmp ierrl = 0 iostat = 0 lcolumns = 1 lsep(1:2) = " "//iotk_eos if(present(columns)) lcolumns = columns if(present(sep)) then call iotk_strcpy(lsep,sep,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if lunit = iotk_phys_unit(unit) call iotk_unit_get(lunit,pointer=this) !-< qe_syntax = .false. if (associated(this)) then qe_syntax = this%qe_syntax end if !-> raw = .false. if(associated(this)) then raw = this%raw end if call iotk_inquire(lunit,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(usefmt,"!",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(present(fmt) .and. .not. raw) call iotk_strcpy(usefmt,iotk_strtrim(fmt),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strscan(usefmt,"<>&")/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Special characters (<>&) found in fmt string') call iotk_error_write(ierrl,"unit",unit) call iotk_error_write(ierrl,"name",trim(name)) call iotk_error_write(ierrl,"fmt",trim(fmt)) goto 1 end if !-< if (.not.qe_syntax) then !-> call iotk_write_attr(lattr,"type",iotk_tolower("COMPLEX"),first=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_attr(lattr,"size",size(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< end if !-> !-< if (qe_syntax) then lattr(1:1) = iotk_eos dat_rank = size(shape(dat)) if (dat_rank>0) then allocate(dat_shape(dat_rank)) dat_shape = shape(dat) call iotk_write_attr(lattr,"rank",dat_rank,ierr=ierrl,first=.true.) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do i=1,dat_rank write(tmpstr,'(i10)') i tmpstr = adjustl(tmpstr) call iotk_write_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),dat_shape(i),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end do deallocate(dat_shape) end if end if !-> if(binary) then call iotk_write_attr(lattr,"kind",kind(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if if(.not.iotk_strcomp(usefmt,"!") .and. .not.qe_syntax) call iotk_write_attr(lattr,"fmt",iotk_strtrim(usefmt),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(lcolumns/=1) call iotk_write_attr(lattr,"columns",lcolumns,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-> if(present(attr)) then attr_tmp(1:1)=iotk_eos call iotk_strcpy(attr_tmp,attr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"type",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"kind",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"size",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"fmt",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"columns",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"len",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strlen_trim(attr_tmp)>0) call iotk_strcat(lattr,iotk_strtrim(attr_tmp),ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,name,lattr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< else if(present(attr)) then call iotk_write_begin(unit,name,attr,ierr=ierrl) else call iotk_write_begin(unit,name,ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,iotk_tolower("COMPLEX"),lattr,ierr=ierrl,new_line=.true.) end if !-> allocate(dattmp(size(dat))) #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dattmp,dat,size(dattmp),1) #else dattmp = pack(dat,mask=.true.) #endif if(binary) then if(raw) then write(lunit,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,iostat=iostat) idummy,(dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if else if(raw) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"*")) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"!")) then !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> else !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> end if end if !-< if (qe_syntax) then call iotk_write_end(unit,iotk_tolower("COMPLEX"),indentation=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> call iotk_write_end(unit,name,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if 1 continue if(allocated(dattmp)) deallocate(dattmp) if(present(ierr)) then ierr = ierrl else if(ierrl/=0) call iotk_error_handler(ierrl) end if end subroutine iotk_write_dat_COMPLEX4_4 subroutine iotk_scan_dat_COMPLEX4_4(unit,name,dat,dummy,attr,found,default,ierr) use iotk_base !-< use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr !-> use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit character(len=*), intent(in) :: name #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:) #endif type(iotk_dummytype), optional :: dummy #ifdef __IOTK_WORKAROUND6 character(len=*), optional :: attr #else character(len=*), optional, intent(out) :: attr #endif logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr !-< ! ... necessary because i need the syntax to use type (iotk_unit), pointer :: this ! ... necessary to read the tag describing the type character(iotk_taglenx) :: ltag character(iotk_namlenx) :: r_name character(iotk_attlenx) :: lattr2 character(len=20) :: tmpstr ! ... necessary for scan_tag logical :: binary,stream,qe_syntax integer :: r_control,rrank integer :: rshape,i !-> integer :: columns logical :: inside,foundl !-< call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .false. if (associated(this)) THEN qe_syntax = this%qe_syntax end if !-> inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. call iotk_scan_begin(unit,name,lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(present(attr)) call iotk_strcpy(attr,lattr,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-< call iotk_parse_dat(lattr,rtype,rkind,rsize,rlen,fmt,columns,ierrl) ! Note that columns is not effectively used if(ierrl/=0) goto 1 !-< else call iotk_inquire(iotk_phys_unit(unit),binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do call iotk_scan_tag(unit,+1,r_control,ltag,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if (r_control==4) then cycle else exit end if end do call iotk_tag_parse(ltag,r_name,lattr2,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(rtype,r_name,ierrl) rtype = iotk_toupper(rtype) rlen = -1 if (rtype(1:iotk_strlen(rtype))/="STRING") then call iotk_scan_attr(lattr2,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr2,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if else call iotk_strcpy(rtype,"CHARACTER",ierrl) rsize = -1 end if call iotk_scan_attr(lattr2,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if end if !-> if(.not. (iotk_strcomp(rtype,iotk_eos) .or. iotk_strcomp(rtype,"COMPLEX") ) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,' ') call iotk_error_write(ierrl,"rtype",rtype(1:iotk_strlen(rtype))) call iotk_error_write(ierrl,"type","COMPLEX") goto 1 end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"name",name) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif 1 continue !-< if ( allocated(tmpdat) ) deallocate(tmpdat) !-> if(inside) then !-< if (qe_syntax) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if !-> call iotk_scan_end(unit,name,ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"name",name) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_COMPLEX4_4 !-< ! ... new procedure: scan dat when you are already inside the data tag subroutine iotk_scan_dat_inside_COMPLEX4_4(unit,dat,dummy,found,default,ierr) use iotk_base use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:) #endif type(iotk_dummytype), optional :: dummy logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) character(len=20) :: tmpstr integer :: rrank integer :: rshape,i integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr character(iotk_namlenx) :: rname type (iotk_unit), pointer :: this integer :: columns logical :: inside,foundl,qe_syntax call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .true. IF (associated(this)) then qe_syntax = this%qe_syntax END IF inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. if (.not.qe_syntax) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rname = iotk_tolower("COMPLEX") call iotk_scan_begin(unit,iotk_tolower("COMPLEX"),lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rlen = -1 call iotk_scan_attr(lattr,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if call iotk_scan_attr(lattr,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"rname",rname) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif deallocate(tmpdat) 1 continue if(inside) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"rname",rname) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_inside_COMPLEX4_4 !-> #endif #endif subroutine iotk_dat_dummy_COMPLEX4_4 write(0,*) end subroutine iotk_dat_dummy_COMPLEX4_4 !------------------------------------------------------------------------------! ! Inclusion of configuration file #include "iotk_config.h" !------------------------------------------------------------------------------! #include "iotk_auxmacros.h" #ifdef __IOTK_COMPLEX4 #if 5 <= __IOTK_MAXRANK subroutine iotk_write_dat_COMPLEX4_5(unit,name,dat,dummy,attr,columns,sep,fmt,ierr) use iotk_base use iotk_error_interf use iotk_attr_interf, only : iotk_write_attr use iotk_write_interf use iotk_fmt_interf use iotk_str_interf use iotk_unit_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit character(len=*), intent(in) :: name COMPLEX (kind=this_kind), intent(in) :: dat (:,:,:,:,:) type(iotk_dummytype), optional :: dummy character(len=*), optional, intent(in) :: attr integer, optional, intent(in) :: columns character(len=*), optional, intent(in) :: sep character(len=*), optional, intent(in) :: fmt integer, optional, intent(out) :: ierr integer :: ierrl,lunit,iostat logical :: binary,raw,stream integer :: lcolumns !-< integer :: dat_rank,i integer, dimension(:), allocatable :: dat_shape logical :: qe_syntax !-> integer(iotk_header_kind), parameter :: idummy=0 character(100) :: lsep character(300) :: usefmt character(iotk_attlenx) :: lattr character(iotk_attlenx) :: attr_tmp !-< character(len=10) :: tmpstr !-> type (iotk_unit), pointer :: this COMPLEX (kind=this_kind),allocatable :: dattmp(:) integer :: itmp ierrl = 0 iostat = 0 lcolumns = 1 lsep(1:2) = " "//iotk_eos if(present(columns)) lcolumns = columns if(present(sep)) then call iotk_strcpy(lsep,sep,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if lunit = iotk_phys_unit(unit) call iotk_unit_get(lunit,pointer=this) !-< qe_syntax = .false. if (associated(this)) then qe_syntax = this%qe_syntax end if !-> raw = .false. if(associated(this)) then raw = this%raw end if call iotk_inquire(lunit,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(usefmt,"!",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(present(fmt) .and. .not. raw) call iotk_strcpy(usefmt,iotk_strtrim(fmt),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strscan(usefmt,"<>&")/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Special characters (<>&) found in fmt string') call iotk_error_write(ierrl,"unit",unit) call iotk_error_write(ierrl,"name",trim(name)) call iotk_error_write(ierrl,"fmt",trim(fmt)) goto 1 end if !-< if (.not.qe_syntax) then !-> call iotk_write_attr(lattr,"type",iotk_tolower("COMPLEX"),first=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_attr(lattr,"size",size(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< end if !-> !-< if (qe_syntax) then lattr(1:1) = iotk_eos dat_rank = size(shape(dat)) if (dat_rank>0) then allocate(dat_shape(dat_rank)) dat_shape = shape(dat) call iotk_write_attr(lattr,"rank",dat_rank,ierr=ierrl,first=.true.) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do i=1,dat_rank write(tmpstr,'(i10)') i tmpstr = adjustl(tmpstr) call iotk_write_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),dat_shape(i),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end do deallocate(dat_shape) end if end if !-> if(binary) then call iotk_write_attr(lattr,"kind",kind(dat),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if if(.not.iotk_strcomp(usefmt,"!") .and. .not.qe_syntax) call iotk_write_attr(lattr,"fmt",iotk_strtrim(usefmt),ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(lcolumns/=1) call iotk_write_attr(lattr,"columns",lcolumns,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-> if(present(attr)) then attr_tmp(1:1)=iotk_eos call iotk_strcpy(attr_tmp,attr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"type",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"kind",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"size",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"fmt",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"columns",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_delete_attr(attr_tmp,"len",ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(iotk_strlen_trim(attr_tmp)>0) call iotk_strcat(lattr,iotk_strtrim(attr_tmp),ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,name,lattr,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< else if(present(attr)) then call iotk_write_begin(unit,name,attr,ierr=ierrl) else call iotk_write_begin(unit,name,ierr=ierrl) end if if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_write_begin(unit,iotk_tolower("COMPLEX"),lattr,ierr=ierrl,new_line=.true.) end if !-> allocate(dattmp(size(dat))) #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dattmp,dat,size(dattmp),1) #else dattmp = pack(dat,mask=.true.) #endif if(binary) then if(raw) then write(lunit,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,iostat=iostat) idummy,(dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if else if(raw) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"*")) then write(lunit,*,iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else if(iotk_strcomp(usefmt,"!")) then !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=trim(iotk_wfmt("COMPLEX",kind(dattmp),lcolumns,-1,lsep)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> else !-< if ((.not. qe_syntax) .or. (size(dattmp)>1)) then write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),iostat=iostat) (dattmp(itmp),itmp=1,size(dattmp)) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if else write(lunit,fmt=usefmt(1:iotk_strlen(usefmt)),advance='no',iostat=iostat) dattmp(1) if(iostat/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> end if end if !-< if (qe_syntax) then call iotk_write_end(unit,iotk_tolower("COMPLEX"),indentation=.true.,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if end if !-> call iotk_write_end(unit,name,ierr=ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_write_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if 1 continue if(allocated(dattmp)) deallocate(dattmp) if(present(ierr)) then ierr = ierrl else if(ierrl/=0) call iotk_error_handler(ierrl) end if end subroutine iotk_write_dat_COMPLEX4_5 subroutine iotk_scan_dat_COMPLEX4_5(unit,name,dat,dummy,attr,found,default,ierr) use iotk_base !-< use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr !-> use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit character(len=*), intent(in) :: name #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:,:) #endif type(iotk_dummytype), optional :: dummy #ifdef __IOTK_WORKAROUND6 character(len=*), optional :: attr #else character(len=*), optional, intent(out) :: attr #endif logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr !-< ! ... necessary because i need the syntax to use type (iotk_unit), pointer :: this ! ... necessary to read the tag describing the type character(iotk_taglenx) :: ltag character(iotk_namlenx) :: r_name character(iotk_attlenx) :: lattr2 character(len=20) :: tmpstr ! ... necessary for scan_tag logical :: binary,stream,qe_syntax integer :: r_control,rrank integer :: rshape,i !-> integer :: columns logical :: inside,foundl !-< call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .false. if (associated(this)) THEN qe_syntax = this%qe_syntax end if !-> inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. call iotk_scan_begin(unit,name,lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(present(attr)) call iotk_strcpy(attr,lattr,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if !-< if (.not.qe_syntax) then !-< call iotk_parse_dat(lattr,rtype,rkind,rsize,rlen,fmt,columns,ierrl) ! Note that columns is not effectively used if(ierrl/=0) goto 1 !-< else call iotk_inquire(iotk_phys_unit(unit),binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if do call iotk_scan_tag(unit,+1,r_control,ltag,binary,stream,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if (r_control==4) then cycle else exit end if end do call iotk_tag_parse(ltag,r_name,lattr2,ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if call iotk_strcpy(rtype,r_name,ierrl) rtype = iotk_toupper(rtype) rlen = -1 if (rtype(1:iotk_strlen(rtype))/="STRING") then call iotk_scan_attr(lattr2,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr2,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if else call iotk_strcpy(rtype,"CHARACTER",ierrl) rsize = -1 end if call iotk_scan_attr(lattr2,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr2,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if end if !-> if(.not. (iotk_strcomp(rtype,iotk_eos) .or. iotk_strcomp(rtype,"COMPLEX") ) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,' ') call iotk_error_write(ierrl,"rtype",rtype(1:iotk_strlen(rtype))) call iotk_error_write(ierrl,"type","COMPLEX") goto 1 end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"name",name) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif 1 continue !-< if ( allocated(tmpdat) ) deallocate(tmpdat) !-> if(inside) then !-< if (qe_syntax) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if !-> call iotk_scan_end(unit,name,ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"name",name) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_COMPLEX4_5 !-< ! ... new procedure: scan dat when you are already inside the data tag subroutine iotk_scan_dat_inside_COMPLEX4_5(unit,dat,dummy,found,default,ierr) use iotk_base use iotk_unit_interf use iotk_attr_interf, only : iotk_scan_attr use iotk_error_interf use iotk_dat_interf, only: iotk_scan_dat_aux use iotk_scan_interf use iotk_str_interf use iotk_misc_interf implicit none integer, parameter :: this_kind = iotk_COMPLEX4 integer, intent(in) :: unit #ifdef __IOTK_WORKAROUND6 COMPLEX(kind=this_kind) :: dat (:,:,:,:,:) #else COMPLEX(kind=this_kind), intent(out) :: dat (:,:,:,:,:) #endif type(iotk_dummytype), optional :: dummy logical, optional, intent(out) :: found COMPLEX(kind=this_kind), optional, intent(in) :: default (:,:,:,:,:) integer, optional, intent(out) :: ierr COMPLEX (kind=this_kind), allocatable :: tmpdat(:) character(len=20) :: tmpstr integer :: rrank integer :: rshape,i integer :: ierrl,ierrl2 integer :: rkind,rsize,rlen character(iotk_vallenx) :: rtype character(iotk_vallenx) :: fmt character(iotk_attlenx) :: lattr character(iotk_namlenx) :: rname type (iotk_unit), pointer :: this integer :: columns logical :: inside,foundl,qe_syntax call iotk_unit_get(iotk_phys_unit(unit),pointer=this) qe_syntax = .true. IF (associated(this)) then qe_syntax = this%qe_syntax END IF inside = .false. ierrl = 0 ierrl2 = 0 foundl=.false. if (.not.qe_syntax) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rname = iotk_tolower("COMPLEX") call iotk_scan_begin(unit,iotk_tolower("COMPLEX"),lattr,found=foundl,ierr=ierrl) if(.not. foundl) goto 1 foundl = .true. inside = .true. if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if rlen = -1 call iotk_scan_attr(lattr,"rank",rrank,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = 1 if (rrank>0) then do i=1,rrank write(tmpstr,'(i20)') i tmpstr = adjustl(tmpstr) call iotk_scan_attr(lattr,"n"//tmpstr(1:len_trim(tmpstr)),rshape,ierr=ierrl,default=0) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if rsize = rsize*rshape end do end if call iotk_scan_attr(lattr,"kind",rkind,ierr=ierrl,default=-1) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"fmt", fmt, ierr=ierrl,eos=.true.,default="!"//iotk_eos) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if call iotk_scan_attr(lattr,"columns",columns,ierr=ierrl,default=1) if(ierrl/=0) then call iotk_error_issue(ierr,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierr,"CVS Revision: 1.27 ") return end if if(.not. (rsize==-1 .or. rsize==size(dat)) ) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") goto 1 end if if(rkind==-1) rkind = kind(dat) allocate(tmpdat(size(dat))) call iotk_scan_dat_aux(unit,tmpdat,rkind,rlen,fmt(1:iotk_strlen(fmt)),ierrl) if(ierrl/=0) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Error reading data') call iotk_error_write(ierrl,"rname",rname) call iotk_error_write(ierrl,"rkind",rkind) call iotk_error_write(ierrl,"rlen",rlen) goto 1 end if #if defined(__IOTK_WORKAROUND3) || defined(__IOTK_WORKAROUND4) call iotk_private_pack_COMPLEX4(dat,tmpdat,size(tmpdat),1) #else dat = reshape(tmpdat,shape(dat)) #endif deallocate(tmpdat) 1 continue if(inside) then call iotk_scan_end(unit,iotk_tolower("COMPLEX"),ierr=ierrl2) if(ierrl2/=0) then call iotk_error_clear(ierrl) ierrl=ierrl2 end if end if if(ierrl/=0) foundl=.false. if(present(found)) found = foundl if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then call iotk_error_issue(ierrl,"iotk_scan_dat_inside",__FILE__,__LINE__) call iotk_error_msg(ierrl,"CVS Revision: 1.27 ") call iotk_error_msg(ierrl,'Dat not found') call iotk_error_write(ierrl,"rname",rname) ierrl = - ierrl end if if(present(default) .and. .not. foundl) then dat=default end if if(present(ierr)) then ierr = ierrl else if(ierrl>0 .or. (.not.present(found) .and. .not.present(default))) call iotk_error_handler(ierrl) end if end subroutine iotk_scan_dat_inside_COMPLEX4_5 !-> #endif #endif subroutine iotk_dat_dummy_COMPLEX4_5 write(0,*) end subroutine iotk_dat_dummy_COMPLEX4_5
gpl-2.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/cuncsd.f
22
22483
*> \brief \b CUNCSD * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CUNCSD + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cuncsd.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cuncsd.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cuncsd.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * RECURSIVE SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, * SIGNS, M, P, Q, X11, LDX11, X12, * LDX12, X21, LDX21, X22, LDX22, THETA, * U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, * LDV2T, WORK, LWORK, RWORK, LRWORK, * IWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS * INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12, * $ LDX21, LDX22, LRWORK, LWORK, M, P, Q * .. * .. Array Arguments .. * INTEGER IWORK( * ) * REAL THETA( * ) * REAL RWORK( * ) * COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), * $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ), * $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22, * $ * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CUNCSD computes the CS decomposition of an M-by-M partitioned *> unitary matrix X: *> *> [ I 0 0 | 0 0 0 ] *> [ 0 C 0 | 0 -S 0 ] *> [ X11 | X12 ] [ U1 | ] [ 0 0 0 | 0 0 -I ] [ V1 | ]**H *> X = [-----------] = [---------] [---------------------] [---------] . *> [ X21 | X22 ] [ | U2 ] [ 0 0 0 | I 0 0 ] [ | V2 ] *> [ 0 S 0 | 0 C 0 ] *> [ 0 0 I | 0 0 0 ] *> *> X11 is P-by-Q. The unitary matrices U1, U2, V1, and V2 are P-by-P, *> (M-P)-by-(M-P), Q-by-Q, and (M-Q)-by-(M-Q), respectively. C and S are *> R-by-R nonnegative diagonal matrices satisfying C^2 + S^2 = I, in *> which R = MIN(P,M-P,Q,M-Q). *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBU1 *> \verbatim *> JOBU1 is CHARACTER *> = 'Y': U1 is computed; *> otherwise: U1 is not computed. *> \endverbatim *> *> \param[in] JOBU2 *> \verbatim *> JOBU2 is CHARACTER *> = 'Y': U2 is computed; *> otherwise: U2 is not computed. *> \endverbatim *> *> \param[in] JOBV1T *> \verbatim *> JOBV1T is CHARACTER *> = 'Y': V1T is computed; *> otherwise: V1T is not computed. *> \endverbatim *> *> \param[in] JOBV2T *> \verbatim *> JOBV2T is CHARACTER *> = 'Y': V2T is computed; *> otherwise: V2T is not computed. *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER *> = 'T': X, U1, U2, V1T, and V2T are stored in row-major *> order; *> otherwise: X, U1, U2, V1T, and V2T are stored in column- *> major order. *> \endverbatim *> *> \param[in] SIGNS *> \verbatim *> SIGNS is CHARACTER *> = 'O': The lower-left block is made nonpositive (the *> "other" convention); *> otherwise: The upper-right block is made nonpositive (the *> "default" convention). *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows and columns in X. *> \endverbatim *> *> \param[in] P *> \verbatim *> P is INTEGER *> The number of rows in X11 and X12. 0 <= P <= M. *> \endverbatim *> *> \param[in] Q *> \verbatim *> Q is INTEGER *> The number of columns in X11 and X21. 0 <= Q <= M. *> \endverbatim *> *> \param[in,out] X11 *> \verbatim *> X11 is COMPLEX array, dimension (LDX11,Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX11 *> \verbatim *> LDX11 is INTEGER *> The leading dimension of X11. LDX11 >= MAX(1,P). *> \endverbatim *> *> \param[in,out] X12 *> \verbatim *> X12 is COMPLEX array, dimension (LDX12,M-Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX12 *> \verbatim *> LDX12 is INTEGER *> The leading dimension of X12. LDX12 >= MAX(1,P). *> \endverbatim *> *> \param[in,out] X21 *> \verbatim *> X21 is COMPLEX array, dimension (LDX21,Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX21 *> \verbatim *> LDX21 is INTEGER *> The leading dimension of X11. LDX21 >= MAX(1,M-P). *> \endverbatim *> *> \param[in,out] X22 *> \verbatim *> X22 is COMPLEX array, dimension (LDX22,M-Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX22 *> \verbatim *> LDX22 is INTEGER *> The leading dimension of X11. LDX22 >= MAX(1,M-P). *> \endverbatim *> *> \param[out] THETA *> \verbatim *> THETA is REAL array, dimension (R), in which R = *> MIN(P,M-P,Q,M-Q). *> C = DIAG( COS(THETA(1)), ... , COS(THETA(R)) ) and *> S = DIAG( SIN(THETA(1)), ... , SIN(THETA(R)) ). *> \endverbatim *> *> \param[out] U1 *> \verbatim *> U1 is COMPLEX array, dimension (P) *> If JOBU1 = 'Y', U1 contains the P-by-P unitary matrix U1. *> \endverbatim *> *> \param[in] LDU1 *> \verbatim *> LDU1 is INTEGER *> The leading dimension of U1. If JOBU1 = 'Y', LDU1 >= *> MAX(1,P). *> \endverbatim *> *> \param[out] U2 *> \verbatim *> U2 is COMPLEX array, dimension (M-P) *> If JOBU2 = 'Y', U2 contains the (M-P)-by-(M-P) unitary *> matrix U2. *> \endverbatim *> *> \param[in] LDU2 *> \verbatim *> LDU2 is INTEGER *> The leading dimension of U2. If JOBU2 = 'Y', LDU2 >= *> MAX(1,M-P). *> \endverbatim *> *> \param[out] V1T *> \verbatim *> V1T is COMPLEX array, dimension (Q) *> If JOBV1T = 'Y', V1T contains the Q-by-Q matrix unitary *> matrix V1**H. *> \endverbatim *> *> \param[in] LDV1T *> \verbatim *> LDV1T is INTEGER *> The leading dimension of V1T. If JOBV1T = 'Y', LDV1T >= *> MAX(1,Q). *> \endverbatim *> *> \param[out] V2T *> \verbatim *> V2T is COMPLEX array, dimension (M-Q) *> If JOBV2T = 'Y', V2T contains the (M-Q)-by-(M-Q) unitary *> matrix V2**H. *> \endverbatim *> *> \param[in] LDV2T *> \verbatim *> LDV2T is INTEGER *> The leading dimension of V2T. If JOBV2T = 'Y', LDV2T >= *> MAX(1,M-Q). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX 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] RWORK *> \verbatim *> RWORK is REAL array, dimension MAX(1,LRWORK) *> On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. *> If INFO > 0 on exit, RWORK(2:R) contains the values PHI(1), *> ..., PHI(R-1) that, together with THETA(1), ..., THETA(R), *> define the matrix in intermediate bidiagonal-block form *> remaining after nonconvergence. INFO specifies the number *> of nonzero PHI's. *> \endverbatim *> *> \param[in] LRWORK *> \verbatim *> LRWORK is INTEGER *> The dimension of the array RWORK. *> *> If LRWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal size of the RWORK array, returns *> this value as the first entry of the work array, and no error *> message related to LRWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (M-MIN(P,M-P,Q,M-Q)) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit. *> < 0: if INFO = -i, the i-th argument had an illegal value. *> > 0: CBBCSD did not converge. See the description of RWORK *> above for details. *> \endverbatim * *> \par References: * ================ *> *> [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. *> Algorithms, 50(1):33-65, 2009. * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2013 * *> \ingroup complexOTHERcomputational * * ===================================================================== RECURSIVE SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, $ SIGNS, M, P, Q, X11, LDX11, X12, $ LDX12, X21, LDX21, X22, LDX22, THETA, $ U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, $ LDV2T, WORK, LWORK, RWORK, LRWORK, $ IWORK, INFO ) * * -- LAPACK computational routine (version 3.5.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2013 * * .. Scalar Arguments .. CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12, $ LDX21, LDX22, LRWORK, LWORK, M, P, Q * .. * .. Array Arguments .. INTEGER IWORK( * ) REAL THETA( * ) REAL RWORK( * ) COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ), $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22, $ * ) * .. * * =================================================================== * * .. Parameters .. COMPLEX ONE, ZERO PARAMETER ( ONE = (1.0E0,0.0E0), $ ZERO = (0.0E0,0.0E0) ) * .. * .. Local Scalars .. CHARACTER TRANST, SIGNST INTEGER CHILDINFO, I, IB11D, IB11E, IB12D, IB12E, $ IB21D, IB21E, IB22D, IB22E, IBBCSD, IORBDB, $ IORGLQ, IORGQR, IPHI, ITAUP1, ITAUP2, ITAUQ1, $ ITAUQ2, J, LBBCSDWORK, LBBCSDWORKMIN, $ LBBCSDWORKOPT, LORBDBWORK, LORBDBWORKMIN, $ LORBDBWORKOPT, LORGLQWORK, LORGLQWORKMIN, $ LORGLQWORKOPT, LORGQRWORK, LORGQRWORKMIN, $ LORGQRWORKOPT, LWORKMIN, LWORKOPT, P1, Q1 LOGICAL COLMAJOR, DEFAULTSIGNS, LQUERY, WANTU1, WANTU2, $ WANTV1T, WANTV2T INTEGER LRWORKMIN, LRWORKOPT LOGICAL LRQUERY * .. * .. External Subroutines .. EXTERNAL XERBLA, CBBCSD, CLACPY, CLAPMR, CLAPMT, CLASCL, $ CLASET, CUNBDB, CUNGLQ, CUNGQR * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Intrinsic Functions INTRINSIC COS, INT, MAX, MIN, SIN * .. * .. Executable Statements .. * * Test input arguments * INFO = 0 WANTU1 = LSAME( JOBU1, 'Y' ) WANTU2 = LSAME( JOBU2, 'Y' ) WANTV1T = LSAME( JOBV1T, 'Y' ) WANTV2T = LSAME( JOBV2T, 'Y' ) COLMAJOR = .NOT. LSAME( TRANS, 'T' ) DEFAULTSIGNS = .NOT. LSAME( SIGNS, 'O' ) LQUERY = LWORK .EQ. -1 LRQUERY = LRWORK .EQ. -1 IF( M .LT. 0 ) THEN INFO = -7 ELSE IF( P .LT. 0 .OR. P .GT. M ) THEN INFO = -8 ELSE IF( Q .LT. 0 .OR. Q .GT. M ) THEN INFO = -9 ELSE IF ( COLMAJOR .AND. LDX11 .LT. MAX( 1, P ) ) THEN INFO = -11 ELSE IF (.NOT. COLMAJOR .AND. LDX11 .LT. MAX( 1, Q ) ) THEN INFO = -11 ELSE IF (COLMAJOR .AND. LDX12 .LT. MAX( 1, P ) ) THEN INFO = -13 ELSE IF (.NOT. COLMAJOR .AND. LDX12 .LT. MAX( 1, M-Q ) ) THEN INFO = -13 ELSE IF (COLMAJOR .AND. LDX21 .LT. MAX( 1, M-P ) ) THEN INFO = -15 ELSE IF (.NOT. COLMAJOR .AND. LDX21 .LT. MAX( 1, Q ) ) THEN INFO = -15 ELSE IF (COLMAJOR .AND. LDX22 .LT. MAX( 1, M-P ) ) THEN INFO = -17 ELSE IF (.NOT. COLMAJOR .AND. LDX22 .LT. MAX( 1, M-Q ) ) THEN INFO = -17 ELSE IF( WANTU1 .AND. LDU1 .LT. P ) THEN INFO = -20 ELSE IF( WANTU2 .AND. LDU2 .LT. M-P ) THEN INFO = -22 ELSE IF( WANTV1T .AND. LDV1T .LT. Q ) THEN INFO = -24 ELSE IF( WANTV2T .AND. LDV2T .LT. M-Q ) THEN INFO = -26 END IF * * Work with transpose if convenient * IF( INFO .EQ. 0 .AND. MIN( P, M-P ) .LT. MIN( Q, M-Q ) ) THEN IF( COLMAJOR ) THEN TRANST = 'T' ELSE TRANST = 'N' END IF IF( DEFAULTSIGNS ) THEN SIGNST = 'O' ELSE SIGNST = 'D' END IF CALL CUNCSD( JOBV1T, JOBV2T, JOBU1, JOBU2, TRANST, SIGNST, M, $ Q, P, X11, LDX11, X21, LDX21, X12, LDX12, X22, $ LDX22, THETA, V1T, LDV1T, V2T, LDV2T, U1, LDU1, $ U2, LDU2, WORK, LWORK, RWORK, LRWORK, IWORK, $ INFO ) RETURN END IF * * Work with permutation [ 0 I; I 0 ] * X * [ 0 I; I 0 ] if * convenient * IF( INFO .EQ. 0 .AND. M-Q .LT. Q ) THEN IF( DEFAULTSIGNS ) THEN SIGNST = 'O' ELSE SIGNST = 'D' END IF CALL CUNCSD( JOBU2, JOBU1, JOBV2T, JOBV1T, TRANS, SIGNST, M, $ M-P, M-Q, X22, LDX22, X21, LDX21, X12, LDX12, X11, $ LDX11, THETA, U2, LDU2, U1, LDU1, V2T, LDV2T, V1T, $ LDV1T, WORK, LWORK, RWORK, LRWORK, IWORK, INFO ) RETURN END IF * * Compute workspace * IF( INFO .EQ. 0 ) THEN * * Real workspace * IPHI = 2 IB11D = IPHI + MAX( 1, Q - 1 ) IB11E = IB11D + MAX( 1, Q ) IB12D = IB11E + MAX( 1, Q - 1 ) IB12E = IB12D + MAX( 1, Q ) IB21D = IB12E + MAX( 1, Q - 1 ) IB21E = IB21D + MAX( 1, Q ) IB22D = IB21E + MAX( 1, Q - 1 ) IB22E = IB22D + MAX( 1, Q ) IBBCSD = IB22E + MAX( 1, Q - 1 ) CALL CBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, $ THETA, THETA, U1, LDU1, U2, LDU2, V1T, LDV1T, $ V2T, LDV2T, THETA, THETA, THETA, THETA, THETA, $ THETA, THETA, THETA, RWORK, -1, CHILDINFO ) LBBCSDWORKOPT = INT( RWORK(1) ) LBBCSDWORKMIN = LBBCSDWORKOPT LRWORKOPT = IBBCSD + LBBCSDWORKOPT - 1 LRWORKMIN = IBBCSD + LBBCSDWORKMIN - 1 RWORK(1) = LRWORKOPT * * Complex workspace * ITAUP1 = 2 ITAUP2 = ITAUP1 + MAX( 1, P ) ITAUQ1 = ITAUP2 + MAX( 1, M - P ) ITAUQ2 = ITAUQ1 + MAX( 1, Q ) IORGQR = ITAUQ2 + MAX( 1, M - Q ) CALL CUNGQR( M-Q, M-Q, M-Q, 0, MAX(1,M-Q), U1, WORK, -1, $ CHILDINFO ) LORGQRWORKOPT = INT( WORK(1) ) LORGQRWORKMIN = MAX( 1, M - Q ) IORGLQ = ITAUQ2 + MAX( 1, M - Q ) CALL CUNGLQ( M-Q, M-Q, M-Q, 0, MAX(1,M-Q), U1, WORK, -1, $ CHILDINFO ) LORGLQWORKOPT = INT( WORK(1) ) LORGLQWORKMIN = MAX( 1, M - Q ) IORBDB = ITAUQ2 + MAX( 1, M - Q ) CALL CUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, $ X21, LDX21, X22, LDX22, THETA, THETA, U1, U2, $ V1T, V2T, WORK, -1, CHILDINFO ) LORBDBWORKOPT = INT( WORK(1) ) LORBDBWORKMIN = LORBDBWORKOPT LWORKOPT = MAX( IORGQR + LORGQRWORKOPT, IORGLQ + LORGLQWORKOPT, $ IORBDB + LORBDBWORKOPT ) - 1 LWORKMIN = MAX( IORGQR + LORGQRWORKMIN, IORGLQ + LORGLQWORKMIN, $ IORBDB + LORBDBWORKMIN ) - 1 WORK(1) = MAX(LWORKOPT,LWORKMIN) * IF( LWORK .LT. LWORKMIN $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN INFO = -22 ELSE IF( LRWORK .LT. LRWORKMIN $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN INFO = -24 ELSE LORGQRWORK = LWORK - IORGQR + 1 LORGLQWORK = LWORK - IORGLQ + 1 LORBDBWORK = LWORK - IORBDB + 1 LBBCSDWORK = LRWORK - IBBCSD + 1 END IF END IF * * Abort if any illegal arguments * IF( INFO .NE. 0 ) THEN CALL XERBLA( 'CUNCSD', -INFO ) RETURN ELSE IF( LQUERY .OR. LRQUERY ) THEN RETURN END IF * * Transform to bidiagonal block form * CALL CUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, X21, $ LDX21, X22, LDX22, THETA, RWORK(IPHI), WORK(ITAUP1), $ WORK(ITAUP2), WORK(ITAUQ1), WORK(ITAUQ2), $ WORK(IORBDB), LORBDBWORK, CHILDINFO ) * * Accumulate Householder reflectors * IF( COLMAJOR ) THEN IF( WANTU1 .AND. P .GT. 0 ) THEN CALL CLACPY( 'L', P, Q, X11, LDX11, U1, LDU1 ) CALL CUNGQR( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGQR), $ LORGQRWORK, INFO) END IF IF( WANTU2 .AND. M-P .GT. 0 ) THEN CALL CLACPY( 'L', M-P, Q, X21, LDX21, U2, LDU2 ) CALL CUNGQR( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2), $ WORK(IORGQR), LORGQRWORK, INFO ) END IF IF( WANTV1T .AND. Q .GT. 0 ) THEN CALL CLACPY( 'U', Q-1, Q-1, X11(1,2), LDX11, V1T(2,2), $ LDV1T ) V1T(1, 1) = ONE DO J = 2, Q V1T(1,J) = ZERO V1T(J,1) = ZERO END DO CALL CUNGLQ( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1), $ WORK(IORGLQ), LORGLQWORK, INFO ) END IF IF( WANTV2T .AND. M-Q .GT. 0 ) THEN CALL CLACPY( 'U', P, M-Q, X12, LDX12, V2T, LDV2T ) IF( M-P .GT. Q ) THEN CALL CLACPY( 'U', M-P-Q, M-P-Q, X22(Q+1,P+1), LDX22, $ V2T(P+1,P+1), LDV2T ) END IF IF( M .GT. Q ) THEN CALL CUNGLQ( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2), $ WORK(IORGLQ), LORGLQWORK, INFO ) END IF END IF ELSE IF( WANTU1 .AND. P .GT. 0 ) THEN CALL CLACPY( 'U', Q, P, X11, LDX11, U1, LDU1 ) CALL CUNGLQ( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGLQ), $ LORGLQWORK, INFO) END IF IF( WANTU2 .AND. M-P .GT. 0 ) THEN CALL CLACPY( 'U', Q, M-P, X21, LDX21, U2, LDU2 ) CALL CUNGLQ( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2), $ WORK(IORGLQ), LORGLQWORK, INFO ) END IF IF( WANTV1T .AND. Q .GT. 0 ) THEN CALL CLACPY( 'L', Q-1, Q-1, X11(2,1), LDX11, V1T(2,2), $ LDV1T ) V1T(1, 1) = ONE DO J = 2, Q V1T(1,J) = ZERO V1T(J,1) = ZERO END DO CALL CUNGQR( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1), $ WORK(IORGQR), LORGQRWORK, INFO ) END IF IF( WANTV2T .AND. M-Q .GT. 0 ) THEN P1 = MIN( P+1, M ) Q1 = MIN( Q+1, M ) CALL CLACPY( 'L', M-Q, P, X12, LDX12, V2T, LDV2T ) IF ( M .GT. P+Q ) THEN CALL CLACPY( 'L', M-P-Q, M-P-Q, X22(P1,Q1), LDX22, $ V2T(P+1,P+1), LDV2T ) END IF CALL CUNGQR( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2), $ WORK(IORGQR), LORGQRWORK, INFO ) END IF END IF * * Compute the CSD of the matrix in bidiagonal-block form * CALL CBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, THETA, $ RWORK(IPHI), U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, $ LDV2T, RWORK(IB11D), RWORK(IB11E), RWORK(IB12D), $ RWORK(IB12E), RWORK(IB21D), RWORK(IB21E), $ RWORK(IB22D), RWORK(IB22E), RWORK(IBBCSD), $ LBBCSDWORK, INFO ) * * Permute rows and columns to place identity submatrices in top- * left corner of (1,1)-block and/or bottom-right corner of (1,2)- * block and/or bottom-right corner of (2,1)-block and/or top-left * corner of (2,2)-block * IF( Q .GT. 0 .AND. WANTU2 ) THEN DO I = 1, Q IWORK(I) = M - P - Q + I END DO DO I = Q + 1, M - P IWORK(I) = I - Q END DO IF( COLMAJOR ) THEN CALL CLAPMT( .FALSE., M-P, M-P, U2, LDU2, IWORK ) ELSE CALL CLAPMR( .FALSE., M-P, M-P, U2, LDU2, IWORK ) END IF END IF IF( M .GT. 0 .AND. WANTV2T ) THEN DO I = 1, P IWORK(I) = M - P - Q + I END DO DO I = P + 1, M - Q IWORK(I) = I - P END DO IF( .NOT. COLMAJOR ) THEN CALL CLAPMT( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK ) ELSE CALL CLAPMR( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK ) END IF END IF * RETURN * * End CUNCSD * END
bsd-3-clause
james-monkeyshines/rna-phase-3
blas/dtrsm.f
39
12281
SUBROUTINE DTRSM ( SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA, $ B, LDB ) * .. Scalar Arguments .. CHARACTER*1 SIDE, UPLO, TRANSA, DIAG INTEGER M, N, LDA, LDB DOUBLE PRECISION ALPHA * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), B( LDB, * ) * .. * * Purpose * ======= * * DTRSM solves one of the matrix equations * * op( A )*X = alpha*B, or X*op( A ) = alpha*B, * * where alpha is a scalar, X and B are m by n matrices, A is a unit, or * non-unit, upper or lower triangular matrix and op( A ) is one of * * op( A ) = A or op( A ) = A'. * * The matrix X is overwritten on B. * * Parameters * ========== * * SIDE - CHARACTER*1. * On entry, SIDE specifies whether op( A ) appears on the left * or right of X as follows: * * SIDE = 'L' or 'l' op( A )*X = alpha*B. * * SIDE = 'R' or 'r' X*op( A ) = alpha*B. * * Unchanged on exit. * * UPLO - CHARACTER*1. * On entry, UPLO specifies whether the matrix A is an upper or * lower triangular matrix as follows: * * UPLO = 'U' or 'u' A is an upper triangular matrix. * * UPLO = 'L' or 'l' A is a lower triangular matrix. * * Unchanged on exit. * * TRANSA - CHARACTER*1. * On entry, TRANSA specifies the form of op( A ) to be used in * the matrix multiplication as follows: * * TRANSA = 'N' or 'n' op( A ) = A. * * TRANSA = 'T' or 't' op( A ) = A'. * * TRANSA = 'C' or 'c' op( A ) = A'. * * Unchanged on exit. * * DIAG - CHARACTER*1. * On entry, DIAG specifies whether or not A is unit triangular * as follows: * * DIAG = 'U' or 'u' A is assumed to be unit triangular. * * DIAG = 'N' or 'n' A is not assumed to be unit * triangular. * * Unchanged on exit. * * M - INTEGER. * On entry, M specifies the number of rows of B. M must be at * least zero. * Unchanged on exit. * * N - INTEGER. * On entry, N specifies the number of columns of B. N must be * at least zero. * Unchanged on exit. * * ALPHA - DOUBLE PRECISION. * On entry, ALPHA specifies the scalar alpha. When alpha is * zero then A is not referenced and B need not be set before * entry. * Unchanged on exit. * * A - DOUBLE PRECISION array of DIMENSION ( LDA, k ), where k is m * when SIDE = 'L' or 'l' and is n when SIDE = 'R' or 'r'. * Before entry with UPLO = 'U' or 'u', the leading k by k * upper triangular part of the array A must contain the upper * triangular matrix and the strictly lower triangular part of * A is not referenced. * Before entry with UPLO = 'L' or 'l', the leading k by k * lower triangular part of the array A must contain the lower * triangular matrix and the strictly upper triangular part of * A is not referenced. * Note that when DIAG = 'U' or 'u', the diagonal elements of * A are not referenced either, but are assumed to be unity. * Unchanged on exit. * * LDA - INTEGER. * On entry, LDA specifies the first dimension of A as declared * in the calling (sub) program. When SIDE = 'L' or 'l' then * LDA must be at least max( 1, m ), when SIDE = 'R' or 'r' * then LDA must be at least max( 1, n ). * Unchanged on exit. * * B - DOUBLE PRECISION array of DIMENSION ( LDB, n ). * Before entry, the leading m by n part of the array B must * contain the right-hand side matrix B, and on exit is * overwritten by the solution matrix X. * * LDB - INTEGER. * On entry, LDB specifies the first dimension of B as declared * in the calling (sub) program. LDB must be at least * max( 1, m ). * Unchanged on exit. * * * Level 3 Blas routine. * * * -- Written on 8-February-1989. * Jack Dongarra, Argonne National Laboratory. * Iain Duff, AERE Harwell. * Jeremy Du Croz, Numerical Algorithms Group Ltd. * Sven Hammarling, Numerical Algorithms Group Ltd. * * * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. External Subroutines .. EXTERNAL XERBLA * .. Intrinsic Functions .. INTRINSIC MAX * .. Local Scalars .. LOGICAL LSIDE, NOUNIT, UPPER INTEGER I, INFO, J, K, NROWA DOUBLE PRECISION TEMP * .. Parameters .. DOUBLE PRECISION ONE , ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) * .. * .. Executable Statements .. * * Test the input parameters. * LSIDE = LSAME( SIDE , 'L' ) IF( LSIDE )THEN NROWA = M ELSE NROWA = N END IF NOUNIT = LSAME( DIAG , 'N' ) UPPER = LSAME( UPLO , 'U' ) * INFO = 0 IF( ( .NOT.LSIDE ).AND. $ ( .NOT.LSAME( SIDE , 'R' ) ) )THEN INFO = 1 ELSE IF( ( .NOT.UPPER ).AND. $ ( .NOT.LSAME( UPLO , 'L' ) ) )THEN INFO = 2 ELSE IF( ( .NOT.LSAME( TRANSA, 'N' ) ).AND. $ ( .NOT.LSAME( TRANSA, 'T' ) ).AND. $ ( .NOT.LSAME( TRANSA, 'C' ) ) )THEN INFO = 3 ELSE IF( ( .NOT.LSAME( DIAG , 'U' ) ).AND. $ ( .NOT.LSAME( DIAG , 'N' ) ) )THEN INFO = 4 ELSE IF( M .LT.0 )THEN INFO = 5 ELSE IF( N .LT.0 )THEN INFO = 6 ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN INFO = 9 ELSE IF( LDB.LT.MAX( 1, M ) )THEN INFO = 11 END IF IF( INFO.NE.0 )THEN CALL XERBLA( 'DTRSM ', INFO ) RETURN END IF * * Quick return if possible. * IF( N.EQ.0 ) $ RETURN * * And when alpha.eq.zero. * IF( ALPHA.EQ.ZERO )THEN DO 20, J = 1, N DO 10, I = 1, M B( I, J ) = ZERO 10 CONTINUE 20 CONTINUE RETURN END IF * * Start the operations. * IF( LSIDE )THEN IF( LSAME( TRANSA, 'N' ) )THEN * * Form B := alpha*inv( A )*B. * IF( UPPER )THEN DO 60, J = 1, N IF( ALPHA.NE.ONE )THEN DO 30, I = 1, M B( I, J ) = ALPHA*B( I, J ) 30 CONTINUE END IF DO 50, K = M, 1, -1 IF( B( K, J ).NE.ZERO )THEN IF( NOUNIT ) $ B( K, J ) = B( K, J )/A( K, K ) DO 40, I = 1, K - 1 B( I, J ) = B( I, J ) - B( K, J )*A( I, K ) 40 CONTINUE END IF 50 CONTINUE 60 CONTINUE ELSE DO 100, J = 1, N IF( ALPHA.NE.ONE )THEN DO 70, I = 1, M B( I, J ) = ALPHA*B( I, J ) 70 CONTINUE END IF DO 90 K = 1, M IF( B( K, J ).NE.ZERO )THEN IF( NOUNIT ) $ B( K, J ) = B( K, J )/A( K, K ) DO 80, I = K + 1, M B( I, J ) = B( I, J ) - B( K, J )*A( I, K ) 80 CONTINUE END IF 90 CONTINUE 100 CONTINUE END IF ELSE * * Form B := alpha*inv( A' )*B. * IF( UPPER )THEN DO 130, J = 1, N DO 120, I = 1, M TEMP = ALPHA*B( I, J ) DO 110, K = 1, I - 1 TEMP = TEMP - A( K, I )*B( K, J ) 110 CONTINUE IF( NOUNIT ) $ TEMP = TEMP/A( I, I ) B( I, J ) = TEMP 120 CONTINUE 130 CONTINUE ELSE DO 160, J = 1, N DO 150, I = M, 1, -1 TEMP = ALPHA*B( I, J ) DO 140, K = I + 1, M TEMP = TEMP - A( K, I )*B( K, J ) 140 CONTINUE IF( NOUNIT ) $ TEMP = TEMP/A( I, I ) B( I, J ) = TEMP 150 CONTINUE 160 CONTINUE END IF END IF ELSE IF( LSAME( TRANSA, 'N' ) )THEN * * Form B := alpha*B*inv( A ). * IF( UPPER )THEN DO 210, J = 1, N IF( ALPHA.NE.ONE )THEN DO 170, I = 1, M B( I, J ) = ALPHA*B( I, J ) 170 CONTINUE END IF DO 190, K = 1, J - 1 IF( A( K, J ).NE.ZERO )THEN DO 180, I = 1, M B( I, J ) = B( I, J ) - A( K, J )*B( I, K ) 180 CONTINUE END IF 190 CONTINUE IF( NOUNIT )THEN TEMP = ONE/A( J, J ) DO 200, I = 1, M B( I, J ) = TEMP*B( I, J ) 200 CONTINUE END IF 210 CONTINUE ELSE DO 260, J = N, 1, -1 IF( ALPHA.NE.ONE )THEN DO 220, I = 1, M B( I, J ) = ALPHA*B( I, J ) 220 CONTINUE END IF DO 240, K = J + 1, N IF( A( K, J ).NE.ZERO )THEN DO 230, I = 1, M B( I, J ) = B( I, J ) - A( K, J )*B( I, K ) 230 CONTINUE END IF 240 CONTINUE IF( NOUNIT )THEN TEMP = ONE/A( J, J ) DO 250, I = 1, M B( I, J ) = TEMP*B( I, J ) 250 CONTINUE END IF 260 CONTINUE END IF ELSE * * Form B := alpha*B*inv( A' ). * IF( UPPER )THEN DO 310, K = N, 1, -1 IF( NOUNIT )THEN TEMP = ONE/A( K, K ) DO 270, I = 1, M B( I, K ) = TEMP*B( I, K ) 270 CONTINUE END IF DO 290, J = 1, K - 1 IF( A( J, K ).NE.ZERO )THEN TEMP = A( J, K ) DO 280, I = 1, M B( I, J ) = B( I, J ) - TEMP*B( I, K ) 280 CONTINUE END IF 290 CONTINUE IF( ALPHA.NE.ONE )THEN DO 300, I = 1, M B( I, K ) = ALPHA*B( I, K ) 300 CONTINUE END IF 310 CONTINUE ELSE DO 360, K = 1, N IF( NOUNIT )THEN TEMP = ONE/A( K, K ) DO 320, I = 1, M B( I, K ) = TEMP*B( I, K ) 320 CONTINUE END IF DO 340, J = K + 1, N IF( A( J, K ).NE.ZERO )THEN TEMP = A( J, K ) DO 330, I = 1, M B( I, J ) = B( I, J ) - TEMP*B( I, K ) 330 CONTINUE END IF 340 CONTINUE IF( ALPHA.NE.ONE )THEN DO 350, I = 1, M B( I, K ) = ALPHA*B( I, K ) 350 CONTINUE END IF 360 CONTINUE END IF END IF END IF * RETURN * * End of DTRSM . * END
gpl-3.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/TESTING/EIG/dlatb9.f
32
9404
*> \brief \b DLATB9 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DLATB9( PATH, IMAT, M, P, N, TYPE, KLA, KUA, KLB, KUB, * ANORM, BNORM, MODEA, MODEB, CNDNMA, CNDNMB, * DISTA, DISTB ) * * .. Scalar Arguments .. * CHARACTER DISTA, DISTB, TYPE * CHARACTER*3 PATH * INTEGER IMAT, KLA, KLB, KUA, KUB, M, MODEA, MODEB, N, P * DOUBLE PRECISION ANORM, BNORM, CNDNMA, CNDNMB * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLATB9 sets parameters for the matrix generator based on the type of *> matrix to be generated. *> \endverbatim * * Arguments: * ========== * *> \param[in] PATH *> \verbatim *> PATH is CHARACTER*3 *> The LAPACK path name. *> \endverbatim *> *> \param[in] IMAT *> \verbatim *> IMAT is INTEGER *> An integer key describing which matrix to generate for this *> path. *> = 1: A: diagonal, B: upper triangular *> = 2: A: upper triangular, B: upper triangular *> = 3: A: lower triangular, B: upper triangular *> Else: A: general dense, B: general dense *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows in the matrix to be generated. *> \endverbatim *> *> \param[in] P *> \verbatim *> P is INTEGER *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns in the matrix to be generated. *> \endverbatim *> *> \param[out] TYPE *> \verbatim *> TYPE is CHARACTER*1 *> The type of the matrix to be generated: *> = 'S': symmetric matrix; *> = 'P': symmetric positive (semi)definite matrix; *> = 'N': nonsymmetric matrix. *> \endverbatim *> *> \param[out] KLA *> \verbatim *> KLA is INTEGER *> The lower band width of the matrix to be generated. *> \endverbatim *> *> \param[out] KUA *> \verbatim *> KUA is INTEGER *> The upper band width of the matrix to be generated. *> \endverbatim *> *> \param[out] KLB *> \verbatim *> KLB is INTEGER *> The lower band width of the matrix to be generated. *> \endverbatim *> *> \param[out] KUB *> \verbatim *> KUA is INTEGER *> The upper band width of the matrix to be generated. *> \endverbatim *> *> \param[out] ANORM *> \verbatim *> ANORM is DOUBLE PRECISION *> The desired norm of the matrix to be generated. The diagonal *> matrix of singular values or eigenvalues is scaled by this *> value. *> \endverbatim *> *> \param[out] BNORM *> \verbatim *> BNORM is DOUBLE PRECISION *> The desired norm of the matrix to be generated. The diagonal *> matrix of singular values or eigenvalues is scaled by this *> value. *> \endverbatim *> *> \param[out] MODEA *> \verbatim *> MODEA is INTEGER *> A key indicating how to choose the vector of eigenvalues. *> \endverbatim *> *> \param[out] MODEB *> \verbatim *> MODEB is INTEGER *> A key indicating how to choose the vector of eigenvalues. *> \endverbatim *> *> \param[out] CNDNMA *> \verbatim *> CNDNMA is DOUBLE PRECISION *> The desired condition number. *> \endverbatim *> *> \param[out] CNDNMB *> \verbatim *> CNDNMB is DOUBLE PRECISION *> The desired condition number. *> \endverbatim *> *> \param[out] DISTA *> \verbatim *> DISTA is CHARACTER*1 *> The type of distribution to be used by the random number *> generator. *> \endverbatim *> *> \param[out] DISTB *> \verbatim *> DISTB is CHARACTER*1 *> The type of distribution to be used by the random number *> generator. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup double_eig * * ===================================================================== SUBROUTINE DLATB9( PATH, IMAT, M, P, N, TYPE, KLA, KUA, KLB, KUB, $ ANORM, BNORM, MODEA, MODEB, CNDNMA, CNDNMB, $ DISTA, DISTB ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER DISTA, DISTB, TYPE CHARACTER*3 PATH INTEGER IMAT, KLA, KLB, KUA, KUB, M, MODEA, MODEB, N, P DOUBLE PRECISION ANORM, BNORM, CNDNMA, CNDNMB * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION SHRINK, TENTH PARAMETER ( SHRINK = 0.25D0, TENTH = 0.1D+0 ) DOUBLE PRECISION ONE, TEN PARAMETER ( ONE = 1.0D+0, TEN = 1.0D+1 ) * .. * .. Local Scalars .. LOGICAL FIRST DOUBLE PRECISION BADC1, BADC2, EPS, LARGE, SMALL * .. * .. External Functions .. LOGICAL LSAMEN DOUBLE PRECISION DLAMCH EXTERNAL LSAMEN, DLAMCH * .. * .. Intrinsic Functions .. INTRINSIC MAX, SQRT * .. * .. External Subroutines .. EXTERNAL DLABAD * .. * .. Save statement .. SAVE EPS, SMALL, LARGE, BADC1, BADC2, FIRST * .. * .. Data statements .. DATA FIRST / .TRUE. / * .. * .. Executable Statements .. * * Set some constants for use in the subroutine. * IF( FIRST ) THEN FIRST = .FALSE. EPS = DLAMCH( 'Precision' ) BADC2 = TENTH / EPS BADC1 = SQRT( BADC2 ) SMALL = DLAMCH( 'Safe minimum' ) LARGE = ONE / SMALL * * If it looks like we're on a Cray, take the square root of * SMALL and LARGE to avoid overflow and underflow problems. * CALL DLABAD( SMALL, LARGE ) SMALL = SHRINK*( SMALL / EPS ) LARGE = ONE / SMALL END IF * * Set some parameters we don't plan to change. * TYPE = 'N' DISTA = 'S' DISTB = 'S' MODEA = 3 MODEB = 4 * * Set the lower and upper bandwidths. * IF( LSAMEN( 3, PATH, 'GRQ' ) .OR. LSAMEN( 3, PATH, 'LSE' ) .OR. $ LSAMEN( 3, PATH, 'GSV' ) ) THEN * * A: M by N, B: P by N * IF( IMAT.EQ.1 ) THEN * * A: diagonal, B: upper triangular * KLA = 0 KUA = 0 KLB = 0 KUB = MAX( N-1, 0 ) * ELSE IF( IMAT.EQ.2 ) THEN * * A: upper triangular, B: upper triangular * KLA = 0 KUA = MAX( N-1, 0 ) KLB = 0 KUB = MAX( N-1, 0 ) * ELSE IF( IMAT.EQ.3 ) THEN * * A: lower triangular, B: upper triangular * KLA = MAX( M-1, 0 ) KUA = 0 KLB = 0 KUB = MAX( N-1, 0 ) * ELSE * * A: general dense, B: general dense * KLA = MAX( M-1, 0 ) KUA = MAX( N-1, 0 ) KLB = MAX( P-1, 0 ) KUB = MAX( N-1, 0 ) * END IF * ELSE IF( LSAMEN( 3, PATH, 'GQR' ) .OR. LSAMEN( 3, PATH, 'GLM' ) ) $ THEN * * A: N by M, B: N by P * IF( IMAT.EQ.1 ) THEN * * A: diagonal, B: lower triangular * KLA = 0 KUA = 0 KLB = MAX( N-1, 0 ) KUB = 0 ELSE IF( IMAT.EQ.2 ) THEN * * A: lower triangular, B: diagonal * KLA = MAX( N-1, 0 ) KUA = 0 KLB = 0 KUB = 0 * ELSE IF( IMAT.EQ.3 ) THEN * * A: lower triangular, B: upper triangular * KLA = MAX( N-1, 0 ) KUA = 0 KLB = 0 KUB = MAX( P-1, 0 ) * ELSE * * A: general dense, B: general dense * KLA = MAX( N-1, 0 ) KUA = MAX( M-1, 0 ) KLB = MAX( N-1, 0 ) KUB = MAX( P-1, 0 ) END IF * END IF * * Set the condition number and norm. * CNDNMA = TEN*TEN CNDNMB = TEN IF( LSAMEN( 3, PATH, 'GQR' ) .OR. LSAMEN( 3, PATH, 'GRQ' ) .OR. $ LSAMEN( 3, PATH, 'GSV' ) ) THEN IF( IMAT.EQ.5 ) THEN CNDNMA = BADC1 CNDNMB = BADC1 ELSE IF( IMAT.EQ.6 ) THEN CNDNMA = BADC2 CNDNMB = BADC2 ELSE IF( IMAT.EQ.7 ) THEN CNDNMA = BADC1 CNDNMB = BADC2 ELSE IF( IMAT.EQ.8 ) THEN CNDNMA = BADC2 CNDNMB = BADC1 END IF END IF * ANORM = TEN BNORM = TEN*TEN*TEN IF( LSAMEN( 3, PATH, 'GQR' ) .OR. LSAMEN( 3, PATH, 'GRQ' ) ) THEN IF( IMAT.EQ.7 ) THEN ANORM = SMALL BNORM = LARGE ELSE IF( IMAT.EQ.8 ) THEN ANORM = LARGE BNORM = SMALL END IF END IF * IF( N.LE.1 ) THEN CNDNMA = ONE CNDNMB = ONE END IF * RETURN * * End of DLATB9 * END
bsd-3-clause
nvarini/espresso_iohpc
PWCOND/src/summary_tran.f90
14
6479
! ! Copyright (C) 2003-2012 A. Smogunov ! 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 summary_tran_tot() ! ! It writes transmission coefficients onto the file tran_file ! USE kinds, only : DP USE cond, ONLY : nenergy, earr, start_e, last_e, tran_tot, tran_file implicit none integer :: i ! ! Output of T onto the file ! IF (tran_file.NE.' ') then open (4,file=trim(tran_file),form='formatted', status='unknown') write(4,'("# E-Ef, T")') do i = start_e, last_e write(4,'(F12.5,3X,E14.5)') earr(i), tran_tot(i) enddo close(unit=4) ENDIF do i = start_e, last_e write(6,'(a8,F12.5,3X,E14.5)') 'T_tot', earr(i), tran_tot(i) enddo return end subroutine summary_tran_tot subroutine summary_tran_k(ien, nk1, nk2, k1, k2) ! ! Writes the k-resolved transmission ! ! USE kinds, only : DP USE cell_base, ONLY : bg USE symm_base, ONLY: nsym, s, t_rev, time_reversal USE cond, ONLY : xyk, nkpts, tran_file, tran_k, tk_plot implicit none integer :: ien, nk1, nk2, k1, k2, c_tab, nk_full, i, j, l, k integer :: isym, ik integer, allocatable :: fbz_ibz(:) logical :: f real(DP) :: ktmp(2), xmin, xmax, ymin, ymax, segno real(DP), parameter :: eps = 1.0e-5 real(DP), allocatable :: xyk_full(:,:), xyk_full_cart(:,:) CHARACTER(LEN=50) :: filename IF(tran_file.eq.' ') return !-- ! Output of T(k) into a file for the IBZ ! c_tab = LEN("ibz_cryst_"//trim(tran_file)) + 1 filename = "ibz_cryst_"//trim(tran_file) WRITE (filename(c_tab:c_tab+1),'(a2)') '_e' c_tab = c_tab + 2 IF (ien>99) THEN write(filename( c_tab : c_tab+2 ),'(i3)') ien ELSEIF (ien>9) THEN write(filename( c_tab : c_tab+1 ),'(i2)') ien ELSE write(filename( c_tab : c_tab ),'(i1)') ien ENDIF open (4,file=filename,form='formatted', status='replace') write(4,*) "# T(k) in IBZ, [k in cryst. coor.]" write(4,*) "# kx ", " ky ", " T" ! write(4,*) nkpts do i=1, nkpts write(4,'(3E16.5)') xyk(:,i), tran_k(i) end do close(4) !-- !-- ! Expand in the full BZ nk_full = nk1*nk2 ALLOCATE( xyk_full(2,nk_full) ) ALLOCATE( xyk_full_cart(2,nk_full) ) ALLOCATE( fbz_ibz(nk_full) ) xyk_full(:,:) = 0.d0 xyk_full_cart(:,:) = 0.d0 fbz_ibz(:) = 0 ! generate k-points in the full BZ, FBZ DO i = 1, nk1 DO j = 1, nk2 k = (i-1)*nk2 + j xyk_full(1,k) = dble(i-1)/nk1 + dble(k1)/2/nk1 xyk_full(2,k) = dble(j-1)/nk2 + dble(k2)/2/nk2 xyk_full(:,k) = xyk_full(:,k) - nint( xyk_full(:,k) ) ENDDO ENDDO ! for each k in FBZ find equivalent k-point in IBZ do i=1, nk_full ! run over ik in IBZ and over symmetries, isym ik = 1 isym = 1 do while (fbz_ibz(i).eq.0) if(ik.gt.nkpts) call errore('summary_tran_k','k in IBZ not found',1) ! shift by a small 1.d-8 to get -0.5 from both +-0.5 if (t_rev(isym)==1) then segno = -1.d0 else segno = 1.d0 endif ktmp(1) = segno*dot_product(s(1,1:2,isym),xyk(:,ik)) + 1.d-8 ktmp(2) = segno*dot_product(s(2,1:2,isym),xyk(:,ik)) + 1.d-8 ktmp(:) = ktmp(:) - nint( ktmp(:) ) - 1.d-8 ! Check if rotated k-point matches to the point in the FBZ f = (abs(ktmp(1)-xyk_full(1,i))<eps.AND.abs(ktmp(2)-xyk_full(2,i))<eps) if (f) fbz_ibz(i) = ik ! applying time reversal ! if ( fbz_ibz(i).eq.0.and.time_reversal ) then ktmp(1) = -segno*dot_product(s(1,1:2,isym),xyk(:,ik)) + 1.d-8 ktmp(2) = -segno*dot_product(s(2,1:2,isym),xyk(:,ik)) + 1.d-8 ktmp(:) = ktmp(:) - nint( ktmp(:) ) - 1.d-8 ! Check again f = (abs(ktmp(1)-xyk_full(1,i))<eps.AND.abs(ktmp(2)-xyk_full(2,i))<eps) if (f) fbz_ibz(i) = ik endif ! going either to next symm. operation or to next k in IBZ isym = isym + 1 if (isym.gt.nsym) then ik = ik + 1 isym = 1 endif enddo ! write(6,*) 'FBZ_to_IBZ(i) = ', i, fbz_ibz(i) if(fbz_ibz(i).eq.0) call errore('summary_tran_k','equivalent k in IBZ not found',1) enddo !-- !-- ! cartesian coordinates (in units of 2pi/a_0) ! do i=1, nk_full do j = 1, 2 xyk_full_cart(j, i) = bg(j, 1)*xyk_full(1, i) + bg(j, 2) & *xyk_full(2, i) enddo enddo !-- !-- ! Output of T(k) into file for the whole BZ ! ! in cryst. coordinates c_tab = LEN("bz_cryst_"//trim(tran_file)) + 1 filename = "bz_cryst_"//trim(tran_file) WRITE (filename(c_tab:c_tab+1),'(a2)') '_e' c_tab = c_tab + 2 IF (ien>99) THEN write(filename( c_tab : c_tab+2 ),'(i3)') ien ELSEIF (ien>9) THEN write(filename( c_tab : c_tab+1 ),'(i2)') ien ELSE write(filename( c_tab : c_tab ),'(i1)') ien ENDIF open (4,file=filename,form='formatted', status='replace') write(4,*) "# T(k) in full BZ, [k in cryst. coor.]" write(4,*) "# kx ", " ky ", " T" ! write(4,*) nk_full do i=1, nk_full write(4,'(3E16.5)') xyk_full(:,i), tran_k( fbz_ibz(i) ) end do close(4) ! in cartesian coordinates (in 2pi/a_0) c_tab = LEN("bz_cart_"//trim(tran_file)) + 1 filename = "bz_cart_"//trim(tran_file) WRITE (filename(c_tab:c_tab+1),'(a2)') '_e' c_tab = c_tab + 2 IF (ien>99) THEN write(filename( c_tab : c_tab+2 ),'(i3)') ien ELSEIF (ien>9) THEN write(filename( c_tab : c_tab+1 ),'(i2)') ien ELSE write(filename( c_tab : c_tab ),'(i1)') ien ENDIF open (4,file=filename,form='formatted', status='replace') write(4,*) "# T(k) in full BZ, [k in cart. coor.]" write(4,*) "# kx(2pi/a_0)", " ky(2pi/a_0)", " T" ! write(4,*) nk_full !-- ! plot within (tk_plot x FBZ) for better visualization xmin = MINVAL( xyk_full_cart(1,1:nk_full) ) xmax = MAXVAL( xyk_full_cart(1,1:nk_full) ) - xmin ymin = MINVAL( xyk_full_cart(2,1:nk_full) ) ymax = MAXVAL( xyk_full_cart(2,1:nk_full) ) - ymin xmax = xmin + tk_plot*xmax ymax = ymin + tk_plot*ymax !-- k = 2*tk_plot do i=1, nk_full do j = -k, k do l = -k, k ktmp(:) = xyk_full_cart(:,i)+bg(1:2,1)*j+bg(1:2,2)*l f = ktmp(1).ge.xmin.and.ktmp(1).le.xmax.and. & ktmp(2).ge.ymin.and.ktmp(2).le.ymax if (f) write(4,'(3E16.5)') ktmp(1), ktmp(2), tran_k( fbz_ibz(i) ) enddo enddo end do close(4) !-- deallocate( xyk_full ) deallocate( xyk_full_cart ) deallocate( fbz_ibz ) return end subroutine summary_tran_k
gpl-2.0
Arenium/ktools
canon_rates.f
1
13064
c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% c c c copyright (c) 2017 john r. barker, jason a. sonk c c john r. barker c jrbarker@umich.edu c university of michigan c ann arbor, mi 48109-2143 c (734) 763 6239 c c this program is free software; you can redistribute it and/or c modify it under the terms of the gnu general public license (version 2) c as published by the free software foundation. c c this program is distributed in the hope that it will be useful, c but without any warranty; without even the implied warranty of c merchantability or fitness for a particular purpose. see the c gnu general public license for more details. c c see the 'readme' file for a copy of the gnu general public license, c or contact: c c free software foundation, inc. c 59 temple place - suite 330 c boston, ma 02111-1307, usa. c c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subroutine canon_rates include 'declare.inc' real*8 tt,bj,bk,cstop,sstop,hstop real*8 he(nt,rcnt+ntts+pcnt) real*8 s(nt,rcnt+ntts+pcnt) real*8 cp(nt,rcnt+ntts+pcnt) real*8 qelec(nt,rcnt+ntts+pcnt) real*8 qqvib(nt,rcnt+ntts+pcnt) real*8 qrot(nt,rcnt+ntts+pcnt) real*8 qhind(nt,rcnt+ntts+pcnt) real*8 qtrans(nt,rcnt+ntts+pcnt) real*8 rqtot(nt) real*8 tsqtot(nt,ntts) real*8 pqtot(nt) real*8 kfor(nt,ntts) real*8 krev(nt,ntts) real*8 dsr(nt),dhr(nt),dcp(nt),dg(nt),ak(nt) real*8 an,cxx,ecrit,hxx,minq,qq,sxx,we,zpe real*8 qele,qvib,qroq,qhin,qstop,tqstop integer*4 ng,ss logical krof 100 format(I3,1x,F10.2,1x,5(ES15.6,2x)) 200 format(I3,1x,10(ES10.4,2x)) 111 format(I1,2x,I2,2x,10(ES15.6,2x)) 222 format(i3,2x,F10.2,2x,1(ES10.4,2x),4(F10.2,2x)) 223 format(i3,2x,F10.2,2x,1(ES10.4,2x),4(F10.2,2x)) 333 format(A3,2x,A10,2x,1(A10,2x),4(A10,2x)) 334 format(A3,2x,A10,2x,1(A10,2x),4(A10,2x)) 99004 FORMAT (' THERMODYNAMIC QUANTITIES',/, $ ' Standard State = molecule/cc'/,3x, & ' DelS units: cal/K/mole'/3x, & ' DelH units: kcal/mole'/3x, & ' DelCp units: cal/K/mole'/3x, & ' DelG units: kcal/mole'/3x, $ ' Keq => Exp[(delS-delH/T)/R]'/3x, $ 'vKeq => kforward/kreverse'//) call sestamp('canon_rates',1) c initialization do i=1,nt do j=1,rcnt+ntts+pcnt he(i,j)=0.0d0 s(i,j)=0.0d0 cp(i,j)=0.0d0 cxx = 0.0d0 hxx = 0.0d0 sxx = 0.0d0 qelec(i,j)=1.0d0 qqvib(i,j)=1.0d0 qrot(i,j)=1.0d0 qhind(i,j)=1.0d0 qtrans(i,j)=1.0d0 end do rqtot(i)=1.0d0 pqtot(i)=1.0d0 do j=1,ntts tsqtot(i,j)=1.0d0 end do end do c calculate canonical rate constants write(*,*)'Calculating Canonical Rate Contants' do i=1,nt write(*,FMT="(A1,A,t21,F6.2,A)",ADVANCE="NO") achar(13), $ " Percent Complete: ",(real(i)/real(nt))*100.0, "%" tt=temps(i) ! set temperature do j=1,rcnt+ntts+pcnt ! calculate partition functions krof=.false. s(i,j) = rgascm1*dlog(DBLE(Sopt(j))/DBLE(Sym(j))) ! entropy from optical isomers/symmetry qelec(i,j) = qele(tt,j,nele(j),elev,gele,cxx,sxx,hxx) ! qelectronic he(i,j) = he(i,j) + rgascm1*hxx*tt ! H(T)-H(0) cp(i,j) = cp(i,j) + rgascm1*cxx s(i,j) = s(i,j) + rgascm1*sxx qtrans(i,j)=(DSqrt( ( amu(j)*tt )**3) )*1.879333D+20 ! qtranslation (std. state= 1 molecule/cc) he(i,j) = he(i,j) + 2.5d0*rgascm1*tt cp(i,j) = cp(i,j) + 2.5d0*rgascm1 s(i,j) = s(i,j) + rgascm1*(2.5d0 + dlog(qtrans(i,j))) if(ndof(j).ne.0)then ! if polyatomic do k=1, ndof(j) ! loop over all degrees of freedom we=wel(j,k) an=anhl(j,k) ng=int(ngl(j,k)) if( idofl(j,k).eq.'vib' ) then ! qvibration qq=qvib(tt,we,an,ng,cxx,sxx,hxx,zpe) qqvib(i,j) = qqvib(i,j) * qq cp(i,j) = cp(i,j) + cxx * rgascm1 he(i,j) = he(i,j) + hxx * rgascm1 * tt s(i,j) = s(i,j) + sxx * rgascm1 elseif( idofl(j,k).eq.'jro') then ! look for j-rotor we=wel(j,k) bj=we do l=1,ndof(j) if( idofl(j,l).eq.'kro')then ! chek for k-rotor krof=.true. an=wel(j,l) bk=an ng=int(ngl(j,l)) end if end do if(.not.krof)then ! if there is no k-rotor then treat j-rotor as a qro dof qq=qroq(tt,we,ng,int(an),cxx,sxx,hxx) qrot(i,j) = qrot(i,j) * qq cp(i,j) = cp(i,j) + cxx * rgascm1 he(i,j) = he(i,j) + hxx * rgascm1 * tt s(i,j) = s(i,j) + sxx * rgascm1 else qq=tqstop(tt,we,an,ng,cxx,sxx,hxx) ! otherwise use top qrot(i,j) = qrot(i,j) * qq cp(i,j) = cp(i,j) + cxx * rgascm1 he(i,j) = he(i,j) + hxx * rgascm1 * tt s(i,j) = s(i,j) + sxx * rgascm1 end if elseif( idofl(j,k).eq.'qro')then ! qrotation qq=qroq(tt,we,ng,int(an),cxx,sxx,hxx) qrot(i,j) = qrot(i,j) * qq cp(i,j) = cp(i,j) + cxx * rgascm1 he(i,j) = he(i,j) + hxx * rgascm1 * tt s(i,j) = s(i,j) + sxx * rgascm1 elseif( idofl(j,k)(1:2).eq.'hr')then ! qhinderedrotation do l=1,valmax(j,k) evh(l)=evhl(j,k,l) c write(*,*)l,evh(l) end do c write(*,*)'qhin in ',j,tt,valmax(j,k),ng,cxx,sxx,hxx,zpe, c $ (evh(l),l=1,valmax(j,k)) qq=qhin(tt,evh,valmax(j,k),ng,cxx,sxx,hxx,zpe) c write(*,*)'qhin out',j,tt,valmax(j,k),ng,cxx,sxx,hxx,zpe, c $ (evh(l),l=1,valmax(j,k)) qhind(i,j)= qhind(i,j) * qq cp(i,j) = cp(i,j) + cxx * rgascm1 he(i,j) = he(i,j) + hxx * rgascm1 * tt s(i,j) = s(i,j) + sxx * rgascm1 end if end do end if end do end do write(*,*) c multiply parition fuctions together to get total partition function do i=1,nt do j=1,rcnt ! reactant total partition function rqtot(i)=rqtot(i)*qtrans(i,j) ! qtrans rqtot(i)=rqtot(i)*qelec(i,j) ! qelec rqtot(i)=rqtot(i)*qqvib(i,j) ! qvib rqtot(i)=rqtot(i)*qrot(i,j) ! qrot rqtot(i)=rqtot(i)*qhind(i,j) ! qhind rqtot(i)=rqtot(i)/sym(j) ! symmetry end do do j=1,ntts ! ts total partition function tsqtot(i,j)=tsqtot(i,j)*qtrans(i,j+rcnt) ! qtrans tsqtot(i,j)=tsqtot(i,j)*qelec(i,j+rcnt) ! qelec tsqtot(i,j)=tsqtot(i,j)*qqvib(i,j+rcnt) ! qvib tsqtot(i,j)=tsqtot(i,j)*qrot(i,j+rcnt) ! qrot tsqtot(i,j)=tsqtot(i,j)*qhind(i,j+rcnt) ! qhind tsqtot(i,j)=tsqtot(i,j)/sym(rcnt+j) ! symmetry end do c do j=rcnt+ntts+1,rcnt+ntts+pcnt ! product total partition function c pqtot(i)=pqtot(i)*qtrans(i,j) ! qtrans c pqtot(i)=pqtot(i)*qelec(i,j) ! qelec c pqtot(i)=pqtot(i)*qqvib(i,j) ! qvib c pqtot(i)=pqtot(i)*qrot(i,j) ! qrot c pqtot(i)=pqtot(i)*qhind(i,j) ! qhind c pqtot(i)=pqtot(i)/sym(j) ! symmetry c end do do j=1,pcnt ! product total partition function pqtot(i)=pqtot(i)*qtrans(i,j+rcnt+ntts) ! qtrans pqtot(i)=pqtot(i)*qelec(i,j+rcnt+ntts) ! qelec pqtot(i)=pqtot(i)*qqvib(i,j+rcnt+ntts) ! qvib pqtot(i)=pqtot(i)*qrot(i,j+rcnt+ntts) ! qrot pqtot(i)=pqtot(i)*qhind(i,j+rcnt+ntts) ! qhind pqtot(i)=pqtot(i)/sym(j+rcnt+ntts) ! symmetry end do end do c find kforward and krev do i=1,nt do j=1,ntts ecrit=(-1.0d0*delhf(rcnt+j))/(kb*temps(i)) ! forward critical energy kfor(i,j)=tsqtot(i,j)/rqtot(i) kfor(i,j)=kfor(i,j)*dexp(ecrit) kfor(i,j)=kfor(i,j)*((kbj*temps(i))/h) if(pcnt.ne.0)then ecrit=(-1.0d0*delhr(rcnt+j))/(kb*temps(i)) ! reverse critical energy krev(i,j)=tsqtot(i,j)/pqtot(i) krev(i,j)=krev(i,j)*dexp(ecrit) krev(i,j)=krev(i,j)*((kbj*temps(i))/h) end if end do end do c write out all k rates to canonical file call canon_writeout(kfor,krev,rqtot,tsqtot,pqtot,qqvib,qrot,qhind, $qelec,qtrans) c do i=1,nt c minq=tsqtot(i,1) c do j=1,ntts c if(tsqtot(i,j).lt.minq)minq=tsqtot(i,j) c end do c write(*,100)i,temps(i),rqtot(i),pqtot(i),minq,kfor(i,1), c $ krev(i,1) c end do c if reactants and products are present, calculate Keq if( (rcnt.ge.1) .and. (pcnt.ge.1) ) then do i=1,nt dsr(i)=0.0d0 dhr(i)=delh(rcnt+ntts+1) dcp(i)=0.0d0 do j=1,rcnt+ntts+pcnt if(reprod(j).eq.'reac')then dsr(i)=dsr(i)- s(i,j) dhr(i)=dhr(i)-he(i,j) dcp(i)=dcp(i)-cp(i,j) elseif(reprod(j).eq.'prod')then dsr(i)=dsr(i)+ s(i,j) dhr(i)=dhr(i)+he(i,j) dcp(i)=dcp(i)+cp(i,j) end if end do dg(i)=(dsr(i)-(dhr(i)/temps(i))) dg(i)=dg(i)/rgascm1 ak(i)=dexp(dg(i)) queues(i)=ak(i) dsr(i)=(dsr(i)/kcal2nu) dhr(i)=(dhr(i)/kcal2nu) dcp(i)=(dcp(i)/kcal2nu) dg(i)=dhr(i)-(temps(i)*dsr(i)) end do do j=lunit,canunit write(j,*) write(j,*)'Reactants and Products found reporting Kequil.' write(j,*) write(j,99004) if((ntts.gt.0).and.(pcnt.gt.0))then write(j,333)"#","T(K)",'Keq','delS(rxn)','delH(rxn)', $ 'delCp(rxn)','delG(rxn)' write(j,*)('-',i=1,73) do i=1,nt write(j,222)i,temps(i),ak(i), $ dsr(i)*1.0d+03,dhr(i),dcp(i)*1.0d+03,dg(i) end do elseif((ntts.eq.0).and.(pcnt.gt.0))then write(j,334)"#","T(K)",'Keq','delS(rxn)','delH(rxn)', $ 'delCp(rxn)','delG(rxn)' write(j,*)('-',i=1,73) do i=1,nt write(j,223)i,temps(i),ak(i), $ dsr(i)*1.0d+03,dhr(i),dcp(i)*1.0d+03,dg(i) end do elseif((ntts.gt.0).and.(pcnt.eq.0))then write(j,334)"#","T(K)",'Keq','delS(rxn)','delH(rxn)', $ 'delCp(rxn)','delG(rxn)' write(j,*)('-',i=1,73) do i=1,nt write(j,223)i,temps(i),kfor(i,1)/krev(i,1), $ dsr(i)*1.0d+03,dhr(i),dcp(i)*1.0d+03,dg(i) end do end if write(j,*) end do end if write(lunit,*) call sestamp('canon_rates',2) return end subroutine
gpl-2.0
sophAi/ptmd
src/bac/testdist.f
1
10032
program main integer i,j,atom_num1,a1,flag1,cycle_num,np(1000),type1,num real*8 k1a,k1b,k1c,x1(3000),y1(3000),z1(3000),dist1a,dist1b real*8 energy1,R01a,ratio1a,ratio1b,avdist1a,avdist1b,avdist1c real*8 m1a(3000),m1b(3000),m1c(3000),R01c,ratio1c,cent_dist(1000) real*8 distm1a(3000),centx,centy,centz,dist1c,R01b,add_fac real*8 delta(1000,1000),order,order_sum,RA,RB,RAB,RA_total, &RB_total,RAB_total real*8 ratiocent,avdistcent(1000),maxtemp,kx(1000),total_bond character name_xyz1*12,atom1a*2,atom1b*2,quick_name*2 character yn*1,name_dist1*8 character atom_name1a*2,atom_name1b*2 k1=0.D0 avdist1=0.D0 centx=0.D0 centy=0.D0 centz=0.D0 write(*,*) "Quick input?(y/n)" read(*,*) yn if(yn.eq."y")then add_fac=0.01D0 cycle_num=50 R01a=2.556D0 ratio1a=1.D0 R01b=2.884D0 ratio1b=1.D0 R01c=2.556D0 ratio1c=1.D0 ratiocent=1.2D0 write(11,*) cent_dist(i),avdistcent(i),atom_num1 yn="n" write(*,*) "Please input the number of cluster #1(ex:01,02,03..)" read(*,*) num quick_name=char(int(num/10)+48)//char(mod(num,10)+48) name_xyz1="0038CA"//quick_name//".xyz" goto 30 endif write(*,*) "Please input the add factor(default=0.01D0)" read(*,*) add_fac write(*,*) "please input the cycle number(default=50)" read(*,*) cycle_num write(*,*) "Please input the file name of cluster #1:(*.xyz)" read(*,*) name_xyz1 write(*,*) "please input R0 of atom a-a(default=2.556D0)" read(*,*) R01a write(*,*) "Please input the ratio of atom a-a(default=1.D0)" read(*,*) ratio1a write(*,*) "please input R0 of atom b-b(default=2.884D0)" read(*,*) R01b write(*,*) "Please input the ratio of atom b-b(default=1.D0)" read(*,*) ratio1b write(*,*) "please input R0 of atom a-b(default=2.556D0)" read(*,*) R01c write(*,*) "Please input the ratio of atom a-b(default=1.D0)" read(*,*) ratio1c write(*,*) &"Please input the ratio of internal strain(default=1.2D0)" read(*,*) ratiocent 30 name_dist1=name_xyz1 open(10,file=name_dist1//".dist",status="replace") open(1,file=name_xyz1,status="old") read(1,*) atom_num1,energy1 a1=1 flag1=0 do i=1,atom_num1 read(1,*) atom1a,x1(i),y1(i),z1(i) centx=centx+x1(i) centy=centy+y1(i) centz=centz+z1(i) if(atom1a.eq.atom1b.and.flag1.eq.0)then a1=a1+1 atom_name1a=atom1a else atom_name1b=atom1a if(i.ne.1) flag1=1 endif atom1b=atom1a enddo centx=centx/atom_num1 centy=centy/atom_num1 centz=centz/atom_num1 close(1) write(*,*)"Read cluster #1 A=",a1,",atom1=",atom_name1a,",R0=", &R01a,",atom2=",atom_name1b,",R0=",R01b write(10,*)"Read cluster #1 A=",a1,",atom1=",atom_name1a,",R0=", &R01a,",atom2=",atom_name1b,",R0=",R01b do n=1,cycle_num avdist1a=0.D0 avdist1b=0.D0 avdist1c=0.D0 k1a=0.D0 k1b=0.D0 k1c=0.D0 do i=1,atom_num1 m1a(i)=0.D0 m1b(i)=0.D0 m1c(i)=0.D0 distm1a(i)=0.D0 do j=1,atom_num1 delta(i,j)=0.D0 if(i.ne.j)then dist1a=(x1(i)-x1(j))**2+(y1(i)-y1(j))**2+(z1(i)-z1(j))**2 dist1a=dsqrt(dist1a) if((i.le.a1).and.(j.le.a1))then if(dist1a.le.(ratio1a*R01a))then avdist1a=avdist1a+dist1a distm1a(i)=distm1a(i)+dist1a k1a=k1a+1.D0 m1a(i)=m1a(i)+1.D0 delta(i,j)=1.D0 endif else if((i.gt.a1).and.(j.gt.a1))then if(dist1a.le.(ratio1b*R01b))then avdist1a=avdist1a+dist1a distm1a(i)=distm1a(i)+dist1a k1a=k1a+1.D0 m1a(i)=m1a(i)+1.D0 delta(i,j)=1.D0 endif else if(dist1a.le.(ratio1c*R01c))then avdist1a=avdist1a+dist1a distm1a(i)=distm1a(i)+dist1a k1a=k1a+1.D0 m1a(i)=m1a(i)+1.D0 delta(i,j)=1.D0 endif endif endif enddo distm1a(i)=distm1a(i)/m1a(i) enddo do i=1,a1 do j=i+1,a1 dist1b=(x1(i)-x1(j))**2+(y1(i)-y1(j))**2+(z1(i)-z1(j))**2 dist1b=dsqrt(dist1b) if(dist1b.le.(ratio1a*R01a))then avdist1b=avdist1b+dist1b k1b=k1b+1.D0 m1b(i)=m1b(i)+1.D0 endif enddo enddo do i=a1+1,atom_num1 do j=i+1,atom_num1 dist1c=(x1(i)-x1(j))**2+(y1(i)-y1(j))**2+(z1(i)-z1(j))**2 dist1c=dsqrt(dist1c) if(dist1c.le.(ratio1b*R01b))then avdist1c=avdist1c+dist1c k1c=k1c+1.D0 m1c(i)=m1c(i)+1.D0 endif enddo enddo avdist1a=avdist1a/k1a avdist1b=avdist1b/k1b avdist1c=avdist1c/k1c write(10,*) "<STEP>=",n write(10,*) "For ",name_xyz1 write(10,*) "Energy is ",energy1 write(10,*) "Average distance is ",avdist1a write(10,*) "Center of mass=",centx,centy,centz open(11,file=name_xyz1,status="old") read(11,*) atom_num1,energy1 write(10,*) &"# name cent_dist #nearest_bond #aa #bb avg_bondist" RA=0.D0 RB=0.D0 do i=1,atom_num1 read(11,*) atom1a,x1(i),y1(i),z1(i) cent_dist(i)=(x1(i)-centx)**2+(y1(i)-centy)**2+(z1(i)-centz)**2 cent_dist(i)=dsqrt(cent_dist(i)) if(i.le.a1) RA=RA+cent_dist(i) if(i.gt.a1) RB=RB+cent_dist(i) write(10,*) i," ",atom1a,cent_dist(i),m1a(i),m1b(i),m1c(i) &,distm1a(i) enddo RA_total=RA RB_total=RB RAB_total=RA+RB RAB=(RA+RB)/atom_num1 if(a1.ne.0.D0)RA=RA/a1 if(a1.ne.atom_num1)RB=RB/(atom_num1-a1) close(11) write(10,*) atom_name1a,"=",avdist1b,",HIT=",k1b, &",",atom_name1b,"=",avdist1c,",HIT=",k1c write(10,*) atom_name1a,"/",atom_name1b," or ",atom_name1b,"/", &atom_name1a write(10,*) avdist1b/avdist1c," or ",avdist1c/avdist1b write(10,*) "=============================================" write(10,*) C pause ratio1a=ratio1a+add_fac ratio1b=ratio1b+add_fac write(10,*) "=============================================" write(10,*) "Ratio of cluster 1 ",atom_name1a,"=",ratio1a, &",dist=",ratio1a*R01a,",R0=",R01a write(10,*) "Ratio of cluster 1 ",atom_name1b,"=",ratio1b, &",dist=",ratio1b*R01b,",R0=",R01b enddo close(10) open(11,file=name_dist1//"a.txt",status="replace") open(12,file=name_dist1//"b.txt",status="replace") open(13,file=name_dist1//".txt",status="replace") do i=1,atom_num1 kx(i)=0.D0 do j=1,atom_num1 if(i.ne.j)then dist1a=(x1(i)-x1(j))**2+(y1(i)-y1(j))**2+(z1(i)-z1(j))**2 dist1a=dsqrt(dist1a) if((i.le.a1).and.(j.le.a1))then if(dist1a.le.(ratiocent*R01a))then avdistcent(i)=avdistcent(i)+dist1a kx(i)=kx(i)+1.D0 endif else if((i.gt.a1).and.(j.gt.a1))then if(dist1a.le.(ratiocent*R01b))then avdistcent(i)=avdistcent(i)+dist1a kx(i)=kx(i)+1.D0 endif else if(dist1a.le.(ratiocent*R01c))then avdistcent(i)=avdistcent(i)+dist1a kx(i)=kx(i)+1.D0 endif endif endif enddo avdistcent(i)=avdistcent(i)/kx(i) enddo do i=1,atom_num1 np(i)=i enddo do i=1,atom_num1 do j=i+1,atom_num1 if(cent_dist(np(i)).gt.cent_dist(np(j)))then maxtemp=np(i) np(i)=np(j) np(j)=maxtemp endif enddo enddo do i=1,atom_num1 total_bond=avdistcent(np(i))*kx(np(i)) if(np(i).le.a1)then type1=1 write(11,*) &cent_dist(np(i)),avdistcent(np(i)),kx(np(i)),total_bond, &atom_num1-a1,type1 else type1=2 write(12,*) &cent_dist(np(i)),avdistcent(np(i)),kx(np(i)),total_bond, &atom_num1-a1,type1 endif write(13,*) &cent_dist(np(i)),avdistcent(np(i)),kx(np(i)),total_bond, &atom_num1-a1,type1 enddo order_sum=0.D0 write(*,*)order do i=1,atom_num1-1 do j=i+1,atom_num1 order_sum=delta(i,j)+order_sum enddo enddo do i=1,a1 do j=a1+1,atom_num1 order=order+delta(i,j) enddo enddo order=order/order_sum open(31,file="0038CA"//quick_name//".ord",status="replace") write(31,*) 38-num,order,RA,RB,RAB,RA_total,RB_total,RAB_total close(31) close(11) close(12) close(13) write(*,*) &"The Output file is ",name_dist1,".dist , ",name_dist1,".txt" write(*,*) name_dist1,"a.txt and ",name_dist1,"b.txt" write(*,*) "The *.ist file can be use to study the internal" write(*,*) "strain by xmgr,x is the distance from center of mass" write(*,*) "y is the average bond distance per atom" write(*,*) "COMPLETED!!" stop end
gpl-2.0
armnlib/librmn
spectral/gauss8.F
3
5201
*/* RMNLIB - Library of useful routines for C and FORTRAN programming * * Copyright (C) 1975-2001 Division de Recherche en Prevision Numerique * * Environnement Canada * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation, * * version 2.1 of the License. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * * Boston, MA 02111-1307, USA. * */ SUBROUTINE GAUSS8(NRACP,RACP,PG,SIA,RAD,PGSSIN2,SINM1,SINM2,SIN2) * ***************************************************************** * CALCULE LES NRACP RACINES POSITIVES DU POLYNOME DE LEGENDRE DE * DEGRE 2*NRACP (ICI-APRES NOTE PN) DEFINI SUR L INTERVALLE DES * COLATITUDES ALLANT DE 0 (POLE NORD) A PI (POLE SUD). ON SAIT QUE * LES 2*NRACP RACINES SONT ANTI-SYMETRIQUES P/R A L EQUATEUR PI/2, * ETANT POSITIVES ENTRE COLAT=0 ET COLAT =PI/2. * ON CALCULE ENSUITE LES POIDS DE GAUSS ASSOCIES AUX COLATITUDES * GAUSSIENNES (ICI APRES NOTEES CG), AINSI QU UN CERTAIN NOMBRE DE * FONCTIONS DE CG DEFINIES PLUS LOIN. ON RAPPELLE ENFIN QUE LA LATI- * TUDE LAT=COLAT-PI/2, ET DONC QUE SIN(LAT)=COS(COLAT). * NRACP : NOMBRE DE RACINES POSITIVES DU POLYNOME DE LEGENDRE * : DE DEGRE 2*NRACP. * RACP(I) : RACINES DE PN, =SIN(LG)=COS(CG). * PG(I) : POIDS DE GAUSS CORRESPONDANTS. * SIA(I) : SIN(CG)=COS(LG). * RAD(I) : COLATITUDE CG EN RADIANS. * PGSSIN2(I) : POIDS DE GAUSS / (SIN(CG))**2. * SINM1(I) : (SIN(CG))**-1. * SINM2(I) : (SIN(CG))**-2. * VOIR NST 8, CHAP. A, PP.1-7, ET APPENDICE D12, PP. 26-27. * VERSION REVISEE PAR MICHEL BELAND, 9 DECEMBRE 1980. * Version codee en REAL*8 par Bernard Dugas, 4 janvier 1994. * ***************************************************************** * ----------------------------------------------------------------- IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N) * ----------------------------------------------------------------- INTEGER NRACP REAL*8 RACP(NRACP), PG(NRACP), SIA(NRACP) REAL*8 SINM1(NRACP), SINM2(NRACP), SIN2(NRACP) REAL*8 RAD(NRACP), PGSSIN2(NRACP) EXTERNAL ORDLEG8 * -------------------------------------------------------------- * ON DEMANDE UNE PRECISION DE 1.E-13 POUR LES RACINES DE PN. XLIM = 1.E-13 PIS2 = 2.0*ATAN(1.D0) IR = 2*NRACP FI = IR FI1 = FI+1. FN = NRACP * ON UTILISE UNE FORMULE ASYMPTOTIQUE POUR OBTENIR LES VALEURS * APPROXIMATIVES DES COLATITUDES GAUSSIENNES * CG(I) = (PI/2) * (2*I-1)/(2*NRACP). * VOIR ABRAMOWITZ AND STEGUN, P. 787, EQU. 22.16.6 . DO 20 I=1,NRACP DOT = I-1 RACP(I) =-PIS2*(DOT+.5)/FN + PIS2 RACP(I) = SIN(RACP(I)) 20 CONTINUE * ON CALCULE ENSUITE LES CONSTANTES FACTEURS DE P(N+1) ET P(N-1) * DANS L EXPRESSION DE LA PSEUDO-DERIVEE DE PN. DN = FI/SQRT(4.*FI*FI-1.) DN1 = FI1/SQRT(4.*FI1*FI1-1.) A = DN1*FI B = DN*FI1 IRP = IR + 1 IRM = IR -1 * ON EMPLOIE ENSUITE UNE METHODE DE NEWTON POUR AUGMENTER LA PREC. * SI RACTEMP EST UNE SOL. APPROXIMATIVE DE PN(RACP)=0., ALORS LA * SEQUENCE RACTEMP(I+1)=RACTEMP(I)-PN(RACTEMP(I))/DER.PN(RACTEMP(I)) * CONVERGE VERS RACP DE FACON QUADRATIQUE. * VOIR ABRAMOWITZ AND STEGUN, P.18, EQU. 3.9.5. * ORDLEG CALCULE LA VALEUR DE PN (RACP) , NORMALISE. DO 50 I=1,NRACP 42 CALL ORDLEG8(G,RACP(I),IR) CALL ORDLEG8( GM,RACP(I),IRM ) CALL ORDLEG8( GP,RACP(I),IRP ) GT = (A*GP-B*GM)/(RACP(I)*RACP(I)-1.) RACTEMP = RACP(I) - G/GT GTEMP = RACP(I) - RACTEMP RACP(I) = RACTEMP IF( ABS(GTEMP).GT.XLIM) GOTO 42 50 CONTINUE * ON CALCULE ENSUITE LES POIDS DE GAUSS SELON L ALGORITHME * PG(I) = 2./[(1.-RACP(I)**2)*(DER.PN(RACP(I)))**2]. * VOIR ABRAMOWITZ AND STEGUN, P.887, EQU. 25.4.29. * NOTE: ON DOIT MULTIPLIER LA PRECEDENTE FORMULE PAR UN FACTEUR * DE DENORMALISATION, LES PN DONNES PAR ORDLEG ETANT NORMALISES. * ON SE SERT D UNE FORMULE DE RECURRENCE POUR LA DERIVEE DE PN. DO 60 I=1,NRACP A = 2.*(1.-RACP(I)**2) CALL ORDLEG8( B,RACP(I),IRM ) B = B*B*FI*FI PG(I) = A*(FI-.5)/B RAD(I) = ACOS(RACP(I)) SIA(I) = SIN(RAD(I)) C = (SIA(I))**2 SINM1(I) = 1./SIA(I) SINM2(I) = 1./C PGSSIN2(I) = PG(I)/C SIN2(I) = C 60 CONTINUE RETURN END
lgpl-2.1
nvarini/espresso_iohpc
Modules/coulomb_vcut.f90
4
11927
! ! Copyright (C) 2002-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 . ! ! Written by Giovanni Bussi ! Adapted to QE by Andrea Ferretti & Layla Martin Samos ! !---------------------------------- MODULE coulomb_vcut_module !---------------------------------- ! IMPLICIT NONE PRIVATE ! ! general purpose parameters ! INTEGER, PARAMETER :: DP=KIND(1.0d0) REAL(DP), PARAMETER :: PI = 3.14159265358979323846_DP REAL(DP), PARAMETER :: TPI = 2.0_DP * pi REAL(DP), PARAMETER :: FPI = 4.0_DP * pi REAL(DP), PARAMETER :: e2 = 2.0_DP REAL(DP), PARAMETER :: eps6 = 1.0E-6_DP ! ! definitions ! TYPE vcut_type REAL(DP) :: a(3,3) REAL(DP) :: b(3,3) REAL(DP) :: a_omega REAL(DP) :: b_omega REAL(DP), POINTER :: corrected(:,:,:) REAL(DP) :: cutoff LOGICAL :: orthorombic END TYPE vcut_type ! PUBLIC :: vcut_type PUBLIC :: vcut_init PUBLIC :: vcut_get PUBLIC :: vcut_spheric_get PUBLIC :: vcut_destroy PUBLIC :: vcut_info CONTAINS !------------------------------------------ SUBROUTINE vcut_init(vcut,a,cutoff) !------------------------------------------ ! TYPE(vcut_type), INTENT(OUT) :: vcut REAL(DP), INTENT(IN) :: a(3,3) REAL(DP), INTENT(IN) :: cutoff INTEGER :: n1,n2,n3 INTEGER :: i1,i2,i3 INTEGER :: ierr REAL(DP) :: q(3) CHARACTER(9) :: subname='vcut_init' REAL(DP) :: mod2a(3) vcut%cutoff=cutoff vcut%a=a vcut%b= TPI * transpose(num_inverse(vcut%a)) vcut%b_omega=num_determinant(vcut%b) vcut%a_omega=num_determinant(vcut%a) ! automatically finds whether the cell is orthorombic or not vcut%orthorombic=.false. mod2a=sum(vcut%a**2,1) if(sum(vcut%a(:,1)*vcut%a(:,2))/(mod2a(1)*mod2a(2))<eps6 .and. & sum(vcut%a(:,2)*vcut%a(:,3))/(mod2a(2)*mod2a(3))<eps6 .and. & sum(vcut%a(:,3)*vcut%a(:,1))/(mod2a(3)*mod2a(1))<eps6) vcut%orthorombic=.true. n1=ceiling(vcut%cutoff*sqrt(sum(vcut%a(1,:)**2))/(2.0*pi)) n2=ceiling(vcut%cutoff*sqrt(sum(vcut%a(2,:)**2))/(2.0*pi)) n3=ceiling(vcut%cutoff*sqrt(sum(vcut%a(3,:)**2))/(2.0*pi)) ALLOCATE(vcut%corrected(-n1:n1,-n2:n2,-n3:n3), STAT=ierr) IF ( ierr/=0 ) CALL errore(subname,'allocating cvut%corrected',ABS(ierr)) ! vcut%corrected=0.0 ! ! define the Fourier component of the modified Coulomb potential ! DO i1=-n1,n1 DO i2=-n2,n2 DO i3=-n3,n3 ! q = MATMUL(vcut%b,(/i1,i2,i3/)) ! IF( SUM(q**2) > vcut%cutoff**2 ) CYCLE ! vcut%corrected(i1,i2,i3) = & vcut_formula(q,vcut%a,vcut%b,vcut%a_omega,vcut%orthorombic) ! ENDDO ENDDO ENDDO ! END SUBROUTINE vcut_init !------------------------------------------ SUBROUTINE vcut_info(iun, vcut) !------------------------------------------ ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: iun TYPE(vcut_type), INTENT(IN) :: vcut ! INTEGER :: i, n(3) ! IF ( ASSOCIATED( vcut%corrected ) ) THEN ! DO i = 1, 3 n(i) = ( SIZE( vcut%corrected, i) -1 ) / 2 ENDDO ! WRITE(iun, "( 2x,'Cutoff: ',f6.2,4x,' n grid: ',3i4,/)") vcut%cutoff, n(:) ! ENDIF ! END SUBROUTINE vcut_info !------------------------------------------ SUBROUTINE vcut_destroy(vcut) !------------------------------------------ ! TYPE(vcut_type), INTENT(INOUT) :: vcut INTEGER :: ierr ! DEALLOCATE(vcut%corrected, STAT=ierr) IF ( ierr/=0 ) CALL errore('vcut_destroy','deallocating vcut',ABS(ierr)) ! END SUBROUTINE vcut_destroy !------------------------------------------ FUNCTION vcut_get(vcut,q) RESULT(res) !------------------------------------------ ! TYPE(vcut_type), INTENT(IN) :: vcut REAL(DP), INTENT(IN) :: q(3) REAL(DP) :: res ! REAL(DP) :: i_real(3) INTEGER :: i(3) CHARACTER(8) :: subname='vcut_get' ! i_real=(MATMUL(TRANSPOSE(vcut%a),q))/ TPI i=NINT(i_real) ! ! internal check IF( SUM( (i-i_real)**2 ) > eps6 ) & CALL errore(subname,'q vector out of the grid',10) ! IF( SUM(q**2) > vcut%cutoff**2 ) THEN ! ! usual form of Coulomb potential res = FPI * e2 / SUM(q**2) ! ELSE ! IF( i(1)>ubound(vcut%corrected,1) .OR. i(1)<lbound(vcut%corrected,1) .OR. & i(2)>ubound(vcut%corrected,2) .OR. i(2)<lbound(vcut%corrected,2) .OR. & i(3)>ubound(vcut%corrected,3) .OR. i(3)<lbound(vcut%corrected,3)) THEN CALL errore(subname,'index out of bound', 10) ENDIF ! res=vcut%corrected(i(1),i(2),i(3)) ! ENDIF ! END FUNCTION vcut_get !------------------------------------------ FUNCTION vcut_spheric_get(vcut,q) RESULT(res) !------------------------------------------ ! TYPE(vcut_type), INTENT(IN) :: vcut REAL(DP), INTENT(IN) :: q(3) REAL(DP) :: res ! REAl(DP) :: a(3,3), Rcut, kg2 LOGICAL :: limit ! ! a = vcut%a ! Rcut=0.5*minval(sqrt(sum(a**2,1))) Rcut=Rcut-Rcut/50.0 limit=.false. kg2=sum(q**2) if(kg2<eps6) then limit=.true. endif if(.not.limit) then res=FPI*e2/kg2*(1.0-cos(Rcut*sqrt(kg2))) else res=FPI*e2*Rcut**2/2.0 endif ! END FUNCTION vcut_spheric_get !--------------------------------------------------------- FUNCTION vcut_formula(q,a,b,a_omega,orthorombic) result(res) !--------------------------------------------------------- ! ! Define the FT of the Coulomb potential according to the ! current lattice. ! REAL(DP), INTENT(IN) :: q(3) REAL(DP), INTENT(IN) :: a(3,3) REAL(DP), INTENT(IN) :: b(3,3) REAL(DP), INTENT(IN) :: a_omega LOGICAL, INTENT(IN) :: orthorombic REAL(DP) :: res ! real(dp) :: rwigner real(dp) :: sigma rwigner=0.5*sqrt(1.0/maxval(sum(b**2,1)))*2*pi ! ! 3.0 is set to give a short range contribution inside the WS cell ! sigma=3.0/rwigner ! compute longrange and shortrange contributions res=vcut_formula_longrange(q,a,b,a_omega,sigma,6.0D0,orthorombic) & +vcut_formula_shortrange(q,sigma) END FUNCTION vcut_formula !--------------------------------------------------------- FUNCTION vcut_formula_longrange(q,a,b,a_omega,sigma,security,orthorombic) result(res) !--------------------------------------------------------- ! compute the longrange contribution real(dp), intent(in) :: q(3) real(dp), intent(in) :: a(3,3) real(dp), intent(in) :: b(3,3) real(dp), intent(in) :: a_omega real(dp), intent(in) :: sigma real(dp), intent(in) :: security ! it determines the grid for the real-space sum; a reasonable value is 4.0 logical, intent(in) :: orthorombic real(dp) :: res integer :: n1,n2,n3 integer :: i1,i2,i3 real(dp) :: d1,d2,d3,weight,factor real(dp) :: r(3),r2,modr logical :: n1_is_even,n1_is_odd real(dp) :: tmp logical, parameter :: shifted=.false. integer :: n1max real(dp) :: i1_real,i2_real,i3_real real(DP), external :: qe_erf n1=security*sqrt(sum(a(:,1)**2))*sigma n2=security*sqrt(sum(a(:,2)**2))*sigma n3=security*sqrt(sum(a(:,3)**2))*sigma n1_is_even=(n1/2)*2==n1 n1_is_odd=.not.n1_is_even d1=1.0/real(n1,dp) d2=1.0/real(n2,dp) d3=1.0/real(n3,dp) res=0.0 weight=a_omega*d1*d2*d3 ! the only symmetry which can be used for any value of q is inversion ! NON-SHIFTED: ! if n1 is even: loop between 0 and n1/2, with weight=2.0 for all points except 0 and n1max ! if n2 is odd: loop between 0 and (n1+1)/2, with weight=2.0 for all points except 0 ! SHIFTED: ! if n1 is even: loop between 0 and n1/2-1, with weight=2.0 for all points ! if n2 is odd: loop between 0 and (n1+1)/2, with weight=2.0 for all points except n1max if(shifted)then if(n1_is_even) n1max=n1/2-1 if(n1_is_odd) n1max=(n1+1)/2-1 else if(n1_is_even) n1max=n1/2 if(n1_is_odd) n1max=(n1+1)/2 end if do i1=0,n1max factor=2.0 if(shifted) then if(n1_is_odd .and. i1==n1max) factor=1.0 else if(i1==0) factor=1.0 if(n1_is_even .and. i1==n1max) factor=1.0 end if i1_real=i1 if(shifted) i1_real=i1_real+0.5 do i2=0,n2-1 i2_real=i2 if(shifted) i2_real=i2_real+0.5 do i3=0,n3-1 i3_real=i3 if(shifted) i3_real=i3_real+0.5 r=vcut_minimal_image(a,b,matmul(a,(/i1_real*d1,i2_real*d2,i3_real*d3/)),orthorombic) r2=sum(r**2) modr=sqrt(r2) if(modr*sigma<eps6) then tmp=e2*sqrt(2.0/pi)*sigma else tmp=e2*qe_erf(sigma*sqrt(0.5)*modr)/modr end if res=res+weight*factor*tmp*cos(sum(r*q)) end do end do end do END FUNCTION vcut_formula_longrange !--------------------------------------------------------- FUNCTION vcut_formula_shortrange(q,sigma) result(res) !--------------------------------------------------------- real(dp), intent(in) :: q(3) real(dp), intent(in) :: sigma real(dp) :: res if(sum(q**2/(sigma*sigma))<eps6) then ! analytic limit for small q res=e2*tpi/(sigma*sigma) else res=e2*fpi/sum(q**2)*(1-exp(-0.5*sum(q**2)/(sigma*sigma))) end if END FUNCTION vcut_formula_shortrange !--------------------------------------------------------- FUNCTION vcut_minimal_image(a,b,r,orthorombic) result(res) !--------------------------------------------------------- real(dp), intent(in) :: a(3,3) real(dp), intent(in) :: b(3,3) real(dp), intent(in) :: r(3) logical, intent(in) :: orthorombic real(dp) :: res(3) real(dp) :: r_minimal(3) real(dp) :: r2_minimal real(dp) :: r_try(3) real(dp) :: r2_try real(dp) :: r_components(3) integer :: i1,i2,i3 integer, parameter :: max_displacement=1 if(orthorombic) then ! NINT ALGORITHM FOR ORTHOROMBIC CELL r_components=(matmul(transpose(b),r))/(2.0*pi) r_components=r_components-nint(r_components) r_minimal=matmul(a,r_components) else ! POOR MAN ALGORITHM FOR GENERIC CELL r_minimal=r r2_minimal=sum(r_minimal**2) ! loop over the possible neighbours do i1=-max_displacement,max_displacement do i2=-max_displacement,max_displacement do i3=-max_displacement,max_displacement if(i1==0 .and. i2==0 .and. i3==0) cycle r_try=r+matmul(a,(/i1,i2,i3/)) r2_try=sum(r_try**2) if(r2_try<r2_minimal) then r2_minimal=r2_try r_minimal=r_try endif end do end do end do end if res=r_minimal END FUNCTION vcut_minimal_image !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! tools from sax function num_inverse(a) result(inv) real(dp) :: inv(0:2,0:2) real(dp), intent(in) :: a(0:2,0:2) real(dp) :: tmp(0:2,0:2) real(dp) :: det real(dp),parameter :: eye3(3,3) = reshape((/ 1,0,0,0,1,0,0,0,1/),(/3,3/)) integer i,j do i=0,2 do j=0,2 tmp(i,j) = a(modulo(i+1,3),modulo(j+1,3)) * a(modulo(i+2,3),modulo(j+2,3)) & & - a(modulo(i+1,3),modulo(j+2,3)) * a(modulo(i+2,3),modulo(j+1,3)) end do end do det = num_determinant(a) inv = transpose(tmp) / det if(sum((matmul(inv,a))**2-eye3) > 1d-5) then write(0,*) "AHIA",sum((matmul(inv,a)-eye3)**2) write(0,*) "A",a write(0,*) "inv",inv write(0,*)">>", matmul(inv,a) stop end if end function num_inverse function num_determinant(a) result(det) real(dp), intent(in) :: a(3,3) real(dp) :: det det = a(1,1)*a(2,2)*a(3,3) + a(1,2)*a(2,3)*a(3,1) + a(1,3)*a(2,1)*a(3,2) & - a(1,1)*a(2,3)*a(3,2) - a(1,2)*a(2,1)*a(3,3) - a(1,3)*a(2,2)*a(3,1) end function num_determinant !!! end tools from sax !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! END MODULE coulomb_vcut_module
gpl-2.0
buaasun/grappa
applications/NPB/OMP/UA/mason.f
5
74889
c----------------------------------------------------------------- subroutine mortar c----------------------------------------------------------------- c generate mortar point index number c----------------------------------------------------------------- include 'header.h' integer count, iel, jface, ntemp, i, ii, jj, ntemp1, & iii, jjj, face2, ne, ie, edge_g, ie2, & mor_v(3), cb, cb1, cb2, cb3, cb4, cb5, cb6, & space, sumcb, ij1, ij2, n1, n2, n3, n4, n5 n1=lx1*lx1*6*4*nelt n2=8*nelt n3=2*64*nelt n4=12*nelt n5=2*12*nelt call nr_init_omp(idmo,n1,0) call nr_init_omp(nemo,n2,0) call nr_init_omp(vassign,n2,0) call nr_init_omp(emo,n3,0) call l_init_omp(if_1_edge,n4,.false.) call nr_init_omp(diagn,n5,0) c.....Mortar points indices are generated in two steps: first generate c them for all element vertices (corner points), then for conforming c edge and conforming face interiors. Each time a new mortar index c is generated for a mortar point, it is broadcast to all elements c sharing this mortar point. c.....VERTICES count=0 c.....assign mortar point indices to element vertices c$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(iel,sumcb,ij1,ij2, c$OMP& cb,cb1,cb2,ntemp,ntemp1) do iel=1,nelt c.......first calculate how many new mortar indices will be generated for c each element. c.......For each element, at least one vertex (vertex 8) will be new mortar c point. All possible new mortar points will be on face 2,4 or 6. By c checking the type of these three faces, we are able to tell c how many new mortar vertex points will be generated in each element. cb=cbc(6,iel) cb1=cbc(4,iel) cb2=cbc(2,iel) c.......For different combinations of the type of these three faces, c we group them into 27 configurations. c For different face types we assign the following integers: c 1 for type 2 or 3 c 2 for type 0 c 5 for type 1 c By summing these integers for faces 2,4 and 6, sumcb will have c 10 different numbers indicating 10 different combinations. sumcb=0 if(cb.eq.2.or.cb.eq.3)then sumcb=sumcb+1 elseif(cb.eq.0)then sumcb=sumcb+2 elseif(cb.eq.1)then sumcb=sumcb+5 end if if(cb1.eq.2.or.cb1.eq.3)then sumcb=sumcb+1 elseif(cb1.eq.0)then sumcb=sumcb+2 elseif(cb1.eq.1)then sumcb=sumcb+5 end if if(cb2.eq.2.or.cb2.eq.3)then sumcb=sumcb+1 elseif(cb2.eq.0)then sumcb=sumcb+2 elseif(cb2.eq.1)then sumcb=sumcb+5 end if c.......compute newc(iel) c newc(iel) records how many new mortar indices will be generated c for element iel c vassign(i,iel) records the element vertex of the i'th new mortar c vertex point for element iel. e.g. vassign(2,iel)=8 means c the 2nd new mortar vertex point generated on element c iel is iel's 8th vertex. if(sumcb.eq.3)then c.......the three face types for face 2,4, and 6 are 2 2 2 newc(iel)=1 vassign(1,iel)=8 elseif(sumcb.eq.4)then c.......the three face types for face 2,4 and 6 are 2 2 0 (not c necessarily in this order) newc(iel)=2 if(cb.eq.0)then vassign(1,iel)=4 elseif(cb1.eq.0)then vassign(1,iel)=6 elseif(cb2.eq.0)then vassign(1,iel)=7 end if vassign(2,iel)=8 elseif(sumcb.eq.7)then c.......the three face types for face 2,4 and 6 are 2 2 1 (not c necessarily in this order) if(cb.eq.1)then ij1=ijel(1,6,iel) ij2=ijel(2,6,iel) if(ij1.eq.1.and.ij2.eq.1)then newc(iel)=2 vassign(1,iel)=4 vassign(2,iel)=8 elseif(ij1.eq.1.and.ij2.eq.2)then ntemp=sje(1,1,6,iel) if(cbc(1,ntemp).eq.3.and.sje(1,1,1,ntemp).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=4 vassign(2,iel)=8 end if elseif(ij1.eq.2.and.ij2.eq.1)then ntemp=sje(1,1,6,iel) if(cbc(3,ntemp).eq.3.and.sje(1,1,3,ntemp).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=4 vassign(2,iel)=8 endif else newc(iel)=1 vassign(1,iel)=8 end if elseif(cb1.eq.1)then ij1=ijel(1,4,iel) ij2=ijel(2,4,iel) if(ij1.eq.1.and.ij2.eq.1)then newc(iel)=2 vassign(1,iel)=6 vassign(2,iel)=8 elseif(ij1.eq.1.and.ij2.eq.2)then ntemp=sje(1,1,4,iel) if(cbc(1,ntemp).eq.3.and.sje(1,1,1,ntemp).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=6 vassign(2,iel)=8 endif elseif(ij1.eq.2.and.ij2.eq.1)then ntemp=sje(1,1,4,iel) if(cbc(5,ntemp).eq.3.and.sje(1,1,5,ntemp).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=6 vassign(2,iel)=8 endif else newc(iel)=1 vassign(1,iel)=8 end if elseif(cb2.eq.1)then ij1=ijel(1,2,iel) ij2=ijel(2,2,iel) if(ij1.eq.1.and.ij2.eq.1)then newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 elseif(ij1.eq.1.and.ij2.eq.2)then ntemp=sje(1,1,2,iel) if(cbc(3,ntemp).eq.3.and.sje(1,1,3,ntemp).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 end if elseif(ij1.eq.2.and.ij2.eq.1)then ntemp=sje(1,1,2,iel) if(cbc(5,ntemp).eq.3.and.sje(1,1,5,ntemp).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 end if else newc(iel)=1 vassign(1,iel)=8 end if end if elseif(sumcb.eq.5)then c.......the three face types for face 2,4 and 6 are 2/3 0 0 (not c necessarily in this order) newc(iel)=4 if(cb.eq.2.or.cb.eq.3)then vassign(1,iel)=5 vassign(2,iel)=6 vassign(3,iel)=7 vassign(4,iel)=8 elseif(cb1.eq.2.or.cb1.eq.3)then vassign(1,iel)=3 vassign(2,iel)=4 vassign(3,iel)=7 vassign(4,iel)=8 elseif(cb2.eq.2.or.cb2.eq.3)then vassign(1,iel)=2 vassign(2,iel)=4 vassign(3,iel)=6 vassign(4,iel)=8 end if elseif(sumcb.eq.8)then c.......the three face types for face 2,4 and 6 are 2 0 1 (not c necessarily in this order) c.........if face 2 of type 1 if(cb.eq.1)then if(cb1.eq.2.or.cb1.eq.3)then ij1=ijel(1,6,iel) if(ij1.eq.1)then newc(iel)=4 vassign(1,iel)=3 vassign(2,iel)=4 vassign(3,iel)=7 vassign(4,iel)=8 else ntemp=sje(1,1,6,iel) if(cbc(3,ntemp).eq.3.and.sje(1,1,3,ntemp).lt.iel)then newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=7 vassign(3,iel)=8 end if end if elseif(cb2.eq.2.or.cb2.eq.3)then if(ijel(2,6,iel).eq.1)then newc(iel)=4 vassign(1,iel)=2 vassign(2,iel)=4 vassign(3,iel)=6 vassign(4,iel)=8 else ntemp=sje(1,1,6,iel) if(cbc(1,ntemp).eq.3.and.sje(1,1,1,ntemp).lt.iel)then newc(iel)=2 vassign(1,iel)=6 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=6 vassign(3,iel)=8 end if end if end if c.........if face 4 of type 1 elseif(cb1.eq.1)then if(cb.eq.2.or.cb.eq.3)then ij1=ijel(1,4,iel) ij2=ijel(2,4,iel) if(ij1.eq.1.and.ij2.eq.1)then ntemp=sje(1,1,4,iel) if(cbc(2,ntemp).eq.3.and.sje(1,1,2,ntemp).lt.iel)then newc(iel)=3 vassign(1,iel)=6 vassign(2,iel)=7 vassign(3,iel)=8 else newc(iel)=4 vassign(1,iel)=5 vassign(2,iel)=6 vassign(3,iel)=7 vassign(4,iel)=8 end if elseif(ij1.eq.1.and.ij2.eq.2)then ntemp=sje(1,1,4,iel) if(cbc(1,ntemp).eq.3.and.sje(1,1,1,ntemp).lt.iel)then newc(iel)=3 vassign(1,iel)=5 vassign(2,iel)=7 vassign(3,iel)=8 else newc(iel)=4 vassign(1,iel)=5 vassign(2,iel)=6 vassign(3,iel)=7 vassign(4,iel)=8 end if elseif(ij1.eq.2.and.ij2.eq.1)then ntemp=sje(1,1,4,iel) if(cbc(5,ntemp).eq.3.and.sje(1,1,5,ntemp).lt.iel)then newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=6 vassign(2,iel)=7 vassign(3,iel)=8 end if elseif(ij1.eq.2.and.ij2.eq.2)then ntemp=sje(1,1,4,iel) if(cbc(5,ntemp).eq.3.and.sje(1,1,5,ntemp).lt.iel)then newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=5 vassign(2,iel)=7 vassign(3,iel)=8 end if end if else if(ijel(2,4,iel).eq.1)then newc(iel)=4 vassign(1,iel)=2 vassign(2,iel)=4 vassign(3,iel)=6 vassign(4,iel)=8 else ntemp=sje(1,1,4,iel) if(cbc(1,ntemp).eq.3.and.sje(1,1,1,ntemp).lt.iel)then newc(iel)=2 vassign(1,iel)=4 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=6 vassign(3,iel)=8 end if end if endif c.........if face 6 of type 1 elseif(cb2.eq.1)then if(cb.eq.2.or.cb.eq.3)then if(ijel(1,2,iel).eq.1)then newc(iel)=4 vassign(1,iel)=5 vassign(2,iel)=6 vassign(3,iel)=7 vassign(4,iel)=8 else ntemp=sje(1,1,2,iel) if(cbc(5,ntemp).eq.3.and.sje(1,1,5,ntemp).lt.iel)then newc(iel)=2 vassign(1,iel)=6 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=6 vassign(2,iel)=7 vassign(3,iel)=8 end if end if else if(ijel(2,2,iel).eq.1)then newc(iel)=4 vassign(1,iel)=3 vassign(2,iel)=4 vassign(3,iel)=7 vassign(4,iel)=8 else ntemp=sje(1,1,2,iel) if(cbc(3,ntemp).eq.3.and.sje(1,1,3,ntemp).lt.iel)then newc(iel)=2 vassign(1,iel)=4 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=7 vassign(3,iel)=8 end if end if end if end if elseif(sumcb.eq.11)then c.......the three face type for face 2,4 and 6 are 2 1 1(not c necessarily in this order) if(cb.eq.2.or.cb.eq.3)then if(ijel(1,4,iel).eq.1)then ntemp=sje(1,1,4,iel) if(cbc(2,ntemp).eq.3.and.sje(1,1,2,ntemp).lt.iel)then newc(iel)=3 vassign(1,iel)=6 vassign(2,iel)=7 vassign(3,iel)=8 else newc(iel)=4 vassign(1,iel)=5 vassign(2,iel)=6 vassign(3,iel)=7 vassign(4,iel)=8 end if c...........if ijel(1,4,iel)=2 else ntemp=sje(1,1,2,iel) if(cbc(5,ntemp).eq.3.and.sje(1,1,5,ntemp).lt.iel)then ntemp1=sje(1,1,4,iel) if(cbc(5,ntemp1).eq.3.and. & sje(1,1,5,ntemp1).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=6 vassign(2,iel)=8 end if else ntemp1=sje(1,1,4,iel) if(cbc(5,ntemp1).eq.3.and. & sje(1,1,5,ntemp1).lt.iel)then newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=6 vassign(2,iel)=7 vassign(3,iel)=8 end if end if end if elseif(cb1.eq.2.or.cb1.eq.3)then if(ijel(2,2,iel).eq.1)then ntemp=sje(1,1,2,iel) if(cbc(6,ntemp).eq.3.and.sje(1,1,6,ntemp).lt.iel)then newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=7 vassign(3,iel)=8 else newc(iel)=4 vassign(1,iel)=3 vassign(2,iel)=4 vassign(3,iel)=7 vassign(4,iel)=8 end if c...........if ijel(2,2,iel)=2 else ntemp=sje(1,1,2,iel) if(cbc(3,ntemp).eq.3.and.sje(1,1,3,ntemp).lt.iel)then ntemp1=sje(1,1,6,iel) if(cbc(3,ntemp1).eq.3.and. & sje(1,1,3,ntemp1).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=4 vassign(2,iel)=8 end if else ntemp1=sje(1,1,6,iel) if(cbc(3,ntemp1).eq.3.and. & sje(1,1,3,ntemp1).lt.iel)then newc(iel)=2 vassign(1,iel)=7 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=7 vassign(3,iel)=8 end if end if end if elseif(cb2.eq.2.or.cb2.eq.3)then if(ijel(2,6,iel).eq.1)then ntemp=sje(1,1,4,iel) if(cbc(6,ntemp).eq.3.and.sje(1,1,6,ntemp).lt.iel)then newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=6 vassign(3,iel)=8 else newc(iel)=4 vassign(1,iel)=2 vassign(2,iel)=4 vassign(3,iel)=6 vassign(4,iel)=8 end if c...........if ijel(2,6,iel)=2 else ntemp=sje(1,1,4,iel) if(cbc(1,ntemp).eq.3.and.sje(1,1,1,ntemp).lt.iel)then ntemp1=sje(1,1,6,iel) if(cbc(1,ntemp1).eq.3.and. & sje(1,1,1,ntemp1).lt.iel)then newc(iel)=1 vassign(1,iel)=8 else newc(iel)=2 vassign(1,iel)=4 vassign(2,iel)=8 end if else ntemp1=sje(1,1,6,iel) if(cbc(1,ntemp1).eq.3.and. & sje(1,1,1,ntemp1).lt.iel)then newc(iel)=2 vassign(1,iel)=6 vassign(2,iel)=8 else newc(iel)=3 vassign(1,iel)=4 vassign(2,iel)=6 vassign(3,iel)=8 end if end if end if end if elseif(sumcb.eq.6)then c.......the three face type for face 2,4 and 6 are 0 0 0(not c necessarily in this order) newc(iel)=8 vassign(1,iel)=1 vassign(2,iel)=2 vassign(3,iel)=3 vassign(4,iel)=4 vassign(5,iel)=5 vassign(6,iel)=6 vassign(7,iel)=7 vassign(8,iel)=8 elseif(sumcb.eq.9)then c.......the three face type for face 2,4 and 6 are 0 0 1(not c necessarily in this order) newc(iel)=7 vassign(1,iel)=2 vassign(2,iel)=3 vassign(3,iel)=4 vassign(4,iel)=5 vassign(5,iel)=6 vassign(6,iel)=7 vassign(7,iel)=8 elseif(sumcb.eq.12)then c.......the three face type for face 2,4 and 6 are 0 1 1(not c necessarily in this order) if(cb.eq.0)then ntemp=sje(1,1,2,iel) if(cbc(4,ntemp).eq.3.and.sje(1,1,4,ntemp).lt.iel)then newc(iel)=6 vassign(1,iel)=2 vassign(2,iel)=3 vassign(3,iel)=4 vassign(4,iel)=6 vassign(5,iel)=7 vassign(6,iel)=8 else newc(iel)=7 vassign(1,iel)=2 vassign(2,iel)=3 vassign(3,iel)=4 vassign(4,iel)=5 vassign(5,iel)=6 vassign(6,iel)=7 vassign(7,iel)=8 end if elseif(cb1.eq.0)then newc(iel)=7 vassign(1,iel)=2 vassign(2,iel)=3 vassign(3,iel)=4 vassign(4,iel)=5 vassign(5,iel)=6 vassign(6,iel)=7 vassign(7,iel)=8 elseif(cb2.eq.0)then ntemp=sje(1,1,4,iel) if(cbc(6,ntemp).eq.3.and.sje(1,1,6,ntemp).lt.iel)then newc(iel)=6 vassign(1,iel)=3 vassign(2,iel)=4 vassign(3,iel)=5 vassign(4,iel)=6 vassign(5,iel)=7 vassign(6,iel)=8 else newc(iel)=7 vassign(1,iel)=2 vassign(2,iel)=3 vassign(3,iel)=4 vassign(4,iel)=5 vassign(5,iel)=6 vassign(6,iel)=7 vassign(7,iel)=8 end if end if elseif(sumcb.eq.15)then c.......the three face type for face 2,4 and 6 are 1 1 1(not c necessarily in this order) ntemp=sje(1,1,4,iel) ntemp1=sje(1,1,2,iel) if(cbc(6,ntemp).eq.3.and.sje(1,1,6,ntemp).lt.iel)then if(cbc(2,ntemp).eq.3.and.sje(1,1,2,ntemp).lt.iel)then if(cbc(6,ntemp1).eq.3.and.sje(1,1,6,ntemp1).lt.iel)then newc(iel)=4 vassign(1,iel)=4 vassign(2,iel)=6 vassign(3,iel)=7 vassign(4,iel)=8 else newc(iel)=5 vassign(1,iel)=3 vassign(2,iel)=4 vassign(3,iel)=6 vassign(4,iel)=7 vassign(5,iel)=8 end if else if(cbc(6,ntemp1).eq.3.and.sje(1,1,6,ntemp1).lt.iel)then newc(iel)=5 vassign(1,iel)=4 vassign(2,iel)=5 vassign(3,iel)=6 vassign(4,iel)=7 vassign(5,iel)=8 else newc(iel)=6 vassign(1,iel)=3 vassign(2,iel)=4 vassign(3,iel)=5 vassign(4,iel)=6 vassign(5,iel)=7 vassign(6,iel)=8 end if end if else if(cbc(2,ntemp).eq.3.and.sje(1,1,2,ntemp).lt.iel)then if(cbc(6,ntemp1).eq.3.and.sje(1,1,6,ntemp1).lt.iel)then newc(iel)=5 vassign(1,iel)=2 vassign(2,iel)=4 vassign(3,iel)=6 vassign(4,iel)=7 vassign(5,iel)=8 else newc(iel)=6 vassign(1,iel)=2 vassign(2,iel)=3 vassign(3,iel)=4 vassign(4,iel)=6 vassign(5,iel)=7 vassign(6,iel)=8 end if else if(cbc(6,ntemp1).eq.3.and.sje(1,1,6,ntemp1).lt.iel)then newc(iel)=6 vassign(1,iel)=2 vassign(2,iel)=4 vassign(3,iel)=5 vassign(4,iel)=6 vassign(5,iel)=7 vassign(6,iel)=8 else newc(iel)=7 vassign(1,iel)=2 vassign(2,iel)=3 vassign(3,iel)=4 vassign(4,iel)=5 vassign(5,iel)=6 vassign(6,iel)=7 vassign(7,iel)=8 end if end if end if end if end do c$OMP END PARALLEL DO c.....end computing how many new mortar vertex points will be generated c on each element. c.....Compute (potentially in parallel) front(iel), which records how many c new mortar point indices are to be generated from element 1 to iel. c front(iel)=newc(1)+newc(2)+...+newc(iel) c$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(iel) do iel=1,nelt front(iel)=newc(iel) end do c$OMP END PARALLEL DO call parallel_add(front) c.....On each element, generate new mortar point indices and assign them c to all elements sharing this mortar point. Note, if a mortar point c is shared by several elements, the mortar point index of it will only c be generated on the element with the lowest element index. c$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(iel,i,count) do iel=1,nelt c.......compute the starting vertex mortar point index in element iel front(iel)=front(iel)-newc(iel) do i=1,newc(iel) c.........count is the new mortar index number, which will be assigned c to a vertex of iel and broadcast to all other elements sharing c this vertex point. count=front(iel)+i call mortar_vertex(vassign(i,iel),iel,count) end do end do c$OMP END PARALLEL DO c.....nvertex records how many mortar indices are for element vertices. c It is used in the computation of the preconditioner. count=front(nelt)+newc(nelt) nvertex=count c.....CONFORMING EDGE AND FACE INTERIOR c.....find out how many new mortar point indices will be assigned to all c.....conforming edges and all conforming face interiors on each element n1=12*nelt n2=6*nelt c.....eassign(i,iel)=.true. indicates that the i'th edge on iel will c generate new mortar points. c ncon_edge(i,iel)=.true. indicates that the i'th edge on iel is c nonconforming call l_init_omp(ncon_edge,n1,.false.) call l_init_omp(eassign,n1,.false.) c.....fassign(i,iel)=.true. indicates that the i'th face of iel will c generate new mortar points call l_init_omp(fassign,n2,.false.) c.....newe records how many new edges are to be assigned c diagn(1,n,iel) records the element index of neighbor element of iel, c that shares edge n of iel c diagn(2,n,iel) records the neighbor element diagn(1,n,iel) shares which c part of edge n of iel. diagn(2,n,iel)=1 refers to left c or bottom half of the edge n, diagn(2,n,iel)=2 refers c to the right or top part of edge n. c if_1_edge(n,iel)=.true. indicates that the size of iel is smaller than c that of its neighbor connected, neighbored by edge n only c$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(iel,cb1,cb2,cb3,cb4,cb5 c$OMP& ,cb6,ntemp) do iel=1,nelt newc(iel)=0 newe(iel)=0 newi(iel)=0 cb1=cbc(1,iel) cb2=cbc(2,iel) cb3=cbc(3,iel) cb4=cbc(4,iel) cb5=cbc(5,iel) cb6=cbc(6,iel) c.......on face 6 if(cb6.eq.0)then if(cb4.eq.0.or.cb4.eq.1)then c...........if face 6 is of type 0 and face 4 is of type 0 or type 1, the edge c shared by face 4 and 6 (edge 11) will generate new mortar point c indices. newe(iel)=newe(iel)+1 eassign(11,iel)=.true. end if if(cb1.ne.3)then c...........if face 1 is of type 3, the edge shared by face 6 and 1 (edge 1) c will generate new mortar points indices. newe(iel)=newe(iel)+1 eassign(1,iel)=.true. end if if(cb3.ne.3)then newe(iel)=newe(iel)+1 eassign(9,iel)=.true. end if if(cb2.eq.0.or.cb2.eq.1)then newe(iel)=newe(iel)+1 eassign(5,iel)=.true. end if elseif(cb6.eq.1)then if(cb4.eq.0)then newe(iel)=newe(iel)+1 eassign(11,iel)=.true. elseif(cb4.eq.1)then c...........If face 6 and face 4 both are of type 1, ntemp is the neighbor c element on face 4. ntemp=sje(1,1,4,iel) c...........if ntemp's face 6 is not noncoforming or the neighbor element c of ntemp on face 6 has an element index larger than iel, the c edge shared by face 6 and 4 (edge 11) will generate new mortar c point indices. if(cbc(6,ntemp).ne.3.or.sje(1,1,6,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(11,iel)=.true. c.............if the face 6 of ntemp is of type 2 if(cbc(6,ntemp).eq.2)then c...............The neighbor element of iel, neighbored by edge 11, is c sje(1,1,6,ntemp) (the neighbor element of ntemp on ntemp's c face 6). diagn(1,11,iel)=sje(1,1,6,ntemp) c...............The neighbor element of iel, neighbored by edge 11 shares c the ijel(2,6,iel) part of edge 11 of iel diagn(2,11,iel)=ijel(2,6,iel) c...............edge 10 of element sje(1,1,6,ntemp) (the neighbor element of c ntemp on ntemp's face 6) is a nonconforming edge ncon_edge(10,sje(1,1,6,ntemp))=.true. c...............if_1_edge(n,iel)=.true. indicates that iel is of a smaller c size than its neighbor element, neighbored by edge n of iel only. if_1_edge(11,iel)=.true. endif if(cbc(6,ntemp).eq.3.and. & sje(1,1,6,ntemp).gt.iel)then diagn(1,11,iel)=sje(2,ijel(2,6,iel),6,ntemp) endif end if endif if(cb1.eq.0)then newe(iel)=newe(iel)+1 eassign(1,iel)=.true. elseif(cb1.eq.1)then ntemp=sje(1,1,1,iel) if(cbc(6,ntemp).ne.3.or.sje(1,1,6,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(1,iel)=.true. if(cbc(6,ntemp).eq.2)then diagn(1,1,iel)=sje(1,1,6,ntemp) diagn(2,1,iel)=ijel(1,6,iel) ncon_edge(7,sje(1,1,6,ntemp))=.true. if_1_edge(1,iel)=.true. endif if(cbc(6,ntemp).eq.3.and. & sje(1,1,6,ntemp).gt.iel)then diagn(1,1,iel)=sje(ijel(1,6,iel),1,6,ntemp) endif end if elseif(cb1.eq.2)then if(ijel(2,6,iel).eq.2)then ntemp=sje(1,1,1,iel) if(cbc(6,ntemp).eq.1)then newe(iel)=newe(iel)+1 eassign(1,iel)=.true. c.............if cbc(6,ntemp)=2 else if(sje(1,1,6,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(1,iel)=.true. diagn(1,1,iel)=sje(1,1,6,ntemp) end if end if else newe(iel)=newe(iel)+1 eassign(1,iel)=.true. end if end if if(cb3.eq.0)then newe(iel)=newe(iel)+1 eassign(9,iel)=.true. elseif(cb3.eq.1)then ntemp=sje(1,1,3,iel) if(cbc(6,ntemp).ne.3.or.sje(1,1,6,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(9,iel)=.true. if(cbc(6,ntemp).eq.2)then diagn(1,9,iel)=sje(1,1,6,ntemp) diagn(2,9,iel)=ijel(2,6,iel) ncon_edge(12,sje(1,1,6,ntemp))=.true. if_1_edge(9,iel)=.true. endif if(cbc(6,ntemp).eq.3.and. & sje(1,1,6,ntemp).gt.iel)then diagn(1,9,iel)=sje(2,ijel(2,6,iel),6,ntemp) endif end if elseif(cb3.eq.2)then if(ijel(1,6,iel).eq.2)then ntemp=sje(1,1,3,iel) if(cbc(6,ntemp).eq.1)then newe(iel)=newe(iel)+1 eassign(9,iel)=.true. c.............if cbc(6,ntemp)=2 else if(sje(1,1,6,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(9,iel)=.true. diagn(1,9,iel)=sje(1,1,6,ntemp) end if end if else newe(iel)=newe(iel)+1 eassign(9,iel)=.true. end if end if if(cb2.eq.0)then newe(iel)=newe(iel)+1 eassign(5,iel)=.true. elseif(cb2.eq.1)then ntemp=sje(1,1,2,iel) if(cbc(6,ntemp).ne.3.or.sje(1,1,6,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(5,iel)=.true. if(cbc(6,ntemp).eq.2)then diagn(1,5,iel)=sje(1,1,6,ntemp) diagn(2,5,iel)=ijel(1,6,iel) ncon_edge(3,sje(1,1,6,ntemp))=.true. if_1_edge(5,iel)=.true. endif if(cbc(6,ntemp).eq.3.and. & sje(1,1,6,ntemp).gt.iel)then diagn(1,9,iel)=sje(2,ijel(2,6,iel),6,ntemp) endif endif end if end if c.......one face 4 if(cb4.eq.0)then if(cb1.ne.3)then newe(iel)=newe(iel)+1 eassign(4,iel)=.true. endif if(cb5.ne.3)then newe(iel)=newe(iel)+1 eassign(12,iel)=.true. endif if(cb2.eq.0.or.cb2.eq.1)then newe(iel)=newe(iel)+1 eassign(8,iel)=.true. end if elseif(cb4.eq.1)then if(cb1.eq.2)then if(ijel(2,4,iel).eq.1)then newe(iel)=newe(iel)+1 eassign(4,iel)=.true. else ntemp=sje(1,1,4,iel) if(cbc(1,ntemp).ne.3.or.sje(1,1,1,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(4,iel)=.true. if(cbc(1,ntemp).eq.3.and. & sje(1,1,1,ntemp).gt.iel)then diagn(1,4,iel)=sje(ijel(1,4,iel),2,1,ntemp) endif endif end if elseif(cb1.eq.0)then newe(iel)=newe(iel)+1 eassign(4,iel)=.true. elseif(cb1.eq.1)then ntemp=sje(1,1,4,iel) if(cbc(1,ntemp).ne.3.or.sje(1,1,1,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(4,iel)=.true. if(cbc(1,ntemp).eq.2)then diagn(1,4,iel)=sje(1,1,1,ntemp) diagn(2,4,iel)=ijel(1,4,iel) ncon_edge(6,sje(1,1,1,ntemp))=.true. if_1_edge(4,iel)=.true. endif if(cbc(1,ntemp).eq.3.and. & sje(1,1,1,ntemp).gt.iel)then diagn(1,4,iel)=sje(ijel(1,4,iel),2,1,ntemp) endif end if end if if(cb5.eq.2)then if(ijel(1,4,iel).eq.1)then newe(iel)=newe(iel)+1 eassign(12,iel)=.true. else ntemp=sje(1,1,4,iel) if(cbc(5,ntemp).ne.3.or.sje(1,1,5,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(12,iel)=.true. if(cbc(5,ntemp).eq.3.and. & sje(1,1,5,ntemp).gt.iel)then diagn(1,12,iel)=sje(2,ijel(2,4,iel),5,ntemp) endif endif end if elseif(cb5.eq.0)then newe(iel)=newe(iel)+1 eassign(12,iel)=.true. elseif(cb5.eq.1)then ntemp=sje(1,1,4,iel) if(cbc(5,ntemp).ne.3.or.sje(1,1,5,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(12,iel)=.true. if(cbc(5,ntemp).eq.2)then diagn(1,12,iel)=sje(1,1,5,ntemp) diagn(2,12,iel)=ijel(2,4,iel) ncon_edge(9,sje(1,1,5,ntemp))=.true. if_1_edge(12,iel)=.true. endif if(cbc(5,ntemp).eq.3.and. & sje(1,1,5,ntemp).gt.iel)then diagn(1,12,iel)=sje(2,ijel(2,4,iel),5,ntemp) endif end if end if if(cb2.eq.0)then newe(iel)=newe(iel)+1 eassign(8,iel)=.true. elseif(cb2.eq.1)then ntemp=sje(1,1,4,iel) if(cbc(2,ntemp).ne.3.or.sje(1,1,2,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(8,iel)=.true. if(cbc(2,ntemp).eq.2)then diagn(1,8,iel)=sje(1,1,2,ntemp) diagn(2,8,iel)=ijel(1,4,iel) ncon_edge(2,sje(1,1,2,ntemp))=.true. if_1_edge(8,iel)=.true. endif if(cbc(2,ntemp).eq.3.and. & sje(1,1,2,ntemp).gt.iel)then diagn(1,8,iel)=sje(ijel(1,4,iel),2,3,ntemp) endif endif end if end if c.......on face 2 if(cb2.eq.0)then if(cb3.ne.3)then newe(iel)=newe(iel)+1 eassign(6,iel)=.true. endif if(cb5.ne.3)then newe(iel)=newe(iel)+1 eassign(7,iel)=.true. endif elseif(cb2.eq.1)then if(cb3.eq.2)then if(ijel(2,2,iel).eq.1)then newe(iel)=newe(iel)+1 eassign(6,iel)=.true. else ntemp=sje(1,1,2,iel) if(cbc(3,ntemp).ne.3.or. & sje(1,1,3,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(6,iel)=.true. if(cbc(3,ntemp).eq.3.and. & sje(1,1,3,ntemp).gt.iel)then diagn(1,6,iel)=sje(ijel(1,2,iel),2,3,ntemp) endif endif endif elseif(cb3.eq.0)then newe(iel)=newe(iel)+1 eassign(6,iel)=.true. elseif(cb3.eq.1)then ntemp=sje(1,1,2,iel) if(cbc(3,ntemp).ne.3.or.sje(1,1,3,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(6,iel)=.true. if(cbc(3,ntemp).eq.2)then diagn(1,6,iel)=sje(1,1,3,ntemp) diagn(2,6,iel)=ijel(1,2,iel) ncon_edge(4,sje(1,1,3,ntemp))=.true. if_1_edge(6,iel)=.true. endif if(cbc(3,ntemp).eq.3.and. & sje(1,1,3,ntemp).gt.iel)then diagn(1,6,iel)=sje(ijel(1,4,iel),2,3,ntemp) endif endif endif if(cb5.eq.2)then if(ijel(1,2,iel).eq.1)then newe(iel)=newe(iel)+1 eassign(7,iel)=.true. else ntemp=sje(1,1,2,iel) if(cbc(5,ntemp).ne.3.or.sje(1,1,5,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(7,iel)=.true. if(cbc(5,ntemp).eq.3.and. & sje(1,1,5,ntemp).gt.iel)then diagn(1,7,iel)=sje(ijel(2,2,iel),2,5,ntemp) endif endif endif elseif(cb5.eq.0)then newe(iel)=newe(iel)+1 eassign(7,iel)=.true. elseif(cb5.eq.1)then ntemp=sje(1,1,2,iel) if(cbc(5,ntemp).ne.3.or.sje(1,1,5,ntemp).gt.iel)then newe(iel)=newe(iel)+1 eassign(7,iel)=.true. if(cbc(5,ntemp).eq.2)then diagn(1,7,iel)=sje(1,1,5,ntemp) diagn(2,7,iel)=ijel(2,2,iel) ncon_edge(1,sje(1,1,5,ntemp))=.true. if_1_edge(7,iel)=.true. endif if(cbc(5,ntemp).eq.3.and. & sje(1,1,5,ntemp).gt.iel)then diagn(1,7,iel)=sje(2,ijel(2,4,iel),5,ntemp) endif endif endif end if c.......on face 1 if(cb1.eq.1)then newe(iel)=newe(iel)+2 eassign(2,iel)=.true. if(cb3.eq.1)then ntemp=sje(1,1,1,iel) if(cbc(3,ntemp).eq.2)then diagn(1,2,iel)=sje(1,1,3,ntemp) diagn(2,2,iel)=ijel(1,1,iel) ncon_edge(8,sje(1,1,3,ntemp))=.true. if_1_edge(2,iel)=.true. elseif(cbc(3,ntemp).eq.3)then diagn(1,2,iel)=sje(ijel(1,1,iel),1,3,ntemp) endif elseif(cb3.eq.2)then ntemp=sje(1,1,3,iel) if(ijel(2,1,iel).eq.2)then if(cbc(1,ntemp).eq.2)then diagn(1,2,iel)=sje(1,1,1,ntemp) end if endif end if eassign(3,iel)=.true. if(cb5.eq.1)then ntemp=sje(1,1,1,iel) if(cbc(5,ntemp).eq.2)then diagn(1,3,iel)=sje(1,1,5,ntemp) diagn(2,3,iel)=ijel(2,1,iel) ncon_edge(5,sje(1,1,5,ntemp))=.true. if_1_edge(3,iel)=.true. elseif(cbc(5,ntemp).eq.3)then diagn(1,3,iel)=sje(ijel(2,1,iel),1,5,ntemp) endif elseif(cb5.eq.2)then ntemp=sje(1,1,5,iel) if(ijel(1,1,iel).eq.2)then if(cbc(1,ntemp).eq.2)then diagn(1,3,iel)=sje(1,1,1,ntemp) end if endif end if elseif(cb1.eq.2)then if(cb3.eq.2)then ntemp=sje(1,1,1,iel) if(cbc(3,ntemp).ne.3)then newe(iel)=newe(iel)+1 eassign(2,iel)=.true. if(cbc(3,ntemp).eq.2)then diagn(1,2,iel)=sje(1,1,3,ntemp) endif endif elseif(cb3.eq.0.or.cb3.eq.1)then newe(iel)=newe(iel)+1 eassign(2,iel)=.true. if(cb3.eq.1)then ntemp=sje(1,1,1,iel) if(cbc(3,ntemp).eq.2)then diagn(1,2,iel)=sje(1,1,3,ntemp) endif endif end if if(cb5.eq.2)then ntemp=sje(1,1,1,iel) if(cbc(5,ntemp).ne.3)then newe(iel)=newe(iel)+1 eassign(3,iel)=.true. if(cbc(5,ntemp).eq.2)then diagn(1,3,iel)=sje(1,1,5,ntemp) endif endif elseif(cb5.eq.0.or.cb5.eq.1)then newe(iel)=newe(iel)+1 eassign(3,iel)=.true. if(cb5.eq.1)then ntemp=sje(1,1,1,iel) if(cbc(5,ntemp).eq.2)then diagn(1,3,iel)=sje(1,1,5,ntemp) endif endif end if elseif(cb1.eq.0)then if(cb3.ne.3)then newe(iel)=newe(iel)+1 eassign(2,iel)=.true. endif if(cb5.ne.3)then newe(iel)=newe(iel)+1 eassign(3,iel)=.true. endif endif c.......on face 3 if(cb3.eq.1)then newe(iel)=newe(iel)+1 eassign(10,iel)=.true. if(cb5.eq.1)then ntemp=sje(1,1,3,iel) if(cbc(5,ntemp).eq.2)then diagn(1,10,iel)=sje(1,1,5,ntemp) diagn(2,10,iel)=ijel(2,3,iel) ncon_edge(11,sje(1,1,5,ntemp))=.true. if_1_edge(10,iel)=.true. endif endif if(ijel(1,3,iel).eq.2)then ntemp=sje(1,1,3,iel) if(cbc(5,ntemp).eq.3)then diagn(1,10,iel)=sje(1,ijel(2,3,iel),5,ntemp) endif endif elseif(cb3.eq.2)then if(cb5.eq.2)then ntemp=sje(1,1,3,iel) if(cbc(5,ntemp).ne.3)then newe(iel)=newe(iel)+1 eassign(10,iel)=.true. if(cbc(5,ntemp).eq.2)then diagn(1,10,iel)=sje(1,1,5,ntemp) endif endif elseif(cb5.eq.0.or.cb5.eq.1)then newe(iel)=newe(iel)+1 eassign(10,iel)=.true. if(cb5.eq.1)then ntemp=sje(1,1,3,iel) if(cbc(5,ntemp).eq.2)then diagn(1,10,iel)=sje(1,1,5,ntemp) endif endif end if elseif(cb3.eq.0)then if(cb5.ne.3)then newe(iel)=newe(iel)+1 eassign(10,iel)=.true. endif endif c CONFORMING FACE INTERIOR c.......find how many new mortar point indices will be assigned c to face interiors on all faces on each element c.......newi record how many new face interior points will be assigned c.......on face 6 if(cb6.eq.1.or.cb6.eq.0)then newi(iel)=newi(iel)+9 fassign(6,iel)=.true. end if c.......on face 4 if(cb4.eq.1.or.cb4.eq.0)then newi(iel)=newi(iel)+9 fassign(4,iel)=.true. end if c.......on face 2 if(cb2.eq.1.or.cb2.eq.0)then newi(iel)=newi(iel)+9 fassign(2,iel)=.true. end if c.......on face 1 if(cb1.ne.3)then newi(iel)=newi(iel)+9 fassign(1,iel)=.true. end if c.......on face 3 if(cb3.ne.3)then newi(iel)=newi(iel)+9 fassign(3,iel)=.true. endif c.......on face 5 if(cb5.ne.3)then newi(iel)=newi(iel)+9 fassign(5,iel)=.true. endif c.......newc is the total number of new mortar point indices c to be assigned to each element. newc(iel)=newe(iel)*3+newi(iel) end do c$OMP END PARALLEL DO c.....Compute (potentially in parallel) front(iel), which records how c many new mortar point indices are to be assigned (to conforming c edges and conforming face interiors) from element 1 to iel. c front(iel)=newc(1)+newc(2)+...+newc(iel) c$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(iel) do iel=1,nelt front(iel)=newc(iel) end do c$OMP END PARALLEL DO call parallel_add(front) c.....nmor is the total number or mortar points nmor=nvertex+front(nelt) c.....Generate (potentially in parallel) new mortar point indices on c each conforming element face. On each face, first visit all c conforming edges, and then the face interior. c$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(iel,count,i,cb1,ne, c$OMP& space,ie,edge_g,face2,ie2,ntemp,ii,jj,jface,cb,mor_v) do iel=1,nelt front(iel)=front(iel)-newc(iel) count=nvertex+front(iel) do i=1,6 cb1=cbc(i,iel) if (i.le.2) then ne=4 space=1 elseif (i.le.4)then ne=3 space=2 c.........i loops over faces. Only 4 faces need to be examed for edge visit. c On face 1, edge 1,2,3 and 4 will be visited. On face 2, edge 5,6,7 c and 8 will be visited. On face 3, edge 9 and 10 will be visited and c on face 4, edge 11 and 12 will be visited. The 12 edges can be c covered by four faces, there is no need to visit edges on face c 5 and 6. So ne is set to be 0. c However, i still needs to loop over 5 and 6, since the interiors c of face 5 and 6 still need to be visited. else ne=0 space=1 end if do ie=1,ne,space edge_g=edgenumber(ie,i) if(eassign(edge_g,iel))then c.............generate the new mortar points index, mor_v call mor_assign(mor_v,count) c.............assign mor_v to local edge ie of face i on element iel call mor_edge(ie,i,iel,mor_v) c.............Since this edge is shared by another face of element c iel, assign mor_v to the corresponding edge on the other c face also. c.............find the other face face2=f_e_ef(ie,i) c.............find the local edge index of this edge on the other face ie2=localedgenumber(face2,edge_g) c.............asssign mor_v to local edge ie2 of face face2 on element iel call mor_edge(ie2,face2,iel,mor_v) c.............There are some neighbor elements also sharing this edge. Assign c mor_v to neighbor element, neighbored by face i. if (cbc(i,iel).eq.2)then ntemp=sje(1,1,i,iel) call mor_edge(ie,jjface(i),ntemp,mor_v) call mor_edge(op(ie2),face2,ntemp,mor_v) end if c.............assign mor_v to neighbor element neighbored by face face2 if (cbc(face2,iel).eq.2)then ntemp=sje(1,1,face2,iel) call mor_edge(ie2,jjface(face2),ntemp,mor_v) call mor_edge(op(ie),i,ntemp,mor_v) end if c.............assign mor_v to neighbor element sharing this edge c.............if the neighbor is of the same size of iel if(.not.if_1_edge(edgenumber(ie,i),iel))then if(diagn(1,edgenumber(ie,i),iel).ne.0)then ntemp=diagn(1,edgenumber(ie,i),iel) call mor_edge(op(ie2),jjface(face2),ntemp,mor_v) call mor_edge(op(ie),jjface(i),ntemp,mor_v) endif c.............if the neighbor has a size larger than iel's else if(diagn(1,edgenumber(ie,i),iel).ne.0)then ntemp=diagn(1,edgenumber(ie,i),iel) call mor_ne(mor_v,diagn(2,edgenumber(ie,i),iel), & ie,i,ie2,face2,iel,ntemp) end if endif endif end do if(fassign(i,iel))then c...........generate new mortar points index in face interior. c if face i is of type 2 or iel doesn't have a neighbor element, c assign new mortar point indices to interior mortar points c of face i of iel. cb=cbc(i,iel) if (cb.eq.1.or.cb.eq.0) then do jj =2,lx1-1 do ii=2,lx1-1 count=count+1 idmo(ii,jj,1,1,i,iel)=count end do end do c...........if face i is of type 2, assign new mortar point indices c to iel as well as to the neighboring element on face i elseif (cb.eq.2) then if (idmo(2,2,1,1,i,iel).eq.0) then ntemp=sje(1,1,i,iel) jface = jjface(i) do jj =2,lx1-1 do ii=2,lx1-1 count=count+1 idmo(ii,jj,1,1,i,iel)=count idmo(ii,jj,1,1,jface,ntemp)=count end do end do end if end if end if end do end do c$OMP END PARALLEL DO c.....for edges on nonconforming faces, copy the mortar points indices c from neighbors. c$OMP PARALLEL DO DEFAULT(SHARED) c$OMP& PRIVATE(iel,i,cb,jface,iii,jjj,ntemp,ii,jj) do iel=1,nelt do i=1,6 cb=cbc(i,iel) if (cb.eq.3) then c...........edges call edgecopy_s(i,iel) end if c.........face interior jface = jjface(i) if (cb.eq.3) then do iii=1,2 do jjj=1,2 ntemp=sje(iii,jjj,i,iel) do jj =1,lx1 do ii=1,lx1 idmo(ii,jj,iii,jjj,i,iel)= & idmo(ii,jj,1,1,jface,ntemp) end do end do idmo(1,1,iii,jjj,i,iel)=idmo(1,1,1,1,jface,ntemp) idmo(lx1,1,iii,jjj,i,iel)=idmo(lx1,1,1,2,jface,ntemp) idmo(1,lx1,iii,jjj,i,iel)=idmo(1,lx1,2,1,jface,ntemp) idmo(lx1,lx1,iii,jjj,i,iel)= & idmo(lx1,lx1,2,2,jface,ntemp) end do end do end if end do end do c$OMP END PARALLEL DO return end c----------------------------------------------------------------- subroutine get_emo(ie,n,ng) c----------------------------------------------------------------- c This subroutine fills array emo. c emo records all elements sharing the same mortar point c (only applies to element vertices) . c emo(1,i,n) gives the element ID of the i'th element sharing c mortar point n. (emo(1,i,n)=ie), ie is element c index. c emo(2,i,n) gives the vertex index of mortar point n on this c element (emo(2,i,n)=ng), ng is the vertex index. c nemo(n) records the total number of elements sharing mortar c point n. c----------------------------------------------------------------- include 'header.h' integer ie, n, ntemp, i,ng logical L1 L1=.false. do i=1,nemo(n) if (emo(1,i,n).eq.ie) L1=.true. end do if (.not.L1) then c$ call omp_set_lock(tlock(n)) ntemp=nemo(n)+1 nemo(n)=ntemp emo(1,ntemp,n)=ie emo(2,ntemp,n)=ng c$ call omp_unset_lock(tlock(n)) end if return end c----------------------------------------------------------------- logical function ifsame(ntemp,j,iel,i) c----------------------------------------------------------------- c Check whether the i's vertex of element iel is at the same c location as j's vertex of element ntemp. c----------------------------------------------------------------- include 'header.h' integer iel, i, ntemp, j ifsame=.false. if (ntemp.eq.0 .or. iel.eq.0) return if (xc(i,iel).eq.xc(j,ntemp).and. & yc(i,iel).eq.yc(j,ntemp).and. & zc(i,iel).eq.zc(j,ntemp)) then ifsame=.true. end if return end c----------------------------------------------------------------- subroutine mor_assign(mor_v,count) c----------------------------------------------------------------- c Assign three consecutive numbers for mor_v, which will c be assigned to the three interior points of an edge as the c mortar point indices. c----------------------------------------------------------------- implicit none integer mor_v(3),count,i do i=1,3 count=count+1 mor_v(i)=count end do return end c----------------------------------------------------------------- subroutine mor_edge(ie,face,iel,mor_v) c----------------------------------------------------------------- c Copy the mortar points index from mor_v to local c edge ie of the face'th face on element iel. c The edge is conforming. c----------------------------------------------------------------- include 'header.h' integer ie,i,iel,mor_v(3),j,nn,face if (ie.eq.1) then j=1 do nn=2,lx1-1 idmo(nn,j,1,1,face,iel)=mor_v(nn-1) end do elseif (ie.eq.2) then i=lx1 do nn=2,lx1-1 idmo(i,nn,1,1,face,iel)=mor_v(nn-1) end do elseif (ie.eq.3) then j=lx1 do nn=2,lx1-1 idmo(nn,j,1,1,face,iel)=mor_v(nn-1) end do elseif (ie.eq.4) then i=1 do nn=2,lx1-1 idmo(i,nn,1,1,face,iel)=mor_v(nn-1) end do end if return end c------------------------------------------------------------ subroutine edgecopy_s(face,iel) c------------------------------------------------------------ c Copy mortar points index on edges from neighbor elements c to an element face of the 3rd type. c------------------------------------------------------------ include 'header.h' integer face, iel, ntemp1, ntemp2, ntemp3, ntemp4, & edge_g, edge_l, face2, mor_s_v(4,2), i c......find four neighbors on this face (3rd type) ntemp1=sje(1,1,face,iel) ntemp2=sje(1,2,face,iel) ntemp3=sje(2,1,face,iel) ntemp4=sje(2,2,face,iel) c......local edge 1 c......mor_s_v is the array of mortar indices to be copied. call nrzero(mor_s_v,4*2) do i=2,lx1-1 mor_s_v(i-1,1)=idmo(i,1,1,1,jjface(face),ntemp1) end do mor_s_v(lx1-1,1)=idmo(lx1,1,1,2,jjface(face),ntemp1) do i=1,lx1-1 mor_s_v(i,2)=idmo(i,1,1,1,jjface(face),ntemp2) end do c......copy mor_s_v to local edge 1 on this face call mor_s_e(1,face,iel,mor_s_v) c......copy mor_s_v to the corresponding edge on the other face sharing c local edge 1 face2=f_e_ef(1,face) edge_g=edgenumber(1,face) edge_l=localedgenumber(face2,edge_g) call mor_s_e(edge_l,face2,iel,mor_s_v) c......local edge 2 do i=2,lx1-1 mor_s_v(i-1,1)=idmo(lx1,i,1,1,jjface(face),ntemp2) end do mor_s_v(lx1-1,1)=idmo(lx1,lx1,2,2,jjface(face),ntemp2) mor_s_v(1,2)=idmo(lx1,1,1,2,jjface(face),ntemp4) do i=2,lx1-1 mor_s_v(i,2)=idmo(lx1,i,1,1,jjface(face),ntemp4) end do call mor_s_e(2,face,iel,mor_s_v) face2=f_e_ef(2,face) edge_g=edgenumber(2,face) edge_l=localedgenumber(face2,edge_g) call mor_s_e(edge_l,face2,iel,mor_s_v) c......local edge 3 do i=2,lx1-1 mor_s_v(i-1,1)=idmo(i,lx1,1,1,jjface(face),ntemp3) end do mor_s_v(lx1-1,1)=idmo(lx1,lx1,2,2,jjface(face),ntemp3) mor_s_v(1,2)=idmo(1,lx1,2,1,jjface(face),ntemp4) do i=2,lx1-1 mor_s_v(i,2)=idmo(i,lx1,1,1,jjface(face),ntemp4) end do call mor_s_e(3,face,iel,mor_s_v) face2=f_e_ef(3,face) edge_g=edgenumber(3,face) edge_l=localedgenumber(face2,edge_g) call mor_s_e(edge_l,face2,iel,mor_s_v) c......local edge 4 do i=2,lx1-1 mor_s_v(i-1,1)=idmo(1,i,1,1,jjface(face),ntemp1) end do mor_s_v(lx1-1,1)=idmo(1,lx1,2,1,jjface(face),ntemp1) do i=1,lx1-1 mor_s_v(i,2)=idmo(1,i,1,1,jjface(face),ntemp3) end do call mor_s_e(4,face,iel,mor_s_v) face2=f_e_ef(4,face) edge_g=edgenumber(4,face) edge_l=localedgenumber(face2,edge_g) call mor_s_e(edge_l,face2,iel,mor_s_v) return end c------------------------------------------------------------ subroutine mor_s_e(n,face,iel,mor_s_v) c------------------------------------------------------------ c Copy mortar points index from mor_s_v to local edge n c on face "face" of element iel. The edge is nonconforming. c------------------------------------------------------------ include 'header.h' integer n,face,iel,mor_s_v(4,2), i if (n.eq.1) then do i=2,lx1 idmo(i,1,1,1,face,iel)=mor_s_v(i-1,1) end do do i=1,lx1-1 idmo(i,1,1,2,face,iel)=mor_s_v(i,2) end do else if (n.eq.2) then do i=2,lx1 idmo(lx1,i,1,2,face,iel)=mor_s_v(i-1,1) end do do i=1,lx1-1 idmo(lx1,i,2,2,face,iel)=mor_s_v(i,2) end do else if (n.eq.3) then do i=2,lx1 idmo(i,lx1,2,1,face,iel)=mor_s_v(i-1,1) end do do i=1,lx1-1 idmo(i,lx1,2,2,face,iel)=mor_s_v(i,2) end do else if (n.eq.4) then do i=2,lx1 idmo(1,i,1,1,face,iel)=mor_s_v(i-1,1) end do do i=1,lx1-1 idmo(1,i,2,1,face,iel)=mor_s_v(i,2) end do end if return end c------------------------------------------------------------ subroutine mor_s_e_nn(n,face,iel,mor_s_v,nn) c------------------------------------------------------------ c Copy mortar point indices from mor_s_v to local edge n c on face "face" of element iel. nn is the edge mortar index, c which indicates that mor_s_v corresponds to left/bottom or c right/top part of the edge. c------------------------------------------------------------ include 'header.h' integer n,face,iel,mor_s_v(4), i,nn if (n.eq.1) then if(nn.eq.1)then do i=2,lx1 idmo(i,1,1,1,face,iel)=mor_s_v(i-1) end do else do i=1,lx1-1 idmo(i,1,1,2,face,iel)=mor_s_v(i) end do endif else if (n.eq.2) then if(nn.eq.1)then do i=2,lx1 idmo(lx1,i,1,2,face,iel)=mor_s_v(i-1) end do else do i=1,lx1-1 idmo(lx1,i,2,2,face,iel)=mor_s_v(i) end do endif else if (n.eq.3) then if(nn.eq.1)then do i=2,lx1 idmo(i,lx1,2,1,face,iel)=mor_s_v(i-1) end do else do i=1,lx1-1 idmo(i,lx1,2,2,face,iel)=mor_s_v(i) end do endif else if (n.eq.4) then if(nn.eq.1)then do i=2,lx1 idmo(1,i,1,1,face,iel)=mor_s_v(i-1) end do else do i=1,lx1-1 idmo(1,i,2,1,face,iel)=mor_s_v(i) end do endif end if return end c--------------------------------------------------------------- subroutine mortar_vertex(i,iel,count) c--------------------------------------------------------------- c Assign mortar point index "count" to iel's i'th vertex c and also to all elements sharing this vertex. c--------------------------------------------------------------- include 'header.h' integer i,iel,count,ntempx(8),ifntempx(8),lc_a(3),nnb(3), & face_a(3),itemp,ntemp,ii, jj,j(3), & iintempx(3),l,nbe, lc, temp logical ifsame,if_temp do l= 1,8 ntempx(l)=0 ifntempx(l)=0 end do c.....face_a records the three faces sharing this vertex on iel. c lc_a gives the local corner number of this vertex on each c face in face_a. do l=1,3 face_a(l)=f_c(l,i) lc_a(l)=local_corner(i,face_a(l)) end do c.....each vertex is shared by at most 8 elements. c ntempx(j) gives the element index of a POSSIBLE element with its c j'th vertex is iel's i'th vertex c ifntempx(i)=ntempx(i) means ntempx(i) exists c ifntempx(i)=0 means ntempx(i) does not exist. ntempx(9-i)=iel ifntempx(9-i)=iel c.....first find all elements sharing this vertex, ifntempx c.....find the three possible neighbors of iel, neighbored by faces c listed in array face_a do itemp= 1, 3 c.......j(itemp) is the local corner number of this vertex on the c neighbor element on the corresponding face. j(itemp)=c_f(lc_a(itemp),jjface(face_a(itemp))) c.......iitempx(itemp) records the vertex index of i on the c neighbor element, neighborned by face_a(itemp) iintempx(itemp)=cal_intempx(lc_a(itemp),face_a(itemp)) c.......ntemp refers the neighbor element ntemp=0 c.......if the face is nonconforming, find out in which piece of the c mortar the vertex is located ii=cal_iijj(1,lc_a(itemp)) jj=cal_iijj(2,lc_a(itemp)) ntemp=sje(ii,jj,face_a(itemp),iel) c.......if the face is conforming if(ntemp.eq.0)then ntemp=sje(1,1,face_a(itemp),iel) c.........find the possible neighbor ntempx(iintempx(itemp))=ntemp c.........check whether this possible neighbor is a real neighbor or not if(ntemp.ne.0)then if(ifsame(ntemp,j(itemp),iel,i))then ifntempx(iintempx(itemp))=ntemp end if end if c.......if the face is nonconforming else if(ntemp.ne.0)then if(ifsame(ntemp,j(itemp),iel,i))then ifntempx(iintempx(itemp))=ntemp ntempx(iintempx(itemp))=ntemp end if end if end if end do c.....find the possible three neighbors, neighbored by an edge only do l=1,3 c.....find first existing neighbor of any of the faces in array face_a if_temp=.false. if(l.eq.1)then if_temp=.true. elseif(l.eq.2)then if(ifntempx(iintempx(l-1)).eq.0)then if_temp=.true. end if elseif(l.eq.3)then if(ifntempx(iintempx(l-1)).eq.0 & .and.ifntempx(iintempx(l-2)).eq.0) then if_temp=.true. end if end if if(if_temp)then if (ifntempx(iintempx(l)).ne.0) then nbe=ifntempx(iintempx(l)) c...........if 1st neighor exists, check the neighbor's two neighbors in c the other two directions. c e.g. if l=1, check directions 2 and 3,i.e. itemp=2,3,1 c if l=2, itemp=3,1,-2 c if l=3, itemp=1,2,1 c do itemp=face_l1(l),face_l2(l),face_ld(l) c.............lc is the local corner number of this vertex on face face_a(itemp) c on the neighbor element of iel, neighbored by a face face_a(l) lc=local_corner(j(l),face_a(itemp)) c.............temp is the vertex index of this vertex on the neighbor element c neighbored by an edge temp=cal_intempx(lc,face_a(itemp)) ii=cal_iijj(1,lc) jj=cal_iijj(2,lc) ntemp=sje(ii,jj,face_a(itemp),nbe) c.............if the face face_a(itemp) is conforming if(ntemp.eq.0)then ntemp=sje(1,1,face_a(itemp),nbe) if(ntemp.ne.0)then if(ifsame(ntemp,c_f(lc,jjface(face_a(itemp))), & nbe,j(l)))then ntempx(temp)=ntemp ifntempx(temp)=ntemp c...................nnb(itemp) records the neighbor element neighbored by an c edge only nnb(itemp)=ntemp end if end if c.............if the face face_a(itemp) is nonconforming else if(ntemp.ne.0)then if(ifsame(ntemp,c_f(lc,jjface(face_a(itemp))), & nbe,j(l)))then ntempx(temp)=ntemp ifntempx(temp)=ntemp nnb(itemp)=ntemp end if end if end if end do c...........check the last neighbor element, neighbored by an edge c...........ifntempx(iintempx(l)) has been visited in the above, now c check another neighbor element(nbe) neighbored by a face c...........if the neighbor element is neighbored by face c face_a(face_l1(l)) exists if(ifntempx(iintempx(face_l1(l))).ne.0)then nbe=ifntempx(iintempx(face_l1(l))) c.............itemp is the last direction other than l and face_l1(l) itemp=face_l2(l) lc=local_corner(j(face_l1(l)),face_a(itemp)) temp=cal_intempx(lc,face_a(itemp)) ii=cal_iijj(1,lc) jj=cal_iijj(2,lc) c.............ntemp records the last neighbor element neighbored by an edge c with element iel ntemp=sje(ii,jj,face_a(itemp),nbe) c.............if conforming if(ntemp.eq.0)then ntemp=sje(1,1,face_a(itemp),nbe) if(ntemp.ne.0)then if(ifsame(ntemp,c_f(lc,jjface(face_a(itemp))), & nbe,j(face_l1(l))))then ntempx(temp)=ntemp ifntempx(temp)=ntemp nnb(l)=ntemp end if end if c.............if nonconforming else if(ntemp.ne.0)then if(ifsame(ntemp,c_f(lc,jjface(face_a(itemp))), & nbe,j(face_l1(l))))then ntempx(temp)=ntemp ifntempx(temp)=ntemp nnb(l)=ntemp end if end if end if c...........if the neighbor element neighbored by face face_a(face_l2(l)) c does not exist elseif(ifntempx(iintempx(face_l2(l))).ne.0)then nbe=ifntempx(iintempx(face_l2(l))) itemp=face_l1(l) lc=local_corner(j(face_l2(l)),face_a(itemp)) temp=cal_intempx(lc,face_a(itemp)) ii=cal_iijj(1,lc) jj=cal_iijj(2,lc) ntemp=sje(ii,jj,face_a(itemp),nbe) if(ntemp.eq.0)then ntemp=sje(1,1,face_a(itemp),nbe) if(ntemp.ne.0)then if(ifsame(ntemp,c_f(lc,jjface(face_a(itemp))), & nbe,j(face_l2(l))))then ntempx(temp)=ntemp ifntempx(temp)=ntemp nnb(l)=ntemp end if end if else if(ntemp.ne.0.)then if(ifsame(ntemp,c_f(lc,jjface(face_a(itemp))), & nbe,j(face_l2(l))))then ntempx(temp)=ntemp ifntempx(temp)=ntemp nnb(l)=ntemp end if end if end if endif endif end if end do c.....check the neighbor element, neighbored by a vertex only c.....nnb are the three possible neighbor elements neighbored by an edge nnb(1)=ifntempx(cal_nnb(1,i)) nnb(2)=ifntempx(cal_nnb(2,i)) nnb(3)=ifntempx(cal_nnb(3,i)) ntemp=0 c.....the neighbor element neighbored by a vertex must be a neighbor of c a valid(nonzero) nnb(i), neighbored by a face if(nnb(1).ne.0)then lc=oplc(local_corner(i,face_a(3))) ii=cal_iijj(1,lc) jj=cal_iijj(2,lc) c.......ntemp records the neighbor of iel, neighbored by vertex i ntemp=sje(ii,jj,face_a(3),nnb(1)) c.......temp is the vertex index of i on ntemp temp=cal_intempx(lc,face_a(3)) if(ntemp.eq.0)then ntemp=sje(1,1,face_a(3),nnb(1)) if(ntemp.ne.0)then if(ifsame(ntemp,c_f(lc,jjface(face_a(3))), & iel,i))then ntempx(temp)=ntemp ifntempx(temp)=ntemp end if end if else if(ntemp.ne.0)then if(ifsame(ntemp,c_f(lc,jjface(face_a(3))), & iel,i))then ntempx(temp)=ntemp ifntempx(temp)=ntemp end if end if end if elseif(nnb(2).ne.0)then lc=oplc(local_corner(i,face_a(1))) ii=cal_iijj(1,lc) jj=cal_iijj(2,lc) ntemp=sje(ii,jj,face_a(1),nnb(2)) temp=cal_intempx(lc,face_a(1)) if(ntemp.eq.0)then ntemp=sje(1,1,face_a(1),nnb(2)) if(ntemp.ne.0)then if(ifsame(ntemp, & c_f(lc,jjface(face_a(1))),iel,i))then ntempx(temp)=ntemp ifntempx(temp)=ntemp end if end if else if(ntemp.ne.0)then if(ifsame(ntemp, & c_f(lc,jjface(face_a(1))),iel,i))then ntempx(temp)=ntemp ifntempx(temp)=ntemp end if end if end if elseif(nnb(3).ne.0)then lc=oplc(local_corner(i,face_a(2))) ii=cal_iijj(1,lc) jj=cal_iijj(2,lc) ntemp=sje(ii,jj,face_a(2),nnb(3)) temp=cal_intempx(lc, face_a(2)) if(ntemp.eq.0)then ntemp=sje(1,1,face_a(2),nnb(3)) if(ntemp.ne.0)then if(ifsame(ntemp, & c_f(lc,jjface(face_a(2))),iel,i))then ifntempx(temp)=ntemp ntempx(temp)=ntemp end if end if else if(ntemp.ne.0)then if(ifsame(ntemp, & c_f(lc,jjface(face_a(2))),iel,i))then ifntempx(temp)=ntemp ntempx(temp)=ntemp end if end if end if end if c.....ifntempx records all elements sharing this vertex, assign count c to all these elements. if (ifntempx(1).ne.0) then idmo(lx1,lx1,2,2,1,ntempx(1))=count idmo(lx1,lx1,2,2,3,ntempx(1))=count idmo(lx1,lx1,2,2,5,ntempx(1))=count call get_emo(ntempx(1),count,8) end if if (ifntempx(2).ne.0) then idmo(lx1,lx1,2,2,2,ntempx(2))=count idmo(1,lx1,2,1,3,ntempx(2))=count idmo(1,lx1,2,1,5,ntempx(2))=count call get_emo(ntempx(2),count,7) end if if (ifntempx(3).ne.0) then idmo(1,lx1,2,1,1,ntempx(3))=count idmo(lx1,lx1,2,2,4,ntempx(3))=count idmo(lx1,1,1,2,5,ntempx(3))=count call get_emo(ntempx(3),count,6) end if if (ifntempx(4).ne.0) then idmo(1,lx1,2,1,2,ntempx(4))=count idmo(1,lx1,2,1,4,ntempx(4))=count idmo(1,1,1,1,5,ntempx(4))=count call get_emo(ntempx(4),count,5) end if if (ifntempx(5).ne.0) then idmo(lx1,1,1,2,1,ntempx(5))=count idmo(lx1,1,1,2,3,ntempx(5))=count idmo(lx1,lx1,2,2,6,ntempx(5))=count call get_emo(ntempx(5),count,4) end if if (ifntempx(6).ne.0) then idmo(lx1,1,1,2,2,ntempx(6))=count idmo(1,1,1,1,3,ntempx(6))=count idmo(1,lx1,2,1,6,ntempx(6))=count call get_emo(ntempx(6),count,3) end if if (ifntempx(7).ne.0) then idmo(1,1,1,1,1,ntempx(7))=count idmo(lx1,1,1,2,4,ntempx(7))=count idmo(lx1,1,1,2,6,ntempx(7))=count call get_emo(ntempx(7),count,2) end if if (ifntempx(8).ne.0) then idmo(1,1,1,1,2,ntempx(8))=count idmo(1,1,1,1,4,ntempx(8))=count idmo(1,1,1,1,6,ntempx(8))=count call get_emo(ntempx(8),count,1) end if return end c--------------------------------------------------------------- subroutine mor_ne(mor_v,nn,edge,face,edge2,face2,ntemp,iel) c--------------------------------------------------------------- c Copy the mortar points index (mor_v + vertex mortar point) from c edge'th local edge on face'th face on element ntemp to iel. c ntemp is iel's neighbor, neighbored by this edge only. c This subroutine is for the situation that iel is of larger c size than ntemp. c face, face2 are face indices c edge and edge2 are local edge numbers of this edge on face and face2 c nn is edge motar index, which indicate whether this edge c corresponds to the left/bottom or right/top part of the edge c on iel. c--------------------------------------------------------------- include 'header.h' integer mor_v(3),nn,edge,face,edge2,face2,ntemp,iel, i, &mor_s_v(4) c.....get mor_s_v which is the mor_v + vertex mortar if (edge.eq.3) then if(nn.eq.1)then do i=2,lx1-1 mor_s_v(i-1)=mor_v(i-1) end do mor_s_v(4)=idmo(lx1,lx1,2,2,face,ntemp) else mor_s_v(1)=idmo(1,lx1,2,1,face,ntemp) do i=2,lx1-1 mor_s_v(i)=mor_v(i-1) end do endif elseif (edge.eq.4) then if(nn.eq.1)then do i=2,lx1-1 mor_s_v(i-1)=mor_v(i-1) end do mor_s_v(4)=idmo(1,lx1,2,1,face,ntemp) else mor_s_v(1)=idmo(1,1,1,1,face,ntemp) do i=2,lx1-1 mor_s_v(i)=mor_v(i-1) end do endif elseif (edge.eq.1) then if(nn.eq.1)then do i=2,lx1-1 mor_s_v(i-1)=mor_v(i-1) end do mor_s_v(4)=idmo(lx1,1,1,2,face,ntemp) else mor_s_v(1)=idmo(1,1,1,1,face,ntemp) do i=2,lx1-1 mor_s_v(i)=mor_v(i-1) end do endif else if (edge.eq.2) then if(nn.eq.1)then do i=2,lx1-1 mor_s_v(i-1)=mor_v(i-1) end do mor_s_v(4)=idmo(lx1,lx1,2,2,face,ntemp) else mor_s_v(1)=idmo(lx1,1,1,2,face,ntemp) do i=2,lx1-1 mor_s_v(i)=mor_v(i-1) end do endif end if c.....copy mor_s_v to iel's local edge(op(edge)), on face jjface(face) call mor_s_e_nn(op(edge),jjface(face),iel,mor_s_v,nn) c.....copy mor_s_v to iel's local edge(op(edge2)), on face jjface(face2) c since this edge is shared by two faces on iel call mor_s_e_nn(op(edge2),jjface(face2),iel,mor_s_v,nn) return end
bsd-3-clause
hlokavarapu/calypso
src/Fortran_libraries/SERIAL_src/IO/ucd_IO_select.f90
3
9277
!>@file ucd_IO_select.F90 !! module ucd_IO_select !! !!@author H. Matsui !!@date programmed by H.Matsui on July, 2006 !!@n Modified by H.Matsui on May, 2009 ! !> @brief UCD data IO selector !! !!@verbatim !! subroutine set_ucd_file_define(ucd) !! !! subroutine sel_write_ucd_file(my_rank, istep_ucd, ucd) !! subroutine sel_write_udt_file(my_rank, istep_ucd, ucd) !! subroutine sel_write_grd_file(my_rank, ucd) !! !! subroutine sel_read_udt_param(my_rank, istep_ucd, ucd) !! subroutine sel_read_alloc_udt_file(my_rank, istep_ucd, ucd) !! subroutine sel_read_udt_file(my_rank, istep_ucd, ucd) !! subroutine sel_read_ucd_file(my_rank, istep_ucd, nnod_ele, ucd) !!@endverbatim !! !!@param my_rank process ID !!@param istep_ucd step number for output ! module ucd_IO_select ! use m_precision use m_constants use m_file_format_switch use m_field_file_format ! use udt_file_IO use ucd_field_file_IO ! use ucd_field_file_IO_b ! !#ifdef ZLIB_IO ! use gz_udt_file_IO ! use gz_ucd_field_file_IO ! use gz_write_ucd_to_vtk_file !#endif ! use t_ucd_data ! implicit none ! !------------------------------------------------------------------ ! contains ! !------------------------------------------------------------------ ! subroutine set_ucd_file_define(ucd) ! use m_ctl_data_4_platforms ! type(ucd_data), intent(inout) :: ucd ! ! ucd%ifmt_file = udt_file_head_ctl%iflag if (ucd%ifmt_file .gt. 0) & & ucd%file_prefix = udt_file_head_ctl%charavalue ! call choose_ucd_file_format(udt_file_fmt_ctl%charavalue, & & udt_file_fmt_ctl%iflag, ucd%ifmt_file) ! end subroutine set_ucd_file_define ! ! ----------------------------------------------------------------------- ! subroutine sel_write_ucd_file(my_rank, istep_ucd, ucd) ! use write_ucd_to_vtk_file ! integer(kind=kint), intent(in) :: my_rank, istep_ucd type(ucd_data), intent(in) :: ucd ! ! if(ucd%ifmt_file .eq. iflag_vtk) then call write_udt_data_2_vtk_file(my_rank, istep_ucd, ucd) ! !#ifdef ZLIB_IO ! else if(ucd%ifmt_file .eq. iflag_vtk_gz) then ! call write_ucd_data_2_gz_vtk(my_rank, istep_ucd, ucd) ! else if (ucd%ifmt_file .eq. iflag_vtd_gz) then ! call write_ucd_data_2_gz_vtk_phys(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_ucd_gz) then ! call write_gz_ucd_file(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_udt_gz) then ! call write_gz_udt_file(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_fld_gz) then ! call write_ucd_2_gz_fld_file(my_rank, istep_ucd, ucd) !#endif ! ! else if (ucd%ifmt_file .eq. iflag_bin) then ! call write_ucd_2_fld_file_b(my_rank, istep_ucd, ucd) else if (ucd%ifmt_file .eq. iflag_vtd) then call write_udt_data_2_vtk_phys(my_rank, istep_ucd, ucd) else if(ucd%ifmt_file .eq. iflag_ucd) then call write_ucd_file(my_rank, istep_ucd, ucd) else if(ucd%ifmt_file .eq. iflag_udt) then call write_udt_file(my_rank, istep_ucd, ucd) else call write_ucd_2_fld_file(my_rank, istep_ucd, ucd) end if ! end subroutine sel_write_ucd_file ! !------------------------------------------------------------------ ! subroutine sel_write_udt_file(my_rank, istep_ucd, ucd) ! use write_ucd_to_vtk_file ! integer(kind=kint), intent(in) :: my_rank, istep_ucd type(ucd_data), intent(in) :: ucd ! ! if(ucd%ifmt_file .eq. iflag_vtk) then call write_udt_data_2_vtk_file(my_rank, istep_ucd, ucd) ! !#ifdef ZLIB_IO ! else if(ucd%ifmt_file .eq. iflag_vtk_gz) then ! call write_ucd_data_2_gz_vtk(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_vtd_gz) then ! call write_ucd_data_2_gz_vtk_phys(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_ucd_gz) then ! call write_gz_ucd_file(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_udt_gz) then ! call write_gz_udt_file(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_fld_gz) then ! call write_ucd_2_gz_fld_file(my_rank, istep_ucd, ucd) !#endif ! ! else if (ucd%ifmt_file .eq. iflag_bin) then ! call write_ucd_2_fld_file_b(my_rank, istep_ucd, ucd) else if(ucd%ifmt_file .eq. iflag_vtd) then call write_udt_data_2_vtk_phys(my_rank, istep_ucd, ucd) else if(ucd%ifmt_file .eq. iflag_ucd) then call write_ucd_file(my_rank, istep_ucd, ucd) else if(ucd%ifmt_file .eq. iflag_udt) then call write_udt_file(my_rank, istep_ucd, ucd) else call write_ucd_2_fld_file(my_rank, istep_ucd, ucd) end if ! end subroutine sel_write_udt_file ! !------------------------------------------------------------------ ! subroutine sel_write_grd_file(my_rank, ucd) ! use udt_file_IO use write_ucd_to_vtk_file ! integer(kind=kint), intent(in) :: my_rank type(ucd_data), intent(in) :: ucd ! ! if(ucd%ifmt_file .eq. iflag_vtd) then call write_udt_data_2_vtk_grid(my_rank, ucd) ! !#ifdef ZLIB_IO ! else if(ucd%ifmt_file .eq. iflag_vtd_gz) then ! call write_ucd_data_2_gz_vtk_grid(my_rank, ucd) ! else if(ucd%ifmt_file .eq. iflag_udt_gz) then ! call write_gz_grd_file(my_rank, ucd) !#endif ! else if(ucd%ifmt_file .eq. iflag_udt) then call write_grd_file(my_rank, ucd) end if ! end subroutine sel_write_grd_file ! !------------------------------------------------------------------ !------------------------------------------------------------------ ! subroutine sel_read_udt_param(my_rank, istep_ucd, ucd) ! ! integer(kind=kint), intent(in) :: my_rank, istep_ucd type(ucd_data), intent(inout) :: ucd ! ! if(ucd%ifmt_file .eq. iflag_udt) then call read_and_alloc_udt_params(my_rank, istep_ucd, ucd) ! !#ifdef ZLIB_IO ! else if(ucd%ifmt_file .eq. iflag_udt_gz) then ! call read_alloc_gz_udt_head(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_fld_gz) then ! call read_alloc_ucd_2_gz_fld_file(my_rank, istep_ucd, ucd) !#endif ! ! else if (ucd%ifmt_file .eq. iflag_bin) then ! call read_alloc_ucd_2_fld_header_b(my_rank, istep_ucd, ucd) else call read_alloc_ucd_2_fld_file(my_rank, istep_ucd, ucd) end if ! end subroutine sel_read_udt_param ! !------------------------------------------------------------------ ! subroutine sel_read_alloc_udt_file(my_rank, istep_ucd, ucd) ! ! integer(kind=kint), intent(in) :: my_rank, istep_ucd type(ucd_data), intent(inout) :: ucd ! ! if(ucd%ifmt_file .eq. iflag_udt) then call read_and_alloc_udt_file(my_rank, istep_ucd, ucd) ! !#ifdef ZLIB_IO ! else if(ucd%ifmt_file .eq. iflag_udt_gz) then ! call read_alloc_gz_udt_file(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_fld_gz) then ! call read_alloc_ucd_2_gz_fld_file(my_rank, istep_ucd, ucd) !#endif ! ! else if (ucd%ifmt_file .eq. iflag_bin) then ! call read_alloc_ucd_2_fld_file_b(my_rank, istep_ucd, ucd) else call read_alloc_ucd_2_fld_file(my_rank, istep_ucd, ucd) end if ! end subroutine sel_read_alloc_udt_file ! !------------------------------------------------------------------ ! subroutine sel_read_udt_file(my_rank, istep_ucd, ucd) ! ! integer(kind=kint), intent(in) :: my_rank, istep_ucd type(ucd_data), intent(inout) :: ucd ! ! if(ucd%ifmt_file .eq. iflag_udt) then call read_udt_file(my_rank, istep_ucd, ucd) ! !#ifdef ZLIB_IO ! else if(ucd%ifmt_file .eq. iflag_udt_gz) then ! call read_gz_udt_file(my_rank, istep_ucd, ucd) ! else if(ucd%ifmt_file .eq. iflag_fld_gz) then ! call read_ucd_2_gz_fld_file(my_rank, istep_ucd, ucd) !#endif ! ! else if (ucd%ifmt_file .eq. iflag_bin) then ! call read_ucd_2_fld_file_b(my_rank, istep_ucd, ucd) else call read_ucd_2_fld_file(my_rank, istep_ucd, ucd) end if ! end subroutine sel_read_udt_file ! !------------------------------------------------------------------ ! subroutine sel_read_ucd_file(my_rank, istep_ucd, nnod_ele, ucd) ! ! integer(kind=kint), intent(in) :: my_rank, istep_ucd, nnod_ele type(ucd_data), intent(inout) :: ucd ! ! if (ucd%ifmt_file .eq. iflag_ucd) then call read_and_alloc_ucd_file(my_rank, istep_ucd, nnod_ele, ucd) ! !#ifdef ZLIB_IO ! else if (ucd%ifmt_file .eq. iflag_ucd_gz) then ! call read_alloc_gz_ucd_file(my_rank, istep_ucd, nnod_ele, ucd) ! else if(ucd%ifmt_file .eq. iflag_udt_gz) then ! call read_gz_ucd_grd(my_rank, nnod_ele, ucd) ! call read_alloc_gz_udt_file(my_rank, istep_ucd, ucd) !#endif ! else call read_grd_file(my_rank, nnod_ele, ucd) call read_and_alloc_udt_file(my_rank, istep_ucd, ucd) end if ! end subroutine sel_read_ucd_file ! !------------------------------------------------------------------ ! end module ucd_IO_select
gpl-3.0
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/zgeqr2p.f
19
5226
*> \brief \b ZGEQR2P computes the QR factorization of a general rectangular matrix with non-negative diagonal elements using an unblocked algorithm. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZGEQR2P + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgeqr2p.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgeqr2p.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgeqr2p.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZGEQR2P( M, N, A, LDA, TAU, WORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, M, N * .. * .. Array Arguments .. * COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZGEQR2P computes a QR factorization of a complex m by n matrix A: *> A = Q * R. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX*16 array, dimension (LDA,N) *> On entry, the m by n matrix A. *> On exit, the elements on and above the diagonal of the array *> contain the min(m,n) by n upper trapezoidal matrix R (R is *> upper triangular if m >= n); the elements below the diagonal, *> with the array TAU, represent the unitary matrix Q as a *> product of elementary reflectors (see Further Details). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is COMPLEX*16 array, dimension (min(M,N)) *> The scalar factors of the elementary reflectors (see Further *> Details). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX*16 array, dimension (N) *> \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. * *> \date September 2012 * *> \ingroup complex16GEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix Q is represented as a product of elementary reflectors *> *> Q = H(1) H(2) . . . H(k), where k = min(m,n). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**H *> *> where tau is a complex scalar, and v is a complex vector with *> v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i), *> and tau in TAU(i). *> \endverbatim *> * ===================================================================== SUBROUTINE ZGEQR2P( M, N, A, LDA, TAU, WORK, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INFO, LDA, M, N * .. * .. Array Arguments .. COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX*16 ONE PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) ) * .. * .. Local Scalars .. INTEGER I, K COMPLEX*16 ALPHA * .. * .. External Subroutines .. EXTERNAL XERBLA, ZLARF, ZLARFGP * .. * .. Intrinsic Functions .. INTRINSIC DCONJG, MAX, MIN * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -4 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZGEQR2P', -INFO ) RETURN END IF * K = MIN( M, N ) * DO 10 I = 1, K * * Generate elementary reflector H(i) to annihilate A(i+1:m,i) * CALL ZLARFGP( M-I+1, A( I, I ), A( MIN( I+1, M ), I ), 1, $ TAU( I ) ) IF( I.LT.N ) THEN * * Apply H(i)**H to A(i:m,i+1:n) from the left * ALPHA = A( I, I ) A( I, I ) = ONE CALL ZLARF( 'Left', M-I+1, N-I, A( I, I ), 1, $ DCONJG( TAU( I ) ), A( I, I+1 ), LDA, WORK ) A( I, I ) = ALPHA END IF 10 CONTINUE RETURN * * End of ZGEQR2P * END
bsd-3-clause
UPenn-RoboCup/OpenBLAS
lapack-netlib/SRC/dtrsen.f
25
18321
*> \brief \b DTRSEN * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DTRSEN + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrsen.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrsen.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrsen.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DTRSEN( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, WR, WI, * M, S, SEP, WORK, LWORK, IWORK, LIWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER COMPQ, JOB * INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N * DOUBLE PRECISION S, SEP * .. * .. Array Arguments .. * LOGICAL SELECT( * ) * INTEGER IWORK( * ) * DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ), * $ WR( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DTRSEN reorders the real Schur factorization of a real matrix *> A = Q*T*Q**T, so that a selected cluster of eigenvalues appears in *> the leading diagonal blocks of the upper quasi-triangular matrix T, *> and the leading columns of Q form an orthonormal basis of the *> corresponding right invariant subspace. *> *> Optionally the routine computes the reciprocal condition numbers of *> the cluster of eigenvalues and/or the invariant subspace. *> *> T must be in Schur canonical form (as returned by DHSEQR), that is, *> block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each *> 2-by-2 diagonal block has its diagonal elements equal and its *> off-diagonal elements of opposite sign. *> \endverbatim * * Arguments: * ========== * *> \param[in] JOB *> \verbatim *> JOB is CHARACTER*1 *> Specifies whether condition numbers are required for the *> cluster of eigenvalues (S) or the invariant subspace (SEP): *> = 'N': none; *> = 'E': for eigenvalues only (S); *> = 'V': for invariant subspace only (SEP); *> = 'B': for both eigenvalues and invariant subspace (S and *> SEP). *> \endverbatim *> *> \param[in] COMPQ *> \verbatim *> COMPQ is CHARACTER*1 *> = 'V': update the matrix Q of Schur vectors; *> = 'N': do not update Q. *> \endverbatim *> *> \param[in] SELECT *> \verbatim *> SELECT is LOGICAL array, dimension (N) *> SELECT specifies the eigenvalues in the selected cluster. To *> select a real eigenvalue w(j), SELECT(j) must be set to *> .TRUE.. To select a complex conjugate pair of eigenvalues *> w(j) and w(j+1), corresponding to a 2-by-2 diagonal block, *> either SELECT(j) or SELECT(j+1) or both must be set to *> .TRUE.; a complex conjugate pair of eigenvalues must be *> either both included in the cluster or both excluded. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix T. N >= 0. *> \endverbatim *> *> \param[in,out] T *> \verbatim *> T is DOUBLE PRECISION array, dimension (LDT,N) *> On entry, the upper quasi-triangular matrix T, in Schur *> canonical form. *> On exit, T is overwritten by the reordered matrix T, again in *> Schur canonical form, with the selected eigenvalues in the *> leading diagonal blocks. *> \endverbatim *> *> \param[in] LDT *> \verbatim *> LDT is INTEGER *> The leading dimension of the array T. LDT >= max(1,N). *> \endverbatim *> *> \param[in,out] Q *> \verbatim *> Q is DOUBLE PRECISION array, dimension (LDQ,N) *> On entry, if COMPQ = 'V', the matrix Q of Schur vectors. *> On exit, if COMPQ = 'V', Q has been postmultiplied by the *> orthogonal transformation matrix which reorders T; the *> leading M columns of Q form an orthonormal basis for the *> specified invariant subspace. *> If COMPQ = 'N', Q is not referenced. *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of the array Q. *> LDQ >= 1; and if COMPQ = 'V', LDQ >= N. *> \endverbatim *> *> \param[out] WR *> \verbatim *> WR is DOUBLE PRECISION array, dimension (N) *> \endverbatim *> \param[out] WI *> \verbatim *> WI is DOUBLE PRECISION array, dimension (N) *> *> The real and imaginary parts, respectively, of the reordered *> eigenvalues of T. The eigenvalues are stored in the same *> order as on the diagonal of T, with WR(i) = T(i,i) and, if *> T(i:i+1,i:i+1) is a 2-by-2 diagonal block, WI(i) > 0 and *> WI(i+1) = -WI(i). Note that if a complex eigenvalue is *> sufficiently ill-conditioned, then its value may differ *> significantly from its value before reordering. *> \endverbatim *> *> \param[out] M *> \verbatim *> M is INTEGER *> The dimension of the specified invariant subspace. *> 0 < = M <= N. *> \endverbatim *> *> \param[out] S *> \verbatim *> S is DOUBLE PRECISION *> If JOB = 'E' or 'B', S is a lower bound on the reciprocal *> condition number for the selected cluster of eigenvalues. *> S cannot underestimate the true reciprocal condition number *> by more than a factor of sqrt(N). If M = 0 or N, S = 1. *> If JOB = 'N' or 'V', S is not referenced. *> \endverbatim *> *> \param[out] SEP *> \verbatim *> SEP is DOUBLE PRECISION *> If JOB = 'V' or 'B', SEP is the estimated reciprocal *> condition number of the specified invariant subspace. If *> M = 0 or N, SEP = norm(T). *> If JOB = 'N' or 'E', SEP is not referenced. *> \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 JOB = 'N', LWORK >= max(1,N); *> if JOB = 'E', LWORK >= max(1,M*(N-M)); *> if JOB = 'V' or 'B', LWORK >= max(1,2*M*(N-M)). *> *> 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] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (MAX(1,LIWORK)) *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. *> \endverbatim *> *> \param[in] LIWORK *> \verbatim *> LIWORK is INTEGER *> The dimension of the array IWORK. *> If JOB = 'N' or 'E', LIWORK >= 1; *> if JOB = 'V' or 'B', LIWORK >= max(1,M*(N-M)). *> *> If LIWORK = -1, then a workspace query is assumed; the *> routine only calculates the optimal size of the IWORK array, *> returns this value as the first entry of the IWORK array, and *> no error message related to LIWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> = 1: reordering of T failed because some eigenvalues are too *> close to separate (the problem is very ill-conditioned); *> T may have been partially reordered, and WR and WI *> contain the eigenvalues in the same order as in T; S and *> SEP (if requested) are set to zero. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date April 2012 * *> \ingroup doubleOTHERcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> DTRSEN first collects the selected eigenvalues by computing an *> orthogonal transformation Z to move them to the top left corner of T. *> In other words, the selected eigenvalues are the eigenvalues of T11 *> in: *> *> Z**T * T * Z = ( T11 T12 ) n1 *> ( 0 T22 ) n2 *> n1 n2 *> *> where N = n1+n2 and Z**T means the transpose of Z. The first n1 columns *> of Z span the specified invariant subspace of T. *> *> If T has been obtained from the real Schur factorization of a matrix *> A = Q*T*Q**T, then the reordered real Schur factorization of A is given *> by A = (Q*Z)*(Z**T*T*Z)*(Q*Z)**T, and the first n1 columns of Q*Z span *> the corresponding invariant subspace of A. *> *> The reciprocal condition number of the average of the eigenvalues of *> T11 may be returned in S. S lies between 0 (very badly conditioned) *> and 1 (very well conditioned). It is computed as follows. First we *> compute R so that *> *> P = ( I R ) n1 *> ( 0 0 ) n2 *> n1 n2 *> *> is the projector on the invariant subspace associated with T11. *> R is the solution of the Sylvester equation: *> *> T11*R - R*T22 = T12. *> *> Let F-norm(M) denote the Frobenius-norm of M and 2-norm(M) denote *> the two-norm of M. Then S is computed as the lower bound *> *> (1 + F-norm(R)**2)**(-1/2) *> *> on the reciprocal of 2-norm(P), the true reciprocal condition number. *> S cannot underestimate 1 / 2-norm(P) by more than a factor of *> sqrt(N). *> *> An approximate error bound for the computed average of the *> eigenvalues of T11 is *> *> EPS * norm(T) / S *> *> where EPS is the machine precision. *> *> The reciprocal condition number of the right invariant subspace *> spanned by the first n1 columns of Z (or of Q*Z) is returned in SEP. *> SEP is defined as the separation of T11 and T22: *> *> sep( T11, T22 ) = sigma-min( C ) *> *> where sigma-min(C) is the smallest singular value of the *> n1*n2-by-n1*n2 matrix *> *> C = kprod( I(n2), T11 ) - kprod( transpose(T22), I(n1) ) *> *> I(m) is an m by m identity matrix, and kprod denotes the Kronecker *> product. We estimate sigma-min(C) by the reciprocal of an estimate of *> the 1-norm of inverse(C). The true reciprocal 1-norm of inverse(C) *> cannot differ from sigma-min(C) by more than a factor of sqrt(n1*n2). *> *> When SEP is small, small changes in T can cause large changes in *> the invariant subspace. An approximate bound on the maximum angular *> error in the computed right invariant subspace is *> *> EPS * norm(T) / SEP *> \endverbatim *> * ===================================================================== SUBROUTINE DTRSEN( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, WR, WI, $ M, S, SEP, WORK, LWORK, IWORK, LIWORK, INFO ) * * -- LAPACK computational routine (version 3.4.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * April 2012 * * .. Scalar Arguments .. CHARACTER COMPQ, JOB INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N DOUBLE PRECISION S, SEP * .. * .. Array Arguments .. LOGICAL SELECT( * ) INTEGER IWORK( * ) DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ), $ WR( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL LQUERY, PAIR, SWAP, WANTBH, WANTQ, WANTS, $ WANTSP INTEGER IERR, K, KASE, KK, KS, LIWMIN, LWMIN, N1, N2, $ NN DOUBLE PRECISION EST, RNORM, SCALE * .. * .. Local Arrays .. INTEGER ISAVE( 3 ) * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DLANGE EXTERNAL LSAME, DLANGE * .. * .. External Subroutines .. EXTERNAL DLACN2, DLACPY, DTREXC, DTRSYL, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, SQRT * .. * .. Executable Statements .. * * Decode and test the input parameters * WANTBH = LSAME( JOB, 'B' ) WANTS = LSAME( JOB, 'E' ) .OR. WANTBH WANTSP = LSAME( JOB, 'V' ) .OR. WANTBH WANTQ = LSAME( COMPQ, 'V' ) * INFO = 0 LQUERY = ( LWORK.EQ.-1 ) IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.WANTS .AND. .NOT.WANTSP ) $ THEN INFO = -1 ELSE IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -4 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN INFO = -6 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN INFO = -8 ELSE * * Set M to the dimension of the specified invariant subspace, * and test LWORK and LIWORK. * M = 0 PAIR = .FALSE. DO 10 K = 1, N IF( PAIR ) THEN PAIR = .FALSE. ELSE IF( K.LT.N ) THEN IF( T( K+1, K ).EQ.ZERO ) THEN IF( SELECT( K ) ) $ M = M + 1 ELSE PAIR = .TRUE. IF( SELECT( K ) .OR. SELECT( K+1 ) ) $ M = M + 2 END IF ELSE IF( SELECT( N ) ) $ M = M + 1 END IF END IF 10 CONTINUE * N1 = M N2 = N - M NN = N1*N2 * IF( WANTSP ) THEN LWMIN = MAX( 1, 2*NN ) LIWMIN = MAX( 1, NN ) ELSE IF( LSAME( JOB, 'N' ) ) THEN LWMIN = MAX( 1, N ) LIWMIN = 1 ELSE IF( LSAME( JOB, 'E' ) ) THEN LWMIN = MAX( 1, NN ) LIWMIN = 1 END IF * IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN INFO = -15 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN INFO = -17 END IF END IF * IF( INFO.EQ.0 ) THEN WORK( 1 ) = LWMIN IWORK( 1 ) = LIWMIN END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'DTRSEN', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible. * IF( M.EQ.N .OR. M.EQ.0 ) THEN IF( WANTS ) $ S = ONE IF( WANTSP ) $ SEP = DLANGE( '1', N, N, T, LDT, WORK ) GO TO 40 END IF * * Collect the selected blocks at the top-left corner of T. * KS = 0 PAIR = .FALSE. DO 20 K = 1, N IF( PAIR ) THEN PAIR = .FALSE. ELSE SWAP = SELECT( K ) IF( K.LT.N ) THEN IF( T( K+1, K ).NE.ZERO ) THEN PAIR = .TRUE. SWAP = SWAP .OR. SELECT( K+1 ) END IF END IF IF( SWAP ) THEN KS = KS + 1 * * Swap the K-th block to position KS. * IERR = 0 KK = K IF( K.NE.KS ) $ CALL DTREXC( COMPQ, N, T, LDT, Q, LDQ, KK, KS, WORK, $ IERR ) IF( IERR.EQ.1 .OR. IERR.EQ.2 ) THEN * * Blocks too close to swap: exit. * INFO = 1 IF( WANTS ) $ S = ZERO IF( WANTSP ) $ SEP = ZERO GO TO 40 END IF IF( PAIR ) $ KS = KS + 1 END IF END IF 20 CONTINUE * IF( WANTS ) THEN * * Solve Sylvester equation for R: * * T11*R - R*T22 = scale*T12 * CALL DLACPY( 'F', N1, N2, T( 1, N1+1 ), LDT, WORK, N1 ) CALL DTRSYL( 'N', 'N', -1, N1, N2, T, LDT, T( N1+1, N1+1 ), $ LDT, WORK, N1, SCALE, IERR ) * * Estimate the reciprocal of the condition number of the cluster * of eigenvalues. * RNORM = DLANGE( 'F', N1, N2, WORK, N1, WORK ) IF( RNORM.EQ.ZERO ) THEN S = ONE ELSE S = SCALE / ( SQRT( SCALE*SCALE / RNORM+RNORM )* $ SQRT( RNORM ) ) END IF END IF * IF( WANTSP ) THEN * * Estimate sep(T11,T22). * EST = ZERO KASE = 0 30 CONTINUE CALL DLACN2( NN, WORK( NN+1 ), WORK, IWORK, EST, KASE, ISAVE ) IF( KASE.NE.0 ) THEN IF( KASE.EQ.1 ) THEN * * Solve T11*R - R*T22 = scale*X. * CALL DTRSYL( 'N', 'N', -1, N1, N2, T, LDT, $ T( N1+1, N1+1 ), LDT, WORK, N1, SCALE, $ IERR ) ELSE * * Solve T11**T*R - R*T22**T = scale*X. * CALL DTRSYL( 'T', 'T', -1, N1, N2, T, LDT, $ T( N1+1, N1+1 ), LDT, WORK, N1, SCALE, $ IERR ) END IF GO TO 30 END IF * SEP = SCALE / EST END IF * 40 CONTINUE * * Store the output eigenvalues in WR and WI. * DO 50 K = 1, N WR( K ) = T( K, K ) WI( K ) = ZERO 50 CONTINUE DO 60 K = 1, N - 1 IF( T( K+1, K ).NE.ZERO ) THEN WI( K ) = SQRT( ABS( T( K, K+1 ) ) )* $ SQRT( ABS( T( K+1, K ) ) ) WI( K+1 ) = -WI( K ) END IF 60 CONTINUE * WORK( 1 ) = LWMIN IWORK( 1 ) = LIWMIN * RETURN * * End of DTRSEN * END
bsd-3-clause
TSC21/Eigen
lapack/clarfb.f
273
23424
*> \brief \b CLARFB * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CLARFB + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clarfb.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clarfb.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clarfb.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CLARFB( SIDE, TRANS, DIRECT, STOREV, M, N, K, V, LDV, * T, LDT, C, LDC, WORK, LDWORK ) * * .. Scalar Arguments .. * CHARACTER DIRECT, SIDE, STOREV, TRANS * INTEGER K, LDC, LDT, LDV, LDWORK, M, N * .. * .. Array Arguments .. * COMPLEX C( LDC, * ), T( LDT, * ), V( LDV, * ), * $ WORK( LDWORK, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CLARFB applies a complex block reflector H or its transpose H**H to a *> complex M-by-N matrix C, from either the left or the right. *> \endverbatim * * Arguments: * ========== * *> \param[in] SIDE *> \verbatim *> SIDE is CHARACTER*1 *> = 'L': apply H or H**H from the Left *> = 'R': apply H or H**H from the Right *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> = 'N': apply H (No transpose) *> = 'C': apply H**H (Conjugate transpose) *> \endverbatim *> *> \param[in] DIRECT *> \verbatim *> DIRECT is CHARACTER*1 *> Indicates how H is formed from a product of elementary *> reflectors *> = 'F': H = H(1) H(2) . . . H(k) (Forward) *> = 'B': H = H(k) . . . H(2) H(1) (Backward) *> \endverbatim *> *> \param[in] STOREV *> \verbatim *> STOREV is CHARACTER*1 *> Indicates how the vectors which define the elementary *> reflectors are stored: *> = 'C': Columnwise *> = 'R': Rowwise *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix C. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix C. *> \endverbatim *> *> \param[in] K *> \verbatim *> K is INTEGER *> The order of the matrix T (= the number of elementary *> reflectors whose product defines the block reflector). *> \endverbatim *> *> \param[in] V *> \verbatim *> V is COMPLEX array, dimension *> (LDV,K) if STOREV = 'C' *> (LDV,M) if STOREV = 'R' and SIDE = 'L' *> (LDV,N) if STOREV = 'R' and SIDE = 'R' *> The matrix V. See Further Details. *> \endverbatim *> *> \param[in] LDV *> \verbatim *> LDV is INTEGER *> The leading dimension of the array V. *> If STOREV = 'C' and SIDE = 'L', LDV >= max(1,M); *> if STOREV = 'C' and SIDE = 'R', LDV >= max(1,N); *> if STOREV = 'R', LDV >= K. *> \endverbatim *> *> \param[in] T *> \verbatim *> T is COMPLEX array, dimension (LDT,K) *> The triangular K-by-K matrix T in the representation of the *> block reflector. *> \endverbatim *> *> \param[in] LDT *> \verbatim *> LDT is INTEGER *> The leading dimension of the array T. LDT >= K. *> \endverbatim *> *> \param[in,out] C *> \verbatim *> C is COMPLEX array, dimension (LDC,N) *> On entry, the M-by-N matrix C. *> On exit, C is overwritten by H*C or H**H*C or C*H or C*H**H. *> \endverbatim *> *> \param[in] LDC *> \verbatim *> LDC is INTEGER *> The leading dimension of the array C. LDC >= max(1,M). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (LDWORK,K) *> \endverbatim *> *> \param[in] LDWORK *> \verbatim *> LDWORK is INTEGER *> The leading dimension of the array WORK. *> If SIDE = 'L', LDWORK >= max(1,N); *> if SIDE = 'R', LDWORK >= max(1,M). *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complexOTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> The shape of the matrix V and the storage of the vectors which define *> the H(i) is best illustrated by the following example with n = 5 and *> k = 3. The elements equal to 1 are not stored; the corresponding *> array elements are modified but restored on exit. The rest of the *> array is not used. *> *> DIRECT = 'F' and STOREV = 'C': DIRECT = 'F' and STOREV = 'R': *> *> V = ( 1 ) V = ( 1 v1 v1 v1 v1 ) *> ( v1 1 ) ( 1 v2 v2 v2 ) *> ( v1 v2 1 ) ( 1 v3 v3 ) *> ( v1 v2 v3 ) *> ( v1 v2 v3 ) *> *> DIRECT = 'B' and STOREV = 'C': DIRECT = 'B' and STOREV = 'R': *> *> V = ( v1 v2 v3 ) V = ( v1 v1 1 ) *> ( v1 v2 v3 ) ( v2 v2 v2 1 ) *> ( 1 v2 v3 ) ( v3 v3 v3 v3 1 ) *> ( 1 v3 ) *> ( 1 ) *> \endverbatim *> * ===================================================================== SUBROUTINE CLARFB( SIDE, TRANS, DIRECT, STOREV, M, N, K, V, LDV, $ T, LDT, C, LDC, WORK, LDWORK ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER DIRECT, SIDE, STOREV, TRANS INTEGER K, LDC, LDT, LDV, LDWORK, M, N * .. * .. Array Arguments .. COMPLEX C( LDC, * ), T( LDT, * ), V( LDV, * ), $ WORK( LDWORK, * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX ONE PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. CHARACTER TRANST INTEGER I, J, LASTV, LASTC * .. * .. External Functions .. LOGICAL LSAME INTEGER ILACLR, ILACLC EXTERNAL LSAME, ILACLR, ILACLC * .. * .. External Subroutines .. EXTERNAL CCOPY, CGEMM, CLACGV, CTRMM * .. * .. Intrinsic Functions .. INTRINSIC CONJG * .. * .. Executable Statements .. * * Quick return if possible * IF( M.LE.0 .OR. N.LE.0 ) $ RETURN * IF( LSAME( TRANS, 'N' ) ) THEN TRANST = 'C' ELSE TRANST = 'N' END IF * IF( LSAME( STOREV, 'C' ) ) THEN * IF( LSAME( DIRECT, 'F' ) ) THEN * * Let V = ( V1 ) (first K rows) * ( V2 ) * where V1 is unit lower triangular. * IF( LSAME( SIDE, 'L' ) ) THEN * * Form H * C or H**H * C where C = ( C1 ) * ( C2 ) * LASTV = MAX( K, ILACLR( M, K, V, LDV ) ) LASTC = ILACLC( LASTV, N, C, LDC ) * * W := C**H * V = (C1**H * V1 + C2**H * V2) (stored in WORK) * * W := C1**H * DO 10 J = 1, K CALL CCOPY( LASTC, C( J, 1 ), LDC, WORK( 1, J ), 1 ) CALL CLACGV( LASTC, WORK( 1, J ), 1 ) 10 CONTINUE * * W := W * V1 * CALL CTRMM( 'Right', 'Lower', 'No transpose', 'Unit', $ LASTC, K, ONE, V, LDV, WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C2**H *V2 * CALL CGEMM( 'Conjugate transpose', 'No transpose', $ LASTC, K, LASTV-K, ONE, C( K+1, 1 ), LDC, $ V( K+1, 1 ), LDV, ONE, WORK, LDWORK ) END IF * * W := W * T**H or W * T * CALL CTRMM( 'Right', 'Upper', TRANST, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - V * W**H * IF( M.GT.K ) THEN * * C2 := C2 - V2 * W**H * CALL CGEMM( 'No transpose', 'Conjugate transpose', $ LASTV-K, LASTC, K, -ONE, V( K+1, 1 ), LDV, $ WORK, LDWORK, ONE, C( K+1, 1 ), LDC ) END IF * * W := W * V1**H * CALL CTRMM( 'Right', 'Lower', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V, LDV, WORK, LDWORK ) * * C1 := C1 - W**H * DO 30 J = 1, K DO 20 I = 1, LASTC C( J, I ) = C( J, I ) - CONJG( WORK( I, J ) ) 20 CONTINUE 30 CONTINUE * ELSE IF( LSAME( SIDE, 'R' ) ) THEN * * Form C * H or C * H**H where C = ( C1 C2 ) * LASTV = MAX( K, ILACLR( N, K, V, LDV ) ) LASTC = ILACLR( M, LASTV, C, LDC ) * * W := C * V = (C1*V1 + C2*V2) (stored in WORK) * * W := C1 * DO 40 J = 1, K CALL CCOPY( LASTC, C( 1, J ), 1, WORK( 1, J ), 1 ) 40 CONTINUE * * W := W * V1 * CALL CTRMM( 'Right', 'Lower', 'No transpose', 'Unit', $ LASTC, K, ONE, V, LDV, WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C2 * V2 * CALL CGEMM( 'No transpose', 'No transpose', $ LASTC, K, LASTV-K, $ ONE, C( 1, K+1 ), LDC, V( K+1, 1 ), LDV, $ ONE, WORK, LDWORK ) END IF * * W := W * T or W * T**H * CALL CTRMM( 'Right', 'Upper', TRANS, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - W * V**H * IF( LASTV.GT.K ) THEN * * C2 := C2 - W * V2**H * CALL CGEMM( 'No transpose', 'Conjugate transpose', $ LASTC, LASTV-K, K, $ -ONE, WORK, LDWORK, V( K+1, 1 ), LDV, $ ONE, C( 1, K+1 ), LDC ) END IF * * W := W * V1**H * CALL CTRMM( 'Right', 'Lower', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V, LDV, WORK, LDWORK ) * * C1 := C1 - W * DO 60 J = 1, K DO 50 I = 1, LASTC C( I, J ) = C( I, J ) - WORK( I, J ) 50 CONTINUE 60 CONTINUE END IF * ELSE * * Let V = ( V1 ) * ( V2 ) (last K rows) * where V2 is unit upper triangular. * IF( LSAME( SIDE, 'L' ) ) THEN * * Form H * C or H**H * C where C = ( C1 ) * ( C2 ) * LASTV = MAX( K, ILACLR( M, K, V, LDV ) ) LASTC = ILACLC( LASTV, N, C, LDC ) * * W := C**H * V = (C1**H * V1 + C2**H * V2) (stored in WORK) * * W := C2**H * DO 70 J = 1, K CALL CCOPY( LASTC, C( LASTV-K+J, 1 ), LDC, $ WORK( 1, J ), 1 ) CALL CLACGV( LASTC, WORK( 1, J ), 1 ) 70 CONTINUE * * W := W * V2 * CALL CTRMM( 'Right', 'Upper', 'No transpose', 'Unit', $ LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV, $ WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C1**H*V1 * CALL CGEMM( 'Conjugate transpose', 'No transpose', $ LASTC, K, LASTV-K, ONE, C, LDC, V, LDV, $ ONE, WORK, LDWORK ) END IF * * W := W * T**H or W * T * CALL CTRMM( 'Right', 'Lower', TRANST, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - V * W**H * IF( LASTV.GT.K ) THEN * * C1 := C1 - V1 * W**H * CALL CGEMM( 'No transpose', 'Conjugate transpose', $ LASTV-K, LASTC, K, -ONE, V, LDV, WORK, LDWORK, $ ONE, C, LDC ) END IF * * W := W * V2**H * CALL CTRMM( 'Right', 'Upper', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV, $ WORK, LDWORK ) * * C2 := C2 - W**H * DO 90 J = 1, K DO 80 I = 1, LASTC C( LASTV-K+J, I ) = C( LASTV-K+J, I ) - $ CONJG( WORK( I, J ) ) 80 CONTINUE 90 CONTINUE * ELSE IF( LSAME( SIDE, 'R' ) ) THEN * * Form C * H or C * H**H where C = ( C1 C2 ) * LASTV = MAX( K, ILACLR( N, K, V, LDV ) ) LASTC = ILACLR( M, LASTV, C, LDC ) * * W := C * V = (C1*V1 + C2*V2) (stored in WORK) * * W := C2 * DO 100 J = 1, K CALL CCOPY( LASTC, C( 1, LASTV-K+J ), 1, $ WORK( 1, J ), 1 ) 100 CONTINUE * * W := W * V2 * CALL CTRMM( 'Right', 'Upper', 'No transpose', 'Unit', $ LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV, $ WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C1 * V1 * CALL CGEMM( 'No transpose', 'No transpose', $ LASTC, K, LASTV-K, $ ONE, C, LDC, V, LDV, ONE, WORK, LDWORK ) END IF * * W := W * T or W * T**H * CALL CTRMM( 'Right', 'Lower', TRANS, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - W * V**H * IF( LASTV.GT.K ) THEN * * C1 := C1 - W * V1**H * CALL CGEMM( 'No transpose', 'Conjugate transpose', $ LASTC, LASTV-K, K, -ONE, WORK, LDWORK, V, LDV, $ ONE, C, LDC ) END IF * * W := W * V2**H * CALL CTRMM( 'Right', 'Upper', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V( LASTV-K+1, 1 ), LDV, $ WORK, LDWORK ) * * C2 := C2 - W * DO 120 J = 1, K DO 110 I = 1, LASTC C( I, LASTV-K+J ) = C( I, LASTV-K+J ) $ - WORK( I, J ) 110 CONTINUE 120 CONTINUE END IF END IF * ELSE IF( LSAME( STOREV, 'R' ) ) THEN * IF( LSAME( DIRECT, 'F' ) ) THEN * * Let V = ( V1 V2 ) (V1: first K columns) * where V1 is unit upper triangular. * IF( LSAME( SIDE, 'L' ) ) THEN * * Form H * C or H**H * C where C = ( C1 ) * ( C2 ) * LASTV = MAX( K, ILACLC( K, M, V, LDV ) ) LASTC = ILACLC( LASTV, N, C, LDC ) * * W := C**H * V**H = (C1**H * V1**H + C2**H * V2**H) (stored in WORK) * * W := C1**H * DO 130 J = 1, K CALL CCOPY( LASTC, C( J, 1 ), LDC, WORK( 1, J ), 1 ) CALL CLACGV( LASTC, WORK( 1, J ), 1 ) 130 CONTINUE * * W := W * V1**H * CALL CTRMM( 'Right', 'Upper', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V, LDV, WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C2**H*V2**H * CALL CGEMM( 'Conjugate transpose', $ 'Conjugate transpose', LASTC, K, LASTV-K, $ ONE, C( K+1, 1 ), LDC, V( 1, K+1 ), LDV, $ ONE, WORK, LDWORK ) END IF * * W := W * T**H or W * T * CALL CTRMM( 'Right', 'Upper', TRANST, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - V**H * W**H * IF( LASTV.GT.K ) THEN * * C2 := C2 - V2**H * W**H * CALL CGEMM( 'Conjugate transpose', $ 'Conjugate transpose', LASTV-K, LASTC, K, $ -ONE, V( 1, K+1 ), LDV, WORK, LDWORK, $ ONE, C( K+1, 1 ), LDC ) END IF * * W := W * V1 * CALL CTRMM( 'Right', 'Upper', 'No transpose', 'Unit', $ LASTC, K, ONE, V, LDV, WORK, LDWORK ) * * C1 := C1 - W**H * DO 150 J = 1, K DO 140 I = 1, LASTC C( J, I ) = C( J, I ) - CONJG( WORK( I, J ) ) 140 CONTINUE 150 CONTINUE * ELSE IF( LSAME( SIDE, 'R' ) ) THEN * * Form C * H or C * H**H where C = ( C1 C2 ) * LASTV = MAX( K, ILACLC( K, N, V, LDV ) ) LASTC = ILACLR( M, LASTV, C, LDC ) * * W := C * V**H = (C1*V1**H + C2*V2**H) (stored in WORK) * * W := C1 * DO 160 J = 1, K CALL CCOPY( LASTC, C( 1, J ), 1, WORK( 1, J ), 1 ) 160 CONTINUE * * W := W * V1**H * CALL CTRMM( 'Right', 'Upper', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V, LDV, WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C2 * V2**H * CALL CGEMM( 'No transpose', 'Conjugate transpose', $ LASTC, K, LASTV-K, ONE, C( 1, K+1 ), LDC, $ V( 1, K+1 ), LDV, ONE, WORK, LDWORK ) END IF * * W := W * T or W * T**H * CALL CTRMM( 'Right', 'Upper', TRANS, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - W * V * IF( LASTV.GT.K ) THEN * * C2 := C2 - W * V2 * CALL CGEMM( 'No transpose', 'No transpose', $ LASTC, LASTV-K, K, $ -ONE, WORK, LDWORK, V( 1, K+1 ), LDV, $ ONE, C( 1, K+1 ), LDC ) END IF * * W := W * V1 * CALL CTRMM( 'Right', 'Upper', 'No transpose', 'Unit', $ LASTC, K, ONE, V, LDV, WORK, LDWORK ) * * C1 := C1 - W * DO 180 J = 1, K DO 170 I = 1, LASTC C( I, J ) = C( I, J ) - WORK( I, J ) 170 CONTINUE 180 CONTINUE * END IF * ELSE * * Let V = ( V1 V2 ) (V2: last K columns) * where V2 is unit lower triangular. * IF( LSAME( SIDE, 'L' ) ) THEN * * Form H * C or H**H * C where C = ( C1 ) * ( C2 ) * LASTV = MAX( K, ILACLC( K, M, V, LDV ) ) LASTC = ILACLC( LASTV, N, C, LDC ) * * W := C**H * V**H = (C1**H * V1**H + C2**H * V2**H) (stored in WORK) * * W := C2**H * DO 190 J = 1, K CALL CCOPY( LASTC, C( LASTV-K+J, 1 ), LDC, $ WORK( 1, J ), 1 ) CALL CLACGV( LASTC, WORK( 1, J ), 1 ) 190 CONTINUE * * W := W * V2**H * CALL CTRMM( 'Right', 'Lower', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV, $ WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C1**H * V1**H * CALL CGEMM( 'Conjugate transpose', $ 'Conjugate transpose', LASTC, K, LASTV-K, $ ONE, C, LDC, V, LDV, ONE, WORK, LDWORK ) END IF * * W := W * T**H or W * T * CALL CTRMM( 'Right', 'Lower', TRANST, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - V**H * W**H * IF( LASTV.GT.K ) THEN * * C1 := C1 - V1**H * W**H * CALL CGEMM( 'Conjugate transpose', $ 'Conjugate transpose', LASTV-K, LASTC, K, $ -ONE, V, LDV, WORK, LDWORK, ONE, C, LDC ) END IF * * W := W * V2 * CALL CTRMM( 'Right', 'Lower', 'No transpose', 'Unit', $ LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV, $ WORK, LDWORK ) * * C2 := C2 - W**H * DO 210 J = 1, K DO 200 I = 1, LASTC C( LASTV-K+J, I ) = C( LASTV-K+J, I ) - $ CONJG( WORK( I, J ) ) 200 CONTINUE 210 CONTINUE * ELSE IF( LSAME( SIDE, 'R' ) ) THEN * * Form C * H or C * H**H where C = ( C1 C2 ) * LASTV = MAX( K, ILACLC( K, N, V, LDV ) ) LASTC = ILACLR( M, LASTV, C, LDC ) * * W := C * V**H = (C1*V1**H + C2*V2**H) (stored in WORK) * * W := C2 * DO 220 J = 1, K CALL CCOPY( LASTC, C( 1, LASTV-K+J ), 1, $ WORK( 1, J ), 1 ) 220 CONTINUE * * W := W * V2**H * CALL CTRMM( 'Right', 'Lower', 'Conjugate transpose', $ 'Unit', LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV, $ WORK, LDWORK ) IF( LASTV.GT.K ) THEN * * W := W + C1 * V1**H * CALL CGEMM( 'No transpose', 'Conjugate transpose', $ LASTC, K, LASTV-K, ONE, C, LDC, V, LDV, ONE, $ WORK, LDWORK ) END IF * * W := W * T or W * T**H * CALL CTRMM( 'Right', 'Lower', TRANS, 'Non-unit', $ LASTC, K, ONE, T, LDT, WORK, LDWORK ) * * C := C - W * V * IF( LASTV.GT.K ) THEN * * C1 := C1 - W * V1 * CALL CGEMM( 'No transpose', 'No transpose', $ LASTC, LASTV-K, K, -ONE, WORK, LDWORK, V, LDV, $ ONE, C, LDC ) END IF * * W := W * V2 * CALL CTRMM( 'Right', 'Lower', 'No transpose', 'Unit', $ LASTC, K, ONE, V( 1, LASTV-K+1 ), LDV, $ WORK, LDWORK ) * * C1 := C1 - W * DO 240 J = 1, K DO 230 I = 1, LASTC C( I, LASTV-K+J ) = C( I, LASTV-K+J ) $ - WORK( I, J ) 230 CONTINUE 240 CONTINUE * END IF * END IF END IF * RETURN * * End of CLARFB * END
bsd-3-clause
hlokavarapu/calypso
src/Fortran_libraries/SERIAL_src/IO/m_ctl_data_4_sphere_model.f90
3
8951
!>@file m_ctl_data_4_sphere_model.f90 !!@brief module m_ctl_data_4_sphere_model !! !!@author H. Matsui !!@date Programmed in July, 2007 ! !>@brief control data for resolutions of spherical shell !! !!@verbatim !! subroutine read_ctl_4_shell_define !! !! ======================================================= !! example of control section !! !! begin num_grid_sph !!! ---------------------------------------------------------------- !!! sph_coef_type_ctl: grid type for spherical harmonics data !!! no_pole: Coefficients on spherical shell only !!! with_center: Add center !!! sph_grid_type_ctl: grid type for mesh data !!! no_pole: Gaussian points only !!! with_pole: Add pole grids !!! with_center: Add center !!! ---------------------------------------------------------------- !! !! sph_coef_type_ctl no_pole !! sph_grid_type_ctl no_pole !! truncation_level_ctl 4 !! longitude_symmetry_ctl 2 !! ngrid_meridonal_ctl 12 !! ngrid_zonal_ctl 24 !! !! radial_grid_type_ctl: Definition for radial grid !! explicit: Set each radial grid explicitly !! Chebyshev: Set Chebyshev collocation points !! equi_distance: Set equi-diatance grid !! !! radial_grid_type_ctl explicit !! array r_layer 4 !! r_layer 1 0.3584615384615 !! r_layer 2 0.5384615384615 ICB !! r_layer 3 1.038461538462 Mid !! r_layer 4 1.538461538462 CMB !! end array r_layer !! !! radial_grid_type_ctl Chebyshev !! num_fluid_grid_ctl 5 !! fluid_core_size_ctl 0.35 !! ICB_to_CMB_ratio_ctl 1.0 !! Min_radius_ctl 0.0 !! ICB_radius_ctl 0.5384615384615 !! CMB_radius_ctl 1.538461538462 !! Max_radius_ctl 2.0 !! !! array boundaries_ctl 3 !! boundaries_ctl to_Center 1 !! boundaries_ctl ICB 2 !! boundaries_ctl CMB 4 !! end array boundaries_ctl !! end num_grid_sph !! !! ======================================================= !!@endverbatim ! module m_ctl_data_4_sphere_model ! use m_precision use t_control_elements use t_read_control_arrays ! implicit none ! ! resolution of spherical harmonics ! !> Truncation lavel of spherical harmonics type(read_integer_item), save :: ltr_ctl !> longitudinal symmetry type(read_integer_item), save :: phi_symmetry_ctl ! !> Type of spherical grids type(read_character_item), save :: sph_grid_type_ctl !> Type of spherical coefficients type(read_character_item), save :: sph_coef_type_ctl ! !> Number of grids in meridional direction type(read_integer_item), save :: ngrid_elevation_ctl !> Number of grids in longitudinal direction type(read_integer_item), save :: ngrid_azimuth_ctl ! !> Structure for radial point data !!@n light_position_ctl%ivec: radial ID !!@n light_position_ctl%vect: Radius type(ctl_array_ir), save :: radius_ctl ! !> Structure for radial grouping data for boundaries !!@n light_position_ctl%c_tble: Group name !!@n light_position_ctl%ivec: radial ID type(ctl_array_ci), save :: radial_grp_ctl ! !> Grid spacing type type(read_character_item), save :: radial_grid_type_ctl !> Minimum radius of the simulation domain @f$ R_{c} @f$ type(read_integer_item), save :: num_fluid_grid_ctl !> ICB radius @f$ R_{i} @f$ type(read_real_item), save :: Min_radius_ctl !> ICB radius @f$ R_{i} @f$ type(read_real_item), save :: ICB_radius_ctl !> CMB radius @f$ R_{o} @f$ type(read_real_item), save :: CMB_radius_ctl !> Maximum radius of the simulation domain @f$ R_{m} @f$ type(read_real_item), save :: Max_radius_ctl !> Size of the fluid shell !! @f$ L = R_{o} - R_{i} @f$ type(read_real_item), save :: fluid_core_size_ctl !> Ratio of inner core radius to the outer core radius !! @f$ R_{i} / R_{o} @f$ type(read_real_item), save :: ICB_to_CMB_ratio_ctl ! ! ! labels of data field ! character(len=kchara), parameter & & :: hd_sph_def = 'shell_define_ctl' character(len=kchara), parameter :: hd_shell_def = 'num_grid_sph' integer(kind = kint) :: i_shell_def = 0 ! ! labels of shell define ! character(len=kchara), parameter & & :: hd_numlayer_shell = 'r_layer' ! character(len=kchara), parameter & & :: hd_ntheta_shell = 'ngrid_meridonal_ctl' character(len=kchara), parameter & & :: hd_nphi_shell = 'ngrid_zonal_ctl' character(len=kchara), parameter & & :: hd_sph_truncate = 'truncation_level_ctl' character(len=kchara), parameter & & :: hd_phi_symmetry = 'longitude_symmetry_ctl' character(len=kchara), parameter & & :: hd_sph_c_type = 'sph_coef_type_ctl' character(len=kchara), parameter & & :: hd_sph_g_type = 'sph_grid_type_ctl' ! character(len=kchara), parameter & & :: hd_r_grid_type = 'radial_grid_type_ctl' character(len=kchara), parameter & & :: hd_n_fluid_grid = 'num_fluid_grid_ctl' character(len=kchara), parameter & & :: hd_Min_radius = 'Min_radius_ctl' character(len=kchara), parameter & & :: hd_ICB_radius = 'ICB_radius_ctl' character(len=kchara), parameter & & :: hd_CMB_radius = 'CMB_radius_ctl' character(len=kchara), parameter & & :: hd_Max_radius = 'Max_radius_ctl' character(len=kchara), parameter & & :: hd_shell_size = 'fluid_core_size_ctl' character(len=kchara), parameter & & :: hd_shell_ratio = 'ICB_to_CMB_ratio_ctl' ! character(len=kchara), parameter & & :: hd_bc_sph = 'boundaries_ctl' ! ! 3rd level for boundary define ! private :: hd_sph_def, hd_shell_def, i_shell_def private :: hd_numlayer_shell, hd_sph_c_type, hd_phi_symmetry private :: hd_ntheta_shell, hd_nphi_shell, hd_sph_truncate private :: hd_r_grid_type, hd_n_fluid_grid, hd_Min_radius private :: hd_ICB_radius, hd_CMB_radius, hd_Max_radius private :: hd_shell_size, hd_shell_ratio, hd_bc_sph ! ! --------------------------------------------------------------------- ! contains ! ! --------------------------------------------------------------------- ! subroutine read_ctl_4_shell_define ! use m_machine_parameter use m_read_control_elements use skip_comment_f ! integer(kind = kint) :: iflag ! ! iflag = right_begin_flag(hd_shell_def) & & + right_begin_flag(hd_sph_def) if(iflag .eq. 0) return if(i_shell_def .gt. 0) return do call load_ctl_label_and_line ! call find_control_end_flag(hd_shell_def, i_shell_def) call find_control_end_flag(hd_sph_def, i_shell_def) if(i_shell_def .gt. 0) exit ! ! call read_control_array_i_r(hd_numlayer_shell, radius_ctl) ! call read_control_array_c_i(hd_bc_sph, radial_grp_ctl) ! ! call read_chara_ctl_type(hd_sph_c_type, sph_coef_type_ctl) call read_chara_ctl_type(hd_sph_g_type, sph_grid_type_ctl) call read_chara_ctl_type(hd_r_grid_type, radial_grid_type_ctl) ! call read_integer_ctl_type(hd_phi_symmetry, phi_symmetry_ctl) call read_integer_ctl_type(hd_sph_truncate, ltr_ctl) call read_integer_ctl_type(hd_ntheta_shell, & & ngrid_elevation_ctl) call read_integer_ctl_type(hd_nphi_shell, ngrid_azimuth_ctl) ! call read_integer_ctl_type(hd_n_fluid_grid, num_fluid_grid_ctl) ! ! call read_real_ctl_type(hd_Min_radius, Min_radius_ctl) call read_real_ctl_type(hd_ICB_radius, ICB_radius_ctl) call read_real_ctl_type(hd_CMB_radius, CMB_radius_ctl) call read_real_ctl_type(hd_Max_radius, Max_radius_ctl) ! call read_real_ctl_type(hd_shell_size, fluid_core_size_ctl) call read_real_ctl_type(hd_shell_ratio, ICB_to_CMB_ratio_ctl) end do ! end subroutine read_ctl_4_shell_define ! ! -------------------------------------------------------------------- ! end module m_ctl_data_4_sphere_model
gpl-3.0