repo_name
stringlengths 7
81
| path
stringlengths 4
224
| copies
stringclasses 221
values | size
stringlengths 4
7
| content
stringlengths 975
1.04M
| license
stringclasses 15
values |
---|---|---|---|---|---|
apollos/Quantum-ESPRESSO | lapack-3.2/TESTING/EIG/dchkbd.f | 1 | 34284 | SUBROUTINE DCHKBD( NSIZES, MVAL, NVAL, NTYPES, DOTYPE, NRHS,
$ ISEED, THRESH, A, LDA, BD, BE, S1, S2, X, LDX,
$ Y, Z, Q, LDQ, PT, LDPT, U, VT, WORK, LWORK,
$ IWORK, NOUT, INFO )
*
* -- LAPACK test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
INTEGER INFO, LDA, LDPT, LDQ, LDX, LWORK, NOUT, NRHS,
$ NSIZES, NTYPES
DOUBLE PRECISION THRESH
* ..
* .. Array Arguments ..
LOGICAL DOTYPE( * )
INTEGER ISEED( 4 ), IWORK( * ), MVAL( * ), NVAL( * )
DOUBLE PRECISION A( LDA, * ), BD( * ), BE( * ), PT( LDPT, * ),
$ Q( LDQ, * ), S1( * ), S2( * ), U( LDPT, * ),
$ VT( LDPT, * ), WORK( * ), X( LDX, * ),
$ Y( LDX, * ), Z( LDX, * )
* ..
*
* Purpose
* =======
*
* DCHKBD checks the singular value decomposition (SVD) routines.
*
* DGEBRD reduces a real general m by n matrix A to upper or lower
* bidiagonal form B by an orthogonal transformation: Q' * A * P = B
* (or A = Q * B * P'). The matrix B is upper bidiagonal if m >= n
* and lower bidiagonal if m < n.
*
* DORGBR generates the orthogonal matrices Q and P' from DGEBRD.
* Note that Q and P are not necessarily square.
*
* DBDSQR computes the singular value decomposition of the bidiagonal
* matrix B as B = U S V'. It is called three times to compute
* 1) B = U S1 V', where S1 is the diagonal matrix of singular
* values and the columns of the matrices U and V are the left
* and right singular vectors, respectively, of B.
* 2) Same as 1), but the singular values are stored in S2 and the
* singular vectors are not computed.
* 3) A = (UQ) S (P'V'), the SVD of the original matrix A.
* In addition, DBDSQR has an option to apply the left orthogonal matrix
* U to a matrix X, useful in least squares applications.
*
* DBDSDC computes the singular value decomposition of the bidiagonal
* matrix B as B = U S V' using divide-and-conquer. It is called twice
* to compute
* 1) B = U S1 V', where S1 is the diagonal matrix of singular
* values and the columns of the matrices U and V are the left
* and right singular vectors, respectively, of B.
* 2) Same as 1), but the singular values are stored in S2 and the
* singular vectors are not computed.
*
* For each pair of matrix dimensions (M,N) and each selected matrix
* type, an M by N matrix A and an M by NRHS matrix X are generated.
* The problem dimensions are as follows
* A: M x N
* Q: M x min(M,N) (but M x M if NRHS > 0)
* P: min(M,N) x N
* B: min(M,N) x min(M,N)
* U, V: min(M,N) x min(M,N)
* S1, S2 diagonal, order min(M,N)
* X: M x NRHS
*
* For each generated matrix, 14 tests are performed:
*
* Test DGEBRD and DORGBR
*
* (1) | A - Q B PT | / ( |A| max(M,N) ulp ), PT = P'
*
* (2) | I - Q' Q | / ( M ulp )
*
* (3) | I - PT PT' | / ( N ulp )
*
* Test DBDSQR on bidiagonal matrix B
*
* (4) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V'
*
* (5) | Y - U Z | / ( |Y| max(min(M,N),k) ulp ), where Y = Q' X
* and Z = U' Y.
* (6) | I - U' U | / ( min(M,N) ulp )
*
* (7) | I - VT VT' | / ( min(M,N) ulp )
*
* (8) S1 contains min(M,N) nonnegative values in decreasing order.
* (Return 0 if true, 1/ULP if false.)
*
* (9) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without
* computing U and V.
*
* (10) 0 if the true singular values of B are within THRESH of
* those in S1. 2*THRESH if they are not. (Tested using
* DSVDCH)
*
* Test DBDSQR on matrix A
*
* (11) | A - (QU) S (VT PT) | / ( |A| max(M,N) ulp )
*
* (12) | X - (QU) Z | / ( |X| max(M,k) ulp )
*
* (13) | I - (QU)'(QU) | / ( M ulp )
*
* (14) | I - (VT PT) (PT'VT') | / ( N ulp )
*
* Test DBDSDC on bidiagonal matrix B
*
* (15) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V'
*
* (16) | I - U' U | / ( min(M,N) ulp )
*
* (17) | I - VT VT' | / ( min(M,N) ulp )
*
* (18) S1 contains min(M,N) nonnegative values in decreasing order.
* (Return 0 if true, 1/ULP if false.)
*
* (19) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without
* computing U and V.
* The possible matrix types are
*
* (1) The zero matrix.
* (2) The identity matrix.
*
* (3) A diagonal matrix with evenly spaced entries
* 1, ..., ULP and random signs.
* (ULP = (first number larger than 1) - 1 )
* (4) A diagonal matrix with geometrically spaced entries
* 1, ..., ULP and random signs.
* (5) A diagonal matrix with "clustered" entries 1, ULP, ..., ULP
* and random signs.
*
* (6) Same as (3), but multiplied by SQRT( overflow threshold )
* (7) Same as (3), but multiplied by SQRT( underflow threshold )
*
* (8) A matrix of the form U D V, where U and V are orthogonal and
* D has evenly spaced entries 1, ..., ULP with random signs
* on the diagonal.
*
* (9) A matrix of the form U D V, where U and V are orthogonal and
* D has geometrically spaced entries 1, ..., ULP with random
* signs on the diagonal.
*
* (10) A matrix of the form U D V, where U and V are orthogonal and
* D has "clustered" entries 1, ULP,..., ULP with random
* signs on the diagonal.
*
* (11) Same as (8), but multiplied by SQRT( overflow threshold )
* (12) Same as (8), but multiplied by SQRT( underflow threshold )
*
* (13) Rectangular matrix with random entries chosen from (-1,1).
* (14) Same as (13), but multiplied by SQRT( overflow threshold )
* (15) Same as (13), but multiplied by SQRT( underflow threshold )
*
* Special case:
* (16) A bidiagonal matrix with random entries chosen from a
* logarithmic distribution on [ulp^2,ulp^(-2)] (I.e., each
* entry is e^x, where x is chosen uniformly on
* [ 2 log(ulp), -2 log(ulp) ] .) For *this* type:
* (a) DGEBRD is not called to reduce it to bidiagonal form.
* (b) the bidiagonal is min(M,N) x min(M,N); if M<N, the
* matrix will be lower bidiagonal, otherwise upper.
* (c) only tests 5--8 and 14 are performed.
*
* A subset of the full set of matrix types may be selected through
* the logical array DOTYPE.
*
* Arguments
* ==========
*
* NSIZES (input) INTEGER
* The number of values of M and N contained in the vectors
* MVAL and NVAL. The matrix sizes are used in pairs (M,N).
*
* MVAL (input) INTEGER array, dimension (NM)
* The values of the matrix row dimension M.
*
* NVAL (input) INTEGER array, dimension (NM)
* The values of the matrix column dimension N.
*
* NTYPES (input) INTEGER
* The number of elements in DOTYPE. If it is zero, DCHKBD
* does nothing. It must be at least zero. If it is MAXTYP+1
* and NSIZES is 1, then an additional type, MAXTYP+1 is
* defined, which is to use whatever matrices are in A and B.
* This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and
* DOTYPE(MAXTYP+1) is .TRUE. .
*
* DOTYPE (input) LOGICAL array, dimension (NTYPES)
* If DOTYPE(j) is .TRUE., then for each size (m,n), a matrix
* of type j will be generated. If NTYPES is smaller than the
* maximum number of types defined (PARAMETER MAXTYP), then
* types NTYPES+1 through MAXTYP will not be generated. If
* NTYPES is larger than MAXTYP, DOTYPE(MAXTYP+1) through
* DOTYPE(NTYPES) will be ignored.
*
* NRHS (input) INTEGER
* The number of columns in the "right-hand side" matrices X, Y,
* and Z, used in testing DBDSQR. If NRHS = 0, then the
* operations on the right-hand side will not be tested.
* NRHS must be at least 0.
*
* ISEED (input/output) INTEGER array, dimension (4)
* On entry ISEED specifies the seed of the random number
* generator. The array elements should be between 0 and 4095;
* if not they will be reduced mod 4096. Also, ISEED(4) must
* be odd. The values of ISEED are changed on exit, and can be
* used in the next call to DCHKBD to continue the same random
* number sequence.
*
* THRESH (input) DOUBLE PRECISION
* The threshold value for the test ratios. A result is
* included in the output file if RESULT >= THRESH. To have
* every test ratio printed, use THRESH = 0. Note that the
* expected value of the test ratios is O(1), so THRESH should
* be a reasonably small multiple of 1, e.g., 10 or 100.
*
* A (workspace) DOUBLE PRECISION array, dimension (LDA,NMAX)
* where NMAX is the maximum value of N in NVAL.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,MMAX),
* where MMAX is the maximum value of M in MVAL.
*
* BD (workspace) DOUBLE PRECISION array, dimension
* (max(min(MVAL(j),NVAL(j))))
*
* BE (workspace) DOUBLE PRECISION array, dimension
* (max(min(MVAL(j),NVAL(j))))
*
* S1 (workspace) DOUBLE PRECISION array, dimension
* (max(min(MVAL(j),NVAL(j))))
*
* S2 (workspace) DOUBLE PRECISION array, dimension
* (max(min(MVAL(j),NVAL(j))))
*
* X (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)
*
* LDX (input) INTEGER
* The leading dimension of the arrays X, Y, and Z.
* LDX >= max(1,MMAX)
*
* Y (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)
*
* Z (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)
*
* Q (workspace) DOUBLE PRECISION array, dimension (LDQ,MMAX)
*
* LDQ (input) INTEGER
* The leading dimension of the array Q. LDQ >= max(1,MMAX).
*
* PT (workspace) DOUBLE PRECISION array, dimension (LDPT,NMAX)
*
* LDPT (input) INTEGER
* The leading dimension of the arrays PT, U, and V.
* LDPT >= max(1, max(min(MVAL(j),NVAL(j)))).
*
* U (workspace) DOUBLE PRECISION array, dimension
* (LDPT,max(min(MVAL(j),NVAL(j))))
*
* V (workspace) DOUBLE PRECISION array, dimension
* (LDPT,max(min(MVAL(j),NVAL(j))))
*
* WORK (workspace) DOUBLE PRECISION array, dimension (LWORK)
*
* LWORK (input) INTEGER
* The number of entries in WORK. This must be at least
* 3(M+N) and M(M + max(M,N,k) + 1) + N*min(M,N) for all
* pairs (M,N)=(MM(j),NN(j))
*
* IWORK (workspace) INTEGER array, dimension at least 8*min(M,N)
*
* NOUT (input) INTEGER
* The FORTRAN unit number for printing out error messages
* (e.g., if a routine returns IINFO not equal to 0.)
*
* INFO (output) INTEGER
* If 0, then everything ran OK.
* -1: NSIZES < 0
* -2: Some MM(j) < 0
* -3: Some NN(j) < 0
* -4: NTYPES < 0
* -6: NRHS < 0
* -8: THRESH < 0
* -11: LDA < 1 or LDA < MMAX, where MMAX is max( MM(j) ).
* -17: LDB < 1 or LDB < MMAX.
* -21: LDQ < 1 or LDQ < MMAX.
* -23: LDPT< 1 or LDPT< MNMAX.
* -27: LWORK too small.
* If DLATMR, SLATMS, DGEBRD, DORGBR, or DBDSQR,
* returns an error code, the
* absolute value of it is returned.
*
*-----------------------------------------------------------------------
*
* Some Local Variables and Parameters:
* ---- ----- --------- --- ----------
*
* ZERO, ONE Real 0 and 1.
* MAXTYP The number of types defined.
* NTEST The number of tests performed, or which can
* be performed so far, for the current matrix.
* MMAX Largest value in NN.
* NMAX Largest value in NN.
* MNMIN min(MM(j), NN(j)) (the dimension of the bidiagonal
* matrix.)
* MNMAX The maximum value of MNMIN for j=1,...,NSIZES.
* NFAIL The number of tests which have exceeded THRESH
* COND, IMODE Values to be passed to the matrix generators.
* ANORM Norm of A; passed to matrix generators.
*
* OVFL, UNFL Overflow and underflow thresholds.
* RTOVFL, RTUNFL Square roots of the previous 2 values.
* ULP, ULPINV Finest relative precision and its inverse.
*
* The following four arrays decode JTYPE:
* KTYPE(j) The general type (1-10) for type "j".
* KMODE(j) The MODE value to be passed to the matrix
* generator for type "j".
* KMAGN(j) The order of magnitude ( O(1),
* O(overflow^(1/2) ), O(underflow^(1/2) )
*
* ======================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE, TWO, HALF
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
$ HALF = 0.5D0 )
INTEGER MAXTYP
PARAMETER ( MAXTYP = 16 )
* ..
* .. Local Scalars ..
LOGICAL BADMM, BADNN, BIDIAG
CHARACTER UPLO
CHARACTER*3 PATH
INTEGER I, IINFO, IMODE, ITYPE, J, JCOL, JSIZE, JTYPE,
$ LOG2UI, M, MINWRK, MMAX, MNMAX, MNMIN, MQ,
$ MTYPES, N, NFAIL, NMAX, NTEST
DOUBLE PRECISION AMNINV, ANORM, COND, OVFL, RTOVFL, RTUNFL,
$ TEMP1, TEMP2, ULP, ULPINV, UNFL
* ..
* .. Local Arrays ..
INTEGER IDUM( 1 ), IOLDSD( 4 ), KMAGN( MAXTYP ),
$ KMODE( MAXTYP ), KTYPE( MAXTYP )
DOUBLE PRECISION DUM( 1 ), DUMMA( 1 ), RESULT( 19 )
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH, DLARND
EXTERNAL DLAMCH, DLARND
* ..
* .. External Subroutines ..
EXTERNAL ALASUM, DBDSDC, DBDSQR, DBDT01, DBDT02, DBDT03,
$ DCOPY, DGEBRD, DGEMM, DLABAD, DLACPY, DLAHD2,
$ DLASET, DLATMR, DLATMS, DORGBR, DORT01, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, EXP, INT, LOG, MAX, MIN, SQRT
* ..
* .. Scalars in Common ..
LOGICAL LERR, OK
CHARACTER*32 SRNAMT
INTEGER INFOT, NUNIT
* ..
* .. Common blocks ..
COMMON / INFOC / INFOT, NUNIT, OK, LERR
COMMON / SRNAMC / SRNAMT
* ..
* .. Data statements ..
DATA KTYPE / 1, 2, 5*4, 5*6, 3*9, 10 /
DATA KMAGN / 2*1, 3*1, 2, 3, 3*1, 2, 3, 1, 2, 3, 0 /
DATA KMODE / 2*0, 4, 3, 1, 4, 4, 4, 3, 1, 4, 4, 0,
$ 0, 0, 0 /
* ..
* .. Executable Statements ..
*
* Check for errors
*
INFO = 0
*
BADMM = .FALSE.
BADNN = .FALSE.
MMAX = 1
NMAX = 1
MNMAX = 1
MINWRK = 1
DO 10 J = 1, NSIZES
MMAX = MAX( MMAX, MVAL( J ) )
IF( MVAL( J ).LT.0 )
$ BADMM = .TRUE.
NMAX = MAX( NMAX, NVAL( J ) )
IF( NVAL( J ).LT.0 )
$ BADNN = .TRUE.
MNMAX = MAX( MNMAX, MIN( MVAL( J ), NVAL( J ) ) )
MINWRK = MAX( MINWRK, 3*( MVAL( J )+NVAL( J ) ),
$ MVAL( J )*( MVAL( J )+MAX( MVAL( J ), NVAL( J ),
$ NRHS )+1 )+NVAL( J )*MIN( NVAL( J ), MVAL( J ) ) )
10 CONTINUE
*
* Check for errors
*
IF( NSIZES.LT.0 ) THEN
INFO = -1
ELSE IF( BADMM ) THEN
INFO = -2
ELSE IF( BADNN ) THEN
INFO = -3
ELSE IF( NTYPES.LT.0 ) THEN
INFO = -4
ELSE IF( NRHS.LT.0 ) THEN
INFO = -6
ELSE IF( LDA.LT.MMAX ) THEN
INFO = -11
ELSE IF( LDX.LT.MMAX ) THEN
INFO = -17
ELSE IF( LDQ.LT.MMAX ) THEN
INFO = -21
ELSE IF( LDPT.LT.MNMAX ) THEN
INFO = -23
ELSE IF( MINWRK.GT.LWORK ) THEN
INFO = -27
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DCHKBD', -INFO )
RETURN
END IF
*
* Initialize constants
*
PATH( 1: 1 ) = 'Double precision'
PATH( 2: 3 ) = 'BD'
NFAIL = 0
NTEST = 0
UNFL = DLAMCH( 'Safe minimum' )
OVFL = DLAMCH( 'Overflow' )
CALL DLABAD( UNFL, OVFL )
ULP = DLAMCH( 'Precision' )
ULPINV = ONE / ULP
LOG2UI = INT( LOG( ULPINV ) / LOG( TWO ) )
RTUNFL = SQRT( UNFL )
RTOVFL = SQRT( OVFL )
INFOT = 0
*
* Loop over sizes, types
*
DO 200 JSIZE = 1, NSIZES
M = MVAL( JSIZE )
N = NVAL( JSIZE )
MNMIN = MIN( M, N )
AMNINV = ONE / MAX( M, N, 1 )
*
IF( NSIZES.NE.1 ) THEN
MTYPES = MIN( MAXTYP, NTYPES )
ELSE
MTYPES = MIN( MAXTYP+1, NTYPES )
END IF
*
DO 190 JTYPE = 1, MTYPES
IF( .NOT.DOTYPE( JTYPE ) )
$ GO TO 190
*
DO 20 J = 1, 4
IOLDSD( J ) = ISEED( J )
20 CONTINUE
*
DO 30 J = 1, 14
RESULT( J ) = -ONE
30 CONTINUE
*
UPLO = ' '
*
* Compute "A"
*
* Control parameters:
*
* KMAGN KMODE KTYPE
* =1 O(1) clustered 1 zero
* =2 large clustered 2 identity
* =3 small exponential (none)
* =4 arithmetic diagonal, (w/ eigenvalues)
* =5 random symmetric, w/ eigenvalues
* =6 nonsymmetric, w/ singular values
* =7 random diagonal
* =8 random symmetric
* =9 random nonsymmetric
* =10 random bidiagonal (log. distrib.)
*
IF( MTYPES.GT.MAXTYP )
$ GO TO 100
*
ITYPE = KTYPE( JTYPE )
IMODE = KMODE( JTYPE )
*
* Compute norm
*
GO TO ( 40, 50, 60 )KMAGN( JTYPE )
*
40 CONTINUE
ANORM = ONE
GO TO 70
*
50 CONTINUE
ANORM = ( RTOVFL*ULP )*AMNINV
GO TO 70
*
60 CONTINUE
ANORM = RTUNFL*MAX( M, N )*ULPINV
GO TO 70
*
70 CONTINUE
*
CALL DLASET( 'Full', LDA, N, ZERO, ZERO, A, LDA )
IINFO = 0
COND = ULPINV
*
BIDIAG = .FALSE.
IF( ITYPE.EQ.1 ) THEN
*
* Zero matrix
*
IINFO = 0
*
ELSE IF( ITYPE.EQ.2 ) THEN
*
* Identity
*
DO 80 JCOL = 1, MNMIN
A( JCOL, JCOL ) = ANORM
80 CONTINUE
*
ELSE IF( ITYPE.EQ.4 ) THEN
*
* Diagonal Matrix, [Eigen]values Specified
*
CALL DLATMS( MNMIN, MNMIN, 'S', ISEED, 'N', WORK, IMODE,
$ COND, ANORM, 0, 0, 'N', A, LDA,
$ WORK( MNMIN+1 ), IINFO )
*
ELSE IF( ITYPE.EQ.5 ) THEN
*
* Symmetric, eigenvalues specified
*
CALL DLATMS( MNMIN, MNMIN, 'S', ISEED, 'S', WORK, IMODE,
$ COND, ANORM, M, N, 'N', A, LDA,
$ WORK( MNMIN+1 ), IINFO )
*
ELSE IF( ITYPE.EQ.6 ) THEN
*
* Nonsymmetric, singular values specified
*
CALL DLATMS( M, N, 'S', ISEED, 'N', WORK, IMODE, COND,
$ ANORM, M, N, 'N', A, LDA, WORK( MNMIN+1 ),
$ IINFO )
*
ELSE IF( ITYPE.EQ.7 ) THEN
*
* Diagonal, random entries
*
CALL DLATMR( MNMIN, MNMIN, 'S', ISEED, 'N', WORK, 6, ONE,
$ ONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE,
$ WORK( 2*MNMIN+1 ), 1, ONE, 'N', IWORK, 0, 0,
$ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )
*
ELSE IF( ITYPE.EQ.8 ) THEN
*
* Symmetric, random entries
*
CALL DLATMR( MNMIN, MNMIN, 'S', ISEED, 'S', WORK, 6, ONE,
$ ONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE,
$ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N,
$ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )
*
ELSE IF( ITYPE.EQ.9 ) THEN
*
* Nonsymmetric, random entries
*
CALL DLATMR( M, N, 'S', ISEED, 'N', WORK, 6, ONE, ONE,
$ 'T', 'N', WORK( MNMIN+1 ), 1, ONE,
$ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N,
$ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )
*
ELSE IF( ITYPE.EQ.10 ) THEN
*
* Bidiagonal, random entries
*
TEMP1 = -TWO*LOG( ULP )
DO 90 J = 1, MNMIN
BD( J ) = EXP( TEMP1*DLARND( 2, ISEED ) )
IF( J.LT.MNMIN )
$ BE( J ) = EXP( TEMP1*DLARND( 2, ISEED ) )
90 CONTINUE
*
IINFO = 0
BIDIAG = .TRUE.
IF( M.GE.N ) THEN
UPLO = 'U'
ELSE
UPLO = 'L'
END IF
ELSE
IINFO = 1
END IF
*
IF( IINFO.EQ.0 ) THEN
*
* Generate Right-Hand Side
*
IF( BIDIAG ) THEN
CALL DLATMR( MNMIN, NRHS, 'S', ISEED, 'N', WORK, 6,
$ ONE, ONE, 'T', 'N', WORK( MNMIN+1 ), 1,
$ ONE, WORK( 2*MNMIN+1 ), 1, ONE, 'N',
$ IWORK, MNMIN, NRHS, ZERO, ONE, 'NO', Y,
$ LDX, IWORK, IINFO )
ELSE
CALL DLATMR( M, NRHS, 'S', ISEED, 'N', WORK, 6, ONE,
$ ONE, 'T', 'N', WORK( M+1 ), 1, ONE,
$ WORK( 2*M+1 ), 1, ONE, 'N', IWORK, M,
$ NRHS, ZERO, ONE, 'NO', X, LDX, IWORK,
$ IINFO )
END IF
END IF
*
* Error Exit
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'Generator', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
RETURN
END IF
*
100 CONTINUE
*
* Call DGEBRD and DORGBR to compute B, Q, and P, do tests.
*
IF( .NOT.BIDIAG ) THEN
*
* Compute transformations to reduce A to bidiagonal form:
* B := Q' * A * P.
*
CALL DLACPY( ' ', M, N, A, LDA, Q, LDQ )
CALL DGEBRD( M, N, Q, LDQ, BD, BE, WORK, WORK( MNMIN+1 ),
$ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )
*
* Check error code from DGEBRD.
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'DGEBRD', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
RETURN
END IF
*
CALL DLACPY( ' ', M, N, Q, LDQ, PT, LDPT )
IF( M.GE.N ) THEN
UPLO = 'U'
ELSE
UPLO = 'L'
END IF
*
* Generate Q
*
MQ = M
IF( NRHS.LE.0 )
$ MQ = MNMIN
CALL DORGBR( 'Q', M, MQ, N, Q, LDQ, WORK,
$ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )
*
* Check error code from DORGBR.
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'DORGBR(Q)', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
RETURN
END IF
*
* Generate P'
*
CALL DORGBR( 'P', MNMIN, N, M, PT, LDPT, WORK( MNMIN+1 ),
$ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )
*
* Check error code from DORGBR.
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'DORGBR(P)', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
RETURN
END IF
*
* Apply Q' to an M by NRHS matrix X: Y := Q' * X.
*
CALL DGEMM( 'Transpose', 'No transpose', M, NRHS, M, ONE,
$ Q, LDQ, X, LDX, ZERO, Y, LDX )
*
* Test 1: Check the decomposition A := Q * B * PT
* 2: Check the orthogonality of Q
* 3: Check the orthogonality of PT
*
CALL DBDT01( M, N, 1, A, LDA, Q, LDQ, BD, BE, PT, LDPT,
$ WORK, RESULT( 1 ) )
CALL DORT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK,
$ RESULT( 2 ) )
CALL DORT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK,
$ RESULT( 3 ) )
END IF
*
* Use DBDSQR to form the SVD of the bidiagonal matrix B:
* B := U * S1 * VT, and compute Z = U' * Y.
*
CALL DCOPY( MNMIN, BD, 1, S1, 1 )
IF( MNMIN.GT.0 )
$ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )
CALL DLACPY( ' ', M, NRHS, Y, LDX, Z, LDX )
CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, U, LDPT )
CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, VT, LDPT )
*
CALL DBDSQR( UPLO, MNMIN, MNMIN, MNMIN, NRHS, S1, WORK, VT,
$ LDPT, U, LDPT, Z, LDX, WORK( MNMIN+1 ), IINFO )
*
* Check error code from DBDSQR.
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'DBDSQR(vects)', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
IF( IINFO.LT.0 ) THEN
RETURN
ELSE
RESULT( 4 ) = ULPINV
GO TO 170
END IF
END IF
*
* Use DBDSQR to compute only the singular values of the
* bidiagonal matrix B; U, VT, and Z should not be modified.
*
CALL DCOPY( MNMIN, BD, 1, S2, 1 )
IF( MNMIN.GT.0 )
$ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )
*
CALL DBDSQR( UPLO, MNMIN, 0, 0, 0, S2, WORK, VT, LDPT, U,
$ LDPT, Z, LDX, WORK( MNMIN+1 ), IINFO )
*
* Check error code from DBDSQR.
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'DBDSQR(values)', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
IF( IINFO.LT.0 ) THEN
RETURN
ELSE
RESULT( 9 ) = ULPINV
GO TO 170
END IF
END IF
*
* Test 4: Check the decomposition B := U * S1 * VT
* 5: Check the computation Z := U' * Y
* 6: Check the orthogonality of U
* 7: Check the orthogonality of VT
*
CALL DBDT03( UPLO, MNMIN, 1, BD, BE, U, LDPT, S1, VT, LDPT,
$ WORK, RESULT( 4 ) )
CALL DBDT02( MNMIN, NRHS, Y, LDX, Z, LDX, U, LDPT, WORK,
$ RESULT( 5 ) )
CALL DORT01( 'Columns', MNMIN, MNMIN, U, LDPT, WORK, LWORK,
$ RESULT( 6 ) )
CALL DORT01( 'Rows', MNMIN, MNMIN, VT, LDPT, WORK, LWORK,
$ RESULT( 7 ) )
*
* Test 8: Check that the singular values are sorted in
* non-increasing order and are non-negative
*
RESULT( 8 ) = ZERO
DO 110 I = 1, MNMIN - 1
IF( S1( I ).LT.S1( I+1 ) )
$ RESULT( 8 ) = ULPINV
IF( S1( I ).LT.ZERO )
$ RESULT( 8 ) = ULPINV
110 CONTINUE
IF( MNMIN.GE.1 ) THEN
IF( S1( MNMIN ).LT.ZERO )
$ RESULT( 8 ) = ULPINV
END IF
*
* Test 9: Compare DBDSQR with and without singular vectors
*
TEMP2 = ZERO
*
DO 120 J = 1, MNMIN
TEMP1 = ABS( S1( J )-S2( J ) ) /
$ MAX( SQRT( UNFL )*MAX( S1( 1 ), ONE ),
$ ULP*MAX( ABS( S1( J ) ), ABS( S2( J ) ) ) )
TEMP2 = MAX( TEMP1, TEMP2 )
120 CONTINUE
*
RESULT( 9 ) = TEMP2
*
* Test 10: Sturm sequence test of singular values
* Go up by factors of two until it succeeds
*
TEMP1 = THRESH*( HALF-ULP )
*
DO 130 J = 0, LOG2UI
* CALL DSVDCH( MNMIN, BD, BE, S1, TEMP1, IINFO )
IF( IINFO.EQ.0 )
$ GO TO 140
TEMP1 = TEMP1*TWO
130 CONTINUE
*
140 CONTINUE
RESULT( 10 ) = TEMP1
*
* Use DBDSQR to form the decomposition A := (QU) S (VT PT)
* from the bidiagonal form A := Q B PT.
*
IF( .NOT.BIDIAG ) THEN
CALL DCOPY( MNMIN, BD, 1, S2, 1 )
IF( MNMIN.GT.0 )
$ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )
*
CALL DBDSQR( UPLO, MNMIN, N, M, NRHS, S2, WORK, PT, LDPT,
$ Q, LDQ, Y, LDX, WORK( MNMIN+1 ), IINFO )
*
* Test 11: Check the decomposition A := Q*U * S2 * VT*PT
* 12: Check the computation Z := U' * Q' * X
* 13: Check the orthogonality of Q*U
* 14: Check the orthogonality of VT*PT
*
CALL DBDT01( M, N, 0, A, LDA, Q, LDQ, S2, DUMMA, PT,
$ LDPT, WORK, RESULT( 11 ) )
CALL DBDT02( M, NRHS, X, LDX, Y, LDX, Q, LDQ, WORK,
$ RESULT( 12 ) )
CALL DORT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK,
$ RESULT( 13 ) )
CALL DORT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK,
$ RESULT( 14 ) )
END IF
*
* Use DBDSDC to form the SVD of the bidiagonal matrix B:
* B := U * S1 * VT
*
CALL DCOPY( MNMIN, BD, 1, S1, 1 )
IF( MNMIN.GT.0 )
$ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )
CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, U, LDPT )
CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, VT, LDPT )
*
CALL DBDSDC( UPLO, 'I', MNMIN, S1, WORK, U, LDPT, VT, LDPT,
$ DUM, IDUM, WORK( MNMIN+1 ), IWORK, IINFO )
*
* Check error code from DBDSDC.
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'DBDSDC(vects)', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
IF( IINFO.LT.0 ) THEN
RETURN
ELSE
RESULT( 15 ) = ULPINV
GO TO 170
END IF
END IF
*
* Use DBDSDC to compute only the singular values of the
* bidiagonal matrix B; U and VT should not be modified.
*
CALL DCOPY( MNMIN, BD, 1, S2, 1 )
IF( MNMIN.GT.0 )
$ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )
*
CALL DBDSDC( UPLO, 'N', MNMIN, S2, WORK, DUM, 1, DUM, 1,
$ DUM, IDUM, WORK( MNMIN+1 ), IWORK, IINFO )
*
* Check error code from DBDSDC.
*
IF( IINFO.NE.0 ) THEN
WRITE( NOUT, FMT = 9998 )'DBDSDC(values)', IINFO, M, N,
$ JTYPE, IOLDSD
INFO = ABS( IINFO )
IF( IINFO.LT.0 ) THEN
RETURN
ELSE
RESULT( 18 ) = ULPINV
GO TO 170
END IF
END IF
*
* Test 15: Check the decomposition B := U * S1 * VT
* 16: Check the orthogonality of U
* 17: Check the orthogonality of VT
*
CALL DBDT03( UPLO, MNMIN, 1, BD, BE, U, LDPT, S1, VT, LDPT,
$ WORK, RESULT( 15 ) )
CALL DORT01( 'Columns', MNMIN, MNMIN, U, LDPT, WORK, LWORK,
$ RESULT( 16 ) )
CALL DORT01( 'Rows', MNMIN, MNMIN, VT, LDPT, WORK, LWORK,
$ RESULT( 17 ) )
*
* Test 18: Check that the singular values are sorted in
* non-increasing order and are non-negative
*
RESULT( 18 ) = ZERO
DO 150 I = 1, MNMIN - 1
IF( S1( I ).LT.S1( I+1 ) )
$ RESULT( 18 ) = ULPINV
IF( S1( I ).LT.ZERO )
$ RESULT( 18 ) = ULPINV
150 CONTINUE
IF( MNMIN.GE.1 ) THEN
IF( S1( MNMIN ).LT.ZERO )
$ RESULT( 18 ) = ULPINV
END IF
*
* Test 19: Compare DBDSQR with and without singular vectors
*
TEMP2 = ZERO
*
DO 160 J = 1, MNMIN
TEMP1 = ABS( S1( J )-S2( J ) ) /
$ MAX( SQRT( UNFL )*MAX( S1( 1 ), ONE ),
$ ULP*MAX( ABS( S1( 1 ) ), ABS( S2( 1 ) ) ) )
TEMP2 = MAX( TEMP1, TEMP2 )
160 CONTINUE
*
RESULT( 19 ) = TEMP2
*
* End of Loop -- Check for RESULT(j) > THRESH
*
170 CONTINUE
DO 180 J = 1, 19
IF( RESULT( J ).GE.THRESH ) THEN
IF( NFAIL.EQ.0 )
$ CALL DLAHD2( NOUT, PATH )
WRITE( NOUT, FMT = 9999 )M, N, JTYPE, IOLDSD, J,
$ RESULT( J )
NFAIL = NFAIL + 1
END IF
180 CONTINUE
IF( .NOT.BIDIAG ) THEN
NTEST = NTEST + 19
ELSE
NTEST = NTEST + 5
END IF
*
190 CONTINUE
200 CONTINUE
*
* Summary
*
CALL ALASUM( PATH, NOUT, NFAIL, NTEST, 0 )
*
RETURN
*
* End of DCHKBD
*
9999 FORMAT( ' M=', I5, ', N=', I5, ', type ', I2, ', seed=',
$ 4( I4, ',' ), ' test(', I2, ')=', G11.4 )
9998 FORMAT( ' DCHKBD: ', A, ' returned INFO=', I6, '.', / 9X, 'M=',
$ I6, ', N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ),
$ I5, ')' )
*
END
| gpl-2.0 |
xianyi/OpenBLAS | lapack-netlib/TESTING/EIG/zsbmv.f | 1 | 10675 | *> \brief \b ZSBMV
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* SUBROUTINE ZSBMV( UPLO, N, K, ALPHA, A, LDA, X, INCX, BETA, Y,
* INCY )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INCX, INCY, K, LDA, N
* COMPLEX*16 ALPHA, BETA
* ..
* .. Array Arguments ..
* COMPLEX*16 A( LDA, * ), X( * ), Y( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZSBMV performs the matrix-vector operation
*>
*> y := alpha*A*x + beta*y,
*>
*> where alpha and beta are scalars, x and y are n element vectors and
*> A is an n by n symmetric band matrix, with k super-diagonals.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \verbatim
*> UPLO - CHARACTER*1
*> On entry, UPLO specifies whether the upper or lower
*> triangular part of the band matrix A is being supplied as
*> follows:
*>
*> UPLO = 'U' or 'u' The upper triangular part of A is
*> being supplied.
*>
*> UPLO = 'L' or 'l' The lower triangular part of A is
*> being supplied.
*>
*> Unchanged on exit.
*>
*> N - INTEGER
*> On entry, N specifies the order of the matrix A.
*> N must be at least zero.
*> Unchanged on exit.
*>
*> K - INTEGER
*> On entry, K specifies the number of super-diagonals of the
*> matrix A. K must satisfy 0 .le. K.
*> Unchanged on exit.
*>
*> ALPHA - COMPLEX*16
*> On entry, ALPHA specifies the scalar alpha.
*> Unchanged on exit.
*>
*> A - COMPLEX*16 array, dimension( LDA, N )
*> Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )
*> by n part of the array A must contain the upper triangular
*> band part of the symmetric matrix, supplied column by
*> column, with the leading diagonal of the matrix in row
*> ( k + 1 ) of the array, the first super-diagonal starting at
*> position 2 in row k, and so on. The top left k by k triangle
*> of the array A is not referenced.
*> The following program segment will transfer the upper
*> triangular part of a symmetric band matrix from conventional
*> full matrix storage to band storage:
*>
*> DO 20, J = 1, N
*> M = K + 1 - J
*> DO 10, I = MAX( 1, J - K ), J
*> A( M + I, J ) = matrix( I, J )
*> 10 CONTINUE
*> 20 CONTINUE
*>
*> Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )
*> by n part of the array A must contain the lower triangular
*> band part of the symmetric matrix, supplied column by
*> column, with the leading diagonal of the matrix in row 1 of
*> the array, the first sub-diagonal starting at position 1 in
*> row 2, and so on. The bottom right k by k triangle of the
*> array A is not referenced.
*> The following program segment will transfer the lower
*> triangular part of a symmetric band matrix from conventional
*> full matrix storage to band storage:
*>
*> DO 20, J = 1, N
*> M = 1 - J
*> DO 10, I = J, MIN( N, J + K )
*> A( M + I, J ) = matrix( I, J )
*> 10 CONTINUE
*> 20 CONTINUE
*>
*> Unchanged on exit.
*>
*> LDA - INTEGER
*> On entry, LDA specifies the first dimension of A as declared
*> in the calling (sub) program. LDA must be at least
*> ( k + 1 ).
*> Unchanged on exit.
*>
*> X - COMPLEX*16 array, dimension at least
*> ( 1 + ( N - 1 )*abs( INCX ) ).
*> Before entry, the incremented array X must contain the
*> vector x.
*> Unchanged on exit.
*>
*> INCX - INTEGER
*> On entry, INCX specifies the increment for the elements of
*> X. INCX must not be zero.
*> Unchanged on exit.
*>
*> BETA - COMPLEX*16
*> On entry, BETA specifies the scalar beta.
*> Unchanged on exit.
*>
*> Y - COMPLEX*16 array, dimension at least
*> ( 1 + ( N - 1 )*abs( INCY ) ).
*> Before entry, the incremented array Y must contain the
*> vector y. On exit, Y is overwritten by the updated vector y.
*>
*> INCY - INTEGER
*> On entry, INCY specifies the increment for the elements of
*> Y. INCY must not be zero.
*> Unchanged on exit.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup complex16_eig
*
* =====================================================================
SUBROUTINE ZSBMV( UPLO, N, K, ALPHA, A, LDA, X, INCX, BETA, Y,
$ INCY )
*
* -- LAPACK test routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INCX, INCY, K, LDA, N
COMPLEX*16 ALPHA, BETA
* ..
* .. Array Arguments ..
COMPLEX*16 A( LDA, * ), X( * ), Y( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
COMPLEX*16 ONE
PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
COMPLEX*16 ZERO
PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )
* ..
* .. Local Scalars ..
INTEGER I, INFO, IX, IY, J, JX, JY, KPLUS1, KX, KY, L
COMPLEX*16 TEMP1, TEMP2
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = 1
ELSE IF( N.LT.0 ) THEN
INFO = 2
ELSE IF( K.LT.0 ) THEN
INFO = 3
ELSE IF( LDA.LT.( K+1 ) ) THEN
INFO = 6
ELSE IF( INCX.EQ.0 ) THEN
INFO = 8
ELSE IF( INCY.EQ.0 ) THEN
INFO = 11
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZSBMV ', INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( ( N.EQ.0 ) .OR. ( ( ALPHA.EQ.ZERO ) .AND. ( BETA.EQ.ONE ) ) )
$ RETURN
*
* Set up the start points in X and Y.
*
IF( INCX.GT.0 ) THEN
KX = 1
ELSE
KX = 1 - ( N-1 )*INCX
END IF
IF( INCY.GT.0 ) THEN
KY = 1
ELSE
KY = 1 - ( N-1 )*INCY
END IF
*
* Start the operations. In this version the elements of the array A
* are accessed sequentially with one pass through A.
*
* First form y := beta*y.
*
IF( BETA.NE.ONE ) THEN
IF( INCY.EQ.1 ) THEN
IF( BETA.EQ.ZERO ) THEN
DO 10 I = 1, N
Y( I ) = ZERO
10 CONTINUE
ELSE
DO 20 I = 1, N
Y( I ) = BETA*Y( I )
20 CONTINUE
END IF
ELSE
IY = KY
IF( BETA.EQ.ZERO ) THEN
DO 30 I = 1, N
Y( IY ) = ZERO
IY = IY + INCY
30 CONTINUE
ELSE
DO 40 I = 1, N
Y( IY ) = BETA*Y( IY )
IY = IY + INCY
40 CONTINUE
END IF
END IF
END IF
IF( ALPHA.EQ.ZERO )
$ RETURN
IF( LSAME( UPLO, 'U' ) ) THEN
*
* Form y when upper triangle of A is stored.
*
KPLUS1 = K + 1
IF( ( INCX.EQ.1 ) .AND. ( INCY.EQ.1 ) ) THEN
DO 60 J = 1, N
TEMP1 = ALPHA*X( J )
TEMP2 = ZERO
L = KPLUS1 - J
DO 50 I = MAX( 1, J-K ), J - 1
Y( I ) = Y( I ) + TEMP1*A( L+I, J )
TEMP2 = TEMP2 + A( L+I, J )*X( I )
50 CONTINUE
Y( J ) = Y( J ) + TEMP1*A( KPLUS1, J ) + ALPHA*TEMP2
60 CONTINUE
ELSE
JX = KX
JY = KY
DO 80 J = 1, N
TEMP1 = ALPHA*X( JX )
TEMP2 = ZERO
IX = KX
IY = KY
L = KPLUS1 - J
DO 70 I = MAX( 1, J-K ), J - 1
Y( IY ) = Y( IY ) + TEMP1*A( L+I, J )
TEMP2 = TEMP2 + A( L+I, J )*X( IX )
IX = IX + INCX
IY = IY + INCY
70 CONTINUE
Y( JY ) = Y( JY ) + TEMP1*A( KPLUS1, J ) + ALPHA*TEMP2
JX = JX + INCX
JY = JY + INCY
IF( J.GT.K ) THEN
KX = KX + INCX
KY = KY + INCY
END IF
80 CONTINUE
END IF
ELSE
*
* Form y when lower triangle of A is stored.
*
IF( ( INCX.EQ.1 ) .AND. ( INCY.EQ.1 ) ) THEN
DO 100 J = 1, N
TEMP1 = ALPHA*X( J )
TEMP2 = ZERO
Y( J ) = Y( J ) + TEMP1*A( 1, J )
L = 1 - J
DO 90 I = J + 1, MIN( N, J+K )
Y( I ) = Y( I ) + TEMP1*A( L+I, J )
TEMP2 = TEMP2 + A( L+I, J )*X( I )
90 CONTINUE
Y( J ) = Y( J ) + ALPHA*TEMP2
100 CONTINUE
ELSE
JX = KX
JY = KY
DO 120 J = 1, N
TEMP1 = ALPHA*X( JX )
TEMP2 = ZERO
Y( JY ) = Y( JY ) + TEMP1*A( 1, J )
L = 1 - J
IX = JX
IY = JY
DO 110 I = J + 1, MIN( N, J+K )
IX = IX + INCX
IY = IY + INCY
Y( IY ) = Y( IY ) + TEMP1*A( L+I, J )
TEMP2 = TEMP2 + A( L+I, J )*X( IX )
110 CONTINUE
Y( JY ) = Y( JY ) + ALPHA*TEMP2
JX = JX + INCX
JY = JY + INCY
120 CONTINUE
END IF
END IF
*
RETURN
*
* End of ZSBMV
*
END
| bsd-3-clause |
xianyi/OpenBLAS | lapack-netlib/TESTING/LIN/zlatsy.f | 1 | 7131 | *> \brief \b ZLATSY
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* SUBROUTINE ZLATSY( UPLO, N, X, LDX, ISEED )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER LDX, N
* ..
* .. Array Arguments ..
* INTEGER ISEED( * )
* COMPLEX*16 X( LDX, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZLATSY generates a special test matrix for the complex symmetric
*> (indefinite) factorization. The pivot blocks of the generated matrix
*> will be in the following order:
*> 2x2 pivot block, non diagonalizable
*> 1x1 pivot block
*> 2x2 pivot block, diagonalizable
*> (cycle repeats)
*> A row interchange is required for each non-diagonalizable 2x2 block.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER
*> Specifies whether the generated matrix is to be upper or
*> lower triangular.
*> = 'U': Upper triangular
*> = 'L': Lower triangular
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The dimension of the matrix to be generated.
*> \endverbatim
*>
*> \param[out] X
*> \verbatim
*> X is COMPLEX*16 array, dimension (LDX,N)
*> The generated matrix, consisting of 3x3 and 2x2 diagonal
*> blocks which result in the pivot sequence given above.
*> The matrix outside of these diagonal blocks is zero.
*> \endverbatim
*>
*> \param[in] LDX
*> \verbatim
*> LDX is INTEGER
*> The leading dimension of the array X.
*> \endverbatim
*>
*> \param[in,out] ISEED
*> \verbatim
*> ISEED is INTEGER array, dimension (4)
*> On entry, the seed for the random number generator. The last
*> of the four integers must be odd. (modified on exit)
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup complex16_lin
*
* =====================================================================
SUBROUTINE ZLATSY( UPLO, N, X, LDX, ISEED )
*
* -- LAPACK test routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER LDX, N
* ..
* .. Array Arguments ..
INTEGER ISEED( * )
COMPLEX*16 X( LDX, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
COMPLEX*16 EYE
PARAMETER ( EYE = ( 0.0D0, 1.0D0 ) )
* ..
* .. Local Scalars ..
INTEGER I, J, N5
DOUBLE PRECISION ALPHA, ALPHA3, BETA
COMPLEX*16 A, B, C, R
* ..
* .. External Functions ..
COMPLEX*16 ZLARND
EXTERNAL ZLARND
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, SQRT
* ..
* .. Executable Statements ..
*
* Initialize constants
*
ALPHA = ( 1.D0+SQRT( 17.D0 ) ) / 8.D0
BETA = ALPHA - 1.D0 / 1000.D0
ALPHA3 = ALPHA*ALPHA*ALPHA
*
* UPLO = 'U': Upper triangular storage
*
IF( UPLO.EQ.'U' ) THEN
*
* Fill the upper triangle of the matrix with zeros.
*
DO 20 J = 1, N
DO 10 I = 1, J
X( I, J ) = 0.0D0
10 CONTINUE
20 CONTINUE
N5 = N / 5
N5 = N - 5*N5 + 1
*
DO 30 I = N, N5, -5
A = ALPHA3*ZLARND( 5, ISEED )
B = ZLARND( 5, ISEED ) / ALPHA
C = A - 2.D0*B*EYE
R = C / BETA
X( I, I ) = A
X( I-2, I ) = B
X( I-2, I-1 ) = R
X( I-2, I-2 ) = C
X( I-1, I-1 ) = ZLARND( 2, ISEED )
X( I-3, I-3 ) = ZLARND( 2, ISEED )
X( I-4, I-4 ) = ZLARND( 2, ISEED )
IF( ABS( X( I-3, I-3 ) ).GT.ABS( X( I-4, I-4 ) ) ) THEN
X( I-4, I-3 ) = 2.0D0*X( I-3, I-3 )
ELSE
X( I-4, I-3 ) = 2.0D0*X( I-4, I-4 )
END IF
30 CONTINUE
*
* Clean-up for N not a multiple of 5.
*
I = N5 - 1
IF( I.GT.2 ) THEN
A = ALPHA3*ZLARND( 5, ISEED )
B = ZLARND( 5, ISEED ) / ALPHA
C = A - 2.D0*B*EYE
R = C / BETA
X( I, I ) = A
X( I-2, I ) = B
X( I-2, I-1 ) = R
X( I-2, I-2 ) = C
X( I-1, I-1 ) = ZLARND( 2, ISEED )
I = I - 3
END IF
IF( I.GT.1 ) THEN
X( I, I ) = ZLARND( 2, ISEED )
X( I-1, I-1 ) = ZLARND( 2, ISEED )
IF( ABS( X( I, I ) ).GT.ABS( X( I-1, I-1 ) ) ) THEN
X( I-1, I ) = 2.0D0*X( I, I )
ELSE
X( I-1, I ) = 2.0D0*X( I-1, I-1 )
END IF
I = I - 2
ELSE IF( I.EQ.1 ) THEN
X( I, I ) = ZLARND( 2, ISEED )
I = I - 1
END IF
*
* UPLO = 'L': Lower triangular storage
*
ELSE
*
* Fill the lower triangle of the matrix with zeros.
*
DO 50 J = 1, N
DO 40 I = J, N
X( I, J ) = 0.0D0
40 CONTINUE
50 CONTINUE
N5 = N / 5
N5 = N5*5
*
DO 60 I = 1, N5, 5
A = ALPHA3*ZLARND( 5, ISEED )
B = ZLARND( 5, ISEED ) / ALPHA
C = A - 2.D0*B*EYE
R = C / BETA
X( I, I ) = A
X( I+2, I ) = B
X( I+2, I+1 ) = R
X( I+2, I+2 ) = C
X( I+1, I+1 ) = ZLARND( 2, ISEED )
X( I+3, I+3 ) = ZLARND( 2, ISEED )
X( I+4, I+4 ) = ZLARND( 2, ISEED )
IF( ABS( X( I+3, I+3 ) ).GT.ABS( X( I+4, I+4 ) ) ) THEN
X( I+4, I+3 ) = 2.0D0*X( I+3, I+3 )
ELSE
X( I+4, I+3 ) = 2.0D0*X( I+4, I+4 )
END IF
60 CONTINUE
*
* Clean-up for N not a multiple of 5.
*
I = N5 + 1
IF( I.LT.N-1 ) THEN
A = ALPHA3*ZLARND( 5, ISEED )
B = ZLARND( 5, ISEED ) / ALPHA
C = A - 2.D0*B*EYE
R = C / BETA
X( I, I ) = A
X( I+2, I ) = B
X( I+2, I+1 ) = R
X( I+2, I+2 ) = C
X( I+1, I+1 ) = ZLARND( 2, ISEED )
I = I + 3
END IF
IF( I.LT.N ) THEN
X( I, I ) = ZLARND( 2, ISEED )
X( I+1, I+1 ) = ZLARND( 2, ISEED )
IF( ABS( X( I, I ) ).GT.ABS( X( I+1, I+1 ) ) ) THEN
X( I+1, I ) = 2.0D0*X( I, I )
ELSE
X( I+1, I ) = 2.0D0*X( I+1, I+1 )
END IF
I = I + 2
ELSE IF( I.EQ.N ) THEN
X( I, I ) = ZLARND( 2, ISEED )
I = I + 1
END IF
END IF
*
RETURN
*
* End of ZLATSY
*
END
| bsd-3-clause |
apollos/Quantum-ESPRESSO | PHonon/PH/set_int12_nc.f90 | 5 | 2924 | !
! Copyright (C) 2007-2009 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!----------------------------------------------------------------------------
SUBROUTINE set_int12_nc(iflag)
!----------------------------------------------------------------------------
!
! This is a driver to call the routines that rotate and multiply
! by the Pauli matrices the integrals.
!
USE ions_base, ONLY : nat, ntyp => nsp, ityp
USE spin_orb, ONLY : lspinorb
USE uspp_param, only: upf
USE phus, ONLY : int1, int2, int1_nc, int2_so
IMPLICIT NONE
INTEGER :: iflag
INTEGER :: np, na
int1_nc=(0.d0,0.d0)
IF (lspinorb) int2_so=(0.d0,0.d0)
DO np = 1, ntyp
IF ( upf(np)%tvanp ) THEN
DO na = 1, nat
IF (ityp(na)==np) THEN
IF (upf(np)%has_so) THEN
CALL transform_int1_so(int1,na,iflag)
CALL transform_int2_so(int2,na,iflag)
ELSE
CALL transform_int1_nc(int1,na,iflag)
IF (lspinorb) CALL transform_int2_nc(int2,na,iflag)
END IF
END IF
END DO
END IF
END DO
END SUBROUTINE set_int12_nc
!----------------------------------------------------------------------------
SUBROUTINE set_int3_nc(npe)
!----------------------------------------------------------------------------
USE ions_base, ONLY : nat, ntyp => nsp, ityp
USE uspp_param, only: upf
USE phus, ONLY : int3, int3_nc
IMPLICIT NONE
INTEGER :: npe
INTEGER :: np, na
int3_nc=(0.d0,0.d0)
DO np = 1, ntyp
IF ( upf(np)%tvanp ) THEN
DO na = 1, nat
IF (ityp(na)==np) THEN
IF (upf(np)%has_so) THEN
CALL transform_int3_so(int3,na,npe)
ELSE
CALL transform_int3_nc(int3,na,npe)
END IF
END IF
END DO
END IF
END DO
END SUBROUTINE set_int3_nc
!
!----------------------------------------------------------------------------
SUBROUTINE set_dbecsum_nc(dbecsum_nc, dbecsum, npe)
!----------------------------------------------------------------------------
USE kinds, ONLY : DP
USE ions_base, ONLY : nat, ntyp => nsp, ityp
USE uspp_param, only: upf, nhm
USE noncollin_module, ONLY : nspin_mag
USE lsda_mod, ONLY : nspin
IMPLICIT NONE
INTEGER :: npe
INTEGER :: np, na
COMPLEX(DP), INTENT(IN) :: dbecsum_nc( nhm, nhm, nat, nspin, npe)
COMPLEX(DP), INTENT(OUT) :: dbecsum( nhm*(nhm+1)/2, nat, nspin_mag, npe)
DO np = 1, ntyp
IF ( upf(np)%tvanp ) THEN
DO na = 1, nat
IF (ityp(na)==np) THEN
IF (upf(np)%has_so) THEN
CALL transform_dbecsum_so(dbecsum_nc,dbecsum,na, npe)
ELSE
CALL transform_dbecsum_nc(dbecsum_nc,dbecsum,na, npe)
END IF
END IF
END DO
END IF
END DO
RETURN
END SUBROUTINE set_dbecsum_nc
| gpl-2.0 |
braghiere/JULESv4.6_clump | extract/jules/src/science/snow/snowpack.F90 | 4 | 23649 | ! *****************************COPYRIGHT*******************************
! (c) [University of Edinburgh] [2009]. All rights reserved.
! This routine has been licensed to the Met Office for use and
! distribution under the JULES collaboration agreement, subject
! to the terms and conditions set out therein.
! [Met Office Ref SC237]
! *****************************COPYRIGHT*******************************
! SUBROUTINE SNOWPACK-------------------------------------------------
! Description:
! Snow thermodynamics and hydrology
! Subroutine Interface:
MODULE snowpack_mod
CHARACTER(LEN=*), PARAMETER, PRIVATE :: ModuleName='SNOWPACK_MOD'
CONTAINS
SUBROUTINE snowpack ( land_pts,surft_pts,timestep,cansnowtile, &
nsnow,surft_index,csnow,ei_surft,hcaps,hcons, &
infiltration, &
ksnow,rho_snow_grnd,smcl1,snowfall,sthf1, &
surf_htf_surft,tile_frac,v_sat1,ds, &
melt_surft,sice,sliq,snomlt_sub_htf, &
snowdepth,snowmass,tsnow,tsoil1,tsurf_elev_surft, &
snow_soil_htf,rho_snow,rho0,sice0,tsnow0 )
USE tridag_mod, ONLY: tridag
USE c_0_dg_c, ONLY : &
! imported scalar parameters
tm ! Temperature at which fresh water freezes
! ! and ice melts (K)
USE c_densty, ONLY : &
! imported scalar parameters
rho_water ! density of pure water (kg/m3)
USE c_lheat , ONLY : &
! imported scalar parameters
lc &
! latent heat of condensation of water
! ! at 0degC (J kg-1)
,lf ! latent heat of fusion at 0degC (J kg-1)
USE water_constants_mod, ONLY : &
! imported scalar parameters
hcapi &
! Specific heat capacity of ice (J/kg/K)
,hcapw &
! Specific heat capacity of water (J/kg/K)
,rho_ice
! Specific density of solid ice (kg/m3)
USE ancil_info, ONLY : l_lice_point
USE jules_soil_mod, ONLY : dzsoil, dzsoil_elev
USE jules_surface_mod, ONLY : l_elev_land_ice
USE jules_snow_mod, ONLY : &
nsmax &
! Maximum possible number of snow layers
,l_snow_infilt &
! Include infiltration of rain into snow
,rho_snow_const &
! constant density of lying snow (kg per m**3)
,rho_snow_fresh &
! density of fresh snow (kg per m**3)
,snowliqcap &
! Liquid water holding capacity of lying snow
! as a fraction of snow mass.
,snow_hcon &
! Conductivity of snow
,rho_firn_pore_restrict &
! Density at which ability of snowpack to hold/percolate
! water starts to be restricted
,rho_firn_pore_closure
! Density at which snowpack pores close off entirely and
! no additional melt can be held/percolated through
USE parkind1, ONLY: jprb, jpim
USE yomhook, ONLY: lhook, dr_hook
IMPLICIT NONE
! Scalar parameters
REAL, PARAMETER :: GAMMA = 0.5
! Implicit timestep weighting
! Scalar arguments with intent(in)
INTEGER, INTENT(IN) :: &
land_pts &
! Total number of land points
,surft_pts ! Number of tile points
REAL, INTENT(IN) :: &
timestep ! Timestep (s)
LOGICAL, INTENT(IN) :: &
cansnowtile ! Switch for canopy snow model
! Array arguments with intent(in)
INTEGER, INTENT(IN) :: &
nsnow(land_pts) &
! Number of snow layers
,surft_index(land_pts)
! Index of tile points
REAL, INTENT(IN) :: &
csnow(land_pts,nsmax) &
! Areal heat capacity of layers (J/K/m2)
,ei_surft(land_pts) &
! Sublimation of snow (kg/m2/s)
,hcaps(land_pts) &
! Heat capacity of soil surface layer (J/K/m3)
,hcons(land_pts) &
! Thermal conductivity of top soil layer,
! ! including water and ice (W/m/K)
,ksnow(land_pts,nsmax) &
! Thermal conductivity of layers (W/m/K)
,rho_snow_grnd(land_pts) &
! Snowpack bulk density (kg/m3)
,smcl1(land_pts) &
! Moisture content of surface soil layer (kg/m2)
,snowfall(land_pts) &
! Snow reaching the ground (kg/m2)
,infiltration(land_pts) &
! Rainfall infiltrating into snowpack (kg/m2)
,sthf1(land_pts) &
! Frozen soil moisture content of surface layer
! ! as a fraction of saturation.
,surf_htf_surft(land_pts) &
! Snow surface heat flux (W/m2)
,tile_frac(land_pts) &
! Tile fractions
,v_sat1(land_pts)
! Surface soil layer volumetric
! ! moisture concentration at saturation
! Array arguments with intent(inout)
REAL, INTENT(INOUT) :: &
ds(land_pts,nsmax) &
! Snow layer depths (m)
,melt_surft(land_pts) &
! Surface snowmelt rate (kg/m2/s)
,sice(land_pts,nsmax) &
! Ice content of snow layers (kg/m2)
,sliq(land_pts,nsmax) &
! Liquid content of snow layers (kg/m2)
,snomlt_sub_htf(land_pts) &
! Sub-canopy snowmelt heat flux (W/m2)
,snowdepth(land_pts) &
! Snow depth (m)
,snowmass(land_pts) &
! Snow mass on the ground (kg/m2)
,tsnow(land_pts,nsmax) &
! Snow layer temperatures (K)
,tsoil1(land_pts) &
! Soil surface layer temperature(K)
,tsurf_elev_surft(land_pts)
! Temperature of elevated subsurface tiles (K)
! Array arguments with intent(out)
REAL, INTENT(OUT) :: &
snow_soil_htf(land_pts) &
! Heat flux into the uppermost subsurface layer
! ! (W/m2)
! ! i.e. snow to ground, or into snow/soil
! ! composite layer
,rho0(land_pts) &
! Density of fresh snow (kg/m3)
! ! Where NSNOW=0, rho0 is the density
! ! of the snowpack.
,sice0(land_pts) &
! Ice content of fresh snow (kg/m2)
! ! Where NSNOW=0, SICE0 is the mass of
! ! the snowpack.
,tsnow0(land_pts) &
! Temperature of fresh snow (K)
,rho_snow(land_pts,nsmax)
! Density of snow layers (kg/m3)
! Local scalars
INTEGER :: &
i &
! land point index
,k &
! Tile point index
,n ! Snow layer index
REAL :: &
asoil &
! 1 / (dz*hcap) for surface soil layer
,can_melt &
! Melt of snow on the canopy (kg/m2/s)
,coldsnow &
! layer cold content (J/m2)
,dsice &
! Change in layer ice content (kg/m2)
,g_snow_surf &
! Heat flux at the snow surface (W/m2)
,sliqmax &
! Maximum liquid content for layer (kg/m2)
,submelt &
! Melt of snow beneath canopy (kg/m2/s)
,smclf &
! Frozen soil moisture content of
! ! surface layer (kg/m2)
,win &
! Water entering layer (kg/m2)
,tsoilw &
,hconsw &
,dzsoilw
! working copies of tsoil, hcon and dzsoil for the loop
! Local arrays
REAL :: &
asnow(nsmax) &
! Effective thermal conductivity (W/m2/k)
,a(nsmax) &
! Below-diagonal matrix elements
,b(nsmax) &
! Diagonal matrix elements
,c(nsmax) &
! Above-diagonal matrix elements
,dt(nsmax) &
! Temperature increments (k)
,r(nsmax) ! Matrix equation rhs
REAL :: rho_temp
! Temporary array for layer density
INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
REAL(KIND=jprb) :: zhook_handle
CHARACTER(LEN=*), PARAMETER :: RoutineName='SNOWPACK'
!-----------------------------------------------------------------------
IF (lhook) CALL dr_hook(ModuleName//':'//RoutineName,zhook_in,zhook_handle)
!Required for bit comparison in the UM to ensure all tile points are set to
!zero regardless of fraction present
rho_snow(:,:) = 0.0
snow_soil_htf(:)=0.
DO k=1,surft_pts
i = surft_index(k)
IF (l_elev_land_ice .AND. l_lice_point(i)) THEN
tsoilw=tsurf_elev_surft(i)
hconsw=snow_hcon
dzsoilw=dzsoil_elev
ELSE
tsoilw=tsoil1(i)
hconsw=hcons(i)
dzsoilw=dzsoil(1)
END IF
g_snow_surf = surf_htf_surft(i)
!-----------------------------------------------------------------------
! Add melt to snow surface heat flux, unless using the snow canopy model
!-----------------------------------------------------------------------
IF ( .NOT. cansnowtile ) &
g_snow_surf = g_snow_surf + lf*melt_surft(i)
IF ( nsnow(i) == 0 ) THEN
! Add snowfall (including canopy unloading) to ground snowpack.
snowmass(i) = snowmass(i) + snowfall(i)
IF ( .NOT. cansnowtile ) THEN
!-----------------------------------------------------------------------
! Remove sublimation and melt from snowpack.
!-----------------------------------------------------------------------
snowmass(i) = snowmass(i) - &
( ei_surft(i) + melt_surft(i) ) * timestep
ELSE IF ( tsoilw > tm ) THEN
!-----------------------------------------------------------------------
! For canopy model, calculate melt of snow on ground underneath canopy.
!-----------------------------------------------------------------------
smclf = rho_water * dzsoilw * v_sat1(i) * sthf1(i)
asoil = 1./ ( dzsoilw * hcaps(i) + &
hcapw * (smcl1(i) - smclf) + hcapi*smclf )
submelt = MIN( snowmass(i) / timestep, &
(tsoilw - tm) / (lf * asoil * timestep) )
snowmass(i) = snowmass(i) - submelt * timestep
tsoilw = tsoilw - &
tile_frac(i) * asoil * timestep * lf * submelt
melt_surft(i) = melt_surft(i) + submelt
snomlt_sub_htf(i) = snomlt_sub_htf(i) + &
tile_frac(i) * lf * submelt
END IF
! Set flux into uppermost snow/soil layer (after melting).
snow_soil_htf(i) = surf_htf_surft(i)
! Diagnose snow depth.
snowdepth(i) = snowmass(i) / rho_snow_grnd(i)
! Set values for the surface layer. These are only needed for nsmax>0.
IF ( nsmax > 0 ) THEN
rho0(i) = rho_snow_grnd(i)
sice0(i) = snowmass(i)
tsnow0(i) = MIN( tsoilw, tm )
END IF
! Note with nsmax>0 the density of a shallow pack (nsnow=0) does not
! evolve with time (until it is exhausted). We could consider updating
! the density using a mass-weighted mean of the pack density and that
! of fresh snow, so that a growing pack would reach nsnow=1 more quickly.
! This would only affect a pack that grows from a non-zero state, and
! is not an issue if the pack grows from zero, because in that case the
! the density was previously set to the fresh snow value.
ELSE
!-----------------------------------------------------------------------
! There is at least one snow layer. Calculate heat conduction between
! layers and temperature increments.
!-----------------------------------------------------------------------
! Save rate of melting of snow on the canopy.
IF ( cansnowtile ) THEN
can_melt = melt_surft(i)
ELSE
can_melt = 0.0
END IF
IF ( nsnow(i) == 1 ) THEN
! Single layer of snow.
asnow(1) = 2.0 / &
( snowdepth(i)/ksnow(i,1) + dzsoilw/hconsw )
snow_soil_htf(i) = asnow(1) * ( tsnow(i,1) - tsoilw )
dt(1) = ( g_snow_surf - snow_soil_htf(i) ) * timestep / &
( csnow(i,1) + GAMMA * asnow(1) * timestep )
snow_soil_htf(i) = asnow(1) * &
( tsnow(i,1) + GAMMA*dt(1) - tsoilw )
tsnow(i,1) = tsnow(i,1) + dt(1)
ELSE
! Multiple snow layers.
DO n=1,nsnow(i)-1
asnow(n) = 2.0 / &
( ds(i,n)/ksnow(i,n) + ds(i,n+1)/ksnow(i,n+1) )
END DO
n = nsnow(i)
asnow(n) = 2.0 / ( ds(i,n)/ksnow(i,n) + dzsoilw/hconsw )
a(1) = 0.
b(1) = csnow(i,1) + GAMMA*asnow(1)*timestep
c(1) = -GAMMA * asnow(1) * timestep
r(1) = ( g_snow_surf - asnow(1)*(tsnow(i,1)-tsnow(i,2)) ) &
* timestep
DO n=2,nsnow(i)-1
a(n) = -GAMMA * asnow(n-1) * timestep
b(n) = csnow(i,n) + GAMMA * ( asnow(n-1) + asnow(n) ) &
* timestep
c(n) = -GAMMA * asnow(n) * timestep
r(n) = asnow(n-1)*(tsnow(i,n-1) - tsnow(i,n) ) * timestep &
+ asnow(n)*(tsnow(i,n+1) - tsnow(i,n)) * timestep
END DO
n = nsnow(i)
a(n) = -GAMMA * asnow(n-1) * timestep
b(n) = csnow(i,n) + GAMMA * (asnow(n-1)+asnow(n)) * timestep
c(n) = 0.
r(n) = asnow(n-1)*( tsnow(i,n-1) - tsnow(i,n) ) * timestep &
+ asnow(n) * ( tsoilw - tsnow(i,n) ) * timestep
!-----------------------------------------------------------------------
! Call the tridiagonal solver.
!-----------------------------------------------------------------------
CALL tridag( nsnow(i),nsmax,a,b,c,r,dt )
n = nsnow(i)
snow_soil_htf(i) = asnow(n) * &
( tsnow(i,n) + GAMMA*dt(n) - tsoilw )
DO n=1,nsnow(i)
tsnow(i,n) = tsnow(i,n) + dt(n)
END DO
END IF ! NSNOW
!-----------------------------------------------------------------------
! Melt snow in layers with temperature exceeding melting point
!-----------------------------------------------------------------------
DO n=1,nsnow(i)
coldsnow = csnow(i,n)*(tm - tsnow(i,n))
IF ( coldsnow < 0 ) THEN
tsnow(i,n) = tm
dsice = -coldsnow / lf
IF ( dsice > sice(i,n) ) dsice = sice(i,n)
ds(i,n) = ( 1.0 - dsice/sice(i,n) ) * ds(i,n)
sice(i,n) = sice(i,n) - dsice
sliq(i,n) = sliq(i,n) + dsice
END IF
END DO
! Melt still > 0? - no snow left
!-----------------------------------------------------------------------
! Remove snow by sublimation unless snow is beneath canopy
!-----------------------------------------------------------------------
IF ( .NOT. cansnowtile ) THEN
dsice = MAX( ei_surft(i), 0. ) * timestep
IF ( dsice > 0.0 ) THEN
DO n=1,nsnow(i)
IF ( dsice > sice(i,n) ) THEN
! Layer sublimates completely
dsice = dsice - sice(i,n)
sice(i,n) = 0.
ds(i,n) = 0.
ELSE
! Layer sublimates partially
ds(i,n) = (1.0 - dsice/sice(i,n))*ds(i,n)
sice(i,n) = sice(i,n) - dsice
EXIT ! sublimation exhausted
END IF
END DO
END IF ! DSICE>0
END IF ! CANSNOWTILE
!-----------------------------------------------------------------------
! Move liquid water in excess of holding capacity downwards or refreeze.
!-----------------------------------------------------------------------
! Optionally include infiltration of rainwater and melting from the
! canopy into the snowpack.
IF (l_snow_infilt) THEN
win = infiltration(i) + can_melt * timestep
ELSE
win = 0.0
END IF
DO n=1,nsnow(i)
sliq(i,n) = sliq(i,n) + win
win = 0.0
sliqmax = snowliqcap * rho_water * ds(i,n)
!construct a temporary rho here. Can't guarantee
!sensible values of anything at ths point in the routine. If layer
!has gone (ds=0), just feed everything down to the next layer
IF ( ds(i,n) > EPSILON(0.0) ) THEN
rho_temp = min(rho_ice,(sice(i,n) + sliq(i,n)) / ds(i,n))
ELSE
rho_temp = rho_ice
END IF
!reduce pore density of pack as we approach solid ice
IF (l_elev_land_ice .AND. l_lice_point(i)) THEN
IF(rho_temp >= rho_firn_pore_closure) THEN
sliqmax = 0.0
ELSE IF((rho_temp >= rho_firn_pore_restrict) .AND. &
(rho_temp < rho_firn_pore_closure)) THEN
sliqmax = sliqmax * (rho_firn_pore_closure - rho_temp) / &
(rho_firn_pore_closure - rho_firn_pore_restrict)
ENDIF
ENDIF
IF (sliq(i,n) > sliqmax) THEN
! Liquid capacity exceeded
win = sliq(i,n) - sliqmax
sliq(i,n) = sliqmax
END IF
coldsnow = csnow(i,n)*(tm - tsnow(i,n))
IF (coldsnow > 0) THEN
! Liquid can freeze
dsice = MIN(sliq(i,n), coldsnow / lf)
sliq(i,n) = sliq(i,n) - dsice
sice(i,n) = sice(i,n) + dsice
tsnow(i,n) = tsnow(i,n) + lf*dsice/csnow(i,n)
END IF
END DO
!-----------------------------------------------------------------------
! The remaining liquid water flux is melt.
! Include any separate canopy melt in this diagnostic.
!-----------------------------------------------------------------------
IF ( l_snow_infilt ) THEN
! Canopy melting has already been added to infiltration.
melt_surft(i) = ( win / timestep )
ELSE
melt_surft(i) = ( win / timestep ) + can_melt
END IF
!-----------------------------------------------------------------------
! Diagnose layer densities
!-----------------------------------------------------------------------
DO n=1,nsnow(i)
! rho_snow(i,n) = 0.0
IF ( ds(i,n) > EPSILON(ds) ) &
rho_snow(i,n) = (sice(i,n) + sliq(i,n)) / ds(i,n)
END DO
!-----------------------------------------------------------------------
! Add snowfall and frost as layer 0.
!-----------------------------------------------------------------------
sice0(i) = snowfall(i)
IF ( .NOT. cansnowtile ) &
sice0(i) = snowfall(i) - MIN(ei_surft(i), 0.) * timestep
tsnow0(i) = tsnow(i,1)
rho0(i) = rho_snow_fresh
!-----------------------------------------------------------------------
! Diagnose total snow depth and mass
!-----------------------------------------------------------------------
snowdepth(i) = sice0(i) / rho0(i)
snowmass(i) = sice0(i)
DO n=1,nsnow(i)
snowdepth(i) = snowdepth(i) + ds(i,n)
snowmass(i) = snowmass(i) + sice(i,n) + sliq(i,n)
END DO
END IF ! NSNOW
! tsoil only modified for canopy snow tiles (and not land ice ones,
! although they shouldn't have this switch on anyway)
IF (.NOT. l_elev_land_ice) THEN
tsoil1(i)=tsoilw
ELSE IF (.NOT. l_lice_point(i)) THEN
tsoil1(i)=tsoilw
END IF
END DO ! k (points)
IF (lhook) CALL dr_hook(ModuleName//':'//RoutineName,zhook_out,zhook_handle)
RETURN
END SUBROUTINE snowpack
END MODULE snowpack_mod
| gpl-2.0 |
apollos/Quantum-ESPRESSO | lapack-3.2/SRC/cpptri.f | 1 | 3642 | SUBROUTINE CPPTRI( UPLO, N, AP, INFO )
*
* -- LAPACK routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, N
* ..
* .. Array Arguments ..
COMPLEX AP( * )
* ..
*
* Purpose
* =======
*
* CPPTRI computes the inverse of a complex Hermitian positive definite
* matrix A using the Cholesky factorization A = U**H*U or A = L*L**H
* computed by CPPTRF.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* = 'U': Upper triangular factor is stored in AP;
* = 'L': Lower triangular factor is stored in AP.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* AP (input/output) COMPLEX array, dimension (N*(N+1)/2)
* On entry, the triangular factor U or L from the Cholesky
* factorization A = U**H*U or A = L*L**H, packed columnwise as
* a linear array. The j-th column of U or L is stored in the
* array AP as follows:
* if UPLO = 'U', AP(i + (j-1)*j/2) = U(i,j) for 1<=i<=j;
* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = L(i,j) for j<=i<=n.
*
* On exit, the upper or lower triangle of the (Hermitian)
* inverse of A, overwriting the input factor U or L.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, the (i,i) element of the factor U or L is
* zero, and the inverse could not be computed.
*
* =====================================================================
*
* .. Parameters ..
REAL ONE
PARAMETER ( ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER J, JC, JJ, JJN
REAL AJJ
* ..
* .. External Functions ..
LOGICAL LSAME
COMPLEX CDOTC
EXTERNAL LSAME, CDOTC
* ..
* .. External Subroutines ..
EXTERNAL CHPR, CSSCAL, CTPMV, CTPTRI, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC REAL
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
UPPER = LSAME( UPLO, 'U' )
IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CPPTRI', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Invert the triangular Cholesky factor U or L.
*
CALL CTPTRI( UPLO, 'Non-unit', N, AP, INFO )
IF( INFO.GT.0 )
$ RETURN
IF( UPPER ) THEN
*
* Compute the product inv(U) * inv(U)'.
*
JJ = 0
DO 10 J = 1, N
JC = JJ + 1
JJ = JJ + J
IF( J.GT.1 )
$ CALL CHPR( 'Upper', J-1, ONE, AP( JC ), 1, AP )
AJJ = AP( JJ )
CALL CSSCAL( J, AJJ, AP( JC ), 1 )
10 CONTINUE
*
ELSE
*
* Compute the product inv(L)' * inv(L).
*
JJ = 1
DO 20 J = 1, N
JJN = JJ + N - J + 1
AP( JJ ) = REAL( CDOTC( N-J+1, AP( JJ ), 1, AP( JJ ), 1 ) )
IF( J.LT.N )
$ CALL CTPMV( 'Lower', 'Conjugate transpose', 'Non-unit',
$ N-J, AP( JJN ), AP( JJ+1 ), 1 )
JJ = JJN
20 CONTINUE
END IF
*
RETURN
*
* End of CPPTRI
*
END
| gpl-2.0 |
xianyi/OpenBLAS | lapack-netlib/SRC/zgebal.f | 1 | 10649 | *> \brief \b ZGEBAL
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ZGEBAL + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgebal.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgebal.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgebal.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
*
* .. Scalar Arguments ..
* CHARACTER JOB
* INTEGER IHI, ILO, INFO, LDA, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION SCALE( * )
* COMPLEX*16 A( LDA, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZGEBAL balances a general complex matrix A. This involves, first,
*> permuting A by a similarity transformation to isolate eigenvalues
*> in the first 1 to ILO-1 and last IHI+1 to N elements on the
*> diagonal; and second, applying a diagonal similarity transformation
*> to rows and columns ILO to IHI to make the rows and columns as
*> close in norm as possible. Both steps are optional.
*>
*> Balancing may reduce the 1-norm of the matrix, and improve the
*> accuracy of the computed eigenvalues and/or eigenvectors.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] JOB
*> \verbatim
*> JOB is CHARACTER*1
*> Specifies the operations to be performed on A:
*> = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
*> for i = 1,...,N;
*> = 'P': permute only;
*> = 'S': scale only;
*> = 'B': both permute and scale.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is COMPLEX*16 array, dimension (LDA,N)
*> On entry, the input matrix A.
*> On exit, A is overwritten by the balanced matrix.
*> If JOB = 'N', A is not referenced.
*> See Further Details.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[out] ILO
*> \verbatim
*> ILO is INTEGER
*> \endverbatim
*>
*> \param[out] IHI
*> \verbatim
*> IHI is INTEGER
*> ILO and IHI are set to INTEGER such that on exit
*> A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
*> If JOB = 'N' or 'S', ILO = 1 and IHI = N.
*> \endverbatim
*>
*> \param[out] SCALE
*> \verbatim
*> SCALE is DOUBLE PRECISION array, dimension (N)
*> Details of the permutations and scaling factors applied to
*> A. If P(j) is the index of the row and column interchanged
*> with row and column j and D(j) is the scaling factor
*> applied to row and column j, then
*> SCALE(j) = P(j) for j = 1,...,ILO-1
*> = D(j) for j = ILO,...,IHI
*> = P(j) for j = IHI+1,...,N.
*> The order in which the interchanges are made is N to IHI+1,
*> then 1 to ILO-1.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit.
*> < 0: if INFO = -i, the i-th argument had an illegal value.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup complex16GEcomputational
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> The permutations consist of row and column interchanges which put
*> the matrix in the form
*>
*> ( T1 X Y )
*> P A P = ( 0 B Z )
*> ( 0 0 T2 )
*>
*> where T1 and T2 are upper triangular matrices whose eigenvalues lie
*> along the diagonal. The column indices ILO and IHI mark the starting
*> and ending columns of the submatrix B. Balancing consists of applying
*> a diagonal similarity transformation inv(D) * B * D to make the
*> 1-norms of each row of B and its corresponding column nearly equal.
*> The output matrix is
*>
*> ( T1 X*D Y )
*> ( 0 inv(D)*B*D inv(D)*Z ).
*> ( 0 0 T2 )
*>
*> Information about the permutations P and the diagonal matrix D is
*> returned in the vector SCALE.
*>
*> This subroutine is based on the EISPACK routine CBAL.
*>
*> Modified by Tzu-Yi Chen, Computer Science Division, University of
*> California at Berkeley, USA
*> \endverbatim
*>
* =====================================================================
SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
*
* -- LAPACK computational routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
CHARACTER JOB
INTEGER IHI, ILO, INFO, LDA, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION SCALE( * )
COMPLEX*16 A( LDA, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
DOUBLE PRECISION SCLFAC
PARAMETER ( SCLFAC = 2.0D+0 )
DOUBLE PRECISION FACTOR
PARAMETER ( FACTOR = 0.95D+0 )
* ..
* .. Local Scalars ..
LOGICAL NOCONV
INTEGER I, ICA, IEXC, IRA, J, K, L, M
DOUBLE PRECISION C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
$ SFMIN2
* ..
* .. External Functions ..
LOGICAL DISNAN, LSAME
INTEGER IZAMAX
DOUBLE PRECISION DLAMCH, DZNRM2
EXTERNAL DISNAN, LSAME, IZAMAX, DLAMCH, DZNRM2
* ..
* .. External Subroutines ..
EXTERNAL XERBLA, ZDSCAL, ZSWAP
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, DIMAG, MAX, MIN
*
* Test the input parameters
*
INFO = 0
IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
$ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -4
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZGEBAL', -INFO )
RETURN
END IF
*
K = 1
L = N
*
IF( N.EQ.0 )
$ GO TO 210
*
IF( LSAME( JOB, 'N' ) ) THEN
DO 10 I = 1, N
SCALE( I ) = ONE
10 CONTINUE
GO TO 210
END IF
*
IF( LSAME( JOB, 'S' ) )
$ GO TO 120
*
* Permutation to isolate eigenvalues if possible
*
GO TO 50
*
* Row and column exchange.
*
20 CONTINUE
SCALE( M ) = J
IF( J.EQ.M )
$ GO TO 30
*
CALL ZSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
CALL ZSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA )
*
30 CONTINUE
GO TO ( 40, 80 )IEXC
*
* Search for rows isolating an eigenvalue and push them down.
*
40 CONTINUE
IF( L.EQ.1 )
$ GO TO 210
L = L - 1
*
50 CONTINUE
DO 70 J = L, 1, -1
*
DO 60 I = 1, L
IF( I.EQ.J )
$ GO TO 60
IF( DBLE( A( J, I ) ).NE.ZERO .OR. DIMAG( A( J, I ) ).NE.
$ ZERO )GO TO 70
60 CONTINUE
*
M = L
IEXC = 1
GO TO 20
70 CONTINUE
*
GO TO 90
*
* Search for columns isolating an eigenvalue and push them left.
*
80 CONTINUE
K = K + 1
*
90 CONTINUE
DO 110 J = K, L
*
DO 100 I = K, L
IF( I.EQ.J )
$ GO TO 100
IF( DBLE( A( I, J ) ).NE.ZERO .OR. DIMAG( A( I, J ) ).NE.
$ ZERO )GO TO 110
100 CONTINUE
*
M = K
IEXC = 2
GO TO 20
110 CONTINUE
*
120 CONTINUE
DO 130 I = K, L
SCALE( I ) = ONE
130 CONTINUE
*
IF( LSAME( JOB, 'P' ) )
$ GO TO 210
*
* Balance the submatrix in rows K to L.
*
* Iterative loop for norm reduction
*
SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' )
SFMAX1 = ONE / SFMIN1
SFMIN2 = SFMIN1*SCLFAC
SFMAX2 = ONE / SFMIN2
140 CONTINUE
NOCONV = .FALSE.
*
DO 200 I = K, L
*
C = DZNRM2( L-K+1, A( K, I ), 1 )
R = DZNRM2( L-K+1, A( I, K ), LDA )
ICA = IZAMAX( L, A( 1, I ), 1 )
CA = ABS( A( ICA, I ) )
IRA = IZAMAX( N-K+1, A( I, K ), LDA )
RA = ABS( A( I, IRA+K-1 ) )
*
* Guard against zero C or R due to underflow.
*
IF( C.EQ.ZERO .OR. R.EQ.ZERO )
$ GO TO 200
G = R / SCLFAC
F = ONE
S = C + R
160 CONTINUE
IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
$ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
IF( DISNAN( C+F+CA+R+G+RA ) ) THEN
*
* Exit if NaN to avoid infinite loop
*
INFO = -3
CALL XERBLA( 'ZGEBAL', -INFO )
RETURN
END IF
F = F*SCLFAC
C = C*SCLFAC
CA = CA*SCLFAC
R = R / SCLFAC
G = G / SCLFAC
RA = RA / SCLFAC
GO TO 160
*
170 CONTINUE
G = C / SCLFAC
180 CONTINUE
IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.
$ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190
F = F / SCLFAC
C = C / SCLFAC
G = G / SCLFAC
CA = CA / SCLFAC
R = R*SCLFAC
RA = RA*SCLFAC
GO TO 180
*
* Now balance.
*
190 CONTINUE
IF( ( C+R ).GE.FACTOR*S )
$ GO TO 200
IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN
IF( F*SCALE( I ).LE.SFMIN1 )
$ GO TO 200
END IF
IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN
IF( SCALE( I ).GE.SFMAX1 / F )
$ GO TO 200
END IF
G = ONE / F
SCALE( I ) = SCALE( I )*F
NOCONV = .TRUE.
*
CALL ZDSCAL( N-K+1, G, A( I, K ), LDA )
CALL ZDSCAL( L, F, A( 1, I ), 1 )
*
200 CONTINUE
*
IF( NOCONV )
$ GO TO 140
*
210 CONTINUE
ILO = K
IHI = L
*
RETURN
*
* End of ZGEBAL
*
END
| bsd-3-clause |
apollos/Quantum-ESPRESSO | lapack-3.2/INSTALL/dlamchtst.f | 2 | 1523 | PROGRAM TEST3
*
* -- LAPACK test routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Local Scalars ..
DOUBLE PRECISION BASE, EMAX, EMIN, EPS, PREC, RMAX, RMIN, RND,
$ SFMIN, T
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH
EXTERNAL DLAMCH
* ..
* .. Executable Statements ..
*
EPS = DLAMCH( 'Epsilon' )
SFMIN = DLAMCH( 'Safe minimum' )
BASE = DLAMCH( 'Base' )
PREC = DLAMCH( 'Precision' )
T = DLAMCH( 'Number of digits in mantissa' )
RND = DLAMCH( 'Rounding mode' )
EMIN = DLAMCH( 'Minimum exponent' )
RMIN = DLAMCH( 'Underflow threshold' )
EMAX = DLAMCH( 'Largest exponent' )
RMAX = DLAMCH( 'Overflow threshold' )
*
WRITE( 6, * )' Epsilon = ', EPS
WRITE( 6, * )' Safe minimum = ', SFMIN
WRITE( 6, * )' Base = ', BASE
WRITE( 6, * )' Precision = ', PREC
WRITE( 6, * )' Number of digits in mantissa = ', T
WRITE( 6, * )' Rounding mode = ', RND
WRITE( 6, * )' Minimum exponent = ', EMIN
WRITE( 6, * )' Underflow threshold = ', RMIN
WRITE( 6, * )' Largest exponent = ', EMAX
WRITE( 6, * )' Overflow threshold = ', RMAX
WRITE( 6, * )' Reciprocal of safe minimum = ', 1 / SFMIN
*
END
| gpl-2.0 |
apollos/Quantum-ESPRESSO | lapack-3.2/SRC/zptsv.f | 1 | 3168 | SUBROUTINE ZPTSV( N, NRHS, D, E, B, LDB, INFO )
*
* -- LAPACK routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
INTEGER INFO, LDB, N, NRHS
* ..
* .. Array Arguments ..
DOUBLE PRECISION D( * )
COMPLEX*16 B( LDB, * ), E( * )
* ..
*
* Purpose
* =======
*
* ZPTSV computes the solution to a complex system of linear equations
* A*X = B, where A is an N-by-N Hermitian positive definite tridiagonal
* matrix, and X and B are N-by-NRHS matrices.
*
* A is factored as A = L*D*L**H, and the factored form of A is then
* used to solve the system of equations.
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrix B. NRHS >= 0.
*
* D (input/output) DOUBLE PRECISION array, dimension (N)
* On entry, the n diagonal elements of the tridiagonal matrix
* A. On exit, the n diagonal elements of the diagonal matrix
* D from the factorization A = L*D*L**H.
*
* E (input/output) COMPLEX*16 array, dimension (N-1)
* On entry, the (n-1) subdiagonal elements of the tridiagonal
* matrix A. On exit, the (n-1) subdiagonal elements of the
* unit bidiagonal factor L from the L*D*L**H factorization of
* A. E can also be regarded as the superdiagonal of the unit
* bidiagonal factor U from the U**H*D*U factorization of A.
*
* B (input/output) COMPLEX*16 array, dimension (LDB,N)
* On entry, the N-by-NRHS right hand side matrix B.
* On exit, if INFO = 0, the N-by-NRHS solution matrix X.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, the leading minor of order i is not
* positive definite, and the solution has not been
* computed. The factorization has not been completed
* unless i = N.
*
* =====================================================================
*
* .. External Subroutines ..
EXTERNAL XERBLA, ZPTTRF, ZPTTRS
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( N.LT.0 ) THEN
INFO = -1
ELSE IF( NRHS.LT.0 ) THEN
INFO = -2
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -6
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZPTSV ', -INFO )
RETURN
END IF
*
* Compute the L*D*L' (or U'*D*U) factorization of A.
*
CALL ZPTTRF( N, D, E, INFO )
IF( INFO.EQ.0 ) THEN
*
* Solve the system A*X = B, overwriting B with X.
*
CALL ZPTTRS( 'Lower', N, NRHS, D, E, B, LDB, INFO )
END IF
RETURN
*
* End of ZPTSV
*
END
| gpl-2.0 |
rmcgibbo/scipy | scipy/linalg/src/id_dist/src/idz_sfft.f | 139 | 5011 | c this file contains the following user-callable routines:
c
c
c routine idz_sffti initializes routine idz_sfft.
c
c routine idz_sfft rapidly computes a subset of the entries
c of the DFT of a vector, composed with permutation matrices
c both on input and on output.
c
c routine idz_ldiv finds the greatest integer less than or equal
c to a specified integer, that is divisible by another (larger)
c specified integer.
c
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c
c
c
subroutine idz_ldiv(l,n,m)
c
c finds the greatest integer less than or equal to l
c that divides n.
c
c input:
c l -- integer at least as great as m
c n -- integer divisible by m
c
c output:
c m -- greatest integer less than or equal to l that divides n
c
implicit none
integer n,l,m
c
c
m = l
c
1000 continue
if(m*(n/m) .eq. n) goto 2000
c
m = m-1
goto 1000
c
2000 continue
c
c
return
end
c
c
c
c
subroutine idz_sffti(l,ind,n,wsave)
c
c initializes wsave for use with routine idz_sfft.
c
c input:
c l -- number of entries in the output of idz_sfft to compute
c ind -- indices of the entries in the output of idz_sfft
c to compute
c n -- length of the vector to be transformed
c
c output:
c wsave -- array needed by routine idz_sfft for processing
c
implicit none
integer l,ind(l),n,nblock,ii,m,idivm,imodm,i,j,k
real*8 r1,twopi,fact
complex*16 wsave(2*l+15+3*n),ci,twopii
c
ci = (0,1)
r1 = 1
twopi = 2*4*atan(r1)
twopii = twopi*ci
c
c
c Determine the block lengths for the FFTs.
c
call idz_ldiv(l,n,nblock)
m = n/nblock
c
c
c Initialize wsave for use with routine zfftf.
c
call zffti(nblock,wsave)
c
c
c Calculate the coefficients in the linear combinations
c needed for the direct portion of the calculation.
c
fact = 1/sqrt(r1*n)
c
ii = 2*l+15
c
do j = 1,l
c
i = ind(j)
c
idivm = (i-1)/m
imodm = (i-1)-m*idivm
c
do k = 1,m
wsave(ii+m*(j-1)+k) = exp(-twopii*imodm*(k-1)/(r1*m))
1 * exp(-twopii*(k-1)*idivm/(r1*n)) * fact
enddo ! k
c
enddo ! j
c
c
return
end
c
c
c
c
subroutine idz_sfft(l,ind,n,wsave,v)
c
c computes a subset of the entries of the DFT of v,
c composed with permutation matrices both on input and on output,
c via a two-stage procedure (routine zfftf2 is supposed
c to calculate the full vector from which idz_sfft returns
c a subset of the entries, when zfftf2 has the same parameter
c nblock as in the present routine).
c
c input:
c l -- number of entries in the output to compute
c ind -- indices of the entries of the output to compute
c n -- length of v
c v -- vector to be transformed
c wsave -- processing array initialized by routine idz_sffti
c
c output:
c v -- entries indexed by ind are given their appropriate
c transformed values
c
c _N.B._: The user has to boost the memory allocations
c for wsave (and change iii accordingly) if s/he wishes
c to use strange sizes of n; it's best to stick to powers
c of 2.
c
c references:
c Sorensen and Burrus, "Efficient computation of the DFT with
c only a subset of input or output points,"
c IEEE Transactions on Signal Processing, 41 (3): 1184-1200,
c 1993.
c Woolfe, Liberty, Rokhlin, Tygert, "A fast randomized algorithm
c for the approximation of matrices," Applied and
c Computational Harmonic Analysis, 25 (3): 335-366, 2008;
c Section 3.3.
c
implicit none
integer n,m,l,k,j,ind(l),i,idivm,nblock,ii,iii
real*8 r1,twopi
complex*16 v(n),wsave(2*l+15+3*n),ci,sum
c
ci = (0,1)
r1 = 1
twopi = 2*4*atan(r1)
c
c
c Determine the block lengths for the FFTs.
c
call idz_ldiv(l,n,nblock)
c
c
m = n/nblock
c
c
c FFT each block of length nblock of v.
c
do k = 1,m
call zfftf(nblock,v(nblock*(k-1)+1),wsave)
enddo ! k
c
c
c Transpose v to obtain wsave(2*l+15+2*n+1 : 2*l+15+3*n).
c
iii = 2*l+15+2*n
c
do k = 1,m
do j = 1,nblock
wsave(iii+m*(j-1)+k) = v(nblock*(k-1)+j)
enddo ! j
enddo ! k
c
c
c Directly calculate the desired entries of v.
c
ii = 2*l+15
iii = 2*l+15+2*n
c
do j = 1,l
c
i = ind(j)
c
idivm = (i-1)/m
c
sum = 0
c
do k = 1,m
sum = sum + wsave(ii+m*(j-1)+k) * wsave(iii+m*idivm+k)
enddo ! k
c
v(i) = sum
c
enddo ! j
c
c
return
end
| bsd-3-clause |
kolawoletech/ce-espresso | upftools/casino_pp.f90 | 2 | 17242 |
MODULE casino_pp
!
! All variables read from CASINO file format
!
! trailing underscore means that a variable with the same name
! is used in module 'upf' containing variables to be written
!
USE kinds, ONLY : dp
CHARACTER(len=20) :: dft_
CHARACTER(len=2) :: psd_
REAL(dp) :: zp_
INTEGER nlc, nnl, lmax_, lloc, nchi, rel_
LOGICAL :: numeric, bhstype, nlcc_
CHARACTER(len=2), ALLOCATABLE :: els_(:)
REAL(dp) :: zmesh
REAL(dp) :: xmin = -7.0_dp
REAL(dp) :: dx = 20.0_dp/1500.0_dp
REAL(dp) :: tn_prefac = 0.75E-6_dp
LOGICAL :: tn_grid = .true.
REAL(dp), ALLOCATABLE:: r_(:)
INTEGER :: mesh_
REAL(dp), ALLOCATABLE:: vnl(:,:)
INTEGER, ALLOCATABLE:: lchi_(:), nns_(:)
REAL(dp), ALLOCATABLE:: chi_(:,:), oc_(:)
CONTAINS
!
! ----------------------------------------------------------
SUBROUTINE read_casino(iunps,nofiles, waveunit)
! ----------------------------------------------------------
!
! Reads in a CASINO tabulated pp file and it's associated
! awfn files. Some basic processing such as removing the
! r factors from the potentials is also performed.
USE kinds, ONLY : dp
IMPLICIT NONE
TYPE :: wavfun_list
INTEGER :: occ,eup,edwn, nquant, lquant
CHARACTER(len=2) :: label
#ifdef __STD_F95
REAL(dp), POINTER :: wavefunc(:)
#else
REAL(dp), ALLOCATABLE :: wavefunc(:)
#endif
TYPE (wavfun_list), POINTER :: p
END TYPE wavfun_list
TYPE :: channel_list
INTEGER :: lquant
#ifdef __STD_F95
REAL(dp), POINTER :: channel(:)
#else
REAL(dp), ALLOCATABLE :: channel(:)
#endif
TYPE (channel_list), POINTER :: p
END TYPE channel_list
TYPE (channel_list), POINTER :: phead
TYPE (channel_list), POINTER :: pptr
TYPE (channel_list), POINTER :: ptail
TYPE (wavfun_list), POINTER :: mhead
TYPE (wavfun_list), POINTER :: mptr
TYPE (wavfun_list), POINTER :: mtail
INTEGER :: iunps, nofiles, ios
!
LOGICAL :: groundstate, found
CHARACTER(len=2) :: label, rellab
INTEGER :: l, i, ir, nb, gsorbs, j,k,m,tmp, lquant, orbs, nquant
INTEGER, ALLOCATABLE :: gs(:,:)
INTEGER, INTENT(in) :: waveunit(nofiles)
NULLIFY ( mhead, mptr, mtail )
dft_ = 'HF' !Hardcoded at the moment should eventually be HF anyway
nlc = 0 !These two values are always 0 for numeric pps
nnl = 0 !so lets just hard code them
nlcc_ = .false. !Again these two are alwas false for CASINO pps
bhstype = .false.
READ(iunps,'(a2,35x,a2)') rellab, psd_
READ(iunps,*)
IF ( rellab == 'DF' ) THEN
rel_=1
ELSE
rel_=0
ENDIF
READ(iunps,*) zmesh,zp_ !Here we are reading zmesh (atomic #) and
DO i=1,3 !zp_ (pseudo charge)
READ(iunps,*)
ENDDO
READ(iunps,*) lloc !reading in lloc
IF ( zp_<=0d0 ) &
CALL errore( 'read_casino','Wrong zp ',1 )
IF ( lloc>3.or.lloc<0 ) &
CALL errore( 'read_casino','Wrong lloc ',1 )
!
! compute the radial mesh
!
DO i=1,3
READ(iunps,*)
ENDDO
READ(iunps,*) mesh_ !Reading in total no. of mesh points
ALLOCATE( r_(mesh_))
READ(iunps,*)
DO i=1,mesh_
READ(iunps,*) r_(i)
ENDDO
! Read in the different channels of V_nl
ALLOCATE(phead)
ptail => phead
pptr => phead
ALLOCATE( pptr%channel(mesh_) )
READ(iunps, '(15x,I1,7x)') l
pptr%lquant=l
READ(iunps, *) (pptr%channel(ir),ir=1,mesh_)
DO
READ(iunps, '(15x,I1,7x)', IOSTAT=ios) l
IF (ios /= 0 ) THEN
exit
ENDIF
ALLOCATE(pptr%p)
pptr=> pptr%p
ptail=> pptr
ALLOCATE( pptr%channel(mesh_) )
pptr%lquant=l
READ(iunps, *) (pptr%channel(ir),ir=1,mesh_)
ENDDO
!Compute the number of channels read in.
lmax_ =-1
pptr => phead
DO
IF ( .not. associated(pptr) )exit
lmax_=lmax_+1
pptr =>pptr%p
ENDDO
ALLOCATE(vnl(mesh_,0:lmax_))
i=0
pptr => phead
DO
IF ( .not. associated(pptr) )exit
! lchi_(i) = pptr%lquant
DO ir=1,mesh_
vnl(ir,i) = pptr%channel(ir)
ENDDO
DEALLOCATE( pptr%channel )
pptr =>pptr%p
i=i+1
ENDDO
!Clean up the linked list (deallocate it)
DO
IF ( .not. associated(phead) )exit
pptr => phead
phead => phead%p
DEALLOCATE( pptr )
ENDDO
DO l = 0, lmax_
DO ir = 1, mesh_
vnl(ir,l) = vnl(ir,l)/r_(ir) !Removing the factor of r CASINO has
ENDDO
! correcting for possible divide by zero
IF ( r_(1) == 0 ) THEN
vnl(1,l) = 0
ENDIF
ENDDO
ALLOCATE(mhead)
mtail => mhead
mptr => mhead
NULLIFY(mtail%p)
groundstate=.true.
DO j=1,nofiles
DO i=1,4
READ(waveunit(j),*)
ENDDO
READ(waveunit(j),*) orbs
IF ( groundstate ) THEN
ALLOCATE( gs(orbs,3) )
gs = 0
gsorbs = orbs
ENDIF
DO i=1,2
READ(waveunit(j),*)
ENDDO
READ(waveunit(j),*) mtail%eup, mtail%edwn
READ(waveunit(j),*)
DO i=1,mtail%eup+mtail%edwn
READ(waveunit(j),*) tmp, nquant, lquant
IF ( groundstate ) THEN
found = .true.
DO m=1,orbs
IF ( (nquant==gs(m,1) .and. lquant==gs(m,2)) ) THEN
gs(m,3) = gs(m,3) + 1
exit
ENDIF
found = .false.
ENDDO
IF (.not. found ) THEN
DO m=1,orbs
IF ( gs(m,1) == 0 ) THEN
gs(m,1) = nquant
gs(m,2) = lquant
gs(m,3) = 1
exit
ENDIF
ENDDO
ENDIF
ENDIF
ENDDO
READ(waveunit(j),*)
READ(waveunit(j),*)
DO i=1,mesh_
READ(waveunit(j),*)
ENDDO
DO k=1,orbs
READ(waveunit(j),'(13x,a2)', err=300) label
READ(waveunit(j),*) tmp, nquant, lquant
IF ( .not. groundstate ) THEN
found = .false.
DO m = 1,gsorbs
IF ( nquant == gs(m,1) .and. lquant == gs(m,2) ) THEN
found = .true.
exit
ENDIF
ENDDO
mptr => mhead
DO
IF ( .not. associated(mptr) )exit
IF ( nquant == mptr%nquant .and. lquant == mptr%lquant ) found = .true.
mptr =>mptr%p
ENDDO
IF ( found ) THEN
DO i=1,mesh_
READ(waveunit(j),*)
ENDDO
CYCLE
ENDIF
ENDIF
#ifdef __STD_F95
IF ( associated(mtail%wavefunc) ) THEN
#else
IF ( allocated(mtail%wavefunc) ) THEN
#endif
ALLOCATE(mtail%p)
mtail=>mtail%p
NULLIFY(mtail%p)
ALLOCATE( mtail%wavefunc(mesh_) )
ELSE
ALLOCATE( mtail%wavefunc(mesh_) )
ENDIF
mtail%label = label
mtail%nquant = nquant
mtail%lquant = lquant
READ(waveunit(j), *, err=300) (mtail%wavefunc(ir),ir=1,mesh_)
ENDDO
groundstate = .false.
ENDDO
nchi =0
mptr => mhead
DO
IF ( .not. associated(mptr) )exit
nchi=nchi+1
mptr =>mptr%p
ENDDO
ALLOCATE(lchi_(nchi), els_(nchi), nns_(nchi))
ALLOCATE(oc_(nchi))
ALLOCATE(chi_(mesh_,nchi))
oc_ = 0
!Sort out the occupation numbers
DO i=1,gsorbs
oc_(i)=gs(i,3)
ENDDO
DEALLOCATE( gs )
i=1
mptr => mhead
DO
IF ( .not. associated(mptr) )exit
nns_(i) = mptr%nquant
lchi_(i) = mptr%lquant
els_(i) = mptr%label
DO ir=1,mesh_
chi_(ir:,i) = mptr%wavefunc(ir)
ENDDO
DEALLOCATE( mptr%wavefunc )
mptr =>mptr%p
i=i+1
ENDDO
!Clean up the linked list (deallocate it)
DO
IF ( .not. associated(mhead) )exit
mptr => mhead
mhead => mhead%p
DEALLOCATE( mptr )
ENDDO
! ----------------------------------------------------------
WRITE (0,'(a)') 'Pseudopotential successfully read'
! ----------------------------------------------------------
RETURN
300 CALL errore('read_casino','pseudo file is empty or wrong',1)
END SUBROUTINE read_casino
! ----------------------------------------------------------
SUBROUTINE convert_casino(upf_out)
! ----------------------------------------------------------
USE kinds, ONLY : dp
USE upf_module
USE radial_grids, ONLY: radial_grid_type, deallocate_radial_grid
USE funct, ONLY : set_dft_from_name, get_iexch, get_icorr, &
get_igcx, get_igcc
IMPLICIT NONE
TYPE(pseudo_upf), INTENT(inout) :: upf_out
REAL(dp), ALLOCATABLE :: aux(:)
REAL(dp) :: vll
INTEGER :: kkbeta, l, iv, ir, i, nb
WRITE(upf_out%generated, '("From a Trail & Needs tabulated &
&PP for CASINO")')
WRITE(upf_out%author,'("unknown")')
WRITE(upf_out%date,'("unknown")')
upf_out%comment = 'Info: automatically converted from CASINO &
&Tabulated format'
IF (rel_== 0) THEN
upf_out%rel = 'no'
ELSEIF (rel_==1 ) THEN
upf_out%rel = 'scalar'
ELSE
upf_out%rel = 'full'
ENDIF
IF (xmin == 0 ) THEN
xmin= log(zmesh * r_(2) )
ENDIF
! Allocate and assign the raidal grid
upf_out%mesh = mesh_
upf_out%zmesh = zmesh
upf_out%dx = dx
upf_out%xmin = xmin
ALLOCATE(upf_out%rab(upf_out%mesh))
ALLOCATE( upf_out%r(upf_out%mesh))
upf_out%r = r_
DEALLOCATE( r_ )
upf_out%rmax = maxval(upf_out%r)
!
! subtract out the local part from the different
! potential channels
!
DO l = 0, lmax_
IF ( l/=lloc ) vnl(:,l) = vnl(:,l) - vnl(:,lloc)
ENDDO
ALLOCATE (upf_out%vloc(upf_out%mesh))
upf_out%vloc(:) = vnl(:,lloc)
! Compute the derivatives of the grid. The Trail and Needs
! grids use r(i) = (tn_prefac / zmesh)*( exp(i*dx) - 1 ) so
! must be treated differently to standard QE grids.
IF ( tn_grid ) THEN
DO ir = 1, upf_out%mesh
upf_out%rab(ir) = dx * ( upf_out%r(ir) + tn_prefac / zmesh )
ENDDO
ELSE
DO ir = 1, upf_out%mesh
upf_out%rab(ir) = dx * upf_out%r(ir)
ENDDO
ENDIF
!
! compute the atomic charges
!
ALLOCATE (upf_out%rho_at(upf_out%mesh))
upf_out%rho_at(:) = 0.d0
DO nb = 1, nchi
IF( oc_(nb)/=0.d0) THEN
upf_out%rho_at(:) = upf_out%rho_at(:) +&
& oc_(nb)*chi_(:,nb)**2
ENDIF
ENDDO
! This section deals with the pseudo wavefunctions.
! These values are just given directly to the pseudo_upf structure
upf_out%nwfc = nchi
ALLOCATE( upf_out%oc(upf_out%nwfc), upf_out%epseu(upf_out%nwfc) )
ALLOCATE( upf_out%lchi(upf_out%nwfc), upf_out%nchi(upf_out%nwfc) )
ALLOCATE( upf_out%els(upf_out%nwfc) )
ALLOCATE( upf_out%rcut_chi(upf_out%nwfc) )
ALLOCATE( upf_out%rcutus_chi (upf_out%nwfc) )
DO i=1, upf_out%nwfc
upf_out%nchi(i) = nns_(i)
upf_out%lchi(i) = lchi_(i)
upf_out%rcut_chi(i) = 0.0d0
upf_out%rcutus_chi(i)= 0.0d0
upf_out%oc (i) = oc_(i)
upf_out%els(i) = els_(i)
upf_out%epseu(i) = 0.0d0
ENDDO
DEALLOCATE (lchi_, oc_, nns_)
upf_out%psd = psd_
upf_out%typ = 'NC'
upf_out%nlcc = nlcc_
upf_out%zp = zp_
upf_out%etotps = 0.0d0
upf_out%ecutrho=0.0d0
upf_out%ecutwfc=0.0d0
upf_out%lloc=lloc
IF ( lmax_ == lloc) THEN
upf_out%lmax = lmax_-1
ELSE
upf_out%lmax = lmax_
ENDIF
upf_out%nbeta = lmax_
ALLOCATE ( upf_out%els_beta(upf_out%nbeta) )
ALLOCATE ( upf_out%rcut(upf_out%nbeta) )
ALLOCATE ( upf_out%rcutus(upf_out%nbeta) )
upf_out%rcut=0.0d0
upf_out%rcutus=0.0d0
upf_out%dft =dft_
IF (upf_out%nbeta > 0) THEN
ALLOCATE(upf_out%kbeta(upf_out%nbeta), upf_out%lll(upf_out%nbeta))
upf_out%kkbeta=upf_out%mesh
DO ir = 1,upf_out%mesh
IF ( upf_out%r(ir) > upf_out%rmax ) THEN
upf_out%kkbeta=ir
exit
ENDIF
ENDDO
! make sure kkbeta is odd as required for simpson
IF(mod(upf_out%kkbeta,2) == 0) upf_out%kkbeta=upf_out%kkbeta-1
upf_out%kbeta(:) = upf_out%kkbeta
ALLOCATE(aux(upf_out%kkbeta))
ALLOCATE(upf_out%beta(upf_out%mesh,upf_out%nbeta))
ALLOCATE(upf_out%dion(upf_out%nbeta,upf_out%nbeta))
upf_out%dion(:,:) =0.d0
iv=0
DO i=1,upf_out%nwfc
l=upf_out%lchi(i)
IF (l/=upf_out%lloc) THEN
iv=iv+1
upf_out%els_beta(iv)=upf_out%els(i)
upf_out%lll(iv)=l
DO ir=1,upf_out%kkbeta
upf_out%beta(ir,iv)=chi_(ir,i)*vnl(ir,l)
aux(ir) = chi_(ir,i)**2*vnl(ir,l)
ENDDO
CALL simpson(upf_out%kkbeta,aux,upf_out%rab,vll)
upf_out%dion(iv,iv) = 1.0d0/vll
ENDIF
IF(iv >= upf_out%nbeta) exit ! skip additional pseudo wfns
ENDDO
DEALLOCATE (vnl, aux)
!
! redetermine ikk2
!
DO iv=1,upf_out%nbeta
upf_out%kbeta(iv)=upf_out%kkbeta
DO ir = upf_out%kkbeta,1,-1
IF ( abs(upf_out%beta(ir,iv)) > 1.d-12 ) THEN
upf_out%kbeta(iv)=ir
exit
ENDIF
ENDDO
ENDDO
ENDIF
ALLOCATE (upf_out%chi(upf_out%mesh,upf_out%nwfc))
upf_out%chi = chi_
DEALLOCATE (chi_)
RETURN
END SUBROUTINE convert_casino
SUBROUTINE write_casino_tab(upf_in, grid)
USE upf_module
USE radial_grids, ONLY: radial_grid_type, deallocate_radial_grid
IMPLICIT NONE
TYPE(pseudo_upf), INTENT(in) :: upf_in
TYPE(radial_grid_type), INTENT(in) :: grid
INTEGER :: i, lp1
INTEGER, EXTERNAL :: atomic_number
WRITE(6,*) "Converted Pseudopotential in REAL space for ", upf_in%psd
WRITE(6,*) "Atomic number and pseudo-charge"
WRITE(6,"(I3,F8.2)") atomic_number( upf_in%psd ),upf_in%zp
WRITE(6,*) "Energy units (rydberg/hartree/ev):"
WRITE(6,*) "rydberg"
WRITE(6,*) "Angular momentum of local component (0=s,1=p,2=d..)"
WRITE(6,"(I2)") upf_in%lloc
WRITE(6,*) "NLRULE override (1) VMC/DMC (2) config gen (0 ==> &
&input/default VALUE)"
WRITE(6,*) "0 0"
WRITE(6,*) "Number of grid points"
WRITE(6,*) grid%mesh
WRITE(6,*) "R(i) in atomic units"
WRITE(6, "(T4,E22.15)") grid%r(:)
lp1 = size ( vnl, 2 )
DO i=1,lp1
WRITE(6, "(A,I1,A)") 'r*potential (L=',i-1,') in Ry'
WRITE(6, "(T4,E22.15)") vnl(:,i)
ENDDO
END SUBROUTINE write_casino_tab
SUBROUTINE conv_upf2casino(upf_in,grid)
USE upf_module
USE radial_grids, ONLY: radial_grid_type, deallocate_radial_grid
IMPLICIT NONE
TYPE(pseudo_upf), INTENT(in) :: upf_in
TYPE(radial_grid_type), INTENT(in) :: grid
INTEGER :: i, l, channels
REAL(dp), PARAMETER :: offset=1E-20_dp
!This is an offset added to the wavefunctions to
!eliminate any divide by zeros that may be caused by
!zeroed wavefunction terms.
channels=upf_in%nbeta+1
ALLOCATE ( vnl(grid%mesh,channels) )
!Set up the local component of each channel
DO i=1,channels
vnl(:,i)=grid%r(:)*upf_in%vloc(:)
ENDDO
DO i=1,upf_in%nbeta
l=upf_in%lll(i)+1
!Check if any wfc components have been zeroed
!and apply the offset IF they have
IF ( minval(abs(upf_in%chi(:,l))) /= 0 ) THEN
vnl(:,l)= (upf_in%beta(:,l)/(upf_in%chi(:,l)) &
*grid%r(:)) + vnl(:,l)
ELSE
WRITE(0,"(A,ES10.3,A)") 'Applying ',offset , ' offset to &
&wavefunction to avoid divide by zero'
vnl(:,l)= (upf_in%beta(:,l)/(upf_in%chi(:,l)+offset) &
*grid%r(:)) + vnl(:,l)
ENDIF
ENDDO
END SUBROUTINE conv_upf2casino
END MODULE casino_pp
| gpl-2.0 |
apollos/Quantum-ESPRESSO | lapack-3.2/TESTING/MATGEN/clarot.f | 6 | 10109 | SUBROUTINE CLAROT( LROWS, LLEFT, LRIGHT, NL, C, S, A, LDA, XLEFT,
$ XRIGHT )
*
* -- LAPACK auxiliary test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
LOGICAL LLEFT, LRIGHT, LROWS
INTEGER LDA, NL
COMPLEX C, S, XLEFT, XRIGHT
* ..
* .. Array Arguments ..
COMPLEX A( * )
* ..
*
* Purpose
* =======
*
* CLAROT applies a (Givens) rotation to two adjacent rows or
* columns, where one element of the first and/or last column/row
* for use on matrices stored in some format other than GE, so
* that elements of the matrix may be used or modified for which
* no array element is provided.
*
* One example is a symmetric matrix in SB format (bandwidth=4), for
* which UPLO='L': Two adjacent rows will have the format:
*
* row j: * * * * * . . . .
* row j+1: * * * * * . . . .
*
* '*' indicates elements for which storage is provided,
* '.' indicates elements for which no storage is provided, but
* are not necessarily zero; their values are determined by
* symmetry. ' ' indicates elements which are necessarily zero,
* and have no storage provided.
*
* Those columns which have two '*'s can be handled by SROT.
* Those columns which have no '*'s can be ignored, since as long
* as the Givens rotations are carefully applied to preserve
* symmetry, their values are determined.
* Those columns which have one '*' have to be handled separately,
* by using separate variables "p" and "q":
*
* row j: * * * * * p . . .
* row j+1: q * * * * * . . . .
*
* The element p would have to be set correctly, then that column
* is rotated, setting p to its new value. The next call to
* CLAROT would rotate columns j and j+1, using p, and restore
* symmetry. The element q would start out being zero, and be
* made non-zero by the rotation. Later, rotations would presumably
* be chosen to zero q out.
*
* Typical Calling Sequences: rotating the i-th and (i+1)-st rows.
* ------- ------- ---------
*
* General dense matrix:
*
* CALL CLAROT(.TRUE.,.FALSE.,.FALSE., N, C,S,
* A(i,1),LDA, DUMMY, DUMMY)
*
* General banded matrix in GB format:
*
* j = MAX(1, i-KL )
* NL = MIN( N, i+KU+1 ) + 1-j
* CALL CLAROT( .TRUE., i-KL.GE.1, i+KU.LT.N, NL, C,S,
* A(KU+i+1-j,j),LDA-1, XLEFT, XRIGHT )
*
* [ note that i+1-j is just MIN(i,KL+1) ]
*
* Symmetric banded matrix in SY format, bandwidth K,
* lower triangle only:
*
* j = MAX(1, i-K )
* NL = MIN( K+1, i ) + 1
* CALL CLAROT( .TRUE., i-K.GE.1, .TRUE., NL, C,S,
* A(i,j), LDA, XLEFT, XRIGHT )
*
* Same, but upper triangle only:
*
* NL = MIN( K+1, N-i ) + 1
* CALL CLAROT( .TRUE., .TRUE., i+K.LT.N, NL, C,S,
* A(i,i), LDA, XLEFT, XRIGHT )
*
* Symmetric banded matrix in SB format, bandwidth K,
* lower triangle only:
*
* [ same as for SY, except:]
* . . . .
* A(i+1-j,j), LDA-1, XLEFT, XRIGHT )
*
* [ note that i+1-j is just MIN(i,K+1) ]
*
* Same, but upper triangle only:
* . . .
* A(K+1,i), LDA-1, XLEFT, XRIGHT )
*
* Rotating columns is just the transpose of rotating rows, except
* for GB and SB: (rotating columns i and i+1)
*
* GB:
* j = MAX(1, i-KU )
* NL = MIN( N, i+KL+1 ) + 1-j
* CALL CLAROT( .TRUE., i-KU.GE.1, i+KL.LT.N, NL, C,S,
* A(KU+j+1-i,i),LDA-1, XTOP, XBOTTM )
*
* [note that KU+j+1-i is just MAX(1,KU+2-i)]
*
* SB: (upper triangle)
*
* . . . . . .
* A(K+j+1-i,i),LDA-1, XTOP, XBOTTM )
*
* SB: (lower triangle)
*
* . . . . . .
* A(1,i),LDA-1, XTOP, XBOTTM )
*
* Arguments
* =========
*
* LROWS - LOGICAL
* If .TRUE., then CLAROT will rotate two rows. If .FALSE.,
* then it will rotate two columns.
* Not modified.
*
* LLEFT - LOGICAL
* If .TRUE., then XLEFT will be used instead of the
* corresponding element of A for the first element in the
* second row (if LROWS=.FALSE.) or column (if LROWS=.TRUE.)
* If .FALSE., then the corresponding element of A will be
* used.
* Not modified.
*
* LRIGHT - LOGICAL
* If .TRUE., then XRIGHT will be used instead of the
* corresponding element of A for the last element in the
* first row (if LROWS=.FALSE.) or column (if LROWS=.TRUE.) If
* .FALSE., then the corresponding element of A will be used.
* Not modified.
*
* NL - INTEGER
* The length of the rows (if LROWS=.TRUE.) or columns (if
* LROWS=.FALSE.) to be rotated. If XLEFT and/or XRIGHT are
* used, the columns/rows they are in should be included in
* NL, e.g., if LLEFT = LRIGHT = .TRUE., then NL must be at
* least 2. The number of rows/columns to be rotated
* exclusive of those involving XLEFT and/or XRIGHT may
* not be negative, i.e., NL minus how many of LLEFT and
* LRIGHT are .TRUE. must be at least zero; if not, XERBLA
* will be called.
* Not modified.
*
* C, S - COMPLEX
* Specify the Givens rotation to be applied. If LROWS is
* true, then the matrix ( c s )
* ( _ _ )
* (-s c ) is applied from the left;
* if false, then the transpose (not conjugated) thereof is
* applied from the right. Note that in contrast to the
* output of CROTG or to most versions of CROT, both C and S
* are complex. For a Givens rotation, |C|**2 + |S|**2 should
* be 1, but this is not checked.
* Not modified.
*
* A - COMPLEX array.
* The array containing the rows/columns to be rotated. The
* first element of A should be the upper left element to
* be rotated.
* Read and modified.
*
* LDA - INTEGER
* The "effective" leading dimension of A. If A contains
* a matrix stored in GE, HE, or SY format, then this is just
* the leading dimension of A as dimensioned in the calling
* routine. If A contains a matrix stored in band (GB, HB, or
* SB) format, then this should be *one less* than the leading
* dimension used in the calling routine. Thus, if A were
* dimensioned A(LDA,*) in CLAROT, then A(1,j) would be the
* j-th element in the first of the two rows to be rotated,
* and A(2,j) would be the j-th in the second, regardless of
* how the array may be stored in the calling routine. [A
* cannot, however, actually be dimensioned thus, since for
* band format, the row number may exceed LDA, which is not
* legal FORTRAN.]
* If LROWS=.TRUE., then LDA must be at least 1, otherwise
* it must be at least NL minus the number of .TRUE. values
* in XLEFT and XRIGHT.
* Not modified.
*
* XLEFT - COMPLEX
* If LLEFT is .TRUE., then XLEFT will be used and modified
* instead of A(2,1) (if LROWS=.TRUE.) or A(1,2)
* (if LROWS=.FALSE.).
* Read and modified.
*
* XRIGHT - COMPLEX
* If LRIGHT is .TRUE., then XRIGHT will be used and modified
* instead of A(1,NL) (if LROWS=.TRUE.) or A(NL,1)
* (if LROWS=.FALSE.).
* Read and modified.
*
* =====================================================================
*
* .. Local Scalars ..
INTEGER IINC, INEXT, IX, IY, IYT, J, NT
COMPLEX TEMPX
* ..
* .. Local Arrays ..
COMPLEX XT( 2 ), YT( 2 )
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC CONJG
* ..
* .. Executable Statements ..
*
* Set up indices, arrays for ends
*
IF( LROWS ) THEN
IINC = LDA
INEXT = 1
ELSE
IINC = 1
INEXT = LDA
END IF
*
IF( LLEFT ) THEN
NT = 1
IX = 1 + IINC
IY = 2 + LDA
XT( 1 ) = A( 1 )
YT( 1 ) = XLEFT
ELSE
NT = 0
IX = 1
IY = 1 + INEXT
END IF
*
IF( LRIGHT ) THEN
IYT = 1 + INEXT + ( NL-1 )*IINC
NT = NT + 1
XT( NT ) = XRIGHT
YT( NT ) = A( IYT )
END IF
*
* Check for errors
*
IF( NL.LT.NT ) THEN
CALL XERBLA( 'CLAROT', 4 )
RETURN
END IF
IF( LDA.LE.0 .OR. ( .NOT.LROWS .AND. LDA.LT.NL-NT ) ) THEN
CALL XERBLA( 'CLAROT', 8 )
RETURN
END IF
*
* Rotate
*
* CROT( NL-NT, A(IX),IINC, A(IY),IINC, C, S ) with complex C, S
*
DO 10 J = 0, NL - NT - 1
TEMPX = C*A( IX+J*IINC ) + S*A( IY+J*IINC )
A( IY+J*IINC ) = -CONJG( S )*A( IX+J*IINC ) +
$ CONJG( C )*A( IY+J*IINC )
A( IX+J*IINC ) = TEMPX
10 CONTINUE
*
* CROT( NT, XT,1, YT,1, C, S ) with complex C, S
*
DO 20 J = 1, NT
TEMPX = C*XT( J ) + S*YT( J )
YT( J ) = -CONJG( S )*XT( J ) + CONJG( C )*YT( J )
XT( J ) = TEMPX
20 CONTINUE
*
* Stuff values back into XLEFT, XRIGHT, etc.
*
IF( LLEFT ) THEN
A( 1 ) = XT( 1 )
XLEFT = YT( 1 )
END IF
*
IF( LRIGHT ) THEN
XRIGHT = XT( NT )
A( IYT ) = YT( NT )
END IF
*
RETURN
*
* End of CLAROT
*
END
| gpl-2.0 |
sargas/scipy | scipy/interpolate/fitpack/fprppo.f | 148 | 1543 | subroutine fprppo(nu,nv,if1,if2,cosi,ratio,c,f,ncoff)
c given the coefficients of a constrained bicubic spline, as determined
c in subroutine fppola, subroutine fprppo calculates the coefficients
c in the standard b-spline representation of bicubic splines.
c ..
c ..scalar arguments..
real*8 ratio
integer nu,nv,if1,if2,ncoff
c ..array arguments
real*8 c(ncoff),f(ncoff),cosi(5,nv)
c ..local scalars..
integer i,iopt,ii,j,k,l,nu4,nvv
c ..
nu4 = nu-4
nvv = nv-7
iopt = if1+1
do 10 i=1,ncoff
f(i) = 0.
10 continue
i = 0
do 120 l=1,nu4
ii = i
if(l.gt.iopt) go to 80
go to (20,40,60),l
20 do 30 k=1,nvv
i = i+1
f(i) = c(1)
30 continue
j = 1
go to 100
40 do 50 k=1,nvv
i = i+1
f(i) = c(1)+c(2)*cosi(1,k)+c(3)*cosi(2,k)
50 continue
j = 3
go to 100
60 do 70 k=1,nvv
i = i+1
f(i) = c(1)+ratio*(c(2)*cosi(1,k)+c(3)*cosi(2,k))+
* c(4)*cosi(3,k)+c(5)*cosi(4,k)+c(6)*cosi(5,k)
70 continue
j = 6
go to 100
80 if(l.eq.nu4 .and. if2.ne.0) go to 120
do 90 k=1,nvv
i = i+1
j = j+1
f(i) = c(j)
90 continue
100 do 110 k=1,3
ii = ii+1
i = i+1
f(i) = f(ii)
110 continue
120 continue
do 130 i=1,ncoff
c(i) = f(i)
130 continue
return
end
| bsd-3-clause |
thewtex/ITK | Modules/ThirdParty/VNL/src/vxl/v3p/netlib/eispack/reduc.f | 41 | 3555 | subroutine reduc(nm,n,a,b,dl,ierr)
c
integer i,j,k,n,i1,j1,nm,nn,ierr
double precision a(nm,n),b(nm,n),dl(n)
double precision x,y
c
c this subroutine is a translation of the algol procedure reduc1,
c num. math. 11, 99-110(1968) by martin and wilkinson.
c handbook for auto. comp., vol.ii-linear algebra, 303-314(1971).
c
c this subroutine reduces the generalized symmetric eigenproblem
c ax=(lambda)bx, where b is positive definite, to the standard
c symmetric eigenproblem using the cholesky factorization of b.
c
c on input
c
c nm must be set to the row dimension of two-dimensional
c array parameters as declared in the calling program
c dimension statement.
c
c n is the order of the matrices a and b. if the cholesky
c factor l of b is already available, n should be prefixed
c with a minus sign.
c
c a and b contain the real symmetric input matrices. only the
c full upper triangles of the matrices need be supplied. if
c n is negative, the strict lower triangle of b contains,
c instead, the strict lower triangle of its cholesky factor l.
c
c dl contains, if n is negative, the diagonal elements of l.
c
c on output
c
c a contains in its full lower triangle the full lower triangle
c of the symmetric matrix derived from the reduction to the
c standard form. the strict upper triangle of a is unaltered.
c
c b contains in its strict lower triangle the strict lower
c triangle of its cholesky factor l. the full upper
c triangle of b is unaltered.
c
c dl contains the diagonal elements of l.
c
c ierr is set to
c zero for normal return,
c 7*n+1 if b is not positive definite.
c
c questions and comments should be directed to burton s. garbow,
c mathematics and computer science div, argonne national laboratory
c
c this version dated august 1983.
c
c ------------------------------------------------------------------
c
ierr = 0
nn = iabs(n)
if (n .lt. 0) go to 100
c .......... form l in the arrays b and dl ..........
do 80 i = 1, n
i1 = i - 1
c
do 80 j = i, n
x = b(i,j)
if (i .eq. 1) go to 40
c
do 20 k = 1, i1
20 x = x - b(i,k) * b(j,k)
c
40 if (j .ne. i) go to 60
if (x .le. 0.0d0) go to 1000
y = dsqrt(x)
dl(i) = y
go to 80
60 b(j,i) = x / y
80 continue
c .......... form the transpose of the upper triangle of inv(l)*a
c in the lower triangle of the array a ..........
100 do 200 i = 1, nn
i1 = i - 1
y = dl(i)
c
do 200 j = i, nn
x = a(i,j)
if (i .eq. 1) go to 180
c
do 160 k = 1, i1
160 x = x - b(i,k) * a(j,k)
c
180 a(j,i) = x / y
200 continue
c .......... pre-multiply by inv(l) and overwrite ..........
do 300 j = 1, nn
j1 = j - 1
c
do 300 i = j, nn
x = a(i,j)
if (i .eq. j) go to 240
i1 = i - 1
c
do 220 k = j, i1
220 x = x - a(k,j) * b(i,k)
c
240 if (j .eq. 1) go to 280
c
do 260 k = 1, j1
260 x = x - a(j,k) * b(i,k)
c
280 a(i,j) = x / dl(i)
300 continue
c
go to 1001
c .......... set error -- b is not positive definite ..........
1000 ierr = 7 * n + 1
1001 return
end
| apache-2.0 |
apollos/Quantum-ESPRESSO | PHonon/PH/addusdbec.f90 | 5 | 3393 | !
! Copyright (C) 2001-2008 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!
!----------------------------------------------------------------------
subroutine addusdbec (ik, wgt, psi, dbecsum)
!----------------------------------------------------------------------
!
! This routine adds to dbecsum the contribution of this
! k point. It implements Eq. B15 of PRB 64, 235118 (2001).
!
USE kinds, only : DP
USE ions_base, ONLY : nat, ityp, ntyp => nsp
USE becmod, ONLY : calbec
USE wvfct, only: npw, npwx, nbnd
USE uspp, only: nkb, vkb, okvan, ijtoh
USE uspp_param, only: upf, nh, nhm
USE phus, ONLY : becp1
USE qpoint, ONLY : npwq, ikks
USE control_ph, ONLY : nbnd_occ
!
USE mp_bands, ONLY : intra_bgrp_comm
!
implicit none
!
! the dummy variables
!
complex(DP) :: dbecsum (nhm*(nhm+1)/2, nat), psi(npwx,nbnd)
! inp/out: the sum kv of bec *
! input : contains delta psi
integer :: ik
! input: the k point
real(DP) :: wgt
! input: the weight of this k point
!
! here the local variables
!
integer :: na, nt, ih, jh, ibnd, ikk, ikb, jkb, ijh, startb, &
lastb, ijkb0
! counter on atoms
! counter on atomic type
! counter on solid beta functions
! counter on solid beta functions
! counter on the bands
! the real k point
! counter on solid becp
! counter on solid becp
! composite index for dbecsum
! divide among processors the sum
! auxiliary variable for counting
complex(DP), allocatable :: dbecq (:,:)
! the change of becq
if (.not.okvan) return
call start_clock ('addusdbec')
allocate (dbecq( nkb, nbnd))
ikk = ikks(ik)
!
! First compute the product of psi and vkb
!
call calbec (npwq, vkb, psi, dbecq)
!
! And then we add the product to becsum
!
! Band parallelization: each processor takes care of its slice of bands
!
call divide (intra_bgrp_comm, nbnd_occ (ikk), startb, lastb)
!
ijkb0 = 0
do nt = 1, ntyp
if (upf(nt)%tvanp ) then
do na = 1, nat
if (ityp (na) .eq.nt) then
!
! And qgmq and becp and dbecq
!
do ih = 1, nh(nt)
ikb = ijkb0 + ih
ijh=ijtoh(ih,ih,nt)
do ibnd = startb, lastb
dbecsum (ijh, na) = dbecsum (ijh, na) + &
wgt * ( CONJG(becp1(ik)%k(ikb,ibnd)) * dbecq(ikb,ibnd) )
enddo
do jh = ih + 1, nh (nt)
ijh=ijtoh(ih,jh,nt)
jkb = ijkb0 + jh
do ibnd = startb, lastb
dbecsum (ijh, na) = dbecsum (ijh, na) + &
wgt*( CONJG(becp1(ik)%k(ikb,ibnd))*dbecq(jkb,ibnd) + &
CONJG(becp1(ik)%k(jkb,ibnd))*dbecq(ikb,ibnd) )
enddo
ijh = ijh + 1
enddo
enddo
ijkb0 = ijkb0 + nh (nt)
endif
enddo
else
do na = 1, nat
if (ityp (na) .eq.nt) ijkb0 = ijkb0 + nh (nt)
enddo
endif
enddo
!
deallocate (dbecq)
call stop_clock ('addusdbec')
return
end subroutine addusdbec
| gpl-2.0 |
xianyi/OpenBLAS | lapack-netlib/SRC/dlasv2.f | 4 | 8428 | *> \brief \b DLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DLASV2 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasv2.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasv2.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasv2.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )
*
* .. Scalar Arguments ..
* DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DLASV2 computes the singular value decomposition of a 2-by-2
*> triangular matrix
*> [ F G ]
*> [ 0 H ].
*> On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the
*> smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and
*> right singular vectors for abs(SSMAX), giving the decomposition
*>
*> [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ]
*> [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ].
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] F
*> \verbatim
*> F is DOUBLE PRECISION
*> The (1,1) element of the 2-by-2 matrix.
*> \endverbatim
*>
*> \param[in] G
*> \verbatim
*> G is DOUBLE PRECISION
*> The (1,2) element of the 2-by-2 matrix.
*> \endverbatim
*>
*> \param[in] H
*> \verbatim
*> H is DOUBLE PRECISION
*> The (2,2) element of the 2-by-2 matrix.
*> \endverbatim
*>
*> \param[out] SSMIN
*> \verbatim
*> SSMIN is DOUBLE PRECISION
*> abs(SSMIN) is the smaller singular value.
*> \endverbatim
*>
*> \param[out] SSMAX
*> \verbatim
*> SSMAX is DOUBLE PRECISION
*> abs(SSMAX) is the larger singular value.
*> \endverbatim
*>
*> \param[out] SNL
*> \verbatim
*> SNL is DOUBLE PRECISION
*> \endverbatim
*>
*> \param[out] CSL
*> \verbatim
*> CSL is DOUBLE PRECISION
*> The vector (CSL, SNL) is a unit left singular vector for the
*> singular value abs(SSMAX).
*> \endverbatim
*>
*> \param[out] SNR
*> \verbatim
*> SNR is DOUBLE PRECISION
*> \endverbatim
*>
*> \param[out] CSR
*> \verbatim
*> CSR is DOUBLE PRECISION
*> The vector (CSR, SNR) is a unit right singular vector for the
*> singular value abs(SSMAX).
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup OTHERauxiliary
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> Any input parameter may be aliased with any output parameter.
*>
*> Barring over/underflow and assuming a guard digit in subtraction, all
*> output quantities are correct to within a few units in the last
*> place (ulps).
*>
*> In IEEE arithmetic, the code works correctly if one matrix element is
*> infinite.
*>
*> Overflow will not occur unless the largest singular value itself
*> overflows or is within a few ulps of overflow. (On machines with
*> partial overflow, like the Cray, overflow may occur if the largest
*> singular value is within a factor of 2 of overflow.)
*>
*> Underflow is harmless if underflow is gradual. Otherwise, results
*> may correspond to a matrix modified by perturbations of size near
*> the underflow threshold.
*> \endverbatim
*>
* =====================================================================
SUBROUTINE DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )
*
* -- LAPACK auxiliary routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D0 )
DOUBLE PRECISION HALF
PARAMETER ( HALF = 0.5D0 )
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D0 )
DOUBLE PRECISION TWO
PARAMETER ( TWO = 2.0D0 )
DOUBLE PRECISION FOUR
PARAMETER ( FOUR = 4.0D0 )
* ..
* .. Local Scalars ..
LOGICAL GASMAL, SWAP
INTEGER PMAX
DOUBLE PRECISION A, CLT, CRT, D, FA, FT, GA, GT, HA, HT, L, M,
$ MM, R, S, SLT, SRT, T, TEMP, TSIGN, TT
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, SIGN, SQRT
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH
EXTERNAL DLAMCH
* ..
* .. Executable Statements ..
*
FT = F
FA = ABS( FT )
HT = H
HA = ABS( H )
*
* PMAX points to the maximum absolute element of matrix
* PMAX = 1 if F largest in absolute values
* PMAX = 2 if G largest in absolute values
* PMAX = 3 if H largest in absolute values
*
PMAX = 1
SWAP = ( HA.GT.FA )
IF( SWAP ) THEN
PMAX = 3
TEMP = FT
FT = HT
HT = TEMP
TEMP = FA
FA = HA
HA = TEMP
*
* Now FA .ge. HA
*
END IF
GT = G
GA = ABS( GT )
IF( GA.EQ.ZERO ) THEN
*
* Diagonal matrix
*
SSMIN = HA
SSMAX = FA
CLT = ONE
CRT = ONE
SLT = ZERO
SRT = ZERO
ELSE
GASMAL = .TRUE.
IF( GA.GT.FA ) THEN
PMAX = 2
IF( ( FA / GA ).LT.DLAMCH( 'EPS' ) ) THEN
*
* Case of very large GA
*
GASMAL = .FALSE.
SSMAX = GA
IF( HA.GT.ONE ) THEN
SSMIN = FA / ( GA / HA )
ELSE
SSMIN = ( FA / GA )*HA
END IF
CLT = ONE
SLT = HT / GT
SRT = ONE
CRT = FT / GT
END IF
END IF
IF( GASMAL ) THEN
*
* Normal case
*
D = FA - HA
IF( D.EQ.FA ) THEN
*
* Copes with infinite F or H
*
L = ONE
ELSE
L = D / FA
END IF
*
* Note that 0 .le. L .le. 1
*
M = GT / FT
*
* Note that abs(M) .le. 1/macheps
*
T = TWO - L
*
* Note that T .ge. 1
*
MM = M*M
TT = T*T
S = SQRT( TT+MM )
*
* Note that 1 .le. S .le. 1 + 1/macheps
*
IF( L.EQ.ZERO ) THEN
R = ABS( M )
ELSE
R = SQRT( L*L+MM )
END IF
*
* Note that 0 .le. R .le. 1 + 1/macheps
*
A = HALF*( S+R )
*
* Note that 1 .le. A .le. 1 + abs(M)
*
SSMIN = HA / A
SSMAX = FA*A
IF( MM.EQ.ZERO ) THEN
*
* Note that M is very tiny
*
IF( L.EQ.ZERO ) THEN
T = SIGN( TWO, FT )*SIGN( ONE, GT )
ELSE
T = GT / SIGN( D, FT ) + M / T
END IF
ELSE
T = ( M / ( S+T )+M / ( R+L ) )*( ONE+A )
END IF
L = SQRT( T*T+FOUR )
CRT = TWO / L
SRT = T / L
CLT = ( CRT+SRT*M ) / A
SLT = ( HT / FT )*SRT / A
END IF
END IF
IF( SWAP ) THEN
CSL = SRT
SNL = CRT
CSR = SLT
SNR = CLT
ELSE
CSL = CLT
SNL = SLT
CSR = CRT
SNR = SRT
END IF
*
* Correct signs of SSMAX and SSMIN
*
IF( PMAX.EQ.1 )
$ TSIGN = SIGN( ONE, CSR )*SIGN( ONE, CSL )*SIGN( ONE, F )
IF( PMAX.EQ.2 )
$ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, CSL )*SIGN( ONE, G )
IF( PMAX.EQ.3 )
$ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, SNL )*SIGN( ONE, H )
SSMAX = SIGN( SSMAX, TSIGN )
SSMIN = SIGN( SSMIN, TSIGN*SIGN( ONE, F )*SIGN( ONE, H ) )
RETURN
*
* End of DLASV2
*
END
| bsd-3-clause |
xianyi/OpenBLAS | lapack-netlib/SRC/dgges3.f | 1 | 22639 | *> \brief <b> DGGES3 computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors for GE matrices (blocked algorithm)</b>
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DGGES3 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgges3.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgges3.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgges3.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DGGES3( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B, LDB,
* SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR,
* LDVSR, WORK, LWORK, BWORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER JOBVSL, JOBVSR, SORT
* INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM
* ..
* .. Array Arguments ..
* LOGICAL BWORK( * )
* DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
* $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ),
* $ VSR( LDVSR, * ), WORK( * )
* ..
* .. Function Arguments ..
* LOGICAL SELCTG
* EXTERNAL SELCTG
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DGGES3 computes for a pair of N-by-N real nonsymmetric matrices (A,B),
*> the generalized eigenvalues, the generalized real Schur form (S,T),
*> optionally, the left and/or right matrices of Schur vectors (VSL and
*> VSR). This gives the generalized Schur factorization
*>
*> (A,B) = ( (VSL)*S*(VSR)**T, (VSL)*T*(VSR)**T )
*>
*> Optionally, it also orders the eigenvalues so that a selected cluster
*> of eigenvalues appears in the leading diagonal blocks of the upper
*> quasi-triangular matrix S and the upper triangular matrix T.The
*> leading columns of VSL and VSR then form an orthonormal basis for the
*> corresponding left and right eigenspaces (deflating subspaces).
*>
*> (If only the generalized eigenvalues are needed, use the driver
*> DGGEV instead, which is faster.)
*>
*> A generalized eigenvalue for a pair of matrices (A,B) is a scalar w
*> or a ratio alpha/beta = w, such that A - w*B is singular. It is
*> usually represented as the pair (alpha,beta), as there is a
*> reasonable interpretation for beta=0 or both being zero.
*>
*> A pair of matrices (S,T) is in generalized real Schur form if T is
*> upper triangular with non-negative diagonal and S is block upper
*> triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond
*> to real generalized eigenvalues, while 2-by-2 blocks of S will be
*> "standardized" by making the corresponding elements of T have the
*> form:
*> [ a 0 ]
*> [ 0 b ]
*>
*> and the pair of corresponding 2-by-2 blocks in S and T will have a
*> complex conjugate pair of generalized eigenvalues.
*>
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] JOBVSL
*> \verbatim
*> JOBVSL is CHARACTER*1
*> = 'N': do not compute the left Schur vectors;
*> = 'V': compute the left Schur vectors.
*> \endverbatim
*>
*> \param[in] JOBVSR
*> \verbatim
*> JOBVSR is CHARACTER*1
*> = 'N': do not compute the right Schur vectors;
*> = 'V': compute the right Schur vectors.
*> \endverbatim
*>
*> \param[in] SORT
*> \verbatim
*> SORT is CHARACTER*1
*> Specifies whether or not to order the eigenvalues on the
*> diagonal of the generalized Schur form.
*> = 'N': Eigenvalues are not ordered;
*> = 'S': Eigenvalues are ordered (see SELCTG);
*> \endverbatim
*>
*> \param[in] SELCTG
*> \verbatim
*> SELCTG is a LOGICAL FUNCTION of three DOUBLE PRECISION arguments
*> SELCTG must be declared EXTERNAL in the calling subroutine.
*> If SORT = 'N', SELCTG is not referenced.
*> If SORT = 'S', SELCTG is used to select eigenvalues to sort
*> to the top left of the Schur form.
*> An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if
*> SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either
*> one of a complex conjugate pair of eigenvalues is selected,
*> then both complex eigenvalues are selected.
*>
*> Note that in the ill-conditioned case, a selected complex
*> eigenvalue may no longer satisfy SELCTG(ALPHAR(j),ALPHAI(j),
*> BETA(j)) = .TRUE. after ordering. INFO is to be set to N+2
*> in this case.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrices A, B, VSL, and VSR. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension (LDA, N)
*> On entry, the first of the pair of matrices.
*> On exit, A has been overwritten by its generalized Schur
*> form S.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] B
*> \verbatim
*> B is DOUBLE PRECISION array, dimension (LDB, N)
*> On entry, the second of the pair of matrices.
*> On exit, B has been overwritten by its generalized Schur
*> form T.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[out] SDIM
*> \verbatim
*> SDIM is INTEGER
*> If SORT = 'N', SDIM = 0.
*> If SORT = 'S', SDIM = number of eigenvalues (after sorting)
*> for which SELCTG is true. (Complex conjugate pairs for which
*> SELCTG is true for either eigenvalue count as 2.)
*> \endverbatim
*>
*> \param[out] ALPHAR
*> \verbatim
*> ALPHAR is DOUBLE PRECISION array, dimension (N)
*> \endverbatim
*>
*> \param[out] ALPHAI
*> \verbatim
*> ALPHAI is DOUBLE PRECISION array, dimension (N)
*> \endverbatim
*>
*> \param[out] BETA
*> \verbatim
*> BETA is DOUBLE PRECISION array, dimension (N)
*> On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
*> be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i,
*> and BETA(j),j=1,...,N are the diagonals of the complex Schur
*> form (S,T) that would result if the 2-by-2 diagonal blocks of
*> the real Schur form of (A,B) were further reduced to
*> triangular form using 2-by-2 complex unitary transformations.
*> If ALPHAI(j) is zero, then the j-th eigenvalue is real; if
*> positive, then the j-th and (j+1)-st eigenvalues are a
*> complex conjugate pair, with ALPHAI(j+1) negative.
*>
*> Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j)
*> may easily over- or underflow, and BETA(j) may even be zero.
*> Thus, the user should avoid naively computing the ratio.
*> However, ALPHAR and ALPHAI will be always less than and
*> usually comparable with norm(A) in magnitude, and BETA always
*> less than and usually comparable with norm(B).
*> \endverbatim
*>
*> \param[out] VSL
*> \verbatim
*> VSL is DOUBLE PRECISION array, dimension (LDVSL,N)
*> If JOBVSL = 'V', VSL will contain the left Schur vectors.
*> Not referenced if JOBVSL = 'N'.
*> \endverbatim
*>
*> \param[in] LDVSL
*> \verbatim
*> LDVSL is INTEGER
*> The leading dimension of the matrix VSL. LDVSL >=1, and
*> if JOBVSL = 'V', LDVSL >= N.
*> \endverbatim
*>
*> \param[out] VSR
*> \verbatim
*> VSR is DOUBLE PRECISION array, dimension (LDVSR,N)
*> If JOBVSR = 'V', VSR will contain the right Schur vectors.
*> Not referenced if JOBVSR = 'N'.
*> \endverbatim
*>
*> \param[in] LDVSR
*> \verbatim
*> LDVSR is INTEGER
*> The leading dimension of the matrix VSR. LDVSR >= 1, and
*> if JOBVSR = 'V', LDVSR >= N.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*> \endverbatim
*>
*> \param[in] LWORK
*> \verbatim
*> LWORK is INTEGER
*> The dimension of the array WORK.
*>
*> If LWORK = -1, then a workspace query is assumed; the routine
*> only calculates the optimal size of the WORK array, returns
*> this value as the first entry of the WORK array, and no error
*> message related to LWORK is issued by XERBLA.
*> \endverbatim
*>
*> \param[out] BWORK
*> \verbatim
*> BWORK is LOGICAL array, dimension (N)
*> Not referenced if SORT = 'N'.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value.
*> = 1,...,N:
*> The QZ iteration failed. (A,B) are not in Schur
*> form, but ALPHAR(j), ALPHAI(j), and BETA(j) should
*> be correct for j=INFO+1,...,N.
*> > N: =N+1: other than QZ iteration failed in DLAQZ0.
*> =N+2: after reordering, roundoff changed values of
*> some complex eigenvalues so that leading
*> eigenvalues in the Generalized Schur form no
*> longer satisfy SELCTG=.TRUE. This could also
*> be caused due to scaling.
*> =N+3: reordering failed in DTGSEN.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup doubleGEeigen
*
* =====================================================================
SUBROUTINE DGGES3( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B,
$ LDB, SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL,
$ VSR, LDVSR, WORK, LWORK, BWORK, INFO )
*
* -- LAPACK driver routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
CHARACTER JOBVSL, JOBVSR, SORT
INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM
* ..
* .. Array Arguments ..
LOGICAL BWORK( * )
DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
$ B( LDB, * ), BETA( * ), VSL( LDVSL, * ),
$ VSR( LDVSR, * ), WORK( * )
* ..
* .. Function Arguments ..
LOGICAL SELCTG
EXTERNAL SELCTG
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL CURSL, ILASCL, ILBSCL, ILVSL, ILVSR, LASTSL,
$ LQUERY, LST2SL, WANTST
INTEGER I, ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT,
$ ILO, IP, IRIGHT, IROWS, ITAU, IWRK, LWKOPT
DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PVSL,
$ PVSR, SAFMAX, SAFMIN, SMLNUM
* ..
* .. Local Arrays ..
INTEGER IDUM( 1 )
DOUBLE PRECISION DIF( 2 )
* ..
* .. External Subroutines ..
EXTERNAL DGEQRF, DGGBAK, DGGBAL, DGGHD3, DLAQZ0, DLABAD,
$ DLACPY, DLASCL, DLASET, DORGQR, DORMQR, DTGSEN,
$ XERBLA
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH, DLANGE
EXTERNAL LSAME, DLAMCH, DLANGE
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, SQRT
* ..
* .. Executable Statements ..
*
* Decode the input arguments
*
IF( LSAME( JOBVSL, 'N' ) ) THEN
IJOBVL = 1
ILVSL = .FALSE.
ELSE IF( LSAME( JOBVSL, 'V' ) ) THEN
IJOBVL = 2
ILVSL = .TRUE.
ELSE
IJOBVL = -1
ILVSL = .FALSE.
END IF
*
IF( LSAME( JOBVSR, 'N' ) ) THEN
IJOBVR = 1
ILVSR = .FALSE.
ELSE IF( LSAME( JOBVSR, 'V' ) ) THEN
IJOBVR = 2
ILVSR = .TRUE.
ELSE
IJOBVR = -1
ILVSR = .FALSE.
END IF
*
WANTST = LSAME( SORT, 'S' )
*
* Test the input arguments
*
INFO = 0
LQUERY = ( LWORK.EQ.-1 )
IF( IJOBVL.LE.0 ) THEN
INFO = -1
ELSE IF( IJOBVR.LE.0 ) THEN
INFO = -2
ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -5
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -7
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( LDVSL.LT.1 .OR. ( ILVSL .AND. LDVSL.LT.N ) ) THEN
INFO = -15
ELSE IF( LDVSR.LT.1 .OR. ( ILVSR .AND. LDVSR.LT.N ) ) THEN
INFO = -17
ELSE IF( LWORK.LT.6*N+16 .AND. .NOT.LQUERY ) THEN
INFO = -19
END IF
*
* Compute workspace
*
IF( INFO.EQ.0 ) THEN
CALL DGEQRF( N, N, B, LDB, WORK, WORK, -1, IERR )
LWKOPT = MAX( 6*N+16, 3*N+INT( WORK ( 1 ) ) )
CALL DORMQR( 'L', 'T', N, N, N, B, LDB, WORK, A, LDA, WORK,
$ -1, IERR )
LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) )
IF( ILVSL ) THEN
CALL DORGQR( N, N, N, VSL, LDVSL, WORK, WORK, -1, IERR )
LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) )
END IF
CALL DGGHD3( JOBVSL, JOBVSR, N, 1, N, A, LDA, B, LDB, VSL,
$ LDVSL, VSR, LDVSR, WORK, -1, IERR )
LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) )
CALL DLAQZ0( 'S', JOBVSL, JOBVSR, N, 1, N, A, LDA, B, LDB,
$ ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR,
$ WORK, -1, 0, IERR )
LWKOPT = MAX( LWKOPT, 2*N+INT( WORK ( 1 ) ) )
IF( WANTST ) THEN
CALL DTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB,
$ ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR,
$ SDIM, PVSL, PVSR, DIF, WORK, -1, IDUM, 1,
$ IERR )
LWKOPT = MAX( LWKOPT, 2*N+INT( WORK ( 1 ) ) )
END IF
WORK( 1 ) = LWKOPT
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DGGES3 ', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 ) THEN
SDIM = 0
RETURN
END IF
*
* Get machine constants
*
EPS = DLAMCH( 'P' )
SAFMIN = DLAMCH( 'S' )
SAFMAX = ONE / SAFMIN
CALL DLABAD( SAFMIN, SAFMAX )
SMLNUM = SQRT( SAFMIN ) / EPS
BIGNUM = ONE / SMLNUM
*
* Scale A if max element outside range [SMLNUM,BIGNUM]
*
ANRM = DLANGE( 'M', N, N, A, LDA, WORK )
ILASCL = .FALSE.
IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
ANRMTO = SMLNUM
ILASCL = .TRUE.
ELSE IF( ANRM.GT.BIGNUM ) THEN
ANRMTO = BIGNUM
ILASCL = .TRUE.
END IF
IF( ILASCL )
$ CALL DLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
*
* Scale B if max element outside range [SMLNUM,BIGNUM]
*
BNRM = DLANGE( 'M', N, N, B, LDB, WORK )
ILBSCL = .FALSE.
IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
BNRMTO = SMLNUM
ILBSCL = .TRUE.
ELSE IF( BNRM.GT.BIGNUM ) THEN
BNRMTO = BIGNUM
ILBSCL = .TRUE.
END IF
IF( ILBSCL )
$ CALL DLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
*
* Permute the matrix to make it more nearly triangular
*
ILEFT = 1
IRIGHT = N + 1
IWRK = IRIGHT + N
CALL DGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ),
$ WORK( IRIGHT ), WORK( IWRK ), IERR )
*
* Reduce B to triangular form (QR decomposition of B)
*
IROWS = IHI + 1 - ILO
ICOLS = N + 1 - ILO
ITAU = IWRK
IWRK = ITAU + IROWS
CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
$ WORK( IWRK ), LWORK+1-IWRK, IERR )
*
* Apply the orthogonal transformation to matrix A
*
CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
$ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
$ LWORK+1-IWRK, IERR )
*
* Initialize VSL
*
IF( ILVSL ) THEN
CALL DLASET( 'Full', N, N, ZERO, ONE, VSL, LDVSL )
IF( IROWS.GT.1 ) THEN
CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
$ VSL( ILO+1, ILO ), LDVSL )
END IF
CALL DORGQR( IROWS, IROWS, IROWS, VSL( ILO, ILO ), LDVSL,
$ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
END IF
*
* Initialize VSR
*
IF( ILVSR )
$ CALL DLASET( 'Full', N, N, ZERO, ONE, VSR, LDVSR )
*
* Reduce to generalized Hessenberg form
*
CALL DGGHD3( JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, VSL,
$ LDVSL, VSR, LDVSR, WORK( IWRK ), LWORK+1-IWRK,
$ IERR )
*
* Perform QZ algorithm, computing Schur vectors if desired
*
IWRK = ITAU
CALL DLAQZ0( 'S', JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB,
$ ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR,
$ WORK( IWRK ), LWORK+1-IWRK, 0, IERR )
IF( IERR.NE.0 ) THEN
IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
INFO = IERR
ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
INFO = IERR - N
ELSE
INFO = N + 1
END IF
GO TO 50
END IF
*
* Sort eigenvalues ALPHA/BETA if desired
*
SDIM = 0
IF( WANTST ) THEN
*
* Undo scaling on eigenvalues before SELCTGing
*
IF( ILASCL ) THEN
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N,
$ IERR )
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N,
$ IERR )
END IF
IF( ILBSCL )
$ CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
*
* Select eigenvalues
*
DO 10 I = 1, N
BWORK( I ) = SELCTG( ALPHAR( I ), ALPHAI( I ), BETA( I ) )
10 CONTINUE
*
CALL DTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB, ALPHAR,
$ ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, SDIM, PVSL,
$ PVSR, DIF, WORK( IWRK ), LWORK-IWRK+1, IDUM, 1,
$ IERR )
IF( IERR.EQ.1 )
$ INFO = N + 3
*
END IF
*
* Apply back-permutation to VSL and VSR
*
IF( ILVSL )
$ CALL DGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ),
$ WORK( IRIGHT ), N, VSL, LDVSL, IERR )
*
IF( ILVSR )
$ CALL DGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ),
$ WORK( IRIGHT ), N, VSR, LDVSR, IERR )
*
* Check if unscaling would cause over/underflow, if so, rescale
* (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of
* B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I)
*
IF( ILASCL ) THEN
DO 20 I = 1, N
IF( ALPHAI( I ).NE.ZERO ) THEN
IF( ( ALPHAR( I ) / SAFMAX ).GT.( ANRMTO / ANRM ) .OR.
$ ( SAFMIN / ALPHAR( I ) ).GT.( ANRM / ANRMTO ) ) THEN
WORK( 1 ) = ABS( A( I, I ) / ALPHAR( I ) )
BETA( I ) = BETA( I )*WORK( 1 )
ALPHAR( I ) = ALPHAR( I )*WORK( 1 )
ALPHAI( I ) = ALPHAI( I )*WORK( 1 )
ELSE IF( ( ALPHAI( I ) / SAFMAX ).GT.
$ ( ANRMTO / ANRM ) .OR.
$ ( SAFMIN / ALPHAI( I ) ).GT.( ANRM / ANRMTO ) )
$ THEN
WORK( 1 ) = ABS( A( I, I+1 ) / ALPHAI( I ) )
BETA( I ) = BETA( I )*WORK( 1 )
ALPHAR( I ) = ALPHAR( I )*WORK( 1 )
ALPHAI( I ) = ALPHAI( I )*WORK( 1 )
END IF
END IF
20 CONTINUE
END IF
*
IF( ILBSCL ) THEN
DO 30 I = 1, N
IF( ALPHAI( I ).NE.ZERO ) THEN
IF( ( BETA( I ) / SAFMAX ).GT.( BNRMTO / BNRM ) .OR.
$ ( SAFMIN / BETA( I ) ).GT.( BNRM / BNRMTO ) ) THEN
WORK( 1 ) = ABS( B( I, I ) / BETA( I ) )
BETA( I ) = BETA( I )*WORK( 1 )
ALPHAR( I ) = ALPHAR( I )*WORK( 1 )
ALPHAI( I ) = ALPHAI( I )*WORK( 1 )
END IF
END IF
30 CONTINUE
END IF
*
* Undo scaling
*
IF( ILASCL ) THEN
CALL DLASCL( 'H', 0, 0, ANRMTO, ANRM, N, N, A, LDA, IERR )
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR )
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR )
END IF
*
IF( ILBSCL ) THEN
CALL DLASCL( 'U', 0, 0, BNRMTO, BNRM, N, N, B, LDB, IERR )
CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
END IF
*
IF( WANTST ) THEN
*
* Check if reordering is correct
*
LASTSL = .TRUE.
LST2SL = .TRUE.
SDIM = 0
IP = 0
DO 40 I = 1, N
CURSL = SELCTG( ALPHAR( I ), ALPHAI( I ), BETA( I ) )
IF( ALPHAI( I ).EQ.ZERO ) THEN
IF( CURSL )
$ SDIM = SDIM + 1
IP = 0
IF( CURSL .AND. .NOT.LASTSL )
$ INFO = N + 2
ELSE
IF( IP.EQ.1 ) THEN
*
* Last eigenvalue of conjugate pair
*
CURSL = CURSL .OR. LASTSL
LASTSL = CURSL
IF( CURSL )
$ SDIM = SDIM + 2
IP = -1
IF( CURSL .AND. .NOT.LST2SL )
$ INFO = N + 2
ELSE
*
* First eigenvalue of conjugate pair
*
IP = 1
END IF
END IF
LST2SL = LASTSL
LASTSL = CURSL
40 CONTINUE
*
END IF
*
50 CONTINUE
*
WORK( 1 ) = LWKOPT
*
RETURN
*
* End of DGGES3
*
END
| bsd-3-clause |
apollos/Quantum-ESPRESSO | lapack-3.2/SRC/chetrf.f | 1 | 8886 | SUBROUTINE CHETRF( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )
*
* -- LAPACK routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDA, LWORK, N
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
COMPLEX A( LDA, * ), WORK( * )
* ..
*
* Purpose
* =======
*
* CHETRF computes the factorization of a complex Hermitian matrix A
* using the Bunch-Kaufman diagonal pivoting method. The form of the
* factorization is
*
* A = U*D*U**H or A = L*D*L**H
*
* where U (or L) is a product of permutation and unit upper (lower)
* triangular matrices, and D is Hermitian and block diagonal with
* 1-by-1 and 2-by-2 diagonal blocks.
*
* This is the blocked version of the algorithm, calling Level 3 BLAS.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* = 'U': Upper triangle of A is stored;
* = 'L': Lower triangle of A is stored.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* A (input/output) COMPLEX array, dimension (LDA,N)
* On entry, the Hermitian matrix A. If UPLO = 'U', the leading
* N-by-N upper triangular part of A contains the upper
* triangular part of the matrix A, and the strictly lower
* triangular part of A is not referenced. If UPLO = 'L', the
* leading N-by-N lower triangular part of A contains the lower
* triangular part of the matrix A, and the strictly upper
* triangular part of A is not referenced.
*
* On exit, the block diagonal matrix D and the multipliers used
* to obtain the factor U or L (see below for further details).
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* IPIV (output) INTEGER array, dimension (N)
* Details of the interchanges and the block structure of D.
* If IPIV(k) > 0, then rows and columns k and IPIV(k) were
* interchanged and D(k,k) is a 1-by-1 diagonal block.
* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) =
* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
*
* WORK (workspace/output) COMPLEX array, dimension (MAX(1,LWORK))
* On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*
* LWORK (input) INTEGER
* The length of WORK. LWORK >=1. For best performance
* LWORK >= N*NB, where NB is the block size returned by ILAENV.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, D(i,i) is exactly zero. The factorization
* has been completed, but the block diagonal matrix D is
* exactly singular, and division by zero will occur if it
* is used to solve a system of equations.
*
* Further Details
* ===============
*
* If UPLO = 'U', then A = U*D*U', where
* U = P(n)*U(n)* ... *P(k)U(k)* ...,
* i.e., U is a product of terms P(k)*U(k), where k decreases from n to
* 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
* defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
* that if the diagonal block D(k) is of order s (s = 1 or 2), then
*
* ( I v 0 ) k-s
* U(k) = ( 0 I 0 ) s
* ( 0 0 I ) n-k
* k-s s n-k
*
* If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
* If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
* and A(k,k), and v overwrites A(1:k-2,k-1:k).
*
* If UPLO = 'L', then A = L*D*L', where
* L = P(1)*L(1)* ... *P(k)*L(k)* ...,
* i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
* n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
* defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
* that if the diagonal block D(k) is of order s (s = 1 or 2), then
*
* ( I 0 0 ) k-1
* L(k) = ( 0 I 0 ) s
* ( 0 v I ) n-k-s+1
* k-1 s n-k-s+1
*
* If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
* If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
* and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
*
* =====================================================================
*
* .. Local Scalars ..
LOGICAL LQUERY, UPPER
INTEGER IINFO, IWS, J, K, KB, LDWORK, LWKOPT, NB, NBMIN
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILAENV
EXTERNAL LSAME, ILAENV
* ..
* .. External Subroutines ..
EXTERNAL CHETF2, CLAHEF, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
UPPER = LSAME( UPLO, 'U' )
LQUERY = ( LWORK.EQ.-1 )
IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -4
ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
INFO = -7
END IF
*
IF( INFO.EQ.0 ) THEN
*
* Determine the block size
*
NB = ILAENV( 1, 'CHETRF', UPLO, N, -1, -1, -1 )
LWKOPT = N*NB
WORK( 1 ) = LWKOPT
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CHETRF', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
NBMIN = 2
LDWORK = N
IF( NB.GT.1 .AND. NB.LT.N ) THEN
IWS = LDWORK*NB
IF( LWORK.LT.IWS ) THEN
NB = MAX( LWORK / LDWORK, 1 )
NBMIN = MAX( 2, ILAENV( 2, 'CHETRF', UPLO, N, -1, -1, -1 ) )
END IF
ELSE
IWS = 1
END IF
IF( NB.LT.NBMIN )
$ NB = N
*
IF( UPPER ) THEN
*
* Factorize A as U*D*U' using the upper triangle of A
*
* K is the main loop index, decreasing from N to 1 in steps of
* KB, where KB is the number of columns factorized by CLAHEF;
* KB is either NB or NB-1, or K for the last block
*
K = N
10 CONTINUE
*
* If K < 1, exit from loop
*
IF( K.LT.1 )
$ GO TO 40
*
IF( K.GT.NB ) THEN
*
* Factorize columns k-kb+1:k of A and use blocked code to
* update columns 1:k-kb
*
CALL CLAHEF( UPLO, K, NB, KB, A, LDA, IPIV, WORK, N, IINFO )
ELSE
*
* Use unblocked code to factorize columns 1:k of A
*
CALL CHETF2( UPLO, K, A, LDA, IPIV, IINFO )
KB = K
END IF
*
* Set INFO on the first occurrence of a zero pivot
*
IF( INFO.EQ.0 .AND. IINFO.GT.0 )
$ INFO = IINFO
*
* Decrease K and return to the start of the main loop
*
K = K - KB
GO TO 10
*
ELSE
*
* Factorize A as L*D*L' using the lower triangle of A
*
* K is the main loop index, increasing from 1 to N in steps of
* KB, where KB is the number of columns factorized by CLAHEF;
* KB is either NB or NB-1, or N-K+1 for the last block
*
K = 1
20 CONTINUE
*
* If K > N, exit from loop
*
IF( K.GT.N )
$ GO TO 40
*
IF( K.LE.N-NB ) THEN
*
* Factorize columns k:k+kb-1 of A and use blocked code to
* update columns k+kb:n
*
CALL CLAHEF( UPLO, N-K+1, NB, KB, A( K, K ), LDA, IPIV( K ),
$ WORK, N, IINFO )
ELSE
*
* Use unblocked code to factorize columns k:n of A
*
CALL CHETF2( UPLO, N-K+1, A( K, K ), LDA, IPIV( K ), IINFO )
KB = N - K + 1
END IF
*
* Set INFO on the first occurrence of a zero pivot
*
IF( INFO.EQ.0 .AND. IINFO.GT.0 )
$ INFO = IINFO + K - 1
*
* Adjust IPIV
*
DO 30 J = K, K + KB - 1
IF( IPIV( J ).GT.0 ) THEN
IPIV( J ) = IPIV( J ) + K - 1
ELSE
IPIV( J ) = IPIV( J ) - K + 1
END IF
30 CONTINUE
*
* Increase K and return to the start of the main loop
*
K = K + KB
GO TO 20
*
END IF
*
40 CONTINUE
WORK( 1 ) = LWKOPT
RETURN
*
* End of CHETRF
*
END
| gpl-2.0 |
apollos/Quantum-ESPRESSO | Modules/stick_set.f90 | 3 | 22694 | !
! Copyright (C) 2011 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 stick_set
!=----------------------------------------------------------------------=
! ... Distribute G-vectors across processors as sticks and planes,
! ... initialize FFT descriptors for both dense and smooth grids
! ... Most important dependencies: next three modules
USE stick_base
!
USE kinds, ONLY: DP
USE io_global, ONLY: ionode, stdout
USE fft_types, ONLY: fft_dlay_descriptor, fft_dlay_allocate, &
fft_dlay_set, fft_dlay_scalar
IMPLICIT NONE
PRIVATE
SAVE
PUBLIC :: pstickset, pstickset_custom
!=----------------------------------------------------------------------=
CONTAINS
!=----------------------------------------------------------------------=
SUBROUTINE pstickset( gamma_only, bg, gcut, gkcut, gcuts, &
dfftp, dffts, ngw, ngm, ngs, mype, root, nproc, comm, nogrp_ )
LOGICAL, INTENT(in) :: gamma_only
! ... bg(:,1), bg(:,2), bg(:,3) reciprocal space base vectors.
REAL(DP), INTENT(in) :: bg(3,3)
REAL(DP), INTENT(in) :: gcut, gkcut, gcuts
TYPE(fft_dlay_descriptor), INTENT(inout) :: dfftp, dffts
INTEGER, INTENT(out) :: ngw, ngm, ngs
INTEGER, INTENT(IN) :: mype, root, nproc, comm
INTEGER, INTENT(IN) :: nogrp_
LOGICAL :: tk
INTEGER :: ub(3), lb(3)
! ... ub(i), lb(i) upper and lower miller indexes
!
! ... Plane Waves
!
INTEGER, ALLOCATABLE :: stw(:,:)
! ... stick map (wave functions), stw(i,j) = number of G-vector in the
! ... stick whose x and y miller index are i and j
INTEGER, ALLOCATABLE :: nstpw(:)
! ... number of sticks (wave functions), nstpw(ip) = number of stick
! ... for processor ip
INTEGER, ALLOCATABLE :: sstpw(:)
! ... number of G-vectors (wave functions), sstpw(ip) = sum of the
! ... sticks length for processor ip = number of G-vectors
! ... owned by the processor ip
INTEGER :: nstw, nstpwx
! ... nstw local number of sticks (wave functions)
! ... nstpwx maximum among all processors of nstw
!
! ... Potentials
!
INTEGER, ALLOCATABLE :: st(:,:)
! ... stick map (potentials), st(i,j) = number of G-vector in the
! ... stick whose x and y miller index are i and j
INTEGER, ALLOCATABLE :: nstp(:)
! ... number of sticks (potentials), nstp(ip) = number of stick
! ... for processor ip
INTEGER, ALLOCATABLE :: sstp(:)
! ... number of G-vectors (potentials), sstp(ip) = sum of the
! ... sticks length for processor ip = number of G-vectors
! ... owned by the processor ip
INTEGER :: nst, nstpx
! ... nst local number of sticks (potentials)
! ... nstpx maximum among all processors of nst
!
! ... Smooth Mesh
!
INTEGER, ALLOCATABLE :: sts(:,:)
! ... stick map (smooth mesh), sts(i,j) = number of G-vector in the
! ... stick whose x and y miller index are i and j
INTEGER, ALLOCATABLE :: nstps(:)
! ... number of sticks (smooth mesh), nstp(ip) = number of stick
! ... for processor ip
INTEGER, ALLOCATABLE :: sstps(:)
! ... number of G-vectors (smooth mesh), sstps(ip) = sum of the
! ... sticks length for processor ip = number of G-vectors
! ... owned by the processor ip
INTEGER :: nsts
! ... nsts local number of sticks (smooth mesh)
INTEGER, ALLOCATABLE :: ist(:,:) ! sticks indices ordered
INTEGER :: ip, ngm_ , ngs_
INTEGER, ALLOCATABLE :: idx(:)
tk = .not. gamma_only
ub(1) = ( dfftp%nr1 - 1 ) / 2
ub(2) = ( dfftp%nr2 - 1 ) / 2
ub(3) = ( dfftp%nr3 - 1 ) / 2
lb = - ub
! ... Allocate maps
ALLOCATE( stw ( lb(1):ub(1), lb(2):ub(2) ) )
ALLOCATE( st ( lb(1):ub(1), lb(2):ub(2) ) )
ALLOCATE( sts ( lb(1):ub(1), lb(2):ub(2) ) )
st = 0
stw = 0
sts = 0
! ... Fill in the stick maps, for given g-space base and cut-off
CALL sticks_maps( tk, ub, lb, bg(:,1), bg(:,2), bg(:,3), &
gcut, gkcut, gcuts, st, stw, sts, mype, &
nproc, comm )
! ... Now count the number of stick nst and nstw
nst = count( st > 0 )
nstw = count( stw > 0 )
nsts = count( sts > 0 )
ALLOCATE(ist(nst,5))
ALLOCATE(nstp(nproc))
ALLOCATE(sstp(nproc))
ALLOCATE(nstpw(nproc))
ALLOCATE(sstpw(nproc))
ALLOCATE(nstps(nproc))
ALLOCATE(sstps(nproc))
! ... initialize the sticks indexes array ist
CALL sticks_countg( tk, ub, lb, st, stw, sts, &
ist(:,1), ist(:,2), ist(:,4), ist(:,3), ist(:,5) )
! ... Sorts the sticks according to their length
ALLOCATE( idx( nst ) )
CALL sticks_sort( ist(:,4), ist(:,3), ist(:,5), nst, idx, nproc )
! ... Set as first stick the stick containing the G=0
!
! DO iss = 1, nst
! IF( ist( idx( iss ), 1 ) == 0 .AND. ist( idx( iss ), 2 ) == 0 ) EXIT
! END DO
! itmp = idx( 1 )
! idx( 1 ) = idx( iss )
! idx( iss ) = itmp
CALL sticks_dist( tk, ub, lb, idx, ist(:,1), ist(:,2), ist(:,4), ist(:,3), ist(:,5), &
nst, nstp, nstpw, nstps, sstp, sstpw, sstps, st, stw, sts, nproc )
ngw = sstpw( mype + 1 )
ngm = sstp( mype + 1 )
ngs = sstps( mype + 1 )
CALL sticks_pairup( tk, ub, lb, idx, ist(:,1), ist(:,2), ist(:,4), ist(:,3), ist(:,5), &
nst, nstp, nstpw, nstps, sstp, sstpw, sstps, st, stw, sts, nproc )
! ... Allocate and Set fft data layout descriptors
#if defined __MPI
CALL fft_dlay_allocate( dfftp, mype, root, nproc, comm, nogrp_ , dfftp%nr1x, dfftp%nr2x )
CALL fft_dlay_allocate( dffts, mype, root, nproc, comm, nogrp_ , dffts%nr1x, dffts%nr2x )
CALL fft_dlay_set( dfftp, tk, nst, dfftp%nr1, dfftp%nr2, dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%nr3x, &
ub, lb, idx, ist(:,1), ist(:,2), nstp, nstpw, sstp, sstpw, st, stw )
CALL fft_dlay_set( dffts, tk, nsts, dffts%nr1, dffts%nr2, dffts%nr3, dffts%nr1x, dffts%nr2x, dffts%nr3x, &
ub, lb, idx, ist(:,1), ist(:,2), nstps, nstpw, sstps, sstpw, sts, stw )
#else
DEALLOCATE( stw )
ALLOCATE( stw( lb(2) : ub(2), lb(3) : ub(3) ) )
CALL sticks_maps_scalar( (.not.tk), ub, lb, bg(:,1),bg(:,2),bg(:,3),&
gcut, gkcut, gcuts, stw, ngm_ , ngs_ )
IF( ngm_ /= ngm ) CALL errore( ' pstickset ', ' inconsistent ngm ', abs( ngm - ngm_ ) )
IF( ngs_ /= ngs ) CALL errore( ' pstickset ', ' inconsistent ngs ', abs( ngs - ngs_ ) )
CALL fft_dlay_allocate( dfftp, mype, root, nproc, comm, 1, max(dfftp%nr1x, dfftp%nr3x), dfftp%nr2x )
CALL fft_dlay_allocate( dffts, mype, root, nproc, comm, 1, max(dffts%nr1x, dffts%nr3x), dffts%nr2x )
CALL fft_dlay_scalar( dfftp, ub, lb, dfftp%nr1, dfftp%nr2, dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%nr3x, stw )
CALL fft_dlay_scalar( dffts, ub, lb, dffts%nr1, dffts%nr2, dffts%nr3, dffts%nr1x, dffts%nr2x, dffts%nr3x, stw )
#endif
! ... Maximum number of sticks (potentials)
nstpx = maxval( nstp )
! ... Maximum number of sticks (wave func.)
nstpwx = maxval( nstpw )
IF( dffts%have_task_groups ) THEN
!
! Initialize task groups.
! Note that this call modify dffts adding task group data.
!
CALL task_groups_init( dffts )
!
END IF
IF (ionode) THEN
WRITE( stdout,*)
IF ( nproc > 1 ) THEN
WRITE( stdout, '(5X,"Parallelization info")')
ELSE
WRITE( stdout, '(5X,"G-vector sticks info")')
ENDIF
WRITE( stdout, '(5X,"--------------------")')
WRITE( stdout, '(5X,"sticks: dense smooth PW", &
& 5X,"G-vecs: dense smooth PW")')
IF ( nproc > 1 ) THEN
WRITE( stdout,'(5X,"Min",4X,2I8,I7,12X,2I9,I8)') &
minval(nstp), minval(nstps), minval(nstpw), &
minval(sstp), minval(sstps), minval(sstpw)
WRITE( stdout,'(5X,"Max",4X,2I8,I7,12X,2I9,I8)') &
maxval(nstp), maxval(nstps), maxval(nstpw), &
maxval(sstp), maxval(sstps), maxval(sstpw)
END IF
WRITE( stdout,'(5X,"Sum",4X,2I8,I7,12X,2I9,I8)') &
sum(nstp), sum(nstps), sum(nstpw), &
sum(sstp), sum(sstps), sum(sstpw)
! in the case k=0, the lines above and below differ:
! above all sticks, below only those in the half sphere
IF ( .NOT. tk ) &
WRITE( stdout,'(5X,"Tot",4X,2I8,I7)') nst, nsts, nstw
ENDIF
DEALLOCATE( ist )
DEALLOCATE( idx )
DEALLOCATE( st, stw, sts )
DEALLOCATE( sstp )
DEALLOCATE( nstp )
DEALLOCATE( sstpw )
DEALLOCATE( nstpw )
DEALLOCATE( sstps )
DEALLOCATE( nstps )
IF(ionode) WRITE( stdout,*)
RETURN
END SUBROUTINE pstickset
!----------------------------------------------------------------------
SUBROUTINE pstickset_custom( gamma_only, bg, gcut, gkcut, gcuts, &
dfftp, dffts, ngw, ngm, ngs, mype, root, nproc, comm, nogrp_ )
LOGICAL, INTENT(in) :: gamma_only
! ... bg(:,1), bg(:,2), bg(:,3) reciprocal space base vectors.
REAL(DP), INTENT(in) :: bg(3,3)
REAL(DP), INTENT(in) :: gcut, gkcut, gcuts
TYPE(fft_dlay_descriptor), INTENT(inout) :: dfftp, dffts
INTEGER, INTENT(inout) :: ngw, ngm, ngs
INTEGER, INTENT(IN) :: mype, root, nproc, comm
INTEGER, INTENT(IN) :: nogrp_
LOGICAL :: tk
INTEGER :: ub(3), lb(3)
! ... ub(i), lb(i) upper and lower miller indexes
!
! ... Plane Waves
!
INTEGER, ALLOCATABLE :: stw(:,:)
! ... stick map (wave functions), stw(i,j) = number of G-vector in the
! ... stick whose x and y miller index are i and j
INTEGER, ALLOCATABLE :: nstpw(:)
! ... number of sticks (wave functions), nstpw(ip) = number of stick
! ... for processor ip
INTEGER, ALLOCATABLE :: sstpw(:)
! ... number of G-vectors (wave functions), sstpw(ip) = sum of the
! ... sticks length for processor ip = number of G-vectors
! ... owned by the processor ip
INTEGER :: nstw, nstpwx
! ... nstw local number of sticks (wave functions)
! ... nstpwx maximum among all processors of nstw
!
! ... Potentials
!
INTEGER, ALLOCATABLE :: st(:,:)
! ... stick map (potentials), st(i,j) = number of G-vector in the
! ... stick whose x and y miller index are i and j
INTEGER, ALLOCATABLE :: nstp(:)
! ... number of sticks (potentials), nstp(ip) = number of stick
! ... for processor ip
INTEGER, ALLOCATABLE :: sstp(:)
! ... number of G-vectors (potentials), sstp(ip) = sum of the
! ... sticks length for processor ip = number of G-vectors
! ... owned by the processor ip
INTEGER :: nst, nstpx
! ... nst local number of sticks (potentials)
! ... nstpx maximum among all processors of nst
!
! ... Smooth Mesh
!
INTEGER, ALLOCATABLE :: sts(:,:)
! ... stick map (smooth mesh), sts(i,j) = number of G-vector in the
! ... stick whose x and y miller index are i and j
INTEGER, ALLOCATABLE :: nstps(:)
! ... number of sticks (smooth mesh), nstp(ip) = number of stick
! ... for processor ip
INTEGER, ALLOCATABLE :: sstps(:)
! ... number of G-vectors (smooth mesh), sstps(ip) = sum of the
! ... sticks length for processor ip = number of G-vectors
! ... owned by the processor ip
INTEGER :: nsts
! ... nsts local number of sticks (smooth mesh)
INTEGER, ALLOCATABLE :: ist(:,:) ! sticks indices ordered
INTEGER :: ip, ngm_ , ngs_
INTEGER, ALLOCATABLE :: idx(:)
tk = .not. gamma_only
ub(1) = ( dfftp%nr1 - 1 ) / 2
ub(2) = ( dfftp%nr2 - 1 ) / 2
ub(3) = ( dfftp%nr3 - 1 ) / 2
lb = - ub
! ... Allocate maps
ALLOCATE( stw ( lb(1):ub(1), lb(2):ub(2) ) )
ALLOCATE( st ( lb(1):ub(1), lb(2):ub(2) ) )
ALLOCATE( sts ( lb(1):ub(1), lb(2):ub(2) ) )
st = 0
stw = 0
sts = 0
! ... Fill in the stick maps, for given g-space base and cut-off
CALL sticks_maps( tk, ub, lb, bg(:,1), bg(:,2), bg(:,3), &
gcut, gkcut, gcuts, st, stw, sts, mype, &
nproc, comm )
! ... Now count the number of stick nst and nstw
nst = count( st > 0 )
nstw = count( stw > 0 )
nsts = count( sts > 0 )
ALLOCATE(ist(nst,5))
ALLOCATE(nstp(nproc))
ALLOCATE(sstp(nproc))
ALLOCATE(nstpw(nproc))
ALLOCATE(sstpw(nproc))
ALLOCATE(nstps(nproc))
ALLOCATE(sstps(nproc))
! ... initialize the sticks indexes array ist
CALL sticks_countg( tk, ub, lb, st, stw, sts, &
ist(:,1), ist(:,2), ist(:,4), ist(:,3), ist(:,5) )
! ... Sorts the sticks according to their length
ALLOCATE( idx( nst ) )
CALL sticks_sort( ist(:,4), ist(:,3), ist(:,5), nst, idx, nproc )
! ... Distribute the sticks as in dfftp
CALL sticks_ordered_dist( tk, ub, lb, idx, ist(:,1), ist(:,2), ist(:,4), ist(:,3), ist(:,5), &
nst, nstp, nstpw, nstps, sstp, sstpw, sstps, st, stw, sts, nproc )
ngw = sstpw( mype + 1 )
ngm = sstp( mype + 1 )
ngs = sstps( mype + 1 )
CALL sticks_pairup( tk, ub, lb, idx, ist(:,1), ist(:,2), ist(:,4), ist(:,3), ist(:,5), &
nst, nstp, nstpw, nstps, sstp, sstpw, sstps, st, stw, sts, nproc )
! ... Allocate and Set fft data layout descriptors
#if defined __MPI
CALL fft_dlay_allocate( dffts, mype, root, nproc, comm, nogrp_ , dffts%nr1x, dffts%nr2x )
CALL fft_dlay_set( dffts, tk, nsts, dffts%nr1, dffts%nr2, dffts%nr3, dffts%nr1x, dffts%nr2x, dffts%nr3x, &
ub, lb, idx, ist(:,1), ist(:,2), nstps, nstpw, sstps, sstpw, sts, stw )
#else
DEALLOCATE( stw )
ALLOCATE( stw( lb(2) : ub(2), lb(3) : ub(3) ) )
CALL sticks_maps_scalar( (.not.tk), ub, lb, bg(:,1),bg(:,2),bg(:,3),&
gcut, gkcut, gcuts, stw, ngm_ , ngs_ )
IF( ngs_ /= ngs ) CALL errore( ' pstickset_custom ', ' inconsistent ngs ', abs( ngs - ngs_ ) )
CALL fft_dlay_allocate( dffts, mype, root, nproc, comm, 1, max(dffts%nr1x, dffts%nr3x), dffts%nr2x )
CALL fft_dlay_scalar( dffts, ub, lb, dffts%nr1, dffts%nr2, dffts%nr3, dffts%nr1x, dffts%nr2x, dffts%nr3x, stw )
#endif
! ... Maximum number of sticks (potentials)
nstpx = maxval( nstp )
! ... Maximum number of sticks (wave func.)
nstpwx = maxval( nstpw )
DEALLOCATE( ist )
DEALLOCATE( idx )
DEALLOCATE( st, stw, sts )
DEALLOCATE( sstp )
DEALLOCATE( nstp )
DEALLOCATE( sstpw )
DEALLOCATE( nstpw )
DEALLOCATE( sstps )
DEALLOCATE( nstps )
IF(ionode) WRITE( stdout,*)
RETURN
END SUBROUTINE pstickset_custom
!-----------------------------------------
! Task groups Contributed by C. Bekas, October 2005
! Revised by C. Cavazzoni
!--------------------------------------------
SUBROUTINE task_groups_init( dffts )
USE parallel_include
!
USE io_global, ONLY : stdout
USE fft_types, ONLY : fft_dlay_descriptor
! T.G.
! NPGRP: Number of processors per group
! NOGRP: Number of processors per orbital task group
IMPLICIT NONE
TYPE(fft_dlay_descriptor), INTENT(inout) :: dffts
!----------------------------------
!Local Variables declaration
!----------------------------------
INTEGER :: I
INTEGER :: IERR
INTEGER :: num_planes, num_sticks
INTEGER :: nnrsx_vec ( dffts%nproc )
INTEGER :: pgroup( dffts%nproc )
INTEGER :: strd
CALL task_groups_init_first( dffts )
!
#ifdef DEBUG
IF ( dffts%nogrp > 1 ) WRITE( stdout, 100 ) dffts%nogrp, dffts%npgrp
100 FORMAT( /,3X,'Task Groups are in USE',/,3X,'groups and procs/group : ',I5,I5 )
#endif
!Find maximum chunk of local data concerning coefficients of eigenfunctions in g-space
#if defined __MPI
CALL MPI_Allgather( dffts%nnr, 1, MPI_INTEGER, nnrsx_vec, 1, MPI_INTEGER, dffts%comm, IERR)
strd = maxval( nnrsx_vec( 1:dffts%nproc ) )
#else
strd = dffts%nnr
#endif
IF( strd /= dffts%tg_nnr ) CALL errore( ' task_groups_init ', ' inconsistent nnr ', 1 )
!-------------------------------------------------------------------------------------
!C. Bekas...TASK GROUP RELATED. FFT DATA STRUCTURES ARE ALREADY DEFINED ABOVE
!-------------------------------------------------------------------------------------
!dfft%nsw(me) holds the number of z-sticks for the current processor per wave-function
!We can either send these in the group with an mpi_allgather...or put them
!in the PSIS vector (in special positions) and send them with them.
!Otherwise we can do this once at the beginning, before the loop.
!we choose to do the latter one.
!-------------------------------------------------------------------------------------
!
!
ALLOCATE( dffts%tg_nsw(dffts%nproc))
ALLOCATE( dffts%tg_npp(dffts%nproc))
num_sticks = 0
num_planes = 0
DO i = 1, dffts%nogrp
num_sticks = num_sticks + dffts%nsw( dffts%nolist(i) + 1 )
num_planes = num_planes + dffts%npp( dffts%nolist(i) + 1 )
ENDDO
#if defined __MPI
CALL MPI_ALLGATHER(num_sticks, 1, MPI_INTEGER, dffts%tg_nsw(1), 1, MPI_INTEGER, dffts%comm, IERR)
CALL MPI_ALLGATHER(num_planes, 1, MPI_INTEGER, dffts%tg_npp(1), 1, MPI_INTEGER, dffts%comm, IERR)
#else
dffts%tg_nsw(1) = num_sticks
dffts%tg_npp(1) = num_planes
#endif
ALLOCATE( dffts%tg_snd( dffts%nogrp ) )
ALLOCATE( dffts%tg_rcv( dffts%nogrp ) )
ALLOCATE( dffts%tg_psdsp( dffts%nogrp ) )
ALLOCATE( dffts%tg_usdsp( dffts%nogrp ) )
ALLOCATE( dffts%tg_rdsp( dffts%nogrp ) )
dffts%tg_snd(1) = dffts%nr3x * dffts%nsw( dffts%mype + 1 )
IF( dffts%nr3x * dffts%nsw( dffts%mype + 1 ) > dffts%tg_nnr ) THEN
CALL errore( ' task_groups_init ', ' inconsistent dffts%tg_nnr ', 1 )
ENDIF
dffts%tg_psdsp(1) = 0
dffts%tg_usdsp(1) = 0
dffts%tg_rcv(1) = dffts%nr3x * dffts%nsw( dffts%nolist(1) + 1 )
dffts%tg_rdsp(1) = 0
DO i = 2, dffts%nogrp
dffts%tg_snd(i) = dffts%nr3x * dffts%nsw( dffts%mype + 1 )
dffts%tg_psdsp(i) = dffts%tg_psdsp(i-1) + dffts%tg_nnr
dffts%tg_usdsp(i) = dffts%tg_usdsp(i-1) + dffts%tg_snd(i-1)
dffts%tg_rcv(i) = dffts%nr3x * dffts%nsw( dffts%nolist(i) + 1 )
dffts%tg_rdsp(i) = dffts%tg_rdsp(i-1) + dffts%tg_rcv(i-1)
ENDDO
RETURN
END SUBROUTINE task_groups_init
!
SUBROUTINE task_groups_init_first( dffts )
USE parallel_include
!
USE fft_types, ONLY : fft_dlay_descriptor
!
IMPLICIT NONE
!
TYPE(fft_dlay_descriptor), INTENT(inout) :: dffts
!
INTEGER :: i, n1, ipos, color, key, ierr, itsk, ntsk
INTEGER :: pgroup( dffts%nproc )
!
!SUBDIVIDE THE PROCESSORS IN GROUPS
!
DO i = 1, dffts%nproc
pgroup( i ) = i - 1
ENDDO
!
!LIST OF PROCESSORS IN MY ORBITAL GROUP
! (processors dealing with my same pw's of different orbitals)
!
! processors in these group have contiguous indexes
!
n1 = ( dffts%mype / dffts%nogrp ) * dffts%nogrp
ipos = dffts%mype - n1
DO i = 1, dffts%nogrp
dffts%nolist( i ) = pgroup( n1 + i )
ENDDO
!
!LIST OF PROCESSORS IN MY PLANE WAVE GROUP
! (processors dealing with different pw's of my same orbital)
!
DO i = 1, dffts%npgrp
dffts%nplist( i ) = pgroup( ipos + ( i - 1 ) * dffts%nogrp + 1 )
ENDDO
!
!SET UP THE GROUPS
!
!CREATE ORBITAL GROUPS
!
#if defined __MPI
! processes with the same color are in the same new communicator
color = dffts%mype / dffts%nogrp
key = MOD( dffts%mype , dffts%nogrp )
CALL MPI_COMM_SPLIT( dffts%comm, color, key, dffts%ogrp_comm, ierr )
if( ierr /= 0 ) &
CALL errore( ' task_groups_init_first ', ' creating ogrp_comm ', ABS(ierr) )
CALL MPI_COMM_RANK( dffts%ogrp_comm, itsk, IERR )
CALL MPI_COMM_SIZE( dffts%ogrp_comm, ntsk, IERR )
IF( dffts%nogrp /= ntsk ) CALL errore( ' task_groups_init_first ', ' ogrp_comm size ', ntsk )
DO i = 1, dffts%nogrp
IF( dffts%mype == dffts%nolist( i ) ) THEN
IF( (i-1) /= itsk ) CALL errore( ' task_groups_init_first ', ' ogrp_comm rank ', itsk )
END IF
END DO
#endif
!
!CREATE PLANEWAVE GROUPS
!
#if defined __MPI
! processes with the same color are in the same new communicator
color = MOD( dffts%mype , dffts%nogrp )
key = dffts%mype / dffts%nogrp
CALL MPI_COMM_SPLIT( dffts%comm, color, key, dffts%pgrp_comm, ierr )
if( ierr /= 0 ) &
CALL errore( ' task_groups_init_first ', ' creating pgrp_comm ', ABS(ierr) )
CALL MPI_COMM_RANK( dffts%pgrp_comm, itsk, IERR )
CALL MPI_COMM_SIZE( dffts%pgrp_comm, ntsk, IERR )
IF( dffts%npgrp /= ntsk ) CALL errore( ' task_groups_init_first ', ' pgrp_comm size ', ntsk )
DO i = 1, dffts%npgrp
IF( dffts%mype == dffts%nplist( i ) ) THEN
IF( (i-1) /= itsk ) CALL errore( ' task_groups_init_first ', ' pgrp_comm rank ', itsk )
END IF
END DO
dffts%me_pgrp = itsk
#endif
RETURN
END SUBROUTINE task_groups_init_first
!
!=----------------------------------------------------------------------=
END MODULE stick_set
!=----------------------------------------------------------------------=
| gpl-2.0 |
xianyi/OpenBLAS | lapack-netlib/TESTING/LIN/zdrvrfp.f | 1 | 19798 | *> \brief \b ZDRVRFP
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* SUBROUTINE ZDRVRFP( NOUT, NN, NVAL, NNS, NSVAL, NNT, NTVAL,
* + THRESH, A, ASAV, AFAC, AINV, B,
* + BSAV, XACT, X, ARF, ARFINV,
* + Z_WORK_ZLATMS, Z_WORK_ZPOT02,
* + Z_WORK_ZPOT03, D_WORK_ZLATMS, D_WORK_ZLANHE,
* + D_WORK_ZPOT01, D_WORK_ZPOT02, D_WORK_ZPOT03 )
*
* .. Scalar Arguments ..
* INTEGER NN, NNS, NNT, NOUT
* DOUBLE PRECISION THRESH
* ..
* .. Array Arguments ..
* INTEGER NVAL( NN ), NSVAL( NNS ), NTVAL( NNT )
* COMPLEX*16 A( * )
* COMPLEX*16 AINV( * )
* COMPLEX*16 ASAV( * )
* COMPLEX*16 B( * )
* COMPLEX*16 BSAV( * )
* COMPLEX*16 AFAC( * )
* COMPLEX*16 ARF( * )
* COMPLEX*16 ARFINV( * )
* COMPLEX*16 XACT( * )
* COMPLEX*16 X( * )
* COMPLEX*16 Z_WORK_ZLATMS( * )
* COMPLEX*16 Z_WORK_ZPOT02( * )
* COMPLEX*16 Z_WORK_ZPOT03( * )
* DOUBLE PRECISION D_WORK_ZLATMS( * )
* DOUBLE PRECISION D_WORK_ZLANHE( * )
* DOUBLE PRECISION D_WORK_ZPOT01( * )
* DOUBLE PRECISION D_WORK_ZPOT02( * )
* DOUBLE PRECISION D_WORK_ZPOT03( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZDRVRFP tests the LAPACK RFP routines:
*> ZPFTRF, ZPFTRS, and ZPFTRI.
*>
*> This testing routine follow the same tests as ZDRVPO (test for the full
*> format Symmetric Positive Definite solver).
*>
*> The tests are performed in Full Format, conversion back and forth from
*> full format to RFP format are performed using the routines ZTRTTF and
*> ZTFTTR.
*>
*> First, a specific matrix A of size N is created. There is nine types of
*> different matrixes possible.
*> 1. Diagonal 6. Random, CNDNUM = sqrt(0.1/EPS)
*> 2. Random, CNDNUM = 2 7. Random, CNDNUM = 0.1/EPS
*> *3. First row and column zero 8. Scaled near underflow
*> *4. Last row and column zero 9. Scaled near overflow
*> *5. Middle row and column zero
*> (* - tests error exits from ZPFTRF, no test ratios are computed)
*> A solution XACT of size N-by-NRHS is created and the associated right
*> hand side B as well. Then ZPFTRF is called to compute L (or U), the
*> Cholesky factor of A. Then L (or U) is used to solve the linear system
*> of equations AX = B. This gives X. Then L (or U) is used to compute the
*> inverse of A, AINV. The following four tests are then performed:
*> (1) norm( L*L' - A ) / ( N * norm(A) * EPS ) or
*> norm( U'*U - A ) / ( N * norm(A) * EPS ),
*> (2) norm(B - A*X) / ( norm(A) * norm(X) * EPS ),
*> (3) norm( I - A*AINV ) / ( N * norm(A) * norm(AINV) * EPS ),
*> (4) ( norm(X-XACT) * RCOND ) / ( norm(XACT) * EPS ),
*> where EPS is the machine precision, RCOND the condition number of A, and
*> norm( . ) the 1-norm for (1,2,3) and the inf-norm for (4).
*> Errors occur when INFO parameter is not as expected. Failures occur when
*> a test ratios is greater than THRES.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] NOUT
*> \verbatim
*> NOUT is INTEGER
*> The unit number for output.
*> \endverbatim
*>
*> \param[in] NN
*> \verbatim
*> NN is INTEGER
*> The number of values of N contained in the vector NVAL.
*> \endverbatim
*>
*> \param[in] NVAL
*> \verbatim
*> NVAL is INTEGER array, dimension (NN)
*> The values of the matrix dimension N.
*> \endverbatim
*>
*> \param[in] NNS
*> \verbatim
*> NNS is INTEGER
*> The number of values of NRHS contained in the vector NSVAL.
*> \endverbatim
*>
*> \param[in] NSVAL
*> \verbatim
*> NSVAL is INTEGER array, dimension (NNS)
*> The values of the number of right-hand sides NRHS.
*> \endverbatim
*>
*> \param[in] NNT
*> \verbatim
*> NNT is INTEGER
*> The number of values of MATRIX TYPE contained in the vector NTVAL.
*> \endverbatim
*>
*> \param[in] NTVAL
*> \verbatim
*> NTVAL is INTEGER array, dimension (NNT)
*> The values of matrix type (between 0 and 9 for PO/PP/PF matrices).
*> \endverbatim
*>
*> \param[in] THRESH
*> \verbatim
*> THRESH is DOUBLE PRECISION
*> The threshold value for the test ratios. A result is
*> included in the output file if RESULT >= THRESH. To have
*> every test ratio printed, use THRESH = 0.
*> \endverbatim
*>
*> \param[out] A
*> \verbatim
*> A is COMPLEX*16 array, dimension (NMAX*NMAX)
*> \endverbatim
*>
*> \param[out] ASAV
*> \verbatim
*> ASAV is COMPLEX*16 array, dimension (NMAX*NMAX)
*> \endverbatim
*>
*> \param[out] AFAC
*> \verbatim
*> AFAC is COMPLEX*16 array, dimension (NMAX*NMAX)
*> \endverbatim
*>
*> \param[out] AINV
*> \verbatim
*> AINV is COMPLEX*16 array, dimension (NMAX*NMAX)
*> \endverbatim
*>
*> \param[out] B
*> \verbatim
*> B is COMPLEX*16 array, dimension (NMAX*MAXRHS)
*> \endverbatim
*>
*> \param[out] BSAV
*> \verbatim
*> BSAV is COMPLEX*16 array, dimension (NMAX*MAXRHS)
*> \endverbatim
*>
*> \param[out] XACT
*> \verbatim
*> XACT is COMPLEX*16 array, dimension (NMAX*MAXRHS)
*> \endverbatim
*>
*> \param[out] X
*> \verbatim
*> X is COMPLEX*16 array, dimension (NMAX*MAXRHS)
*> \endverbatim
*>
*> \param[out] ARF
*> \verbatim
*> ARF is COMPLEX*16 array, dimension ((NMAX*(NMAX+1))/2)
*> \endverbatim
*>
*> \param[out] ARFINV
*> \verbatim
*> ARFINV is COMPLEX*16 array, dimension ((NMAX*(NMAX+1))/2)
*> \endverbatim
*>
*> \param[out] Z_WORK_ZLATMS
*> \verbatim
*> Z_WORK_ZLATMS is COMPLEX*16 array, dimension ( 3*NMAX )
*> \endverbatim
*>
*> \param[out] Z_WORK_ZPOT02
*> \verbatim
*> Z_WORK_ZPOT02 is COMPLEX*16 array, dimension ( NMAX*MAXRHS )
*> \endverbatim
*>
*> \param[out] Z_WORK_ZPOT03
*> \verbatim
*> Z_WORK_ZPOT03 is COMPLEX*16 array, dimension ( NMAX*NMAX )
*> \endverbatim
*>
*> \param[out] D_WORK_ZLATMS
*> \verbatim
*> D_WORK_ZLATMS is DOUBLE PRECISION array, dimension ( NMAX )
*> \endverbatim
*>
*> \param[out] D_WORK_ZLANHE
*> \verbatim
*> D_WORK_ZLANHE is DOUBLE PRECISION array, dimension ( NMAX )
*> \endverbatim
*>
*> \param[out] D_WORK_ZPOT01
*> \verbatim
*> D_WORK_ZPOT01 is DOUBLE PRECISION array, dimension ( NMAX )
*> \endverbatim
*>
*> \param[out] D_WORK_ZPOT02
*> \verbatim
*> D_WORK_ZPOT02 is DOUBLE PRECISION array, dimension ( NMAX )
*> \endverbatim
*>
*> \param[out] D_WORK_ZPOT03
*> \verbatim
*> D_WORK_ZPOT03 is DOUBLE PRECISION array, dimension ( NMAX )
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup complex16_lin
*
* =====================================================================
SUBROUTINE ZDRVRFP( NOUT, NN, NVAL, NNS, NSVAL, NNT, NTVAL,
+ THRESH, A, ASAV, AFAC, AINV, B,
+ BSAV, XACT, X, ARF, ARFINV,
+ Z_WORK_ZLATMS, Z_WORK_ZPOT02,
+ Z_WORK_ZPOT03, D_WORK_ZLATMS, D_WORK_ZLANHE,
+ D_WORK_ZPOT01, D_WORK_ZPOT02, D_WORK_ZPOT03 )
*
* -- LAPACK test routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
INTEGER NN, NNS, NNT, NOUT
DOUBLE PRECISION THRESH
* ..
* .. Array Arguments ..
INTEGER NVAL( NN ), NSVAL( NNS ), NTVAL( NNT )
COMPLEX*16 A( * )
COMPLEX*16 AINV( * )
COMPLEX*16 ASAV( * )
COMPLEX*16 B( * )
COMPLEX*16 BSAV( * )
COMPLEX*16 AFAC( * )
COMPLEX*16 ARF( * )
COMPLEX*16 ARFINV( * )
COMPLEX*16 XACT( * )
COMPLEX*16 X( * )
COMPLEX*16 Z_WORK_ZLATMS( * )
COMPLEX*16 Z_WORK_ZPOT02( * )
COMPLEX*16 Z_WORK_ZPOT03( * )
DOUBLE PRECISION D_WORK_ZLATMS( * )
DOUBLE PRECISION D_WORK_ZLANHE( * )
DOUBLE PRECISION D_WORK_ZPOT01( * )
DOUBLE PRECISION D_WORK_ZPOT02( * )
DOUBLE PRECISION D_WORK_ZPOT03( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
INTEGER NTESTS
PARAMETER ( NTESTS = 4 )
* ..
* .. Local Scalars ..
LOGICAL ZEROT
INTEGER I, INFO, IUPLO, LDA, LDB, IMAT, NERRS, NFAIL,
+ NRHS, NRUN, IZERO, IOFF, K, NT, N, IFORM, IIN,
+ IIT, IIS
CHARACTER DIST, CTYPE, UPLO, CFORM
INTEGER KL, KU, MODE
DOUBLE PRECISION ANORM, AINVNM, CNDNUM, RCONDC
* ..
* .. Local Arrays ..
CHARACTER UPLOS( 2 ), FORMS( 2 )
INTEGER ISEED( 4 ), ISEEDY( 4 )
DOUBLE PRECISION RESULT( NTESTS )
* ..
* .. External Functions ..
DOUBLE PRECISION ZLANHE
EXTERNAL ZLANHE
* ..
* .. External Subroutines ..
EXTERNAL ALADHD, ALAERH, ALASVM, ZGET04, ZTFTTR, ZLACPY,
+ ZLAIPD, ZLARHS, ZLATB4, ZLATMS, ZPFTRI, ZPFTRF,
+ ZPFTRS, ZPOT01, ZPOT02, ZPOT03, ZPOTRI, ZPOTRF,
+ ZTRTTF
* ..
* .. Scalars in Common ..
CHARACTER*32 SRNAMT
* ..
* .. Common blocks ..
COMMON / SRNAMC / SRNAMT
* ..
* .. Data statements ..
DATA ISEEDY / 1988, 1989, 1990, 1991 /
DATA UPLOS / 'U', 'L' /
DATA FORMS / 'N', 'C' /
* ..
* .. Executable Statements ..
*
* Initialize constants and the random number seed.
*
NRUN = 0
NFAIL = 0
NERRS = 0
DO 10 I = 1, 4
ISEED( I ) = ISEEDY( I )
10 CONTINUE
*
DO 130 IIN = 1, NN
*
N = NVAL( IIN )
LDA = MAX( N, 1 )
LDB = MAX( N, 1 )
*
DO 980 IIS = 1, NNS
*
NRHS = NSVAL( IIS )
*
DO 120 IIT = 1, NNT
*
IMAT = NTVAL( IIT )
*
* If N.EQ.0, only consider the first type
*
IF( N.EQ.0 .AND. IIT.GE.1 ) GO TO 120
*
* Skip types 3, 4, or 5 if the matrix size is too small.
*
IF( IMAT.EQ.4 .AND. N.LE.1 ) GO TO 120
IF( IMAT.EQ.5 .AND. N.LE.2 ) GO TO 120
*
* Do first for UPLO = 'U', then for UPLO = 'L'
*
DO 110 IUPLO = 1, 2
UPLO = UPLOS( IUPLO )
*
* Do first for CFORM = 'N', then for CFORM = 'C'
*
DO 100 IFORM = 1, 2
CFORM = FORMS( IFORM )
*
* Set up parameters with ZLATB4 and generate a test
* matrix with ZLATMS.
*
CALL ZLATB4( 'ZPO', IMAT, N, N, CTYPE, KL, KU,
+ ANORM, MODE, CNDNUM, DIST )
*
SRNAMT = 'ZLATMS'
CALL ZLATMS( N, N, DIST, ISEED, CTYPE,
+ D_WORK_ZLATMS,
+ MODE, CNDNUM, ANORM, KL, KU, UPLO, A,
+ LDA, Z_WORK_ZLATMS, INFO )
*
* Check error code from ZLATMS.
*
IF( INFO.NE.0 ) THEN
CALL ALAERH( 'ZPF', 'ZLATMS', INFO, 0, UPLO, N,
+ N, -1, -1, -1, IIT, NFAIL, NERRS,
+ NOUT )
GO TO 100
END IF
*
* For types 3-5, zero one row and column of the matrix to
* test that INFO is returned correctly.
*
ZEROT = IMAT.GE.3 .AND. IMAT.LE.5
IF( ZEROT ) THEN
IF( IIT.EQ.3 ) THEN
IZERO = 1
ELSE IF( IIT.EQ.4 ) THEN
IZERO = N
ELSE
IZERO = N / 2 + 1
END IF
IOFF = ( IZERO-1 )*LDA
*
* Set row and column IZERO of A to 0.
*
IF( IUPLO.EQ.1 ) THEN
DO 20 I = 1, IZERO - 1
A( IOFF+I ) = ZERO
20 CONTINUE
IOFF = IOFF + IZERO
DO 30 I = IZERO, N
A( IOFF ) = ZERO
IOFF = IOFF + LDA
30 CONTINUE
ELSE
IOFF = IZERO
DO 40 I = 1, IZERO - 1
A( IOFF ) = ZERO
IOFF = IOFF + LDA
40 CONTINUE
IOFF = IOFF - IZERO
DO 50 I = IZERO, N
A( IOFF+I ) = ZERO
50 CONTINUE
END IF
ELSE
IZERO = 0
END IF
*
* Set the imaginary part of the diagonals.
*
CALL ZLAIPD( N, A, LDA+1, 0 )
*
* Save a copy of the matrix A in ASAV.
*
CALL ZLACPY( UPLO, N, N, A, LDA, ASAV, LDA )
*
* Compute the condition number of A (RCONDC).
*
IF( ZEROT ) THEN
RCONDC = ZERO
ELSE
*
* Compute the 1-norm of A.
*
ANORM = ZLANHE( '1', UPLO, N, A, LDA,
+ D_WORK_ZLANHE )
*
* Factor the matrix A.
*
CALL ZPOTRF( UPLO, N, A, LDA, INFO )
*
* Form the inverse of A.
*
CALL ZPOTRI( UPLO, N, A, LDA, INFO )
IF ( N .NE. 0 ) THEN
*
* Compute the 1-norm condition number of A.
*
AINVNM = ZLANHE( '1', UPLO, N, A, LDA,
+ D_WORK_ZLANHE )
RCONDC = ( ONE / ANORM ) / AINVNM
*
* Restore the matrix A.
*
CALL ZLACPY( UPLO, N, N, ASAV, LDA, A, LDA )
END IF
*
END IF
*
* Form an exact solution and set the right hand side.
*
SRNAMT = 'ZLARHS'
CALL ZLARHS( 'ZPO', 'N', UPLO, ' ', N, N, KL, KU,
+ NRHS, A, LDA, XACT, LDA, B, LDA,
+ ISEED, INFO )
CALL ZLACPY( 'Full', N, NRHS, B, LDA, BSAV, LDA )
*
* Compute the L*L' or U'*U factorization of the
* matrix and solve the system.
*
CALL ZLACPY( UPLO, N, N, A, LDA, AFAC, LDA )
CALL ZLACPY( 'Full', N, NRHS, B, LDB, X, LDB )
*
SRNAMT = 'ZTRTTF'
CALL ZTRTTF( CFORM, UPLO, N, AFAC, LDA, ARF, INFO )
SRNAMT = 'ZPFTRF'
CALL ZPFTRF( CFORM, UPLO, N, ARF, INFO )
*
* Check error code from ZPFTRF.
*
IF( INFO.NE.IZERO ) THEN
*
* LANGOU: there is a small hick here: IZERO should
* always be INFO however if INFO is ZERO, ALAERH does not
* complain.
*
CALL ALAERH( 'ZPF', 'ZPFSV ', INFO, IZERO,
+ UPLO, N, N, -1, -1, NRHS, IIT,
+ NFAIL, NERRS, NOUT )
GO TO 100
END IF
*
* Skip the tests if INFO is not 0.
*
IF( INFO.NE.0 ) THEN
GO TO 100
END IF
*
SRNAMT = 'ZPFTRS'
CALL ZPFTRS( CFORM, UPLO, N, NRHS, ARF, X, LDB,
+ INFO )
*
SRNAMT = 'ZTFTTR'
CALL ZTFTTR( CFORM, UPLO, N, ARF, AFAC, LDA, INFO )
*
* Reconstruct matrix from factors and compute
* residual.
*
CALL ZLACPY( UPLO, N, N, AFAC, LDA, ASAV, LDA )
CALL ZPOT01( UPLO, N, A, LDA, AFAC, LDA,
+ D_WORK_ZPOT01, RESULT( 1 ) )
CALL ZLACPY( UPLO, N, N, ASAV, LDA, AFAC, LDA )
*
* Form the inverse and compute the residual.
*
IF(MOD(N,2).EQ.0)THEN
CALL ZLACPY( 'A', N+1, N/2, ARF, N+1, ARFINV,
+ N+1 )
ELSE
CALL ZLACPY( 'A', N, (N+1)/2, ARF, N, ARFINV,
+ N )
END IF
*
SRNAMT = 'ZPFTRI'
CALL ZPFTRI( CFORM, UPLO, N, ARFINV , INFO )
*
SRNAMT = 'ZTFTTR'
CALL ZTFTTR( CFORM, UPLO, N, ARFINV, AINV, LDA,
+ INFO )
*
* Check error code from ZPFTRI.
*
IF( INFO.NE.0 )
+ CALL ALAERH( 'ZPO', 'ZPFTRI', INFO, 0, UPLO, N,
+ N, -1, -1, -1, IMAT, NFAIL, NERRS,
+ NOUT )
*
CALL ZPOT03( UPLO, N, A, LDA, AINV, LDA,
+ Z_WORK_ZPOT03, LDA, D_WORK_ZPOT03,
+ RCONDC, RESULT( 2 ) )
*
* Compute residual of the computed solution.
*
CALL ZLACPY( 'Full', N, NRHS, B, LDA,
+ Z_WORK_ZPOT02, LDA )
CALL ZPOT02( UPLO, N, NRHS, A, LDA, X, LDA,
+ Z_WORK_ZPOT02, LDA, D_WORK_ZPOT02,
+ RESULT( 3 ) )
*
* Check solution from generated exact solution.
*
CALL ZGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC,
+ RESULT( 4 ) )
NT = 4
*
* Print information about the tests that did not
* pass the threshold.
*
DO 60 K = 1, NT
IF( RESULT( K ).GE.THRESH ) THEN
IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
+ CALL ALADHD( NOUT, 'ZPF' )
WRITE( NOUT, FMT = 9999 )'ZPFSV ', UPLO,
+ N, IIT, K, RESULT( K )
NFAIL = NFAIL + 1
END IF
60 CONTINUE
NRUN = NRUN + NT
100 CONTINUE
110 CONTINUE
120 CONTINUE
980 CONTINUE
130 CONTINUE
*
* Print a summary of the results.
*
CALL ALASVM( 'ZPF', NOUT, NFAIL, NRUN, NERRS )
*
9999 FORMAT( 1X, A6, ', UPLO=''', A1, ''', N =', I5, ', type ', I1,
+ ', test(', I1, ')=', G12.5 )
*
RETURN
*
* End of ZDRVRFP
*
END
| bsd-3-clause |
rmcgibbo/scipy | scipy/interpolate/fitpack/fpcoco.f | 148 | 5210 | subroutine fpcoco(iopt,m,x,y,w,v,s,nest,maxtr,maxbin,n,t,c,sq,sx,
* bind,e,wrk,lwrk,iwrk,kwrk,ier)
c ..scalar arguments..
real*8 s,sq
integer iopt,m,nest,maxtr,maxbin,n,lwrk,kwrk,ier
c ..array arguments..
integer iwrk(kwrk)
real*8 x(m),y(m),w(m),v(m),t(nest),c(nest),sx(m),e(nest),wrk(lwrk)
*
logical bind(nest)
c ..local scalars..
integer i,ia,ib,ic,iq,iu,iz,izz,i1,j,k,l,l1,m1,nmax,nr,n4,n6,n8,
* ji,jib,jjb,jl,jr,ju,mb,nm
real*8 sql,sqmax,term,tj,xi,half
c ..subroutine references..
c fpcosp,fpbspl,fpadno,fpdeno,fpseno,fpfrno
c ..
c set constant
half = 0.5e0
c determine the maximal admissible number of knots.
nmax = m+4
c the initial choice of knots depends on the value of iopt.
c if iopt=0 the program starts with the minimal number of knots
c so that can be guarantied that the concavity/convexity constraints
c will be satisfied.
c if iopt = 1 the program will continue from the point on where she
c left at the foregoing call.
if(iopt.gt.0) go to 80
c find the minimal number of knots.
c a knot is located at the data point x(i), i=2,3,...m-1 if
c 1) v(i) ^= 0 and
c 2) v(i)*v(i-1) <= 0 or v(i)*v(i+1) <= 0.
m1 = m-1
n = 4
do 20 i=2,m1
if(v(i).eq.0. .or. (v(i)*v(i-1).gt.0. .and.
* v(i)*v(i+1).gt.0.)) go to 20
n = n+1
c test whether the required storage space exceeds the available one.
if(n+4.gt.nest) go to 200
t(n) = x(i)
20 continue
c find the position of the knots t(1),...t(4) and t(n-3),...t(n) which
c are needed for the b-spline representation of s(x).
do 30 i=1,4
t(i) = x(1)
n = n+1
t(n) = x(m)
30 continue
c test whether the minimum number of knots exceeds the maximum number.
if(n.gt.nmax) go to 210
c main loop for the different sets of knots.
c find corresponding values e(j) to the knots t(j+3),j=1,2,...n-6
c e(j) will take the value -1,1, or 0 according to the requirement
c that s(x) must be locally convex or concave at t(j+3) or that the
c sign of s''(x) is unrestricted at that point.
40 i= 1
xi = x(1)
j = 4
tj = t(4)
n6 = n-6
do 70 l=1,n6
50 if(xi.eq.tj) go to 60
i = i+1
xi = x(i)
go to 50
60 e(l) = v(i)
j = j+1
tj = t(j)
70 continue
c we partition the working space
nm = n+maxbin
mb = maxbin+1
ia = 1
ib = ia+4*n
ic = ib+nm*maxbin
iz = ic+n
izz = iz+n
iu = izz+n
iq = iu+maxbin
ji = 1
ju = ji+maxtr
jl = ju+maxtr
jr = jl+maxtr
jjb = jr+maxtr
jib = jjb+mb
c given the set of knots t(j),j=1,2,...n, find the least-squares cubic
c spline which satisfies the imposed concavity/convexity constraints.
call fpcosp(m,x,y,w,n,t,e,maxtr,maxbin,c,sq,sx,bind,nm,mb,wrk(ia),
*
* wrk(ib),wrk(ic),wrk(iz),wrk(izz),wrk(iu),wrk(iq),iwrk(ji),
* iwrk(ju),iwrk(jl),iwrk(jr),iwrk(jjb),iwrk(jib),ier)
c if sq <= s or in case of abnormal exit from fpcosp, control is
c repassed to the driver program.
if(sq.le.s .or. ier.gt.0) go to 300
c calculate for each knot interval t(l-1) <= xi <= t(l) the
c sum((wi*(yi-s(xi)))**2).
c find the interval t(k-1) <= x <= t(k) for which this sum is maximal
c on the condition that this interval contains at least one interior
c data point x(nr) and that s(x) is not given there by a straight line.
80 sqmax = 0.
sql = 0.
l = 5
nr = 0
i1 = 1
n4 = n-4
do 110 i=1,m
term = (w(i)*(sx(i)-y(i)))**2
if(x(i).lt.t(l) .or. l.gt.n4) go to 100
term = term*half
sql = sql+term
if(i-i1.le.1 .or. (bind(l-4).and.bind(l-3))) go to 90
if(sql.le.sqmax) go to 90
k = l
sqmax = sql
nr = i1+(i-i1)/2
90 l = l+1
i1 = i
sql = 0.
100 sql = sql+term
110 continue
if(m-i1.le.1 .or. (bind(l-4).and.bind(l-3))) go to 120
if(sql.le.sqmax) go to 120
k = l
nr = i1+(m-i1)/2
c if no such interval is found, control is repassed to the driver
c program (ier = -1).
120 if(nr.eq.0) go to 190
c if s(x) is given by the same straight line in two succeeding knot
c intervals t(l-1) <= x <= t(l) and t(l) <= x <= t(l+1),delete t(l)
n8 = n-8
l1 = 0
if(n8.le.0) go to 150
do 140 i=1,n8
if(.not. (bind(i).and.bind(i+1).and.bind(i+2))) go to 140
l = i+4-l1
if(k.gt.l) k = k-1
n = n-1
l1 = l1+1
do 130 j=l,n
t(j) = t(j+1)
130 continue
140 continue
c test whether we cannot further increase the number of knots.
150 if(n.eq.nmax) go to 180
if(n.eq.nest) go to 170
c locate an additional knot at the point x(nr).
j = n
do 160 i=k,n
t(j+1) = t(j)
j = j-1
160 continue
t(k) = x(nr)
n = n+1
c restart the computations with the new set of knots.
go to 40
c error codes and messages.
170 ier = -3
go to 300
180 ier = -2
go to 300
190 ier = -1
go to 300
200 ier = 4
go to 300
210 ier = 5
300 return
end
| bsd-3-clause |
apollos/Quantum-ESPRESSO | COUPLE/src/libqemod.f90 | 18 | 1593 | !
! Copyright (C) 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 .
!
!==-----------------------------------------------------------------------==!
! Wrappers for accessing facilities in the Modules subdirectory
!----------------------------------------------------------------------------
! These init subroutines have to be outside of Fortran modules so they
! can be called from C/C++ or Fortran code
!==-----------------------------------------------------------------------==!
! Configure qm/mm interface for MPI message passing, C version
SUBROUTINE c2qmmm_mpi_config ( qmmm_mode, inter_comm, verb, steps ) BIND(C)
USE iso_c_binding
USE qmmm, ONLY: qmmm_config
IMPLICIT NONE
!
INTEGER(C_INT), VALUE, INTENT(in) :: qmmm_mode, inter_comm, verb, steps
CALL qmmm_config( mode=qmmm_mode, comm=inter_comm, verbose=verb, step=steps )
END SUBROUTINE c2qmmm_mpi_config
!==-----------------------------------------------------------------------==!
! Configure qm/mm interface for MPI message passing, Fortran version
SUBROUTINE f2qmmm_mpi_config ( qmmm_mode, inter_comm, verb, steps )
USE iso_c_binding
USE qmmm, ONLY: qmmm_config
IMPLICIT NONE
!
INTEGER, INTENT(in) :: qmmm_mode, inter_comm, verb, steps
CALL qmmm_config( mode=qmmm_mode, comm=inter_comm, verbose=verb, step=steps )
END SUBROUTINE f2qmmm_mpi_config
!==-----------------------------------------------------------------------==!
| gpl-2.0 |
apollos/Quantum-ESPRESSO | 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 |
xianyi/OpenBLAS | lapack-netlib/INSTALL/dsecnd_EXT_ETIME.f | 6 | 1457 | *> \brief \b DSECND Using ETIME
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* DOUBLE PRECISION FUNCTION DSECND( )
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DSECND returns the user time for a process in seconds.
*> This version gets the time from the EXTERNAL system function ETIME.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date December 2016
*
*> \ingroup auxOTHERauxiliary
*
* =====================================================================
DOUBLE PRECISION FUNCTION DSECND( )
*
* -- LAPACK auxiliary routine (version 3.7.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* December 2016
*
*
* =====================================================================
*
* .. Local Scalars ..
REAL T1
* ..
* .. Local Arrays ..
REAL TARRAY( 2 )
* ..
* .. External Functions ..
REAL ETIME
EXTERNAL ETIME
* ..
* .. Executable Statements ..
*
T1 = ETIME( TARRAY )
DSECND = TARRAY( 1 )
RETURN
*
* End of DSECND
*
END
| bsd-3-clause |
xianyi/OpenBLAS | lapack-netlib/SRC/dtgex2.f | 1 | 24727 | *> \brief \b DTGEX2 swaps adjacent diagonal blocks in an upper (quasi) triangular matrix pair by an orthogonal equivalence transformation.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DTGEX2 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgex2.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgex2.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgex2.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
* LDZ, J1, N1, N2, WORK, LWORK, INFO )
*
* .. Scalar Arguments ..
* LOGICAL WANTQ, WANTZ
* INTEGER INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2
* ..
* .. Array Arguments ..
* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
* $ WORK( * ), Z( LDZ, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DTGEX2 swaps adjacent diagonal blocks (A11, B11) and (A22, B22)
*> of size 1-by-1 or 2-by-2 in an upper (quasi) triangular matrix pair
*> (A, B) by an orthogonal equivalence transformation.
*>
*> (A, B) must be in generalized real Schur canonical form (as returned
*> by DGGES), i.e. A is block upper triangular with 1-by-1 and 2-by-2
*> diagonal blocks. B is upper triangular.
*>
*> Optionally, the matrices Q and Z of generalized Schur vectors are
*> updated.
*>
*> Q(in) * A(in) * Z(in)**T = Q(out) * A(out) * Z(out)**T
*> Q(in) * B(in) * Z(in)**T = Q(out) * B(out) * Z(out)**T
*>
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] WANTQ
*> \verbatim
*> WANTQ is LOGICAL
*> .TRUE. : update the left transformation matrix Q;
*> .FALSE.: do not update Q.
*> \endverbatim
*>
*> \param[in] WANTZ
*> \verbatim
*> WANTZ is LOGICAL
*> .TRUE. : update the right transformation matrix Z;
*> .FALSE.: do not update Z.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrices A and B. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimensions (LDA,N)
*> On entry, the matrix A in the pair (A, B).
*> On exit, the updated matrix A.
*> \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, dimensions (LDB,N)
*> On entry, the matrix B in the pair (A, B).
*> On exit, the updated 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] Q
*> \verbatim
*> Q is DOUBLE PRECISION array, dimension (LDQ,N)
*> On entry, if WANTQ = .TRUE., the orthogonal matrix Q.
*> On exit, the updated matrix Q.
*> Not referenced if WANTQ = .FALSE..
*> \endverbatim
*>
*> \param[in] LDQ
*> \verbatim
*> LDQ is INTEGER
*> The leading dimension of the array Q. LDQ >= 1.
*> If WANTQ = .TRUE., LDQ >= N.
*> \endverbatim
*>
*> \param[in,out] Z
*> \verbatim
*> Z is DOUBLE PRECISION array, dimension (LDZ,N)
*> On entry, if WANTZ =.TRUE., the orthogonal matrix Z.
*> On exit, the updated matrix Z.
*> Not referenced if WANTZ = .FALSE..
*> \endverbatim
*>
*> \param[in] LDZ
*> \verbatim
*> LDZ is INTEGER
*> The leading dimension of the array Z. LDZ >= 1.
*> If WANTZ = .TRUE., LDZ >= N.
*> \endverbatim
*>
*> \param[in] J1
*> \verbatim
*> J1 is INTEGER
*> The index to the first block (A11, B11). 1 <= J1 <= N.
*> \endverbatim
*>
*> \param[in] N1
*> \verbatim
*> N1 is INTEGER
*> The order of the first block (A11, B11). N1 = 0, 1 or 2.
*> \endverbatim
*>
*> \param[in] N2
*> \verbatim
*> N2 is INTEGER
*> The order of the second block (A22, B22). N2 = 0, 1 or 2.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)).
*> \endverbatim
*>
*> \param[in] LWORK
*> \verbatim
*> LWORK is INTEGER
*> The dimension of the array WORK.
*> LWORK >= MAX( 1, N*(N2+N1), (N2+N1)*(N2+N1)*2 )
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> =0: Successful exit
*> >0: If INFO = 1, the transformed matrix (A, B) would be
*> too far from generalized Schur form; the blocks are
*> not swapped and (A, B) and (Q, Z) are unchanged.
*> The problem of swapping is too ill-conditioned.
*> <0: If INFO = -16: LWORK is too small. Appropriate value
*> for LWORK is returned in WORK(1).
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup doubleGEauxiliary
*
*> \par Further Details:
* =====================
*>
*> In the current code both weak and strong stability tests are
*> performed. The user can omit the strong stability test by changing
*> the internal logical parameter WANDS to .FALSE.. See ref. [2] for
*> details.
*
*> \par Contributors:
* ==================
*>
*> Bo Kagstrom and Peter Poromaa, Department of Computing Science,
*> Umea University, S-901 87 Umea, Sweden.
*
*> \par References:
* ================
*>
*> \verbatim
*>
*> [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the
*> Generalized Real Schur Form of a Regular Matrix Pair (A, B), in
*> M.S. Moonen et al (eds), Linear Algebra for Large Scale and
*> Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218.
*>
*> [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified
*> Eigenvalues of a Regular Matrix Pair (A, B) and Condition
*> Estimation: Theory, Algorithms and Software,
*> Report UMINF - 94.04, Department of Computing Science, Umea
*> University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working
*> Note 87. To appear in Numerical Algorithms, 1996.
*> \endverbatim
*>
* =====================================================================
SUBROUTINE DTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
$ LDZ, J1, N1, N2, WORK, LWORK, INFO )
*
* -- 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 ..
LOGICAL WANTQ, WANTZ
INTEGER INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
$ WORK( * ), Z( LDZ, * )
* ..
*
* =====================================================================
* Replaced various illegal calls to DCOPY by calls to DLASET, or by DO
* loops. Sven Hammarling, 1/5/02.
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
DOUBLE PRECISION TWENTY
PARAMETER ( TWENTY = 2.0D+01 )
INTEGER LDST
PARAMETER ( LDST = 4 )
LOGICAL WANDS
PARAMETER ( WANDS = .TRUE. )
* ..
* .. Local Scalars ..
LOGICAL STRONG, WEAK
INTEGER I, IDUM, LINFO, M
DOUBLE PRECISION BQRA21, BRQA21, DDUM, DNORMA, DNORMB, DSCALE,
$ DSUM, EPS, F, G, SA, SB, SCALE, SMLNUM,
$ THRESHA, THRESHB
* ..
* .. Local Arrays ..
INTEGER IWORK( LDST )
DOUBLE PRECISION AI( 2 ), AR( 2 ), BE( 2 ), IR( LDST, LDST ),
$ IRCOP( LDST, LDST ), LI( LDST, LDST ),
$ LICOP( LDST, LDST ), S( LDST, LDST ),
$ SCPY( LDST, LDST ), T( LDST, LDST ),
$ TAUL( LDST ), TAUR( LDST ), TCPY( LDST, LDST )
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH
EXTERNAL DLAMCH
* ..
* .. External Subroutines ..
EXTERNAL DGEMM, DGEQR2, DGERQ2, DLACPY, DLAGV2, DLARTG,
$ DLASET, DLASSQ, DORG2R, DORGR2, DORM2R, DORMR2,
$ DROT, DSCAL, DTGSY2
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, SQRT
* ..
* .. Executable Statements ..
*
INFO = 0
*
* Quick return if possible
*
IF( N.LE.1 .OR. N1.LE.0 .OR. N2.LE.0 )
$ RETURN
IF( N1.GT.N .OR. ( J1+N1 ).GT.N )
$ RETURN
M = N1 + N2
IF( LWORK.LT.MAX( 1, N*M, M*M*2 ) ) THEN
INFO = -16
WORK( 1 ) = MAX( 1, N*M, M*M*2 )
RETURN
END IF
*
WEAK = .FALSE.
STRONG = .FALSE.
*
* Make a local copy of selected block
*
CALL DLASET( 'Full', LDST, LDST, ZERO, ZERO, LI, LDST )
CALL DLASET( 'Full', LDST, LDST, ZERO, ZERO, IR, LDST )
CALL DLACPY( 'Full', M, M, A( J1, J1 ), LDA, S, LDST )
CALL DLACPY( 'Full', M, M, B( J1, J1 ), LDB, T, LDST )
*
* Compute threshold for testing acceptance of swapping.
*
EPS = DLAMCH( 'P' )
SMLNUM = DLAMCH( 'S' ) / EPS
DSCALE = ZERO
DSUM = ONE
CALL DLACPY( 'Full', M, M, S, LDST, WORK, M )
CALL DLASSQ( M*M, WORK, 1, DSCALE, DSUM )
DNORMA = DSCALE*SQRT( DSUM )
DSCALE = ZERO
DSUM = ONE
CALL DLACPY( 'Full', M, M, T, LDST, WORK, M )
CALL DLASSQ( M*M, WORK, 1, DSCALE, DSUM )
DNORMB = DSCALE*SQRT( DSUM )
*
* THRES has been changed from
* THRESH = MAX( TEN*EPS*SA, SMLNUM )
* to
* THRESH = MAX( TWENTY*EPS*SA, SMLNUM )
* on 04/01/10.
* "Bug" reported by Ondra Kamenik, confirmed by Julie Langou, fixed by
* Jim Demmel and Guillaume Revy. See forum post 1783.
*
THRESHA = MAX( TWENTY*EPS*DNORMA, SMLNUM )
THRESHB = MAX( TWENTY*EPS*DNORMB, SMLNUM )
*
IF( M.EQ.2 ) THEN
*
* CASE 1: Swap 1-by-1 and 1-by-1 blocks.
*
* Compute orthogonal QL and RQ that swap 1-by-1 and 1-by-1 blocks
* using Givens rotations and perform the swap tentatively.
*
F = S( 2, 2 )*T( 1, 1 ) - T( 2, 2 )*S( 1, 1 )
G = S( 2, 2 )*T( 1, 2 ) - T( 2, 2 )*S( 1, 2 )
SA = ABS( S( 2, 2 ) ) * ABS( T( 1, 1 ) )
SB = ABS( S( 1, 1 ) ) * ABS( T( 2, 2 ) )
CALL DLARTG( F, G, IR( 1, 2 ), IR( 1, 1 ), DDUM )
IR( 2, 1 ) = -IR( 1, 2 )
IR( 2, 2 ) = IR( 1, 1 )
CALL DROT( 2, S( 1, 1 ), 1, S( 1, 2 ), 1, IR( 1, 1 ),
$ IR( 2, 1 ) )
CALL DROT( 2, T( 1, 1 ), 1, T( 1, 2 ), 1, IR( 1, 1 ),
$ IR( 2, 1 ) )
IF( SA.GE.SB ) THEN
CALL DLARTG( S( 1, 1 ), S( 2, 1 ), LI( 1, 1 ), LI( 2, 1 ),
$ DDUM )
ELSE
CALL DLARTG( T( 1, 1 ), T( 2, 1 ), LI( 1, 1 ), LI( 2, 1 ),
$ DDUM )
END IF
CALL DROT( 2, S( 1, 1 ), LDST, S( 2, 1 ), LDST, LI( 1, 1 ),
$ LI( 2, 1 ) )
CALL DROT( 2, T( 1, 1 ), LDST, T( 2, 1 ), LDST, LI( 1, 1 ),
$ LI( 2, 1 ) )
LI( 2, 2 ) = LI( 1, 1 )
LI( 1, 2 ) = -LI( 2, 1 )
*
* Weak stability test: |S21| <= O(EPS F-norm((A)))
* and |T21| <= O(EPS F-norm((B)))
*
WEAK = ABS( S( 2, 1 ) ) .LE. THRESHA .AND.
$ ABS( T( 2, 1 ) ) .LE. THRESHB
IF( .NOT.WEAK )
$ GO TO 70
*
IF( WANDS ) THEN
*
* Strong stability test:
* F-norm((A-QL**H*S*QR)) <= O(EPS*F-norm((A)))
* and
* F-norm((B-QL**H*T*QR)) <= O(EPS*F-norm((B)))
*
CALL DLACPY( 'Full', M, M, A( J1, J1 ), LDA, WORK( M*M+1 ),
$ M )
CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, S, LDST, ZERO,
$ WORK, M )
CALL DGEMM( 'N', 'T', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
$ WORK( M*M+1 ), M )
DSCALE = ZERO
DSUM = ONE
CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
SA = DSCALE*SQRT( DSUM )
*
CALL DLACPY( 'Full', M, M, B( J1, J1 ), LDB, WORK( M*M+1 ),
$ M )
CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, T, LDST, ZERO,
$ WORK, M )
CALL DGEMM( 'N', 'T', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
$ WORK( M*M+1 ), M )
DSCALE = ZERO
DSUM = ONE
CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
SB = DSCALE*SQRT( DSUM )
STRONG = SA.LE.THRESHA .AND. SB.LE.THRESHB
IF( .NOT.STRONG )
$ GO TO 70
END IF
*
* Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and
* (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)).
*
CALL DROT( J1+1, A( 1, J1 ), 1, A( 1, J1+1 ), 1, IR( 1, 1 ),
$ IR( 2, 1 ) )
CALL DROT( J1+1, B( 1, J1 ), 1, B( 1, J1+1 ), 1, IR( 1, 1 ),
$ IR( 2, 1 ) )
CALL DROT( N-J1+1, A( J1, J1 ), LDA, A( J1+1, J1 ), LDA,
$ LI( 1, 1 ), LI( 2, 1 ) )
CALL DROT( N-J1+1, B( J1, J1 ), LDB, B( J1+1, J1 ), LDB,
$ LI( 1, 1 ), LI( 2, 1 ) )
*
* Set N1-by-N2 (2,1) - blocks to ZERO.
*
A( J1+1, J1 ) = ZERO
B( J1+1, J1 ) = ZERO
*
* Accumulate transformations into Q and Z if requested.
*
IF( WANTZ )
$ CALL DROT( N, Z( 1, J1 ), 1, Z( 1, J1+1 ), 1, IR( 1, 1 ),
$ IR( 2, 1 ) )
IF( WANTQ )
$ CALL DROT( N, Q( 1, J1 ), 1, Q( 1, J1+1 ), 1, LI( 1, 1 ),
$ LI( 2, 1 ) )
*
* Exit with INFO = 0 if swap was successfully performed.
*
RETURN
*
ELSE
*
* CASE 2: Swap 1-by-1 and 2-by-2 blocks, or 2-by-2
* and 2-by-2 blocks.
*
* Solve the generalized Sylvester equation
* S11 * R - L * S22 = SCALE * S12
* T11 * R - L * T22 = SCALE * T12
* for R and L. Solutions in LI and IR.
*
CALL DLACPY( 'Full', N1, N2, T( 1, N1+1 ), LDST, LI, LDST )
CALL DLACPY( 'Full', N1, N2, S( 1, N1+1 ), LDST,
$ IR( N2+1, N1+1 ), LDST )
CALL DTGSY2( 'N', 0, N1, N2, S, LDST, S( N1+1, N1+1 ), LDST,
$ IR( N2+1, N1+1 ), LDST, T, LDST, T( N1+1, N1+1 ),
$ LDST, LI, LDST, SCALE, DSUM, DSCALE, IWORK, IDUM,
$ LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
*
* Compute orthogonal matrix QL:
*
* QL**T * LI = [ TL ]
* [ 0 ]
* where
* LI = [ -L ]
* [ SCALE * identity(N2) ]
*
DO 10 I = 1, N2
CALL DSCAL( N1, -ONE, LI( 1, I ), 1 )
LI( N1+I, I ) = SCALE
10 CONTINUE
CALL DGEQR2( M, N2, LI, LDST, TAUL, WORK, LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
CALL DORG2R( M, M, N2, LI, LDST, TAUL, WORK, LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
*
* Compute orthogonal matrix RQ:
*
* IR * RQ**T = [ 0 TR],
*
* where IR = [ SCALE * identity(N1), R ]
*
DO 20 I = 1, N1
IR( N2+I, I ) = SCALE
20 CONTINUE
CALL DGERQ2( N1, M, IR( N2+1, 1 ), LDST, TAUR, WORK, LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
CALL DORGR2( M, M, N1, IR, LDST, TAUR, WORK, LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
*
* Perform the swapping tentatively:
*
CALL DGEMM( 'T', 'N', M, M, M, ONE, LI, LDST, S, LDST, ZERO,
$ WORK, M )
CALL DGEMM( 'N', 'T', M, M, M, ONE, WORK, M, IR, LDST, ZERO, S,
$ LDST )
CALL DGEMM( 'T', 'N', M, M, M, ONE, LI, LDST, T, LDST, ZERO,
$ WORK, M )
CALL DGEMM( 'N', 'T', M, M, M, ONE, WORK, M, IR, LDST, ZERO, T,
$ LDST )
CALL DLACPY( 'F', M, M, S, LDST, SCPY, LDST )
CALL DLACPY( 'F', M, M, T, LDST, TCPY, LDST )
CALL DLACPY( 'F', M, M, IR, LDST, IRCOP, LDST )
CALL DLACPY( 'F', M, M, LI, LDST, LICOP, LDST )
*
* Triangularize the B-part by an RQ factorization.
* Apply transformation (from left) to A-part, giving S.
*
CALL DGERQ2( M, M, T, LDST, TAUR, WORK, LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
CALL DORMR2( 'R', 'T', M, M, M, T, LDST, TAUR, S, LDST, WORK,
$ LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
CALL DORMR2( 'L', 'N', M, M, M, T, LDST, TAUR, IR, LDST, WORK,
$ LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
*
* Compute F-norm(S21) in BRQA21. (T21 is 0.)
*
DSCALE = ZERO
DSUM = ONE
DO 30 I = 1, N2
CALL DLASSQ( N1, S( N2+1, I ), 1, DSCALE, DSUM )
30 CONTINUE
BRQA21 = DSCALE*SQRT( DSUM )
*
* Triangularize the B-part by a QR factorization.
* Apply transformation (from right) to A-part, giving S.
*
CALL DGEQR2( M, M, TCPY, LDST, TAUL, WORK, LINFO )
IF( LINFO.NE.0 )
$ GO TO 70
CALL DORM2R( 'L', 'T', M, M, M, TCPY, LDST, TAUL, SCPY, LDST,
$ WORK, INFO )
CALL DORM2R( 'R', 'N', M, M, M, TCPY, LDST, TAUL, LICOP, LDST,
$ WORK, INFO )
IF( LINFO.NE.0 )
$ GO TO 70
*
* Compute F-norm(S21) in BQRA21. (T21 is 0.)
*
DSCALE = ZERO
DSUM = ONE
DO 40 I = 1, N2
CALL DLASSQ( N1, SCPY( N2+1, I ), 1, DSCALE, DSUM )
40 CONTINUE
BQRA21 = DSCALE*SQRT( DSUM )
*
* Decide which method to use.
* Weak stability test:
* F-norm(S21) <= O(EPS * F-norm((S)))
*
IF( BQRA21.LE.BRQA21 .AND. BQRA21.LE.THRESHA ) THEN
CALL DLACPY( 'F', M, M, SCPY, LDST, S, LDST )
CALL DLACPY( 'F', M, M, TCPY, LDST, T, LDST )
CALL DLACPY( 'F', M, M, IRCOP, LDST, IR, LDST )
CALL DLACPY( 'F', M, M, LICOP, LDST, LI, LDST )
ELSE IF( BRQA21.GE.THRESHA ) THEN
GO TO 70
END IF
*
* Set lower triangle of B-part to zero
*
CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, T(2,1), LDST )
*
IF( WANDS ) THEN
*
* Strong stability test:
* F-norm((A-QL**H*S*QR)) <= O(EPS*F-norm((A)))
* and
* F-norm((B-QL**H*T*QR)) <= O(EPS*F-norm((B)))
*
CALL DLACPY( 'Full', M, M, A( J1, J1 ), LDA, WORK( M*M+1 ),
$ M )
CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, S, LDST, ZERO,
$ WORK, M )
CALL DGEMM( 'N', 'N', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
$ WORK( M*M+1 ), M )
DSCALE = ZERO
DSUM = ONE
CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
SA = DSCALE*SQRT( DSUM )
*
CALL DLACPY( 'Full', M, M, B( J1, J1 ), LDB, WORK( M*M+1 ),
$ M )
CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, T, LDST, ZERO,
$ WORK, M )
CALL DGEMM( 'N', 'N', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
$ WORK( M*M+1 ), M )
DSCALE = ZERO
DSUM = ONE
CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
SB = DSCALE*SQRT( DSUM )
STRONG = SA.LE.THRESHA .AND. SB.LE.THRESHB
IF( .NOT.STRONG )
$ GO TO 70
*
END IF
*
* If the swap is accepted ("weakly" and "strongly"), apply the
* transformations and set N1-by-N2 (2,1)-block to zero.
*
CALL DLASET( 'Full', N1, N2, ZERO, ZERO, S(N2+1,1), LDST )
*
* copy back M-by-M diagonal block starting at index J1 of (A, B)
*
CALL DLACPY( 'F', M, M, S, LDST, A( J1, J1 ), LDA )
CALL DLACPY( 'F', M, M, T, LDST, B( J1, J1 ), LDB )
CALL DLASET( 'Full', LDST, LDST, ZERO, ZERO, T, LDST )
*
* Standardize existing 2-by-2 blocks.
*
CALL DLASET( 'Full', M, M, ZERO, ZERO, WORK, M )
WORK( 1 ) = ONE
T( 1, 1 ) = ONE
IDUM = LWORK - M*M - 2
IF( N2.GT.1 ) THEN
CALL DLAGV2( A( J1, J1 ), LDA, B( J1, J1 ), LDB, AR, AI, BE,
$ WORK( 1 ), WORK( 2 ), T( 1, 1 ), T( 2, 1 ) )
WORK( M+1 ) = -WORK( 2 )
WORK( M+2 ) = WORK( 1 )
T( N2, N2 ) = T( 1, 1 )
T( 1, 2 ) = -T( 2, 1 )
END IF
WORK( M*M ) = ONE
T( M, M ) = ONE
*
IF( N1.GT.1 ) THEN
CALL DLAGV2( A( J1+N2, J1+N2 ), LDA, B( J1+N2, J1+N2 ), LDB,
$ TAUR, TAUL, WORK( M*M+1 ), WORK( N2*M+N2+1 ),
$ WORK( N2*M+N2+2 ), T( N2+1, N2+1 ),
$ T( M, M-1 ) )
WORK( M*M ) = WORK( N2*M+N2+1 )
WORK( M*M-1 ) = -WORK( N2*M+N2+2 )
T( M, M ) = T( N2+1, N2+1 )
T( M-1, M ) = -T( M, M-1 )
END IF
CALL DGEMM( 'T', 'N', N2, N1, N2, ONE, WORK, M, A( J1, J1+N2 ),
$ LDA, ZERO, WORK( M*M+1 ), N2 )
CALL DLACPY( 'Full', N2, N1, WORK( M*M+1 ), N2, A( J1, J1+N2 ),
$ LDA )
CALL DGEMM( 'T', 'N', N2, N1, N2, ONE, WORK, M, B( J1, J1+N2 ),
$ LDB, ZERO, WORK( M*M+1 ), N2 )
CALL DLACPY( 'Full', N2, N1, WORK( M*M+1 ), N2, B( J1, J1+N2 ),
$ LDB )
CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, WORK, M, ZERO,
$ WORK( M*M+1 ), M )
CALL DLACPY( 'Full', M, M, WORK( M*M+1 ), M, LI, LDST )
CALL DGEMM( 'N', 'N', N2, N1, N1, ONE, A( J1, J1+N2 ), LDA,
$ T( N2+1, N2+1 ), LDST, ZERO, WORK, N2 )
CALL DLACPY( 'Full', N2, N1, WORK, N2, A( J1, J1+N2 ), LDA )
CALL DGEMM( 'N', 'N', N2, N1, N1, ONE, B( J1, J1+N2 ), LDB,
$ T( N2+1, N2+1 ), LDST, ZERO, WORK, N2 )
CALL DLACPY( 'Full', N2, N1, WORK, N2, B( J1, J1+N2 ), LDB )
CALL DGEMM( 'T', 'N', M, M, M, ONE, IR, LDST, T, LDST, ZERO,
$ WORK, M )
CALL DLACPY( 'Full', M, M, WORK, M, IR, LDST )
*
* Accumulate transformations into Q and Z if requested.
*
IF( WANTQ ) THEN
CALL DGEMM( 'N', 'N', N, M, M, ONE, Q( 1, J1 ), LDQ, LI,
$ LDST, ZERO, WORK, N )
CALL DLACPY( 'Full', N, M, WORK, N, Q( 1, J1 ), LDQ )
*
END IF
*
IF( WANTZ ) THEN
CALL DGEMM( 'N', 'N', N, M, M, ONE, Z( 1, J1 ), LDZ, IR,
$ LDST, ZERO, WORK, N )
CALL DLACPY( 'Full', N, M, WORK, N, Z( 1, J1 ), LDZ )
*
END IF
*
* Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and
* (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)).
*
I = J1 + M
IF( I.LE.N ) THEN
CALL DGEMM( 'T', 'N', M, N-I+1, M, ONE, LI, LDST,
$ A( J1, I ), LDA, ZERO, WORK, M )
CALL DLACPY( 'Full', M, N-I+1, WORK, M, A( J1, I ), LDA )
CALL DGEMM( 'T', 'N', M, N-I+1, M, ONE, LI, LDST,
$ B( J1, I ), LDB, ZERO, WORK, M )
CALL DLACPY( 'Full', M, N-I+1, WORK, M, B( J1, I ), LDB )
END IF
I = J1 - 1
IF( I.GT.0 ) THEN
CALL DGEMM( 'N', 'N', I, M, M, ONE, A( 1, J1 ), LDA, IR,
$ LDST, ZERO, WORK, I )
CALL DLACPY( 'Full', I, M, WORK, I, A( 1, J1 ), LDA )
CALL DGEMM( 'N', 'N', I, M, M, ONE, B( 1, J1 ), LDB, IR,
$ LDST, ZERO, WORK, I )
CALL DLACPY( 'Full', I, M, WORK, I, B( 1, J1 ), LDB )
END IF
*
* Exit with INFO = 0 if swap was successfully performed.
*
RETURN
*
END IF
*
* Exit with INFO = 1 if swap was rejected.
*
70 CONTINUE
*
INFO = 1
RETURN
*
* End of DTGEX2
*
END
| bsd-3-clause |
kolawoletech/ce-espresso | atomic/src/calculate_gipaw_orbitals.f90 | 18 | 10518 | !
! Copyright (C) 2004 PWSCF 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 calculate_gipaw_orbitals
!------------------------------------------------------------
USE ld1_parameters, ONLY : nwfsx
USE ld1inc, ONLY : nld, file_logder, zed, grid, &
wfc_ae_recon, wfc_ps_recon, nspin, nwftsc, lltsc, enltsc, &
nwfs, eltsc, el, nwf, enl, rel, vpot, nbeta, pseudotype, &
vpstot, nstoaets, enlts, vnl, lls, betas, ddd, qq, jjs, els, &
rcutus, ikk, nwfts, verbosity
USE io_global, ONLY : stdout
USE kinds, ONLY : dp
USE radial_grids, ONLY : ndmx, series
IMPLICIT NONE
!<apsi> from lderiv.f90
INTEGER :: &
lam, & ! the angular momentum
nc, & ! counter on logarithmic derivatives
is, & ! counter on spin
ierr, & ! used for allocation control
ios, & ! used for I/O control
n,ie ! generic counter
real(DP) :: &
aux(ndmx), & ! the square of the wavefunction
aux_dir(ndmx,2), & ! the square of the wavefunction
ze2, & ! the nuclear charge in Ry units
e, & ! the eigenvalue
j ! total angular momentum for log_der
INTEGER :: &
nbf ! number of b functions
real(DP) :: &
jam, & ! the total angular momentum
lamsq, & ! combined angular momentum
b(0:3),c(4), & ! used for starting guess of the solution
b0e, rr1,rr2, & ! auxiliary
xl1, x4l6, ddx12, &
x6l12, x8l20
real(DP) :: &
vaux(ndmx), & ! auxiliary: the potential
al(ndmx) ! the known part of the differential equation
real(DP), EXTERNAL :: int_0_inf_dr
INTEGER :: &
ib,jb,iib,jjb, & ! counters on beta functions
nst,nstop, & ! auxiliary for integrals
ind ! counters on index
REAL ( dp ) :: r1, r2, thrdum = 0.0_dp
INTEGER :: ns, outer_r_radial_index, n_idx, ik, i, r_write_max_index
INTEGER :: ik_stop
REAL ( dp ) :: factor, rcut_match, max_val
REAL ( dp ) :: wfc_ae_recon2(ndmx,nwfsx)
REAL ( dp ) :: wfc_ps_recon2(ndmx,nwfsx)
REAL ( dp ) :: de
REAL ( dp ), ALLOCATABLE :: f_ae(:), f_ps(:)
IF ( verbosity == 'high' ) THEN
WRITE ( stdout, '( 3A )' ) &
" ------------------------", &
" (GI)PAW reconstruction ", &
"-------------------------"
ENDIF
IF ( nld > nwfsx ) &
CALL errore ( 'calculate_gipaw_orbitals', 'nld is too large', 1 )
vaux(:) = 0.0_dp
ze2=-zed*2.0_dp
! Choose a radius for the normalisation of all-electron wave functions
! In principle the value for radius is arbitrary [apsi]
ik_stop = 10
DO n = 1, grid%mesh
IF ( grid%r(n) < 1.5 ) ik_stop = n
ENDDO
DO is=1,nspin
DO ns = 1, nwftsc(1)
lam = lltsc(ns,1)
j = 0.0_dp
DO n = 1, grid%mesh
IF ( grid%r(n) < 15.0 ) THEN
outer_r_radial_index = n
ENDIF
ENDDO
n_idx = -1
IF ( abs ( enltsc(ns,1) ) > 1e-8 ) THEN
e = enltsc(ns,1)
DO n = 1, nwf
IF ( eltsc(ns,1) == el(n) ) THEN
n_idx = n
ENDIF
ENDDO
ELSE
DO n = 1, nwf
IF ( eltsc(ns,1) == el(n) ) THEN
e = enl(n)
n_idx = n
ENDIF
ENDDO
ENDIF
IF ( verbosity == 'high' ) THEN
WRITE ( stdout, '( /, 5X, 3A )') "========================= ", &
trim(el(n_idx)), &
" ========================="
WRITE ( stdout, * ) " AE: e(ref), l, n_idx ", e, lam, n_idx
ENDIF
!
! integrate outward up to ik_stop
!
IF (rel == 1) THEN
CALL lschps(3, zed, thrdum, grid, outer_r_radial_index, &
1, lam, e, vpot(1,is), aux, nstop)
ELSEIF (rel == 2) THEN
CALL dir_outward(ndmx,outer_r_radial_index,lam,j,e,grid%dx,&
aux_dir,grid%r,grid%rab,vpot(1,is))
aux(:)=aux_dir(:,1)
ELSE
CALL intref(lam,e,outer_r_radial_index,grid,vpot(1,is),ze2,aux)
ENDIF
wfc_ae_recon(:grid%mesh,n_idx) = aux(:grid%mesh)
! Set the maximum to be +-1
wfc_ae_recon(:grid%mesh,n_idx) = wfc_ae_recon(:grid%mesh,n_idx) &
/ maxval ( abs ( wfc_ae_recon(:ik_stop,n_idx) ) )
ENDDO
ENDDO
!</apsi> from lderiv.f90
!<apsi> from lderivps.f90
DO is = 1, nspin
IF ( .not. rel < 2 ) THEN
CALL errore ( 'calculate_gipaw_orbitals', &
'not implemented for rel >= 2', rel )
ENDIF
DO ns = 1, nwftsc(1)
lam = lltsc(ns,1)
jam=0.0_dp
xl1=lam+1
x4l6=4*lam+6
x6l12=6*lam+12
x8l20=8*lam+20
ddx12=grid%dx*grid%dx/12.0_dp
nst=(lam+1)*2
nbf=nbeta
IF (pseudotype == 1) THEN
IF (rel < 2 .or. lam == 0 .or. abs(jam-lam+0.5_dp) < 0.001_dp) THEN
ind=1
ELSEIF (rel==2 .and. lam>0 .and. abs(jam-lam-0.5_dp)<0.001_dp) THEN
ind=2
ENDIF
DO n=1,grid%mesh
vaux(n) = vpstot(n,is) + vnl(n,lam,ind)
ENDDO
nbf=0.0
ELSE
DO n=1,grid%mesh
vaux(n) = vpstot(n,is)
ENDDO
ENDIF
DO n=1,4
al(n)=vaux(n)-ze2/grid%r(n)
ENDDO
CALL series(al,grid%r,grid%r2,b)
IF ( abs ( enltsc(ns,1) ) > 1e-8 ) THEN
e = enltsc(ns,1)
ELSE
e = enlts(ns)
ENDIF
DO n = 1, nwftsc(1)
IF ( eltsc(n,1) == el(nstoaets(ns)) ) THEN
n_idx = n
ENDIF
ENDDO
IF ( verbosity == 'high' ) THEN
WRITE ( stdout, '( /, 5X, 3A )' ) "========================= ", &
trim(eltsc(ns,1)), &
" ========================="
WRITE ( stdout, * ) " PS: e(ref), e(eig), n_idx ", &
e, enlts(ns), n_idx
ENDIF
rcut_match = -1.0_dp
DO n = 1, nwfs
! If this one has already a core radius...
IF ( els(n) == el(nstoaets(ns)) ) THEN
rcut_match = rcutus(n)
ENDIF
ENDDO
IF ( rcut_match < 0.0_dp ) THEN
DO n = 1, nwfs
! If there is one with the same l...
IF ( lltsc(ns,1) == lls(n) ) THEN
rcut_match = rcutus(n)
ENDIF
ENDDO
ENDIF
IF ( rcut_match < 0.0_dp ) THEN
max_val = -1.0_dp
DO n = 1, grid%mesh
IF ( grid%r(n) < 5.0_dp &
.and. abs ( wfc_ae_recon(n,n_idx) ) > max_val ) THEN
rcut_match = grid%r(n)
max_val = abs ( wfc_ae_recon(n,n_idx) )
ENDIF
ENDDO
! In case over divergence
rcut_match = min ( rcut_match, 5.0_dp )
ENDIF
ik = 10
DO n = 1, grid%mesh
IF ( grid%r(n) < rcut_match ) ik = n
ENDDO
IF ( verbosity == 'high' ) THEN
WRITE ( stdout, * ) " r(cut): ", rcut_match, ik, outer_r_radial_index
ENDIF
DO n = 1, grid%mesh
IF ( grid%r(n) < 15.0 ) THEN
outer_r_radial_index = n
ENDIF
ENDDO
lamsq=(lam+0.5_dp)**2
!
! b) find the value of solution s in the first two points
!
b0e=b(0)-e
c(1)=0.5_dp*ze2/xl1
c(2)=(c(1)*ze2+b0e)/x4l6
c(3)=(c(2)*ze2+c(1)*b0e+b(1))/x6l12
c(4)=(c(3)*ze2+c(2)*b0e+c(1)*b(1)+b(2))/x8l20
r1 = grid%r(1)
r2 = grid%r(2)
rr1=(1.0_dp+r1*(c(1)+r1*(c(2)+r1*(c(3)+r1*c(4)))))*r1**(lam+1)
rr2=(1.0_dp+r2*(c(1)+r2*(c(2)+r2*(c(3)+r2*c(4)))))*r2**(lam+1)
aux(1)=rr1/grid%sqr(1)
aux(2)=rr2/grid%sqr(2)
DO n=1,grid%mesh
al(n)=( (vaux(n)-e)*grid%r2(n) + lamsq )*ddx12
al(n)=1.0_dp-al(n)
ENDDO
CALL integrate_outward (lam,jam,e,grid%mesh,ndmx,grid,al,b,aux, &
betas,ddd,qq,nbf,nwfsx,lls,jjs,ikk,outer_r_radial_index)
wfc_ps_recon(:grid%mesh,n_idx) = aux(:grid%mesh) &
* sqrt ( grid%r(:grid%mesh) )
DO n = 1, grid%mesh
IF ( grid%r(n) > 5.0 ) exit
ENDDO
IF ( abs ( wfc_ps_recon(ik,n_idx) ) < 1e-5 ) THEN
WRITE ( stdout, * ) " Warning: ", wfc_ps_recon(ik,n_idx), ns
CALL errore ( "calculate_gipaw_orbitals", &
"safer to stop here...", ik )
ENDIF
factor = wfc_ae_recon(ik,nstoaets(n_idx)) / wfc_ps_recon(ik,n_idx)
wfc_ps_recon(:grid%mesh,n_idx) = wfc_ps_recon(:grid%mesh,n_idx) &
* factor
IF ( verbosity == 'high' ) THEN
WRITE ( stdout, * ) " SCALE: ", &
wfc_ae_recon(ik,nstoaets(n_idx)) &
/ wfc_ps_recon(ik,n_idx), grid%r(ik), factor
WRITE ( stdout, * ) " SCALE: ", &
wfc_ae_recon(ik+5,nstoaets(n_idx)) &
/ wfc_ps_recon(ik+5,n_idx),grid%r(ik+5)
ALLOCATE ( f_ae(grid%mesh), f_ps(grid%mesh) )
f_ae = wfc_ae_recon(:grid%mesh,nstoaets(n_idx)) ** 2
f_ps = wfc_ps_recon(:grid%mesh,n_idx) ** 2
! Test the norm
nst = ( lam + 1 ) * 2
IF ( verbosity == 'high' ) THEN
WRITE ( stdout, '(A,3F12.8)' ) " NORM: ", &
int_0_inf_dr ( f_ae, grid, ik, nst ), &
int_0_inf_dr ( f_ps, grid, ik, nst )
ENDIF
DEALLOCATE ( f_ae, f_ps )
ENDIF
ENDDO
ENDDO
!</apsi> from lderivps.f90
IF ( verbosity == 'high' ) THEN
WRITE ( stdout, '( 3A )' ) &
" ---------------------", &
" End of (GI)PAW reconstruction ", &
"---------------------"
ENDIF
END SUBROUTINE calculate_gipaw_orbitals
| gpl-2.0 |
xianyi/OpenBLAS | lapack-netlib/SRC/sppequ.f | 1 | 6371 | *> \brief \b SPPEQU
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SPPEQU + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sppequ.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sppequ.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sppequ.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE SPPEQU( UPLO, N, AP, S, SCOND, AMAX, INFO )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INFO, N
* REAL AMAX, SCOND
* ..
* .. Array Arguments ..
* REAL AP( * ), S( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SPPEQU computes row and column scalings intended to equilibrate a
*> symmetric positive definite matrix A in packed storage 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.
*> \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] AP
*> \verbatim
*> AP is REAL array, dimension (N*(N+1)/2)
*> 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.
*> \endverbatim
*>
*> \param[out] S
*> \verbatim
*> S is REAL array, dimension (N)
*> If INFO = 0, S contains the scale factors for A.
*> \endverbatim
*>
*> \param[out] SCOND
*> \verbatim
*> SCOND is 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.
*> \endverbatim
*>
*> \param[out] AMAX
*> \verbatim
*> AMAX is REAL
*> Absolute value of largest matrix element. If AMAX is very
*> close to overflow or very close to underflow, the matrix
*> should be scaled.
*> \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 i-th diagonal element is nonpositive.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup realOTHERcomputational
*
* =====================================================================
SUBROUTINE SPPEQU( UPLO, N, AP, S, SCOND, AMAX, INFO )
*
* -- LAPACK computational routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, N
REAL AMAX, SCOND
* ..
* .. Array Arguments ..
REAL AP( * ), S( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ONE, ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER I, JJ
REAL 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
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SPPEQU', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 ) THEN
SCOND = ONE
AMAX = ZERO
RETURN
END IF
*
* Initialize SMIN and AMAX.
*
S( 1 ) = AP( 1 )
SMIN = S( 1 )
AMAX = S( 1 )
*
IF( UPPER ) THEN
*
* UPLO = 'U': Upper triangle of A is stored.
* Find the minimum and maximum diagonal elements.
*
JJ = 1
DO 10 I = 2, N
JJ = JJ + I
S( I ) = AP( JJ )
SMIN = MIN( SMIN, S( I ) )
AMAX = MAX( AMAX, S( I ) )
10 CONTINUE
*
ELSE
*
* UPLO = 'L': Lower triangle of A is stored.
* Find the minimum and maximum diagonal elements.
*
JJ = 1
DO 20 I = 2, N
JJ = JJ + N - I + 2
S( I ) = AP( JJ )
SMIN = MIN( SMIN, S( I ) )
AMAX = MAX( AMAX, S( I ) )
20 CONTINUE
END IF
*
IF( SMIN.LE.ZERO ) THEN
*
* Find the first non-positive diagonal element and return.
*
DO 30 I = 1, N
IF( S( I ).LE.ZERO ) THEN
INFO = I
RETURN
END IF
30 CONTINUE
ELSE
*
* Set the scale factors to the reciprocals
* of the diagonal elements.
*
DO 40 I = 1, N
S( I ) = ONE / SQRT( S( I ) )
40 CONTINUE
*
* Compute SCOND = min(S(I)) / max(S(I))
*
SCOND = SQRT( SMIN ) / SQRT( AMAX )
END IF
RETURN
*
* End of SPPEQU
*
END
| bsd-3-clause |
xianyi/OpenBLAS | lapack-netlib/SRC/zla_gbrfsx_extended.f | 1 | 26427 | *> \brief \b ZLA_GBRFSX_EXTENDED improves the computed solution to a system of linear equations for general banded matrices by performing extra-precise iterative refinement and provides error bounds and backward error estimates for the solution.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ZLA_GBRFSX_EXTENDED + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zla_gbrfsx_extended.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zla_gbrfsx_extended.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zla_gbrfsx_extended.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE ZLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE, N, KL, KU,
* NRHS, AB, LDAB, AFB, LDAFB, IPIV,
* COLEQU, C, B, LDB, Y, LDY,
* BERR_OUT, N_NORMS, ERR_BNDS_NORM,
* ERR_BNDS_COMP, RES, AYB, DY,
* Y_TAIL, RCOND, ITHRESH, RTHRESH,
* DZ_UB, IGNORE_CWISE, INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LDAB, LDAFB, LDB, LDY, N, KL, KU, NRHS,
* $ PREC_TYPE, TRANS_TYPE, N_NORMS, ITHRESH
* LOGICAL COLEQU, IGNORE_CWISE
* DOUBLE PRECISION RTHRESH, DZ_UB
* ..
* .. Array Arguments ..
* INTEGER IPIV( * )
* COMPLEX*16 AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
* $ Y( LDY, * ), RES( * ), DY( * ), Y_TAIL( * )
* DOUBLE PRECISION C( * ), AYB(*), RCOND, BERR_OUT( * ),
* $ ERR_BNDS_NORM( NRHS, * ),
* $ ERR_BNDS_COMP( NRHS, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZLA_GBRFSX_EXTENDED improves the computed solution to a system of
*> linear equations by performing extra-precise iterative refinement
*> and provides error bounds and backward error estimates for the solution.
*> This subroutine is called by ZGBRFSX to perform iterative refinement.
*> 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. Note that this
*> subroutine is only responsible for setting the second fields of
*> ERR_BNDS_NORM and ERR_BNDS_COMP.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] PREC_TYPE
*> \verbatim
*> PREC_TYPE is INTEGER
*> Specifies the intermediate precision to be used in refinement.
*> The value is defined by ILAPREC(P) where P is a CHARACTER and P
*> = 'S': Single
*> = 'D': Double
*> = 'I': Indigenous
*> = 'X' or 'E': Extra
*> \endverbatim
*>
*> \param[in] TRANS_TYPE
*> \verbatim
*> TRANS_TYPE is INTEGER
*> Specifies the transposition operation on A.
*> The value is defined by ILATRANS(T) where T is a CHARACTER and T
*> = 'N': No transpose
*> = 'T': Transpose
*> = 'C': Conjugate transpose
*> \endverbatim
*>
*> \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] NRHS
*> \verbatim
*> NRHS is INTEGER
*> The number of right-hand-sides, i.e., the number of columns of the
*> matrix B.
*> \endverbatim
*>
*> \param[in] AB
*> \verbatim
*> AB is COMPLEX*16 array, dimension (LDAB,N)
*> On entry, the N-by-N matrix A.
*> \endverbatim
*>
*> \param[in] LDAB
*> \verbatim
*> LDAB is INTEGER
*> The leading dimension of the array A. LDAB >= max(1,N).
*> \endverbatim
*>
*> \param[in] AFB
*> \verbatim
*> AFB is COMPLEX*16 array, dimension (LDAF,N)
*> The factors L and U from the factorization
*> A = P*L*U as computed by ZGBTRF.
*> \endverbatim
*>
*> \param[in] LDAFB
*> \verbatim
*> LDAFB 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 the factorization A = P*L*U
*> as computed by ZGBTRF; row i of the matrix was interchanged
*> with row IPIV(i).
*> \endverbatim
*>
*> \param[in] COLEQU
*> \verbatim
*> COLEQU is LOGICAL
*> If .TRUE. then column equilibration was done to A before calling
*> this routine. This is needed to compute the solution and error
*> bounds correctly.
*> \endverbatim
*>
*> \param[in] C
*> \verbatim
*> C is DOUBLE PRECISION array, dimension (N)
*> The column scale factors for A. If COLEQU = .FALSE., C
*> is not accessed. 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.
*> \endverbatim
*>
*> \param[in] B
*> \verbatim
*> B is COMPLEX*16 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] Y
*> \verbatim
*> Y is COMPLEX*16 array, dimension (LDY,NRHS)
*> On entry, the solution matrix X, as computed by ZGBTRS.
*> On exit, the improved solution matrix Y.
*> \endverbatim
*>
*> \param[in] LDY
*> \verbatim
*> LDY is INTEGER
*> The leading dimension of the array Y. LDY >= max(1,N).
*> \endverbatim
*>
*> \param[out] BERR_OUT
*> \verbatim
*> BERR_OUT is DOUBLE PRECISION array, dimension (NRHS)
*> On exit, BERR_OUT(j) contains the componentwise relative backward
*> error for right-hand-side j from the formula
*> max(i) ( abs(RES(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. This is computed by ZLA_LIN_BERR.
*> \endverbatim
*>
*> \param[in] N_NORMS
*> \verbatim
*> N_NORMS is INTEGER
*> Determines which error bounds to return (see ERR_BNDS_NORM
*> and ERR_BNDS_COMP).
*> If N_NORMS >= 1 return normwise error bounds.
*> If N_NORMS >= 2 return componentwise error bounds.
*> \endverbatim
*>
*> \param[in,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) * slamch('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) * slamch('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) * slamch('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.
*>
*> This subroutine is only responsible for setting the second field
*> above.
*> See Lapack Working Note 165 for further details and extra
*> cautions.
*> \endverbatim
*>
*> \param[in,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 < 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) * slamch('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) * slamch('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) * slamch('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.
*>
*> This subroutine is only responsible for setting the second field
*> above.
*> See Lapack Working Note 165 for further details and extra
*> cautions.
*> \endverbatim
*>
*> \param[in] RES
*> \verbatim
*> RES is COMPLEX*16 array, dimension (N)
*> Workspace to hold the intermediate residual.
*> \endverbatim
*>
*> \param[in] AYB
*> \verbatim
*> AYB is DOUBLE PRECISION array, dimension (N)
*> Workspace.
*> \endverbatim
*>
*> \param[in] DY
*> \verbatim
*> DY is COMPLEX*16 array, dimension (N)
*> Workspace to hold the intermediate solution.
*> \endverbatim
*>
*> \param[in] Y_TAIL
*> \verbatim
*> Y_TAIL is COMPLEX*16 array, dimension (N)
*> Workspace to hold the trailing bits of the intermediate solution.
*> \endverbatim
*>
*> \param[in] 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[in] ITHRESH
*> \verbatim
*> ITHRESH is INTEGER
*> The maximum number of residual computations allowed for
*> refinement. The default is 10. For '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.
*> \endverbatim
*>
*> \param[in] RTHRESH
*> \verbatim
*> RTHRESH is DOUBLE PRECISION
*> Determines when to stop refinement if the error estimate stops
*> decreasing. Refinement will stop when the next solution no longer
*> satisfies norm(dx_{i+1}) < RTHRESH * norm(dx_i) where norm(Z) is
*> the infinity norm of Z. RTHRESH satisfies 0 < RTHRESH <= 1. The
*> default value is 0.5. For 'aggressive' set to 0.9 to permit
*> convergence on extremely ill-conditioned matrices. See LAWN 165
*> for more details.
*> \endverbatim
*>
*> \param[in] DZ_UB
*> \verbatim
*> DZ_UB is DOUBLE PRECISION
*> Determines when to start considering componentwise convergence.
*> Componentwise convergence is only considered after each component
*> of the solution Y is stable, which we define as the relative
*> change in each component being less than DZ_UB. The default value
*> is 0.25, requiring the first bit to be stable. See LAWN 165 for
*> more details.
*> \endverbatim
*>
*> \param[in] IGNORE_CWISE
*> \verbatim
*> IGNORE_CWISE is LOGICAL
*> If .TRUE. then ignore componentwise convergence. Default value
*> is .FALSE..
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: Successful exit.
*> < 0: if INFO = -i, the ith argument to ZGBTRS had an illegal
*> value
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \ingroup complex16GBcomputational
*
* =====================================================================
SUBROUTINE ZLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE, N, KL, KU,
$ NRHS, AB, LDAB, AFB, LDAFB, IPIV,
$ COLEQU, C, B, LDB, Y, LDY,
$ BERR_OUT, N_NORMS, ERR_BNDS_NORM,
$ ERR_BNDS_COMP, RES, AYB, DY,
$ Y_TAIL, RCOND, ITHRESH, RTHRESH,
$ DZ_UB, IGNORE_CWISE, 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, LDAB, LDAFB, LDB, LDY, N, KL, KU, NRHS,
$ PREC_TYPE, TRANS_TYPE, N_NORMS, ITHRESH
LOGICAL COLEQU, IGNORE_CWISE
DOUBLE PRECISION RTHRESH, DZ_UB
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
COMPLEX*16 AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
$ Y( LDY, * ), RES( * ), DY( * ), Y_TAIL( * )
DOUBLE PRECISION C( * ), AYB(*), RCOND, BERR_OUT( * ),
$ ERR_BNDS_NORM( NRHS, * ),
$ ERR_BNDS_COMP( NRHS, * )
* ..
*
* =====================================================================
*
* .. Local Scalars ..
CHARACTER TRANS
INTEGER CNT, I, J, M, X_STATE, Z_STATE, Y_PREC_STATE
DOUBLE PRECISION YK, DYK, YMIN, NORMY, NORMX, NORMDX, DXRAT,
$ DZRAT, PREVNORMDX, PREV_DZ_Z, DXRATMAX,
$ DZRATMAX, DX_X, DZ_Z, FINAL_DX_X, FINAL_DZ_Z,
$ EPS, HUGEVAL, INCR_THRESH
LOGICAL INCR_PREC
COMPLEX*16 ZDUM
* ..
* .. Parameters ..
INTEGER UNSTABLE_STATE, WORKING_STATE, CONV_STATE,
$ NOPROG_STATE, BASE_RESIDUAL, EXTRA_RESIDUAL,
$ EXTRA_Y
PARAMETER ( UNSTABLE_STATE = 0, WORKING_STATE = 1,
$ CONV_STATE = 2, NOPROG_STATE = 3 )
PARAMETER ( BASE_RESIDUAL = 0, EXTRA_RESIDUAL = 1,
$ EXTRA_Y = 2 )
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 )
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 )
* ..
* .. External Subroutines ..
EXTERNAL ZAXPY, ZCOPY, ZGBTRS, ZGBMV, BLAS_ZGBMV_X,
$ BLAS_ZGBMV2_X, ZLA_GBAMV, ZLA_WWADDW, DLAMCH,
$ CHLA_TRANSTYPE, ZLA_LIN_BERR
DOUBLE PRECISION DLAMCH
CHARACTER CHLA_TRANSTYPE
* ..
* .. Intrinsic Functions..
INTRINSIC ABS, MAX, MIN
* ..
* .. Statement Functions ..
DOUBLE PRECISION CABS1
* ..
* .. Statement Function Definitions ..
CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
* ..
* .. Executable Statements ..
*
IF (INFO.NE.0) RETURN
TRANS = CHLA_TRANSTYPE(TRANS_TYPE)
EPS = DLAMCH( 'Epsilon' )
HUGEVAL = DLAMCH( 'Overflow' )
* Force HUGEVAL to Inf
HUGEVAL = HUGEVAL * HUGEVAL
* Using HUGEVAL may lead to spurious underflows.
INCR_THRESH = DBLE( N ) * EPS
M = KL+KU+1
DO J = 1, NRHS
Y_PREC_STATE = EXTRA_RESIDUAL
IF ( Y_PREC_STATE .EQ. EXTRA_Y ) THEN
DO I = 1, N
Y_TAIL( I ) = 0.0D+0
END DO
END IF
DXRAT = 0.0D+0
DXRATMAX = 0.0D+0
DZRAT = 0.0D+0
DZRATMAX = 0.0D+0
FINAL_DX_X = HUGEVAL
FINAL_DZ_Z = HUGEVAL
PREVNORMDX = HUGEVAL
PREV_DZ_Z = HUGEVAL
DZ_Z = HUGEVAL
DX_X = HUGEVAL
X_STATE = WORKING_STATE
Z_STATE = UNSTABLE_STATE
INCR_PREC = .FALSE.
DO CNT = 1, ITHRESH
*
* Compute residual RES = B_s - op(A_s) * Y,
* op(A) = A, A**T, or A**H depending on TRANS (and type).
*
CALL ZCOPY( N, B( 1, J ), 1, RES, 1 )
IF ( Y_PREC_STATE .EQ. BASE_RESIDUAL ) THEN
CALL ZGBMV( TRANS, M, N, KL, KU, (-1.0D+0,0.0D+0), AB,
$ LDAB, Y( 1, J ), 1, (1.0D+0,0.0D+0), RES, 1 )
ELSE IF ( Y_PREC_STATE .EQ. EXTRA_RESIDUAL ) THEN
CALL BLAS_ZGBMV_X( TRANS_TYPE, N, N, KL, KU,
$ (-1.0D+0,0.0D+0), AB, LDAB, Y( 1, J ), 1,
$ (1.0D+0,0.0D+0), RES, 1, PREC_TYPE )
ELSE
CALL BLAS_ZGBMV2_X( TRANS_TYPE, N, N, KL, KU,
$ (-1.0D+0,0.0D+0), AB, LDAB, Y( 1, J ), Y_TAIL, 1,
$ (1.0D+0,0.0D+0), RES, 1, PREC_TYPE )
END IF
! XXX: RES is no longer needed.
CALL ZCOPY( N, RES, 1, DY, 1 )
CALL ZGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV, DY, N,
$ INFO )
*
* Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT.
*
NORMX = 0.0D+0
NORMY = 0.0D+0
NORMDX = 0.0D+0
DZ_Z = 0.0D+0
YMIN = HUGEVAL
DO I = 1, N
YK = CABS1( Y( I, J ) )
DYK = CABS1( DY( I ) )
IF (YK .NE. 0.0D+0) THEN
DZ_Z = MAX( DZ_Z, DYK / YK )
ELSE IF ( DYK .NE. 0.0D+0 ) THEN
DZ_Z = HUGEVAL
END IF
YMIN = MIN( YMIN, YK )
NORMY = MAX( NORMY, YK )
IF ( COLEQU ) THEN
NORMX = MAX( NORMX, YK * C( I ) )
NORMDX = MAX(NORMDX, DYK * C(I))
ELSE
NORMX = NORMY
NORMDX = MAX( NORMDX, DYK )
END IF
END DO
IF ( NORMX .NE. 0.0D+0 ) THEN
DX_X = NORMDX / NORMX
ELSE IF ( NORMDX .EQ. 0.0D+0 ) THEN
DX_X = 0.0D+0
ELSE
DX_X = HUGEVAL
END IF
DXRAT = NORMDX / PREVNORMDX
DZRAT = DZ_Z / PREV_DZ_Z
*
* Check termination criteria.
*
IF (.NOT.IGNORE_CWISE
$ .AND. YMIN*RCOND .LT. INCR_THRESH*NORMY
$ .AND. Y_PREC_STATE .LT. EXTRA_Y )
$ INCR_PREC = .TRUE.
IF ( X_STATE .EQ. NOPROG_STATE .AND. DXRAT .LE. RTHRESH )
$ X_STATE = WORKING_STATE
IF ( X_STATE .EQ. WORKING_STATE ) THEN
IF ( DX_X .LE. EPS ) THEN
X_STATE = CONV_STATE
ELSE IF ( DXRAT .GT. RTHRESH ) THEN
IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
INCR_PREC = .TRUE.
ELSE
X_STATE = NOPROG_STATE
END IF
ELSE
IF ( DXRAT .GT. DXRATMAX ) DXRATMAX = DXRAT
END IF
IF ( X_STATE .GT. WORKING_STATE ) FINAL_DX_X = DX_X
END IF
IF ( Z_STATE .EQ. UNSTABLE_STATE .AND. DZ_Z .LE. DZ_UB )
$ Z_STATE = WORKING_STATE
IF ( Z_STATE .EQ. NOPROG_STATE .AND. DZRAT .LE. RTHRESH )
$ Z_STATE = WORKING_STATE
IF ( Z_STATE .EQ. WORKING_STATE ) THEN
IF ( DZ_Z .LE. EPS ) THEN
Z_STATE = CONV_STATE
ELSE IF ( DZ_Z .GT. DZ_UB ) THEN
Z_STATE = UNSTABLE_STATE
DZRATMAX = 0.0D+0
FINAL_DZ_Z = HUGEVAL
ELSE IF ( DZRAT .GT. RTHRESH ) THEN
IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
INCR_PREC = .TRUE.
ELSE
Z_STATE = NOPROG_STATE
END IF
ELSE
IF ( DZRAT .GT. DZRATMAX ) DZRATMAX = DZRAT
END IF
IF ( Z_STATE .GT. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
END IF
*
* Exit if both normwise and componentwise stopped working,
* but if componentwise is unstable, let it go at least two
* iterations.
*
IF ( X_STATE.NE.WORKING_STATE ) THEN
IF ( IGNORE_CWISE ) GOTO 666
IF ( Z_STATE.EQ.NOPROG_STATE .OR. Z_STATE.EQ.CONV_STATE )
$ GOTO 666
IF ( Z_STATE.EQ.UNSTABLE_STATE .AND. CNT.GT.1 ) GOTO 666
END IF
IF ( INCR_PREC ) THEN
INCR_PREC = .FALSE.
Y_PREC_STATE = Y_PREC_STATE + 1
DO I = 1, N
Y_TAIL( I ) = 0.0D+0
END DO
END IF
PREVNORMDX = NORMDX
PREV_DZ_Z = DZ_Z
*
* Update soluton.
*
IF ( Y_PREC_STATE .LT. EXTRA_Y ) THEN
CALL ZAXPY( N, (1.0D+0,0.0D+0), DY, 1, Y(1,J), 1 )
ELSE
CALL ZLA_WWADDW( N, Y(1,J), Y_TAIL, DY )
END IF
END DO
* Target of "IF (Z_STOP .AND. X_STOP)". Sun's f77 won't EXIT.
666 CONTINUE
*
* Set final_* when cnt hits ithresh.
*
IF ( X_STATE .EQ. WORKING_STATE ) FINAL_DX_X = DX_X
IF ( Z_STATE .EQ. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
*
* Compute error bounds.
*
IF ( N_NORMS .GE. 1 ) THEN
ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) =
$ FINAL_DX_X / (1 - DXRATMAX)
END IF
IF ( N_NORMS .GE. 2 ) THEN
ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) =
$ FINAL_DZ_Z / (1 - DZRATMAX)
END IF
*
* Compute componentwise relative backward error from 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.
*
* Compute residual RES = B_s - op(A_s) * Y,
* op(A) = A, A**T, or A**H depending on TRANS (and type).
*
CALL ZCOPY( N, B( 1, J ), 1, RES, 1 )
CALL ZGBMV( TRANS, N, N, KL, KU, (-1.0D+0,0.0D+0), AB, LDAB,
$ Y(1,J), 1, (1.0D+0,0.0D+0), RES, 1 )
DO I = 1, N
AYB( I ) = CABS1( B( I, J ) )
END DO
*
* Compute abs(op(A_s))*abs(Y) + abs(B_s).
*
CALL ZLA_GBAMV( TRANS_TYPE, N, N, KL, KU, 1.0D+0,
$ AB, LDAB, Y(1, J), 1, 1.0D+0, AYB, 1 )
CALL ZLA_LIN_BERR( N, N, 1, RES, AYB, BERR_OUT( J ) )
*
* End of loop for each RHS.
*
END DO
*
RETURN
*
* End of ZLA_GBRFSX_EXTENDED
*
END
| bsd-3-clause |
rmcgibbo/scipy | scipy/special/cdflib/cumfnc.f | 95 | 4745 | SUBROUTINE cumfnc(f,dfn,dfd,pnonc,cum,ccum)
C**********************************************************************
C
C F -NON- -C-ENTRAL F DISTRIBUTION
C
C
C
C Function
C
C
C COMPUTES NONCENTRAL F DISTRIBUTION WITH DFN AND DFD
C DEGREES OF FREEDOM AND NONCENTRALITY PARAMETER PNONC
C
C
C Arguments
C
C
C X --> UPPER LIMIT OF INTEGRATION OF NONCENTRAL F IN EQUATION
C
C DFN --> DEGREES OF FREEDOM OF NUMERATOR
C
C DFD --> DEGREES OF FREEDOM OF DENOMINATOR
C
C PNONC --> NONCENTRALITY PARAMETER.
C
C CUM <-- CUMULATIVE NONCENTRAL F DISTRIBUTION
C
C CCUM <-- COMPLIMENT OF CUMMULATIVE
C
C
C Method
C
C
C USES FORMULA 26.6.20 OF REFERENCE FOR INFINITE SERIES.
C SERIES IS CALCULATED BACKWARD AND FORWARD FROM J = LAMBDA/2
C (THIS IS THE TERM WITH THE LARGEST POISSON WEIGHT) UNTIL
C THE CONVERGENCE CRITERION IS MET.
C
C FOR SPEED, THE INCOMPLETE BETA FUNCTIONS ARE EVALUATED
C BY FORMULA 26.5.16.
C
C
C REFERENCE
C
C
C HANDBOOD OF MATHEMATICAL FUNCTIONS
C EDITED BY MILTON ABRAMOWITZ AND IRENE A. STEGUN
C NATIONAL BUREAU OF STANDARDS APPLIED MATEMATICS SERIES - 55
C MARCH 1965
C P 947, EQUATIONS 26.6.17, 26.6.18
C
C
C Note
C
C
C THE SUM CONTINUES UNTIL A SUCCEEDING TERM IS LESS THAN EPS
C TIMES THE SUM (OR THE SUM IS LESS THAN 1.0E-20). EPS IS
C SET TO 1.0E-4 IN A DATA STATEMENT WHICH CAN BE CHANGED.
C
C**********************************************************************
C .. Scalar Arguments ..
DOUBLE PRECISION dfd,dfn,pnonc,f,cum,ccum
C ..
C .. Local Scalars ..
DOUBLE PRECISION dsum,dummy,prod,xx,yy
DOUBLE PRECISION adn,aup,b,betdn,betup,centwt,dnterm,eps,sum,
+ upterm,xmult,xnonc,x,abstol
INTEGER i,icent,ierr
C ..
C .. External Functions ..
DOUBLE PRECISION alngam
EXTERNAL alngam
C ..
C .. Intrinsic Functions ..
INTRINSIC log,dble,exp
C ..
C .. Statement Functions ..
LOGICAL qsmall
C ..
C .. External Subroutines ..
EXTERNAL bratio,cumf
C ..
C .. Parameters ..
DOUBLE PRECISION half
PARAMETER (half=0.5D0)
DOUBLE PRECISION done
PARAMETER (done=1.0D0)
C ..
C .. Data statements ..
DATA eps/1.0D-4/
DATA abstol/1.0D-300/
C ..
C .. Statement Function definitions ..
qsmall(x) = sum .LT. abstol .OR. x .LT. eps*sum
C ..
C .. Executable Statements ..
C
IF (.NOT. (f.LE.0.0D0)) GO TO 10
cum = 0.0D0
ccum = 1.0D0
RETURN
10 IF (.NOT. (pnonc.LT.1.0D-10)) GO TO 20
C
C Handle case in which the non-centrality parameter is
C (essentially) zero.
CALL cumf(f,dfn,dfd,cum,ccum)
RETURN
20 xnonc = pnonc/2.0D0
C Calculate the central term of the poisson weighting factor.
icent = xnonc
IF (icent.EQ.0) icent = 1
C Compute central weight term
centwt = exp(-xnonc+icent*log(xnonc)-alngam(dble(icent+1)))
C Compute central incomplete beta term
C Assure that minimum of arg to beta and 1 - arg is computed
C accurately.
prod = dfn*f
dsum = dfd + prod
yy = dfd/dsum
IF (yy.GT.half) THEN
xx = prod/dsum
yy = done - xx
ELSE
xx = done - yy
END IF
CALL bratio(dfn*half+dble(icent),dfd*half,xx,yy,betdn,dummy,ierr)
adn = dfn/2.0D0 + dble(icent)
aup = adn
b = dfd/2.0D0
betup = betdn
sum = centwt*betdn
C Now sum terms backward from icent until convergence or all done
xmult = centwt
i = icent
dnterm = exp(alngam(adn+b)-alngam(adn+1.0D0)-alngam(b)+
+ adn*log(xx)+b*log(yy))
30 IF (qsmall(xmult*betdn) .OR. i.LE.0) GO TO 40
xmult = xmult* (i/xnonc)
i = i - 1
adn = adn - 1
dnterm = (adn+1)/ ((adn+b)*xx)*dnterm
betdn = betdn + dnterm
sum = sum + xmult*betdn
GO TO 30
40 i = icent + 1
C Now sum forwards until convergence
xmult = centwt
IF ((aup-1+b).EQ.0) THEN
upterm = exp(-alngam(aup)-alngam(b)+ (aup-1)*log(xx)+
+ b*log(yy))
ELSE
upterm = exp(alngam(aup-1+b)-alngam(aup)-alngam(b)+
+ (aup-1)*log(xx)+b*log(yy))
END IF
GO TO 60
50 IF (qsmall(xmult*betup)) GO TO 70
60 xmult = xmult* (xnonc/i)
i = i + 1
aup = aup + 1
upterm = (aup+b-2.0D0)*xx/ (aup-1)*upterm
betup = betup - upterm
sum = sum + xmult*betup
GO TO 50
70 cum = sum
ccum = 0.5D0 + (0.5D0-cum)
RETURN
END
| bsd-3-clause |
apollos/Quantum-ESPRESSO | lapack-3.2/SRC/dormr2.f | 1 | 5179 | SUBROUTINE DORMR2( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
$ WORK, INFO )
*
* -- LAPACK routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER SIDE, TRANS
INTEGER INFO, K, LDA, LDC, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DORMR2 overwrites the general real m by n matrix C with
*
* Q * C if SIDE = 'L' and TRANS = 'N', or
*
* Q'* C if SIDE = 'L' and TRANS = 'T', or
*
* C * Q if SIDE = 'R' and TRANS = 'N', or
*
* C * Q' if SIDE = 'R' and TRANS = 'T',
*
* where Q is a real orthogonal matrix defined as the product of k
* elementary reflectors
*
* Q = H(1) H(2) . . . H(k)
*
* as returned by DGERQF. Q is of order m if SIDE = 'L' and of order n
* if SIDE = 'R'.
*
* Arguments
* =========
*
* SIDE (input) CHARACTER*1
* = 'L': apply Q or Q' from the Left
* = 'R': apply Q or Q' from the Right
*
* TRANS (input) CHARACTER*1
* = 'N': apply Q (No transpose)
* = 'T': apply Q' (Transpose)
*
* M (input) INTEGER
* The number of rows of the matrix C. M >= 0.
*
* N (input) INTEGER
* The number of columns of the matrix C. N >= 0.
*
* K (input) INTEGER
* The number of elementary reflectors whose product defines
* the matrix Q.
* If SIDE = 'L', M >= K >= 0;
* if SIDE = 'R', N >= K >= 0.
*
* A (input) DOUBLE PRECISION array, dimension
* (LDA,M) if SIDE = 'L',
* (LDA,N) if SIDE = 'R'
* The i-th row must contain the vector which defines the
* elementary reflector H(i), for i = 1,2,...,k, as returned by
* DGERQF in the last k rows of its array argument A.
* A is modified by the routine but restored on exit.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,K).
*
* TAU (input) DOUBLE PRECISION array, dimension (K)
* TAU(i) must contain the scalar factor of the elementary
* reflector H(i), as returned by DGERQF.
*
* C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
* On entry, the m by n matrix C.
* On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
*
* LDC (input) INTEGER
* The leading dimension of the array C. LDC >= max(1,M).
*
* WORK (workspace) DOUBLE PRECISION array, dimension
* (N) if SIDE = 'L',
* (M) if SIDE = 'R'
*
* 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 LEFT, NOTRAN
INTEGER I, I1, I2, I3, MI, NI, NQ
DOUBLE PRECISION AII
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DLARF, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input arguments
*
INFO = 0
LEFT = LSAME( SIDE, 'L' )
NOTRAN = LSAME( TRANS, 'N' )
*
* NQ is the order of Q
*
IF( LEFT ) THEN
NQ = M
ELSE
NQ = N
END IF
IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
INFO = -2
ELSE IF( M.LT.0 ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN
INFO = -5
ELSE IF( LDA.LT.MAX( 1, K ) ) THEN
INFO = -7
ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
INFO = -10
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DORMR2', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 )
$ RETURN
*
IF( ( LEFT .AND. .NOT.NOTRAN ) .OR. ( .NOT.LEFT .AND. NOTRAN ) )
$ THEN
I1 = 1
I2 = K
I3 = 1
ELSE
I1 = K
I2 = 1
I3 = -1
END IF
*
IF( LEFT ) THEN
NI = N
ELSE
MI = M
END IF
*
DO 10 I = I1, I2, I3
IF( LEFT ) THEN
*
* H(i) is applied to C(1:m-k+i,1:n)
*
MI = M - K + I
ELSE
*
* H(i) is applied to C(1:m,1:n-k+i)
*
NI = N - K + I
END IF
*
* Apply H(i)
*
AII = A( I, NQ-K+I )
A( I, NQ-K+I ) = ONE
CALL DLARF( SIDE, MI, NI, A( I, 1 ), LDA, TAU( I ), C, LDC,
$ WORK )
A( I, NQ-K+I ) = AII
10 CONTINUE
RETURN
*
* End of DORMR2
*
END
| gpl-2.0 |
arm-hpc/papi | src/ftests/tenth.F | 6 | 7102 | #include "fpapi_test.h"
#define ITERS 100
#if defined(sun) && defined(sparc)
#define CACHE_LEVEL "PAPI_L2_TCM"
#define EVT1 PAPI_L2_TCM
#define EVT2 PAPI_L2_TCA
#define EVT3 PAPI_L2_TCH
#define EVT1_STR "PAPI_L2_TCM"
#define EVT2_STR "PAPI_L2_TCA"
#define EVT3_STR "PAPI_L2_TCH"
#else
#if defined(__powerpc__)
#define CACHE_LEVEL "PAPI_L1_DCA"
#define EVT1 PAPI_L1_DCA
#define EVT2 PAPI_L1_DCW
#define EVT3 PAPI_L1_DCR
#define EVT1_STR "PAPI_L1_DCA"
#define EVT2_STR "PAPI_L1_DCW"
#define EVT3_STR "PAPI_L1_DCR"
#else
#define CACHE_LEVEL "PAPI_L1_TCM"
#define EVT1 PAPI_L1_TCM
#define EVT2 PAPI_L1_ICM
#define EVT3 PAPI_L1_DCM
#define EVT1_STR "PAPI_L1_TCM"
#define EVT2_STR "PAPI_L1_ICM"
#define EVT3_STR "PAPI_L1_DCM"
#endif
#endif
program tenth
implicit integer (p)
integer*8 values(10)
integer es1, es2, es3
integer*4 mask1, mask2, mask3
integer domain, granularity
character*(PAPI_MAX_STR_LEN) domainstr, grnstr
integer retval
Integer last_char
External last_char
integer tests_quiet, get_quiet
external get_quiet
tests_quiet = get_quiet()
es1 = PAPI_NULL
es2 = PAPI_NULL
es3 = PAPI_NULL
mask1 = EVT1
mask2 = EVT2
mask3 = EVT3
retval = PAPI_VER_CURRENT
call PAPIf_library_init(retval)
if ( retval.NE.PAPI_VER_CURRENT) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPI_library_init', retval)
end if
call PAPIf_query_event(mask1, retval)
if ( retval.NE.PAPI_OK) then
call ftest_skip(__FILE__, __LINE__,
.'PAPIf_query_event', retval)
end if
call PAPIf_query_event(mask2, retval)
if ( retval.NE.PAPI_OK) then
call ftest_skip(__FILE__, __LINE__,
.'PAPIf_query_event', retval)
end if
call PAPIf_query_event(mask3, retval)
if ( retval.NE.PAPI_OK) then
call ftest_skip(__FILE__, __LINE__,
.'PAPIf_query_event', retval)
end if
call PAPIf_create_eventset(es1, retval)
if ( retval.NE.PAPI_OK) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_create_eventset',
*retval)
end if
call PAPIf_add_event( es1, mask1, retval )
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_add_event', retval)
end if
call PAPIf_create_eventset(es2, retval)
if ( retval.NE.PAPI_OK) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_create_eventset',
*retval)
end if
call PAPIf_add_event( es2, mask2, retval )
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_add_event', retval)
end if
call PAPIf_create_eventset(es3, retval)
if ( retval.NE.PAPI_OK) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_create_eventset',
* retval)
end if
call PAPIf_add_event( es3, mask3, retval )
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_add_event', retval)
end if
call fdo_l1misses(ITERS)
call PAPIf_start(es1, retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_start', retval)
end if
call fdo_l1misses(ITERS)
call PAPIf_stop(es1, values(1), retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_stop', retval)
end if
call PAPIf_start(es2, retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_start', retval)
end if
call fdo_l1misses(ITERS)
call PAPIf_stop(es2, values(3), retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_stop', retval)
end if
call PAPIf_start(es3, retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_start', retval)
end if
call fdo_l1misses(ITERS)
call PAPIf_stop(es3, values(5), retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_stop', retval)
end if
call PAPIf_remove_event( es1, mask1, retval )
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_remove_event', retval)
end if
call PAPIf_remove_event( es2, mask2, retval )
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_remove_event', retval)
end if
call PAPIf_remove_event( es3, mask3, retval )
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_remove_event', retval)
end if
if (tests_quiet .EQ. 0) then
#if (defined(sun) && defined(sparc))
print *, "Test case 10: start, stop for derived event ",
*"PAPI_L2_TCM."
#else
print *, "Test case 10: start, stop for derived event ",
*"PAPI_L1_TCM."
#endif
print *, "------------------------------------------------------"
end if
call PAPIf_get_domain(es1, domain, PAPI_DEFDOM, retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_get_domain', retval)
end if
call stringify_domain(domain, domainstr)
if (tests_quiet .EQ. 0) then
write (*,900) "Default domain is:", domain, domainstr
900 format(a20, i3, " ", a70)
end if
call PAPIf_get_granularity(es1, granularity, PAPI_DEFGRN,
*retval)
if ( retval .NE. PAPI_OK ) then
call ftest_fail(__FILE__, __LINE__,
. 'PAPIf_get_granularity',
*retval)
end if
call stringify_granularity(granularity, grnstr)
if (tests_quiet .EQ. 0) then
write (*,800) "Default granularity is:", granularity, grnstr
800 format(a25, i3, " ", a20)
print *, "Using", NUM_FLOPS, " iterations of c += b*c"
print *, "------------------------------------------------------"
write (*,500) "Test type", 1, 2, 3
#if (defined(sun) && defined(sparc))
write (*,500) EVT1_STR, values(1), 0, 0
write (*,500) EVT2_STR, 0, values(3), 0
write (*,500) EVT3_STR, 0, 0, values(5)
print *, "------------------------------------------------",
*"------"
print *, "Verification:"
print *, "First number row 1 approximately equals (2,2) - (3,3) ",
*"or ",(values(3)-values(5))
#else
write (*,500) EVT1_STR, values(1), 0, 0
write (*,500) EVT2_STR, 0, values(3), 0
write (*,500) EVT3_STR, 0, 0, values(5)
print *, "------------------------------------------------",
*"------"
print *, "Verification:"
print *, "First number row 1 approximately equals (2,2) + (3,3) ",
*"or ", (values(3)+values(5))
#endif
end if
500 format(A13, ": ", I10, I10, I10)
call ftests_pass(__FILE__)
end
| bsd-3-clause |
specfem3d-zhang-ksu/specfem3d | src/shared/prepare_assemble_MPI.f90 | 4 | 13428 | !=====================================================================
!
! S p e c f e m 3 D V e r s i o n 3 . 0
! ---------------------------------------
!
! Main historical authors: Dimitri Komatitsch and Jeroen Tromp
! Princeton University, USA
! and CNRS / University of Marseille, France
! (there are currently many more authors!)
! (c) Princeton University and CNRS / University of Marseille, July 2012
!
! 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.,
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
!
!=====================================================================
subroutine prepare_assemble_MPI (nelmnts,knods, &
ibool,npoin, &
ninterface, max_interface_size, &
my_nelmnts_neighbours, my_interfaces, &
ibool_interfaces_ext_mesh, &
nibool_interfaces_ext_mesh,NGNOD )
! returns: ibool_interfaces_ext_mesh with the global indices (as defined in ibool)
! nibool_interfaces_ext_mesh with the number of points in ibool_interfaces_ext_mesh
!
! for all points on the interface defined by ninterface, my_nelmnts_neighbours and my_interfaces
use constants
implicit none
! spectral element indexing
! ( nelmnts = number of spectral elements
! NGNOD = number of element control points
! knods = corner indices array )
integer, intent(in) :: NGNOD,nelmnts
integer, dimension(NGNOD,nelmnts), intent(in) :: knods
! global number of points
integer, intent(in) :: npoin
! global indexing
integer, dimension(NGLLX,NGLLY,NGLLZ,nelmnts), intent(in) :: ibool
! MPI interfaces
integer :: ninterface
integer :: max_interface_size
integer, dimension(ninterface) :: my_nelmnts_neighbours
integer, dimension(6,max_interface_size,ninterface) :: my_interfaces
integer, dimension(NGLLX*NGLLX*max_interface_size,ninterface) :: ibool_interfaces_ext_mesh
integer, dimension(ninterface) :: nibool_interfaces_ext_mesh
! local parameters
integer :: num_interface
integer :: ispec_interface
logical, dimension(:),allocatable :: mask_ibool_ext_mesh
integer :: ixmin, ixmax, iymin, iymax, izmin, izmax
integer, dimension(NGNOD_EIGHT_CORNERS) :: n
integer :: e1, e2, e3, e4
integer :: ispec,k,ix,iy,iz,ier,itype,iglob
integer :: npoin_interface_ext_mesh
! initializes
allocate( mask_ibool_ext_mesh(npoin), stat=ier); if (ier /= 0) stop 'error allocating array'
ibool_interfaces_ext_mesh(:,:) = 0
nibool_interfaces_ext_mesh(:) = 0
! loops over MPI interfaces
do num_interface = 1, ninterface
npoin_interface_ext_mesh = 0
mask_ibool_ext_mesh(:) = .false.
! loops over number of elements on interface
do ispec_interface = 1, my_nelmnts_neighbours(num_interface)
! spectral element on interface
ispec = my_interfaces(1,ispec_interface,num_interface)
! type of interface: (1) corner point, (2) edge, (4) face
itype = my_interfaces(2,ispec_interface,num_interface)
! gets spectral element corner indices (defines all nodes of face/edge)
do k = 1, NGNOD_EIGHT_CORNERS
n(k) = knods(k,ispec)
enddo
! interface node ids
e1 = my_interfaces(3,ispec_interface,num_interface)
e2 = my_interfaces(4,ispec_interface,num_interface)
e3 = my_interfaces(5,ispec_interface,num_interface)
e4 = my_interfaces(6,ispec_interface,num_interface)
! gets i,j,k ranges for interface type
call get_edge(n, itype, e1, e2, e3, e4, &
ixmin, ixmax, iymin, iymax, izmin, izmax)
! counts number and stores indices of (global) points on MPI interface
do iz = min(izmin,izmax), max(izmin,izmax)
do iy = min(iymin,iymax), max(iymin,iymax)
do ix = min(ixmin,ixmax), max(ixmin,ixmax)
! global index
iglob = ibool(ix,iy,iz,ispec)
! stores global index of point on interface
if (.not. mask_ibool_ext_mesh(iglob)) then
! masks point as being accounted for
mask_ibool_ext_mesh(iglob) = .true.
! adds point to interface
npoin_interface_ext_mesh = npoin_interface_ext_mesh + 1
ibool_interfaces_ext_mesh(npoin_interface_ext_mesh,num_interface) = iglob
endif
enddo
enddo
enddo
enddo
! stores total number of (global) points on this MPI interface
nibool_interfaces_ext_mesh(num_interface) = npoin_interface_ext_mesh
enddo
deallocate( mask_ibool_ext_mesh )
end subroutine prepare_assemble_MPI
!
!----
!
subroutine get_edge ( n, itype, e1, e2, e3, e4, &
ixmin, ixmax, iymin, iymax, izmin, izmax )
! returns range of local (GLL) point indices i,j,k depending on given type
! for corner point (1), edge (2) or face (4)
use constants
implicit none
! corner node indices per spectral element (8)
integer, dimension(NGNOD_EIGHT_CORNERS), intent(in) :: n
! interface type & nodes
integer, intent(in) :: itype, e1, e2, e3, e4
! local (GLL) i,j,k index ranges
integer, intent(out) :: ixmin, ixmax, iymin, iymax, izmin, izmax
! local parameters
integer, dimension(4) :: en
integer :: valence, i
! determines local indexes for corners/edges/faces
if (itype == 1) then
! corner point
if (e1 == n(1)) then
ixmin = 1
ixmax = 1
iymin = 1
iymax = 1
izmin = 1
izmax = 1
endif
if (e1 == n(2)) then
ixmin = NGLLX
ixmax = NGLLX
iymin = 1
iymax = 1
izmin = 1
izmax = 1
endif
if (e1 == n(3)) then
ixmin = NGLLX
ixmax = NGLLX
iymin = NGLLY
iymax = NGLLY
izmin = 1
izmax = 1
endif
if (e1 == n(4)) then
ixmin = 1
ixmax = 1
iymin = NGLLY
iymax = NGLLY
izmin = 1
izmax = 1
endif
if (e1 == n(5)) then
ixmin = 1
ixmax = 1
iymin = 1
iymax = 1
izmin = NGLLZ
izmax = NGLLZ
endif
if (e1 == n(6)) then
ixmin = NGLLX
ixmax = NGLLX
iymin = 1
iymax = 1
izmin = NGLLZ
izmax = NGLLZ
endif
if (e1 == n(7)) then
ixmin = NGLLX
ixmax = NGLLX
iymin = NGLLY
iymax = NGLLY
izmin = NGLLZ
izmax = NGLLZ
endif
if (e1 == n(8)) then
ixmin = 1
ixmax = 1
iymin = NGLLY
iymax = NGLLY
izmin = NGLLZ
izmax = NGLLZ
endif
else if (itype == 2) then
! edges
if (e1 == n(1)) then
ixmin = 1
iymin = 1
izmin = 1
if (e2 == n(2)) then
ixmax = NGLLX
iymax = 1
izmax = 1
endif
if (e2 == n(4)) then
ixmax = 1
iymax = NGLLY
izmax = 1
endif
if (e2 == n(5)) then
ixmax = 1
iymax = 1
izmax = NGLLZ
endif
endif
if (e1 == n(2)) then
ixmin = NGLLX
iymin = 1
izmin = 1
if (e2 == n(3)) then
ixmax = NGLLX
iymax = NGLLY
izmax = 1
endif
if (e2 == n(1)) then
ixmax = 1
iymax = 1
izmax = 1
endif
if (e2 == n(6)) then
ixmax = NGLLX
iymax = 1
izmax = NGLLZ
endif
endif
if (e1 == n(3)) then
ixmin = NGLLX
iymin = NGLLY
izmin = 1
if (e2 == n(4)) then
ixmax = 1
iymax = NGLLY
izmax = 1
endif
if (e2 == n(2)) then
ixmax = NGLLX
iymax = 1
izmax = 1
endif
if (e2 == n(7)) then
ixmax = NGLLX
iymax = NGLLY
izmax = NGLLZ
endif
endif
if (e1 == n(4)) then
ixmin = 1
iymin = NGLLY
izmin = 1
if (e2 == n(1)) then
ixmax = 1
iymax = 1
izmax = 1
endif
if (e2 == n(3)) then
ixmax = NGLLX
iymax = NGLLY
izmax = 1
endif
if (e2 == n(8)) then
ixmax = 1
iymax = NGLLY
izmax = NGLLZ
endif
endif
if (e1 == n(5)) then
ixmin = 1
iymin = 1
izmin = NGLLZ
if (e2 == n(1)) then
ixmax = 1
iymax = 1
izmax = 1
endif
if (e2 == n(6)) then
ixmax = NGLLX
iymax = 1
izmax = NGLLZ
endif
if (e2 == n(8)) then
ixmax = 1
iymax = NGLLY
izmax = NGLLZ
endif
endif
if (e1 == n(6)) then
ixmin = NGLLX
iymin = 1
izmin = NGLLZ
if (e2 == n(2)) then
ixmax = NGLLX
iymax = 1
izmax = 1
endif
if (e2 == n(7)) then
ixmax = NGLLX
iymax = NGLLY
izmax = NGLLZ
endif
if (e2 == n(5)) then
ixmax = 1
iymax = 1
izmax = NGLLZ
endif
endif
if (e1 == n(7)) then
ixmin = NGLLX
iymin = NGLLY
izmin = NGLLZ
if (e2 == n(3)) then
ixmax = NGLLX
iymax = NGLLY
izmax = 1
endif
if (e2 == n(8)) then
ixmax = 1
iymax = NGLLY
izmax = NGLLZ
endif
if (e2 == n(6)) then
ixmax = NGLLX
iymax = 1
izmax = NGLLZ
endif
endif
if (e1 == n(8)) then
ixmin = 1
iymin = NGLLY
izmin = NGLLZ
if (e2 == n(4)) then
ixmax = 1
iymax = NGLLY
izmax = 1
endif
if (e2 == n(5)) then
ixmax = 1
iymax = 1
izmax = NGLLZ
endif
if (e2 == n(7)) then
ixmax = NGLLX
iymax = NGLLY
izmax = NGLLZ
endif
endif
else if (itype == 4) then
! face corners
en(1) = e1
en(2) = e2
en(3) = e3
en(4) = e4
! zmin face
valence = 0
do i = 1, 4
if (en(i) == n(1)) then
valence = valence+1
endif
if (en(i) == n(2)) then
valence = valence+1
endif
if (en(i) == n(3)) then
valence = valence+1
endif
if (en(i) == n(4)) then
valence = valence+1
endif
enddo
if (valence == 4) then
ixmin = 1
iymin = 1
izmin = 1
ixmax = NGLLX
iymax = NGLLY
izmax = 1
endif
! ymin face
valence = 0
do i = 1, 4
if (en(i) == n(1)) then
valence = valence+1
endif
if (en(i) == n(2)) then
valence = valence+1
endif
if (en(i) == n(5)) then
valence = valence+1
endif
if (en(i) == n(6)) then
valence = valence+1
endif
enddo
if (valence == 4) then
ixmin = 1
iymin = 1
izmin = 1
ixmax = NGLLX
iymax = 1
izmax = NGLLZ
endif
! xmax face
valence = 0
do i = 1, 4
if (en(i) == n(2)) then
valence = valence+1
endif
if (en(i) == n(3)) then
valence = valence+1
endif
if (en(i) == n(6)) then
valence = valence+1
endif
if (en(i) == n(7)) then
valence = valence+1
endif
enddo
if (valence == 4) then
ixmin = NGLLX
iymin = 1
izmin = 1
ixmax = NGLLX
iymax = NGLLZ
izmax = NGLLZ
endif
! ymax face
valence = 0
do i = 1, 4
if (en(i) == n(3)) then
valence = valence+1
endif
if (en(i) == n(4)) then
valence = valence+1
endif
if (en(i) == n(7)) then
valence = valence+1
endif
if (en(i) == n(8)) then
valence = valence+1
endif
enddo
if (valence == 4) then
ixmin = 1
iymin = NGLLY
izmin = 1
ixmax = NGLLX
iymax = NGLLY
izmax = NGLLZ
endif
! xmin face
valence = 0
do i = 1, 4
if (en(i) == n(1)) then
valence = valence+1
endif
if (en(i) == n(4)) then
valence = valence+1
endif
if (en(i) == n(5)) then
valence = valence+1
endif
if (en(i) == n(8)) then
valence = valence+1
endif
enddo
if (valence == 4) then
ixmin = 1
iymin = 1
izmin = 1
ixmax = 1
iymax = NGLLY
izmax = NGLLZ
endif
! zmax face
valence = 0
do i = 1, 4
if (en(i) == n(5)) then
valence = valence+1
endif
if (en(i) == n(6)) then
valence = valence+1
endif
if (en(i) == n(7)) then
valence = valence+1
endif
if (en(i) == n(8)) then
valence = valence+1
endif
enddo
if (valence == 4) then
ixmin = 1
iymin = 1
izmin = NGLLZ
ixmax = NGLLX
iymax = NGLLY
izmax = NGLLZ
endif
else
stop 'ERROR get_edge'
endif
! endif
! endif
end subroutine get_edge
| gpl-2.0 |
apollos/Quantum-ESPRESSO | lapack-3.2/SRC/zlargv.f | 1 | 7238 | SUBROUTINE ZLARGV( N, X, INCX, Y, INCY, C, INCC )
*
* -- LAPACK auxiliary routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
INTEGER INCC, INCX, INCY, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION C( * )
COMPLEX*16 X( * ), Y( * )
* ..
*
* Purpose
* =======
*
* ZLARGV generates a vector of complex plane rotations with real
* cosines, determined by elements of the complex vectors x and y.
* For i = 1,2,...,n
*
* ( c(i) s(i) ) ( x(i) ) = ( r(i) )
* ( -conjg(s(i)) c(i) ) ( y(i) ) = ( 0 )
*
* where c(i)**2 + ABS(s(i))**2 = 1
*
* The following conventions are used (these are the same as in ZLARTG,
* but differ from the BLAS1 routine ZROTG):
* If y(i)=0, then c(i)=1 and s(i)=0.
* If x(i)=0, then c(i)=0 and s(i) is chosen so that r(i) is real.
*
* Arguments
* =========
*
* N (input) INTEGER
* The number of plane rotations to be generated.
*
* X (input/output) COMPLEX*16 array, dimension (1+(N-1)*INCX)
* On entry, the vector x.
* On exit, x(i) is overwritten by r(i), for i = 1,...,n.
*
* INCX (input) INTEGER
* The increment between elements of X. INCX > 0.
*
* Y (input/output) COMPLEX*16 array, dimension (1+(N-1)*INCY)
* On entry, the vector y.
* On exit, the sines of the plane rotations.
*
* INCY (input) INTEGER
* The increment between elements of Y. INCY > 0.
*
* C (output) DOUBLE PRECISION array, dimension (1+(N-1)*INCC)
* The cosines of the plane rotations.
*
* INCC (input) INTEGER
* The increment between elements of C. INCC > 0.
*
* Further Details
* ======= =======
*
* 6-6-96 - Modified with a new algorithm by W. Kahan and J. Demmel
*
* This version has a few statements commented out for thread safety
* (machine parameters are computed on each entry). 10 feb 03, SJH.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION TWO, ONE, ZERO
PARAMETER ( TWO = 2.0D+0, ONE = 1.0D+0, ZERO = 0.0D+0 )
COMPLEX*16 CZERO
PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) )
* ..
* .. Local Scalars ..
* LOGICAL FIRST
INTEGER COUNT, I, IC, IX, IY, J
DOUBLE PRECISION CS, D, DI, DR, EPS, F2, F2S, G2, G2S, SAFMIN,
$ SAFMN2, SAFMX2, SCALE
COMPLEX*16 F, FF, FS, G, GS, R, SN
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH, DLAPY2
EXTERNAL DLAMCH, DLAPY2
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, INT, LOG,
$ MAX, SQRT
* ..
* .. Statement Functions ..
DOUBLE PRECISION ABS1, ABSSQ
* ..
* .. Save statement ..
* SAVE FIRST, SAFMX2, SAFMIN, SAFMN2
* ..
* .. Data statements ..
* DATA FIRST / .TRUE. /
* ..
* .. Statement Function definitions ..
ABS1( FF ) = MAX( ABS( DBLE( FF ) ), ABS( DIMAG( FF ) ) )
ABSSQ( FF ) = DBLE( FF )**2 + DIMAG( FF )**2
* ..
* .. Executable Statements ..
*
* IF( FIRST ) THEN
* FIRST = .FALSE.
SAFMIN = DLAMCH( 'S' )
EPS = DLAMCH( 'E' )
SAFMN2 = DLAMCH( 'B' )**INT( LOG( SAFMIN / EPS ) /
$ LOG( DLAMCH( 'B' ) ) / TWO )
SAFMX2 = ONE / SAFMN2
* END IF
IX = 1
IY = 1
IC = 1
DO 60 I = 1, N
F = X( IX )
G = Y( IY )
*
* Use identical algorithm as in ZLARTG
*
SCALE = MAX( ABS1( F ), ABS1( G ) )
FS = F
GS = G
COUNT = 0
IF( SCALE.GE.SAFMX2 ) THEN
10 CONTINUE
COUNT = COUNT + 1
FS = FS*SAFMN2
GS = GS*SAFMN2
SCALE = SCALE*SAFMN2
IF( SCALE.GE.SAFMX2 )
$ GO TO 10
ELSE IF( SCALE.LE.SAFMN2 ) THEN
IF( G.EQ.CZERO ) THEN
CS = ONE
SN = CZERO
R = F
GO TO 50
END IF
20 CONTINUE
COUNT = COUNT - 1
FS = FS*SAFMX2
GS = GS*SAFMX2
SCALE = SCALE*SAFMX2
IF( SCALE.LE.SAFMN2 )
$ GO TO 20
END IF
F2 = ABSSQ( FS )
G2 = ABSSQ( GS )
IF( F2.LE.MAX( G2, ONE )*SAFMIN ) THEN
*
* This is a rare case: F is very small.
*
IF( F.EQ.CZERO ) THEN
CS = ZERO
R = DLAPY2( DBLE( G ), DIMAG( G ) )
* Do complex/real division explicitly with two real
* divisions
D = DLAPY2( DBLE( GS ), DIMAG( GS ) )
SN = DCMPLX( DBLE( GS ) / D, -DIMAG( GS ) / D )
GO TO 50
END IF
F2S = DLAPY2( DBLE( FS ), DIMAG( FS ) )
* G2 and G2S are accurate
* G2 is at least SAFMIN, and G2S is at least SAFMN2
G2S = SQRT( G2 )
* Error in CS from underflow in F2S is at most
* UNFL / SAFMN2 .lt. sqrt(UNFL*EPS) .lt. EPS
* If MAX(G2,ONE)=G2, then F2 .lt. G2*SAFMIN,
* and so CS .lt. sqrt(SAFMIN)
* If MAX(G2,ONE)=ONE, then F2 .lt. SAFMIN
* and so CS .lt. sqrt(SAFMIN)/SAFMN2 = sqrt(EPS)
* Therefore, CS = F2S/G2S / sqrt( 1 + (F2S/G2S)**2 ) = F2S/G2S
CS = F2S / G2S
* Make sure abs(FF) = 1
* Do complex/real division explicitly with 2 real divisions
IF( ABS1( F ).GT.ONE ) THEN
D = DLAPY2( DBLE( F ), DIMAG( F ) )
FF = DCMPLX( DBLE( F ) / D, DIMAG( F ) / D )
ELSE
DR = SAFMX2*DBLE( F )
DI = SAFMX2*DIMAG( F )
D = DLAPY2( DR, DI )
FF = DCMPLX( DR / D, DI / D )
END IF
SN = FF*DCMPLX( DBLE( GS ) / G2S, -DIMAG( GS ) / G2S )
R = CS*F + SN*G
ELSE
*
* This is the most common case.
* Neither F2 nor F2/G2 are less than SAFMIN
* F2S cannot overflow, and it is accurate
*
F2S = SQRT( ONE+G2 / F2 )
* Do the F2S(real)*FS(complex) multiply with two real
* multiplies
R = DCMPLX( F2S*DBLE( FS ), F2S*DIMAG( FS ) )
CS = ONE / F2S
D = F2 + G2
* Do complex/real division explicitly with two real divisions
SN = DCMPLX( DBLE( R ) / D, DIMAG( R ) / D )
SN = SN*DCONJG( GS )
IF( COUNT.NE.0 ) THEN
IF( COUNT.GT.0 ) THEN
DO 30 J = 1, COUNT
R = R*SAFMX2
30 CONTINUE
ELSE
DO 40 J = 1, -COUNT
R = R*SAFMN2
40 CONTINUE
END IF
END IF
END IF
50 CONTINUE
C( IC ) = CS
Y( IY ) = SN
X( IX ) = R
IC = IC + INCC
IY = IY + INCY
IX = IX + INCX
60 CONTINUE
RETURN
*
* End of ZLARGV
*
END
| gpl-2.0 |
victorsndvg/feconv | source/patran/module_fuerzas.f90 | 1 | 3156 | module module_fuerzas_fcnv
!-----------------------------------------------------------------------
! Modulo para guardar las condiciones sobre la fuerza
! Last update: 30/07/2009
! Programmer: fran.pena@usc.es
!
! ATRIBUTOS PRIVADOS DE CLASE:
! val: matrix 3 x n de valores de la fuerza
! (cada fila de 'val' indica los valores de la condicion n-esima)
! nod: para cada n, nodos asociados a la condicion n-esima
!
! METODOS PUBLICOS:
! set_FORCE: para cada linea con una condicion SPC, almacena (val, nod)
! assign_FORCE: asigna los numeros de referencia Neumann a cada nodo
!-----------------------------------------------------------------------
use basicmod, only: string
use module_ALLOC_int_alloc_r2_fcnv
use module_ALLOC_real_r2_fcnv
implicit none
!Variables
integer, private :: ncond = 0 !numero total de condiciones
real, private, dimension(:,:), allocatable :: val !valores de la fuerza
type(int_alloc_r2), private :: nod !nodos asociados a la condicion
contains
!-----------------------------------------------------------------------
! set_SPC: para cada linea con una entrada FORCE, almacena (val, nod)
!
! Lectura del cammpo SPC: MD Nastran 2006. Quick Reference Guide (p.1550)
! FORCE: (A8)
! SID: Load set identification number. (I8)
! G: Grid point identification number. (I8)
! CID: Coordinate system identification number. (I8)
! F: Scale factor. (Real, 8 pos.)
! N1, N2, N3: Components of a vector [...] (Real, 8 pos.)
!-----------------------------------------------------------------------
subroutine set_FORCE(iu)
integer, intent(in) :: iu !identificador del fichero
integer :: SID, G, CID
character(len=8) :: FORCE, F, N1, N2, N3
real, dimension(3) :: newval
integer :: res, i
newval = 0.
! lectura del registro
read(unit=iu, fmt='(A8,I8,I8,I8,A8,A8,A8,A8)', iostat=res) FORCE, SID, G, CID, F, N1, N2, N3
if (res /= 0) call info('(module_desplazamientos/set_FORCE) Unable to read record')
newval = (/ real(N1), real(N2), real(N3) /) !construcci�n de newval
do i = 1, ncond
if (maxval(abs(val(:,i)-newval)) < epsilon(1.)) then !condicion ya guardada (en i)
call set(nod, G, row=i, fit_col=.true.)
exit
end if
end do
if (i > ncond) then !la condicion no estaba guardada
ncond = ncond + 1
call set(val, newval, col=ncond, fit_row=.true.)
call set(nod, G, row=ncond, fit_col=.true.)
end if
end subroutine
!-----------------------------------------------------------------------
! assign_FORCE: asigna los numeros de referencia Neumann a cada nodo
!-----------------------------------------------------------------------
subroutine assign_FORCE(nnrv, nD)
integer, dimension(:) :: nnrv !numeros de referencia (por nodo)
integer, intent(in) :: nD !numero total de condiciones Dirichlet (ya asignadas)
integer :: i, j, n
do i = 1, ncond
do j = 1, size(nod%row(i)%col, 1)
n = nod%row(i)%col(j)
! si no tiene Dirichlet, se le asigna el mayor valor de Neumann
if (nnrv(n) <=0 .or. nD < nnrv(n)) nnrv(n) = nD + i
end do
end do
end subroutine
end module
| gpl-3.0 |
xhteam/external-eigen | blas/lsame.f | 211 | 2324 | LOGICAL FUNCTION LSAME(CA,CB)
*
* -- LAPACK auxiliary routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER CA,CB
* ..
*
* Purpose
* =======
*
* LSAME returns .TRUE. if CA is the same letter as CB regardless of
* case.
*
* Arguments
* =========
*
* CA (input) CHARACTER*1
*
* CB (input) CHARACTER*1
* CA and CB specify the single characters to be compared.
*
* =====================================================================
*
* .. Intrinsic Functions ..
INTRINSIC ICHAR
* ..
* .. Local Scalars ..
INTEGER INTA,INTB,ZCODE
* ..
*
* Test if the characters are equal
*
LSAME = CA .EQ. CB
IF (LSAME) RETURN
*
* Now test for equivalence if both characters are alphabetic.
*
ZCODE = ICHAR('Z')
*
* Use 'Z' rather than 'A' so that ASCII can be detected on Prime
* machines, on which ICHAR returns a value with bit 8 set.
* ICHAR('A') on Prime machines returns 193 which is the same as
* ICHAR('A') on an EBCDIC machine.
*
INTA = ICHAR(CA)
INTB = ICHAR(CB)
*
IF (ZCODE.EQ.90 .OR. ZCODE.EQ.122) THEN
*
* ASCII is assumed - ZCODE is the ASCII code of either lower or
* upper case 'Z'.
*
IF (INTA.GE.97 .AND. INTA.LE.122) INTA = INTA - 32
IF (INTB.GE.97 .AND. INTB.LE.122) INTB = INTB - 32
*
ELSE IF (ZCODE.EQ.233 .OR. ZCODE.EQ.169) THEN
*
* EBCDIC is assumed - ZCODE is the EBCDIC code of either lower or
* upper case 'Z'.
*
IF (INTA.GE.129 .AND. INTA.LE.137 .OR.
+ INTA.GE.145 .AND. INTA.LE.153 .OR.
+ INTA.GE.162 .AND. INTA.LE.169) INTA = INTA + 64
IF (INTB.GE.129 .AND. INTB.LE.137 .OR.
+ INTB.GE.145 .AND. INTB.LE.153 .OR.
+ INTB.GE.162 .AND. INTB.LE.169) INTB = INTB + 64
*
ELSE IF (ZCODE.EQ.218 .OR. ZCODE.EQ.250) THEN
*
* ASCII is assumed, on Prime machines - ZCODE is the ASCII code
* plus 128 of either lower or upper case 'Z'.
*
IF (INTA.GE.225 .AND. INTA.LE.250) INTA = INTA - 32
IF (INTB.GE.225 .AND. INTB.LE.250) INTB = INTB - 32
END IF
LSAME = INTA .EQ. INTB
*
* RETURN
*
* End of LSAME
*
END
| bsd-3-clause |
abinit/abinit | src/78_effpot/m_spin_hist.F90 | 1 | 14330 | !!****m* ABINIT/m_spin_hist
!! NAME
!! m_spin_hist
!!
!! FUNCTION
!! This module contains definition the type spin_hist_t
!! and its related routines
!! The observables are also calculated.
!!
!! Datatypes:
!!
!! * spin_hist_t: history record of spin orientations and amplitudes
!!
!! Subroutines:
!!
!! * init
!! * free
!! * spin_hist_t
!! * get_S
!! * findIndex
!! * set_vars
!! * set_params
!!
!!
!! COPYRIGHT
!! Copyright (C) 2001-2021 ABINIT group (hexu)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!! For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
!!
!! SOURCE
! TODO hexu:
! sync ihist_latt when with lattice dynamics
! add average, variance, etc (should they be here?)
! structural information and some parameters are no longer
! used here. They should be removed form this file.
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
module m_spin_hist
use defs_basis
use m_abicore
use m_errors
use m_xmpi
implicit none
private
!!***
!----------------------------------------------------------------------
!!****t* m_spin_hist/spin_hist_t
!! NAME
!! spin_hist_t
!!
!! FUNCTION
!! This type has several vectors, and index scalars to store
!! a proper history of previous evaluations of forces and
!! stresses,velocities,positions and energies
!!
!! It contains:
!! * mxhist : Maximum size of history
!! * ihist : index of history
!! natoms : number of atoms
!! nspin: number of magnetic atoms
!! * acell(3) : Acell (acell , rprimd, xred: only initial value kept if there is!! no lattice dynamics. Other wise for each step, the corresponding lattice step number is kept)
!! * rprimd(3,3) : Rprimd
!! * xred(3,natoms) : Xred
!! * index_spin : the index of atom in spin model, -1 if it is not in the spin model
!! * heff(3,nspin,mxhist) : effective magnetic field (cartesian)
!! * snorm(nspin, mxhist) : magnetitude of spin.
!! * S(3,nspin,mxhist) : spin orientation of atoms (cartesian)
!! * dSdt(3, nspin, mxhist) : dS/dt (cartesian)
!! * etot(mxhist) : Electronic total Energy
!! * entropy(mxhist) : Entropy
!! * itime(mxhist) : index of spin dynamics step.
!! * time(mxhist) : Time (or iteration number for GO)
!!
!! * has_latt (whether lattice dynamics is also present)
!! * ihist_latt(mxhist): the corresponding lattice step. 0 if none.
!! SOURCE
type, public :: spin_hist_t
! scalars
! Index of the last element on all records
integer :: ihist = 0
integer :: ihist_prev = -1
! Maximun size of the historical records
integer :: mxhist = 0
integer :: nspin, nspin_prim
! whether lattice dynamics is also present
integer, allocatable :: ihist_latt(:)
logical :: has_latt
! arrays
! placeholders for structure-related parameters. They are not used currently.
integer :: natoms
real(dp) :: acell(3)
real(dp) :: rprimd(3,3)
real(dp), allocatable :: xred(:, :)
integer :: ntypat
integer, allocatable :: typat(:)
real(dp), allocatable :: znucl(:)
integer, allocatable :: spin_index(:)
! spin
!heff(3, nspin, mxhist)
real(dp), allocatable :: heff(:, :, :)
!snorm(nspin, mxhist)
real(dp), allocatable :: snorm(:, :)
!S(3, nspin, mxhist)
real(dp), allocatable :: S(:, :, :)
!dSdt(3, nspin, mxhist)
! TODO hexu: is it useful?
real(dp), allocatable :: dSdt(:, :, :)
! etot(mxhist)
real(dp), allocatable :: etot(:)
real(dp), allocatable :: entropy(:)
real(dp), allocatable :: time(:)
integer, allocatable :: itime(:)
! spin_nctime: interval of step for writing to netcdf hist file.
integer :: spin_nctime
real(dp) :: spin_temperature
! observables
integer:: calc_thermo_obs, calc_traj_obs, calc_correlation_obs
real(dp), allocatable :: ms_sub(:,:) ! staggered M.
real(dp), allocatable :: Cv(:) ! specfic heat
real(dp), allocatable :: binderU4_sub(:,:), binderU4(:)
real(dp), allocatable :: chi_sub(:, :), chi(:) ! magnetic susceptibility
real(dp), allocatable :: rcorr(:,:)
real(dp), allocatable :: sp_corr_func(:,:,:)
contains
procedure :: initialize
procedure :: finalize
procedure :: reset
procedure :: set_vars
procedure :: get_S => get_S
procedure :: findIndex => findIndex
procedure :: set_params => set_params
procedure :: inc1
end type spin_hist_t
!!***
!public :: spinhist2var
!public :: var2spinhist
!public :: write_sd_hist
!public :: read_md_hist
!public :: get_dims_spinhist
contains
!!****f* m_spin_hist/initialize
!!
!! NAME
!! initialize
!!
!! FUNCTION
!! initialize spin hist
!!
!! INPUTS
!! nspin = number of magnetic atoms
!! mxhist = maximum number of hist steps
!! has_latt = whether spin dynamics in with lattice dynamics
!!
!! OUTPUT
!! hist <type(spin_hist_t)()> = spin hist type
!! PARENTS
!! m_spin_hist
!!
!! CHILDREN
!!
!! SOURCE
subroutine initialize(self, nspin, mxhist, has_latt)
implicit none
class(spin_hist_t), intent(inout) :: self
integer, intent(in) :: nspin, mxhist
logical, intent(in) :: has_latt
!integer, optional, intent(in) :: calc_traj_obs, calc_thermo_obs, calc_correlation_obs
self%nspin=nspin
self%ntypat=0
self%ihist=1
self%ihist_prev=0
self%mxhist=mxhist
self%natoms=0
self%has_latt=has_latt
ABI_MALLOC(self%heff, (3, nspin, mxhist))
ABI_MALLOC(self%snorm, (nspin, mxhist))
ABI_MALLOC(self%S, (3, nspin, mxhist))
ABI_MALLOC(self%dSdt, (3, nspin, mxhist))
ABI_MALLOC(self%etot, (mxhist))
ABI_MALLOC(self%entropy, (mxhist))
ABI_MALLOC(self%time, (mxhist))
ABI_MALLOC(self%itime, (mxhist))
ABI_MALLOC(self%ihist_latt, (mxhist))
! TODO: add observable allocation here.
self%etot(1) =zero
self%entropy(1) =zero
self%time(1) =zero
!self%acell(:)=zero
!self%rprimd(:, :)=zero
!self%xred(:,:) =zero
self%heff(:,:,:)=zero
self%S(:,:,:)=zero
self%dSdt(:,:,:)=zero
self%snorm(:,:)=zero
end subroutine initialize
!!***
subroutine reset(self, array_to_zero)
implicit none
class(spin_hist_t), intent(inout) :: self
logical :: array_to_zero
self%ntypat=0
self%ihist=1
self%ihist_prev=0
self%natoms=0
self%etot(1) =zero
self%entropy(1) =zero
self%time(1) =zero
if(array_to_zero) then
self%heff(:,:,1)=zero
self%S(:,:,1)=zero
self%dSdt(:,:,1)=zero
self%snorm(:,1)=zero
self%Cv( 1)=zero
self%sp_corr_func(:, :, 1)=zero
endif
end subroutine reset
!!****f* m_spin_hist/set_atomic_structure
!!
!! NAME
!! set_atomic_structure
!!
!! FUNCTION
!!
!! set atomic structure
!!
!! INPUTS
!! acell(3) = acell
!! rprimd(3, 3) =
!! xred(3, natoms) = positions in reduced coordinates
!! spin_index(3, natoms) = index of atom in spin hamiltonian
!! ntypat = number of types of atoms
!! typat(ntypat)=types of atoms
!! znucl=z of atoms
!!
!! OUTPUT
!! hist <type(spin_hist_t)()> = spin hist type
!! PARENTS
!!
!! CHILDREN
!! self%inc1
!!
!! SOURCE
subroutine set_atomic_structure(self, acell, rprimd, xred, spin_index, ntypat, typat, znucl)
class(spin_hist_t), intent(inout) :: self
real(dp), intent(in) :: acell(3), rprimd(3,3), xred(:,:), znucl(:)
integer, intent(in):: spin_index(:), ntypat, typat(:)
integer :: natoms
natoms=size(typat)
ABI_MALLOC(self%xred, (3, natoms))
ABI_MALLOC(self%spin_index, (natoms))
ABI_MALLOC(self%typat,(ntypat))
ABI_MALLOC(self%znucl, (ntypat))
self%acell(:)=acell(:)
self%rprimd(:,:)=rprimd(:,:)
self%xred(:,:)=xred(:,:)
self%spin_index(:)=spin_index(:)
self%ntypat=ntypat
self%typat(:)=typat(:)
self%znucl(:)=znucl(:)
end subroutine set_atomic_structure
!!***
!!****f* m_spin_hist/set_params
!!
!! NAME
!! set_params
!!
!! FUNCTION
!!
!! set parameters for spin_hist_t
!!
!! INPUTS
!! spin_nctime=number of step between two write to netcdf hist file
!! spin_temperate= temperature of spin
!!
!! OUTPUT
!! hist <type(spin_hist_t)()> = spin hist type
!! PARENTS
!! m_spin_hist
!!
!! CHILDREN
!!
!! SOURCE
subroutine set_params(self, spin_nctime, spin_temperature)
class(spin_hist_t), intent(inout) :: self
integer, intent(in) :: spin_nctime
real(dp), intent(in) :: spin_temperature
self%spin_nctime= spin_nctime
self%spin_temperature=spin_temperature
end subroutine set_params
!!***
!!****f* m_spin_hist/finalize
!!
!! NAME
!! finalize
!!
!! FUNCTION
!!
!! free memory for spin_hist_t
!!
!! INPUTS
!!
!! OUTPUT
!! hist <type(spin_hist_t)()> = spin hist type
!! PARENTS
!! m_spin_hist
!!
!! CHILDREN
!!
!! SOURCE
subroutine finalize(self)
class(spin_hist_t) , intent(inout) :: self
if (allocated(self%xred)) then
ABI_FREE(self%xred)
end if
if (allocated(self%typat)) then
ABI_FREE(self%typat)
end if
if (allocated(self%znucl)) then
ABI_FREE(self%znucl)
end if
if (allocated(self%spin_index)) then
ABI_FREE(self%spin_index)
end if
if (allocated(self%heff)) then
ABI_FREE(self%heff)
end if
if (allocated(self%snorm)) then
ABI_FREE(self%snorm)
end if
if (allocated(self%S)) then
ABI_FREE(self%S)
end if
if (allocated(self%dSdt)) then
ABI_FREE(self%dSdt)
end if
if (allocated(self%etot)) then
ABI_FREE(self%etot)
end if
if (allocated(self%entropy)) then
ABI_FREE(self%entropy)
end if
if (allocated(self%time)) then
ABI_FREE(self%time)
end if
if (allocated(self%itime)) then
ABI_FREE(self%itime)
end if
if (allocated(self%ihist_latt)) then
ABI_FREE(self%ihist_latt)
end if
end subroutine finalize
!!***
!!****f* m_spin_hist/get_S
!!
!! NAME
!! get_S
!!
!! FUNCTION
!!
!! get the S for step. step=0 is current. step=-1 is last...
!!
!! INPUTS
!! hist <type(spin_hist_t)()> = spin hist type
!! step = index of step. current step is 0. last step is -1.
!! OUTPUT
!! S(3, nspin)=spin orientations at step
!! PARENTS
!! m_spin_hist
!!
!! CHILDREN
!!
!! SOURCE
function get_S(self, step) result(S)
class(spin_hist_t), intent(inout) :: self
integer, intent(in), optional:: step
real(dp) :: S(3, self%nspin)
integer :: i, j
if (.not. present(step)) then
j=0
else
j=step
end if
i=self%findIndex(step=j)
S(:,:)=self%S(:,:,i)
end function get_S
!!***
!!****f* m_spin_hist/inc1
!!
!! NAME
!! inc1
!!
!! FUNCTION
!!
!! time counter increase
!!
!! INPUTS
!!
!! OUTPUT
!! hist <type(spin_hist_t)()> = spin hist type
!! PARENTS
!!
!! CHILDREN
!! self%inc1
!!
!! SOURCE
subroutine inc1(self)
class(spin_hist_t), intent(inout) :: self
if(self%ihist_prev ==0 ) then
self%itime(self%ihist)=1
else
self%itime(self%ihist)=self%itime(self%ihist_prev)+1
endif
self%ihist_prev=self%ihist
self%ihist=self%findIndex(1)
end subroutine inc1
!!***
!!***f* m_spin_hist/findIndex
!!
!! NAME
!! get_findIndex
!!
!! FUNCTION
!! get the index of the step in the self%S array
!! INPUTS
!!
!! OUTPUT
!! index: the index of the step in the self%S array.
!! PARENTS
!! m_spin_hist
!!
!! CHILDREN
!!
!! SOURCE
function findIndex(self, step) result(index)
class(spin_hist_t), intent(inout) :: self
integer , intent(in) :: step
integer :: index
!Local variables-------------------------------
!scalars
integer :: mxhist
!arrays
character(len=500) :: msg
! *************************************************************
mxhist = self%mxhist
if ((mxhist ==1.and.step/=+1).or.&
& (mxhist /=1.and.abs(step) >=mxhist)) then
write(msg,'(a,I0,2a)')' The requested step must be less than ',mxhist,ch10,&
& 'Action: increase the number of history store in the hist'
ABI_BUG(msg)
end if
index= mod(self%ihist+step, self%mxhist)+1
end function findIndex
!!***
!!***f* m_spin_hist/set_vars
!!
!! NAME
!! get_set_vars
!!
!! FUNCTION
!! put the data into hist
!! INPUTS
!! S(3, nspin)=spin orientation
!! Snorm(nspin)=spin amplitude
!! dSdt(3,nspin)= dS/dt
!! Heff(3, nspin) = effective magnetic field
!! etot = total energy
!! entropy = entropy
!! time = time (note: not index of time)
!! ihist_latt = index of lattice dynamics step.
!! inc = whether this step is finished. If true, increment counter.
!! OUTPUT
!! index: the index of the step in the self%S array.
!! PARENTS
!! m_spin_hist
!!
!! CHILDREN
!!
!! SOURCE
subroutine set_vars(self, S, Snorm, dSdt, Heff, etot, entropy, time, ihist_latt, inc)
class(spin_hist_t), intent(inout) ::self
real(dp), optional, intent(in) :: S(3, self%nspin), Snorm(self%nspin), dSdt(3, self%nspin), &
& Heff(3, self%nspin), etot, entropy, time
integer, optional :: ihist_latt
logical, intent(in), optional :: inc
integer :: ihist
ihist=self%ihist
if(present(inc)) then
if (inc) then
call self%inc1()
end if
end if
if(present(S)) then
self%S(:, :, ihist)=S(:,:)
end if
if(present(Snorm)) then
self%Snorm(:, ihist)=Snorm(:)
endif
if(present(dSdt)) then
self%dSdt(:, :, ihist)=dSdt(:,:)
end if
if(present(Heff)) then
self%Heff(:, :, ihist)=Heff(:,:)
end if
if(present(etot)) then
self%etot(ihist)=etot
end if
if(present(entropy)) then
self%entropy(ihist)=entropy
end if
if(present(time)) then
self%time( ihist)=time
end if
if(present(ihist_latt)) then
self%ihist_latt(ihist)=ihist_latt
endif
end subroutine set_vars
!!***
end module m_spin_hist
| gpl-3.0 |
HEPcodes/FeynHiggs | src/OneLoop/mfv/td_h0_mfv.F | 2 | 4093 | * td_h0_mfv.F
* generated 25-Sep-2020 15:37
* this file is part of FeynHiggs
* please do not edit directly
#include "externals.h"
#include "types.h"
#include "debug.h"
subroutine td_h0_mfv(se)
implicit none
ComplexType se
#include "FH.h"
#include "looptools.h"
integer Cha2, Gen2, Neu2, Sfe2
se = 0
LOOP(Gen2, gM,3,1)
se = se - 3/(8.D0*Pi**2)*
& (CA*EL1L*A0(Mf2(tM1,Gen2))*Mf2(tM1,Gen2))/(MW*SB*SW)
ENDLOOP(Gen2)
LOOP(Sfe2, 1,2,1)
LOOP(Gen2, gM,3,1)
se = se + 1/(32.D0*Pi**2)*
& (EL1L*A0(MSf2(Sfe2,tM1,Gen2))*
& (((1 - 4*CW2)*MW*MZ*SAB*SB + 6*CA*CW*Mf2(tM1,Gen2))*
& USf2(Sfe2,1,tM1,Gen2) -
& 2*(2*MW*MZ*SAB*SB*SW2 - 3*CA*CW*Mf2(tM1,Gen2))*
& USf2(Sfe2,2,tM1,Gen2) +
& 3*CW*((CA*Kf(Gen2,Gen2,tM1) +
& MUEC*SA*Mf(tM1,Gen2))*USf(Sfe2,2,tM1,Gen2)*
& USfC(Sfe2,1,tM1,Gen2) +
& (CA*KfC(Gen2,Gen2,tM1) + MUE*SA*Mf(tM1,Gen2))*
& USf(Sfe2,1,tM1,Gen2)*USfC(Sfe2,2,tM1,Gen2))))/
& (CW*MW*SB*SW)
ENDLOOP(Gen2)
ENDLOOP(Sfe2)
#ifdef DETAILED_DEBUG
DHIGGS "td_h0_mfv t/st =", se ENDL
#endif
if( mssmpart .le. 1 ) return
LOOP(Gen2, gM,3,1)
se = se + 3/(8.D0*Pi**2)*
& (EL1L*SA*A0(Mf2(bM1,Gen2))*Mf2(bM1,Gen2))/(CB*MW*SW)
ENDLOOP(Gen2)
LOOP(Sfe2, 1,2,1)
LOOP(Gen2, gM,3,1)
se = se + 1/(32.D0*Pi**2)*
& (EL1L*A0(MSf2(Sfe2,bM1,Gen2))*
& ((CB*(1 + 2*CW2)*MW*MZ*SAB - 6*CW*SA*Mf2(bM1,Gen2))*
& USf2(Sfe2,1,bM1,Gen2) +
& 2*(CB*MW*MZ*SAB*SW2 - 3*CW*SA*Mf2(bM1,Gen2))*
& USf2(Sfe2,2,bM1,Gen2) -
& 3*CW*((SA*Kf(Gen2,Gen2,bM1) +
& CA*MUEC*Mf(bM1,Gen2))*USf(Sfe2,2,bM1,Gen2)*
& USfC(Sfe2,1,bM1,Gen2) +
& (SA*KfC(Gen2,Gen2,bM1) + CA*MUE*Mf(bM1,Gen2))*
& USf(Sfe2,1,bM1,Gen2)*USfC(Sfe2,2,bM1,Gen2))))/
& (CB*CW*MW*SW)
ENDLOOP(Gen2)
ENDLOOP(Sfe2)
#ifdef DETAILED_DEBUG
DHIGGS "td_h0_mfv +b/sb =", se ENDL
#endif
if( mssmpart .le. 2 ) return
LOOP(Gen2, 1,3,1)
se = se - 1/(32.D0*Pi**2)*
& (EL1L*(CB*MW*MZ*SAB*A0(MSf2(1,1,Gen2)) -
& 4*CW*SA*A0(Mf2(2,Gen2))*Mf2(2,Gen2)))/(CB*CW*MW*SW)
ENDLOOP(Gen2)
LOOP(Gen2, 1,3,1)
LOOP(Sfe2, 1,2,1)
se = se - 1/(32.D0*Pi**2)*
& (EL1L*A0(MSf2(Sfe2,2,Gen2))*
& ((CB*(1 - 2*CW2)*MW*MZ*SAB + 2*CW*SA*Mf2(2,Gen2))*
& USf2(Sfe2,1,2,Gen2) -
& 2*(CB*MW*MZ*SAB*SW2 - CW*SA*Mf2(2,Gen2))*
& USf2(Sfe2,2,2,Gen2) +
& CW*((SA*Kf(Gen2,Gen2,2) + CA*MUEC*Mf(2,Gen2))*
& USf(Sfe2,2,2,Gen2)*USfC(Sfe2,1,2,Gen2) +
& (SA*KfC(Gen2,Gen2,2) + CA*MUE*Mf(2,Gen2))*
& USf(Sfe2,1,2,Gen2)*USfC(Sfe2,2,2,Gen2))))/
& (CB*CW*MW*SW)
ENDLOOP(Sfe2)
ENDLOOP(Gen2)
#ifdef DETAILED_DEBUG
DHIGGS "td_h0_mfv +l/sl =", se ENDL
#endif
if( mssmpart .le. 3 ) return
se = se + 1/(64.D0*Pi**2)*
& (EL1L*MW*(SAB*(C2B*A0(MA02) + 3*C2A*A0(Mh02)) -
& (2*CAB*S2A + C2A*SAB)*A0(MHH2) +
& 2*(CA*(C2B + 2*CW2)*SB -
& SA*(CW2*S2B*SB + CB*(1 - 2*CB2*SW2)))*A0(MHp2)-
& 2*(C2B*SAB - 6*CW2*SBA)*A0(MW2) -
& (C2B*SAB - 6*SBA)*A0(MZ2)))/(CW2*SW)
LOOP(Cha2, 1,2,1)
se = se + 1/(8.D0*Pi**2*sqrt2)*
& (EL1L*A0(MCha2(Cha2))*MCha(Cha2)*
& (SA*(UCha(Cha2,2)*VCha(Cha2,1) +
& UChaC(Cha2,2)*VChaC(Cha2,1)) -
& CA*(UCha(Cha2,1)*VCha(Cha2,2) +
& UChaC(Cha2,1)*VChaC(Cha2,2))))/SW
ENDLOOP(Cha2)
LOOP(Neu2, 1,4,1)
se = se - 1/(16.D0*Pi**2)*
& (EL1L*A0(MNeu2(Neu2))*MNeu(Neu2)*
& ((SW*ZNeu(Neu2,1) - CW*ZNeu(Neu2,2))*
& (SA*ZNeu(Neu2,3) + CA*ZNeu(Neu2,4)) +
& (SW*ZNeuC(Neu2,1) - CW*ZNeuC(Neu2,2))*
& (SA*ZNeuC(Neu2,3) + CA*ZNeuC(Neu2,4))))/(CW*SW)
ENDLOOP(Neu2)
#ifdef DETAILED_DEBUG
DHIGGS "td_h0_mfv all =", se ENDL
#endif
end
| gpl-3.0 |
abinit/abinit | src/67_common/m_common.F90 | 1 | 79696 | ! CP modified
!!****m* ABINIT/m_common
!! NAME
!! m_common
!!
!! FUNCTION
!! This module gathers routines used by higher-level procedures.
!! Mainly printing routines.
!!
!! COPYRIGHT
!! Copyright (C) 1998-2021 ABINIT group (DCA, XG, AF, GMR, LBoeri, MT)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! PARENTS
!!
!! CHILDREN
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
module m_common
use defs_basis
use m_errors
use m_abicore
use m_exit
use m_fftcore
use m_fock
use m_io_tools
#if defined DEV_YP_VDWXC
use m_xc_vdw
#endif
#ifdef HAVE_NETCDF
use netcdf
#endif
use m_nctk
use m_crystal
use m_wfk
use m_ebands
use m_hdr
use m_xmpi
use m_dtset
use m_xpapi
use m_yaml
use m_invars2
use m_dtset
use m_fstrings, only : indent, endswith, sjoin, itoa
use m_electronpositron, only : electronpositron_type
use m_energies, only : energies_type, energies_eval_eint
use m_pair_list, only : pair_list
use m_geometry, only : mkrdim, metric
use m_kg, only : getcut
use m_parser, only : parsefile, ab_dimensions
use m_invars1, only : invars0, invars1m, indefo
use m_time, only : timab, time_set_papiopt
use defs_abitypes, only : MPI_type
use defs_datatypes, only : pspheader_type, ebands_t
use m_pspheads, only : inpspheads, pspheads_comm
use m_kpts, only : kpts_timrev_from_kptopt
implicit none
private
!!***
public :: scprqt
public :: setup1
public :: prteigrs
public :: prtene
public :: get_dtsets_pspheads ! Parse input file, get list of pseudos for files file and build list of datasets
! pseudopotential headers, maxval of dimensions needed in outvars
public :: ebands_from_file ! Build an ebands_t object from file. Supports Fortran and netcdf files
public :: crystal_from_file ! Build a crystal_t object from netcdf or Fortran file with Header
!!***
contains
!!***
!!****f* ABINIT/scprqt
!! NAME
!! scprqt
!!
!! FUNCTION
!! Conducts printing inside the scfcv.F90 routine, according to the value of choice.
!! Also checks the convergence with respect to the different criteria.
!! Eventually send a signal to quit the SCF cycle.
!!
!! INPUTS
!! choice= if 1 => called at the initialisation of scfcv.f
!! if 2 => called during the loop in scfcv.f
!! if 3 => called at the end of scfcv.f
!! cpus=cpu time limit in seconds
!! deltae=change in energy between the previous and present SCF cycle
!! diffor=maximum absolute change in component of fcart between present and previous SCF cycle.
!! dtset <type(dataset_type)>=all input variables in this dataset
!! | chkexit= if non-zero, check whether the user wishes to exit
!! | enunit=parameter determining units of output energies
!! | ionmov=governs the movement of atoms (see help file)
!! | kptopt=option for the generation of k points
!! | mband=maximum number of bands
!! | natom=number of atoms in cell.
!! | nnsclo_now=number of non-self-consistent loops for the current vtrial
!! | (often 1 for SCF calculation, =nstep for non-SCF calculations)
!! | nsppol=1 for unpolarized, 2 for spin-polarized
!! | occopt=option for occupancies
!! | prtxml=1 if values have to be stored in an XML file.
!! | prteig=
!! | prtstm=print STM input variable
!! | prtvol= control print volume
!! | usedmatpu=DFT+U: number of SCF steps keeping occ. matrix fixed
!! | usefock=1 if Fock operator is present (hence possibility of a double loop)
!! | usepawu=0 if no DFT+U; /=0 if DFT+U
!! eigen(mband*nkpt*nsppol)=array for holding eigenvalues (hartree)
!! electronpositron <type(electronpositron_type)>=quantities for the electron-positron annihilation (optional argument)
!! etotal=total energy (hartree)
!! favg(3)=average of forces (ha/bohr)
!! fcart(3,natom)=cartesian forces (hartree/bohr)
!! fermie=fermi energy (Hartree) / for electrons thermalized in the conduction bands when occopt==9 ! CP modified
!! fermih=fermi energy (Hartree) for holes thermalized in the VB when occopt==9 ! CP added
!! fname_eig=filename for printing of the eigenenergies
!! fock <type(fock_type)>=quantities for the fock operator (optional argument)
!! character(len=fnlen) :: filnam1=character strings giving input file name
!! initGS= 1 if one GS SCF cycle has already be done
!! iscf=( <= 0 =>non-SCF), >0 => SCF)
!! iscf =1 => determination of the largest eigenvalue of the SCF cycle
!! iscf =2 => SCF cycle, simple mixing
!! iscf =3 => SCF cycle, anderson mixing
!! iscf =5 => SCF cycle, CG based on estimations of gradients of the energy
!! iscf =6 => SCF cycle, CG based on true minimization of the energy
!! iscf =-3, although non-SCF, the energy is computed, so print it here.
!! istep=number of the SCF iteration (needed if choice=2)
!! istep_fock_outer=number of outer SCF iteration in the double loop approach
!! istep_mix=number of inner SCF iteration in the double loop approach
!! kpt(3,nkpt)=reduced coordinates of k points.
!! maxfor=maximum absolute value of fcart
!! moved_atm_inside: if==1, the atoms are allowed to move.
!! mpi_enreg=information about MPI parallelization
!! nband(nkpt*nsppol)=number of bands at each k point, for each polarization
!! nkpt=number of k points
!! nstep=number of steps expected in iterations.
!! occ(mband*nkpt*nsppol)=occupation number for each band at each k point.
!! optres=0 if the residual (res2) is a POTENTIAL residual
!! 1 if the residual (res2) is a DENSITY residual
!! prtfor=1 only if forces have to be printed (0 otherwise)
!! prtxml=1 if XML file has to be output
!! res2=square of the density/potential residual
!! resid(mband*nkpt*nsppol)=residuals for each band over all k points and spins
!! residm=maximum value from resid array (except for nbdbuf highest bands)
!! in Wavelets mode, it is used as the maximum value for the gradient norm.
!! response= if 0, GS case, if 1, RF case.
!! tollist(12)=tolerance list. Presently, the following are defined :
!! tollist(1)=tolmxf ; tollist(2)=tolwfr ; tollist(3)=toldff
!! tollist(4)=toldfe ; tollist(5)=toleig ; tollist(6)=tolvrs
!! tollist(7)=tolrff
!! usepaw= 0 for non paw calculation; =1 for paw calculation
!! vxcavg=mean of the vxc potential
!! wtk(nkpt)=weight assigned to each k point.
!! xred(3,natom)=reduced dimensionless atomic coordinates
!!
!! OUTPUT
!! quit= 0 if the SCF cycle is not finished; 1 otherwise.
!! conv_retcode=Only if choice==3, != 0 if convergence is not achieved.
!!
!! PARENTS
!! m_afterscfloop,m_dfpt_scfcv,m_scfcv_core
!!
!! CHILDREN
!! hdr%free,hdr_ncread,hdr_read_from_fname,indefo,inpspheads,invars0
!! invars1m,invars2m,macroin,macroin2,parsefile,pspheads_comm,timab
!! time_set_papiopt,wfk_read_eigenvalues
!!
!! SOURCE
! CP modified: added fermih to the list of arguments
subroutine scprqt(choice,cpus,deltae,diffor,dtset,&
& eigen,etotal,favg,fcart,fermie,fermih,fname_eig,filnam1,initGS,&
& iscf,istep,istep_fock_outer,istep_mix,kpt,maxfor,moved_atm_inside,mpi_enreg,&
& nband,nkpt,nstep,occ,optres,&
& prtfor,prtxml,quit,res2,resid,residm,response,tollist,usepaw,&
& vxcavg,wtk,xred,conv_retcode,&
& electronpositron, fock) ! optional arguments)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: choice,initGS,iscf,istep,istep_fock_outer,istep_mix
integer,intent(in) :: moved_atm_inside,nkpt,nstep
integer,intent(in) :: optres,prtfor,prtxml,response,usepaw
integer,intent(out) :: quit,conv_retcode
real(dp),intent(in) :: cpus,deltae,diffor,etotal,fermie,fermih,maxfor,res2,residm ! CP added fermih
real(dp),intent(in) :: vxcavg
character(len=fnlen),intent(in) :: fname_eig,filnam1
type(electronpositron_type),pointer,optional :: electronpositron
type(fock_type),pointer,optional :: fock
type(MPI_type),intent(in) :: mpi_enreg
type(dataset_type),intent(in) :: dtset
!arrays
integer,intent(in) :: nband(nkpt*dtset%nsppol)
real(dp),intent(in) :: eigen(dtset%mband*nkpt*dtset%nsppol),favg(3)
real(dp),intent(in) :: fcart(3,dtset%natom),kpt(3,nkpt)
real(dp),intent(in) :: occ(dtset%mband*nkpt*dtset%nsppol)
real(dp),intent(in) :: resid(dtset%mband*nkpt*dtset%nsppol),tollist(12)
real(dp),intent(in) :: wtk(nkpt),xred(3,dtset%natom)
!Local variables-------------------------------
!scalars
integer,parameter :: master=0
integer,save :: toldfe_ok,toldff_ok,tolrff_ok,ttoldfe,ttoldff,ttolrff,ttolvrs,ttolwfr
integer :: iatom,iband,iexit,ikpt,ii,ishift,isppol,my_rank
integer :: nband_index,nband_k,nnsclohf
integer :: openexit,option,tmagnet,usefock
#if defined DEV_YP_VDWXC
integer :: ivdw
#endif
real(dp),save :: toldfe,toldff,tolrff,tolvrs,tolwfr,vdw_df_threshold
real(dp) :: diff_e,diff_f,magnet,rhodn,rhoup
logical :: noquit,use_dpfft
character(len=500) :: message, message2, message3
character(len=2) :: format_istep
character(len=5) :: format_magnet
character(len=8) :: colname
character(len=1) :: firstchar
type(yamldoc_t) :: ydoc
!arrays
real(dp) :: residm_band(dtset%mband,dtset%nsppol), f_tmp(3)
! *********************************************************************
DBG_ENTER("COLL")
my_rank = mpi_enreg%me_cell
quit=0; conv_retcode=0
usefock=dtset%usefock
nnsclohf=dtset%nnsclohf
use_dpfft = .False.
tmagnet=0
if(response==0.and.(iscf>0.or.iscf==-3).and.dtset%nsppol==2.and.dtset%occopt>2)tmagnet=1
ishift=0
residm_band = zero
do isppol=1, dtset%nsppol
do ikpt=1, nkpt
do iband=1, nband(ikpt+(isppol-1)*nkpt)
ishift = ishift+1
residm_band(iband, isppol) = max (resid(ishift), residm_band(iband, isppol))
end do
end do
end do
select case (choice)
case (1)
! choice= if 1 => called at the initialisation of scfcv.f
! Examine tolerance criteria
! NB: The tests on tolwfr and the presence of tolerances in the SCF case are
! also done at the level of the parser in chkinp.
tolwfr=tollist(2)
toldff=tollist(3)
toldfe=tollist(4)
tolvrs=tollist(6)
tolrff=tollist(7)
vdw_df_threshold=tollist(8)
ttolwfr=0 ; ttoldff=0 ; ttoldfe=0 ; ttolvrs=0; ttolrff=0;
if(abs(tolwfr)>tiny(zero))ttolwfr=1
if(abs(toldff)>tiny(zero))ttoldff=1
if(abs(tolrff)>tiny(zero))ttolrff=1
if(abs(toldfe)>tiny(zero))ttoldfe=1
if(abs(tolvrs)>tiny(zero))ttolvrs=1
! If non-scf calculations, tolwfr must be defined
if(ttolwfr /= 1 .and. (iscf<0 .and. iscf/=-3) )then
write(message,'(a,a,a,es14.6,a,a)')&
'when iscf <0 and /= -3, tolwfr must be strictly',ch10,&
'positive, while it is ',tolwfr,ch10,&
'Action: change tolwfr in your input file and resubmit the job.'
ABI_ERROR(message)
end if
! toldff only allowed when prtfor==1
! FIXME: this test should be done on input, not during calculation
if((ttoldff == 1 .or. ttolrff == 1) .and. prtfor==0 )then
ABI_ERROR('toldff only allowed when prtfor=1!')
end if
! If SCF calculations, one and only one of these can differ from zero
if(ttolwfr+ttoldff+ttoldfe+ttolvrs+ttolrff /= 1 .and. (iscf>0 .or. iscf==-3))then
write(message,'(6a,es14.6,a,es14.6,a,es14.6,a,es14.6,a,a,es14.6,a,a,a)' )&
& 'For the SCF case, one and only one of the input tolerance criteria ',ch10,&
& 'tolwfr, toldff, tolrff, toldfe or tolvrs ','must differ from zero, while they are',ch10,&
& 'tolwfr=',tolwfr,', toldff=',toldff,', tolrff=',tolrff,', toldfe=',toldfe,ch10,&
& 'and tolvrs=',tolvrs,' .',ch10,&
& 'Action: change your input file and resubmit the job.'
ABI_ERROR(message)
end if
if (dtset%usewvl == 1) then
write(colname, "(A)") "grdnorm "
else
write(colname, "(A)") "residm "
end if
if (nstep>0 .and. (iscf>=0 .or.iscf==-3) .and. dtset%prtstm==0) then
if(tmagnet==1)then
if (prtfor==0) then
if (optres==0) then
write(message, '(4a)' ) ch10,&
& ' iter Etot(hartree) deltaE(h) ',colname,' vres2 magn'
else
write(message, '(4a)' ) ch10,&
& ' iter Etot(hartree) deltaE(h) ',colname,' nres2 magn'
end if
else
if (optres==0) then
write(message, '(4a)' ) ch10,&
& ' iter Etot(hartree) deltaE(h) ',colname,' vres2 diffor maxfor magn'
else
write(message, '(4a)' ) ch10,&
& ' iter Etot(hartree) deltaE(h) ',colname,' nres2 diffor maxfor magn'
end if
end if
else
if(response==0)then
if (prtfor==0) then
if (optres==0) then
write(message, '(4a)' ) ch10,&
' iter Etot(hartree) deltaE(h) ', colname, ' vres2'
else
write(message, '(4a)' ) ch10,&
' iter Etot(hartree) deltaE(h) ', colname, ' nres2'
end if
else
if (optres==0) then
write(message, '(4a)' ) ch10,&
' iter Etot(hartree) deltaE(h) ',colname,' vres2 diffor maxfor '
else
write(message, '(4a)' ) ch10,&
' iter Etot(hartree) deltaE(h) ',colname,' nres2 diffor maxfor '
end if
end if
else
if (optres==0) then
write(message, '(4a)' ) ch10,&
' iter 2DEtotal(Ha) deltaE(Ha) ', colname, ' vres2'
else
write(message, '(4a)' ) ch10,&
' iter 2DEtotal(Ha) deltaE(Ha) ', colname, ' nres2'
end if
end if
end if
ydoc = yamldoc_open('BeginCycle')
call ydoc%add_ints("iscf, nstep, nline, wfoptalg", &
[dtset%iscf, dtset%nstep, dtset%nline, dtset%wfoptalg], dict_key="solver")
call ydoc%add_reals("tolwfr, toldff, toldfe, tolvrs, tolrff", & ! , vdw_df_threshold", &
[tolwfr, toldff, toldfe, tolvrs, tolrff], & !, vdw_df_threshold], &
real_fmt="(es8.2)", dict_key="tolerances", ignore=zero)
!if (dtset%use_yaml == 1) then
call ydoc%write_and_free(ab_out, newline=.False.)
!else
!call ydoc%write_and_free(std_out, newline=.False.)
!end if
call wrtout(ab_out,message,'COLL')
end if
case (2)
! Examine tolerance criteria
tolwfr=tollist(2)
toldff=tollist(3)
toldfe=tollist(4)
tolvrs=tollist(6)
tolrff=tollist(7)
vdw_df_threshold=tollist(8)
ttolwfr=0 ; ttoldff=0 ; ttoldfe=0 ; ttolvrs=0; ttolrff=0;
if(abs(tolwfr)>tiny(0.0_dp))ttolwfr=1
if(abs(toldff)>tiny(0.0_dp))ttoldff=1
if(abs(tolrff)>tiny(0.0_dp))ttolrff=1
if(abs(toldfe)>tiny(0.0_dp))ttoldfe=1
if(abs(tolvrs)>tiny(0.0_dp))ttolvrs=1
! Conduct printing. If extra output follows, then put a blank line into the output here
if (dtset%prtvol>=10) call wrtout([std_out, ab_out], ' ')
! Calculate up and down charge and magnetization
if(tmagnet==1) then
rhoup = zero
rhodn = zero
nband_index = 1
do isppol=1,dtset%nsppol
do ikpt=1,nkpt
nband_k=nband(ikpt+(isppol-1)*nkpt)
do iband=1,nband_k
if(isppol==1) rhoup = rhoup + wtk(ikpt)*occ(nband_index)
if(isppol==2) rhodn = rhodn + wtk(ikpt)*occ(nband_index)
nband_index = nband_index + 1
end do
end do
end do
magnet = abs(rhoup - rhodn)
end if
if (prtxml == 1) then
write(ab_xml_out, "(A)", advance = "NO") ' <scfcvStep'
write(message, "(es22.10)") etotal
write(ab_xml_out, "(A,A,A)", advance = "NO") ' eTotal="', trim(message) ,'"'
write(message, "(es20.8)") deltae
write(ab_xml_out, "(A,A,A)", advance = "NO") ' deltaETotal="', trim(message) ,'"'
write(message, "(es20.8)") residm
write(ab_xml_out, "(A,A,A)", advance = "NO") ' maxResid="', trim(message) ,'"'
write(message, "(es20.8)") res2
if (optres == 0) then
write(ab_xml_out, "(A,A,A)", advance = "NO") ' potResid="', trim(message) ,'"'
else
write(ab_xml_out, "(A,A,A)", advance = "NO") ' denResid="', trim(message) ,'"'
end if
if (tmagnet== 1) then
write(message, "(es20.8)") magnet
write(ab_xml_out, "(A,A,A)", advance = "NO") ' magn="', trim(message) ,'"'
end if
if (prtfor == 1) then
write(message, "(es20.8)") diffor
write(ab_xml_out, "(A,A,A)", advance = "NO") ' deltaForces="', trim(message) ,'"'
write(message, "(es20.8)") maxfor
write(ab_xml_out, "(A,A,A)", advance = "NO") ' maxForces="', trim(message) ,'"'
end if
write(ab_xml_out, "(A)") " />"
end if
! Print total (free) energy (hartree) and other convergence measures
if(dtset%prtstm==0)then
format_istep='i3'
if(istep>99)format_istep='i5'
if(istep>9999)format_istep='i7'
if(tmagnet==1)then
if(magnet<10)then
format_magnet='f6.3)'
else if(magnet<100)then
format_magnet='f6.2)'
else
format_magnet='f6.1)'
end if
if (prtfor==0) then
write(message, '(a,'//format_istep//',1p,g22.14,3es9.2,0p,'//format_magnet ) &
& ' ETOT',istep,etotal,deltae,residm,res2,magnet
else
write(message, '(a,'//format_istep//',1p,g22.14,3es9.2,es8.1,es9.2,0p,'//format_magnet ) &
& ' ETOT',istep,etotal,deltae,residm,res2,diffor,maxfor,magnet
end if
else
firstchar=' '
if (response/=0.and.istep==1) firstchar="-"
if (response==0) then
if (prtfor==0) then
write(message, '(2a,'//format_istep//',1p,g22.14,3es10.3)' ) &
& firstchar,'ETOT',istep,etotal,deltae,residm,res2
else
write(message, '(2a,'//format_istep//',1p,g22.14,5es10.3)' ) &
& firstchar,'ETOT',istep,etotal,deltae,residm,res2,diffor,maxfor
end if
else
write(message, '(2a,'//format_istep//',1p,g22.14,1x,3es10.3)' ) &
& firstchar,'ETOT',istep,etotal,deltae,residm,res2
end if
end if
!if (etot_yaml_doc%stream%length /= 0) call etot_yaml_doc%add_tabular_line(' '//message(6:))
call wrtout(ab_out,message,'COLL')
if(mpi_enreg%paral_pert==1) then
call wrtout(std_out, message,'PERS')
elseif(mpi_enreg%paral_pert==0) then
call wrtout(std_out, message,'COLL')
end if
end if ! dtset%prtstm==0
! Print positions/forces every step if dtset%prtvol>=10 and iscf>0 or -3 and GS case
if (dtset%prtvol>=10.and.(iscf>=0.or.iscf==-3).and.response==0.and.dtset%prtstm==0) then
call wrtout(ab_out," ",'COLL')
! Print up and down charge and magnetization
if(tmagnet==1) then
write(message,'(a,f11.6,a,f11.6,a,f10.6)')&
& ' #electrons spin up=',rhoup,', spin down=',rhodn,', magnetization=',magnet
call wrtout([std_out, ab_out], message)
end if
! Moreover, print atomic positions if dtset%ionmov==4, and moved_atm_inside==1
if (dtset%ionmov==4 .and. moved_atm_inside==1)then
call wrtout([std_out, ab_out], ' reduced coordinates :')
do iatom=1,dtset%natom
write(message, '(i5,1x,3es21.11)' ) iatom,xred(:,iatom)
call wrtout([std_out, ab_out], message)
end do
end if
! Slightly change favg for printing reasons
if (prtfor>0) then
f_tmp(:)=favg(:)
if(abs(favg(1))<1.0d-13)f_tmp(1)=zero
if(abs(favg(2))<1.0d-13)f_tmp(2)=zero
if(abs(favg(3))<1.0d-13)f_tmp(3)=zero
write(message, '(a,3es10.2)' )' cartesian forces (ha/bohr); non-corrected avg=',f_tmp(:)
call wrtout([std_out, ab_out], message)
do iatom=1,dtset%natom
f_tmp(:)=fcart(:,iatom)
if(abs(fcart(1,iatom))<1.0d-13)f_tmp(1)=zero
if(abs(fcart(2,iatom))<1.0d-13)f_tmp(2)=zero
if(abs(fcart(3,iatom))<1.0d-13)f_tmp(3)=zero
write(message, '(i5,1x,3es21.11)' ) iatom,f_tmp(:)
call wrtout([std_out, ab_out], message)
end do
end if
end if
! Print eigenvalues every step if dtset%prtvol>=10 and GS case
if (my_rank == master .and. (dtset%prtvol>=10 .and. response==0 .and. dtset%tfkinfunc==0 .and. dtset%usewvl==0)) then
option=1
! CP modified
! call prteigrs(eigen,dtset%enunit,fermie,fname_eig,ab_out,iscf,kpt,dtset%kptopt,dtset%mband,&
!& nband,nkpt,dtset%nnsclo,dtset%nsppol,occ,dtset%occopt,option,dtset%prteig,dtset%prtvol,resid,tolwfr,vxcavg,wtk)
!
! call prteigrs(eigen,dtset%enunit,fermie,fname_eig,std_out,iscf,kpt,dtset%kptopt,dtset%mband,&
!& nband,nkpt,dtset%nnsclo,dtset%nsppol,occ,dtset%occopt,option,dtset%prteig,dtset%prtvol,resid,tolwfr,vxcavg,wtk)
call prteigrs(eigen,dtset%enunit,fermie,fermih,fname_eig,ab_out,iscf,kpt,dtset%kptopt,dtset%mband,&
& nband,nkpt,dtset%nnsclo,dtset%nsppol,occ,dtset%occopt,option,dtset%prteig,dtset%prtvol,resid,tolwfr,vxcavg,wtk)
call prteigrs(eigen,dtset%enunit,fermie,fermih,fname_eig,std_out,iscf,kpt,dtset%kptopt,dtset%mband,&
& nband,nkpt,dtset%nnsclo,dtset%nsppol,occ,dtset%occopt,option,dtset%prteig,dtset%prtvol,resid,tolwfr,vxcavg,wtk)
! End CP modified
end if
if(response==0)then
write(message, '(a,1p,e15.7,a)' ) ' scprqt: <Vxc>=',vxcavg,' hartree'
call wrtout(std_out,message,'COLL')
end if
! Check whether exiting was required by the user.
openexit=1 ; if(dtset%chkexit==0) openexit=0
call exit_check(cpus,filnam1,iexit,ab_out,mpi_enreg%comm_cell,openexit)
if (iexit/=0) quit=1
! In special cases, do not quit even if convergence is reached
noquit=((istep<nstep).and.(usepaw==1).and.(dtset%usepawu/=0).and.&
& (dtset%usedmatpu/=0).and.(istep<=abs(dtset%usedmatpu)).and.&
& (dtset%usedmatpu<0.or.initGS==0))
! Additional stuff for electron/positron
if (present(electronpositron)) then
if (associated(electronpositron)) then
if (electronpositron%istep_scf==1) then
toldff_ok=0;tolrff_ok=0;toldfe_ok=0
end if
end if
end if
! Stopping criteria in the SCF case
if(iscf>1 .or. iscf==-3 .or. iscf == 0) then
! Here treat the vdw_df_threshold criterion : if the change of energy is less than
! input vdw_df_threshold, trigger the calculation of vdW interactions
! write(message,'(1x,a,e10.3,1x,a,e10.3,1x,l1,a)') &
! & '[vdW-DF][DEBUG] deltae=',deltae,'vdw_df_threshold=',vdw_df_threshold, &
! & (abs(deltae)<vdw_df_threshold),ch10
! call wrtout(std_out,message,'COLL')
#if defined DEV_YP_VDWXC
call xc_vdw_trigger( (abs(deltae)<vdw_df_threshold) )
#endif
! Here treat the tolwfr criterion: if maximum residual is less than
! input tolwfr, stop steps (exit loop here)
if (ttolwfr == 1 .and. .not. noquit) then
if (residm < tolwfr) then
if (dtset%usewvl == 0) then
write(message, '(a,a,i5,a,1p,e10.2,a,e10.2,a,a)' )ch10, &
' At SCF step',istep,' max residual=',residm,' < tolwfr=',tolwfr,' =>converged.'
else
write(message, '(a,a,i5,a,1p,e10.2,a,e10.2,a,a)' )ch10, &
' At SCF step',istep,' max grdnorm=',residm,' < tolwfr=',tolwfr,' =>converged.'
end if
call wrtout([std_out, ab_out], message)
quit=1
else
use_dpfft = residm < tol7
end if
end if
! Here treat the toldff criterion: if maximum change of fcart is less than
! input toldff twice consecutively, stop steps (exit loop here)
if (ttoldff==1) then
if (istep==1) then
toldff_ok=0
else if (diffor < toldff) then
toldff_ok=toldff_ok+1
! add warning for forces which are 0 by symmetry. Also added Matteo check below that the wave
! functions are relatively converged as well
if (diffor < tol12) then
write (message,'(3a)') ' toldff criterion is satisfied, but your forces are suspiciously low.', ch10,&
& ' Check if the forces are 0 by symmetry: in that case you can not use the toldff convergence criterion!'
ABI_WARNING(message)
if (maxfor < tol16 .and. res2 > tol9) tolrff_ok=0
end if
else
toldff_ok=0
use_dpfft = diffor < tol6
end if
if(toldff_ok==2 .and. .not.noquit)then
write(message, '(a,a,i5,a,a,a,es11.3,a,es11.3)' ) ch10, &
& ' At SCF step',istep,', forces are converged : ',ch10,&
& ' for the second time, max diff in force=',diffor,' < toldff=',toldff
call wrtout([std_out, ab_out], message)
quit=1
end if
end if
! Here treat the tolrff criterion: if maximum change of fcart is less than
! input tolrff times fcart itself twice consecutively, stop steps (exit loop here)
if (ttolrff==1) then
if (istep==1) then
tolrff_ok=0
! 27/7/2009: added test for absolute value of maxfor, otherwise if it is 0 this never exits the scf loop.
else if (diffor < tolrff*maxfor .or. (maxfor < tol16 .and. diffor < tol16)) then
tolrff_ok=tolrff_ok+1
! Thu Mar 12 19:01:40 MG: added additional check on res2 to make sure the SCF cycle is close to convergence.
! Needed for structural relaxations otherwise the stress tensor is wrong and the relax algo makes wrong moves.
if (maxfor < tol16 .and. res2 > tol9) tolrff_ok=0
else
tolrff_ok=0
use_dpfft = diffor < tolrff * maxfor * five
end if
if(tolrff_ok==2 .and. (.not.noquit))then
write(message, '(a,a,i5,a,a,a,es11.3,a,es11.3,a)' ) ch10, &
' At SCF step',istep,', forces are sufficiently converged : ',ch10,&
' for the second time, max diff in force=',diffor,&
' is less than < tolrff=',tolrff, ' times max force'
call wrtout([std_out, ab_out], message)
quit=1
end if
end if
! Here treat the toldfe criterion: if the change of energy is less than
! input toldfe twice consecutively, stop steps (exit loop here)
if (ttoldfe==1) then
if (istep==1) then
toldfe_ok=0
else if (abs(deltae)<toldfe) then
toldfe_ok=toldfe_ok+1
else
toldfe_ok=0
use_dpfft = abs(deltae) < tol8
end if
if(toldfe_ok==2 .and. (.not.noquit))then
if(usefock==0 .or. nnsclohf<2)then
write(message, '(a,a,i5,a,a,a,es11.3,a,es11.3)' ) ch10, &
' At SCF step',istep,', etot is converged : ',ch10,&
' for the second time, diff in etot=',abs(deltae),' < toldfe=',toldfe
else
write(message, '(a,i3,a,i3,a,a,a,es11.3,a,es11.3)' ) &
' Outer loop step',istep_fock_outer,' - inner step',istep_mix,' - frozen Fock etot converged : ',ch10,&
' for the second time, diff in etot=',abs(deltae),' < toldfe=',toldfe
endif
call wrtout([std_out, ab_out], message)
quit=1
end if
if(usefock==1 .and. nnsclohf>1)then
if(istep_mix==1 .and. (.not.noquit))then
! The change due to the update of the Fock operator is sufficiently small. No need to meet it a second times.
if (abs(deltae)<toldfe) then
write(message, '(a,i3,a,i3,a,a,a,es11.3,a,es11.3)' ) &
' Outer loop step',istep_fock_outer,' - inner step',istep_mix,' - etot converged : ',ch10,&
' update of Fock operator yields diff in etot=',abs(deltae),' < toldfe=',toldfe
call wrtout([std_out, ab_out], message)
fock%fock_common%fock_converged=.true.
quit=1
endif
endif
!TODO: separate messages: if HF is imposing a continuation of the loop, then abs(deltae) is actually not > toldfe
if(istep_mix==nnsclohf .and. quit==0)then
write(message, '(a,i3,a,i3,a,a,a,es11.3,a,es11.3)' ) &
' Outer loop step',istep_fock_outer,' - inner step',istep_mix,' - frozen Fock etot NOT converged : ',ch10,&
' diff in etot=',abs(deltae),' > toldfe=',toldfe
call wrtout([std_out, ab_out], message)
endif
endif
! Here treat the vdw_df_threshold criterion for non-SCF vdW-DF
! calculations: If input vdw_df_threshold is lesss than toldfe
! then the vdW-DF is triggered once selfconsistency criteria is
! reached for the first time.
! write(message,'(1x,a,e10.3,1x,a,e10.3,1x,l1,a)') &
! & '[vdW-DF][DEBUG] deltae=',deltae,'vdw_df_threshold=',vdw_df_threshold, &
! & (abs(deltae)<toldfe),ch10
! call wrtout(std_out,message,'COLL')
#if defined DEV_YP_VDWXC
ivdw = 0
if ( toldfe > vdw_df_threshold ) then
ivdw = ivdw + 1
end if
call xc_vdw_trigger((toldfe_ok==1 .and. toldfe>vdw_df_threshold))
if ( ivdw == 2) then
quit=1
end if
#endif
end if
! Here treat the tolvrs criterion: if density/potential residual (squared)
! is less than input tolvrs, stop steps (exit loop here)
if (ttolvrs==1 .and. .not. noquit) then
if (res2 < tolvrs) then
if (optres==0) then
write(message, '(a,a,i5,a,1p,e10.2,a,e10.2,a)' ) ch10,&
' At SCF step',istep,' vres2 =',res2,' < tolvrs=',tolvrs,' =>converged.'
else
write(message, '(a,a,i5,a,1p,e10.2,a,e10.2,a)' ) ch10,&
' At SCF step',istep,' nres2 =',res2,' < tolvrs=',tolvrs,' =>converged.'
end if
call wrtout([std_out, ab_out], message)
quit=1
else
use_dpfft = res2 < tol5
end if
end if
if (quit==1.and.noquit) then
write(message, '(a,a,a)' ) ch10, &
' SCF cycle will continue as it is in an initialization stage',' (occ. matrix was kept constant)...'
call wrtout([std_out, ab_out], message)
end if
end if
! Activate FFT in double-precision.
if (use_dpfft) then
if (fftcore_mixprec == 1) call wrtout(std_out, " Approaching convergence. Activating FFT in double-precision")
ii = fftcore_set_mixprec(0)
end if
case (3)
! If wavefunction convergence was not reached (for nstep>0) print a warning and return conv_retcode
conv_retcode = 0
if(nstep>0) then
if (.not. converged()) then
conv_retcode = 1
if(iscf>=1 .or. iscf==-3 .or. iscf == 0)then
write(message, '(a,a,a,a,i5,a)' ) ch10,&
' scprqt: WARNING -',ch10,&
' nstep=',nstep,' was not enough SCF cycles to converge;'
write(std_out,'(6a,i0,3a)')ch10,&
"--- !ScfConvergenceWarning",ch10,&
"message: |",ch10,&
' nstep ',nstep,' was not enough SCF cycles to converge.',ch10,&
"..."
!ABI_WARNING_CLASS(message, "ScfConvergenceWarning")
else
write(message, '(a,a,a,a,i5,a)' ) ch10,&
' scprqt: WARNING -',ch10,&
' nstep=',nstep,' was not enough non-SCF iterations to converge;'
write(std_out,'(8a)')ch10,&
"--- !NscfConvergenceWarning",ch10,&
"message: |",ch10,TRIM(indent(message)),ch10,&
"..."
!ABI_WARNING_CLASS(message, "NScfConvergenceWarning")
end if
call wrtout([std_out, ab_out], message)
if (ttolwfr==1) then
if (dtset%usewvl == 0) then
write(message, '(a,es11.3,a,es11.3,a)' ) &
' maximum residual=',residm,' exceeds tolwfr=',tolwfr,ch10
write(message2, '(a,es11.3,2a)' ) &
' maximum residual each band. tolwfr= ',tolwfr,ch10,&
' iband, isppol, individual band residuals (max over all k-points):'
call wrtout(std_out, message2,'COLL')
do isppol = 1, dtset%nsppol
do iband = 1, dtset%mband
write(message3, '(2i6, es11.3)') iband, isppol, residm_band(iband,isppol)
call wrtout(std_out,message3,'COLL')
end do
end do
else
write(message, '(a,es11.3,a,es11.3,a)' ) &
' maximum grdnorm=',residm,' exceeds tolwfr=',tolwfr,ch10
end if
else if (ttoldff==1) then
write(message, '(a,es11.3,a,es11.3,a)' ) &
' maximum force difference=',diffor,' exceeds toldff=',toldff,ch10
else if (ttolrff==1) then
write(message, '(a,es11.3,a,es11.3,a)' ) &
' maximum force difference=',diffor,' exceeds tolrff*maxfor=',tolrff*maxfor,ch10
else if (ttoldfe==1) then
write(message, '(a,es11.3,a,es11.3,a)' ) &
' maximum energy difference=',abs(deltae),' exceeds toldfe=',toldfe,ch10
else if(ttolvrs==1)then
if (optres==0) then
write(message, '(a,es11.3,a,es11.3,a)' ) &
' potential residual=',res2,' exceeds tolvrs=',tolvrs,ch10
else
write(message, '(a,es11.3,a,es11.3,a)' ) &
' density residual=',res2,' exceeds tolvrs=',tolvrs,ch10
end if
end if
call wrtout([std_out, ab_out], message)
if (prtxml == 1) then
write(ab_xml_out, "(A)", advance = "NO") ' <status cvState="Failed"'
end if
else
! Convergence is OK
if (prtxml == 1) then
write(ab_xml_out, "(A)", advance = "NO") ' <status cvState="Ok"'
end if
end if ! test for convergence reached or not
if (prtxml == 1) then
if (ttoldfe == 1) then
write(ab_xml_out, "(A)") ' stop-criterion="toldfe" />'
else if (ttoldff == 1) then
write(ab_xml_out, "(A)") ' stop-criterion="toldff" />'
else if (ttolrff == 1) then
write(ab_xml_out, "(A)") ' stop-criterion="tolrff" />'
else if (ttolvrs == 1) then
write(ab_xml_out, "(A)") ' stop-criterion="tolvrs" />'
else if (ttolwfr == 1) then
write(ab_xml_out, "(A)") ' stop-criterion="tolwfr" />'
else
write(ab_xml_out, "(A)") ' />'
end if
end if
! If enabled, output a YAML document with the ETOT iterations
!if (etot_yaml_doc%stream%length > 0) call etot_yaml_doc%write_and_free(ab_out)
end if ! nstep == 0 : no output
case default
write(message, '(a,i0,a)' )' choice = ',choice,' is not an allowed value.'
ABI_BUG(message)
end select
! Additional stuff for the Fock+SCF cycle
if (present(fock)) then
if (associated(fock)) then
fock%fock_common%scf_converged=(quit==1)
! At present, the decision that the Fock loop is converged is not taken here
if (.not.fock%fock_common%fock_converged)quit=0
end if
end if
! Additional stuff for the two-component DFT SCF cycle (electrons+positron)
if (present(electronpositron)) then
if (associated(electronpositron)) then
electronpositron%scf_converged=(quit==1)
if (dtset%positron<0) then
diff_e=abs(etotal-electronpositron%etotal_prev)
diff_f=abs(maxfor-electronpositron%maxfor_prev)
end if
if (choice==1) then
ttoldff=0;ttoldfe=0
if(abs(dtset%postoldff)>tiny(0.0_dp))ttoldff=1
if(abs(dtset%postoldfe)>tiny(0.0_dp))ttoldfe=1
if (dtset%positron<0.and.ttoldff+ttoldfe/=1.and.iscf>0) then
ABI_ERROR('one and only one of toldff or toldfe must differ from zero !')
end if
end if
if (choice==2) then
if (dtset%positron<0.and.istep<=nstep) then
if (electronpositron%scf_converged) then
if (electronpositron%istep/=electronpositron%nstep) then
if ((.not.noquit).and.&
& (diff_e<electronpositron%postoldfe.or.diff_f<electronpositron%postoldff).and.&
& (mod(electronpositron%calctype,2)==0.or.(dtset%positron>-20.and.dtset%positron/=-2))) then
if (diff_e<electronpositron%postoldfe) then
write(message, '(2a,i5,5a,es11.3,a,es11.3)' ) ch10, &
& ' At SCF step',istep,', the difference between',ch10,&
& ' etotal from electronic calculation and etotal from positronic calculation',ch10,&
& ' is converged : diff(etot_el-etot_pos)=',diff_e,' < postoldfe=',electronpositron%postoldfe
else
write(message, '(2a,i5,5a,es11.3,a,es11.3)' ) ch10, &
& ' At SCF step',istep,', the difference between',ch10,&
& ' max. force from electronic calculation and max. force from positronic calculation',ch10,&
& ' is converged : diff(maxfor_el-maxfor_pos)=',diff_f,' < postoldff=',electronpositron%postoldff
end if
call wrtout([std_out, ab_out], message)
else
quit=0
end if
end if
end if
end if
end if
if (choice==3) then
if (dtset%positron<0.and.nstep>0)then
if (diff_e>=electronpositron%postoldfe.and.abs(dtset%postoldfe)>tiny(0.0_dp)) then
write(message, '(4a,i5,5a,es11.3,a,es11.3)' ) ch10,&
& ' scprqt: WARNING -',ch10,&
& ' posnstep=',dtset%posnstep,' was not enough SCF cycles to converge difference between',ch10,&
& ' etotal from electronic calculation and etotal from positronic calculation;',ch10,&
& ' diff=',diff_e,' exceeds postoldfe=',electronpositron%postoldfe
call wrtout([std_out, ab_out], message)
end if
if (diff_f>=electronpositron%postoldff.and.abs(dtset%postoldff)>tiny(0.0_dp)) then
write(message, '(4a,i5,5a,es11.3,a,es11.3)' ) ch10,&
& ' scprqt: WARNING -',ch10,&
& ' posnstep=',dtset%posnstep,' was not enough SCF cycles to converge difference between',ch10,&
& ' max. force from electronic calculation and max. force from positronic calculation;',ch10,&
& ' diff=',diff_e,' exceeds postoldff=',electronpositron%postoldff
call wrtout([std_out, ab_out], message)
end if
end if
end if
end if
end if
call flush_unit(ab_out)
DBG_EXIT("COLL")
contains
logical function converged()
! LB-02/01/2017:
! This code avoids evaluation of undefined variables (which could happen in respfn, apparently)
logical :: loc_conv
loc_conv = .true.
if (ttolwfr==1) then
if (residm > tolwfr) loc_conv=.false.
end if
if (ttoldff==1) then
if (diffor > toldff) loc_conv=.false.
end if
if (ttolrff==1) then
if (diffor > tolrff*maxfor .and. maxfor > tol16) loc_conv=.false.
end if
if (ttoldfe==1) then
if (abs(deltae) > toldfe) loc_conv=.false.
end if
if (ttolvrs==1) then
if (res2 > tolvrs) loc_conv=.false.
end if
converged = loc_conv
end function converged
end subroutine scprqt
!!***
!!****f* ABINIT/setup1
!! NAME
!! setup1
!!
!! FUNCTION
!! Call near top of main routine to handle setup of various arrays,
!! filenames, checking of input data, etc.
!!
!! INPUTS
!! acell(3)=length scales (bohr)
!! ecut_eff=effective energy cutoff (hartree) for planewave basis sphere
!! ecutc_eff=- PAW only - effective energy cutoff (hartree) for the coarse grid
!! natom=number of atoms
!! ngfft(18)=contain all needed information about 3D FFT, see ~abinit/doc/variables/vargs.htm#ngfft
!! ngfftc(18)=contain all needed information about 3D FFT for the coarse grid
!! nkpt=number of k points
!! nsppol=1 for unpolarized, 2 for spin-polarized
!! ntypat=number of types of atoms
!! response=0 if called by gstate, =1 if called by respfn
!! rprim(3,3)=dimensionless real space primitive translations
!! usepaw= 0 for non paw calculation; =1 for paw calculation
!!
!! OUTPUT
!! bantot=total number of bands at all k points
!! gmet(3,3)=metric for reciprocal space inner products (bohr^-2)
!! gprimd(3,3)=dimens. primitive translations for reciprocal space (bohr**-1)
!! gsqcut_eff=Fourier cutoff on G^2 for "large sphere" of radius double
!! gsqcutc_eff=(PAW) Fourier cutoff on G^2 for "large sphere" of radius double for the coarse FFT grid
!! that of the basis sphere--appropriate for charge density rho(G),
!! Hartree potential, and pseudopotentials, corresponding to ecut_eff
!! rmet(3,3)=real space metric (bohr**2)
!! rprimd(3,3)=dimensional primitive translations in real space (bohr)
!! ucvol=unit cell volume (bohr^3)
!!
!! NOTES
!! SHOULD BE CLEANED !
!!
!! PARENTS
!! m_gstate,m_longwave,m_nonlinear,m_respfn_driver
!!
!! CHILDREN
!! hdr%free,hdr_ncread,hdr_read_from_fname,indefo,inpspheads,invars0
!! invars1m,invars2m,macroin,macroin2,parsefile,pspheads_comm,timab
!! time_set_papiopt,wfk_read_eigenvalues
!!
!! SOURCE
subroutine setup1(acell,bantot,dtset,ecut_eff,ecutc_eff,gmet,&
& gprimd,gsqcut_eff,gsqcutc_eff,ngfft,ngfftc,nkpt,nsppol,&
& response,rmet,rprim,rprimd,ucvol,usepaw)
!Arguments ------------------------------------
!scalars
type(dataset_type),intent(in) :: dtset
integer,intent(in) :: nkpt,nsppol
integer,intent(in) :: response,usepaw
integer,intent(out) :: bantot
real(dp),intent(in) :: ecut_eff,ecutc_eff
real(dp),intent(out) :: gsqcut_eff,gsqcutc_eff,ucvol
!arrays
integer,intent(in) :: ngfft(18),ngfftc(18)
real(dp),intent(in) :: acell(3),rprim(3,3)
real(dp),intent(out) :: gmet(3,3),gprimd(3,3),rmet(3,3)
real(dp),intent(out) :: rprimd(3,3)
!Local variables-------------------------------
!scalars
integer :: ikpt,isppol
real(dp) :: boxcut,boxcutc
character(len=500) :: message
!arrays
real(dp) :: k0(3)
! ************************************************************************
!Compute bantot
bantot=0
do isppol=1,nsppol
do ikpt=1,nkpt
bantot=bantot+dtset%nband(ikpt+(isppol-1)*nkpt)
end do
end do
if(dtset%nqpt>1.or.dtset%nqpt<0) then
write(message,'(a,i0,5a)')&
'nqpt =',dtset%nqpt,' is not allowed',ch10,&
'(only 0 or 1 are allowed).',ch10,&
'Action: correct your input file.'
ABI_ERROR(message)
end if
! Compute dimensional primitive translations rprimd
call mkrdim(acell,rprim,rprimd)
! Obtain dimensional translations in reciprocal space gprimd,
! metrics and unit cell volume, from rprimd.
! Also output rprimd, gprimd and ucvol
call metric(gmet,gprimd,ab_out,rmet,rprimd,ucvol)
! Get boxcut for given acell, gmet, ngfft, and ecut_eff
! (center at 000 for groundstate, center at q for respfn):
! boxcut=ratio of basis sphere diameter to fft box side
k0(:)=0.0_dp
if(response==1 .and. dtset%nqpt==1)then
k0(:)=dtset%qptn(:)
write(message, '(a)' )' setup1 : take into account q-point for computing boxcut.'
call wrtout([std_out, ab_out], message)
end if
if (usepaw==1) then
write(message,'(2a)') ch10,' Coarse grid specifications (used for wave-functions):'
call wrtout([std_out, ab_out], message)
call getcut(boxcutc,ecutc_eff,gmet,gsqcutc_eff,dtset%iboxcut,ab_out,k0,ngfftc)
write(message,'(2a)') ch10,' Fine grid specifications (used for densities):'
call wrtout([std_out, ab_out], message)
call getcut(boxcut,ecut_eff,gmet,gsqcut_eff,dtset%iboxcut,ab_out,k0,ngfft)
else
call getcut(boxcut,ecut_eff,gmet,gsqcut_eff,dtset%iboxcut,ab_out,k0,ngfft)
gsqcutc_eff=gsqcut_eff
end if
! Check that boxcut>=2 if dtset%intxc=1; otherwise dtset%intxc must be set=0
if (boxcut<2.0_dp.and.dtset%intxc==1) then
write(message, '(a,es12.4,a,a,a,a,a)' )&
'boxcut= ',boxcut,' is < 2.0 => intxc must be 0;',ch10,&
'Need larger ngfft to use intxc=1.',ch10,&
'Action: you could increase ngfft, or decrease ecut, or put intxcn=0.'
ABI_ERROR(message)
end if
end subroutine setup1
!!***
!!****f* ABINIT/prteigrs
!! NAME
!! prteigrs
!!
!! FUNCTION
!! Print out eigenvalues band by band and k point by k point.
!! If option=1, do it in a standard way, for self-consistent calculations.
!! If option=2, print out residuals and eigenvalues, in a format
!! adapted for nonself-consistent calculations, within the loops.
!! If option=3, print out eigenvalues, in a format
!! adapted for nonself-consistent calculations, at the end of the job.
!! If option=4, print out derivatives of eigenvalues (same format as option==3, except header that is printed)
!! If option=5, print out Fan contribution to zero-point motion correction to eigenvalues (averaged)
!! (same format as option==3, except header that is printed)
!! If option=6, print out DDW contribution to zero-point motion correction to eigenvalues (averaged)
!! (same format as option==3, except header that is printed)
!! If option=7, print out Fan+DDW contribution to zero-point motion correction to eigenvalues (averaged)
!! (same format as option==3, except header that is printed)
!!
!! INPUTS
!! eigen(mband*nkpt*nsppol)=eigenvalues (hartree)
!! or, if option==4, diagonal of derivative of eigenvalues
!! or, if option==5...7, zero-point motion correction to eigenvalues (averaged)
!! enunit=choice parameter: 0=>output in hartree; 1=>output in eV;
!! 2=> output in both hartree and eV
!! fermie=fermi energy (Hartree)/ for electrons thermalized in the conduction bands when occopt==9 ! CP modified
!! fermih=fermi energy (Hartree) for holes thermalized in the VB when occopt==9 ! CP modified
!! fname_eig=filename for printing of the eigenenergies
!! iout=unit number for formatted output file
!! iscf=option for self-consistency
!! kptns(3,nkpt)=k points in reduced coordinates
!! kptopt=option for the generation of k points
!! mband=maximum number of bands
!! nband(nkpt)=number of bands at each k point
!! nkpt=number of k points
!! nnsclo_now=number of non-self-consistent loops for the current vtrial
!! (often 1 for SCF calculation, =nstep for non-SCF calculations)
!! nsppol=1 for unpolarized, 2 for spin-polarized
!! occ(maxval(nband(:))*nkpt*nsppol)=occupancies for each band and k point
!! occopt=option for occupancies
!! option= (see above)
!! prteig=control print eigenenergies
!! prtvol=control print volume and debugging
!! resid(mband*nkpt*nsppol)=residuals (hartree**2)
!! tolwfr=tolerance on band residual of wf, hartrees**2 (needed when option=2)
!! vxcavg=average of vxc potential
!! wtk(nkpt)=k-point weights
!!
!! OUTPUT
!! (only writing)
!!
!! PARENTS
!! m_common,m_dfpt_looppert,m_gstate,m_respfn_driver,m_vtorho
!!
!! CHILDREN
!! hdr%free,hdr_ncread,hdr_read_from_fname,indefo,inpspheads,invars0
!! invars1m,invars2m,macroin,macroin2,parsefile,pspheads_comm,timab
!! time_set_papiopt,wfk_read_eigenvalues
!!
!! SOURCE
!CP added fermih to argument list
subroutine prteigrs(eigen,enunit,fermie,fermih,fname_eig,iout,iscf,kptns,kptopt,mband,nband,&
& nkpt,nnsclo_now,nsppol,occ,occopt,option,prteig,prtvol,resid,tolwfr,vxcavg,wtk)
use m_io_tools, only : open_file
!Arguments ------------------------------------
!scalars
integer,intent(in) :: enunit,iout,iscf,kptopt,mband,nkpt,nnsclo_now,nsppol
integer,intent(in) :: occopt,option,prteig,prtvol
real(dp),intent(in) :: fermie,fermih,tolwfr,vxcavg ! CP added fermih
character(len=*),intent(in) :: fname_eig
!arrays
integer,intent(in) :: nband(nkpt*nsppol)
real(dp),intent(in) :: eigen(mband*nkpt*nsppol),kptns(3,nkpt)
real(dp),intent(in) :: occ(mband*nkpt*nsppol),resid(mband*nkpt*nsppol)
real(dp),intent(in) :: wtk(nkpt)
!Local variables-------------------------------
!scalars
integer,parameter :: nkpt_max=50
integer :: band_index,iband,ienunit,ii,ikpt,isppol,nband_index,nband_k,nkpt_eff,tmagnet,tmetal,temp_unit
real(dp) :: convrt,magnet,residk,rhodn,rhoup
character(len=2) :: ibnd_fmt,ikpt_fmt
character(len=7) :: strunit1,strunit2
character(len=39) :: kind_of_output
character(len=500) :: msg
! *************************************************************************
if (enunit<0.or.enunit>2) then
ABI_BUG(sjoin('enunit must be 0, 1 or 2. Argument was:', itoa(enunit)))
end if
if (prteig > 0) then
call wrtout(iout, sjoin(' prteigrs : about to open file ', fname_eig))
if (open_file(fname_eig, msg, newunit=temp_unit, status='unknown', form='formatted') /= 0) then
ABI_ERROR(msg)
end if
rewind(temp_unit) ! always rewind disk file and print latest eigenvalues
end if
kind_of_output= ' Eigenvalues '
if(option==4) kind_of_output=' Expectation of eigenvalue derivatives'
if(option==5) kind_of_output=' Fan corrections to eigenvalues at T=0'
if(option==6) kind_of_output=' DDW corrections to eigenvalues at T=0'
if(option==7) kind_of_output=' Fan+DDW corrs to eigenvalues at T=0'
nkpt_eff=nkpt
!write(msg,'(a,5i5)')' prtvol,iscf,kptopt,nkpt_eff,nkpt_max ',prtvol,iscf,kptopt,nkpt_eff,nkpt_max
!call wrtout(iout,msg)
if( (prtvol==0.or.prtvol==1) .and. (iscf/=-2 .or. kptopt>0) .and. nkpt_eff>nkpt_max)nkpt_eff=nkpt_max
if( (prtvol==0.or.prtvol==1) .and. (iscf/=-2 .or. kptopt>0) .and. nkpt_eff>1 .and. iout==ab_out)nkpt_eff=1
if(option==1 .or. (option>=3 .and. option<=7))then
do ienunit=0,1
if (enunit==1 .and. ienunit==0)cycle
if (enunit==0 .and. ienunit==1)cycle
! Print eigenvalues in hartree for enunit=0 or 2
! The definition of two different strings is quite ridiculous. Historical reasons ...
if (ienunit==0)then
convrt=one
strunit1='hartree'
strunit2='hartree'
end if
if (ienunit==1)then
convrt=Ha_eV
strunit1=' eV '
strunit2='eV '
end if
band_index=0
if(ienunit==0)then ! XG20140730 I do not know why this is only done when ienunit==0
tmetal=0
if(option==1 .and. occopt>=3 .and. occopt<=8)tmetal=1
tmagnet=0
if(tmetal==1 .and. nsppol==2)then
tmagnet=1
rhoup = 0._dp
rhodn = 0._dp
nband_index = 1
do isppol=1,nsppol
do ikpt=1,nkpt
nband_k=nband(ikpt+(isppol-1)*nkpt)
do iband=1,nband_k
if(isppol==1) rhoup = rhoup + wtk(ikpt)*occ(nband_index)
if(isppol==2) rhodn = rhodn + wtk(ikpt)*occ(nband_index)
nband_index = nband_index + 1
end do
end do
end do
magnet = abs(rhoup - rhodn)
end if
end if
if(iscf>=0 .and. (ienunit==0 .or. option==1))then
! CP modified for occopt 9 case
!write(msg, '(3a,f10.5,3a,f10.5)' ) &
! ' Fermi (or HOMO) energy (',trim(strunit2),') =',convrt*fermie,' Average Vxc (',trim(strunit2),')=',convrt*vxcavg
if (occopt == 9) then
write(msg, '(3a,f10.5,a,f10.5,3a,f10.5)' ) &
' Fermi energy for thermalized electrons and holes (',trim(strunit2),') =',&
convrt*fermie,', ',convrt*fermih,' Average Vxc (',trim(strunit2),')=',convrt*vxcavg
else
write(msg, '(3a,f10.5,3a,f10.5)' ) &
' Fermi (or HOMO) energy (',trim(strunit2),') =',convrt*fermie,' Average Vxc (',trim(strunit2),')=',convrt*vxcavg
end if
! End CP modified
call wrtout(iout,msg)
if (prteig > 0) call wrtout(temp_unit,msg)
end if
! if( (iscf>=0 .or. iscf==-3) .and. ienunit==0)then ! This is the most correct
if(iscf>=0 .and. ienunit==0)then ! For historical reasons
if(tmagnet==1)then
write(msg, '(a,es16.8,a,a,es16.8,a,es16.8)' )&
& ' Magnetization (Bohr magneton)=',magnet,ch10,&
& ' Total spin up =',rhoup,' Total spin down =',rhodn
call wrtout(iout,msg,'COLL')
if (prteig > 0) call wrtout(temp_unit,msg)
end if
end if
! Loop over spins (suppress spin data if nsppol not 2)
do isppol=1,nsppol
ikpt_fmt="i4" ; if(nkpt>=10000)ikpt_fmt="i6" ; if(nkpt>=1000000)ikpt_fmt="i9"
if (nsppol==2.and.isppol==1) then
write(msg, '(4a,'//ikpt_fmt//',2x,a)' ) &
& trim(kind_of_output),' (',strunit1,') for nkpt=',nkpt,'k points, SPIN UP:'
else if (nsppol==2.and.isppol==2) then
write(msg, '(4a,'//ikpt_fmt//',2x,a)' ) &
& trim(kind_of_output),' (',strunit1,') for nkpt=',nkpt,'k points, SPIN DOWN:'
else
write(msg, '(4a,'//ikpt_fmt//',2x,a)' ) &
& trim(kind_of_output),' (',strunit1,') for nkpt=',nkpt,'k points:'
end if
call wrtout(iout,msg)
if (prteig > 0) call wrtout(temp_unit,msg)
if(ienunit==0)then
if(option>=4 .and. option<=7)then
msg = ' (in case of degenerate eigenvalues, averaged derivative)'
call wrtout(iout,msg)
if (prteig > 0) call wrtout(temp_unit,msg)
end if
end if
do ikpt=1,nkpt
nband_k=nband(ikpt+(isppol-1)*nkpt)
ikpt_fmt="i4" ; if(nkpt>=10000)ikpt_fmt="i6" ; if(nkpt>=1000000)ikpt_fmt="i9"
ibnd_fmt="i3" ; if(nband_k>=1000)ibnd_fmt="i6" ; if(nband_k>=1000000)ibnd_fmt="i9"
if(ikpt<=nkpt_eff)then
write(msg, '(a,'//ikpt_fmt//',a,'//ibnd_fmt//',a,f9.5,a,3f8.4,a)' ) &
& ' kpt#',ikpt,', nband=',nband_k,', wtk=',wtk(ikpt)+tol10,', kpt=',&
& kptns(1:3,ikpt)+tol10,' (reduced coord)'
call wrtout(iout,msg,'COLL')
if (prteig > 0) call wrtout(temp_unit,msg)
do ii=0,(nband_k-1)/8
! write(msg, '(8f15.10)' ) (convrt*eigen(iband+band_index),&
write(msg, '(8(f10.5,1x))' ) (convrt*eigen(iband+band_index), iband=1+ii*8,min(nband_k,8+ii*8))
call wrtout(iout,msg,'COLL')
if (prteig > 0) call wrtout(temp_unit,msg)
end do
if(ienunit==0 .and. option==1 .and. occopt>=3 .and. occopt<=8)then
write(msg, '(5x,a,'//ikpt_fmt//')' ) ' occupation numbers for kpt#',ikpt
call wrtout(iout,msg)
do ii=0,(nband_k-1)/8
write(msg, '(8(f10.5,1x))' ) (occ(iband+band_index),iband=1+ii*8,min(nband_k,8+ii*8))
call wrtout(iout,msg)
end do
end if
else
if(ikpt==nkpt_eff+1)then
write(msg, '(a,a)' )' prteigrs : prtvol=0 or 1, do not print more k-points.',ch10
call wrtout(iout,msg)
end if
if (prteig > 0) then
write(msg, '(a,'//ikpt_fmt//',a,'//ibnd_fmt//',a,f9.5,a,3f8.4,a)' ) &
& ' kpt#',ikpt,', nband=',nband_k,', wtk=',wtk(ikpt)+tol10,', kpt=',&
& kptns(1:3,ikpt)+tol10,' (reduced coord)'
call wrtout(temp_unit,msg)
do ii=0,(nband_k-1)/8
write(msg, '(8(f10.5,1x))' ) (convrt*eigen(iband+band_index),iband=1+ii*8,min(nband_k,8+ii*8))
call wrtout(temp_unit,msg)
end do
end if
end if
band_index=band_index+nband_k
end do ! do ikpt=1,nkpt
end do ! do isppol=1,nsppol
end do ! End loop over Hartree or eV
else if(option==2)then
band_index=0
do isppol=1,nsppol
if(nsppol==2)then
if(isppol==1)write(msg, '(2a)' ) ch10,' SPIN UP channel '
if(isppol==2)write(msg, '(2a)' ) ch10,' SPIN DOWN channel '
call wrtout(iout,msg)
if(prteig>0) call wrtout(temp_unit,msg)
end if
do ikpt=1,nkpt
nband_k=nband(ikpt+(isppol-1)*nkpt)
ikpt_fmt="i5" ; if(nkpt>=10000)ikpt_fmt="i7" ; if(nkpt>=1000000)ikpt_fmt="i9"
if(ikpt<=nkpt_eff)then
write(msg, '(1x,a,'//ikpt_fmt//',a,f9.5,2f9.5,a)' ) &
& 'Non-SCF case, kpt',ikpt,' (',(kptns(ii,ikpt),ii=1,3),'), residuals and eigenvalues='
call wrtout(iout,msg)
if (prteig > 0) then
write(msg, '(1x,a,'//ikpt_fmt//',a,f9.5,2f9.5,a)' ) &
& 'Non-SCF case, kpt',ikpt,' eig(',(kptns(ii,ikpt),ii=1,3),') '
call wrtout(temp_unit,msg)
end if
do ii=0,(nband_k-1)/8
write(msg, '(1p,8e10.2)' )(resid(iband+band_index),iband=1+8*ii,min(8+8*ii,nband_k))
call wrtout(iout,msg)
end do
do ii=0,(nband_k-1)/6
write(msg, '(1p,6e12.4)' )(eigen(iband+band_index),iband=1+6*ii,min(6+6*ii,nband_k))
call wrtout(iout,msg)
if (prteig > 0) call wrtout(temp_unit,msg)
end do
else
if(ikpt==nkpt_eff+1)then
write(msg, '(a,a)' )' prteigrs : prtvol=0 or 1, do not print more k-points.',ch10
call wrtout(iout,msg)
end if
if (prteig > 0) then
write(msg, '(1x,a,i5,a,f9.5,2f9.5,a)' )'Non-SCF kpt',ikpt,' eig(',(kptns(ii,ikpt),ii=1,3),') '
call wrtout(temp_unit,msg)
do ii=0,(nband_k-1)/6
write(msg, '(1p,6e12.4)' )(eigen(iband+band_index),iband=1+6*ii,min(6+6*ii,nband_k))
call wrtout(temp_unit,msg)
end do
end if
end if
! MG: I don't understand why we should include the buffer in the output.
! It's already difficult to make the tests pass for the residuals without the buffer if nband >> nbocc
residk=maxval(resid(band_index+1:band_index+nband_k))
if (residk>tolwfr) then
write(msg, '(1x,a,2i5,a,1p,e13.5)' ) &
& ' prteigrs : nnsclo,ikpt=',nnsclo_now,ikpt,' max resid (incl. the buffer)=',residk
call wrtout(iout,msg)
end if
band_index=band_index+nband_k
end do
end do
call wrtout(iout," ")
else
ABI_BUG(sjoin('option:', itoa(option),', is not allowed.'))
end if
if (prteig > 0) close (temp_unit)
end subroutine prteigrs
!!***
!!****f* ABINIT/prtene
!!
!! NAME
!! prtene
!!
!! FUNCTION
!! Print components of total energy in nice format
!!
!! INPUTS
!! dtset <type(dataset_type)>=all input variables in this dataset
!! | berryphase
!! | kptopt
!! | occopt
!! | positron=option for electron-positron calculation
!! | tphysel="physical" electronic temperature with FD occupations
!! | tsmear=smearing energy or temperature (if metal)
!! energies <type(energies_type)>=values of parts of total energy
!! iout=unit number to which output is written
!! usepaw= 0 for non paw calculation; =1 for paw calculation
!!
!! OUTPUT
!! (only writing)
!!
!! PARENTS
!! m_gstate,m_scfcv_core
!!
!! CHILDREN
!! hdr%free,hdr_ncread,hdr_read_from_fname,indefo,inpspheads,invars0
!! invars1m,invars2m,macroin,macroin2,parsefile,pspheads_comm,timab
!! time_set_papiopt,wfk_read_eigenvalues
!!
!! SOURCE
subroutine prtene(dtset,energies,iout,usepaw)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: iout,usepaw
type(dataset_type),intent(in) :: dtset
type(energies_type),intent(in) :: energies
!Local variables-------------------------------
!scalars
integer :: ipositron,optdc
logical :: directE_avail,testdmft
real(dp) :: eent,enevalue,etotal,etotaldc,exc_semilocal
! Do not modify the length of these strings
character(len=14) :: eneName
character(len=500) :: msg
type(yamldoc_t) :: edoc, dc_edoc
!arrays
!character(len=10) :: EPName(1:2)=(/"Positronic","Electronic"/)
! *************************************************************************
directE_avail=(usepaw==0.or.dtset%pawspnorb==0.or.dtset%pawcpxocc==2.or.dtset%kptopt==1.or.dtset%kptopt==2)
!============= Evaluate some parts of the energy ===========
optdc=-1;ipositron=merge(0,2,dtset%positron==0)
if (abs(energies%e_ewald)<1.e-15_dp.and.abs(energies%e_hartree)<1.e-15_dp) ipositron=1
call energies_eval_eint(energies,dtset,usepaw,optdc,etotal,etotaldc)
!Here, treat the case of metals
!In re-smeared case the free energy is defined with tphysel
if(dtset%occopt>=3 .and. dtset%occopt<=8)then
if (abs(dtset%tphysel) < tol10) then
eent=-dtset%tsmear * energies%entropy
else
eent=-dtset%tphysel * energies%entropy
end if
else
eent=zero
end if
! If DMFT is used and DMFT Entropy is not computed, then do not print
! non interacting entropy
testdmft=(dtset%dmftcheck>=0.and.dtset%usedmft>=1.and.(sum(dtset%upawu(:,1))>=tol8.or. &
& sum(dtset%jpawu(:,1))>tol8).and.dtset%dmft_entropy==0)
if(testdmft) eent=zero
etotal = etotal + eent
etotaldc = etotaldc + eent
!============= Printing of Etotal by direct scheme ===========
if (dtset%icoulomb == 1) then
eneName = "Ion-ion energy"
else
eneName = "Ewald energy"
end if
enevalue = energies%e_ewald
if (optdc==0.or.optdc==2) then
if (directE_avail) then
edoc = yamldoc_open('EnergyTerms', info='Components of total free energy in Hartree', &
width=20, real_fmt='(es21.14)')
call edoc%add_real('kinetic', energies%e_kinetic)
if(abs(energies%e_extfpmd)>tiny(0.0_dp)) then
call edoc%add_real('kinetic_extfpmd',energies%e_extfpmd)
call edoc%add_real('total_kinetic',energies%e_extfpmd+energies%e_kinetic)
end if
if (ipositron/=1) then
exc_semilocal=energies%e_xc+energies%e_hybcomp_E0-energies%e_hybcomp_v0+energies%e_hybcomp_v
! XG20181025 This should NOT be a part of the semilocal XC energy, but treated separately.
! At present, there is still a problem with the variational formulation for the Fock term with PAW.
! So, for the time being, keep it inside.
if(usepaw==1)exc_semilocal=exc_semilocal+energies%e_fock
call edoc%add_real('hartree', energies%e_hartree)
call edoc%add_real('xc', exc_semilocal)
call edoc%add_real(eneName, enevalue)
call edoc%add_real('psp_core', energies%e_corepsp)
#if defined DEV_YP_VDWXC
if ( (dtset%vdw_xc > 0) .and. (dtset%vdw_xc < 10) .and. (xc_vdw_status()) ) then
call edoc%add_real('VdWaals_df', energies%e_xc_vdw)
end if
#endif
end if
call edoc%add_real('local_psp', energies%e_localpsp)
if (usepaw==0) then
if(abs(energies%e_fock0)<tol8)then
call edoc%add_real('non_local_psp', energies%e_nlpsp_vfock)
else
call edoc%add_real('non_local_psp+x', energies%e_nlpsp_vfock-energies%e_fock0)
endif
else
call edoc%add_real('spherical_terms', energies%e_paw)
!!!XG20181025 Does not work (yet)...
!!!if(abs(energies%e_nlpsp_vfock)>tol8)then
!!! write(msg, '(a,es21.14)' )' Fock-type term = ',energies%e_nlpsp_vfock
!!! call wrtout(iout,msg,'COLL')
!!! write(msg, '(a,es21.14)' ) ' -frozen Fock en.= ',-energies%e_fock0
!!! call wrtout(iout,msg,'COLL')
!!!endif
end if
if (ANY(ABS(dtset%nucdipmom)>tol8)) then
call edoc%add_real('nucl. magn. dipoles',energies%e_nucdip)
end if
if ((dtset%vdw_xc>=5.and.dtset%vdw_xc<=7).and.ipositron/=1) then
call edoc%add_real('VdWaals_dft_d', energies%e_vdw_dftd)
end if
if (dtset%nzchempot>=1) then
call edoc%add_real('chem_potential', energies%e_chempot)
end if
if(dtset%occopt>=3.and.dtset%occopt<=8.and.ipositron==0) then
call edoc%add_real('internal', etotal-eent)
if(.not.testdmft) then
call edoc%add_real('-kT*entropy', eent)
end if
else if (ipositron/=0) then
if (dtset%occopt>=3.and.dtset%occopt<=8) then
call edoc%add_real('-kT*entropy', eent)
end if
!write(msg, '(3a,es21.14,a)' ) &
! ' >>> ',EPName(ipositron),' E= ',etotal-energies%e0_electronpositron -energies%e_electronpositron,ch10
!call wrtout(iout,msg,'COLL')
!write(msg, '(3a,es21.14,2a,es21.14)' ) &
! ' ',EPName(3-ipositron),' ener.= ',energies%e0_electronpositron,ch10,&
! ' EP interaction E= ' ,energies%e_electronpositron
!call wrtout(iout,msg,'COLL')
if(ipositron == 1) then
call edoc%add_real('positronic', etotal - energies%e0_electronpositron-energies%e_electronpositron)
call edoc%add_real('electronic', energies%e0_electronpositron)
else
call edoc%add_real('electronic', etotal- energies%e0_electronpositron-energies%e_electronpositron)
call edoc%add_real('positronic', energies%e0_electronpositron)
end if
call edoc%add_real('electron_positron_interaction', energies%e_electronpositron)
end if
if ((dtset%berryopt==4 .or. dtset%berryopt==6 .or. dtset%berryopt==7 .or. &
dtset%berryopt==14 .or. dtset%berryopt==16 .or. dtset%berryopt==17) .and.ipositron/=1) then
call edoc%add_real('electric', energies%e_elecfield)
call edoc%add_real('kohn_sham', etotal-energies%e_elecfield)
end if
call edoc%add_real('total_energy', etotal)
else
write(msg, '(9a)' ) &
' COMMENT: ',ch10,&
' "Direct" decomposition of total free energy cannot be printed out !!!',ch10,&
' PAW contribution due to spin-orbit coupling cannot be evaluated',ch10,&
' without the knowledge of imaginary part of Rhoij atomic occupancies',ch10,&
' (computed only when pawcpxocc=2).'
call wrtout(iout,msg,'COLL')
end if
end if
!============= Printing of Etotal by double-counting scheme ===========
if (optdc>=1) then
dc_edoc = yamldoc_open('EnergyTermsDC', info='"Double-counting" decomposition of free energy', &
width=20, real_fmt="(es21.14)")
call dc_edoc%add_real('band_energy', energies%e_eigenvalues)
if(abs(energies%e_extfpmd)>tiny(0.0_dp)) then
call dc_edoc%add_real('kinetic_extfpmd_dc',energies%edc_extfpmd)
end if
if (ipositron/=1) then
!write(msg, '(2(a,es21.14,a),a,es21.14)' ) &
! ' '//eneName//' =',enevalue,ch10,&
! ' PspCore energy = ',energies%e_corepsp-energies%e_corepspdc,ch10,&
! ' Dble-C XC-energy= ',-energies%e_hartree+energies%e_xc-energies%e_xcdc -energies%e_fock0 + &
! energies%e_hybcomp_E0-energies%e_hybcomp_v0
!call wrtout(iout,msg,'COLL')
call dc_edoc%add_real(eneName, enevalue)
call dc_edoc%add_real('psp_core', energies%e_corepsp-energies%e_corepspdc)
call dc_edoc%add_real('xc_dc', -energies%e_hartree+energies%e_xc-energies%e_xcdc - energies%e_fock0 + &
energies%e_hybcomp_E0-energies%e_hybcomp_v0)
end if
if ((dtset%berryopt==4 .or. dtset%berryopt==6 .or. dtset%berryopt==7 .or. &
dtset%berryopt==14 .or. dtset%berryopt==16 .or. dtset%berryopt==17).and.ipositron/=1) then
call dc_edoc%add_real('electric_field', energies%e_elecfield)
end if
if (usepaw==1) then
call dc_edoc%add_real('spherical_terms', energies%e_pawdc)
end if
if ((dtset%vdw_xc>=5.and.dtset%vdw_xc<=7).and.ipositron/=1) then
call dc_edoc%add_real('VdWaals_dft_d', energies%e_vdw_dftd)
end if
if (dtset%nzchempot>=1) then
call dc_edoc%add_real('chem_potential', energies%e_chempot)
end if
if(dtset%occopt>=3.and.dtset%occopt<=8.and.ipositron==0) then
if(.not.testdmft) then
!write(msg, '(a,es21.14,a,a,a,es21.14)' ) &
! ' >>>>> Internal E= ',etotaldc-eent,ch10,ch10,&
! ' -kT*entropy = ',eent
!call wrtout(iout,msg,'COLL')
call dc_edoc%add_real('internal', etotaldc-eent)
call dc_edoc%add_real('-kT*entropy', eent)
else
call dc_edoc%add_real('internal', etotaldc-eent)
end if
else if (ipositron/=0) then
if (dtset%occopt>=3 .and. dtset%occopt<=8) then
call dc_edoc%add_real('-kT*entropy', eent)
end if
!write(msg, '(a,es21.14,4a,es21.14,a)' ) &
! ' - EP dble-ct En.= ',-energies%edc_electronpositron,ch10,&
! ' >>> ',EPName(ipositron),' E= ',etotaldc-energies%e0_electronpositron -energies%e_electronpositron,ch10
!call wrtout(iout,msg,'COLL')
!write(msg, '(3a,es21.14,2a,es21.14)' ) &
! ' ',EPName(3-ipositron),' ener.= ',energies%e0_electronpositron,ch10,&
! ' EP interaction E= ' ,energies%e_electronpositron
!call wrtout(iout,msg,'COLL')
call dc_edoc%add_real('electron_positron_dc', -energies%edc_electronpositron)
if(ipositron == 1) then
call dc_edoc%add_real('positronic', etotaldc-energies%e0_electronpositron-energies%e_electronpositron)
call dc_edoc%add_real('electronic', energies%e0_electronpositron)
else
call dc_edoc%add_real('electronic', etotaldc-energies%e0_electronpositron-energies%e_electronpositron)
call dc_edoc%add_real('positronic', energies%e0_electronpositron)
end if
call dc_edoc%add_real('electron_positron_interaction', energies%e_electronpositron)
end if
write(msg, '(a,es21.14)' ) ' >>>> Etotal (DC)= ',etotaldc
!call wrtout(iout,msg,'COLL')
call dc_edoc%add_real('total_energy_dc', etotaldc)
end if
!======= Additional printing for compatibility ==========
if (usepaw==0.and.optdc==0) then
call edoc%add_real('total_energy_eV', etotal*Ha_eV)
call edoc%add_real('band_energy', energies%e_eigenvalues)
end if
if ((optdc==0.or.optdc==2).and.(.not.directE_avail)) then
!write(msg, '(a,a,es18.10)' ) ch10,' Band energy (Ha)= ',energies%e_eigenvalues
!call wrtout(iout,msg,'COLL')
call edoc%add_real('band_energy', energies%e_eigenvalues)
end if
if (usepaw==1) then
if ((optdc==0.or.optdc==2).and.(directE_avail)) then
call edoc%add_real('total_energy_eV', etotal*Ha_eV)
end if
if (optdc>=1) then
!if (optdc==1) write(msg, '(a,a,es21.14)' ) ch10,' >Total DC energy in eV = ',etotaldc*Ha_eV
!if (optdc==2) write(msg, '(a,es21.14)' ) ' >Total DC energy in eV = ',etotaldc*Ha_eV
!call wrtout(iout,msg,'COLL')
call dc_edoc%add_real('total_energy_dc_eV', etotaldc*Ha_eV)
end if
end if
if( dtset%icoulomb/=1.and.abs(dtset%cellcharge(1))>tol8) then
write(msg, '(6a)' ) &
ch10,' Calculation was performed for a charged system with PBC',&
ch10,' You may consider including the monopole correction to the total energy',&
ch10,' The correction is to be divided by the dielectric constant'
call wrtout(iout,msg,'COLL')
call edoc%add_real('monopole_correction', energies%e_monopole)
call edoc%add_real('monopole_correction_eV', energies%e_monopole*Ha_eV)
end if
! Write components of total energies in Yaml format.
call edoc%write_and_free(iout)
if (optdc >= 1) call dc_edoc%write_and_free(iout)
end subroutine prtene
!!***
!!****f* ABINIT/get_dtsets_pspheads
!! NAME
!! get_dtsets_pspheads
!!
!! FUNCTION
!! Parse input file, get list of pseudos for files file and build list of datasets
!! pseudopotential headers, maxval of dimensions needed in outvars
!!
!! INPUTS
!! input_path: Input filename specifed on the command line. zero lenght if files file syntax is used.
!! Mainly used to check whether pseudos are defined in the input to avoid entering the files file
!! branch that prompts for pseudos.
!! path: Input Filename
!! comm: MPI communicator
!!
!! OUTPUT
!! lenstr= the length of the resulting string.
!! ndtset= the number of declared datasets.
!! string= contains on output the content of the file, ready for parsing.
!! dtsets(0:ndtset): List of datasets
!! dmatpuflag=flag controlling the use of an initial density matrix in PAW+U (max. value over datasets)
!! mx<ab_dimensions>=datatype storing the maximal dimensions.
!! pspheads(npsp)=<type pspheader_type>=all the important information from the
!! pseudopotential file headers, as well as the psp file names
!!
!! PARENTS
!! abinit
!!
!! CHILDREN
!! hdr%free,hdr_ncread,hdr_read_from_fname,indefo,inpspheads,invars0
!! invars1m,invars2m,macroin,macroin2,parsefile,pspheads_comm,timab
!! time_set_papiopt,wfk_read_eigenvalues
!!
!! SOURCE
subroutine get_dtsets_pspheads(input_path, path, ndtset, lenstr, string, timopt, dtsets, pspheads, mx, dmatpuflag, comm)
!Arguments ------------------------------------
!scalars
integer,intent(out) :: lenstr, ndtset
type(ab_dimensions),intent(out) :: mx
character(len=strlen), intent(out) :: string
character(len=*),intent(in) :: input_path, path
integer,intent(in) :: comm
integer,intent(out) :: timopt, dmatpuflag
!arrays
type(dataset_type),allocatable,intent(out) :: dtsets(:)
type(pspheader_type),allocatable,intent(out):: pspheads(:)
!Local variables-------------------------------
!scalars
integer :: ipsp,ios, me, ndtset_alloc, nprocs
integer :: istatr,istatshft, papiopt, npsp, ii, idtset, msym, usepaw
character(len=fnlen) :: filpsp
character(len=500) :: msg
!arrays
integer,allocatable :: mband_upper_(:)
real(dp) :: ecut_tmp(3,2,10),tsec(2)
real(dp),allocatable :: zionpsp(:)
character(len=fnlen), allocatable :: pspfilnam_(:), pseudo_paths(:)
!************************************************************************
me = xmpi_comm_rank(comm); nprocs = xmpi_comm_size(comm)
! Read the file, stringify it and return the number of datasets.
call parsefile(path, lenstr, ndtset, string, comm)
ndtset_alloc = ndtset; if (ndtset == 0) ndtset_alloc=1
ABI_MALLOC(dtsets, (0:ndtset_alloc))
timopt = 1; if (xmpi_paral==1) timopt = 0
! Continue to analyze the input string, get upper dimensions, and allocate the remaining arrays.
call invars0(dtsets, istatr, istatshft, lenstr, msym, mx%natom, mx%nimage, mx%ntypat, &
ndtset, ndtset_alloc, npsp, pseudo_paths, papiopt, timopt, string, comm)
! Enable PAPI timers
call time_set_papiopt(papiopt)
dtsets(:)%timopt = timopt
dtsets(0)%timopt = 1
if (xmpi_paral == 1) dtsets(0)%timopt = 0
call timab(41,2,tsec)
call timab(timopt,5,tsec)
! Initialize pspheads, that contains the important information
! from the pseudopotential headers, as well as the psp filename
call timab(42,1,tsec)
usepaw = 0
ABI_MALLOC(pspheads, (npsp))
if (npsp > 10) then
ABI_BUG('ecut_tmp is not well defined.')
end if
ecut_tmp = -one
pspheads(:)%usewvl = dtsets(1)%usewvl
if (me == 0) then
ABI_MALLOC(pspfilnam_, (npsp))
if (len_trim(pseudo_paths(1)) == 0) then
! Enter Legacy `files file` mode --> Read the name of the psp file from files file.
! Catch possible mistake done by user (input without pseudos and `abinit t01.in` syntax)
! else the code starts to prompt for pseudos and execution gets stuck
if (len_trim(input_path) /= 0) then
ABI_ERROR("`pseudos` variable must be specified in input when the code is invoked with the `abinit t01.in` syntax")
end if
! Finish to read the "file" file completely, as npsp is known,
do ipsp=1,npsp
write(std_out,'(/,a)' )' Please give name of formatted atomic psp file (and finish with a newline character)'
read (std_in, '(a)' , iostat=ios ) filpsp
! It might be that a file name is missing
if (ios /= 0) then
write(msg, '(5a)' )&
'There are not enough names of pseudopotentials provided in the files file.',ch10,&
'Action: check first the variable ntypat (and/or npsp) in the input file;',ch10,&
'if they are correct, complete your files file.'
ABI_ERROR(msg)
end if
pspfilnam_(ipsp) = trim(filpsp)
write(std_out,'(a,i0,2a)' )' For atom type ',ipsp,', psp file is ',trim(filpsp)
end do ! ipsp
else
! Get pseudopotential paths from input file.
pspfilnam_ = pseudo_paths
do ipsp=1,npsp
write(std_out,'(a,i0,2a)' )' For atom type ',ipsp,', psp file is ',trim(pspfilnam_(ipsp))
end do
end if
! Now read the psp headers
call inpspheads(pspfilnam_, npsp, pspheads, ecut_tmp)
ABI_FREE(pspfilnam_)
if (minval(abs(pspheads(1:npsp)%pspcod - 7)) == 0) usepaw=1
if (minval(abs(pspheads(1:npsp)%pspcod - 17)) == 0) usepaw=1
end if
ABI_FREE(pseudo_paths)
! Communicate pspheads to all processors
call pspheads_comm(npsp, pspheads, usepaw)
! If (all) pspcod are 7 then this is a PAW calculation. Initialize (default) the value of ratsph
do idtset=0,ndtset_alloc
dtsets(idtset)%usepaw = usepaw
if (usepaw == 0) then
dtsets(idtset)%ratsph(:)=two
else
! Note that the following coding assumes that npsp=ntypat for PAW, which is true as of now (XG20101024).
! dtsets(idtset)%ratsph(1:npsp)=token%pspheads(1:npsp)%pawheader%rpaw
do ipsp=1,npsp
dtsets(idtset)%ratsph(ipsp) = pspheads(ipsp)%pawheader%rpaw
end do
endif
end do
! Take care of other dimensions, and part of the content of dtsets that is or might be needed early.
ABI_MALLOC(zionpsp, (npsp))
do ii=1,npsp
zionpsp(ii) = pspheads(ii)%zionpsp
end do
ABI_MALLOC(mband_upper_, (0:ndtset_alloc))
! Get MAX dimension over datasets
call invars1m(dmatpuflag, dtsets, ab_out, lenstr, mband_upper_, mx,&
msym, ndtset, ndtset_alloc, string, npsp, zionpsp, comm)
ABI_FREE(zionpsp)
call timab(42,2,tsec)
call timab(43,3,tsec)
! Provide defaults for the variables that have not yet been initialized.
call indefo(dtsets, ndtset_alloc, nprocs)
! Perform some global initialization, depending on the value of
! pseudopotentials, parallelism variables, or macro input variables
call macroin(dtsets, ecut_tmp, lenstr, ndtset_alloc, string)
! If all the pseudopotentials have the same pspxc, override the default value for dtsets 1 to ndtset
if (minval(abs((pspheads(1:npsp)%pspxc - pspheads(1)%pspxc)))==0) then
dtsets(1:ndtset_alloc)%ixc = pspheads(1)%pspxc
end if
! Call the main input routine.
call invars2m(dtsets,ab_out,lenstr,mband_upper_,msym,ndtset,ndtset_alloc,npsp,pspheads,string, comm)
call macroin2(dtsets, ndtset_alloc)
mx%mband = dtsets(1)%mband
do ii=1,ndtset_alloc
mx%mband = max(dtsets(ii)%mband, mx%mband)
end do
call timab(43,2,tsec)
ABI_FREE(mband_upper_)
end subroutine get_dtsets_pspheads
!!***
!!****f* ABINIT/ebands_from_file
!! NAME
!! ebands_from_file
!!
!! FUNCTION
!! Build and ebands_t object from file. Supports Fortran and netcdf files
!! provided they have a Abinit header and obviously GS eigenvalues
!!
!! INPUTS
!! path: File name.
!! comm: MPI communicator.
!!
!! OUTPUT
!!
!! PARENTS
!!
!! CHILDREN
!!
!! SOURCE
type(ebands_t) function ebands_from_file(path, comm) result(new)
!Arguments ------------------------------------
!scalars
character(len=*),intent(in) :: path
integer,intent(in) :: comm
!Local variables-------------------------------
!scalars
integer :: ncid, fform
type(hdr_type) :: hdr
!arrays
real(dp),pointer :: gs_eigen(:,:,:)
! *************************************************************************
! NOTE: Assume file with header. Must use wfk_read_eigenvalues to handle Fortran WFK
if (endswith(path, "_WFK") .or. endswith(path, "_WFK.nc")) then
call wfk_read_eigenvalues(path, gs_eigen, hdr, comm)
new = ebands_from_hdr(hdr, maxval(hdr%nband), gs_eigen)
else if (endswith(path, ".nc")) then
#ifdef HAVE_NETCDF
NCF_CHECK(nctk_open_read(ncid, path, comm))
call hdr_ncread(hdr, ncid, fform)
ABI_CHECK(fform /= 0, "fform == 0")
ABI_MALLOC(gs_eigen, (hdr%mband, hdr%nkpt, hdr%nsppol))
NCF_CHECK(nf90_get_var(ncid, nctk_idname(ncid, "eigenvalues"), gs_eigen))
new = ebands_from_hdr(hdr, maxval(hdr%nband), gs_eigen)
NCF_CHECK(nf90_close(ncid))
#endif
else
ABI_ERROR(sjoin("Don't know how to construct crystal structure from: ", path, ch10, "Supported extensions: _WFK or .nc"))
end if
ABI_FREE(gs_eigen)
call hdr%free()
end function ebands_from_file
!!***
!!****f* ABINIT/crystal_from_file
!! NAME
!! crystal_from_file
!!
!! FUNCTION
!! Build crystal_t object from netcdf file
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!!
!! CHILDREN
!!
!! SOURCE
type(crystal_t) function crystal_from_file(path, comm) result(new)
!Arguments ------------------------------------
!scalars
character(len=*),intent(in) :: path
integer,intent(in) :: comm
!Local variables-------------------------------
!scalars
integer :: fform
type(hdr_type) :: hdr
! *************************************************************************
! Assume file with Abinit header
! TODO: Should add routine to read crystal from structure without hdr
call hdr_read_from_fname(hdr, path, fform, comm)
ABI_CHECK(fform /= 0, "fform == 0")
new = hdr%get_crystal()
call hdr%free()
end function crystal_from_file
!!***
end module m_common
!!***
| gpl-3.0 |
MeteoSwiss-APN/omni-compiler | tests/xcalablemp/others/F/type_bound_procedure_attr.F90 | 2 | 1373 | #if defined(__GNUC__) && (4 < __GNUC__ || 4 == __GNUC__ && 7 < __GNUC_MINOR__) \
|| defined(__INTEL_COMPILER) && (1600 < __INTEL_COMPILER)
MODULE m_type_bound_procedure_attr
TYPE :: t
INTEGER :: v
CONTAINS
PROCEDURE,PASS(x),non_overridable :: show => show
PROCEDURE,PASS(x),private:: show1
END TYPE t
CONTAINS
SUBROUTINE show(x, v1)
integer v1
CLASS(t) :: x
call show1(x, v1)
END SUBROUTINE show
SUBROUTINE show1(x, v1)
integer v1
CLASS(t) :: x
! PRINT *, v1 + x%v
if (v1+x%v.eq.3) then
print *, 'PASS'
else
print *, 'NG : ', v1+x%v, ', should be 3'
call exit(1)
endif
END SUBROUTINE show1
END MODULE m_type_bound_procedure_attr
PROGRAM MAIN
USE m_type_bound_procedure_attr
CLASS(t), POINTER :: a
TYPE(t), TARGET :: b = t(v=1)
a => b
CALL a%show(2)
END PROGRAM MAIN
#else
print *, 'SKIPPED'
end
#endif
| lgpl-3.0 |
HEPcodes/FeynHiggs | gen/prod/old/f/CHiggsProdFits-LHC14.f | 1 | 7950 |
if( sqrtm .lt. 14.142135623730951D0 .or.
& sqrtm .gt. 24.49489742783178D0 )
& Warning('Extrapolating tHm2 in MHiggs')
if( TBeff .lt. 1.D0 .or.
& TBeff .gt. 60.D0 )
& Warning('Extrapolating tHm2 in TBeff')
if( TBeff.lt.6.D0 ) then
tHm2 = enh*exp(13.436746248619631D0 -
& sqrtm*(0.08324422879362986D0 +
& sqrtm*(0.008644014723430408D0 +
& TBeff*(0.00037805820241529266D0 -
& 3.5463287600719694D-6*TBeff) -
& sqrtm*(0.00011780437026987039D0 +
& 6.318271081715444D-8*sqrtm +
& 5.702646863097232D-6*TBeff)) -
& TBeff*(0.00824040038717313D0 -
& TBeff*(0.00011316298574048705D0 +
& 0.000010307125839643559D0*TBeff))) -
& TBeff*(3.457576926158099D0 -
& TBeff*(0.9670523793599399D0 -
& TBeff*(0.12903948595180198D0 +
& TBeff*
& (0.0034185782525928D0 -
& TBeff*
& (0.0027663706330801814D0 -
& 0.000202200905345916D0*TBeff))))))
else if( TBeff.lt.20.D0 ) then
tHm2 = enh*exp(10.957253227431181D0 -
& sqrtm*(0.09898940902026043D0 +
& TBeff*(0.002582840064649972D0 -
& TBeff*(0.00004914980575925384D0 -
& 1.9936491067797788D-7*TBeff)) +
& sqrtm*(0.00541989044675933D0 -
& TBeff*(0.00003613518898170127D0 +
& 4.512237727486485D-8*TBeff) +
& sqrtm*(0.000033397357839278356D0 -
& 2.408802770295183D-6*sqrtm +
& 4.3046509525023864D-7*TBeff))) -
& TBeff*(1.1498683420882574D0 -
& TBeff*(0.13003757937440716D0 -
& TBeff*(0.0057164378426485425D0 -
& 0.00009142415549207455D0*TBeff))))
else if( TBeff.lt.30.D0 ) then
tHm2 = enh*exp(7.109062657165521D0 -
& sqrtm*(0.22660488357832087D0 +
& 0.0015832946872747404D0*sqrtm +
& 0.00003584792605161799D0*TBeff) +
& TBeff*(0.15208288322676444D0 -
& 0.001443815805546688D0*TBeff))
else
tHm2 = enh*exp(8.070708897011066D0 -
& sqrtm*(0.22749176703828072D0 +
& 0.0015796916651176236D0*sqrtm +
& 9.905026119661305D-6*TBeff) +
& TBeff*(0.09247841854821934D0 -
& 0.000517754467164491D0*TBeff))
endif
#ifdef DETAILED_DEBUG
DPROD "tHm2 =", tHm2 ENDL
#endif
if( sqrtm .lt. 14.142135623730951D0 .or.
& sqrtm .gt. 24.49489742783178D0 )
& Warning('Extrapolating tHm2lo in MHiggs')
if( TBeff .lt. 1.D0 .or.
& TBeff .gt. 60.D0 )
& Warning('Extrapolating tHm2lo in TBeff')
if( TBeff.lt.6.D0 ) then
tHm2lo = enh*exp(12.487256152833043D0 +
& sqrtm*(0.07417626088567057D0 +
& TBeff*(0.005149299759343552D0 -
& TBeff*(6.6889301920602925D-6 +
& 1.3250070405421093D-6*TBeff)) -
& sqrtm*(0.02119755632813506D0 +
& TBeff*(0.0002350636185958048D0 +
& 1.255439472055291D-6*TBeff) -
& sqrtm*(0.0005628606054062444D0 -
& 5.852888569113973D-6*sqrtm +
& 3.7195888172528723D-6*TBeff))) -
& TBeff*(3.4405346255004527D0 -
& TBeff*(0.9689605318607828D0 -
& TBeff*(0.12969972619835585D0 +
& TBeff*
& (0.003408082542892064D0 -
& TBeff*
& (0.0027769848733989644D0 -
& 0.00020321410734441483D0*TBeff))))))
else if( TBeff.lt.20.D0 ) then
tHm2lo = enh*exp(10.58815995809759D0 -
& sqrtm*(0.08432437878158214D0 +
& TBeff*(0.007920269440391684D0 -
& TBeff*(0.00014051011873331668D0 -
& 1.7648834049517707D-6*TBeff)) +
& sqrtm*(0.0056435801966716725D0 -
& TBeff*(0.0002492482402297318D0 -
& 7.363281125140205D-7*TBeff) +
& sqrtm*(0.000038885465672113586D0 -
& 2.5061566722708945D-6*sqrtm +
& 3.6289330100293575D-6*TBeff))) -
& TBeff*(1.1096098294998273D0 -
& TBeff*(0.1296542250566069D0 -
& TBeff*(0.005756511951400485D0 -
& 0.00009295907222951423D0*TBeff))))
else if( TBeff.lt.30.D0 ) then
tHm2lo = enh*exp(6.864162690297306D0 -
& sqrtm*(0.22225928625897007D0 +
& 0.0017034685005055431D0*sqrtm +
& 0.00003158002364425872D0*TBeff) +
& TBeff*(0.1521709843189063D0 -
& 0.0014472834434296777D0*TBeff))
else
tHm2lo = enh*exp(7.820306427674642D0 -
& sqrtm*(0.22262255728054425D0 +
& 0.001711729333350848D0*sqrtm +
& 6.691365867374509D-6*TBeff) +
& TBeff*(0.09250271510423186D0 -
& 0.0005186137850249781D0*TBeff))
endif
#ifdef DETAILED_DEBUG
DPROD "tHm2lo =", tHm2lo ENDL
#endif
if( sqrtm .lt. 14.142135623730951D0 .or.
& sqrtm .gt. 24.49489742783178D0 )
& Warning('Extrapolating tHm2hi in MHiggs')
if( TBeff .lt. 1.D0 .or.
& TBeff .gt. 60.D0 )
& Warning('Extrapolating tHm2hi in TBeff')
if( TBeff.lt.6.D0 ) then
tHm2hi = enh*exp(14.789256715794139D0 -
& sqrtm*(0.3529700900413113D0 -
& sqrtm*(0.01430253684017569D0 -
& TBeff*(0.0005057290462755276D0 -
& 7.187273401174564D-6*TBeff) -
& sqrtm*(0.000743282238984049D0 -
& 0.000012065506670769241D0*sqrtm -
& 7.5513649138153195D-6*TBeff)) -
& TBeff*(0.010950149098506005D0 -
& TBeff*(0.0002006121976933005D0 +
& 0.00001638158163268968D0*TBeff))) -
& TBeff*(3.473152101179105D0 -
& TBeff*(0.9658996624445984D0 -
& TBeff*(0.12858233287559D0 +
& TBeff*
& (0.003429831346174149D0 -
& TBeff*
& (0.002759846074737704D0 -
& 0.00020155379390869257D0*TBeff))))))
else if( TBeff.lt.20.D0 ) then
tHm2hi = enh*exp(12.034301573776196D0 -
& sqrtm*(0.29952853195028967D0 -
& TBeff*(0.0013067338755130603D0 -
& TBeff*(3.5585119709207857D-6 -
& 7.880933027598925D-7*TBeff)) -
& sqrtm*(0.01152322026481797D0 -
& TBeff*(0.0001303516759692075D0 -
& 4.108267782300673D-7*TBeff) -
& sqrtm*(0.0006756771166600049D0 -
& 0.000011500799503762068D0*sqrtm -
& 2.216944237523049D-6*TBeff))) -
& TBeff*(1.1782030356400874D0 -
& TBeff*(0.1302353259004671D0 -
& TBeff*(0.005690616141020891D0 -
& 0.0000904389555763092D0*TBeff))))
else if( TBeff.lt.30.D0 ) then
tHm2hi = enh*exp(7.358694835495833D0 -
& sqrtm*(0.2354653732837003D0 +
& 0.0013497302691223235D0*sqrtm +
& 0.00003870014891298283D0*TBeff) +
& TBeff*(0.15200939622113957D0 -
& 0.0014412432922088349D0*TBeff))
else
tHm2hi = enh*exp(8.324239853206478D0 -
& sqrtm*(0.23674004594129472D0 +
& 0.0013372489725143291D0*sqrtm +
& 0.000012065316082131659D0*TBeff) +
& TBeff*(0.09245927560206861D0 -
& 0.0005171481279629904D0*TBeff))
endif
#ifdef DETAILED_DEBUG
DPROD "tHm2hi =", tHm2hi ENDL
#endif
| gpl-3.0 |
abinit/abinit | src/69_wfdesc/m_wfd_optic.F90 | 1 | 9228 | !!****m* ABINIT/m_wfd_optic
!! NAME
!! m_wfd_optic
!!
!! FUNCTION
!! Functions to compute optical matrix elements using the wavefunction descriptor.
!!
!! COPYRIGHT
!! Copyright (C) 2008-2021 ABINIT group (MG)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! PARENTS
!!
!! CHILDREN
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
module m_wfd_optic
use defs_basis
use m_errors
use m_abicore
use m_xmpi
use defs_datatypes, only : ebands_t, pseudopotential_type
use m_hide_lapack, only : matrginv
use m_bz_mesh, only : kmesh_t, get_BZ_item
use m_crystal, only : crystal_t
use m_vkbr, only : vkbr_t, vkbr_free, vkbr_init, nc_ihr_comm
use m_wfd, only : wfd_t, wave_t
use m_pawtab, only : pawtab_type
use m_pawcprj, only : pawcprj_type, pawcprj_alloc, pawcprj_free
use m_paw_hr, only : pawhur_t, paw_ihr
implicit none
private
!!***
public :: calc_optical_mels
!!***
contains
!!***
!!****f* ABINIT/calc_optical_mels
!! NAME
!! calc_optical_mels
!!
!! FUNCTION
!! Calculate all optical matrix elements in the BZ.
!!
!! INPUTS
!! lomo_spin(Wfd%nsppol)=Index of the lomo band for the different spins.
!! lomo_min,max_band=minimum and max band index to be calculated.
!! nkbz=Number of points in the full Brillouin zone.
!! inclvkb=if different from 0, [Vnl,r] is included in the calculation of the
!! matrix element of the velocity operator. No meaning for PAW (except for DFT+U)
!! qpt(3)
!! Kmesh<kmesh_t>=Info on the k-point sampling for wave functions.
!! Cryst<crystal_t>=Structure defining the crystalline structure.
!! KS_Bst<ebands_t>
!! Pawtab(Cryst%ntypat*usepaw)<pawtab_type>=PAW tabulated starting data
!! Psps <pseudopotential_type>=variables related to pseudopotentials.
!! Hur(Cryst%natom*usepaw)<pawhur_t>=Only for PAW and DFT+U, quantities used to evaluate the commutator [H_u,r].
!! Wfd<wfd_t>=Handler for the wavefunctions.
!!
!! OUTPUT
!! opt_cvk(lomo_min:max_band,lomo_min:max_band,nkbz,nsppol)=Matrix elements <c k|e^{+iqr}|v k>
!!
!! PARENTS
!! m_exc_spectra,m_haydock
!!
!! CHILDREN
!! get_bz_item,matrginv,pawcprj_alloc,pawcprj_free,vkbr_free,vkbr_init
!! wfd%distribute_bbp,wfd%get_cprj,wrtout,xmpi_barrier,xmpi_sum
!!
!! SOURCE
subroutine calc_optical_mels(Wfd,Kmesh,KS_Bst,Cryst,Psps,Pawtab,Hur,&
& inclvkb,lomo_spin,lomo_min,max_band,nkbz,qpoint,opt_cvk)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: nkbz,inclvkb,lomo_min,max_band
type(kmesh_t),intent(in) :: Kmesh
type(crystal_t),intent(in) :: Cryst
type(pseudopotential_type),intent(in) :: Psps
type(ebands_t),intent(in) :: KS_Bst
type(wfd_t),target,intent(inout) :: Wfd
!arrays
integer,intent(in) :: lomo_spin(Wfd%nsppol)
real(dp),intent(in) :: qpoint(3)
complex(dpc),intent(out) :: opt_cvk(lomo_min:max_band,lomo_min:max_band,nkbz,Wfd%nsppol)
type(pawtab_type),intent(in) :: Pawtab(Cryst%ntypat*Wfd%usepaw)
type(pawhur_t),intent(in) :: Hur(Cryst%natom*Wfd%usepaw)
!Local variables ------------------------------
!scalars
integer :: nsppol,usepaw,nspinor,comm,spin,npw_k,istwf_k,my_nbbp
integer :: ik_bz,ik_ibz,itim_k,isym_k,ib_c,ib_v,ierr,my_rank
real(dp) :: ediff
complex(dpc) :: emcvk
character(len=500) :: msg
type(vkbr_t) :: vkbr
type(wave_t),pointer :: wave_v, wave_c
!arrays
integer,allocatable :: bbp_distrb(:,:)
integer,ABI_CONTIGUOUS pointer :: kg_k(:,:)
real(dp) :: mat_dp(3,3),qrot(3),b1(3),b2(3),b3(3),kbz(3)
complex(dpc),allocatable :: ir_kibz(:,:,:,:,:)
complex(gwpc), ABI_CONTIGUOUS pointer :: ug_c(:),ug_v(:)
complex(gwpc) :: ihrc(3,Wfd%nspinor**2)
logical :: bbp_mask(Wfd%mband,Wfd%mband)
type(pawcprj_type),allocatable :: Cp_v(:,:),Cp_c(:,:)
!************************************************************************
call wrtout(std_out," Calculating optical matrix elements in the IBZ","COLL")
ABI_CHECK(Wfd%nspinor==1,"nspinor==2 not coded")
comm = Wfd%comm
my_rank = Wfd%my_rank
nsppol = Wfd%nsppol
nspinor = Wfd%nspinor
usepaw = Wfd%usepaw
if (usepaw==1) then
ABI_MALLOC(Cp_v,(Wfd%natom,nspinor))
call pawcprj_alloc(Cp_v,0,Wfd%nlmn_atm)
ABI_MALLOC(Cp_c,(Wfd%natom,nspinor))
call pawcprj_alloc(Cp_c,0,Wfd%nlmn_atm)
end if
if (inclvkb==1.and.usepaw==0) then
ABI_ERROR("inclvkb==1 not coded,using inclvkb==2")
end if
!
! Calculate the matrix elements of ir in the IBZ.
ABI_MALLOC(ir_kibz,(3,lomo_min:max_band,lomo_min:max_band,Wfd%nkibz,nsppol))
ir_kibz=czero
ABI_MALLOC(bbp_distrb, (Wfd%mband,Wfd%mband))
do spin=1,nsppol
do ik_ibz=1,Wfd%nkibz
!
! Distribute the (b,b') entries.
bbp_mask=.FALSE.; bbp_mask(lomo_spin(spin):max_band,lomo_spin(spin):max_band)=.TRUE.
call wfd%distribute_bbp(ik_ibz,spin,"All",my_nbbp,bbp_distrb,bbp_mask=bbp_mask)
if (ALL(bbp_distrb/=my_rank)) CYCLE
istwf_k = Wfd%istwfk(ik_ibz)
ABI_CHECK(istwf_k==1,"istwf_k/=1 not coded") ! KB stuff is missing.
npw_k = Wfd%npwarr(ik_ibz)
kg_k => Wfd%Kdata(ik_ibz)%kg_k
if (inclvkb/=0.and.usepaw==0) then
! Prepare term i <n,k|[Vnl,r]|n"k>
call vkbr_init(vkbr,Cryst,Psps,inclvkb,istwf_k,npw_k,Kmesh%ibz(:,ik_ibz),kg_k)
end if
! Note: spinorial case is not coded therefore we work with ihrc(:,1).
! TODO: The lower triangle can be Reconstructed by symmetry.
do ib_v=lomo_spin(spin),max_band ! Loop over bands
if ( ALL(bbp_distrb(ib_v,:)/=my_rank) ) CYCLE
ABI_CHECK(wfd%get_wave_ptr(ib_v, ik_ibz, spin, wave_v, msg) == 0, msg)
ug_v => wave_v%ug
if (usepaw==1) call wfd%get_cprj(ib_v,ik_ibz,spin,Cryst,Cp_v,sorted=.FALSE.)
do ib_c=lomo_spin(spin),max_band
if (bbp_distrb(ib_v,ib_c)/=my_rank) CYCLE
ABI_CHECK(wfd%get_wave_ptr(ib_c, ik_ibz, spin, wave_c, msg) == 0, msg)
ug_c => wave_c%ug
if (usepaw==0) then
! Calculate matrix elements of i[H,r] for NC pseudopotentials.
ihrc = nc_ihr_comm(vkbr,cryst,psps,npw_k,nspinor,istwf_k,inclvkb,Kmesh%ibz(:,ik_ibz),ug_c,ug_v,kg_k)
else
! Matrix elements of i[H,r] for PAW.
call wfd%get_cprj(ib_c,ik_ibz,spin,Cryst,Cp_c,sorted=.FALSE.)
ihrc = paw_ihr(spin,nspinor,npw_k,istwf_k,Kmesh%ibz(:,ik_ibz),Cryst,Pawtab,ug_c,ug_v,kg_k,Cp_c,Cp_v,HUr)
end if
!
! Save matrix elements of i*r in the IBZ
ediff = KS_Bst%eig(ib_c,ik_ibz,spin) - KS_BSt%eig(ib_v,ik_ibz,spin)
if (ABS(ediff)<tol16) ediff=tol6 ! Treat a possible degeneracy between v and c.
ir_kibz(:,ib_c,ib_v,ik_ibz,spin) = ihrc(:,1)/ediff
end do !ib_c
end do !ib_v
call vkbr_free(vkbr)
end do !spin
end do !ik_ibz
! Collect results on each node.
call xmpi_sum(ir_kibz,comm,ierr)
ABI_FREE(bbp_distrb)
if (usepaw==1) then
call pawcprj_free(Cp_v)
ABI_FREE(Cp_v)
call pawcprj_free(Cp_c)
ABI_FREE(Cp_c)
end if
!
! ======================================================
! ==== Calculate Fcv(kBZ) in the full Brilouin zone ====
! ======================================================
!
! Symmetrization of the matrix elements of the position operator.
! <Sk b|r|Sk b'> = R <k b|r|k b'> + \tau \delta_{bb'}
! where S is one of the symrec operations in reciprocal space, R is the
! corresponding operation in real space, \tau being the associated fractional translations.
!
! q.Mcv( Sk) = S^{-1}q. Mcv(k)
! q.Mcv(-Sk) = -S^{-1}q. CONJG(Mcv(k)) if time-reversal is used.
b1=Cryst%gprimd(:,1)*two_pi
b2=Cryst%gprimd(:,2)*two_pi
b3=Cryst%gprimd(:,3)*two_pi
opt_cvk = czero
do spin=1,nsppol
do ik_bz=1,nkbz
!
! Get ik_ibz, and symmetries index from ik_bz.
call get_BZ_item(Kmesh,ik_bz,kbz,ik_ibz,isym_k,itim_k)
mat_dp = DBLE(Cryst%symrec(:,:,isym_k))
call matrginv(mat_dp,3,3) ! Invert
qrot = (3-2*itim_k) * MATMUL(mat_dp,qpoint)
do ib_v=lomo_spin(spin),max_band ! Loops over the bands C and V start
do ib_c=lomo_spin(spin),max_band
!if (ib_c==ib_v) CYCLE
emcvk = pdtqrc(qrot,ir_kibz(:,ib_c,ib_v,ik_ibz,spin),b1,b2,b3)
if (itim_k==2) emcvk = CONJG(emcvk)
opt_cvk(ib_c,ib_v,ik_bz,spin) = emcvk
end do !ib_c
end do !ib_v
end do !ik_bz
end do !spin
ABI_FREE(ir_kibz)
call xmpi_barrier(comm)
contains
!!***
!!****f* ABINIT/pdtqrc
!! NAME
!! pdtqrc
!!
!! FUNCTION
!! Calculate the dot product of a real vector with a complex vector, where each is in terms of b1-b3
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!!
!! SOURCE
pure function pdtqrc(R,C,b1,b2,b3)
!Arguments ------------------------------------
!arrays
real(dp),intent(in) :: R(3),b1(3),b2(3),b3(3)
complex(dpc),intent(in) :: C(3)
complex(dpc) :: pdtqrc
!Local variables ------------------------------
!scalars
integer :: ii
!************************************************************************
pdtqrc=czero
do ii=1,3
pdtqrc = pdtqrc + (R(1)*b1(ii)+R(2)*b2(ii)+R(3)*b3(ii)) * &
& (C(1)*b1(ii)+C(2)*b2(ii)+C(3)*b3(ii))
end do
end function pdtqrc
!!***
end subroutine calc_optical_mels
!!***
end module m_wfd_optic
!!***
| gpl-3.0 |
abinit/abinit | src/57_iovars/m_outvar_a_h.F90 | 1 | 54608 | !!****m* ABINIT/m_outvar_a_h
!! NAME
!! m_outvar_a_h
!!
!! FUNCTION
!!
!! COPYRIGHT
!! Copyright (C) 1998-2021 ABINIT group (DCA, XG, GMR, MM)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! PARENTS
!!
!! CHILDREN
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
module m_outvar_a_h
use defs_basis
use m_abicore
use m_results_out
use m_dtset
use m_parser, only : prttagm, prttagm_images, ab_dimensions
implicit none
private
!!***
public :: outvar_a_h
!!***
contains
!!***
!!****f* ABINIT/outvar_a_h
!! NAME
!! outvar_a_h
!!
!! FUNCTION
!! Echo variables between acell and gw_ ... (by alphabetic order) for the ABINIT code.
!!
!! INPUTS
!! choice= 1 if echo of preprocessed variables, 2 if echo after call driver
!! dmatpuflag=flag controlling the use of an initial density matrix in PAW+U (max. value over datasets)
!! dtsets(0:ndtset_alloc)=<type datafiles_type>contains all input variables
!! iout=unit number for echoed output
!! jdtset_(0:ndtset_alloc)=actual index of the dataset (equal to dtsets(:)%jdtset)
!! marr=maximum number of numbers in an array (might need to be increased ... !)
!! multivals= <type ab_dimensions> either 0 or 1 , depending whether the
!! dimension has different values for different datasets
!! mxvals= <type ab_dimensions>
!! maximum size of some arrays along all datasets, including
!! lpawu =maximal value of input lpawu for all the datasets
!! gw_nqlwl =maximal value of input gw_nqlwl for all the datasets
!! mband =maximum number of bands
!! natom =maximal value of input natom for all the datasets
!! natpawu =maximal value of number of atoms on which +U is applied for all the datasets
!! natvshift =maximal value of input natvshift for all the datasets
!! nconeq =maximal value of input nconeq for all the datasets
!! nimage =maximal value of input nimage for all the datasets
!! nkpt =maximal value of input nkpt for all the datasets
!! nkptgw =maximal value of input nkptgw for all the datasets
!! nnos =maximal value of input nnos for all the datasets
!! nqptdm =maximal value of input nqptdm for all the datasets
!! nspinor =maximal value of input nspinor for all the datasets
!! nsppol =maximal value of input nsppol for all the datasets
!! nsym =maximum number of symmetries
!! ntypat =maximum number of type of atoms
!! nzchempot =maximal value of input nzchempot for all the datasets
!! ncid= NetCDF handler
!! ndtset=number of datasets
!! ndtset_alloc=number of datasets, corrected for allocation of at least
!! one data set. Use for most dimensioned arrays.
!! for different datasets
!! results_out(0:ndtset_alloc)=<type results_out_type>contains the results
!! needed for outvars, including evolving variables
!!
!! OUTPUT
!!
!! NOTES
!! Note that this routine is called only by the processor me==0 .
!! In consequence, no use of message and wrtout routine.
!! The lines of code needed to output the defaults are preserved
!! (see last section of the routine, but are presently disabled)
!!
!! Note that acell, occ, rprim, xred and vel might have been modified by the
!! computation, so that their values if choice=1 or choice=2 will differ.
!!
!! PARENTS
!! m_outvars
!!
!! CHILDREN
!! prttagm,prttagm_images
!!
!! SOURCE
subroutine outvar_a_h (choice,dmatpuflag,dtsets,iout,&
& jdtset_,marr,multivals,mxvals,ncid,ndtset,ndtset_alloc,&
& results_out,strimg)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: choice,dmatpuflag,iout,marr,ndtset
integer,intent(in) :: ndtset_alloc,ncid
!arrays
integer,intent(in) :: jdtset_(0:ndtset_alloc)
type(ab_dimensions),intent(in) :: multivals,mxvals
type(dataset_type),intent(in) :: dtsets(0:ndtset_alloc)
type(results_out_type),intent(in) :: results_out(0:ndtset_alloc)
character(len=8),intent(in) :: strimg(mxvals%nimage)
!Local variables-------------------------------
!scalars
integer,parameter :: nkpt_max=50
integer :: defo,idtset,ii,iimage,ga_n_rules,nn
integer :: lpawu1,narr,mxnsp
integer :: natom,nimfrqs,nimage
integer :: ntypalch,ntypat,print_constraint,size1,size2,tmpimg0
logical :: compute_static_images
real(dp) :: cpus
character(len=1) :: firstchar_fftalg,firstchar_gpu
character(len=14) :: str_hyb
!arrays
integer,allocatable :: narrm(:)
integer,allocatable :: nimagem(:),prtimg(:,:)
integer,allocatable :: intarr(:,:)
real(dp),allocatable :: dprarr(:,:),dprarr_images(:,:,:)
! *************************************************************************
!###########################################################
!### 01. Initial allocations and initialisations.
ABI_MALLOC(dprarr,(marr,0:ndtset_alloc))
ABI_MALLOC(dprarr_images,(marr,mxvals%nimage,0:ndtset_alloc))
ABI_MALLOC(intarr,(marr,0:ndtset_alloc))
ABI_MALLOC(narrm,(0:ndtset_alloc))
ABI_MALLOC(nimagem,(0:ndtset_alloc))
ABI_MALLOC(prtimg,(mxvals%nimage,0:ndtset_alloc))
do idtset=0,ndtset_alloc
nimagem(idtset)=dtsets(idtset)%nimage
end do
firstchar_gpu=' ';if (maxval(dtsets(1:ndtset_alloc)%use_gpu_cuda)>0) firstchar_gpu='-'
!if(multivals%ga_n_rules==0)ga_n_rules=dtsets(1)%ga_n_rules
ga_n_rules=dtsets(1)%ga_n_rules
!if(multivals%natom==0)natom=dtsets(1)%natom
natom=dtsets(1)%natom
!if(multivals%nimage==0)nimage=dtsets(1)%nimage
nimage=dtsets(1)%nimage
nimfrqs=dtsets(1)%cd_customnimfrqs
!if(multivals%ntypalch==0)ntypalch=dtsets(1)%ntypalch
ntypalch=dtsets(1)%ntypalch
!if(multivals%ntypat==0)ntypat=dtsets(1)%ntypat
ntypat=dtsets(1)%ntypat
!###########################################################
!### 03. Print all the input variables (A)
!##
intarr(1,:)=dtsets(:)%iomode
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'iomode','INT',0,firstchar="-")
intarr(1,:)=dtsets(:)%accuracy
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'accuracy','INT',0)
!acell
prtimg(:,:)=1
do idtset=0,ndtset_alloc
narrm(idtset)=3
do iimage=1,nimagem(idtset)
if (narrm(idtset)>0) then
dprarr_images(1:narrm(idtset),iimage,idtset)=results_out(idtset)%acell(1:3,iimage)
end if
end do
end do
call prttagm_images(dprarr_images,iout,jdtset_,2,marr,narrm,ncid,ndtset_alloc,'acell','LEN',&
mxvals%nimage,nimagem,ndtset,prtimg,strimg)
!adpimd and adpimd_gamma
intarr(1,:)=dtsets(:)%adpimd
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'adpimd','INT',0)
dprarr(1,:)=dtsets(:)%adpimd_gamma
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'adpimd_gamma','DPR',0)
!algalch
narr=ntypalch ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%ntypalch
if(idtset==0)narrm(idtset)=mxvals%ntypat
intarr(1:narrm(idtset),idtset)=dtsets(idtset)%algalch(1:narrm(idtset))
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,&
narrm,ncid,ndtset_alloc,'algalch','INT',multivals%ntypalch)
!amu
prtimg(:,:)=1
do idtset=0,ndtset_alloc
if(idtset/=0)then
size1=dtsets(idtset)%ntypat
else
size1=mxvals%ntypat
end if
narrm(idtset)=size1
do iimage=1,nimagem(idtset)
if (narrm(idtset)>0) then
dprarr_images(1:narrm(idtset),iimage,idtset)=results_out(idtset)%amu(1:size1,iimage)
end if
end do
end do
call prttagm_images(dprarr_images,iout,jdtset_,1,marr,narrm,ncid,ndtset_alloc,'amu','DPR',&
& mxvals%nimage,nimagem,ndtset,prtimg,strimg,forceprint=2)
intarr(1,:)=dtsets(:)%asr
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'asr','INT',0)
!atvshift
if(mxvals%natpawu>0)then
narr=dtsets(1)%natvshift*dtsets(1)%nsppol*mxvals%natom ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
if(idtset/=0)then
narrm(idtset)=dtsets(idtset)%natvshift*dtsets(idtset)%nsppol*mxvals%natom
if(narrm(idtset)/=0)&
& dprarr(1:narrm(idtset),idtset)=&
& reshape(dtsets(idtset)%atvshift(1:dtsets(idtset)%natvshift,&
& 1:dtsets(idtset)%nsppol,1:mxvals%natom),&
& (/ narrm(idtset) /) )
else
narrm(idtset)=mxvals%natvshift*mxvals%nsppol*mxvals%natom
if(narrm(idtset)/=0)&
& dprarr(1:narrm(idtset),idtset)=&
& reshape(dtsets(idtset)%atvshift(1:mxvals%natvshift,&
& 1:mxvals%nsppol,1:mxvals%natom),&
& (/ narrm(idtset) /) )
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,5,marr,narr,&
& narrm,ncid,ndtset_alloc,'atvshift','DPR',&
& multivals%natvshift+multivals%nsppol+multivals%natom)
end if
intarr(1,:)=dtsets(:)%autoparal
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'autoparal','INT',0)
intarr(1,:)=dtsets(:)%auxc_ixc
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'auxc_ixc','INT',0)
dprarr(1,:)=dtsets(:)%auxc_scal
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'auxc_scal','DPR',0)
intarr(1,:)=dtsets(:)%awtr
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'awtr','INT',0)
!###########################################################
!### 03. Print all the input variables (B)
!##
intarr(1,:)=dtsets(:)%bandpp
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bandpp','INT',0)
intarr(1,:)=dtsets(:)%bdberry(1)
intarr(2,:)=dtsets(:)%bdberry(2)
intarr(3,:)=dtsets(:)%bdberry(3)
intarr(4,:)=dtsets(:)%bdberry(4)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,4,narrm,ncid,ndtset_alloc,'bdberry','INT',0)
intarr(1,:)=dtsets(:)%bdeigrf
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bdeigrf','INT',0)
!bdgw
narr=2*dtsets(1)%nkptgw*dtsets(1)%nsppol ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
if(idtset/=0)then
narrm(idtset)=2*dtsets(idtset)%nkptgw*dtsets(idtset)%nsppol
if (narrm(idtset)>0)&
& intarr(1:narrm(idtset),idtset)=&
& reshape(dtsets(idtset)%bdgw(1:2,1:dtsets(idtset)%nkptgw,1:dtsets(idtset)%nsppol),(/narrm(idtset)/))
else
narrm(idtset)=2*mxvals%nkptgw*mxvals%nsppol
if (narrm(idtset)>0)&
& intarr(1:narrm(idtset),idtset)=&
& reshape(dtsets(idtset)%bdgw(1:2,1:mxvals%nkptgw,1:mxvals%nsppol),(/ narrm(idtset) /) )
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,narr,&
& narrm,ncid,ndtset_alloc,'bdgw','INT',multivals%nkptgw+multivals%nsppol)
intarr(1,:)=dtsets(:)%berryopt
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'berryopt','INT',0)
intarr(1,:)=dtsets(:)%berrysav
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'berrysav','INT',0)
intarr(1,:)=dtsets(:)%berrystep
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'berrystep','INT',0)
dprarr(1,:)=dtsets(:)%bfield(1)
dprarr(2,:)=dtsets(:)%bfield(2)
dprarr(3,:)=dtsets(:)%bfield(3)
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'bfield','DPR',0)
dprarr(1,:)=dtsets(:)%bmass
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'bmass','DPR',0)
dprarr(1,:)=dtsets(:)%boxcenter(1)
dprarr(2,:)=dtsets(:)%boxcenter(2)
dprarr(3,:)=dtsets(:)%boxcenter(3)
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'boxcenter','DPR',0)
dprarr(1,:)=dtsets(:)%boxcutmin
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'boxcutmin','DPR',0)
intarr(1,:)=dtsets(:)%brav
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'brav','INT',0)
intarr(1,:)=dtsets(:)%bs_algorithm
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_algorithm','INT',0)
intarr(1,:)=dtsets(:)%bs_calctype
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_calctype','INT',0)
intarr(1,:)=dtsets(:)%bs_coulomb_term
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_coulomb_term','INT',0)
intarr(1,:)=dtsets(:)%bs_coupling
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_coupling','INT',0)
do idtset=0,ndtset_alloc
dprarr(1:2,idtset)=dtsets(idtset)%bs_eh_cutoff(1:2)
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,2,narrm,ncid,ndtset_alloc,'bs_eh_cutoff','ENE',0)
intarr(1,:)=dtsets(:)%bs_exchange_term
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_exchange_term','INT',0)
do idtset=0,ndtset_alloc
dprarr(1:3,idtset)=dtsets(idtset)%bs_freq_mesh(1:3)
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'bs_freq_mesh','ENE',0)
intarr(1,:)=dtsets(:)%bs_haydock_niter
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_haydock_niter','INT',0)
do idtset=0,ndtset_alloc
dprarr(1:2,idtset)=dtsets(idtset)%bs_haydock_tol(:)
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,2,narrm,ncid,ndtset_alloc,'bs_haydock_tol','DPR',0)
intarr(1,:)=dtsets(:)%bs_hayd_term
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_hayd_term','INT',0)
do idtset=0,ndtset_alloc
intarr(1:3,idtset)=dtsets(idtset)%bs_interp_kmult(1:3)
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'bs_interp_kmult','INT',0)
intarr(1,:)=dtsets(:)%bs_interp_method
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_interp_method','INT',0)
intarr(1,:)=dtsets(:)%bs_interp_mode
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_interp_mode','INT',0)
intarr(1,:)=dtsets(:)%bs_interp_prep
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_interp_prep','INT',0)
intarr(1,:)=dtsets(:)%bs_interp_rl_nb
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_interp_rl_nb','INT',0)
!bs_loband
narr=dtsets(1)%nsppol ! default size for all datasets
intarr = 0
do idtset=0,ndtset_alloc ! specific size for each dataset
if(idtset/=0)then
narrm(idtset)=dtsets(idtset)%nsppol
else
narrm(idtset)=mxvals%nsppol
end if
intarr(1:narrm(idtset),idtset)=dtsets(idtset)%bs_loband(1:narrm(idtset))
end do
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,narr,narrm,ncid,ndtset_alloc,'bs_loband','INT',multivals%nsppol)
intarr(1,:)=dtsets(:)%bs_nstates
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'bs_nstates','INT',0)
intarr(1,:)=dtsets(:)%builtintest
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'builtintest','INT',0)
dprarr(1,:)=dtsets(:)%bxctmindg
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'bxctmindg','DPR',0)
!###########################################################
!### 03. Print all the input variables (C)
!##
if (ANY(dtsets(:)%cd_customnimfrqs/=0)) then
intarr(1,:)=dtsets(:)%cd_customnimfrqs
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'cd_customnimfrqs','INT',0)
end if
intarr(1,:)=dtsets(:)%cd_frqim_method
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'cd_frqim_method','INT',0)
intarr(1,:)=dtsets(:)%cd_full_grid
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'cd_full_grid','INT',0)
dprarr(1,:)=dtsets(:)%cd_halfway_freq
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'cd_halfway_freq','ENE',0)
!cd_imfrqs
narr=mxvals%nimfrqs ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%cd_customnimfrqs
if(idtset==0)narrm(idtset)=mxvals%nimfrqs
if (narrm(idtset)>0) then
dprarr(1:narrm(idtset),idtset)=dtsets(idtset)%cd_imfrqs(1:narrm(idtset))
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,6,marr,narr,narrm,ncid,ndtset_alloc,'cd_imfrqs','ENE',multivals%nimfrqs)
dprarr(1,:)=dtsets(:)%cd_max_freq
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'cd_max_freq','ENE',0)
if (ANY(dtsets(:)%cd_subset_freq(1)/=0)) then
intarr(1,:)=dtsets(:)%cd_subset_freq(1)
intarr(2,:)=dtsets(:)%cd_subset_freq(2)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,2,narrm,ncid,ndtset_alloc,'cd_subset_freq','INT',0)
end if
!cellcharge
prtimg(:,:)=1
do idtset=0,ndtset_alloc
narrm(idtset)=1
do iimage=1,nimagem(idtset)
if (narrm(idtset)>0) then
dprarr_images(1:narrm(idtset),iimage,idtset)=dtsets(idtset)%cellcharge(iimage)
end if
end do
end do
call prttagm_images(dprarr_images,iout,jdtset_,1,marr,narrm,ncid,ndtset_alloc,'cellcharge','DPR',&
& mxvals%nimage,nimagem,ndtset,prtimg,strimg)
!chempot
narr=3*mxvals%nzchempot*mxvals%ntypat ! default size for all datasets
if(narr/=0)then
do idtset=0,ndtset_alloc ! specific size for each dataset
if(idtset/=0)then
narrm(idtset)=3*dtsets(idtset)%nzchempot*dtsets(idtset)%ntypat
if(narrm(idtset)/=0)&
& dprarr(1:narrm(idtset),idtset)=&
& reshape(dtsets(idtset)%chempot(1:3,1:dtsets(idtset)%nzchempot,&
& 1:dtsets(idtset)%ntypat),&
& (/ narrm(idtset) /) )
else
narrm(idtset)=3*mxvals%nzchempot*mxvals%ntypat
if(narrm(idtset)/=0)&
& dprarr(1:narrm(idtset),idtset)=&
& reshape(dtsets(idtset)%chempot(1:3,1:mxvals%nzchempot,1:mxvals%ntypat),(/ narrm(idtset) /) )
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'chempot','DPR',1)
end if
intarr(1,:)=dtsets(:)%chkdilatmx
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'chkdilatmx','INT',0)
intarr(1,:)=dtsets(:)%chkexit
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'chkexit','INT',0)
intarr(1,:)=dtsets(:)%chkprim
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'chkprim','INT',0)
intarr(1,:)=dtsets(:)%chksymbreak
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'chksymbreak','INT',0)
intarr(1,:)=dtsets(:)%chksymtnons
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'chksymtnons','INT',0)
intarr(1,:)=dtsets(:)%chneut
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'chneut','INT',0)
!chrgat
narr=mxvals%natom ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%natom
if(idtset==0)narrm(idtset)=mxvals%natom
if (narrm(idtset)>0) dprarr(1:narrm(idtset),idtset)=dtsets(idtset)%chrgat(1:narrm(idtset))
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'chrgat','DPR',multivals%natom)
intarr(1,:)=dtsets(:)%cineb_start
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'cineb_start','INT',0)
if(dtsets(1)%cpus>one)then
cpus=dtsets(1)%cpus
write(iout,'(1x,a16,1x,1p,t22,g10.2,t25,a)') 'cpus',cpus,'(seconds)'
write(iout,'(1x,a16,1x,1p,t22,g10.2,t25,a)') 'cpum',cpus/60.0_dp,'(minutes)'
write(iout,'(1x,a16,1x,1p,t22,g10.2,t25,a)') 'cpuh',cpus/3600.0_dp,'(hours)'
end if
!constraint_kind
narr=mxvals%ntypat ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%ntypat
if(idtset==0)narrm(idtset)=mxvals%ntypat
if (narrm(idtset)>0) intarr(1:narrm(idtset),idtset)=dtsets(idtset)%constraint_kind(1:narrm(idtset))
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'constraint_kind','INT',multivals%ntypat)
!corecs
narr=mxvals%ntypat ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%ntypat
if(idtset==0)narrm(idtset)=mxvals%ntypat
if (narrm(idtset)>0) dprarr(1:narrm(idtset),idtset)=dtsets(idtset)%corecs(1:narrm(idtset))
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'corecs','DPR',multivals%ntypat)
intarr(1,:)=dtsets(:)%cprj_update_lvl
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'cprj_update_lvl','INT',0)
!###########################################################
!### 03. Print all the input variables (D)
!##
dprarr(1,:)=dtsets(:)%ddamp
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'ddamp','DPR',0)
do idtset=0,ndtset_alloc
intarr(1:3,idtset)=dtsets(idtset)%ddb_ngqpt
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'ddb_ngqpt','INT',0)
dprarr(1,:)=dtsets(:)%ddb_shiftq(1)
dprarr(2,:)=dtsets(:)%ddb_shiftq(2)
dprarr(3,:)=dtsets(:)%ddb_shiftq(3)
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'ddb_shiftq','DPR',0)
intarr(1,:)=dtsets(:)%delayperm
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'delayperm','INT',0)
intarr(1,:)=dtsets(:)%densfor_pred
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'densfor_pred','INT',0)
!densty
narr=mxvals%ntypat ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%ntypat
if(idtset==0)narrm(idtset)=mxvals%ntypat
! Only one component of densty is used until now
dprarr(1:narrm(idtset),idtset)=dtsets(idtset)%densty(1:narrm(idtset),1)
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'densty','DPR',multivals%ntypat)
dprarr(1,:)=dtsets(:)%dfield(1)
dprarr(2,:)=dtsets(:)%dfield(2)
dprarr(3,:)=dtsets(:)%dfield(3)
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'dfield','DPR',0)
dprarr(1,:)=dtsets(:)%dfpt_sciss
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dfpt_sciss','ENE',0)
dprarr(1,:)=dtsets(:)%diecut
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'diecut','ENE',0)
dprarr(1,:)=dtsets(:)%diegap
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'diegap','ENE',0)
dprarr(1,:)=dtsets(:)%dielam
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dielam','DPR',0)
dprarr(1,:)=dtsets(:)%dielng
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dielng','LEN',0)
dprarr(1,:)=dtsets(:)%diemac
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'diemac','DPR',0)
dprarr(1,:)=dtsets(:)%diemix
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'diemix','DPR',0)
if (any(dtsets(1:ndtset_alloc)%diemixmag/=dtsets(1:ndtset_alloc)%diemix)) then
dprarr(1,:)=dtsets(:)%diemixmag
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'diemixmag','DPR',0)
end if
intarr(1,:)=dtsets(:)%diismemory
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'diismemory','INT',0)
dprarr(1,:)=dtsets(:)%dilatmx
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dilatmx','DPR',0)
intarr(1,:)=dtsets(:)%dipdip
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dipdip','INT',0)
intarr(1,:)=dtsets(:)%dipquad
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dipquad','INT',0)
!dmatpawu
if (dmatpuflag==1.and.mxvals%natpawu>0) then
prtimg(:,:)=1
do idtset=0,ndtset_alloc
mxnsp=max(dtsets(idtset)%nsppol,dtsets(idtset)%nspinor)
lpawu1=maxval(dtsets(idtset)%lpawu(:))
narrm(idtset)=((2*lpawu1+1)**2)*mxnsp*dtsets(idtset)%natpawu
do iimage=1,nimagem(idtset)
if (narrm(idtset)>0) then
dprarr_images(1:narrm(idtset),iimage,idtset)= &
& reshape(dtsets(idtset)%dmatpawu(&
& 1:2*lpawu1+1,1:2*lpawu1+1,1:mxnsp,1:dtsets(idtset)%natpawu,iimage),&
& (/narrm(idtset)/))
end if
end do
end do
call prttagm_images(dprarr_images,iout,jdtset_,5,marr,narrm,&
ncid,ndtset_alloc,'dmatpawu','DPR',mxvals%nimage,nimagem,ndtset,prtimg,strimg)
end if
intarr(1,:)=dtsets(:)%dmatpuopt
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmatpuopt','INT',0)
intarr(1,:)=dtsets(:)%dmatudiag
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmatudiag','INT',0)
intarr(1,:)=dtsets(:)%dmftbandf
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmftbandf','INT',0)
intarr(1,:)=dtsets(:)%dmftbandi
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmftbandi','INT',0)
intarr(1,:)=dtsets(:)%dmftcheck
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmftcheck','INT',0)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_dc','INT',0)
intarr(1,:)=dtsets(:)%dmft_iter
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_iter','INT',0)
! intarr(1,:)=dtsets(:)%dmft_kspectralfunc
! call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_kspectralfunc','INT',0)
dprarr(1,:)=dtsets(:)%dmft_mxsf
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_mxsf','DPR',0)
intarr(1,:)=dtsets(:)%dmft_nwli
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_nwli','INT',0)
intarr(1,:)=dtsets(:)%dmft_nwlo
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_nwlo','INT',0)
intarr(1,:)=dtsets(:)%dmft_occnd_imag
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_occnd_imag','INT',0)
intarr(1,:)=dtsets(:)%dmft_read_occnd
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_read_occnd','INT',0)
intarr(1,:)=dtsets(:)%dmft_rslf
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_rslf','INT',0)
intarr(1,:)=dtsets(:)%dmft_solv
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_solv','INT',0)
dprarr(1,:)=dtsets(:)%dmft_tolfreq
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_tolfreq','DPR',0)
dprarr(1,:)=dtsets(:)%dmft_tollc
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_tollc','DPR',0)
intarr(1,:)=dtsets(:)%dmft_wanorthnorm
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_wanorthnorm','INT',0)
dprarr(1,:)=dtsets(:)%dmft_charge_prec
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'dmft_charge_prec','DPR',0)
dprarr(1,:)=dtsets(:)%dosdeltae
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dosdeltae','ENE',0)
dprarr(1,:)=dtsets(:)%dtion
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dtion','DPR',0,forceprint=2)
intarr(1,:)=dtsets(:)%dvdb_add_lr
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dvdb_add_lr','INT',0)
dprarr(1,:)=dtsets(:)%dvdb_qcache_mb
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dvdb_qcache_mb','DPR',0)
dprarr(1,:)=dtsets(:)%dvdb_qdamp
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dvdb_qdamp','DPR',0)
intarr(1,:)=dtsets(:)%dvdb_rspace_cell
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'dvdb_rspace_cell','INT',0)
!dynimage
intarr(1:marr,0)=1 ! default value
narr=nimage ! default size for all datasets
do idtset=1,ndtset_alloc ! specific size and array for each dataset
narrm(idtset)=dtsets(idtset)%nimage
intarr(1:narrm(idtset),idtset)=dtsets(idtset)%dynimage(1:narrm(idtset))
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'dynimage','INT',multivals%nimage)
!Variables for nonlinear response
intarr(1,:)=dtsets(:)%d3e_pert1_atpol(1)
intarr(2,:)=dtsets(:)%d3e_pert1_atpol(2)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,2,narrm,ncid,ndtset_alloc,'d3e_pert1_atpol','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert1_dir(1)
intarr(2,:)=dtsets(:)%d3e_pert1_dir(2)
intarr(3,:)=dtsets(:)%d3e_pert1_dir(3)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,3,narrm,ncid,ndtset_alloc,'d3e_pert1_dir','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert1_elfd
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'d3e_pert1_elfd','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert1_phon
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'d3e_pert1_phon','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert2_atpol(1)
intarr(2,:)=dtsets(:)%d3e_pert2_atpol(2)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,2,narrm,ncid,ndtset_alloc,'d3e_pert2_atpol','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert2_dir(1)
intarr(2,:)=dtsets(:)%d3e_pert2_dir(2)
intarr(3,:)=dtsets(:)%d3e_pert2_dir(3)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,3,narrm,ncid,ndtset_alloc,'d3e_pert2_dir','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert2_elfd
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'d3e_pert2_elfd','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert2_phon
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'d3e_pert2_phon','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert2_strs
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'d3e_pert2_strs','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert3_atpol(1)
intarr(2,:)=dtsets(:)%d3e_pert3_atpol(2)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,2,narrm,ncid,ndtset_alloc,'d3e_pert3_atpol','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert3_dir(1)
intarr(2,:)=dtsets(:)%d3e_pert3_dir(2)
intarr(3,:)=dtsets(:)%d3e_pert3_dir(3)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,3,narrm,ncid,ndtset_alloc,'d3e_pert3_dir','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert3_elfd
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'d3e_pert3_elfd','INT',0)
intarr(1,:)=dtsets(:)%d3e_pert3_phon
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'d3e_pert3_phon','INT',0)
!###########################################################
!### 03. Print all the input variables (E)
!##
dprarr(1,:)=dtsets(:)%ecut
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'ecut','ENE',0)
dprarr(1,:)=dtsets(:)%ecuteps
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'ecuteps','ENE',0)
dprarr(1,:)=dtsets(:)%ecutsigx
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'ecutsigx','ENE',0)
dprarr(1,:)=dtsets(:)%ecutsm
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'ecutsm','ENE',0)
dprarr(1,:)=dtsets(:)%ecutwfn
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'ecutwfn','ENE',0)
dprarr(1,:)=dtsets(:)%effmass_free
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'effmass_free','DPR',0)
dprarr(1,:)=dtsets(:)%efield(1)
dprarr(2,:)=dtsets(:)%efield(2)
dprarr(3,:)=dtsets(:)%efield(3)
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'efield','DPR',0)
nn = size(dtsets(0)%einterp)
do ii=1,nn
dprarr(ii,:)=dtsets(:)%einterp(ii)
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,nn,narrm,ncid,ndtset_alloc,'einterp','DPR',0)
dprarr(1,:)=dtsets(:)%elph2_imagden
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'elph2_imagden','ENE',0)
intarr(1,:)=dtsets(:)%enunit
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'enunit','INT',0)
dprarr(1,:)=dtsets(:)%eph_ecutosc
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eph_ecutosc','ENE',0)
dprarr(1,:)=dtsets(:)%eph_phwinfact
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eph_phwinfact','DPR',0)
dprarr(1,:)=dtsets(:)%eph_extrael
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eph_extrael','DPR',0)
dprarr(1,:)=dtsets(:)%eph_fermie
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eph_fermie','ENE',0)
intarr(1,:)=dtsets(:)%eph_frohlichm
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'eph_frohlichm','INT',0)
dprarr(1,:)=dtsets(:)%eph_fsewin
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eph_fsewin','ENE',0)
dprarr(1,:)=dtsets(:)%eph_fsmear
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eph_fsmear','ENE',0)
intarr(1,:)=dtsets(:)%eph_intmeth
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'eph_intmeth','INT',0)
dprarr(1,:)=dtsets(:)%eph_mustar
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eph_mustar','DPR',0)
do idtset=0,ndtset_alloc
intarr(1:3,idtset)=dtsets(idtset)%eph_ngqpt_fine
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,3,narrm,ncid,ndtset_alloc,'eph_ngqpt_fine','INT',0)
narr = size(dtsets(0)%eph_np_pqbks)
do idtset=0,ndtset_alloc
intarr(1:narr,idtset) = dtsets(idtset)%eph_np_pqbks
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'eph_np_pqbks','INT',0, firstchar="-")
intarr(1,:)=dtsets(:)%eph_phrange(1)
intarr(2,:)=dtsets(:)%eph_phrange(2)
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,2,narrm,ncid,ndtset_alloc,'eph_phrange','INT',0)
intarr(1,:)=dtsets(:)%eph_restart
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'eph_restart','INT',0)
intarr(1,:)=dtsets(:)%eph_stern
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'eph_stern','INT',0)
intarr(1,:)=dtsets(:)%eph_task
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'eph_task','INT',0)
dprarr(1,:)=dtsets(:)%eph_tols_idelta(1)
dprarr(2,:)=dtsets(:)%eph_tols_idelta(2)
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,2,narrm,ncid,ndtset_alloc,'eph_tols_idelta','DPR',0)
intarr(1,:)=dtsets(:)%eph_transport
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'eph_transport','INT',0)
intarr(1,:)=dtsets(:)%eph_use_ftinterp
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'eph_use_ftinterp','INT',0)
dprarr(1,:)=dtsets(:)%eshift
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'eshift','ENE',0)
dprarr(1,:)=dtsets(:)%esmear
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'esmear','ENE',0)
!etotal
if(choice==2)then
prtimg(:,:)=1
do idtset=0,ndtset_alloc ! specific size for each dataset
compute_static_images=(dtsets(idtset)%istatimg>0)
narrm(idtset)=1
if(dtsets(idtset)%iscf>=0 .or. dtsets(idtset)%iscf==-3)then
do iimage=1,dtsets(idtset)%nimage
if (narrm(idtset)>0) then
dprarr_images(1:narrm(idtset),iimage,idtset)=results_out(idtset)%etotal(iimage)
end if
if(.not.(dtsets(idtset)%dynimage(iimage)==1.or.compute_static_images))then
prtimg(iimage,idtset)=0
end if
end do
else
narrm(idtset)=0
end if
end do
! This is a trick to force printing of etotal even if zero, still not destroying the value of nimagem(0).
tmpimg0=nimagem(0)
nimagem(0)=0
call prttagm_images(dprarr_images,iout,jdtset_,2,marr,narrm,ncid,ndtset_alloc,'etotal','DPR',&
mxvals%nimage,nimagem,ndtset,prtimg,strimg)
nimagem(0)=tmpimg0
end if
dprarr(1,:)=dtsets(:)%exchmix
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'exchmix','DPR',0)
intarr(1,:)=dtsets(:)%exchn2n3d
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'exchn2n3d','INT',0)
intarr(1,:)=dtsets(:)%extrapwf
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'extrapwf','INT',0)
intarr(1,:)=dtsets(:)%expert_user
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'expert_user','INT',0)
!###########################################################
!### 03. Print all the input variables (F)
!##
!fcart
if(choice==2)then
prtimg(:,:)=1
do idtset=0,ndtset_alloc ! specific size for each dataset
compute_static_images=(dtsets(idtset)%istatimg>0)
size2=dtsets(idtset)%natom
if(idtset==0)size2=0
narrm(idtset)=3*size2
if(dtsets(idtset)%iscf>=0 .or. idtset==0)then
do iimage=1,dtsets(idtset)%nimage
if (narrm(idtset)>0) then
dprarr_images(1:narrm(idtset),iimage,idtset)=&
& reshape(results_out(idtset)%fcart(1:3,1:size2,iimage),(/ narrm(idtset) /) )
end if
if(.not.(dtsets(idtset)%dynimage(iimage)==1.or.compute_static_images))then
prtimg(iimage,idtset)=0
end if
end do
else
narrm(idtset)=0
end if
end do
! This is a trick to force printing of fcart even if zero, still not destroying the value of nimagem(0).
tmpimg0=nimagem(0)
nimagem(0)=0
call prttagm_images(dprarr_images,iout,jdtset_,2,marr,narrm,ncid,ndtset_alloc,'fcart','DPR',&
mxvals%nimage,nimagem,ndtset,prtimg,strimg)
nimagem(0)=tmpimg0
end if
dprarr(1,:)=dtsets(:)%fermie_nest
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'fermie_nest','DPR',0)
firstchar_fftalg = "_"
intarr(1,:)=dtsets(:)%ngfft(7)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'fftalg','INT',0,firstchar="-",forceprint=3)
intarr(1,:)=dtsets(:)%ngfft(8)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'fftcache','INT',0)
intarr(1,:)=dtsets(:)%fftgw
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'fftgw','INT',0)
intarr(1,:)=dtsets(:)%fft_count
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'fft_count','INT',0)
intarr(1,:)=dtsets(:)%fockoptmix
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'fockoptmix','INT',0)
dprarr(1,:)=dtsets(:)%focktoldfe
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'focktoldfe','DPR',0)
intarr(1,:)=dtsets(:)%fockdownsampling(1)
intarr(2,:)=dtsets(:)%fockdownsampling(2)
intarr(3,:)=dtsets(:)%fockdownsampling(3)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,3,narrm,ncid,ndtset_alloc,'fockdownsampling','INT',0)
intarr(1,:)=dtsets(:)%fock_icutcoul
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'fock_icutcoul','INT',0)
dprarr(1,:)=dtsets(:)%freqim_alpha
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'freqim_alpha','DPR',0)
dprarr(1,:)=dtsets(:)%freqremax
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'freqremax','ENE',0)
dprarr(1,:)=dtsets(:)%freqremin
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'freqremin','ENE',0)
dprarr(1,:)=dtsets(:)%freqspmax
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'freqspmax','ENE',0)
dprarr(1,:)=dtsets(:)%freqspmin
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'freqspmin','ENE',0)
dprarr(1,:)=dtsets(:)%friction
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'friction','DPR',0)
intarr(1,:)=dtsets(:)%frzfermi
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'frzfermi','INT',0)
dprarr(1,:)=dtsets(:)%fxcartfactor
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'fxcartfactor','DPR',0)
!f4of2_sla
narr=mxvals%ntypat ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%ntypat
if(idtset==0)narrm(idtset)=mxvals%ntypat
if (narrm(idtset)>0) then
dprarr(1:narrm(idtset),idtset)=dtsets(idtset)%f4of2_sla(1:narrm(idtset))
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'f4of2_sla','DPR',multivals%ntypat)
!f6of2_sla
narr=mxvals%ntypat ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%ntypat
if(idtset==0)narrm(idtset)=mxvals%ntypat
if (narrm(idtset)>0) then
dprarr(1:narrm(idtset),idtset)=dtsets(idtset)%f6of2_sla(1:narrm(idtset))
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'f6of2_sla','DPR',multivals%ntypat)
!###########################################################
!### 03. Print all the input variables (G)
!##
intarr(1,:)=dtsets(:)%ga_algor
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'ga_algor','INT',0)
intarr(1,:)=dtsets(:)%ga_fitness
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'ga_fitness','INT',0)
intarr(1,:)=dtsets(:)%ga_n_rules
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'ga_n_rules','INT',0)
dprarr(1,:)=dtsets(:)%ga_opt_percent
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'ga_opt_percent','DPR',0)
!ga_rules
narr=ga_n_rules ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
narrm(idtset)=dtsets(idtset)%ga_n_rules
if(idtset==0)narrm(idtset)=mxvals%ga_n_rules
intarr(1:narrm(idtset),idtset)=dtsets(idtset)%ga_rules(1:narrm(idtset))
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'ga_rules','INT',multivals%ga_n_rules)
intarr(1,:)=dtsets(:)%getbscoup
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getbscoup','INT',0)
intarr(1,:)=dtsets(:)%getbseig
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getbseig','INT',0)
intarr(1,:)=dtsets(:)%getbsreso
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getbsreso','INT',0)
intarr(1,:)=dtsets(:)%getcell
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getcell','INT',0)
intarr(1,:)=dtsets(:)%getddb
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getddb','INT',0)
intarr(1,:)=dtsets(:)%getddk
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getddk','INT',0)
intarr(1,:)=dtsets(:)%getdelfd
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getdelfd','INT',0)
intarr(1,:)=dtsets(:)%getdkdk
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getdkdk','INT',0)
intarr(1,:)=dtsets(:)%getdkde
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getdkde','INT',0)
intarr(1,:)=dtsets(:)%getden
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getden','INT',0)
intarr(1,:)=dtsets(:)%getdvdb
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getdvdb','INT',0)
intarr(1,:)=dtsets(:)%getefmas
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getefmas','INT',0)
intarr(1,:)=dtsets(:)%getgam_eig2nkq
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getgam_eig2nkq','INT',0)
intarr(1,:)=dtsets(:)%gethaydock
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gethaydock','INT',0)
intarr(1,:)=dtsets(:)%getocc
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getocc','INT',0)
intarr(1,:)=dtsets(:)%getpawden
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getpawden','INT',0)
intarr(1,:)=dtsets(:)%getqps
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getqps','INT',0)
intarr(1,:)=dtsets(:)%getscr
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getscr','INT',0)
intarr(1,:)=dtsets(:)%getsuscep
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getsuscep','INT',0)
intarr(1,:)=dtsets(:)%getvel
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getvel','INT',0)
intarr(1,:)=dtsets(:)%getwfk
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getwfk','INT',0)
intarr(1,:)=dtsets(:)%getwfkfine
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getwfkfine','INT',0)
intarr(1,:)=dtsets(:)%getwfq
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getwfq','INT',0)
intarr(1,:)=dtsets(:)%getxcart
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getxcart','INT',0)
intarr(1,:)=dtsets(:)%getxred
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'getxred','INT',0)
intarr(1,:)=dtsets(:)%get1den
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'get1den','INT',0)
intarr(1,:)=dtsets(:)%get1wf
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'get1wf','INT',0)
intarr(1,:)=dtsets(:)%goprecon
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'goprecon','INT',0)
dprarr(1,:)=dtsets(:)%goprecprm(1)
dprarr(2,:)=dtsets(:)%goprecprm(2)
dprarr(3,:)=dtsets(:)%goprecprm(3)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,3,narrm,ncid,ndtset_alloc,'goprecprm','DPR',0)
intarr(1,:)=dtsets(:)%gpu_devices(1) ; intarr(2,:)=dtsets(:)%gpu_devices(2)
intarr(3,:)=dtsets(:)%gpu_devices(3) ; intarr(4,:)=dtsets(:)%gpu_devices(4)
intarr(5,:)=dtsets(:)%gpu_devices(5)
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,5,narrm,ncid,ndtset_alloc,'gpu_devices','INT',0)
intarr(1,:)=dtsets(:)%gpu_linalg_limit
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gpu_linalg_limit','INT',0)
!grchrg
print_constraint=0
do idtset=1,ndtset_alloc
if(any(dtsets(idtset)%constraint_kind(:)>=10))print_constraint=1
enddo
if(print_constraint==1)then
!if(any(dtsets(1:ndtset_alloc)%constraint_kind(:)>=10))then
if(choice==2)then
prtimg(:,:)=1
do idtset=0,ndtset_alloc ! specific size for each dataset
compute_static_images=(dtsets(idtset)%istatimg>0)
size2=dtsets(idtset)%natom
if(idtset==0)size2=0
narrm(idtset)=size2
if(dtsets(idtset)%iscf>=0 .or. idtset==0)then
do iimage=1,dtsets(idtset)%nimage
if (narrm(idtset)>0) then
! Note the minus sign, because chrgat is the ziontypat minus the electronic charge
dprarr_images(1:narrm(idtset),iimage,idtset)=&
& -results_out(idtset)%intgres(1,1:size2,iimage)
end if
if(.not.(dtsets(idtset)%dynimage(iimage)==1.or.compute_static_images))then
prtimg(iimage,idtset)=0
end if
end do
else
narrm(idtset)=0
end if
end do
! This is a trick to force printing of fcart even if zero, still not destroying the value of nimagem(0).
tmpimg0=nimagem(0)
nimagem(0)=0
call prttagm_images(dprarr_images,iout,jdtset_,1,marr,narrm,ncid,ndtset_alloc,'grchrg','DPR',&
mxvals%nimage,nimagem,ndtset,prtimg,strimg)
nimagem(0)=tmpimg0
end if
endif
!grspin
print_constraint=0
do idtset=1,ndtset_alloc
if(any(mod(dtsets(idtset)%constraint_kind(:),10)>0))print_constraint=1
enddo
if(print_constraint==1)then
!if(any(mod(dtsets(1:ndtset_alloc)%constraint_kind(:),10)/=0))then
if(choice==2)then
prtimg(:,:)=1
do idtset=0,ndtset_alloc ! specific size for each dataset
compute_static_images=(dtsets(idtset)%istatimg>0)
size2=dtsets(idtset)%natom
if(idtset==0)size2=0
narrm(idtset)=3*size2
if(dtsets(idtset)%iscf>=0 .or. idtset==0)then
do iimage=1,dtsets(idtset)%nimage
if (narrm(idtset)>0) then
dprarr_images(1:narrm(idtset),iimage,idtset)=&
& reshape(results_out(idtset)%intgres(2:4,1:size2,iimage),(/ narrm(idtset) /) )
end if
if(.not.(dtsets(idtset)%dynimage(iimage)==1.or.compute_static_images))then
prtimg(iimage,idtset)=0
end if
end do
else
narrm(idtset)=0
end if
end do
! This is a trick to force printing of fcart even if zero, still not destroying the value of nimagem(0).
tmpimg0=nimagem(0)
nimagem(0)=0
call prttagm_images(dprarr_images,iout,jdtset_,2,marr,narrm,ncid,ndtset_alloc,'grspin','DPR',&
mxvals%nimage,nimagem,ndtset,prtimg,strimg)
nimagem(0)=tmpimg0
end if
endif
intarr(1,:)=dtsets(:)%gwaclowrank
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwaclowrank','INT',0)
intarr(1,:)=dtsets(:)%gwcalctyp
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwcalctyp','INT',0)
intarr(1,:)=dtsets(:)%gw1rdm
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw1rdm','INT',0)
intarr(1,:)=dtsets(:)%gwcomp
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwcomp','INT',0)
dprarr(1,:)=dtsets(:)%gwencomp
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwencomp','ENE',0)
intarr(1,:)=dtsets(:)%gwgamma
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwgamma','INT',0)
intarr(1,:)=dtsets(:)%gwmem
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwmem','INT',0)
intarr(1,:)=dtsets(:)%gwpara
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwpara','INT',0, firstchar="-")
intarr(1,:)=dtsets(:)%gwrpacorr
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwrpacorr','INT',0)
intarr(1,:)=dtsets(:)%gwgmcorr
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gwgmcorr','INT',0)
!gw_customnfreqsp
!It actually overrides the content of nfreqsp (which is forbidden !) in dtset.
!This is to be cleaned ...
if (ANY(dtsets(:)%gw_customnfreqsp/=0)) then
intarr(1,:)=dtsets(:)%gw_customnfreqsp
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_customnfreqsp','INT',0)
end if
!gw_freqsp
!This is to be cleaned ... See above ...
narr=mxvals%nfreqsp ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
dprarr(1:narr,idtset)=zero
narrm(idtset)=dtsets(idtset)%gw_customnfreqsp
if(idtset==0)narrm(idtset)=mxvals%nfreqsp
if (narrm(idtset)>0) then
dprarr(1:narrm(idtset),idtset)=dtsets(idtset)%gw_freqsp(1:narrm(idtset))
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,6,marr,narr,narrm,ncid,ndtset_alloc,'gw_freqsp','ENE',multivals%nfreqsp)
intarr(1,:)=dtsets(:)%gw_frqim_inzgrid
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_frqim_inzgrid','INT',0)
intarr(1,:)=dtsets(:)%gw_frqre_inzgrid
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_frqre_inzgrid','INT',0)
intarr(1,:)=dtsets(:)%gw_frqre_tangrid
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_frqre_tangrid','INT',0)
intarr(1,:)=dtsets(:)%gw_invalid_freq
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_invalid_freq','INT',0)
intarr(1,:)=dtsets(:)%gw_qprange
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_qprange','INT',0)
intarr(1,:)=dtsets(:)%gw_nqlwl
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_nqlwl','INT',0)
intarr(1,:)=dtsets(:)%gw_nstep
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_nstep','INT',0)
!gw_qlwl
narr=3*dtsets(1)%gw_nqlwl ! default size for all datasets
do idtset=0,ndtset_alloc ! specific size for each dataset
if(idtset/=0)then
narrm(idtset)=3*dtsets(idtset)%gw_nqlwl
if (narrm(idtset)>0)then
dprarr(1:narrm(idtset),idtset)=&
& reshape(dtsets(idtset)%gw_qlwl(1:3,1:dtsets(idtset)%gw_nqlwl),(/ narrm(idtset) /) )
end if
else
narrm(idtset)=3*mxvals%gw_nqlwl
if (narrm(idtset)>0)then
dprarr(1:narrm(idtset),idtset)=zero
dprarr(1:3,idtset)=(/0.00001_dp, 0.00002_dp, 0.00003_dp/)
end if
end if
end do
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,narr,narrm,ncid,ndtset_alloc,'gw_qlwl','DPR',multivals%gw_nqlwl)
intarr(1,:)=dtsets(:)%gw_sctype
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_sctype','INT',0)
intarr(1,:)=dtsets(:)%gw_sigxcore
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_sigxcore','INT',0)
intarr(1,:)=dtsets(:)%gw_icutcoul
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'gw_icutcoul','INT',0)
dprarr(1,:)=dtsets(:)%gw_toldfeig
call prttagm(dprarr,intarr,iout,jdtset_,1,marr,1,narrm,ncid,ndtset_alloc,'gw_toldfeig','ENE',0)
intarr(1,:)=dtsets(:)%hmcsst
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'hmcsst','INT',0)
intarr(1,:)=dtsets(:)%hmctt
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'hmctt','INT',0)
intarr(1,:)=dtsets(:)%extfpmd_nbcut
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,'extfpmd_nbcut','INT',0)
!Special treatment of the default values for the hybrid functional parameters.
do ii=1,4
if(ii==1)dprarr(1,:)=dtsets(:)%hyb_mixing
if(ii==2)dprarr(1,:)=dtsets(:)%hyb_mixing_sr
if(ii==3)dprarr(1,:)=dtsets(:)%hyb_range_dft
if(ii==4)dprarr(1,:)=dtsets(:)%hyb_range_fock
defo=1
do idtset=1,ndtset_alloc
if(dprarr(1,idtset)<-tol8 .and. abs(dprarr(1,idtset)+999.0_dp)>tol8)defo=0
end do
if(defo==0)then
do idtset=1,ndtset_alloc
! Change the sign of user defined input value
if(dprarr(1,idtset)<-tol8 .and. abs(dprarr(1,idtset)+999.0_dp)>tol8)then
dprarr(1,idtset)=abs(dprarr(1,idtset))
end if
end do
if(ii==1)str_hyb='hyb_mixing'
if(ii==2)str_hyb='hyb_mixing_sr'
if(ii==3)str_hyb='hyb_range_dft'
if(ii==4)str_hyb='hyb_range_fock'
call prttagm(dprarr,intarr,iout,jdtset_,2,marr,1,narrm,ncid,ndtset_alloc,str_hyb,'DPR',0)
end if
end do
!###########################################################
!## Deallocation for generic arrays, and for n-z variables
ABI_FREE(dprarr)
ABI_FREE(intarr)
ABI_FREE(narrm)
ABI_FREE(nimagem)
ABI_FREE(dprarr_images)
ABI_FREE(prtimg)
end subroutine outvar_a_h
!!***
end module m_outvar_a_h
!!***
| gpl-3.0 |
kellerroman/RUFS | src/control.F90 | 1 | 1968 | module control
use const
implicit none
save
public
!!! CONFIG VARIABLES FROM INPUT FILE
integer :: space_Order,space_disc
character ( len = len_str_filename ):: file_cfg_in = "config.bin"
!<
character ( len = len_str_filename ):: file_git_in = "git.bin"
!<
character ( len = len_str_filename ):: file_bc_in = "bc.bin"
!<
character ( len = len_str_filename ):: file_sol_out = "sol.bin"
!<
character ( len = len_str_filename ):: file_ani_out = "ani.bin"
!<
integer :: control_num_iteration
integer :: control_sol_out
integer :: control_res_out
integer :: control_bc_cells_out
!< defines if bc_cells are outputtet to sol file
!< 0: not outputted
!< 1: outputted
integer :: control_dimension
!< Gibt die Art der Simulation an
!< 1 : 2D Simulation
!< 2 : 2D Rotationssymmetrisch e Simulation
!< 3 : 3D Simulation
integer :: control_riemann_solver
!< Gibt die Riemann Löser an
!< 1 : RHLL
!< 2 : Roe
!< 3 : AUSM
real(kind=dp) :: control_CFL
real(kind=dp) :: control_timestep
integer :: control_equation
!< Gibt das Physikalische Modell an:
!< 1: Euler - Gleichung
!< 2: Navier-Stokes
!< [ 3: Wärmeleitung ]
integer :: control_dt_method
!< Gibt an wie der Zeitschritt berechnet wird:
!< 1: Es wird ein vorgegebener Zeitschritt verwendet
!< 2: Es wird mittels einer CFL Nummer ein Lokaler Zeitschritt in jeder Zelle berechnet
!< 3: Es wird mittels einer CFL Nummer ein Lokaler Zeitschritt in jeder Zelle berechnet,
!< und alle Zellen verwenden den kleinsten Zeitschritt aller Zellen
!!! CALCULATED VARIABLES
integer :: n_BC_Cells
integer :: nVar
!< Anzahl der Variablen im Variablenvektor Q
integer :: sol_out_nVar
!< Anzahl der Variablen in der Ausgabedatei
end module control
| mit |
abinit/abinit | src/71_bse/m_haydock.F90 | 1 | 81928 | !!****m* ABINIT/m_haydock
!! NAME
!! m_haydock
!!
!! FUNCTION
!!
!! COPYRIGHT
!! Copyright (C) 2008-2021 ABINIT group (M.Giantomassi, Y. Gillet, L.Reining, V.Olevano, F.Sottile, S.Albrecht, G.Onida)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! PARENTS
!!
!! CHILDREN
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
MODULE m_haydock
use defs_basis
use m_abicore
use m_bs_defs
use m_xmpi
use m_errors
use m_nctk
use m_haydock_io
use m_linalg_interfaces
use m_ebands
use m_hdr
#ifdef HAVE_NETCDF
use netcdf
#endif
use m_time, only : timab
use m_fstrings, only : strcat, sjoin, itoa, int2char4
use m_io_tools, only : file_exists, open_file
use defs_datatypes, only : ebands_t, pseudopotential_type
use m_geometry, only : normv
use m_hide_blas, only : xdotc, xgemv
use m_hide_lapack, only : matrginv
use m_numeric_tools, only : print_arr, symmetrize, hermitianize, continued_fract, wrap2_pmhalf, iseven
use m_kpts, only : listkk
use m_crystal, only : crystal_t
use m_bz_mesh, only : kmesh_t, findqg0, get_bz_item
use m_double_grid, only : double_grid_t, get_kpt_from_indices_coarse, compute_corresp
use m_paw_hr, only : pawhur_t
use m_wfd, only : wfd_t
use m_bse_io, only : exc_write_optme
use m_pawtab, only : pawtab_type
use m_vcoul, only : vcoul_t
use m_hexc, only : hexc_init, hexc_interp_init, hexc_free, hexc_interp_free, &
& hexc_build_hinterp, hexc_matmul_tda, hexc_matmul_full, hexc_t, hexc_matmul_elphon, hexc_interp_t
use m_exc_spectra, only : exc_write_data, exc_eps_rpa, exc_write_tensor, mdfs_ncwrite
use m_eprenorms, only : eprenorms_t, renorm_bst
use m_wfd_optic, only : calc_optical_mels
implicit none
private
!!***
public :: exc_haydock_driver ! Driver for the Haydock method (main entry point for client code).
CONTAINS !=======================================================================
!!***
!!****f* m_haydock/exc_haydock_driver
!! NAME
!! exc_haydock_driver
!!
!! FUNCTION
!! Calculate the imaginary part of the macroscopic dielectric function with the Haydock recursive method.
!!
!! INPUTS
!! BSp<type(excparam)=The parameter for the Bethe-Salpeter run.
!! BS_files<excparam>=Files associated to the bethe_salpeter code.
!! Cryst<crystal_t>=Info on the crystalline structure.
!! Kmesh<type(kmesh_t)>=The list of k-points in the BZ, IBZ and symmetry tables.
!! Cryst<type(crystal_t)>=Info on the crystalline structure.
!! Hdr_bse
!! KS_BSt=The KS energies.
!! QP_BSt=The QP energies.
!! Wfd<wfd_t>=Wavefunction descriptor (input k-mesh)
!! Psps <type(pseudopotential_type)>=variables related to pseudopotentials.
!! Pawtab(Cryst%ntypat*usepaw)<pawtab_type>=PAW tabulated starting data.
!! Hur(Cryst%natom*usepaw)<type(pawhur_t)>=Only for PAW and DFT+U, quantities used to evaluate the commutator [H_u,r].
!!
!! OUTPUT
!! The imaginary part of the macroscopic dielectric function is written on the external file _EXC_MDF
!!
!! PARENTS
!! m_bethe_salpeter
!!
!! CHILDREN
!!
!! SOURCE
subroutine exc_haydock_driver(BSp,BS_files,Cryst,Kmesh,Hdr_bse,KS_BSt,QP_Bst,Wfd,Psps,Pawtab,Hur,Epren,&
& Kmesh_dense, KS_BSt_dense, QP_BSt_dense, Wfd_dense, Vcp_dense, grid)
!Arguments ------------------------------------
!scalars
type(excparam),intent(in) :: BSp
type(excfiles),intent(in) :: BS_files
type(kmesh_t),intent(in) :: Kmesh
type(crystal_t),intent(in) :: Cryst
type(Hdr_type),intent(in) :: Hdr_bse
type(wfd_t),intent(inout) :: Wfd
type(pseudopotential_type),intent(in) :: Psps
type(ebands_t),intent(in) :: KS_BSt,QP_Bst
type(double_grid_t),intent(in),optional :: grid
type(kmesh_t),intent(in),optional :: Kmesh_dense
type(wfd_t),intent(inout),optional :: Wfd_dense
type(ebands_t),intent(in),optional :: KS_BSt_dense, QP_Bst_dense
type(vcoul_t),intent(in),optional :: Vcp_dense
type(eprenorms_t),intent(in) :: Epren
!arrays
type(pawtab_type),intent(in) :: Pawtab(Cryst%ntypat*Wfd%usepaw)
type(pawhur_t),intent(in) :: Hur(Cryst%natom*Wfd%usepaw)
!Local variables ------------------------------
!scalars
integer,parameter :: master=0
integer :: io,my_rank,iq,itt,ierr
integer :: hsize,comm,my_t1,my_t2,nsppol,nkets,nproc,ncid
integer :: spin,spad,ik_bz,iv,ic,trans_idx,lomo_min,max_band
real(dp) :: omegaev,rand_phi !,norm
complex(dpc) :: ks_avg,gw_avg,exc_avg
logical :: use_mpio,prtdos
character(len=500) :: msg
type(hexc_t) :: hexc
type(hexc_interp_t) :: hexc_i
!arrays
real(dp) :: tsec(2)
real(dp),allocatable :: dos(:),dos_gw(:),dos_ks(:)
complex(dpc),allocatable :: green(:,:)
complex(dpc),allocatable :: opt_cvk(:,:,:,:,:),kets(:,:)
complex(dpc),allocatable :: eps_rpanlf(:,:),eps_gwnlf(:,:)
complex(dpc),allocatable :: tensor_cart(:,:),tensor_cart_rpanlf(:,:),tensor_cart_gwnlf(:,:)
complex(dpc),allocatable :: tensor_red(:,:),tensor_red_rpanlf(:,:),tensor_red_gwnlf(:,:)
!Temperature
real(dp) :: dksqmax, en
integer,allocatable :: bs2eph(:,:)
integer :: sppoldbl, timrev
logical :: do_ep_renorm, do_ep_lifetime
integer :: ntemp
character(len=4) :: ts
character(len=fnlen) :: prefix
character(len=fnlen) :: path
complex(dpc),allocatable :: ep_renorms(:)
integer :: ep_ik, ik, ireh, isppol
integer :: itemp
type(ebands_t) :: EPBSt, EP_QPBSt
!************************************************************************
call timab(690,1,tsec) ! exc_haydock_driver
call timab(691,1,tsec) ! exc_haydock_driver(read)
if (BSp%have_complex_ene) then
ABI_ERROR("Complex energies are not supported yet")
end if
my_rank = Wfd%my_rank
comm = Wfd%comm
nsppol = Wfd%nsppol
nproc = Wfd%nproc
use_mpio=.FALSE.
#ifdef HAVE_MPI_IO
use_mpio = (nproc > 1)
!use_mpio = .TRUE.
#endif
use_mpio=.FALSE.
!use_mpio = .TRUE.
! Hsize refers to the size of the individual blocks (resonant and coupling).
! Thanks to the symmetry property of the starting vector, the Haydock method
! can be reformulated in terms of matrix-vector multiplication involving the
! blocks thus avoiding to allocation of the full matrix ( R C )
! -C* -R*)
hsize=SUM(BSp%nreh)
!YG2014
call hexc_init(hexc, BSp, BS_files, Cryst, Kmesh, Wfd, KS_BSt, QP_BSt, comm)
!YG2014
if(BSp%use_interp) then
call hexc_interp_init(hexc_i, hexc, BSp%interp_m3_width, BSp%interp_method,&
& Kmesh_dense, Vcp_dense, grid, Wfd_dense, &
& KS_BSt_dense, QP_BSt_dense, Psps, Pawtab)
end if
call timab(691,2,tsec) ! exc_haydock_driver(read)
call timab(692,1,tsec) ! exc_haydock_driver(prep)
!
! Prepare the starting vectors for the Lanczos chain.
nkets=Bsp%nq
prtdos=.FALSE. !prtdos=.TRUE.
if (prtdos) then
nkets=nkets+1
if (Bsp%use_coupling>0) then
ABI_ERROR("DOS with coupling not coded")
nkets=nkets+1
end if
end if
!YG2014
ABI_MALLOC_OR_DIE(kets,(hexc%hsize,nkets), ierr)
kets=czero
!
! Prepare the kets for the macroscopic dielectric function.
lomo_min=Bsp%lomo_min; max_band=Bsp%nbnds
!YG2014
ABI_MALLOC_OR_DIE(opt_cvk,(lomo_min:max_band,lomo_min:max_band,hexc%nbz,Wfd%nsppol,BSp%nq), ierr)
do iq=1,Bsp%nq
! Note KS_BSt is used here to calculate the commutator.
call calc_optical_mels(hexc%Wfd,hexc%Kmesh,hexc%KS_BSt,Cryst,Psps,Pawtab,Hur, &
& BSp%inclvkb,BSp%lomo_spin,lomo_min,max_band,hexc%nbz,BSp%q(:,iq),opt_cvk(:,:,:,:,iq))
! Fill ket0 using the same ordering for the indeces as the one used for the excitonic Hamiltonian.
! Note that only the resonant part is used here.
do spin=1,nsppol
if(BSp%use_interp) then
spad=(spin-1)*BSp%nreh_interp(spin)
else
spad=(spin-1)*BSp%nreh(spin)
end if
do ik_bz=1,hexc%nbz
do iv=BSp%lomo_spin(spin),BSp%homo_spin(spin)
do ic=BSp%lumo_spin(spin),BSp%nbnds
if(BSp%use_interp) then
trans_idx = BSp%vcks2t_interp(iv,ic,ik_bz,spin)
else
trans_idx = BSp%vcks2t(iv,ic,ik_bz,spin)
end if
if (trans_idx>0) kets(trans_idx+spad,iq)=opt_cvk(ic,iv,ik_bz,spin,iq)
end do
end do
end do
end do
end do
!
! ========================================================
! === Write the Optical Matrix Elements to NetCDF file ===
! ========================================================
!if (.false.) then
! ome_fname='test_OME.nc'
! call exc_write_optme(ome_fname,minb,maxb,BSp%nkbz,Wfd%nsppol,BSp%nq,opt_cvk,ierr)
!end if
! Free WFD descriptor, we don't need ur and ug anymore !
! We make space for interpolated hamiltonian
call wfd%wave_free("All")
if(BSp%use_interp) call wfd_dense%wave_free("All")
! Build interpolated hamiltonian
if(BSp%use_interp) then
if (any(BSp%interp_mode == [2,3,4])) then
call hexc_build_hinterp(hexc, hexc_i)
end if
end if
call timab(692,2,tsec) ! exc_haydock_driver(prep)
call timab(693,1,tsec) ! exc_haydock_driver(wo lf) - that is, without local field
do_ep_renorm = .FALSE.
ntemp = 1
do_ep_lifetime = .FALSE.
if(BSp%do_ep_renorm) then
if (BSp%nsppol == 2) then
ABI_ERROR('Elphon renorm with nsppol == 2 not yet coded !')
end if
do_ep_renorm = .TRUE.
ntemp = Epren%ntemp
if(BSp%do_lifetime) then
do_ep_lifetime = .TRUE.
end if
! Force elphon linewidth
do_ep_lifetime = .TRUE.
! Map points from BSE to elphon kpoints
sppoldbl = 1 !; if (any(Cryst%symafm == -1) .and. Epren%nsppol == 1) nsppoldbl=2
ABI_MALLOC(bs2eph, (Kmesh%nbz*sppoldbl, 6))
ABI_MALLOC(ep_renorms, (hsize))
timrev = 1
call listkk(dksqmax, Cryst%gmet, bs2eph, Epren%kpts, Kmesh%bz, Epren%nkpt, Kmesh%nbz, Cryst%nsym, &
sppoldbl, Cryst%symafm, Cryst%symrel, timrev, comm, use_symrec=.False.)
end if
call timab(693,2,tsec) ! exc_haydock_driver(wo lf - that is, without local field
call timab(694,1,tsec) ! exc_haydock_driver(apply
prefix = ""
do itemp = 1, ntemp
call ebands_copy(hexc%KS_BSt, EPBSt)
call ebands_copy(hexc%QP_BSt, EP_QPBSt)
! =================================================
! == Calculate elphon vector in transition space ==
! =================================================
if (do_ep_renorm) then
! Will perform elphon renormalization for itemp
call int2char4(itemp,ts)
prefix = TRIM("_T") // ts
! No scissor with KSBST
call renorm_bst(Epren, EPBSt, Cryst, itemp, do_lifetime=.TRUE.,do_check=.TRUE.)
call renorm_bst(Epren, EP_QPBSt, Cryst, itemp, do_lifetime=.TRUE.,do_check=.FALSE.)
do isppol = 1, BSp%nsppol
do ireh = 1, BSp%nreh(isppol)
ic = BSp%Trans(ireh,isppol)%c
iv = BSp%Trans(ireh,isppol)%v
ik = BSp%Trans(ireh,isppol)%k ! In the full bz
en = BSp%Trans(ireh,isppol)%en
ep_ik = bs2eph(ik,1)
!TODO support multiple spins !
if(ABS(en - (Epren%eigens(ic,ep_ik,isppol)-Epren%eigens(iv,ep_ik,isppol)+BSp%mbpt_sciss)) > tol3) then
ABI_ERROR("Eigen from the transition does not correspond to the EP file !")
end if
ep_renorms(ireh) = (Epren%renorms(1,ic,ik,isppol,itemp) - Epren%renorms(1,iv,ik,isppol,itemp))
! Add linewith
if(do_ep_lifetime) then
ep_renorms(ireh) = ep_renorms(ireh) - j_dpc*(Epren%linewidth(1,ic,ik,isppol,itemp) +&
& Epren%linewidth(1,iv,ik,isppol,itemp))
end if
end do
end do
end if
! =======================================================
! === Make EPS RPA and GW without local-field effects ===
! =======================================================
ABI_MALLOC(eps_rpanlf,(BSp%nomega,BSp%nq))
ABI_MALLOC(dos_ks,(BSp%nomega))
ABI_MALLOC(eps_gwnlf ,(BSp%nomega,BSp%nq))
ABI_MALLOC(dos_gw,(BSp%nomega))
call wrtout(std_out," Calculating RPA NLF and QP NLF epsilon","COLL")
call exc_eps_rpa(BSp%nbnds,BSp%lomo_spin,BSp%lomo_min,BSp%homo_spin,hexc%Kmesh,EPBSt,BSp%nq,nsppol,&
& opt_cvk,Cryst%ucvol,BSp%broad,BSp%nomega,BSp%omega,eps_rpanlf,dos_ks)
call exc_eps_rpa(BSp%nbnds,BSp%lomo_spin,BSp%lomo_min,BSp%homo_spin,hexc%Kmesh,EP_QPBSt,BSp%nq,nsppol,&
& opt_cvk,Cryst%ucvol,Bsp%broad,BSp%nomega,BSp%omega,eps_gwnlf,dos_gw)
if (my_rank==master) then ! Only master works.
!
! Master node writes final results on file.
call exc_write_data(BSp,BS_files,"RPA_NLF_MDF",eps_rpanlf,prefix=prefix,dos=dos_ks)
call exc_write_data(BSp,BS_files,"GW_NLF_MDF",eps_gwnlf,prefix=prefix,dos=dos_gw)
! Computing and writing tensor in files
! RPA_NLF
ABI_MALLOC(tensor_cart_rpanlf,(BSp%nomega,6))
ABI_MALLOC(tensor_red_rpanlf,(BSp%nomega,6))
call wrtout(std_out," Calculating RPA NLF dielectric tensor","COLL")
call haydock_mdf_to_tensor(BSp,Cryst,eps_rpanlf,tensor_cart_rpanlf, tensor_red_rpanlf, ierr)
if(ierr == 0) then
! Writing tensor
call exc_write_tensor(BSp,BS_files,"RPA_NLF_TSR_CART",tensor_cart_rpanlf)
call exc_write_tensor(BSp,BS_files,"RPA_NLF_TSR_RED",tensor_red_rpanlf)
else
write(msg,'(3a)')&
& 'The RPA_NLF dielectric complex tensor cannot be computed',ch10,&
& 'There must be 6 different q-points in long wavelength limit (see gw_nqlwl)'
ABI_COMMENT(msg)
end if
ABI_FREE(tensor_cart_rpanlf)
ABI_FREE(tensor_red_rpanlf)
! GW_NLF
ABI_MALLOC(tensor_cart_gwnlf,(BSp%nomega,6))
ABI_MALLOC(tensor_red_gwnlf,(BSp%nomega,6))
call wrtout(std_out," Calculating GW NLF dielectric tensor","COLL")
call haydock_mdf_to_tensor(BSp,Cryst,eps_gwnlf,tensor_cart_gwnlf, tensor_red_gwnlf, ierr)
if(ierr == 0) then
! Writing tensor
call exc_write_tensor(BSp,BS_files,"GW_NLF_TSR_CART",tensor_cart_gwnlf)
call exc_write_tensor(BSp,BS_files,"GW_NLF_TSR_RED",tensor_red_gwnlf)
else
write(msg,'(3a)')&
& 'The GW_NLF dielectric complex tensor cannot be computed',ch10,&
& 'There must be 6 different q-points in long wavelength limit (see gw_nqlwl)'
ABI_COMMENT(msg)
end if
ABI_FREE(tensor_cart_gwnlf)
ABI_FREE(tensor_red_gwnlf)
!call wrtout(std_out," Checking Kramers Kronig on Excitonic Macroscopic Epsilon","COLL")
!call check_kramerskronig(BSp%nomega,REAL(BSp%omega),eps_exc(:,1))
!call wrtout(std_out," Checking Kramers Kronig on RPA NLF Macroscopic Epsilon","COLL")
!call check_kramerskronig(BSp%nomega,REAL(BSp%omega),eps_rpanlf(:,1))
!call wrtout(std_out," Checking Kramers Kronig on GW NLF Macroscopic Epsilon","COLL")
!call check_kramerskronig(BSp%nomega,REAL(BSp%omega),eps_gwnlf(:,1))
!call wrtout(std_out," Checking f-sum rule on Excitonic Macroscopic Epsilon","COLL")
!if (BSp%exchange_term>0) then
! ABI_COMMENT(' f-sum rule should be checked without LF')
!end if
!call check_fsumrule(BSp%nomega,REAL(BSp%omega),AIMAG(eps_exc(:,1)),drude_plsmf)
!call wrtout(std_out," Checking f-sum rule on RPA NLF Macroscopic Epsilon","COLL")
!call check_fsumrule(BSp%nomega,REAL(BSp%omega),AIMAG(eps_rpanlf(:,1)),drude_plsmf)
!call wrtout(std_out," Checking f-sum rule on GW NLF Macroscopic Epsilon","COLL")
!call check_fsumrule(BSp%nomega,REAL(BSp%omega),AIMAG(eps_gwnlf(:,1)),drude_plsmf)
end if ! my_rank==master
!call xmpi_barrier(comm)
!
! The ket for the approximated DOS.
if (prtdos) then
ABI_WARNING("Calculating DOS with Haydock method")
ABI_CHECK(BSp%use_coupling==0,"DOS with coupling not coded")
iq = BSp%nq + 1
if (my_rank==master) then
!call random_seed()
do itt=1,SUM(Bsp%nreh)
call RANDOM_NUMBER(rand_phi)
rand_phi = two_pi*rand_phi
kets(itt,iq) = CMPLX( COS(rand_phi), SIN(rand_phi) )
end do
! Normalize the vector.
!norm = SQRT( DOT_PRODUCT(kets(:,iq), kets(:,iq)) )
!kets(:,iq) = kets(:,iq)/norm
end if
call xmpi_bcast(kets(:,iq),master,comm,ierr)
end if
ABI_MALLOC(green,(BSp%nomega,nkets))
if (BSp%use_coupling==0) then
if(do_ep_renorm) then
call haydock_bilanczos(BSp,BS_files,Cryst,Hdr_bse,hexc,hexc_i,hsize,hexc%my_t1,hexc%my_t2,nkets,kets,ep_renorms,green,comm)
else
!YG2014
call haydock_herm(BSp,BS_files,Cryst,Hdr_bse,hexc%my_t1,hexc%my_t2,&
& nkets,kets,green,hexc,hexc_i,comm)
end if
else
if (BSp%use_interp) then
ABI_ERROR("BSE Interpolation with coupling is not supported")
else
call haydock_psherm(BSp,BS_files,Cryst,Hdr_bse,hexc,hexc_i,hsize,my_t1,my_t2,nkets,kets,green,comm)
end if
end if
!
! Add 1 to have the real part right.
green = one + green
if (my_rank==master) then ! Master writes the final results.
!
if (prtdos) then
ABI_MALLOC(dos,(BSp%nomega))
dos = -AIMAG(green(:,BSp%nq+1))
call exc_write_data(BSp,BS_files,"EXC_MDF",green,prefix=prefix,dos=dos)
ABI_FREE(dos)
else
call exc_write_data(BSp,BS_files,"EXC_MDF",green,prefix=prefix)
end if
!
! =========================
! === Write out Epsilon ===
! =========================
ABI_MALLOC(tensor_cart,(BSp%nomega,6))
ABI_MALLOC(tensor_red,(BSp%nomega,6))
call wrtout(std_out," Calculating EXC dielectric tensor","COLL")
call haydock_mdf_to_tensor(BSp,Cryst,green,tensor_cart,tensor_red,ierr)
if (ierr == 0) then
! Writing tensor
call exc_write_tensor(BSp,BS_files,"EXC_TSR_CART",tensor_cart)
call exc_write_tensor(BSp,BS_files,"EXC_TSR_RED",tensor_red)
else
write(msg,'(3a)')&
& 'The EXC dielectric complex tensor cannot be computed',ch10,&
& 'There must be 6 different q-points in long wavelength limit (see gw_nqlwl)'
ABI_COMMENT(msg)
end if
ABI_FREE(tensor_cart)
ABI_FREE(tensor_red)
!
! This part will be removed when fldiff will be able to compare two mdf files.
write(ab_out,*)" "
write(ab_out,*)"Macroscopic dielectric function:"
write(ab_out,*)"omega [eV] <KS_RPA_nlf> <GW_RPA_nlf> <BSE> "
do io=1,MIN(BSp%nomega,10)
omegaev = REAL(BSp%omega(io))*Ha_eV
ks_avg = SUM( eps_rpanlf(io,:)) / Bsp%nq
gw_avg = SUM( eps_gwnlf (io,:)) / Bsp%nq
exc_avg = SUM( green (io,:)) / BSp%nq
write(ab_out,'(7f9.4)')omegaev,ks_avg,gw_avg,exc_avg
end do
write(ab_out,*)" "
! Write MDF file with the final results.
! FIXME: It won't work if prtdos == True
#ifdef HAVE_NETCDF
path = strcat(BS_files%out_basename,strcat(prefix,"_MDF.nc"))
NCF_CHECK(nctk_open_create(ncid, path, xmpi_comm_self))
NCF_CHECK(cryst%ncwrite(ncid))
NCF_CHECK(ebands_ncwrite(QP_bst, ncid))
call mdfs_ncwrite(ncid, Bsp, green, eps_rpanlf, eps_gwnlf)
NCF_CHECK(nf90_close(ncid))
#else
ABI_UNUSED(ncid)
#endif
end if
ABI_FREE(green)
ABI_FREE(eps_rpanlf)
ABI_FREE(eps_gwnlf)
ABI_FREE(dos_ks)
ABI_FREE(dos_gw)
call ebands_free(EPBSt)
call ebands_free(EP_QPBst)
end do ! itemp loop
ABI_FREE(opt_cvk)
ABI_FREE(kets)
call timab(694,2,tsec) ! exc_haydock_driver(apply
call timab(695,1,tsec) ! exc_haydock_driver(end)
!YG2014
call hexc_free(hexc)
call hexc_interp_free(hexc_i)
if (do_ep_renorm) then
ABI_FREE(ep_renorms)
ABI_FREE(bs2eph)
end if
call timab(695,2,tsec) ! exc_haydock_driver(end)
call timab(690,2,tsec) ! exc_haydock_driver
end subroutine exc_haydock_driver
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_herm
!! NAME
!! haydock_herm
!!
!! FUNCTION
!! Reads the excitonic Hamiltonian from file and construct the Lanczos set of vectors
!! by iterative matrix-vector multiplications.
!!
!! INPUTS
!! BSp<excparam>=Parameters for the Bethe-Salpeter calculation.
!! BS_files<excparam>=Files associated to the bethe_salpeter code.
!! Cryst<crystal_t>=Info on the crystalline structure.
!! Pawtab(Cryst%ntypat*usepaw)<pawtab_type>=PAW tabulated starting data.
!! hize=Size of the excitonic matrix.
!! my_t1,my_t2=First and last columns treated by this node.
!! nkets=Number of starting vectors for Haydock method.
!! kets(hsize,nkets)=The kets in the eh representation.
!! comm=MPI communicator.
!!
!! OUTPUT
!! green(BSp%nomega,nkets)=
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_herm(BSp,BS_files,Cryst,Hdr_bse,my_t1,my_t2,&
& nkets,kets,green,hexc,hexc_i,comm)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: my_t1,my_t2,nkets,comm
type(crystal_t),intent(in) :: Cryst
type(excparam),intent(in) :: BSp
type(excfiles),intent(in) :: BS_files
type(Hdr_type),intent(in) :: Hdr_bse
type(hexc_t),intent(inout) :: hexc
type(hexc_interp_t),intent(inout) :: hexc_i
!arrays
complex(dp),intent(out) :: green(BSp%nomega,nkets)
complex(dpc),intent(in) :: kets(hexc%hsize,nkets)
!Local variables ------------------------------
!scalars
integer,parameter :: master=0
integer :: inn,nproc,my_rank,ierr
integer :: niter_file,niter_max,niter_done,nsppol,iq,my_nt,term_type,n_all_omegas
real(dp) :: norm,nfact
logical :: can_restart,is_converged
complex(dpc) :: factor
character(len=500) :: msg
character(len=fnlen),parameter :: tag_file="_HAYDR_SAVE"
character(len=fnlen) :: restart_file,out_file
type(haydock_type) :: haydock_file
!arrays
real(dp),allocatable :: bb_file(:)
real(dp),allocatable :: bb(:)
complex(dpc),allocatable :: aa(:),phi_nm1(:),phi_n(:),hphi_n(:),hphi_nm1(:)
complex(dpc),allocatable :: aa_file(:),phi_n_file(:),phi_nm1_file(:)
complex(dpc),allocatable :: ket0(:),all_omegas(:),green_temp(:,:)
! complex(dpc),allocatable :: diag_dense(:)
logical :: check(2)
!************************************************************************
ABI_CHECK(Bsp%nsppol==1,"nsppol > 1 not implemented yet")
nproc = xmpi_comm_size(comm); my_rank= xmpi_comm_rank(comm)
nsppol = Hdr_bse%nsppol
if (BSp%use_interp) then
ABI_COMMENT("No parallelization in Interpolation")
my_nt = SUM(Bsp%nreh_interp)
else
my_nt = my_t2-my_t1+1
end if
ABI_CHECK(my_nt>0,"One of the processors has zero columns")
write(msg,'(a,i0)')' Haydock algorithm with MAX number of iterations: ',BSp%niter
call wrtout(std_out,msg,"COLL")
!
! Select the terminator for the continued fraction.
term_type=0; if (Bsp%hayd_term>0) term_type=1
call wrtout(std_out,sjoin("Using terminator type: ",itoa(term_type)),"COLL")
!
! Check for presence of the restart file.
can_restart=.FALSE.
if ( BS_files%in_haydock_basename /= BSE_NOFILE) then
restart_file = TRIM(BS_files%in_haydock_basename)//TRIM(tag_file)
if (file_exists(restart_file) ) then
can_restart=.TRUE.
msg = " Restarting Haydock calculation from file: "//TRIM(restart_file)
call wrtout(std_out,msg,"COLL")
call wrtout(ab_out,msg,"COLL")
else
can_restart=.FALSE.
call wrtout(ab_out," WARNING: cannot find restart file: "//TRIM(restart_file),"COLL")
end if
end if
ABI_CHECK(.not.can_restart,"restart not yet implemented")
! Open the file and write basic dimensions and info.
if (my_rank==master) then
out_file = TRIM(BS_files%out_basename)//TRIM(tag_file)
call open_haydock(out_file,haydock_file)
haydock_file%hsize = hexc%hsize
haydock_file%use_coupling = Bsp%use_coupling
haydock_file%op = BSE_HAYD_IMEPS
haydock_file%nq = nkets
haydock_file%broad = Bsp%broad
call write_dim_haydock(haydock_file)
end if
!
! Calculate green(w) for the different starting points.
green=czero
do iq=1,nkets
ABI_MALLOC(ket0,(hexc%hsize))
ket0=kets(:,iq)
!
niter_file=0
if (can_restart) then
call haydock_restart(BSp,restart_file,BSE_HAYD_IMEPS,iq,hexc%hsize,&
& niter_file,aa_file,bb_file,phi_nm1_file,phi_n_file,comm)
end if
!
! For n>1, we have:
! 1) a_n = <n|H|n>
! 2) b_n = || H|n> - a_n|n> -b_{n-1}|n-1> ||
! 3) |n+1> = [H|n> -a_n|n> -b_{n-1}|n-1>]/b_n
!
! The sequences starts with |1> normalized to 1 and b_0 =0, therefore:
! a_1 = <1|H|1>
! b_1 = || H|1> - a_1|1> ||
! |2> = [H|1> - a_1|1>]/b_1
!
ABI_MALLOC(hphi_n,(hexc%hsize))
ABI_MALLOC(hphi_nm1,(hexc%hsize))
ABI_MALLOC(phi_nm1,(my_nt))
ABI_MALLOC(phi_n,(my_nt))
niter_max = niter_file + Bsp%niter
ABI_MALLOC(aa,(niter_max))
ABI_MALLOC(bb,(niter_max))
aa=czero; bb=zero
if (niter_file==0) then ! Calculation from scratch.
phi_nm1=ket0(my_t1:my_t2) ! Select the slice treated by this node.
norm = DZNRM2(hexc%hsize,ket0,1) ! Normalization
phi_nm1=phi_nm1/norm
call hexc_matmul_tda(hexc,hexc_i,phi_nm1,hphi_n)
aa(1)=xdotc(my_nt,phi_nm1,1,hphi_n(my_t1:),1)
call xmpi_sum(aa(1:1),comm,ierr)
phi_n = hphi_n(my_t1:my_t2) - aa(1)*phi_nm1
bb(1) = xdotc(my_nt,phi_n,1,phi_n,1)
call xmpi_sum(bb(1:1),comm,ierr)
bb(1) = SQRT(bb(1))
phi_n = phi_n/bb(1)
niter_done=1
else ! Use the previous a and b.
niter_done=niter_file
aa(1:niter_done) = aa_file
bb(1:niter_done) = bb_file
phi_nm1=phi_nm1_file(my_t1:my_t2) ! Select the slice treated by this node.
phi_n =phi_n_file (my_t1:my_t2)
end if
if (can_restart) then
ABI_FREE(aa_file)
ABI_FREE(bb_file)
ABI_FREE(phi_nm1_file)
ABI_FREE(phi_n_file)
end if
! Multiplicative factor (k-point sampling and unit cell volume)
! TODO be careful with the spin here
! TODO four_pi comes from the coulomb term 1/|q| is already included in the
! oscillators hence the present approach wont work if a cutoff interaction is used.
nfact = -four_pi/(Cryst%ucvol*hexc%nbz)
if (nsppol==1) nfact=two*nfact
factor = nfact*(DZNRM2(hexc%hsize,ket0,1)**2)
! Which quantity should be checked for convergence?
check = (/.TRUE.,.TRUE./)
if (ABS(Bsp%haydock_tol(2)-one)<tol6) check = (/.TRUE. ,.FALSE./)
if (ABS(Bsp%haydock_tol(2)-two)<tol6) check = (/.FALSE.,.TRUE./)
! Create new frequencies "mirror" in negative range to add
! their contributions. Can be improved by computing only once
! zero frequency, but loosing clearness
n_all_omegas = 2*BSp%nomega
ABI_MALLOC(all_omegas,(n_all_omegas))
! Put all omegas with frequency > 0 in table
all_omegas(BSp%nomega+1:n_all_omegas) = BSp%omega
! Put all omegas with frequency < 0
! Warning, the broadening must be kept positive
all_omegas(1:BSp%nomega) = -DBLE(BSp%omega(BSp%nomega:1:-1)) + j_dpc*AIMAG(BSp%omega(BSp%nomega:1:-1))
ABI_MALLOC(green_temp,(n_all_omegas,nkets))
call haydock_herm_algo(niter_done,niter_max,n_all_omegas,all_omegas,BSp%haydock_tol(1),check,&
& my_t1,my_t2,factor,term_type,aa,bb,phi_nm1,phi_n,&
& green_temp(:,iq),inn,is_converged,&
& hexc, hexc_i, comm)
! Computing result from two ranges of frequencies
! The real part is added, the imaginary part is substracted
green(:,iq) = green_temp(BSp%nomega+1:n_all_omegas,iq)+CONJG(green_temp(BSp%nomega:1:-1,iq))
ABI_FREE(all_omegas)
ABI_FREE(green_temp)
!
! Save the a"s and the b"s for possible restarting.
! 1) Info on the Q.
! 2) Number of iterations performed.
! 3) do iter=1,niter_performed
! aa(iter),bb(iter)
! end do
! 4) |n-1>
! |n>
!
hphi_nm1 = czero
hphi_nm1(my_t1:my_t2) = phi_nm1
call xmpi_sum_master(hphi_nm1,master,comm,ierr)
hphi_n = czero
hphi_n(my_t1:my_t2) = phi_n
call xmpi_sum_master(hphi_n,master,comm,ierr)
if (my_rank==master) then
! Write data for restarting
call write_haydock(haydock_file, hexc%hsize, Bsp%q(:,iq), aa, bb, hphi_n, hphi_nm1, MIN(inn,niter_max), factor)
end if
ABI_FREE(hphi_n)
ABI_FREE(hphi_nm1)
ABI_FREE(phi_nm1)
ABI_FREE(phi_n)
ABI_FREE(aa)
ABI_FREE(bb)
ABI_FREE(ket0)
end do ! iq
if (my_rank==master) call close_haydock(haydock_file)
call xmpi_barrier(comm)
end subroutine haydock_herm
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_herm_algo
!! NAME
!! haydock_herm_algo
!!
!! FUNCTION
!!
!! INPUTS
!! niter_done=Number of iterations already performed (0 if the run starts from scratch).
!! niter_max=Max number of iterations. Always > niter_done
!! nomega=Number of Frequency points for the evaluation of the matrix element.
!! omega(nomega)=Frequency set (imaginary part is already included).
!! tol_iter=Tolerance used to stop the algorithm.
!! check(2)=Logical flags to specify where both the real and the imaginary part of the
!! matrix elements of the Green functions have to be checked for convergence.
!! hsize=Size of the blocks.
!! my_t1,my_t2=Indices of the first and last column stored treated by this done.
!! term_type=0 if no terminator is used, 1 otherwise.
!! hmat(hsize,my_t1:my_t2)=The columns of the block.
!! factor
!! ntrans = Number of transitions
!! corresp = mapping between coarse points and neighbours
!! overlaps = overlaps of wavefunctions between dense k-point coarse neighbours and bands
!! comm=MPI communicator.
!!
!! OUTPUT
!! green(nomega)=Output matrix elements.
!! inn=Last iteration performed.
!! is_converged=.TRUE. of the algorithm converged.
!!
!! SIDE EFFECTS
!! phi_nm1(my_t2-my_t1+1), phi_n(my_t2-my_t1+1)
!! input: vectors used to initialize the iteration
!! output: the vectors obtained in the last iteration
!! aa(niter_max) and bb(niter_max)
!! if niter_done>0: aa(1:niter_done), bb(1:niter_done) store the coefficients of the previous run.
!! when the routine returns aa(1:inn) and bb(1:inn) contain the matrix elements of the tridiagonal form.
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_herm_algo(niter_done,niter_max,nomega,omega,tol_iter,check,&
& my_t1,my_t2,factor,term_type,aa,bb,phi_nm1,phi_n,&
& green,inn,is_converged,&
& hexc, hexc_i, comm)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: niter_max,niter_done,nomega
integer,intent(in) :: my_t1,my_t2,term_type
integer,intent(in) :: comm
integer,intent(out) :: inn
logical,intent(out) :: is_converged
real(dp),intent(in) :: tol_iter
complex(dpc),intent(in) :: factor
type(hexc_t),intent(in) :: hexc
type(hexc_interp_t),intent(in) :: hexc_i
!arrays
real(dp),intent(inout) :: bb(niter_max)
complex(dpc),intent(out) :: green(nomega)
complex(dpc),intent(in) :: omega(nomega)
complex(dpc),intent(inout) :: aa(niter_max)
complex(dpc),intent(inout) :: phi_nm1(my_t2-my_t1+1)
complex(dpc),intent(inout) :: phi_n (my_t2-my_t1+1)
logical,intent(in) :: check(2)
!Local variables ------------------------------
!scalars
integer :: ierr,my_nt,niter_min,nconv
character(len=500) :: msg
logical,parameter :: force_real=.TRUE.
!arrays
real(dp) :: abs_err(nomega,2) !,rel_err(nomega,2)
complex(dpc),allocatable :: oldg(:),newg(:)
complex(dpc),allocatable :: phi_np1(:),hphi_n(:),cfact(:)
logical :: test(2)
!************************************************************************
! The sequences starts with |1> normalized to 1 and b_0 =0, therefore:
! a_1 = <1|H|1>
! b_1 = || H|1> - a_1|1> ||
! |2> = [H|1> - a_1|1>]/b_1
!
! For n>1 we have
! 1) a_n = <n|H|n>
! 2) b_n = || H|n> - a_n|n> -b_{n-1}|n-1> ||
! 3) |n+1> = [H|n> -a_n|n> -b_{n-1}|n-1>]/b_n
!
my_nt = my_t2-my_t1+1
ABI_MALLOC_OR_DIE(hphi_n,(hexc%hsize), ierr)
ABI_MALLOC(phi_np1,(my_nt))
ABI_MALLOC(oldg,(nomega))
oldg=czero
ABI_MALLOC(newg,(nomega))
newg=czero
ABI_MALLOC(cfact,(nomega))
cfact=czero
nconv=0
do inn=niter_done+1,niter_max
!YG2014
call hexc_matmul_tda(hexc,hexc_i,phi_n,hphi_n)
aa(inn) = xdotc(my_nt,phi_n,1,hphi_n(my_t1:),1)
call xmpi_sum(aa(inn:inn),comm,ierr)
if (force_real) aa(inn) = DBLE(aa(inn)) ! Matrix is Hermitian.
! |n+1> = H|n> - A(n)|n> - B(n-1)|n-1>
phi_np1 = hphi_n(my_t1:my_t2) - aa(inn)*phi_n - bb(inn-1)*phi_nm1
bb(inn) = xdotc(my_nt,phi_np1,1,phi_np1,1)
call xmpi_sum(bb(inn),comm,ierr)
bb(inn) = SQRT(bb(inn))
phi_np1 = phi_np1/bb(inn)
phi_nm1 = phi_n
phi_n = phi_np1
write(msg,'(a,i0,a,3es12.4)')' Iteration number ',inn,', b_i RE(a_i) IM(a_i) ',bb(inn),REAL(aa(inn)),AIMAG(aa(inn))
call wrtout(std_out,msg,"COLL")
call continued_fract(inn,term_type,aa,bb,nomega,omega,cfact)
newg= factor*cfact
!
! Avoid spurious convergence.
niter_min=4; if (niter_done>1) niter_min=niter_done+1
if (inn>niter_min) then
test=.TRUE.
abs_err(:,1) = ABS(DBLE (newg-oldg))
abs_err(:,2) = ABS(AIMAG(newg-oldg))
!
if (tol_iter>zero) then
! Test on the L1 norm.
if (check(1)) test(1) = SUM(abs_err(:,1)) < tol_iter*SUM(ABS(DBLE (newg)))
if (check(2)) test(2) = SUM(abs_err(:,2)) < tol_iter*SUM(ABS(AIMAG(newg)))
else
! Stringent test for each point.
if (check(1)) test(1) = ALL( abs_err(:,1) < -tol_iter*ABS(DBLE (newg)))
if (check(2)) test(2) = ALL( abs_err(:,2) < -tol_iter*ABS(AIMAG(newg)))
end if
!
if (ALL(test)) then
nconv = nconv+1
else
nconv = 0
end if
if (nconv==2) then
if(inn<100)then
write(msg,'(a,es10.2,a)')&
& " >>> Haydock algorithm converged twice within haydock_tol= ",tol_iter," after less than 100 iterations."
else
write(msg,'(a,es10.2,a,i0,a)')&
& " >>> Haydock algorithm converged twice within haydock_tol= ",tol_iter," after ",inn," iterations."
endif
call wrtout(std_out,msg,'COLL')
call wrtout(ab_out,msg,'COLL')
EXIT
end if
end if
oldg = newg
end do ! inn
green = newg
if (nconv/=2) then
write(msg,'(a,es10.2,a,i0,a)')&
& " WARNING: Haydock algorithm did not converge within ",tol_iter," after ",niter_max," iterations."
call wrtout(std_out,msg,'COLL')
call wrtout(ab_out,msg,'COLL')
end if
is_converged = (nconv==2)
ABI_FREE(oldg)
ABI_FREE(newg)
ABI_FREE(cfact)
ABI_FREE(hphi_n)
ABI_FREE(phi_np1)
end subroutine haydock_herm_algo
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_restart
!! NAME
!! haydock_restart
!!
!! FUNCTION
!! Restart the Haydock method from file reading the data produced in a previous run.
!!
!! INPUTS
!! BSp<type(excparam)>=Parameters defining the Bethe-Salpeter calculation.
!! omega(BSp%nomega)=Frequency mesh for the macroscopic dielectric function (broadening is already included).
!! iq_search=The index of the q-point to be searched.
!! hsize
!! comm=MPI communicator.
!! nsppol
!! restart_file
!!
!! OUTPUT
!! niter_file=Number of iterations already performed. 0 to signal that an error occurred during the reading
!! bb_file(:)
!! aa_file(:)
!! phi_n_file(:)
!! phi_nm1_file(:)
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_restart(BSp,restart_file,ftype,iq_search,hsize,niter_file,aa_file,bb_file,phi_nm1_file,phi_n_file,comm)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: comm,hsize,iq_search,ftype
integer,intent(out) :: niter_file
character(len=*),intent(in) :: restart_file
type(excparam),intent(in) :: BSp
!arrays
real(dp),allocatable,intent(out) :: bb_file(:)
complex(dpc),allocatable,intent(out) :: aa_file(:),phi_n_file(:),phi_nm1_file(:)
!Local variables ------------------------------
!scalars
integer,parameter :: master=0
integer :: nproc,my_rank,ierr,op_file
integer :: hsize_file,use_coupling_file
complex(dpc) :: factor_file
character(len=500) :: msg
type(haydock_type) :: haydock_file
!************************************************************************
nproc = xmpi_comm_size(comm); my_rank= xmpi_comm_rank(comm)
if (my_rank==master) then
call open_haydock(restart_file, haydock_file)
call read_dim_haydock(haydock_file)
if (haydock_file%op/=ftype) then
write(msg,"(2(a,i0))")" Expecting restart file with filetype: ",ftype," but found ",op_file
ABI_ERROR(msg)
end if
if (haydock_file%hsize/=hsize) then
write(msg,"(2(a,i0))")&
& " Rank of H_exc read from file: ",hsize_file," differs from the one used in this run: ",hsize
ABI_ERROR(msg)
end if
if (haydock_file%use_coupling /= BSp%use_coupling) then
write(msg,'(2(a,i0))')&
& " use_coupling_file: ",use_coupling_file," differs from input file value: ",BSp%use_coupling
ABI_ERROR(msg)
end if
call read_haydock(haydock_file, Bsp%q(:,iq_search), aa_file, bb_file, &
& phi_n_file, phi_nm1_file, niter_file, factor_file)
if (niter_file == 0) then
write(msg,"(a,3f8.4,3a)")&
& " Could not find q-point: ",BSp%q(:,iq_search)," in file ",TRIM(restart_file),&
& " Cannot restart Haydock iterations for this q-point"
ABI_COMMENT(msg)
else
write(msg,'(a,i0)')" Number of iterations already performed: ",niter_file
call wrtout(std_out,msg,"COLL")
call wrtout(ab_out,msg,"COLL")
if ( ABS(haydock_file%broad - BSp%broad) > tol6) then
write(msg,'(2a,2(a,f8.4),a)')&
& " Restart file has been produced with a different Lorentzian broadening: ",ch10,&
& " broad_file: ",haydock_file%broad," input broadening: ",BSp%broad," Continuing anyway. "
ABI_WARNING(msg)
end if
call close_haydock(haydock_file)
end if
end if
!
! Master broadcasts the data.
call xmpi_bcast(niter_file,master,comm,ierr)
if (my_rank/=master) then
ABI_MALLOC(aa_file,(niter_file))
ABI_MALLOC(bb_file,(niter_file))
ABI_MALLOC(phi_nm1_file,(hsize))
ABI_MALLOC(phi_n_file,(hsize))
end if
call xmpi_bcast(aa_file,master,comm,ierr)
call xmpi_bcast(bb_file,master,comm,ierr)
call xmpi_bcast(phi_nm1_file,master,comm,ierr)
call xmpi_bcast(phi_n_file,master,comm,ierr)
end subroutine haydock_restart
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_mdf_to_tensor
!! NAME
!! haydock_mdf_to_tensor
!!
!! FUNCTION
!! Transform macroscopic dielectric function from green function to each components of the tensor in red and cart coord.
!!
!! INPUTS
!! BSp<type(excparam)>=Parameters defining the Bethe-Salpeter calculation.
!! omega(BSp%nomega)=Frequency mesh for the macroscopic dielectric function (broadening is already included).
!! Cryst=Parameters of the crystal
!! eps(BSp%nomega,BSp%nq) = Macroscopic dielectric function to be written.
!!
!! OUTPUT
!! tensor_cart(BSp%nomega,6) = dielectric tensor for each frequency, order (11,22,33,12,13,23) in cart. coord.
!! tensor_red(BSp%nomega, 6) = idem in reduced coordinated
!! ierr = 0 if the tensors have been successfully computed
!! \= 0 if the system is ill-posed in terms of q-points (not enough or not independent q-points)
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_mdf_to_tensor(BSp,Cryst,eps,tensor_cart,tensor_red,ierr)
!Arguments ------------------------------------
!scalars
integer,intent(out) :: ierr
type(excparam),intent(in) :: BSp
type(crystal_t),intent(in) :: Cryst
!arrays
complex(dpc),intent(in) :: eps(BSp%nomega,BSp%nq)
complex(dpc),intent(out) :: tensor_cart(BSp%nomega,6), tensor_red(BSp%nomega,6)
!Local variables ------------------------------
!scalars
integer :: iq,info
real(dp) :: normqcart, normqred
!arrays
integer,allocatable :: ipiv(:)
real(dp) :: qcart(3), qtmet(3)
real(dp) :: qred2cart(3,3),qcart2red(3,3)
complex(dpc) :: qqcart(BSp%nq,6), qqred(BSp%nq,6)
complex(dpc) :: b(6,BSP%nomega)
!************************************************************************
! Error flag
ierr = 0
if(BSp%nq /= 6) then
ierr = -1
return
end if
! Transformation matrices from reduced coordinates to cartesian coordinates
qred2cart = two_pi*Cryst%gprimd
qcart2red = qred2cart
call matrginv(qcart2red,3,3)
do iq = 1, 6
! Computing cartesian q-vector
qcart = MATMUL(qred2cart, BSp%q(:,iq))
! Computing product 'metric - qred' to form quadratic form
qtmet = (two_pi**2)*MATMUL(Cryst%gmet, BSp%q(:,iq))
! squared norms
normqcart = qcart(1)**2+qcart(2)**2+qcart(3)**2
normqred = (normv(BSp%q(:,iq),Cryst%gmet,"G"))**2
! Compute line 'iq' for matrix in cartesian coord
qqcart(iq,1) = (qcart(1))**2
qqcart(iq,2) = (qcart(2))**2
qqcart(iq,3) = (qcart(3))**2
qqcart(iq,4) = 2*(qcart(1)*qcart(2))
qqcart(iq,5) = 2*(qcart(1)*qcart(3))
qqcart(iq,6) = 2*(qcart(2)*qcart(3))
! Compute line 'iq' for matrix in reduced coord
qqred(iq,1) = (qtmet(1))**2
qqred(iq,2) = (qtmet(2))**2
qqred(iq,3) = (qtmet(3))**2
qqred(iq,4) = 2*(qtmet(1)*qtmet(2))
qqred(iq,5) = 2*(qtmet(1)*qtmet(3))
qqred(iq,6) = 2*(qtmet(2)*qtmet(3))
! Renormalize line
qqcart(iq,:) = qqcart(iq,:)/normqcart
qqred(iq,:) = qqred(iq,:)/normqred
end do
ABI_MALLOC(ipiv,(6))
! Solving linear system
b = TRANSPOSE(eps)
call ZGESV(6,BSp%nomega,qqcart,6,ipiv,b,6,info)
tensor_cart = TRANSPOSE(b)
if(info /= 0) then
! Skipping the rest of the routine
ierr = info
ABI_FREE(ipiv)
return
end if
b = TRANSPOSE(eps)
call ZGESV(6,BSp%nomega,qqred,6,ipiv,b,6,info)
tensor_red = TRANSPOSE(b)
if(info /= 0) ierr = info
ABI_FREE(ipiv)
end subroutine haydock_mdf_to_tensor
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_psherm
!! NAME
!! haydock_psherm
!!
!! FUNCTION
!! Reads the excitonic Hamiltonian from file and construct the Lanczos set of vectors
!! by iterative matrix-vector multiplications.
!!
!! INPUTS
!! BSp<type(excparam)>=Parameters defining the Bethe-Salpeter calculation.
!! omega(BSp%nomega)=Frequency mesh for the macroscopic dielectric function (broadening is already included).
!! hize
!! my_t1,my_t2
!! hreso(hsize,my_t1:my_t2)
!! hcoup(hsize,my_t1:my_t2)
!! nkets
!! kets(hsize,nkets)
!! comm=MPI communicator.
!!
!! OUTPUT
!! green(BSp%nomega)=The imaginary part of the macroscopic dielectric function.
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_psherm(BSp,BS_files,Cryst,Hdr_bse,hexc,hexc_i,hsize,my_t1,my_t2,nkets,kets,green,comm)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: hsize,my_t1,my_t2,nkets,comm
type(crystal_t),intent(in) :: Cryst
type(excparam),intent(in) :: BSp
type(excfiles),intent(in) :: BS_files
type(Hdr_type),intent(in) :: Hdr_bse
!arrays
complex(dp),intent(out) :: green(BSp%nomega,BSp%nq)
complex(dpc),intent(in) :: kets(hsize,nkets)
!Local variables ------------------------------
!scalars
integer,parameter :: master=0
integer :: inn,itt,out_unt,nproc,my_rank,ierr
integer :: niter_file,niter_max,niter_done,nsppol,iq,my_nt,term_type
real(dp) :: ket0_hbar_norm,nfact
logical :: can_restart,is_converged
complex(dpc) :: factor
character(len=fnlen),parameter :: tag_file="_HAYDC_SAVE"
character(len=500) :: msg
character(len=fnlen) :: restart_file,out_file
type(hexc_t),intent(in) :: hexc
type(hexc_interp_t),intent(in) :: hexc_i
!arrays
real(dp),allocatable :: bb_file(:)
real(dp),allocatable :: bb(:)
complex(dpc),allocatable :: aa(:),cc(:),phi_np1(:),phi_n(:),phi_nm1(:),cbuff(:)
complex(dpc),allocatable :: aa_file(:),phi_n_file(:),phi_np1_file(:),cc_file(:)
complex(dpc),allocatable :: ket0(:)
logical :: check(2)
!************************************************************************
ABI_WARNING("Haydock + coupling is still under development")
if(BSp%use_interp) then
ABI_ERROR("Coupling is not yet implemented with interpolation")
end if
nproc = xmpi_comm_size(comm)
my_rank= xmpi_comm_rank(comm)
nsppol = Hdr_bse%nsppol
my_nt = my_t2-my_t1+1
ABI_CHECK(my_nt>0,"One of the processors has zero columns")
! Multiplicative factor (k-point sampling and unit cell volume)
! TODO be careful with the spin here
! TODO four_pi comes from the coulomb term 1/|q| is already included in the
! oscillators hence the present approach wont work if a cutoff interaction is used.
nfact = four_pi/(Cryst%ucvol*BSp%nkbz)
if (nsppol==1) nfact=two*nfact
write(msg,'(a,i0)')' Haydock algorithm with MAX number of iterations: ',BSp%niter
call wrtout(std_out,msg,"COLL")
!
! Check for presence of the restart file.
can_restart=.FALSE.
if ( BS_files%in_haydock_basename /= BSE_NOFILE) then
restart_file = strcat(BS_files%in_haydock_basename,tag_file)
if (file_exists(restart_file) ) then
can_restart=.TRUE.
msg = strcat(" Restarting Haydock calculation from file: ",restart_file)
call wrtout(std_out,msg,"COLL")
call wrtout(ab_out,msg,"COLL")
ABI_ERROR("Restart is not tested")
else
can_restart=.FALSE.
ABI_WARNING(strcat("Cannot find restart file: ",restart_file))
end if
end if
!
! Open the file and writes basic dimensions and info.
if (my_rank==master) then
out_file = TRIM(BS_files%out_basename)//TRIM(tag_file)
if (open_file(out_file,msg,newunit=out_unt,form="unformatted") /= 0) then
ABI_ERROR(msg)
end if
! write header TODO: standardize this part.
write(out_unt)hsize,Bsp%use_coupling,BSE_HAYD_IMEPS,nkets,Bsp%broad
end if
!
! Select the terminator for the continued fraction.
term_type=0 !; if (Bsp%hayd_term>0) term_type=2
call wrtout(std_out,sjoin("Using terminator type: ",itoa(term_type)),"COLL")
!
! Calculate green(w) for the different starting kets.
green=czero
do iq=1,nkets
ABI_MALLOC(ket0,(my_nt))
ket0 = kets(my_t1:my_t2,iq)
!
niter_file=0
if (can_restart) then
call haydock_restart(BSp,restart_file,BSE_HAYD_IMEPS,iq,hsize,&
& niter_file,aa_file,bb_file,phi_np1_file,phi_n_file,comm)
end if
!
ABI_MALLOC(phi_nm1,(my_nt))
ABI_MALLOC(phi_n,(my_nt))
ABI_MALLOC(phi_np1,(my_nt))
!
! TODO: Note the different convention used for the coefficients
! Should use the same convention in the Hermitian case.
niter_max = niter_file + Bsp%niter
ABI_MALLOC(aa,(niter_max))
ABI_MALLOC(bb,(niter_max+1))
ABI_MALLOC(cc,(niter_max+1))
aa=czero; bb=czero; cc=czero
if (niter_file==0) then ! Calculation from scratch.
phi_n = ket0
call hexc_matmul_full(hexc, hexc_i, phi_n, phi_np1, -1)
!phi_np1 = MATMUL(hreso,ket0) - MATMUL(hcoup,CONJG(ket0))
ket0_hbar_norm = SQRT(two*DBLE(DOT_PRODUCT(phi_n,phi_np1)))
phi_n = phi_n /ket0_hbar_norm
phi_np1 = phi_np1/ket0_hbar_norm
!ket0 = ket0/ket0_hbar_norm
cc(1)=zero ! <P|F|P>
!cc(1) = DOT_PRODUCT(ket0,phi_np1)
write(std_out,*)" cc(1), ket0_hbar_norm =",cc(1),ket0_hbar_norm
phi_nm1 = czero
niter_done=0 ! TODO Be careful here
else ! Use the previously calculates a and b.
niter_done=niter_file
ABI_ERROR("Restart not coded")
!aa(1:niter_done) = aa_file
!bb(1:niter_done) = bb_file
!phi_np1=phi_np1_file(my_t1:my_t2) ! Select the slice treated by this node.
!phi_n =phi_n_file (my_t1:my_t2)
end if
if (can_restart) then
ABI_FREE(aa_file)
ABI_FREE(bb_file)
ABI_FREE(cc_file)
ABI_FREE(phi_np1_file)
ABI_FREE(phi_n_file)
end if
! This factor gives the correct results
factor = -nfact*ket0_hbar_norm / SQRT(two)
! Which quantity should be checked for convergence?
check = (/.TRUE.,.TRUE./)
if (ABS(Bsp%haydock_tol(2)-one)<tol6) check = (/.TRUE. ,.FALSE./)
if (ABS(Bsp%haydock_tol(2)-two)<tol6) check = (/.FALSE.,.TRUE./)
call haydock_psherm_optalgo(niter_done,niter_max,BSp%nomega,BSp%omega,BSp%haydock_tol(1),check,hexc,hexc_i,&
& hsize,my_t1,my_t2,factor,term_type,aa,bb,cc,ket0,ket0_hbar_norm,phi_nm1,phi_n,phi_np1,&
& green(:,iq),inn,is_converged,comm)
!
! Save the a"s and the b"s for possible restarting.
! 1) Info on the Q.
! 2) Number of iterations performed.
! 3) do iter=1,niter_performed
! aa(iter),bb(iter)
! end do
! 4) |n-1>
! |n>
! |n+1>
!
if (my_rank==master) then ! Open the file and writes basic dimensions and info.
write(out_unt)Bsp%q(:,iq)
write(out_unt)MIN(inn,niter_max) ! NB: if the previous loop completed inn=niter_max+1
do itt=1,MIN(inn,niter_max) ! if we exited then inn is not incremented by one.
write(out_unt)itt,aa(itt),bb(itt)
end do
end if
!
! cbuff is used as workspace to gather |n-1>, |n> and |n+1>.
ABI_MALLOC(cbuff,(hsize))
cbuff=czero; cbuff(my_t1:my_t2) = phi_nm1
call xmpi_sum_master(cbuff,master,comm,ierr)
if (my_rank==master) write(out_unt) cbuff ! |n-1>
cbuff=czero; cbuff(my_t1:my_t2) = phi_n
call xmpi_sum_master(cbuff,master,comm,ierr)
if (my_rank==master) write(out_unt) cbuff ! |n>
cbuff=czero; cbuff(my_t1:my_t2) = phi_np1
call xmpi_sum_master(cbuff,master,comm,ierr)
if (my_rank==master) write(out_unt) cbuff ! |n+1>
ABI_FREE(phi_nm1)
ABI_FREE(phi_n)
ABI_FREE(phi_np1)
ABI_FREE(cbuff)
ABI_FREE(aa)
ABI_FREE(bb)
ABI_FREE(cc)
ABI_FREE(ket0)
end do ! iq
if (my_rank==master) close(out_unt)
call xmpi_barrier(comm)
end subroutine haydock_psherm
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_psherm_optalgo
!! NAME
!! haydock_psherm_optalgo
!!
!! FUNCTION
!! Haydock algorithm for pseudo-hermitian matrix
!!
!! INPUTS
!! niter_done=Number of iterations already performed (0 if the run starts from scratch).
!! niter_tot=Max number of iterations. Always > niter_done
!! nomega=Number of Frequency points for the evaluation of the matrix element.
!! omega(nomega)=Frequency set (imaginary part is already included).
!! tol_iter=Tollerance used to stop the the algorithm.
!! check(2)=Logical flags to specify where both the real and the imaginary part of the
!! matrix elements of the Green functions have to be checked for convergence.
!! hsize=Size of the blocks.
!! my_t1,my_t2=Indeces of the first and last column stored treated by this done.
!! term_type=0 if no terminator is used, 1 otherwise.
!! hreso(hsize,my_t1:my_t2)=The columns of the resonant block.
!! hcoup(hsize,my_t1:my_t2)=The columns of the coupling block.
!! factor
!! comm=MPI communicator.
!!
!! OUTPUT
!! green(nomega)=Output matrix elements.
!! inn=Last iteration performed.
!! is_converged=.TRUE. of the algorithm converged.
!!
!! SIDE EFFECTS
!! phi_nm1(my_t2-my_t1+1), phi_n(my_t2-my_t1+1)
!! input: vectors used to initialize the iteration
!! output: the vectors obtained in the last iteration
!! aa(niter_tot) and bb(niter_tot+1)
!! if niter_done>0: aa(1:niter_done), bb(1:niter_done) store the coefficients of the previous run.
!! when the routine returns aa(1:inn) and bb(1:inn) contain the matrix elements of the tridiagonal form.
!! cc(niter_tot+1)
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_psherm_optalgo(niter_done,niter_tot,nomega,omega,tol_iter,check,hexc,hexc_i,hsize,my_t1,my_t2,&
& factor,term_type,aa,bb,cc,ket0,ket0_hbar_norm,phi_nm1,phi_n,phi_np1,green,inn,is_converged,comm)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: niter_tot,niter_done,nomega,comm,hsize,my_t1,my_t2,term_type
integer,intent(out) :: inn
logical,intent(out) :: is_converged
real(dp),intent(in) :: tol_iter,ket0_hbar_norm
complex(dpc),intent(in) :: factor
type(hexc_t),intent(in) :: hexc
type(hexc_interp_t),intent(in) :: hexc_i
!arrays
real(dp),intent(inout) :: bb(niter_tot+1)
complex(dpc),intent(out) :: green(nomega)
complex(dpc),intent(in) :: omega(nomega)
complex(dpc),intent(inout) :: aa(niter_tot),cc(niter_tot+1)
complex(dpc),intent(in) :: ket0(my_t2-my_t1+1)
complex(dpc),intent(inout) :: phi_nm1(my_t2-my_t1+1)
complex(dpc),intent(inout) :: phi_n (my_t2-my_t1+1)
complex(dpc),intent(inout) :: phi_np1(my_t2-my_t1+1)
logical,intent(in) :: check(2)
!Local variables ------------------------------
!scalars
integer :: my_nt,niter_min,nconv,parity,ii,jj,tdim,ierr
integer :: row_max,col_max,nlev
character(len=500) :: msg
real(dp) :: max_err,mean_err,mean_err2,std_dev,err
logical :: keep_vectors=.TRUE.
!arrays
real(dp) :: abs_err(nomega,2) !,ww_err(nomega,2)
complex(dpc) :: gn0(nomega,niter_tot)
complex(dpc),allocatable :: oldg(:),newg(:)
complex(dpc),allocatable :: hphi_n(:),save_phi(:,:)
complex(dpc),allocatable :: alpha(:,:),beta(:,:),ovlp(:,:)
complex(dpc),allocatable :: phi_test(:),phi_test2(:),g00(:)
logical :: test(2)
!************************************************************************
ABI_UNUSED(ket0_hbar_norm)
my_nt = my_t2-my_t1+1
ABI_MALLOC(oldg,(nomega))
ABI_MALLOC(newg,(nomega))
ABI_MALLOC(g00,(nomega))
oldg=czero; newg=czero; g00=czero
nconv=0
keep_vectors = (keep_vectors.and.xmpi_comm_size(comm)==1)
if (keep_vectors) then
ABI_MALLOC_OR_DIE(save_phi,(my_t2-my_t1+1,niter_tot), ierr)
save_phi=czero
end if
ABI_MALLOC(hphi_n,(hsize))
do inn=niter_done+1,niter_tot
!
! a(n) = <Vn+1|F|Vn+1> = <Vn|HFH|Vn>) = 0 by symmetry.
aa(inn)=zero
! |n+1> = |n+1> - a(n)|Vn> - a(n)|n-1>
phi_np1 = phi_np1 - bb(inn)*phi_nm1
!
! |n-1> = |n>
! |n> = |n+1>
phi_nm1 = phi_n
phi_n = phi_np1
!
!|n+1> = H |n> using all eh components.
parity = (-1)**(inn+1)
call hexc_matmul_full(hexc, hexc_i, phi_n, phi_np1, parity)
!phi_np1 = MATMUL(hreso,phi_n) + parity * MATMUL(hcoup,CONJG(phi_n))
!call xmpi_sum(hphi_np1,comm,ierr)
!
! B(n+1)= <n|F|n+1>^(1/2) = <n|FH|n>^(1/2))= (2*Re(<n|V+1>))^(1/2)
! by symmetry, where the dot_product is done in the resonant eh sub-space.
!
bb(inn+1)=SQRT(two*DBLE(DOT_PRODUCT(phi_n,phi_np1)))
!bb(inn+1)=two*DBLE(DOT_PRODUCT(phi_n,phi_np1))
!call xmpi_sum(bb(inn+1),comm,ierr)
!bb(inn+1)=SQRT(bb(inn+1)
!
!|n+1> =|n+1>/B(n+1)
phi_n = phi_n /bb(inn+1)
phi_np1 = phi_np1/bb(inn+1)
if (keep_vectors) save_phi(:,inn) = phi_n
parity = (-1)**(inn+1)
!if (parity==-1) then
! cc(inn+1)=czero
!else
cc(inn+1)=DOT_PRODUCT(ket0,phi_n) + parity * DOT_PRODUCT(phi_n,ket0)
!end if
!call xmpi_sum(cc(inn+1),comm,ierr)
write(msg,'(a,i0,a,3es12.4)')' Iteration number ',inn,', b_i RE(c_i+1) IM(c_i+1) ',bb(inn),REAL(cc(inn+1)),AIMAG(cc(inn+1))
call wrtout(std_out,msg,"COLL")
call continued_fract(inn,term_type,aa,bb(2:),nomega,omega,g00)
gn0(:,1) = g00
if (.FALSE.) then
gn0(:,2) = (one - omega(:)*g00(:))/bb(2)
do ii=3,inn
gn0(:,ii) = -(-bb(ii)*gn0(:,ii-2) -omega(:)*gn0(:,ii-1))/bb(ii+1)
end do
else
do ii=2,inn
nlev = inn-ii
call continued_fract(nlev,term_type,aa,bb(ii+1:),nomega,omega,g00)
gn0(:,ii) = +bb(ii+1) * g00 * gn0(:,ii-1)
end do
end if
newg=czero
do ii=1,inn
newg(:) = newg + cc(ii)* gn0(:,ii)
end do
newg = factor*newg
!
! Avoid spurious convergence.
niter_min=4; if (niter_done>1) niter_min=niter_done+1
if (inn>niter_min) then
test=.TRUE.
abs_err(:,1) = ABS(DBLE (newg-oldg))
abs_err(:,2) = ABS(AIMAG(newg-oldg))
!
if (tol_iter>zero) then
! Test on the L1 norm.
if (check(1)) test(1) = SUM(abs_err(:,1)) < tol_iter*SUM(ABS(DBLE (newg)))
if (check(2)) test(2) = SUM(abs_err(:,2)) < tol_iter*SUM(ABS(AIMAG(newg)))
else
! Stringent test for each point.
if (check(1)) test(1) = ALL( abs_err(:,1) < -tol_iter*ABS(DBLE (newg)))
if (check(2)) test(2) = ALL( abs_err(:,2) < -tol_iter*ABS(AIMAG(newg)))
end if
!
if (ALL(test)) then
nconv = nconv+1
else
nconv = 0
end if
if (nconv==2) then
if(inn<100)then
write(msg,'(a,es10.2,a)')&
& " >>> Haydock algorithm converged twice within haydock_tol= ",tol_iter," after less than 100 iterations."
else
write(msg,'(a,es10.2,a,i0,a)')&
& " >>> Haydock algorithm converged twice within haydock_tol= ",tol_iter," after ",inn," iterations."
endif
call wrtout(std_out,msg,'COLL')
call wrtout(ab_out,msg,'COLL')
EXIT
end if
end if
!
oldg = newg
end do ! inn
green = newg
if (nconv/=2) then
write(msg,'(a,es10.2,a,i0,a)')&
& " WARNING: Haydock algorithm did not converge within ",tol_iter," after ",niter_tot," iterations."
call wrtout(std_out,msg,'COLL')
call wrtout(ab_out,msg,'COLL')
end if
is_converged = (nconv==2)
ABI_FREE(oldg)
ABI_FREE(newg)
ABI_FREE(g00)
ABI_FREE(hphi_n)
if (keep_vectors) then
tdim = MIN(inn,niter_tot)
ABI_MALLOC(ovlp,(tdim,tdim))
ABI_MALLOC(phi_test,(hsize))
ABI_MALLOC(phi_test2,(hsize))
max_err=smallest_real; mean_err=zero; mean_err2=zero; row_max=-1
do ii=1,tdim
parity = (-1)**(ii+1)
phi_test = save_phi(:,ii)
call hexc_matmul_full(hexc, hexc_i, phi_test, phi_test2, parity)
!phi_test2 = MATMUL(hreso,phi_test) + parity * MATMUL(hcoup,CONJG(phi_test))
ovlp(ii,ii) = DOT_PRODUCT(phi_test,phi_test2) + DOT_PRODUCT(phi_test2,phi_test)
err = ABS(ovlp(ii,ii)-cone)
mean_err = mean_err + err
mean_err2 = mean_err2 + err**2
if (err > max_err) then
max_err = err
row_max = ii
end if
end do
mean_err = mean_err/tdim
std_dev = mean_err2/tdim -mean_err**2
write(std_out,'(a,i0,1x,3es14.6)')&
& " Error in normalization (ii, max_err,mean,std_dev): ",row_max,max_err,mean_err,std_dev
ABI_FREE(phi_test)
ABI_FREE(phi_test2)
ABI_MALLOC(alpha,(hsize,tdim))
! Less efficient but for sake of simplicity with hexc_matmul
! TODO possibility to call hreso * phi, and hcoup * phi separately
do ii=1,tdim
parity = (-1)**(ii+1)
call hexc_matmul_full(hexc, hexc_i, save_phi(:,ii), alpha(:,ii), parity)
end do
!alpha = MATMUL(hreso,save_phi(:,1:tdim))
!
!do ii=1,tdim
! parity = (-1)**(ii+1)
! alpha(:,ii) = alpha(:,ii) + parity*MATMUL(hcoup,CONJG(save_phi(:,ii)))
!end do
ovlp = MATMUL(TRANSPOSE(CONJG(save_phi(:,1:tdim))),alpha)
ABI_MALLOC(beta,(hsize,tdim))
do ii=1,tdim
parity = (-1)**(ii+1)
beta(:,ii) = parity*save_phi(:,ii)
alpha(:,ii) = -parity*alpha(:,ii)
end do
ovlp = ovlp - MATMUL(TRANSPOSE(CONJG(beta)),alpha)
max_err=smallest_real; row_max=-1; col_max=-1
mean_err=zero; mean_err2=zero
do jj=1,tdim
do ii=1,jj
err = ABS(ovlp(ii,jj))
if (ii==jj) err = ABS(err - one)
mean_err = mean_err + err
mean_err2 = mean_err2 + err**2
if (err > max_err) then
max_err = err
row_max=ii
col_max=jj
end if
end do
end do
mean_err = mean_err/(tdim*(tdim+1)/2)
std_dev = mean_err2/(tdim*(tdim+1)/2) - mean_err**2
write(std_out,'(a,2(i0,1x),3es14.6)')&
& " Error in Hbar-ortho (i,j), max_err, mean, std_dev ",row_max,col_max,max_err,mean_err,std_dev
!call print_arr(ovlp,max_r=185,max_c=10,unit=std_out)
ABI_FREE(alpha)
ABI_FREE(beta)
ABI_FREE(ovlp)
ABI_FREE(save_phi)
end if
end subroutine haydock_psherm_optalgo
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_bilanczos
!! NAME
!! haydock_bilanczos
!!
!! FUNCTION
!! Reads the excitonic Hamiltonian from file and construct the Lanczos set of vectors
!! by iterative matrix-vector multiplications for any general matrix.
!!
!! INPUTS
!! BSp<type(excparam)>=Parameters defining the Bethe-Salpeter calculation.
!! omega(BSp%nomega)=Frequency mesh for the macroscopic dielectric function (broadening is already included).
!! hize
!! my_t1,my_t2
!! hreso(hsize,my_t1:my_t2)
!! hcoup(hsize,my_t1:my_t2)
!! nkets
!! kets(hsize,nkets)
!! comm=MPI communicator.
!!
!! OUTPUT
!! green(BSp%nomega)=The imaginary part of the macroscopic dielectric function.
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_bilanczos(BSp,BS_files,Cryst,Hdr_bse,hexc,hexc_i,hsize,my_t1,my_t2,nkets,kets,ep_renorms,green,comm)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: hsize,my_t1,my_t2,nkets,comm
type(crystal_t),intent(in) :: Cryst
type(excparam),intent(in) :: BSp
type(excfiles),intent(in) :: BS_files
type(Hdr_type),intent(in) :: Hdr_bse
!arrays
complex(dp),intent(out) :: green(BSp%nomega,BSp%nq)
complex(dpc),intent(in) :: kets(hsize,nkets)
complex(dpc),intent(in) :: ep_renorms(hsize)
!Local variables ------------------------------
!scalars
integer,parameter :: master=0
integer :: inn,itt,out_unt,nproc,my_rank,ierr
integer :: niter_file,niter_max,niter_done,nsppol,iq,my_nt,term_type,n_all_omegas
real(dp) :: ket0_hbar_norm,nfact,norm
logical :: can_restart,is_converged
complex(dpc) :: factor
character(len=fnlen),parameter :: tag_file="_HAYDC_SAVE"
character(len=500) :: msg
character(len=fnlen) :: restart_file,out_file
type(hexc_t),intent(in) :: hexc
type(hexc_interp_t),intent(in) :: hexc_i
!arrays
complex(dpc),allocatable :: aa_file(:),bb_file(:),cc_file(:)
complex(dpc),allocatable :: aa(:),bb(:),cc(:)
complex(dpc),allocatable :: phi_np1(:),phi_n(:),phi_nm1(:)
complex(dpc),allocatable :: phit_np1(:),phit_n(:),phit_nm1(:)
complex(dpc),allocatable :: cbuff(:), phi_n_file(:),phi_np1_file(:)
complex(dpc),allocatable :: ket0(:)
complex(dpc),allocatable :: hphi_n(:), hphit_n(:)
complex(dpc),allocatable :: all_omegas(:),green_temp(:,:)
logical :: check(2)
!************************************************************************
ABI_WARNING("Haydock with Bilanczos is still under development")
if(BSp%use_interp) then
ABI_ERROR("Bilanczos is not yet implemented with interpolation")
end if
nproc = xmpi_comm_size(comm)
my_rank= xmpi_comm_rank(comm)
nsppol = Hdr_bse%nsppol
my_nt = my_t2-my_t1+1
ABI_CHECK(my_nt>0,"One of the processors has zero columns")
! Multiplicative factor (k-point sampling and unit cell volume)
! TODO be careful with the spin here
! TODO four_pi comes from the coulomb term 1/|q| is already included in the
! oscillators hence the present approach wont work if a cutoff interaction is used.
nfact = four_pi/(Cryst%ucvol*BSp%nkbz)
if (nsppol==1) nfact=two*nfact
write(msg,'(a,i0)')' Bi-Lanczos algorithm with MAX number of iterations: ',BSp%niter
call wrtout(std_out,msg,"COLL")
!
! Check for presence of the restart file.
can_restart=.FALSE.
if ( BS_files%in_haydock_basename /= BSE_NOFILE) then
restart_file = strcat(BS_files%in_haydock_basename,tag_file)
if (file_exists(restart_file) ) then
can_restart=.TRUE.
msg = strcat(" Restarting Haydock calculation from file: ",restart_file)
call wrtout(std_out,msg,"COLL")
call wrtout(ab_out,msg,"COLL")
ABI_ERROR("Restart is not implemented")
else
can_restart=.FALSE.
ABI_WARNING(strcat("Cannot find restart file: ",restart_file))
end if
end if
!
! Open the file and writes basic dimensions and info.
if (my_rank==master) then
out_file = TRIM(BS_files%out_basename)//TRIM(tag_file)
if (open_file(out_file,msg,newunit=out_unt,form="unformatted") /= 0) then
ABI_ERROR(msg)
end if
! write header TODO: standardize this part.
write(out_unt)hsize,Bsp%use_coupling,BSE_HAYD_IMEPS,nkets,Bsp%broad
end if
!
! Select the terminator for the continued fraction.
term_type=0 !; if (Bsp%hayd_term>0) term_type=2
call wrtout(std_out,sjoin("Using terminator type: ",itoa(term_type)),"COLL")
!
! Calculate green(w) for the different starting kets.
green=czero
do iq=1,nkets
ABI_MALLOC(ket0,(hexc%hsize))
ket0 = kets(:,iq)
!
niter_file=0
if (can_restart) then
! call haydock_restart(BSp,restart_file,BSE_HAYD_IMEPS,iq,hsize,&
!& niter_file,aa_file,bb_file,phi_np1_file,phi_n_file,comm)
end if
!
ABI_MALLOC(phi_nm1,(my_nt))
ABI_MALLOC(phi_n,(my_nt))
ABI_MALLOC(phi_np1,(my_nt))
ABI_MALLOC(phit_nm1,(my_nt))
ABI_MALLOC(phit_n,(my_nt))
ABI_MALLOC(phit_np1,(my_nt))
ABI_MALLOC(hphi_n,(hexc%hsize))
ABI_MALLOC(hphit_n,(hexc%hsize))
!
! TODO: Note the different convention used for the coefficients
! Should use the same convention in the Hermitian case.
niter_max = niter_file + Bsp%niter
ABI_MALLOC(aa,(niter_max))
ABI_MALLOC(bb,(niter_max))
ABI_MALLOC(cc,(niter_max))
aa=czero; bb=czero; cc=czero
if (niter_file==0) then ! Calculation from scratch.
phi_nm1 = ket0(my_t1:my_t2)
phit_nm1 = ket0(my_t1:my_t2)
norm = DZNRM2(hexc%hsize,ket0,1)
phi_nm1=phi_nm1/norm
phit_nm1=phit_nm1/norm
call hexc_matmul_elphon(hexc,phi_nm1,hphi_n,'N',ep_renorms)
call hexc_matmul_elphon(hexc,phit_nm1,hphit_n,'C',ep_renorms)
aa(1)=xdotc(my_nt,phit_nm1,1,hphi_n(my_t1:),1)
call xmpi_sum(aa(1:1),comm,ierr)
phi_n = hphi_n(my_t1:my_t2) - aa(1)*phi_nm1
phit_n = hphit_n(my_t1:my_t2) - CONJG(aa(1))*phit_nm1
bb(1)=xdotc(my_nt,phi_n,1,phi_n,1)
call xmpi_sum(bb(1:1),comm,ierr)
bb(1) = SQRT(bb(1))
cc(1)=xdotc(my_nt,phit_n,1,phi_n,1)
call xmpi_sum(cc(1:1),comm,ierr)
cc(1) = cc(1)/bb(1)
phi_n = phi_n /bb(1)
phit_n = phit_n /CONJG(cc(1))
niter_done=1 ! TODO Be careful here
else ! Use the previously calculates a and b.
niter_done=niter_file
ABI_ERROR("Restart not coded")
!aa(1:niter_done) = aa_file
!bb(1:niter_done) = bb_file
!phi_np1=phi_np1_file(my_t1:my_t2) ! Select the slice treated by this node.
!phi_n =phi_n_file (my_t1:my_t2)
end if
if (can_restart) then
ABI_FREE(aa_file)
ABI_FREE(bb_file)
ABI_FREE(cc_file)
ABI_FREE(phi_np1_file)
ABI_FREE(phi_n_file)
end if
! This factor gives the correct results
factor = -nfact*(DZNRM2(hexc%hsize,ket0,1)**2)
! Which quantity should be checked for convergence?
check = (/.TRUE.,.TRUE./)
if (ABS(Bsp%haydock_tol(2)-one)<tol6) check = (/.TRUE. ,.FALSE./)
if (ABS(Bsp%haydock_tol(2)-two)<tol6) check = (/.FALSE.,.TRUE./)
! Create new frequencies "mirror" in negative range to add
! their contributions. Can be improved by computing only once
! zero frequency, but loosing clearness
n_all_omegas = 2*BSp%nomega
ABI_MALLOC(all_omegas,(n_all_omegas))
! Put all omegas with frequency > 0 in table
all_omegas(BSp%nomega+1:n_all_omegas) = BSp%omega
! Put all omegas with frequency < 0
! Warning, the broadening must be kept positive
all_omegas(1:BSp%nomega) = -DBLE(BSp%omega(BSp%nomega:1:-1)) + j_dpc*AIMAG(BSp%omega(BSp%nomega:1:-1))
ABI_MALLOC(green_temp,(n_all_omegas,nkets))
call haydock_bilanczos_optalgo(niter_done,niter_max,n_all_omegas,all_omegas,BSp%haydock_tol(1),check,hexc,hexc_i,&
& hsize,my_t1,my_t2,factor,term_type,ep_renorms,aa,bb,cc,ket0,ket0_hbar_norm,phi_nm1,phi_n,phi_np1,&
& phit_nm1,phit_n,phit_np1,green_temp(:,iq),inn,is_converged,comm)
! Computing result from two ranges of frequencies
! The real part is added, the imaginary part is substracted
green(:,iq) = green_temp(BSp%nomega+1:n_all_omegas,iq)+CONJG(green_temp(BSp%nomega:1:-1,iq))
ABI_FREE(all_omegas)
ABI_FREE(green_temp)
!
! Save the a"s and the b"s for possible restarting.
! 1) Info on the Q.
! 2) Number of iterations performed.
! 3) do iter=1,niter_performed
! aa(iter),bb(iter)
! end do
! 4) |n-1>
! |n>
! |n+1>
!
if (my_rank==master) then ! Open the file and writes basic dimensions and info.
write(out_unt)Bsp%q(:,iq)
write(out_unt)MIN(inn,niter_max) ! NB: if the previous loop completed inn=niter_max+1
do itt=1,MIN(inn,niter_max) ! if we exited then inn is not incremented by one.
write(out_unt)itt,aa(itt),bb(itt)
end do
end if
!
! cbuff is used as workspace to gather |n-1>, |n> and |n+1>.
ABI_MALLOC(cbuff,(hsize))
cbuff=czero; cbuff(my_t1:my_t2) = phi_nm1
call xmpi_sum_master(cbuff,master,comm,ierr)
if (my_rank==master) write(out_unt) cbuff ! |n-1>
cbuff=czero; cbuff(my_t1:my_t2) = phi_n
call xmpi_sum_master(cbuff,master,comm,ierr)
if (my_rank==master) write(out_unt) cbuff ! |n>
cbuff=czero; cbuff(my_t1:my_t2) = phi_np1
call xmpi_sum_master(cbuff,master,comm,ierr)
if (my_rank==master) write(out_unt) cbuff ! |n+1>
ABI_FREE(phi_nm1)
ABI_FREE(phi_n)
ABI_FREE(phi_np1)
ABI_FREE(phit_nm1)
ABI_FREE(phit_n)
ABI_FREE(phit_np1)
ABI_FREE(hphi_n)
ABI_FREE(hphit_n)
ABI_FREE(cbuff)
ABI_FREE(aa)
ABI_FREE(bb)
ABI_FREE(cc)
ABI_FREE(ket0)
end do ! iq
if (my_rank==master) close(out_unt)
call xmpi_barrier(comm)
end subroutine haydock_bilanczos
!!***
!----------------------------------------------------------------------
!!****f* m_haydock/haydock_bilanczos_optalgo
!! NAME
!! haydock_bilanczos_optalgo
!!
!! FUNCTION
!! Haydock algorithm for general matrix
!!
!! INPUTS
!! niter_done=Number of iterations already performed (0 if the run starts from scratch).
!! niter_tot=Max number of iterations. Always > niter_done
!! nomega=Number of Frequency points for the evaluation of the matrix element.
!! omega(nomega)=Frequency set (imaginary part is already included).
!! tol_iter=Tollerance used to stop the the algorithm.
!! check(2)=Logical flags to specify where both the real and the imaginary part of the
!! matrix elements of the Green functions have to be checked for convergence.
!! hsize=Size of the blocks.
!! my_t1,my_t2=Indeces of the first and last column stored treated by this done.
!! term_type=0 if no terminator is used, 1 otherwise.
!! hreso(hsize,my_t1:my_t2)=The columns of the resonant block.
!! hcoup(hsize,my_t1:my_t2)=The columns of the coupling block.
!! factor
!! comm=MPI communicator.
!!
!! OUTPUT
!! green(nomega)=Output matrix elements.
!! inn=Last iteration performed.
!! is_converged=.TRUE. of the algorithm converged.
!!
!! SIDE EFFECTS
!! phi_nm1(my_t2-my_t1+1), phi_n(my_t2-my_t1+1)
!! input: vectors used to initialize the iteration
!! output: the vectors obtained in the last iteration
!! aa(niter_tot) and bb(niter_tot+1)
!! if niter_done>0: aa(1:niter_done), bb(1:niter_done) store the coefficients of the previous run.
!! when the routine returns aa(1:inn) and bb(1:inn) contain the matrix elements of the tridiagonal form.
!! cc(niter_tot+1)
!!
!! PARENTS
!! m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine haydock_bilanczos_optalgo(niter_done,niter_tot,nomega,omega,tol_iter,check,hexc,hexc_i,hsize,my_t1,my_t2,&
& factor,term_type,ep_renorms,aa,bb,cc,ket0,ket0_hbar_norm,phi_nm1,phi_n,phi_np1,phit_nm1,phit_n,phit_np1,&
& green,inn,is_converged,comm)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: niter_tot,niter_done,nomega,comm,hsize,my_t1,my_t2,term_type
integer,intent(out) :: inn
logical,intent(out) :: is_converged
real(dp),intent(in) :: tol_iter,ket0_hbar_norm
complex(dpc),intent(in) :: factor
type(hexc_t),intent(in) :: hexc
type(hexc_interp_t),intent(in) :: hexc_i
!arrays
complex(dpc),intent(inout) :: bb(niter_tot+1)
complex(dpc),intent(out) :: green(nomega)
complex(dpc),intent(in) :: omega(nomega)
complex(dpc),intent(inout) :: aa(niter_tot),cc(niter_tot+1)
complex(dpc),intent(in) :: ket0(my_t2-my_t1+1)
complex(dpc),intent(in) :: ep_renorms(hsize)
complex(dpc),intent(inout) :: phi_nm1(my_t2-my_t1+1)
complex(dpc),intent(inout) :: phi_n (my_t2-my_t1+1)
complex(dpc),intent(inout) :: phi_np1(my_t2-my_t1+1)
complex(dpc),intent(inout) :: phit_nm1(my_t2-my_t1+1)
complex(dpc),intent(inout) :: phit_n (my_t2-my_t1+1)
complex(dpc),intent(inout) :: phit_np1(my_t2-my_t1+1)
logical,intent(in) :: check(2)
!Local variables ------------------------------
!scalars
integer :: my_nt,niter_min,nconv !,ierr
character(len=500) :: msg
logical :: keep_vectors=.TRUE.
!arrays
real(dp) :: abs_err(nomega,2) !,ww_err(nomega,2)
complex(dpc),allocatable :: oldg(:),newg(:)
complex(dpc),allocatable :: hphi_np1(:),hphit_np1(:),save_phi(:,:),save_phit(:,:)
complex(dpc),allocatable :: g00(:)
logical :: test(2)
integer :: ierr
!************************************************************************
ABI_UNUSED(ket0_hbar_norm)
ABI_UNUSED(ket0(1))
ABI_UNUSED(hexc_i%hsize_dense)
my_nt = my_t2-my_t1+1
ABI_MALLOC(oldg,(nomega))
ABI_MALLOC(newg,(nomega))
ABI_MALLOC(g00,(nomega))
oldg=czero; newg=czero; g00=czero
nconv=0
keep_vectors = (keep_vectors.and.xmpi_comm_size(comm)==1)
if (keep_vectors) then
ABI_MALLOC(save_phi,(my_t2-my_t1+1,niter_tot))
ABI_MALLOC_OR_DIE(save_phit,(my_t2-my_t1+1,niter_tot),ierr)
save_phi=czero
save_phit=czero
end if
ABI_MALLOC_OR_DIE(hphi_np1,(hexc%hsize),ierr)
ABI_MALLOC_OR_DIE(hphit_np1,(hexc%hsize),ierr)
do inn=niter_done+1,niter_tot
!|n+1> = H |n> using all eh components.
call hexc_matmul_elphon(hexc, phi_n, hphi_np1, 'N', ep_renorms)
call hexc_matmul_elphon(hexc, phit_n, hphit_np1, 'C', ep_renorms)
! a(n) = < phit_n | H | phi_n >
aa(inn)=xdotc(my_nt,phit_n,1,hphi_np1(my_t1:),1)
call xmpi_sum(aa(inn),comm,ierr)
! |n+1> = |n+1> - a(n)|Vn> - c(n)|n-1>
phi_np1 = hphi_np1(my_t1:my_t2) - aa(inn)*phi_n - cc(inn-1)*phi_nm1
phit_np1 = hphit_np1(my_t1:my_t2) - CONJG(aa(inn))*phit_n - CONJG(bb(inn-1))*phit_nm1
bb(inn) = xdotc(my_nt,phi_np1,1,phi_np1,1)
call xmpi_sum(bb(inn),comm,ierr)
bb(inn) = SQRT(bb(inn))
cc(inn) = xdotc(my_nt,phit_np1,1,phi_np1,1)
call xmpi_sum(cc(inn),comm,ierr)
cc(inn) = cc(inn)/bb(inn)
phi_np1 = phi_np1 / bb(inn)
phit_np1 = phit_np1 / CONJG(cc(inn))
!
! |n-1> = |n>
! |n> = |n+1>
phi_nm1 = phi_n
phi_n = phi_np1
phit_nm1 = phit_n
phit_n = phit_np1
if (keep_vectors) then
save_phi(:,inn) = phi_n
save_phit(:,inn) = phit_n
end if
write(msg,'(a,i0,a,3es12.4)')' Iteration number ',inn,', b_i RE(c_i) IM(c_i) ',REAL(bb(inn)),REAL(cc(inn)),AIMAG(cc(inn))
call wrtout(std_out,msg,"COLL")
call continued_fract_general(inn,term_type,aa,bb,cc,nomega,omega,g00)
newg = factor*g00
!
! Avoid spurious convergence.
niter_min=4; if (niter_done>1) niter_min=niter_done+1
if (inn>niter_min) then
test=.TRUE.
abs_err(:,1) = ABS(DBLE (newg-oldg))
abs_err(:,2) = ABS(AIMAG(newg-oldg))
!
if (tol_iter>zero) then
! Test on the L1 norm.
if (check(1)) test(1) = SUM(abs_err(:,1)) < tol_iter*SUM(ABS(DBLE (newg)))
if (check(2)) test(2) = SUM(abs_err(:,2)) < tol_iter*SUM(ABS(AIMAG(newg)))
else
! Stringent test for each point.
if (check(1)) test(1) = ALL( abs_err(:,1) < -tol_iter*ABS(DBLE (newg)))
if (check(2)) test(2) = ALL( abs_err(:,2) < -tol_iter*ABS(AIMAG(newg)))
end if
!
if (ALL(test)) then
nconv = nconv+1
else
nconv = 0
end if
if (nconv==2) then
if(inn<100)then
write(msg,'(a,es10.2,a)')&
& " >>> Haydock algorithm converged twice within haydock_tol= ",tol_iter," after less than 100 iterations."
else
write(msg,'(a,es10.2,a,i0,a)')&
& " >>> Haydock algorithm converged twice within haydock_tol= ",tol_iter," after ",inn," iterations."
endif
call wrtout(std_out,msg,'COLL')
call wrtout(ab_out,msg,'COLL')
EXIT
end if
end if
!
oldg = newg
end do ! inn
green = newg
if (nconv/=2) then
write(msg,'(a,es10.2,a,i0,a)')&
& " WARNING: Haydock algorithm did not converge within ",tol_iter," after ",niter_tot," iterations."
call wrtout(std_out,msg,'COLL')
call wrtout(ab_out,msg,'COLL')
end if
is_converged = (nconv==2)
ABI_FREE(oldg)
ABI_FREE(newg)
ABI_FREE(g00)
ABI_FREE(hphi_np1)
ABI_FREE(hphit_np1)
if (keep_vectors) then
ABI_FREE(save_phi)
ABI_FREE(save_phit)
end if
!! if (keep_vectors) then
!! tdim = MIN(inn,niter_tot)
!! ABI_MALLOC(ovlp,(tdim,tdim))
!! ABI_MALLOC(phi_test,(hsize))
!! ABI_MALLOC(phi_test2,(hsize))
!! max_err=smallest_real; mean_err=zero; mean_err2=zero; row_max=-1
!! do ii=1,tdim
!! parity = (-1)**(ii+1)
!! phi_test = save_phi(:,ii)
!! call hexc_matmul_full(hexc, hexc_i, phi_test, phi_test2, parity)
!! !phi_test2 = MATMUL(hreso,phi_test) + parity * MATMUL(hcoup,CONJG(phi_test))
!! ovlp(ii,ii) = DOT_PRODUCT(phi_test,phi_test2) + DOT_PRODUCT(phi_test2,phi_test)
!! err = ABS(ovlp(ii,ii)-cone)
!! mean_err = mean_err + err
!! mean_err2 = mean_err2 + err**2
!! if (err > max_err) then
!! max_err = err
!! row_max = ii
!! end if
!! end do
!! mean_err = mean_err/tdim
!! std_dev = mean_err2/tdim -mean_err**2
!! write(std_out,'(a,i0,1x,3es14.6)')&
!!& " Error in normalization (ii, max_err,mean,std_dev): ",row_max,max_err,mean_err,std_dev
!! ABI_FREE(phi_test)
!! ABI_FREE(phi_test2)
!!
!! ABI_MALLOC(alpha,(hsize,tdim))
!! ! Less efficient but for sake of simplicity with hexc_matmul
!! ! TODO possibility to call hreso * phi, and hcoup * phi separately
!! do ii=1,tdim
!! parity = (-1)**(ii+1)
!! call hexc_matmul_full(hexc, hexc_i, save_phi(:,ii), alpha(:,ii), parity)
!! end do
!! !alpha = MATMUL(hreso,save_phi(:,1:tdim))
!! !
!! !do ii=1,tdim
!! ! parity = (-1)**(ii+1)
!! ! alpha(:,ii) = alpha(:,ii) + parity*MATMUL(hcoup,CONJG(save_phi(:,ii)))
!! !end do
!! ovlp = MATMUL(TRANSPOSE(CONJG(save_phi(:,1:tdim))),alpha)
!! ABI_MALLOC(beta,(hsize,tdim))
!! do ii=1,tdim
!! parity = (-1)**(ii+1)
!! beta(:,ii) = parity*save_phi(:,ii)
!! alpha(:,ii) = -parity*alpha(:,ii)
!! end do
!! ovlp = ovlp - MATMUL(TRANSPOSE(CONJG(beta)),alpha)
!! max_err=smallest_real; row_max=-1; col_max=-1
!! mean_err=zero; mean_err2=zero
!! do jj=1,tdim
!! do ii=1,jj
!! err = ABS(ovlp(ii,jj))
!! if (ii==jj) err = ABS(err - one)
!! mean_err = mean_err + err
!! mean_err2 = mean_err2 + err**2
!! if (err > max_err) then
!! max_err = err
!! row_max=ii
!! col_max=jj
!! end if
!! end do
!! end do
!! mean_err = mean_err/(tdim*(tdim+1)/2)
!! std_dev = mean_err2/(tdim*(tdim+1)/2) - mean_err**2
!! write(std_out,'(a,2(i0,1x),3es14.6)')&
!! " Error in Hbar-ortho (i,j), max_err, mean, std_dev ",row_max,col_max,max_err,mean_err,std_dev
!! !call print_arr(ovlp,max_r=185,max_c=10,unit=std_out)
!! ABI_FREE(alpha)
!! ABI_FREE(beta)
!! ABI_FREE(ovlp)
!! ABI_FREE(save_phi)
!! end if
end subroutine haydock_bilanczos_optalgo
!!***
!----------------------------------------------------------------------
!!****f* m_numeric_tools/continued_fract_general
!! NAME
!! continued_fract
!!
!! FUNCTION
!! This routine calculates the continued fraction:
!!
!! 1
!! f(z) = _______________________________
!! z - a1 - b1^2
!! _____________________
!! z - a2 - b2^2
!! ___________
!! z -a3 - ........
!!
!! INPUTS
!! nlev=Number of "levels" in the continued fraction.
!! term_type=Type of the terminator.
!! 0 --> No terminator.
!! -1 --> Assume constant coefficients for a_i and b_i for i>nlev with a_inf = a(nlev) and b_inf = b(nleb)
!! 1 --> Same as above but a_inf and b_inf are obtained by averaging over the nlev values.
!! aa(nlev)=Set of a_i coefficients.
!! bb(nlev)=Set of b_i coefficients.
!! nz=Number of points on the z-mesh.
!! zpts(nz)=z-mesh.
!!
!! OUTPUT
!! spectrum(nz)=Contains f(z) on the input mesh.
!!
!! PARENTS
!! bsepostproc,m_haydock
!!
!! CHILDREN
!!
!! SOURCE
subroutine continued_fract_general(nlev,term_type,aa,bb,cc,nz,zpts,spectrum)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: nlev,term_type,nz
!arrays
complex(dpc),intent(in) :: bb(nlev)
complex(dpc),intent(in) :: cc(nlev)
complex(dpc),intent(in) :: aa(nlev)
complex(dpc),intent(in) :: zpts(nz)
complex(dpc),intent(out) :: spectrum(nz)
!Local variables ------------------------------
!scalars
integer :: it
complex(dpc) :: bb_inf,bg,bu,swap
complex(dpc) :: aa_inf
character(len=500) :: msg
!arrays
complex(dpc),allocatable :: div(:),den(:)
!************************************************************************
ABI_MALLOC(div,(nz))
ABI_MALLOC(den,(nz))
select case (term_type)
case (0) ! No terminator.
div=czero
case (-1,1)
ABI_ERROR("Not yet implemented")
if (term_type==-1) then
bb_inf=bb(nlev)
aa_inf=aa(nlev)
else
bb_inf=SUM(bb)/nlev
aa_inf=SUM(aa)/nlev
end if
! Be careful with the sign of the SQRT.
div(:) = half*(bb(nlev)/(bb_inf))**2 * ( zpts-aa_inf - SQRT((zpts-aa_inf)**2 - four*bb_inf**2) )
case (2)
ABI_ERROR("Not yet implemented")
div = zero
if (nlev>4) then
bg=zero; bu=zero
do it=1,nlev,2
if (it+2<nlev) bg = bg + bb(it+2)
bu = bu + bb(it)
end do
bg = bg/(nlev/2+MOD(nlev,2))
bu = bg/((nlev+1)/2)
!if (iseven(nlev)) then
if (.not.iseven(nlev)) then
swap = bg
bg = bu
bu = bg
end if
!write(std_out,*)nlev,bg,bu
!Here be careful with the sign of SQRT
do it=1,nz
div(it) = half/zpts(it) * (bb(nlev)/bu)**2 * &
& ( (zpts(it)**2 +bu**2 -bg**2) - SQRT( (zpts(it)**2+bu**2-bg**2)**2 -four*(zpts(it)*bu)**2) )
end do
end if
case default
write(msg,'(a,i0)')" Wrong value for term_type : ",term_type
ABI_ERROR(msg)
end select
do it=nlev,2,-1
den(:) = zpts(:) - aa(it) - div(:)
div(:) = (bb(it-1)*cc(it-1) )/ den(:)
end do
den = zpts(:) - aa(1) - div(:)
div = one/den(:)
spectrum = div
ABI_FREE(div)
ABI_FREE(den)
end subroutine continued_fract_general
!!***
!----------------------------------------------------------------------
end module m_haydock
!!***
| gpl-3.0 |
Sahloul/Eigen | blas/testing/cblat1.f | 245 | 31188 | PROGRAM CBLAT1
* Test program for the COMPLEX Level 1 BLAS.
* Based upon the original BLAS test routine together with:
* F06GAF Example Program Text
* .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
* .. Scalars in Common ..
INTEGER ICASE, INCX, INCY, MODE, N
LOGICAL PASS
* .. Local Scalars ..
REAL SFAC
INTEGER IC
* .. External Subroutines ..
EXTERNAL CHECK1, CHECK2, HEADER
* .. Common blocks ..
COMMON /COMBLA/ICASE, N, INCX, INCY, MODE, PASS
* .. Data statements ..
DATA SFAC/9.765625E-4/
* .. Executable Statements ..
WRITE (NOUT,99999)
DO 20 IC = 1, 10
ICASE = IC
CALL HEADER
*
* Initialize PASS, INCX, INCY, and MODE for a new case.
* The value 9999 for INCX, INCY or MODE will appear in the
* detailed output, if any, for cases that do not involve
* these parameters.
*
PASS = .TRUE.
INCX = 9999
INCY = 9999
MODE = 9999
IF (ICASE.LE.5) THEN
CALL CHECK2(SFAC)
ELSE IF (ICASE.GE.6) THEN
CALL CHECK1(SFAC)
END IF
* -- Print
IF (PASS) WRITE (NOUT,99998)
20 CONTINUE
STOP
*
99999 FORMAT (' Complex BLAS Test Program Results',/1X)
99998 FORMAT (' ----- PASS -----')
END
SUBROUTINE HEADER
* .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
* .. Scalars in Common ..
INTEGER ICASE, INCX, INCY, MODE, N
LOGICAL PASS
* .. Local Arrays ..
CHARACTER*6 L(10)
* .. Common blocks ..
COMMON /COMBLA/ICASE, N, INCX, INCY, MODE, PASS
* .. Data statements ..
DATA L(1)/'CDOTC '/
DATA L(2)/'CDOTU '/
DATA L(3)/'CAXPY '/
DATA L(4)/'CCOPY '/
DATA L(5)/'CSWAP '/
DATA L(6)/'SCNRM2'/
DATA L(7)/'SCASUM'/
DATA L(8)/'CSCAL '/
DATA L(9)/'CSSCAL'/
DATA L(10)/'ICAMAX'/
* .. Executable Statements ..
WRITE (NOUT,99999) ICASE, L(ICASE)
RETURN
*
99999 FORMAT (/' Test of subprogram number',I3,12X,A6)
END
SUBROUTINE CHECK1(SFAC)
* .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
* .. Scalar Arguments ..
REAL SFAC
* .. Scalars in Common ..
INTEGER ICASE, INCX, INCY, MODE, N
LOGICAL PASS
* .. Local Scalars ..
COMPLEX CA
REAL SA
INTEGER I, J, LEN, NP1
* .. Local Arrays ..
COMPLEX CTRUE5(8,5,2), CTRUE6(8,5,2), CV(8,5,2), CX(8),
+ MWPCS(5), MWPCT(5)
REAL STRUE2(5), STRUE4(5)
INTEGER ITRUE3(5)
* .. External Functions ..
REAL SCASUM, SCNRM2
INTEGER ICAMAX
EXTERNAL SCASUM, SCNRM2, ICAMAX
* .. External Subroutines ..
EXTERNAL CSCAL, CSSCAL, CTEST, ITEST1, STEST1
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Common blocks ..
COMMON /COMBLA/ICASE, N, INCX, INCY, MODE, PASS
* .. Data statements ..
DATA SA, CA/0.3E0, (0.4E0,-0.7E0)/
DATA ((CV(I,J,1),I=1,8),J=1,5)/(0.1E0,0.1E0),
+ (1.0E0,2.0E0), (1.0E0,2.0E0), (1.0E0,2.0E0),
+ (1.0E0,2.0E0), (1.0E0,2.0E0), (1.0E0,2.0E0),
+ (1.0E0,2.0E0), (0.3E0,-0.4E0), (3.0E0,4.0E0),
+ (3.0E0,4.0E0), (3.0E0,4.0E0), (3.0E0,4.0E0),
+ (3.0E0,4.0E0), (3.0E0,4.0E0), (3.0E0,4.0E0),
+ (0.1E0,-0.3E0), (0.5E0,-0.1E0), (5.0E0,6.0E0),
+ (5.0E0,6.0E0), (5.0E0,6.0E0), (5.0E0,6.0E0),
+ (5.0E0,6.0E0), (5.0E0,6.0E0), (0.1E0,0.1E0),
+ (-0.6E0,0.1E0), (0.1E0,-0.3E0), (7.0E0,8.0E0),
+ (7.0E0,8.0E0), (7.0E0,8.0E0), (7.0E0,8.0E0),
+ (7.0E0,8.0E0), (0.3E0,0.1E0), (0.1E0,0.4E0),
+ (0.4E0,0.1E0), (0.1E0,0.2E0), (2.0E0,3.0E0),
+ (2.0E0,3.0E0), (2.0E0,3.0E0), (2.0E0,3.0E0)/
DATA ((CV(I,J,2),I=1,8),J=1,5)/(0.1E0,0.1E0),
+ (4.0E0,5.0E0), (4.0E0,5.0E0), (4.0E0,5.0E0),
+ (4.0E0,5.0E0), (4.0E0,5.0E0), (4.0E0,5.0E0),
+ (4.0E0,5.0E0), (0.3E0,-0.4E0), (6.0E0,7.0E0),
+ (6.0E0,7.0E0), (6.0E0,7.0E0), (6.0E0,7.0E0),
+ (6.0E0,7.0E0), (6.0E0,7.0E0), (6.0E0,7.0E0),
+ (0.1E0,-0.3E0), (8.0E0,9.0E0), (0.5E0,-0.1E0),
+ (2.0E0,5.0E0), (2.0E0,5.0E0), (2.0E0,5.0E0),
+ (2.0E0,5.0E0), (2.0E0,5.0E0), (0.1E0,0.1E0),
+ (3.0E0,6.0E0), (-0.6E0,0.1E0), (4.0E0,7.0E0),
+ (0.1E0,-0.3E0), (7.0E0,2.0E0), (7.0E0,2.0E0),
+ (7.0E0,2.0E0), (0.3E0,0.1E0), (5.0E0,8.0E0),
+ (0.1E0,0.4E0), (6.0E0,9.0E0), (0.4E0,0.1E0),
+ (8.0E0,3.0E0), (0.1E0,0.2E0), (9.0E0,4.0E0)/
DATA STRUE2/0.0E0, 0.5E0, 0.6E0, 0.7E0, 0.7E0/
DATA STRUE4/0.0E0, 0.7E0, 1.0E0, 1.3E0, 1.7E0/
DATA ((CTRUE5(I,J,1),I=1,8),J=1,5)/(0.1E0,0.1E0),
+ (1.0E0,2.0E0), (1.0E0,2.0E0), (1.0E0,2.0E0),
+ (1.0E0,2.0E0), (1.0E0,2.0E0), (1.0E0,2.0E0),
+ (1.0E0,2.0E0), (-0.16E0,-0.37E0), (3.0E0,4.0E0),
+ (3.0E0,4.0E0), (3.0E0,4.0E0), (3.0E0,4.0E0),
+ (3.0E0,4.0E0), (3.0E0,4.0E0), (3.0E0,4.0E0),
+ (-0.17E0,-0.19E0), (0.13E0,-0.39E0),
+ (5.0E0,6.0E0), (5.0E0,6.0E0), (5.0E0,6.0E0),
+ (5.0E0,6.0E0), (5.0E0,6.0E0), (5.0E0,6.0E0),
+ (0.11E0,-0.03E0), (-0.17E0,0.46E0),
+ (-0.17E0,-0.19E0), (7.0E0,8.0E0), (7.0E0,8.0E0),
+ (7.0E0,8.0E0), (7.0E0,8.0E0), (7.0E0,8.0E0),
+ (0.19E0,-0.17E0), (0.32E0,0.09E0),
+ (0.23E0,-0.24E0), (0.18E0,0.01E0),
+ (2.0E0,3.0E0), (2.0E0,3.0E0), (2.0E0,3.0E0),
+ (2.0E0,3.0E0)/
DATA ((CTRUE5(I,J,2),I=1,8),J=1,5)/(0.1E0,0.1E0),
+ (4.0E0,5.0E0), (4.0E0,5.0E0), (4.0E0,5.0E0),
+ (4.0E0,5.0E0), (4.0E0,5.0E0), (4.0E0,5.0E0),
+ (4.0E0,5.0E0), (-0.16E0,-0.37E0), (6.0E0,7.0E0),
+ (6.0E0,7.0E0), (6.0E0,7.0E0), (6.0E0,7.0E0),
+ (6.0E0,7.0E0), (6.0E0,7.0E0), (6.0E0,7.0E0),
+ (-0.17E0,-0.19E0), (8.0E0,9.0E0),
+ (0.13E0,-0.39E0), (2.0E0,5.0E0), (2.0E0,5.0E0),
+ (2.0E0,5.0E0), (2.0E0,5.0E0), (2.0E0,5.0E0),
+ (0.11E0,-0.03E0), (3.0E0,6.0E0),
+ (-0.17E0,0.46E0), (4.0E0,7.0E0),
+ (-0.17E0,-0.19E0), (7.0E0,2.0E0), (7.0E0,2.0E0),
+ (7.0E0,2.0E0), (0.19E0,-0.17E0), (5.0E0,8.0E0),
+ (0.32E0,0.09E0), (6.0E0,9.0E0),
+ (0.23E0,-0.24E0), (8.0E0,3.0E0),
+ (0.18E0,0.01E0), (9.0E0,4.0E0)/
DATA ((CTRUE6(I,J,1),I=1,8),J=1,5)/(0.1E0,0.1E0),
+ (1.0E0,2.0E0), (1.0E0,2.0E0), (1.0E0,2.0E0),
+ (1.0E0,2.0E0), (1.0E0,2.0E0), (1.0E0,2.0E0),
+ (1.0E0,2.0E0), (0.09E0,-0.12E0), (3.0E0,4.0E0),
+ (3.0E0,4.0E0), (3.0E0,4.0E0), (3.0E0,4.0E0),
+ (3.0E0,4.0E0), (3.0E0,4.0E0), (3.0E0,4.0E0),
+ (0.03E0,-0.09E0), (0.15E0,-0.03E0),
+ (5.0E0,6.0E0), (5.0E0,6.0E0), (5.0E0,6.0E0),
+ (5.0E0,6.0E0), (5.0E0,6.0E0), (5.0E0,6.0E0),
+ (0.03E0,0.03E0), (-0.18E0,0.03E0),
+ (0.03E0,-0.09E0), (7.0E0,8.0E0), (7.0E0,8.0E0),
+ (7.0E0,8.0E0), (7.0E0,8.0E0), (7.0E0,8.0E0),
+ (0.09E0,0.03E0), (0.03E0,0.12E0),
+ (0.12E0,0.03E0), (0.03E0,0.06E0), (2.0E0,3.0E0),
+ (2.0E0,3.0E0), (2.0E0,3.0E0), (2.0E0,3.0E0)/
DATA ((CTRUE6(I,J,2),I=1,8),J=1,5)/(0.1E0,0.1E0),
+ (4.0E0,5.0E0), (4.0E0,5.0E0), (4.0E0,5.0E0),
+ (4.0E0,5.0E0), (4.0E0,5.0E0), (4.0E0,5.0E0),
+ (4.0E0,5.0E0), (0.09E0,-0.12E0), (6.0E0,7.0E0),
+ (6.0E0,7.0E0), (6.0E0,7.0E0), (6.0E0,7.0E0),
+ (6.0E0,7.0E0), (6.0E0,7.0E0), (6.0E0,7.0E0),
+ (0.03E0,-0.09E0), (8.0E0,9.0E0),
+ (0.15E0,-0.03E0), (2.0E0,5.0E0), (2.0E0,5.0E0),
+ (2.0E0,5.0E0), (2.0E0,5.0E0), (2.0E0,5.0E0),
+ (0.03E0,0.03E0), (3.0E0,6.0E0),
+ (-0.18E0,0.03E0), (4.0E0,7.0E0),
+ (0.03E0,-0.09E0), (7.0E0,2.0E0), (7.0E0,2.0E0),
+ (7.0E0,2.0E0), (0.09E0,0.03E0), (5.0E0,8.0E0),
+ (0.03E0,0.12E0), (6.0E0,9.0E0), (0.12E0,0.03E0),
+ (8.0E0,3.0E0), (0.03E0,0.06E0), (9.0E0,4.0E0)/
DATA ITRUE3/0, 1, 2, 2, 2/
* .. Executable Statements ..
DO 60 INCX = 1, 2
DO 40 NP1 = 1, 5
N = NP1 - 1
LEN = 2*MAX(N,1)
* .. Set vector arguments ..
DO 20 I = 1, LEN
CX(I) = CV(I,NP1,INCX)
20 CONTINUE
IF (ICASE.EQ.6) THEN
* .. SCNRM2 ..
CALL STEST1(SCNRM2(N,CX,INCX),STRUE2(NP1),STRUE2(NP1),
+ SFAC)
ELSE IF (ICASE.EQ.7) THEN
* .. SCASUM ..
CALL STEST1(SCASUM(N,CX,INCX),STRUE4(NP1),STRUE4(NP1),
+ SFAC)
ELSE IF (ICASE.EQ.8) THEN
* .. CSCAL ..
CALL CSCAL(N,CA,CX,INCX)
CALL CTEST(LEN,CX,CTRUE5(1,NP1,INCX),CTRUE5(1,NP1,INCX),
+ SFAC)
ELSE IF (ICASE.EQ.9) THEN
* .. CSSCAL ..
CALL CSSCAL(N,SA,CX,INCX)
CALL CTEST(LEN,CX,CTRUE6(1,NP1,INCX),CTRUE6(1,NP1,INCX),
+ SFAC)
ELSE IF (ICASE.EQ.10) THEN
* .. ICAMAX ..
CALL ITEST1(ICAMAX(N,CX,INCX),ITRUE3(NP1))
ELSE
WRITE (NOUT,*) ' Shouldn''t be here in CHECK1'
STOP
END IF
*
40 CONTINUE
60 CONTINUE
*
INCX = 1
IF (ICASE.EQ.8) THEN
* CSCAL
* Add a test for alpha equal to zero.
CA = (0.0E0,0.0E0)
DO 80 I = 1, 5
MWPCT(I) = (0.0E0,0.0E0)
MWPCS(I) = (1.0E0,1.0E0)
80 CONTINUE
CALL CSCAL(5,CA,CX,INCX)
CALL CTEST(5,CX,MWPCT,MWPCS,SFAC)
ELSE IF (ICASE.EQ.9) THEN
* CSSCAL
* Add a test for alpha equal to zero.
SA = 0.0E0
DO 100 I = 1, 5
MWPCT(I) = (0.0E0,0.0E0)
MWPCS(I) = (1.0E0,1.0E0)
100 CONTINUE
CALL CSSCAL(5,SA,CX,INCX)
CALL CTEST(5,CX,MWPCT,MWPCS,SFAC)
* Add a test for alpha equal to one.
SA = 1.0E0
DO 120 I = 1, 5
MWPCT(I) = CX(I)
MWPCS(I) = CX(I)
120 CONTINUE
CALL CSSCAL(5,SA,CX,INCX)
CALL CTEST(5,CX,MWPCT,MWPCS,SFAC)
* Add a test for alpha equal to minus one.
SA = -1.0E0
DO 140 I = 1, 5
MWPCT(I) = -CX(I)
MWPCS(I) = -CX(I)
140 CONTINUE
CALL CSSCAL(5,SA,CX,INCX)
CALL CTEST(5,CX,MWPCT,MWPCS,SFAC)
END IF
RETURN
END
SUBROUTINE CHECK2(SFAC)
* .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
* .. Scalar Arguments ..
REAL SFAC
* .. Scalars in Common ..
INTEGER ICASE, INCX, INCY, MODE, N
LOGICAL PASS
* .. Local Scalars ..
COMPLEX CA
INTEGER I, J, KI, KN, KSIZE, LENX, LENY, MX, MY
* .. Local Arrays ..
COMPLEX CDOT(1), CSIZE1(4), CSIZE2(7,2), CSIZE3(14),
+ CT10X(7,4,4), CT10Y(7,4,4), CT6(4,4), CT7(4,4),
+ CT8(7,4,4), CX(7), CX1(7), CY(7), CY1(7)
INTEGER INCXS(4), INCYS(4), LENS(4,2), NS(4)
* .. External Functions ..
COMPLEX CDOTC, CDOTU
EXTERNAL CDOTC, CDOTU
* .. External Subroutines ..
EXTERNAL CAXPY, CCOPY, CSWAP, CTEST
* .. Intrinsic Functions ..
INTRINSIC ABS, MIN
* .. Common blocks ..
COMMON /COMBLA/ICASE, N, INCX, INCY, MODE, PASS
* .. Data statements ..
DATA CA/(0.4E0,-0.7E0)/
DATA INCXS/1, 2, -2, -1/
DATA INCYS/1, -2, 1, -2/
DATA LENS/1, 1, 2, 4, 1, 1, 3, 7/
DATA NS/0, 1, 2, 4/
DATA CX1/(0.7E0,-0.8E0), (-0.4E0,-0.7E0),
+ (-0.1E0,-0.9E0), (0.2E0,-0.8E0),
+ (-0.9E0,-0.4E0), (0.1E0,0.4E0), (-0.6E0,0.6E0)/
DATA CY1/(0.6E0,-0.6E0), (-0.9E0,0.5E0),
+ (0.7E0,-0.6E0), (0.1E0,-0.5E0), (-0.1E0,-0.2E0),
+ (-0.5E0,-0.3E0), (0.8E0,-0.7E0)/
DATA ((CT8(I,J,1),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.32E0,-1.41E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.32E0,-1.41E0),
+ (-1.55E0,0.5E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.32E0,-1.41E0), (-1.55E0,0.5E0),
+ (0.03E0,-0.89E0), (-0.38E0,-0.96E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0)/
DATA ((CT8(I,J,2),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.32E0,-1.41E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (-0.07E0,-0.89E0),
+ (-0.9E0,0.5E0), (0.42E0,-1.41E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.78E0,0.06E0), (-0.9E0,0.5E0),
+ (0.06E0,-0.13E0), (0.1E0,-0.5E0),
+ (-0.77E0,-0.49E0), (-0.5E0,-0.3E0),
+ (0.52E0,-1.51E0)/
DATA ((CT8(I,J,3),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.32E0,-1.41E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (-0.07E0,-0.89E0),
+ (-1.18E0,-0.31E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.78E0,0.06E0), (-1.54E0,0.97E0),
+ (0.03E0,-0.89E0), (-0.18E0,-1.31E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0)/
DATA ((CT8(I,J,4),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.32E0,-1.41E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.32E0,-1.41E0), (-0.9E0,0.5E0),
+ (0.05E0,-0.6E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.32E0,-1.41E0),
+ (-0.9E0,0.5E0), (0.05E0,-0.6E0), (0.1E0,-0.5E0),
+ (-0.77E0,-0.49E0), (-0.5E0,-0.3E0),
+ (0.32E0,-1.16E0)/
DATA CT7/(0.0E0,0.0E0), (-0.06E0,-0.90E0),
+ (0.65E0,-0.47E0), (-0.34E0,-1.22E0),
+ (0.0E0,0.0E0), (-0.06E0,-0.90E0),
+ (-0.59E0,-1.46E0), (-1.04E0,-0.04E0),
+ (0.0E0,0.0E0), (-0.06E0,-0.90E0),
+ (-0.83E0,0.59E0), (0.07E0,-0.37E0),
+ (0.0E0,0.0E0), (-0.06E0,-0.90E0),
+ (-0.76E0,-1.15E0), (-1.33E0,-1.82E0)/
DATA CT6/(0.0E0,0.0E0), (0.90E0,0.06E0),
+ (0.91E0,-0.77E0), (1.80E0,-0.10E0),
+ (0.0E0,0.0E0), (0.90E0,0.06E0), (1.45E0,0.74E0),
+ (0.20E0,0.90E0), (0.0E0,0.0E0), (0.90E0,0.06E0),
+ (-0.55E0,0.23E0), (0.83E0,-0.39E0),
+ (0.0E0,0.0E0), (0.90E0,0.06E0), (1.04E0,0.79E0),
+ (1.95E0,1.22E0)/
DATA ((CT10X(I,J,1),I=1,7),J=1,4)/(0.7E0,-0.8E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.6E0,-0.6E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.6E0,-0.6E0), (-0.9E0,0.5E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.6E0,-0.6E0),
+ (-0.9E0,0.5E0), (0.7E0,-0.6E0), (0.1E0,-0.5E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0)/
DATA ((CT10X(I,J,2),I=1,7),J=1,4)/(0.7E0,-0.8E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.6E0,-0.6E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.7E0,-0.6E0), (-0.4E0,-0.7E0),
+ (0.6E0,-0.6E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.8E0,-0.7E0),
+ (-0.4E0,-0.7E0), (-0.1E0,-0.2E0),
+ (0.2E0,-0.8E0), (0.7E0,-0.6E0), (0.1E0,0.4E0),
+ (0.6E0,-0.6E0)/
DATA ((CT10X(I,J,3),I=1,7),J=1,4)/(0.7E0,-0.8E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.6E0,-0.6E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (-0.9E0,0.5E0), (-0.4E0,-0.7E0),
+ (0.6E0,-0.6E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.1E0,-0.5E0),
+ (-0.4E0,-0.7E0), (0.7E0,-0.6E0), (0.2E0,-0.8E0),
+ (-0.9E0,0.5E0), (0.1E0,0.4E0), (0.6E0,-0.6E0)/
DATA ((CT10X(I,J,4),I=1,7),J=1,4)/(0.7E0,-0.8E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.6E0,-0.6E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.6E0,-0.6E0), (0.7E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.6E0,-0.6E0),
+ (0.7E0,-0.6E0), (-0.1E0,-0.2E0), (0.8E0,-0.7E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0)/
DATA ((CT10Y(I,J,1),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.7E0,-0.8E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.7E0,-0.8E0), (-0.4E0,-0.7E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.7E0,-0.8E0),
+ (-0.4E0,-0.7E0), (-0.1E0,-0.9E0),
+ (0.2E0,-0.8E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0)/
DATA ((CT10Y(I,J,2),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.7E0,-0.8E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (-0.1E0,-0.9E0), (-0.9E0,0.5E0),
+ (0.7E0,-0.8E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (-0.6E0,0.6E0),
+ (-0.9E0,0.5E0), (-0.9E0,-0.4E0), (0.1E0,-0.5E0),
+ (-0.1E0,-0.9E0), (-0.5E0,-0.3E0),
+ (0.7E0,-0.8E0)/
DATA ((CT10Y(I,J,3),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.7E0,-0.8E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (-0.1E0,-0.9E0), (0.7E0,-0.8E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (-0.6E0,0.6E0),
+ (-0.9E0,-0.4E0), (-0.1E0,-0.9E0),
+ (0.7E0,-0.8E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0)/
DATA ((CT10Y(I,J,4),I=1,7),J=1,4)/(0.6E0,-0.6E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.7E0,-0.8E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.7E0,-0.8E0), (-0.9E0,0.5E0),
+ (-0.4E0,-0.7E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.7E0,-0.8E0),
+ (-0.9E0,0.5E0), (-0.4E0,-0.7E0), (0.1E0,-0.5E0),
+ (-0.1E0,-0.9E0), (-0.5E0,-0.3E0),
+ (0.2E0,-0.8E0)/
DATA CSIZE1/(0.0E0,0.0E0), (0.9E0,0.9E0),
+ (1.63E0,1.73E0), (2.90E0,2.78E0)/
DATA CSIZE3/(0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (1.17E0,1.17E0),
+ (1.17E0,1.17E0), (1.17E0,1.17E0),
+ (1.17E0,1.17E0), (1.17E0,1.17E0),
+ (1.17E0,1.17E0), (1.17E0,1.17E0)/
DATA CSIZE2/(0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (0.0E0,0.0E0),
+ (0.0E0,0.0E0), (0.0E0,0.0E0), (1.54E0,1.54E0),
+ (1.54E0,1.54E0), (1.54E0,1.54E0),
+ (1.54E0,1.54E0), (1.54E0,1.54E0),
+ (1.54E0,1.54E0), (1.54E0,1.54E0)/
* .. Executable Statements ..
DO 60 KI = 1, 4
INCX = INCXS(KI)
INCY = INCYS(KI)
MX = ABS(INCX)
MY = ABS(INCY)
*
DO 40 KN = 1, 4
N = NS(KN)
KSIZE = MIN(2,KN)
LENX = LENS(KN,MX)
LENY = LENS(KN,MY)
* .. initialize all argument arrays ..
DO 20 I = 1, 7
CX(I) = CX1(I)
CY(I) = CY1(I)
20 CONTINUE
IF (ICASE.EQ.1) THEN
* .. CDOTC ..
CDOT(1) = CDOTC(N,CX,INCX,CY,INCY)
CALL CTEST(1,CDOT,CT6(KN,KI),CSIZE1(KN),SFAC)
ELSE IF (ICASE.EQ.2) THEN
* .. CDOTU ..
CDOT(1) = CDOTU(N,CX,INCX,CY,INCY)
CALL CTEST(1,CDOT,CT7(KN,KI),CSIZE1(KN),SFAC)
ELSE IF (ICASE.EQ.3) THEN
* .. CAXPY ..
CALL CAXPY(N,CA,CX,INCX,CY,INCY)
CALL CTEST(LENY,CY,CT8(1,KN,KI),CSIZE2(1,KSIZE),SFAC)
ELSE IF (ICASE.EQ.4) THEN
* .. CCOPY ..
CALL CCOPY(N,CX,INCX,CY,INCY)
CALL CTEST(LENY,CY,CT10Y(1,KN,KI),CSIZE3,1.0E0)
ELSE IF (ICASE.EQ.5) THEN
* .. CSWAP ..
CALL CSWAP(N,CX,INCX,CY,INCY)
CALL CTEST(LENX,CX,CT10X(1,KN,KI),CSIZE3,1.0E0)
CALL CTEST(LENY,CY,CT10Y(1,KN,KI),CSIZE3,1.0E0)
ELSE
WRITE (NOUT,*) ' Shouldn''t be here in CHECK2'
STOP
END IF
*
40 CONTINUE
60 CONTINUE
RETURN
END
SUBROUTINE STEST(LEN,SCOMP,STRUE,SSIZE,SFAC)
* ********************************* STEST **************************
*
* THIS SUBR COMPARES ARRAYS SCOMP() AND STRUE() OF LENGTH LEN TO
* SEE IF THE TERM BY TERM DIFFERENCES, MULTIPLIED BY SFAC, ARE
* NEGLIGIBLE.
*
* C. L. LAWSON, JPL, 1974 DEC 10
*
* .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
* .. Scalar Arguments ..
REAL SFAC
INTEGER LEN
* .. Array Arguments ..
REAL SCOMP(LEN), SSIZE(LEN), STRUE(LEN)
* .. Scalars in Common ..
INTEGER ICASE, INCX, INCY, MODE, N
LOGICAL PASS
* .. Local Scalars ..
REAL SD
INTEGER I
* .. External Functions ..
REAL SDIFF
EXTERNAL SDIFF
* .. Intrinsic Functions ..
INTRINSIC ABS
* .. Common blocks ..
COMMON /COMBLA/ICASE, N, INCX, INCY, MODE, PASS
* .. Executable Statements ..
*
DO 40 I = 1, LEN
SD = SCOMP(I) - STRUE(I)
IF (SDIFF(ABS(SSIZE(I))+ABS(SFAC*SD),ABS(SSIZE(I))).EQ.0.0E0)
+ GO TO 40
*
* HERE SCOMP(I) IS NOT CLOSE TO STRUE(I).
*
IF ( .NOT. PASS) GO TO 20
* PRINT FAIL MESSAGE AND HEADER.
PASS = .FALSE.
WRITE (NOUT,99999)
WRITE (NOUT,99998)
20 WRITE (NOUT,99997) ICASE, N, INCX, INCY, MODE, I, SCOMP(I),
+ STRUE(I), SD, SSIZE(I)
40 CONTINUE
RETURN
*
99999 FORMAT (' FAIL')
99998 FORMAT (/' CASE N INCX INCY MODE I ',
+ ' COMP(I) TRUE(I) DIFFERENCE',
+ ' SIZE(I)',/1X)
99997 FORMAT (1X,I4,I3,3I5,I3,2E36.8,2E12.4)
END
SUBROUTINE STEST1(SCOMP1,STRUE1,SSIZE,SFAC)
* ************************* STEST1 *****************************
*
* THIS IS AN INTERFACE SUBROUTINE TO ACCOMODATE THE FORTRAN
* REQUIREMENT THAT WHEN A DUMMY ARGUMENT IS AN ARRAY, THE
* ACTUAL ARGUMENT MUST ALSO BE AN ARRAY OR AN ARRAY ELEMENT.
*
* C.L. LAWSON, JPL, 1978 DEC 6
*
* .. Scalar Arguments ..
REAL SCOMP1, SFAC, STRUE1
* .. Array Arguments ..
REAL SSIZE(*)
* .. Local Arrays ..
REAL SCOMP(1), STRUE(1)
* .. External Subroutines ..
EXTERNAL STEST
* .. Executable Statements ..
*
SCOMP(1) = SCOMP1
STRUE(1) = STRUE1
CALL STEST(1,SCOMP,STRUE,SSIZE,SFAC)
*
RETURN
END
REAL FUNCTION SDIFF(SA,SB)
* ********************************* SDIFF **************************
* COMPUTES DIFFERENCE OF TWO NUMBERS. C. L. LAWSON, JPL 1974 FEB 15
*
* .. Scalar Arguments ..
REAL SA, SB
* .. Executable Statements ..
SDIFF = SA - SB
RETURN
END
SUBROUTINE CTEST(LEN,CCOMP,CTRUE,CSIZE,SFAC)
* **************************** CTEST *****************************
*
* C.L. LAWSON, JPL, 1978 DEC 6
*
* .. Scalar Arguments ..
REAL SFAC
INTEGER LEN
* .. Array Arguments ..
COMPLEX CCOMP(LEN), CSIZE(LEN), CTRUE(LEN)
* .. Local Scalars ..
INTEGER I
* .. Local Arrays ..
REAL SCOMP(20), SSIZE(20), STRUE(20)
* .. External Subroutines ..
EXTERNAL STEST
* .. Intrinsic Functions ..
INTRINSIC AIMAG, REAL
* .. Executable Statements ..
DO 20 I = 1, LEN
SCOMP(2*I-1) = REAL(CCOMP(I))
SCOMP(2*I) = AIMAG(CCOMP(I))
STRUE(2*I-1) = REAL(CTRUE(I))
STRUE(2*I) = AIMAG(CTRUE(I))
SSIZE(2*I-1) = REAL(CSIZE(I))
SSIZE(2*I) = AIMAG(CSIZE(I))
20 CONTINUE
*
CALL STEST(2*LEN,SCOMP,STRUE,SSIZE,SFAC)
RETURN
END
SUBROUTINE ITEST1(ICOMP,ITRUE)
* ********************************* ITEST1 *************************
*
* THIS SUBROUTINE COMPARES THE VARIABLES ICOMP AND ITRUE FOR
* EQUALITY.
* C. L. LAWSON, JPL, 1974 DEC 10
*
* .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
* .. Scalar Arguments ..
INTEGER ICOMP, ITRUE
* .. Scalars in Common ..
INTEGER ICASE, INCX, INCY, MODE, N
LOGICAL PASS
* .. Local Scalars ..
INTEGER ID
* .. Common blocks ..
COMMON /COMBLA/ICASE, N, INCX, INCY, MODE, PASS
* .. Executable Statements ..
IF (ICOMP.EQ.ITRUE) GO TO 40
*
* HERE ICOMP IS NOT EQUAL TO ITRUE.
*
IF ( .NOT. PASS) GO TO 20
* PRINT FAIL MESSAGE AND HEADER.
PASS = .FALSE.
WRITE (NOUT,99999)
WRITE (NOUT,99998)
20 ID = ICOMP - ITRUE
WRITE (NOUT,99997) ICASE, N, INCX, INCY, MODE, ICOMP, ITRUE, ID
40 CONTINUE
RETURN
*
99999 FORMAT (' FAIL')
99998 FORMAT (/' CASE N INCX INCY MODE ',
+ ' COMP TRUE DIFFERENCE',
+ /1X)
99997 FORMAT (1X,I4,I3,3I5,2I36,I12)
END
| bsd-3-clause |
mom-ocean/MOM5 | src/atmos_param/shallow_cu/conv_closures.F90 | 7 | 15051 |
MODULE CONV_CLOSURES_MOD
! use Sat_Vapor_Pres_Mod, ONLY: ESCOMP, DESCOMP
! use Constants_Mod, ONLY: tfreeze,HLv,HLf,HLs,CP_AIR,GRAV,Kappa,rdgas,rvgas
use fms_mod, only: write_version_number
use conv_utilities_k_mod,only: sd_copy_k, adi_cloud_k, extend_sd_k,&
adicloud, sounding, uw_params
use conv_plumes_k_mod, only: cumulus_plume_k, cumulus_tend_k, &
cplume, ctend, cpnlist
!---------------------------------------------------------------------
implicit none
private
!---------------------------------------------------------------------
!----------- ****** VERSION NUMBER ******* ---------------------------
character(len=128) :: version = '$Id: conv_closures.F90,v 19.0 2012/01/06 20:25:26 fms Exp $'
character(len=128) :: tagname = '$Name: tikal $'
logical :: module_is_initialized=.false. ! module initialized ?
!---------------------------------------------------------------------
!------- interfaces --------
public :: cclosure_bretherton, cclosure_relaxcbmf, cclosure_emanuel, &
cclosure_implicit, cclosure_relaxwfn, &
conv_closures_init, conv_closures_end
character(len=11) :: mod_name = 'conv_closures'
public cclosure
type cclosure
real :: cbmf, wrel, ufrc, scaleh, dcin, dcape, dwfn, wfn
integer :: igauss
real :: rkfre, rmaxfrac, rbuoy, tau_sh, tau_dp, wcrit_min
real :: maxcldfrac
end type cclosure
contains
!#####################################################################
!#####################################################################
function erfccc(x)
!--------------------------------------------------------------
! This numerical recipes routine calculates the complementary
! error function.
!--------------------------------------------------------------
real :: erfccc
real, intent(in) :: x
real :: t,z
z=abs(x)
t=1./(1.+0.5*z)
erfccc=t*exp(-z*z-1.26551223+t*(1.00002368+t*(.37409196+t* &
(.09678418+t*(-.18628806+t*(.27886807+t*(-1.13520398+t* &
(1.48851587+t*(-.82215223+t*.17087277)))))))))
if (x.lt.0.) erfccc=2.-erfccc
end function erfccc
!#####################################################################
!#####################################################################
subroutine solvecbmf(alpha, beta, x)
!Newton iteration solving Eq. x = beta * exp (-alpha * x)
implicit none
real, intent(in) :: alpha, beta
real, intent(inout) :: x
integer :: iteration, niteration=5, id_check
real :: dydx, x0, y0
x0=1.
do iteration = 1,niteration
y0 = x0 - beta * exp(-alpha * x0)
dydx = 1. + beta * alpha * exp(-alpha * x0)
x0 = x0 - y0 / dydx
if (abs(y0) < 0.0001) then
x=x0; id_check=0
else
id_check=1
end if
end do
if (id_check==1) then
x=1.
print*, 'ID_CHECK=1, in solvecbmfffffffffffff'
endif
end subroutine solvecbmf
!#####################################################################
!#####################################################################
subroutine cclosure_bretherton(tkeavg, cpn, sd, Uw_p, ac, cc, &
cbmf_unmod)
implicit none
real, intent(in) :: tkeavg
type(cpnlist), intent(in) :: cpn
type(sounding), intent(in) :: sd
type(uw_params), intent(inout) :: Uw_p
type(adicloud), intent(in) :: ac
type(cclosure), intent(inout) :: cc
real, intent(out), optional :: cbmf_unmod
real :: sigmaw, wcrit, erfarg, cbmf, wexp, ufrc, wtw
real :: rmfk1=0.3, rmfk2=5.0, rmfk3=3.0
cc%cbmf=0.; cc%wrel=0.; cc%ufrc=0.;
if(cc%igauss.eq.0)then !Use cin and pbl tke
cbmf = rmfk1* ac % rho0lcl * sqrt(tkeavg) * exp(-rmfk2* ac % cin/tkeavg)
wexp = rmfk3* sqrt(tkeavg) !Updraft vertical velocity at release height depends on tke
elseif(cc%igauss.eq.1)then !Use cin and gaussian distribution of w
wcrit = sqrt(2. * ac % cin * cc%rbuoy)
sigmaw = sqrt(cc%rkfre * tkeavg)
wcrit = max(wcrit, cc%wcrit_min*sigmaw)
cbmf = ac % rho0lcl * sigmaw / 2.5066 * exp(-0.5*((wcrit/sigmaw)**2.))
if (present (cbmf_unmod)) then
cbmf_unmod = MAX(0.0, cbmf)
endif
!Diagnose updraft fraction sqrt(2.) = 1.4142
erfarg=wcrit / (1.4142 * sigmaw)
if(erfarg.lt.20.)then
ufrc = min(cc%maxcldfrac, cc%rmaxfrac, 0.5*erfccc(erfarg))
else
ufrc = 0.
endif
if(ufrc.gt.0.0) then !Diagnose expected value of cloud base vertical velocity
wexp = cbmf / ac % rho0lcl / ufrc
else
wexp = 0.
cbmf = 0.
endif
endif
wtw = wexp * wexp - 2 * ac % cin * cc%rbuoy !used for the runs of xx-hv1_amip and tropical storm
if(wtw.le.0.) then
cc%wrel=0.;
else
cc%wrel=sqrt(wtw)
end if
cc%cbmf=cbmf
cc%wrel=min(cc%wrel, 50.)!cc%ufrc=min(cc%rmaxfrac, cc%ufrc)
cbmf = (sd%ps(0) - ac%plcl ) * 0.25 / sd%delt / Uw_p%GRAV
if (cc%cbmf .gt. cbmf) cc%cbmf = cbmf
if (cc%wrel .gt. 0.) then
cc%ufrc=cc%cbmf / cc%wrel /ac % rho0lcl
else
cc%ufrc=0.
end if
if (cc%ufrc > cc%maxcldfrac) then
cc%ufrc = cc%maxcldfrac
cc%cbmf = cc%wrel*ac%rho0lcl*cc%ufrc
end if
! cc%cbmf=cbmf
! cc%ufrc=ufrc
!
! cbmf = (sd%ps(0) - ac%plcl ) * 0.25 / sd%delt / Uw_p%GRAV
! if (cc%cbmf .gt. cbmf .and. cc%wrel .gt. 0) then
! cc%cbmf = cbmf
! cc%ufrc = cc%cbmf / wexp /ac % rho0lcl
! end if
! cc%wrel=min(cc%wrel, 50.)
! cc%ufrc=min(cc%rmaxfrac, cc%ufrc)
return
end subroutine cclosure_bretherton
!#####################################################################
!#####################################################################
subroutine cclosure_implicit(tkeavg, cpn, sd, Uw_p, ac, cc, delt, rkm, &
do_coldT, sd1, ac1, cc1, cp1, ct1, ier, ermesg)
implicit none
real, intent(in) :: tkeavg, delt, rkm
type(cpnlist), intent(in) :: cpn
type(sounding), intent(in) :: sd
type(uw_params), intent(inout) :: Uw_p
type(adicloud), intent(in) :: ac
type(cclosure), intent(inout) :: cc, cc1
type(sounding), intent(inout) :: sd1
type(adicloud), intent(inout) :: ac1
type(cplume), intent(inout) :: cp1
type(ctend), intent(inout) :: ct1
logical, intent(in) :: do_coldT
integer, intent(out) :: ier
character(len=256), intent(out) :: ermesg
logical :: dofast=.false., doice=.true.
real :: cbmf0=0.001, alpha, beta, phi
call cclosure_bretherton(tkeavg, cpn, sd, Uw_p, ac, cc)
if(cc%cbmf.eq.0.) then
cc % dcin=0.
return
end if
call cumulus_plume_k(cpn, sd, ac, cp1, rkm, cbmf0, cc%wrel, cc%scaleh, Uw_p, ier, ermesg)
if (ier /= 0) then
ermesg = 'Called from cclosure_implicit : '// trim(ermesg)
return
endif
if(cp1%ltop.lt.cp1%krel+2 .or. cp1%let.le.cp1%krel+1) then
cc % dcin=0.
return
else
call cumulus_tend_k(cpn, sd, Uw_p, cp1, ct1, do_coldT)
call sd_copy_k(sd, sd1)
sd1 % t = sd1 % t + ct1%tten * delt
sd1 % qv = sd1 % qv + ct1%qvten * delt
sd1 % ql = sd1 % ql + ct1%qlten * delt
sd1 % qi = sd1 % qi + ct1%qiten * delt
sd1 % qa = sd1 % qa + ct1%qaten * delt
sd1 % qn = sd1 % qn + ct1%qnten * delt
sd1 % u = sd1 % u + ct1%uten * delt
sd1 % v = sd1 % v + ct1%vten * delt
call extend_sd_k(sd1, sd%pblht, doice, Uw_p)
call adi_cloud_k(sd1%zs(1), sd1%ps(1), sd1%hl(1), sd1%thc(1), sd1%qct(1), sd1, Uw_p, dofast, doice, ac1)
cc % dcin=(ac1%cin-ac%cin)/cbmf0
alpha = (2. * cc%rbuoy) / (2. * cc%rkfre * tkeavg) * cc % cbmf * cc % dcin
beta = 1. ! ac % rho0lcl * sqrt(cc%rkfre * tkeavg) / 2.5066
phi = 1.
if (alpha .gt. 0.) then
call solvecbmf(alpha, beta, phi)
cc % cbmf = phi * cc % cbmf
end if
end if
end subroutine cclosure_implicit
!#####################################################################
!#####################################################################
subroutine cclosure_relaxcbmf(tkeavg, cpn, sd, Uw_p, ac, cc, delt)
implicit none
real, intent(in) :: tkeavg, delt
type(cpnlist), intent(in) :: cpn
type(sounding), intent(in) :: sd
type(uw_params), intent(in) :: Uw_p
type(adicloud), intent(in) :: ac
type(cclosure), intent(inout) :: cc
real :: sigmaw, wcrit, erfarg, wexp, wtw
real :: cbmfs, tmp
cc%wrel=0.; cc%ufrc=0.;
wcrit = sqrt(2. * ac % cin * cc%rbuoy)
sigmaw = sqrt(cc%rkfre * tkeavg)
cbmfs = ac % rho0lcl * sigmaw / 2.5066 * exp(-0.5*((wcrit/sigmaw)**2.))
tmp = delt/cc%tau_sh
cc%cbmf= max((cc%cbmf+tmp*cbmfs)/(1.+tmp),0.0)
!Diagnose updraft fraction
erfarg=wcrit / (1.4142 * sigmaw)
if(erfarg.lt.20.)then
cc%ufrc = min(cc%maxcldfrac, cc%rmaxfrac, 0.5*erfccc(erfarg))
else
cc%ufrc = 0.
endif
if(cc%ufrc.gt.0.001)then !Diagnose expected value of cloud base vertical velocity
wexp = cc%cbmf / ac % rho0lcl / cc%ufrc
else
wexp = 0.
cc%cbmf = 0.
endif
wexp=min(wexp, 50.)
wtw = wexp * wexp - 2 * ac % cin * cc%rbuoy
if(wtw.le.0.) then
cc%wrel=0.;
else
cc%wrel=sqrt(wtw)
end if
return
end subroutine cclosure_relaxcbmf
!#####################################################################
!#####################################################################
subroutine cclosure_emanuel(tkeavg, cpn, sd, Uw_p, ac, cc, delt)
implicit none
real, intent(in) :: tkeavg, delt
type(cpnlist), intent(in) :: cpn
type(uw_params), intent(inout) :: Uw_p
type(sounding), intent(in) :: sd
type(adicloud), intent(in) :: ac
type(cclosure), intent(inout) :: cc
integer :: k
real :: ufrc=0.01
real :: dtmin, dpsum, dtpbl, damps
real :: cbmf
real :: dtmax = 0.9 ! MAXIMUM NEGATIVE TEMPERATURE PERTURBATION
! A LIFTED PARCEL IS ALLOWED TO HAVE BELOW ITS LFC
real :: damp = 0.1 ! ALPHA AND DAMP ARE PARAMETERS THAT CONTROL THE RATE OF
real :: alpha = 0.1 ! APPROACH TO QUASI-EQUILIBRIUM
cbmf=cc%cbmf; cc%cbmf=0.; cc%wrel=0.; cc%ufrc=0.;
dpsum=0.; dtpbl=0.
do k=1, ac%klcl-1
dtpbl=dtpbl+(ac%thv(k)-sd%thv(k))*sd%exner(k)*sd%dp(k)
dpsum=dpsum+sd%dp(k);
end do
dtpbl=dtpbl/dpsum
dtmin=(ac%thvlcl-ac%thv0lcl)+dtpbl+dtmax
damps=damp*delt/300.
cbmf =(1.-damps)*cbmf+0.1*alpha*dtmin
cc%cbmf=max(cbmf,0.0)
cc%wrel=cbmf / ac % rho0lcl / ufrc
cc%ufrc=ufrc
return
end subroutine cclosure_emanuel
!#####################################################################
!#####################################################################
subroutine cclosure_relaxwfn(tkeavg, cpn, sd, Uw_p, ac, cc, cp, ct, delt, rkm, &
do_coldT, sd1, ac1, cc1, cp1, ct1, ier, ermesg)
implicit none
real, intent(in) :: tkeavg, delt, rkm
type(cpnlist), intent(in) :: cpn
type(uw_params), intent(inout) :: Uw_p
type(sounding), intent(in) :: sd
type(adicloud), intent(in) :: ac
type(cclosure), intent(inout) :: cc, cc1
type(sounding), intent(inout) :: sd1
type(adicloud), intent(inout) :: ac1
type(cplume), intent(inout) :: cp, cp1
type(ctend), intent(inout) :: ct, ct1
logical, intent(in) :: do_coldT
integer, intent(out) :: ier
character(len=256), intent(out) :: ermesg
logical :: dofast=.false., doice=.true.
integer :: k
real :: cbmf0=0.0001, delp, cbmf_old, tmp, cbmfs
cbmf_old= cc%cbmf
call cclosure_bretherton(tkeavg, cpn, sd, Uw_p, ac, cc)
call cumulus_plume_k(cpn, sd, ac, cp, rkm, cbmf0, cc%wrel, cc%scaleh, Uw_p, ier, ermesg)
if (ier /= 0) then
ermesg = 'Called from cclosure_relaxwfn : '//trim(ermesg)
return
endif
if(cp%ltop.lt.cp%krel+2 .or. cp%let.le.cp%krel+1) then
cc % dcin=0.
return
else
call cumulus_tend_k(cpn, sd, Uw_p, cp, ct, do_coldT)
call sd_copy_k(sd, sd1)
sd1 % t = sd1 % t + ct%tten * delt
sd1 % qv = sd1 % qv + ct%qvten * delt
sd1 % ql = sd1 % ql + ct%qlten * delt
sd1 % qi = sd1 % qi + ct%qiten * delt
sd1 % qa = sd1 % qa + ct%qaten * delt
sd1 % qn = sd1 % qn + ct%qnten * delt
sd1 % u = sd1 % u + ct%uten * delt
sd1 % v = sd1 % v + ct%vten * delt
call extend_sd_k(sd1, sd%pblht, doice, Uw_p)
call adi_cloud_k(sd1%zs(1), sd1%ps(1), sd1%hl(1), sd1%thc(1), sd1%qct(1), sd1, Uw_p, dofast, doice, ac1)
cc % dcin=(ac1%cin-ac%cin)/cbmf0
cc % dcape=(ac1%cape-ac%cape)/cbmf0
call cumulus_plume_k(cpn, sd1, ac1, cp1, rkm, cbmf0, cc%wrel, cc%scaleh, Uw_p, ier, ermesg)
if (ier /= 0) then
ermesg = 'Called from cclosure_relaxwfn 2nd call : '//trim(ermesg)
endif
cc%dwfn=0.; cc%wfn=0.; delp=0.;
do k=cp1%krel, cp1%let
cc % wfn = cc % wfn + 0.5*(cp %wu(k)*cp %wu(k)) * cp%dp(k)
cc % dwfn = cc % dwfn + 0.5*(cp1%wu(k)*cp1%wu(k) - cp%wu(k)*cp%wu(k)) * cp%dp(k)
delp = delp + cp%dp(k)
end do
cc % wfn = cc % wfn / delp
cc % dwfn = cc % dwfn / delp / cbmf0
cbmfs = - cc%wfn / cc % dwfn
tmp = delt/cc%tau_sh
cc%cbmf= (cbmf_old+tmp*cbmfs)/(1.+tmp)
cc % cbmf = max(cc%cbmf,0.)
end if
end subroutine cclosure_relaxwfn
!#####################################################################
!#####################################################################
subroutine conv_closures_init
!---------------------------------------------------------------------
! write version number and namelist to logfile.
!---------------------------------------------------------------------
call write_version_number(version, tagname)
!---------------------------------------------------------------------
! mark the module as initialized.
!---------------------------------------------------------------------
module_is_initialized = .true.
end subroutine conv_closures_init
!#####################################################################
!#####################################################################
subroutine conv_closures_end
module_is_initialized = .false.
end subroutine conv_closures_end
!#####################################################################
!#####################################################################
end MODULE CONV_CLOSURES_MOD
| lgpl-3.0 |
MeteoSwiss-APN/omni-compiler | F-FrontEnd/test/testRegression/MPI-BT/z_solve.f | 2 | 28951 | c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_solve
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c Performs line solves in Z 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---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
integer c, kstart, stage,
> first, last, recv_id, error, r_status(MPI_STATUS_SIZE),
> isize,jsize,ksize,send_id
kstart = 0
c---------------------------------------------------------------------
c in our terminology stage is the number of the cell in the y-direction
c i.e. stage = 1 means the start of the line stage=ncells means end
c---------------------------------------------------------------------
do stage = 1,ncells
c = slice(3,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 lhsz(c)
call z_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
call z_receive_solve_info(recv_id,c)
c---------------------------------------------------------------------
c overlap computations and communications
c---------------------------------------------------------------------
c call lhsz(c)
c---------------------------------------------------------------------
c wait for completion
c---------------------------------------------------------------------
call mpi_wait(send_id,r_status,error)
call mpi_wait(recv_id,r_status,error)
c---------------------------------------------------------------------
c install C'(kstart+1) and rhs'(kstart+1) to be used in this cell
c---------------------------------------------------------------------
call z_unpack_solve_info(c)
call z_solve_cell(first,last,c)
endif
if (last .eq. 0) call z_send_solve_info(send_id,c)
enddo
c---------------------------------------------------------------------
c now perform backsubstitution in reverse direction
c---------------------------------------------------------------------
do stage = ncells, 1, -1
c = slice(3,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 z_backsubstitute(first, last,c)
else
call z_receive_backsub_info(recv_id,c)
call mpi_wait(send_id,r_status,error)
call mpi_wait(recv_id,r_status,error)
call z_unpack_backsub_info(c)
call z_backsubstitute(first,last,c)
endif
if (first .eq. 0) call z_send_backsub_info(send_id,c)
enddo
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_unpack_solve_info(c)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c unpack C'(-1) and rhs'(-1) for
c all i and j
c---------------------------------------------------------------------
include 'header.h'
integer i,j,m,n,ptr,c,kstart
kstart = 0
ptr = 0
do j=0,JMAX-1
do i=0,IMAX-1
do m=1,BLOCK_SIZE
do n=1,BLOCK_SIZE
lhsc(m,n,i,j,kstart-1,c) = out_buffer(ptr+n)
enddo
ptr = ptr+BLOCK_SIZE
enddo
do n=1,BLOCK_SIZE
rhs(n,i,j,kstart-1,c) = out_buffer(ptr+n)
enddo
ptr = ptr+BLOCK_SIZE
enddo
enddo
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_send_solve_info(send_id,c)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c pack up and send C'(kend) and rhs'(kend) for
c all i and j
c---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
integer i,j,m,n,ksize,ptr,c,ip,jp
integer error,send_id,buffer_size
ksize = cell_size(3,c)-1
ip = cell_coord(1,c) - 1
jp = cell_coord(2,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 j=0,JMAX-1
do i=0,IMAX-1
do m=1,BLOCK_SIZE
do n=1,BLOCK_SIZE
in_buffer(ptr+n) = lhsc(m,n,i,j,ksize,c)
enddo
ptr = ptr+BLOCK_SIZE
enddo
do n=1,BLOCK_SIZE
in_buffer(ptr+n) = rhs(n,i,j,ksize,c)
enddo
ptr = ptr+BLOCK_SIZE
enddo
enddo
c---------------------------------------------------------------------
c send buffer
c---------------------------------------------------------------------
call mpi_isend(in_buffer, buffer_size,
> dp_type, successor(3),
> BOTTOM+ip+jp*NCELLS, comm_solve,
> send_id,error)
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_send_backsub_info(send_id,c)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c pack up and send U(jstart) for all i and j
c---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
integer i,j,n,ptr,c,kstart,ip,jp
integer error,send_id,buffer_size
c---------------------------------------------------------------------
c Send element 0 to previous processor
c---------------------------------------------------------------------
kstart = 0
ip = cell_coord(1,c)-1
jp = cell_coord(2,c)-1
buffer_size=MAX_CELL_DIM*MAX_CELL_DIM*BLOCK_SIZE
ptr = 0
do j=0,JMAX-1
do i=0,IMAX-1
do n=1,BLOCK_SIZE
in_buffer(ptr+n) = rhs(n,i,j,kstart,c)
enddo
ptr = ptr+BLOCK_SIZE
enddo
enddo
call mpi_isend(in_buffer, buffer_size,
> dp_type, predecessor(3),
> TOP+ip+jp*NCELLS, comm_solve,
> send_id,error)
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_unpack_backsub_info(c)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c unpack U(ksize) for all i and j
c---------------------------------------------------------------------
include 'header.h'
integer i,j,n,ptr,c
ptr = 0
do j=0,JMAX-1
do i=0,IMAX-1
do n=1,BLOCK_SIZE
backsub_info(n,i,j,c) = out_buffer(ptr+n)
enddo
ptr = ptr+BLOCK_SIZE
enddo
enddo
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_receive_backsub_info(recv_id,c)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c post mpi receives
c---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
integer error,recv_id,ip,jp,c,buffer_size
ip = cell_coord(1,c) - 1
jp = cell_coord(2,c) - 1
buffer_size=MAX_CELL_DIM*MAX_CELL_DIM*BLOCK_SIZE
call mpi_irecv(out_buffer, buffer_size,
> dp_type, successor(3),
> TOP+ip+jp*NCELLS, comm_solve,
> recv_id, error)
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_receive_solve_info(recv_id,c)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c post mpi receives
c---------------------------------------------------------------------
include 'header.h'
include 'mpinpb.h'
integer ip,jp,recv_id,error,c,buffer_size
ip = cell_coord(1,c) - 1
jp = cell_coord(2,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(3),
> BOTTOM+ip+jp*NCELLS, comm_solve,
> recv_id, error)
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_backsubstitute(first, last, c)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c back solve: if last cell, then generate U(ksize)=rhs(ksize)
c else assume U(ksize) is loaded in un pack backsub_info
c so just use it
c after call u(kstart) will be sent to next cell
c---------------------------------------------------------------------
include 'header.h'
integer first, last, c, i, k
integer m,n,j,jsize,isize,ksize,kstart
kstart = 0
isize = cell_size(1,c)-end(1,c)-1
jsize = cell_size(2,c)-end(2,c)-1
ksize = cell_size(3,c)-1
if (last .eq. 0) then
do j=start(2,c),jsize
do i=start(1,c),isize
c---------------------------------------------------------------------
c U(jsize) uses info from previous cell if not last cell
c---------------------------------------------------------------------
do m=1,BLOCK_SIZE
do n=1,BLOCK_SIZE
rhs(m,i,j,ksize,c) = rhs(m,i,j,ksize,c)
> - lhsc(m,n,i,j,ksize,c)*
> backsub_info(n,i,j,c)
enddo
enddo
enddo
enddo
endif
do k=ksize-1,kstart,-1
do j=start(2,c),jsize
do i=start(1,c),isize
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,j,k+1,c)
enddo
enddo
enddo
enddo
enddo
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine z_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'(KMAX) and rhs'(KMAX) 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,kstart
double precision utmp(6,-2:KMAX+1)
kstart = 0
isize = cell_size(1,c)-end(1,c)-1
jsize = cell_size(2,c)-end(2,c)-1
ksize = cell_size(3,c)-1
call lhsabinit(lhsa, lhsb, ksize)
do j=start(2,c),jsize
do i=start(1,c),isize
c---------------------------------------------------------------------
c This function computes the left hand side for the three z-factors
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c Compute the indices for storing the block-diagonal matrix;
c determine c (labeled f) and s jacobians for cell c
c---------------------------------------------------------------------
do k = start(3,c)-1, cell_size(3,c)-end(3,c)
utmp(1,k) = 1.0d0 / u(1,i,j,k,c)
utmp(2,k) = u(2,i,j,k,c)
utmp(3,k) = u(3,i,j,k,c)
utmp(4,k) = u(4,i,j,k,c)
utmp(5,k) = u(5,i,j,k,c)
utmp(6,k) = qs(i,j,k,c)
end do
do k = start(3,c)-1, cell_size(3,c)-end(3,c)
tmp1 = utmp(1,k)
tmp2 = tmp1 * tmp1
tmp3 = tmp1 * tmp2
fjac(1,1,k) = 0.0d+00
fjac(1,2,k) = 0.0d+00
fjac(1,3,k) = 0.0d+00
fjac(1,4,k) = 1.0d+00
fjac(1,5,k) = 0.0d+00
fjac(2,1,k) = - ( utmp(2,k)*utmp(4,k) )
> * tmp2
fjac(2,2,k) = utmp(4,k) * tmp1
fjac(2,3,k) = 0.0d+00
fjac(2,4,k) = utmp(2,k) * tmp1
fjac(2,5,k) = 0.0d+00
fjac(3,1,k) = - ( utmp(3,k)*utmp(4,k) )
> * tmp2
fjac(3,2,k) = 0.0d+00
fjac(3,3,k) = utmp(4,k) * tmp1
fjac(3,4,k) = utmp(3,k) * tmp1
fjac(3,5,k) = 0.0d+00
fjac(4,1,k) = - (utmp(4,k)*utmp(4,k) * tmp2 )
> + c2 * utmp(6,k)
fjac(4,2,k) = - c2 * utmp(2,k) * tmp1
fjac(4,3,k) = - c2 * utmp(3,k) * tmp1
fjac(4,4,k) = ( 2.0d+00 - c2 )
> * utmp(4,k) * tmp1
fjac(4,5,k) = c2
fjac(5,1,k) = ( c2 * 2.0d0 * utmp(6,k)
> - c1 * ( utmp(5,k) * tmp1 ) )
> * ( utmp(4,k) * tmp1 )
fjac(5,2,k) = - c2 * ( utmp(2,k)*utmp(4,k) )
> * tmp2
fjac(5,3,k) = - c2 * ( utmp(3,k)*utmp(4,k) )
> * tmp2
fjac(5,4,k) = c1 * ( utmp(5,k) * tmp1 )
> - c2 * ( utmp(6,k)
> + utmp(4,k)*utmp(4,k) * tmp2 )
fjac(5,5,k) = c1 * utmp(4,k) * tmp1
njac(1,1,k) = 0.0d+00
njac(1,2,k) = 0.0d+00
njac(1,3,k) = 0.0d+00
njac(1,4,k) = 0.0d+00
njac(1,5,k) = 0.0d+00
njac(2,1,k) = - c3c4 * tmp2 * utmp(2,k)
njac(2,2,k) = c3c4 * tmp1
njac(2,3,k) = 0.0d+00
njac(2,4,k) = 0.0d+00
njac(2,5,k) = 0.0d+00
njac(3,1,k) = - c3c4 * tmp2 * utmp(3,k)
njac(3,2,k) = 0.0d+00
njac(3,3,k) = c3c4 * tmp1
njac(3,4,k) = 0.0d+00
njac(3,5,k) = 0.0d+00
njac(4,1,k) = - con43 * c3c4 * tmp2 * utmp(4,k)
njac(4,2,k) = 0.0d+00
njac(4,3,k) = 0.0d+00
njac(4,4,k) = con43 * c3 * c4 * tmp1
njac(4,5,k) = 0.0d+00
njac(5,1,k) = - ( c3c4
> - c1345 ) * tmp3 * (utmp(2,k)**2)
> - ( c3c4 - c1345 ) * tmp3 * (utmp(3,k)**2)
> - ( con43 * c3c4
> - c1345 ) * tmp3 * (utmp(4,k)**2)
> - c1345 * tmp2 * utmp(5,k)
njac(5,2,k) = ( c3c4 - c1345 ) * tmp2 * utmp(2,k)
njac(5,3,k) = ( c3c4 - c1345 ) * tmp2 * utmp(3,k)
njac(5,4,k) = ( con43 * c3c4
> - c1345 ) * tmp2 * utmp(4,k)
njac(5,5,k) = ( c1345 )* tmp1
enddo
c---------------------------------------------------------------------
c now joacobians set, so form left hand side in z direction
c---------------------------------------------------------------------
do k = start(3,c), ksize-end(3,c)
tmp1 = dt * tz1
tmp2 = dt * tz2
lhsa(1,1,k) = - tmp2 * fjac(1,1,k-1)
> - tmp1 * njac(1,1,k-1)
> - tmp1 * dz1
lhsa(1,2,k) = - tmp2 * fjac(1,2,k-1)
> - tmp1 * njac(1,2,k-1)
lhsa(1,3,k) = - tmp2 * fjac(1,3,k-1)
> - tmp1 * njac(1,3,k-1)
lhsa(1,4,k) = - tmp2 * fjac(1,4,k-1)
> - tmp1 * njac(1,4,k-1)
lhsa(1,5,k) = - tmp2 * fjac(1,5,k-1)
> - tmp1 * njac(1,5,k-1)
lhsa(2,1,k) = - tmp2 * fjac(2,1,k-1)
> - tmp1 * njac(2,1,k-1)
lhsa(2,2,k) = - tmp2 * fjac(2,2,k-1)
> - tmp1 * njac(2,2,k-1)
> - tmp1 * dz2
lhsa(2,3,k) = - tmp2 * fjac(2,3,k-1)
> - tmp1 * njac(2,3,k-1)
lhsa(2,4,k) = - tmp2 * fjac(2,4,k-1)
> - tmp1 * njac(2,4,k-1)
lhsa(2,5,k) = - tmp2 * fjac(2,5,k-1)
> - tmp1 * njac(2,5,k-1)
lhsa(3,1,k) = - tmp2 * fjac(3,1,k-1)
> - tmp1 * njac(3,1,k-1)
lhsa(3,2,k) = - tmp2 * fjac(3,2,k-1)
> - tmp1 * njac(3,2,k-1)
lhsa(3,3,k) = - tmp2 * fjac(3,3,k-1)
> - tmp1 * njac(3,3,k-1)
> - tmp1 * dz3
lhsa(3,4,k) = - tmp2 * fjac(3,4,k-1)
> - tmp1 * njac(3,4,k-1)
lhsa(3,5,k) = - tmp2 * fjac(3,5,k-1)
> - tmp1 * njac(3,5,k-1)
lhsa(4,1,k) = - tmp2 * fjac(4,1,k-1)
> - tmp1 * njac(4,1,k-1)
lhsa(4,2,k) = - tmp2 * fjac(4,2,k-1)
> - tmp1 * njac(4,2,k-1)
lhsa(4,3,k) = - tmp2 * fjac(4,3,k-1)
> - tmp1 * njac(4,3,k-1)
lhsa(4,4,k) = - tmp2 * fjac(4,4,k-1)
> - tmp1 * njac(4,4,k-1)
> - tmp1 * dz4
lhsa(4,5,k) = - tmp2 * fjac(4,5,k-1)
> - tmp1 * njac(4,5,k-1)
lhsa(5,1,k) = - tmp2 * fjac(5,1,k-1)
> - tmp1 * njac(5,1,k-1)
lhsa(5,2,k) = - tmp2 * fjac(5,2,k-1)
> - tmp1 * njac(5,2,k-1)
lhsa(5,3,k) = - tmp2 * fjac(5,3,k-1)
> - tmp1 * njac(5,3,k-1)
lhsa(5,4,k) = - tmp2 * fjac(5,4,k-1)
> - tmp1 * njac(5,4,k-1)
lhsa(5,5,k) = - tmp2 * fjac(5,5,k-1)
> - tmp1 * njac(5,5,k-1)
> - tmp1 * dz5
lhsb(1,1,k) = 1.0d+00
> + tmp1 * 2.0d+00 * njac(1,1,k)
> + tmp1 * 2.0d+00 * dz1
lhsb(1,2,k) = tmp1 * 2.0d+00 * njac(1,2,k)
lhsb(1,3,k) = tmp1 * 2.0d+00 * njac(1,3,k)
lhsb(1,4,k) = tmp1 * 2.0d+00 * njac(1,4,k)
lhsb(1,5,k) = tmp1 * 2.0d+00 * njac(1,5,k)
lhsb(2,1,k) = tmp1 * 2.0d+00 * njac(2,1,k)
lhsb(2,2,k) = 1.0d+00
> + tmp1 * 2.0d+00 * njac(2,2,k)
> + tmp1 * 2.0d+00 * dz2
lhsb(2,3,k) = tmp1 * 2.0d+00 * njac(2,3,k)
lhsb(2,4,k) = tmp1 * 2.0d+00 * njac(2,4,k)
lhsb(2,5,k) = tmp1 * 2.0d+00 * njac(2,5,k)
lhsb(3,1,k) = tmp1 * 2.0d+00 * njac(3,1,k)
lhsb(3,2,k) = tmp1 * 2.0d+00 * njac(3,2,k)
lhsb(3,3,k) = 1.0d+00
> + tmp1 * 2.0d+00 * njac(3,3,k)
> + tmp1 * 2.0d+00 * dz3
lhsb(3,4,k) = tmp1 * 2.0d+00 * njac(3,4,k)
lhsb(3,5,k) = tmp1 * 2.0d+00 * njac(3,5,k)
lhsb(4,1,k) = tmp1 * 2.0d+00 * njac(4,1,k)
lhsb(4,2,k) = tmp1 * 2.0d+00 * njac(4,2,k)
lhsb(4,3,k) = tmp1 * 2.0d+00 * njac(4,3,k)
lhsb(4,4,k) = 1.0d+00
> + tmp1 * 2.0d+00 * njac(4,4,k)
> + tmp1 * 2.0d+00 * dz4
lhsb(4,5,k) = tmp1 * 2.0d+00 * njac(4,5,k)
lhsb(5,1,k) = tmp1 * 2.0d+00 * njac(5,1,k)
lhsb(5,2,k) = tmp1 * 2.0d+00 * njac(5,2,k)
lhsb(5,3,k) = tmp1 * 2.0d+00 * njac(5,3,k)
lhsb(5,4,k) = tmp1 * 2.0d+00 * njac(5,4,k)
lhsb(5,5,k) = 1.0d+00
> + tmp1 * 2.0d+00 * njac(5,5,k)
> + tmp1 * 2.0d+00 * dz5
lhsc(1,1,i,j,k,c) = tmp2 * fjac(1,1,k+1)
> - tmp1 * njac(1,1,k+1)
> - tmp1 * dz1
lhsc(1,2,i,j,k,c) = tmp2 * fjac(1,2,k+1)
> - tmp1 * njac(1,2,k+1)
lhsc(1,3,i,j,k,c) = tmp2 * fjac(1,3,k+1)
> - tmp1 * njac(1,3,k+1)
lhsc(1,4,i,j,k,c) = tmp2 * fjac(1,4,k+1)
> - tmp1 * njac(1,4,k+1)
lhsc(1,5,i,j,k,c) = tmp2 * fjac(1,5,k+1)
> - tmp1 * njac(1,5,k+1)
lhsc(2,1,i,j,k,c) = tmp2 * fjac(2,1,k+1)
> - tmp1 * njac(2,1,k+1)
lhsc(2,2,i,j,k,c) = tmp2 * fjac(2,2,k+1)
> - tmp1 * njac(2,2,k+1)
> - tmp1 * dz2
lhsc(2,3,i,j,k,c) = tmp2 * fjac(2,3,k+1)
> - tmp1 * njac(2,3,k+1)
lhsc(2,4,i,j,k,c) = tmp2 * fjac(2,4,k+1)
> - tmp1 * njac(2,4,k+1)
lhsc(2,5,i,j,k,c) = tmp2 * fjac(2,5,k+1)
> - tmp1 * njac(2,5,k+1)
lhsc(3,1,i,j,k,c) = tmp2 * fjac(3,1,k+1)
> - tmp1 * njac(3,1,k+1)
lhsc(3,2,i,j,k,c) = tmp2 * fjac(3,2,k+1)
> - tmp1 * njac(3,2,k+1)
lhsc(3,3,i,j,k,c) = tmp2 * fjac(3,3,k+1)
> - tmp1 * njac(3,3,k+1)
> - tmp1 * dz3
lhsc(3,4,i,j,k,c) = tmp2 * fjac(3,4,k+1)
> - tmp1 * njac(3,4,k+1)
lhsc(3,5,i,j,k,c) = tmp2 * fjac(3,5,k+1)
> - tmp1 * njac(3,5,k+1)
lhsc(4,1,i,j,k,c) = tmp2 * fjac(4,1,k+1)
> - tmp1 * njac(4,1,k+1)
lhsc(4,2,i,j,k,c) = tmp2 * fjac(4,2,k+1)
> - tmp1 * njac(4,2,k+1)
lhsc(4,3,i,j,k,c) = tmp2 * fjac(4,3,k+1)
> - tmp1 * njac(4,3,k+1)
lhsc(4,4,i,j,k,c) = tmp2 * fjac(4,4,k+1)
> - tmp1 * njac(4,4,k+1)
> - tmp1 * dz4
lhsc(4,5,i,j,k,c) = tmp2 * fjac(4,5,k+1)
> - tmp1 * njac(4,5,k+1)
lhsc(5,1,i,j,k,c) = tmp2 * fjac(5,1,k+1)
> - tmp1 * njac(5,1,k+1)
lhsc(5,2,i,j,k,c) = tmp2 * fjac(5,2,k+1)
> - tmp1 * njac(5,2,k+1)
lhsc(5,3,i,j,k,c) = tmp2 * fjac(5,3,k+1)
> - tmp1 * njac(5,3,k+1)
lhsc(5,4,i,j,k,c) = tmp2 * fjac(5,4,k+1)
> - tmp1 * njac(5,4,k+1)
lhsc(5,5,i,j,k,c) = tmp2 * fjac(5,5,k+1)
> - tmp1 * njac(5,5,k+1)
> - tmp1 * dz5
enddo
c---------------------------------------------------------------------
c outer most do loops - sweeping in i direction
c---------------------------------------------------------------------
if (first .eq. 1) then
c---------------------------------------------------------------------
c multiply c(i,j,kstart) by b_inverse and copy back to c
c multiply rhs(kstart) by b_inverse(kstart) and copy to rhs
c---------------------------------------------------------------------
call binvcrhs( lhsb(1,1,kstart),
> lhsc(1,1,i,j,kstart,c),
> rhs(1,i,j,kstart,c) )
endif
c---------------------------------------------------------------------
c begin inner most do loop
c do all the elements of the cell unless last
c---------------------------------------------------------------------
do k=kstart+first,ksize-last
c---------------------------------------------------------------------
c subtract A*lhs_vector(k-1) from lhs_vector(k)
c
c rhs(k) = rhs(k) - A*rhs(k-1)
c---------------------------------------------------------------------
call matvec_sub(lhsa(1,1,k),
> rhs(1,i,j,k-1,c),rhs(1,i,j,k,c))
c---------------------------------------------------------------------
c B(k) = B(k) - C(k-1)*A(k)
c call matmul_sub(aa,i,j,k,c,cc,i,j,k-1,c,bb,i,j,k,c)
c---------------------------------------------------------------------
call matmul_sub(lhsa(1,1,k),
> lhsc(1,1,i,j,k-1,c),
> lhsb(1,1,k))
c---------------------------------------------------------------------
c multiply c(i,j,k) by b_inverse and copy back to c
c multiply rhs(i,j,1) by b_inverse(i,j,1) and copy to rhs
c---------------------------------------------------------------------
call binvcrhs( lhsb(1,1,k),
> 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(ksize) = rhs(ksize) - A*rhs(ksize-1)
c---------------------------------------------------------------------
call matvec_sub(lhsa(1,1,ksize),
> rhs(1,i,j,ksize-1,c),rhs(1,i,j,ksize,c))
c---------------------------------------------------------------------
c B(ksize) = B(ksize) - C(ksize-1)*A(ksize)
c call matmul_sub(aa,i,j,ksize,c,
c $ cc,i,j,ksize-1,c,bb,i,j,ksize,c)
c---------------------------------------------------------------------
call matmul_sub(lhsa(1,1,ksize),
> lhsc(1,1,i,j,ksize-1,c),
> lhsb(1,1,ksize))
c---------------------------------------------------------------------
c multiply rhs(ksize) by b_inverse(ksize) and copy to rhs
c---------------------------------------------------------------------
call binvrhs( lhsb(1,1,ksize),
> rhs(1,i,j,ksize,c) )
endif
enddo
enddo
return
end
| lgpl-3.0 |
radiasoft/pypi-shadow3 | fortran/gen_source.f90 | 1 | 3307 | ! C+++
! C PROGRAM GEN_SOURCE
! C
! C PURPOSE Reads in a start.00 file and create the specified
! C source (file begin.dat)
! C
! C INPUT Variables in start.00 type file
! C
! C OUTPUT A BINARY file begin.dat
! C
! C COMMAND LINE gen_source [start_file_name]
! C
! C NOTE: This program mimics the gen_source program in shadow2
! C It is maintained for compatibility reasons.
! C The same functionality is also in shadow3.f90
!
! C---
PROGRAM Gen_Source
use shadow_globaldefinitions ! Global definitions
use stringio, only : RString
use shadow_beamio, only : beamWrite
use shadow_variables
use shadow_kernel
use shadow_synchrotron
implicit none
character(len=sklen) :: infile,outfile,bgnfile,arg
integer(kind=ski) :: indx, numArg, iErr
integer (kind=ski) :: iSynchrotron=0, ioform=0
type (poolSource) :: pool00
real(kind=skr), allocatable, dimension(:,:) :: ray
infile = " "
bgnfile = "begin.dat"
! C
! C Look at the command line for user parameters.
! C
numArg = COMMAND_ARGUMENT_COUNT()
IF (numarg.NE.0) THEN
indx = 1
DO WHILE (indx .LE. numarg)
!! Curiously get_command_argument is not recognised by g95 in 64bit
!! Back to OLD way, which seems to work
!! CALL get_command_argument (INDX, ARG)
CALL GETARG (indx, arg)
IF (arg (1:1) .NE. '-') infile = arg
! this option (ascii output) has been eliminated in Shadow3 (srio)
! IF (ARG (1:2) .EQ. '-a' .OR. ARG (1:2) .EQ. '-A') THEN
! IOFORM = 1
! BGNFILE = 'begin.dat.ascii'
indx = indx + 1
END DO
ENDIF
! C
! C If the INFILE was not supplied in the command line, ask for it.
! C
IF (infile(1:1).EQ." ") THEN
infile = RString ('GEN_SOURCE => File with source specifications ? ')
ENDIF
!
! load variables from start.00
!
CALL PoolSourceLoad(pool00,infile)
!
! allocate ray
!
!print *,'Allocating array with pool00%npoint: ',pool00%npoint
ALLOCATE( ray(18,pool00%npoint) )
ray=0.0d0
IF ((pool00%fdistr.EQ.4).OR.(pool00%fsource_depth.EQ.4).OR.(pool00%f_wiggler.GT.0)) THEN
iSynchrotron = 1
ENDIF
IF (iSynchrotron .eq. 1) THEN
CALL SourceSync (pool00,ray,pool00%npoint)
ELSE
! Note that the routine sourceGeom (geometrical source) in
! shadow_kernel is a subset of SourceSync (in shadow_sourcesync)
! therefore this call is unnecessary because the same work can be
! done by SourceSync.
! The reason for keeping the two functions is for simplicity and
! to structurate better the shadow3 code: sourceGeom uses a relatively
! small number of subroutines and functions, all available in the
! kernel, whereas SourceSync is much more complex and is included in
! a separated synchrotron module.
! Therefore, users that do not want synchrotron, they just comment
! the "USE shadow_sourcesync" and "CALL SourceSync"
CALL sourceGeom(pool00, ray,pool00%npoint)
ENDIF
! write file begin.dat
CALL beamWrite(ray,ierr,ncol,npoint,bgnfile)
IF (ierr.NE.0) PRINT *, "GEN_SOURCE: beamWrite failed to write file: "//TRIM(bgnfile)
! write end.00 file
CALL GlobalToPoolSource(pool00)
CALL PoolSourceWrite(pool00,"end.00")
END PROGRAM Gen_Source
| gpl-3.0 |
MeteoSwiss-APN/omni-compiler | tests/xcalablemp/NOT-IMPLEMENTED/59/reduction_async8.f90 | 2 | 1073 | ! testp041.f
! reduction»Ø¼¨Ê¸(min)¤Î¥Æ¥¹¥È
program main
include 'xmp_lib.h'
integer,parameter:: N=1000
integer random_array(N), ans_val, val
!$xmp nodes p(*)
!$xmp template t(N)
!$xmp distribute t(block) onto p
character(len=2) result
result = 'OK'
do k=114, 10000, 17
random_array(1) = k
do i=2, N
random_array(i) =
$ mod(random_array(i-1)**2, 100000000)
random_array(i) =
$ mod((random_array(i)-mod(random_array(i),100))/100,
$ 10000)
enddo
val = 2147483647
!$xmp loop on t(i)
do i=1, N
val = min(val, random_array(i))
enddo
!$xmp reduction(min: val) async(1)
ans_val = 2147483647
do i=1, N
ans_val = min(ans_val, random_array(i))
enddo
!$xmp wait_async(1)
if(val .ne. ans_val) then
print *, val, '!=', ans_val
result = 'NG'
endif
enddo
print *, xmp_node_num(), 'testp041.f ', result
end
| lgpl-3.0 |
mom-ocean/MOM5 | src/mom5/ocean_blobs/ocean_blob_util.F90 | 8 | 73775 | module ocean_blob_util_mod
#define COMP isc:iec,jsc:jec
!
!<CONTACT EMAIL="m.bates@student.unsw.edu.au"> Michael L. Bates
!</CONTACT>
!
!<CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> Stephen M. Griffies
!</CONTACT>
!
!<OVERVIEW>
! This module contains subroutines that are common (or are likely to
! need be common to future implementations) to some or all of the
! various modules that run the Lagrangian blob scheme.
!</OVERVIEW>
!
!<DESCRIPTION>
! This module contains subroutines that are common (or may be common
! in a future implementation) to some of the modules that make up the
! blobs framework.
!
! Some of the subroutines contained herein perform tasks such as
! performing checksums, checking a linked lists for very small blobs
! (and deleting them), inserting blobs into a list, a bunch of routines
! for writing blob restart and history files, grid cell search algorithms,
! buffer manipulations, computations etc.
!
! The module has no namelist. All potential namelist variables are
! controlled through the ocean_blob_mod namelist.
!</DESCRIPTION>
!
!<INFO>
! <REFERENCE>
! Cormen, T. H, Leiserson, C. E. Rivest, R. L., Stein, C. (2001) Introduction
! to Algorithms. The MIT Press.
! </REFERENCE>
!
! <REFERENCE>
! Shepard, D. (1968) A two-dimensional interpolation function for
! irregularly-spaced data. In: Proceedings of the 1968 23rd ACM national
! conference. ACM '68. ACM, New York, NY, USA, pp. 517-524.
! </REFERENCE>
!
! <REFERENCE>
! Murray, R. J. (1996) Explicit generation of orthogonal grids for
! ocean models. Journal of Computational Physics 126, 251-273.
! </REFERENCE>
!
!</INFO>
use constants_mod, only: rad_to_deg, epsln
use fms_mod, only: error_mesg, FATAL, WARNING, stdout, stderr, mpp_error
use fms_mod, only: read_data
use mpp_domains_mod, only: mpp_global_sum, mpp_get_neighbor_pe, mpp_update_domains
use mpp_domains_mod, only: mpp_get_current_ntile, mpp_get_tile_id
use mpp_domains_mod, only: NORTH, SOUTH, EAST, WEST
use mpp_mod, only: mpp_sum, NULL_PE
use grid_mod, only: get_grid_cell_vertices, get_grid_size
use ocean_parameters_mod, only: onehalf, rho0r, grav, omega_earth
use ocean_parameters_mod, only: GEOPOTENTIAL, ZSTAR, DEPTH_BASED
use ocean_types_mod, only: ocean_thickness_type, ocean_lagrangian_type
use ocean_types_mod, only: ocean_prog_tracer_type, ocean_time_type
use ocean_types_mod, only: ocean_blob_type, ocean_grid_type, ocean_external_mode_type
use ocean_types_mod, only: ocean_domain_type, ocean_density_type, blob_grid_type
use ocean_workspace_mod, only: wrk1, wrk2
use ocean_util_mod, only: write_chksum_3d, write_chksum_3d_int
implicit none
include 'netcdf.inc'
private
integer :: vert_coordinate_class
integer :: vert_coordinate
! set module types
type(ocean_grid_type), pointer :: Grd => NULL()
type(ocean_domain_type), pointer :: Dom => NULL()
type(ocean_domain_type), pointer :: Bdom => NULL()
type(blob_grid_type), pointer :: Info => NULL()
real, dimension(:,:,:), pointer :: ht => NULL()
real, dimension(:,:,:), pointer :: hu => NULL()
real, dimension(:,:,:,:), allocatable :: vert_t
real, dimension(:,:,:), allocatable :: ij_im1j, im1jm1_im1j, ij_ijm1, im1jm1_ijm1
real, dimension(:,:,:), allocatable :: t_im1jm1, t_ijm1, t_ij, t_im1j
real, dimension(:,:), allocatable :: xt, xu
real, dimension(:,:), allocatable :: yt, yu
real, dimension(:,:), allocatable :: datdtime_r ! 1./(Grd%dat*dtime)
integer, dimension(9) :: im, jm
integer, dimension(5) :: it, jt
integer, dimension(4) :: iu, ju
integer :: nig,njg,ni,nip1
real :: grav_rho0r
real :: two_omega
real :: dtimer
real :: grav_dtimer
public blob_util_init
public blob_chksum
public lagrangian_system_chksum
public E_and_L_totals
public blob_delete
public insert_blob
public count_blob
public put_att
public inq_var
public get_double
public get_int
public put_double
public put_int
public def_var
public blob_util_end
public write_blobs
public check_ijcell
public check_kcell
public kill_blob
public free_blob_memory
public hashfun
public unlink_blob
public allocate_interaction_memory
public reallocate_interaction_memory
public interp_tcoeff
public interp_ucoeff
public check_cyclic
! variables that are read in during init
integer :: index_temp
integer :: index_salt
integer :: global_sum_flag
integer :: num_prog_tracers
logical :: bitwise_reproduction
logical :: debug_this_module
logical :: really_debug
integer :: isd,ied,jsd,jed
integer :: isc,iec,jsc,jec
integer :: isg,ieg,jsg,jeg
integer :: nk
integer :: isbd, iebd, jsbd, jebd
real :: blob_small_mass
contains
!######################################################################
! <SUBROUTINE NAME="blob_util_init">
!
! <DESCRIPTION>
! Initialises this module.
! </DESCRIPTION>
!
subroutine blob_util_init(Grid, Domain, PE_info, Blob_domain, &
sum_flag, num_tracers, itemp, isalt, &
small_mass, dtime, bitwise, ver_coordinate_class,&
ver_coordinate, debug, debug_lots)
type(ocean_grid_type), intent(in), target :: Grid
type(ocean_domain_type), intent(in), target :: Domain
type(ocean_domain_type), intent(in), target :: Blob_domain
type(blob_grid_type), intent(in), target :: PE_info
integer, intent(in) :: sum_flag
integer, intent(in) :: num_tracers
integer, intent(in) :: itemp
integer, intent(in) :: isalt
real, intent(in) :: small_mass
real, intent(in) :: dtime
logical, intent(in) :: bitwise
integer, intent(in) :: ver_coordinate_class
integer, intent(in) :: ver_coordinate
logical, intent(in) :: debug
logical, intent(in) :: debug_lots
real, dimension(:,:), allocatable :: dxte, dxue, dytn, dyun, verticies
real, dimension(:,:), allocatable :: lon_vert, lat_vert
integer, dimension(:), allocatable :: tile_ids
integer :: tile, nlon, nlat
integer :: stdoutunit
integer :: nfstatus, gsfile, x_vert_t_id, y_vert_t_id, ni, nj
integer :: i,j,m, iscii,jscjj
integer :: ii(4), jj(4)
logical :: do_wst_bnd, do_est_bnd, do_nth_bnd, do_sth_bnd
logical :: other_vars
character(len=128) :: filename
stdoutunit = stdout()
write (stdoutunit, '(/,a)') 'Note from ocean_blob_util_mod: Initialising ocean_blob_util_mod'
Grd => Grid
Dom => Domain
Bdom => Blob_domain
Info => PE_info
isd=Dom%isd; ied=Dom%ied; jsd=Dom%jsd; jed=Dom%jed
isc=Dom%isc; iec=Dom%iec; jsc=Dom%jsc; jec=Dom%jec
isg=Dom%isg; ieg=Dom%ieg; jsg=Dom%jsg; jeg=Dom%jeg
ni = Grd%ni; nk = Grd%nk
nip1 = ni+1
nig = ieg-(isg-1); njg = jeg-(jsg-1)
isbd=Bdom%isd; iebd=Bdom%ied; jsbd=Bdom%jsd; jebd=Bdom%jed
index_temp = itemp
index_salt = isalt
num_prog_tracers = num_tracers
global_sum_flag = sum_flag
bitwise_reproduction = bitwise
blob_small_mass = small_mass
debug_this_module = debug
really_debug = debug_lots
vert_coordinate_class = ver_coordinate_class
vert_coordinate = ver_coordinate
! handy constants
grav_rho0r = grav*rho0r
two_omega = 2 * omega_earth
dtimer = 1./dtime
grav_dtimer = grav*dtimer
!1: (i,j)
!2: (i+1,j), 3: (i+1,j+1), 4: (i,j+1), 5: (i-1,j+1)
!6: (i-1,j), 7: (i-1,j-1), 8: (i,j-1), 9: (i+1,j-1)
im(1)= 0; jm(1)= 0
im(2)= 1; jm(2)= 0
im(3)= 1; jm(3)= 1
im(4)= 0; jm(4)= 1
im(5)=-1; jm(5)= 1
im(6)=-1; jm(6)= 0
im(7)=-1; jm(7)=-1
im(8)= 0; jm(8)=-1
im(9)= 1; jm(9)=-1
allocate(xt(isbd:iebd, jsbd:jebd))
allocate(yt(isbd:iebd, jsbd:jebd))
allocate(xu(isbd:iebd, jsbd:jebd))
allocate(yu(isbd:iebd, jsbd:jebd))
xt(isc:iec, jsc:jec) = Grd%xt(isc:iec, jsc:jec)
yt(isc:iec, jsc:jec) = Grd%yt(isc:iec, jsc:jec)
xu(isc:iec, jsc:jec) = Grd%xu(isc:iec, jsc:jec)
yu(isc:iec, jsc:jec) = Grd%yu(isc:iec, jsc:jec)
call mpp_update_domains(xt(:,:), Bdom%domain2d, complete=.false.)
call mpp_update_domains(yt(:,:), Bdom%domain2d, complete=.false.)
call mpp_update_domains(xu(:,:), Bdom%domain2d, complete=.false.)
call mpp_update_domains(yu(:,:), Bdom%domain2d, complete=.true.)
! For cyclic boundary conditions, we need to adjust the halo values
! for lon and lat so that the lon and lat are always monotonic
! on the one processor to make the calculations for the point location
! scheme a bit easier.
if (Grd%cyclic_x) then
do_wst_bnd = .false.
do_est_bnd = .false.
do j=jsc,jec
if (xt(iec+1,j) < xt(iec, j)) do_est_bnd=.true.
if (xt(isc, j) < xt(isc-1,j)) do_wst_bnd=.true.
enddo
allocate(dxte(isbd:iebd,jsbd:jebd))
allocate(dxue(isbd:iebd,jsbd:jebd))
dxte(isc:iec,jsc:jec) = Grd%dxte(isc:iec,jsc:jec)
dxue(isc:iec,jsc:jec) = Grd%dxue(isc:iec,jsc:jec)
call mpp_update_domains(dxte(:,:), Bdom%domain2d)
call mpp_update_domains(dxue(:,:), Bdom%domain2d)
if (do_wst_bnd) then
xt(isc-1,jsc:jec) = &
xt(isc ,jsc:jec) - rad_to_deg*2*dxte(isc-1,jsc:jec)/(Info%ht(isc ,jsc:jec,1)+Info%ht(isc-1,jsc:jec,1))
xt(isc-2,jsc:jec) = &
xt(isc-1,jsc:jec) - rad_to_deg*2*dxte(isc-2,jsc:jec)/(Info%ht(isc-1,jsc:jec,1)+Info%ht(isc-2,jsc:jec,1))
xu(isc-1,jsc:jec) = &
xu(isc ,jsc:jec) - rad_to_deg*2*dxue(isc-1,jsc:jec)/(Info%hu(isc ,jsc:jec,2)+Info%hu(isc-1,jsc:jec,2))
xu(isc-2,jsc:jec) = &
xu(isc-1,jsc:jec) - rad_to_deg*2*dxue(isc-2,jsc:jec)/(Info%hu(isc-1,jsc:jec,2)+Info%hu(isc-2,jsc:jec,2))
! Take care of the corners
if(Info%pe_NW /= NULL_PE) then
xt(isc-1,jed:jebd) = &
xt(isc ,jed:jebd) - rad_to_deg*2*dxte(isc-1,jed:jebd)/(Info%ht(isc ,jed:jebd,1)+Info%ht(isc-1,jed:jebd,1))
xt(isc-2,jed:jebd) = &
xt(isc-1,jed:jebd) - rad_to_deg*2*dxte(isc-2,jed:jebd)/(Info%ht(isc-1,jed:jebd,1)+Info%ht(isc-2,jed:jebd,1))
xu(isc-1,jed:jebd) = &
xu(isc ,jed:jebd) - rad_to_deg*2*dxue(isc-1,jed:jebd)/(Info%hu(isc ,jed:jebd,2)+Info%hu(isc-1,jed:jebd,2))
xu(isc-2,jed:jebd) = &
xu(isc-1,jed:jebd) - rad_to_deg*2*dxue(isc-2,jed:jebd)/(Info%hu(isc-1,jed:jebd,2)+Info%hu(isc-2,jed:jebd,2))
endif
if(Info%pe_SW /= NULL_PE) then
xt(isc-1,jsbd:jsd) = &
xt(isc ,jsbd:jsd) - rad_to_deg*2*dxte(isc-1,jsbd:jsd)/(Info%ht(isc ,jsbd:jsd,1)+Info%ht(isc-1,jsbd:jsd,1))
xt(isc-2,jsbd:jsd) = &
xt(isc-1,jsbd:jsd) - rad_to_deg*2*dxte(isc-2,jsbd:jsd)/(Info%ht(isc-1,jsbd:jsd,1)+Info%ht(isc-2,jsbd:jsd,1))
xu(isc-1,jsbd:jsd) = &
xu(isc ,jsbd:jsd) - rad_to_deg*2*dxue(isc-1,jsbd:jsd)/(Info%hu(isc ,jsbd:jsd,2)+Info%hu(isc-1,jsbd:jsd,2))
xu(isc-2,jsbd:jsd) = &
xu(isc-1,jsbd:jsd) - rad_to_deg*2*dxue(isc-2,jsbd:jsd)/(Info%hu(isc-1,jsbd:jsd,2)+Info%hu(isc-2,jsbd:jsd,2))
endif
endif
if (do_est_bnd) then
xt(iec+1,jsc:jec) = &
xt(iec ,jsc:jec) + rad_to_deg*2*dxte(iec ,jsc:jec)/(Info%ht(iec ,jsc:jec,1)+Info%ht(iec+1,jsc:jec,1))
xt(iec+2,jsc:jec) = &
xt(iec+1,jsc:jec) + rad_to_deg*2*dxte(iec+1,jsc:jec)/(Info%ht(iec+1,jsc:jec,1)+Info%ht(iec+2,jsc:jec,1))
xu(iec+1,jsc:jec) = &
xu(iec ,jsc:jec) + rad_to_deg*2*dxue(iec ,jsc:jec)/(Info%hu(iec ,jsc:jec,2)+Info%hu(iec+1,jsc:jec,2))
xu(iec+2,jsc:jec) = &
xu(iec+1,jsc:jec) + rad_to_deg*2*dxue(iec+1,jsc:jec)/(Info%hu(iec+1,jsc:jec,2)+Info%hu(iec+2,jsc:jec,2))
! Take care of the corners
if(Info%pe_NE /= NULL_PE) then
xt(iec+1,jed:jebd) = &
xt(iec ,jed:jebd) + rad_to_deg*2*dxte(iec ,jed:jebd)/(Info%ht(iec ,jed:jebd,1)+Info%ht(iec+1,jed:jebd,1))
xt(iec+2,jed:jebd) = &
xt(iec+1,jed:jebd) + rad_to_deg*2*dxte(iec+1,jed:jebd)/(Info%ht(iec+1,jed:jebd,1)+Info%ht(iec+2,jed:jebd,1))
xu(iec+1,jed:jebd) = &
xu(iec ,jed:jebd) + rad_to_deg*2*dxue(iec ,jed:jebd)/(Info%hu(iec ,jed:jebd,2)+Info%hu(iec+1,jed:jebd,2))
xu(iec+2,jed:jebd) = &
xu(iec+1,jed:jebd) + rad_to_deg*2*dxue(iec+1,jed:jebd)/(Info%hu(iec+1,jed:jebd,2)+Info%hu(iec+2,jed:jebd,2))
endif
if(Info%pe_SE /= NULL_PE) then
xt(iec+1,jsbd:jsd) = &
xt(iec ,jsbd:jsd) + rad_to_deg*2*dxte(iec ,jsbd:jsd)/(Info%ht(iec ,jsbd:jsd,1)+Info%ht(iec+1,jsbd:jsd,1))
xt(iec+2,jsbd:jsd) = &
xt(iec+1,jsbd:jsd) + rad_to_deg*2*dxte(iec+1,jsbd:jsd)/(Info%ht(iec+1,jsbd:jsd,1)+Info%ht(iec+2,jsbd:jsd,1))
xu(iec+1,jsbd:jsd) = &
xu(iec ,jsbd:jsd) + rad_to_deg*2*dxue(iec ,jsbd:jsd)/(Info%hu(iec ,jsbd:jsd,2)+Info%hu(iec+1,jsbd:jsd,2))
xu(iec+2,jsbd:jsd) = &
xu(iec+1,jsbd:jsd) + rad_to_deg*2*dxue(iec+1,jsbd:jsd)/(Info%hu(iec+1,jsbd:jsd,2)+Info%hu(iec+2,jsbd:jsd,2))
endif
endif
deallocate(dxte)
deallocate(dxue)
endif
if (Grd%cyclic_y .or. Grd%tripolar) then
do_nth_bnd = .false.
do_sth_bnd = .false.
do i=isc,iec
if (yt(i,jec+1) < yt(i,jec) ) do_nth_bnd=.true.
if (yt(i,jsc) < yt(i,jsc-1)) do_sth_bnd=.true.
enddo
allocate(dytn(isbd:iebd,jsbd:jebd))
allocate(dyun(isbd:iebd,jsbd:jebd))
dytn(isc:iec,jsc:jec) = Grd%dytn(isc:iec,jsc:jec)
dyun(isc:iec,jsc:jec) = Grd%dyun(isc:iec,jsc:jec)
call mpp_update_domains(dytn(:,:), Bdom%domain2d)
call mpp_update_domains(dyun(:,:), Bdom%domain2d)
if (do_sth_bnd .and. .not. Grd%tripolar) then
! The tripolar grid has a solid southern boundary, so, we only want to alter the halos at the northern boundary
yt(isc:iec,jsc-1) = &
yt(isc:iec,jsc ) - rad_to_deg*2*dytn(isc:iec,jsc-1)/(Info%ht(isc:iec,jsc ,1)+Info%ht(isc:iec,jsc-1,1))
yt(isc:iec,jsc-2) = &
yt(isc:iec,jsc-1) - rad_to_deg*2*dytn(isc:iec,jsc-2)/(Info%ht(isc:iec,jsc-1,1)+Info%ht(isc:iec,jsc-2,1))
yu(isc:iec,jsc-1) = &
yu(isc:iec,jsc ) - rad_to_deg*2*dyun(isc:iec,jsc-1)/(Info%hu(isc:iec,jsc ,2)+Info%hu(isc:iec,jsc-1,2))
yu(isc:iec,jsc-2) = &
yu(isc:iec,jsc-1) - rad_to_deg*2*dyun(isc:iec,jsc-2)/(Info%hu(isc:iec,jsc-1,2)+Info%hu(isc:iec,jsc-2,2))
! Do the corners
if (Info%pe_SW /= NULL_PE) then
yt(isbd:isd,jsc-1) = &
yt(isbd:isd,jsc ) - rad_to_deg*2*dytn(isbd:isd,jsc-1)/(Info%ht(isbd:isd,jsc ,1)+Info%ht(isbd:isd,jsc-1,1))
yt(isbd:isd,jsc-2) = &
yt(isbd:isd,jsc-1) - rad_to_deg*2*dytn(isbd:isd,jsc-2)/(Info%ht(isbd:isd,jsc-1,1)+Info%ht(isbd:isd,jsc-2,1))
yu(isbd:isd,jsc-1) = &
yu(isbd:isd,jsc ) - rad_to_deg*2*dyun(isbd:isd,jsc-1)/(Info%hu(isbd:isd,jsc ,2)+Info%hu(isbd:isd,jsc-1,2))
yu(isbd:isd,jsc-2) = &
yu(isbd:isd,jsc-1) - rad_to_deg*2*dyun(isbd:isd,jsc-2)/(Info%hu(isbd:isd,jsc-1,2)+Info%hu(isbd:isd,jsc-2,2))
endif
if (Info%pe_SE /= NULL_PE) then
yt(ied:iebd,jsc-1) = &
yt(ied:iebd,jsc ) - rad_to_deg*2*dytn(ied:iebd,jsc-1)/(Info%ht(ied:iebd,jsc ,1)+Info%ht(ied:iebd,jsc-1,1))
yt(ied:iebd,jsc-2) = &
yt(ied:iebd,jsc-1) - rad_to_deg*2*dytn(ied:iebd,jsc-2)/(Info%ht(ied:iebd,jsc-1,1)+Info%ht(ied:iebd,jsc-2,1))
yu(ied:iebd,jsc-1) = &
yu(ied:iebd,jsc ) - rad_to_deg*2*dyun(ied:iebd,jsc-1)/(Info%hu(ied:iebd,jsc ,2)+Info%hu(ied:iebd,jsc-1,2))
yu(ied:iebd,jsc-2) = &
yu(ied:iebd,jsc-1) - rad_to_deg*2*dyun(ied:iebd,jsc-2)/(Info%hu(ied:iebd,jsc-1,2)+Info%hu(ied:iebd,jsc-2,2))
endif
endif
if (do_nth_bnd) then
yt(isc:iec,jec+1) = &
yt(isc:iec,jec ) + rad_to_deg*2*dytn(isc:iec,jsc )/(Info%ht(isc:iec,jec ,1)+Info%ht(isc:iec,jec+1,1))
yt(isc:iec,jec+2) = &
yt(isc:iec,jec+1) + rad_to_deg*2*dytn(isc:iec,jsc+1)/(Info%ht(isc:iec,jec+1,1)+Info%ht(isc:iec,jec+2,1))
yu(isc:iec,jec+1) = &
yu(isc:iec,jec ) + rad_to_deg*2*dyun(isc:iec,jsc )/(Info%hu(isc:iec,jec ,2)+Info%hu(isc:iec,jec+1,2))
yu(isc:iec,jec+2) = &
yu(isc:iec,jec+1) + rad_to_deg*2*dyun(isc:iec,jsc+1)/(Info%hu(isc:iec,jec+1,2)+Info%hu(isc:iec,jec+2,2))
! Do the corners
if (Info%pe_NW /= NULL_PE) then
yt(isbd:isd,jec+1) = &
yt(isbd:isd,jec ) + rad_to_deg*2*dytn(isbd:isd,jsc )/(Info%ht(isbd:isd,jec ,1)+Info%ht(isbd:isd,jec+1,1))
yt(isbd:isd,jec+2) = &
yt(isbd:isd,jec+1) + rad_to_deg*2*dytn(isbd:isd,jsc+1)/(Info%ht(isbd:isd,jec+1,1)+Info%ht(isbd:isd,jec+2,1))
yu(isbd:isd,jec+1) = &
yu(isbd:isd,jec ) + rad_to_deg*2*dyun(isbd:isd,jsc )/(Info%hu(isbd:isd,jec ,2)+Info%hu(isbd:isd,jec+1,2))
yu(isbd:isd,jec+2) = &
yu(isbd:isd,jec+1) + rad_to_deg*2*dyun(isbd:isd,jsc+1)/(Info%hu(isbd:isd,jec+1,2)+Info%hu(isbd:isd,jec+2,2))
endif
if (Info%pe_NE /= NULL_PE) then
yt(ied:iebd,jec+1) = &
yt(ied:iebd,jec ) + rad_to_deg*2*dytn(ied:iebd,jsc )/(Info%ht(ied:iebd,jec ,1)+Info%ht(ied:iebd,jec+1,1))
yt(ied:iebd,jec+2) = &
yt(ied:iebd,jec+1) + rad_to_deg*2*dytn(ied:iebd,jsc+1)/(Info%ht(ied:iebd,jec+1,1)+Info%ht(ied:iebd,jec+2,1))
yu(ied:iebd,jec+1) = &
yu(ied:iebd,jec ) + rad_to_deg*2*dyun(ied:iebd,jsc )/(Info%hu(ied:iebd,jec ,2)+Info%hu(ied:iebd,jec+1,2))
yu(ied:iebd,jec+2) = &
yu(ied:iebd,jec+1) + rad_to_deg*2*dyun(ied:iebd,jsc+1)/(Info%hu(ied:iebd,jec+1,2)+Info%hu(ied:iebd,jec+2,2))
endif
endif
deallocate(dytn)
deallocate(dyun)
endif
allocate( datdtime_r(isd:ied,jsd:jed) )
datdtime_r(:,:) = Grd%datr(:,:)/dtime
! Calculate the vectors of the sides of grid cells (in
! the horizontal) for the point location scheme.
allocate( vert_t(2,4,isd:ied,jsd:jed) )
allocate(tile_ids(mpp_get_current_ntile(Dom%domain2d)))
tile_ids = mpp_get_tile_id(Dom%domain2d)
tile = tile_ids(1) ! Assume one tile per PE
deallocate(tile_ids)
call get_grid_size('OCN', tile, nlon, nlat)
allocate(lon_vert(nlon+1, nlat+1))
allocate(lat_vert(nlon+1, nlat+1))
call get_grid_cell_vertices('OCN', tile, lon_vert, lat_vert)
! In this grid configuration, we derive the verticies from a 2d configuration
! with shape (isc:iec+1,jsc:jec+1).
! The verticies with the bottom left hand corner corresponding to i,j
!
! 4 3
! +-----+
! | i,j |
! +-----+
! 1 2
!
! 1==(i,j); 2==(i+1,j); 3==(i+1,j+1); 4==(i,j+1)
call mpp_update_domains(lon_vert(:,:), Dom%domain2d)
vert_t(1, 1, isc:iec, jsc:jec) = lon_vert(isc:iec, jsc:jec)
vert_t(1, 2, isc:iec, jsc:jec) = lon_vert((1+isc):(1+iec), jsc:jec)
vert_t(1, 3, isc:iec, jsc:jec) = lon_vert((1+isc):(1+iec), (1+jsc):(1+jec))
vert_t(1, 4, isc:iec, jsc:jec) = lon_vert(isc:iec, (1+jsc):(1+jec))
call mpp_update_domains(lat_vert(:,:), Dom%domain2d)
vert_t(2, 1, isc:iec, jsc:jec) = lat_vert(isc:iec, jsc:jec)
vert_t(2, 2, isc:iec, jsc:jec) = lat_vert((1+isc):(1+iec), jsc:jec)
vert_t(2, 3, isc:iec, jsc:jec) = lat_vert((1+isc):(1+iec), (1+jsc):(1+jec))
vert_t(2, 4, isc:iec, jsc:jec) = lat_vert(isc:iec, (1+jsc):(1+jec))
deallocate(lon_vert)
deallocate(lat_vert)
! Now fill/get the values in the halos
if (Info%pe_E==NULL_PE) vert_t(:,:,ied,jsc:jec) = 0.0
if (Info%pe_N==NULL_PE) vert_t(:,:,isc:iec,jed) = 0.0
if (Info%pe_W==NULL_PE) vert_t(:,:,isd,jsc:jec) = 0.0
if (Info%pe_S==NULL_PE) vert_t(:,:,isc:iec,jsd) = 0.0
if (Info%pe_NE==NULL_PE) vert_t(:,:,ied,jed) = 0.0
if (Info%pe_NW==NULL_PE) vert_t(:,:,isd,jed) = 0.0
if (Info%pe_SW==NULL_PE) vert_t(:,:,isd,jsd) = 0.0
if (Info%pe_SE==NULL_PE) vert_t(:,:,ied,jsd) = 0.0
! The verticies are indexed from southwest, anticlockwise
! 4-----3
! | |
! | T |
! | |
! 1-----2
!Pre calculate some of the vectors for the point location scheme
!See notes for details
allocate( ij_im1j( 2,isd:ied,jsd:jed) )
allocate( im1jm1_ijm1(2,isd:ied,jsd:jed) )
allocate( ij_ijm1( 2,isd:ied,jsd:jed) )
allocate( im1jm1_im1j(2,isd:ied,jsd:jed) )
allocate( t_im1j( 2,isd:ied,jsd:jed) )
allocate( t_ij( 2,isd:ied,jsd:jed) )
allocate( t_ijm1( 2,isd:ied,jsd:jed) )
allocate( t_im1jm1( 2,isd:ied,jsd:jed) )
!North vector: U(i ,j )=>U(i-1,j ), aka 3=>4
ij_im1j( :,isd:ied,jsd:jed) = vert_t(:,4,isd:ied,jsd:jed) - vert_t(:,3,isd:ied,jsd:jed)
!South vector: U(i-1,j-1)=>U(i-1,j ), aka 1=>2
im1jm1_ijm1(:,isd:ied,jsd:jed) = vert_t(:,2,isd:ied,jsd:jed) - vert_t(:,1,isd:ied,jsd:jed)
!East vector: U(i ,j )=>U(i ,j-1), aka 3=>2
ij_ijm1( :,isd:ied,jsd:jed) = vert_t(:,2,isd:ied,jsd:jed) - vert_t(:,3,isd:ied,jsd:jed)
!West vector: U(i-1,j-1)=>U(i-1,j ), aka 1=>4
im1jm1_im1j(:,isd:ied,jsd:jed) = vert_t(:,4,isd:ied,jsd:jed) - vert_t(:,1,isd:ied,jsd:jed)
!T(i,j)=>U(i-1,j-1)
t_im1jm1(1,isd:ied,jsd:jed) = vert_t(1,1,isd:ied,jsd:jed) - Grd%xt(isd:ied,jsd:jed)
t_im1jm1(2,isd:ied,jsd:jed) = vert_t(2,1,isd:ied,jsd:jed) - Grd%yt(isd:ied,jsd:jed)
!T(i,j)=>U(i ,j-1)
t_ijm1(1,isd:ied,jsd:jed) = vert_t(1,2,isd:ied,jsd:jed) - Grd%xt(isd:ied,jsd:jed)
t_ijm1(2,isd:ied,jsd:jed) = vert_t(2,2,isd:ied,jsd:jed) - Grd%yt(isd:ied,jsd:jed)
!T(i,j)=>U(i ,j )
t_ij(1,isd:ied,jsd:jed) = vert_t(1,3,isd:ied,jsd:jed) - Grd%xt(isd:ied,jsd:jed)
t_ij(2,isd:ied,jsd:jed) = vert_t(2,3,isd:ied,jsd:jed) - Grd%yt(isd:ied,jsd:jed)
!T(i,j)=>U(i-1,j )
t_im1j(1,isd:ied,jsd:jed) = vert_t(1,4,isd:ied,jsd:jed) - Grd%xt(isd:ied,jsd:jed)
t_im1j(2,isd:ied,jsd:jed) = vert_t(2,4,isd:ied,jsd:jed) - Grd%yt(isd:ied,jsd:jed)
allocate(Info%maxlon(jsc:jec))
allocate(Info%minlon(jsc:jec))
allocate(Info%maxlat(isc:iec))
allocate(Info%minlat(isc:iec))
do j=jsc,jec
Info%minlon(j) = minval(vert_t(1,:,isc:iec,j))
Info%maxlon(j) = maxval(vert_t(1,:,isc:iec,j))
enddo
do i=isc,iec
Info%minlat(i) = minval(vert_t(2,:,i,jsc:jec))
Info%maxlat(i) = maxval(vert_t(2,:,i,jsc:jec))
enddo
end subroutine blob_util_init
! </SUBROUTINE> NAME="blob_util_init"
!######################################################################
! <SUBROUTINE NAME="blob_chksum">
!
! <DESCRIPTION>
! Performs global sums and checksums for all blob types (for diagnostic
! purposes).
! </DESCRIPTION>
!
subroutine blob_chksum(T_prog, head_static_free, head_static_bott, &
head_dynamic_free, head_dynamic_bott, blob_counter)
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_blob_type), pointer :: head_static_free
type(ocean_blob_type), pointer :: head_static_bott
type(ocean_blob_type), pointer :: head_dynamic_free
type(ocean_blob_type), pointer :: head_dynamic_bott
integer, dimension(isc:iec,jsc:jec,nk), intent(in) :: blob_counter
type(ocean_blob_type), pointer :: this=>NULL()
real, dimension(isd:ied,jsd:jed,nk,num_prog_tracers) :: grdtracer, grdfield
real, dimension(isd:ied,jsd:jed,nk) :: grdlat, grdlon, grddepth, grdgeodepth
real, dimension(isd:ied,jsd:jed,nk) :: grdu, grdv, grdw, grdent
real, dimension(isd:ied,jsd:jed,nk) :: grdmass, grddens, grdvolume
real, dimension(isd:ied,jsd:jed,nk) :: grdh1, grdh2, grdstep, grdst
integer, dimension(isd:ied,jsd:jed,nk) :: grdhash, grdnum
integer, dimension(isd:ied,jsd:jed,nk) :: grdnsteps, grdmsteps
integer, dimension(isd:ied,jsd:jed,nk) :: grdi, grdj, grdk
integer :: tmpi
integer :: i, j, k, p, n, nblobs
character(len=28) :: tname
character(len=28) :: fname
character(len=*), parameter :: fmti="(a,x,i25)"
character(len=*), parameter :: fmte="(a,x,es25.18)"
integer :: stdoutunit
real :: tmpr
stdoutunit=stdout()
grdlat(:,:,:) = 0.0
grdlon(:,:,:) = 0.0
grddepth(:,:,:) = 0.0
grdgeodepth(:,:,:) = 0.0
grdst(:,:,:) = 0.0
grdmass(:,:,:) = 0.0
grddens(:,:,:) = 0.0
grdvolume(:,:,:) = 0.0
grdu(:,:,:) = 0.0
grdv(:,:,:) = 0.0
grdw(:,:,:) = 0.0
grdent(:,:,:) = 0.0
grdh1(:,:,:) = 0.0
grdh2(:,:,:) = 0.0
grdstep(:,:,:) = 0.0
grdtracer(:,:,:,:) = 0.0
grdfield(:,:,:,:) = 0.0
grdhash(:,:,:) = 0
grdnum(:,:,:) = 0
grdnsteps(:,:,:) = 0
grdmsteps(:,:,:) = 0
grdi(:,:,:) = 0
grdj(:,:,:) = 0
grdk(:,:,:) = 0
nblobs = 0 !number of blobs
do p=1,4
nullify(this)
if(p==1 .and. associated(head_static_free)) this=>head_static_free
if(p==2 .and. associated(head_static_bott)) this=>head_static_bott
if(p==3 .and. associated(head_dynamic_free)) this=>head_dynamic_free
if(p==4 .and. associated(head_dynamic_bott)) this=>head_dynamic_bott
if (associated(this)) then
fullcycle: do
i = this%i - Dom%ioff
j = this%j - Dom%joff
k = this%k
if (isc<=i .and. i<=iec .and. jsc<=j .and. j<=jec) then
grdlat(i,j,k) = grdlat(i,j,k) + this%lat
grdlon(i,j,k) = grdlon(i,j,k) + this%lon
grddepth(i,j,k) = grddepth(i,j,k) + this%depth
grdgeodepth(i,j,k) = grdgeodepth(i,j,k) + this%geodepth
grdst(i,j,k) = grdst(i,j,k) + this%st
grdmass(i,j,k) = grdmass(i,j,k) + this%mass
grddens(i,j,k) = grddens(i,j,k) + this%density
grdvolume(i,j,k) = grdvolume(i,j,k) + this%volume
grdu(i,j,k) = grdu(i,j,k) + this%v(1)
grdv(i,j,k) = grdv(i,j,k) + this%v(2)
grdw(i,j,k) = grdw(i,j,k) + this%v(3)
grdent(i,j,k) = grdent(i,j,k) + this%ent
grdh1(i,j,k) = grdh1(i,j,k) + this%h1
grdh2(i,j,k) = grdh2(i,j,k) + this%h2
grdhash(i,j,k) = grdhash(i,j,k) + this%hash
grdnum(i,j,k) = grdnum(i,j,k) + this%number
grdstep(i,j,k) = grdstep(i,j,k) + this%step
grdnsteps(i,j,k) = grdnsteps(i,j,k) + this%nsteps
grdmsteps(i,j,k) = grdmsteps(i,j,k) + this%model_steps
grdi(i,j,k) = grdi(i,j,k) + this%i
grdj(i,j,k) = grdj(i,j,k) + this%j
grdk(i,j,k) = grdk(i,j,k) + this%k
nblobs = nblobs + 1
do n=1,num_prog_tracers
grdtracer(i,j,k,n) = grdtracer(i,j,k,n) + this%tracer(n)
if (p==3.or.p==4) grdfield(i,j,k,n) = grdfield(i,j,k,n) + this%field(n)
enddo
endif
this=>this%next
if(.not. associated(this)) exit fullcycle
enddo fullcycle
endif
enddo
call mpp_sum(nblobs)
write(stdoutunit, fmti) 'total number of blobs =', nblobs
tmpi = sum(blob_counter(:,:,:))
call mpp_sum(tmpi)
write(stdoutunit, fmti) 'global number of blobs for all time =', tmpi
tmpr = mpp_global_sum(Dom%domain2d, grdmass(isc:iec,jsc:jec,1:nk),global_sum_flag)
write(stdoutunit, fmte) 'global mass of blobs =', tmpr
do n=1,num_prog_tracers
tmpr = mpp_global_sum(Dom%domain2d, grdtracer(isc:iec,jsc:jec,1:nk,n),global_sum_flag)
if(n==index_temp) then
write(stdoutunit, fmte) 'global heat content of blobs =', tmpr
else
tname = trim(T_prog(n)%name)//' content of blobs'
fname = trim(T_prog(n)%name)//' concentration of blobs'
write(stdoutunit, fmte) 'global '//tname(:)//' =', tmpr
endif
enddo
call write_chksum_3d_int('blob counter', blob_counter(COMP,1:nk))
call write_chksum_3d('blob latitude', grdlat(COMP,1:nk))
call write_chksum_3d('blob longitude', grdlon(COMP,1:nk))
call write_chksum_3d('blob depth', grddepth(COMP,1:nk))
call write_chksum_3d('blob geodepth', grdgeodepth(COMP,1:nk))
call write_chksum_3d('blob vertical coord. (st)', grdst(COMP,1:nk))
call write_chksum_3d('blob mass', grdmass(COMP,1:nk))
call write_chksum_3d('blob density', grddens(COMP,1:nk))
call write_chksum_3d('blob volume', grdvolume(COMP,1:nk))
call write_chksum_3d('blob zonal velocity', grdu(COMP,1:nk))
call write_chksum_3d('blob meridional velocity', grdv(COMP,1:nk))
call write_chksum_3d('blob vertical velocity', grdw(COMP,1:nk))
call write_chksum_3d('blob entrainment velocity', grdent(COMP,1:nk))
call write_chksum_3d('stretching function 1', grdh1(COMP,1:nk))
call write_chksum_3d('stretching function 2', grdh2(COMP,1:nk))
call write_chksum_3d_int('blob number', grdnum(COMP,1:nk))
call write_chksum_3d('blob step size', grdstep(COMP,1:nk))
call write_chksum_3d_int('number of blob steps', grdnsteps(COMP,1:nk))
call write_chksum_3d_int('number of E system steps', grdmsteps(COMP,1:nk))
call write_chksum_3d_int('zonal cell index (i)', grdi(COMP,1:nk))
call write_chksum_3d_int('meridional cell index (j)', grdj(COMP,1:nk))
call write_chksum_3d_int('depth cell index (k)', grdk(COMP,1:nk))
do n=1,num_prog_tracers
if (n==index_temp) then
call write_chksum_3d('blob heat content', grdtracer(COMP,1:nk,n))
call writE_chksum_3d('blob temp concentration', grdfield(COMP,1:nk,n))
else
tname = trim(T_prog(n)%name)//' content'
call write_chksum_3d('blob '//tname(1:19), grdtracer(COMP,1:nk,n))
call write_chksum_3d(fname(1:19), grdfield(COMP,1:nk,n))
endif
enddo
write(stdoutunit, '(a)') 'end blob chksums'
end subroutine blob_chksum
! </SUBROUTINE> NAME="blob_chksum"
!######################################################################
! <SUBROUTINE NAME="lagrangian_system_chksum">
!
! <DESCRIPTION>
!
! Performs checksums for the Lagrangian_system derived type. This is
! the derived type that stores all of the "gridded" blob variables,
! and is essential for the accounting required to interact with the
! Eulerian model in a conservative manner. The checksums are for
! diagnostic purposes.
!
! </DESCRIPTION>
!
subroutine lagrangian_system_chksum(L_system)
type(ocean_lagrangian_type), intent(in) :: L_system
integer :: stdoutunit
character(len=*), parameter :: fmt="(a,x,i20)"
stdoutunit=stdout()
call write_chksum_3d('T-grid upper cell rho_dzt (taup1)', L_system%rho_dztup(COMP,1:nk))
call write_chksum_3d('T-grid lower cell rho_dzt (taup1)', L_system%rho_dztlo(COMP,1:nk))
call write_chksum_3d('T-grid blob convergence (taup1)', L_system%conv_blob(COMP,1:nk))
write(stdoutunit, fmt) 'end Lagrangian system chksums'
end subroutine lagrangian_system_chksum
! </SUBROUTINE> NAME="lagrangian_system_chksum"
!######################################################################
! <SUBROUTINE NAME="E_and_L_totals">
!
! <DESCRIPTION>
! Gives a brief summary of the total mass, volume and tracer content
! of the E, L and total systems. Usually used for debuggin purposes.
! </DESCRIPTION>
!
subroutine E_and_L_totals(L_system, Thickness, T_prog, idx)
type(ocean_lagrangian_type), intent(in) :: L_system
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
integer, intent(in) :: idx
real, dimension(isd:ied,jsd:jed) :: tmpE, tmpL1, tmpL2, tmpT
real :: tmpE_total, tmpL1_total, tmpL2_total, tmpT_total
character(len=128) :: tname
integer :: n, k
integer :: stdoutunit
stdoutunit=stdout()
tmpE = Grd%dat(:,:)*sum(Grd%tmask(:,:,:)*Thickness%rho_dzt( :,:,:,idx),3)
tmpL1 = Grd%dat(:,:)*sum(Grd%tmask(:,:,:)*Thickness%rho_dztL(:,:,:,idx),3)
do k=1,nk
tmpL2 = Grd%tmask(:,:,k)*Grd%dat(:,:)*(L_system%rho_dztup(:,:,k)+L_system%rho_dztlo(:,:,k))
enddo
tmpT = Grd%dat(:,:)*sum(Grd%tmask(:,:,:)*Thickness%rho_dztT(:,:,:,idx),3)
call maketotal(.true.)
write(stdoutunit,'(a,x,es25.18,x,a)') 'E mass =',tmpE_total, 'kg'
write(stdoutunit,'(a,x,es25.18,x,a)') 'L mass (from thickness) =',tmpL1_total,'kg'
write(stdoutunit,'(a,x,es25.18,x,a)') 'L mass (from L_system) =',tmpL2_total,'kg'
write(stdoutunit,'(a,x,es25.18,x,a)') 'E + L mass =',tmpE_total+tmpL1_total,'kg'
write(stdoutunit,'(a,x,es25.18,x,a)') 'T mass (from rho_dztT) =',tmpT_total,'kg'
tmpE = Grd%dat(:,:)*sum(Grd%tmask(:,:,:)*Thickness%dzt( :,:,:),3)
tmpL1 = Grd%dat(:,:)*sum(Grd%tmask(:,:,:)*Thickness%dztL(:,:,:),3)
tmpT = Grd%dat(:,:)*sum(Grd%tmask(:,:,:)*Thickness%dztT(:,:,:,idx),3)
call maketotal(.true.)
write(stdoutunit,'(a,x,es25.18,x,a)') 'E volume =',tmpE_total, 'm^3'
write(stdoutunit,'(a,x,es25.18,x,a)') 'L volume (from thickness) =',tmpL1_total,'m^3'
write(stdoutunit,'(a,x,es25.18,x,a)') 'E + L volume =',tmpE_total+tmpL1_total,'m^3'
write(stdoutunit,'(a,x,es25.18,x,a)') 'T volume (from dztT) =',tmpT_total,'m^3'
do n=1,num_prog_tracers
tmpE = T_prog(n)%conversion*Grd%dat(:,:) &
*sum( Grd%tmask(:,:,:)*Thickness%rho_dzt(:,:,:,idx)*T_prog(n)%field(:,:,:,idx), 3)
tmpL1 = T_prog(n)%conversion*sum(Grd%tmask(:,:,:)*T_prog(n)%sum_blob(:,:,:,idx), 3)
tmpT = tmpE + tmpL1
call maketotal(.false.)
if(n==index_temp) then
write(stdoutunit,'(a,x,es25.18,x,a)') 'E heat =',tmpE_total, 'J'
write(stdoutunit,'(a,x,es25.18,x,a)') 'L heat =',tmpL1_total,'J'
write(stdoutunit,'(a,x,es25.18,x,a)') 'T heat =',tmpT_total, 'J'
elseif(T_prog(n)%name(1:3)=='age') then
tname = trim(T_prog(n)%name)
write(stdoutunit,'(a,x,es25.18,x,a)') 'E '//tname(1:10)//' =',tmpE_total, 'yr'
write(stdoutunit,'(a,x,es25.18,x,a)') 'L '//tname(1:10)//' =',tmpL1_total,'yr'
write(stdoutunit,'(a,x,es25.18,x,a)') 'T '//tname(1:10)//' =',tmpT_total, 'yr'
else
tname = trim(T_prog(n)%name)
write(stdoutunit,'(a,x,es25.18,x,a)') 'E '//tname(1:10)//' =',tmpE_total, 'kg'
write(stdoutunit,'(a,x,es25.18,x,a)') 'L '//tname(1:10)//' =',tmpL1_total,'kg'
write(stdoutunit,'(a,x,es25.18,x,a)') 'T '//tname(1:10)//' =',tmpT_total, 'kg'
endif
enddo
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! This is a nested subroutine that does the global sum of an array for !
! each of the E system, L system and the combined system. !
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine maketotal(do_L2)
logical, intent(in) :: do_L2
tmpE_total = mpp_global_sum(Dom%domain2d, tmpE, global_sum_flag)
tmpL1_total = mpp_global_sum(Dom%domain2d, tmpL1, global_sum_flag)
tmpT_total = mpp_global_sum(Dom%domain2d, tmpT, global_sum_flag)
if (do_L2) then
tmpL2_total = mpp_global_sum(Dom%domain2d, tmpL2, global_sum_flag)
endif
end subroutine maketotal
end subroutine E_and_L_totals
! </SUBROUTINE> NAME="E_and_L_totals"
!######################################################################
! <SUBROUTINE NAME="write_blobs">
!
! <DESCRIPTION>
! Dumps most of the information carried around by blobs, for all blobs
! in a particular list. Useful for debugging.
! </DESCRIPTION>
!
subroutine write_blobs(head, head_name, time)
type(ocean_blob_type), pointer :: head
character(len=*), intent(in) :: head_name
character(len=*), intent(in) :: time
type(ocean_blob_type), pointer :: this=>NULL()
integer :: i,j,n
integer :: stdoutunit
stdoutunit = stdout()
write(stdoutunit, '(a)') ' '
write(stdoutunit, '(a)') 'Summary of all blobs in '//trim(head_name)//' list ('//trim(time)//')'
write(stdoutunit,'(4(a3,x),2(a6,x),4(a6,x),2(a10,x),1(a8,x),2(a10,x),2(a6,x),3(a9,x),(a10))') &
'pe','i','j','k', &
'hash','number', &
'lat','lon','depth', 'gdepth',&
'mass','volume','density', &
'heat','S (kg)', &
'temp','sal', &
'u','v','w', &
'dzt'
n=0
if(associated(head)) then
this=>head
blobcycle: do
i=this%i; j=this%j
print('(4(i3,x),2(i6,x),4(f6.1,x),2(es10.3,x),(f8.2,x),2(es10.3,x),2(f6.2,x),3(es9.2,x),(es10.3))'), &
Info%pe_this, i, j, this%k,&
this%hash, this%number, &
this%lat, this%lon, this%depth, this%geodepth,&
this%mass, this%volume, &
this%density,&
this%tracer(index_temp), this%tracer(index_salt), &
this%field(index_temp), this%field(index_salt),&
this%v(1), this%v(2), this%v(3), &
this%volume*Grd%datr(i,j)
n=n+1
this=>this%next
if(.not.associated(this)) exit blobcycle
enddo blobcycle
endif
print('(a,i3,a,i10)'), 'total '//trim(head_name)//' blobs on pe ',Info%pe_this,' = ', n
end subroutine write_blobs
! </SUBROUTINE> NAME="write_blobs"
!######################################################################
! <SUBROUTINE NAME="blob_delete">
!
! <DESCRIPTION>
! Deletes all (nearly) zero mass blob objects from the linked list.
! The size of the blobs that are deleted is controlled by the variable
! blob_small_mass in the ocean_blob_nml.
! </DESCRIPTION>
!
subroutine blob_delete(Time, Thickness, T_prog, head)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(inout) :: Thickness
type(ocean_prog_tracer_type), intent(inout) :: T_prog(:)
type(ocean_blob_type), pointer :: head
! local variables
type(ocean_blob_type), pointer :: prev => NULL()
type(ocean_blob_type), pointer :: this => NULL()
type(ocean_blob_type), pointer :: next => NULL()
integer :: i,j,k,tau,taup1
taup1 = Time%taup1
tau = Time%tau
! point this to the head blob
this => head
!====================================================================!
! if the head is not associated, the list is empty and there is !
! nothing to delete if it is associated, then cycle through the list,!
! deleting all zero-mass blobs until the end (tail) of the list is !
! reached !
!====================================================================!
! check if the head is associated
if(associated(this)) then
next => this%next
blobdel: do
i = this%i
j = this%j
k = this%k
if(this%mass < blob_small_mass) then
! return any blob properties to the E system
call kill_blob(Thickness, T_prog(:), this, i, j, k)
! Deallocate the blob from memory
call free_blob_memory(this)
! Unlink the blob from the list. Point the previous blob
! to the next blob and vice versa.
if(associated(prev)) then
prev%next=>next
else
! if the prev is not associated, we are at the head
! and we need to point the head towards the next
head => next
if(associated(next)) next%prev=>NULL()
endif
! this is the vice versa bit
if(associated(next)) next%prev=>prev
endif ! blob mass small?
! check to see whether we are at the end of the list. If so, exit
! the loop. If not, then move our current, prev and next blobs
! further down the list and go back to the beginning of the do loop
if(associated(next)) then
this => next
prev => this%prev
next => this%next
else
exit blobdel
endif
enddo blobdel
nullify(this)
nullify(prev)
nullify(next)
endif !head associated?
end subroutine blob_delete
! </SUBROUTINE> NAME="blob_delete"
!######################################################################
! <SUBROUTINE NAME="unlink_blob">
!
! <DESCRIPTION>
! Unlinks a blob from a doubly linked list. It returns pointers to
! the blob, the head of the list, the (formerly) previous blob in the
! list and the (formerly) next blob in the list.
! </DESCRIPTION>
!
subroutine unlink_blob(blob, head, prev, next)
type(ocean_blob_type), pointer :: blob
type(ocean_blob_type), pointer :: head
type(ocean_blob_type), pointer :: prev
type(ocean_blob_type), pointer :: next
prev=>blob%prev
next=>blob%next
! Unlink the list from the blob
if(associated(prev)) then
prev%next=>next
else
head=>next
if(associated(next)) next%prev=>NULL()
endif
if(associated(next)) next%prev=>prev
! Unlink the blob from the list
blob%next=>NULL()
blob%prev=>NULL()
end subroutine unlink_blob
! </SUBROUTINE> NAME="unlink_blob"
!######################################################################
! <SUBROUTINE NAME="insert_blob">
!
! <DESCRIPTION>
! Inserts a blob to the linked list. The relative order of blobs in
! a linked list determines whether bitwise reproduction is possible.
!
! Regardless of bitwise reproducability or not, we must ensure that
! blobs always appear in the same relative order when we are using
! dynamic blobs because if we have a situation where dztL>dztT, we
! start destroying blobs to enforce dztL<dztT. In order that we do
! not significantly change answers, we must always destroy the same
! blob, regardless of domain decomposition, restarts, etc. So, we must
! always sort blobs so they appear in the linked list in the same
! relative order.
! </DESCRIPTION>
!
subroutine insert_blob(blob, head)
type(ocean_blob_type), pointer :: blob
type(ocean_blob_type), pointer :: head
! local variables
type(ocean_blob_type), pointer :: prev
type(ocean_blob_type), pointer :: next
logical :: order, eol
integer :: stdoutunit
stdoutunit = stdout()
if (associated(head)) then
prev => NULL()
next => head
! cycle through hash, looking for a spot
checkhash: do
call inorder(blob%hash, next%hash, order, eol)
if (eol .or. order) exit checkhash
enddo checkhash
if (eol) return
! cycle through the blob number, ensuring we remain
! in the correct hash
checknumber: do
if (blob%hash > next%hash) then
order = .true.
elseif(blob%hash == next%hash) then
call inorder(blob%number, next%number, order, eol)
else
write(stdoutunit,'(a)') 'ocean_blob_util_mod, insert_blob: list out of order'
call debugoutput('blob information (hash and number)', prev, blob, next)
call mpp_error(FATAL, 'ocean_blob_util_mod, insert_blob: list out of order')
endif
if (eol .or. order) exit checknumber
enddo checknumber
if (eol) return
! if we have made it this far, then we have not reached the end of the
! list and the blob should be in its correct place in the list, so
! insert it into the list between prev and next, or if we are at the
! top of the list, insert it at the head.
if (associated(prev)) then
! insert the blob after the previous blob
prev%next => blob
blob%prev => prev
else
! insert the blobs at the head of the list
head => blob
blob%prev => NULL()
endif
next%prev => blob
blob%next => next
else !head associated
! the list is empty, so make the blob the only item in the list
head => blob
blob%next => NULL()
blob%prev => NULL()
endif !head associated
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! This is a nested subroutine that checks if the blob is in the right spot
! in the linked list
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine inorder(var1, var2, foundslot, eolist)
integer, intent(in) :: var1, var2
logical, intent(out) :: foundslot, eolist
foundslot = .false.
eolist = .false.
if (var1 >= var2) then
foundslot = .true.
else
call checkeol(eolist)
if (.not. eolist) then
! move down the list
prev => next
next => next%next
endif
endif
end subroutine inorder
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! This is a nested subroutine that checks if we are at the end of the
! linked list
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine checkeol(endoflist)
logical :: endoflist
endoflist = .false.
if(.not. associated(next%next)) then
! we are at the end of the list
next%next => blob
blob%prev => next
blob%next => NULL()
endoflist = .true.
endif
end subroutine checkeol
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! This is a nested subroutine that outputs useful debugging information
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine debugoutput(message, pr, th, ne)
type(ocean_blob_type), pointer :: pr, th, ne
character(len=*), intent(in) :: message
print ('(/,a)'), trim(message)
if(associated(pr)) then
print('(a5,2i6)'), 'prev:', pr%hash, pr%number
else
print('(a19)'), 'prev not associated'
endif
if(associated(th)) then
print('(a5,2i6)'), 'this:', th%hash, th%number
else
print('(a19)'), 'this not associated'
endif
if(associated(ne)) then
print('(a5,2i6)'), 'next:', ne%hash, ne%number
else
print('(a19)'), 'next not associated'
endif
end subroutine debugoutput
end subroutine insert_blob
! </SUBROUTINE> NAME="insert_blob"
!######################################################################
! <SUBROUTINE NAME="count_blob">
!
! <DESCRIPTION>
! Allocates a blob its hash and a number. These two numbers can
! uniquely identify any blob. The hash and number is based on the grid
! cell of origin. Each grid cell has a unique hash. We have an array
! which keeps track of the number of blobs formed in a grid cell. These
! two numbers give the unique identifier. So, we also need to increment
! the counter array.
! </DESCRIPTION>
!
subroutine count_blob(blob, blob_counter)
type(ocean_blob_type) :: blob
integer, dimension(isc:iec,jsc:jec,nk), intent(inout) :: blob_counter
integer :: ii, jj, kk
blob%hash = hashfun(blob%i, blob%j, blob%k)
ii = blob%i
jj = blob%j
kk = blob%k
blob%number = blob_counter(ii, jj, kk) + 1
blob_counter(ii,jj,kk) = blob%number
end subroutine count_blob
! </SUBROUTINE> NAME="count_blob"
!######################################################################
! <SUBROUTINE NAME="put_att">
!
! <DESCRIPTION>
! Writes an attribute to a netcdf file.
! </DESCRIPTION>
!
subroutine put_att(ncid, id, att, attval)
integer, intent(in) :: ncid, id
character (len=*), intent(in) :: att, attval
integer :: vallen, mret
integer :: stderrunit
stderrunit=stderr()
! Define the attribute for the netcdf file
vallen=len_trim(attval)
mret = nf_put_att_text(ncid, id, att, vallen, attval)
! If something goes wrong give error and bring the model down
if (mret .ne. NF_NOERR) then
write(stderrunit,'(a)') 'ocean_blob_util_mod, putt_att: '&
//'nf_put_att_text failed adding '//trim(att)//' = '//trim(attval)
write(stderrunit,'(3x,a,i3)') 'error code = ',mret
call give_error_code(mret)
call error_mesg('ocean_blob_util_mod, put_att', &
'netcdf function returned a failure!', FATAL)
endif
end subroutine put_att
! </SUBROUTINE> NAME="put_att"
!######################################################################
! <FUNCTION NAME="inq_var">
!
! <DESCRIPTION>
! Gets the variable identifier from a netcdf file.
! </DESCRIPTION>
!
integer function inq_var(ncid, var)
integer, intent(in) :: ncid
character(len=*), intent(in) :: var
integer :: iret
integer :: stderrunit
stderrunit = stderr()
iret = nf_inq_varid(ncid, var, inq_var)
if (iret .ne. NF_NOERR) then
write(stderrunit,*) 'ocean_blob_util_mod, inq_var: nf_inq_varid ',&
var,' failed'
call error_mesg('ocean_blob_util_mod, inq_var', &
'netcdf function returned a failure!', FATAL)
endif
end function inq_var
! </FUNCTION> NAME="inq_var"
!######################################################################
! <FUNCTION NAME="get_double">
!
! <DESCRIPTION>
! Gets the value of a "double" variable from a netcdf file
! </DESCRIPTION>
!
real function get_double(ncid, id, m)
integer, intent(in) :: ncid, id, m
integer :: iret
integer :: stderrunit
stderrunit = stderr()
iret=nf_get_var1_double(ncid, id, m, get_double)
if (iret .ne. NF_NOERR) then
write(stderrunit,'(a)') 'ocean_blob_util_mod, get_double: ' &
//'nf_get_var1_double failed reading'
call error_mesg('ocean_blob_util_mod, get_double', &
'netcdf function returned a failure!', FATAL)
endif
end function get_double
! </FUNCTION> NAME="get_double"
!######################################################################
! <FUNCTION NAME="get_int">
!
! <DESCRIPTION>
! Gets the value of an integer variable from a netcdf file
! </DESCRIPTION>
!
integer function get_int(ncid, id, m)
integer, intent(in) :: ncid, id, m
integer :: iret
integer :: stderrunit
stderrunit = stderr()
iret=nf_get_var1_int(ncid, id, m, get_int)
if (iret .ne. NF_NOERR) then
write(stderrunit,'(a)') 'ocean_blob_util_mod, get_int: '&
//'nf_get_var1_double failed reading'
call error_mesg('ocean_blob_util_mod, get_int', &
'netcdf function returned a failure!', FATAL)
endif
end function get_int
! </FUNCTION> NAME="get_int"
!######################################################################
! <SUBROUTINE NAME="put_double">
!
! <DESCRIPTION>
! Writes the value of a "double" variable to a netcdf file
! </DESCRIPTION>
!
subroutine put_double(ncid, varid, start, val)
integer, intent(in) :: ncid, varid, start
real, intent(in) :: val
integer :: mret, mret1
character(len=31) :: varname
integer :: stderrunit
stderrunit = stderr()
mret = nf_put_vara_double(ncid, varid, start, 1, val)
if (mret .ne. NF_NOERR) then
mret1 = nf_inq_varname(ncid, varid, varname)
write(stderrunit,*) 'ocean_blob_util_mod, put_double: '&
//'nf_put_vara_double failed writing'//trim(varname)
write(stderrunit, '(a,i10)') 'Failed with error code: ', mret
print *, 'ocean_blob_util_mod, put_double: '&
//'nf_put_vara_double failed writing '//trim(varname)
print *, 'Failed with error code: ', mret
call give_error_code(mret)
call error_mesg('ocean_blob_util_mod, put_double', &
'netcdf function returned a failure!', FATAL)
endif
end subroutine put_double
! </SUBROUTINE> NAME="put_double"
!######################################################################
! <SUBROUTINE NAME="put_int">
!
! <DESCRIPTION>
! Writes the value of an integer variable to a netcdf file
! </DESCRIPTION>
!
subroutine put_int(ncid, varid, start, val)
integer, intent(in) :: ncid, varid, start, val
integer :: mret, mret1
character(len=31) :: varname
integer :: stderrunit
stderrunit = stderr()
mret = nf_put_vara_int(ncid, varid, start, 1, val)
if (mret .ne. NF_NOERR) then
mret1 = nf_inq_varname(ncid, varid, varname)
write(stderrunit,*) 'ocean_blob_util_mod, put_int: '&
//'nf_put_vara_int failed writing '//trim(varname)
write(stderrunit, '(a,i10)') 'Failed with error code: ', mret
print *, 'ocean_blob_util_mod, put_int: '&
//'nf_put_vara_int failed writing '//trim(varname)
print *, 'Failed with error code: ', mret
call give_error_code(mret)
call error_mesg('ocean_blob_util_mod, put_int', &
'netcdf function returned a failure!', FATAL)
endif
end subroutine put_int
! </SUBROUTINE> NAME="put_int"
!######################################################################
! <FUNCTION NAME="def_var">
!
! <DESCRIPTION>
! Defines a netcdf variable
! </DESCRIPTION>
!
integer function def_var(ncid, var, ntype, idim)
integer, intent(in) :: ncid
integer, intent(in) :: ntype
integer, intent(in) ::idim
character(len=*), intent(in) :: var
integer :: mret
character(len=30) :: problem
integer :: stderrunit
stderrunit = stderr()
mret = nf_def_var(ncid, var, ntype, 1, idim, def_var)
if (mret .ne. NF_NOERR) then
write(stderrunit,'(a,i4)') 'ocean_blob_util_mod, def_var: '//&
'nf_def_var failed for '//trim(var)//'with error code ',mret
write(stderrunit,'(3x,a,i3)') 'error code = ',mret
call give_error_code(mret)
call error_mesg('ocean_blob_util_mod, '//trim(problem), &
'netcdf function returned a failure!', FATAL)
endif
end function def_var
! </FUNCTION> NAME="def_var"
!######################################################################
! <SUBROUTINE NAME="give_error_code">
!
! <DESCRIPTION>
! Gives error descriptions for netcdf calls.
! </DESCRIPTION>
!
subroutine give_error_code(retval)
integer :: retval
print *, ' '
if(retval == NF_EBADDIM) print *, 'Bad dimension'
if(retval == NF_ENAMEINUSE) print *, 'Name already in use'
if(retval == NF_ENOTVAR) print *, 'Not a variable'
end subroutine give_error_code
! </SUBROUTINE> NAME="give_error_code"
!######################################################################
! <FUNCTION NAME="hashfun">
!
! <DESCRIPTION>
! Calculates the hash
! </DESCRIPTION>
!
integer function hashfun(i,j,k)
integer, intent(in) :: i
integer, intent(in) :: j
integer, intent(in) :: k
hashfun = k + nk*j + Info%nk_nj*i
end function hashfun
! </FUNCTION> NAME="hashfun"
!######################################################################
! <SUBROUTINE NAME="blob_util_end">
!
! <DESCRIPTION>
! Does what is necessary to shut down the module.
! </DESCRIPTION>
!
subroutine blob_util_end()
nullify(Info)
nullify(Grd)
nullify(Dom)
end subroutine blob_util_end
! </SUBROUTINE> NAME="blob_util_end"
!######################################################################
! <SUBROUTINE NAME="check_ijcell">
!
! <DESCRIPTION>
! Checks whether a blob (horizontally) resides in a grid cell or not.
! If it does not it figures out which direction the blob is in and
! checks the neighbouring grid cell, until it finds which grid cell
! the blob resides in.
!
! It uses a cross product technique from computational geometry
! (Cormen et al., 2001).
! </DESCRIPTION>
!
subroutine check_ijcell(dx, dy, i, j, h, a, lon, lat, off)
real, intent(in) :: dx
real, intent(in) :: dy
integer, intent(inout) :: i
integer, intent(inout) :: j
real, dimension(2), intent(inout) :: h
real, dimension(2), intent(in) :: a
real, intent(out) :: lon
real, intent(out) :: lat
logical, dimension(2), intent(out) :: off
real, dimension(2) :: b, a_b, b_ij, b_im1jm1, t_b
logical :: check_north, check_south, check_east, check_west, doublecheck
integer :: new_i, new_j
integer :: stdoutunit
stdoutunit = stdout()
! set default values
check_north = .true.
check_south = .true.
check_east = .true.
check_west = .true.
doublecheck = .true.
! Update the blob longitude and latitude and calculate the required vectors
a_b(1) = dx/h(1)
a_b(2) = dy/h(2)
a_b(:) = rad_to_deg*a_b(:)
b(:) = a(:) + a_b(:)
new_i = i
new_j = j
! The verticies are indexed from southwest, anticlockwise
! 4-----3 U(i-1,j ) == im1j == 4
! | | U(i ,j ) == ij == 3
! | T | tracer cell, T(i,j)
! | a-+-b U(i j-1) == ijm1 == 2
! 1-----2 U(i-1,j-1) == im1jm1 == 1
! a is the start position of the blob and b is the end position
checkcell: do while (doublecheck)
doublecheck = .false.
b_im1jm1(:) = vert_t(:,1,i,j) - b(:)
b_ij(:) = vert_t(:,3,i,j) - b(:)
t_b(1) = b(1) - xt(i,j)
t_b(2) = b(2) - yt(i,j)
if (check_north) then
if( cross( t_im1j(:,i,j), t_b(:) ) < 0.0 .and. & !T=>i-1j x T =>b
cross( t_ij(:,i,j), t_b(:) ) > 0.0 .and. & !T=>ij x T =>b
cross( b_ij(:), ij_im1j(:,i,j) ) < 0.0 ) then !b=>ij x ij=>i-1j
new_j=new_j+1
check_south = .false.
doublecheck = .true.
endif
endif
if (check_south) then
if( cross( t_ijm1(:,i,j), t_b(:) ) < 0.0 .and. & !T=>ij-1 x T =>b
cross( t_im1jm1(:,i,j), t_b(:) ) > 0.0 .and. & !b=>i-1j-1 x T =>b
cross( b_im1jm1(:), im1jm1_ijm1(:,i,j) ) < 0.0 ) then !b=>i-1j-1 x i-1j-1=>ij-1
new_j=new_j-1
check_north = .false.
doublecheck = .true.
endif
endif
if (check_east) then
if( cross( t_ij(:,i,j), t_b(:) ) < 0.0 .and. & !T=>ij x T =>b
cross( t_ijm1(:,i,j), t_b(:) ) > 0.0 .and. & !T=>ij-1 x T =>b
cross( b_ij(:), ij_ijm1(:,i,j) ) > 0.0 ) then !b=>ij x ij=>ij-1
new_i=new_i+1
check_west = .false.
doublecheck = .true.
endif
endif
if (check_west) then
if( cross( t_im1jm1(:,i,j), t_b(:) ) < 0.0 .and. & !T=>i-1j-1 x T =>b
cross( t_im1j(:,i,j), t_b(:) ) > 0.0 .and. & !T=>i-1j x T =>b
cross( b_im1jm1(:), im1jm1_im1j(:,i,j) ) > 0.0) then !b=>i-1j-1 x i-1j-1=>i-1j
new_i=new_i-1
check_east = .false.
doublecheck = .true.
endif
endif
if (new_i<isd .or. ied<new_i .or. new_j<jsd .or. jed<new_j) then
if (bitwise_reproduction) then
write (stdoutunit, '(a,i4,a,a,2(i4,a),a,4(i4,a))') &
'Error on pe ',Info%pe_this, ' a blob has gone outside the halo. ',&
'blobs (i,j) location = (',new_i,',',new_j,') ', &
'(isd:ied,jsd:jed) = (',isd,':',ied,',',jsd,':',jed,')'
call mpp_error(FATAL, &
'==>Error in ocean_blob_util_mod (check_ijcell): ' &
//'blob has gone outside of halo.')
else
b(:) = a(:)
exit checkcell
endif
else
i = new_i
j = new_j
endif
enddo checkcell
off(1:2) = .false.
if (i<isc .or. iec<i) off(1) = .true.
if (j<jsc .or. jec<j) off(2) = .true.
lon = b(1)
lat = b(2)
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! A nested function that does the cross product of two vectors of length!
! two. !
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pure function cross(vec1,vec2)
real :: cross
real, intent(in) :: vec1(2)
real, intent(in) :: vec2(2)
cross = vec1(1)*vec2(2) - vec1(2)*vec2(1)
end function cross
end subroutine check_ijcell
! </SUBROUTINE> NAME="check_ijcell"
!######################################################################
! <SUBROUTINE NAME="check_kcell">
!
! <DESCRIPTION>
! Searches for which (vertical) grid cell a blob resides in).
! </DESCRIPTION>
!
subroutine check_kcell(Time,Ext_mode,Thickness,geodepth,w,i,j,k,off)
type(ocean_time_type), intent(in) :: Time
type(ocean_external_mode_type), intent(in) :: Ext_mode
type(ocean_thickness_type), intent(in) :: Thickness
real, intent(in) :: geodepth
real, intent(in) :: w
integer, intent(in) :: i
integer, intent(in) :: j
integer, intent(inout) :: k
logical, intent(out) :: off
integer :: tau, increment
logical :: foundk
tau = Time%tau
off = .false.
foundk = .false.
! Check if the blob has gone out of bounds. This can happen even if
! a blob does not change from one k level to another.
if (geodepth < -Ext_mode%eta_t(i,j,tau)) then
k=1
off=.true.
return
elseif (geodepth > Grd%ht(i,j)) then
k=Grd%kmt(i,j)
off=.true.
return
endif
! Next, check if the blob remains in the same vertical k-level.
if (k>1) then
if (Thickness%geodepth_zwt(i,j,k-1) < geodepth .and. geodepth <= Thickness%geodepth_zwt(i,j,k)) foundk=.true.
else
if (-Ext_mode%eta_t(i,j,tau) < geodepth .and. geodepth <= Thickness%geodepth_zwt(i,j,k)) foundk=.true.
endif
if (foundk) then
! Because of the way that Thickness%geodepth_zwt is calculated, there
!can be a very small discrepency with Grd%ht. So, we double check
! that the cell that we are in is actually a water cell. If it is not,
! and we have made it here, we know that
! Thickness%geodepth_zwt(k)<geodepth<=Grd%ht for some k<kmt. However,
! there can be circumstances where, due to the discrepency between
! geodepth_zwt and ht, we can have geodepth<Grd%ht and
! Thickness%geodepth_zwt(kmt)<geodepth<=Thickness%geodepth_zwt(kmt+1).
! In these cases we need to ensure that the blob is in the kmt cell and
! not kmt+1.
if (k>Grd%kmt(i,j)) k=Grd%kmt(i,j)
return
endif
! Guess which direction to search based on the vertical velocity
if(w>=0.0) then !up
increment = -1
else !down
increment = +1
endif
kcycle: do
k = k+increment
if (k<2 .or. Grd%kmt(i,j)<k) exit kcycle !note: we need to treat the surface grid cell differently
if (Thickness%geodepth_zwt(i,j,k-1) < geodepth .and. geodepth <= Thickness%geodepth_zwt(i,j,k)) return
enddo kcycle
! Treating the surface cell
k=1
if ( -Ext_mode%eta_t(i,j,tau) < geodepth .and. geodepth <= Thickness%geodepth_zwt(i,j,1)) return
! If we have made it this far then the search has not been successful, so, we take a brute
! force approach and do a full sweep of the water column from top to bottom
column: do
k=k+1
if (k>Grd%kmt(i,j)) exit column !something is wrong
if (Thickness%geodepth_zwt(i,j,k-1) < geodepth .and. geodepth <= Thickness%geodepth_zwt(i,j,k)) return
enddo column
! Somtimes, there can be really small differences between Thickness%geodepth_zwt(kmt) and Grd%ht.
! So, we check against Grd%ht before raising an error
if (Thickness%geodepth_zwt(i,j,Grd%kmt(i,j))<geodepth .and. geodepth<=Grd%ht(i,j)) then
k = Grd%kmt(i,j)
return
endif
! By now, we have covered all bases, so if we have made it this far, there is a problem with the logic
! of the search algorithm, so, we raise a fatal error
call mpp_error(FATAL, 'ocean_blob_util_mod, check_kcell: Cannot find vertical cell for blob!')
end subroutine check_kcell
! </SUBROUTINE> NAME="check_kcell"
!######################################################################
! <SUBROUTINE NAME="kill_blob">
!
! <DESCRIPTION>
! Kills a blob by returning all of its remaining properties to the E
! system.
! </DESCRIPTION>
!
subroutine kill_blob(Thickness, T_prog, this, i, j, k)
type(ocean_thickness_type), intent(inout) :: Thickness
type(ocean_prog_tracer_type), intent(inout) :: T_prog(:)
type(ocean_blob_type), pointer :: this
integer, intent(in) :: i
integer, intent(in) :: j
integer, intent(in) :: k
integer :: n
Thickness%blob_source(i,j) = Thickness%blob_source(i,j) &
+ datdtime_r(i,j)*this%mass
this%mass = 0.0
do n=1,num_prog_tracers
T_prog(n)%tend_blob(i,j,k) = T_prog(n)%tend_blob(i,j,k) &
+ this%tracer(n)*datdtime_r(i,j)
this%tracer(n) = 0.0
enddo
end subroutine kill_blob
! </SUBROUTINE> NAME="kill_blob"
!######################################################################
! <SUBROUTINE NAME="free_blob_memory">
!
! <DESCRIPTION>
! Frees the heap memory taken up by a blob.
! </DESCRIPTION>
!
subroutine free_blob_memory(blob)
type(ocean_blob_type), pointer :: blob
deallocate(blob)
nullify(blob)
end subroutine free_blob_memory
! </SUBROUTINE> NAME="free_blob_memory"
!######################################################################
! <SUBROUTINE NAME="allocate_interaction_memory">
!
! <DESCRIPTION>
! Allocates the history arrays for a blob (only used when
! bitwise_reproduction=.true. in the ocean_blob_nml).
! </DESCRIPTION>
!
subroutine allocate_interaction_memory(blob, total_ns)
type(ocean_blob_type), pointer :: blob
integer, intent(in) :: total_ns
allocate(blob%dtracer(num_prog_tracers))
if (bitwise_reproduction) then
allocate(blob%di(0:total_ns))
allocate(blob%dj(0:total_ns))
allocate(blob%dk(0:total_ns))
allocate(blob%entrainment(1:total_ns,0:num_prog_tracers))
allocate(blob%detrainment(1:total_ns,0:num_prog_tracers))
allocate(blob%mass_in(1:total_ns))
allocate(blob%mass_out(0:total_ns))
endif
end subroutine allocate_interaction_memory
! </SUBROUTINE> NAME="allocate_interaction_memory"
!######################################################################
! <SUBROUTINE NAME="reallocate_interaction_memory">
!
! <DESCRIPTION>
! Different blobs can have different history memory requirements.
! When they change from one type of blob to another, we need to change
! the memory allocated to a blob to reflect the new requirements. This
! is only necessary if bitwise_reproduction=.true. in the ocean_blob_nml.
! </DESCRIPTION>
!
subroutine reallocate_interaction_memory(blob, head, total_ns)
type(ocean_blob_type), pointer :: blob
type(ocean_blob_type), pointer :: head
integer, intent(in) :: total_ns
type(ocean_blob_type), pointer :: new_blob
! Allocate memory to the new blob
allocate(new_blob)
allocate(new_blob%tracer(num_prog_tracers))
allocate(new_blob%field( num_prog_tracers))
call allocate_interaction_memory(new_blob, total_ns)
! Copy the data from the old blob to the new blob
new_blob%i = blob%i
new_blob%j = blob%j
new_blob%k = blob%k
new_blob%m = blob%m
new_blob%kdw = blob%kdw
new_blob%kup = blob%kup
new_blob%hash = blob%hash
new_blob%number = blob%number
new_blob%model_steps = blob%model_steps
new_blob%nsteps = blob%nsteps
new_blob%sink = blob%sink
new_blob%new = blob%new
new_blob%h1 = blob%h1
new_blob%h2 = blob%h2
new_blob%lat = blob%lat
new_blob%lon = blob%lon
new_blob%depth = blob%depth
new_blob%geodepth = blob%geodepth
new_blob%st = blob%st
new_blob%mass = blob%mass
new_blob%density = blob%density
new_blob%densityr = blob%densityr
new_blob%volume = blob%volume
new_blob%tracer(:) = blob%tracer(:)
new_blob%field(:) = blob%field(:)
new_blob%step = blob%step
new_blob%nfrac_steps = blob%nfrac_steps
new_blob%v(:) = blob%v(:)
! Unlink the blob from the list, and link in the new blob
new_blob%next => blob%next
if(associated(new_blob%next)) new_blob%next%prev=>new_blob
new_blob%prev => blob%prev
if(associated(new_blob%prev)) then
new_blob%prev%next=>new_blob
else
head=>new_blob
endif
! Deallocate memory from the old blob
call free_blob_memory(blob)
! Now point to the new bit of memory
blob => new_blob
end subroutine reallocate_interaction_memory
! </SUBROUTINE> NAME="reallocate_interaction_memory"
!######################################################################
! <SUBROUTINE NAME="interp_tcoeff">
!
! <DESCRIPTION>
! Used for the horizontal interpolation of T grid variables. The
! routine returns coefficients required for inverse distance
! weighting (Shephard, 1968).
! </DESCRIPTION>
!
subroutine interp_tcoeff(i, j, h, lon, lat, dsq_r)
integer, intent(in) :: i
integer, intent(in) :: j
real, dimension(2), intent(in) :: h
real, intent(in) :: lon
real, intent(in) :: lat
real, dimension(9), intent(out) :: dsq_r
real, dimension(9) :: distance
integer :: m, iit, jjt
distance(:) = 0.0
! We have special treatment for solid boundaries
tcoeff: do m=1,Info%tidx(0,i,j)
iit = i+Info%it(Info%tidx(m,i,j))
jjt = j+Info%jt(Info%tidx(m,i,j))
! Calculate the distance from each point to the blob
! We do not need to include deg_to_rad because it cancels anyway
distance(m) = onehalf &
*sqrt( abs(lon-xt(iit,jjt))**2 * (h(1)+Info%ht(iit,jjt,1))**2 &
+abs(lat-yt(iit,jjt))**2 * (h(2)+info%ht(iit,jjt,2))**2 )
if (distance(m)<epsln) then
dsq_r(:) = 0.0
dsq_r(m) = 1.0
exit tcoeff
endif
! Accumulate that distance
dsq_r(m) = 1.0/distance(m)**2
enddo tcoeff
end subroutine interp_tcoeff
! </SUBROUTINE> NAME="interp_tcoeff"
!######################################################################
! <SUBROUTINE NAME="interp_ucoeff">
!
! <DESCRIPTION>
! Used for the horizontal interpolation of U grid variables. The
! routine returns coefficients required for inverse distance
! weighting (Shephard, 1968).
! </DESCRIPTION>
!
subroutine interp_ucoeff(i, j, h, lon, lat, dsq_r)
integer, intent(in) :: i
integer, intent(in) :: j
real, dimension(2), intent(in) :: h
real, intent(in) :: lon
real, intent(in) :: lat
real, dimension(4), intent(out) :: dsq_r
real, dimension(4) :: distance
integer :: m, iiu, jju
!Initialise some variables
distance(:) = 0.0
ucoeff: do m=1,Info%uidx(0,i,j)
iiu = i+Info%iu(Info%uidx(m,i,j))
jju = j+Info%ju(Info%uidx(m,i,j))
! Calculate the distance from each point to the blob
! We do not need to include deg_to_rad because it cancels anyway
distance(m) = onehalf &
*sqrt( abs(lon-xu(iiu,jju))**2 * (h(1)+Info%hu(iiu,jju,1))**2 &
+abs(lat-yu(iiu,jju))**2 * (h(2)+Info%hu(iiu,jju,2))**2 )
if (distance(m)<epsln) then
dsq_r(:) = 0.0
dsq_r(m) = 1.0
exit ucoeff
endif
! Accumulate that distance
dsq_r(m) = 1.0/distance(m)**2
enddo ucoeff
end subroutine interp_ucoeff
! </SUBROUTINE> NAME="interp_ucoeff"
!######################################################################
! <SUBROUTINE NAME="check_cyclic">
!
! <DESCRIPTION>
! Checks and adjusts blob position and grid cell index
! for cylclic/periodic domains, as well as
! the Murray (1996) tripolar grid.
! </DESCRIPTION>
!
subroutine check_cyclic(blob, i, j, adjust_latlon)
type(ocean_blob_type), pointer :: blob
integer, intent(inout) :: i
integer, intent(inout) :: j
logical, intent(in) :: adjust_latlon
logical :: change_ij
! If we have a cyclic grid and a blob goes from one PE to another
! we need to reset its (i,j) coordinates and its (lon,lat).
! Same with the tripolar grid. Things get a bit more
! complicated if we cross the arctic bipolar fold.
change_ij = .false.
if (Grd%cyclic_x) then
if (i<isg) then
i = nig - i
change_ij=.true.
elseif (i>ieg) then
i = i - nig
change_ij=.true.
endif
endif
if (Grd%cyclic_y) then
if (j<jsg) then
j = njg - j
change_ij=.true.
elseif (j>jeg) then
j = j - njg
change_ij=.true.
endif
elseif(Grd%tripolar) then
if (j>jeg) then
! We have crossed the bipolar Arctic fold.
! We reset the i vlue to correspond to the
! opposing i value, and reset the j value
! to be jeg.
! See figure 4.6 of Griffies et al (2004)
i = nip1 - i
j = jeg
! If we cross the geographic north pole.
if (blob%lat>90.) then
blob%lat = 180-blob%lat
blob%v(2) = -blob%v(2)
endif
if (adjust_latlon) then
! Handle the x-cyclic bit, if required
if (blob%lon<Info%minlon(j)) then
blob%lon = Info%maxlon(j) - modulo(Info%minlon(j),blob%lon)
elseif(blob%lon>Info%maxlon(j)) then
blob%lon = Info%minlon(j) + modulo(blob%lon,Info%maxlon(j))
endif
endif
endif
endif
if (adjust_latlon) then
if (change_ij) then
if (blob%lon<Info%minlon(j)) then
blob%lon = Info%maxlon(j) - modulo(Info%minlon(j),blob%lon)
elseif(blob%lon>Info%maxlon(j)) then
blob%lon = Info%minlon(j) + modulo(blob%lon,Info%maxlon(j))
endif
if (blob%lat<Info%minlat(i)) then
blob%lat = Info%maxlat(i) - modulo(Info%minlat(i),blob%lat)
elseif(blob%lat>Info%maxlat(i)) then
blob%lat = Info%minlat(i) + modulo(blob%lat,Info%maxlat(i))
endif
endif
endif
end subroutine check_cyclic
! </SUBROUTINE> NAME="check_cyclic"
end module ocean_blob_util_mod
| lgpl-3.0 |
OpenACCUserGroup/OpenACCV-V | Tests/atomic_update_x_plus_expr.F90 | 1 | 1873 | #ifndef T1
!T1:construct-independent,atomic,V:2.0-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x, y !Iterators
REAL(8),DIMENSION(LOOPCOUNT, 10):: a !Data
REAL(8),DIMENSION(LOOPCOUNT):: totals, totals_comparison
INTEGER :: errors = 0
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
totals = 0
totals_comparison = 0
!$acc data copyin(a(1:LOOPCOUNT, 1:10)) copy(totals(1:LOOPCOUNT))
!$acc parallel
!$acc loop
DO x = 1, LOOPCOUNT
DO y = 1, 10
!$acc atomic update
totals(x) = totals(x) + a(x, y)
END DO
END DO
!$acc end parallel
!$acc end data
DO x = 1, LOOPCOUNT
DO y = 1, 10
totals_comparison(x) = totals_comparison(x) + a(x, y)
END DO
END DO
DO x = 1, LOOPCOUNT
IF (totals_comparison(x) .NE. totals(x)) THEN
errors = errors + 1
WRITE(*, *) totals_comparison(x)
END IF
END DO
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
| bsd-3-clause |
ewiger/libppmnumerics | src/fft/ppm_fft_plan_3d_vec_bc2c_z.f | 1 | 6773 | !-------------------------------------------------------------------------
! Subroutine : ppm_fft_plan_3d_vec_bc2c_z
!-------------------------------------------------------------------------
! Copyright (c) 2010 CSE Lab (ETH Zurich), MOSAIC Group (ETH Zurich),
! Center for Fluid Dynamics (DTU)
!
! FFTW plan wrapper for 3d arrays, 1d complex to complex
! (backward) FFT in the z direction
! The routine does not work with fields that include ghost layers
!-------------------------------------------------------------------------
#if __KIND == __SINGLE
#define __ROUTINE ppm_fft_plan_3d_vec_bc2c_z_s
#define __PREC ppm_kind_single
#elif __KIND == __DOUBLE
#define __ROUTINE ppm_fft_plan_3d_vec_bc2c_z_d
#define __PREC ppm_kind_double
#endif
SUBROUTINE __ROUTINE(topoid,meshid,ppmplan,infield,outfield,info)
!!! FFTW plan wrapper for 3d arrays, 1d complex to complex
!!! (backward) FFT in the z direction
!!! The routine does not work with fields that include ghost layers
USE ppm_module_substart
USE ppm_module_substop
USE ppm_module_typedef
USE ppm_module_topo_get
USE ppm_module_write
USE ppm_module_data,ONLY:ppm_rank,ppm_kind_single,ppm_kind_double
IMPLICIT NONE
INCLUDE 'fftw3.f'
! if debug check if dimensions are 2a 3b 5c 7d 11e 13f
!-------------------------------------------------------------------------
! Arguments
!-------------------------------------------------------------------------
!!!topology identifier of target
INTEGER,INTENT(IN) :: topoid
!!!id of the mesh
INTEGER,INTENT(IN) :: meshid
!!!ppm fft plan type
TYPE(ppm_fft_plan),INTENT(INOUT) :: ppmplan
!!!input field to fourier transform
!COMPLEX(__PREC),DIMENSION(:,:,:,:,:),POINTER,INTENT(INOUT) :: infield
COMPLEX(__PREC),DIMENSION(:,:,:,:,:),POINTER :: infield
!!!output field for the result of the fourier transform
!COMPLEX(__PREC),DIMENSION(:,:,:,:,:),POINTER,INTENT(INOUT) :: outfield
COMPLEX(__PREC),DIMENSION(:,:,:,:,:),POINTER :: outfield
!!!Returns status, 0 upon success
INTEGER,INTENT(OUT) :: info
!in time perhaps an argument for alternate directions
!-------------------------------------------------------------------------
! Local variables
!-------------------------------------------------------------------------
REAL(__PREC) :: t0
INTEGER :: isub,isubl
INTEGER :: nsubs
INTEGER,DIMENSION(:),POINTER :: isublist
TYPE(ppm_t_topo),POINTER :: topology
TYPE(ppm_t_equi_mesh) :: mesh
!-------------------------------------------------------------------------
! Initialise routine
!-------------------------------------------------------------------------
CALL substart('ppm_fft_plan',t0,info)
!-------------------------------------------------------------------------
! Get topology and mesh values
!-------------------------------------------------------------------------
CALL ppm_topo_get(topoid,topology,info)
IF (info .NE. 0) THEN
CALL ppm_write(ppm_rank,'ppm_fft_plan','Failed to get topology.',isub)
GOTO 9999
ENDIF
nsubs = topology%nsublist
ALLOCATE(isublist(nsubs))
DO isub=1,nsubs
isublist(isub) = topology%isublist(isub)
ENDDO
mesh = topology%mesh(meshid)
!-------------------------------------------------------------------------
! Setup parameters for this particular routine
!-------------------------------------------------------------------------
!the dimension of the FFT (1D/2D/3D)
ppmplan%rank=1
!the number of points along each direction of the piece to be transformed
ALLOCATE(ppmplan%nx(ppmplan%rank,nsubs))
!the direction of the transform
ppmplan%sign=FFTW_BACKWARD
!the method to setup the optimal plan
ppmplan%flag=FFTW_MEASURE
!the number of components to transform - 3 component vector
ppmplan%howmany=3
!the size of the input array - full size (assuming LBOUND=1 thus UBOUND)
ALLOCATE(ppmplan%inembed(ppmplan%rank))
ppmplan%inembed(1) = UBOUND(infield,4)
!the size of the output array - full size (assuming LBOUND=1 thus UBOUND)
ALLOCATE(ppmplan%onembed(ppmplan%rank))
ppmplan%onembed(1) = UBOUND(outfield,4)
!istride tells how the same componenet data points are spaced in memory
!e.g. z values recur every x-dim*y-dim*component values
ppmplan%istride = UBOUND(infield,2) *UBOUND(infield,3)*3
ppmplan%ostride = UBOUND(outfield,2)*UBOUND(outfield,3)*3
!idist tells how multiple arrays are spaced in memory. I.e. a memory
!offset. e.g. vector components (idist=1) or scalar 2D arrays in
!3D array(idist=NxNy)
ppmplan%idist = 1
ppmplan%odist = 1
!-------------------------------------------------------------------------
! Allocate plan array
!-------------------------------------------------------------------------
IF(ASSOCIATED(ppmplan%plan)) THEN
DEALLOCATE(ppmplan%plan,stat=info)
IF (info .NE. 0) THEN
CALL ppm_write(ppm_rank,'ppm_fft_plan','Failed to deallocate plan-array.',isub)
GOTO 9999
ENDIF
END IF
ALLOCATE(ppmplan%plan(nsubs))
DO isub=1,nsubs
isubl=isublist(isub)
!@ maybe the -1 needs to be removed when doing cell data
!we subtract the -1 to avoid the periodic vertex point
IF (topology%bcdef(3) .EQ. ppm_param_bcdef_periodic) THEN !vertex
ppmplan%nx(1,isub) = mesh%nm(3)-1
ELSE
ppmplan%nx(1,isub) = mesh%nm(3)
ENDIF
CALL dfftw_plan_many_dft(ppmplan%plan(isub),ppmplan%rank,&
& ppmplan%nx(:,isub),ppmplan%howmany,infield(1,1,1,1,isub),&
& ppmplan%inembed(1),ppmplan%istride,ppmplan%idist,&
& outfield(1,1,1,1,isub),ppmplan%onembed(1),ppmplan%ostride,&
& ppmplan%odist,ppmplan%sign,ppmplan%flag)
END DO
!-------------------------------------------------------------------------
! Return
!-------------------------------------------------------------------------
9999 CONTINUE
CALL substop('ppm_fft_plan',t0,info)
RETURN
END SUBROUTINE __ROUTINE
#undef __ROUTINE
#undef __PREC
| gpl-3.0 |
mesjetiu/grandorgue-es | src/fftw/src/doc/f77_wisdom.f | 19 | 2924 | c Copyright (c) 2003, 2007-11 Matteo Frigo
c Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
c
c This program is free software; you can redistribute it and/or modify
c it under the terms of the GNU General Public License as published by
c the Free Software Foundation; either version 2 of the License, or
c (at your option) any later version.
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 You should have received a copy of the GNU General Public License
c along with this program; if not, write to the Free Software
c Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c This is an example implementation of Fortran wisdom export/import
c to/from a Fortran unit (file), exploiting the generic
c dfftw_export_wisdom/dfftw_import_wisdom functions.
c
c We cannot compile this file into the FFTW library itself, lest all
c FFTW-calling programs be required to link to the Fortran I/O
c libraries.
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Strictly speaking, the '$' format specifier, which allows us to
c write a character without a trailing newline, is not standard F77.
c However, it seems to be a nearly universal extension.
subroutine write_char(c, iunit)
character c
integer iunit
write(iunit,321) c
321 format(a,$)
end
subroutine export_wisdom_to_file(iunit)
integer iunit
external write_char
call dfftw_export_wisdom(write_char, iunit)
end
c Fortran 77 does not have any portable way to read an arbitrary
c file one character at a time. The best alternative seems to be to
c read a whole line into a buffer, since for fftw-exported wisdom we
c can bound the line length. (If the file contains longer lines,
c then the lines will be truncated and the wisdom import should
c simply fail.) Ugh.
subroutine read_char(ic, iunit)
integer ic
integer iunit
character*256 buf
save buf
integer ibuf
data ibuf/257/
save ibuf
if (ibuf .lt. 257) then
ic = ichar(buf(ibuf:ibuf))
ibuf = ibuf + 1
return
endif
read(iunit,123,end=666) buf
ic = ichar(buf(1:1))
ibuf = 2
return
666 ic = -1
ibuf = 257
123 format(a256)
end
subroutine import_wisdom_from_file(isuccess, iunit)
integer isuccess
integer iunit
external read_char
call dfftw_import_wisdom(isuccess, read_char, iunit)
end
| gpl-2.0 |
OpenACCUserGroup/OpenACCV-V | Tests/serial_private.F90 | 1 | 1691 | #ifndef T1
!T1:serial,private,V:2.6-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
REAL(8),DIMENSION(LOOPCOUNT, 10):: a, b
REAL(8),DIMENSION(LOOPCOUNT):: c
REAL(8),DIMENSION(10):: d
REAL(8):: temp
INTEGER:: x, y
INTEGER:: errors
errors = 0
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
CALL RANDOM_NUMBER(b)
c = 0
d = 0
!$acc data copyin(a(1:LOOPCOUNT, 1:10), b(1:LOOPCOUNT, 1:10)) copy(d(1:10))
!$acc serial private(c(1:LOOPCOUNT))
!$acc loop gang
DO y = 1, 10
!$acc loop worker
DO x = 1, LOOPCOUNT
c(x) = a(x, y) + b(x, y)
END DO
!$acc loop seq
DO x = 1, LOOPCOUNT
d(y) = d(y) + c(x)
END DO
END DO
!$acc end serial
!$acc end data
DO y = 1, 10
temp = 0
DO x = 1, LOOPCOUNT
temp = temp + (a(x, y) + b(x, y))
END DO
IF (abs(d(x) - temp) .gt. (2 * PRECISION * LOOPCOUNT)) THEN
errors = errors + 1
END IF
END DO
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
| bsd-3-clause |
huard/scipy-work | scipy/integrate/quadpack/dqags.f | 114 | 8392 | subroutine dqags(f,a,b,epsabs,epsrel,result,abserr,neval,ier,
* limit,lenw,last,iwork,work)
c***begin prologue dqags
c***date written 800101 (yymmdd)
c***revision date 830518 (yymmdd)
c***category no. h2a1a1
c***keywords automatic integrator, general-purpose,
c (end-point) singularities, extrapolation,
c globally adaptive
c***author piessens,robert,appl. math. & progr. div. - k.u.leuven
c de doncker,elise,appl. math. & prog. 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 abs(i-result).le.max(epsabs,epsrel*abs(i)).
c***description
c
c computation of a definite integral
c standard fortran subroutine
c double precision version
c
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 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 sub-
c divisions by increasing the value of limit
c (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 (e.g. singularity,
c discontinuity within the interval) one
c will probably gain from splitting up the
c interval at this point and calling the
c integrator on the subranges. if possible,
c an appropriate special-purpose integrator
c should be used, which is designed for
c handling the type of difficulty involved.
c = 2 the occurrence of roundoff error is detec-
c ted, which prevents the requested
c tolerance from being achieved.
c the error may be under-estimated.
c = 3 extremely bad integrand behaviour
c occurs 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.
c = 6 the input is invalid, because
c (epsabs.le.0 and
c epsrel.lt.max(50*rel.mach.acc.,0.5d-28)
c or limit.lt.1 or lenw.lt.limit*4.
c result, abserr, neval, last are set to
c zero.except when limit or lenw is invalid,
c iwork(1), work(limit*2+1) and
c work(limit*3+1) are set to zero, work(1)
c is set to a and work(limit+1) to b.
c
c dimensioning parameters
c limit - integer
c dimensioning parameter for iwork
c limit determines the maximum number of subintervals
c in the partition of the given integration interval
c (a,b), limit.ge.1.
c if limit.lt.1, the routine will end with ier = 6.
c
c lenw - integer
c dimensioning parameter for work
c lenw must be at least limit*4.
c if lenw.lt.limit*4, 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, detemines the
c number of significant elements actually in the work
c arrays.
c
c work arrays
c iwork - integer
c vector of dimension at least limit, the first k
c elements of which contain pointers
c to the error estimates over the subintervals
c 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),
c and k = limit+1-last otherwise
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 error estimates.
c
c***references (none)
c***routines called dqagse,xerror
c***end prologue dqags
c
c
double precision a,abserr,b,epsabs,epsrel,f,result,work
integer ier,iwork,last,lenw,limit,lvl,l1,l2,l3,neval
c
dimension iwork(limit),work(lenw)
c
external f
c
c check validity of limit and lenw.
c
c***first executable statement dqags
ier = 6
neval = 0
last = 0
result = 0.0d+00
abserr = 0.0d+00
if(limit.lt.1.or.lenw.lt.limit*4) go to 10
c
c prepare call for dqagse.
c
l1 = limit+1
l2 = limit+l1
l3 = limit+l2
c
call dqagse(f,a,b,epsabs,epsrel,limit,result,abserr,neval,
* ier,work(1),work(l1),work(l2),work(l3),iwork,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 dqags',26,ier,lvl)
return
end
| bsd-3-clause |
bryantabaird/cs6660 | Include/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
| mpl-2.0 |
aamaricci/SciFortran | src/lapack/sgttrs.f | 1 | 4197 | SUBROUTINE SGTTRS( TRANS, N, NRHS, DL, D, DU, DU2, IPIV, B, LDB,
$ INFO )
*
* -- LAPACK 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 TRANS
INTEGER INFO, LDB, N, NRHS
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
REAL B( LDB, * ), D( * ), DL( * ), DU( * ), DU2( * )
* ..
*
* Purpose
* =======
*
* SGTTRS solves one of the systems of equations
* A*X = B or A**T*X = B,
* with a tridiagonal matrix A using the LU factorization computed
* by SGTTRF.
*
* Arguments
* =========
*
* 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**T* X = B (Conjugate transpose = Transpose)
*
* N (input) INTEGER
* The order of the matrix A.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrix B. NRHS >= 0.
*
* DL (input) REAL array, dimension (N-1)
* The (n-1) multipliers that define the matrix L from the
* LU factorization of A.
*
* D (input) REAL array, dimension (N)
* The n diagonal elements of the upper triangular matrix U from
* the LU factorization of A.
*
* DU (input) REAL array, dimension (N-1)
* The (n-1) elements of the first super-diagonal of U.
*
* DU2 (input) REAL array, dimension (N-2)
* The (n-2) elements of the second super-diagonal of U.
*
* IPIV (input) INTEGER array, dimension (N)
* The pivot indices; for 1 <= i <= n, 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.
*
* B (input/output) REAL array, dimension (LDB,NRHS)
* On entry, the matrix of right hand side vectors B.
* On exit, B is overwritten by the solution vectors X.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
*
* =====================================================================
*
* .. Local Scalars ..
LOGICAL NOTRAN
INTEGER ITRANS, J, JB, NB
* ..
* .. External Functions ..
INTEGER ILAENV
EXTERNAL ILAENV
* ..
* .. External Subroutines ..
EXTERNAL SGTTS2, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. Executable Statements ..
*
INFO = 0
NOTRAN = ( TRANS.EQ.'N' .OR. TRANS.EQ.'n' )
IF( .NOT.NOTRAN .AND. .NOT.( TRANS.EQ.'T' .OR. TRANS.EQ.
$ 't' ) .AND. .NOT.( TRANS.EQ.'C' .OR. TRANS.EQ.'c' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( NRHS.LT.0 ) THEN
INFO = -3
ELSE IF( LDB.LT.MAX( N, 1 ) ) THEN
INFO = -10
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SGTTRS', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 .OR. NRHS.EQ.0 )
$ RETURN
*
* Decode TRANS
*
IF( NOTRAN ) THEN
ITRANS = 0
ELSE
ITRANS = 1
END IF
*
* Determine the number of right-hand sides to solve at a time.
*
IF( NRHS.EQ.1 ) THEN
NB = 1
ELSE
NB = MAX( 1, ILAENV( 1, 'SGTTRS', TRANS, N, NRHS, -1, -1 ) )
END IF
*
IF( NB.GE.NRHS ) THEN
CALL SGTTS2( ITRANS, N, NRHS, DL, D, DU, DU2, IPIV, B, LDB )
ELSE
DO 10 J = 1, NRHS, NB
JB = MIN( NRHS-J+1, NB )
CALL SGTTS2( ITRANS, N, JB, DL, D, DU, DU2, IPIV, B( 1, J ),
$ LDB )
10 CONTINUE
END IF
*
* End of SGTTRS
*
END
| lgpl-3.0 |
aamaricci/SciFortran | src/lapack/slasd8.f | 1 | 8760 | SUBROUTINE SLASD8( ICOMPQ, K, D, Z, VF, VL, DIFL, DIFR, LDDIFR,
$ DSIGMA, WORK, INFO )
*
* -- LAPACK auxiliary routine (version 3.3.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2010
*
* .. Scalar Arguments ..
INTEGER ICOMPQ, INFO, K, LDDIFR
* ..
* .. Array Arguments ..
REAL D( * ), DIFL( * ), DIFR( LDDIFR, * ),
$ DSIGMA( * ), VF( * ), VL( * ), WORK( * ),
$ Z( * )
* ..
*
* Purpose
* =======
*
* SLASD8 finds the square roots of the roots of the secular equation,
* as defined by the values in DSIGMA and Z. It makes the appropriate
* calls to SLASD4, and stores, for each element in D, the distance
* to its two nearest poles (elements in DSIGMA). It also updates
* the arrays VF and VL, the first and last components of all the
* right singular vectors of the original bidiagonal matrix.
*
* SLASD8 is called from SLASD6.
*
* Arguments
* =========
*
* ICOMPQ (input) INTEGER
* Specifies whether singular vectors are to be computed in
* factored form in the calling routine:
* = 0: Compute singular values only.
* = 1: Compute singular vectors in factored form as well.
*
* K (input) INTEGER
* The number of terms in the rational function to be solved
* by SLASD4. K >= 1.
*
* D (output) REAL array, dimension ( K )
* On output, D contains the updated singular values.
*
* Z (input/output) REAL array, dimension ( K )
* On entry, the first K elements of this array contain the
* components of the deflation-adjusted updating row vector.
* On exit, Z is updated.
*
* VF (input/output) REAL array, dimension ( K )
* On entry, VF contains information passed through DBEDE8.
* On exit, VF contains the first K components of the first
* components of all right singular vectors of the bidiagonal
* matrix.
*
* VL (input/output) REAL array, dimension ( K )
* On entry, VL contains information passed through DBEDE8.
* On exit, VL contains the first K components of the last
* components of all right singular vectors of the bidiagonal
* matrix.
*
* DIFL (output) REAL array, dimension ( K )
* On exit, DIFL(I) = D(I) - DSIGMA(I).
*
* DIFR (output) REAL array,
* dimension ( LDDIFR, 2 ) if ICOMPQ = 1 and
* dimension ( K ) if ICOMPQ = 0.
* On exit, DIFR(I,1) = D(I) - DSIGMA(I+1), DIFR(K,1) is not
* defined and will not be referenced.
*
* If ICOMPQ = 1, DIFR(1:K,2) is an array containing the
* normalizing factors for the right singular vector matrix.
*
* LDDIFR (input) INTEGER
* The leading dimension of DIFR, must be at least K.
*
* DSIGMA (input/output) REAL array, dimension ( K )
* On entry, the first K elements of this array contain the old
* roots of the deflated updating problem. These are the poles
* of the secular equation.
* On exit, the elements of DSIGMA may be very slightly altered
* in value.
*
* WORK (workspace) REAL array, dimension at least 3 * K
*
* INFO (output) INTEGER
* = 0: successful exit.
* < 0: if INFO = -i, the i-th argument had an illegal value.
* > 0: if INFO = 1, a singular value did not converge
*
* Further Details
* ===============
*
* Based on contributions by
* Ming Gu and Huan Ren, Computer Science Division, University of
* California at Berkeley, USA
*
* =====================================================================
*
* .. Parameters ..
REAL ONE
PARAMETER ( ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
INTEGER I, IWK1, IWK2, IWK2I, IWK3, IWK3I, J
REAL DIFLJ, DIFRJ, DJ, DSIGJ, DSIGJP, RHO, TEMP
* ..
* .. External Subroutines ..
EXTERNAL SCOPY, SLASCL, SLASD4, SLASET, XERBLA
* ..
* .. External Functions ..
REAL SDOT, SLAMC3, SNRM2
EXTERNAL SDOT, SLAMC3, SNRM2
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, SIGN, SQRT
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
*
IF( ( ICOMPQ.LT.0 ) .OR. ( ICOMPQ.GT.1 ) ) THEN
INFO = -1
ELSE IF( K.LT.1 ) THEN
INFO = -2
ELSE IF( LDDIFR.LT.K ) THEN
INFO = -9
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SLASD8', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( K.EQ.1 ) THEN
D( 1 ) = ABS( Z( 1 ) )
DIFL( 1 ) = D( 1 )
IF( ICOMPQ.EQ.1 ) THEN
DIFL( 2 ) = ONE
DIFR( 1, 2 ) = ONE
END IF
RETURN
END IF
*
* Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can
* be computed with high relative accuracy (barring over/underflow).
* This is a problem on machines without a guard digit in
* add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
* The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I),
* which on any of these machines zeros out the bottommost
* bit of DSIGMA(I) if it is 1; this makes the subsequent
* subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation
* occurs. On binary machines with a guard digit (almost all
* machines) it does not change DSIGMA(I) at all. On hexadecimal
* and decimal machines with a guard digit, it slightly
* changes the bottommost bits of DSIGMA(I). It does not account
* for hexadecimal or decimal machines without guard digits
* (we know of none). We use a subroutine call to compute
* 2*DLAMBDA(I) to prevent optimizing compilers from eliminating
* this code.
*
DO 10 I = 1, K
DSIGMA( I ) = SLAMC3( DSIGMA( I ), DSIGMA( I ) ) - DSIGMA( I )
10 CONTINUE
*
* Book keeping.
*
IWK1 = 1
IWK2 = IWK1 + K
IWK3 = IWK2 + K
IWK2I = IWK2 - 1
IWK3I = IWK3 - 1
*
* Normalize Z.
*
RHO = SNRM2( K, Z, 1 )
CALL SLASCL( 'G', 0, 0, RHO, ONE, K, 1, Z, K, INFO )
RHO = RHO*RHO
*
* Initialize WORK(IWK3).
*
CALL SLASET( 'A', K, 1, ONE, ONE, WORK( IWK3 ), K )
*
* Compute the updated singular values, the arrays DIFL, DIFR,
* and the updated Z.
*
DO 40 J = 1, K
CALL SLASD4( K, J, DSIGMA, Z, WORK( IWK1 ), RHO, D( J ),
$ WORK( IWK2 ), INFO )
*
* If the root finder fails, the computation is terminated.
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SLASD4', -INFO )
RETURN
END IF
WORK( IWK3I+J ) = WORK( IWK3I+J )*WORK( J )*WORK( IWK2I+J )
DIFL( J ) = -WORK( J )
DIFR( J, 1 ) = -WORK( J+1 )
DO 20 I = 1, J - 1
WORK( IWK3I+I ) = WORK( IWK3I+I )*WORK( I )*
$ WORK( IWK2I+I ) / ( DSIGMA( I )-
$ DSIGMA( J ) ) / ( DSIGMA( I )+
$ DSIGMA( J ) )
20 CONTINUE
DO 30 I = J + 1, K
WORK( IWK3I+I ) = WORK( IWK3I+I )*WORK( I )*
$ WORK( IWK2I+I ) / ( DSIGMA( I )-
$ DSIGMA( J ) ) / ( DSIGMA( I )+
$ DSIGMA( J ) )
30 CONTINUE
40 CONTINUE
*
* Compute updated Z.
*
DO 50 I = 1, K
Z( I ) = SIGN( SQRT( ABS( WORK( IWK3I+I ) ) ), Z( I ) )
50 CONTINUE
*
* Update VF and VL.
*
DO 80 J = 1, K
DIFLJ = DIFL( J )
DJ = D( J )
DSIGJ = -DSIGMA( J )
IF( J.LT.K ) THEN
DIFRJ = -DIFR( J, 1 )
DSIGJP = -DSIGMA( J+1 )
END IF
WORK( J ) = -Z( J ) / DIFLJ / ( DSIGMA( J )+DJ )
DO 60 I = 1, J - 1
WORK( I ) = Z( I ) / ( SLAMC3( DSIGMA( I ), DSIGJ )-DIFLJ )
$ / ( DSIGMA( I )+DJ )
60 CONTINUE
DO 70 I = J + 1, K
WORK( I ) = Z( I ) / ( SLAMC3( DSIGMA( I ), DSIGJP )+DIFRJ )
$ / ( DSIGMA( I )+DJ )
70 CONTINUE
TEMP = SNRM2( K, WORK, 1 )
WORK( IWK2I+J ) = SDOT( K, WORK, 1, VF, 1 ) / TEMP
WORK( IWK3I+J ) = SDOT( K, WORK, 1, VL, 1 ) / TEMP
IF( ICOMPQ.EQ.1 ) THEN
DIFR( J, 2 ) = TEMP
END IF
80 CONTINUE
*
CALL SCOPY( K, WORK( IWK2 ), 1, VF, 1 )
CALL SCOPY( K, WORK( IWK3 ), 1, VL, 1 )
*
RETURN
*
* End of SLASD8
*
END
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/cspr.f | 24 | 8384 | *> \brief \b CSPR performs the symmetrical rank-1 update of a complex symmetric packed matrix.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CSPR + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cspr.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cspr.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cspr.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CSPR( UPLO, N, ALPHA, X, INCX, AP )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INCX, N
* COMPLEX ALPHA
* ..
* .. Array Arguments ..
* COMPLEX AP( * ), X( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CSPR performs the symmetric rank 1 operation
*>
*> A := alpha*x*x**H + A,
*>
*> where alpha is a complex scalar, x is an n element vector and A is an
*> n by n symmetric matrix, supplied in packed form.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> On entry, UPLO specifies whether the upper or lower
*> triangular part of the matrix A is supplied in the packed
*> array AP as follows:
*>
*> UPLO = 'U' or 'u' The upper triangular part of A is
*> supplied in AP.
*>
*> UPLO = 'L' or 'l' The lower triangular part of A is
*> supplied in AP.
*>
*> Unchanged on exit.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> On entry, N specifies the order of the matrix A.
*> N must be at least zero.
*> Unchanged on exit.
*> \endverbatim
*>
*> \param[in] ALPHA
*> \verbatim
*> ALPHA is COMPLEX
*> On entry, ALPHA specifies the scalar alpha.
*> Unchanged on exit.
*> \endverbatim
*>
*> \param[in] X
*> \verbatim
*> X is COMPLEX array, dimension at least
*> ( 1 + ( N - 1 )*abs( INCX ) ).
*> Before entry, the incremented array X must contain the N-
*> element vector x.
*> Unchanged on exit.
*> \endverbatim
*>
*> \param[in] INCX
*> \verbatim
*> INCX is INTEGER
*> On entry, INCX specifies the increment for the elements of
*> X. INCX must not be zero.
*> Unchanged on exit.
*> \endverbatim
*>
*> \param[in,out] AP
*> \verbatim
*> AP is COMPLEX array, dimension at least
*> ( ( N*( N + 1 ) )/2 ).
*> Before entry, with UPLO = 'U' or 'u', the array AP must
*> contain the upper triangular part of the symmetric matrix
*> packed sequentially, column by column, so that AP( 1 )
*> contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )
*> and a( 2, 2 ) respectively, and so on. On exit, the array
*> AP is overwritten by the upper triangular part of the
*> updated matrix.
*> Before entry, with UPLO = 'L' or 'l', the array AP must
*> contain the lower triangular part of the symmetric matrix
*> packed sequentially, column by column, so that AP( 1 )
*> contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )
*> and a( 3, 1 ) respectively, and so on. On exit, the array
*> AP 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.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup complexOTHERauxiliary
*
* =====================================================================
SUBROUTINE CSPR( UPLO, N, ALPHA, X, INCX, AP )
*
* -- 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 ..
CHARACTER UPLO
INTEGER INCX, N
COMPLEX ALPHA
* ..
* .. Array Arguments ..
COMPLEX AP( * ), X( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
INTEGER I, INFO, IX, J, JX, K, KK, KX
COMPLEX TEMP
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = 1
ELSE IF( N.LT.0 ) THEN
INFO = 2
ELSE IF( INCX.EQ.0 ) THEN
INFO = 5
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CSPR ', INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( ( N.EQ.0 ) .OR. ( ALPHA.EQ.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 the array AP
* are accessed sequentially with one pass through AP.
*
KK = 1
IF( LSAME( UPLO, 'U' ) ) THEN
*
* Form A when upper triangle is stored in AP.
*
IF( INCX.EQ.1 ) THEN
DO 20 J = 1, N
IF( X( J ).NE.ZERO ) THEN
TEMP = ALPHA*X( J )
K = KK
DO 10 I = 1, J - 1
AP( K ) = AP( K ) + X( I )*TEMP
K = K + 1
10 CONTINUE
AP( KK+J-1 ) = AP( KK+J-1 ) + X( J )*TEMP
ELSE
AP( KK+J-1 ) = AP( KK+J-1 )
END IF
KK = KK + J
20 CONTINUE
ELSE
JX = KX
DO 40 J = 1, N
IF( X( JX ).NE.ZERO ) THEN
TEMP = ALPHA*X( JX )
IX = KX
DO 30 K = KK, KK + J - 2
AP( K ) = AP( K ) + X( IX )*TEMP
IX = IX + INCX
30 CONTINUE
AP( KK+J-1 ) = AP( KK+J-1 ) + X( JX )*TEMP
ELSE
AP( KK+J-1 ) = AP( KK+J-1 )
END IF
JX = JX + INCX
KK = KK + J
40 CONTINUE
END IF
ELSE
*
* Form A when lower triangle is stored in AP.
*
IF( INCX.EQ.1 ) THEN
DO 60 J = 1, N
IF( X( J ).NE.ZERO ) THEN
TEMP = ALPHA*X( J )
AP( KK ) = AP( KK ) + TEMP*X( J )
K = KK + 1
DO 50 I = J + 1, N
AP( K ) = AP( K ) + X( I )*TEMP
K = K + 1
50 CONTINUE
ELSE
AP( KK ) = AP( KK )
END IF
KK = KK + N - J + 1
60 CONTINUE
ELSE
JX = KX
DO 80 J = 1, N
IF( X( JX ).NE.ZERO ) THEN
TEMP = ALPHA*X( JX )
AP( KK ) = AP( KK ) + TEMP*X( JX )
IX = JX
DO 70 K = KK + 1, KK + N - J
IX = IX + INCX
AP( K ) = AP( K ) + X( IX )*TEMP
70 CONTINUE
ELSE
AP( KK ) = AP( KK )
END IF
JX = JX + INCX
KK = KK + N - J + 1
80 CONTINUE
END IF
END IF
*
RETURN
*
* End of CSPR
*
END
| apache-2.0 |
OpenDA-Association/OpenDA | core/native/external/lapack/dtptri.f | 2 | 5078 | SUBROUTINE DTPTRI( UPLO, DIAG, N, AP, 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 DIAG, UPLO
INTEGER INFO, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION AP( * )
* ..
*
* Purpose
* =======
*
* DTPTRI computes the inverse of a real upper or lower triangular
* matrix A stored in packed format.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* = 'U': A is upper triangular;
* = 'L': A is lower triangular.
*
* DIAG (input) CHARACTER*1
* = 'N': A is non-unit triangular;
* = 'U': A is unit 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 triangular matrix A, stored
* 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.
* See below for further details.
* On exit, the (triangular) inverse of the original matrix, in
* the same packed storage format.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, A(i,i) is exactly zero. The triangular
* matrix is singular and its inverse can not be computed.
*
* Further Details
* ===============
*
* A triangular matrix A can be transferred to packed storage using one
* of the following program segments:
*
* UPLO = 'U': UPLO = 'L':
*
* JC = 1 JC = 1
* DO 2 J = 1, N DO 2 J = 1, N
* DO 1 I = 1, J DO 1 I = J, N
* AP(JC+I-1) = A(I,J) AP(JC+I-J) = A(I,J)
* 1 CONTINUE 1 CONTINUE
* JC = JC + J JC = JC + N - J + 1
* 2 CONTINUE 2 CONTINUE
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL NOUNIT, UPPER
INTEGER J, JC, JCLAST, JJ
DOUBLE PRECISION AJJ
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DSCAL, DTPMV, XERBLA
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
UPPER = LSAME( UPLO, 'U' )
NOUNIT = LSAME( DIAG, 'N' )
IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
INFO = -2
ELSE IF( N.LT.0 ) THEN
INFO = -3
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DTPTRI', -INFO )
RETURN
END IF
*
* Check for singularity if non-unit.
*
IF( NOUNIT ) THEN
IF( UPPER ) THEN
JJ = 0
DO 10 INFO = 1, N
JJ = JJ + INFO
IF( AP( JJ ).EQ.ZERO )
$ RETURN
10 CONTINUE
ELSE
JJ = 1
DO 20 INFO = 1, N
IF( AP( JJ ).EQ.ZERO )
$ RETURN
JJ = JJ + N - INFO + 1
20 CONTINUE
END IF
INFO = 0
END IF
*
IF( UPPER ) THEN
*
* Compute inverse of upper triangular matrix.
*
JC = 1
DO 30 J = 1, N
IF( NOUNIT ) THEN
AP( JC+J-1 ) = ONE / AP( JC+J-1 )
AJJ = -AP( JC+J-1 )
ELSE
AJJ = -ONE
END IF
*
* Compute elements 1:j-1 of j-th column.
*
CALL DTPMV( 'Upper', 'No transpose', DIAG, J-1, AP,
$ AP( JC ), 1 )
CALL DSCAL( J-1, AJJ, AP( JC ), 1 )
JC = JC + J
30 CONTINUE
*
ELSE
*
* Compute inverse of lower triangular matrix.
*
JC = N*( N+1 ) / 2
DO 40 J = N, 1, -1
IF( NOUNIT ) THEN
AP( JC ) = ONE / AP( JC )
AJJ = -AP( JC )
ELSE
AJJ = -ONE
END IF
IF( J.LT.N ) THEN
*
* Compute elements j+1:n of j-th column.
*
CALL DTPMV( 'Lower', 'No transpose', DIAG, N-J,
$ AP( JCLAST ), AP( JC+1 ), 1 )
CALL DSCAL( N-J, AJJ, AP( JC+1 ), 1 )
END IF
JCLAST = JC
JC = JC - N + J - 2
40 CONTINUE
END IF
*
RETURN
*
* End of DTPTRI
*
END
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/dgebrd.f | 52 | 11278 | *> \brief \b DGEBRD
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DGEBRD + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgebrd.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgebrd.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgebrd.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DGEBRD( M, N, A, LDA, D, E, TAUQ, TAUP, WORK, LWORK,
* INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LDA, LWORK, M, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION A( LDA, * ), D( * ), E( * ), TAUP( * ),
* $ TAUQ( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DGEBRD reduces a general real M-by-N matrix A to upper or lower
*> bidiagonal form B by an orthogonal transformation: Q**T * A * P = B.
*>
*> If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows in the matrix A. M >= 0.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns in 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 general matrix to be reduced.
*> On exit,
*> if m >= n, the diagonal and the first superdiagonal are
*> overwritten with the upper bidiagonal matrix B; the
*> elements below the diagonal, with the array TAUQ, represent
*> the orthogonal matrix Q as a product of elementary
*> reflectors, and the elements above the first superdiagonal,
*> with the array TAUP, represent the orthogonal matrix P as
*> a product of elementary reflectors;
*> if m < n, the diagonal and the first subdiagonal are
*> overwritten with the lower bidiagonal matrix B; the
*> elements below the first subdiagonal, with the array TAUQ,
*> represent the orthogonal matrix Q as a product of
*> elementary reflectors, and the elements above the diagonal,
*> with the array TAUP, represent the orthogonal matrix P 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] D
*> \verbatim
*> D is DOUBLE PRECISION array, dimension (min(M,N))
*> The diagonal elements of the bidiagonal matrix B:
*> D(i) = A(i,i).
*> \endverbatim
*>
*> \param[out] E
*> \verbatim
*> E is DOUBLE PRECISION array, dimension (min(M,N)-1)
*> The off-diagonal elements of the bidiagonal matrix B:
*> if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1;
*> if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1.
*> \endverbatim
*>
*> \param[out] TAUQ
*> \verbatim
*> TAUQ is DOUBLE PRECISION array dimension (min(M,N))
*> The scalar factors of the elementary reflectors which
*> represent the orthogonal matrix Q. See Further Details.
*> \endverbatim
*>
*> \param[out] TAUP
*> \verbatim
*> TAUP is DOUBLE PRECISION array, dimension (min(M,N))
*> The scalar factors of the elementary reflectors which
*> represent the orthogonal matrix P. 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 length of the array WORK. LWORK >= max(1,M,N).
*> For optimum performance LWORK >= (M+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 November 2011
*
*> \ingroup doubleGEcomputational
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> The matrices Q and P are represented as products of elementary
*> reflectors:
*>
*> If m >= n,
*>
*> Q = H(1) H(2) . . . H(n) and P = G(1) G(2) . . . G(n-1)
*>
*> Each H(i) and G(i) has the form:
*>
*> H(i) = I - tauq * v * v**T and G(i) = I - taup * u * u**T
*>
*> where tauq and taup are real scalars, and v and u are real vectors;
*> v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i);
*> u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n);
*> tauq is stored in TAUQ(i) and taup in TAUP(i).
*>
*> If m < n,
*>
*> Q = H(1) H(2) . . . H(m-1) and P = G(1) G(2) . . . G(m)
*>
*> Each H(i) and G(i) has the form:
*>
*> H(i) = I - tauq * v * v**T and G(i) = I - taup * u * u**T
*>
*> where tauq and taup are real scalars, and v and u are real vectors;
*> v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i);
*> u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n);
*> tauq is stored in TAUQ(i) and taup in TAUP(i).
*>
*> The contents of A on exit are illustrated by the following examples:
*>
*> m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n):
*>
*> ( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 )
*> ( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 )
*> ( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 )
*> ( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 )
*> ( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 )
*> ( v1 v2 v3 v4 v5 )
*>
*> where d and e denote diagonal and off-diagonal elements of B, vi
*> denotes an element of the vector defining H(i), and ui an element of
*> the vector defining G(i).
*> \endverbatim
*>
* =====================================================================
SUBROUTINE DGEBRD( M, N, A, LDA, D, E, TAUQ, TAUP, 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, * ), D( * ), E( * ), TAUP( * ),
$ TAUQ( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL LQUERY
INTEGER I, IINFO, J, LDWRKX, LDWRKY, LWKOPT, MINMN, NB,
$ NBMIN, NX
DOUBLE PRECISION WS
* ..
* .. External Subroutines ..
EXTERNAL DGEBD2, DGEMM, DLABRD, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC DBLE, MAX, MIN
* ..
* .. External Functions ..
INTEGER ILAENV
EXTERNAL ILAENV
* ..
* .. Executable Statements ..
*
* Test the input parameters
*
INFO = 0
NB = MAX( 1, ILAENV( 1, 'DGEBRD', ' ', M, N, -1, -1 ) )
LWKOPT = ( M+N )*NB
WORK( 1 ) = DBLE( LWKOPT )
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
ELSE IF( LWORK.LT.MAX( 1, M, N ) .AND. .NOT.LQUERY ) THEN
INFO = -10
END IF
IF( INFO.LT.0 ) THEN
CALL XERBLA( 'DGEBRD', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Quick return if possible
*
MINMN = MIN( M, N )
IF( MINMN.EQ.0 ) THEN
WORK( 1 ) = 1
RETURN
END IF
*
WS = MAX( M, N )
LDWRKX = M
LDWRKY = N
*
IF( NB.GT.1 .AND. NB.LT.MINMN ) THEN
*
* Set the crossover point NX.
*
NX = MAX( NB, ILAENV( 3, 'DGEBRD', ' ', M, N, -1, -1 ) )
*
* Determine when to switch from blocked to unblocked code.
*
IF( NX.LT.MINMN ) THEN
WS = ( M+N )*NB
IF( LWORK.LT.WS ) THEN
*
* Not enough work space for the optimal NB, consider using
* a smaller block size.
*
NBMIN = ILAENV( 2, 'DGEBRD', ' ', M, N, -1, -1 )
IF( LWORK.GE.( M+N )*NBMIN ) THEN
NB = LWORK / ( M+N )
ELSE
NB = 1
NX = MINMN
END IF
END IF
END IF
ELSE
NX = MINMN
END IF
*
DO 30 I = 1, MINMN - NX, NB
*
* Reduce rows and columns i:i+nb-1 to bidiagonal form and return
* the matrices X and Y which are needed to update the unreduced
* part of the matrix
*
CALL DLABRD( M-I+1, N-I+1, NB, A( I, I ), LDA, D( I ), E( I ),
$ TAUQ( I ), TAUP( I ), WORK, LDWRKX,
$ WORK( LDWRKX*NB+1 ), LDWRKY )
*
* Update the trailing submatrix A(i+nb:m,i+nb:n), using an update
* of the form A := A - V*Y**T - X*U**T
*
CALL DGEMM( 'No transpose', 'Transpose', M-I-NB+1, N-I-NB+1,
$ NB, -ONE, A( I+NB, I ), LDA,
$ WORK( LDWRKX*NB+NB+1 ), LDWRKY, ONE,
$ A( I+NB, I+NB ), LDA )
CALL DGEMM( 'No transpose', 'No transpose', M-I-NB+1, N-I-NB+1,
$ NB, -ONE, WORK( NB+1 ), LDWRKX, A( I, I+NB ), LDA,
$ ONE, A( I+NB, I+NB ), LDA )
*
* Copy diagonal and off-diagonal elements of B back into A
*
IF( M.GE.N ) THEN
DO 10 J = I, I + NB - 1
A( J, J ) = D( J )
A( J, J+1 ) = E( J )
10 CONTINUE
ELSE
DO 20 J = I, I + NB - 1
A( J, J ) = D( J )
A( J+1, J ) = E( J )
20 CONTINUE
END IF
30 CONTINUE
*
* Use unblocked code to reduce the remainder of the matrix
*
CALL DGEBD2( M-I+1, N-I+1, A( I, I ), LDA, D( I ), E( I ),
$ TAUQ( I ), TAUP( I ), WORK, IINFO )
WORK( 1 ) = WS
RETURN
*
* End of DGEBRD
*
END
| apache-2.0 |
aamaricci/SciFortran | src/lapack/zspr.f | 1 | 6730 | SUBROUTINE ZSPR( UPLO, N, ALPHA, X, INCX, AP )
*
* -- 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 UPLO
INTEGER INCX, N
COMPLEX*16 ALPHA
* ..
* .. Array Arguments ..
COMPLEX*16 AP( * ), X( * )
* ..
*
* Purpose
* =======
*
* ZSPR performs the symmetric rank 1 operation
*
* A := alpha*x*x**H + A,
*
* where alpha is a complex scalar, x is an n element vector and A is an
* n by n symmetric matrix, supplied in packed form.
*
* Arguments
* ==========
*
* UPLO (input) CHARACTER*1
* On entry, UPLO specifies whether the upper or lower
* triangular part of the matrix A is supplied in the packed
* array AP as follows:
*
* UPLO = 'U' or 'u' The upper triangular part of A is
* supplied in AP.
*
* UPLO = 'L' or 'l' The lower triangular part of A is
* supplied in AP.
*
* Unchanged on exit.
*
* N (input) INTEGER
* On entry, N specifies the order of the matrix A.
* N must be at least zero.
* Unchanged on exit.
*
* ALPHA (input) COMPLEX*16
* On entry, ALPHA specifies the scalar alpha.
* Unchanged on exit.
*
* X (input) COMPLEX*16 array, 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 (input) INTEGER
* On entry, INCX specifies the increment for the elements of
* X. INCX must not be zero.
* Unchanged on exit.
*
* AP (input/output) COMPLEX*16 array, dimension at least
* ( ( N*( N + 1 ) )/2 ).
* Before entry, with UPLO = 'U' or 'u', the array AP must
* contain the upper triangular part of the symmetric matrix
* packed sequentially, column by column, so that AP( 1 )
* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )
* and a( 2, 2 ) respectively, and so on. On exit, the array
* AP is overwritten by the upper triangular part of the
* updated matrix.
* Before entry, with UPLO = 'L' or 'l', the array AP must
* contain the lower triangular part of the symmetric matrix
* packed sequentially, column by column, so that AP( 1 )
* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )
* and a( 3, 1 ) respectively, and so on. On exit, the array
* AP 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.
*
* =====================================================================
*
* .. Parameters ..
COMPLEX*16 ZERO
PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )
* ..
* .. Local Scalars ..
INTEGER I, INFO, IX, J, JX, K, KK, KX
COMPLEX*16 TEMP
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = 1
ELSE IF( N.LT.0 ) THEN
INFO = 2
ELSE IF( INCX.EQ.0 ) THEN
INFO = 5
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZSPR ', INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( ( N.EQ.0 ) .OR. ( ALPHA.EQ.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 the array AP
* are accessed sequentially with one pass through AP.
*
KK = 1
IF( LSAME( UPLO, 'U' ) ) THEN
*
* Form A when upper triangle is stored in AP.
*
IF( INCX.EQ.1 ) THEN
DO 20 J = 1, N
IF( X( J ).NE.ZERO ) THEN
TEMP = ALPHA*X( J )
K = KK
DO 10 I = 1, J - 1
AP( K ) = AP( K ) + X( I )*TEMP
K = K + 1
10 CONTINUE
AP( KK+J-1 ) = AP( KK+J-1 ) + X( J )*TEMP
ELSE
AP( KK+J-1 ) = AP( KK+J-1 )
END IF
KK = KK + J
20 CONTINUE
ELSE
JX = KX
DO 40 J = 1, N
IF( X( JX ).NE.ZERO ) THEN
TEMP = ALPHA*X( JX )
IX = KX
DO 30 K = KK, KK + J - 2
AP( K ) = AP( K ) + X( IX )*TEMP
IX = IX + INCX
30 CONTINUE
AP( KK+J-1 ) = AP( KK+J-1 ) + X( JX )*TEMP
ELSE
AP( KK+J-1 ) = AP( KK+J-1 )
END IF
JX = JX + INCX
KK = KK + J
40 CONTINUE
END IF
ELSE
*
* Form A when lower triangle is stored in AP.
*
IF( INCX.EQ.1 ) THEN
DO 60 J = 1, N
IF( X( J ).NE.ZERO ) THEN
TEMP = ALPHA*X( J )
AP( KK ) = AP( KK ) + TEMP*X( J )
K = KK + 1
DO 50 I = J + 1, N
AP( K ) = AP( K ) + X( I )*TEMP
K = K + 1
50 CONTINUE
ELSE
AP( KK ) = AP( KK )
END IF
KK = KK + N - J + 1
60 CONTINUE
ELSE
JX = KX
DO 80 J = 1, N
IF( X( JX ).NE.ZERO ) THEN
TEMP = ALPHA*X( JX )
AP( KK ) = AP( KK ) + TEMP*X( JX )
IX = JX
DO 70 K = KK + 1, KK + N - J
IX = IX + INCX
AP( K ) = AP( K ) + X( IX )*TEMP
70 CONTINUE
ELSE
AP( KK ) = AP( KK )
END IF
JX = JX + INCX
KK = KK + N - J + 1
80 CONTINUE
END IF
END IF
*
RETURN
*
* End of ZSPR
*
END
| lgpl-3.0 |
aamaricci/SciFortran | src/lapack/clahqr.f | 2 | 16175 | SUBROUTINE CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
$ IHIZ, Z, LDZ, INFO )
*
* -- LAPACK auxiliary routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
LOGICAL WANTT, WANTZ
* ..
* .. Array Arguments ..
COMPLEX H( LDH, * ), W( * ), Z( LDZ, * )
* ..
*
* Purpose
* =======
*
* CLAHQR is an auxiliary routine called by CHSEQR to update the
* eigenvalues and Schur decomposition already computed by CHSEQR, by
* dealing with the Hessenberg submatrix in rows and columns ILO to
* IHI.
*
* Arguments
* =========
*
* WANTT (input) LOGICAL
* = .TRUE. : the full Schur form T is required;
* = .FALSE.: only eigenvalues are required.
*
* WANTZ (input) LOGICAL
* = .TRUE. : the matrix of Schur vectors Z is required;
* = .FALSE.: Schur vectors are not required.
*
* N (input) INTEGER
* The order of the matrix H. N >= 0.
*
* ILO (input) INTEGER
* IHI (input) INTEGER
* It is assumed that H is already upper triangular in rows and
* columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1).
* CLAHQR works primarily with the Hessenberg submatrix in rows
* and columns ILO to IHI, but applies transformations to all of
* H if WANTT is .TRUE..
* 1 <= ILO <= max(1,IHI); IHI <= N.
*
* H (input/output) COMPLEX array, dimension (LDH,N)
* On entry, the upper Hessenberg matrix H.
* On exit, if INFO is zero and if WANTT is .TRUE., then H
* is upper triangular in rows and columns ILO:IHI. If INFO
* is zero and if WANTT is .FALSE., then the contents of H
* are unspecified on exit. The output state of H in case
* INF is positive is below under the description of INFO.
*
* LDH (input) INTEGER
* The leading dimension of the array H. LDH >= max(1,N).
*
* W (output) COMPLEX array, dimension (N)
* The computed eigenvalues ILO to IHI are stored in the
* corresponding elements of W. If WANTT is .TRUE., the
* eigenvalues are stored in the same order as on the diagonal
* of the Schur form returned in H, with W(i) = H(i,i).
*
* ILOZ (input) INTEGER
* IHIZ (input) INTEGER
* Specify the rows of Z to which transformations must be
* applied if WANTZ is .TRUE..
* 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
*
* Z (input/output) COMPLEX array, dimension (LDZ,N)
* If WANTZ is .TRUE., on entry Z must contain the current
* matrix Z of transformations accumulated by CHSEQR, and on
* exit Z has been updated; transformations are applied only to
* the submatrix Z(ILOZ:IHIZ,ILO:IHI).
* If WANTZ is .FALSE., Z is not referenced.
*
* LDZ (input) INTEGER
* The leading dimension of the array Z. LDZ >= max(1,N).
*
* INFO (output) INTEGER
* = 0: successful exit
* .GT. 0: if INFO = i, CLAHQR failed to compute all the
* eigenvalues ILO to IHI in a total of 30 iterations
* per eigenvalue; elements i+1:ihi of W contain
* those eigenvalues which have been successfully
* computed.
*
* If INFO .GT. 0 and WANTT is .FALSE., then on exit,
* the remaining unconverged eigenvalues are the
* eigenvalues of the upper Hessenberg matrix
* rows and columns ILO thorugh INFO of the final,
* output value of H.
*
* If INFO .GT. 0 and WANTT is .TRUE., then on exit
* (*) (initial value of H)*U = U*(final value of H)
* where U is an orthognal matrix. The final
* value of H is upper Hessenberg and triangular in
* rows and columns INFO+1 through IHI.
*
* If INFO .GT. 0 and WANTZ is .TRUE., then on exit
* (final value of Z) = (initial value of Z)*U
* where U is the orthogonal matrix in (*)
* (regardless of the value of WANTT.)
*
* Further Details
* ===============
*
* 02-96 Based on modifications by
* David Day, Sandia National Laboratory, USA
*
* 12-04 Further modifications by
* Ralph Byers, University of Kansas, USA
* This is a modified version of CLAHQR from LAPACK version 3.0.
* It is (1) more robust against overflow and underflow and
* (2) adopts the more conservative Ahues & Tisseur stopping
* criterion (LAWN 122, 1997).
*
* =========================================================
*
* .. Parameters ..
INTEGER ITMAX
PARAMETER ( ITMAX = 30 )
COMPLEX ZERO, ONE
PARAMETER ( ZERO = ( 0.0e0, 0.0e0 ),
$ ONE = ( 1.0e0, 0.0e0 ) )
REAL RZERO, RONE, HALF
PARAMETER ( RZERO = 0.0e0, RONE = 1.0e0, HALF = 0.5e0 )
REAL DAT1
PARAMETER ( DAT1 = 3.0e0 / 4.0e0 )
* ..
* .. Local Scalars ..
COMPLEX CDUM, H11, H11S, H22, SC, SUM, T, T1, TEMP, U,
$ V2, X, Y
REAL AA, AB, BA, BB, H10, H21, RTEMP, S, SAFMAX,
$ SAFMIN, SMLNUM, SX, T2, TST, ULP
INTEGER I, I1, I2, ITS, J, JHI, JLO, K, L, M, NH, NZ
* ..
* .. Local Arrays ..
COMPLEX V( 2 )
* ..
* .. External Functions ..
COMPLEX CLADIV
REAL SLAMCH
EXTERNAL CLADIV, SLAMCH
* ..
* .. External Subroutines ..
EXTERNAL CCOPY, CLARFG, CSCAL, SLABAD
* ..
* .. Statement Functions ..
REAL CABS1
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, CONJG, MAX, MIN, REAL, SQRT
* ..
* .. Statement Function definitions ..
CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( CDUM ) )
* ..
* .. Executable Statements ..
*
INFO = 0
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
IF( ILO.EQ.IHI ) THEN
W( ILO ) = H( ILO, ILO )
RETURN
END IF
*
* ==== clear out the trash ====
DO 10 J = ILO, IHI - 3
H( J+2, J ) = ZERO
H( J+3, J ) = ZERO
10 CONTINUE
IF( ILO.LE.IHI-2 )
$ H( IHI, IHI-2 ) = ZERO
* ==== ensure that subdiagonal entries are real ====
IF( WANTT ) THEN
JLO = 1
JHI = N
ELSE
JLO = ILO
JHI = IHI
END IF
DO 20 I = ILO + 1, IHI
IF( AIMAG( H( I, I-1 ) ).NE.RZERO ) THEN
* ==== The following redundant normalization
* . avoids problems with both gradual and
* . sudden underflow in ABS(H(I,I-1)) ====
SC = H( I, I-1 ) / CABS1( H( I, I-1 ) )
SC = CONJG( SC ) / ABS( SC )
H( I, I-1 ) = ABS( H( I, I-1 ) )
CALL CSCAL( JHI-I+1, SC, H( I, I ), LDH )
CALL CSCAL( MIN( JHI, I+1 )-JLO+1, CONJG( SC ), H( JLO, I ),
$ 1 )
IF( WANTZ )
$ CALL CSCAL( IHIZ-ILOZ+1, CONJG( SC ), Z( ILOZ, I ), 1 )
END IF
20 CONTINUE
*
NH = IHI - ILO + 1
NZ = IHIZ - ILOZ + 1
*
* Set machine-dependent constants for the stopping criterion.
*
SAFMIN = SLAMCH( 'SAFE MINIMUM' )
SAFMAX = RONE / SAFMIN
CALL SLABAD( SAFMIN, SAFMAX )
ULP = SLAMCH( 'PRECISION' )
SMLNUM = SAFMIN*( REAL( NH ) / ULP )
*
* I1 and I2 are the indices of the first row and last column of H
* to which transformations must be applied. If eigenvalues only are
* being computed, I1 and I2 are set inside the main loop.
*
IF( WANTT ) THEN
I1 = 1
I2 = N
END IF
*
* The main loop begins here. I is the loop index and decreases from
* IHI to ILO in steps of 1. Each iteration of the loop works
* with the active submatrix in rows and columns L to I.
* Eigenvalues I+1 to IHI have already converged. Either L = ILO, or
* H(L,L-1) is negligible so that the matrix splits.
*
I = IHI
30 CONTINUE
IF( I.LT.ILO )
$ GO TO 150
*
* Perform QR iterations on rows and columns ILO to I until a
* submatrix of order 1 splits off at the bottom because a
* subdiagonal element has become negligible.
*
L = ILO
DO 130 ITS = 0, ITMAX
*
* Look for a single small subdiagonal element.
*
DO 40 K = I, L + 1, -1
IF( CABS1( H( K, K-1 ) ).LE.SMLNUM )
$ GO TO 50
TST = CABS1( H( K-1, K-1 ) ) + CABS1( H( K, K ) )
IF( TST.EQ.ZERO ) THEN
IF( K-2.GE.ILO )
$ TST = TST + ABS( REAL( H( K-1, K-2 ) ) )
IF( K+1.LE.IHI )
$ TST = TST + ABS( REAL( H( K+1, K ) ) )
END IF
* ==== The following is a conservative small subdiagonal
* . deflation criterion due to Ahues & Tisseur (LAWN 122,
* . 1997). It has better mathematical foundation and
* . improves accuracy in some examples. ====
IF( ABS( REAL( H( K, K-1 ) ) ).LE.ULP*TST ) THEN
AB = MAX( CABS1( H( K, K-1 ) ), CABS1( H( K-1, K ) ) )
BA = MIN( CABS1( H( K, K-1 ) ), CABS1( H( K-1, K ) ) )
AA = MAX( CABS1( H( K, K ) ),
$ CABS1( H( K-1, K-1 )-H( K, K ) ) )
BB = MIN( CABS1( H( K, K ) ),
$ CABS1( H( K-1, K-1 )-H( K, K ) ) )
S = AA + AB
IF( BA*( AB / S ).LE.MAX( SMLNUM,
$ ULP*( BB*( AA / S ) ) ) )GO TO 50
END IF
40 CONTINUE
50 CONTINUE
L = K
IF( L.GT.ILO ) THEN
*
* H(L,L-1) is negligible
*
H( L, L-1 ) = ZERO
END IF
*
* Exit from loop if a submatrix of order 1 has split off.
*
IF( L.GE.I )
$ GO TO 140
*
* Now the active submatrix is in rows and columns L to I. If
* eigenvalues only are being computed, only the active submatrix
* need be transformed.
*
IF( .NOT.WANTT ) THEN
I1 = L
I2 = I
END IF
*
IF( ITS.EQ.10 ) THEN
*
* Exceptional shift.
*
S = DAT1*ABS( REAL( H( L+1, L ) ) )
T = S + H( L, L )
ELSE IF( ITS.EQ.20 ) THEN
*
* Exceptional shift.
*
S = DAT1*ABS( REAL( H( I, I-1 ) ) )
T = S + H( I, I )
ELSE
*
* Wilkinson's shift.
*
T = H( I, I )
U = SQRT( H( I-1, I ) )*SQRT( H( I, I-1 ) )
S = CABS1( U )
IF( S.NE.RZERO ) THEN
X = HALF*( H( I-1, I-1 )-T )
SX = CABS1( X )
S = MAX( S, CABS1( X ) )
Y = S*SQRT( ( X / S )**2+( U / S )**2 )
IF( SX.GT.RZERO ) THEN
IF( REAL( X / SX )*REAL( Y )+AIMAG( X / SX )*
$ AIMAG( Y ).LT.RZERO )Y = -Y
END IF
T = T - U*CLADIV( U, ( X+Y ) )
END IF
END IF
*
* Look for two consecutive small subdiagonal elements.
*
DO 60 M = I - 1, L + 1, -1
*
* Determine the effect of starting the single-shift QR
* iteration at row M, and see if this would make H(M,M-1)
* negligible.
*
H11 = H( M, M )
H22 = H( M+1, M+1 )
H11S = H11 - T
H21 = REAL( H( M+1, M ) )
S = CABS1( H11S ) + ABS( H21 )
H11S = H11S / S
H21 = H21 / S
V( 1 ) = H11S
V( 2 ) = H21
H10 = REAL( H( M, M-1 ) )
IF( ABS( H10 )*ABS( H21 ).LE.ULP*
$ ( CABS1( H11S )*( CABS1( H11 )+CABS1( H22 ) ) ) )
$ GO TO 70
60 CONTINUE
H11 = H( L, L )
H22 = H( L+1, L+1 )
H11S = H11 - T
H21 = REAL( H( L+1, L ) )
S = CABS1( H11S ) + ABS( H21 )
H11S = H11S / S
H21 = H21 / S
V( 1 ) = H11S
V( 2 ) = H21
70 CONTINUE
*
* Single-shift QR step
*
DO 120 K = M, I - 1
*
* The first iteration of this loop determines a reflection G
* from the vector V and applies it from left and right to H,
* thus creating a nonzero bulge below the subdiagonal.
*
* Each subsequent iteration determines a reflection G to
* restore the Hessenberg form in the (K-1)th column, and thus
* chases the bulge one step toward the bottom of the active
* submatrix.
*
* V(2) is always real before the call to CLARFG, and hence
* after the call T2 ( = T1*V(2) ) is also real.
*
IF( K.GT.M )
$ CALL CCOPY( 2, H( K, K-1 ), 1, V, 1 )
CALL CLARFG( 2, V( 1 ), V( 2 ), 1, T1 )
IF( K.GT.M ) THEN
H( K, K-1 ) = V( 1 )
H( K+1, K-1 ) = ZERO
END IF
V2 = V( 2 )
T2 = REAL( T1*V2 )
*
* Apply G from the left to transform the rows of the matrix
* in columns K to I2.
*
DO 80 J = K, I2
SUM = CONJG( T1 )*H( K, J ) + T2*H( K+1, J )
H( K, J ) = H( K, J ) - SUM
H( K+1, J ) = H( K+1, J ) - SUM*V2
80 CONTINUE
*
* Apply G from the right to transform the columns of the
* matrix in rows I1 to min(K+2,I).
*
DO 90 J = I1, MIN( K+2, I )
SUM = T1*H( J, K ) + T2*H( J, K+1 )
H( J, K ) = H( J, K ) - SUM
H( J, K+1 ) = H( J, K+1 ) - SUM*CONJG( V2 )
90 CONTINUE
*
IF( WANTZ ) THEN
*
* Accumulate transformations in the matrix Z
*
DO 100 J = ILOZ, IHIZ
SUM = T1*Z( J, K ) + T2*Z( J, K+1 )
Z( J, K ) = Z( J, K ) - SUM
Z( J, K+1 ) = Z( J, K+1 ) - SUM*CONJG( V2 )
100 CONTINUE
END IF
*
IF( K.EQ.M .AND. M.GT.L ) THEN
*
* If the QR step was started at row M > L because two
* consecutive small subdiagonals were found, then extra
* scaling must be performed to ensure that H(M,M-1) remains
* real.
*
TEMP = ONE - T1
TEMP = TEMP / ABS( TEMP )
H( M+1, M ) = H( M+1, M )*CONJG( TEMP )
IF( M+2.LE.I )
$ H( M+2, M+1 ) = H( M+2, M+1 )*TEMP
DO 110 J = M, I
IF( J.NE.M+1 ) THEN
IF( I2.GT.J )
$ CALL CSCAL( I2-J, TEMP, H( J, J+1 ), LDH )
CALL CSCAL( J-I1, CONJG( TEMP ), H( I1, J ), 1 )
IF( WANTZ ) THEN
CALL CSCAL( NZ, CONJG( TEMP ), Z( ILOZ, J ), 1 )
END IF
END IF
110 CONTINUE
END IF
120 CONTINUE
*
* Ensure that H(I,I-1) is real.
*
TEMP = H( I, I-1 )
IF( AIMAG( TEMP ).NE.RZERO ) THEN
RTEMP = ABS( TEMP )
H( I, I-1 ) = RTEMP
TEMP = TEMP / RTEMP
IF( I2.GT.I )
$ CALL CSCAL( I2-I, CONJG( TEMP ), H( I, I+1 ), LDH )
CALL CSCAL( I-I1, TEMP, H( I1, I ), 1 )
IF( WANTZ ) THEN
CALL CSCAL( NZ, TEMP, Z( ILOZ, I ), 1 )
END IF
END IF
*
130 CONTINUE
*
* Failure to converge in remaining number of iterations
*
INFO = I
RETURN
*
140 CONTINUE
*
* H(I,I-1) is negligible: one eigenvalue has converged.
*
W( I ) = H( I, I )
*
* return to start of the main loop with new value of I.
*
I = L - 1
GO TO 30
*
150 CONTINUE
RETURN
*
* End of CLAHQR
*
END
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack95/SRC/la_dsyevd.f90 | 1 | 5217 | SUBROUTINE DSYEVD_F95( A, W, JOBZ, UPLO, INFO )
! .. USE STATEMENTS ..
USE LA_PRECISION, ONLY: WP => DP
USE LA_AUXMOD, ONLY: ERINFO, LSAME
USE F77_LAPACK, ONLY: SYEVD_F77 => LA_SYEVD, ILAENV_F77 => ILAENV
!
! -- LAPACK95 interface driver routine (version 3.0) --
! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK
! September, 2000
!
! .. IMPLICIT STATEMENT ..
IMPLICIT NONE
! .. CHARACTER ARGUMENTS ..
CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: JOBZ, UPLO
! .. SCALAR ARGUMENTS ..
INTEGER, INTENT(OUT), OPTIONAL :: INFO
! .. ARRAY ARGUMENTS ..
REAL(WP), INTENT(INOUT) :: A(:,:)
REAL(WP), INTENT(OUT) :: W(:)
!----------------------------------------------------------------------
!
! Purpose
! =======
!
! LA_SYEV and LA_SYEVD compute all eigenvalues and, optionally, all
! eigenvectors of a real symmetric matrix A.
! LA_HEEV and LA_HEEVD compute all eigenvalues and, optionally, all
! eigenvectors of a complex Hermitian matrix A.
! LA_SYEVD and LA_HEEVD use a divide and conquer algorithm. If
! eigenvectors are desired, they can be much faster than LA_SYEV and
! LA_HEEV for large matrices but use more workspace.
!
! =========
!
! SUBROUTINE LA_SYEV / LA_HEEV / LA_SYEVD / LA_HEEVD( A, W, &
! JOBZ=jobz, UPLO=uplo, INFO=info )
! <type>(<wp>), INTENT(INOUT) :: A(:,:)
! REAL(<wp>), INTENT(OUT) :: W(:)
! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: JOBZ, UPLO
! INTEGER, INTENT(OUT), OPTIONAL :: INFO
! where
! <type> ::= REAL | COMPLEX
! <wp> ::= KIND(1.0) | KIND(1.0D0)
!
!
! Arguments
! =========
!
! A (input/output) REAL or COMPLEX square array, shape (:,:).
! On entry, the matrix A.
! If UPLO = 'U', the upper triangular part of A contains the upper
! triangular part of the matrix A. If UPLO = 'L', the lower
! triangular part of A contains the lower triangular part of the
! matrix A.
! On exit:
! If JOBZ = 'V', then the columns of A contain the orthonormal
! eigenvectors of the matrix A in the order of the eigenvalues.
! If JOBZ = 'N', then the upper triangle (if UPLO = 'U') or the
! lower triangle (if UPLO = 'L') of A, including the diagonal, is
! destroyed.
! W (output) REAL array, shape (:) with size(W) = size(A,1).
! The eigenvalues in ascending order.
! JOBZ Optional (input) CHARACTER(LEN=1).
! = 'N': Computes eigenvalues only;
! = 'V': Computes eigenvalues and eigenvectors.
! Default value: 'N'.
! UPLO Optional (input) CHARACTER(LEN=1).
! = 'U': Upper triangle of A is stored;
! = 'L': Lower triangle of A is stored.
! Default value: 'U'.
! 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 off-diagonal elements of an
! intermediate tridiagonal form did not converge to zero.
! If INFO is not present and an error occurs, then the program is
! terminated with an error message.
!-----------------------------------------------------------------------
! .. LOCAL PARAMETERS ..
CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_SYEVD'
CHARACTER(LEN=6), PARAMETER :: BSNAME = 'DSYTRD'
! .. LOCAL SCALARS ..
CHARACTER(LEN=1) :: LJOBZ, LUPLO
INTEGER :: N, LINFO, LD, ISTAT, ISTAT1, LIWORK, LMWORK, LWORK, NB
! .. LOCAL ARRAYS ..
REAL(WP), POINTER :: WORK(:)
INTEGER, POINTER :: IWORK(:)
! .. INTRINSIC FUNCTIONS ..
INTRINSIC MAX, PRESENT
! .. EXECUTABLE STATEMENTS ..
N = SIZE( A, 1 ); LINFO = 0; LD = MAX(1,N); ISTAT = 0
IF( PRESENT(JOBZ) ) THEN
LJOBZ = JOBZ
ELSE
LJOBZ = 'N'
END IF
IF( PRESENT(UPLO) ) THEN
LUPLO = UPLO
ELSE
LUPLO = 'U'
END IF
! .. TEST THE ARGUMENTS
IF( SIZE( A, 2 ) /= N .OR. N < 0 )THEN
LINFO = -1
ELSE IF( SIZE( W ) /= N )THEN
LINFO = -2
ELSE IF( .NOT.LSAME(LJOBZ,'N') .AND. .NOT.LSAME(LJOBZ,'V') )THEN
LINFO = -3
ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN
LINFO = -4
ELSE IF( N > 0 )THEN
! .. DETERMINE THE WORKSPACE
IF( LSAME(LJOBZ,'V') )THEN
LMWORK = 1+6*N+2*N**2
LIWORK = 3+5*N
ELSE
LMWORK = 2*N+1
LIWORK = 1
END IF
NB = ILAENV_F77( 1, BSNAME, LUPLO, N, -1, -1, -1 )
IF( NB <= 1 .OR. NB >= N )THEN
NB = 1
END IF
LWORK = MAX( LMWORK, (NB+2)*N )
ALLOCATE(WORK(LWORK), IWORK(LIWORK), STAT=ISTAT)
IF( ISTAT /= 0 )THEN
DEALLOCATE(WORK, IWORK, STAT=ISTAT1)
LWORK = LMWORK
ALLOCATE(WORK(LWORK), IWORK(LIWORK), STAT=ISTAT)
IF( ISTAT /= 0 ) THEN
LINFO = - 100
ELSE
CALL ERINFO( -200, SRNAME, LINFO )
ENDIF
ENDIF
!
IF( LINFO == 0 )THEN
! .. CALL LAPACK77 ROUTINE
CALL SYEVD_F77( LJOBZ, LUPLO, N, A, LD, W, WORK, LWORK, &
IWORK, LIWORK, LINFO )
ENDIF
DEALLOCATE(WORK, IWORK, STAT=ISTAT1)
ENDIF
CALL ERINFO(LINFO,SRNAME,INFO,ISTAT)
END SUBROUTINE DSYEVD_F95
| apache-2.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/clauum.f | 24 | 6705 | *> \brief \b CLAUUM computes the product UUH or LHL, where U and L are upper or lower triangular matrices (blocked algorithm).
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CLAUUM + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clauum.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clauum.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clauum.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CLAUUM( UPLO, N, A, LDA, INFO )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INFO, LDA, N
* ..
* .. Array Arguments ..
* COMPLEX A( LDA, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CLAUUM computes the product U * U**H or L**H * L, where the triangular
*> factor U or L is stored in the upper or lower triangular part of
*> the array A.
*>
*> If UPLO = 'U' or 'u' then the upper triangle of the result is stored,
*> overwriting the factor U in A.
*> If UPLO = 'L' or 'l' then the lower triangle of the result is stored,
*> overwriting the factor L in A.
*>
*> This is the blocked form of the algorithm, calling Level 3 BLAS.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> Specifies whether the triangular factor stored in the array A
*> is upper or lower triangular:
*> = 'U': Upper triangular
*> = 'L': Lower triangular
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the triangular factor U or L. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is COMPLEX array, dimension (LDA,N)
*> On entry, the triangular factor U or L.
*> On exit, if UPLO = 'U', the upper triangle of A is
*> overwritten with the upper triangle of the product U * U**H;
*> if UPLO = 'L', the lower triangle of A is overwritten with
*> the lower triangle of the product L**H * L.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -k, the k-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 complexOTHERauxiliary
*
* =====================================================================
SUBROUTINE CLAUUM( UPLO, N, A, LDA, 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 ..
CHARACTER UPLO
INTEGER INFO, LDA, N
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ONE
PARAMETER ( ONE = 1.0E+0 )
COMPLEX CONE
PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER I, IB, NB
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILAENV
EXTERNAL LSAME, ILAENV
* ..
* .. External Subroutines ..
EXTERNAL CGEMM, CHERK, CLAUU2, CTRMM, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. 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
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CLAUUM', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Determine the block size for this environment.
*
NB = ILAENV( 1, 'CLAUUM', UPLO, N, -1, -1, -1 )
*
IF( NB.LE.1 .OR. NB.GE.N ) THEN
*
* Use unblocked code
*
CALL CLAUU2( UPLO, N, A, LDA, INFO )
ELSE
*
* Use blocked code
*
IF( UPPER ) THEN
*
* Compute the product U * U**H.
*
DO 10 I = 1, N, NB
IB = MIN( NB, N-I+1 )
CALL CTRMM( 'Right', 'Upper', 'Conjugate transpose',
$ 'Non-unit', I-1, IB, CONE, A( I, I ), LDA,
$ A( 1, I ), LDA )
CALL CLAUU2( 'Upper', IB, A( I, I ), LDA, INFO )
IF( I+IB.LE.N ) THEN
CALL CGEMM( 'No transpose', 'Conjugate transpose',
$ I-1, IB, N-I-IB+1, CONE, A( 1, I+IB ),
$ LDA, A( I, I+IB ), LDA, CONE, A( 1, I ),
$ LDA )
CALL CHERK( 'Upper', 'No transpose', IB, N-I-IB+1,
$ ONE, A( I, I+IB ), LDA, ONE, A( I, I ),
$ LDA )
END IF
10 CONTINUE
ELSE
*
* Compute the product L**H * L.
*
DO 20 I = 1, N, NB
IB = MIN( NB, N-I+1 )
CALL CTRMM( 'Left', 'Lower', 'Conjugate transpose',
$ 'Non-unit', IB, I-1, CONE, A( I, I ), LDA,
$ A( I, 1 ), LDA )
CALL CLAUU2( 'Lower', IB, A( I, I ), LDA, INFO )
IF( I+IB.LE.N ) THEN
CALL CGEMM( 'Conjugate transpose', 'No transpose', IB,
$ I-1, N-I-IB+1, CONE, A( I+IB, I ), LDA,
$ A( I+IB, 1 ), LDA, CONE, A( I, 1 ), LDA )
CALL CHERK( 'Lower', 'Conjugate transpose', IB,
$ N-I-IB+1, ONE, A( I+IB, I ), LDA, ONE,
$ A( I, I ), LDA )
END IF
20 CONTINUE
END IF
END IF
*
RETURN
*
* End of CLAUUM
*
END
| apache-2.0 |
aamaricci/SciFortran | src/fftpack/cfftmb.f90 | 1 | 4460 | subroutine cfftmb ( lot, jump, n, inc, c, lenc, wsave, lensav, work, &
lenwrk, ier )
!*****************************************************************************80
!
!! CFFTMB: complex double precision backward FFT, 1D, multiple vectors.
!
! Discussion:
!
! CFFTMB computes the one-dimensional Fourier transform of multiple
! periodic sequences within a complex array. This transform is referred
! to as the backward transform or Fourier synthesis, transforming the
! sequences from spectral to physical space. This transform is
! normalized since a call to CFFTMF followed by a call to CFFTMB (or
! vice-versa) reproduces the original array within roundoff error.
!
! The parameters INC, JUMP, N and LOT are consistent if equality
! I1*INC + J1*JUMP = I2*INC + J2*JUMP for I1,I2 < N and J1,J2 < LOT
! implies I1=I2 and J1=J2. For multiple FFTs to execute correctly,
! input variables INC, JUMP, N and LOT must be consistent, otherwise
! at least one array element mistakenly is transformed more than once.
!
! 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 ) LOT, the number of sequences to be transformed
! within array C.
!
! Input, integer ( kind = 4 ) JUMP, the increment between the locations, in
! array C, of the first elements of two consecutive sequences to be
! transformed.
!
! Input, integer ( kind = 4 ) N, the length of each sequence to be
! transformed. The transform is most efficient when N is a product of
! small primes.
!
! Input, integer ( kind = 4 ) INC, the increment between the locations, in
! array C, of two consecutive elements within the same sequence to be
! transformed.
!
! Input/output, complex ( kind = 8 ) C(LENC), an array containing LOT
! sequences, each having length N, to be transformed. C can have any
! number of dimensions, but the total number of locations must be at least
! LENC. On output, C contains the transformed sequences.
!
! Input, integer ( kind = 4 ) LENC, the dimension of the C array.
! LENC must be at least (LOT-1)*JUMP + INC*(N-1) + 1.
!
! Input, real ( kind = 8 ) WSAVE(LENSAV). WSAVE's contents must be
! initialized with a call to CFFTMI before the first call to routine CFFTMF
! or CFFTMB for a given transform length N.
!
! Input, integer ( kind = 4 ) LENSAV, the dimension of the WSAVE array.
! LENSAV must be at least 2*N + INT(LOG(REAL(N))) + 4.
!
! Workspace, real ( kind = 8 ) WORK(LENWRK).
!
! Input, integer ( kind = 4 ) LENWRK, the dimension of the WORK array.
! LENWRK must be at least 2*LOT*N.
!
! Output, integer ( kind = 4 ) IER, error flag.
! 0, successful exit
! 1, input parameter LENC not big enough;
! 2, input parameter LENSAV not big enough;
! 3, input parameter LENWRK not big enough;
! 4, input parameters INC, JUMP, N, LOT are not consistent.
!
implicit none
integer ( kind = 4 ) lenc
integer ( kind = 4 ) lensav
integer ( kind = 4 ) lenwrk
complex ( kind = 8 ) c(lenc)
integer ( kind = 4 ) ier
integer ( kind = 4 ) inc
integer ( kind = 4 ) iw1
integer ( kind = 4 ) jump
integer ( kind = 4 ) lot
integer ( kind = 4 ) n
real ( kind = 8 ) work(lenwrk)
real ( kind = 8 ) wsave(lensav)
logical xercon
ier = 0
if (lenc < (lot-1)*jump + inc*(n-1) + 1) then
ier = 1
call xerfft ('cfftmb ', 6)
else if (lensav < 2*n + int(log( real ( n, kind = 8 )) &
/log( 2.0D+00 )) + 4) then
ier = 2
call xerfft ('cfftmb ', 8)
else if (lenwrk < 2*lot*n) then
ier = 3
call xerfft ('cfftmb ', 10)
else if (.not. xercon(inc,jump,n,lot)) then
ier = 4
call xerfft ('cfftmb ', -1)
end if
if (n == 1) then
return
end if
iw1 = n+n+1
call cmfm1b (lot,jump,n,inc,c,work,wsave,wsave(iw1),wsave(iw1+1))
return
end
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack95/SRC/la_dsysvx.f90 | 1 | 10718 | SUBROUTINE DSYSVX_F95(A, B, X, UPLO, AF, IPIV, FACT, &
FERR, BERR, RCOND, INFO)
!
! -- LAPACK95 interface driver routine (version 3.0) --
! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK
! September, 2000
!
! .. USE STATEMENTS ..
USE LA_PRECISION, ONLY: WP => DP
USE LA_AUXMOD, ONLY: LSAME, ERINFO
USE F77_LAPACK, ONLY: SYSVX_F77 => LA_SYSVX, ILAENV_F77 => ILAENV
! .. IMPLICIT STATEMENT ..
IMPLICIT NONE
! .. SCALAR ARGUMENTS ..
CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO, FACT
INTEGER, INTENT(OUT), OPTIONAL :: INFO
REAL(WP), INTENT(OUT), OPTIONAL :: RCOND
! .. ARRAY ARGUMENTS ..
REAL(WP), INTENT(IN) :: A(:,:), B(:,:)
REAL(WP), INTENT(OUT) :: X(:,:)
INTEGER, INTENT(INOUT), OPTIONAL, TARGET :: IPIV(:)
REAL(WP), INTENT(INOUT), OPTIONAL, TARGET :: AF(:,:)
REAL(WP), INTENT(OUT), OPTIONAL, TARGET :: FERR(:), BERR(:)
!----------------------------------------------------------------------
!
! Purpose
! =======
!
! LA_SYSVX computes the solution to a linear system of equations
! A*X = B, where A is a real or complex symmetric matrix and X and B are
! rectangular matrices or vectors.
! LA_HESVX computes the solution to a linear system of equations
! A*X = B, where A is a complex Hermitian matrix and X and B are
! rectangular matrices or vectors.
! LA_SYSVX and LA_HESVX can also optionally estimate the condition
! number of A and compute error bounds.
!
! =========
!
! SUBROUTINE LA_SYSVX / LA HESVX( A, B, X, UPLO=uplo, AF=af, &
! IPIV=ipiv, FACT=fact, FERR=ferr, BERR=berr, &
! RCOND=rcond, INFO=info )
! <type>(<wp>), INTENT(IN) :: A(:,:), <rhs>
! <type>(<wp>), INTENT(OUT) :: <sol>
! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO
! <type>(<wp>), INTENT(INOUT), OPTIONAL :: AF(:,:)
! INTEGER, INTENT(INOUT), OPTIONAL :: IPIV(:)
! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: FACT
! REAL(<wp>), INTENT(OUT), OPTIONAL :: <err>, RCOND
! INTEGER, INTENT(OUT), OPTIONAL :: INFO
! where
! <type> ::= REAL | COMPLEX
! <wp> ::= KIND(1.0) | KIND(1.0D0)
! <rhs> ::= B(:,:) | B(:)
! <sol> ::= X(:,:) | X(:)
! <err> ::= FERR(:), BERR(:) | FERR, BERR
!
! Arguments
! =========
!
! A (input) REAL or COMPLEX square array, shape (:,:).
! The symmetric or Hermitian matrix A.
! If UPLO = 'U', the 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
! 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.
! B (input) REAL or COMPLEX array, shape (:,:) with size(B,1) =
! size(A,1) or shape (:) with size(B) = size(A,1).
! The matrix B.
! X (output) REAL or COMPLEX array, shape (:,:) with size(X,1) =
! size(A,1) and size(X,2) = size(B,2), or shape (:) with size(X)
! = size(A,1).
! The solution matrix X.
! UPLO Optional (input) CHARACTER(LEN=1).
! = 'U': Upper triangle of A is stored;
! = 'L': Lower triangle of A is stored.
! Default value: 'U'.
! AF Optional (input or output) REAL or COMPLEX array, shape (:,:)
! with the same size as A.
! If FACT = 'F', then AF is an input argument that contains the
! block diagonal matrix D and the multipliers used to obtain the
! factor L or U from the factorization of A, returned by a
! previous call to LA_SYSVX or LA_HESVX.
! If FACT = 'N', then AF is an output argument that contains the
! block diagonal matrix D and the multipliers used to obtain the
! factor L or U from the factorization of A.
! IPIV Optional (input or output) INTEGER array, shape (:) with
! size(IPIV) = size(A,1).
! If FACT = 'F', then IPIV is an input argument that contains
! details of the row and column 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 IPIV(k) < 0 , then there are two cases:
! 1. 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.
! 2. 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.
! If FACT = 'N', then IPIV is an output argument that contains
! details of the row and column interchanges and the block
! structure of D; as described above.
! FACT Optional (input) CHARACTER(LEN=1).
! Specifies whether the factored form of the matrix A has been
! supplied on entry.
! = 'N': The matrix A will be copied to AF and factored.
! = 'F': AF and IPIV contain the factored form of A.
! Default value: 'N'.
! FERR Optional (output) REAL array of shape (:), with
! size(FERR) = size(X,2), or REAL scalar.
! 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.
! BERR Optional (output) REAL array of shape (:), with size(BERR) =
! size(X,2), or REAL scalar.
! 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).
! RCOND Optional (output) REAL
! The estimate of the reciprocal condition number of A. If RCOND
! is less than the machine
! precision, the matrix is singular to working precision. This
! condition is indicated by a return code of INFO > 0.
! INFO (output) INTEGER
! = 0: successful exit.
! < 0: if INFO = -i, the i-th argument had an illegal value.
! > 0: if INFO = i, and i is
! <= n: D(i,i) = 0. The factorization has been completed, but
! the block diagonal matrix D is singular, so the
! solution could not be computed.
! = n+1: D is nonsingular, but RCOND is less than machine
! precision, so the matrix is singular to working
! precision. Nevertheless, the solution and error bounds
! are computed because the computed solution can be more
! accurate than the value of RCOND would suggest.
! n is the order of A.
! If INFO is not present and an error occurs, then the program is
! terminated with an error message.
!------------------------------------------------------------------------
! .. PARAMETERS ..
CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_SYSVX'
CHARACTER(LEN=6), PARAMETER :: BSNAME = 'DSYTRF'
! .. LOCAL SCALARS ..
CHARACTER(LEN=1) :: LFACT, LUPLO
INTEGER :: LINFO, NRHS, N, NB, LWORK, ISTAT, ISTAT1, SIPIV, S1AF, S2AF, SFERR, SBERR
REAL(WP) :: LRCOND
! .. LOCAL POINTERS ..
INTEGER, POINTER :: IWORK(:), LPIV(:)
REAL(WP), POINTER :: LFERR(:), LBERR(:)
REAL(WP), POINTER :: WORK(:), LAF(:, :)
! .. INTRINSIC FUNCTIONS ..
INTRINSIC PRESENT, SIZE, MAX
! .. EXECUTABLE STATEMENTS ..
LINFO = 0; ISTAT = 0; N = SIZE(A, 1); NRHS = SIZE(B, 2)
IF( PRESENT(RCOND) ) RCOND = 1.0_WP
IF( PRESENT(FACT) )THEN; LFACT = FACT; ELSE; LFACT='N'; END IF
IF( PRESENT(UPLO) ) THEN; LUPLO = UPLO; ELSE; LUPLO = 'U'; END IF
IF( PRESENT(IPIV) )THEN; SIPIV = SIZE(IPIV); ELSE; SIPIV = N; END IF
IF( PRESENT(AF) )THEN; S1AF = SIZE(AF,1); S2AF = SIZE(AF,2)
ELSE; S1AF = N; S2AF = N; END IF
IF( PRESENT(FERR) )THEN; SFERR = SIZE(FERR); ELSE; SFERR = NRHS; END IF
IF( PRESENT(BERR) )THEN; SBERR = SIZE(BERR); ELSE; SBERR = NRHS; END IF
! .. TEST THE ARGUMENTS
IF( SIZE(A, 2) /= N .OR. N < 0 )THEN; LINFO = -1
ELSE IF( SIZE(B, 1) /= N .OR. NRHS < 0 )THEN; LINFO = -2
ELSE IF( SIZE(X, 1) /= N .OR. SIZE(X, 2) /= NRHS )THEN; LINFO = -3
ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN; LINFO = -4
ELSE IF( S1AF /= N .OR. S2AF /= N ) THEN; LINFO = -5
ELSE IF( SIPIV /= N )THEN; LINFO = -6
ELSE IF( ( .NOT. LSAME(LFACT,'F') .AND. .NOT. LSAME(LFACT,'N') ) .OR. &
( LSAME(LFACT,'F') .AND. .NOT.( PRESENT(AF) .AND. PRESENT(IPIV) ) ) )THEN; LINFO = -7
ELSE IF( SFERR /= NRHS )THEN; LINFO = -8
ELSE IF( SBERR /= NRHS )THEN; LINFO = -9
ELSE IF ( N > 0 )THEN
IF( .NOT.PRESENT(AF) ) THEN; ALLOCATE( LAF(N,N), STAT=ISTAT )
ELSE; LAF => AF; END IF
IF( ISTAT == 0 )THEN
IF( .NOT.PRESENT(IPIV) )THEN; ALLOCATE( LPIV(N), STAT=ISTAT )
ELSE; LPIV => IPIV; END IF
END IF
IF( ISTAT == 0 )THEN
IF( .NOT.PRESENT(FERR) )THEN; ALLOCATE( LFERR(NRHS), STAT=ISTAT )
ELSE; LFERR => FERR; END IF
END IF
IF( ISTAT == 0 )THEN
IF( .NOT.PRESENT(BERR) )THEN; ALLOCATE( LBERR(NRHS), STAT=ISTAT )
ELSE; LBERR => BERR; END IF
END IF
IF( ISTAT == 0 )THEN
NB = ILAENV_F77( 1, BSNAME, LUPLO, N, -1, -1, -1 )
IF( NB <= 1 .OR. NB >= N ) NB = 1; LWORK = MAX(1,3*N,N*NB)
ALLOCATE(WORK(LWORK), IWORK(N), STAT=ISTAT)
IF( ISTAT /= 0 )THEN
DEALLOCATE(WORK, IWORK, STAT=ISTAT1); LWORK = MAX(1,3*N)
ALLOCATE(WORK(LWORK), IWORK(N), STAT=ISTAT)
IF( ISTAT /= 0 ) THEN; LINFO = - 100
ELSE; CALL ERINFO( -200, SRNAME, LINFO ); ENDIF
ENDIF
END IF
IF( ISTAT == 0 )THEN
! .. CALL LAPACK77 ROUTINE
CALL SYSVX_F77( LFACT, LUPLO, N, NRHS, A, N, LAF, N, LPIV, B, N, X, N, &
LRCOND, LFERR, LBERR, WORK, LWORK, IWORK, LINFO )
ELSE; LINFO = -100; END IF
IF( .NOT.PRESENT(AF) ) DEALLOCATE( LAF, STAT=ISTAT1 )
IF( .NOT.PRESENT(IPIV) ) DEALLOCATE( LPIV, STAT=ISTAT1 )
IF( .NOT.PRESENT(FERR) ) DEALLOCATE( LFERR, STAT=ISTAT1 )
IF( .NOT.PRESENT(BERR) ) DEALLOCATE( LBERR, STAT=ISTAT1 )
IF( PRESENT(RCOND) ) RCOND=LRCOND
DEALLOCATE( WORK, IWORK, STAT=ISTAT1 )
END IF
CALL ERINFO( LINFO, SRNAME, INFO, ISTAT )
END SUBROUTINE DSYSVX_F95
| apache-2.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/dgebak.f | 25 | 7242 | *> \brief \b DGEBAK
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DGEBAK + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgebak.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgebak.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgebak.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DGEBAK( JOB, SIDE, N, ILO, IHI, SCALE, M, V, LDV,
* INFO )
*
* .. Scalar Arguments ..
* CHARACTER JOB, SIDE
* INTEGER IHI, ILO, INFO, LDV, M, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION SCALE( * ), V( LDV, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> 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.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] JOB
*> \verbatim
*> JOB is 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.
*> \endverbatim
*>
*> \param[in] SIDE
*> \verbatim
*> SIDE is CHARACTER*1
*> = 'R': V contains right eigenvectors;
*> = 'L': V contains left eigenvectors.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of rows of the matrix V. N >= 0.
*> \endverbatim
*>
*> \param[in] ILO
*> \verbatim
*> ILO is INTEGER
*> \endverbatim
*>
*> \param[in] IHI
*> \verbatim
*> IHI is INTEGER
*> The integers ILO and IHI determined by DGEBAL.
*> 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
*> \endverbatim
*>
*> \param[in] SCALE
*> \verbatim
*> SCALE is DOUBLE PRECISION array, dimension (N)
*> Details of the permutation and scaling factors, as returned
*> by DGEBAL.
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of columns of the matrix V. M >= 0.
*> \endverbatim
*>
*> \param[in,out] V
*> \verbatim
*> V is 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.
*> \endverbatim
*>
*> \param[in] LDV
*> \verbatim
*> LDV is INTEGER
*> The leading dimension of the array V. LDV >= max(1,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 2011
*
*> \ingroup doubleGEcomputational
*
* =====================================================================
SUBROUTINE DGEBAK( JOB, SIDE, N, ILO, IHI, SCALE, M, V, LDV,
$ 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 JOB, SIDE
INTEGER IHI, ILO, INFO, LDV, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION SCALE( * ), V( LDV, * )
* ..
*
* =====================================================================
*
* .. 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
| apache-2.0 |
aamaricci/SciFortran | src/lapack/dgehrd.f | 2 | 9062 | SUBROUTINE DGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, 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 2009 --
*
* .. Scalar Arguments ..
INTEGER IHI, ILO, INFO, LDA, LWORK, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DGEHRD reduces a real general matrix A to upper Hessenberg form H by
* an orthogonal similarity transformation: Q**T * A * Q = H .
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* ILO (input) INTEGER
* IHI (input) INTEGER
* 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 DGEBAL; otherwise they should be
* set to 1 and N respectively. See Further Details.
* 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
*
* A (input/output) 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
* elements below the first subdiagonal, with the array TAU,
* represent the orthogonal matrix Q as a product of elementary
* reflectors. See Further Details.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* TAU (output) DOUBLE PRECISION array, dimension (N-1)
* The scalar factors of the elementary reflectors (see Further
* Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
* zero.
*
* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
* On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*
* LWORK (input) INTEGER
* The length 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.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value.
*
* Further Details
* ===============
*
* The matrix Q is represented as a product of (ihi-ilo) elementary
* reflectors
*
* Q = H(ilo) H(ilo+1) . . . H(ihi-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, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
* exit in A(i+2:ihi,i), and tau in TAU(i).
*
* The contents of A are illustrated by the following example, with
* n = 7, ilo = 2 and ihi = 6:
*
* on entry, on exit,
*
* ( a a a a a a a ) ( a a h h h h a )
* ( a a a a a a ) ( a h h h h a )
* ( a a a a a a ) ( h h h h h h )
* ( a a a a a a ) ( v2 h h h h h )
* ( a a a a a a ) ( v2 v3 h h h h )
* ( a a a a a a ) ( v2 v3 v4 h h h )
* ( 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 file is a slight modification of LAPACK-3.0's DGEHRD
* subroutine incorporating improvements proposed by Quintana-Orti and
* Van de Geijn (2006). (See DLAHR2.)
*
* =====================================================================
*
* .. Parameters ..
INTEGER NBMAX, LDT
PARAMETER ( NBMAX = 64, LDT = NBMAX+1 )
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0,
$ ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL LQUERY
INTEGER I, IB, IINFO, IWS, J, LDWORK, LWKOPT, NB,
$ NBMIN, NH, NX
DOUBLE PRECISION EI
* ..
* .. Local Arrays ..
DOUBLE PRECISION T( LDT, NBMAX )
* ..
* .. External Subroutines ..
EXTERNAL DAXPY, DGEHD2, DGEMM, DLAHR2, DLARFB, DTRMM,
$ XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. External Functions ..
INTEGER ILAENV
EXTERNAL ILAENV
* ..
* .. Executable Statements ..
*
* Test the input parameters
*
INFO = 0
NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) )
LWKOPT = N*NB
WORK( 1 ) = LWKOPT
LQUERY = ( LWORK.EQ.-1 )
IF( N.LT.0 ) THEN
INFO = -1
ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
INFO = -2
ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
INFO = -3
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -5
ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
INFO = -8
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DGEHRD', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Set elements 1:ILO-1 and IHI:N-1 of TAU to zero
*
DO 10 I = 1, ILO - 1
TAU( I ) = ZERO
10 CONTINUE
DO 20 I = MAX( 1, IHI ), N - 1
TAU( I ) = ZERO
20 CONTINUE
*
* Quick return if possible
*
NH = IHI - ILO + 1
IF( NH.LE.1 ) THEN
WORK( 1 ) = 1
RETURN
END IF
*
* Determine the block size
*
NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) )
NBMIN = 2
IWS = 1
IF( NB.GT.1 .AND. NB.LT.NH ) THEN
*
* Determine when to cross over from blocked to unblocked code
* (last block is always handled by unblocked code)
*
NX = MAX( NB, ILAENV( 3, 'DGEHRD', ' ', N, ILO, IHI, -1 ) )
IF( NX.LT.NH ) THEN
*
* Determine if workspace is large enough for blocked code
*
IWS = N*NB
IF( LWORK.LT.IWS ) 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, 'DGEHRD', ' ', N, ILO, IHI,
$ -1 ) )
IF( LWORK.GE.N*NBMIN ) THEN
NB = LWORK / N
ELSE
NB = 1
END IF
END IF
END IF
END IF
LDWORK = N
*
IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN
*
* Use unblocked code below
*
I = ILO
*
ELSE
*
* Use blocked code
*
DO 40 I = ILO, IHI - 1 - NX, NB
IB = MIN( NB, IHI-I )
*
* Reduce columns i:i+ib-1 to Hessenberg form, returning the
* matrices V and T of the block reflector H = I - V*T*V**T
* which performs the reduction, and also the matrix Y = A*V*T
*
CALL DLAHR2( IHI, I, IB, A( 1, I ), LDA, TAU( I ), T, LDT,
$ WORK, LDWORK )
*
* Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
* right, computing A := A - Y * V**T. V(i+ib,ib-1) must be set
* to 1
*
EI = A( I+IB, I+IB-1 )
A( I+IB, I+IB-1 ) = ONE
CALL DGEMM( 'No transpose', 'Transpose',
$ IHI, IHI-I-IB+1,
$ IB, -ONE, WORK, LDWORK, A( I+IB, I ), LDA, ONE,
$ A( 1, I+IB ), LDA )
A( I+IB, I+IB-1 ) = EI
*
* Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
* right
*
CALL DTRMM( 'Right', 'Lower', 'Transpose',
$ 'Unit', I, IB-1,
$ ONE, A( I+1, I ), LDA, WORK, LDWORK )
DO 30 J = 0, IB-2
CALL DAXPY( I, -ONE, WORK( LDWORK*J+1 ), 1,
$ A( 1, I+J+1 ), 1 )
30 CONTINUE
*
* Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
* left
*
CALL DLARFB( 'Left', 'Transpose', 'Forward',
$ 'Columnwise',
$ IHI-I, N-I-IB+1, IB, A( I+1, I ), LDA, T, LDT,
$ A( I+1, I+IB ), LDA, WORK, LDWORK )
40 CONTINUE
END IF
*
* Use unblocked code to reduce the rest of the matrix
*
CALL DGEHD2( N, I, IHI, A, LDA, TAU, WORK, IINFO )
WORK( 1 ) = IWS
*
RETURN
*
* End of DGEHRD
*
END
| lgpl-3.0 |
ALICEHLT/AliRoot | TEvtGen/Tauola/tauola-fortran/new-currents/RChL-currents/rcht_common/value_parameter.f | 9 | 15514 | SUBROUTINE CH3PISET(JJ)
C information on 3 pion sub-channel under construction obtained
C J3PI=1 means 3 prong
C J3PI=2 means 1 prong
C to be initialized in routine DPHSAA of tauola.f
COMMON /CHANOPT/ J3PI
INTEGER J3PI
J3PI=JJ
end
SUBROUTINE CH3PIGET(JJ)
C information on 3 pion sub-channel under construction obtained
C J3PI=1 means 3 prong
C J3PI=2 means 1 prong
C to be initialized in routine DPHSAA of tauola.f
COMMON /CHANOPT/ J3PI
INTEGER J3PI
IF (J3PI.EQ.1.OR.J3PI.EQ.2) THEN
JJ=J3PI
ELSE
write(*,*) 'FROM value_parameter.f CH3PIGET, wrong J3PI=',J3PI
stop
ENDIF
end
SUBROUTINE GETFF2PIRHO(JJ)
IMPLICIT NONE
include '../parameter.inc'
INTEGER JJ
JJ = FF2PIRHO
END
SUBROUTINE OLACHNL(SIGN)
C provides sign of tau, to be used in CP dependent parts of current.
COMMON / JAKI / JAK1,JAK2,JAKP,JAKM,KTOM
INTEGER JAK1,JAK2,JAKP,JAKM,KTOM
COMMON / IDFC / IDFF
INTEGER KTO
REAL SIGN
IF (KTOM.EQ.1.OR.KTOM.EQ.-1) THEN
SIGN= IDFF/ABS(IDFF)
ELSEIF (KTOM.EQ.2) THEN
SIGN=-IDFF/ABS(IDFF)
ELSE
PRINT *, 'STOP IN OLACHNL: KTOM=',KTOM
STOP
ENDIF
END
FUNCTION COEFrr(I,J)
C clebsh gordan (or so ...) coefs for 3 scalar final states
implicit none
C TAUOLA RChL COEF(I,J) = COEFr(I,J)
REAL COEFr(1:5,0:7)
REAL COEFrr
DATA PI /3.141592653589793238462643/
REAL PI
DATA ICONT /0/
INTEGER ICONT
INTEGER I,J
REAL FPIr
C initialization of FPI matrix defined in ...
C FPIc is to be used with cleo initialization
C FPIr is to be used with RChL initialization
C actual choice is made in ???
DATA FPIr /92.4E-3/
C initialization of COEF matrix defined in ...
C COEFc is to be used with cleo initialization
C COEFr is to be used with RChL initialization
IF (ICONT.EQ.0) THEN
ICONT=1
C
C********* COEFr(I,J) *******
COEFr(1,0)= 1.
COEFr(2,0)= -1.
COEFr(3,0)= 0.
COEFr(4,0)= 1.
COEFr(5,0)= 0.
COEFr(1,1)= 1.
COEFr(2,1)= -1.
COEFr(3,1)= 0.
COEFr(4,1)= 1.
COEFr(5,1)= 1.
C
COEFr(1,2)=1.
COEFr(2,2)= -1.
COEFr(3,2)= 0.0
COEFr(4,2)= 1.
COEFr(5,2)=1.
C
COEFr(1,3)= 0.
COEFr(2,3)= 1.
COEFr(3,3)= -1.
COEFr(4,3)= 1.
COEFr(5,3)= - 1.
C
COEFr(1,4)= 1.0/SQRT(2.)/3.0
COEFr(2,4)=-1.0/SQRT(2.)/3.0
COEFr(3,4)= 0.0
COEFr(4,4)= 0.0
COEFr(5,4)= 0.0
C
COEFr(1,5)=-SQRT(2.)/3.0
COEFr(2,5)= SQRT(2.)/3.0
COEFr(3,5)= 0.0
COEFr(4,5)= 0.0
COEFr(5,5)=-SQRT(2.)
C
COEFr(1,6)= 1./3.
COEFr(2,6)=-2./3.
COEFr(3,6)= 2./3.
COEFr(4,6)= 0.0
COEFr(5,6)=-2.0
C
COEFr(1,7)= 0.0
COEFr(2,7)= 0.0
COEFr(3,7)= 0.0
COEFr(4,7)= 0.0
COEFr(5,7)=-SQRT(2.0/3.0)
ENDIF
COEFrr=COEFr(I,J)
END
subroutine rchl_parameters(KAK)
implicit none
C==============================================================================
C Initialization, of '../parameter.inc' common block group
C
C KAK may be equal to JAK of TAUOLA namespace, but it is not always the case
C Hard-coded fit parameters:
C rho, rhoprime, f2(1275), f0(1186), sigma(made up!)
C The value of both the mass and width of resonances are taken
C from fit to ALEPH data (ref [1], Set 1)
C References: [1] arXiv: 0911.4436 [hep-ph] D. Gomez Dumm et al
C [2] arXiv: 0911.2640 [hep-ph] D. Gomez Dumm et al.
C [3] P Roig, talk PhiPsi2011, Novosibirsk
C [4] arXiv:0807.4883 [hep-ph] Diogo R. Boito et al.
C [5] arXiv:0803.1786 [hep-ph] M. Jamin et al.
C WARNING: some of parameters require RERUN of da1wid_tot_rho1_gauss.f
C pretabulating Q dependent a1 width,
C directory RChL-currents/tabler/a1
C==============================================================================
include '../parameter.inc'
INTEGER KAK
DATA IWARM/0/
INTEGER IWARM
INTEGER J3PI
COMMON /CHANOPT/ J3PI
IF(KAK.EQ.4) THEN
C /MASS_RES/; resonances parameters initialization:
C ! at present only for two pion mode non-default
c ! values are used:
mro = 0.77554d0
mrho1 = 1.453d0
grho1 = 0.50155D0
c /PAR_RHOPRIME/; parameters of rho' and rho''
C used for 2 pion form factor, reference [3]
COEF_GA = 0.14199D0
COEF_DE = -0.12623D0
phi_1 = -0.17377D0
phi_2 = 0.27632D0
grho2 = 0.41786D0
mrho2 = 1.8105d0
ELSE IF(KAK.EQ.5) THEN
MRO = 0.771849d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MRHO1 = 1.35d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
GRHO1 = 0.448379d0 !0.473287d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
ELSE
MRO = 0.775 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MRHO1 = 1.465 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
GRHO1 = 0.4 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
c /PAR_RHOPRIME/; parameters of rho' and rho''
C used for 2 kaon form factor, reference [3]
c FOR THE MOMENT THEIR NUMERICAL VALUES COINCIDE WITH
c ONES FOR THE TWO PION MODE !!!!
COEF_GA = 0.14199D0
COEF_DE = -0.12623D0
phi_1 = -0.17377D0
phi_2 = 0.27632D0
grho2 = 0.41786D0
mrho2 = 1.8105d0
ENDIF
IF(KAK.EQ.70) THEN ! non default values to be used
! for KPI MODE NO FSR INTERACTION
c /PAR_KPI/; parameters for Kpi mode, reference [4], table 4, row2
MKST = 0.943d0
MKSTPR = 1.374D0
GAMMA_KST = 0.06672d0
GAMMA_KSTPR = 0.240d0
GAMMA_RCHT =-0.039d0
ELSE IF(KAK.EQ.71) THEN ! non default values to be used
! for KPI MODE WITH FSR INTERACTION
c parameters for Kpi mode, reference [5]
MKST = 0.8953d0
GAMMA_KST = 0.0475d0
MKSTPR = 1.307d0
GAMMA_KSTPR = 0.206d0
GAMMA_RCHT = -0.043d0
ELSE
C /MASS_SCAL/; stable particles - final scalars
Mksp = 0.89166d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
Mks0 = 0.89610d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MKST = (Mksp +Mks0)/2.
MKSTPR = 1.374d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
GAMMA_KST = 0.06672
GAMMA_KSTPR = 0.240
GAMMA_RCHT = -0.043 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
ENDIF
C /RCHT_3PI/; model parameters; their value are from fit,
c reference [1], set 1
C CHANGE OF THEIR VALUES REQUIRES
C RERUN /tabler/a1/da1wid_tot_rho1_gauss.f
IF(KAK.EQ.5) THEN
FPI_RPT = 0.091337d0
FV_RPT = 0.168652d0
FA_RPT = 0.131425d0
BETA_RHO = -0.318551d0
ELSE
FPI_RPT = 0.0924
FV_RPT = 0.18
FA_RPT = 0.149
BETA_RHO = -0.25
ENDIF
FK_RPT = FPI_RPT*1.198d0
GV_RPT = FPI_RPT*FPI_RPT/FV_RPT
c$$$c It has to be used for a new parametrization of rho1 for 3pions,
C$$$c that is not checked yet
c$$$c IF(KAK.EQ.5) THEN ! high energy behaviour imposes these relations
c$$$c GV_RPT = 0.066
c$$$c FV1_RPT = 0.18D0
c$$$c GV1_RPT = (FPI_RPT*FPI_RPT- FV_RPT*GV_RPT)/FV1_RPT
c$$$c ELSE
c$$$c GV_RPT = FPI_RPT*FPI_RPT/FV_RPT
c$$$c ENDIF
c /SCAL_3PI/; parameters of sigma meson for 3 pion mode
C* Parameteres for the sigma contribution, using BW for sigma
IF(KAK.EQ.5) THEN
IF (J3PI.EQ.1) THEN
alpsig = -8.795938d0
betasig = 9.763701d0
gamsig = 1.264263d0
delsig = 0.656762d0
rsigma = 1.866913d0
ELSE IF (J3PI.EQ.2) THEN
alpsig = 1.139486d0*0.63d0
betasig = 1.139486d0*0.63d0
gamsig = 0.889769d0*0.63d0
delsig = 0.889769d0*0.63d0
rsigma = 0.000013d0
ENDIF
ENDIF
C /MASS_RES/
IF(KAK.EQ.5) THEN
MMA1 = 1.091865d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
IF (J3PI.EQ.1) THEN
MSIG = 0.487512d0
GSIG = 0.70d0
ELSE IF(J3PI.EQ.2) THEN
MSIG = 0.55d0
GSIG = 0.7d0
ENDIF
ELSE
MMA1 = 1.12
MSIG = 0.475
GSIG = 0.550
ENDIF
call rchl_REparam(0,IWARM,KAK)
IF (IWARM.EQ.1) RETURN ! parameters below do not need
IWARM=1 ! re-initialization
C /MASS_RES/
GRO = 0.149d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MF2 = 1.275d0
GF2 = 0.185d0
MF0 = 1.186d0
GF0 = 0.350d0
MSG = 0.860d0
GSG = 0.880d0
MPHI = 1.019d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
GPHI = 0.0042d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MOM = 0.781940d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
GOM = 0.00843d0 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
C /RES_MIXING_RCHT/; a parameter defines w-phi angle mixing
THETA = 35.*PI/180.
C /FF0SCKPI/ a parameter normalized FFSC_KPI
F00 = 0.972
C /MASS_SCAL/; stable particles - final scalars
C CHANGE OF THEIR VALUES (useful for some tests) REQUIRES,
C RERUN /tabler/a1/da1wid_tot_rho1_gauss.f
MPIZ = 0.1349766d0 !PKORB(1,7) ! NEUTRAL PION MASS
MPIC = 0.13957018d0 !PKORB(1,8) ! CHARGED PION MASS
MMPI_AV = (MPIZ+2.*MPIC)/3.d0
MKZ = 0.497648d0 !PKORB(1,12) ! NEUTRAL KAON MASS
MKC = 0.493677d0 !PKORB(1,11) ! CHARGED KAON MASS
MMK = (MKC+MKZ)/2.d0
MTAU = 1.777
MNUTA = 0.001
META = 0.547d0
c /PAR_KKPI/; parameters to describe KKpi modes, reference [2]
C CHANGE OF THEIR VALUES REQUIRES
C RERUN /tabler/a1/da1wid_tot_rho1_gauss.f
G2 = mro/(192.*pi*pi*sqrt(2.)*FV_RPT)*3.
G13 = -2.*g2
G4 = -0.72
G5 = -0.6-2.*g4
C125 = 0.
C1256 = -3/96./pi**2*FV_RPT*MRO/SQRT(2.)/FPI_RPT**2
C1235 = 0.
C4 = -0.07
D123 = 0.05
D3 = -MRO**2/(64.*PI*PI*FPI_RPT**2)
c /PAR_KPI/; parameters to describe Kpi mode, reference [4]
Ht0 = -1.2400398216503017D-2
C Ht0 = !!!!! TO ADD A FORMULAE FOR Ht0 (Jamin's email) !!!!!
lap_KPI = 24.66e-3
lapp_KPI = 11.99e-4
c1_KPI = lap_KPI/mpic**2
c2_KPI = (lapp_KPI - lap_kpi**2)/2.d0/mpic**4
c /KPISC_EM/; parameters for Kpi scalar FF from
c http://arxiv.org/pdf/1103.4855.pdf
lnC = 0.20193d0
lambda0 = 0.013139d0
c /SCAL_3PI/; parameters of sigma meson for 3 pion mode
a00_3piscal = 0.220
b00_3piscal = 0.268/mmpi_av**2
c00_3piscal = -0.0139/mmpi_av**4
d00_3piscal = -0.00139/mmpi_av**6
x00_3piscal = 36.77*mmpi_av**2
a02_3piscal = -0.0444
b02_3piscal = -0.0857/mmpi_av**2
c02_3piscal = -0.00221/mmpi_av**4
d02_3piscal = -0.000129/mmpi_av**6
x02_3piscal = -21.62*mmpi_av**2
MMF0 = 0.441
c /SCAL_3PI/; parameters for the scalar part 3 pion modes
c Pablo private
ALPHA0_3PI = 1.
ALPHA1_3PI = 1.
GAMMA0_3PI = 1.
GAMMA1_3PI = 1.
C FFVEC: dipswitch for Final State interaction in two scalar modes
C with FSI (default FFVEC =1) and
C without FSI (FFVEC =0)
FFVEC = 1
C FFKPIVEC : parameter to choose the parametrization for
C vector Kpi form factor with FSI effects
C FFKPIVEC = 0 parametrization Eqs.(17),(18) of [4]
C FFKPIVEC = 1 parametrization Eq.(5) of [5]
C FFKPIVEC = 2 parmetrization [4], total result
FFKPIVEC = 2
C FFKPISCAL : parameter to choose the parametrization for
C scalar Kpi form factor with FSI effects
C FFKPISCAL = 0 no scalar contribution
C FFKPISCAL = 1 parametrization of Mathias Jamin,adopted his private code
C FFKPISCAL = 2 parametrization of Emilie Passerman,
C adopted her private code []
FFKPISCAL = 1
C FFKKVEC: dipswitch for K0K- mode
C with rho' and rho'' (FFKKVEC =1) and
C without rho' and rho'' (default FFKKVEC =0)
FFKKVEC = 0
C FF3PISCAL: dipswitch for the scalar contribution for 3 pion modes
C with the scalar contribution ( default FF3PISCAL = 2)
c FF3PISCAL = 2 BW parametrization for sigma meson
c FF3PISCAL = 1 simplified RCHT results
C FF3PISCAL =0 no sigma contribution
FF3PISCAL = 2
C Implemetation of another parametrization rho1, not checked yet by tests
C FF3PIRHOPR: dipswitch for the parametrization for rho' contribution
C For 3 pion modes
C general parametrization ( default FF3RHOPR =1) and
C simplified (FF3PIRHOPR =0)
FF3PIRHOPR = 0
C FF2PIRHO: dipswitch for the two pion form factor (default FF2PIRHO = 1)
C FF2PIRHO =1 RChL parametrization
C FF2PIRHO = 2 Belle parametrization,
C all parameters par (1...11) of fit are free
C FF2PIRHO = 3 Belle parametrization,
C parameters of fit are free
C except for fixed par(1)=F_pi(0)=1
FF2PIRHO =2
C FCOUL: dipswitch for the Coulomb interaction
C FCOUL = 1 with
C FCOUL = 0 without
FCOUL = 0
call rchl_REparam(1,IWARM,KAK)
return
end
subroutine rchl_REparam(IMODE,IWARM,KAK)
include '../parameter.inc'
common / PARAMS / P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,IUSE
INTEGER IUSE
DOUBLE PRECISION P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16
DATA IUSE /0/
IF(IUSE.EQ.0) RETURN
IF (IMODE.EQ.-1) THEN
IWARM=IWARM
ELSE
C FF3PISCAL: dipswitch for the scalar contribution for 3 pion modes
C with the scalar contribution ( default FF3PISCAL = 2)
c FF3PISCAL = 2 BW parametrization for sigma meson
c FF3PISCAL = 1 simplified RCHT results
C FF3PISCAL =0 no sigma contribution
c FF3PISCAL = 2
C CANDIDATES FOR PARAMETERS TO FIT with default values
C* Parameteres for the sigma contribution, using BW for sigma
alpsig = P1
betasig = P2
gamsig = P3
delsig = P4
rsigma = P5
MRO = P6 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MRHO1 = P7 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
GRHO1 = P8 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
C /MASS_RES/
GRO = P9 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MMA1 = P10 !CHANGE REQUIRES RERUN da1wid_tot_rho1_gauss.f
MSIG = P11
GSIG = P12
C /RCHT_3PI/; model parameters; their value are from fit,
c reference [1], set 1
C CHANGE OF THEIR VALUES REQUIRES
C RERUN /tabler/a1/da1wid_tot_rho1_gauss.f
FPI_RPT = P13
FV_RPT = P14
FA_RPT = P15
BETA_RHO = P16
FK_RPT = FPI_RPT*1.198d0
GV_RPT = FPI_RPT*FPI_RPT/FV_RPT
ENDIF
return
end
| bsd-3-clause |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/clarfg.f | 24 | 5402 | *> \brief \b CLARFG generates an elementary reflector (Householder matrix).
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CLARFG + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clarfg.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clarfg.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clarfg.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CLARFG( N, ALPHA, X, INCX, TAU )
*
* .. Scalar Arguments ..
* INTEGER INCX, N
* COMPLEX ALPHA, TAU
* ..
* .. Array Arguments ..
* COMPLEX X( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CLARFG 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
*> On entry, the value alpha.
*> On exit, it is overwritten with the value beta.
*> \endverbatim
*>
*> \param[in,out] X
*> \verbatim
*> X is COMPLEX 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
*> The value tau.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup complexOTHERauxiliary
*
* =====================================================================
SUBROUTINE CLARFG( N, ALPHA, X, INCX, TAU )
*
* -- 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
COMPLEX ALPHA, TAU
* ..
* .. Array Arguments ..
COMPLEX X( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ONE, ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Local Scalars ..
INTEGER J, KNT
REAL ALPHI, ALPHR, BETA, RSAFMN, SAFMIN, XNORM
* ..
* .. External Functions ..
REAL SCNRM2, SLAMCH, SLAPY3
COMPLEX CLADIV
EXTERNAL SCNRM2, SLAMCH, SLAPY3, CLADIV
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, CMPLX, REAL, SIGN
* ..
* .. External Subroutines ..
EXTERNAL CSCAL, CSSCAL
* ..
* .. Executable Statements ..
*
IF( N.LE.0 ) THEN
TAU = ZERO
RETURN
END IF
*
XNORM = SCNRM2( N-1, X, INCX )
ALPHR = REAL( ALPHA )
ALPHI = AIMAG( ALPHA )
*
IF( XNORM.EQ.ZERO .AND. ALPHI.EQ.ZERO ) THEN
*
* H = I
*
TAU = ZERO
ELSE
*
* general case
*
BETA = -SIGN( SLAPY3( ALPHR, ALPHI, XNORM ), ALPHR )
SAFMIN = SLAMCH( 'S' ) / SLAMCH( '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 CSSCAL( N-1, RSAFMN, X, INCX )
BETA = BETA*RSAFMN
ALPHI = ALPHI*RSAFMN
ALPHR = ALPHR*RSAFMN
IF( ABS( BETA ).LT.SAFMIN )
$ GO TO 10
*
* New BETA is at most 1, at least SAFMIN
*
XNORM = SCNRM2( N-1, X, INCX )
ALPHA = CMPLX( ALPHR, ALPHI )
BETA = -SIGN( SLAPY3( ALPHR, ALPHI, XNORM ), ALPHR )
END IF
TAU = CMPLX( ( BETA-ALPHR ) / BETA, -ALPHI / BETA )
ALPHA = CLADIV( CMPLX( ONE ), ALPHA-BETA )
CALL CSCAL( 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 CLARFG
*
END
| apache-2.0 |
oere/pfft | tests/fortran/simple_check_ousam_c2c_transposed.F90 | 3 | 3933 |
program test
implicit none
include "mpif.h"
#include "fftw3.f"
include "pfft.f"
integer np(2), myrank, ierror, comm_cart_2d
integer(ptrdiff_t_kind) :: l, m
integer(ptrdiff_t_kind) :: n(3), ni(3), no(3)
integer(ptrdiff_t_kind) :: alloc_local_forw, alloc_local_back, alloc_local
integer(ptrdiff_t_kind) :: howmany
integer(ptrdiff_t_kind) :: local_ni(3), local_i_start(3)
integer(ptrdiff_t_kind) :: local_n(3), local_start(3)
integer(ptrdiff_t_kind) :: local_no(3), local_o_start(3)
integer(8) plan_forw, plan_back
complex(8), allocatable :: data_in(:)
complex(8), allocatable :: data_out(:)
real(8) error
! Set size of FFT and process mesh
ni = (/ 16,16,16 /)
n = (/ 29,27,31 /)
do l=1,3
no(l) = ni(l)
enddo
howmany = 1
np = (/ 2,2 /)
! Initialize MPI and PFFT
call MPI_Init(ierror)
call dpfft_init();
call MPI_Comm_rank(MPI_COMM_WORLD, myrank, ierror)
! Create two-dimensional process grid of
! size np(1) x np(2), if possible
call dpfft_create_procmesh_2d(ierror, MPI_COMM_WORLD, &
& np(1), np(2), comm_cart_2d)
if (ierror .ne. 0) then
if(myrank .eq. 0) then
write(*,*) "Error: This test file only works with 4 processes"
endif
call MPI_Finalize(ierror)
call exit(1)
endif
! Get parameters of data distribution
call dpfft_local_size_many_dft( &
& alloc_local_forw, 3, n, ni, n, howmany, &
& PFFT_DEFAULT_BLOCKS, PFFT_DEFAULT_BLOCKS, &
& comm_cart_2d, PFFT_TRANSPOSED_OUT, &
& local_ni, local_i_start, local_n, local_start);
call dpfft_local_size_many_dft( &
& alloc_local_back, 3, n, n, no, howmany, &
& PFFT_DEFAULT_BLOCKS, PFFT_DEFAULT_BLOCKS, &
& comm_cart_2d, PFFT_TRANSPOSED_IN, &
& local_n, local_start, local_no, local_o_start);
! Allocate enough memory for both trafos
alloc_local = alloc_local_forw
if(alloc_local_back .gt. alloc_local_forw) then
alloc_local = alloc_local_back
endif
allocate(data_in(alloc_local))
allocate(data_out(alloc_local))
! Plan parallel forward FFT
call dpfft_plan_many_dft( &
& plan_forw, 3, n, ni, n, howmany, &
& PFFT_DEFAULT_BLOCKS, PFFT_DEFAULT_BLOCKS, &
& data_in, data_out, comm_cart_2d, &
& PFFT_FORWARD, PFFT_TRANSPOSED_OUT + PFFT_MEASURE + PFFT_DESTROY_INPUT)
! Plan parallel backward FFT
call dpfft_plan_many_dft( &
& plan_back, 3, n, n, no, howmany, &
& PFFT_DEFAULT_BLOCKS, PFFT_DEFAULT_BLOCKS, &
& data_out, data_in, comm_cart_2d, &
& PFFT_BACKWARD, PFFT_TRANSPOSED_IN + PFFT_MEASURE + PFFT_DESTROY_INPUT)
! Initialize input with random numbers
call dpfft_init_input_complex_3d(ni, local_ni, local_i_start, &
& data_in)
! Execute parallel forward FFT
call dpfft_execute(plan_forw)
! Execute parallel backward FFT
call dpfft_execute(plan_back)
! Scale data
m=1
do l=1,local_ni(1) * local_ni(2) * local_ni(3)
data_in(l) = data_in(l) / (n(1)*n(2)*n(3))
m = m+1
enddo
! Print error of back transformed data
call dpfft_check_output_complex_3d(error, ni, local_ni, local_i_start, &
& data_in, comm_cart_2d)
if(myrank .eq. 0) then
write(*,*) "Error after one forward and backward&
& trafo of size n=(", n(1), n(2), n(3), "):"
write(*,*) "maxerror = ", error
endif
! free mem and finalize
call dpfft_destroy_plan(plan_forw)
call dpfft_destroy_plan(plan_back)
call MPI_Comm_free(comm_cart_2d, ierror)
deallocate(data_out)
deallocate(data_in)
! Finalize MPI
call MPI_Finalize(ierror)
end
| gpl-3.0 |
leo-butler/Maxima-CAS | share/lapack/lapack/fortran/dlasq3.f | 18 | 7904 | SUBROUTINE DLASQ3( I0, N0, Z, PP, DMIN, SIGMA, DESIG, QMAX, NFAIL,
$ ITER, NDIV, IEEE )
*
* -- LAPACK auxiliary routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* May 17, 2000
*
* .. Scalar Arguments ..
LOGICAL IEEE
INTEGER I0, ITER, N0, NDIV, NFAIL, PP
DOUBLE PRECISION DESIG, DMIN, QMAX, SIGMA
* ..
* .. Array Arguments ..
DOUBLE PRECISION Z( * )
* ..
*
* Purpose
* =======
*
* DLASQ3 checks for deflation, computes a shift (TAU) and calls dqds.
* In case of failure it changes shifts, and tries again until output
* is positive.
*
* Arguments
* =========
*
* I0 (input) INTEGER
* First index.
*
* N0 (input) INTEGER
* Last index.
*
* Z (input) DOUBLE PRECISION array, dimension ( 4*N )
* Z holds the qd array.
*
* PP (input) INTEGER
* PP=0 for ping, PP=1 for pong.
*
* DMIN (output) DOUBLE PRECISION
* Minimum value of d.
*
* SIGMA (output) DOUBLE PRECISION
* Sum of shifts used in current segment.
*
* DESIG (input/output) DOUBLE PRECISION
* Lower order part of SIGMA
*
* QMAX (input) DOUBLE PRECISION
* Maximum value of q.
*
* NFAIL (output) INTEGER
* Number of times shift was too big.
*
* ITER (output) INTEGER
* Number of iterations.
*
* NDIV (output) INTEGER
* Number of divisions.
*
* TTYPE (output) INTEGER
* Shift type.
*
* IEEE (input) LOGICAL
* Flag for IEEE or non IEEE arithmetic (passed to DLASQ5).
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION CBIAS
PARAMETER ( CBIAS = 1.50D0 )
DOUBLE PRECISION ZERO, QURTR, HALF, ONE, TWO, HUNDRD
PARAMETER ( ZERO = 0.0D0, QURTR = 0.250D0, HALF = 0.5D0,
$ ONE = 1.0D0, TWO = 2.0D0, HUNDRD = 100.0D0 )
* ..
* .. Local Scalars ..
INTEGER IPN4, J4, N0IN, NN, TTYPE
DOUBLE PRECISION DMIN1, DMIN2, DN, DN1, DN2, EPS, S, SAFMIN, T,
$ TAU, TEMP, TOL, TOL2
* ..
* .. External Subroutines ..
EXTERNAL DLASQ4, DLASQ5, DLASQ6
* ..
* .. External Function ..
DOUBLE PRECISION DLAMCH
EXTERNAL DLAMCH
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MIN, SQRT
* ..
* .. Save statement ..
SAVE TTYPE
SAVE DMIN1, DMIN2, DN, DN1, DN2, TAU
* ..
* .. Data statement ..
DATA TTYPE / 0 /
DATA DMIN1 / ZERO /, DMIN2 / ZERO /, DN / ZERO /,
$ DN1 / ZERO /, DN2 / ZERO /, TAU / ZERO /
* ..
* .. Executable Statements ..
*
N0IN = N0
EPS = DLAMCH( 'Precision' )
SAFMIN = DLAMCH( 'Safe minimum' )
TOL = EPS*HUNDRD
TOL2 = TOL**2
*
* Check for deflation.
*
10 CONTINUE
*
IF( N0.LT.I0 )
$ RETURN
IF( N0.EQ.I0 )
$ GO TO 20
NN = 4*N0 + PP
IF( N0.EQ.( I0+1 ) )
$ GO TO 40
*
* Check whether E(N0-1) is negligible, 1 eigenvalue.
*
IF( Z( NN-5 ).GT.TOL2*( SIGMA+Z( NN-3 ) ) .AND.
$ Z( NN-2*PP-4 ).GT.TOL2*Z( NN-7 ) )
$ GO TO 30
*
20 CONTINUE
*
Z( 4*N0-3 ) = Z( 4*N0+PP-3 ) + SIGMA
N0 = N0 - 1
GO TO 10
*
* Check whether E(N0-2) is negligible, 2 eigenvalues.
*
30 CONTINUE
*
IF( Z( NN-9 ).GT.TOL2*SIGMA .AND.
$ Z( NN-2*PP-8 ).GT.TOL2*Z( NN-11 ) )
$ GO TO 50
*
40 CONTINUE
*
IF( Z( NN-3 ).GT.Z( NN-7 ) ) THEN
S = Z( NN-3 )
Z( NN-3 ) = Z( NN-7 )
Z( NN-7 ) = S
END IF
IF( Z( NN-5 ).GT.Z( NN-3 )*TOL2 ) THEN
T = HALF*( ( Z( NN-7 )-Z( NN-3 ) )+Z( NN-5 ) )
S = Z( NN-3 )*( Z( NN-5 ) / T )
IF( S.LE.T ) THEN
S = Z( NN-3 )*( Z( NN-5 ) /
$ ( T*( ONE+SQRT( ONE+S / T ) ) ) )
ELSE
S = Z( NN-3 )*( Z( NN-5 ) / ( T+SQRT( T )*SQRT( T+S ) ) )
END IF
T = Z( NN-7 ) + ( S+Z( NN-5 ) )
Z( NN-3 ) = Z( NN-3 )*( Z( NN-7 ) / T )
Z( NN-7 ) = T
END IF
Z( 4*N0-7 ) = Z( NN-7 ) + SIGMA
Z( 4*N0-3 ) = Z( NN-3 ) + SIGMA
N0 = N0 - 2
GO TO 10
*
50 CONTINUE
*
* Reverse the qd-array, if warranted.
*
IF( DMIN.LE.ZERO .OR. N0.LT.N0IN ) THEN
IF( CBIAS*Z( 4*I0+PP-3 ).LT.Z( 4*N0+PP-3 ) ) THEN
IPN4 = 4*( I0+N0 )
DO 60 J4 = 4*I0, 2*( I0+N0-1 ), 4
TEMP = Z( J4-3 )
Z( J4-3 ) = Z( IPN4-J4-3 )
Z( IPN4-J4-3 ) = TEMP
TEMP = Z( J4-2 )
Z( J4-2 ) = Z( IPN4-J4-2 )
Z( IPN4-J4-2 ) = TEMP
TEMP = Z( J4-1 )
Z( J4-1 ) = Z( IPN4-J4-5 )
Z( IPN4-J4-5 ) = TEMP
TEMP = Z( J4 )
Z( J4 ) = Z( IPN4-J4-4 )
Z( IPN4-J4-4 ) = TEMP
60 CONTINUE
IF( N0-I0.LE.4 ) THEN
Z( 4*N0+PP-1 ) = Z( 4*I0+PP-1 )
Z( 4*N0-PP ) = Z( 4*I0-PP )
END IF
DMIN2 = MIN( DMIN2, Z( 4*N0+PP-1 ) )
Z( 4*N0+PP-1 ) = MIN( Z( 4*N0+PP-1 ), Z( 4*I0+PP-1 ),
$ Z( 4*I0+PP+3 ) )
Z( 4*N0-PP ) = MIN( Z( 4*N0-PP ), Z( 4*I0-PP ),
$ Z( 4*I0-PP+4 ) )
QMAX = MAX( QMAX, Z( 4*I0+PP-3 ), Z( 4*I0+PP+1 ) )
DMIN = -ZERO
END IF
END IF
*
70 CONTINUE
*
IF( DMIN.LT.ZERO .OR. SAFMIN*QMAX.LT.MIN( Z( 4*N0+PP-1 ),
$ Z( 4*N0+PP-9 ), DMIN2+Z( 4*N0-PP ) ) ) THEN
*
* Choose a shift.
*
CALL DLASQ4( I0, N0, Z, PP, N0IN, DMIN, DMIN1, DMIN2, DN, DN1,
$ DN2, TAU, TTYPE )
*
* Call dqds until DMIN > 0.
*
80 CONTINUE
*
CALL DLASQ5( I0, N0, Z, PP, TAU, DMIN, DMIN1, DMIN2, DN,
$ DN1, DN2, IEEE )
*
NDIV = NDIV + ( N0-I0+2 )
ITER = ITER + 1
*
* Check status.
*
IF( DMIN.GE.ZERO .AND. DMIN1.GT.ZERO ) THEN
*
* Success.
*
GO TO 100
*
ELSE IF( DMIN.LT.ZERO .AND. DMIN1.GT.ZERO .AND.
$ Z( 4*( N0-1 )-PP ).LT.TOL*( SIGMA+DN1 ) .AND.
$ ABS( DN ).LT.TOL*SIGMA ) THEN
*
* Convergence hidden by negative DN.
*
Z( 4*( N0-1 )-PP+2 ) = ZERO
DMIN = ZERO
GO TO 100
ELSE IF( DMIN.LT.ZERO ) THEN
*
* TAU too big. Select new TAU and try again.
*
NFAIL = NFAIL + 1
IF( TTYPE.LT.-22 ) THEN
*
* Failed twice. Play it safe.
*
TAU = ZERO
ELSE IF( DMIN1.GT.ZERO ) THEN
*
* Late failure. Gives excellent shift.
*
TAU = ( TAU+DMIN )*( ONE-TWO*EPS )
TTYPE = TTYPE - 11
ELSE
*
* Early failure. Divide by 4.
*
TAU = QURTR*TAU
TTYPE = TTYPE - 12
END IF
GO TO 80
ELSE IF( DMIN.NE.DMIN ) THEN
*
* NaN.
*
TAU = ZERO
GO TO 80
ELSE
*
* Possible underflow. Play it safe.
*
GO TO 90
END IF
END IF
*
* Risk of underflow.
*
90 CONTINUE
CALL DLASQ6( I0, N0, Z, PP, DMIN, DMIN1, DMIN2, DN, DN1, DN2 )
NDIV = NDIV + ( N0-I0+2 )
ITER = ITER + 1
TAU = ZERO
*
100 CONTINUE
IF( TAU.LT.SIGMA ) THEN
DESIG = DESIG + TAU
T = SIGMA + DESIG
DESIG = DESIG - ( T-SIGMA )
ELSE
T = SIGMA + TAU
DESIG = SIGMA - ( T-TAU ) + DESIG
END IF
SIGMA = T
*
RETURN
*
* End of DLASQ3
*
END
| gpl-2.0 |
OpenDA-Association/OpenDA | core/native/external/lapack/ctrsyl.f | 2 | 11661 | SUBROUTINE CTRSYL( TRANA, TRANB, ISGN, M, N, A, LDA, B, LDB, C,
$ LDC, SCALE, INFO )
*
* -- LAPACK 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 TRANA, TRANB
INTEGER INFO, ISGN, LDA, LDB, LDC, M, N
REAL SCALE
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * ), B( LDB, * ), C( LDC, * )
* ..
*
* Purpose
* =======
*
* CTRSYL solves the complex Sylvester matrix equation:
*
* op(A)*X + X*op(B) = scale*C or
* op(A)*X - X*op(B) = scale*C,
*
* where op(A) = A or A**H, and A and B are both upper triangular. A is
* M-by-M and B is N-by-N; the right hand side C and the solution X are
* M-by-N; and scale is an output scale factor, set <= 1 to avoid
* overflow in X.
*
* Arguments
* =========
*
* TRANA (input) CHARACTER*1
* Specifies the option op(A):
* = 'N': op(A) = A (No transpose)
* = 'C': op(A) = A**H (Conjugate transpose)
*
* TRANB (input) CHARACTER*1
* Specifies the option op(B):
* = 'N': op(B) = B (No transpose)
* = 'C': op(B) = B**H (Conjugate transpose)
*
* ISGN (input) INTEGER
* Specifies the sign in the equation:
* = +1: solve op(A)*X + X*op(B) = scale*C
* = -1: solve op(A)*X - X*op(B) = scale*C
*
* M (input) INTEGER
* The order of the matrix A, and the number of rows in the
* matrices X and C. M >= 0.
*
* N (input) INTEGER
* The order of the matrix B, and the number of columns in the
* matrices X and C. N >= 0.
*
* A (input) COMPLEX array, dimension (LDA,M)
* The upper triangular matrix A.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,M).
*
* B (input) COMPLEX array, dimension (LDB,N)
* The upper triangular matrix B.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* C (input/output) COMPLEX array, dimension (LDC,N)
* On entry, the M-by-N right hand side matrix C.
* On exit, C is overwritten by the solution matrix X.
*
* LDC (input) INTEGER
* The leading dimension of the array C. LDC >= max(1,M)
*
* SCALE (output) REAL
* The scale factor, scale, set <= 1 to avoid overflow in X.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* = 1: A and B have common or very close eigenvalues; perturbed
* values were used to solve the equation (but the matrices
* A and B are unchanged).
*
* =====================================================================
*
* .. Parameters ..
REAL ONE
PARAMETER ( ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL NOTRNA, NOTRNB
INTEGER J, K, L
REAL BIGNUM, DA11, DB, EPS, SCALOC, SGN, SMIN,
$ SMLNUM
COMPLEX A11, SUML, SUMR, VEC, X11
* ..
* .. Local Arrays ..
REAL DUM( 1 )
* ..
* .. External Functions ..
LOGICAL LSAME
REAL CLANGE, SLAMCH
COMPLEX CDOTC, CDOTU, CLADIV
EXTERNAL LSAME, CLANGE, SLAMCH, CDOTC, CDOTU, CLADIV
* ..
* .. External Subroutines ..
EXTERNAL CSSCAL, SLABAD, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, MIN, REAL
* ..
* .. Executable Statements ..
*
* Decode and Test input parameters
*
NOTRNA = LSAME( TRANA, 'N' )
NOTRNB = LSAME( TRANB, 'N' )
*
INFO = 0
IF( .NOT.NOTRNA .AND. .NOT.LSAME( TRANA, 'T' ) .AND. .NOT.
$ LSAME( TRANA, 'C' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOTRNB .AND. .NOT.LSAME( TRANB, 'T' ) .AND. .NOT.
$ LSAME( TRANB, 'C' ) ) THEN
INFO = -2
ELSE IF( ISGN.NE.1 .AND. ISGN.NE.-1 ) THEN
INFO = -3
ELSE IF( M.LT.0 ) THEN
INFO = -4
ELSE IF( N.LT.0 ) THEN
INFO = -5
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
INFO = -7
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
INFO = -11
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CTRSYL', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( M.EQ.0 .OR. N.EQ.0 )
$ RETURN
*
* Set constants to control overflow
*
EPS = SLAMCH( 'P' )
SMLNUM = SLAMCH( 'S' )
BIGNUM = ONE / SMLNUM
CALL SLABAD( SMLNUM, BIGNUM )
SMLNUM = SMLNUM*REAL( M*N ) / EPS
BIGNUM = ONE / SMLNUM
SMIN = MAX( SMLNUM, EPS*CLANGE( 'M', M, M, A, LDA, DUM ),
$ EPS*CLANGE( 'M', N, N, B, LDB, DUM ) )
SCALE = ONE
SGN = ISGN
*
IF( NOTRNA .AND. NOTRNB ) THEN
*
* Solve A*X + ISGN*X*B = scale*C.
*
* The (K,L)th block of X is determined starting from
* bottom-left corner column by column by
*
* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L)
*
* Where
* M L-1
* R(K,L) = SUM [A(K,I)*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)].
* I=K+1 J=1
*
DO 30 L = 1, N
DO 20 K = M, 1, -1
*
SUML = CDOTU( M-K, A( K, MIN( K+1, M ) ), LDA,
$ C( MIN( K+1, M ), L ), 1 )
SUMR = CDOTU( L-1, C( K, 1 ), LDC, B( 1, L ), 1 )
VEC = C( K, L ) - ( SUML+SGN*SUMR )
*
SCALOC = ONE
A11 = A( K, K ) + SGN*B( L, L )
DA11 = ABS( REAL( A11 ) ) + ABS( AIMAG( A11 ) )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( REAL( VEC ) ) + ABS( AIMAG( VEC ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
X11 = CLADIV( VEC*CMPLX( SCALOC ), A11 )
*
IF( SCALOC.NE.ONE ) THEN
DO 10 J = 1, N
CALL CSSCAL( M, SCALOC, C( 1, J ), 1 )
10 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K, L ) = X11
*
20 CONTINUE
30 CONTINUE
*
ELSE IF( .NOT.NOTRNA .AND. NOTRNB ) THEN
*
* Solve A' *X + ISGN*X*B = scale*C.
*
* The (K,L)th block of X is determined starting from
* upper-left corner column by column by
*
* A'(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L)
*
* Where
* K-1 L-1
* R(K,L) = SUM [A'(I,K)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)]
* I=1 J=1
*
DO 60 L = 1, N
DO 50 K = 1, M
*
SUML = CDOTC( K-1, A( 1, K ), 1, C( 1, L ), 1 )
SUMR = CDOTU( L-1, C( K, 1 ), LDC, B( 1, L ), 1 )
VEC = C( K, L ) - ( SUML+SGN*SUMR )
*
SCALOC = ONE
A11 = CONJG( A( K, K ) ) + SGN*B( L, L )
DA11 = ABS( REAL( A11 ) ) + ABS( AIMAG( A11 ) )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( REAL( VEC ) ) + ABS( AIMAG( VEC ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
*
X11 = CLADIV( VEC*CMPLX( SCALOC ), A11 )
*
IF( SCALOC.NE.ONE ) THEN
DO 40 J = 1, N
CALL CSSCAL( M, SCALOC, C( 1, J ), 1 )
40 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K, L ) = X11
*
50 CONTINUE
60 CONTINUE
*
ELSE IF( .NOT.NOTRNA .AND. .NOT.NOTRNB ) THEN
*
* Solve A'*X + ISGN*X*B' = C.
*
* The (K,L)th block of X is determined starting from
* upper-right corner column by column by
*
* A'(K,K)*X(K,L) + ISGN*X(K,L)*B'(L,L) = C(K,L) - R(K,L)
*
* Where
* K-1
* R(K,L) = SUM [A'(I,K)*X(I,L)] +
* I=1
* N
* ISGN*SUM [X(K,J)*B'(L,J)].
* J=L+1
*
DO 90 L = N, 1, -1
DO 80 K = 1, M
*
SUML = CDOTC( K-1, A( 1, K ), 1, C( 1, L ), 1 )
SUMR = CDOTC( N-L, C( K, MIN( L+1, N ) ), LDC,
$ B( L, MIN( L+1, N ) ), LDB )
VEC = C( K, L ) - ( SUML+SGN*CONJG( SUMR ) )
*
SCALOC = ONE
A11 = CONJG( A( K, K )+SGN*B( L, L ) )
DA11 = ABS( REAL( A11 ) ) + ABS( AIMAG( A11 ) )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( REAL( VEC ) ) + ABS( AIMAG( VEC ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
*
X11 = CLADIV( VEC*CMPLX( SCALOC ), A11 )
*
IF( SCALOC.NE.ONE ) THEN
DO 70 J = 1, N
CALL CSSCAL( M, SCALOC, C( 1, J ), 1 )
70 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K, L ) = X11
*
80 CONTINUE
90 CONTINUE
*
ELSE IF( NOTRNA .AND. .NOT.NOTRNB ) THEN
*
* Solve A*X + ISGN*X*B' = C.
*
* The (K,L)th block of X is determined starting from
* bottom-left corner column by column by
*
* A(K,K)*X(K,L) + ISGN*X(K,L)*B'(L,L) = C(K,L) - R(K,L)
*
* Where
* M N
* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B'(L,J)]
* I=K+1 J=L+1
*
DO 120 L = N, 1, -1
DO 110 K = M, 1, -1
*
SUML = CDOTU( M-K, A( K, MIN( K+1, M ) ), LDA,
$ C( MIN( K+1, M ), L ), 1 )
SUMR = CDOTC( N-L, C( K, MIN( L+1, N ) ), LDC,
$ B( L, MIN( L+1, N ) ), LDB )
VEC = C( K, L ) - ( SUML+SGN*CONJG( SUMR ) )
*
SCALOC = ONE
A11 = A( K, K ) + SGN*CONJG( B( L, L ) )
DA11 = ABS( REAL( A11 ) ) + ABS( AIMAG( A11 ) )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( REAL( VEC ) ) + ABS( AIMAG( VEC ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
*
X11 = CLADIV( VEC*CMPLX( SCALOC ), A11 )
*
IF( SCALOC.NE.ONE ) THEN
DO 100 J = 1, N
CALL CSSCAL( M, SCALOC, C( 1, J ), 1 )
100 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K, L ) = X11
*
110 CONTINUE
120 CONTINUE
*
END IF
*
RETURN
*
* End of CTRSYL
*
END
| lgpl-3.0 |
aamaricci/SciFortran | src/lapack/cpstrf.f | 1 | 12051 | SUBROUTINE CPSTRF( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
*
* -- LAPACK routine (version 3.2.2) --
* Craig Lucas, University of Manchester / NAG Ltd.
* October, 2008
*
* .. Scalar Arguments ..
REAL TOL
INTEGER INFO, LDA, N, RANK
CHARACTER UPLO
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * )
REAL WORK( 2*N )
INTEGER PIV( N )
* ..
*
* Purpose
* =======
*
* CPSTRF computes the Cholesky factorization with complete
* pivoting of a complex Hermitian positive semidefinite matrix A.
*
* The factorization has the form
* P**T * A * P = U**H * U , if UPLO = 'U',
* P**T * A * P = L * L**H, if UPLO = 'L',
* where U is an upper triangular matrix and L is lower triangular, and
* P is stored as vector PIV.
*
* This algorithm does not attempt to check that A is positive
* semidefinite. This version of the algorithm calls level 3 BLAS.
*
* 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.
*
* A (input/output) COMPLEX 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, if INFO = 0, the factor U or L from the Cholesky
* factorization as above.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* PIV (output) INTEGER array, dimension (N)
* PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
*
* RANK (output) INTEGER
* The rank of A given by the number of steps the algorithm
* completed.
*
* TOL (input) REAL
* User defined tolerance. If TOL < 0, then N*U*MAX( A(K,K) )
* will be used. The algorithm terminates at the (K-1)st step
* if the pivot <= TOL.
*
* WORK (workspace) REAL array, dimension (2*N)
* Work space.
*
* INFO (output) INTEGER
* < 0: If INFO = -K, the K-th argument had an illegal value,
* = 0: algorithm completed successfully, and
* > 0: the matrix A is either rank deficient with computed rank
* as returned in RANK, or is indefinite. See Section 7 of
* LAPACK Working Note #161 for further information.
*
* =====================================================================
*
* .. Parameters ..
REAL ONE, ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
COMPLEX CONE
PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
COMPLEX CTEMP
REAL AJJ, SSTOP, STEMP
INTEGER I, ITEMP, J, JB, K, NB, PVT
LOGICAL UPPER
* ..
* .. External Functions ..
REAL SLAMCH
INTEGER ILAENV
LOGICAL LSAME, SISNAN
EXTERNAL SLAMCH, ILAENV, LSAME, SISNAN
* ..
* .. External Subroutines ..
EXTERNAL CGEMV, CHERK, CLACGV, CPSTF2, CSSCAL, CSWAP,
$ XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC CONJG, MAX, MIN, REAL, SQRT, MAXLOC
* ..
* .. 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
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CPSTRF', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Get block size
*
NB = ILAENV( 1, 'CPOTRF', UPLO, N, -1, -1, -1 )
IF( NB.LE.1 .OR. NB.GE.N ) THEN
*
* Use unblocked code
*
CALL CPSTF2( UPLO, N, A( 1, 1 ), LDA, PIV, RANK, TOL, WORK,
$ INFO )
GO TO 230
*
ELSE
*
* Initialize PIV
*
DO 100 I = 1, N
PIV( I ) = I
100 CONTINUE
*
* Compute stopping value
*
DO 110 I = 1, N
WORK( I ) = REAL( A( I, I ) )
110 CONTINUE
PVT = MAXLOC( WORK( 1:N ), 1 )
AJJ = REAL( A( PVT, PVT ) )
IF( AJJ.EQ.ZERO.OR.SISNAN( AJJ ) ) THEN
RANK = 0
INFO = 1
GO TO 230
END IF
*
* Compute stopping value if not supplied
*
IF( TOL.LT.ZERO ) THEN
SSTOP = N * SLAMCH( 'Epsilon' ) * AJJ
ELSE
SSTOP = TOL
END IF
*
*
IF( UPPER ) THEN
*
* Compute the Cholesky factorization P**T * A * P = U**H * U
*
DO 160 K = 1, N, NB
*
* Account for last block not being NB wide
*
JB = MIN( NB, N-K+1 )
*
* Set relevant part of first half of WORK to zero,
* holds dot products
*
DO 120 I = K, N
WORK( I ) = 0
120 CONTINUE
*
DO 150 J = K, K + JB - 1
*
* Find pivot, test for exit, else swap rows and columns
* Update dot products, compute possible pivots which are
* stored in the second half of WORK
*
DO 130 I = J, N
*
IF( J.GT.K ) THEN
WORK( I ) = WORK( I ) +
$ REAL( CONJG( A( J-1, I ) )*
$ A( J-1, I ) )
END IF
WORK( N+I ) = REAL( A( I, I ) ) - WORK( I )
*
130 CONTINUE
*
IF( J.GT.1 ) THEN
ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
PVT = ITEMP + J - 1
AJJ = WORK( N+PVT )
IF( AJJ.LE.SSTOP.OR.SISNAN( AJJ ) ) THEN
A( J, J ) = AJJ
GO TO 220
END IF
END IF
*
IF( J.NE.PVT ) THEN
*
* Pivot OK, so can now swap pivot rows and columns
*
A( PVT, PVT ) = A( J, J )
CALL CSWAP( J-1, A( 1, J ), 1, A( 1, PVT ), 1 )
IF( PVT.LT.N )
$ CALL CSWAP( N-PVT, A( J, PVT+1 ), LDA,
$ A( PVT, PVT+1 ), LDA )
DO 140 I = J + 1, PVT - 1
CTEMP = CONJG( A( J, I ) )
A( J, I ) = CONJG( A( I, PVT ) )
A( I, PVT ) = CTEMP
140 CONTINUE
A( J, PVT ) = CONJG( A( J, PVT ) )
*
* Swap dot products and PIV
*
STEMP = WORK( J )
WORK( J ) = WORK( PVT )
WORK( PVT ) = STEMP
ITEMP = PIV( PVT )
PIV( PVT ) = PIV( J )
PIV( J ) = ITEMP
END IF
*
AJJ = SQRT( AJJ )
A( J, J ) = AJJ
*
* Compute elements J+1:N of row J.
*
IF( J.LT.N ) THEN
CALL CLACGV( J-1, A( 1, J ), 1 )
CALL CGEMV( 'Trans', J-K, N-J, -CONE, A( K, J+1 ),
$ LDA, A( K, J ), 1, CONE, A( J, J+1 ),
$ LDA )
CALL CLACGV( J-1, A( 1, J ), 1 )
CALL CSSCAL( N-J, ONE / AJJ, A( J, J+1 ), LDA )
END IF
*
150 CONTINUE
*
* Update trailing matrix, J already incremented
*
IF( K+JB.LE.N ) THEN
CALL CHERK( 'Upper', 'Conj Trans', N-J+1, JB, -ONE,
$ A( K, J ), LDA, ONE, A( J, J ), LDA )
END IF
*
160 CONTINUE
*
ELSE
*
* Compute the Cholesky factorization P**T * A * P = L * L**H
*
DO 210 K = 1, N, NB
*
* Account for last block not being NB wide
*
JB = MIN( NB, N-K+1 )
*
* Set relevant part of first half of WORK to zero,
* holds dot products
*
DO 170 I = K, N
WORK( I ) = 0
170 CONTINUE
*
DO 200 J = K, K + JB - 1
*
* Find pivot, test for exit, else swap rows and columns
* Update dot products, compute possible pivots which are
* stored in the second half of WORK
*
DO 180 I = J, N
*
IF( J.GT.K ) THEN
WORK( I ) = WORK( I ) +
$ REAL( CONJG( A( I, J-1 ) )*
$ A( I, J-1 ) )
END IF
WORK( N+I ) = REAL( A( I, I ) ) - WORK( I )
*
180 CONTINUE
*
IF( J.GT.1 ) THEN
ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
PVT = ITEMP + J - 1
AJJ = WORK( N+PVT )
IF( AJJ.LE.SSTOP.OR.SISNAN( AJJ ) ) THEN
A( J, J ) = AJJ
GO TO 220
END IF
END IF
*
IF( J.NE.PVT ) THEN
*
* Pivot OK, so can now swap pivot rows and columns
*
A( PVT, PVT ) = A( J, J )
CALL CSWAP( J-1, A( J, 1 ), LDA, A( PVT, 1 ), LDA )
IF( PVT.LT.N )
$ CALL CSWAP( N-PVT, A( PVT+1, J ), 1,
$ A( PVT+1, PVT ), 1 )
DO 190 I = J + 1, PVT - 1
CTEMP = CONJG( A( I, J ) )
A( I, J ) = CONJG( A( PVT, I ) )
A( PVT, I ) = CTEMP
190 CONTINUE
A( PVT, J ) = CONJG( A( PVT, J ) )
*
* Swap dot products and PIV
*
STEMP = WORK( J )
WORK( J ) = WORK( PVT )
WORK( PVT ) = STEMP
ITEMP = PIV( PVT )
PIV( PVT ) = PIV( J )
PIV( J ) = ITEMP
END IF
*
AJJ = SQRT( AJJ )
A( J, J ) = AJJ
*
* Compute elements J+1:N of column J.
*
IF( J.LT.N ) THEN
CALL CLACGV( J-1, A( J, 1 ), LDA )
CALL CGEMV( 'No Trans', N-J, J-K, -CONE,
$ A( J+1, K ), LDA, A( J, K ), LDA, CONE,
$ A( J+1, J ), 1 )
CALL CLACGV( J-1, A( J, 1 ), LDA )
CALL CSSCAL( N-J, ONE / AJJ, A( J+1, J ), 1 )
END IF
*
200 CONTINUE
*
* Update trailing matrix, J already incremented
*
IF( K+JB.LE.N ) THEN
CALL CHERK( 'Lower', 'No Trans', N-J+1, JB, -ONE,
$ A( J, K ), LDA, ONE, A( J, J ), LDA )
END IF
*
210 CONTINUE
*
END IF
END IF
*
* Ran to completion, A has full rank
*
RANK = N
*
GO TO 230
220 CONTINUE
*
* Rank is the number of steps completed. Set INFO = 1 to signal
* that the factorization cannot be used to solve a system.
*
RANK = J - 1
INFO = 1
*
230 CONTINUE
RETURN
*
* End of CPSTRF
*
END
| lgpl-3.0 |
aamaricci/SciFortran | src/lapack/cgetrf.f | 1 | 4753 | SUBROUTINE CGETRF( M, N, A, LDA, IPIV, INFO )
*
* -- LAPACK 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 ..
INTEGER INFO, LDA, M, N
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
COMPLEX A( LDA, * )
* ..
*
* Purpose
* =======
*
* CGETRF computes an LU factorization of a general M-by-N matrix A
* using partial pivoting with row interchanges.
*
* The factorization has the form
* A = P * L * U
* where P is a permutation matrix, L is lower triangular with unit
* diagonal elements (lower trapezoidal if m > n), and U is upper
* triangular (upper trapezoidal if m < n).
*
* This is the right-looking Level 3 BLAS version of the algorithm.
*
* Arguments
* =========
*
* M (input) INTEGER
* The number of rows of the matrix A. M >= 0.
*
* N (input) INTEGER
* The number of columns of the matrix A. N >= 0.
*
* A (input/output) COMPLEX array, dimension (LDA,N)
* On entry, the M-by-N matrix to be factored.
* On exit, the factors L and U from the factorization
* A = P*L*U; the unit diagonal elements of L are not stored.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,M).
*
* IPIV (output) 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).
*
* INFO (output) 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.
*
* =====================================================================
*
* .. Parameters ..
COMPLEX ONE
PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
INTEGER I, IINFO, J, JB, NB
* ..
* .. External Subroutines ..
EXTERNAL CGEMM, CGETF2, CLASWP, CTRSM, 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( 'CGETRF', -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, 'CGETRF', ' ', M, N, -1, -1 )
IF( NB.LE.1 .OR. NB.GE.MIN( M, N ) ) THEN
*
* Use unblocked code.
*
CALL CGETF2( 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 )
*
* Factor diagonal and subdiagonal blocks and test for exact
* singularity.
*
CALL CGETF2( 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 columns 1:J-1.
*
CALL CLASWP( J-1, A, LDA, J, J+JB-1, IPIV, 1 )
*
IF( J+JB.LE.N ) THEN
*
* Apply interchanges to columns J+JB:N.
*
CALL CLASWP( N-J-JB+1, A( 1, J+JB ), LDA, J, J+JB-1,
$ IPIV, 1 )
*
* Compute block row of U.
*
CALL CTRSM( 'Left', 'Lower', 'No transpose', 'Unit', JB,
$ N-J-JB+1, ONE, A( J, J ), LDA, A( J, J+JB ),
$ LDA )
IF( J+JB.LE.M ) THEN
*
* Update trailing submatrix.
*
CALL CGEMM( 'No transpose', 'No transpose', M-J-JB+1,
$ N-J-JB+1, JB, -ONE, A( J+JB, J ), LDA,
$ A( J, J+JB ), LDA, ONE, A( J+JB, J+JB ),
$ LDA )
END IF
END IF
20 CONTINUE
END IF
RETURN
*
* End of CGETRF
*
END
| lgpl-3.0 |
aamaricci/SciFortran | src/lapack/ctgevc.f | 1 | 20963 | SUBROUTINE CTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL,
$ LDVL, VR, LDVR, MM, M, WORK, RWORK, INFO )
*
* -- LAPACK 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 HOWMNY, SIDE
INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N
* ..
* .. Array Arguments ..
LOGICAL SELECT( * )
REAL RWORK( * )
COMPLEX P( LDP, * ), S( LDS, * ), VL( LDVL, * ),
$ VR( LDVR, * ), WORK( * )
* ..
*
*
* Purpose
* =======
*
* CTGEVC computes some or all of the right and/or left eigenvectors of
* a pair of complex matrices (S,P), where S and P are upper triangular.
* Matrix pairs of this type are produced by the generalized Schur
* factorization of a complex matrix pair (A,B):
*
* A = Q*S*Z**H, B = Q*P*Z**H
*
* as computed by CGGHRD + CHGEQZ.
*
* The right eigenvector x and the left eigenvector y of (S,P)
* corresponding to an eigenvalue w are defined by:
*
* S*x = w*P*x, (y**H)*S = w*(y**H)*P,
*
* where y**H denotes the conjugate tranpose of y.
* The eigenvalues are not input to this routine, but are computed
* directly from the diagonal elements of S and P.
*
* This routine returns the matrices X and/or Y of right and left
* eigenvectors of (S,P), or the products Z*X and/or Q*Y,
* where Z and Q are input matrices.
* If Q and Z are the unitary factors from the generalized Schur
* factorization of a matrix pair (A,B), then Z*X and Q*Y
* are the matrices of right and left eigenvectors of (A,B).
*
* Arguments
* =========
*
* SIDE (input) CHARACTER*1
* = 'R': compute right eigenvectors only;
* = 'L': compute left eigenvectors only;
* = 'B': compute both right and left eigenvectors.
*
* HOWMNY (input) CHARACTER*1
* = 'A': compute all right and/or left eigenvectors;
* = 'B': compute all right and/or left eigenvectors,
* backtransformed by the matrices in VR and/or VL;
* = 'S': compute selected right and/or left eigenvectors,
* specified by the logical array SELECT.
*
* SELECT (input) LOGICAL array, dimension (N)
* If HOWMNY='S', SELECT specifies the eigenvectors to be
* computed. The eigenvector corresponding to the j-th
* eigenvalue is computed if SELECT(j) = .TRUE..
* Not referenced if HOWMNY = 'A' or 'B'.
*
* N (input) INTEGER
* The order of the matrices S and P. N >= 0.
*
* S (input) COMPLEX array, dimension (LDS,N)
* The upper triangular matrix S from a generalized Schur
* factorization, as computed by CHGEQZ.
*
* LDS (input) INTEGER
* The leading dimension of array S. LDS >= max(1,N).
*
* P (input) COMPLEX array, dimension (LDP,N)
* The upper triangular matrix P from a generalized Schur
* factorization, as computed by CHGEQZ. P must have real
* diagonal elements.
*
* LDP (input) INTEGER
* The leading dimension of array P. LDP >= max(1,N).
*
* VL (input/output) COMPLEX array, dimension (LDVL,MM)
* On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
* contain an N-by-N matrix Q (usually the unitary matrix Q
* of left Schur vectors returned by CHGEQZ).
* On exit, if SIDE = 'L' or 'B', VL contains:
* if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P);
* if HOWMNY = 'B', the matrix Q*Y;
* if HOWMNY = 'S', the left eigenvectors of (S,P) specified by
* SELECT, stored consecutively in the columns of
* VL, in the same order as their eigenvalues.
* Not referenced if SIDE = 'R'.
*
* LDVL (input) INTEGER
* The leading dimension of array VL. LDVL >= 1, and if
* SIDE = 'L' or 'l' or 'B' or 'b', LDVL >= N.
*
* VR (input/output) COMPLEX array, dimension (LDVR,MM)
* On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
* contain an N-by-N matrix Q (usually the unitary matrix Z
* of right Schur vectors returned by CHGEQZ).
* On exit, if SIDE = 'R' or 'B', VR contains:
* if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P);
* if HOWMNY = 'B', the matrix Z*X;
* if HOWMNY = 'S', the right eigenvectors of (S,P) specified by
* SELECT, stored consecutively in the columns of
* VR, in the same order as their eigenvalues.
* Not referenced if SIDE = 'L'.
*
* LDVR (input) INTEGER
* The leading dimension of the array VR. LDVR >= 1, and if
* SIDE = 'R' or 'B', LDVR >= N.
*
* MM (input) INTEGER
* The number of columns in the arrays VL and/or VR. MM >= M.
*
* M (output) INTEGER
* The number of columns in the arrays VL and/or VR actually
* used to store the eigenvectors. If HOWMNY = 'A' or 'B', M
* is set to N. Each selected eigenvector occupies one column.
*
* WORK (workspace) COMPLEX array, dimension (2*N)
*
* RWORK (workspace) REAL array, dimension (2*N)
*
* INFO (output) INTEGER
* = 0: successful exit.
* < 0: if INFO = -i, the i-th argument had an illegal value.
*
* =====================================================================
*
* .. 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 ) )
* ..
* .. Local Scalars ..
LOGICAL COMPL, COMPR, ILALL, ILBACK, ILBBAD, ILCOMP,
$ LSA, LSB
INTEGER I, IBEG, IEIG, IEND, IHWMNY, IM, ISIDE, ISRC,
$ J, JE, JR
REAL ACOEFA, ACOEFF, ANORM, ASCALE, BCOEFA, BIG,
$ BIGNUM, BNORM, BSCALE, DMIN, SAFMIN, SBETA,
$ SCALE, SMALL, TEMP, ULP, XMAX
COMPLEX BCOEFF, CA, CB, D, SALPHA, SUM, SUMA, SUMB, X
* ..
* .. External Functions ..
LOGICAL LSAME
REAL SLAMCH
COMPLEX CLADIV
EXTERNAL LSAME, SLAMCH, CLADIV
* ..
* .. External Subroutines ..
EXTERNAL CGEMV, SLABAD, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, MIN, REAL
* ..
* .. Statement Functions ..
REAL ABS1
* ..
* .. Statement Function definitions ..
ABS1( X ) = ABS( REAL( X ) ) + ABS( AIMAG( X ) )
* ..
* .. Executable Statements ..
*
* Decode and Test the input parameters
*
IF( LSAME( HOWMNY, 'A' ) ) THEN
IHWMNY = 1
ILALL = .TRUE.
ILBACK = .FALSE.
ELSE IF( LSAME( HOWMNY, 'S' ) ) THEN
IHWMNY = 2
ILALL = .FALSE.
ILBACK = .FALSE.
ELSE IF( LSAME( HOWMNY, 'B' ) ) THEN
IHWMNY = 3
ILALL = .TRUE.
ILBACK = .TRUE.
ELSE
IHWMNY = -1
END IF
*
IF( LSAME( SIDE, 'R' ) ) THEN
ISIDE = 1
COMPL = .FALSE.
COMPR = .TRUE.
ELSE IF( LSAME( SIDE, 'L' ) ) THEN
ISIDE = 2
COMPL = .TRUE.
COMPR = .FALSE.
ELSE IF( LSAME( SIDE, 'B' ) ) THEN
ISIDE = 3
COMPL = .TRUE.
COMPR = .TRUE.
ELSE
ISIDE = -1
END IF
*
INFO = 0
IF( ISIDE.LT.0 ) THEN
INFO = -1
ELSE IF( IHWMNY.LT.0 ) THEN
INFO = -2
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( LDS.LT.MAX( 1, N ) ) THEN
INFO = -6
ELSE IF( LDP.LT.MAX( 1, N ) ) THEN
INFO = -8
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CTGEVC', -INFO )
RETURN
END IF
*
* Count the number of eigenvectors
*
IF( .NOT.ILALL ) THEN
IM = 0
DO 10 J = 1, N
IF( SELECT( J ) )
$ IM = IM + 1
10 CONTINUE
ELSE
IM = N
END IF
*
* Check diagonal of B
*
ILBBAD = .FALSE.
DO 20 J = 1, N
IF( AIMAG( P( J, J ) ).NE.ZERO )
$ ILBBAD = .TRUE.
20 CONTINUE
*
IF( ILBBAD ) THEN
INFO = -7
ELSE IF( COMPL .AND. LDVL.LT.N .OR. LDVL.LT.1 ) THEN
INFO = -10
ELSE IF( COMPR .AND. LDVR.LT.N .OR. LDVR.LT.1 ) THEN
INFO = -12
ELSE IF( MM.LT.IM ) THEN
INFO = -13
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CTGEVC', -INFO )
RETURN
END IF
*
* Quick return if possible
*
M = IM
IF( N.EQ.0 )
$ RETURN
*
* Machine Constants
*
SAFMIN = SLAMCH( 'Safe minimum' )
BIG = ONE / SAFMIN
CALL SLABAD( SAFMIN, BIG )
ULP = SLAMCH( 'Epsilon' )*SLAMCH( 'Base' )
SMALL = SAFMIN*N / ULP
BIG = ONE / SMALL
BIGNUM = ONE / ( SAFMIN*N )
*
* Compute the 1-norm of each column of the strictly upper triangular
* part of A and B to check for possible overflow in the triangular
* solver.
*
ANORM = ABS1( S( 1, 1 ) )
BNORM = ABS1( P( 1, 1 ) )
RWORK( 1 ) = ZERO
RWORK( N+1 ) = ZERO
DO 40 J = 2, N
RWORK( J ) = ZERO
RWORK( N+J ) = ZERO
DO 30 I = 1, J - 1
RWORK( J ) = RWORK( J ) + ABS1( S( I, J ) )
RWORK( N+J ) = RWORK( N+J ) + ABS1( P( I, J ) )
30 CONTINUE
ANORM = MAX( ANORM, RWORK( J )+ABS1( S( J, J ) ) )
BNORM = MAX( BNORM, RWORK( N+J )+ABS1( P( J, J ) ) )
40 CONTINUE
*
ASCALE = ONE / MAX( ANORM, SAFMIN )
BSCALE = ONE / MAX( BNORM, SAFMIN )
*
* Left eigenvectors
*
IF( COMPL ) THEN
IEIG = 0
*
* Main loop over eigenvalues
*
DO 140 JE = 1, N
IF( ILALL ) THEN
ILCOMP = .TRUE.
ELSE
ILCOMP = SELECT( JE )
END IF
IF( ILCOMP ) THEN
IEIG = IEIG + 1
*
IF( ABS1( S( JE, JE ) ).LE.SAFMIN .AND.
$ ABS( REAL( P( JE, JE ) ) ).LE.SAFMIN ) THEN
*
* Singular matrix pencil -- return unit eigenvector
*
DO 50 JR = 1, N
VL( JR, IEIG ) = CZERO
50 CONTINUE
VL( IEIG, IEIG ) = CONE
GO TO 140
END IF
*
* Non-singular eigenvalue:
* Compute coefficients a and b in
* H
* y ( a A - b B ) = 0
*
TEMP = ONE / MAX( ABS1( S( JE, JE ) )*ASCALE,
$ ABS( REAL( P( JE, JE ) ) )*BSCALE, SAFMIN )
SALPHA = ( TEMP*S( JE, JE ) )*ASCALE
SBETA = ( TEMP*REAL( P( JE, JE ) ) )*BSCALE
ACOEFF = SBETA*ASCALE
BCOEFF = SALPHA*BSCALE
*
* Scale to avoid underflow
*
LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEFF ).LT.SMALL
LSB = ABS1( SALPHA ).GE.SAFMIN .AND. ABS1( BCOEFF ).LT.
$ SMALL
*
SCALE = ONE
IF( LSA )
$ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
IF( LSB )
$ SCALE = MAX( SCALE, ( SMALL / ABS1( SALPHA ) )*
$ MIN( BNORM, BIG ) )
IF( LSA .OR. LSB ) THEN
SCALE = MIN( SCALE, ONE /
$ ( SAFMIN*MAX( ONE, ABS( ACOEFF ),
$ ABS1( BCOEFF ) ) ) )
IF( LSA ) THEN
ACOEFF = ASCALE*( SCALE*SBETA )
ELSE
ACOEFF = SCALE*ACOEFF
END IF
IF( LSB ) THEN
BCOEFF = BSCALE*( SCALE*SALPHA )
ELSE
BCOEFF = SCALE*BCOEFF
END IF
END IF
*
ACOEFA = ABS( ACOEFF )
BCOEFA = ABS1( BCOEFF )
XMAX = ONE
DO 60 JR = 1, N
WORK( JR ) = CZERO
60 CONTINUE
WORK( JE ) = CONE
DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
*
* H
* Triangular solve of (a A - b B) y = 0
*
* H
* (rowwise in (a A - b B) , or columnwise in a A - b B)
*
DO 100 J = JE + 1, N
*
* Compute
* j-1
* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k)
* k=je
* (Scale if necessary)
*
TEMP = ONE / XMAX
IF( ACOEFA*RWORK( J )+BCOEFA*RWORK( N+J ).GT.BIGNUM*
$ TEMP ) THEN
DO 70 JR = JE, J - 1
WORK( JR ) = TEMP*WORK( JR )
70 CONTINUE
XMAX = ONE
END IF
SUMA = CZERO
SUMB = CZERO
*
DO 80 JR = JE, J - 1
SUMA = SUMA + CONJG( S( JR, J ) )*WORK( JR )
SUMB = SUMB + CONJG( P( JR, J ) )*WORK( JR )
80 CONTINUE
SUM = ACOEFF*SUMA - CONJG( BCOEFF )*SUMB
*
* Form x(j) = - SUM / conjg( a*S(j,j) - b*P(j,j) )
*
* with scaling and perturbation of the denominator
*
D = CONJG( ACOEFF*S( J, J )-BCOEFF*P( J, J ) )
IF( ABS1( D ).LE.DMIN )
$ D = CMPLX( DMIN )
*
IF( ABS1( D ).LT.ONE ) THEN
IF( ABS1( SUM ).GE.BIGNUM*ABS1( D ) ) THEN
TEMP = ONE / ABS1( SUM )
DO 90 JR = JE, J - 1
WORK( JR ) = TEMP*WORK( JR )
90 CONTINUE
XMAX = TEMP*XMAX
SUM = TEMP*SUM
END IF
END IF
WORK( J ) = CLADIV( -SUM, D )
XMAX = MAX( XMAX, ABS1( WORK( J ) ) )
100 CONTINUE
*
* Back transform eigenvector if HOWMNY='B'.
*
IF( ILBACK ) THEN
CALL CGEMV( 'N', N, N+1-JE, CONE, VL( 1, JE ), LDVL,
$ WORK( JE ), 1, CZERO, WORK( N+1 ), 1 )
ISRC = 2
IBEG = 1
ELSE
ISRC = 1
IBEG = JE
END IF
*
* Copy and scale eigenvector into column of VL
*
XMAX = ZERO
DO 110 JR = IBEG, N
XMAX = MAX( XMAX, ABS1( WORK( ( ISRC-1 )*N+JR ) ) )
110 CONTINUE
*
IF( XMAX.GT.SAFMIN ) THEN
TEMP = ONE / XMAX
DO 120 JR = IBEG, N
VL( JR, IEIG ) = TEMP*WORK( ( ISRC-1 )*N+JR )
120 CONTINUE
ELSE
IBEG = N + 1
END IF
*
DO 130 JR = 1, IBEG - 1
VL( JR, IEIG ) = CZERO
130 CONTINUE
*
END IF
140 CONTINUE
END IF
*
* Right eigenvectors
*
IF( COMPR ) THEN
IEIG = IM + 1
*
* Main loop over eigenvalues
*
DO 250 JE = N, 1, -1
IF( ILALL ) THEN
ILCOMP = .TRUE.
ELSE
ILCOMP = SELECT( JE )
END IF
IF( ILCOMP ) THEN
IEIG = IEIG - 1
*
IF( ABS1( S( JE, JE ) ).LE.SAFMIN .AND.
$ ABS( REAL( P( JE, JE ) ) ).LE.SAFMIN ) THEN
*
* Singular matrix pencil -- return unit eigenvector
*
DO 150 JR = 1, N
VR( JR, IEIG ) = CZERO
150 CONTINUE
VR( IEIG, IEIG ) = CONE
GO TO 250
END IF
*
* Non-singular eigenvalue:
* Compute coefficients a and b in
*
* ( a A - b B ) x = 0
*
TEMP = ONE / MAX( ABS1( S( JE, JE ) )*ASCALE,
$ ABS( REAL( P( JE, JE ) ) )*BSCALE, SAFMIN )
SALPHA = ( TEMP*S( JE, JE ) )*ASCALE
SBETA = ( TEMP*REAL( P( JE, JE ) ) )*BSCALE
ACOEFF = SBETA*ASCALE
BCOEFF = SALPHA*BSCALE
*
* Scale to avoid underflow
*
LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEFF ).LT.SMALL
LSB = ABS1( SALPHA ).GE.SAFMIN .AND. ABS1( BCOEFF ).LT.
$ SMALL
*
SCALE = ONE
IF( LSA )
$ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
IF( LSB )
$ SCALE = MAX( SCALE, ( SMALL / ABS1( SALPHA ) )*
$ MIN( BNORM, BIG ) )
IF( LSA .OR. LSB ) THEN
SCALE = MIN( SCALE, ONE /
$ ( SAFMIN*MAX( ONE, ABS( ACOEFF ),
$ ABS1( BCOEFF ) ) ) )
IF( LSA ) THEN
ACOEFF = ASCALE*( SCALE*SBETA )
ELSE
ACOEFF = SCALE*ACOEFF
END IF
IF( LSB ) THEN
BCOEFF = BSCALE*( SCALE*SALPHA )
ELSE
BCOEFF = SCALE*BCOEFF
END IF
END IF
*
ACOEFA = ABS( ACOEFF )
BCOEFA = ABS1( BCOEFF )
XMAX = ONE
DO 160 JR = 1, N
WORK( JR ) = CZERO
160 CONTINUE
WORK( JE ) = CONE
DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
*
* Triangular solve of (a A - b B) x = 0 (columnwise)
*
* WORK(1:j-1) contains sums w,
* WORK(j+1:JE) contains x
*
DO 170 JR = 1, JE - 1
WORK( JR ) = ACOEFF*S( JR, JE ) - BCOEFF*P( JR, JE )
170 CONTINUE
WORK( JE ) = CONE
*
DO 210 J = JE - 1, 1, -1
*
* Form x(j) := - w(j) / d
* with scaling and perturbation of the denominator
*
D = ACOEFF*S( J, J ) - BCOEFF*P( J, J )
IF( ABS1( D ).LE.DMIN )
$ D = CMPLX( DMIN )
*
IF( ABS1( D ).LT.ONE ) THEN
IF( ABS1( WORK( J ) ).GE.BIGNUM*ABS1( D ) ) THEN
TEMP = ONE / ABS1( WORK( J ) )
DO 180 JR = 1, JE
WORK( JR ) = TEMP*WORK( JR )
180 CONTINUE
END IF
END IF
*
WORK( J ) = CLADIV( -WORK( J ), D )
*
IF( J.GT.1 ) THEN
*
* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling
*
IF( ABS1( WORK( J ) ).GT.ONE ) THEN
TEMP = ONE / ABS1( WORK( J ) )
IF( ACOEFA*RWORK( J )+BCOEFA*RWORK( N+J ).GE.
$ BIGNUM*TEMP ) THEN
DO 190 JR = 1, JE
WORK( JR ) = TEMP*WORK( JR )
190 CONTINUE
END IF
END IF
*
CA = ACOEFF*WORK( J )
CB = BCOEFF*WORK( J )
DO 200 JR = 1, J - 1
WORK( JR ) = WORK( JR ) + CA*S( JR, J ) -
$ CB*P( JR, J )
200 CONTINUE
END IF
210 CONTINUE
*
* Back transform eigenvector if HOWMNY='B'.
*
IF( ILBACK ) THEN
CALL CGEMV( 'N', N, JE, CONE, VR, LDVR, WORK, 1,
$ CZERO, WORK( N+1 ), 1 )
ISRC = 2
IEND = N
ELSE
ISRC = 1
IEND = JE
END IF
*
* Copy and scale eigenvector into column of VR
*
XMAX = ZERO
DO 220 JR = 1, IEND
XMAX = MAX( XMAX, ABS1( WORK( ( ISRC-1 )*N+JR ) ) )
220 CONTINUE
*
IF( XMAX.GT.SAFMIN ) THEN
TEMP = ONE / XMAX
DO 230 JR = 1, IEND
VR( JR, IEIG ) = TEMP*WORK( ( ISRC-1 )*N+JR )
230 CONTINUE
ELSE
IEND = 0
END IF
*
DO 240 JR = IEND + 1, N
VR( JR, IEIG ) = CZERO
240 CONTINUE
*
END IF
250 CONTINUE
END IF
*
RETURN
*
* End of CTGEVC
*
END
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/dlartgs.f | 24 | 4220 | *> \brief \b DLARTGS generates a plane rotation designed to introduce a bulge in implicit QR iteration for the bidiagonal SVD problem.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DLARTGS + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlartgs.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlartgs.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlartgs.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DLARTGS( X, Y, SIGMA, CS, SN )
*
* .. Scalar Arguments ..
* DOUBLE PRECISION CS, SIGMA, SN, X, Y
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DLARTGS generates a plane rotation designed to introduce a bulge in
*> Golub-Reinsch-style implicit QR iteration for the bidiagonal SVD
*> problem. X and Y are the top-row entries, and SIGMA is the shift.
*> The computed CS and SN define a plane rotation satisfying
*>
*> [ CS SN ] . [ X^2 - SIGMA ] = [ R ],
*> [ -SN CS ] [ X * Y ] [ 0 ]
*>
*> with R nonnegative. If X^2 - SIGMA and X * Y are 0, then the
*> rotation is by PI/2.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] X
*> \verbatim
*> X is DOUBLE PRECISION
*> The (1,1) entry of an upper bidiagonal matrix.
*> \endverbatim
*>
*> \param[in] Y
*> \verbatim
*> Y is DOUBLE PRECISION
*> The (1,2) entry of an upper bidiagonal matrix.
*> \endverbatim
*>
*> \param[in] SIGMA
*> \verbatim
*> SIGMA is DOUBLE PRECISION
*> The shift.
*> \endverbatim
*>
*> \param[out] CS
*> \verbatim
*> CS is DOUBLE PRECISION
*> The cosine of the rotation.
*> \endverbatim
*>
*> \param[out] SN
*> \verbatim
*> SN is DOUBLE PRECISION
*> The sine of the rotation.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup auxOTHERcomputational
*
* =====================================================================
SUBROUTINE DLARTGS( X, Y, SIGMA, CS, SN )
*
* -- 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 ..
DOUBLE PRECISION CS, SIGMA, SN, X, Y
* ..
*
* ===================================================================
*
* .. Parameters ..
DOUBLE PRECISION NEGONE, ONE, ZERO
PARAMETER ( NEGONE = -1.0D0, ONE = 1.0D0, ZERO = 0.0D0 )
* ..
* .. Local Scalars ..
DOUBLE PRECISION R, S, THRESH, W, Z
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH
EXTERNAL DLAMCH
* .. Executable Statements ..
*
THRESH = DLAMCH('E')
*
* Compute the first column of B**T*B - SIGMA^2*I, up to a scale
* factor.
*
IF( (SIGMA .EQ. ZERO .AND. ABS(X) .LT. THRESH) .OR.
$ (ABS(X) .EQ. SIGMA .AND. Y .EQ. ZERO) ) THEN
Z = ZERO
W = ZERO
ELSE IF( SIGMA .EQ. ZERO ) THEN
IF( X .GE. ZERO ) THEN
Z = X
W = Y
ELSE
Z = -X
W = -Y
END IF
ELSE IF( ABS(X) .LT. THRESH ) THEN
Z = -SIGMA*SIGMA
W = ZERO
ELSE
IF( X .GE. ZERO ) THEN
S = ONE
ELSE
S = NEGONE
END IF
Z = S * (ABS(X)-SIGMA) * (S+SIGMA/X)
W = S * Y
END IF
*
* Generate the rotation.
* CALL DLARTGP( Z, W, CS, SN, R ) might seem more natural;
* reordering the arguments ensures that if Z = 0 then the rotation
* is by PI/2.
*
CALL DLARTGP( W, Z, SN, CS, R )
*
RETURN
*
* End DLARTGS
*
END
| apache-2.0 |
aamaricci/SciFortran | src/lapack/dgerqf.f | 1 | 6449 | SUBROUTINE DGERQF( M, N, A, LDA, TAU, WORK, LWORK, 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 --
*
* .. Scalar Arguments ..
INTEGER INFO, LDA, LWORK, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DGERQF computes an RQ factorization of a real M-by-N matrix A:
* A = R * Q.
*
* Arguments
* =========
*
* M (input) INTEGER
* The number of rows of the matrix A. M >= 0.
*
* N (input) INTEGER
* The number of columns of the matrix A. N >= 0.
*
* A (input/output) 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).
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,M).
*
* TAU (output) DOUBLE PRECISION array, dimension (min(M,N))
* The scalar factors of the elementary reflectors (see Further
* Details).
*
* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
* On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*
* LWORK (input) 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.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
*
* Further Details
* ===============
*
* 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).
*
* =====================================================================
*
* .. 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
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack95/SRC/la_sgelsy1.f90 | 1 | 2571 | SUBROUTINE SGELSY1_F95( A, B, RANK, JPVT, RCOND, INFO )
!
! -- LAPACK95 interface driver routine (version 3.0) --
! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK
! September, 2000
!
! .. USE STATEMENTS ..
USE LA_PRECISION, ONLY: WP => SP
USE LA_AUXMOD, ONLY: ERINFO
USE F77_LAPACK, ONLY: GELSY_F77 => LA_GELSY
! .. IMPLICIT STATEMENT ..
IMPLICIT NONE
! .. SCALAR ARGUMENTS ..
INTEGER, INTENT(OUT), OPTIONAL :: RANK
INTEGER, INTENT(OUT), OPTIONAL :: INFO
REAL(WP), INTENT(IN), OPTIONAL :: RCOND
! .. ARRAY ARGUMENTS ..
INTEGER, INTENT(INOUT), OPTIONAL, TARGET :: JPVT(:)
REAL(WP), INTENT(INOUT) :: A(:,:), B(:)
! .. PARAMETERS ..
CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_GELSY'
! .. LOCAL SCALARS ..
INTEGER :: LINFO, ISTAT, ISTAT1, LWORK, N, M, MN, LRANK, SJPVT
REAL(WP) :: LRCOND
! .. LOCAL POINTERS ..
INTEGER, POINTER :: LJPVT(:)
REAL(WP), POINTER :: WORK(:)
REAL(WP) :: WORKMIN(1)
! .. INTRINSIC FUNCTIONS ..
INTRINSIC SIZE, PRESENT, MAX, MIN, EPSILON
! .. EXECUTABLE STATEMENTS ..
LINFO = 0; ISTAT = 0; M = SIZE(A,1); N = SIZE(A,2)
MN = MIN(M,N)
IF( PRESENT(RCOND) )THEN; LRCOND = RCOND; ELSE
LRCOND = 100*EPSILON(1.0_WP) ; ENDIF
IF( PRESENT(JPVT) )THEN; SJPVT = SIZE(JPVT); ELSE; SJPVT = N; ENDIF
! .. TEST THE ARGUMENTS
IF( M < 0 .OR. N < 0 ) THEN; LINFO = -1
ELSE IF( SIZE( B ) /= MAX(1,M,N)) THEN; LINFO = -2
ELSE IF( SJPVT /= N ) THEN; LINFO = -4
ELSE IF( LRCOND <= 0.0_WP ) THEN; LINFO = -5
ELSE
IF( PRESENT(JPVT) )THEN; LJPVT => JPVT
ELSE; ALLOCATE( LJPVT(N), STAT = ISTAT ); LJPVT = 0; END IF
! .. DETERMINE THE WORKSPACE ..
! .. QUERING THE SIZE OF WORKSPACE ..
LWORK = -1
CALL GELSY_F77( M, N, 1, A, MAX(1,M), B, MAX(1,M,N), &
& LJPVT, LRCOND, LRANK, WORKMIN, LWORK, LINFO )
LWORK = WORKMIN(1)
IF( ISTAT == 0 ) THEN
ALLOCATE( WORK(LWORK), STAT = ISTAT )
IF( ISTAT /= 0 ) CALL ERINFO( -200, SRNAME, LINFO )
END IF
IF ( ISTAT == 0 ) THEN
CALL GELSY_F77( M, N, 1, A, MAX(1,M), B, MAX(1,M,N), &
& LJPVT, LRCOND, LRANK, WORK, LWORK, LINFO )
ELSE; LINFO = -100; END IF
IF( PRESENT(RANK) ) RANK = LRANK
IF( PRESENT(JPVT) ) JPVT = LJPVT
DEALLOCATE(WORK, STAT = ISTAT1 )
END IF
CALL ERINFO( LINFO, SRNAME, INFO, ISTAT )
END SUBROUTINE SGELSY1_F95
| apache-2.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/ssytri2x.f | 29 | 16006 | *> \brief \b SSYTRI2X
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SSYTRI2X + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytri2x.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytri2x.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytri2x.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE SSYTRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, INFO )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INFO, LDA, N, NB
* ..
* .. Array Arguments ..
* INTEGER IPIV( * )
* REAL A( LDA, * ), WORK( N+NB+1,* )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SSYTRI2X computes the inverse of a real symmetric indefinite matrix
*> A using the factorization A = U*D*U**T or A = L*D*L**T computed by
*> SSYTRF.
*> \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] A
*> \verbatim
*> A is REAL 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 SSYTRF.
*>
*> 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.
*> \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)
*> Details of the interchanges and the NNB structure of D
*> as determined by SSYTRF.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is REAL array, dimension (N+NNB+1,NNB+3)
*> \endverbatim
*>
*> \param[in] NB
*> \verbatim
*> NB is INTEGER
*> Block size
*> \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 realSYcomputational
*
* =====================================================================
SUBROUTINE SSYTRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, 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, N, NB
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
REAL A( LDA, * ), WORK( N+NB+1,* )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ONE, ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER I, IINFO, IP, K, CUT, NNB
INTEGER COUNT
INTEGER J, U11, INVD
REAL AK, AKKP1, AKP1, D, T
REAL U01_I_J, U01_IP1_J
REAL U11_I_J, U11_IP1_J
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL SSYCONV, XERBLA, STRTRI
EXTERNAL SGEMM, STRMM, SSYSWAPR
* ..
* .. 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( 'SSYTRI2X', -INFO )
RETURN
END IF
IF( N.EQ.0 )
$ RETURN
*
* Convert A
* Workspace got Non-diag elements of D
*
CALL SSYCONV( 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**T)*inv(D)*inv(U)*P**T.
*
CALL STRTRI( 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 / A( K, K )
WORK(K,INVD+1) = 0
K=K+1
ELSE
* 2 x 2 diagonal NNB
T = WORK(K+1,1)
AK = A( K, K ) / T
AKP1 = 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) = -AKKP1 / D
K=K+2
END IF
END DO
*
* inv(U**T) = (inv(U))**T
*
* inv(U**T)*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)=ONE
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**T*invD1*U11->U11
*
CALL STRMM('L','U','T','U',NNB, NNB,
$ ONE,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**T*invD*U01->A(CUT+I,CUT+J)
*
CALL SGEMM('T','N',NNB,NNB,CUT,ONE,A(1,CUT+1),LDA,
$ WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1)
*
* U11 = U11**T*invD1*U11 + U01**T*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**T*invD0*U01
*
CALL STRMM('L',UPLO,'T','U',CUT, NNB,
$ ONE,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**T: P * inv(U**T)*inv(D)*inv(U) *P**T
*
I=1
DO WHILE ( I .LE. N )
IF( IPIV(I) .GT. 0 ) THEN
IP=IPIV(I)
IF (I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP )
IF (I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I )
ELSE
IP=-IPIV(I)
I=I+1
IF ( (I-1) .LT. IP)
$ CALL SSYSWAPR( UPLO, N, A, LDA, I-1 ,IP )
IF ( (I-1) .GT. IP)
$ CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I-1 )
ENDIF
I=I+1
END DO
ELSE
*
* LOWER...
*
* invA = P * inv(U**T)*inv(D)*inv(U)*P**T.
*
CALL STRTRI( 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 / A( K, K )
WORK(K,INVD+1) = 0
K=K-1
ELSE
* 2 x 2 diagonal NNB
T = WORK(K-1,1)
AK = A( K-1, K-1 ) / T
AKP1 = 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) = -AKKP1 / D
K=K-2
END IF
END DO
*
* inv(U**T) = (inv(U))**T
*
* inv(U**T)*inv(D)*inv(U)
*
CUT=0
DO WHILE (CUT .LT. N)
NNB=NB
IF (CUT + NNB .GT. 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)=ONE
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**T*invD1*L11->L11
*
CALL STRMM('L',UPLO,'T','U',NNB, NNB,
$ ONE,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**T*invD2*L21->A(CUT+I,CUT+J)
*
CALL SGEMM('T','N',NNB,NNB,N-NNB-CUT,ONE,A(CUT+NNB+1,CUT+1)
$ ,LDA,WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1)
*
* L11 = L11**T*invD1*L11 + U01**T*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**T*invD2*L21
*
CALL STRMM('L',UPLO,'T','U', N-NNB-CUT, NNB,
$ ONE,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**T*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**T: P * inv(U**T)*inv(D)*inv(U) *P**T
*
I=N
DO WHILE ( I .GE. 1 )
IF( IPIV(I) .GT. 0 ) THEN
IP=IPIV(I)
IF (I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP )
IF (I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I )
ELSE
IP=-IPIV(I)
IF ( I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP )
IF ( I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I )
I=I-1
ENDIF
I=I-1
END DO
END IF
*
RETURN
*
* End of SSYTRI2X
*
END
| apache-2.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/DEPRECATED/dtzrqf.f | 24 | 6691 | *> \brief \b DTZRQF
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DTZRQF + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtzrqf.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtzrqf.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtzrqf.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DTZRQF( M, N, A, LDA, TAU, INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LDA, M, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION A( LDA, * ), TAU( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> This routine is deprecated and has been replaced by routine DTZRZF.
*>
*> DTZRQF reduces the M-by-N ( M<=N ) real upper trapezoidal matrix A
*> to upper triangular form by means of orthogonal transformations.
*>
*> The upper trapezoidal matrix A is factored as
*>
*> A = ( R 0 ) * Z,
*>
*> where Z is an N-by-N orthogonal matrix and R is an M-by-M upper
*> triangular matrix.
*> \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 >= M.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension (LDA,N)
*> On entry, the leading M-by-N upper trapezoidal part of the
*> array A must contain the matrix to be factorized.
*> On exit, the leading M-by-M upper triangular part of A
*> contains the upper triangular matrix R, and elements M+1 to
*> N of the first M rows of A, with the array TAU, represent the
*> orthogonal matrix Z as a product of M elementary reflectors.
*> \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 (M)
*> The scalar factors of the elementary reflectors.
*> \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
*>
*> The factorization is obtained by Householder's method. The kth
*> transformation matrix, Z( k ), which is used to introduce zeros into
*> the ( m - k + 1 )th row of A, is given in the form
*>
*> Z( k ) = ( I 0 ),
*> ( 0 T( k ) )
*>
*> where
*>
*> T( k ) = I - tau*u( k )*u( k )**T, u( k ) = ( 1 ),
*> ( 0 )
*> ( z( k ) )
*>
*> tau is a scalar and z( k ) is an ( n - m ) element vector.
*> tau and z( k ) are chosen to annihilate the elements of the kth row
*> of X.
*>
*> The scalar tau is returned in the kth element of TAU and the vector
*> u( k ) in the kth row of A, such that the elements of z( k ) are
*> in a( k, m + 1 ), ..., a( k, n ). The elements of R are returned in
*> the upper triangular part of A.
*>
*> Z is given by
*>
*> Z = Z( 1 ) * Z( 2 ) * ... * Z( m ).
*> \endverbatim
*>
* =====================================================================
SUBROUTINE DTZRQF( M, N, A, LDA, 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 ..
INTEGER INFO, LDA, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), TAU( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, K, M1
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. External Subroutines ..
EXTERNAL DAXPY, DCOPY, DGEMV, DGER, DLARFG, XERBLA
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( M.LT.0 ) THEN
INFO = -1
ELSE IF( N.LT.M ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
INFO = -4
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DTZRQF', -INFO )
RETURN
END IF
*
* Perform the factorization.
*
IF( M.EQ.0 )
$ RETURN
IF( M.EQ.N ) THEN
DO 10 I = 1, N
TAU( I ) = ZERO
10 CONTINUE
ELSE
M1 = MIN( M+1, N )
DO 20 K = M, 1, -1
*
* Use a Householder reflection to zero the kth row of A.
* First set up the reflection.
*
CALL DLARFG( N-M+1, A( K, K ), A( K, M1 ), LDA, TAU( K ) )
*
IF( ( TAU( K ).NE.ZERO ) .AND. ( K.GT.1 ) ) THEN
*
* We now perform the operation A := A*P( k ).
*
* Use the first ( k - 1 ) elements of TAU to store a( k ),
* where a( k ) consists of the first ( k - 1 ) elements of
* the kth column of A. Also let B denote the first
* ( k - 1 ) rows of the last ( n - m ) columns of A.
*
CALL DCOPY( K-1, A( 1, K ), 1, TAU, 1 )
*
* Form w = a( k ) + B*z( k ) in TAU.
*
CALL DGEMV( 'No transpose', K-1, N-M, ONE, A( 1, M1 ),
$ LDA, A( K, M1 ), LDA, ONE, TAU, 1 )
*
* Now form a( k ) := a( k ) - tau*w
* and B := B - tau*w*z( k )**T.
*
CALL DAXPY( K-1, -TAU( K ), TAU, 1, A( 1, K ), 1 )
CALL DGER( K-1, N-M, -TAU( K ), TAU, 1, A( K, M1 ), LDA,
$ A( 1, M1 ), LDA )
END IF
20 CONTINUE
END IF
*
RETURN
*
* End of DTZRQF
*
END
| apache-2.0 |
aamaricci/SciFortran | src/lapack/zptcon.f | 1 | 4176 | SUBROUTINE ZPTCON( N, D, E, ANORM, RCOND, RWORK, 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 --
*
* .. Scalar Arguments ..
INTEGER INFO, N
DOUBLE PRECISION ANORM, RCOND
* ..
* .. Array Arguments ..
DOUBLE PRECISION D( * ), RWORK( * )
COMPLEX*16 E( * )
* ..
*
* Purpose
* =======
*
* ZPTCON computes the reciprocal of the condition number (in the
* 1-norm) of a complex Hermitian positive definite tridiagonal matrix
* using the factorization A = L*D*L**H or A = U**H*D*U computed by
* ZPTTRF.
*
* Norm(inv(A)) is computed by a direct method, and the reciprocal of
* the condition number is computed as
* RCOND = 1 / (ANORM * norm(inv(A))).
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* D (input) DOUBLE PRECISION array, dimension (N)
* The n diagonal elements of the diagonal matrix D from the
* factorization of A, as computed by ZPTTRF.
*
* E (input) COMPLEX*16 array, dimension (N-1)
* The (n-1) off-diagonal elements of the unit bidiagonal factor
* U or L from the factorization of A, as computed by ZPTTRF.
*
* ANORM (input) DOUBLE PRECISION
* The 1-norm of the original matrix A.
*
* RCOND (output) DOUBLE PRECISION
* The reciprocal of the condition number of the matrix A,
* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is the
* 1-norm of inv(A) computed in this routine.
*
* RWORK (workspace) DOUBLE PRECISION array, dimension (N)
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
*
* Further Details
* ===============
*
* The method used is described in Nicholas J. Higham, "Efficient
* Algorithms for Computing the Condition Number of a Tridiagonal
* Matrix", SIAM J. Sci. Stat. Comput., Vol. 7, No. 1, January 1986.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, IX
DOUBLE PRECISION AINVNM
* ..
* .. External Functions ..
INTEGER IDAMAX
EXTERNAL IDAMAX
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS
* ..
* .. Executable Statements ..
*
* Test the input arguments.
*
INFO = 0
IF( N.LT.0 ) THEN
INFO = -1
ELSE IF( ANORM.LT.ZERO ) THEN
INFO = -4
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZPTCON', -INFO )
RETURN
END IF
*
* Quick return if possible
*
RCOND = ZERO
IF( N.EQ.0 ) THEN
RCOND = ONE
RETURN
ELSE IF( ANORM.EQ.ZERO ) THEN
RETURN
END IF
*
* Check that D(1:N) is positive.
*
DO 10 I = 1, N
IF( D( I ).LE.ZERO )
$ RETURN
10 CONTINUE
*
* Solve M(A) * x = e, where M(A) = (m(i,j)) is given by
*
* m(i,j) = abs(A(i,j)), i = j,
* m(i,j) = -abs(A(i,j)), i .ne. j,
*
* and e = [ 1, 1, ..., 1 ]**T. Note M(A) = M(L)*D*M(L)**H.
*
* Solve M(L) * x = e.
*
RWORK( 1 ) = ONE
DO 20 I = 2, N
RWORK( I ) = ONE + RWORK( I-1 )*ABS( E( I-1 ) )
20 CONTINUE
*
* Solve D * M(L)**H * x = b.
*
RWORK( N ) = RWORK( N ) / D( N )
DO 30 I = N - 1, 1, -1
RWORK( I ) = RWORK( I ) / D( I ) + RWORK( I+1 )*ABS( E( I ) )
30 CONTINUE
*
* Compute AINVNM = max(x(i)), 1<=i<=n.
*
IX = IDAMAX( N, RWORK, 1 )
AINVNM = ABS( RWORK( IX ) )
*
* Compute the reciprocal condition number.
*
IF( AINVNM.NE.ZERO )
$ RCOND = ( ONE / AINVNM ) / ANORM
*
RETURN
*
* End of ZPTCON
*
END
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/cgeqlf.f | 25 | 8099 | *> \brief \b CGEQLF
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CGEQLF + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeqlf.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeqlf.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeqlf.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CGEQLF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LDA, LWORK, M, N
* ..
* .. Array Arguments ..
* COMPLEX A( LDA, * ), TAU( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CGEQLF computes a QL factorization of a complex M-by-N matrix A:
*> A = Q * L.
*> \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 array, dimension (LDA,N)
*> On entry, the M-by-N matrix A.
*> On exit,
*> if m >= n, the lower triangle of the subarray
*> A(m-n+1:m,1:n) contains the N-by-N lower triangular matrix L;
*> if m <= n, the elements on and below the (n-m)-th
*> superdiagonal contain the M-by-N lower trapezoidal matrix L;
*> the remaining elements, 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 array, dimension (min(M,N))
*> The scalar factors of the elementary reflectors (see Further
*> Details).
*> \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. 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 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 complexGEcomputational
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> The matrix Q is represented as a product of elementary reflectors
*>
*> Q = H(k) . . . H(2) H(1), 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(m-k+i+1:m) = 0 and v(m-k+i) = 1; v(1:m-k+i-1) is stored on exit in
*> A(1:m-k+i-1,n-k+i), and tau in TAU(i).
*> \endverbatim
*>
* =====================================================================
SUBROUTINE CGEQLF( 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 ..
COMPLEX 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 CGEQL2, CLARFB, CLARFT, 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, 'CGEQLF', ' ', M, N, -1, -1 )
LWKOPT = N*NB
END IF
WORK( 1 ) = LWKOPT
*
IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
INFO = -7
END IF
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CGEQLF', -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 = 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, 'CGEQLF', ' ', M, N, -1, -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, 'CGEQLF', ' ', 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 columns 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 QL factorization of the current block
* A(1:m-k+i+ib-1,n-k+i:n-k+i+ib-1)
*
CALL CGEQL2( M-K+I+IB-1, IB, A( 1, N-K+I ), LDA, TAU( I ),
$ WORK, IINFO )
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 CLARFT( 'Backward', 'Columnwise', M-K+I+IB-1, IB,
$ A( 1, N-K+I ), LDA, TAU( I ), WORK, LDWORK )
*
* Apply H**H to A(1:m-k+i+ib-1,1:n-k+i-1) from the left
*
CALL CLARFB( 'Left', 'Conjugate 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
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 CGEQL2( MU, NU, A, LDA, TAU, WORK, IINFO )
*
WORK( 1 ) = IWS
RETURN
*
* End of CGEQLF
*
END
| apache-2.0 |
stanmoore1/lammps | unittest/fortran/test_fortran_extract_compute.f90 | 3 | 5261 | FUNCTION f_lammps_with_args() BIND(C)
USE ISO_C_BINDING, ONLY: c_ptr
USE liblammps
USE keepstuff, ONLY: lmp
IMPLICIT NONE
TYPE(c_ptr) :: f_lammps_with_args
CHARACTER(len=12), DIMENSION(12), PARAMETER :: args = &
[ CHARACTER(len=12) :: 'liblammps', '-log', 'none', &
'-echo','screen','-nocite','-var','zpos','1.5','-var','x','2']
lmp = lammps(args)
f_lammps_with_args = lmp%handle
END FUNCTION f_lammps_with_args
SUBROUTINE f_lammps_close() BIND(C)
USE ISO_C_BINDING, ONLY: c_null_ptr
USE liblammps
USE keepstuff, ONLY: lmp
IMPLICIT NONE
CALL lmp%close()
lmp%handle = c_null_ptr
END SUBROUTINE f_lammps_close
SUBROUTINE f_lammps_setup_extract_compute() BIND(C)
USE LIBLAMMPS
USE keepstuff, ONLY : lmp, big_input, cont_input, more_input, pair_input
IMPLICIT NONE
CALL lmp%commands_list(big_input)
CALL lmp%commands_list(cont_input)
CALL lmp%commands_list(more_input)
CALL lmp%commands_list(pair_input)
CALL lmp%command("compute peratompe all pe/atom") ! per-atom vector
call lmp%command("compute stress all stress/atom thermo_temp") ! per-atom array
CALL lmp%command("compute totalpe all reduce sum c_peratompe") ! global scalar
CALL lmp%command("compute COM all com") ! global vector
CALL lmp%command("compute RDF all rdf 100") ! global array
CALL lmp%command("compute pairdist all pair/local dist") ! local vector
CALL lmp%command("compute pairlocal all pair/local dist dx dy dz") ! local array
CALL lmp%command("thermo_style custom step pe c_totalpe c_COM[1]")
CALL lmp%command("run 0") ! must be here, otherwise will SEGFAULT
END SUBROUTINE f_lammps_setup_extract_compute
FUNCTION f_lammps_extract_compute_peratom_vector(i) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i
REAL(c_double) :: f_lammps_extract_compute_peratom_vector
REAL(c_double), DIMENSION(:), POINTER :: vector => NULL()
vector = lmp%extract_compute('peratompe', lmp%style%atom, lmp%type%vector)
f_lammps_extract_compute_peratom_vector = vector(i)
END FUNCTION f_lammps_extract_compute_peratom_vector
FUNCTION f_lammps_extract_compute_peratom_array(i,j) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i, j
REAL(c_double) :: f_lammps_extract_compute_peratom_array
REAL(c_double), DIMENSION(:,:), POINTER :: array => NULL()
array = lmp%extract_compute('stress', lmp%style%atom, lmp%type%array)
f_lammps_extract_compute_peratom_array = array(i,j)
END FUNCTION f_lammps_extract_compute_peratom_array
FUNCTION f_lammps_extract_compute_global_scalar() BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
REAL(c_double) :: f_lammps_extract_compute_global_scalar
REAL(c_double), POINTER :: scalar
scalar = lmp%extract_compute('totalpe', lmp%style%global, lmp%type%scalar)
f_lammps_extract_compute_global_scalar = scalar
END FUNCTION f_lammps_extract_compute_global_scalar
FUNCTION f_lammps_extract_compute_global_vector(i) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i
REAL(c_double) :: f_lammps_extract_compute_global_vector
REAL(c_double), DIMENSION(:), POINTER :: vector
vector = lmp%extract_compute('COM', lmp%style%global, lmp%type%vector)
f_lammps_extract_compute_global_vector = vector(i)
END FUNCTION f_lammps_extract_compute_global_vector
FUNCTION f_lammps_extract_compute_global_array(i,j) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i, j
REAL(c_double) :: f_lammps_extract_compute_global_array
REAL(c_double), DIMENSION(:,:), POINTER :: array
array = lmp%extract_compute('RDF', lmp%style%global, lmp%type%array)
f_lammps_extract_compute_global_array = array(i,j)
END FUNCTION f_lammps_extract_compute_global_array
FUNCTION f_lammps_extract_compute_local_vector(i) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i
REAL(c_double) :: f_lammps_extract_compute_local_vector
REAL(c_double), DIMENSION(:), POINTER :: vector
vector = lmp%extract_compute('pairdist', lmp%style%local, lmp%type%vector)
f_lammps_extract_compute_local_vector = vector(i)
END FUNCTION f_lammps_extract_compute_local_vector
FUNCTION f_lammps_extract_compute_local_array(i, j) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i, j
REAL(c_double) :: f_lammps_extract_compute_local_array
REAL(c_double), DIMENSION(:,:), POINTER :: array
array = lmp%extract_compute('pairlocal', lmp%style%local, lmp%type%array)
f_lammps_extract_compute_local_array = array(i,j)
END FUNCTION f_lammps_extract_compute_local_array
| gpl-2.0 |
aamaricci/SciFortran | src/arpack/src/dsaup2.f | 1 | 32235 | c-----------------------------------------------------------------------
c\BeginDoc
c
c\Name: dsaup2
c
c\Description:
c Intermediate level interface called by dsaupd.
c
c\Usage:
c call dsaup2
c ( IDO, BMAT, N, WHICH, NEV, NP, TOL, RESID, MODE, IUPD,
c ISHIFT, MXITER, V, LDV, H, LDH, RITZ, BOUNDS, Q, LDQ, WORKL,
c IPNTR, WORKD, INFO )
c
c\Arguments
c
c IDO, BMAT, N, WHICH, NEV, TOL, RESID: same as defined in dsaupd.
c MODE, ISHIFT, MXITER: see the definition of IPARAM in dsaupd.
c
c NP Integer. (INPUT/OUTPUT)
c Contains the number of implicit shifts to apply during
c each Arnoldi/Lanczos iteration.
c If ISHIFT=1, NP is adjusted dynamically at each iteration
c to accelerate convergence and prevent stagnation.
c This is also roughly equal to the number of matrix-vector
c products (involving the operator OP) per Arnoldi iteration.
c The logic for adjusting is contained within the current
c subroutine.
c If ISHIFT=0, NP is the number of shifts the user needs
c to provide via reverse communication. 0 < NP < NCV-NEV.
c NP may be less than NCV-NEV since a leading block of the current
c upper Tridiagonal matrix has split off and contains "unwanted"
c Ritz values.
c Upon termination of the IRA iteration, NP contains the number
c of "converged" wanted Ritz values.
c
c IUPD Integer. (INPUT)
c IUPD .EQ. 0: use explicit restart instead implicit update.
c IUPD .NE. 0: use implicit update.
c
c V Double precision N by (NEV+NP) array. (INPUT/OUTPUT)
c The Lanczos basis vectors.
c
c LDV Integer. (INPUT)
c Leading dimension of V exactly as declared in the calling
c program.
c
c H Double precision (NEV+NP) by 2 array. (OUTPUT)
c H is used to store the generated symmetric tridiagonal matrix
c The subdiagonal is stored in the first column of H starting
c at H(2,1). The main diagonal is stored in the arscnd column
c of H starting at H(1,2). If dsaup2 converges store the
c B-norm of the final residual vector in H(1,1).
c
c LDH Integer. (INPUT)
c Leading dimension of H exactly as declared in the calling
c program.
c
c RITZ Double precision array of length NEV+NP. (OUTPUT)
c RITZ(1:NEV) contains the computed Ritz values of OP.
c
c BOUNDS Double precision array of length NEV+NP. (OUTPUT)
c BOUNDS(1:NEV) contain the error bounds corresponding to RITZ.
c
c Q Double precision (NEV+NP) by (NEV+NP) array. (WORKSPACE)
c Private (replicated) work array used to accumulate the
c rotation in the shift application step.
c
c LDQ Integer. (INPUT)
c Leading dimension of Q exactly as declared in the calling
c program.
c
c WORKL Double precision array of length at least 3*(NEV+NP). (INPUT/WORKSPACE)
c Private (replicated) array on each PE or array allocated on
c the front end. It is used in the computation of the
c tridiagonal eigenvalue problem, the calculation and
c application of the shifts and convergence checking.
c If ISHIFT .EQ. O and IDO .EQ. 3, the first NP locations
c of WORKL are used in reverse communication to hold the user
c supplied shifts.
c
c IPNTR Integer array of length 3. (OUTPUT)
c Pointer to mark the starting locations in the WORKD for
c vectors used by the Lanczos 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 one of
c the spectral transformation modes. X is the current
c operand.
c -------------------------------------------------------------
c
c WORKD Double precision work array of length 3*N. (REVERSE COMMUNICATION)
c Distributed array to be used in the basic Lanczos iteration
c for reverse communication. The user should not use WORKD
c as temporary workspace during the iteration !!!!!!!!!!
c See Data Distribution Note in dsaupd.
c
c INFO Integer. (INPUT/OUTPUT)
c If INFO .EQ. 0, a randomly initial residual vector is used.
c If INFO .NE. 0, RESID contains the initial residual vector,
c possibly from a previous run.
c Error flag on output.
c = 0: Normal return.
c = 1: All possible eigenvalues of OP has been found.
c NP returns the size of the invariant subspace
c spanning the operator OP.
c = 2: No shifts could be applied.
c = -8: Error return from trid. eigenvalue calculation;
c This should never happen.
c = -9: Starting vector is zero.
c = -9999: Could not build an Lanczos factorization.
c Size that was built in returned in NP.
c
c\EndDoc
c
c-----------------------------------------------------------------------
c
c\BeginLib
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 3. B.N. Parlett, "The Symmetric Eigenvalue Problem". Prentice-Hall,
c 1980.
c 4. B.N. Parlett, B. Nour-Omid, "Towards a Black Box Lanczos Program",
c Computer Physics Communications, 53 (1989), pp 169-179.
c 5. B. Nour-Omid, B.N. Parlett, T. Ericson, P.S. Jensen, "How to
c Implement the Spectral Transformation", Math. Comp., 48 (1987),
c pp 663-673.
c 6. R.G. Grimes, J.G. Lewis and H.D. Simon, "A Shifted Block Lanczos
c Algorithm for Solving Sparse Symmetric Generalized Eigenproblems",
c SIAM J. Matr. Anal. Apps., January (1993).
c 7. L. Reichel, W.B. Gragg, "Algorithm 686: FORTRAN Subroutines
c for Updating the QR decomposition", ACM TOMS, December 1990,
c Volume 16 Number 4, pp 369-377.
c
c\Routines called:
c dgetv0 ARPACK initial vector generation routine.
c dsaitr ARPACK Lanczos factorization routine.
c dsapps ARPACK application of implicit shifts routine.
c dsconv ARPACK convergence of Ritz values routine.
c dseigt ARPACK compute Ritz values and error bounds routine.
c dsgets ARPACK reorder Ritz values and error bounds routine.
c dsortr ARPACK sorting routine.
c ivout ARPACK utility routine that prints integers.
c arscnd ARPACK utility routine for timing.
c dvout ARPACK utility routine that prints vectors.
c dlamch LAPACK routine that determines machine constants.
c dcopy Level 1 BLAS that copies one vector to another.
c ddot Level 1 BLAS that computes the scalar product of two vectors.
c dnrm2 Level 1 BLAS that computes the norm of a vector.
c dscal Level 1 BLAS that scales a vector.
c dswap Level 1 BLAS that swaps two vectors.
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\Revision history:
c 12/15/93: Version ' 2.4'
c xx/xx/95: Version ' 2.4'. (R.B. Lehoucq)
c
c\SCCS Information: @(#)
c FILE: saup2.F SID: 2.7 DATE OF SID: 5/19/98 RELEASE: 2
c
c\EndLib
c
c-----------------------------------------------------------------------
c
subroutine dsaup2
& ( ido, bmat, n, which, nev, np, tol, resid, mode, iupd,
& ishift, mxiter, v, ldv, h, ldh, ritz, bounds,
& q, ldq, workl, 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, which*2
integer ido, info, ishift, iupd, ldh, ldq, ldv, mxiter,
& n, mode, nev, np
Double precision
& tol
c
c %-----------------%
c | Array Arguments |
c %-----------------%
c
integer ipntr(3)
Double precision
& bounds(nev+np), h(ldh,2), q(ldq,nev+np), resid(n),
& ritz(nev+np), v(ldv,nev+np), workd(3*n),
& workl(3*(nev+np))
c
c %------------%
c | Parameters |
c %------------%
c
Double precision
& one, zero
parameter (one = 1.0D+0, zero = 0.0D+0)
c
c %---------------%
c | Local Scalars |
c %---------------%
c
character wprime*2
logical cnorm, getv0, initv, update, ushift
integer ierr, iter, j, kplusp, msglvl, nconv, nevbef, nev0,
& np0, nptemp, nevd2, nevm2, kp(3)
Double precision
& rnorm, temp, eps23
save cnorm, getv0, initv, update, ushift,
& iter, kplusp, msglvl, nconv, nev0, np0,
& rnorm, eps23
c
c %----------------------%
c | External Subroutines |
c %----------------------%
c
external dcopy, dgetv0, dsaitr, dscal, dsconv, dseigt, dsgets,
& dsapps, dsortr, dvout, ivout, arscnd, dswap
c
c %--------------------%
c | External Functions |
c %--------------------%
c
Double precision
& ddot, dnrm2, dlamch
external ddot, dnrm2, dlamch
c
c %---------------------%
c | Intrinsic Functions |
c %---------------------%
c
intrinsic min
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
c
if (ido .eq. 0) then
c
c %-------------------------------%
c | Initialize timing statistics |
c | & message level for debugging |
c %-------------------------------%
c
call arscnd (t0)
msglvl = msaup2
c
c %---------------------------------%
c | Set machine dependent constant. |
c %---------------------------------%
c
eps23 = dlamch('Epsilon-Machine')
eps23 = eps23**(2.0D+0/3.0D+0)
c
c %-------------------------------------%
c | nev0 and np0 are integer variables |
c | hold the initial values of NEV & NP |
c %-------------------------------------%
c
nev0 = nev
np0 = np
c
c %-------------------------------------%
c | kplusp is the bound on the largest |
c | Lanczos factorization built. |
c | nconv is the current number of |
c | "converged" eigenvlues. |
c | iter is the counter on the current |
c | iteration step. |
c %-------------------------------------%
c
kplusp = nev0 + np0
nconv = 0
iter = 0
c
c %--------------------------------------------%
c | Set flags for computing the first NEV steps |
c | of the Lanczos factorization. |
c %--------------------------------------------%
c
getv0 = .true.
update = .false.
ushift = .false.
cnorm = .false.
c
if (info .ne. 0) then
c
c %--------------------------------------------%
c | User provides the initial residual vector. |
c %--------------------------------------------%
c
initv = .true.
info = 0
else
initv = .false.
end if
end if
c
c %---------------------------------------------%
c | Get a possibly random starting vector and |
c | force it into the range of the operator OP. |
c %---------------------------------------------%
c
10 continue
c
if (getv0) then
call dgetv0 (ido, bmat, 1, initv, n, 1, v, ldv, resid, rnorm,
& ipntr, workd, info)
c
if (ido .ne. 99) go to 9000
c
if (rnorm .eq. zero) then
c
c %-----------------------------------------%
c | The initial vector is zero. Error exit. |
c %-----------------------------------------%
c
info = -9
go to 1200
end if
getv0 = .false.
ido = 0
end if
c
c %------------------------------------------------------------%
c | Back from reverse communication: continue with update step |
c %------------------------------------------------------------%
c
if (update) go to 20
c
c %-------------------------------------------%
c | Back from computing user specified shifts |
c %-------------------------------------------%
c
if (ushift) go to 50
c
c %-------------------------------------%
c | Back from computing residual norm |
c | at the end of the current iteration |
c %-------------------------------------%
c
if (cnorm) go to 100
c
c %----------------------------------------------------------%
c | Compute the first NEV steps of the Lanczos factorization |
c %----------------------------------------------------------%
c
call dsaitr (ido, bmat, n, 0, nev0, mode, resid, rnorm, v, ldv,
& h, ldh, ipntr, workd, info)
c
c %---------------------------------------------------%
c | ido .ne. 99 implies use of reverse communication |
c | to compute operations involving OP and possibly B |
c %---------------------------------------------------%
c
if (ido .ne. 99) go to 9000
c
if (info .gt. 0) then
c
c %-----------------------------------------------------%
c | dsaitr was unable to build an Lanczos factorization |
c | of length NEV0. INFO is returned with the size of |
c | the factorization built. Exit main loop. |
c %-----------------------------------------------------%
c
np = info
mxiter = iter
info = -9999
go to 1200
end if
c
c %--------------------------------------------------------------%
c | |
c | M A I N LANCZOS I T E R A T I O N L O O P |
c | Each iteration implicitly restarts the Lanczos |
c | factorization in place. |
c | |
c %--------------------------------------------------------------%
c
1000 continue
c
iter = iter + 1
c
if (msglvl .gt. 0) then
call ivout (logfil, 1, iter, ndigit,
& '_saup2: **** Start of major iteration number ****')
end if
if (msglvl .gt. 1) then
call ivout (logfil, 1, nev, ndigit,
& '_saup2: The length of the current Lanczos factorization')
call ivout (logfil, 1, np, ndigit,
& '_saup2: Extend the Lanczos factorization by')
end if
c
c %------------------------------------------------------------%
c | Compute NP additional steps of the Lanczos factorization. |
c %------------------------------------------------------------%
c
ido = 0
20 continue
update = .true.
c
call dsaitr (ido, bmat, n, nev, np, mode, resid, rnorm, v,
& ldv, h, ldh, ipntr, workd, info)
c
c %---------------------------------------------------%
c | ido .ne. 99 implies use of reverse communication |
c | to compute operations involving OP and possibly B |
c %---------------------------------------------------%
c
if (ido .ne. 99) go to 9000
c
if (info .gt. 0) then
c
c %-----------------------------------------------------%
c | dsaitr was unable to build an Lanczos factorization |
c | of length NEV0+NP0. INFO is returned with the size |
c | of the factorization built. Exit main loop. |
c %-----------------------------------------------------%
c
np = info
mxiter = iter
info = -9999
go to 1200
end if
update = .false.
c
if (msglvl .gt. 1) then
call dvout (logfil, 1, rnorm, ndigit,
& '_saup2: Current B-norm of residual for factorization')
end if
c
c %--------------------------------------------------------%
c | Compute the eigenvalues and corresponding error bounds |
c | of the current symmetric tridiagonal matrix. |
c %--------------------------------------------------------%
c
call dseigt (rnorm, kplusp, h, ldh, ritz, bounds, workl, ierr)
c
if (ierr .ne. 0) then
info = -8
go to 1200
end if
c
c %----------------------------------------------------%
c | Make a copy of eigenvalues and corresponding error |
c | bounds obtained from _seigt. |
c %----------------------------------------------------%
c
call dcopy(kplusp, ritz, 1, workl(kplusp+1), 1)
call dcopy(kplusp, bounds, 1, workl(2*kplusp+1), 1)
c
c %---------------------------------------------------%
c | Select the wanted Ritz values and their bounds |
c | to be used in the convergence test. |
c | The selection is based on the requested number of |
c | eigenvalues instead of the current NEV and NP to |
c | prevent possible misconvergence. |
c | * Wanted Ritz values := RITZ(NP+1:NEV+NP) |
c | * Shifts := RITZ(1:NP) := WORKL(1:NP) |
c %---------------------------------------------------%
c
nev = nev0
np = np0
call dsgets (ishift, which, nev, np, ritz, bounds, workl)
c
c %-------------------%
c | Convergence test. |
c %-------------------%
c
call dcopy (nev, bounds(np+1), 1, workl(np+1), 1)
call dsconv (nev, ritz(np+1), workl(np+1), tol, nconv)
c
if (msglvl .gt. 2) then
kp(1) = nev
kp(2) = np
kp(3) = nconv
call ivout (logfil, 3, kp, ndigit,
& '_saup2: NEV, NP, NCONV are')
call dvout (logfil, kplusp, ritz, ndigit,
& '_saup2: The eigenvalues of H')
call dvout (logfil, kplusp, bounds, ndigit,
& '_saup2: Ritz estimates of the current NCV Ritz values')
end if
c
c %---------------------------------------------------------%
c | Count the number of unwanted Ritz values that have zero |
c | Ritz estimates. If any Ritz estimates are equal to zero |
c | then a leading block of H of order equal to at least |
c | the number of Ritz values with zero Ritz estimates has |
c | split off. None of these Ritz values may be removed by |
c | shifting. Decrease NP the number of shifts to apply. If |
c | no shifts may be applied, then prepare to exit |
c %---------------------------------------------------------%
c
nptemp = np
do 30 j=1, nptemp
if (bounds(j) .eq. zero) then
np = np - 1
nev = nev + 1
end if
30 continue
c
if ( (nconv .ge. nev0) .or.
& (iter .gt. mxiter) .or.
& (np .eq. 0) ) then
c
c %------------------------------------------------%
c | Prepare to exit. Put the converged Ritz values |
c | and corresponding bounds in RITZ(1:NCONV) and |
c | BOUNDS(1:NCONV) respectively. Then sort. Be |
c | careful when NCONV > NP since we don't want to |
c | swap overlapping locations. |
c %------------------------------------------------%
c
if (which .eq. 'BE') then
c
c %-----------------------------------------------------%
c | Both ends of the spectrum are requested. |
c | Sort the eigenvalues into algebraically decreasing |
c | order first then swap low end of the spectrum next |
c | to high end in appropriate locations. |
c | NOTE: when np < floor(nev/2) be careful not to swap |
c | overlapping locations. |
c %-----------------------------------------------------%
c
wprime = 'SA'
call dsortr (wprime, .true., kplusp, ritz, bounds)
nevd2 = nev0 / 2
nevm2 = nev0 - nevd2
if ( nev .gt. 1 ) then
np = kplusp - nev0
call dswap ( min(nevd2,np), ritz(nevm2+1), 1,
& ritz( max(kplusp-nevd2+1,kplusp-np+1) ), 1)
call dswap ( min(nevd2,np), bounds(nevm2+1), 1,
& bounds( max(kplusp-nevd2+1,kplusp-np+1)), 1)
end if
c
else
c
c %--------------------------------------------------%
c | LM, SM, LA, SA case. |
c | Sort the eigenvalues of H into the an order that |
c | is opposite to WHICH, and apply the resulting |
c | order to BOUNDS. The eigenvalues are sorted so |
c | that the wanted part are always within the first |
c | NEV locations. |
c %--------------------------------------------------%
c
if (which .eq. 'LM') wprime = 'SM'
if (which .eq. 'SM') wprime = 'LM'
if (which .eq. 'LA') wprime = 'SA'
if (which .eq. 'SA') wprime = 'LA'
c
call dsortr (wprime, .true., kplusp, ritz, bounds)
c
end if
c
c %--------------------------------------------------%
c | Scale the Ritz estimate of each Ritz value |
c | by 1 / max(eps23,magnitude of the Ritz value). |
c %--------------------------------------------------%
c
do 35 j = 1, nev0
temp = max( eps23, abs(ritz(j)) )
bounds(j) = bounds(j)/temp
35 continue
c
c %----------------------------------------------------%
c | Sort the Ritz values according to the scaled Ritz |
c | esitmates. This will push all the converged ones |
c | towards the front of ritzr, ritzi, bounds |
c | (in the case when NCONV < NEV.) |
c %----------------------------------------------------%
c
wprime = 'LA'
call dsortr(wprime, .true., nev0, bounds, ritz)
c
c %----------------------------------------------%
c | Scale the Ritz estimate back to its original |
c | value. |
c %----------------------------------------------%
c
do 40 j = 1, nev0
temp = max( eps23, abs(ritz(j)) )
bounds(j) = bounds(j)*temp
40 continue
c
c %--------------------------------------------------%
c | Sort the "converged" Ritz values again so that |
c | the "threshold" values and their associated Ritz |
c | estimates appear at the appropriate position in |
c | ritz and bound. |
c %--------------------------------------------------%
c
if (which .eq. 'BE') then
c
c %------------------------------------------------%
c | Sort the "converged" Ritz values in increasing |
c | order. The "threshold" values are in the |
c | middle. |
c %------------------------------------------------%
c
wprime = 'LA'
call dsortr(wprime, .true., nconv, ritz, bounds)
c
else
c
c %----------------------------------------------%
c | In LM, SM, LA, SA case, sort the "converged" |
c | Ritz values according to WHICH so that the |
c | "threshold" value appears at the front of |
c | ritz. |
c %----------------------------------------------%
call dsortr(which, .true., nconv, ritz, bounds)
c
end if
c
c %------------------------------------------%
c | Use h( 1,1 ) as storage to communicate |
c | rnorm to _seupd if needed |
c %------------------------------------------%
c
h(1,1) = rnorm
c
if (msglvl .gt. 1) then
call dvout (logfil, kplusp, ritz, ndigit,
& '_saup2: Sorted Ritz values.')
call dvout (logfil, kplusp, bounds, ndigit,
& '_saup2: Sorted ritz estimates.')
end if
c
c %------------------------------------%
c | Max iterations have been exceeded. |
c %------------------------------------%
c
if (iter .gt. mxiter .and. nconv .lt. nev) info = 1
c
c %---------------------%
c | No shifts to apply. |
c %---------------------%
c
if (np .eq. 0 .and. nconv .lt. nev0) info = 2
c
np = nconv
go to 1100
c
else if (nconv .lt. nev .and. ishift .eq. 1) then
c
c %---------------------------------------------------%
c | Do not have all the requested eigenvalues yet. |
c | To prevent possible stagnation, adjust the number |
c | of Ritz values and the shifts. |
c %---------------------------------------------------%
c
nevbef = nev
nev = nev + min (nconv, np/2)
if (nev .eq. 1 .and. kplusp .ge. 6) then
nev = kplusp / 2
else if (nev .eq. 1 .and. kplusp .gt. 2) then
nev = 2
end if
np = kplusp - nev
c
c %---------------------------------------%
c | If the size of NEV was just increased |
c | resort the eigenvalues. |
c %---------------------------------------%
c
if (nevbef .lt. nev)
& call dsgets (ishift, which, nev, np, ritz, bounds,
& workl)
c
end if
c
if (msglvl .gt. 0) then
call ivout (logfil, 1, nconv, ndigit,
& '_saup2: no. of "converged" Ritz values at this iter.')
if (msglvl .gt. 1) then
kp(1) = nev
kp(2) = np
call ivout (logfil, 2, kp, ndigit,
& '_saup2: NEV and NP are')
call dvout (logfil, nev, ritz(np+1), ndigit,
& '_saup2: "wanted" Ritz values.')
call dvout (logfil, nev, bounds(np+1), ndigit,
& '_saup2: Ritz estimates of the "wanted" values ')
end if
end if
c
if (ishift .eq. 0) then
c
c %-----------------------------------------------------%
c | User specified shifts: reverse communication to |
c | compute the shifts. They are returned in the first |
c | NP locations of WORKL. |
c %-----------------------------------------------------%
c
ushift = .true.
ido = 3
go to 9000
end if
c
50 continue
c
c %------------------------------------%
c | Back from reverse communication; |
c | User specified shifts are returned |
c | in WORKL(1:*NP) |
c %------------------------------------%
c
ushift = .false.
c
c
c %---------------------------------------------------------%
c | Move the NP shifts to the first NP locations of RITZ to |
c | free up WORKL. This is for the non-exact shift case; |
c | in the exact shift case, dsgets already handles this. |
c %---------------------------------------------------------%
c
if (ishift .eq. 0) call dcopy (np, workl, 1, ritz, 1)
c
if (msglvl .gt. 2) then
call ivout (logfil, 1, np, ndigit,
& '_saup2: The number of shifts to apply ')
call dvout (logfil, np, workl, ndigit,
& '_saup2: shifts selected')
if (ishift .eq. 1) then
call dvout (logfil, np, bounds, ndigit,
& '_saup2: corresponding Ritz estimates')
end if
end if
c
c %---------------------------------------------------------%
c | Apply the NP0 implicit shifts by QR bulge chasing. |
c | Each shift is applied to the entire tridiagonal matrix. |
c | The first 2*N locations of WORKD are used as workspace. |
c | After dsapps is done, we have a Lanczos |
c | factorization of length NEV. |
c %---------------------------------------------------------%
c
call dsapps (n, nev, np, ritz, v, ldv, h, ldh, resid, q, ldq,
& workd)
c
c %---------------------------------------------%
c | Compute the B-norm of the updated residual. |
c | Keep B*RESID in WORKD(1:N) to be used in |
c | the first step of the next call to dsaitr. |
c %---------------------------------------------%
c
cnorm = .true.
call arscnd (t2)
if (bmat .eq. 'G') then
nbx = nbx + 1
call dcopy (n, resid, 1, workd(n+1), 1)
ipntr(1) = n + 1
ipntr(2) = 1
ido = 2
c
c %----------------------------------%
c | Exit in order to compute B*RESID |
c %----------------------------------%
c
go to 9000
else if (bmat .eq. 'I') then
call dcopy (n, resid, 1, workd, 1)
end if
c
100 continue
c
c %----------------------------------%
c | Back from reverse communication; |
c | WORKD(1:N) := B*RESID |
c %----------------------------------%
c
if (bmat .eq. 'G') then
call arscnd (t3)
tmvbx = tmvbx + (t3 - t2)
end if
c
if (bmat .eq. 'G') then
rnorm = ddot (n, resid, 1, workd, 1)
rnorm = sqrt(abs(rnorm))
else if (bmat .eq. 'I') then
rnorm = dnrm2(n, resid, 1)
end if
cnorm = .false.
130 continue
c
if (msglvl .gt. 2) then
call dvout (logfil, 1, rnorm, ndigit,
& '_saup2: B-norm of residual for NEV factorization')
call dvout (logfil, nev, h(1,2), ndigit,
& '_saup2: main diagonal of compressed H matrix')
call dvout (logfil, nev-1, h(2,1), ndigit,
& '_saup2: subdiagonal of compressed H matrix')
end if
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
1100 continue
c
mxiter = iter
nev = nconv
c
1200 continue
ido = 99
c
c %------------%
c | Error exit |
c %------------%
c
call arscnd (t1)
tsaup2 = t1 - t0
c
9000 continue
return
c
c %---------------%
c | End of dsaup2 |
c %---------------%
c
end
| lgpl-3.0 |
OpenDA-Association/OpenDA | core/native/external/lapack/dlarrb.f | 4 | 8656 | SUBROUTINE DLARRB( N, D, L, LD, LLD, IFIRST, ILAST, SIGMA, RELTOL,
$ W, WGAP, WERR, WORK, IWORK, 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 ..
INTEGER IFIRST, ILAST, INFO, N
DOUBLE PRECISION RELTOL, SIGMA
* ..
* .. Array Arguments ..
INTEGER IWORK( * )
DOUBLE PRECISION D( * ), L( * ), LD( * ), LLD( * ), W( * ),
$ WERR( * ), WGAP( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* Given the relatively robust representation(RRR) L D L^T, DLARRB
* does ``limited'' bisection to locate the eigenvalues of L D L^T,
* W( IFIRST ) thru' W( ILAST ), to more accuracy. Intervals
* [left, right] are maintained by storing their mid-points and
* semi-widths in the arrays W and WERR respectively.
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix.
*
* D (input) DOUBLE PRECISION array, dimension (N)
* The n diagonal elements of the diagonal matrix D.
*
* L (input) DOUBLE PRECISION array, dimension (N-1)
* The n-1 subdiagonal elements of the unit bidiagonal matrix L.
*
* LD (input) DOUBLE PRECISION array, dimension (N-1)
* The n-1 elements L(i)*D(i).
*
* LLD (input) DOUBLE PRECISION array, dimension (N-1)
* The n-1 elements L(i)*L(i)*D(i).
*
* IFIRST (input) INTEGER
* The index of the first eigenvalue in the cluster.
*
* ILAST (input) INTEGER
* The index of the last eigenvalue in the cluster.
*
* SIGMA (input) DOUBLE PRECISION
* The shift used to form L D L^T (see DLARRF).
*
* RELTOL (input) DOUBLE PRECISION
* The relative tolerance.
*
* W (input/output) DOUBLE PRECISION array, dimension (N)
* On input, W( IFIRST ) thru' W( ILAST ) are estimates of the
* corresponding eigenvalues of L D L^T.
* On output, these estimates are ``refined''.
*
* WGAP (input/output) DOUBLE PRECISION array, dimension (N)
* The gaps between the eigenvalues of L D L^T. Very small
* gaps are changed on output.
*
* WERR (input/output) DOUBLE PRECISION array, dimension (N)
* On input, WERR( IFIRST ) thru' WERR( ILAST ) are the errors
* in the estimates W( IFIRST ) thru' W( ILAST ).
* On output, these are the ``refined'' errors.
*
*****Reminder to Inder --- WORK is never used in this subroutine *****
* WORK (input) DOUBLE PRECISION array, dimension (???)
* Workspace.
*
* IWORK (input) INTEGER array, dimension (2*N)
* Workspace.
*
*****Reminder to Inder --- INFO is never set in this subroutine ******
* INFO (output) INTEGER
* Error flag.
*
* Further Details
* ===============
*
* Based on contributions by
* Inderjit Dhillon, IBM Almaden, USA
* Osni Marques, LBNL/NERSC, USA
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, TWO, HALF
PARAMETER ( ZERO = 0.0D0, TWO = 2.0D0, HALF = 0.5D0 )
* ..
* .. Local Scalars ..
INTEGER CNT, I, I1, I2, INITI1, INITI2, J, K, NCNVRG,
$ NEIG, NINT, NRIGHT, OLNINT
DOUBLE PRECISION DELTA, EPS, GAP, LEFT, MID, PERT, RIGHT, S,
$ THRESH, TMP, WIDTH
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH
EXTERNAL DLAMCH
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, MIN
* ..
* .. Executable Statements ..
*
EPS = DLAMCH( 'Precision' )
I1 = IFIRST
I2 = IFIRST
NEIG = ILAST - IFIRST + 1
NCNVRG = 0
THRESH = RELTOL
DO 10 I = IFIRST, ILAST
IWORK( I ) = 0
PERT = EPS*( ABS( SIGMA )+ABS( W( I ) ) )
WERR( I ) = WERR( I ) + PERT
IF( WGAP( I ).LT.PERT )
$ WGAP( I ) = PERT
10 CONTINUE
DO 20 I = I1, ILAST
IF( I.EQ.1 ) THEN
GAP = WGAP( I )
ELSE IF( I.EQ.N ) THEN
GAP = WGAP( I-1 )
ELSE
GAP = MIN( WGAP( I-1 ), WGAP( I ) )
END IF
IF( WERR( I ).LT.THRESH*GAP ) THEN
NCNVRG = NCNVRG + 1
IWORK( I ) = 1
IF( I1.EQ.I )
$ I1 = I1 + 1
ELSE
I2 = I
END IF
20 CONTINUE
*
* Initialize the unconverged intervals.
*
I = I1
NINT = 0
RIGHT = ZERO
30 CONTINUE
IF( I.LE.I2 ) THEN
IF( IWORK( I ).EQ.0 ) THEN
DELTA = EPS
LEFT = W( I ) - WERR( I )
*
* Do while( CNT(LEFT).GT.I-1 )
*
40 CONTINUE
IF( I.GT.I1 .AND. LEFT.LE.RIGHT ) THEN
LEFT = RIGHT
CNT = I - 1
ELSE
S = -LEFT
CNT = 0
DO 50 J = 1, N - 1
TMP = D( J ) + S
S = S*( LD( J ) / TMP )*L( J ) - LEFT
IF( TMP.LT.ZERO )
$ CNT = CNT + 1
50 CONTINUE
TMP = D( N ) + S
IF( TMP.LT.ZERO )
$ CNT = CNT + 1
IF( CNT.GT.I-1 ) THEN
DELTA = TWO*DELTA
LEFT = LEFT - ( ABS( SIGMA )+ABS( LEFT ) )*DELTA
GO TO 40
END IF
END IF
DELTA = EPS
RIGHT = W( I ) + WERR( I )
*
* Do while( CNT(RIGHT).LT.I )
*
60 CONTINUE
S = -RIGHT
CNT = 0
DO 70 J = 1, N - 1
TMP = D( J ) + S
S = S*( LD( J ) / TMP )*L( J ) - RIGHT
IF( TMP.LT.ZERO )
$ CNT = CNT + 1
70 CONTINUE
TMP = D( N ) + S
IF( TMP.LT.ZERO )
$ CNT = CNT + 1
IF( CNT.LT.I ) THEN
DELTA = TWO*DELTA
RIGHT = RIGHT + ( ABS( SIGMA )+ABS( RIGHT ) )*DELTA
GO TO 60
END IF
WERR( I ) = LEFT
W( I ) = RIGHT
IWORK( N+I ) = CNT
NINT = NINT + 1
I = CNT + 1
ELSE
I = I + 1
END IF
GO TO 30
END IF
*
* While( NCNVRG.LT.NEIG )
*
INITI1 = I1
INITI2 = I2
80 CONTINUE
IF( NCNVRG.LT.NEIG ) THEN
OLNINT = NINT
I = I1
DO 100 K = 1, OLNINT
NRIGHT = IWORK( N+I )
IF( IWORK( I ).EQ.0 ) THEN
MID = HALF*( WERR( I )+W( I ) )
S = -MID
CNT = 0
DO 90 J = 1, N - 1
TMP = D( J ) + S
S = S*( LD( J ) / TMP )*L( J ) - MID
IF( TMP.LT.ZERO )
$ CNT = CNT + 1
90 CONTINUE
TMP = D( N ) + S
IF( TMP.LT.ZERO )
$ CNT = CNT + 1
CNT = MAX( I-1, MIN( NRIGHT, CNT ) )
IF( I.EQ.NRIGHT ) THEN
IF( I.EQ.IFIRST ) THEN
GAP = WERR( I+1 ) - W( I )
ELSE IF( I.EQ.ILAST ) THEN
GAP = WERR( I ) - W( I-1 )
ELSE
GAP = MIN( WERR( I+1 )-W( I ), WERR( I )-W( I-1 ) )
END IF
WIDTH = W( I ) - MID
IF( WIDTH.LT.THRESH*GAP ) THEN
NCNVRG = NCNVRG + 1
IWORK( I ) = 1
IF( I1.EQ.I ) THEN
I1 = I1 + 1
NINT = NINT - 1
END IF
END IF
END IF
IF( IWORK( I ).EQ.0 )
$ I2 = K
IF( CNT.EQ.I-1 ) THEN
WERR( I ) = MID
ELSE IF( CNT.EQ.NRIGHT ) THEN
W( I ) = MID
ELSE
IWORK( N+I ) = CNT
NINT = NINT + 1
WERR( CNT+1 ) = MID
W( CNT+1 ) = W( I )
W( I ) = MID
I = CNT + 1
IWORK( N+I ) = NRIGHT
END IF
END IF
I = NRIGHT + 1
100 CONTINUE
NINT = NINT - OLNINT + I2
GO TO 80
END IF
DO 110 I = INITI1, INITI2
W( I ) = HALF*( WERR( I )+W( I ) )
WERR( I ) = W( I ) - WERR( I )
110 CONTINUE
*
RETURN
*
* End of DLARRB
*
END
| lgpl-3.0 |
aamaricci/SciFortran | src/arpack/src/zsortc.f | 1 | 8075 | c\BeginDoc
c
c\Name: zsortc
c
c\Description:
c Sorts the Complex*16 array in X into the order
c specified by WHICH and optionally applies the permutation to the
c Double precision array Y.
c
c\Usage:
c call zsortc
c ( WHICH, APPLY, N, X, Y )
c
c\Arguments
c WHICH Character*2. (Input)
c 'LM' -> sort X into increasing order of magnitude.
c 'SM' -> sort X into decreasing order of magnitude.
c 'LR' -> sort X with real(X) in increasing algebraic order
c 'SR' -> sort X with real(X) in decreasing algebraic order
c 'LI' -> sort X with imag(X) in increasing algebraic order
c 'SI' -> sort X with imag(X) in decreasing algebraic order
c
c APPLY Logical. (Input)
c APPLY = .TRUE. -> apply the sorted order to array Y.
c APPLY = .FALSE. -> do not apply the sorted order to array Y.
c
c N Integer. (INPUT)
c Size of the arrays.
c
c X Complex*16 array of length N. (INPUT/OUTPUT)
c This is the array to be sorted.
c
c Y Complex*16 array of length N. (INPUT/OUTPUT)
c
c\EndDoc
c
c-----------------------------------------------------------------------
c
c\BeginLib
c
c\Routines called:
c dlapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully.
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 Adapted from the sort routine in LANSO.
c
c\SCCS Information: @(#)
c FILE: sortc.F SID: 2.2 DATE OF SID: 4/20/96 RELEASE: 2
c
c\EndLib
c
c-----------------------------------------------------------------------
c
subroutine zsortc (which, apply, n, x, y)
c
c %------------------%
c | Scalar Arguments |
c %------------------%
c
character*2 which
logical apply
integer n
c
c %-----------------%
c | Array Arguments |
c %-----------------%
c
Complex*16
& x(0:n-1), y(0:n-1)
c
c %---------------%
c | Local Scalars |
c %---------------%
c
integer i, igap, j
Complex*16
& temp
Double precision
& temp1, temp2
c
c %--------------------%
c | External functions |
c %--------------------%
c
Double precision
& dlapy2
c
c %--------------------%
c | Intrinsic Functions |
c %--------------------%
Intrinsic
& dble, dimag
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
c
igap = n / 2
c
if (which .eq. 'LM') then
c
c %--------------------------------------------%
c | Sort X into increasing order of magnitude. |
c %--------------------------------------------%
c
10 continue
if (igap .eq. 0) go to 9000
c
do 30 i = igap, n-1
j = i-igap
20 continue
c
if (j.lt.0) go to 30
c
temp1 = dlapy2(dble(x(j)),dimag(x(j)))
temp2 = dlapy2(dble(x(j+igap)),dimag(x(j+igap)))
c
if (temp1.gt.temp2) then
temp = x(j)
x(j) = x(j+igap)
x(j+igap) = temp
c
if (apply) then
temp = y(j)
y(j) = y(j+igap)
y(j+igap) = temp
end if
else
go to 30
end if
j = j-igap
go to 20
30 continue
igap = igap / 2
go to 10
c
else if (which .eq. 'SM') then
c
c %--------------------------------------------%
c | Sort X into decreasing order of magnitude. |
c %--------------------------------------------%
c
40 continue
if (igap .eq. 0) go to 9000
c
do 60 i = igap, n-1
j = i-igap
50 continue
c
if (j .lt. 0) go to 60
c
temp1 = dlapy2(dble(x(j)),dimag(x(j)))
temp2 = dlapy2(dble(x(j+igap)),dimag(x(j+igap)))
c
if (temp1.lt.temp2) then
temp = x(j)
x(j) = x(j+igap)
x(j+igap) = temp
c
if (apply) then
temp = y(j)
y(j) = y(j+igap)
y(j+igap) = temp
end if
else
go to 60
endif
j = j-igap
go to 50
60 continue
igap = igap / 2
go to 40
c
else if (which .eq. 'LR') then
c
c %------------------------------------------------%
c | Sort XREAL into increasing order of algebraic. |
c %------------------------------------------------%
c
70 continue
if (igap .eq. 0) go to 9000
c
do 90 i = igap, n-1
j = i-igap
80 continue
c
if (j.lt.0) go to 90
c
if (dble(x(j)).gt.dble(x(j+igap))) then
temp = x(j)
x(j) = x(j+igap)
x(j+igap) = temp
c
if (apply) then
temp = y(j)
y(j) = y(j+igap)
y(j+igap) = temp
end if
else
go to 90
endif
j = j-igap
go to 80
90 continue
igap = igap / 2
go to 70
c
else if (which .eq. 'SR') then
c
c %------------------------------------------------%
c | Sort XREAL into decreasing order of algebraic. |
c %------------------------------------------------%
c
100 continue
if (igap .eq. 0) go to 9000
do 120 i = igap, n-1
j = i-igap
110 continue
c
if (j.lt.0) go to 120
c
if (dble(x(j)).lt.dble(x(j+igap))) then
temp = x(j)
x(j) = x(j+igap)
x(j+igap) = temp
c
if (apply) then
temp = y(j)
y(j) = y(j+igap)
y(j+igap) = temp
end if
else
go to 120
endif
j = j-igap
go to 110
120 continue
igap = igap / 2
go to 100
c
else if (which .eq. 'LI') then
c
c %--------------------------------------------%
c | Sort XIMAG into increasing algebraic order |
c %--------------------------------------------%
c
130 continue
if (igap .eq. 0) go to 9000
do 150 i = igap, n-1
j = i-igap
140 continue
c
if (j.lt.0) go to 150
c
if (dimag(x(j)).gt.dimag(x(j+igap))) then
temp = x(j)
x(j) = x(j+igap)
x(j+igap) = temp
c
if (apply) then
temp = y(j)
y(j) = y(j+igap)
y(j+igap) = temp
end if
else
go to 150
endif
j = j-igap
go to 140
150 continue
igap = igap / 2
go to 130
c
else if (which .eq. 'SI') then
c
c %---------------------------------------------%
c | Sort XIMAG into decreasing algebraic order |
c %---------------------------------------------%
c
160 continue
if (igap .eq. 0) go to 9000
do 180 i = igap, n-1
j = i-igap
170 continue
c
if (j.lt.0) go to 180
c
if (dimag(x(j)).lt.dimag(x(j+igap))) then
temp = x(j)
x(j) = x(j+igap)
x(j+igap) = temp
c
if (apply) then
temp = y(j)
y(j) = y(j+igap)
y(j+igap) = temp
end if
else
go to 180
endif
j = j-igap
go to 170
180 continue
igap = igap / 2
go to 160
end if
c
9000 continue
return
c
c %---------------%
c | End of zsortc |
c %---------------%
c
end
| lgpl-3.0 |
aamaricci/SciFortran | src/lapack/stpttf.f | 1 | 12204 | SUBROUTINE STPTTF( TRANSR, UPLO, N, AP, ARF, INFO )
*
* -- LAPACK routine (version 3.3.1) --
*
* -- Contributed by Fred Gustavson of the IBM Watson Research Center --
* -- April 2011 --
*
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* ..
* .. Scalar Arguments ..
CHARACTER TRANSR, UPLO
INTEGER INFO, N
* ..
* .. Array Arguments ..
REAL AP( 0: * ), ARF( 0: * )
*
* Purpose
* =======
*
* STPTTF copies a triangular matrix A from standard packed format (TP)
* to rectangular full packed format (TF).
*
* Arguments
* =========
*
* TRANSR (input) CHARACTER*1
* = 'N': ARF in Normal format is wanted;
* = 'T': ARF in Conjugate-transpose format is wanted.
*
* UPLO (input) CHARACTER*1
* = 'U': A is upper triangular;
* = 'L': A is lower triangular.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* AP (input) REAL array, dimension ( N*(N+1)/2 ),
* On entry, the upper or lower triangular 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.
*
* ARF (output) REAL array, dimension ( N*(N+1)/2 ),
* On exit, the upper or lower triangular matrix A stored in
* RFP format. For a further discussion see Notes below.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
*
* Further Details
* ===============
*
* We first consider Rectangular Full Packed (RFP) Format when N is
* even. We give an example where N = 6.
*
* AP is Upper AP is Lower
*
* 00 01 02 03 04 05 00
* 11 12 13 14 15 10 11
* 22 23 24 25 20 21 22
* 33 34 35 30 31 32 33
* 44 45 40 41 42 43 44
* 55 50 51 52 53 54 55
*
*
* Let TRANSR = 'N'. RFP holds AP as follows:
* For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last
* three columns of AP upper. The lower triangle A(4:6,0:2) consists of
* the transpose of the first three columns of AP upper.
* For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first
* three columns of AP lower. The upper triangle A(0:2,0:2) consists of
* the transpose of the last three columns of AP lower.
* This covers the case N even and TRANSR = 'N'.
*
* RFP A RFP A
*
* 03 04 05 33 43 53
* 13 14 15 00 44 54
* 23 24 25 10 11 55
* 33 34 35 20 21 22
* 00 44 45 30 31 32
* 01 11 55 40 41 42
* 02 12 22 50 51 52
*
* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the
* transpose of RFP A above. One therefore gets:
*
*
* RFP A RFP A
*
* 03 13 23 33 00 01 02 33 00 10 20 30 40 50
* 04 14 24 34 44 11 12 43 44 11 21 31 41 51
* 05 15 25 35 45 55 22 53 54 55 22 32 42 52
*
*
* We then consider Rectangular Full Packed (RFP) Format when N is
* odd. We give an example where N = 5.
*
* AP is Upper AP is Lower
*
* 00 01 02 03 04 00
* 11 12 13 14 10 11
* 22 23 24 20 21 22
* 33 34 30 31 32 33
* 44 40 41 42 43 44
*
*
* Let TRANSR = 'N'. RFP holds AP as follows:
* For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last
* three columns of AP upper. The lower triangle A(3:4,0:1) consists of
* the transpose of the first two columns of AP upper.
* For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first
* three columns of AP lower. The upper triangle A(0:1,1:2) consists of
* the transpose of the last two columns of AP lower.
* This covers the case N odd and TRANSR = 'N'.
*
* RFP A RFP A
*
* 02 03 04 00 33 43
* 12 13 14 10 11 44
* 22 23 24 20 21 22
* 00 33 34 30 31 32
* 01 11 44 40 41 42
*
* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the
* transpose of RFP A above. One therefore gets:
*
* RFP A RFP A
*
* 02 12 22 00 01 00 10 20 30 40 50
* 03 13 23 33 11 33 11 21 31 41 51
* 04 14 24 34 44 43 44 22 32 42 52
*
* =====================================================================
*
* .. Parameters ..
* ..
* .. Local Scalars ..
LOGICAL LOWER, NISODD, NORMALTRANSR
INTEGER N1, N2, K, NT
INTEGER I, J, IJ
INTEGER IJP, JP, LDA, JS
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MOD
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
NORMALTRANSR = LSAME( TRANSR, 'N' )
LOWER = LSAME( UPLO, 'L' )
IF( .NOT.NORMALTRANSR .AND. .NOT.LSAME( TRANSR, 'T' ) ) THEN
INFO = -1
ELSE IF( .NOT.LOWER .AND. .NOT.LSAME( UPLO, 'U' ) ) THEN
INFO = -2
ELSE IF( N.LT.0 ) THEN
INFO = -3
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'STPTTF', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
IF( N.EQ.1 ) THEN
IF( NORMALTRANSR ) THEN
ARF( 0 ) = AP( 0 )
ELSE
ARF( 0 ) = AP( 0 )
END IF
RETURN
END IF
*
* Size of array ARF(0:NT-1)
*
NT = N*( N+1 ) / 2
*
* Set N1 and N2 depending on LOWER
*
IF( LOWER ) THEN
N2 = N / 2
N1 = N - N2
ELSE
N1 = N / 2
N2 = N - N1
END IF
*
* If N is odd, set NISODD = .TRUE.
* If N is even, set K = N/2 and NISODD = .FALSE.
*
* set lda of ARF^C; ARF^C is (0:(N+1)/2-1,0:N-noe)
* where noe = 0 if n is even, noe = 1 if n is odd
*
IF( MOD( N, 2 ).EQ.0 ) THEN
K = N / 2
NISODD = .FALSE.
LDA = N + 1
ELSE
NISODD = .TRUE.
LDA = N
END IF
*
* ARF^C has lda rows and n+1-noe cols
*
IF( .NOT.NORMALTRANSR )
$ LDA = ( N+1 ) / 2
*
* start execution: there are eight cases
*
IF( NISODD ) THEN
*
* N is odd
*
IF( NORMALTRANSR ) THEN
*
* N is odd and TRANSR = 'N'
*
IF( LOWER ) THEN
*
* N is odd, TRANSR = 'N', and UPLO = 'L'
*
IJP = 0
JP = 0
DO J = 0, N2
DO I = J, N - 1
IJ = I + JP
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JP = JP + LDA
END DO
DO I = 0, N2 - 1
DO J = 1 + I, N2
IJ = I + J*LDA
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
END DO
*
ELSE
*
* N is odd, TRANSR = 'N', and UPLO = 'U'
*
IJP = 0
DO J = 0, N1 - 1
IJ = N2 + J
DO I = 0, J
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
IJ = IJ + LDA
END DO
END DO
JS = 0
DO J = N1, N - 1
IJ = JS
DO IJ = JS, JS + J
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JS = JS + LDA
END DO
*
END IF
*
ELSE
*
* N is odd and TRANSR = 'T'
*
IF( LOWER ) THEN
*
* N is odd, TRANSR = 'T', and UPLO = 'L'
*
IJP = 0
DO I = 0, N2
DO IJ = I*( LDA+1 ), N*LDA - 1, LDA
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
END DO
JS = 1
DO J = 0, N2 - 1
DO IJ = JS, JS + N2 - J - 1
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JS = JS + LDA + 1
END DO
*
ELSE
*
* N is odd, TRANSR = 'T', and UPLO = 'U'
*
IJP = 0
JS = N2*LDA
DO J = 0, N1 - 1
DO IJ = JS, JS + J
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JS = JS + LDA
END DO
DO I = 0, N1
DO IJ = I, I + ( N1+I )*LDA, LDA
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
END DO
*
END IF
*
END IF
*
ELSE
*
* N is even
*
IF( NORMALTRANSR ) THEN
*
* N is even and TRANSR = 'N'
*
IF( LOWER ) THEN
*
* N is even, TRANSR = 'N', and UPLO = 'L'
*
IJP = 0
JP = 0
DO J = 0, K - 1
DO I = J, N - 1
IJ = 1 + I + JP
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JP = JP + LDA
END DO
DO I = 0, K - 1
DO J = I, K - 1
IJ = I + J*LDA
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
END DO
*
ELSE
*
* N is even, TRANSR = 'N', and UPLO = 'U'
*
IJP = 0
DO J = 0, K - 1
IJ = K + 1 + J
DO I = 0, J
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
IJ = IJ + LDA
END DO
END DO
JS = 0
DO J = K, N - 1
IJ = JS
DO IJ = JS, JS + J
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JS = JS + LDA
END DO
*
END IF
*
ELSE
*
* N is even and TRANSR = 'T'
*
IF( LOWER ) THEN
*
* N is even, TRANSR = 'T', and UPLO = 'L'
*
IJP = 0
DO I = 0, K - 1
DO IJ = I + ( I+1 )*LDA, ( N+1 )*LDA - 1, LDA
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
END DO
JS = 0
DO J = 0, K - 1
DO IJ = JS, JS + K - J - 1
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JS = JS + LDA + 1
END DO
*
ELSE
*
* N is even, TRANSR = 'T', and UPLO = 'U'
*
IJP = 0
JS = ( K+1 )*LDA
DO J = 0, K - 1
DO IJ = JS, JS + J
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
JS = JS + LDA
END DO
DO I = 0, K - 1
DO IJ = I, I + ( K+I )*LDA, LDA
ARF( IJ ) = AP( IJP )
IJP = IJP + 1
END DO
END DO
*
END IF
*
END IF
*
END IF
*
RETURN
*
* End of STPTTF
*
END
| lgpl-3.0 |
takuto-maeda/OpenSWPC | src/shared/m_rdrmed.F90 | 1 | 4287 | #include "m_debug.h"
!! ----------------------------------------------------------------------------------------------------------------------------- !!
!>
!! Read random media volume
!!
!! @copyright
!! Copyright 2013-2019 Takuto Maeda. All rights reserved. This project is released under the MIT license.
!<
!! --
module m_rdrmed
use m_std
use m_debug
#ifdef _NETCDF
use netcdf
#endif
implicit none
public
contains
!! --------------------------------------------------------------------------------------------------------------------------- !!
subroutine rdrmed__2d( ib, ie, kb, ke, fn_rmed, vol )
integer, intent(in) :: ib, ie
integer, intent(in) :: kb, ke
character(*), intent(in) :: fn_rmed
real(SP), intent(out) :: vol(kb:ke, ib:ie)
!! --
real(SP), allocatable :: hh(:,:)
integer :: i, k, ii, kk
integer :: ncid, vid
character(80) :: xn, zn, vn
integer :: nxc, nzc !< netcdf volume size
!! ----
#ifdef _NETCDF
call debug( fn_rmed )
call assert( nf90_open( fn_rmed, NF90_NOWRITE, ncid ) == NF90_NOERR )
!! size
call assert( nf90_inquire_dimension( ncid, 1, xn, nxc ) == NF90_NOERR )
call assert( nf90_inquire_dimension( ncid, 2, zn, nzc ) == NF90_NOERR )
call assert( nf90_inquire_variable ( ncid, 3, vn ) == NF90_NOERR )
call assert( nf90_inq_varid ( ncid, vn, vid ) == NF90_NOERR )
call debug( vn )
call debug( vid )
call debug( ncid )
allocate( hh(nxc,nzc) )
call assert( nf90_get_var( ncid, vid, hh ) == NF90_NOERR )
do k=kb, min(ke,nzc)
if( k <= 0 ) then
kk = k + nzc
else
kk = k
end if
do i=ib, ie
ii = mod(i,nxc)
if( ii<=0 ) ii = ii + nxc
vol(k,i) = hh(ii,kk)
end do
end do
deallocate( hh )
!! bottom cyclic part
do k=nzc+1, ke
kk = mod(k,nzc)
if( kk<=0 ) kk = kk + nzc
vol(k,ib:ie) = vol(kk,ib:ie)
end do
#endif
end subroutine rdrmed__2d
!! --------------------------------------------------------------------------------------------------------------------------- !!
!! --------------------------------------------------------------------------------------------------------------------------- !!
subroutine rdrmed__3d( ib, ie, jb, je, kb, ke, fn_rmed, vol )
integer, intent(in) :: ib, ie
integer, intent(in) :: jb, je
integer, intent(in) :: kb, ke
character(*), intent(in) :: fn_rmed
real(SP), intent(out) :: vol(kb:ke, ib:ie, jb:je)
!! --
real(SP), allocatable :: hh(:,:)
integer :: i, j, k, ii, jj, kk
integer :: ncid, vid
character(80) :: xn, yn, zn, vn
integer :: nxc, nyc, nzc !< netcdf volume size
integer :: st(3), ct(3)
!! ----
#ifdef _NETCDF
call assert( nf90_open( fn_rmed, NF90_NOWRITE, ncid ) == NF90_NOERR )
!! size
call assert( nf90_inquire_dimension( ncid, 1, xn, nxc ) == NF90_NOERR )
call assert( nf90_inquire_dimension( ncid, 2, yn, nyc ) == NF90_NOERR )
call assert( nf90_inquire_dimension( ncid, 3, zn, nzc ) == NF90_NOERR )
call assert( nf90_inquire_variable ( ncid, 4, vn ) == NF90_NOERR )
call assert( nf90_inq_varid ( ncid, vn, vid ) == NF90_NOERR )
allocate( hh(nxc,nyc) )
st(1:3) = (/1,1,1/)
ct(1:3) = (/nxc,nyc,1/)
do k=kb, min(ke,nzc)
if( k <= 0 ) then
kk = k + nzc
else
kk = k
end if
st(3) = kk
call assert( nf90_get_var(ncid, vid, hh, start=st, count=ct ) == NF90_NOERR )
do j=jb, je
jj = mod(j,nyc)
if( jj<=0 ) jj = jj + nyc
do i=ib, ie
ii = mod(i,nxc)
if( ii<=0 ) ii = ii + nxc
vol(k,i,j) = hh(ii,jj)
end do
end do
end do
deallocate( hh )
!! bottom cyclic part
do k=nzc+1, ke
kk = mod(k,nzc)
vol(k,ib:ie,jb:je) = vol(kk,ib:ie,jb:je)
end do
#endif
end subroutine rdrmed__3d
!! --------------------------------------------------------------------------------------------------------------------------- !!
end module m_rdrmed
!! ----------------------------------------------------------------------------------------------------------------------------- !!
| mit |
aamaricci/SciFortran | src/lapack/cunbdb.f | 1 | 19380 | SUBROUTINE CUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12,
$ X21, LDX21, X22, LDX22, THETA, PHI, TAUP1,
$ TAUP2, TAUQ1, TAUQ2, WORK, LWORK, INFO )
IMPLICIT NONE
*
* -- LAPACK routine ((version 3.3.0)) --
*
* -- Contributed by Brian Sutton of the Randolph-Macon College --
* -- November 2010
*
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*
* .. Scalar Arguments ..
CHARACTER SIGNS, TRANS
INTEGER INFO, LDX11, LDX12, LDX21, LDX22, LWORK, M, P,
$ Q
* ..
* .. Array Arguments ..
REAL PHI( * ), THETA( * )
COMPLEX TAUP1( * ), TAUP2( * ), TAUQ1( * ), TAUQ2( * ),
$ WORK( * ), X11( LDX11, * ), X12( LDX12, * ),
$ X21( LDX21, * ), X22( LDX22, * )
* ..
*
* Purpose
* =======
*
* CUNBDB simultaneously bidiagonalizes the blocks of an M-by-M
* partitioned unitary matrix X:
*
* [ B11 | B12 0 0 ]
* [ X11 | X12 ] [ P1 | ] [ 0 | 0 -I 0 ] [ Q1 | ]**H
* X = [-----------] = [---------] [----------------] [---------] .
* [ X21 | X22 ] [ | P2 ] [ B21 | B22 0 0 ] [ | Q2 ]
* [ 0 | 0 0 I ]
*
* X11 is P-by-Q. Q must be no larger than P, M-P, or M-Q. (If this is
* not the case, then X must be transposed and/or permuted. This can be
* done in constant time using the TRANS and SIGNS options. See CUNCSD
* for details.)
*
* The unitary matrices P1, P2, Q1, and Q2 are P-by-P, (M-P)-by-
* (M-P), Q-by-Q, and (M-Q)-by-(M-Q), respectively. They are
* represented implicitly by Householder vectors.
*
* B11, B12, B21, and B22 are Q-by-Q bidiagonal matrices represented
* implicitly by angles THETA, PHI.
*
* Arguments
* =========
*
* TRANS (input) 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.
*
* SIGNS (input) CHARACTER
* = 'O': The lower-left block is made nonpositive (the
* "other" convention);
* otherwise: The upper-right block is made nonpositive (the
* "default" convention).
*
* M (input) INTEGER
* The number of rows and columns in X.
*
* P (input) INTEGER
* The number of rows in X11 and X12. 0 <= P <= M.
*
* Q (input) INTEGER
* The number of columns in X11 and X21. 0 <= Q <=
* MIN(P,M-P,M-Q).
*
* X11 (input/output) COMPLEX array, dimension (LDX11,Q)
* On entry, the top-left block of the unitary matrix to be
* reduced. On exit, the form depends on TRANS:
* If TRANS = 'N', then
* the columns of tril(X11) specify reflectors for P1,
* the rows of triu(X11,1) specify reflectors for Q1;
* else TRANS = 'T', and
* the rows of triu(X11) specify reflectors for P1,
* the columns of tril(X11,-1) specify reflectors for Q1.
*
* LDX11 (input) INTEGER
* The leading dimension of X11. If TRANS = 'N', then LDX11 >=
* P; else LDX11 >= Q.
*
* X12 (input/output) CMPLX array, dimension (LDX12,M-Q)
* On entry, the top-right block of the unitary matrix to
* be reduced. On exit, the form depends on TRANS:
* If TRANS = 'N', then
* the rows of triu(X12) specify the first P reflectors for
* Q2;
* else TRANS = 'T', and
* the columns of tril(X12) specify the first P reflectors
* for Q2.
*
* LDX12 (input) INTEGER
* The leading dimension of X12. If TRANS = 'N', then LDX12 >=
* P; else LDX11 >= M-Q.
*
* X21 (input/output) COMPLEX array, dimension (LDX21,Q)
* On entry, the bottom-left block of the unitary matrix to
* be reduced. On exit, the form depends on TRANS:
* If TRANS = 'N', then
* the columns of tril(X21) specify reflectors for P2;
* else TRANS = 'T', and
* the rows of triu(X21) specify reflectors for P2.
*
* LDX21 (input) INTEGER
* The leading dimension of X21. If TRANS = 'N', then LDX21 >=
* M-P; else LDX21 >= Q.
*
* X22 (input/output) COMPLEX array, dimension (LDX22,M-Q)
* On entry, the bottom-right block of the unitary matrix to
* be reduced. On exit, the form depends on TRANS:
* If TRANS = 'N', then
* the rows of triu(X22(Q+1:M-P,P+1:M-Q)) specify the last
* M-P-Q reflectors for Q2,
* else TRANS = 'T', and
* the columns of tril(X22(P+1:M-Q,Q+1:M-P)) specify the last
* M-P-Q reflectors for P2.
*
* LDX22 (input) INTEGER
* The leading dimension of X22. If TRANS = 'N', then LDX22 >=
* M-P; else LDX22 >= M-Q.
*
* THETA (output) REAL array, dimension (Q)
* The entries of the bidiagonal blocks B11, B12, B21, B22 can
* be computed from the angles THETA and PHI. See Further
* Details.
*
* PHI (output) REAL array, dimension (Q-1)
* The entries of the bidiagonal blocks B11, B12, B21, B22 can
* be computed from the angles THETA and PHI. See Further
* Details.
*
* TAUP1 (output) COMPLEX array, dimension (P)
* The scalar factors of the elementary reflectors that define
* P1.
*
* TAUP2 (output) COMPLEX array, dimension (M-P)
* The scalar factors of the elementary reflectors that define
* P2.
*
* TAUQ1 (output) COMPLEX array, dimension (Q)
* The scalar factors of the elementary reflectors that define
* Q1.
*
* TAUQ2 (output) COMPLEX array, dimension (M-Q)
* The scalar factors of the elementary reflectors that define
* Q2.
*
* WORK (workspace) COMPLEX array, dimension (LWORK)
*
* LWORK (input) INTEGER
* The dimension of the array WORK. LWORK >= M-Q.
*
* 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.
*
* Further Details
* ===============
*
* The bidiagonal blocks B11, B12, B21, and B22 are represented
* implicitly by angles THETA(1), ..., THETA(Q) and PHI(1), ...,
* PHI(Q-1). B11 and B21 are upper bidiagonal, while B21 and B22 are
* lower bidiagonal. Every entry in each bidiagonal band is a product
* of a sine or cosine of a THETA with a sine or cosine of a PHI. See
* [1] or CUNCSD for details.
*
* P1, P2, Q1, and Q2 are represented as products of elementary
* reflectors. See CUNCSD for details on generating P1, P2, Q1, and Q2
* using CUNGQR and CUNGLQ.
*
* Reference
* =========
*
* [1] Brian D. Sutton. Computing the complete CS decomposition. Numer.
* Algorithms, 50(1):33-65, 2009.
*
* ====================================================================
*
* .. Parameters ..
REAL REALONE
PARAMETER ( REALONE = 1.0E0 )
COMPLEX NEGONE, ONE
PARAMETER ( NEGONE = (-1.0E0,0.0E0),
$ ONE = (1.0E0,0.0E0) )
* ..
* .. Local Scalars ..
LOGICAL COLMAJOR, LQUERY
INTEGER I, LWORKMIN, LWORKOPT
REAL Z1, Z2, Z3, Z4
* ..
* .. External Subroutines ..
EXTERNAL CAXPY, CLARF, CLARFGP, CSCAL, XERBLA
EXTERNAL CLACGV
*
* ..
* .. External Functions ..
REAL SCNRM2
LOGICAL LSAME
EXTERNAL SCNRM2, LSAME
* ..
* .. Intrinsic Functions
INTRINSIC ATAN2, COS, MAX, MIN, SIN
INTRINSIC CMPLX, CONJG
* ..
* .. Executable Statements ..
*
* Test input arguments
*
INFO = 0
COLMAJOR = .NOT. LSAME( TRANS, 'T' )
IF( .NOT. LSAME( SIGNS, 'O' ) ) THEN
Z1 = REALONE
Z2 = REALONE
Z3 = REALONE
Z4 = REALONE
ELSE
Z1 = REALONE
Z2 = -REALONE
Z3 = REALONE
Z4 = -REALONE
END IF
LQUERY = LWORK .EQ. -1
*
IF( M .LT. 0 ) THEN
INFO = -3
ELSE IF( P .LT. 0 .OR. P .GT. M ) THEN
INFO = -4
ELSE IF( Q .LT. 0 .OR. Q .GT. P .OR. Q .GT. M-P .OR.
$ Q .GT. M-Q ) THEN
INFO = -5
ELSE IF( COLMAJOR .AND. LDX11 .LT. MAX( 1, P ) ) THEN
INFO = -7
ELSE IF( .NOT.COLMAJOR .AND. LDX11 .LT. MAX( 1, Q ) ) THEN
INFO = -7
ELSE IF( COLMAJOR .AND. LDX12 .LT. MAX( 1, P ) ) THEN
INFO = -9
ELSE IF( .NOT.COLMAJOR .AND. LDX12 .LT. MAX( 1, M-Q ) ) THEN
INFO = -9
ELSE IF( COLMAJOR .AND. LDX21 .LT. MAX( 1, M-P ) ) THEN
INFO = -11
ELSE IF( .NOT.COLMAJOR .AND. LDX21 .LT. MAX( 1, Q ) ) THEN
INFO = -11
ELSE IF( COLMAJOR .AND. LDX22 .LT. MAX( 1, M-P ) ) THEN
INFO = -13
ELSE IF( .NOT.COLMAJOR .AND. LDX22 .LT. MAX( 1, M-Q ) ) THEN
INFO = -13
END IF
*
* Compute workspace
*
IF( INFO .EQ. 0 ) THEN
LWORKOPT = M - Q
LWORKMIN = M - Q
WORK(1) = LWORKOPT
IF( LWORK .LT. LWORKMIN .AND. .NOT. LQUERY ) THEN
INFO = -21
END IF
END IF
IF( INFO .NE. 0 ) THEN
CALL XERBLA( 'xORBDB', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Handle column-major and row-major separately
*
IF( COLMAJOR ) THEN
*
* Reduce columns 1, ..., Q of X11, X12, X21, and X22
*
DO I = 1, Q
*
IF( I .EQ. 1 ) THEN
CALL CSCAL( P-I+1, CMPLX( Z1, 0.0E0 ), X11(I,I), 1 )
ELSE
CALL CSCAL( P-I+1, CMPLX( Z1*COS(PHI(I-1)), 0.0E0 ),
$ X11(I,I), 1 )
CALL CAXPY( P-I+1, CMPLX( -Z1*Z3*Z4*SIN(PHI(I-1)),
$ 0.0E0 ), X12(I,I-1), 1, X11(I,I), 1 )
END IF
IF( I .EQ. 1 ) THEN
CALL CSCAL( M-P-I+1, CMPLX( Z2, 0.0E0 ), X21(I,I), 1 )
ELSE
CALL CSCAL( M-P-I+1, CMPLX( Z2*COS(PHI(I-1)), 0.0E0 ),
$ X21(I,I), 1 )
CALL CAXPY( M-P-I+1, CMPLX( -Z2*Z3*Z4*SIN(PHI(I-1)),
$ 0.0E0 ), X22(I,I-1), 1, X21(I,I), 1 )
END IF
*
THETA(I) = ATAN2( SCNRM2( M-P-I+1, X21(I,I), 1 ),
$ SCNRM2( P-I+1, X11(I,I), 1 ) )
*
CALL CLARFGP( P-I+1, X11(I,I), X11(I+1,I), 1, TAUP1(I) )
X11(I,I) = ONE
CALL CLARFGP( M-P-I+1, X21(I,I), X21(I+1,I), 1, TAUP2(I) )
X21(I,I) = ONE
*
CALL CLARF( 'L', P-I+1, Q-I, X11(I,I), 1, CONJG(TAUP1(I)),
$ X11(I,I+1), LDX11, WORK )
CALL CLARF( 'L', P-I+1, M-Q-I+1, X11(I,I), 1,
$ CONJG(TAUP1(I)), X12(I,I), LDX12, WORK )
CALL CLARF( 'L', M-P-I+1, Q-I, X21(I,I), 1, CONJG(TAUP2(I)),
$ X21(I,I+1), LDX21, WORK )
CALL CLARF( 'L', M-P-I+1, M-Q-I+1, X21(I,I), 1,
$ CONJG(TAUP2(I)), X22(I,I), LDX22, WORK )
*
IF( I .LT. Q ) THEN
CALL CSCAL( Q-I, CMPLX( -Z1*Z3*SIN(THETA(I)), 0.0E0 ),
$ X11(I,I+1), LDX11 )
CALL CAXPY( Q-I, CMPLX( Z2*Z3*COS(THETA(I)), 0.0E0 ),
$ X21(I,I+1), LDX21, X11(I,I+1), LDX11 )
END IF
CALL CSCAL( M-Q-I+1, CMPLX( -Z1*Z4*SIN(THETA(I)), 0.0E0 ),
$ X12(I,I), LDX12 )
CALL CAXPY( M-Q-I+1, CMPLX( Z2*Z4*COS(THETA(I)), 0.0E0 ),
$ X22(I,I), LDX22, X12(I,I), LDX12 )
*
IF( I .LT. Q )
$ PHI(I) = ATAN2( SCNRM2( Q-I, X11(I,I+1), LDX11 ),
$ SCNRM2( M-Q-I+1, X12(I,I), LDX12 ) )
*
IF( I .LT. Q ) THEN
CALL CLACGV( Q-I, X11(I,I+1), LDX11 )
CALL CLARFGP( Q-I, X11(I,I+1), X11(I,I+2), LDX11,
$ TAUQ1(I) )
X11(I,I+1) = ONE
END IF
CALL CLACGV( M-Q-I+1, X12(I,I), LDX12 )
CALL CLARFGP( M-Q-I+1, X12(I,I), X12(I,I+1), LDX12,
$ TAUQ2(I) )
X12(I,I) = ONE
*
IF( I .LT. Q ) THEN
CALL CLARF( 'R', P-I, Q-I, X11(I,I+1), LDX11, TAUQ1(I),
$ X11(I+1,I+1), LDX11, WORK )
CALL CLARF( 'R', M-P-I, Q-I, X11(I,I+1), LDX11, TAUQ1(I),
$ X21(I+1,I+1), LDX21, WORK )
END IF
CALL CLARF( 'R', P-I, M-Q-I+1, X12(I,I), LDX12, TAUQ2(I),
$ X12(I+1,I), LDX12, WORK )
CALL CLARF( 'R', M-P-I, M-Q-I+1, X12(I,I), LDX12, TAUQ2(I),
$ X22(I+1,I), LDX22, WORK )
*
IF( I .LT. Q )
$ CALL CLACGV( Q-I, X11(I,I+1), LDX11 )
CALL CLACGV( M-Q-I+1, X12(I,I), LDX12 )
*
END DO
*
* Reduce columns Q + 1, ..., P of X12, X22
*
DO I = Q + 1, P
*
CALL CSCAL( M-Q-I+1, CMPLX( -Z1*Z4, 0.0E0 ), X12(I,I),
$ LDX12 )
CALL CLACGV( M-Q-I+1, X12(I,I), LDX12 )
CALL CLARFGP( M-Q-I+1, X12(I,I), X12(I,I+1), LDX12,
$ TAUQ2(I) )
X12(I,I) = ONE
*
CALL CLARF( 'R', P-I, M-Q-I+1, X12(I,I), LDX12, TAUQ2(I),
$ X12(I+1,I), LDX12, WORK )
IF( M-P-Q .GE. 1 )
$ CALL CLARF( 'R', M-P-Q, M-Q-I+1, X12(I,I), LDX12,
$ TAUQ2(I), X22(Q+1,I), LDX22, WORK )
*
CALL CLACGV( M-Q-I+1, X12(I,I), LDX12 )
*
END DO
*
* Reduce columns P + 1, ..., M - Q of X12, X22
*
DO I = 1, M - P - Q
*
CALL CSCAL( M-P-Q-I+1, CMPLX( Z2*Z4, 0.0E0 ),
$ X22(Q+I,P+I), LDX22 )
CALL CLACGV( M-P-Q-I+1, X22(Q+I,P+I), LDX22 )
CALL CLARFGP( M-P-Q-I+1, X22(Q+I,P+I), X22(Q+I,P+I+1),
$ LDX22, TAUQ2(P+I) )
X22(Q+I,P+I) = ONE
CALL CLARF( 'R', M-P-Q-I, M-P-Q-I+1, X22(Q+I,P+I), LDX22,
$ TAUQ2(P+I), X22(Q+I+1,P+I), LDX22, WORK )
*
CALL CLACGV( M-P-Q-I+1, X22(Q+I,P+I), LDX22 )
*
END DO
*
ELSE
*
* Reduce columns 1, ..., Q of X11, X12, X21, X22
*
DO I = 1, Q
*
IF( I .EQ. 1 ) THEN
CALL CSCAL( P-I+1, CMPLX( Z1, 0.0E0 ), X11(I,I),
$ LDX11 )
ELSE
CALL CSCAL( P-I+1, CMPLX( Z1*COS(PHI(I-1)), 0.0E0 ),
$ X11(I,I), LDX11 )
CALL CAXPY( P-I+1, CMPLX( -Z1*Z3*Z4*SIN(PHI(I-1)),
$ 0.0E0 ), X12(I-1,I), LDX12, X11(I,I), LDX11 )
END IF
IF( I .EQ. 1 ) THEN
CALL CSCAL( M-P-I+1, CMPLX( Z2, 0.0E0 ), X21(I,I),
$ LDX21 )
ELSE
CALL CSCAL( M-P-I+1, CMPLX( Z2*COS(PHI(I-1)), 0.0E0 ),
$ X21(I,I), LDX21 )
CALL CAXPY( M-P-I+1, CMPLX( -Z2*Z3*Z4*SIN(PHI(I-1)),
$ 0.0E0 ), X22(I-1,I), LDX22, X21(I,I), LDX21 )
END IF
*
THETA(I) = ATAN2( SCNRM2( M-P-I+1, X21(I,I), LDX21 ),
$ SCNRM2( P-I+1, X11(I,I), LDX11 ) )
*
CALL CLACGV( P-I+1, X11(I,I), LDX11 )
CALL CLACGV( M-P-I+1, X21(I,I), LDX21 )
*
CALL CLARFGP( P-I+1, X11(I,I), X11(I,I+1), LDX11, TAUP1(I) )
X11(I,I) = ONE
CALL CLARFGP( M-P-I+1, X21(I,I), X21(I,I+1), LDX21,
$ TAUP2(I) )
X21(I,I) = ONE
*
CALL CLARF( 'R', Q-I, P-I+1, X11(I,I), LDX11, TAUP1(I),
$ X11(I+1,I), LDX11, WORK )
CALL CLARF( 'R', M-Q-I+1, P-I+1, X11(I,I), LDX11, TAUP1(I),
$ X12(I,I), LDX12, WORK )
CALL CLARF( 'R', Q-I, M-P-I+1, X21(I,I), LDX21, TAUP2(I),
$ X21(I+1,I), LDX21, WORK )
CALL CLARF( 'R', M-Q-I+1, M-P-I+1, X21(I,I), LDX21,
$ TAUP2(I), X22(I,I), LDX22, WORK )
*
CALL CLACGV( P-I+1, X11(I,I), LDX11 )
CALL CLACGV( M-P-I+1, X21(I,I), LDX21 )
*
IF( I .LT. Q ) THEN
CALL CSCAL( Q-I, CMPLX( -Z1*Z3*SIN(THETA(I)), 0.0E0 ),
$ X11(I+1,I), 1 )
CALL CAXPY( Q-I, CMPLX( Z2*Z3*COS(THETA(I)), 0.0E0 ),
$ X21(I+1,I), 1, X11(I+1,I), 1 )
END IF
CALL CSCAL( M-Q-I+1, CMPLX( -Z1*Z4*SIN(THETA(I)), 0.0E0 ),
$ X12(I,I), 1 )
CALL CAXPY( M-Q-I+1, CMPLX( Z2*Z4*COS(THETA(I)), 0.0E0 ),
$ X22(I,I), 1, X12(I,I), 1 )
*
IF( I .LT. Q )
$ PHI(I) = ATAN2( SCNRM2( Q-I, X11(I+1,I), 1 ),
$ SCNRM2( M-Q-I+1, X12(I,I), 1 ) )
*
IF( I .LT. Q ) THEN
CALL CLARFGP( Q-I, X11(I+1,I), X11(I+2,I), 1, TAUQ1(I) )
X11(I+1,I) = ONE
END IF
CALL CLARFGP( M-Q-I+1, X12(I,I), X12(I+1,I), 1, TAUQ2(I) )
X12(I,I) = ONE
*
IF( I .LT. Q ) THEN
CALL CLARF( 'L', Q-I, P-I, X11(I+1,I), 1,
$ CONJG(TAUQ1(I)), X11(I+1,I+1), LDX11, WORK )
CALL CLARF( 'L', Q-I, M-P-I, X11(I+1,I), 1,
$ CONJG(TAUQ1(I)), X21(I+1,I+1), LDX21, WORK )
END IF
CALL CLARF( 'L', M-Q-I+1, P-I, X12(I,I), 1, CONJG(TAUQ2(I)),
$ X12(I,I+1), LDX12, WORK )
CALL CLARF( 'L', M-Q-I+1, M-P-I, X12(I,I), 1,
$ CONJG(TAUQ2(I)), X22(I,I+1), LDX22, WORK )
*
END DO
*
* Reduce columns Q + 1, ..., P of X12, X22
*
DO I = Q + 1, P
*
CALL CSCAL( M-Q-I+1, CMPLX( -Z1*Z4, 0.0E0 ), X12(I,I), 1 )
CALL CLARFGP( M-Q-I+1, X12(I,I), X12(I+1,I), 1, TAUQ2(I) )
X12(I,I) = ONE
*
CALL CLARF( 'L', M-Q-I+1, P-I, X12(I,I), 1, CONJG(TAUQ2(I)),
$ X12(I,I+1), LDX12, WORK )
IF( M-P-Q .GE. 1 )
$ CALL CLARF( 'L', M-Q-I+1, M-P-Q, X12(I,I), 1,
$ CONJG(TAUQ2(I)), X22(I,Q+1), LDX22, WORK )
*
END DO
*
* Reduce columns P + 1, ..., M - Q of X12, X22
*
DO I = 1, M - P - Q
*
CALL CSCAL( M-P-Q-I+1, CMPLX( Z2*Z4, 0.0E0 ),
$ X22(P+I,Q+I), 1 )
CALL CLARFGP( M-P-Q-I+1, X22(P+I,Q+I), X22(P+I+1,Q+I), 1,
$ TAUQ2(P+I) )
X22(P+I,Q+I) = ONE
*
CALL CLARF( 'L', M-P-Q-I+1, M-P-Q-I, X22(P+I,Q+I), 1,
$ CONJG(TAUQ2(P+I)), X22(P+I,Q+I+1), LDX22, WORK )
*
END DO
*
END IF
*
RETURN
*
* End of CUNBDB
*
END
| lgpl-3.0 |
OpenDA-Association/OpenDA | core/native/external/lapack/slasv2.f | 46 | 6636 | SUBROUTINE SLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )
*
* -- LAPACK auxiliary routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* October 31, 1992
*
* .. Scalar Arguments ..
REAL CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN
* ..
*
* Purpose
* =======
*
* SLASV2 computes the singular value decomposition of a 2-by-2
* triangular matrix
* [ F G ]
* [ 0 H ].
* On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the
* smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and
* right singular vectors for abs(SSMAX), giving the decomposition
*
* [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ]
* [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ].
*
* Arguments
* =========
*
* F (input) REAL
* The (1,1) element of the 2-by-2 matrix.
*
* G (input) REAL
* The (1,2) element of the 2-by-2 matrix.
*
* H (input) REAL
* The (2,2) element of the 2-by-2 matrix.
*
* SSMIN (output) REAL
* abs(SSMIN) is the smaller singular value.
*
* SSMAX (output) REAL
* abs(SSMAX) is the larger singular value.
*
* SNL (output) REAL
* CSL (output) REAL
* The vector (CSL, SNL) is a unit left singular vector for the
* singular value abs(SSMAX).
*
* SNR (output) REAL
* CSR (output) REAL
* The vector (CSR, SNR) is a unit right singular vector for the
* singular value abs(SSMAX).
*
* Further Details
* ===============
*
* Any input parameter may be aliased with any output parameter.
*
* Barring over/underflow and assuming a guard digit in subtraction, all
* output quantities are correct to within a few units in the last
* place (ulps).
*
* In IEEE arithmetic, the code works correctly if one matrix element is
* infinite.
*
* Overflow will not occur unless the largest singular value itself
* overflows or is within a few ulps of overflow. (On machines with
* partial overflow, like the Cray, overflow may occur if the largest
* singular value is within a factor of 2 of overflow.)
*
* Underflow is harmless if underflow is gradual. Otherwise, results
* may correspond to a matrix modified by perturbations of size near
* the underflow threshold.
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0E0 )
REAL HALF
PARAMETER ( HALF = 0.5E0 )
REAL ONE
PARAMETER ( ONE = 1.0E0 )
REAL TWO
PARAMETER ( TWO = 2.0E0 )
REAL FOUR
PARAMETER ( FOUR = 4.0E0 )
* ..
* .. Local Scalars ..
LOGICAL GASMAL, SWAP
INTEGER PMAX
REAL A, CLT, CRT, D, FA, FT, GA, GT, HA, HT, L, M,
$ MM, R, S, SLT, SRT, T, TEMP, TSIGN, TT
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, SIGN, SQRT
* ..
* .. External Functions ..
REAL SLAMCH
EXTERNAL SLAMCH
* ..
* .. Executable Statements ..
*
FT = F
FA = ABS( FT )
HT = H
HA = ABS( H )
*
* PMAX points to the maximum absolute element of matrix
* PMAX = 1 if F largest in absolute values
* PMAX = 2 if G largest in absolute values
* PMAX = 3 if H largest in absolute values
*
PMAX = 1
SWAP = ( HA.GT.FA )
IF( SWAP ) THEN
PMAX = 3
TEMP = FT
FT = HT
HT = TEMP
TEMP = FA
FA = HA
HA = TEMP
*
* Now FA .ge. HA
*
END IF
GT = G
GA = ABS( GT )
IF( GA.EQ.ZERO ) THEN
*
* Diagonal matrix
*
SSMIN = HA
SSMAX = FA
CLT = ONE
CRT = ONE
SLT = ZERO
SRT = ZERO
ELSE
GASMAL = .TRUE.
IF( GA.GT.FA ) THEN
PMAX = 2
IF( ( FA / GA ).LT.SLAMCH( 'EPS' ) ) THEN
*
* Case of very large GA
*
GASMAL = .FALSE.
SSMAX = GA
IF( HA.GT.ONE ) THEN
SSMIN = FA / ( GA / HA )
ELSE
SSMIN = ( FA / GA )*HA
END IF
CLT = ONE
SLT = HT / GT
SRT = ONE
CRT = FT / GT
END IF
END IF
IF( GASMAL ) THEN
*
* Normal case
*
D = FA - HA
IF( D.EQ.FA ) THEN
*
* Copes with infinite F or H
*
L = ONE
ELSE
L = D / FA
END IF
*
* Note that 0 .le. L .le. 1
*
M = GT / FT
*
* Note that abs(M) .le. 1/macheps
*
T = TWO - L
*
* Note that T .ge. 1
*
MM = M*M
TT = T*T
S = SQRT( TT+MM )
*
* Note that 1 .le. S .le. 1 + 1/macheps
*
IF( L.EQ.ZERO ) THEN
R = ABS( M )
ELSE
R = SQRT( L*L+MM )
END IF
*
* Note that 0 .le. R .le. 1 + 1/macheps
*
A = HALF*( S+R )
*
* Note that 1 .le. A .le. 1 + abs(M)
*
SSMIN = HA / A
SSMAX = FA*A
IF( MM.EQ.ZERO ) THEN
*
* Note that M is very tiny
*
IF( L.EQ.ZERO ) THEN
T = SIGN( TWO, FT )*SIGN( ONE, GT )
ELSE
T = GT / SIGN( D, FT ) + M / T
END IF
ELSE
T = ( M / ( S+T )+M / ( R+L ) )*( ONE+A )
END IF
L = SQRT( T*T+FOUR )
CRT = TWO / L
SRT = T / L
CLT = ( CRT+SRT*M ) / A
SLT = ( HT / FT )*SRT / A
END IF
END IF
IF( SWAP ) THEN
CSL = SRT
SNL = CRT
CSR = SLT
SNR = CLT
ELSE
CSL = CLT
SNL = SLT
CSR = CRT
SNR = SRT
END IF
*
* Correct signs of SSMAX and SSMIN
*
IF( PMAX.EQ.1 )
$ TSIGN = SIGN( ONE, CSR )*SIGN( ONE, CSL )*SIGN( ONE, F )
IF( PMAX.EQ.2 )
$ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, CSL )*SIGN( ONE, G )
IF( PMAX.EQ.3 )
$ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, SNL )*SIGN( ONE, H )
SSMAX = SIGN( SSMAX, TSIGN )
SSMIN = SIGN( SSMIN, TSIGN*SIGN( ONE, F )*SIGN( ONE, H ) )
RETURN
*
* End of SLASV2
*
END
| lgpl-3.0 |
huard/scipy-work | scipy/integrate/odepack/nnfc.f | 18 | 4938 | subroutine nnfc
* (n, r,c,ic, ia,ja,a, z, b,
* lmax,il,jl,ijl,l, d, umax,iu,ju,iju,u,
* row, tmp, irl,jrl, flag)
clll. optimize
c*** subroutine nnfc
c*** numerical ldu-factorization of sparse nonsymmetric matrix and
c solution of system of linear equations (compressed pointer
c storage)
c
c
c input variables.. n, r, c, ic, ia, ja, a, b,
c il, jl, ijl, lmax, iu, ju, iju, umax
c output variables.. z, l, d, u, flag
c
c parameters used internally..
c nia - irl, - vectors used to find the rows of l. at the kth step
c nia - jrl of the factorization, jrl(k) points to the head
c - of a linked list in jrl of column indices j
c - such j .lt. k and l(k,j) is nonzero. zero
c - indicates the end of the list. irl(j) (j.lt.k)
c - points to the smallest i such that i .ge. k and
c - l(i,j) is nonzero.
c - size of each = n.
c fia - row - holds intermediate values in calculation of u and l.
c - size = n.
c fia - tmp - holds new right-hand side b* for solution of the
c - equation ux = b*.
c - size = n.
c
c internal variables..
c jmin, jmax - indices of the first and last positions in a row to
c be examined.
c sum - used in calculating tmp.
c
integer rk,umax
integer r(1), c(1), ic(1), ia(1), ja(1), il(1), jl(1), ijl(1)
integer iu(1), ju(1), iju(1), irl(1), jrl(1), flag
double precision a(1), l(1), d(1), u(1), z(1), b(1), row(1)
double precision tmp(1), lki, sum, dk
c
c ****** initialize pointers and test storage ***********************
if(il(n+1)-1 .gt. lmax) go to 104
if(iu(n+1)-1 .gt. umax) go to 107
do 1 k=1,n
irl(k) = il(k)
jrl(k) = 0
1 continue
c
c ****** for each row ***********************************************
do 19 k=1,n
c ****** reverse jrl and zero row where kth row of l will fill in ***
row(k) = 0
i1 = 0
if (jrl(k) .eq. 0) go to 3
i = jrl(k)
2 i2 = jrl(i)
jrl(i) = i1
i1 = i
row(i) = 0
i = i2
if (i .ne. 0) go to 2
c ****** set row to zero where u will fill in ***********************
3 jmin = iju(k)
jmax = jmin + iu(k+1) - iu(k) - 1
if (jmin .gt. jmax) go to 5
do 4 j=jmin,jmax
4 row(ju(j)) = 0
c ****** place kth row of a in row **********************************
5 rk = r(k)
jmin = ia(rk)
jmax = ia(rk+1) - 1
do 6 j=jmin,jmax
row(ic(ja(j))) = a(j)
6 continue
c ****** initialize sum, and link through jrl ***********************
sum = b(rk)
i = i1
if (i .eq. 0) go to 10
c ****** assign the kth row of l and adjust row, sum ****************
7 lki = -row(i)
c ****** if l is not required, then comment out the following line **
l(irl(i)) = -lki
sum = sum + lki * tmp(i)
jmin = iu(i)
jmax = iu(i+1) - 1
if (jmin .gt. jmax) go to 9
mu = iju(i) - jmin
do 8 j=jmin,jmax
8 row(ju(mu+j)) = row(ju(mu+j)) + lki * u(j)
9 i = jrl(i)
if (i .ne. 0) go to 7
c
c ****** assign kth row of u and diagonal d, set tmp(k) *************
10 if (row(k) .eq. 0.0d0) go to 108
dk = 1.0d0 / row(k)
d(k) = dk
tmp(k) = sum * dk
if (k .eq. n) go to 19
jmin = iu(k)
jmax = iu(k+1) - 1
if (jmin .gt. jmax) go to 12
mu = iju(k) - jmin
do 11 j=jmin,jmax
11 u(j) = row(ju(mu+j)) * dk
12 continue
c
c ****** update irl and jrl, keeping jrl in decreasing order ********
i = i1
if (i .eq. 0) go to 18
14 irl(i) = irl(i) + 1
i1 = jrl(i)
if (irl(i) .ge. il(i+1)) go to 17
ijlb = irl(i) - il(i) + ijl(i)
j = jl(ijlb)
15 if (i .gt. jrl(j)) go to 16
j = jrl(j)
go to 15
16 jrl(i) = jrl(j)
jrl(j) = i
17 i = i1
if (i .ne. 0) go to 14
18 if (irl(k) .ge. il(k+1)) go to 19
j = jl(ijl(k))
jrl(k) = jrl(j)
jrl(j) = k
19 continue
c
c ****** solve ux = tmp by back substitution **********************
k = n
do 22 i=1,n
sum = tmp(k)
jmin = iu(k)
jmax = iu(k+1) - 1
if (jmin .gt. jmax) go to 21
mu = iju(k) - jmin
do 20 j=jmin,jmax
20 sum = sum - u(j) * tmp(ju(mu+j))
21 tmp(k) = sum
z(c(k)) = sum
22 k = k-1
flag = 0
return
c
c ** error.. insufficient storage for l
104 flag = 4*n + 1
return
c ** error.. insufficient storage for u
107 flag = 7*n + 1
return
c ** error.. zero pivot
108 flag = 8*n + k
return
end
| bsd-3-clause |
leo-butler/Maxima-CAS | src/numerical/slatec/fortran/dqawfe.f | 12 | 15821 | *DECK DQAWFE
SUBROUTINE DQAWFE (F, A, OMEGA, INTEGR, EPSABS, LIMLST, LIMIT,
+ MAXP1, RESULT, ABSERR, NEVAL, IER, RSLST, ERLST, IERLST, LST,
+ ALIST, BLIST, RLIST, ELIST, IORD, NNLOG, CHEBMO)
C***BEGIN PROLOGUE DQAWFE
C***PURPOSE The routine calculates an approximation result to a
C given Fourier integral
C I = Integral of F(X)*W(X) over (A,INFINITY)
C where W(X)=COS(OMEGA*X) or W(X)=SIN(OMEGA*X),
C hopefully satisfying following claim for accuracy
C ABS(I-RESULT).LE.EPSABS.
C***LIBRARY SLATEC (QUADPACK)
C***CATEGORY H2A3A1
C***TYPE DOUBLE PRECISION (QAWFE-S, DQAWFE-D)
C***KEYWORDS AUTOMATIC INTEGRATOR, CONVERGENCE ACCELERATION,
C FOURIER INTEGRALS, INTEGRATION BETWEEN ZEROS, QUADPACK,
C QUADRATURE, SPECIAL-PURPOSE INTEGRAL
C***AUTHOR Piessens, Robert
C Applied Mathematics and Programming Division
C K. U. Leuven
C de Doncker, Elise
C Applied Mathematics and Programming Division
C K. U. Leuven
C***DESCRIPTION
C
C Computation of Fourier integrals
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
C be 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 OMEGA - Double precision
C Parameter in the WEIGHT function
C
C INTEGR - Integer
C Indicates which WEIGHT function is used
C INTEGR = 1 W(X) = COS(OMEGA*X)
C INTEGR = 2 W(X) = SIN(OMEGA*X)
C If INTEGR.NE.1.AND.INTEGR.NE.2, the routine will
C end with IER = 6.
C
C EPSABS - Double precision
C absolute accuracy requested, EPSABS.GT.0
C If EPSABS.LE.0, the routine will end with IER = 6.
C
C LIMLST - Integer
C LIMLST gives an upper bound on the number of
C cycles, LIMLST.GE.1.
C If LIMLST.LT.3, the routine will end with IER = 6.
C
C LIMIT - Integer
C Gives an upper bound on the number of subintervals
C allowed in the partition of each cycle, LIMIT.GE.1
C each cycle, LIMIT.GE.1.
C
C MAXP1 - Integer
C Gives an upper bound on the number of
C Chebyshev moments which can be stored, I.E.
C for the intervals of lengths ABS(B-A)*2**(-L),
C L=0,1, ..., MAXP1-2, MAXP1.GE.1
C
C ON RETURN
C RESULT - Double precision
C Approximation to the integral X
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
C the routine. It is assumed that the
C requested accuracy has been achieved.
C IER.GT.0 Abnormal termination of the routine. The
C estimates for integral and error are less
C reliable. It is assumed that the requested
C accuracy has not been achieved.
C ERROR MESSAGES
C If OMEGA.NE.0
C IER = 1 Maximum number of cycles allowed
C Has been achieved., i.e. of subintervals
C (A+(K-1)C,A+KC) where
C C = (2*INT(ABS(OMEGA))+1)*PI/ABS(OMEGA),
C for K = 1, 2, ..., LST.
C One can allow more cycles by increasing
C the value of LIMLST (and taking the
C according dimension adjustments into
C account).
C Examine the array IWORK which contains
C the error flags on the cycles, in order to
C look for eventual local integration
C difficulties. If the position of a local
C difficulty can be determined (e.g.
C SINGULARITY, DISCONTINUITY within the
C interval) one will probably gain from
C splitting up the interval at this point
C and calling appropriate integrators on
C the subranges.
C = 4 The extrapolation table constructed for
C convergence acceleration of the series
C formed by the integral contributions over
C the cycles, does not converge to within
C the requested accuracy. As in the case of
C IER = 1, it is advised to examine the
C array IWORK which contains the error
C flags on the cycles.
C = 6 The input is invalid because
C (INTEGR.NE.1 AND INTEGR.NE.2) or
C EPSABS.LE.0 or LIMLST.LT.3.
C RESULT, ABSERR, NEVAL, LST are set
C to zero.
C = 7 Bad integrand behaviour occurs within one
C or more of the cycles. Location and type
C of the difficulty involved can be
C determined from the vector IERLST. Here
C LST is the number of cycles actually
C needed (see below).
C IERLST(K) = 1 The maximum number of
C subdivisions (= LIMIT) has
C been achieved on the K th
C cycle.
C = 2 Occurrence of roundoff error
C is detected and prevents the
C tolerance imposed on the
C K th cycle, from being
C achieved.
C = 3 Extremely bad integrand
C behaviour occurs at some
C points of the K th cycle.
C = 4 The integration procedure
C over the K th cycle does
C not converge (to within the
C required accuracy) due to
C roundoff in the
C extrapolation procedure
C invoked on this cycle. It
C is assumed that the result
C on this interval is the
C best which can be obtained.
C = 5 The integral over the K th
C cycle is probably divergent
C or slowly convergent. It
C must be noted that
C divergence can occur with
C any other value of
C IERLST(K).
C If OMEGA = 0 and INTEGR = 1,
C The integral is calculated by means of DQAGIE
C and IER = IERLST(1) (with meaning as described
C for IERLST(K), K = 1).
C
C RSLST - Double precision
C Vector of dimension at least LIMLST
C RSLST(K) contains the integral contribution
C over the interval (A+(K-1)C,A+KC) where
C C = (2*INT(ABS(OMEGA))+1)*PI/ABS(OMEGA),
C K = 1, 2, ..., LST.
C Note that, if OMEGA = 0, RSLST(1) contains
C the value of the integral over (A,INFINITY).
C
C ERLST - Double precision
C Vector of dimension at least LIMLST
C ERLST(K) contains the error estimate corresponding
C with RSLST(K).
C
C IERLST - Integer
C Vector of dimension at least LIMLST
C IERLST(K) contains the error flag corresponding
C with RSLST(K). For the meaning of the local error
C flags see description of output parameter IER.
C
C LST - Integer
C Number of subintervals needed for the integration
C If OMEGA = 0 then LST is set to 1.
C
C ALIST, BLIST, RLIST, ELIST - Double precision
C vector of dimension at least LIMIT,
C
C IORD, NNLOG - Integer
C Vector of dimension at least LIMIT, providing
C space for the quantities needed in the subdivision
C process of each cycle
C
C CHEBMO - Double precision
C Array of dimension at least (MAXP1,25), providing
C space for the Chebyshev moments needed within the
C cycles
C
C***REFERENCES (NONE)
C***ROUTINES CALLED D1MACH, DQAGIE, DQAWOE, DQELG
C***REVISION HISTORY (YYMMDD)
C 800101 DATE WRITTEN
C 890531 Changed all specific intrinsics to generic. (WRB)
C 890831 Modified array declarations. (WRB)
C 891009 Removed unreferenced variable. (WRB)
C 891009 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C***END PROLOGUE DQAWFE
C
DOUBLE PRECISION A,ABSEPS,ABSERR,ALIST,BLIST,CHEBMO,CORREC,CYCLE,
1 C1,C2,DL,DRL,D1MACH,ELIST,ERLST,EP,EPS,EPSA,
2 EPSABS,ERRSUM,F,FACT,OMEGA,P,PI,P1,PSUM,RESEPS,RESULT,RES3LA,
3 RLIST,RSLST,UFLOW
INTEGER IER,IERLST,INTEGR,IORD,KTMIN,L,LAST,LST,LIMIT,LIMLST,LL,
1 MAXP1,MOMCOM,NEV,NEVAL,NNLOG,NRES,NUMRL2
C
DIMENSION ALIST(*),BLIST(*),CHEBMO(MAXP1,25),ELIST(*),
1 ERLST(*),IERLST(*),IORD(*),NNLOG(*),PSUM(52),
2 RES3LA(3),RLIST(*),RSLST(*)
C
EXTERNAL F
C
C
C THE DIMENSION OF PSUM IS DETERMINED BY THE VALUE OF
C LIMEXP IN SUBROUTINE DQELG (PSUM MUST BE OF DIMENSION
C (LIMEXP+2) AT LEAST).
C
C LIST OF MAJOR VARIABLES
C -----------------------
C
C C1, C2 - END POINTS OF SUBINTERVAL (OF LENGTH CYCLE)
C CYCLE - (2*INT(ABS(OMEGA))+1)*PI/ABS(OMEGA)
C PSUM - VECTOR OF DIMENSION AT LEAST (LIMEXP+2)
C (SEE ROUTINE DQELG)
C PSUM CONTAINS THE PART OF THE EPSILON TABLE
C WHICH IS STILL NEEDED FOR FURTHER COMPUTATIONS.
C EACH ELEMENT OF PSUM IS A PARTIAL SUM OF THE
C SERIES WHICH SHOULD SUM TO THE VALUE OF THE
C INTEGRAL.
C ERRSUM - SUM OF ERROR ESTIMATES OVER THE SUBINTERVALS,
C CALCULATED CUMULATIVELY
C EPSA - ABSOLUTE TOLERANCE REQUESTED OVER CURRENT
C SUBINTERVAL
C CHEBMO - ARRAY CONTAINING THE MODIFIED CHEBYSHEV
C MOMENTS (SEE ALSO ROUTINE DQC25F)
C
SAVE P, PI
DATA P/0.9D+00/
DATA PI / 3.1415926535 8979323846 2643383279 50 D0 /
C
C TEST ON VALIDITY OF PARAMETERS
C ------------------------------
C
C***FIRST EXECUTABLE STATEMENT DQAWFE
RESULT = 0.0D+00
ABSERR = 0.0D+00
NEVAL = 0
LST = 0
IER = 0
IF((INTEGR.NE.1.AND.INTEGR.NE.2).OR.EPSABS.LE.0.0D+00.OR.
1 LIMLST.LT.3) IER = 6
IF(IER.EQ.6) GO TO 999
IF(OMEGA.NE.0.0D+00) GO TO 10
C
C INTEGRATION BY DQAGIE IF OMEGA IS ZERO
C --------------------------------------
C
IF(INTEGR.EQ.1) CALL DQAGIE(F,A,1,EPSABS,0.0D+00,LIMIT,
1 RESULT,ABSERR,NEVAL,IER,ALIST,BLIST,RLIST,ELIST,IORD,LAST)
RSLST(1) = RESULT
ERLST(1) = ABSERR
IERLST(1) = IER
LST = 1
GO TO 999
C
C INITIALIZATIONS
C ---------------
C
10 L = ABS(OMEGA)
DL = 2*L+1
CYCLE = DL*PI/ABS(OMEGA)
IER = 0
KTMIN = 0
NEVAL = 0
NUMRL2 = 0
NRES = 0
C1 = A
C2 = CYCLE+A
P1 = 0.1D+01-P
UFLOW = D1MACH(1)
EPS = EPSABS
IF(EPSABS.GT.UFLOW/P1) EPS = EPSABS*P1
EP = EPS
FACT = 0.1D+01
CORREC = 0.0D+00
ABSERR = 0.0D+00
ERRSUM = 0.0D+00
C
C MAIN DO-LOOP
C ------------
C
DO 50 LST = 1,LIMLST
C
C INTEGRATE OVER CURRENT SUBINTERVAL.
C
EPSA = EPS*FACT
CALL DQAWOE(F,C1,C2,OMEGA,INTEGR,EPSA,0.0D+00,LIMIT,LST,MAXP1,
1 RSLST(LST),ERLST(LST),NEV,IERLST(LST),LAST,ALIST,BLIST,RLIST,
2 ELIST,IORD,NNLOG,MOMCOM,CHEBMO)
NEVAL = NEVAL+NEV
FACT = FACT*P
ERRSUM = ERRSUM+ERLST(LST)
DRL = 0.5D+02*ABS(RSLST(LST))
C
C TEST ON ACCURACY WITH PARTIAL SUM
C
IF((ERRSUM+DRL).LE.EPSABS.AND.LST.GE.6) GO TO 80
CORREC = MAX(CORREC,ERLST(LST))
IF(IERLST(LST).NE.0) EPS = MAX(EP,CORREC*P1)
IF(IERLST(LST).NE.0) IER = 7
IF(IER.EQ.7.AND.(ERRSUM+DRL).LE.CORREC*0.1D+02.AND.
1 LST.GT.5) GO TO 80
NUMRL2 = NUMRL2+1
IF(LST.GT.1) GO TO 20
PSUM(1) = RSLST(1)
GO TO 40
20 PSUM(NUMRL2) = PSUM(LL)+RSLST(LST)
IF(LST.EQ.2) GO TO 40
C
C TEST ON MAXIMUM NUMBER OF SUBINTERVALS
C
IF(LST.EQ.LIMLST) IER = 1
C
C PERFORM NEW EXTRAPOLATION
C
CALL DQELG(NUMRL2,PSUM,RESEPS,ABSEPS,RES3LA,NRES)
C
C TEST WHETHER EXTRAPOLATED RESULT IS INFLUENCED BY ROUNDOFF
C
KTMIN = KTMIN+1
IF(KTMIN.GE.15.AND.ABSERR.LE.0.1D-02*(ERRSUM+DRL)) IER = 4
IF(ABSEPS.GT.ABSERR.AND.LST.NE.3) GO TO 30
ABSERR = ABSEPS
RESULT = RESEPS
KTMIN = 0
C
C IF IER IS NOT 0, CHECK WHETHER DIRECT RESULT (PARTIAL SUM)
C OR EXTRAPOLATED RESULT YIELDS THE BEST INTEGRAL
C APPROXIMATION
C
IF((ABSERR+0.1D+02*CORREC).LE.EPSABS.OR.
1 (ABSERR.LE.EPSABS.AND.0.1D+02*CORREC.GE.EPSABS)) GO TO 60
30 IF(IER.NE.0.AND.IER.NE.7) GO TO 60
40 LL = NUMRL2
C1 = C2
C2 = C2+CYCLE
50 CONTINUE
C
C SET FINAL RESULT AND ERROR ESTIMATE
C -----------------------------------
C
60 ABSERR = ABSERR+0.1D+02*CORREC
IF(IER.EQ.0) GO TO 999
IF(RESULT.NE.0.0D+00.AND.PSUM(NUMRL2).NE.0.0D+00) GO TO 70
IF(ABSERR.GT.ERRSUM) GO TO 80
IF(PSUM(NUMRL2).EQ.0.0D+00) GO TO 999
70 IF(ABSERR/ABS(RESULT).GT.(ERRSUM+DRL)/ABS(PSUM(NUMRL2)))
1 GO TO 80
IF(IER.GE.1.AND.IER.NE.7) ABSERR = ABSERR+DRL
GO TO 999
80 RESULT = PSUM(NUMRL2)
ABSERR = ERRSUM+DRL
999 RETURN
END
| gpl-2.0 |
aamaricci/SciFortran | src/lapack/cptsvx.f | 1 | 8615 | SUBROUTINE CPTSVX( FACT, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,
$ RCOND, FERR, BERR, WORK, RWORK, 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 --
*
* .. Scalar Arguments ..
CHARACTER FACT
INTEGER INFO, LDB, LDX, N, NRHS
REAL RCOND
* ..
* .. Array Arguments ..
REAL BERR( * ), D( * ), DF( * ), FERR( * ),
$ RWORK( * )
COMPLEX B( LDB, * ), E( * ), EF( * ), WORK( * ),
$ X( LDX, * )
* ..
*
* Purpose
* =======
*
* CPTSVX uses the factorization A = L*D*L**H to compute the solution
* to a complex system of linear equations A*X = B, where A is an
* N-by-N Hermitian positive definite tridiagonal matrix and X and B
* are N-by-NRHS matrices.
*
* Error bounds on the solution and a condition estimate are also
* provided.
*
* Description
* ===========
*
* The following steps are performed:
*
* 1. If FACT = 'N', the matrix A is factored as A = L*D*L**H, where L
* is a unit lower bidiagonal matrix and D is diagonal. The
* factorization can also be regarded as having the form
* A = U**H*D*U.
*
* 2. If the leading i-by-i principal minor is not positive definite,
* 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.
*
* Arguments
* =========
*
* FACT (input) CHARACTER*1
* Specifies whether or not the factored form of the matrix
* A is supplied on entry.
* = 'F': On entry, DF and EF contain the factored form of A.
* D, E, DF, and EF will not be modified.
* = 'N': The matrix A will be copied to DF and EF and
* factored.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrices B and X. NRHS >= 0.
*
* D (input) REAL array, dimension (N)
* The n diagonal elements of the tridiagonal matrix A.
*
* E (input) COMPLEX array, dimension (N-1)
* The (n-1) subdiagonal elements of the tridiagonal matrix A.
*
* DF (input or output) REAL array, dimension (N)
* If FACT = 'F', then DF is an input argument and on entry
* contains the n diagonal elements of the diagonal matrix D
* from the L*D*L**H factorization of A.
* If FACT = 'N', then DF is an output argument and on exit
* contains the n diagonal elements of the diagonal matrix D
* from the L*D*L**H factorization of A.
*
* EF (input or output) COMPLEX array, dimension (N-1)
* If FACT = 'F', then EF is an input argument and on entry
* contains the (n-1) subdiagonal elements of the unit
* bidiagonal factor L from the L*D*L**H factorization of A.
* If FACT = 'N', then EF is an output argument and on exit
* contains the (n-1) subdiagonal elements of the unit
* bidiagonal factor L from the L*D*L**H factorization of A.
*
* B (input) COMPLEX array, dimension (LDB,NRHS)
* The N-by-NRHS right hand side matrix B.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* X (output) COMPLEX array, dimension (LDX,NRHS)
* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X.
*
* LDX (input) INTEGER
* The leading dimension of the array X. LDX >= max(1,N).
*
* RCOND (output) REAL
* 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.
*
* FERR (output) REAL array, dimension (NRHS)
* The 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).
*
* BERR (output) 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).
*
* WORK (workspace) COMPLEX array, dimension (N)
*
* RWORK (workspace) REAL array, dimension (N)
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, and i is
* <= N: the leading minor of order i of A is
* not positive definite, so the factorization
* could not be completed, and the solution has not
* been 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.
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL NOFACT
REAL ANORM
* ..
* .. External Functions ..
LOGICAL LSAME
REAL CLANHT, SLAMCH
EXTERNAL LSAME, CLANHT, SLAMCH
* ..
* .. External Subroutines ..
EXTERNAL CCOPY, CLACPY, CPTCON, CPTRFS, CPTTRF, CPTTRS,
$ SCOPY, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
NOFACT = LSAME( FACT, 'N' )
IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( NRHS.LT.0 ) THEN
INFO = -3
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
INFO = -11
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CPTSVX', -INFO )
RETURN
END IF
*
IF( NOFACT ) THEN
*
* Compute the L*D*L**H (or U**H*D*U) factorization of A.
*
CALL SCOPY( N, D, 1, DF, 1 )
IF( N.GT.1 )
$ CALL CCOPY( N-1, E, 1, EF, 1 )
CALL CPTTRF( N, DF, EF, 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.
*
ANORM = CLANHT( '1', N, D, E )
*
* Compute the reciprocal of the condition number of A.
*
CALL CPTCON( N, DF, EF, ANORM, RCOND, RWORK, INFO )
*
* Compute the solution vectors X.
*
CALL CLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
CALL CPTTRS( 'Lower', N, NRHS, DF, EF, X, LDX, INFO )
*
* Use iterative refinement to improve the computed solutions and
* compute error bounds and backward error estimates for them.
*
CALL CPTRFS( 'Lower', N, NRHS, D, E, DF, EF, B, LDB, X, LDX, FERR,
$ BERR, WORK, RWORK, INFO )
*
* Set INFO = N+1 if the matrix is singular to working precision.
*
IF( RCOND.LT.SLAMCH( 'Epsilon' ) )
$ INFO = N + 1
*
RETURN
*
* End of CPTSVX
*
END
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/cunbdb4.f | 22 | 12620 | *> \brief \b CUNBDB4
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CUNBDB4 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cunbdb4.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cunbdb4.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cunbdb4.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CUNBDB4( M, P, Q, X11, LDX11, X21, LDX21, THETA, PHI,
* TAUP1, TAUP2, TAUQ1, PHANTOM, WORK, LWORK,
* INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LWORK, M, P, Q, LDX11, LDX21
* ..
* .. Array Arguments ..
* REAL PHI(*), THETA(*)
* COMPLEX PHANTOM(*), TAUP1(*), TAUP2(*), TAUQ1(*),
* $ WORK(*), X11(LDX11,*), X21(LDX21,*)
* ..
*
*
*> \par Purpose:
*> =============
*>
*>\verbatim
*>
*> CUNBDB4 simultaneously bidiagonalizes the blocks of a tall and skinny
*> matrix X with orthonomal columns:
*>
*> [ B11 ]
*> [ X11 ] [ P1 | ] [ 0 ]
*> [-----] = [---------] [-----] Q1**T .
*> [ X21 ] [ | P2 ] [ B21 ]
*> [ 0 ]
*>
*> X11 is P-by-Q, and X21 is (M-P)-by-Q. M-Q must be no larger than P,
*> M-P, or Q. Routines CUNBDB1, CUNBDB2, and CUNBDB3 handle cases in
*> which M-Q is not the minimum dimension.
*>
*> The unitary matrices P1, P2, and Q1 are P-by-P, (M-P)-by-(M-P),
*> and (M-Q)-by-(M-Q), respectively. They are represented implicitly by
*> Householder vectors.
*>
*> B11 and B12 are (M-Q)-by-(M-Q) bidiagonal matrices represented
*> implicitly by angles THETA, PHI.
*>
*>\endverbatim
*
* Arguments:
* ==========
*
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows X11 plus the number of rows in X21.
*> \endverbatim
*>
*> \param[in] P
*> \verbatim
*> P is INTEGER
*> The number of rows in X11. 0 <= P <= M.
*> \endverbatim
*>
*> \param[in] Q
*> \verbatim
*> Q is INTEGER
*> The number of columns in X11 and X21. 0 <= Q <= M and
*> M-Q <= min(P,M-P,Q).
*> \endverbatim
*>
*> \param[in,out] X11
*> \verbatim
*> X11 is COMPLEX array, dimension (LDX11,Q)
*> On entry, the top block of the matrix X to be reduced. On
*> exit, the columns of tril(X11) specify reflectors for P1 and
*> the rows of triu(X11,1) specify reflectors for Q1.
*> \endverbatim
*>
*> \param[in] LDX11
*> \verbatim
*> LDX11 is INTEGER
*> The leading dimension of X11. LDX11 >= P.
*> \endverbatim
*>
*> \param[in,out] X21
*> \verbatim
*> X21 is COMPLEX array, dimension (LDX21,Q)
*> On entry, the bottom block of the matrix X to be reduced. On
*> exit, the columns of tril(X21) specify reflectors for P2.
*> \endverbatim
*>
*> \param[in] LDX21
*> \verbatim
*> LDX21 is INTEGER
*> The leading dimension of X21. LDX21 >= M-P.
*> \endverbatim
*>
*> \param[out] THETA
*> \verbatim
*> THETA is REAL array, dimension (Q)
*> The entries of the bidiagonal blocks B11, B21 are defined by
*> THETA and PHI. See Further Details.
*> \endverbatim
*>
*> \param[out] PHI
*> \verbatim
*> PHI is REAL array, dimension (Q-1)
*> The entries of the bidiagonal blocks B11, B21 are defined by
*> THETA and PHI. See Further Details.
*> \endverbatim
*>
*> \param[out] TAUP1
*> \verbatim
*> TAUP1 is COMPLEX array, dimension (P)
*> The scalar factors of the elementary reflectors that define
*> P1.
*> \endverbatim
*>
*> \param[out] TAUP2
*> \verbatim
*> TAUP2 is COMPLEX array, dimension (M-P)
*> The scalar factors of the elementary reflectors that define
*> P2.
*> \endverbatim
*>
*> \param[out] TAUQ1
*> \verbatim
*> TAUQ1 is COMPLEX array, dimension (Q)
*> The scalar factors of the elementary reflectors that define
*> Q1.
*> \endverbatim
*>
*> \param[out] PHANTOM
*> \verbatim
*> PHANTOM is COMPLEX array, dimension (M)
*> The routine computes an M-by-1 column vector Y that is
*> orthogonal to the columns of [ X11; X21 ]. PHANTOM(1:P) and
*> PHANTOM(P+1:M) contain Householder vectors for Y(1:P) and
*> Y(P+1:M), respectively.
*> \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 >= M-Q.
*>
*> 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 July 2012
*
*> \ingroup complexOTHERcomputational
*
*> \par Further Details:
* =====================
*> \verbatim
*>
*> The upper-bidiagonal blocks B11, B21 are represented implicitly by
*> angles THETA(1), ..., THETA(Q) and PHI(1), ..., PHI(Q-1). Every entry
*> in each bidiagonal band is a product of a sine or cosine of a THETA
*> with a sine or cosine of a PHI. See [1] or CUNCSD for details.
*>
*> P1, P2, and Q1 are represented as products of elementary reflectors.
*> See CUNCSD2BY1 for details on generating P1, P2, and Q1 using CUNGQR
*> and CUNGLQ.
*> \endverbatim
*
*> \par References:
* ================
*>
*> [1] Brian D. Sutton. Computing the complete CS decomposition. Numer.
*> Algorithms, 50(1):33-65, 2009.
*>
* =====================================================================
SUBROUTINE CUNBDB4( M, P, Q, X11, LDX11, X21, LDX21, THETA, PHI,
$ TAUP1, TAUP2, TAUQ1, PHANTOM, 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..--
* July 2012
*
* .. Scalar Arguments ..
INTEGER INFO, LWORK, M, P, Q, LDX11, LDX21
* ..
* .. Array Arguments ..
REAL PHI(*), THETA(*)
COMPLEX PHANTOM(*), TAUP1(*), TAUP2(*), TAUQ1(*),
$ WORK(*), X11(LDX11,*), X21(LDX21,*)
* ..
*
* ====================================================================
*
* .. Parameters ..
COMPLEX NEGONE, ONE, ZERO
PARAMETER ( NEGONE = (-1.0E0,0.0E0), ONE = (1.0E0,0.0E0),
$ ZERO = (0.0E0,0.0E0) )
* ..
* .. Local Scalars ..
REAL C, S
INTEGER CHILDINFO, I, ILARF, IORBDB5, J, LLARF,
$ LORBDB5, LWORKMIN, LWORKOPT
LOGICAL LQUERY
* ..
* .. External Subroutines ..
EXTERNAL CLARF, CLARFGP, CUNBDB5, CSROT, CSCAL, XERBLA
* ..
* .. External Functions ..
REAL SCNRM2
EXTERNAL SCNRM2
* ..
* .. Intrinsic Function ..
INTRINSIC ATAN2, COS, MAX, SIN, SQRT
* ..
* .. Executable Statements ..
*
* Test input arguments
*
INFO = 0
LQUERY = LWORK .EQ. -1
*
IF( M .LT. 0 ) THEN
INFO = -1
ELSE IF( P .LT. M-Q .OR. M-P .LT. M-Q ) THEN
INFO = -2
ELSE IF( Q .LT. M-Q .OR. Q .GT. M ) THEN
INFO = -3
ELSE IF( LDX11 .LT. MAX( 1, P ) ) THEN
INFO = -5
ELSE IF( LDX21 .LT. MAX( 1, M-P ) ) THEN
INFO = -7
END IF
*
* Compute workspace
*
IF( INFO .EQ. 0 ) THEN
ILARF = 2
LLARF = MAX( Q-1, P-1, M-P-1 )
IORBDB5 = 2
LORBDB5 = Q
LWORKOPT = ILARF + LLARF - 1
LWORKOPT = MAX( LWORKOPT, IORBDB5 + LORBDB5 - 1 )
LWORKMIN = LWORKOPT
WORK(1) = LWORKOPT
IF( LWORK .LT. LWORKMIN .AND. .NOT.LQUERY ) THEN
INFO = -14
END IF
END IF
IF( INFO .NE. 0 ) THEN
CALL XERBLA( 'CUNBDB4', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Reduce columns 1, ..., M-Q of X11 and X21
*
DO I = 1, M-Q
*
IF( I .EQ. 1 ) THEN
DO J = 1, M
PHANTOM(J) = ZERO
END DO
CALL CUNBDB5( P, M-P, Q, PHANTOM(1), 1, PHANTOM(P+1), 1,
$ X11, LDX11, X21, LDX21, WORK(IORBDB5),
$ LORBDB5, CHILDINFO )
CALL CSCAL( P, NEGONE, PHANTOM(1), 1 )
CALL CLARFGP( P, PHANTOM(1), PHANTOM(2), 1, TAUP1(1) )
CALL CLARFGP( M-P, PHANTOM(P+1), PHANTOM(P+2), 1, TAUP2(1) )
THETA(I) = ATAN2( REAL( PHANTOM(1) ), REAL( PHANTOM(P+1) ) )
C = COS( THETA(I) )
S = SIN( THETA(I) )
PHANTOM(1) = ONE
PHANTOM(P+1) = ONE
CALL CLARF( 'L', P, Q, PHANTOM(1), 1, CONJG(TAUP1(1)), X11,
$ LDX11, WORK(ILARF) )
CALL CLARF( 'L', M-P, Q, PHANTOM(P+1), 1, CONJG(TAUP2(1)),
$ X21, LDX21, WORK(ILARF) )
ELSE
CALL CUNBDB5( P-I+1, M-P-I+1, Q-I+1, X11(I,I-1), 1,
$ X21(I,I-1), 1, X11(I,I), LDX11, X21(I,I),
$ LDX21, WORK(IORBDB5), LORBDB5, CHILDINFO )
CALL CSCAL( P-I+1, NEGONE, X11(I,I-1), 1 )
CALL CLARFGP( P-I+1, X11(I,I-1), X11(I+1,I-1), 1, TAUP1(I) )
CALL CLARFGP( M-P-I+1, X21(I,I-1), X21(I+1,I-1), 1,
$ TAUP2(I) )
THETA(I) = ATAN2( REAL( X11(I,I-1) ), REAL( X21(I,I-1) ) )
C = COS( THETA(I) )
S = SIN( THETA(I) )
X11(I,I-1) = ONE
X21(I,I-1) = ONE
CALL CLARF( 'L', P-I+1, Q-I+1, X11(I,I-1), 1,
$ CONJG(TAUP1(I)), X11(I,I), LDX11, WORK(ILARF) )
CALL CLARF( 'L', M-P-I+1, Q-I+1, X21(I,I-1), 1,
$ CONJG(TAUP2(I)), X21(I,I), LDX21, WORK(ILARF) )
END IF
*
CALL CSROT( Q-I+1, X11(I,I), LDX11, X21(I,I), LDX21, S, -C )
CALL CLACGV( Q-I+1, X21(I,I), LDX21 )
CALL CLARFGP( Q-I+1, X21(I,I), X21(I,I+1), LDX21, TAUQ1(I) )
C = REAL( X21(I,I) )
X21(I,I) = ONE
CALL CLARF( 'R', P-I, Q-I+1, X21(I,I), LDX21, TAUQ1(I),
$ X11(I+1,I), LDX11, WORK(ILARF) )
CALL CLARF( 'R', M-P-I, Q-I+1, X21(I,I), LDX21, TAUQ1(I),
$ X21(I+1,I), LDX21, WORK(ILARF) )
CALL CLACGV( Q-I+1, X21(I,I), LDX21 )
IF( I .LT. M-Q ) THEN
S = SQRT( SCNRM2( P-I, X11(I+1,I), 1, X11(I+1,I),
$ 1 )**2 + SCNRM2( M-P-I, X21(I+1,I), 1, X21(I+1,I),
$ 1 )**2 )
PHI(I) = ATAN2( S, C )
END IF
*
END DO
*
* Reduce the bottom-right portion of X11 to [ I 0 ]
*
DO I = M - Q + 1, P
CALL CLACGV( Q-I+1, X11(I,I), LDX11 )
CALL CLARFGP( Q-I+1, X11(I,I), X11(I,I+1), LDX11, TAUQ1(I) )
X11(I,I) = ONE
CALL CLARF( 'R', P-I, Q-I+1, X11(I,I), LDX11, TAUQ1(I),
$ X11(I+1,I), LDX11, WORK(ILARF) )
CALL CLARF( 'R', Q-P, Q-I+1, X11(I,I), LDX11, TAUQ1(I),
$ X21(M-Q+1,I), LDX21, WORK(ILARF) )
CALL CLACGV( Q-I+1, X11(I,I), LDX11 )
END DO
*
* Reduce the bottom-right portion of X21 to [ 0 I ]
*
DO I = P + 1, Q
CALL CLACGV( Q-I+1, X21(M-Q+I-P,I), LDX21 )
CALL CLARFGP( Q-I+1, X21(M-Q+I-P,I), X21(M-Q+I-P,I+1), LDX21,
$ TAUQ1(I) )
X21(M-Q+I-P,I) = ONE
CALL CLARF( 'R', Q-I, Q-I+1, X21(M-Q+I-P,I), LDX21, TAUQ1(I),
$ X21(M-Q+I-P+1,I), LDX21, WORK(ILARF) )
CALL CLACGV( Q-I+1, X21(M-Q+I-P,I), LDX21 )
END DO
*
RETURN
*
* End of CUNBDB4
*
END
| apache-2.0 |
OpenDA-Association/OpenDA | core/native/external/lapack/zpteqr.f | 2 | 6109 | SUBROUTINE ZPTEQR( COMPZ, N, D, E, Z, LDZ, 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 COMPZ
INTEGER INFO, LDZ, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION D( * ), E( * ), WORK( * )
COMPLEX*16 Z( LDZ, * )
* ..
*
* Purpose
* =======
*
* ZPTEQR computes all eigenvalues and, optionally, eigenvectors of a
* symmetric positive definite tridiagonal matrix by first factoring the
* matrix using DPTTRF and then calling ZBDSQR to compute the singular
* values of the bidiagonal factor.
*
* This routine computes the eigenvalues of the positive definite
* tridiagonal matrix to high relative accuracy. This means that if the
* eigenvalues range over many orders of magnitude in size, then the
* small eigenvalues and corresponding eigenvectors will be computed
* more accurately than, for example, with the standard QR method.
*
* The eigenvectors of a full or band positive definite Hermitian matrix
* can also be found if ZHETRD, ZHPTRD, or ZHBTRD has been used to
* reduce this matrix to tridiagonal form. (The reduction to
* tridiagonal form, however, may preclude the possibility of obtaining
* high relative accuracy in the small eigenvalues of the original
* matrix, if these eigenvalues range over many orders of magnitude.)
*
* Arguments
* =========
*
* COMPZ (input) CHARACTER*1
* = 'N': Compute eigenvalues only.
* = 'V': Compute eigenvectors of original Hermitian
* matrix also. Array Z contains the unitary matrix
* used to reduce the original matrix to tridiagonal
* form.
* = 'I': Compute eigenvectors of tridiagonal matrix also.
*
* N (input) INTEGER
* The order of the matrix. N >= 0.
*
* D (input/output) DOUBLE PRECISION array, dimension (N)
* On entry, the n diagonal elements of the tridiagonal matrix.
* On normal exit, D contains the eigenvalues, in descending
* order.
*
* E (input/output) DOUBLE PRECISION array, dimension (N-1)
* On entry, the (n-1) subdiagonal elements of the tridiagonal
* matrix.
* On exit, E has been destroyed.
*
* Z (input/output) COMPLEX*16 array, dimension (LDZ, N)
* On entry, if COMPZ = 'V', the unitary matrix used in the
* reduction to tridiagonal form.
* On exit, if COMPZ = 'V', the orthonormal eigenvectors of the
* original Hermitian matrix;
* if COMPZ = 'I', the orthonormal eigenvectors of the
* tridiagonal matrix.
* If INFO > 0 on exit, Z contains the eigenvectors associated
* with only the stored eigenvalues.
* If COMPZ = 'N', then Z is not referenced.
*
* LDZ (input) INTEGER
* The leading dimension of the array Z. LDZ >= 1, and if
* COMPZ = 'V' or 'I', LDZ >= max(1,N).
*
* 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: if INFO = i, and i is:
* <= N the Cholesky factorization of the matrix could
* not be performed because the i-th principal minor
* was not positive definite.
* > N the SVD algorithm failed to converge;
* if INFO = N+i, i off-diagonal elements of the
* bidiagonal factor did not converge to zero.
*
* ====================================================================
*
* .. Parameters ..
COMPLEX*16 CZERO, CONE
PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
$ CONE = ( 1.0D+0, 0.0D+0 ) )
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DPTTRF, XERBLA, ZBDSQR, ZLASET
* ..
* .. Local Arrays ..
COMPLEX*16 C( 1, 1 ), VT( 1, 1 )
* ..
* .. Local Scalars ..
INTEGER I, ICOMPZ, NRU
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, SQRT
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
*
IF( LSAME( COMPZ, 'N' ) ) THEN
ICOMPZ = 0
ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
ICOMPZ = 1
ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
ICOMPZ = 2
ELSE
ICOMPZ = -1
END IF
IF( ICOMPZ.LT.0 ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( ( LDZ.LT.1 ) .OR. ( ICOMPZ.GT.0 .AND. LDZ.LT.MAX( 1,
$ N ) ) ) THEN
INFO = -6
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZPTEQR', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
IF( N.EQ.1 ) THEN
IF( ICOMPZ.GT.0 )
$ Z( 1, 1 ) = CONE
RETURN
END IF
IF( ICOMPZ.EQ.2 )
$ CALL ZLASET( 'Full', N, N, CZERO, CONE, Z, LDZ )
*
* Call DPTTRF to factor the matrix.
*
CALL DPTTRF( N, D, E, INFO )
IF( INFO.NE.0 )
$ RETURN
DO 10 I = 1, N
D( I ) = SQRT( D( I ) )
10 CONTINUE
DO 20 I = 1, N - 1
E( I ) = E( I )*D( I )
20 CONTINUE
*
* Call ZBDSQR to compute the singular values/vectors of the
* bidiagonal factor.
*
IF( ICOMPZ.GT.0 ) THEN
NRU = N
ELSE
NRU = 0
END IF
CALL ZBDSQR( 'Lower', N, 0, NRU, 0, D, E, VT, 1, Z, LDZ, C, 1,
$ WORK, INFO )
*
* Square the singular values.
*
IF( INFO.EQ.0 ) THEN
DO 30 I = 1, N
D( I ) = D( I )*D( I )
30 CONTINUE
ELSE
INFO = N + INFO
END IF
*
RETURN
*
* End of ZPTEQR
*
END
| lgpl-3.0 |
sradanov/flyingpigeon | flyingpigeon/Fsrc/Lapack/SRC/dlaqp2.f | 25 | 7694 | *> \brief \b DLAQP2 computes a QR factorization with column pivoting of the matrix block.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DLAQP2 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaqp2.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaqp2.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaqp2.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DLAQP2( M, N, OFFSET, A, LDA, JPVT, TAU, VN1, VN2,
* WORK )
*
* .. Scalar Arguments ..
* INTEGER LDA, M, N, OFFSET
* ..
* .. Array Arguments ..
* INTEGER JPVT( * )
* DOUBLE PRECISION A( LDA, * ), TAU( * ), VN1( * ), VN2( * ),
* $ WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DLAQP2 computes a QR factorization with column pivoting of
*> the block A(OFFSET+1:M,1:N).
*> The block A(1:OFFSET,1:N) is accordingly pivoted, but not factorized.
*> \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] OFFSET
*> \verbatim
*> OFFSET is INTEGER
*> The number of rows of the matrix A that must be pivoted
*> but no factorized. OFFSET >= 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, the upper triangle of block A(OFFSET+1:M,1:N) is
*> the triangular factor obtained; the elements in block
*> A(OFFSET+1:M,1:N) below the diagonal, together with the
*> array TAU, represent the orthogonal matrix Q as a product of
*> elementary reflectors. Block A(1:OFFSET,1:N) has been
*> accordingly pivoted, but no factorized.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,M).
*> \endverbatim
*>
*> \param[in,out] JPVT
*> \verbatim
*> JPVT is INTEGER array, dimension (N)
*> On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted
*> to the front of A*P (a leading column); if JPVT(i) = 0,
*> the i-th column of A is a free column.
*> On exit, if JPVT(i) = k, then the i-th column of A*P
*> was the k-th column of A.
*> \endverbatim
*>
*> \param[out] TAU
*> \verbatim
*> TAU is DOUBLE PRECISION array, dimension (min(M,N))
*> The scalar factors of the elementary reflectors.
*> \endverbatim
*>
*> \param[in,out] VN1
*> \verbatim
*> VN1 is DOUBLE PRECISION array, dimension (N)
*> The vector with the partial column norms.
*> \endverbatim
*>
*> \param[in,out] VN2
*> \verbatim
*> VN2 is DOUBLE PRECISION array, dimension (N)
*> The vector with the exact column norms.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension (N)
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2013
*
*> \ingroup doubleOTHERauxiliary
*
*> \par Contributors:
* ==================
*>
*> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
*> X. Sun, Computer Science Dept., Duke University, USA
*> \n
*> Partial column norm updating strategy modified on April 2011
*> Z. Drmac and Z. Bujanovic, Dept. of Mathematics,
*> University of Zagreb, Croatia.
*
*> \par References:
* ================
*>
*> LAPACK Working Note 176
*
*> \htmlonly
*> <a href="http://www.netlib.org/lapack/lawnspdf/lawn176.pdf">[PDF]</a>
*> \endhtmlonly
*
* =====================================================================
SUBROUTINE DLAQP2( M, N, OFFSET, A, LDA, JPVT, TAU, VN1, VN2,
$ WORK )
*
* -- LAPACK auxiliary 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 LDA, M, N, OFFSET
* ..
* .. Array Arguments ..
INTEGER JPVT( * )
DOUBLE PRECISION A( LDA, * ), TAU( * ), VN1( * ), VN2( * ),
$ WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, ITEMP, J, MN, OFFPI, PVT
DOUBLE PRECISION AII, TEMP, TEMP2, TOL3Z
* ..
* .. External Subroutines ..
EXTERNAL DLARF, DLARFG, DSWAP
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, MIN, SQRT
* ..
* .. External Functions ..
INTEGER IDAMAX
DOUBLE PRECISION DLAMCH, DNRM2
EXTERNAL IDAMAX, DLAMCH, DNRM2
* ..
* .. Executable Statements ..
*
MN = MIN( M-OFFSET, N )
TOL3Z = SQRT(DLAMCH('Epsilon'))
*
* Compute factorization.
*
DO 20 I = 1, MN
*
OFFPI = OFFSET + I
*
* Determine ith pivot column and swap if necessary.
*
PVT = ( I-1 ) + IDAMAX( N-I+1, VN1( I ), 1 )
*
IF( PVT.NE.I ) THEN
CALL DSWAP( M, A( 1, PVT ), 1, A( 1, I ), 1 )
ITEMP = JPVT( PVT )
JPVT( PVT ) = JPVT( I )
JPVT( I ) = ITEMP
VN1( PVT ) = VN1( I )
VN2( PVT ) = VN2( I )
END IF
*
* Generate elementary reflector H(i).
*
IF( OFFPI.LT.M ) THEN
CALL DLARFG( M-OFFPI+1, A( OFFPI, I ), A( OFFPI+1, I ), 1,
$ TAU( I ) )
ELSE
CALL DLARFG( 1, A( M, I ), A( M, I ), 1, TAU( I ) )
END IF
*
IF( I.LT.N ) THEN
*
* Apply H(i)**T to A(offset+i:m,i+1:n) from the left.
*
AII = A( OFFPI, I )
A( OFFPI, I ) = ONE
CALL DLARF( 'Left', M-OFFPI+1, N-I, A( OFFPI, I ), 1,
$ TAU( I ), A( OFFPI, I+1 ), LDA, WORK( 1 ) )
A( OFFPI, I ) = AII
END IF
*
* Update partial column norms.
*
DO 10 J = I + 1, N
IF( VN1( J ).NE.ZERO ) THEN
*
* NOTE: The following 4 lines follow from the analysis in
* Lapack Working Note 176.
*
TEMP = ONE - ( ABS( A( OFFPI, J ) ) / VN1( J ) )**2
TEMP = MAX( TEMP, ZERO )
TEMP2 = TEMP*( VN1( J ) / VN2( J ) )**2
IF( TEMP2 .LE. TOL3Z ) THEN
IF( OFFPI.LT.M ) THEN
VN1( J ) = DNRM2( M-OFFPI, A( OFFPI+1, J ), 1 )
VN2( J ) = VN1( J )
ELSE
VN1( J ) = ZERO
VN2( J ) = ZERO
END IF
ELSE
VN1( J ) = VN1( J )*SQRT( TEMP )
END IF
END IF
10 CONTINUE
*
20 CONTINUE
*
RETURN
*
* End of DLAQP2
*
END
| apache-2.0 |
OpenDA-Association/OpenDA | core/native/external/lapack/clangt.f | 2 | 4113 | REAL FUNCTION CLANGT( NORM, N, DL, D, DU )
*
* -- 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 NORM
INTEGER N
* ..
* .. Array Arguments ..
COMPLEX D( * ), DL( * ), DU( * )
* ..
*
* Purpose
* =======
*
* CLANGT returns the value of the one norm, or the Frobenius norm, or
* the infinity norm, or the element of largest absolute value of a
* complex tridiagonal matrix A.
*
* Description
* ===========
*
* CLANGT returns the value
*
* CLANGT = ( max(abs(A(i,j))), NORM = 'M' or 'm'
* (
* ( norm1(A), NORM = '1', 'O' or 'o'
* (
* ( normI(A), NORM = 'I' or 'i'
* (
* ( normF(A), NORM = 'F', 'f', 'E' or 'e'
*
* where norm1 denotes the one norm of a matrix (maximum column sum),
* normI denotes the infinity norm of a matrix (maximum row sum) and
* normF denotes the Frobenius norm of a matrix (square root of sum of
* squares). Note that max(abs(A(i,j))) is not a matrix norm.
*
* Arguments
* =========
*
* NORM (input) CHARACTER*1
* Specifies the value to be returned in CLANGT as described
* above.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0. When N = 0, CLANGT is
* set to zero.
*
* DL (input) COMPLEX array, dimension (N-1)
* The (n-1) sub-diagonal elements of A.
*
* D (input) COMPLEX array, dimension (N)
* The diagonal elements of A.
*
* DU (input) COMPLEX array, dimension (N-1)
* The (n-1) super-diagonal elements of A.
*
* =====================================================================
*
* .. Parameters ..
REAL ONE, ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Local Scalars ..
INTEGER I
REAL ANORM, SCALE, SUM
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL CLASSQ
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, SQRT
* ..
* .. Executable Statements ..
*
IF( N.LE.0 ) THEN
ANORM = ZERO
ELSE IF( LSAME( NORM, 'M' ) ) THEN
*
* Find max(abs(A(i,j))).
*
ANORM = ABS( D( N ) )
DO 10 I = 1, N - 1
ANORM = MAX( ANORM, ABS( DL( I ) ) )
ANORM = MAX( ANORM, ABS( D( I ) ) )
ANORM = MAX( ANORM, ABS( DU( I ) ) )
10 CONTINUE
ELSE IF( LSAME( NORM, 'O' ) .OR. NORM.EQ.'1' ) THEN
*
* Find norm1(A).
*
IF( N.EQ.1 ) THEN
ANORM = ABS( D( 1 ) )
ELSE
ANORM = MAX( ABS( D( 1 ) )+ABS( DL( 1 ) ),
$ ABS( D( N ) )+ABS( DU( N-1 ) ) )
DO 20 I = 2, N - 1
ANORM = MAX( ANORM, ABS( D( I ) )+ABS( DL( I ) )+
$ ABS( DU( I-1 ) ) )
20 CONTINUE
END IF
ELSE IF( LSAME( NORM, 'I' ) ) THEN
*
* Find normI(A).
*
IF( N.EQ.1 ) THEN
ANORM = ABS( D( 1 ) )
ELSE
ANORM = MAX( ABS( D( 1 ) )+ABS( DU( 1 ) ),
$ ABS( D( N ) )+ABS( DL( N-1 ) ) )
DO 30 I = 2, N - 1
ANORM = MAX( ANORM, ABS( D( I ) )+ABS( DU( I ) )+
$ ABS( DL( I-1 ) ) )
30 CONTINUE
END IF
ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
*
* Find normF(A).
*
SCALE = ZERO
SUM = ONE
CALL CLASSQ( N, D, 1, SCALE, SUM )
IF( N.GT.1 ) THEN
CALL CLASSQ( N-1, DL, 1, SCALE, SUM )
CALL CLASSQ( N-1, DU, 1, SCALE, SUM )
END IF
ANORM = SCALE*SQRT( SUM )
END IF
*
CLANGT = ANORM
RETURN
*
* End of CLANGT
*
END
| lgpl-3.0 |
OpenDA-Association/OpenDA | core/native/src/cta_f90/generated/cta_f90_resultwriter.f90 | 2 | 4610 | module cta_f90_resultwriter
implicit none
public
! \brief Handle a string message send to the resultwriter
!
! \param idWriter I ID of this resultwriter (Counter of number of native result writers)
! \param config I Name of XML configuration file containting the function pointers and additional information
! \param workingDir I Full path to working directory
! \param message I Message send to resultwriter
!
! \param status O error status: CTA_OK if successful
!
interface CTA_F90_Resultwriter_putmessage
subroutine CTA_Resultwriter_putmessage( idWriter, config, workingDir, message, status )
integer , intent(in ) :: idWriter
character(len=*) , intent(in ) :: config(*)
character(len=*) , intent(in ) :: workingDir(*)
character(len=*) , intent(in ) :: message(*)
integer , intent(out ) :: status
end subroutine CTA_Resultwriter_putmessage
end interface
! \brief Handle a string message send to the resultwriter
!
! \param idWriter I ID of this resultwriter (Counter of number of native result writers)
! \param config I Name of XML configuration file containting the function pointers and additional information
! \param workingDir I Full path to working directory
! \param id I Name of the variable/array send to the resultwriter
! \param handle I Handle (Vector or TreeVector) of variable
! \param outputLevel I Selected output level (see opendabridge for possible values)
! \param context I Location from which the resultwriter was called
! \param iteration I Iteration number from which the resultwriter was called
!
! \param status O error status: CTA_OK if successful
!
interface CTA_F90_Resultwriter_putvalue
subroutine CTA_Resultwriter_putvalue( idWriter, config, workingDir, id, handle, outputLevel, context, iteration, status )
integer , intent(in ) :: idWriter
character(len=*) , intent(in ) :: config(*)
character(len=*) , intent(in ) :: workingDir(*)
character(len=*) , intent(in ) :: id(*)
integer , intent(in ) :: handle
integer , intent(in ) :: outputLevel
character(len=*) , intent(in ) :: context(*)
integer , intent(in ) :: iteration
integer , intent(out ) :: status
end subroutine CTA_Resultwriter_putvalue
end interface
! \brief Handle a string message send to the resultwriter
!
! \param idWriter I ID of this resultwriter (Counter of number of native result writers)
! \param config I Name of XML configuration file containting the function pointers and additional information
! \param workingDir I Full path to working directory
! \param iteration I Iteration number from which the resultwriter was called
! \param cost I Value of cost function
! \param handle I Handle (Vector or TreeVector) of the current parameters
!
! \param status O error status: CTA_OK if successful
!
interface CTA_F90_Resultwriter_putiterationreport
subroutine CTA_Resultwriter_putiterationreport( idWriter, config, workingDir, iteration, cost, handle, status )
integer , intent(in ) :: idWriter
character(len=*) , intent(in ) :: config(*)
character(len=*) , intent(in ) :: workingDir(*)
integer , intent(in ) :: iteration
real(8) , intent(in ) :: cost
integer , intent(in ) :: handle
integer , intent(out ) :: status
end subroutine CTA_Resultwriter_putiterationreport
end interface
! \brief Free a resultwriter (close output files etc).
!
! \param idWriter I ID of this resultwriter (Counter of number of native result writers)
!
! \param status O error status: CTA_OK if successful
!
interface CTA_F90_Resultwriter_free
subroutine CTA_Resultwriter_free( idWriter, status )
integer , intent(in ) :: idWriter
integer , intent(out ) :: status
end subroutine CTA_Resultwriter_free
end interface
end module cta_f90_resultwriter
| lgpl-3.0 |