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 |
---|---|---|---|---|---|
pnedunuri/scipy | scipy/optimize/minpack/chkder.f | 127 | 4892 | subroutine chkder(m,n,x,fvec,fjac,ldfjac,xp,fvecp,mode,err)
integer m,n,ldfjac,mode
double precision x(n),fvec(m),fjac(ldfjac,n),xp(n),fvecp(m),
* err(m)
c **********
c
c subroutine chkder
c
c this subroutine checks the gradients of m nonlinear functions
c in n variables, evaluated at a point x, for consistency with
c the functions themselves. the user must call chkder twice,
c first with mode = 1 and then with mode = 2.
c
c mode = 1. on input, x must contain the point of evaluation.
c on output, xp is set to a neighboring point.
c
c mode = 2. on input, fvec must contain the functions and the
c rows of fjac must contain the gradients
c of the respective functions each evaluated
c at x, and fvecp must contain the functions
c evaluated at xp.
c on output, err contains measures of correctness of
c the respective gradients.
c
c the subroutine does not perform reliably if cancellation or
c rounding errors cause a severe loss of significance in the
c evaluation of a function. therefore, none of the components
c of x should be unusually small (in particular, zero) or any
c other value which may cause loss of significance.
c
c the subroutine statement is
c
c subroutine chkder(m,n,x,fvec,fjac,ldfjac,xp,fvecp,mode,err)
c
c where
c
c m is a positive integer input variable set to the number
c of functions.
c
c n is a positive integer input variable set to the number
c of variables.
c
c x is an input array of length n.
c
c fvec is an array of length m. on input when mode = 2,
c fvec must contain the functions evaluated at x.
c
c fjac is an m by n array. on input when mode = 2,
c the rows of fjac must contain the gradients of
c the respective functions evaluated at x.
c
c ldfjac is a positive integer input parameter not less than m
c which specifies the leading dimension of the array fjac.
c
c xp is an array of length n. on output when mode = 1,
c xp is set to a neighboring point of x.
c
c fvecp is an array of length m. on input when mode = 2,
c fvecp must contain the functions evaluated at xp.
c
c mode is an integer input variable set to 1 on the first call
c and 2 on the second. other values of mode are equivalent
c to mode = 1.
c
c err is an array of length m. on output when mode = 2,
c err contains measures of correctness of the respective
c gradients. if there is no severe loss of significance,
c then if err(i) is 1.0 the i-th gradient is correct,
c while if err(i) is 0.0 the i-th gradient is incorrect.
c for values of err between 0.0 and 1.0, the categorization
c is less certain. in general, a value of err(i) greater
c than 0.5 indicates that the i-th gradient is probably
c correct, while a value of err(i) less than 0.5 indicates
c that the i-th gradient is probably incorrect.
c
c subprograms called
c
c minpack supplied ... dpmpar
c
c fortran supplied ... dabs,dlog10,dsqrt
c
c argonne national laboratory. minpack project. march 1980.
c burton s. garbow, kenneth e. hillstrom, jorge j. more
c
c **********
integer i,j
double precision eps,epsf,epslog,epsmch,factor,one,temp,zero
double precision dpmpar
data factor,one,zero /1.0d2,1.0d0,0.0d0/
c
c epsmch is the machine precision.
c
epsmch = dpmpar(1)
c
eps = dsqrt(epsmch)
c
if (mode .eq. 2) go to 20
c
c mode = 1.
c
do 10 j = 1, n
temp = eps*dabs(x(j))
if (temp .eq. zero) temp = eps
xp(j) = x(j) + temp
10 continue
go to 70
20 continue
c
c mode = 2.
c
epsf = factor*epsmch
epslog = dlog10(eps)
do 30 i = 1, m
err(i) = zero
30 continue
do 50 j = 1, n
temp = dabs(x(j))
if (temp .eq. zero) temp = one
do 40 i = 1, m
err(i) = err(i) + temp*fjac(i,j)
40 continue
50 continue
do 60 i = 1, m
temp = one
if (fvec(i) .ne. zero .and. fvecp(i) .ne. zero
* .and. dabs(fvecp(i)-fvec(i)) .ge. epsf*dabs(fvec(i)))
* temp = eps*dabs((fvecp(i)-fvec(i))/eps-err(i))
* /(dabs(fvec(i)) + dabs(fvecp(i)))
err(i) = one
if (temp .gt. epsmch .and. temp .lt. eps)
* err(i) = (dlog10(temp) - epslog)/epslog
if (temp .ge. eps) err(i) = zero
60 continue
70 continue
c
return
c
c last card of subroutine chkder.
c
end
| bsd-3-clause |
tkelman/OpenBLAS | lapack-netlib/TESTING/LIN/schksp.f | 32 | 17764 | *> \brief \b SCHKSP
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* SUBROUTINE SCHKSP( DOTYPE, NN, NVAL, NNS, NSVAL, THRESH, TSTERR,
* NMAX, A, AFAC, AINV, B, X, XACT, WORK, RWORK,
* IWORK, NOUT )
*
* .. Scalar Arguments ..
* LOGICAL TSTERR
* INTEGER NMAX, NN, NNS, NOUT
* REAL THRESH
* ..
* .. Array Arguments ..
* LOGICAL DOTYPE( * )
* INTEGER IWORK( * ), NSVAL( * ), NVAL( * )
* REAL A( * ), AFAC( * ), AINV( * ), B( * ),
* $ RWORK( * ), WORK( * ), X( * ), XACT( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SCHKSP tests SSPTRF, -TRI, -TRS, -RFS, and -CON
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] DOTYPE
*> \verbatim
*> DOTYPE is LOGICAL array, dimension (NTYPES)
*> The matrix types to be used for testing. Matrices of type j
*> (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) =
*> .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used.
*> \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] THRESH
*> \verbatim
*> THRESH is REAL
*> 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[in] TSTERR
*> \verbatim
*> TSTERR is LOGICAL
*> Flag that indicates whether error exits are to be tested.
*> \endverbatim
*>
*> \param[in] NMAX
*> \verbatim
*> NMAX is INTEGER
*> The maximum value permitted for N, used in dimensioning the
*> work arrays.
*> \endverbatim
*>
*> \param[out] A
*> \verbatim
*> A is REAL array, dimension
*> (NMAX*(NMAX+1)/2)
*> \endverbatim
*>
*> \param[out] AFAC
*> \verbatim
*> AFAC is REAL array, dimension
*> (NMAX*(NMAX+1)/2)
*> \endverbatim
*>
*> \param[out] AINV
*> \verbatim
*> AINV is REAL array, dimension
*> (NMAX*(NMAX+1)/2)
*> \endverbatim
*>
*> \param[out] B
*> \verbatim
*> B is REAL array, dimension (NMAX*NSMAX)
*> where NSMAX is the largest entry in NSVAL.
*> \endverbatim
*>
*> \param[out] X
*> \verbatim
*> X is REAL array, dimension (NMAX*NSMAX)
*> \endverbatim
*>
*> \param[out] XACT
*> \verbatim
*> XACT is REAL array, dimension (NMAX*NSMAX)
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is REAL array, dimension
*> (NMAX*max(2,NSMAX))
*> \endverbatim
*>
*> \param[out] RWORK
*> \verbatim
*> RWORK is REAL array,
*> dimension (NMAX+2*NSMAX)
*> \endverbatim
*>
*> \param[out] IWORK
*> \verbatim
*> IWORK is INTEGER array, dimension (2*NMAX)
*> \endverbatim
*>
*> \param[in] NOUT
*> \verbatim
*> NOUT is INTEGER
*> The unit number for output.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup single_lin
*
* =====================================================================
SUBROUTINE SCHKSP( DOTYPE, NN, NVAL, NNS, NSVAL, THRESH, TSTERR,
$ NMAX, A, AFAC, AINV, B, X, XACT, WORK, RWORK,
$ IWORK, NOUT )
*
* -- LAPACK test routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
LOGICAL TSTERR
INTEGER NMAX, NN, NNS, NOUT
REAL THRESH
* ..
* .. Array Arguments ..
LOGICAL DOTYPE( * )
INTEGER IWORK( * ), NSVAL( * ), NVAL( * )
REAL A( * ), AFAC( * ), AINV( * ), B( * ),
$ RWORK( * ), WORK( * ), X( * ), XACT( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0E+0 )
INTEGER NTYPES
PARAMETER ( NTYPES = 10 )
INTEGER NTESTS
PARAMETER ( NTESTS = 8 )
* ..
* .. Local Scalars ..
LOGICAL TRFCON, ZEROT
CHARACTER DIST, PACKIT, TYPE, UPLO, XTYPE
CHARACTER*3 PATH
INTEGER I, I1, I2, IMAT, IN, INFO, IOFF, IRHS, IUPLO,
$ IZERO, J, K, KL, KU, LDA, MODE, N, NERRS,
$ NFAIL, NIMAT, NPP, NRHS, NRUN, NT
REAL ANORM, CNDNUM, RCOND, RCONDC
* ..
* .. Local Arrays ..
CHARACTER UPLOS( 2 )
INTEGER ISEED( 4 ), ISEEDY( 4 )
REAL RESULT( NTESTS )
* ..
* .. External Functions ..
LOGICAL LSAME
REAL SGET06, SLANSP
EXTERNAL LSAME, SGET06, SLANSP
* ..
* .. External Subroutines ..
EXTERNAL ALAERH, ALAHD, ALASUM, SCOPY, SERRSY, SGET04,
$ SLACPY, SLARHS, SLATB4, SLATMS, SPPT02, SPPT03,
$ SPPT05, SSPCON, SSPRFS, SSPT01, SSPTRF, SSPTRI,
$ SSPTRS
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. 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 ISEEDY / 1988, 1989, 1990, 1991 /
DATA UPLOS / 'U', 'L' /
* ..
* .. Executable Statements ..
*
* Initialize constants and the random number seed.
*
PATH( 1: 1 ) = 'Single precision'
PATH( 2: 3 ) = 'SP'
NRUN = 0
NFAIL = 0
NERRS = 0
DO 10 I = 1, 4
ISEED( I ) = ISEEDY( I )
10 CONTINUE
*
* Test the error exits
*
IF( TSTERR )
$ CALL SERRSY( PATH, NOUT )
INFOT = 0
*
* Do for each value of N in NVAL
*
DO 170 IN = 1, NN
N = NVAL( IN )
LDA = MAX( N, 1 )
XTYPE = 'N'
NIMAT = NTYPES
IF( N.LE.0 )
$ NIMAT = 1
*
IZERO = 0
DO 160 IMAT = 1, NIMAT
*
* Do the tests only if DOTYPE( IMAT ) is true.
*
IF( .NOT.DOTYPE( IMAT ) )
$ GO TO 160
*
* Skip types 3, 4, 5, or 6 if the matrix size is too small.
*
ZEROT = IMAT.GE.3 .AND. IMAT.LE.6
IF( ZEROT .AND. N.LT.IMAT-2 )
$ GO TO 160
*
* Do first for UPLO = 'U', then for UPLO = 'L'
*
DO 150 IUPLO = 1, 2
UPLO = UPLOS( IUPLO )
IF( LSAME( UPLO, 'U' ) ) THEN
PACKIT = 'C'
ELSE
PACKIT = 'R'
END IF
*
* Set up parameters with SLATB4 and generate a test matrix
* with SLATMS.
*
CALL SLATB4( PATH, IMAT, N, N, TYPE, KL, KU, ANORM, MODE,
$ CNDNUM, DIST )
*
SRNAMT = 'SLATMS'
CALL SLATMS( N, N, DIST, ISEED, TYPE, RWORK, MODE,
$ CNDNUM, ANORM, KL, KU, PACKIT, A, LDA, WORK,
$ INFO )
*
* Check error code from SLATMS.
*
IF( INFO.NE.0 ) THEN
CALL ALAERH( PATH, 'SLATMS', INFO, 0, UPLO, N, N, -1,
$ -1, -1, IMAT, NFAIL, NERRS, NOUT )
GO TO 150
END IF
*
* For types 3-6, zero one or more rows and columns of
* the matrix to test that INFO is returned correctly.
*
IF( ZEROT ) THEN
IF( IMAT.EQ.3 ) THEN
IZERO = 1
ELSE IF( IMAT.EQ.4 ) THEN
IZERO = N
ELSE
IZERO = N / 2 + 1
END IF
*
IF( IMAT.LT.6 ) THEN
*
* Set row and column IZERO to zero.
*
IF( IUPLO.EQ.1 ) THEN
IOFF = ( IZERO-1 )*IZERO / 2
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 + I
30 CONTINUE
ELSE
IOFF = IZERO
DO 40 I = 1, IZERO - 1
A( IOFF ) = ZERO
IOFF = IOFF + N - I
40 CONTINUE
IOFF = IOFF - IZERO
DO 50 I = IZERO, N
A( IOFF+I ) = ZERO
50 CONTINUE
END IF
ELSE
IOFF = 0
IF( IUPLO.EQ.1 ) THEN
*
* Set the first IZERO rows and columns to zero.
*
DO 70 J = 1, N
I2 = MIN( J, IZERO )
DO 60 I = 1, I2
A( IOFF+I ) = ZERO
60 CONTINUE
IOFF = IOFF + J
70 CONTINUE
ELSE
*
* Set the last IZERO rows and columns to zero.
*
DO 90 J = 1, N
I1 = MAX( J, IZERO )
DO 80 I = I1, N
A( IOFF+I ) = ZERO
80 CONTINUE
IOFF = IOFF + N - J
90 CONTINUE
END IF
END IF
ELSE
IZERO = 0
END IF
*
* Compute the L*D*L' or U*D*U' factorization of the matrix.
*
NPP = N*( N+1 ) / 2
CALL SCOPY( NPP, A, 1, AFAC, 1 )
SRNAMT = 'SSPTRF'
CALL SSPTRF( UPLO, N, AFAC, IWORK, INFO )
*
* Adjust the expected value of INFO to account for
* pivoting.
*
K = IZERO
IF( K.GT.0 ) THEN
100 CONTINUE
IF( IWORK( K ).LT.0 ) THEN
IF( IWORK( K ).NE.-K ) THEN
K = -IWORK( K )
GO TO 100
END IF
ELSE IF( IWORK( K ).NE.K ) THEN
K = IWORK( K )
GO TO 100
END IF
END IF
*
* Check error code from SSPTRF.
*
IF( INFO.NE.K )
$ CALL ALAERH( PATH, 'SSPTRF', INFO, K, UPLO, N, N, -1,
$ -1, -1, IMAT, NFAIL, NERRS, NOUT )
IF( INFO.NE.0 ) THEN
TRFCON = .TRUE.
ELSE
TRFCON = .FALSE.
END IF
*
*+ TEST 1
* Reconstruct matrix from factors and compute residual.
*
CALL SSPT01( UPLO, N, A, AFAC, IWORK, AINV, LDA, RWORK,
$ RESULT( 1 ) )
NT = 1
*
*+ TEST 2
* Form the inverse and compute the residual.
*
IF( .NOT.TRFCON ) THEN
CALL SCOPY( NPP, AFAC, 1, AINV, 1 )
SRNAMT = 'SSPTRI'
CALL SSPTRI( UPLO, N, AINV, IWORK, WORK, INFO )
*
* Check error code from SSPTRI.
*
IF( INFO.NE.0 )
$ CALL ALAERH( PATH, 'SSPTRI', INFO, 0, UPLO, N, N,
$ -1, -1, -1, IMAT, NFAIL, NERRS, NOUT )
*
CALL SPPT03( UPLO, N, A, AINV, WORK, LDA, RWORK,
$ RCONDC, RESULT( 2 ) )
NT = 2
END IF
*
* Print information about the tests that did not pass
* the threshold.
*
DO 110 K = 1, NT
IF( RESULT( K ).GE.THRESH ) THEN
IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
$ CALL ALAHD( NOUT, PATH )
WRITE( NOUT, FMT = 9999 )UPLO, N, IMAT, K,
$ RESULT( K )
NFAIL = NFAIL + 1
END IF
110 CONTINUE
NRUN = NRUN + NT
*
* Do only the condition estimate if INFO is not 0.
*
IF( TRFCON ) THEN
RCONDC = ZERO
GO TO 140
END IF
*
DO 130 IRHS = 1, NNS
NRHS = NSVAL( IRHS )
*
*+ TEST 3
* Solve and compute residual for A * X = B.
*
SRNAMT = 'SLARHS'
CALL SLARHS( PATH, XTYPE, UPLO, ' ', N, N, KL, KU,
$ NRHS, A, LDA, XACT, LDA, B, LDA, ISEED,
$ INFO )
CALL SLACPY( 'Full', N, NRHS, B, LDA, X, LDA )
*
SRNAMT = 'SSPTRS'
CALL SSPTRS( UPLO, N, NRHS, AFAC, IWORK, X, LDA,
$ INFO )
*
* Check error code from SSPTRS.
*
IF( INFO.NE.0 )
$ CALL ALAERH( PATH, 'SSPTRS', INFO, 0, UPLO, N, N,
$ -1, -1, NRHS, IMAT, NFAIL, NERRS,
$ NOUT )
*
CALL SLACPY( 'Full', N, NRHS, B, LDA, WORK, LDA )
CALL SPPT02( UPLO, N, NRHS, A, X, LDA, WORK, LDA,
$ RWORK, RESULT( 3 ) )
*
*+ TEST 4
* Check solution from generated exact solution.
*
CALL SGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC,
$ RESULT( 4 ) )
*
*+ TESTS 5, 6, and 7
* Use iterative refinement to improve the solution.
*
SRNAMT = 'SSPRFS'
CALL SSPRFS( UPLO, N, NRHS, A, AFAC, IWORK, B, LDA, X,
$ LDA, RWORK, RWORK( NRHS+1 ), WORK,
$ IWORK( N+1 ), INFO )
*
* Check error code from SSPRFS.
*
IF( INFO.NE.0 )
$ CALL ALAERH( PATH, 'SSPRFS', INFO, 0, UPLO, N, N,
$ -1, -1, NRHS, IMAT, NFAIL, NERRS,
$ NOUT )
*
CALL SGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC,
$ RESULT( 5 ) )
CALL SPPT05( UPLO, N, NRHS, A, B, LDA, X, LDA, XACT,
$ LDA, RWORK, RWORK( NRHS+1 ),
$ RESULT( 6 ) )
*
* Print information about the tests that did not pass
* the threshold.
*
DO 120 K = 3, 7
IF( RESULT( K ).GE.THRESH ) THEN
IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
$ CALL ALAHD( NOUT, PATH )
WRITE( NOUT, FMT = 9998 )UPLO, N, NRHS, IMAT,
$ K, RESULT( K )
NFAIL = NFAIL + 1
END IF
120 CONTINUE
NRUN = NRUN + 5
130 CONTINUE
*
*+ TEST 8
* Get an estimate of RCOND = 1/CNDNUM.
*
140 CONTINUE
ANORM = SLANSP( '1', UPLO, N, A, RWORK )
SRNAMT = 'SSPCON'
CALL SSPCON( UPLO, N, AFAC, IWORK, ANORM, RCOND, WORK,
$ IWORK( N+1 ), INFO )
*
* Check error code from SSPCON.
*
IF( INFO.NE.0 )
$ CALL ALAERH( PATH, 'SSPCON', INFO, 0, UPLO, N, N, -1,
$ -1, -1, IMAT, NFAIL, NERRS, NOUT )
*
RESULT( 8 ) = SGET06( RCOND, RCONDC )
*
* Print the test ratio if it is .GE. THRESH.
*
IF( RESULT( 8 ).GE.THRESH ) THEN
IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
$ CALL ALAHD( NOUT, PATH )
WRITE( NOUT, FMT = 9999 )UPLO, N, IMAT, 8,
$ RESULT( 8 )
NFAIL = NFAIL + 1
END IF
NRUN = NRUN + 1
150 CONTINUE
160 CONTINUE
170 CONTINUE
*
* Print a summary of the results.
*
CALL ALASUM( PATH, NOUT, NFAIL, NRUN, NERRS )
*
9999 FORMAT( ' UPLO = ''', A1, ''', N =', I5, ', type ', I2, ', test ',
$ I2, ', ratio =', G12.5 )
9998 FORMAT( ' UPLO = ''', A1, ''', N =', I5, ', NRHS=', I3, ', type ',
$ I2, ', test(', I2, ') =', G12.5 )
RETURN
*
* End of SCHKSP
*
END
| bsd-3-clause |
tkelman/OpenBLAS | lapack-netlib/SRC/cunm2r.f | 24 | 7532 | *> \brief \b CUNM2R multiplies a general matrix by the unitary matrix from a QR factorization determined by cgeqrf (unblocked algorithm).
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CUNM2R + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cunm2r.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cunm2r.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cunm2r.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CUNM2R( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
* WORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER SIDE, TRANS
* INTEGER INFO, K, LDA, LDC, M, N
* ..
* .. Array Arguments ..
* COMPLEX A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CUNM2R overwrites the general complex m-by-n matrix C with
*>
*> Q * C if SIDE = 'L' and TRANS = 'N', or
*>
*> Q**H* C if SIDE = 'L' and TRANS = 'C', or
*>
*> C * Q if SIDE = 'R' and TRANS = 'N', or
*>
*> C * Q**H if SIDE = 'R' and TRANS = 'C',
*>
*> where Q is a complex unitary matrix defined as the product of k
*> elementary reflectors
*>
*> Q = H(1) H(2) . . . H(k)
*>
*> as returned by CGEQRF. Q is of order m if SIDE = 'L' and of order n
*> if SIDE = 'R'.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] SIDE
*> \verbatim
*> SIDE is CHARACTER*1
*> = 'L': apply Q or Q**H from the Left
*> = 'R': apply Q or Q**H from the Right
*> \endverbatim
*>
*> \param[in] TRANS
*> \verbatim
*> TRANS is CHARACTER*1
*> = 'N': apply Q (No transpose)
*> = 'C': apply Q**H (Conjugate transpose)
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix C. M >= 0.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix C. N >= 0.
*> \endverbatim
*>
*> \param[in] K
*> \verbatim
*> K is INTEGER
*> The number of elementary reflectors whose product defines
*> the matrix Q.
*> If SIDE = 'L', M >= K >= 0;
*> if SIDE = 'R', N >= K >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is COMPLEX array, dimension (LDA,K)
*> The i-th column must contain the vector which defines the
*> elementary reflector H(i), for i = 1,2,...,k, as returned by
*> CGEQRF in the first k columns of its array argument A.
*> A is modified by the routine but restored on exit.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A.
*> If SIDE = 'L', LDA >= max(1,M);
*> if SIDE = 'R', LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in] TAU
*> \verbatim
*> TAU is COMPLEX array, dimension (K)
*> TAU(i) must contain the scalar factor of the elementary
*> reflector H(i), as returned by CGEQRF.
*> \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 Q*C or Q**H*C or C*Q**H or C*Q.
*> \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
*> (N) if SIDE = 'L',
*> (M) if SIDE = 'R'
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup complexOTHERcomputational
*
* =====================================================================
SUBROUTINE CUNM2R( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
$ WORK, INFO )
*
* -- LAPACK computational routine (version 3.4.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* September 2012
*
* .. Scalar Arguments ..
CHARACTER SIDE, TRANS
INTEGER INFO, K, LDA, LDC, M, N
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
COMPLEX ONE
PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
LOGICAL LEFT, NOTRAN
INTEGER I, I1, I2, I3, IC, JC, MI, NI, NQ
COMPLEX AII, TAUI
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL CLARF, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC CONJG, 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, 'C' ) ) 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, NQ ) ) THEN
INFO = -7
ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
INFO = -10
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CUNM2R', -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
JC = 1
ELSE
MI = M
IC = 1
END IF
*
DO 10 I = I1, I2, I3
IF( LEFT ) THEN
*
* H(i) or H(i)**H is applied to C(i:m,1:n)
*
MI = M - I + 1
IC = I
ELSE
*
* H(i) or H(i)**H is applied to C(1:m,i:n)
*
NI = N - I + 1
JC = I
END IF
*
* Apply H(i) or H(i)**H
*
IF( NOTRAN ) THEN
TAUI = TAU( I )
ELSE
TAUI = CONJG( TAU( I ) )
END IF
AII = A( I, I )
A( I, I ) = ONE
CALL CLARF( SIDE, MI, NI, A( I, I ), 1, TAUI, C( IC, JC ), LDC,
$ WORK )
A( I, I ) = AII
10 CONTINUE
RETURN
*
* End of CUNM2R
*
END
| bsd-3-clause |
blue236/gcc | libgfortran/generated/_acosh_r16.F90 | 47 | 1484 | ! Copyright (C) 2002-2015 Free Software Foundation, Inc.
! Contributed by Paul Brook <paul@nowt.org>
!
!This file is part of the GNU Fortran 95 runtime library (libgfortran).
!
!GNU libgfortran 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 3 of the License, or (at your option) any later version.
!GNU libgfortran 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.
!
!Under Section 7 of GPL version 3, you are granted additional
!permissions described in the GCC Runtime Library Exception, version
!3.1, as published by the Free Software Foundation.
!
!You should have received a copy of the GNU General Public License and
!a copy of the GCC Runtime Library Exception along with this program;
!see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
!<http://www.gnu.org/licenses/>.
!
!This file is machine generated.
#include "config.h"
#include "kinds.inc"
#include "c99_protos.inc"
#if defined (HAVE_GFC_REAL_16)
#ifdef HAVE_ACOSHL
elemental function _gfortran_specific__acosh_r16 (parm)
real (kind=16), intent (in) :: parm
real (kind=16) :: _gfortran_specific__acosh_r16
_gfortran_specific__acosh_r16 = acosh (parm)
end function
#endif
#endif
| gpl-2.0 |
aamaricci/DMFTtools | src/.module_archive/greenfunx_deallocate_gf.f90 | 1 | 2066 | subroutine deallocate_matsubara_gf(fgk)
type(matsubara_gf),intent(inout) :: fgk
deallocate(fgk%iw,fgk%tau)
fgk%status=.false.
end subroutine deallocate_matsubara_gf
subroutine deallocate_matsubara_gf_(fgk)
type(matsubara_gf),intent(inout) :: fgk(:)
integer :: i,L1
L1=size(fgk,1)
do i=1,L1
deallocate(fgk(i)%iw,fgk(i)%tau)
fgk(i)%status=.false.
enddo
end subroutine deallocate_matsubara_gf_
subroutine deallocate_matsubara_gf__(fgk)
type(matsubara_gf),intent(inout) :: fgk(:,:)
integer :: L1,L2,i,j
L1=size(fgk,1);L2=size(fgk,2)
do i=1,L1
do j=1,L2
deallocate(fgk(i,j)%iw,fgk(i,j)%tau)
fgk(i,j)%status=.false.
enddo
enddo
end subroutine deallocate_matsubara_gf__
subroutine deallocate_real_gf(fgk)
type(real_gf),intent(inout) :: fgk
deallocate(fgk%w,fgk%t)
fgk%status=.false.
end subroutine deallocate_real_gf
subroutine deallocate_real_gf_(fgk)
type(real_gf),intent(inout) :: fgk(:)
integer :: L1,i
L1=size(fgk,1)
do i=1,L1
deallocate(fgk(i)%w,fgk(i)%t)
fgk(i)%status=.false.
enddo
end subroutine deallocate_real_gf_
subroutine deallocate_real_gf__(fgk)
type(real_gf),intent(inout) :: fgk(:,:)
integer :: L1,L2,i,j
L1=size(fgk,1);L2=size(fgk,2)
do i=1,L1
do j=1,L2
deallocate(fgk(i,j)%w,fgk(i,j)%t)
fgk(i,j)%status=.false.
enddo
enddo
end subroutine deallocate_real_gf__
subroutine deallocate_keldysh_equilibrium_component(fgk)
type(keldysh_equilibrium_component),intent(inout) :: fgk
deallocate(fgk%w,fgk%t)
end subroutine deallocate_keldysh_equilibrium_component
subroutine deallocate_keldysh_equilibrium_gf(fgk)
type(keldysh_equilibrium_gf),intent(inout) :: fgk
call deallocate_keldysh_equilibrium_component(fgk%less)
call deallocate_keldysh_equilibrium_component(fgk%gtr)
call deallocate_keldysh_equilibrium_component(fgk%ret)
fgk%status=.false.
end subroutine deallocate_keldysh_equilibrium_gf
| lgpl-3.0 |
sigma-random/gcc | gcc/testsuite/gfortran.dg/gomp/sharing-3.f90 | 162 | 1080 | ! { dg-do compile }
! { dg-options "-fopenmp" }
subroutine foo (vara, varb, varc, vard, n)
integer :: n, vara(n), varb(*), varc(:), vard(6), vare(6)
vare(:) = 0
!$omp parallel default(none) shared(vara, varb, varc, vard, vare)
!$omp master
vara(1) = 1
varb(1) = 1
varc(1) = 1
vard(1) = 1
vare(1) = 1
!$omp end master
!$omp end parallel
!$omp parallel default(none) private(vara, varc, vard, vare)
vara(1) = 1
varc(1) = 1
vard(1) = 1
vare(1) = 1
!$omp end parallel
!$omp parallel default(none) firstprivate(vara, varc, vard, vare)
vara(1) = 1
varc(1) = 1
vard(1) = 1
vare(1) = 1
!$omp end parallel
!$omp parallel default(none) ! { dg-error "enclosing parallel" }
!$omp master
vara(1) = 1 ! { dg-error "not specified" }
varb(1) = 1 ! Assumed-size is predetermined
varc(1) = 1 ! { dg-error "not specified" }
vard(1) = 1 ! { dg-error "not specified" }
vare(1) = 1 ! { dg-error "not specified" }
!$omp end master
!$omp end parallel
end subroutine foo
| gpl-2.0 |
sigma-random/gcc | gcc/testsuite/gfortran.dg/no_arg_check_2.f90 | 20 | 6079 | ! { dg-do run }
! { dg-options "-fdump-tree-original" }
!
! PR fortran/39505
!
! Test NO_ARG_CHECK
! Copied from assumed_type_2.f90
!
module mod
use iso_c_binding, only: c_loc, c_ptr, c_bool
implicit none
interface my_c_loc
function my_c_loc1(x) bind(C)
import c_ptr
!GCC$ attributes NO_ARG_CHECK :: x
type(*) :: x
type(c_ptr) :: my_c_loc1
end function
end interface my_c_loc
contains
subroutine sub_scalar (arg1, presnt)
integer(8), target, optional :: arg1
logical :: presnt
type(c_ptr) :: cpt
!GCC$ attributes NO_ARG_CHECK :: arg1
if (presnt .neqv. present (arg1)) call abort ()
cpt = c_loc (arg1)
end subroutine sub_scalar
subroutine sub_array_assumed (arg3)
!GCC$ attributes NO_ARG_CHECK :: arg3
logical(1), target :: arg3(*)
type(c_ptr) :: cpt
cpt = c_loc (arg3)
end subroutine sub_array_assumed
end module
use mod
use iso_c_binding, only: c_int, c_null_ptr
implicit none
type t1
integer :: a
end type t1
type :: t2
sequence
integer :: b
end type t2
type, bind(C) :: t3
integer(c_int) :: c
end type t3
integer :: scalar_int
real, allocatable :: scalar_real_alloc
character, pointer :: scalar_char_ptr
integer :: array_int(3)
real, allocatable :: array_real_alloc(:,:)
character, pointer :: array_char_ptr(:,:)
type(t1) :: scalar_t1
type(t2), allocatable :: scalar_t2_alloc
type(t3), pointer :: scalar_t3_ptr
type(t1) :: array_t1(4)
type(t2), allocatable :: array_t2_alloc(:,:)
type(t3), pointer :: array_t3_ptr(:,:)
class(t1), allocatable :: scalar_class_t1_alloc
class(t1), pointer :: scalar_class_t1_ptr
class(t1), allocatable :: array_class_t1_alloc(:,:)
class(t1), pointer :: array_class_t1_ptr(:,:)
scalar_char_ptr => null()
scalar_t3_ptr => null()
call sub_scalar (presnt=.false.)
call sub_scalar (scalar_real_alloc, .false.)
call sub_scalar (scalar_char_ptr, .false.)
call sub_scalar (null (), .false.)
call sub_scalar (scalar_t2_alloc, .false.)
call sub_scalar (scalar_t3_ptr, .false.)
allocate (scalar_real_alloc, scalar_char_ptr, scalar_t3_ptr)
allocate (scalar_class_t1_alloc, scalar_class_t1_ptr, scalar_t2_alloc)
allocate (array_real_alloc(3:5,2:4), array_char_ptr(-2:2,2))
allocate (array_t2_alloc(3:5,2:4), array_t3_ptr(-2:2,2))
allocate (array_class_t1_alloc(3,3), array_class_t1_ptr(4,4))
call sub_scalar (scalar_int, .true.)
call sub_scalar (scalar_real_alloc, .true.)
call sub_scalar (scalar_char_ptr, .true.)
call sub_scalar (array_int(2), .true.)
call sub_scalar (array_real_alloc(3,2), .true.)
call sub_scalar (array_char_ptr(0,1), .true.)
call sub_scalar (scalar_t1, .true.)
call sub_scalar (scalar_t2_alloc, .true.)
call sub_scalar (scalar_t3_ptr, .true.)
call sub_scalar (array_t1(2), .true.)
call sub_scalar (array_t2_alloc(3,2), .true.)
call sub_scalar (array_t3_ptr(0,1), .true.)
call sub_scalar (array_class_t1_alloc(2,1), .true.)
call sub_scalar (array_class_t1_ptr(3,3), .true.)
call sub_array_assumed (array_int)
call sub_array_assumed (array_real_alloc)
call sub_array_assumed (array_char_ptr)
call sub_array_assumed (array_t1)
call sub_array_assumed (array_t2_alloc)
call sub_array_assumed (array_t3_ptr)
call sub_array_assumed (array_class_t1_alloc)
call sub_array_assumed (array_class_t1_ptr)
deallocate (scalar_char_ptr, scalar_class_t1_ptr, array_char_ptr)
deallocate (array_class_t1_ptr, array_t3_ptr)
contains
subroutine sub(x)
integer :: x(:)
call sub_array_assumed (x)
end subroutine sub
end
! { dg-final { scan-tree-dump-times "sub_scalar .0B," 2 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .scalar_real_alloc," 2 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .scalar_char_ptr," 2 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .scalar_t2_alloc," 2 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .scalar_t3_ptr" 2 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&scalar_int," 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&scalar_t1," 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&array_int.1.," 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&scalar_t1," 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(real.kind=4..0:. . restrict\\) array_real_alloc.data" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(character.kind=1..0:..1:1. .\\) array_char_ptr.data" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(struct t2.0:. . restrict\\) array_t2_alloc.data" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(struct t3.0:. .\\) array_t3_ptr.data" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) array_class_t1_alloc._data.data" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) array_class_t1_ptr._data.dat" 1 "original" } }a
! { dg-final { scan-tree-dump-times "sub_array_assumed \\(D" 3 "original" } }
! { dg-final { scan-tree-dump-times " = _gfortran_internal_pack \\(&parm" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_array_assumed \\(&array_int\\)" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_array_assumed \\(\\(real\\(kind=4\\).0:. . restrict\\) array_real_alloc.data" 1 "original" } }
! { dg-final { scan-tree-dump-times " = _gfortran_internal_pack \\(&array_char_ptr\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "\\.data = \\(void .\\) &array_t1.0.;" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_array_assumed \\(\\(struct t1.0:. .\\) parm" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_array_assumed \\(\\(struct t2.0:. . restrict\\) array_t2_alloc.data\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_array_assumed \\(\\(struct t1.0:. . restrict\\) array_class_t1_alloc._data.data\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "sub_array_assumed \\(\\(struct t1.0:. .\\) array_class_t1_ptr._data.data\\);" 1 "original" } }
| gpl-2.0 |
geodynamics/relax | src/friction3d.f90 | 1 | 15252 | !-----------------------------------------------------------------------
! Copyright 2007, 2008, 2009 Sylvain Barbot
!
! This file is part of RELAX
!
! RELAX 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 3 of the License, or
! (at your option) any later version.
!
! RELAX 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 RELAX. If not, see <http://www.gnu.org/licenses/>.
!-----------------------------------------------------------------------
#include "include.f90"
MODULE friction3d
USE types
USE elastic3d
IMPLICIT NONE
REAL*8, PRIVATE, PARAMETER :: pi = 3.141592653589793115997963468544185161_8
REAL*8, PRIVATE, PARAMETER :: pi2 = 6.28318530717958623199592693708837032318_8
REAL*8, PRIVATE, PARAMETER :: pid2 = 1.57079632679489655799898173427209258079_8
CONTAINS
!-----------------------------------------------------------------
!> subroutine FrictionEigenStress
!! compute the eigen-stress (forcing moment) to be relaxed by
!! rate-dependent inelastic deformation in the case of a frictional
!! surface:
!!
!! sigma^i = C:F:sigma
!!
!! where C is the elastic moduli tensor, F is the heterogeneous
!! fluidity moduli tensor and sigma is the instantaneous stress
!! tensor. for a frictional surface, the eigenstrain-rate is given
!! by
!!
!! epsilon^i^dot = F:sigma = gamma^dot R
!!
!! where gamma^dot is the slip rate (a scalar) and R is the
!! deviatoric, symmetric, and unitary, tensor:
!!
!! R_ij = 1/2 ( t_i n_j + t_j n_i ) / sqrt( t_j t_j )
!!
!! where the shear traction t_i is the projection of the traction
!! vector on the plane surface. the strain amplitude is given by
!!
!! gamma^dot = H( t_j r_j ) 2 vo sinh( taus / (t_c )
!!
!! where taus is the effective shear on the fault plane,
!!
!! taus = tau + mu*sigma
!!
!! where tau is the shear and sigma the normal stress. tau and sigma
!! assumed to be the co-seismic change only, not the absolute
!! stress. vo is a reference slip velocity, and t_c, the critical
!! stress, corresponds to (a-b)*sigma in the framework of rate-and-
!! state friction. the effective viscosity eta* and the fluidity
!!
!! eta* = tau / gamma^dot
!! fluidity = 1 / eta*
!!
!! are used to compute the optimal time-step. H( x ) is the
!! Heaviside function and r_i is the rake vector. I impose
!! gamma^dot to be zero is t_j r_j < 0. This constraint is
!! enforced to ensure that no back slip occurs on faults.
!!
!! \author sylvain barbot (07/24/07) - original form
!! (02/28/11) - add constraints on the direction
!! of afterslip
!-----------------------------------------------------------------
SUBROUTINE frictioneigenstress(x,y,z,L,W,strike,dip,rake,beta, &
sig,prestress,mu,structure,sx1,sx2,sx3,dx1,dx2,dx3,moment,maxwelltime,vel)
INTEGER, INTENT(IN) :: sx1,sx2,sx3
REAL*8, INTENT(IN) :: mu,dx1,dx2,dx3,x,y,z,L,W,strike,dip,rake,beta
TYPE(LAYER_STRUCT), DIMENSION(:), INTENT(IN) :: structure
TYPE(TENSOR_LAYER_STRUCT), DIMENSION(:), INTENT(IN) :: prestress
TYPE(TENSOR), INTENT(IN), DIMENSION(sx1,sx2,sx3) :: sig
TYPE(TENSOR), INTENT(INOUT), DIMENSION(sx1,sx2,sx3) :: moment
REAL*8, OPTIONAL, INTENT(INOUT) :: maxwelltime
#ifdef ALIGN_DATA
REAL*4, INTENT(OUT), DIMENSION(sx1+2,sx2,sx3), OPTIONAL :: vel
#else
REAL*4, INTENT(OUT), DIMENSION(sx1,sx2,sx3), OPTIONAL :: vel
#endif
INTEGER :: i1,i2,i3
TYPE(TENSOR) :: s
REAL*8, DIMENSION(3) :: t,ts,n,r
REAL*8 :: vo,tauc,taun,taus,gammadot,impulse, &
friction,tau,scaling,cohesion
REAL*8 :: x1,x2,x3,x1s,x2s,x3s,x1i,x3i, &
cstrike,sstrike,cdip,sdip,cr,sr,x2r,&
temp1,temp2,temp3,sourc,image,xr,yr,zr,Wp,Lp,dum
REAL*4 :: tm
IF (PRESENT(maxwelltime)) THEN
tm=REAL(maxwelltime)
i1=1
ELSE
tm=1e30
i1=0
END IF
#ifdef USING_CUDA
CALL cufrictioneigenstress (%VAL(x), %VAL(y), %VAL(z), %VAL(L), %VAL(W),%VAL(strike), &
%VAL(dip), %VAL(rake), %VAL(beta), %VAL(mu), structure, %VAL(sx1),%VAL(sx2), &
%VAL(sx3), %VAL(dx1), %VAL(dx2), %VAL(dx3), %VAL(i1), tm, moment, sig)
#else
! delta function scaling
scaling=sqrt(pi2)*dx1
cstrike=cos(strike)
sstrike=sin(strike)
cdip=cos(dip)
sdip=sin(dip)
cr=cos(rake)
sr=sin(rake)
! effective tapered dimensions
Wp=W*(1._8+2._8*beta)/2._8
Lp=L*(1._8+2._8*beta)/2._8
! rotate centre coordinates of source and images
x2r= cstrike*x -sstrike*y
xr = cdip *x2r-sdip *z
yr = sstrike*x +cstrike*y
zr = sdip *x2r+cdip *z
! surface normal vector components
n(1)=+cdip*cstrike
n(2)=-cdip*sstrike
n(3)=-sdip
! rake vector component
r(1)=sstrike*cr+cstrike*sdip*sr
r(2)=cstrike*cr-sstrike*sdip*sr
r(3)=cdip*sr
DO i3=1,sx3
x3=DBLE(i3-1)*dx3
IF ((abs(x3-z).gt.Lp) .and. (abs(x3+z).gt.Lp)) CYCLE
vo=structure(i3)%gammadot0
tauc=structure(i3)%stressexponent
friction=structure(i3)%friction
cohesion=structure(i3)%cohesion
DO i2=1,sx2
DO i1=1,sx1
CALL shiftedcoordinates(i1,i2,i3,sx1,sx2,sx3, &
dx1,dx2,dx3,x1,x2,dum)
IF ((ABS(x1-x).gt.MAX(Wp,Lp)) .OR. (ABS(x2-y).gt.MAX(Wp,Lp))) CYCLE
x2r= cstrike*x1-sstrike*x2
x1s= cdip*x2r-sdip*x3
x1i= cdip*x2r+sdip*x3
IF ((ABS(x1s-xr).GT.7.01_8*dx1).AND.(ABS(x1i-xr).GT.7.01_8*dx1)) CYCLE
x2s= sstrike*x1+cstrike*x2
x3s= sdip*x2r+cdip*x3
x3i=-sdip*x2r+cdip*x3
! integrate at depth and along strike with raised cosine taper
! and shift sources to x,y,z coordinate
temp1=gauss(x1s-xr,dx1)
temp2=omega((x2s-yr)/W,beta)
temp3=omega((x3s-zr)/L,beta)
sourc=temp1*temp2*temp3
temp1=gauss(x1i-xr,dx1)
temp3=omega((x3i+zr)/L,beta)
image=temp1*temp2*temp3
impulse=sourc+image
! traction = sigma . n
s=sig(i1,i2,i3)
t=s .tdot. n
! signed normal component
taun=SUM(t*n)
! absolute value of shear component
ts=t-taun*n
taus=SQRT(SUM(ts*ts))
! effective shear stress on fault plane
tau=MAX(0.d0,taus+friction*taun-cohesion)
! rake direction test only if | rake | < 3*Pi
IF (SUM(ts*r).LT.0.d0 .AND. ABS(rake).LT.pi2*1.5d0) CYCLE
! warning for wrong input
IF ((tau/tauc) .gt. 20) THEN
WRITE_DEBUG_INFO
WRITE (0,'("------------------------------------------")')
WRITE (0,'("wrong value of (a-b)sigma gives rise to")')
WRITE (0,'("(a - b) * sigma = ",ES11.3E2)') tauc
WRITE (0,'("tau = ",ES11.3E2)') tau
WRITE (0,'("tau_s = ",ES11.3E2)') taus
WRITE (0,'("tau_n = ",ES11.3E2)') taun
WRITE (0,'("tau / ((a - b) sigma) = ",ES11.3E2)') tau/tauc
WRITE (0,'("------------------------------------------")')
STOP 5
END IF
! shear traction direction
ts=ts/taus
! deviatoric strain rate
gammadot=vo*2._8*my_sinh(tau/tauc)
tm=MIN(tm,REAL(tau/mu/gammadot*(MIN(L,W)/sqrt(dx1*dx3))))
! provide the strain-rate on request
IF (PRESENT(vel)) THEN
vel(i1,i2,i3)=REAL(vel(i1,i2,i3)+gammadot*impulse*scaling)
END IF
! deviatoric strain
moment(i1,i2,i3)=moment(i1,i2,i3) .plus. &
(ts .sdyad. ((2._8*mu*impulse*gammadot)*n))
END DO
END DO
END DO
#endif
IF (PRESENT(maxwelltime)) maxwelltime=MIN(tm,maxwelltime)
END SUBROUTINE frictioneigenstress
!---------------------------------------------------------------------
!> function MonitorFriction
!! samples a scalar field along a specified planar surface.
!!
!! input:
!! @param x,y,z coordinates of the creeping segment
!! @param L dimension of segment in the depth direction
!! @param W dimension of segment in the strike direction
!! @param beta smoothing factor
!! @param sx1,2,3 dimension of the stress tensor array
!! @param dx1,2,3 sampling size
!! @param sig stress tensor array
!! @param structure frictional properties as a function of depth
!!
!! output:
!! @param patch list of strike- and dip-slip as a function of position
!! on the fault.
!!
!! \author sylvain barbot (10-16-07) - original form
!---------------------------------------------------------------------
SUBROUTINE monitorfriction(x,y,z,L,W,strike,dip,rake,beta, &
sx1,sx2,sx3,dx1,dx2,dx3,sig,prestress,structure,patch)
INTEGER, INTENT(IN) :: sx1,sx2,sx3
REAL*8, INTENT(IN) :: x,y,z,L,W,strike,rake,dip,beta,dx1,dx2,dx3
TYPE(TENSOR), DIMENSION(sx1,sx2,sx3), INTENT(IN) :: sig
TYPE(SLIPPATCH_STRUCT), ALLOCATABLE, DIMENSION(:,:), INTENT(INOUT) :: patch
TYPE(LAYER_STRUCT), DIMENSION(:), INTENT(IN) :: structure
TYPE(TENSOR_LAYER_STRUCT), DIMENSION(:), INTENT(IN) :: prestress
INTEGER :: i1,i2,i3,px2,px3,j2,j3
REAL*8 :: cstrike,sstrike,cdip,sdip,cr,sr
REAL*8 :: vo,tauc,taun,taus, &
friction,tau,cohesion
REAL*8 :: x1,x2,x3,xr,yr,zr
TYPE(TENSOR) :: s
REAL*8, DIMENSION(3) :: t,ts,n,sv,dv,r
cstrike=cos(strike)
sstrike=sin(strike)
cdip=cos(dip)
sdip=sin(dip)
cr=cos(rake)
sr=sin(rake)
! strike direction vector
sv=(/ sstrike, cstrike, 0._8 /)
! dip direction vector
dv=(/ -cstrike*sdip, +sstrike*sdip, -cdip /)
! number of samples in the dip and strike direction
px2=SIZE(patch,1)
px3=SIZE(patch,2)
! surface normal vector components
n(1)=+cdip*cstrike
n(2)=-cdip*sstrike
n(3)=-sdip
! rake vector component
r(1)=sstrike*cr+cstrike*sdip*sr
r(2)=cstrike*cr-sstrike*sdip*sr
r(3)=cdip*sr
! loop in the dip direction
DO j3=1,px3
! loop in the strike direction
DO j2=1,px2
CALL ref2local(x,y,z,xr,yr,zr)
! no translation in out of plane direction
yr=REAL(yr)+REAL((DBLE(j2)-DBLE(px2)/2._8-1._8)*dx2)
zr=REAL(zr)+REAL((DBLE(j3)-DBLE(px3)/2._8-1._8)*dx3)
CALL local2ref(xr,yr,zr,x1,x2,x3)
! initialize zero slip velocity
patch(j2,j3)%x1=x1
patch(j2,j3)%x2=x2
patch(j2,j3)%x3=x3
patch(j2,j3)%lx=yr
patch(j2,j3)%lz=zr
! discard out-of-bound locations
IF ( (x1 .GT. DBLE(sx1/2-1)*dx1) .OR. (x1 .LT. -DBLE(sx1/2)*dx1) &
.OR. (x2 .GT. DBLE(sx2/2-1)*dx2) .OR. (x2 .LT. -DBLE(sx2/2)*dx2) &
.OR. (x3 .GT. DBLE(sx3-1)*dx3) .OR. (x3 .LT. 0._8) ) CYCLE
! evaluates instantaneous creep velocity
CALL shiftedindex(x1,x2,x3,sx1,sx2,sx3,dx1,dx2,dx3,i1,i2,i3)
! retrieve friction parameters
vo=structure(i3)%gammadot0
tauc=structure(i3)%stressexponent
friction=structure(i3)%friction
cohesion=structure(i3)%cohesion
! traction = sigma . n
s=sig(i1,i2,i3)
patch(j2,j3)%sig=s
t=s .tdot. n
! signed normal component
taun=SUM(t*n)
! absolute value of shear component
ts=t-taun*n
taus=SQRT(SUM(ts*ts))
! effective shear stress on fault plane
tau=MAX(0.d0,taus+friction*taun-cohesion)
! rake direction test only if | rake | < 3*Pi
IF (SUM(ts*r).LT.0.d0 .AND. ABS(rake).LT.pi2*1.5d0) CYCLE
! shear stress
patch(j2,j3)%taus=taus
! creep rate
patch(j2,j3)%v=vo*2._8*my_sinh(tau/tauc)
! shear traction direction
ts=ts/taus
! strike-direction creep rate
patch(j2,j3)%vss=patch(j2,j3)%v*SUM(ts*sv)
! dip-direction creep rate
patch(j2,j3)%vds=patch(j2,j3)%v*SUM(ts*dv)
END DO
END DO
CONTAINS
!-----------------------------------------------
! subroutine ref2local
! convert reference Cartesian coordinates into
! the rotated, local fault coordinates system.
!-----------------------------------------------
SUBROUTINE ref2local(x,y,z,xp,yp,zp)
REAL*8, INTENT(IN) :: x,y,z
REAL*8, INTENT(OUT) :: xp,yp,zp
REAL*8 :: x2
x2 = cstrike*x -sstrike*y
xp = cdip *x2 -sdip *z
yp = sstrike*x +cstrike*y
zp = sdip *x2 +cdip *z
END SUBROUTINE ref2local
!-----------------------------------------------
! subroutine local2ref
! converts a set of coordinates from the rotated
! fault-aligned coordinate system into the
! reference, Cartesian coordinates system.
!-----------------------------------------------
SUBROUTINE local2ref(xp,yp,zp,x,y,z)
REAL*8, INTENT(IN) :: xp,yp,zp
REAL*8, INTENT(OUT) :: x,y,z
REAL*8 :: x2p
x2p= cdip*xp+sdip*zp
x = cstrike*x2p+sstrike*yp
y = -sstrike*x2p+cstrike*yp
z = -sdip*xp +cdip*zp
END SUBROUTINE local2ref
END SUBROUTINE monitorfriction
!---------------------------------------------------------------------
!> function FrictionAdd
!! update the cumulative slip of a creeping segment
!!
!! \author sylvain barbot (04-01-12) - original form
!---------------------------------------------------------------------
SUBROUTINE frictionadd(np,n,dt)
INTEGER, INTENT(IN) :: np
TYPE(PLANE_STRUCT), INTENT(INOUT), DIMENSION(np) :: n
REAL*8, INTENT(IN) :: dt
INTEGER :: px2,px3,j2,j3,k
! number of samples in the dip and strike direction
DO k=1,np
px2=SIZE(n(k)%patch,1)
px3=SIZE(n(k)%patch,2)
! loop in the dip direction
DO j3=1,px3
! loop in the strike direction
DO j2=1,px2
! cumulative strike-direction creep
n(k)%patch(j2,j3)%ss=n(k)%patch(j2,j3)%ss+dt*n(k)%patch(j2,j3)%vss
! cumulative dip-direction creep
n(k)%patch(j2,j3)%ds=n(k)%patch(j2,j3)%ds+dt*n(k)%patch(j2,j3)%vds
! cumulative creep
n(k)%patch(j2,j3)%slip=(n(k)%patch(j2,j3)%ds**2+n(k)%patch(j2,j3)%ss**2)**0.5
END DO
END DO
END DO
END SUBROUTINE frictionadd
END MODULE friction3d
| gpl-3.0 |
tkelman/OpenBLAS | lapack-netlib/SRC/zspsvx.f | 28 | 13208 | *> \brief <b> ZSPSVX computes the solution to system of linear equations A * X = B for OTHER matrices</b>
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ZSPSVX + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zspsvx.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zspsvx.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zspsvx.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE ZSPSVX( FACT, UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X,
* LDX, RCOND, FERR, BERR, WORK, RWORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER FACT, UPLO
* INTEGER INFO, LDB, LDX, N, NRHS
* DOUBLE PRECISION RCOND
* ..
* .. Array Arguments ..
* INTEGER IPIV( * )
* DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
* COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
* $ X( LDX, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZSPSVX uses the diagonal pivoting factorization A = U*D*U**T or
*> A = L*D*L**T to compute the solution to a complex system of linear
*> equations A * X = B, where A is an N-by-N symmetric matrix stored
*> in packed format and X and B are N-by-NRHS matrices.
*>
*> Error bounds on the solution and a condition estimate are also
*> provided.
*> \endverbatim
*
*> \par Description:
* =================
*>
*> \verbatim
*>
*> The following steps are performed:
*>
*> 1. If FACT = 'N', the diagonal pivoting method is used to factor A as
*> A = U * D * U**T, if UPLO = 'U', or
*> A = L * D * L**T, if UPLO = 'L',
*> where U (or L) is a product of permutation and unit upper (lower)
*> triangular matrices and D is symmetric and block diagonal with
*> 1-by-1 and 2-by-2 diagonal blocks.
*>
*> 2. If some D(i,i)=0, so that D is exactly singular, then the routine
*> returns with INFO = i. Otherwise, the factored form of A is used
*> to estimate the condition number of the matrix A. If the
*> reciprocal of the condition number is less than machine precision,
*> INFO = N+1 is returned as a warning, but the routine still goes on
*> to solve for X and compute error bounds as described below.
*>
*> 3. The system of equations is solved for X using the factored form
*> of A.
*>
*> 4. Iterative refinement is applied to improve the computed solution
*> matrix and calculate error bounds and backward error estimates
*> for it.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] FACT
*> \verbatim
*> FACT is CHARACTER*1
*> Specifies whether or not the factored form of A has been
*> supplied on entry.
*> = 'F': On entry, AFP and IPIV contain the factored form
*> of A. AP, AFP and IPIV will not be modified.
*> = 'N': The matrix A will be copied to AFP and factored.
*> \endverbatim
*>
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> = 'U': Upper triangle of A is stored;
*> = 'L': Lower triangle of A is stored.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of linear equations, i.e., the order of the
*> matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in] NRHS
*> \verbatim
*> NRHS is INTEGER
*> The number of right hand sides, i.e., the number of columns
*> of the matrices B and X. NRHS >= 0.
*> \endverbatim
*>
*> \param[in] AP
*> \verbatim
*> AP is COMPLEX*16 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)*(2*n-j)/2) = A(i,j) for j<=i<=n.
*> See below for further details.
*> \endverbatim
*>
*> \param[in,out] AFP
*> \verbatim
*> AFP is COMPLEX*16 array, dimension (N*(N+1)/2)
*> If FACT = 'F', then AFP is an input argument and on entry
*> contains the block diagonal matrix D and the multipliers used
*> to obtain the factor U or L from the factorization
*> A = U*D*U**T or A = L*D*L**T as computed by ZSPTRF, stored as
*> a packed triangular matrix in the same storage format as A.
*>
*> If FACT = 'N', then AFP is an output argument and on exit
*> contains the block diagonal matrix D and the multipliers used
*> to obtain the factor U or L from the factorization
*> A = U*D*U**T or A = L*D*L**T as computed by ZSPTRF, stored as
*> a packed triangular matrix in the same storage format as A.
*> \endverbatim
*>
*> \param[in,out] IPIV
*> \verbatim
*> IPIV is INTEGER array, dimension (N)
*> If FACT = 'F', then IPIV is an input argument and on entry
*> contains details of the interchanges and the block structure
*> of D, as determined by ZSPTRF.
*> 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.
*>
*> If FACT = 'N', then IPIV is an output argument and on exit
*> contains details of the interchanges and the block structure
*> of D, as determined by ZSPTRF.
*> \endverbatim
*>
*> \param[in] B
*> \verbatim
*> B is COMPLEX*16 array, dimension (LDB,NRHS)
*> The N-by-NRHS right hand side matrix B.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of the array B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[out] X
*> \verbatim
*> X is COMPLEX*16 array, dimension (LDX,NRHS)
*> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X.
*> \endverbatim
*>
*> \param[in] LDX
*> \verbatim
*> LDX is INTEGER
*> The leading dimension of the array X. LDX >= max(1,N).
*> \endverbatim
*>
*> \param[out] RCOND
*> \verbatim
*> RCOND is DOUBLE PRECISION
*> The estimate of the reciprocal condition number of the matrix
*> A. If RCOND is less than the machine precision (in
*> particular, if RCOND = 0), the matrix is singular to working
*> precision. This condition is indicated by a return code of
*> INFO > 0.
*> \endverbatim
*>
*> \param[out] FERR
*> \verbatim
*> FERR is DOUBLE PRECISION array, dimension (NRHS)
*> The estimated forward error bound for each solution vector
*> X(j) (the j-th column of the solution matrix X).
*> If XTRUE is the true solution corresponding to X(j), FERR(j)
*> is an estimated upper bound for the magnitude of the largest
*> element in (X(j) - XTRUE) divided by the magnitude of the
*> largest element in X(j). The estimate is as reliable as
*> the estimate for RCOND, and is almost always a slight
*> overestimate of the true error.
*> \endverbatim
*>
*> \param[out] BERR
*> \verbatim
*> BERR is DOUBLE PRECISION array, dimension (NRHS)
*> The componentwise relative backward error of each solution
*> vector X(j) (i.e., the smallest relative change in
*> any element of A or B that makes X(j) an exact solution).
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is COMPLEX*16 array, dimension (2*N)
*> \endverbatim
*>
*> \param[out] RWORK
*> \verbatim
*> RWORK is DOUBLE PRECISION array, dimension (N)
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> > 0: if INFO = i, and i is
*> <= N: D(i,i) is exactly zero. The factorization
*> has been completed but the factor D is exactly
*> singular, so the solution and error bounds could
*> not be computed. RCOND = 0 is returned.
*> = N+1: D is nonsingular, but RCOND is less than machine
*> precision, meaning that the matrix is singular
*> to working precision. Nevertheless, the
*> solution and error bounds are computed because
*> there are a number of situations where the
*> computed solution can be more accurate than the
*> value of RCOND would suggest.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date April 2012
*
*> \ingroup complex16OTHERsolve
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> The packed storage scheme is illustrated by the following example
*> when N = 4, UPLO = 'U':
*>
*> Two-dimensional storage of the symmetric matrix A:
*>
*> a11 a12 a13 a14
*> a22 a23 a24
*> a33 a34 (aij = aji)
*> a44
*>
*> Packed storage of the upper triangle of A:
*>
*> AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ]
*> \endverbatim
*>
* =====================================================================
SUBROUTINE ZSPSVX( FACT, UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X,
$ LDX, RCOND, FERR, BERR, WORK, RWORK, INFO )
*
* -- LAPACK driver routine (version 3.4.1) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* April 2012
*
* .. Scalar Arguments ..
CHARACTER FACT, UPLO
INTEGER INFO, LDB, LDX, N, NRHS
DOUBLE PRECISION RCOND
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
$ X( LDX, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL NOFACT
DOUBLE PRECISION ANORM
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH, ZLANSP
EXTERNAL LSAME, DLAMCH, ZLANSP
* ..
* .. External Subroutines ..
EXTERNAL XERBLA, ZCOPY, ZLACPY, ZSPCON, ZSPRFS, ZSPTRF,
$ ZSPTRS
* ..
* .. 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( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) )
$ THEN
INFO = -2
ELSE IF( N.LT.0 ) THEN
INFO = -3
ELSE IF( NRHS.LT.0 ) THEN
INFO = -4
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
INFO = -11
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZSPSVX', -INFO )
RETURN
END IF
*
IF( NOFACT ) THEN
*
* Compute the factorization A = U*D*U**T or A = L*D*L**T.
*
CALL ZCOPY( N*( N+1 ) / 2, AP, 1, AFP, 1 )
CALL ZSPTRF( UPLO, N, AFP, IPIV, INFO )
*
* Return if INFO is non-zero.
*
IF( INFO.GT.0 )THEN
RCOND = ZERO
RETURN
END IF
END IF
*
* Compute the norm of the matrix A.
*
ANORM = ZLANSP( 'I', UPLO, N, AP, RWORK )
*
* Compute the reciprocal of the condition number of A.
*
CALL ZSPCON( UPLO, N, AFP, IPIV, ANORM, RCOND, WORK, INFO )
*
* Compute the solution vectors X.
*
CALL ZLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
CALL ZSPTRS( UPLO, N, NRHS, AFP, IPIV, X, LDX, INFO )
*
* Use iterative refinement to improve the computed solutions and
* compute error bounds and backward error estimates for them.
*
CALL ZSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX, FERR,
$ BERR, WORK, RWORK, INFO )
*
* Set INFO = N+1 if the matrix is singular to working precision.
*
IF( RCOND.LT.DLAMCH( 'Epsilon' ) )
$ INFO = N + 1
*
RETURN
*
* End of ZSPSVX
*
END
| bsd-3-clause |
blue236/gcc | gcc/testsuite/gfortran.dg/auto_char_pointer_array_result_1.f90 | 188 | 1056 | ! { dg-do run }
! Tests the fixes for PR25597 and PR27096.
!
! This test combines the PR testcases.
!
character(10), dimension (2) :: implicit_result
character(10), dimension (2) :: explicit_result
character(10), dimension (2) :: source
source = "abcdefghij"
explicit_result = join_1(source)
if (any (explicit_result .ne. source)) call abort ()
implicit_result = reallocate_hnv (source, size(source, 1), LEN (source))
if (any (implicit_result .ne. source)) call abort ()
contains
! This function would cause an ICE in gfc_trans_deferred_array.
function join_1(self) result(res)
character(len=*), dimension(:) :: self
character(len=len(self)), dimension(:), pointer :: res
allocate (res(2))
res = self
end function
! This function originally ICEd and latterly caused a runtime error.
FUNCTION reallocate_hnv(p, n, LEN)
CHARACTER(LEN=LEN), DIMENSION(:), POINTER :: reallocate_hnv
character(*), dimension(:) :: p
ALLOCATE (reallocate_hnv(n))
reallocate_hnv = p
END FUNCTION reallocate_hnv
end
| gpl-2.0 |
sigma-random/gcc | gcc/testsuite/gfortran.dg/char_result_5.f90 | 188 | 2864 | ! Related to PR 15326. Test calls to string functions whose lengths
! depend on various types of scalar value.
! { dg-do run }
pure function select (selector, iftrue, iffalse)
logical, intent (in) :: selector
integer, intent (in) :: iftrue, iffalse
integer :: select
if (selector) then
select = iftrue
else
select = iffalse
end if
end function select
program main
implicit none
interface
pure function select (selector, iftrue, iffalse)
logical, intent (in) :: selector
integer, intent (in) :: iftrue, iffalse
integer :: select
end function select
end interface
type pair
integer :: left, right
end type pair
integer, target :: i
integer, pointer :: ip
real, target :: r
real, pointer :: rp
logical, target :: l
logical, pointer :: lp
complex, target :: c
complex, pointer :: cp
character, target :: ch
character, pointer :: chp
type (pair), target :: p
type (pair), pointer :: pp
character (len = 10) :: dig
i = 100
r = 50.5
l = .true.
c = (10.9, 11.2)
ch = '1'
p%left = 40
p%right = 50
ip => i
rp => r
lp => l
cp => c
chp => ch
pp => p
dig = '1234567890'
call test (f1 (i), 200)
call test (f1 (ip), 200)
call test (f1 (-30), 60)
call test (f1 (i / (-4)), 50)
call test (f2 (r), 100)
call test (f2 (rp), 100)
call test (f2 (70.1), 140)
call test (f2 (r / 4), 24)
call test (f2 (real (i)), 200)
call test (f3 (l), 50)
call test (f3 (lp), 50)
call test (f3 (.false.), 55)
call test (f3 (i < 30), 55)
call test (f4 (c), 10)
call test (f4 (cp), 10)
call test (f4 (cmplx (60.0, r)), 60)
call test (f4 (cmplx (r, 1.0)), 50)
call test (f5 (ch), 11)
call test (f5 (chp), 11)
call test (f5 ('23'), 12)
call test (f5 (dig (3:)), 13)
call test (f5 (dig (10:)), 10)
call test (f6 (p), 145)
call test (f6 (pp), 145)
call test (f6 (pair (20, 10)), 85)
call test (f6 (pair (i / 2, 1)), 106)
contains
function f1 (i)
integer :: i
character (len = abs (i) * 2) :: f1
f1 = ''
end function f1
function f2 (r)
real :: r
character (len = floor (r) * 2) :: f2
f2 = ''
end function f2
function f3 (l)
logical :: l
character (len = select (l, 50, 55)) :: f3
f3 = ''
end function f3
function f4 (c)
complex :: c
character (len = int (c)) :: f4
f4 = ''
end function f4
function f5 (c)
character :: c
character (len = scan ('123456789', c) + 10) :: f5
f5 = ''
end function f5
function f6 (p)
type (pair) :: p
integer :: i
character (len = sum ((/ p%left, p%right, (i, i = 1, 10) /))) :: f6
f6 = ''
end function f6
subroutine test (string, length)
character (len = *) :: string
integer, intent (in) :: length
if (len (string) .ne. length) call abort
end subroutine test
end program main
| gpl-2.0 |
tkelman/OpenBLAS | lapack-netlib/TESTING/LIN/zpbt01.f | 32 | 7476 | *> \brief \b ZPBT01
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* SUBROUTINE ZPBT01( UPLO, N, KD, A, LDA, AFAC, LDAFAC, RWORK,
* RESID )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER KD, LDA, LDAFAC, N
* DOUBLE PRECISION RESID
* ..
* .. Array Arguments ..
* DOUBLE PRECISION RWORK( * )
* COMPLEX*16 A( LDA, * ), AFAC( LDAFAC, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZPBT01 reconstructs a Hermitian positive definite band matrix A from
*> its L*L' or U'*U factorization and computes the residual
*> norm( L*L' - A ) / ( N * norm(A) * EPS ) or
*> norm( U'*U - A ) / ( N * norm(A) * EPS ),
*> where EPS is the machine epsilon, L' is the conjugate transpose of
*> L, and U' is the conjugate transpose of U.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> Specifies whether the upper or lower triangular part of the
*> Hermitian matrix A is stored:
*> = 'U': Upper triangular
*> = 'L': Lower triangular
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of rows and columns of the matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in] KD
*> \verbatim
*> KD is INTEGER
*> The number of super-diagonals of the matrix A if UPLO = 'U',
*> or the number of sub-diagonals if UPLO = 'L'. KD >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is COMPLEX*16 array, dimension (LDA,N)
*> The original Hermitian band matrix A. If UPLO = 'U', the
*> upper triangular part of A is stored as a band matrix; if
*> UPLO = 'L', the lower triangular part of A is stored. The
*> columns of the appropriate triangle are stored in the columns
*> of A and the diagonals of the triangle are stored in the rows
*> of A. See ZPBTRF for further details.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER.
*> The leading dimension of the array A. LDA >= max(1,KD+1).
*> \endverbatim
*>
*> \param[in] AFAC
*> \verbatim
*> AFAC is COMPLEX*16 array, dimension (LDAFAC,N)
*> The factored form of the matrix A. AFAC contains the factor
*> L or U from the L*L' or U'*U factorization in band storage
*> format, as computed by ZPBTRF.
*> \endverbatim
*>
*> \param[in] LDAFAC
*> \verbatim
*> LDAFAC is INTEGER
*> The leading dimension of the array AFAC.
*> LDAFAC >= max(1,KD+1).
*> \endverbatim
*>
*> \param[out] RWORK
*> \verbatim
*> RWORK is DOUBLE PRECISION array, dimension (N)
*> \endverbatim
*>
*> \param[out] RESID
*> \verbatim
*> RESID is DOUBLE PRECISION
*> If UPLO = 'L', norm(L*L' - A) / ( N * norm(A) * EPS )
*> If UPLO = 'U', norm(U'*U - A) / ( N * norm(A) * EPS )
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup complex16_lin
*
* =====================================================================
SUBROUTINE ZPBT01( UPLO, N, KD, A, LDA, AFAC, LDAFAC, RWORK,
$ RESID )
*
* -- LAPACK test routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER KD, LDA, LDAFAC, N
DOUBLE PRECISION RESID
* ..
* .. Array Arguments ..
DOUBLE PRECISION RWORK( * )
COMPLEX*16 A( LDA, * ), AFAC( LDAFAC, * )
* ..
*
* =====================================================================
*
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, J, K, KC, KLEN, ML, MU
DOUBLE PRECISION AKK, ANORM, EPS
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH, ZLANHB
COMPLEX*16 ZDOTC
EXTERNAL LSAME, DLAMCH, ZLANHB, ZDOTC
* ..
* .. External Subroutines ..
EXTERNAL ZDSCAL, ZHER, ZTRMV
* ..
* .. Intrinsic Functions ..
INTRINSIC DBLE, DIMAG, MAX, MIN
* ..
* .. Executable Statements ..
*
* Quick exit if N = 0.
*
IF( N.LE.0 ) THEN
RESID = ZERO
RETURN
END IF
*
* Exit with RESID = 1/EPS if ANORM = 0.
*
EPS = DLAMCH( 'Epsilon' )
ANORM = ZLANHB( '1', UPLO, N, KD, A, LDA, RWORK )
IF( ANORM.LE.ZERO ) THEN
RESID = ONE / EPS
RETURN
END IF
*
* Check the imaginary parts of the diagonal elements and return with
* an error code if any are nonzero.
*
IF( LSAME( UPLO, 'U' ) ) THEN
DO 10 J = 1, N
IF( DIMAG( AFAC( KD+1, J ) ).NE.ZERO ) THEN
RESID = ONE / EPS
RETURN
END IF
10 CONTINUE
ELSE
DO 20 J = 1, N
IF( DIMAG( AFAC( 1, J ) ).NE.ZERO ) THEN
RESID = ONE / EPS
RETURN
END IF
20 CONTINUE
END IF
*
* Compute the product U'*U, overwriting U.
*
IF( LSAME( UPLO, 'U' ) ) THEN
DO 30 K = N, 1, -1
KC = MAX( 1, KD+2-K )
KLEN = KD + 1 - KC
*
* Compute the (K,K) element of the result.
*
AKK = ZDOTC( KLEN+1, AFAC( KC, K ), 1, AFAC( KC, K ), 1 )
AFAC( KD+1, K ) = AKK
*
* Compute the rest of column K.
*
IF( KLEN.GT.0 )
$ CALL ZTRMV( 'Upper', 'Conjugate', 'Non-unit', KLEN,
$ AFAC( KD+1, K-KLEN ), LDAFAC-1,
$ AFAC( KC, K ), 1 )
*
30 CONTINUE
*
* UPLO = 'L': Compute the product L*L', overwriting L.
*
ELSE
DO 40 K = N, 1, -1
KLEN = MIN( KD, N-K )
*
* Add a multiple of column K of the factor L to each of
* columns K+1 through N.
*
IF( KLEN.GT.0 )
$ CALL ZHER( 'Lower', KLEN, ONE, AFAC( 2, K ), 1,
$ AFAC( 1, K+1 ), LDAFAC-1 )
*
* Scale column K by the diagonal element.
*
AKK = AFAC( 1, K )
CALL ZDSCAL( KLEN+1, AKK, AFAC( 1, K ), 1 )
*
40 CONTINUE
END IF
*
* Compute the difference L*L' - A or U'*U - A.
*
IF( LSAME( UPLO, 'U' ) ) THEN
DO 60 J = 1, N
MU = MAX( 1, KD+2-J )
DO 50 I = MU, KD + 1
AFAC( I, J ) = AFAC( I, J ) - A( I, J )
50 CONTINUE
60 CONTINUE
ELSE
DO 80 J = 1, N
ML = MIN( KD+1, N-J+1 )
DO 70 I = 1, ML
AFAC( I, J ) = AFAC( I, J ) - A( I, J )
70 CONTINUE
80 CONTINUE
END IF
*
* Compute norm( L*L' - A ) / ( N * norm(A) * EPS )
*
RESID = ZLANHB( '1', UPLO, N, KD, AFAC, LDAFAC, RWORK )
*
RESID = ( ( RESID / DBLE( N ) ) / ANORM ) / EPS
*
RETURN
*
* End of ZPBT01
*
END
| bsd-3-clause |
blue236/gcc | gcc/testsuite/gfortran.dg/iso_fortran_env_1.f90 | 136 | 1193 | ! { dg-do run }
module iso_fortran_env
real :: x
end module iso_fortran_env
subroutine bar
use , intrinsic :: iso_fortran_env
implicit none
if (file_storage_size /= 8) call abort
if (character_storage_size /= 8) call abort
if (all (numeric_storage_size /= [ 8, 16, 32, 64, 128])) call abort
if (input_unit /= 5) call abort
if (output_unit /= 6) call abort
if (error_unit /= 0) call abort
if (iostat_end /= -1) call abort
if (iostat_eor /= -2) call abort
end
subroutine bar2
use , intrinsic :: iso_fortran_env, only : file_storage_size, &
character_storage_size, numeric_storage_size, input_unit, output_unit, &
error_unit, iostat_end, iostat_eor
implicit none
if (file_storage_size /= 8) call abort
if (character_storage_size /= 8) call abort
if (all (numeric_storage_size /= [ 8, 16, 32, 64, 128])) call abort
if (input_unit /= 5) call abort
if (output_unit /= 6) call abort
if (error_unit /= 0) call abort
if (iostat_end /= -1) call abort
if (iostat_eor /= -2) call abort
end
program test
use , intrinsic :: iso_fortran_env, uu => output_unit
implicit none
if (input_unit /= 5 .or. uu /= 6) call abort
call bar
call bar2
end
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/velvct/vvdata.f | 1 | 19378 | C
C $Id: vvdata.f,v 1.15 2008-07-27 00:17:35 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE VVDATA
C
C Calling this do-nothing subroutine forces "ld" to load the following
C block data routine (but only if they are in the same ".f" file).
C
RETURN
C
END
CNOSPLIT
BLOCKDATA VVDATAX
C
C This 'routine' sets the default values of the VVECTR parameters.
C
C ---------------------------------------------------------------------
C
C NOTE:
C Since implicit typing is used for all real and integer variables
C a consistent length convention has been adopted to help clarify the
C significance of the variables encountered in the code for this
C utility. All local variable and subroutine parameter identifiers
C are limited to 1,2,or 3 characters. Four character names identify
C members of common blocks. Five and 6 character variable names
C denote PARAMETER constants or subroutine or function names.
C
C Declare the VV common blocks.
C
C IPLVLS - Maximum number of color threshold level values
C IPAGMX - Maximum number of area groups allowed in the area map
C
PARAMETER (IPLVLS = 256, IPAGMX = 64)
C
C Integer and real common block variables
C
C
COMMON /VVCOM/
+ IUD1 ,IVD1 ,IPD1 ,IXDM ,
+ IYDN ,VLOM ,VHIM ,ISET ,
+ VRMG ,VRLN ,VFRC ,IXIN ,
+ IYIN ,ISVF ,UUSV ,UVSV ,
+ UPSV ,IMSK ,ICPM ,UVPS ,
+ UVPL ,UVPR ,UVPB ,UVPT ,
+ UWDL ,UWDR ,UWDB ,UWDT ,
+ UXC1 ,UXCM ,UYC1 ,UYCN ,
+ NLVL ,IPAI ,ICTV ,WDLV ,
+ UVMN ,UVMX ,PMIN ,PMAX ,
+ RVMN ,RVMX ,RDMN ,RDMX ,
+ ISPC ,RVMD ,IPLR ,IVST ,
+ IVPO ,ILBL ,IDPF ,IMSG ,
+ ICLR(IPLVLS) ,TVLU(IPLVLS)
C
C Arrow size/shape parameters
C
COMMON / VVARO /
+ HDSZ ,HINF ,HANG ,IAST ,
+ HSIN ,HCOS ,FAMN ,FAMX ,
+ UVMG ,FAIR ,FAWR ,FAWF ,
+ FAXR ,FAXF ,FAYR ,FAYF ,
+ AROX(8) ,AROY(8) ,FXSZ ,FYSZ ,
+ FXRF ,FXMN ,FYRF ,FYMN ,
+ FWRF ,FWMN ,FIRF ,FIMN ,
+ AXMN ,AXMX ,AYMN ,AYMX ,
+ IACM ,IAFO ,WBAD ,WBTF ,
+ WBCF ,WBDF ,WBSC
C
C
C Text related parameters
C
COMMON /VVTXP /
+ FCWM ,ICSZ ,
+ FMNS ,FMNX ,FMNY ,IMNP ,IMNC ,
+ FMXS ,FMXX ,FMXY ,IMXP ,IMXC ,
+ FZFS ,FZFX ,FZFY ,IZFP ,IZFC ,
+ FILS ,FILX ,FILY ,IILP ,IILC ,
+ FLBS ,ILBC
C
C Character variable declartions
C
CHARACTER*160 CSTR
PARAMETER (IPCHSZ=36)
CHARACTER*(IPCHSZ) CMNT,CMXT,CZFT,CLBT,CILT
C
C Text string parameters
C
COMMON /VVCHAR/ CSTR,CMNT,CMXT,CZFT,CLBT,CILT
C
SAVE /VVCOM/, /VVARO/, /VVTXP/, /VVCHAR/
C
C The mapping common block: made available to user mapping routines
C
COMMON /VVMAP/
+ IMAP ,
+ XVPL ,XVPR ,YVPB ,YVPT ,
+ WXMN ,WXMX ,WYMN ,WYMX ,
+ XLOV ,XHIV ,YLOV ,YHIV ,
+ SXDC ,SYDC ,NXCT ,NYCT ,
+ RLEN ,LNLG ,INVX ,INVY ,
+ ITRT ,IWCT ,FW2W ,FH2H ,
+ DVMN ,DVMX ,RBIG ,IBIG
C
SAVE /VVMAP/
C
C Math constants
C
PARAMETER (PDTOR = 0.017453292519943,
+ PRTOD = 57.2957795130823,
+ P1XPI = 3.14159265358979,
+ P2XPI = 6.28318530717959,
+ P1D2PI = 1.57079632679489,
+ P5D2PI = 7.85398163397448)
C
C --------------------------------------------------------------------
C *********************************************************************
C
C Initialization of VVCOM
C
C IUD1 -- 'UD1' -- First dimension of U
C
DATA IUD1 / -1 /
C
C IVD1 -- 'VD1' -- First dimension of V
C
DATA IVD1 / -1 /
C
C IPD1 -- 'PD1' -- First dimension of P
C
DATA IPD1 / -1 /
C
C IXDM -- 'XDM' -- First dimension of data for U,V,P
C
DATA IXDM / -1 /
C
C IYDN -- 'YDN' -- Second dimension of data for U,V,P
C
DATA IYDN / -1 /
C
C VLOM -- 'VLC' -- Vector low cutoff -- minimum size vector to plot
C Old FLO parameter
C
DATA VLOM / 0.0 /
C
C VHIM -- 'VHC' -- Vector high cutoff -- maximum size vector to plot
C Old HI parameter
C
DATA VHIM / 0.0 /
C
C ISET -- 'SET' -- The Set call flag - Old NSET parameter
C
DATA ISET / 1 /
C
C VRMG -- 'VRM' -- Reference magnitude - the magnitude represented by
C the reference length. If 0.0, the maximum magnitude
C is used as the reference magnitude
C
DATA VRMG / 0.0 /
C
C
C VRLN -- 'VRL' -- Old LENGTH parameter (but stored as a fraction of
C the viewport width).
C 0.0 causes VVINIT to select a value.
C
DATA VRLN / 0.0 /
C
C VFRC -- 'VFR' -- Fraction of the maximum length used to represent
C the minimum length vector. 1.0 causes all vectors to
C become maximum length. 0.0 means the minimum length
C is linearly scaled from the maximum length (as now),
C
DATA VFRC / 0.0 /
C
C IXIN -- 'XIN' -- The X Axis grid increment, must be > 0
C IYIN -- 'YIN' -- The Y Axis grid increment, must be > 0
C
DATA IXIN / 1 /
DATA IYIN / 1 /
C
C
C ISVF -- 'SVF' -- Special value flag
C Old ISPV parameter
C
DATA ISVF / 0 /
C
C UUSV -- 'USV' -- The U array special value
C Old SPV(1)
C
DATA UUSV / 1.0E12 /
C
C UVSV -- 'VSV' -- The V array special value
C Old SPV(2)
C
DATA UVSV / 1.0E12 /
C
C UPSV -- 'PSV' -- The P array special value
C
DATA UPSV / 1.0E12 /
C
C IMSK -- 'MSK' -- Mask the vectors to an area map: <1 -- no mapping,
C 1 - high precision mapping;>1 low precision mapping
C
DATA IMSK / 0 /
C
C ICPM -- 'CPM' -- the compatibility mode. If 0, the default, the
C the behavior depends on whether the old routines
C or the new routines are called. If >0 the FX,FY,
C MXF,MYF functions are used. Additionally, when
C used in conjunction with the VELVCT routine,
C has a meaningful range from -4 to +4 inclusive,
C where various combinations are allowed to use or
C ignore 1) the optional input parameters to
C VELVCT, 2) the data in VEC1 and VEC2 common
C 3) FX, etc routines, as follows:
C
C -4: no FX, ignore params, ignore VEC1,VEC2
C -3: no FX, ignore params, use VEC1,VEC2
C -2: no FX, use params, ignore VEC1,VEC2
C -1: no FX, use params, use VEC1,VEC2
C 0: default: same as -4 if VVINIT,VVECTR called,
C same as +1 if VELVCT,EZVEC, or VELVEC called.
C +1: FX, use params, use VEC1,VEC2
C +2: FX, use params, ignore VEC1,VEC2
C +3: FX, ignore params, use VEC1,VEC2
C +4: FX, ignore params, ignore VEC1,VEC2
C
C FX means using FX,FY,MXF,and MYF
C Params include FLO,HI,NSET,LENGTH,ISPV,SPV.
C VEC1,VEC2 data includes all settable values
C from these two common blocks.
C When parameters and common block values are
C used they override anything done using the
C vvset routines
C
DATA ICPM / 0 /
C
C UVPS -- 'VPS' -- The viewport mode
C
DATA UVPS / 0.25 /
C
C UVPL -- 'VPL' -- Viewport left
C
DATA UVPL / 0.05 /
C
C UVPR -- 'VPR' -- Viewport right
C
DATA UVPR / 0.95 /
C
C UVPB -- 'VPB' -- Viewport bottom
C
DATA UVPB / 0.05 /
C
C UVPT -- 'VPT' -- Viewport top
C
DATA UVPT / 0.95 /
C
C UWDL -- 'WDL' -- Window left
C
DATA UWDL / 0.0 /
C
C UWDR -- 'WDR' -- Window right
C
DATA UWDR / 0.0 /
C
C UWDB -- 'WDB' -- Window bottom
C
DATA UWDB / 0.0 /
C
C UWDT -- 'WDT' -- Window top
C
DATA UWDT / 0.0 /
C
C UXC1 -- 'XC1' -- minimum X coord
C
DATA UXC1 / 0.0 /
C
C UXCM -- 'XCM' -- maximum Y coord
C
DATA UXCM / 0.0 /
C
C UYC1 -- 'YC1' -- minimum Y coord
C
DATA UYC1 / 0.0 /
C
C UYCN -- 'YCN' -- maximum Y coord
C
DATA UYCN / 0.0 /
C
C NLVL -- 'NLV' -- number of distinct colors to use for the
C independent variable mapping -- cannot exceed
C IPLVLS, number of elements used in CLR and TVL
C
DATA NLVL / 0 /
C
C IPAI -- 'PAI' -- the current level -- must be set before
C modifying an internal level array value
C
DATA IPAI / 1 /
C
C ICTV -- 'CTV' -- compute thresholds flag:
C -2: color vectors by scalar value, user sets TVL
C -1: color vectors by vector magnitude, user sets TVL
C 0: no vector coloring
C +1: color vectors by magnitude, VVINIT sets TVL
C +2: color vectors by scalar array, VVINIT sets TVL
C
DATA ICTV / 0 /
C
C WDLV -- 'LWD' -- the width of a vector line
C
DATA WDLV / 1.0 /
C
C UVMN -- the minimum vector magnitude
C UVMX -- the maximum vector magnitude
C PMIN -- 'PMN' -- the minimum scalar array value, read-only
C PMAX -- 'PMX' -- the maximum scalar array value, read-only
C
DATA UVMN / 0.0 /
DATA UVMX / 0.0 /
DATA PMIN / 0.0 /
DATA PMAX / 0.0 /
C
C RVMN -- 'VMN' -- the minimum vector magnitude, read-only
C RVMX -- 'VMX' -- the maximum vector magnitude, read-only
C RDMN -- 'DMN' -- the minimum vector in NDC, read-only
C RDMX -- 'DMX' -- the maximum vector in NDC, read-only
C
DATA RVMN / 0.0 /
DATA RVMX / 0.0 /
DATA RDMN / 0.0 /
DATA RDMX / 0.0 /
C
C ISPC -- 'SPC' -- Special color --
C < 0: no P special value
C = 0: don't draw vector that has a P spec val
C > 0: draw P special values using color SPC
C
C DATA ISPC / -1 /
C
C RVMD -- 'VMD' -- vector minimum distance
C
DATA RVMD / 0.0 /
C
C IPLR -- 'PLR' -- Polar coordinates for UV array flag
C
DATA IPLR / 0 /
C
C IVST -- 'VST' -- Vector statistics flag
C
DATA IVST / 0 /
C
C
C IVPO -- 'VPO' -- vector position flag: < 0 - head at position,
C 0 - center at position, > 0 - tail at position
C
DATA IVPO / 0 /
C
C
C ILBL -- 'LBL' -- Vector labelling flag: 0 - don't, 1 - do
C
DATA ILBL / 0 /
C
C IDPF -- 'DPF' -- decimal point flag for vector label strings
C 1 - include decimal point, non-zero don't
C
DATA IDPF / 1 /
C
C ICLR -- 'CLR' -- the GKS color index value
C
DATA ICLR / IPLVLS * 1 /
C
C TVLU -- 'TVL' -- the list of threshold values
C
DATA TVLU / IPLVLS * 0.0 /
C
C End of VVCOM intialization
C
C --------------------------------------------------------------------
C
C VVARO -Arrow size/shape parameters
C
C HDSZ - head size as fraction of arrow length
C
DATA HDSZ / 0.25 /
C
C HINF - interior point of head as fraction of head size
C
DATA HINF / 0.5 /
C
C HANG - half angle of head
C
DATA HANG / 22.5 /
C
C FAMN -- 'AMN' -- arrow head min size as FVPW
C (fraction of viewport width)
C
DATA FAMN / 0.005 /
C
C FAMX -- 'AMX' -- arrow head max size as FVPW
C
DATA FAMX / 0.05 /
C
C IAST -- 'AST' -- arrow style (currently line or filled)
C
DATA IAST / 0 /
C
C FAIR -- 'AIR' -- arrow interior position (reference)
C
DATA FAIR / 0.33 /
C
C FAWR -- 'AWR' -- arrow width (reference)
C
DATA FAWR / 0.1 /
C
C FAWF -- 'AWF' -- arrow width (minimum)
C
DATA FAWF / 0.25 /
C
C FAXR -- 'AXR' -- arrowhead X-coord length (reference)
C
DATA FAXR / 0.36 /
C
C FAXF -- 'AXF' -- arrowhead X-coord length (minimum)
C
DATA FAXF / 0.25 /
C
C FAYR -- 'AYR' -- arrowhead Y-coord length (reference)
C
DATA FAYR / 0.12 /
C
C FAYF -- 'AYF' -- arrowhead Y-coord length (minimum)
C
DATA FAYF / 0.25 /
C
C IACM -- 'ACM' -- arrow color mode
C (ignored if AST = 0)
C (if CTV is 0, all lines and fill become mono;
C only -2, -1, and 0 will be distinguishable states)
C -2 multi-fill, no-line
C -1 no-fill, multi-line
C 0 multi-fill, mono-line
C 1 mono-fill, multi-line
C 2 multi-fill, multi-line
C
C
DATA IACM / 0 /
C
C IAFO -- 'AFO' -- arrow fill over (arrow lines)
C
DATA IAFO / 1 /
C
C WBAD -- 'WBA' -- wind barb angle
C
DATA WBAD / 62.0 /
C
C WBTF -- 'WBT' -- wind barb tic size (fraction of wb length)
C
DATA WBTF / 0.33 /
C
C WBCF -- 'WBC' -- wind barb zero circle size (fraction of wb length)
C
DATA WBCF / 0.25 /
C
C WBDF -- 'WBD' -- wind barb distance (spacing beteen ticks as
C fraction of wb length)
C
DATA WBDF / 0.1 /
C
C WBSC -- 'WBS' -- wind barb scale factor
C
DATA WBSC / 1.0 /
C
C
C --------------------------------------------------------------------
C
C VVTXP - Text parameters
C
C FCWM -- 'CWM' -- character width multiple, scale factor for all
C text put out by the VELVCT routine
C
DATA FCWM / 1.0 /
C
C ICCM -- internal - maximum length of character strings
C
DATA ICSZ / IPCHSZ /
C
C FMNS -- 'MNS' -- size of text for minimum vector string as FVPW
C FMNX -- 'MNX' -- X position of minimum vector string as FVPW
C FMNY -- 'MNY' -- Y position of minimum vector string as FVPW
C IMNP -- 'MNP' -- minimum vector string position flag
C IMNC -- 'MNC' -- color of text for minimum vector label
C
DATA FMNS / 0.0075 /
DATA FMNX / 0.475 /
DATA FMNY / -0.01 /
DATA IMNP / 4 /
DATA IMNC / -1 /
C
C FMXS -- 'MXS' -- size of text for maximum vector string as FVPW
C FMXX -- 'MXX' -- X position of maximum vector string as FVPW
C FMXY -- 'MXY' -- Y position of maximum vector string as FVPW
C IMXP -- 'MXP' -- maximum vector string position flag
C IMNC -- 'MXC' -- color of text for maximum vector label
C
DATA FMXS / 0.0075 /
DATA FMXX / 0.525 /
DATA FMXY / -0.01 /
DATA IMXP / 2 /
DATA IMXC / -1 /
C
C FZFS -- 'ZFS' -- size of text for zero field string as FVPW
C FZFX -- 'ZFX' -- X position of zero field string as FVPW
C FZFY -- 'ZFY' -- Y position of zero field string as FVPW
C IZFP -- 'ZFP' -- zero field string position flag
C IMNC -- 'ZFC' -- color of text for zero field label
C
DATA FZFS / 0.033 /
DATA FZFX / 0.5 /
DATA FZFY / 0.5 /
DATA IZFP / 0 /
DATA IZFC / -1 /
C
C FLBS -- 'LBS' -- vector label text size as FVPW
C IMNC -- 'LBC' -- color of text for vector labels
C
DATA FLBS / 0.007 /
DATA ILBC / -1 /
C
C The informational label has not yet been implemented
C FILS -- 'ILS' -- size of text for informational label string as FVPW
C FILX -- 'ILX' -- X position of informational label string as FVPW
C FILY -- 'ILY' -- Y position of informational label string as FVPW
C IILP -- 'ILP' -- informational label string position flag
C IILC -- 'ILC' -- color of text for informational label
C
DATA FILS / 0.05 /
DATA FILX / 0.0 /
DATA FILY / 0.0 /
DATA IILP / 0 /
DATA IILC / -1 /
C
C ---------------------------------------------------------------------
C
C Beginning of VVCHAR initialization
C
DATA CMNT / 'Minimum Vector' /
DATA CMXT / 'Maximum Vector' /
DATA CZFT / 'ZERO FIELD' /
DATA CILT / 'Vector Field Map' /
C
C End of VVCHAR initialization
C
C *********************************************************************
C
C VVMAP initialization
C
C RLEN -- 'RML' -- Vector max length in WC
C
DATA RLEN / 0.0 /
C
C ITRT -- 'TRT' -- Transform type flag:
C 0 - transform position only
C 1 - transform position and angle
C -1 - transform position, angle, and magnitude
C
DATA ITRT / 1 /
C
C DVMN -- the minimum vector size in NDC
C DVMX -- the maximum vector size in NDC
C
DATA DVMN / 0.0 /
DATA DVMX / 0.0 /
C
C IMAP -- 'MAP' -- the mapping transformation to use
C
DATA IMAP / 0 /
C
C XVPL,XVPT,YVPB,YVPT -- the viewport values
C
C WXMN,WXMX,WYMN,WYMX -- the window minimum and maximum values
C
C XLOV,XHIV,YLOV,YHIV -- the mapped array endpoint values
C
C SXDC,SYDC -- scale values for the calculated vector endpoint
C
C NXCT,NYCT -- number of points in X and Y used for the plot
C
C RLEN -- maximum vector length in window coordinates
C
C LNLG -- the log scale mapping flag from SET call
C
C INVX,INVY -- inverse flags for the window boundaries
C
C *********************************************************************
C
C REVISION HISTORY ----------------------------------------------------
C
C FEBRUARY, 1979 ADDED REVISION HISTORY
C MODIFIED CODE TO CONFORM TO FORTRAN 66 STANDARD
C
C JULY, 1979 FIXED HI VECTOR TRAP AND MESSAGE INDICATING
C MAXIMUM VECTOR PLOTTED.
C
C DECEMBER, 1979 CHANGED THE STATISTICS CALL FROM CRAYLIB TO NSSL
C
C MARCH, 1981 FIXED SOME FRINGE-CASE ERRORS, CHANGED THE CODE TO
C USE FL2INTT AND PLOTIT INSTEAD OF MXMY, FRSTPT, AND
C VECTOR, AND MADE THE ARROWHEADS NARROWER (45 DEGREES
C APART, RATHER THAN 60 DEGREES APART)
C
C FEBRUARY, 1984 PROVIDED A DIMENSION STATEMENT FOR A VARIABLE INTO
C WHICH A TEN-CHARACTER STRING WAS BEING ENCODED. ON
C THE CRAY, WHEN THE ENCODE WAS DONE, A WORD FOLLOWING
C THE VARIABLE WAS CLOBBERED, BUT THIS APPARENTLY MADE
C NO DIFFERENCE. ON AT LEAST ONE OTHER MACHINE, THE
C CODE BLEW UP. (ERROR REPORTED BY GREG WOODS)
C
C JULY, 1984 CONVERTED TO FORTRAN77 AND GKS.
C
C MARCH, 1990 CORRECTED THE USE OF SET CALLS.
C
C ---------------------------------------------------------------------
END
| gpl-2.0 |
LeChuck42/or1k-gcc | libgfortran/generated/_sqrt_c10.F90 | 35 | 1489 | ! Copyright (C) 2002-2014 Free Software Foundation, Inc.
! Contributed by Paul Brook <paul@nowt.org>
!
!This file is part of the GNU Fortran 95 runtime library (libgfortran).
!
!GNU libgfortran 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 3 of the License, or (at your option) any later version.
!GNU libgfortran 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.
!
!Under Section 7 of GPL version 3, you are granted additional
!permissions described in the GCC Runtime Library Exception, version
!3.1, as published by the Free Software Foundation.
!
!You should have received a copy of the GNU General Public License and
!a copy of the GCC Runtime Library Exception along with this program;
!see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
!<http://www.gnu.org/licenses/>.
!
!This file is machine generated.
#include "config.h"
#include "kinds.inc"
#include "c99_protos.inc"
#if defined (HAVE_GFC_COMPLEX_10)
#ifdef HAVE_CSQRTL
elemental function _gfortran_specific__sqrt_c10 (parm)
complex (kind=10), intent (in) :: parm
complex (kind=10) :: _gfortran_specific__sqrt_c10
_gfortran_specific__sqrt_c10 = sqrt (parm)
end function
#endif
#endif
| gpl-2.0 |
FRidh/scipy | scipy/linalg/src/id_dist/src/idzr_aid.f | 128 | 4815 | c this file contains the following user-callable routines:
c
c
c routine idzr_aid computes the ID, to a specified rank,
c of an arbitrary matrix. This routine is randomized.
c
c routine idzr_aidi initializes routine idzr_aid.
c
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c
c
c
subroutine idzr_aid(m,n,a,krank,w,list,proj)
c
c computes the ID of the matrix a, i.e., lists in list
c the indices of krank columns of a such that
c
c a(j,list(k)) = a(j,list(k))
c
c for all j = 1, ..., m; k = 1, ..., krank, and
c
c min(m,n,krank)
c a(j,list(k)) = Sigma a(j,list(l)) * proj(l,k-krank)(*)
c l=1
c
c + epsilon(j,k-krank)
c
c for all j = 1, ..., m; k = krank+1, ..., n,
c
c for some matrix epsilon, dimensioned epsilon(m,n-krank),
c whose norm is (hopefully) minimized by the pivoting procedure.
c
c input:
c m -- number of rows in a
c n -- number of columns in a
c a -- matrix to be ID'd; the present routine does not alter a
c krank -- rank of the ID to be constructed
c w -- initialization array that routine idzr_aidi
c has constructed
c
c output:
c list -- indices of the columns in the ID
c proj -- matrix of coefficients needed to interpolate
c from the selected columns to the other columns
c in the original matrix being ID'd
c
c _N.B._: The algorithm used by this routine is randomized.
c
c reference:
c Halko, Martinsson, Tropp, "Finding structure with randomness:
c probabilistic algorithms for constructing approximate
c matrix decompositions," SIAM Review, 53 (2): 217-288,
c 2011.
c
implicit none
integer m,n,krank,list(n),lw,ir,lr,lw2,iw
complex*16 a(m,n),proj(krank*(n-krank)),
1 w((2*krank+17)*n+21*m+80)
c
c
c Allocate memory in w.
c
lw = 0
c
iw = lw+1
lw2 = 21*m+80+n
lw = lw+lw2
c
ir = lw+1
lr = (krank+8)*2*n
lw = lw+lr
c
c
call idzr_aid0(m,n,a,krank,w(iw),list,proj,w(ir))
c
c
return
end
c
c
c
c
subroutine idzr_aid0(m,n,a,krank,w,list,proj,r)
c
c routine idzr_aid serves as a memory wrapper
c for the present routine
c (see idzr_aid for further documentation).
c
implicit none
integer k,l,m,n2,n,krank,list(n),mn,lproj
complex*16 a(m,n),r(krank+8,2*n),proj(krank,n-krank),
1 w(21*m+80+n)
c
c Please note that the second dimension of r is 2*n
c (instead of n) so that if krank+8 >= m/2, then
c we can copy the whole of a into r.
c
c
c Retrieve the number of random test vectors
c and the greatest integer less than m that is
c a positive integer power of two.
c
l = w(1)
n2 = w(2)
c
c
if(l .lt. n2 .and. l .le. m) then
c
c Apply the random matrix.
c
do k = 1,n
call idz_sfrm(l,m,n2,w(11),a(1,k),r(1,k))
enddo ! k
c
c ID r.
c
call idzr_id(l,n,r,krank,list,w(20*m+81))
c
c Retrieve proj from r.
c
lproj = krank*(n-krank)
call idzr_copyzarr(lproj,r,proj)
c
endif
c
c
if(l .ge. n2 .or. l .gt. m) then
c
c ID a directly.
c
mn = m*n
call idzr_copyzarr(mn,a,r)
call idzr_id(m,n,r,krank,list,w(20*m+81))
c
c Retrieve proj from r.
c
lproj = krank*(n-krank)
call idzr_copyzarr(lproj,r,proj)
c
endif
c
c
return
end
c
c
c
c
subroutine idzr_copyzarr(n,a,b)
c
c copies a into b.
c
c input:
c n -- length of a and b
c a -- array to copy into b
c
c output:
c b -- copy of a
c
implicit none
integer n,k
complex*16 a(n),b(n)
c
c
do k = 1,n
b(k) = a(k)
enddo ! k
c
c
return
end
c
c
c
c
subroutine idzr_aidi(m,n,krank,w)
c
c initializes the array w for using routine idzr_aid.
c
c input:
c m -- number of rows in the matrix to be ID'd
c n -- number of columns in the matrix to be ID'd
c krank -- rank of the ID to be constructed
c
c output:
c w -- initialization array for using routine idzr_aid
c
implicit none
integer m,n,krank,l,n2
complex*16 w((2*krank+17)*n+21*m+80)
c
c
c Set the number of random test vectors to 8 more than the rank.
c
l = krank+8
w(1) = l
c
c
c Initialize the rest of the array w.
c
n2 = 0
if(l .le. m) call idz_sfrmi(l,m,n2,w(11))
w(2) = n2
c
c
return
end
| bsd-3-clause |
likev/ncl | ncl_ncarg_src/external/lapack/dgesc2.f | 43 | 3700 | SUBROUTINE DGESC2( N, A, LDA, RHS, IPIV, JPIV, SCALE )
*
* -- 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 LDA, N
DOUBLE PRECISION SCALE
* ..
* .. Array Arguments ..
INTEGER IPIV( * ), JPIV( * )
DOUBLE PRECISION A( LDA, * ), RHS( * )
* ..
*
* Purpose
* =======
*
* DGESC2 solves a system of linear equations
*
* A * X = scale* RHS
*
* with a general N-by-N matrix A using the LU factorization with
* complete pivoting computed by DGETC2.
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix A.
*
* A (input) DOUBLE PRECISION array, dimension (LDA,N)
* On entry, the LU part of the factorization of the n-by-n
* matrix A computed by DGETC2: A = P * L * U * Q
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1, N).
*
* RHS (input/output) DOUBLE PRECISION array, dimension (N).
* On entry, the right hand side vector b.
* On exit, the solution vector X.
*
* IPIV (iput) INTEGER array, dimension (N).
* The pivot indices; for 1 <= i <= N, row i of the
* matrix has been interchanged with row IPIV(i).
*
* JPIV (iput) INTEGER array, dimension (N).
* The pivot indices; for 1 <= j <= N, column j of the
* matrix has been interchanged with column JPIV(j).
*
* SCALE (output) DOUBLE PRECISION
* On exit, SCALE contains the scale factor. SCALE is chosen
* 0 <= SCALE <= 1 to prevent owerflow in the solution.
*
* Further Details
* ===============
*
* Based on contributions by
* Bo Kagstrom and Peter Poromaa, Department of Computing Science,
* Umea University, S-901 87 Umea, Sweden.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, TWO
PARAMETER ( ONE = 1.0D+0, TWO = 2.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, J
DOUBLE PRECISION BIGNUM, EPS, SMLNUM, TEMP
* ..
* .. External Subroutines ..
EXTERNAL DLASWP, DSCAL
* ..
* .. External Functions ..
INTEGER IDAMAX
DOUBLE PRECISION DLAMCH
EXTERNAL IDAMAX, DLAMCH
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS
* ..
* .. Executable Statements ..
*
* Set constant to control owerflow
*
EPS = DLAMCH( 'P' )
SMLNUM = DLAMCH( 'S' ) / EPS
BIGNUM = ONE / SMLNUM
CALL DLABAD( SMLNUM, BIGNUM )
*
* Apply permutations IPIV to RHS
*
CALL DLASWP( 1, RHS, LDA, 1, N-1, IPIV, 1 )
*
* Solve for L part
*
DO 20 I = 1, N - 1
DO 10 J = I + 1, N
RHS( J ) = RHS( J ) - A( J, I )*RHS( I )
10 CONTINUE
20 CONTINUE
*
* Solve for U part
*
SCALE = ONE
*
* Check for scaling
*
I = IDAMAX( N, RHS, 1 )
IF( TWO*SMLNUM*ABS( RHS( I ) ).GT.ABS( A( N, N ) ) ) THEN
TEMP = ( ONE / TWO ) / ABS( RHS( I ) )
CALL DSCAL( N, TEMP, RHS( 1 ), 1 )
SCALE = SCALE*TEMP
END IF
*
DO 40 I = N, 1, -1
TEMP = ONE / A( I, I )
RHS( I ) = RHS( I )*TEMP
DO 30 J = I + 1, N
RHS( I ) = RHS( I ) - RHS( J )*( A( I, J )*TEMP )
30 CONTINUE
40 CONTINUE
*
* Apply permutations JPIV to the solution (RHS)
*
CALL DLASWP( 1, RHS, LDA, 1, N-1, JPIV, -1 )
RETURN
*
* End of DGESC2
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/examples/econpa/cpex01.f | 1 | 14391 |
PROGRAM CPEX01
C
C Define the error file, the Fortran unit number, the workstation type,
C and the workstation ID to be used in calls to GKS routines.
C
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript
C
PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1)
C
C Declare an array to hold the data to be contoured.
C
DIMENSION ZDAT(23,14)
C
C Declare an array to hold dense data (5152=4x4x23x14).
C
DIMENSION ZDNS(5152)
C
C Declare the required real and integer workspaces.
C
DIMENSION RWRK(5000),IWRK(1000)
C
C Declare an array to hold an area map.
C
DIMENSION IAMA(25000)
C
C Declare the arrays needed by ARSCAM for x/y coordinates.
C
DIMENSION XCRA(1000),YCRA(1000)
C
C Declare the arrays needed by ARSCAM for area and group identifiers.
C
DIMENSION IARA(10),IGRA(10)
C
C Declare an array to hold the GKS "aspect source flags".
C
DIMENSION IASF(13)
C
C Declare the routine which will draw contour lines, avoiding labels.
C
EXTERNAL DRAWCL
C
C Declare the routine which does the shading.
C
EXTERNAL SHADER
C
C Initialize the values in the aspect-source-flag array.
C
DATA IASF / 13*1 /
C
C Open GKS.
C
CALL GOPKS (IERRF, ISZDM)
CALL GOPWK (IWKID, LUNIT, IWTYPE)
CALL GACWK (IWKID)
C
C Turn off the clipping indicator.
C
CALL GSCLIP (0)
C
C Set all the GKS aspect source flags to "individual".
C
CALL GSASF (IASF)
C
C Generate an array of test data.
C
CALL GENDAT (ZDAT,23,23,14,20,20,-136.148,451.834)
C
C Example 1-1 ---------------------------------------------------------
C
C Force PLOTCHAR to use characters of the lowest quality.
C
CALL PCSETI ('QU - QUALITY FLAG',2)
C
C Initialize the drawing of the contour plot.
C
CALL CPRECT (ZDAT,23,23,14,RWRK,5000,IWRK,1000)
C
C Draw the default background.
C
CALL CPBACK (ZDAT,RWRK,IWRK)
C
C Draw contour lines and labels.
C
CALL CPCLDR (ZDAT,RWRK,IWRK)
C
C Add the informational label and the high/low labels.
C
CALL CPLBDR (ZDAT,RWRK,IWRK)
C
C Compute and print statistics for the plot, label it, and put a
C boundary line around the edge of the plotter frame.
C
CALL CAPSAP ('EXAMPLE 1-1',IAMA,0)
CALL LABTOP ('EXAMPLE 1-1',.017)
CALL BNDARY
C
C Advance the frame.
C
CALL FRAME
C
C Example 1-2 ---------------------------------------------------------
C
C Make PLOTCHAR use medium-quality characters.
C
CALL PCSETI ('QU - QUALITY FLAG',1)
C
C Turn on the positioning of labels by the penalty scheme.
C
CALL CPSETI ('LLP - LINE LABEL POSITIONING',3)
C
C Turn on the drawing of the high and low label boxes.
C
CALL CPSETI ('HLB - HIGH/LOW LABEL BOX FLAG',1)
C
C Tell CONPACK to delete high/low labels which overlap the informational
C label, another high/low label, or the edge.
C
CALL CPSETI ('HLO - HIGH/LOW LABEL OVERLAP FLAG',7)
C
C Tell CONPACK not to choose contour levels, so that the ones chosen
C for example 1-1 will be used.
C
CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG',0)
C
C Increase the line width for labelled levels.
C
CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS',NCLV)
C
DO 101 ICLV=1,NCLV
CALL CPSETI ('PAI - PARAMETER ARRAY INDEX',ICLV)
CALL CPGETI ('CLU - CONTOUR LEVEL USE FLAG',ICLU)
IF (ICLU.EQ.3) THEN
CALL CPSETI ('CLL - CONTOUR-LINE LINE WIDTH',2)
END IF
101 CONTINUE
C
C Initialize the drawing of the contour plot.
C
CALL CPRECT (ZDAT,23,23,14,RWRK,5000,IWRK,1000)
C
C Draw the default background, using a wider line than normal.
C
CALL GSLWSC (2.)
CALL CPBACK (ZDAT,RWRK,IWRK)
CALL GSLWSC (1.)
C
C Initialize the area map.
C
CALL ARINAM (IAMA,25000)
C
C Put label boxes into the area map.
C
CALL CPLBAM (ZDAT,RWRK,IWRK,IAMA)
C
C Draw contour lines, avoiding drawing them through the label boxes.
C
CALL CPCLDM (ZDAT,RWRK,IWRK,IAMA,DRAWCL)
C
C Draw all the labels.
C
CALL CPLBDR (ZDAT,RWRK,IWRK)
C
C Compute and print statistics for the plot, label it, and put a
C boundary line around the edge of the plotter frame.
C
CALL CAPSAP ('EXAMPLE 1-2',IAMA,25000)
CALL LABTOP ('EXAMPLE 1-2',.017)
CALL BNDARY
C
C Advance the frame.
C
CALL FRAME
C
C Example 1-3 ---------------------------------------------------------
C
C Make PLOTCHAR use high-quality characters.
C
CALL PCSETI ('QU - QUALITY FLAG',0)
C
C Tell CONPACK to delete high/low labels which overlap the informational
C label or another high/low label, but to move those which overlap the
C edge inward a little.
C
CALL CPSETI ('HLO - HIGH/LOW LABEL OVERLAP FLAG',11)
C
C Turn off the area identifiers for all except the zero contour and set
C its identifiers in such a way that we can shade the areas "below" that
C contour.
C
DO 102 ICLV=1,NCLV
CALL CPSETI ('PAI - PARAMETER ARRAY INDEX',ICLV)
CALL CPGETR ('CLV - CONTOUR LEVEL VALUE',CLEV)
IF (CLEV.NE.0.) THEN
CALL CPSETI ('AIA - AREA IDENTIFIER ABOVE LINE',0)
CALL CPSETI ('AIB - AREA IDENTIFIER BELOW LINE',0)
ELSE
CALL CPSETI ('AIA - AREA IDENTIFIER ABOVE LINE',2)
CALL CPSETI ('AIB - AREA IDENTIFIER BELOW LINE',1)
END IF
102 CONTINUE
C
C Draw the contour plot, using the same calls as for example 1-2.
C
CALL CPRECT (ZDAT,23,23,14,RWRK,5000,IWRK,1000)
CALL GSLWSC (2.)
CALL CPBACK (ZDAT,RWRK,IWRK)
CALL GSLWSC (1.)
CALL ARINAM (IAMA,25000)
CALL CPLBAM (ZDAT,RWRK,IWRK,IAMA)
CALL CPCLDM (ZDAT,RWRK,IWRK,IAMA,DRAWCL)
CALL CPLBDR (ZDAT,RWRK,IWRK)
C
C Now, add the zero contour line to the area map.
C
CALL CPCLAM (ZDAT,RWRK,IWRK,IAMA)
C
C Scan the area map. The routine SHADER will be called to shade the
C areas below the zero contour line.
C
CALL ARSCAM (IAMA,XCRA,YCRA,1000,IARA,IGRA,10,SHADER)
C
C Compute and print statistics for the plot, label it, and put a
C boundary line around the edge of the plotter frame.
C
CALL CAPSAP ('EXAMPLE 1-3',IAMA,25000)
CALL LABTOP ('EXAMPLE 1-3',.017)
CALL BNDARY
C
C Advance the frame.
C
CALL FRAME
C
C Example 1-4 ---------------------------------------------------------
C
C Turn on the 2D smoother.
C
CALL CPSETR ('T2D - TENSION ON THE 2D SPLINES',1.)
C
C Draw the contour plot, using the same calls as for example 1-3.
C
CALL CPRECT (ZDAT,23,23,14,RWRK,5000,IWRK,1000)
CALL GSLWSC (2.)
CALL CPBACK (ZDAT,RWRK,IWRK)
CALL GSLWSC (1.)
CALL ARINAM (IAMA,25000)
CALL CPLBAM (ZDAT,RWRK,IWRK,IAMA)
CALL CPCLDM (ZDAT,RWRK,IWRK,IAMA,DRAWCL)
CALL CPLBDR (ZDAT,RWRK,IWRK)
CALL CPCLAM (ZDAT,RWRK,IWRK,IAMA)
CALL ARSCAM (IAMA,XCRA,YCRA,1000,IARA,IGRA,10,SHADER)
C
C Compute and print statistics for the plot, label it, and put a
C boundary line around the edge of the plotter frame.
C
CALL CAPSAP ('EXAMPLE 1-4',IAMA,25000)
CALL LABTOP ('EXAMPLE 1-4',.017)
CALL BNDARY
C
C Advance the frame.
C
CALL FRAME
C
C Example 1-5 ---------------------------------------------------------
C
C Make CONPACK set up the contour levels again (the range of the data
C may be increased by 3D interpolation), but force it to use the same
C contour interval and label interval that were used for the first four
C plots.
C
CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG',16)
CALL CPGETR ('CIU - CONTOUR INTERVAL USED',CINU)
CALL CPSETR ('CIS - CONTOUR INTERVAL SPECIFIER',CINU)
CALL CPGETI ('LIU - LABEL INTERVAL USED',LINU)
CALL CPSETI ('LIS - LABEL INTERVAL SPECIFIER',LINU)
C
C Provide more room for storing coordinates used to trace contour
C lines. The default is slightly too small to hold a complete line,
C and this causes some lines to have a couple of labels right next to
C one another.
C
CALL CPSETI ('RWC - REAL WORKSPACE FOR CONTOUR TRACING',200)
C
C Turn off the 2D smoother.
C
CALL CPSETR ('T2D - TENSION ON THE 2D SPLINES',0.)
C
C Initialize the drawing of the contour plot.
C
CALL CPSPRS (ZDAT,23,23,14,RWRK,5000,IWRK,1000,ZDNS,5152)
C
C Force the selection of contour levels and tweak associated parameters.
C
CALL CPPKCL (ZDNS,RWRK,IWRK)
C
CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS',NCLV)
C
DO 103 ICLV=1,NCLV
CALL CPSETI ('PAI - PARAMETER ARRAY INDEX',ICLV)
CALL CPGETI ('CLU - CONTOUR LEVEL USE FLAG',ICLU)
IF (ICLU.EQ.3) THEN
CALL CPSETI ('CLL - CONTOUR LINE LINE WIDTH',2)
END IF
CALL CPGETR ('CLV - CONTOUR LEVEL VALUE',CLEV)
IF (CLEV.NE.0.) THEN
CALL CPSETI ('AIA - AREA IDENTIFIER ABOVE LINE',0)
CALL CPSETI ('AIB - AREA IDENTIFIER BELOW LINE',0)
ELSE
CALL CPSETI ('AIA - AREA IDENTIFIER ABOVE LINE',2)
CALL CPSETI ('AIB - AREA IDENTIFIER BELOW LINE',1)
END IF
103 CONTINUE
C
C The rest is pretty much the same as for example 1-4, but the array
C ZDNS is used in place of ZDAT.
C
CALL GSLWSC (2.)
CALL PERIM (0,0,0,0)
CALL GSLWSC (1.)
CALL ARINAM (IAMA,25000)
CALL CPLBAM (ZDNS,RWRK,IWRK,IAMA)
CALL CPCLDM (ZDNS,RWRK,IWRK,IAMA,DRAWCL)
CALL CPLBDR (ZDNS,RWRK,IWRK)
CALL CPCLAM (ZDNS,RWRK,IWRK,IAMA)
CALL ARSCAM (IAMA,XCRA,YCRA,1000,IARA,IGRA,10,SHADER)
C
C Compute and print statistics for the plot, label it, and put a
C boundary line around the edge of the plotter frame.
C
CALL CAPSAP ('EXAMPLE 1-5',IAMA,25000)
CALL LABTOP ('EXAMPLE 1-5',.017)
CALL BNDARY
C
C Advance the frame.
C
CALL FRAME
C
C Example 1-6 ---------------------------------------------------------
C
C Turn off the selection of contour levels, so that the set picked for
C example 1-5 will be used.
C
CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG',0)
C
C Draw an EZMAP background. The perimeter and the grid are turned off.
C The "political + U.S. states" dataset is used and it is dotted. We
C use a satellite-view projection, centered over the U.S., showing
C maximal area.
C
CALL MAPSTI ('PE - PERIMETER',0)
CALL MAPSTI ('GR - GRID',0)
CALL MAPSTC ('OU - OUTLINE DATASET','PS')
CALL MAPSTI ('DO - DOTTING OF OUTLINES',1)
CALL MAPSTR ('SA - SATELLITE HEIGHT',1.13)
CALL MAPROJ ('SV - SATELLITE-VIEW',40.,-95.,0.)
CALL MAPSET ('MA - MAXIMAL AREA',0.,0.,0.,0.)
CALL MAPDRW
C
C Tell CONPACK that the SET call has been done, force it to generate X
C coordinates that are longitudes and Y coordinates that are latitudes,
C turn on mapping to an EZMAP background, define the out-of-range value
C (returned by MAPTRN for an unprojectable point), and put the
C informational label in a different place.
C
CALL CPSETI ('SET - DO SET-CALL FLAG',0)
CALL CPSETR ('XC1 - X COORDINATE AT I = 1',-130.)
CALL CPSETR ('XCM - X COORDINATE AT I = M',-60.)
CALL CPSETR ('YC1 - Y COORDINATE AT J = 1',10.)
CALL CPSETR ('YCN - Y COORDINATE AT J = N',70.)
CALL CPSETI ('MAP - MAPPING FLAG',1)
CALL CPSETR ('ORV - OUT-OF-RANGE VALUE',1.E12)
CALL CPSETI ('ILP - INFORMATIONAL LABEL POSITIONING',3)
CALL CPSETR ('ILX - INFORMATIONAL LABEL X POSITION',.5)
CALL CPSETR ('ILY - INFORMATIONAL LABEL Y POSITION',-.02)
C
C The rest of the calls are just as in example 1-5, except that the
C perimeter is not drawn.
C
CALL CPSPRS (ZDAT,23,23,14,RWRK,5000,IWRK,1000,ZDNS,5152)
CALL ARINAM (IAMA,25000)
CALL CPLBAM (ZDNS,RWRK,IWRK,IAMA)
CALL CPCLDM (ZDNS,RWRK,IWRK,IAMA,DRAWCL)
CALL CPLBDR (ZDNS,RWRK,IWRK)
CALL CPCLAM (ZDNS,RWRK,IWRK,IAMA)
CALL ARSCAM (IAMA,XCRA,YCRA,1000,IARA,IGRA,10,SHADER)
C
C Compute and print statistics for the plot, label it, and put a
C boundary line around the edge of the plotter frame.
C
CALL CAPSAP ('EXAMPLE 1-6',IAMA,25000)
CALL LABTOP ('EXAMPLE 1-6',.017)
CALL BNDARY
C
C Advance the frame.
C
CALL FRAME
C
C ---------------------------------------------------------------------
C
C Close GKS.
C
CALL GDAWK (IWKID)
CALL GCLWK (IWKID)
CALL GCLKS
C
C Done.
C
STOP
C
END
SUBROUTINE DRAWCL (XCS,YCS,NCS,IAI,IAG,NAI)
C
C This version of DRAWCL draws the polyline defined by the points
C ((XCS(I),YCS(I)),I=1,NCS) if and only if none of the area identifiers
C for the area containing the polyline are negative. The dash package
C routine CURVED is called to do the drawing.
C
DIMENSION XCS(*),YCS(*),IAI(*),IAG(*)
C
C Turn on drawing.
C
IDR=1
C
C If any area identifier is negative, turn off drawing.
C
DO 101 I=1,NAI
IF (IAI(I).LT.0) IDR=0
101 CONTINUE
C
C If drawing is turned on, draw the polyline.
C
IF (IDR.NE.0) CALL CURVED (XCS,YCS,NCS)
C
C Done.
C
RETURN
C
END
SUBROUTINE SHADER (XCS,YCS,NCS,IAI,IAG,NAI)
C
C This version of SHADER shades the polygon whose edge is defined by
C the points ((XCS(I),YCS(I)),I=1,NCS) if and only, relative to edge
C group 3, its area identifier is a 1. The package SOFTFILL is used
C to do the shading.
C
DIMENSION XCS(*),YCS(*),IAI(*),IAG(*)
C
C Define workspaces for the shading routine.
C
DIMENSION DST(1100),IND(1200)
C
C Turn off shading.
C
ISH=0
C
C If the area identifier for group 3 is a 1, turn on shading.
C
DO 101 I=1,NAI
IF (IAG(I).EQ.3.AND.IAI(I).EQ.1) ISH=1
101 CONTINUE
C
C If shading is turned on, shade the area. The last point of the
C edge is redundant and may be omitted.
C
IF (ISH.NE.0) THEN
CALL SFSETI ('ANGLE',45)
CALL SFSETR ('SPACING',.006)
CALL SFWRLD (XCS,YCS,NCS-1,DST,1100,IND,1200)
CALL SFSETI ('ANGLE',135)
CALL SFNORM (XCS,YCS,NCS-1,DST,1100,IND,1200)
END IF
C
C Done.
C
RETURN
C
END
| gpl-2.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/integer_exponentiation_5.F90 | 136 | 1741 | ! { dg-do run { xfail spu-*-* } }
! FAILs on SPU because of invalid result of 1.0/0.0 inline code
! { dg-options "-fno-range-check" }
! { dg-add-options ieee }
module mod_check
implicit none
interface check
module procedure check_i8
module procedure check_i4
module procedure check_r8
module procedure check_r4
module procedure check_c8
module procedure check_c4
end interface check
contains
subroutine check_i8 (a, b)
integer(kind=8), intent(in) :: a, b
if (a /= b) call abort()
end subroutine check_i8
subroutine check_i4 (a, b)
integer(kind=4), intent(in) :: a, b
if (a /= b) call abort()
end subroutine check_i4
subroutine check_r8 (a, b)
real(kind=8), intent(in) :: a, b
if (a /= b) call abort()
end subroutine check_r8
subroutine check_r4 (a, b)
real(kind=4), intent(in) :: a, b
if (a /= b) call abort()
end subroutine check_r4
subroutine check_c8 (a, b)
complex(kind=8), intent(in) :: a, b
if (a /= b) call abort()
end subroutine check_c8
subroutine check_c4 (a, b)
complex(kind=4), intent(in) :: a, b
if (a /= b) call abort()
end subroutine check_c4
end module mod_check
program test
use mod_check
implicit none
integer(kind=4) :: i4
integer(kind=8) :: i8
real(kind=4) :: r4
real(kind=8) :: r8
complex(kind=4) :: c4
complex(kind=8) :: c8
#define TEST(base,exp,var) var = base; call check((var)**(exp),(base)**(exp))
!!!!! INTEGER BASE !!!!!
TEST(3,23,i4)
TEST(-3,23,i4)
TEST(3_8,43_8,i8)
TEST(-3_8,43_8,i8)
TEST(17_8,int(huge(0_4),kind=8)+1,i8)
!!!!! REAL BASE !!!!!
TEST(0.0,-1,r4)
TEST(0.0,-huge(0)-1,r4)
TEST(2.0,huge(0),r4)
TEST(nearest(1.0,-1.0),-huge(0),r4)
end program test
| gpl-2.0 |
acquaman/acquaman | source/Eigen/blas/ztbmv.f | 184 | 12662 | SUBROUTINE ZTBMV(UPLO,TRANS,DIAG,N,K,A,LDA,X,INCX)
* .. Scalar Arguments ..
INTEGER INCX,K,LDA,N
CHARACTER DIAG,TRANS,UPLO
* ..
* .. Array Arguments ..
DOUBLE COMPLEX A(LDA,*),X(*)
* ..
*
* Purpose
* =======
*
* ZTBMV performs one of the matrix-vector operations
*
* x := A*x, or x := A'*x, or x := conjg( A' )*x,
*
* where x is an n element vector and A is an n by n unit, or non-unit,
* upper or lower triangular band matrix, with ( k + 1 ) diagonals.
*
* Arguments
* ==========
*
* UPLO - CHARACTER*1.
* On entry, UPLO specifies whether the matrix is an upper or
* lower triangular matrix as follows:
*
* UPLO = 'U' or 'u' A is an upper triangular matrix.
*
* UPLO = 'L' or 'l' A is a lower triangular matrix.
*
* Unchanged on exit.
*
* TRANS - CHARACTER*1.
* On entry, TRANS specifies the operation to be performed as
* follows:
*
* TRANS = 'N' or 'n' x := A*x.
*
* TRANS = 'T' or 't' x := A'*x.
*
* TRANS = 'C' or 'c' x := conjg( A' )*x.
*
* Unchanged on exit.
*
* DIAG - CHARACTER*1.
* On entry, DIAG specifies whether or not A is unit
* triangular as follows:
*
* DIAG = 'U' or 'u' A is assumed to be unit triangular.
*
* DIAG = 'N' or 'n' A is not assumed to be unit
* triangular.
*
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the order of the matrix A.
* N must be at least zero.
* Unchanged on exit.
*
* K - INTEGER.
* On entry with UPLO = 'U' or 'u', K specifies the number of
* super-diagonals of the matrix A.
* On entry with UPLO = 'L' or 'l', K specifies the number of
* sub-diagonals of the matrix A.
* K must satisfy 0 .le. K.
* Unchanged on exit.
*
* A - COMPLEX*16 array of DIMENSION ( LDA, n ).
* Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )
* by n part of the array A must contain the upper triangular
* band part of the matrix of coefficients, supplied column by
* column, with the leading diagonal of the matrix in row
* ( k + 1 ) of the array, the first super-diagonal starting at
* position 2 in row k, and so on. The top left k by k triangle
* of the array A is not referenced.
* The following program segment will transfer an upper
* triangular band matrix from conventional full matrix storage
* to band storage:
*
* DO 20, J = 1, N
* M = K + 1 - J
* DO 10, I = MAX( 1, J - K ), J
* A( M + I, J ) = matrix( I, J )
* 10 CONTINUE
* 20 CONTINUE
*
* Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )
* by n part of the array A must contain the lower triangular
* band part of the matrix of coefficients, supplied column by
* column, with the leading diagonal of the matrix in row 1 of
* the array, the first sub-diagonal starting at position 1 in
* row 2, and so on. The bottom right k by k triangle of the
* array A is not referenced.
* The following program segment will transfer a lower
* triangular band matrix from conventional full matrix storage
* to band storage:
*
* DO 20, J = 1, N
* M = 1 - J
* DO 10, I = J, MIN( N, J + K )
* A( M + I, J ) = matrix( I, J )
* 10 CONTINUE
* 20 CONTINUE
*
* Note that when DIAG = 'U' or 'u' the elements of the array A
* corresponding to the diagonal elements of the matrix are not
* referenced, but are assumed to be unity.
* Unchanged on exit.
*
* LDA - INTEGER.
* On entry, LDA specifies the first dimension of A as declared
* in the calling (sub) program. LDA must be at least
* ( k + 1 ).
* Unchanged on exit.
*
* X - COMPLEX*16 array of dimension at least
* ( 1 + ( n - 1 )*abs( INCX ) ).
* Before entry, the incremented array X must contain the n
* element vector x. On exit, X is overwritten with the
* tranformed vector x.
*
* INCX - INTEGER.
* On entry, INCX specifies the increment for the elements of
* X. INCX must not be zero.
* Unchanged on exit.
*
* Further Details
* ===============
*
* Level 2 Blas routine.
*
* -- Written on 22-October-1986.
* Jack Dongarra, Argonne National Lab.
* Jeremy Du Croz, Nag Central Office.
* Sven Hammarling, Nag Central Office.
* Richard Hanson, Sandia National Labs.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE COMPLEX ZERO
PARAMETER (ZERO= (0.0D+0,0.0D+0))
* ..
* .. Local Scalars ..
DOUBLE COMPLEX TEMP
INTEGER I,INFO,IX,J,JX,KPLUS1,KX,L
LOGICAL NOCONJ,NOUNIT
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC DCONJG,MAX,MIN
* ..
*
* Test the input parameters.
*
INFO = 0
IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
INFO = 1
ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
+ .NOT.LSAME(TRANS,'C')) THEN
INFO = 2
ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
INFO = 3
ELSE IF (N.LT.0) THEN
INFO = 4
ELSE IF (K.LT.0) THEN
INFO = 5
ELSE IF (LDA.LT. (K+1)) THEN
INFO = 7
ELSE IF (INCX.EQ.0) THEN
INFO = 9
END IF
IF (INFO.NE.0) THEN
CALL XERBLA('ZTBMV ',INFO)
RETURN
END IF
*
* Quick return if possible.
*
IF (N.EQ.0) RETURN
*
NOCONJ = LSAME(TRANS,'T')
NOUNIT = LSAME(DIAG,'N')
*
* Set up the start point in X if the increment is not unity. This
* will be ( N - 1 )*INCX too small for descending loops.
*
IF (INCX.LE.0) THEN
KX = 1 - (N-1)*INCX
ELSE IF (INCX.NE.1) THEN
KX = 1
END IF
*
* Start the operations. In this version the elements of A are
* accessed sequentially with one pass through A.
*
IF (LSAME(TRANS,'N')) THEN
*
* Form x := A*x.
*
IF (LSAME(UPLO,'U')) THEN
KPLUS1 = K + 1
IF (INCX.EQ.1) THEN
DO 20 J = 1,N
IF (X(J).NE.ZERO) THEN
TEMP = X(J)
L = KPLUS1 - J
DO 10 I = MAX(1,J-K),J - 1
X(I) = X(I) + TEMP*A(L+I,J)
10 CONTINUE
IF (NOUNIT) X(J) = X(J)*A(KPLUS1,J)
END IF
20 CONTINUE
ELSE
JX = KX
DO 40 J = 1,N
IF (X(JX).NE.ZERO) THEN
TEMP = X(JX)
IX = KX
L = KPLUS1 - J
DO 30 I = MAX(1,J-K),J - 1
X(IX) = X(IX) + TEMP*A(L+I,J)
IX = IX + INCX
30 CONTINUE
IF (NOUNIT) X(JX) = X(JX)*A(KPLUS1,J)
END IF
JX = JX + INCX
IF (J.GT.K) KX = KX + INCX
40 CONTINUE
END IF
ELSE
IF (INCX.EQ.1) THEN
DO 60 J = N,1,-1
IF (X(J).NE.ZERO) THEN
TEMP = X(J)
L = 1 - J
DO 50 I = MIN(N,J+K),J + 1,-1
X(I) = X(I) + TEMP*A(L+I,J)
50 CONTINUE
IF (NOUNIT) X(J) = X(J)*A(1,J)
END IF
60 CONTINUE
ELSE
KX = KX + (N-1)*INCX
JX = KX
DO 80 J = N,1,-1
IF (X(JX).NE.ZERO) THEN
TEMP = X(JX)
IX = KX
L = 1 - J
DO 70 I = MIN(N,J+K),J + 1,-1
X(IX) = X(IX) + TEMP*A(L+I,J)
IX = IX - INCX
70 CONTINUE
IF (NOUNIT) X(JX) = X(JX)*A(1,J)
END IF
JX = JX - INCX
IF ((N-J).GE.K) KX = KX - INCX
80 CONTINUE
END IF
END IF
ELSE
*
* Form x := A'*x or x := conjg( A' )*x.
*
IF (LSAME(UPLO,'U')) THEN
KPLUS1 = K + 1
IF (INCX.EQ.1) THEN
DO 110 J = N,1,-1
TEMP = X(J)
L = KPLUS1 - J
IF (NOCONJ) THEN
IF (NOUNIT) TEMP = TEMP*A(KPLUS1,J)
DO 90 I = J - 1,MAX(1,J-K),-1
TEMP = TEMP + A(L+I,J)*X(I)
90 CONTINUE
ELSE
IF (NOUNIT) TEMP = TEMP*DCONJG(A(KPLUS1,J))
DO 100 I = J - 1,MAX(1,J-K),-1
TEMP = TEMP + DCONJG(A(L+I,J))*X(I)
100 CONTINUE
END IF
X(J) = TEMP
110 CONTINUE
ELSE
KX = KX + (N-1)*INCX
JX = KX
DO 140 J = N,1,-1
TEMP = X(JX)
KX = KX - INCX
IX = KX
L = KPLUS1 - J
IF (NOCONJ) THEN
IF (NOUNIT) TEMP = TEMP*A(KPLUS1,J)
DO 120 I = J - 1,MAX(1,J-K),-1
TEMP = TEMP + A(L+I,J)*X(IX)
IX = IX - INCX
120 CONTINUE
ELSE
IF (NOUNIT) TEMP = TEMP*DCONJG(A(KPLUS1,J))
DO 130 I = J - 1,MAX(1,J-K),-1
TEMP = TEMP + DCONJG(A(L+I,J))*X(IX)
IX = IX - INCX
130 CONTINUE
END IF
X(JX) = TEMP
JX = JX - INCX
140 CONTINUE
END IF
ELSE
IF (INCX.EQ.1) THEN
DO 170 J = 1,N
TEMP = X(J)
L = 1 - J
IF (NOCONJ) THEN
IF (NOUNIT) TEMP = TEMP*A(1,J)
DO 150 I = J + 1,MIN(N,J+K)
TEMP = TEMP + A(L+I,J)*X(I)
150 CONTINUE
ELSE
IF (NOUNIT) TEMP = TEMP*DCONJG(A(1,J))
DO 160 I = J + 1,MIN(N,J+K)
TEMP = TEMP + DCONJG(A(L+I,J))*X(I)
160 CONTINUE
END IF
X(J) = TEMP
170 CONTINUE
ELSE
JX = KX
DO 200 J = 1,N
TEMP = X(JX)
KX = KX + INCX
IX = KX
L = 1 - J
IF (NOCONJ) THEN
IF (NOUNIT) TEMP = TEMP*A(1,J)
DO 180 I = J + 1,MIN(N,J+K)
TEMP = TEMP + A(L+I,J)*X(IX)
IX = IX + INCX
180 CONTINUE
ELSE
IF (NOUNIT) TEMP = TEMP*DCONJG(A(1,J))
DO 190 I = J + 1,MIN(N,J+K)
TEMP = TEMP + DCONJG(A(L+I,J))*X(IX)
IX = IX + INCX
190 CONTINUE
END IF
X(JX) = TEMP
JX = JX + INCX
200 CONTINUE
END IF
END IF
END IF
*
RETURN
*
* End of ZTBMV .
*
END
| gpl-3.0 |
likev/ncl | ncl_ncarg_src/ngmath/src/lib/gridpack/cssgrid/cssgprnt.f | 1 | 5183 | C
C $Id: cssgprnt.f,v 1.5 2008-07-27 03:10:08 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE CSSGPRNT (N,LUNIT,LIST,LPTR,LEND,SIGMA)
INTEGER N, LUNIT, LIST(*), LPTR(*), LEND(N)
DOUBLE PRECISION SIGMA(*)
C
C***********************************************************
C
C From SSRFPACK
C Robert J. Renka
C Dept. of Computer Science
C Univ. of North Texas
C renka@cs.unt.edu
C 07/21/98
C
C Given a triangulation of a set of nodes on the unit
C sphere, along with an array of tension factors associated
C with the triangulation arcs, this subroutine prints the
C list of arcs (with tension factors) ordered by endpoint
C nodal indexes. An arc is identified with its smaller
C endpoint index: N1-N2, where N1 < N2.
C
C This routine is identical to the similarly named routine
C in SRFPACK.
C
C
C On input:
C
C N = Number of nodes in the triangulation. 3 .LE. N
C .LE. 9999.
C
C LUNIT = Logical unit for output. 0 .LE. LUNIT .LE.
C 99. Output is printed on unit 6 if LUNIT is
C outside its valid range.
C
C LIST,LPTR,LEND = Data structure defining the trian-
C gulation. Refer to STRIPACK
C Subroutine CSTRMESH.
C
C SIGMA = Array of length 2*NA = 6*(N-1)-2*NB, where
C NA and NB are the numbers of arcs and boun-
C dary nodes, respectively, containing tension
C factors associated with arcs in one-to-one
C correspondence with LIST entries. Note that
C each arc N1-N2 has two LIST entries and
C thus, SIGMA(I) and SIGMA(J) should be iden-
C tical, where LIST(I) = N2 (in the adjacency
C list for N1) and LIST(J) = N1 (in the list
C associated with N2). Both SIGMA(I) and
C SIGMA(J) are printed if they are not iden-
C tical.
C
C None of the parameters are altered by this routine.
C
C STRIPACK module required by CSSGPRNT: CSLSTPTR
C
C Intrinsic function called by CSSGPRNT: ABS
C
C***********************************************************
C
INTEGER CSLSTPTR
INTEGER LP1, LP2, LPL, LUN, N1, N2, NA, NAT, NB, NE,
. NL, NLMAX, NM1, NMAX
LOGICAL ERROR
DOUBLE PRECISION SIG
DATA NMAX/9999/, NLMAX/58/
C
LUN = LUNIT
IF (LUN .LT. 0 .OR. LUN .GT. 99) LUN = 6
C
C Print a heading, test for invalid N, and initialize coun-
C ters:
C
C NL = Number of lines printed on the current page
C NA = Number of arcs encountered
C NE = Number of errors in SIGMA encountered
C NB = Number of boundary nodes encountered
C
WRITE (LUN,100) N
IF (N .LT. 3 .OR. N .GT. NMAX) GO TO 4
NL = 6
NA = 0
NE = 0
NB = 0
C
C Outer loop on nodes N1. LPL points to the last neighbor
C of N1.
C
NM1 = N - 1
DO 3 N1 = 1,NM1
LPL = LEND(N1)
IF (LIST(LPL) .LT. 0) NB = NB + 1
LP1 = LPL
C
C Inner loop on neighbors N2 of N1 such that N1 < N2.
C
1 LP1 = LPTR(LP1)
N2 = ABS(LIST(LP1))
IF (N2 .LT. N1) GO TO 2
NA = NA + 1
SIG = SIGMA(LP1)
C
C Test for an invalid SIGMA entry.
C
LP2 = CSLSTPTR (LEND(N2),N1,LIST,LPTR)
ERROR = SIGMA(LP2) .NE. SIG
IF (ERROR) NE = NE + 1
C
C Print a line and update the counters.
C
IF (.NOT. ERROR) WRITE (LUN,110) N1, N2, SIG
IF (ERROR) WRITE (LUN,120) N1, N2, SIG, SIGMA(LP2)
NL = NL + 1
IF (NL .GE. NLMAX) THEN
WRITE (LUN,130)
NL = 1
ENDIF
C
C Bottom of loop on neighbors N2 of N1.
C
2 IF (LP1 .NE. LPL) GO TO 1
3 CONTINUE
LPL = LEND(N)
IF (LIST(LPL) .LT. 0) NB = NB + 1
C
C Test for errors in SIGMA.
C
IF (NE .GT. 0) WRITE (LUN,200) NE
C
C Print NA and test for an invalid triangulation.
C
WRITE (LUN,140) NA
IF (NB .NE. 0) THEN
NAT = 3*NM1 - NB
ELSE
NAT = 3*N - 6
ENDIF
IF (NAT .NE. NA) WRITE (LUN,210) NAT
RETURN
C
C N is outside its valid range.
C
4 WRITE (LUN,220) NMAX
RETURN
C
C Print formats:
C
100 FORMAT ('1',14X,'TENSION FACTORS, N =',I5,
. ' NODES'//1X,18X,'N1',5X,'N2',8X,'TENSION'//)
110 FORMAT (1X,16X,I4,3X,I4,5X,F12.8)
120 FORMAT (1X,16X,I4,3X,I4,5X,F12.8,3X,F12.8,' *')
130 FORMAT ('1')
140 FORMAT (//1X,10X,'NA =',I5,' ARCS')
C
C Error messages:
C
200 FORMAT (//1X,10X,'*',I5,' ERRORS IN SIGMA')
210 FORMAT (/1X,10X,'*** ERROR IN TRIANGULATION -- ',
. '3N-NB-3 = ',I5,' ***')
220 FORMAT (1X,10X,'*** N IS OUT OF RANGE -- NMAX = ',
. I4,' ***')
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/dlarfx.f | 16 | 17734 | SUBROUTINE DLARFX( SIDE, M, N, V, TAU, C, LDC, WORK )
*
* -- 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 SIDE
INTEGER LDC, M, N
DOUBLE PRECISION TAU
* ..
* .. Array Arguments ..
DOUBLE PRECISION C( LDC, * ), V( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DLARFX applies a real elementary reflector H to a real m by n
* matrix C, from either the left or the right. H is represented in the
* form
*
* H = I - tau * v * v'
*
* where tau is a real scalar and v is a real vector.
*
* If tau = 0, then H is taken to be the unit matrix
*
* This version uses inline code if H has order < 11.
*
* Arguments
* =========
*
* SIDE (input) CHARACTER*1
* = 'L': form H * C
* = 'R': form C * H
*
* M (input) INTEGER
* The number of rows of the matrix C.
*
* N (input) INTEGER
* The number of columns of the matrix C.
*
* V (input) DOUBLE PRECISION array, dimension (M) if SIDE = 'L'
* or (N) if SIDE = 'R'
* The vector v in the representation of H.
*
* TAU (input) DOUBLE PRECISION
* The value tau in the representation of H.
*
* C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
* On entry, the m by n matrix C.
* On exit, C is overwritten by the matrix H * C if SIDE = 'L',
* or C * H if SIDE = 'R'.
*
* LDC (input) INTEGER
* The leading dimension of the array C. LDA >= (1,M).
*
* WORK (workspace) DOUBLE PRECISION array, dimension
* (N) if SIDE = 'L'
* or (M) if SIDE = 'R'
* WORK is not referenced if H has order < 11.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
INTEGER J
DOUBLE PRECISION SUM, T1, T10, T2, T3, T4, T5, T6, T7, T8, T9,
$ V1, V10, V2, V3, V4, V5, V6, V7, V8, V9
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DGEMV, DGER
* ..
* .. Executable Statements ..
*
IF( TAU.EQ.ZERO )
$ RETURN
IF( LSAME( SIDE, 'L' ) ) THEN
*
* Form H * C, where H has order m.
*
GO TO ( 10, 30, 50, 70, 90, 110, 130, 150,
$ 170, 190 )M
*
* Code for general M
*
* w := C'*v
*
CALL DGEMV( 'Transpose', M, N, ONE, C, LDC, V, 1, ZERO, WORK,
$ 1 )
*
* C := C - tau * v * w'
*
CALL DGER( M, N, -TAU, V, 1, WORK, 1, C, LDC )
GO TO 410
10 CONTINUE
*
* Special code for 1 x 1 Householder
*
T1 = ONE - TAU*V( 1 )*V( 1 )
DO 20 J = 1, N
C( 1, J ) = T1*C( 1, J )
20 CONTINUE
GO TO 410
30 CONTINUE
*
* Special code for 2 x 2 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
DO 40 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
40 CONTINUE
GO TO 410
50 CONTINUE
*
* Special code for 3 x 3 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
DO 60 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
60 CONTINUE
GO TO 410
70 CONTINUE
*
* Special code for 4 x 4 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
DO 80 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
$ V4*C( 4, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
C( 4, J ) = C( 4, J ) - SUM*T4
80 CONTINUE
GO TO 410
90 CONTINUE
*
* Special code for 5 x 5 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
DO 100 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
$ V4*C( 4, J ) + V5*C( 5, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
C( 4, J ) = C( 4, J ) - SUM*T4
C( 5, J ) = C( 5, J ) - SUM*T5
100 CONTINUE
GO TO 410
110 CONTINUE
*
* Special code for 6 x 6 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
DO 120 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
$ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
C( 4, J ) = C( 4, J ) - SUM*T4
C( 5, J ) = C( 5, J ) - SUM*T5
C( 6, J ) = C( 6, J ) - SUM*T6
120 CONTINUE
GO TO 410
130 CONTINUE
*
* Special code for 7 x 7 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
DO 140 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
$ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
$ V7*C( 7, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
C( 4, J ) = C( 4, J ) - SUM*T4
C( 5, J ) = C( 5, J ) - SUM*T5
C( 6, J ) = C( 6, J ) - SUM*T6
C( 7, J ) = C( 7, J ) - SUM*T7
140 CONTINUE
GO TO 410
150 CONTINUE
*
* Special code for 8 x 8 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
V8 = V( 8 )
T8 = TAU*V8
DO 160 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
$ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
$ V7*C( 7, J ) + V8*C( 8, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
C( 4, J ) = C( 4, J ) - SUM*T4
C( 5, J ) = C( 5, J ) - SUM*T5
C( 6, J ) = C( 6, J ) - SUM*T6
C( 7, J ) = C( 7, J ) - SUM*T7
C( 8, J ) = C( 8, J ) - SUM*T8
160 CONTINUE
GO TO 410
170 CONTINUE
*
* Special code for 9 x 9 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
V8 = V( 8 )
T8 = TAU*V8
V9 = V( 9 )
T9 = TAU*V9
DO 180 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
$ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
$ V7*C( 7, J ) + V8*C( 8, J ) + V9*C( 9, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
C( 4, J ) = C( 4, J ) - SUM*T4
C( 5, J ) = C( 5, J ) - SUM*T5
C( 6, J ) = C( 6, J ) - SUM*T6
C( 7, J ) = C( 7, J ) - SUM*T7
C( 8, J ) = C( 8, J ) - SUM*T8
C( 9, J ) = C( 9, J ) - SUM*T9
180 CONTINUE
GO TO 410
190 CONTINUE
*
* Special code for 10 x 10 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
V8 = V( 8 )
T8 = TAU*V8
V9 = V( 9 )
T9 = TAU*V9
V10 = V( 10 )
T10 = TAU*V10
DO 200 J = 1, N
SUM = V1*C( 1, J ) + V2*C( 2, J ) + V3*C( 3, J ) +
$ V4*C( 4, J ) + V5*C( 5, J ) + V6*C( 6, J ) +
$ V7*C( 7, J ) + V8*C( 8, J ) + V9*C( 9, J ) +
$ V10*C( 10, J )
C( 1, J ) = C( 1, J ) - SUM*T1
C( 2, J ) = C( 2, J ) - SUM*T2
C( 3, J ) = C( 3, J ) - SUM*T3
C( 4, J ) = C( 4, J ) - SUM*T4
C( 5, J ) = C( 5, J ) - SUM*T5
C( 6, J ) = C( 6, J ) - SUM*T6
C( 7, J ) = C( 7, J ) - SUM*T7
C( 8, J ) = C( 8, J ) - SUM*T8
C( 9, J ) = C( 9, J ) - SUM*T9
C( 10, J ) = C( 10, J ) - SUM*T10
200 CONTINUE
GO TO 410
ELSE
*
* Form C * H, where H has order n.
*
GO TO ( 210, 230, 250, 270, 290, 310, 330, 350,
$ 370, 390 )N
*
* Code for general N
*
* w := C * v
*
CALL DGEMV( 'No transpose', M, N, ONE, C, LDC, V, 1, ZERO,
$ WORK, 1 )
*
* C := C - tau * w * v'
*
CALL DGER( M, N, -TAU, WORK, 1, V, 1, C, LDC )
GO TO 410
210 CONTINUE
*
* Special code for 1 x 1 Householder
*
T1 = ONE - TAU*V( 1 )*V( 1 )
DO 220 J = 1, M
C( J, 1 ) = T1*C( J, 1 )
220 CONTINUE
GO TO 410
230 CONTINUE
*
* Special code for 2 x 2 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
DO 240 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
240 CONTINUE
GO TO 410
250 CONTINUE
*
* Special code for 3 x 3 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
DO 260 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
260 CONTINUE
GO TO 410
270 CONTINUE
*
* Special code for 4 x 4 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
DO 280 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
$ V4*C( J, 4 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
C( J, 4 ) = C( J, 4 ) - SUM*T4
280 CONTINUE
GO TO 410
290 CONTINUE
*
* Special code for 5 x 5 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
DO 300 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
$ V4*C( J, 4 ) + V5*C( J, 5 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
C( J, 4 ) = C( J, 4 ) - SUM*T4
C( J, 5 ) = C( J, 5 ) - SUM*T5
300 CONTINUE
GO TO 410
310 CONTINUE
*
* Special code for 6 x 6 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
DO 320 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
$ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
C( J, 4 ) = C( J, 4 ) - SUM*T4
C( J, 5 ) = C( J, 5 ) - SUM*T5
C( J, 6 ) = C( J, 6 ) - SUM*T6
320 CONTINUE
GO TO 410
330 CONTINUE
*
* Special code for 7 x 7 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
DO 340 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
$ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
$ V7*C( J, 7 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
C( J, 4 ) = C( J, 4 ) - SUM*T4
C( J, 5 ) = C( J, 5 ) - SUM*T5
C( J, 6 ) = C( J, 6 ) - SUM*T6
C( J, 7 ) = C( J, 7 ) - SUM*T7
340 CONTINUE
GO TO 410
350 CONTINUE
*
* Special code for 8 x 8 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
V8 = V( 8 )
T8 = TAU*V8
DO 360 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
$ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
$ V7*C( J, 7 ) + V8*C( J, 8 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
C( J, 4 ) = C( J, 4 ) - SUM*T4
C( J, 5 ) = C( J, 5 ) - SUM*T5
C( J, 6 ) = C( J, 6 ) - SUM*T6
C( J, 7 ) = C( J, 7 ) - SUM*T7
C( J, 8 ) = C( J, 8 ) - SUM*T8
360 CONTINUE
GO TO 410
370 CONTINUE
*
* Special code for 9 x 9 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
V8 = V( 8 )
T8 = TAU*V8
V9 = V( 9 )
T9 = TAU*V9
DO 380 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
$ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
$ V7*C( J, 7 ) + V8*C( J, 8 ) + V9*C( J, 9 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
C( J, 4 ) = C( J, 4 ) - SUM*T4
C( J, 5 ) = C( J, 5 ) - SUM*T5
C( J, 6 ) = C( J, 6 ) - SUM*T6
C( J, 7 ) = C( J, 7 ) - SUM*T7
C( J, 8 ) = C( J, 8 ) - SUM*T8
C( J, 9 ) = C( J, 9 ) - SUM*T9
380 CONTINUE
GO TO 410
390 CONTINUE
*
* Special code for 10 x 10 Householder
*
V1 = V( 1 )
T1 = TAU*V1
V2 = V( 2 )
T2 = TAU*V2
V3 = V( 3 )
T3 = TAU*V3
V4 = V( 4 )
T4 = TAU*V4
V5 = V( 5 )
T5 = TAU*V5
V6 = V( 6 )
T6 = TAU*V6
V7 = V( 7 )
T7 = TAU*V7
V8 = V( 8 )
T8 = TAU*V8
V9 = V( 9 )
T9 = TAU*V9
V10 = V( 10 )
T10 = TAU*V10
DO 400 J = 1, M
SUM = V1*C( J, 1 ) + V2*C( J, 2 ) + V3*C( J, 3 ) +
$ V4*C( J, 4 ) + V5*C( J, 5 ) + V6*C( J, 6 ) +
$ V7*C( J, 7 ) + V8*C( J, 8 ) + V9*C( J, 9 ) +
$ V10*C( J, 10 )
C( J, 1 ) = C( J, 1 ) - SUM*T1
C( J, 2 ) = C( J, 2 ) - SUM*T2
C( J, 3 ) = C( J, 3 ) - SUM*T3
C( J, 4 ) = C( J, 4 ) - SUM*T4
C( J, 5 ) = C( J, 5 ) - SUM*T5
C( J, 6 ) = C( J, 6 ) - SUM*T6
C( J, 7 ) = C( J, 7 ) - SUM*T7
C( J, 8 ) = C( J, 8 ) - SUM*T8
C( J, 9 ) = C( J, 9 ) - SUM*T9
C( J, 10 ) = C( J, 10 ) - SUM*T10
400 CONTINUE
GO TO 410
END IF
410 CONTINUE
RETURN
*
* End of DLARFX
*
END
| gpl-2.0 |
marshallward/mom | src/land_lad2/canopy_air/canopy_air.F90 | 9 | 22473 | ! ============================================================================
! canopy air
! ============================================================================
module canopy_air_mod
#include "../shared/debug.inc"
#include "../shared/concat.inc"
#ifdef INTERNAL_FILE_NML
use mpp_mod, only: input_nml_file
#else
use fms_mod, only: open_namelist_file
#endif
use fms_mod, only : write_version_number, error_mesg, FATAL, NOTE, file_exist, &
close_file, check_nml_error, &
mpp_pe, mpp_root_pe, stdlog
use time_manager_mod, only : time_type, time_type_to_real
use constants_mod, only : rdgas, rvgas, cp_air, PI, VONKARM
use sphum_mod, only : qscomp
use nf_utils_mod, only : nfu_inq_var
use land_constants_mod, only : NBANDS,d608,mol_CO2,mol_air
use cana_tile_mod, only : cana_tile_type, cana_prog_type, &
canopy_air_mass, canopy_air_mass_for_tracers, cpw
use land_tile_mod, only : land_tile_type, land_tile_enum_type, &
first_elmt, tail_elmt, next_elmt, current_tile, operator(/=)
use land_tile_diag_mod, only : &
register_tiled_diag_field, send_tile_data, diag_buff_type
use land_data_mod, only : land_state_type, lnd
use land_tile_io_mod, only : create_tile_out_file, read_tile_data_r0d_fptr, write_tile_data_r0d_fptr, &
get_input_restart_name, print_netcdf_error
use land_debug_mod, only : is_watch_point, check_temp_range
implicit none
private
! ==== public interfaces =====================================================
public :: read_cana_namelist
public :: cana_init
public :: cana_end
public :: save_cana_restart
public :: cana_radiation
public :: cana_turbulence
public :: cana_roughness
public :: cana_state
public :: cana_step_1
public :: cana_step_2
! ==== end of public interfaces ==============================================
! ==== module constants ======================================================
character(len=*), private, parameter :: &
version = '$Id: canopy_air.F90,v 20.0 2013/12/13 23:29:31 fms Exp $', &
tagname = '$Name: tikal $', &
module_name = 'canopy_air_mod'
! options for turbulence parameter calculations
integer, parameter :: TURB_LM3W = 1, TURB_LM3V = 2
! ==== module variables ======================================================
!---- namelist ---------------------------------------------------------------
real :: init_T = 288.
real :: init_T_cold = 260.
real :: init_q = 0.
real :: init_co2 = 350.0e-6 ! ppmv = mol co2/mol of dry air
character(len=32) :: turbulence_to_use = 'lm3w' ! or lm3v
logical :: save_qco2 = .TRUE.
logical :: sfc_dir_albedo_bug = .FALSE. ! if true, reverts to buggy behavior
! where direct albedo was mistakenly used for part of sub-canopy diffuse light
logical :: allow_small_z0 = .FALSE. ! to use z0 provided by lake and glac modules
real :: lai_min_turb = 0.0 ! fudge to desensitize Tv to SW/cosz inconsistency
namelist /cana_nml/ &
init_T, init_T_cold, init_q, init_co2, turbulence_to_use, &
canopy_air_mass, canopy_air_mass_for_tracers, cpw, save_qco2, &
sfc_dir_albedo_bug, allow_small_z0, lai_min_turb
!---- end of namelist --------------------------------------------------------
logical :: module_is_initialized =.FALSE.
type(time_type) :: time ! *** NOT YET USED
real :: delta_time ! fast time step
integer :: turbulence_option ! selected option of turbulence parameters
! calculations
! ==== NetCDF declarations ===================================================
include 'netcdf.inc'
#define __NF_ASRT__(x) call print_netcdf_error((x),module_name,__LINE__)
contains
! ============================================================================
subroutine read_cana_namelist()
! ---- local vars
integer :: unit ! unit for namelist i/o
integer :: io ! i/o status for the namelist
integer :: ierr ! error code, returned by i/o routines
call write_version_number(version, tagname)
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=cana_nml, iostat=io)
ierr = check_nml_error(io, 'cana_nml')
#else
if (file_exist('input.nml')) then
unit = open_namelist_file()
ierr = 1;
do while (ierr /= 0)
read (unit, nml=cana_nml, iostat=io, end=10)
ierr = check_nml_error (io, 'cana_nml')
enddo
10 continue
call close_file (unit)
endif
#endif
if (mpp_pe() == mpp_root_pe()) then
unit = stdlog()
write (unit, nml=cana_nml)
endif
end subroutine read_cana_namelist
! ============================================================================
! initialize canopy air
subroutine cana_init ( id_lon, id_lat )
integer, intent(in) :: id_lon ! ID of land longitude (X) axis
integer, intent(in) :: id_lat ! ID of land latitude (Y) axis
! ---- local vars ----------------------------------------------------------
integer :: unit ! unit for various i/o
type(land_tile_enum_type) :: te,ce ! last and current tile
type(land_tile_type), pointer :: tile ! pointer to current tile
character(len=256) :: restart_file_name
logical :: restart_exists
module_is_initialized = .TRUE.
! ---- make module copy of time --------------------------------------------
time = lnd%time
delta_time = time_type_to_real(lnd%dt_fast)
! ---- initialize cana state -----------------------------------------------
! first, set the initial values
te = tail_elmt (lnd%tile_map)
ce = first_elmt(lnd%tile_map)
do while(ce /= te)
tile=>current_tile(ce) ! get pointer to current tile
ce=next_elmt(ce) ! advance position to the next tile
if (.not.associated(tile%cana)) cycle
if (associated(tile%glac)) then
tile%cana%prog%T = init_T_cold
else
tile%cana%prog%T = init_T
endif
tile%cana%prog%q = init_q
! convert to kg CO2/kg wet air
tile%cana%prog%co2 = init_co2*mol_CO2/mol_air*(1-tile%cana%prog%q)
enddo
! then read the restart if it exists
call get_input_restart_name('INPUT/cana.res.nc',restart_exists,restart_file_name)
if (restart_exists) then
call error_mesg('cana_init',&
'reading NetCDF restart "'//trim(restart_file_name)//'"',&
NOTE)
__NF_ASRT__(nf_open(restart_file_name,NF_NOWRITE,unit))
call read_tile_data_r0d_fptr(unit, 'temp' , cana_T_ptr )
call read_tile_data_r0d_fptr(unit, 'sphum' , cana_q_ptr )
if(nfu_inq_var(unit,'co2')==NF_NOERR) then
call read_tile_data_r0d_fptr(unit, 'co2', cana_co2_ptr )
endif
__NF_ASRT__(nf_close(unit))
else
call error_mesg('cana_init',&
'cold-starting canopy air',&
NOTE)
endif
! initialize options, to avoid expensive character comparisons during
! run-time
if (trim(turbulence_to_use)=='lm3v') then
turbulence_option = TURB_LM3V
else if (trim(turbulence_to_use)=='lm3w') then
turbulence_option = TURB_LM3W
else
call error_mesg('cana_init', 'canopy air turbulence option turbulence_to_use="'// &
trim(turbulence_to_use)//'" is invalid, use "lm3w" or "lm3v"', FATAL)
endif
end subroutine cana_init
! ============================================================================
! release memory
subroutine cana_end ()
module_is_initialized =.FALSE.
end subroutine cana_end
! ============================================================================
subroutine save_cana_restart (tile_dim_length, timestamp)
integer, intent(in) :: tile_dim_length ! length of tile dim. in the output file
character(*), intent(in) :: timestamp ! timestamp to add to the file name
! ---- local vars ----------------------------------------------------------
integer :: unit ! restart file i/o unit
call error_mesg('cana_end','writing NetCDF restart',NOTE)
call create_tile_out_file(unit,'RESTART/'//trim(timestamp)//'cana.res.nc',&
lnd%coord_glon, lnd%coord_glat, cana_tile_exists, tile_dim_length)
! write fields
call write_tile_data_r0d_fptr(unit,'temp' ,cana_T_ptr,'canopy air temperature','degrees_K')
call write_tile_data_r0d_fptr(unit,'sphum',cana_q_ptr,'canopy air specific humidity','kg/kg')
if (save_qco2) then
call write_tile_data_r0d_fptr(unit,'co2' ,cana_co2_ptr,'canopy air co2 concentration','(kg CO2)/(kg wet air)')
endif
! close output file
__NF_ASRT__(nf_close(unit))
end subroutine save_cana_restart
! ============================================================================
! set up constants for linearization of radiative transfer, using information
! provided by soil, snow and vegetation modules.
subroutine cana_radiation (lm2, &
subs_refl_dir, subs_refl_dif, subs_refl_lw, &
snow_refl_dir, snow_refl_dif, snow_refl_lw, &
snow_area, &
vegn_refl_dir, vegn_refl_dif, vegn_tran_dir, vegn_tran_dif, &
vegn_tran_dir_dir, vegn_refl_lw, vegn_tran_lw, &
vegn_cover, &
Sg_dir, Sg_dif, Sv_dir, Sv_dif, &
land_albedo_dir, land_albedo_dif )
logical, intent(in) :: lm2
real, intent(in) :: &
subs_refl_dir(NBANDS), subs_refl_dif(NBANDS), subs_refl_lw, & ! sub-snow reflectances for direct, diffuse, and LW radiation respectively
snow_refl_dir(NBANDS), snow_refl_dif(NBANDS), snow_refl_lw, & ! snow reflectances for direct, diffuse, and LW radiation respectively
snow_area, &
vegn_refl_dir(NBANDS), vegn_tran_dir(NBANDS), & ! vegn reflectance & transmittance for direct light
vegn_tran_dir_dir(NBANDS), & !
vegn_refl_dif(NBANDS), vegn_tran_dif(NBANDS), & ! vegn reflectance & transmittance for diffuse light
vegn_refl_lw, vegn_tran_lw, & ! vegn reflectance & transmittance for thermal radiation
vegn_cover
real, intent(out) :: &
Sg_dir(NBANDS), Sg_dif(NBANDS), & ! fraction of downward short-wave absorbed by ground and snow
Sv_dir(NBANDS), Sv_dif(NBANDS), & ! fraction of downward short-wave absorbed by vegetation
land_albedo_dir(NBANDS), land_albedo_dif(NBANDS)
! ---- local vars
real :: &
grnd_refl_dir(NBANDS), & ! SW reflectances of ground surface (by spectral band)
grnd_refl_dif(NBANDS), & ! SW reflectances of ground surface (by spectral band)
grnd_refl_lw ! LW reflectance of ground surface
real :: &
subs_up_from_dir(NBANDS), subs_up_from_dif(NBANDS), &
subs_dn_dir_from_dir(NBANDS), subs_dn_dif_from_dif(NBANDS), subs_dn_dif_from_dir(NBANDS)
grnd_refl_dir = subs_refl_dir + (snow_refl_dir - subs_refl_dir) * snow_area
grnd_refl_dif = subs_refl_dif + (snow_refl_dif - subs_refl_dif) * snow_area
grnd_refl_lw = subs_refl_lw + (snow_refl_lw - subs_refl_lw ) * snow_area
! ---- shortwave -----------------------------------------------------------
! allocation to canopy and ground, based on solution for single
! vegetation layer of limited cover. both ground and vegetation are gray.
Sv_dir = 0; Sv_dif = 0
IF (LM2) THEN
subs_dn_dir_from_dir = vegn_tran_dir_dir
subs_dn_dif_from_dir = vegn_tran_dir
subs_dn_dif_from_dif = vegn_tran_dif
if (sfc_dir_albedo_bug) then
subs_up_from_dir = grnd_refl_dir &
* (subs_dn_dir_from_dir + subs_dn_dif_from_dir)
else
subs_up_from_dir = grnd_refl_dir*subs_dn_dir_from_dir + &
grnd_refl_dif*subs_dn_dif_from_dir
endif
subs_up_from_dif = grnd_refl_dif*subs_dn_dif_from_dif
land_albedo_dir = subs_up_from_dir+vegn_refl_dir
land_albedo_dif = subs_up_from_dif+vegn_refl_dif
ELSE
subs_dn_dir_from_dir = vegn_tran_dir_dir
subs_dn_dif_from_dir = (vegn_tran_dir + vegn_refl_dif*grnd_refl_dir*vegn_tran_dir_dir)&
/ (1 - grnd_refl_dif*vegn_refl_dif)
subs_dn_dif_from_dif = vegn_tran_dif &
/ (1 - grnd_refl_dif*vegn_refl_dif)
if (sfc_dir_albedo_bug) then
subs_up_from_dir = grnd_refl_dir * (subs_dn_dir_from_dir + subs_dn_dif_from_dir)
else
subs_up_from_dir = grnd_refl_dir*subs_dn_dir_from_dir + &
grnd_refl_dif*subs_dn_dif_from_dir
endif
subs_up_from_dif = grnd_refl_dif*subs_dn_dif_from_dif
land_albedo_dir = subs_up_from_dir*vegn_tran_dif + vegn_refl_dir
land_albedo_dif = subs_up_from_dif*vegn_tran_dif + vegn_refl_dif
ENDIF
Sg_dir = subs_dn_dir_from_dir + subs_dn_dif_from_dir - subs_up_from_dir
Sg_dif = subs_dn_dif_from_dif - subs_up_from_dif
Sv_dir = 1 - Sg_dir - land_albedo_dir
Sv_dif = 1 - Sg_dif - land_albedo_dif
end subroutine cana_radiation
! ============================================================================
subroutine cana_turbulence (u_star,&
vegn_cover, vegn_height, vegn_lai, vegn_sai, vegn_d_leaf, &
land_d, land_z0m, land_z0s, grnd_z0s, &
con_v_h, con_v_v, con_g_h, con_g_v )
real, intent(in) :: &
u_star, & ! friction velocity, m/s
land_d, land_z0m, land_z0s, grnd_z0s, &
vegn_cover, vegn_height, &
vegn_lai, vegn_sai, vegn_d_leaf
real, intent(out) :: &
con_v_h, con_v_v, & ! one-sided foliage-cas conductance per unit of ground area
con_g_h, con_g_v ! ground-CAS conductance per unit ground area
!---- local constants
real, parameter :: a_max = 3
real, parameter :: leaf_co = 0.01 ! meters per second^(1/2)
! leaf_co = g_b(z)/sqrt(wind(z)/d_leaf)
! ---- local vars
real :: a ! parameter of exponential wind profile within canopy:
! u = u(ztop)*exp(-a*(1-z/ztop))
real :: height ! effective height of vegetation
real :: wind ! normalized wind on top of canopy, m/s
real :: Kh_top ! turbulent exchange coefficient on top of the canopy
real :: vegn_idx ! total vegetation index = LAI+SAI
real :: rah_sca ! ground-SCA resistance
vegn_idx = vegn_lai+vegn_sai ! total vegetation index
select case(turbulence_option)
case(TURB_LM3W)
if(vegn_cover > 0) then
wind = u_star/VONKARM*log((vegn_height-land_d)/land_z0m) ! normalized wind on top of the canopy
a = vegn_cover*a_max
con_v_h = (2*max(vegn_lai,lai_min_turb)*leaf_co*(1-exp(-a/2))/a)*sqrt(wind/vegn_d_leaf)
con_g_h = u_star*a*VONKARM*(1-land_d/vegn_height) &
/ (exp(a*(1-grnd_z0s/vegn_height)) - exp(a*(1-(land_z0s+land_d)/vegn_height)))
else
con_v_h = 0
con_g_h = 0
endif
case(TURB_LM3V)
height = max(vegn_height,0.1) ! effective height of the vegetation
a = a_max
wind=u_star/VONKARM*log((height-land_d)/land_z0m) ! normalized wind on top of the canopy
con_v_h = (2*max(vegn_lai,lai_min_turb)*leaf_co*(1-exp(-a/2))/a)*sqrt(wind/vegn_d_leaf)
if (land_d > 0.06 .and. vegn_idx > 0.25) then
Kh_top = VONKARM*u_star*(height-land_d)
rah_sca = height/a/Kh_top * &
(exp(a*(1-grnd_z0s/height)) - exp(a*(1-(land_z0m+land_d)/height)))
rah_sca = min(rah_sca,1250.0)
else
rah_sca=0.01
endif
con_g_h = 1.0/rah_sca
end select
con_g_v = con_g_h
con_v_v = con_v_h
end subroutine
! ============================================================================
! update effective surface roughness lengths for CAS-to-atmosphere fluxes
! and conductances for canopy-to-CAS and ground-to-CAS fluxes
!
! Strategy: Always define a canopy present. Non-vegetated situation is simply
! a limit as vegetation density approaches (but isn't allowed to reach) zero.
! Create expressions for the outputs that reduce to the special
! cases of full canopy cover and no canopy. Full canopy solution is that
! from Bonan (NCAR/TN-417+STR, 1996, p. 63). Thus, setting cover=1 in
! recovers Bonan. Letting cover approach 0 makes con_v_coef go to zero,
! preventing exchange with canopy, and makes con_g_coef go infinite,
! removing sub-canopy resistance and putting all resistance above the
! canopy, where it can be affected by stability adjustments.
!
! ** However, there is still a problem with this formulation when a
! canopy is present, because surface flux (I think) is not told to
! subtract out the resistances associated with con_v_coef and con_g_coef,
! which thus seem to be double-counted. For testing LM2, we should set them
! to zero anyway.
subroutine cana_roughness(lm2, &
subs_z0m, subs_z0s, &
snow_z0m, snow_z0s, snow_area, &
vegn_cover, vegn_height, vegn_lai, vegn_sai, &
land_d, land_z0m, land_z0s, is_lake_or_glac )
logical, intent(in) :: lm2, is_lake_or_glac
real, intent(in) :: &
subs_z0m, subs_z0s, snow_z0m, snow_z0s, snow_area, vegn_cover, vegn_height, &
vegn_lai, vegn_sai
real, intent(out) :: &
land_d ,&
land_z0m ,&
land_z0s
!---- local constants
real, parameter :: d_h_max = 2./3.
real, parameter :: z0m_h_max = 1/7.35
! ---- local vars
real :: d_h ! ratio of displacement height to vegetation height
real :: z0m_h ! ratio of roughness length to vegetation height
real :: grnd_z0m, grnd_z0s
real :: z0s_h, z0s_h_max
real :: vegn_idx ! total vegetation index = LAI+SAI
real :: height ! effective vegetation height
grnd_z0m = exp( (1-snow_area)*log(subs_z0m) + snow_area*log(snow_z0m))
grnd_z0s = exp( (1-snow_area)*log(subs_z0s) + snow_area*log(snow_z0s))
select case(turbulence_option)
case(TURB_LM3W)
if(vegn_cover > 0) then
z0s_h_max = z0m_h_max*grnd_z0s/grnd_z0m ! to ensure cover->0 limit works
d_h = vegn_cover*d_h_max
if (lm2) then
if (vegn_lai.gt.1) then ! TEMP ***
z0m_h = z0m_h_max
z0s_h = z0s_h_max
else
z0m_h = grnd_z0m/vegn_height
z0s_h = grnd_z0s/vegn_height
endif
else
z0m_h = exp( vegn_cover*log(z0m_h_max) + (1-vegn_cover)*log(grnd_z0m/vegn_height))
z0s_h = exp( vegn_cover*log(z0s_h_max) + (1-vegn_cover)*log(grnd_z0s/vegn_height))
endif
land_d = d_h*vegn_height
land_z0m = z0m_h*vegn_height
land_z0s = z0s_h*vegn_height
else
land_d = 0
land_z0m = grnd_z0m
land_z0s = grnd_z0s
endif
case(TURB_LM3V)
height = max(vegn_height,0.1) ! effective height of the vegetation
vegn_idx = vegn_lai+vegn_sai ! total vegetation index
if(vegn_idx>1e-4) then
land_d = 1.1*height*log(1+(0.07*vegn_idx)**0.25)
if(vegn_idx>2.85) then
land_z0m = 0.3*(height-land_d)
else
land_z0m = grnd_z0m + 0.3*height*sqrt(0.07*vegn_idx)
endif
else
! bare soil or leaf off
land_z0m = 0.1 *height
land_d = 0.66*height
endif
land_z0s = land_z0m*exp(-2.0)
if (allow_small_z0.and.is_lake_or_glac) then
land_d = 0
land_z0m = grnd_z0m
land_z0s = grnd_z0s
endif
end select
end subroutine cana_roughness
! ============================================================================
subroutine cana_state ( cana, cana_T, cana_q, cana_co2 )
type(cana_tile_type), intent(in) :: cana
real, optional , intent(out) :: cana_T, cana_q, cana_co2
if (present(cana_T)) cana_T = cana%prog%T
if (present(cana_q)) cana_q = cana%prog%q
if (present(cana_co2)) cana_co2 = cana%prog%co2
end subroutine
! ============================================================================
subroutine cana_step_1 ( cana,&
p_surf, con_g_h, con_g_v, grnd_T, grnd_rh, grnd_rh_psi, &
Hge, DHgDTg, DHgDTc, &
Ege, DEgDTg, DEgDqc, DEgDpsig )
type(cana_tile_type), intent(in) :: cana
real, intent(in) :: &
p_surf, & ! surface pressure, Pa
con_g_h, & ! conductivity between ground and CAS for heat
con_g_v, & ! conductivity between ground and CAS for vapor
grnd_T, & ! ground temperature, degK
grnd_rh, & ! ground relative humidity
grnd_rh_psi ! psi derivative of ground relative humidity
real, intent(out) :: &
Hge, DHgDTg, DHgDTc, & ! linearization of the sensible heat flux from ground
Ege, DEgDTg, DEgDqc, DEgDpsig ! linearization of evaporation from ground
! ---- local vars
real :: rho, grnd_q, qsat, DqsatDTg
call check_temp_range(grnd_T,'cana_step_1','grnd_T', lnd%time)
call qscomp(grnd_T,p_surf,qsat,DqsatDTg)
grnd_q = grnd_rh * qsat
rho = p_surf/(rdgas*cana%prog%T*(1+d608*cana%prog%q))
Hge = rho*cp_air*con_g_h*(grnd_T - cana%prog%T)
DHgDTg = rho*cp_air*con_g_h
DHgDTc = -rho*cp_air*con_g_h
Ege = rho*con_g_v*(grnd_q - cana%prog%q)
DEgDTg = rho*con_g_v*DqsatDTg*grnd_rh
DEgDqc = -rho*con_g_v
DEgDpsig = rho*con_g_v*qsat*grnd_rh_psi
if(is_watch_point())then
write(*,*)'#### cana_step_1 input ####'
__DEBUG1__(p_surf)
__DEBUG2__(con_g_h,con_g_v)
__DEBUG2__(grnd_T,grnd_rh)
write(*,*)'#### cana_step_1 internals ####'
__DEBUG4__(rho, grnd_q, qsat, DqsatDTg)
__DEBUG2__(cana%prog%T,cana%prog%q)
write(*,*)'#### cana_step_1 output ####'
__DEBUG3__(Hge, DHgDTg, DHgDTc)
__DEBUG4__(Ege, DEgDTg, DEgDqc, DEgDpsig)
endif
end subroutine
! ============================================================================
subroutine cana_step_2 ( cana, delta_Tc, delta_qc )
type(cana_tile_type), intent(inout) :: cana
real, intent(in) :: &
delta_Tc, & ! change in canopy air temperature
delta_qc ! change in canopy air humidity
cana%prog%T = cana%prog%T + delta_Tc
cana%prog%q = cana%prog%q + delta_qc
end subroutine cana_step_2
! ============================================================================
! tile existence detector: returns a logical value indicating wether component
! model tile exists or not
logical function cana_tile_exists(tile)
type(land_tile_type), pointer :: tile
cana_tile_exists = associated(tile%cana)
end function cana_tile_exists
! ============================================================================
! accessor functions: given a pointer to a land tile, they return pointer
! to the desired member of the land tile, of NULL if this member does not
! exist.
#define DEFINE_CANA_ACCESSOR_0D(xtype,x) subroutine CONCAT3(cana_,x,_ptr(t,p));\
type(land_tile_type),pointer::t;xtype,pointer::p;p=>NULL();if(associated(t))then;if(associated(t%cana))p=>t%cana%prog%x;endif;end subroutine
DEFINE_CANA_ACCESSOR_0D(real,T)
DEFINE_CANA_ACCESSOR_0D(real,q)
DEFINE_CANA_ACCESSOR_0D(real,co2)
end module canopy_air_mod
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/slasq6.f | 5 | 4813 | SUBROUTINE SLASQ6( I0, N0, Z, PP, DMIN, DMIN1, DMIN2, DN,
$ DNM1, DNM2 )
*
* -- 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, 1999
*
* .. Scalar Arguments ..
INTEGER I0, N0, PP
REAL DMIN, DMIN1, DMIN2, DN, DNM1, DNM2
* ..
* .. Array Arguments ..
REAL Z( * )
* ..
*
* Purpose
* =======
*
* SLASQ6 computes one dqd (shift equal to zero) transform in
* ping-pong form, with protection against underflow and overflow.
*
* Arguments
* =========
*
* I0 (input) INTEGER
* First index.
*
* N0 (input) INTEGER
* Last index.
*
* Z (input) REAL array, dimension ( 4*N )
* Z holds the qd array. EMIN is stored in Z(4*N0) to avoid
* an extra argument.
*
* PP (input) INTEGER
* PP=0 for ping, PP=1 for pong.
*
* DMIN (output) REAL
* Minimum value of d.
*
* DMIN1 (output) REAL
* Minimum value of d, excluding D( N0 ).
*
* DMIN2 (output) REAL
* Minimum value of d, excluding D( N0 ) and D( N0-1 ).
*
* DN (output) REAL
* d(N0), the last value of d.
*
* DNM1 (output) REAL
* d(N0-1).
*
* DNM2 (output) REAL
* d(N0-2).
*
* =====================================================================
*
* .. Parameter ..
REAL ZERO
PARAMETER ( ZERO = 0.0E0 )
* ..
* .. Local Scalars ..
INTEGER J4, J4P2
REAL D, EMIN, SAFMIN, TEMP
* ..
* .. External Function ..
REAL SLAMCH
EXTERNAL SLAMCH
* ..
* .. Intrinsic Functions ..
INTRINSIC MIN
* ..
* .. Executable Statements ..
*
IF( ( N0-I0-1 ).LE.0 )
$ RETURN
*
SAFMIN = SLAMCH( 'Safe minimum' )
J4 = 4*I0 + PP - 3
EMIN = Z( J4+4 )
D = Z( J4 )
DMIN = D
*
IF( PP.EQ.0 ) THEN
DO 10 J4 = 4*I0, 4*( N0-3 ), 4
Z( J4-2 ) = D + Z( J4-1 )
IF( Z( J4-2 ).EQ.ZERO ) THEN
Z( J4 ) = ZERO
D = Z( J4+1 )
DMIN = D
EMIN = ZERO
ELSE IF( SAFMIN*Z( J4+1 ).LT.Z( J4-2 ) .AND.
$ SAFMIN*Z( J4-2 ).LT.Z( J4+1 ) ) THEN
TEMP = Z( J4+1 ) / Z( J4-2 )
Z( J4 ) = Z( J4-1 )*TEMP
D = D*TEMP
ELSE
Z( J4 ) = Z( J4+1 )*( Z( J4-1 ) / Z( J4-2 ) )
D = Z( J4+1 )*( D / Z( J4-2 ) )
END IF
DMIN = MIN( DMIN, D )
EMIN = MIN( EMIN, Z( J4 ) )
10 CONTINUE
ELSE
DO 20 J4 = 4*I0, 4*( N0-3 ), 4
Z( J4-3 ) = D + Z( J4 )
IF( Z( J4-3 ).EQ.ZERO ) THEN
Z( J4-1 ) = ZERO
D = Z( J4+2 )
DMIN = D
EMIN = ZERO
ELSE IF( SAFMIN*Z( J4+2 ).LT.Z( J4-3 ) .AND.
$ SAFMIN*Z( J4-3 ).LT.Z( J4+2 ) ) THEN
TEMP = Z( J4+2 ) / Z( J4-3 )
Z( J4-1 ) = Z( J4 )*TEMP
D = D*TEMP
ELSE
Z( J4-1 ) = Z( J4+2 )*( Z( J4 ) / Z( J4-3 ) )
D = Z( J4+2 )*( D / Z( J4-3 ) )
END IF
DMIN = MIN( DMIN, D )
EMIN = MIN( EMIN, Z( J4-1 ) )
20 CONTINUE
END IF
*
* Unroll last two steps.
*
DNM2 = D
DMIN2 = DMIN
J4 = 4*( N0-2 ) - PP
J4P2 = J4 + 2*PP - 1
Z( J4-2 ) = DNM2 + Z( J4P2 )
IF( Z( J4-2 ).EQ.ZERO ) THEN
Z( J4 ) = ZERO
DNM1 = Z( J4P2+2 )
DMIN = DNM1
EMIN = ZERO
ELSE IF( SAFMIN*Z( J4P2+2 ).LT.Z( J4-2 ) .AND.
$ SAFMIN*Z( J4-2 ).LT.Z( J4P2+2 ) ) THEN
TEMP = Z( J4P2+2 ) / Z( J4-2 )
Z( J4 ) = Z( J4P2 )*TEMP
DNM1 = DNM2*TEMP
ELSE
Z( J4 ) = Z( J4P2+2 )*( Z( J4P2 ) / Z( J4-2 ) )
DNM1 = Z( J4P2+2 )*( DNM2 / Z( J4-2 ) )
END IF
DMIN = MIN( DMIN, DNM1 )
*
DMIN1 = DMIN
J4 = J4 + 4
J4P2 = J4 + 2*PP - 1
Z( J4-2 ) = DNM1 + Z( J4P2 )
IF( Z( J4-2 ).EQ.ZERO ) THEN
Z( J4 ) = ZERO
DN = Z( J4P2+2 )
DMIN = DN
EMIN = ZERO
ELSE IF( SAFMIN*Z( J4P2+2 ).LT.Z( J4-2 ) .AND.
$ SAFMIN*Z( J4-2 ).LT.Z( J4P2+2 ) ) THEN
TEMP = Z( J4P2+2 ) / Z( J4-2 )
Z( J4 ) = Z( J4P2 )*TEMP
DN = DNM1*TEMP
ELSE
Z( J4 ) = Z( J4P2+2 )*( Z( J4P2 ) / Z( J4-2 ) )
DN = Z( J4P2+2 )*( DNM1 / Z( J4-2 ) )
END IF
DMIN = MIN( DMIN, DN )
*
Z( J4+2 ) = DN
Z( 4*N0-PP ) = EMIN
RETURN
*
* End of SLASQ6
*
END
| gpl-2.0 |
FRidh/scipy | scipy/special/amos/zuni2.f | 157 | 8752 | SUBROUTINE ZUNI2(ZR, ZI, FNU, KODE, N, YR, YI, NZ, NLAST, FNUL,
* TOL, ELIM, ALIM)
C***BEGIN PROLOGUE ZUNI2
C***REFER TO ZBESI,ZBESK
C
C ZUNI2 COMPUTES I(FNU,Z) IN THE RIGHT HALF PLANE BY MEANS OF
C UNIFORM ASYMPTOTIC EXPANSION FOR J(FNU,ZN) WHERE ZN IS Z*I
C OR -Z*I AND ZN IS IN THE RIGHT HALF PLANE ALSO.
C
C FNUL IS THE SMALLEST ORDER PERMITTED FOR THE ASYMPTOTIC
C EXPANSION. NLAST=0 MEANS ALL OF THE Y VALUES WERE SET.
C NLAST.NE.0 IS THE NUMBER LEFT TO BE COMPUTED BY ANOTHER
C FORMULA FOR ORDERS FNU TO FNU+NLAST-1 BECAUSE FNU+NLAST-1.LT.FNUL.
C Y(I)=CZERO FOR I=NLAST+1,N
C
C***ROUTINES CALLED ZAIRY,ZUCHK,ZUNHJ,ZUOIK,D1MACH,AZABS
C***END PROLOGUE ZUNI2
C COMPLEX AI,ARG,ASUM,BSUM,CFN,CI,CID,CIP,CONE,CRSC,CSCL,CSR,CSS,
C *CZERO,C1,C2,DAI,PHI,RZ,S1,S2,Y,Z,ZB,ZETA1,ZETA2,ZN
DOUBLE PRECISION AARG, AIC, AII, AIR, ALIM, ANG, APHI, ARGI,
* ARGR, ASCLE, ASUMI, ASUMR, BRY, BSUMI, BSUMR, CIDI, CIPI, CIPR,
* CONER, CRSC, CSCL, CSRR, CSSR, C1R, C2I, C2M, C2R, DAII,
* DAIR, ELIM, FN, FNU, FNUL, HPI, PHII, PHIR, RAST, RAZ, RS1, RZI,
* RZR, STI, STR, S1I, S1R, S2I, S2R, TOL, YI, YR, ZBI, ZBR, ZEROI,
* ZEROR, ZETA1I, ZETA1R, ZETA2I, ZETA2R, ZI, ZNI, ZNR, ZR, CYR,
* CYI, D1MACH, AZABS, CAR, SAR
INTEGER I, IFLAG, IN, INU, J, K, KODE, N, NAI, ND, NDAI, NLAST,
* NN, NUF, NW, NZ, IDUM
DIMENSION BRY(3), YR(N), YI(N), CIPR(4), CIPI(4), CSSR(3),
* CSRR(3), CYR(2), CYI(2)
DATA ZEROR,ZEROI,CONER / 0.0D0, 0.0D0, 1.0D0 /
DATA CIPR(1),CIPI(1),CIPR(2),CIPI(2),CIPR(3),CIPI(3),CIPR(4),
* CIPI(4)/ 1.0D0,0.0D0, 0.0D0,1.0D0, -1.0D0,0.0D0, 0.0D0,-1.0D0/
DATA HPI, AIC /
1 1.57079632679489662D+00, 1.265512123484645396D+00/
C
NZ = 0
ND = N
NLAST = 0
C-----------------------------------------------------------------------
C COMPUTED VALUES WITH EXPONENTS BETWEEN ALIM AND ELIM IN MAG-
C NITUDE ARE SCALED TO KEEP INTERMEDIATE ARITHMETIC ON SCALE,
C EXP(ALIM)=EXP(ELIM)*TOL
C-----------------------------------------------------------------------
CSCL = 1.0D0/TOL
CRSC = TOL
CSSR(1) = CSCL
CSSR(2) = CONER
CSSR(3) = CRSC
CSRR(1) = CRSC
CSRR(2) = CONER
CSRR(3) = CSCL
BRY(1) = 1.0D+3*D1MACH(1)/TOL
C-----------------------------------------------------------------------
C ZN IS IN THE RIGHT HALF PLANE AFTER ROTATION BY CI OR -CI
C-----------------------------------------------------------------------
ZNR = ZI
ZNI = -ZR
ZBR = ZR
ZBI = ZI
CIDI = -CONER
INU = INT(SNGL(FNU))
ANG = HPI*(FNU-DBLE(FLOAT(INU)))
C2R = DCOS(ANG)
C2I = DSIN(ANG)
CAR = C2R
SAR = C2I
IN = INU + N - 1
IN = MOD(IN,4) + 1
STR = C2R*CIPR(IN) - C2I*CIPI(IN)
C2I = C2R*CIPI(IN) + C2I*CIPR(IN)
C2R = STR
IF (ZI.GT.0.0D0) GO TO 10
ZNR = -ZNR
ZBI = -ZBI
CIDI = -CIDI
C2I = -C2I
10 CONTINUE
C-----------------------------------------------------------------------
C CHECK FOR UNDERFLOW AND OVERFLOW ON FIRST MEMBER
C-----------------------------------------------------------------------
FN = DMAX1(FNU,1.0D0)
CALL ZUNHJ(ZNR, ZNI, FN, 1, TOL, PHIR, PHII, ARGR, ARGI, ZETA1R,
* ZETA1I, ZETA2R, ZETA2I, ASUMR, ASUMI, BSUMR, BSUMI)
IF (KODE.EQ.1) GO TO 20
STR = ZBR + ZETA2R
STI = ZBI + ZETA2I
RAST = FN/AZABS(STR,STI)
STR = STR*RAST*RAST
STI = -STI*RAST*RAST
S1R = -ZETA1R + STR
S1I = -ZETA1I + STI
GO TO 30
20 CONTINUE
S1R = -ZETA1R + ZETA2R
S1I = -ZETA1I + ZETA2I
30 CONTINUE
RS1 = S1R
IF (DABS(RS1).GT.ELIM) GO TO 150
40 CONTINUE
NN = MIN0(2,ND)
DO 90 I=1,NN
FN = FNU + DBLE(FLOAT(ND-I))
CALL ZUNHJ(ZNR, ZNI, FN, 0, TOL, PHIR, PHII, ARGR, ARGI,
* ZETA1R, ZETA1I, ZETA2R, ZETA2I, ASUMR, ASUMI, BSUMR, BSUMI)
IF (KODE.EQ.1) GO TO 50
STR = ZBR + ZETA2R
STI = ZBI + ZETA2I
RAST = FN/AZABS(STR,STI)
STR = STR*RAST*RAST
STI = -STI*RAST*RAST
S1R = -ZETA1R + STR
S1I = -ZETA1I + STI + DABS(ZI)
GO TO 60
50 CONTINUE
S1R = -ZETA1R + ZETA2R
S1I = -ZETA1I + ZETA2I
60 CONTINUE
C-----------------------------------------------------------------------
C TEST FOR UNDERFLOW AND OVERFLOW
C-----------------------------------------------------------------------
RS1 = S1R
IF (DABS(RS1).GT.ELIM) GO TO 120
IF (I.EQ.1) IFLAG = 2
IF (DABS(RS1).LT.ALIM) GO TO 70
C-----------------------------------------------------------------------
C REFINE TEST AND SCALE
C-----------------------------------------------------------------------
C-----------------------------------------------------------------------
APHI = AZABS(PHIR,PHII)
AARG = AZABS(ARGR,ARGI)
RS1 = RS1 + DLOG(APHI) - 0.25D0*DLOG(AARG) - AIC
IF (DABS(RS1).GT.ELIM) GO TO 120
IF (I.EQ.1) IFLAG = 1
IF (RS1.LT.0.0D0) GO TO 70
IF (I.EQ.1) IFLAG = 3
70 CONTINUE
C-----------------------------------------------------------------------
C SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR
C EXPONENT EXTREMES
C-----------------------------------------------------------------------
CALL ZAIRY(ARGR, ARGI, 0, 2, AIR, AII, NAI, IDUM)
CALL ZAIRY(ARGR, ARGI, 1, 2, DAIR, DAII, NDAI, IDUM)
STR = DAIR*BSUMR - DAII*BSUMI
STI = DAIR*BSUMI + DAII*BSUMR
STR = STR + (AIR*ASUMR-AII*ASUMI)
STI = STI + (AIR*ASUMI+AII*ASUMR)
S2R = PHIR*STR - PHII*STI
S2I = PHIR*STI + PHII*STR
STR = DEXP(S1R)*CSSR(IFLAG)
S1R = STR*DCOS(S1I)
S1I = STR*DSIN(S1I)
STR = S2R*S1R - S2I*S1I
S2I = S2R*S1I + S2I*S1R
S2R = STR
IF (IFLAG.NE.1) GO TO 80
CALL ZUCHK(S2R, S2I, NW, BRY(1), TOL)
IF (NW.NE.0) GO TO 120
80 CONTINUE
IF (ZI.LE.0.0D0) S2I = -S2I
STR = S2R*C2R - S2I*C2I
S2I = S2R*C2I + S2I*C2R
S2R = STR
CYR(I) = S2R
CYI(I) = S2I
J = ND - I + 1
YR(J) = S2R*CSRR(IFLAG)
YI(J) = S2I*CSRR(IFLAG)
STR = -C2I*CIDI
C2I = C2R*CIDI
C2R = STR
90 CONTINUE
IF (ND.LE.2) GO TO 110
RAZ = 1.0D0/AZABS(ZR,ZI)
STR = ZR*RAZ
STI = -ZI*RAZ
RZR = (STR+STR)*RAZ
RZI = (STI+STI)*RAZ
BRY(2) = 1.0D0/BRY(1)
BRY(3) = D1MACH(2)
S1R = CYR(1)
S1I = CYI(1)
S2R = CYR(2)
S2I = CYI(2)
C1R = CSRR(IFLAG)
ASCLE = BRY(IFLAG)
K = ND - 2
FN = DBLE(FLOAT(K))
DO 100 I=3,ND
C2R = S2R
C2I = S2I
S2R = S1R + (FNU+FN)*(RZR*C2R-RZI*C2I)
S2I = S1I + (FNU+FN)*(RZR*C2I+RZI*C2R)
S1R = C2R
S1I = C2I
C2R = S2R*C1R
C2I = S2I*C1R
YR(K) = C2R
YI(K) = C2I
K = K - 1
FN = FN - 1.0D0
IF (IFLAG.GE.3) GO TO 100
STR = DABS(C2R)
STI = DABS(C2I)
C2M = DMAX1(STR,STI)
IF (C2M.LE.ASCLE) GO TO 100
IFLAG = IFLAG + 1
ASCLE = BRY(IFLAG)
S1R = S1R*C1R
S1I = S1I*C1R
S2R = C2R
S2I = C2I
S1R = S1R*CSSR(IFLAG)
S1I = S1I*CSSR(IFLAG)
S2R = S2R*CSSR(IFLAG)
S2I = S2I*CSSR(IFLAG)
C1R = CSRR(IFLAG)
100 CONTINUE
110 CONTINUE
RETURN
120 CONTINUE
IF (RS1.GT.0.0D0) GO TO 140
C-----------------------------------------------------------------------
C SET UNDERFLOW AND UPDATE PARAMETERS
C-----------------------------------------------------------------------
YR(ND) = ZEROR
YI(ND) = ZEROI
NZ = NZ + 1
ND = ND - 1
IF (ND.EQ.0) GO TO 110
CALL ZUOIK(ZR, ZI, FNU, KODE, 1, ND, YR, YI, NUF, TOL, ELIM, ALIM)
IF (NUF.LT.0) GO TO 140
ND = ND - NUF
NZ = NZ + NUF
IF (ND.EQ.0) GO TO 110
FN = FNU + DBLE(FLOAT(ND-1))
IF (FN.LT.FNUL) GO TO 130
C FN = CIDI
C J = NUF + 1
C K = MOD(J,4) + 1
C S1R = CIPR(K)
C S1I = CIPI(K)
C IF (FN.LT.0.0D0) S1I = -S1I
C STR = C2R*S1R - C2I*S1I
C C2I = C2R*S1I + C2I*S1R
C C2R = STR
IN = INU + ND - 1
IN = MOD(IN,4) + 1
C2R = CAR*CIPR(IN) - SAR*CIPI(IN)
C2I = CAR*CIPI(IN) + SAR*CIPR(IN)
IF (ZI.LE.0.0D0) C2I = -C2I
GO TO 40
130 CONTINUE
NLAST = ND
RETURN
140 CONTINUE
NZ = -1
RETURN
150 CONTINUE
IF (RS1.GT.0.0D0) GO TO 140
NZ = N
DO 160 I=1,N
YR(I) = ZEROR
YI(I) = ZEROI
160 CONTINUE
RETURN
END
| bsd-3-clause |
likev/ncl | ncl_ncarg_src/ncarg2d/src/fundamental/fgks/fgkgpm.f | 1 | 5523 |
PROGRAM FGKGPM
C
C Define the error file, the Fortran unit number, the workstation type,
C and the workstation ID to be used in calls to GKS routines.
C
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript
C
PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1)
C
C Illustrate polymarkers.
C
PARAMETER (ID=50)
DIMENSION XM1(ID),YM1(ID),XM2(ID),YM2(ID),XM3(ID),YM3(ID)
C
C Open GKS, open and activate a workstation.
C
CALL GOPKS (IERRF, ISZDM)
CALL GOPWK (IWKID, LUNIT, IWTYPE)
CALL GACWK (IWKID)
C
C Define the necessary color indices.
C
CALL GSCR(IWKID,0,1.,1.,1.)
CALL GSCR(IWKID,1,0.,0.,0.)
CALL GSCR(IWKID,2,1.,1.,0.)
CALL GSCR(IWKID,3,0.,1.,0.)
CALL GSCR(IWKID,4,1.,1.,0.)
CALL GSCR(IWKID,5,0.,1.,1.)
CALL GSCR(IWKID,6,1.,0.,1.)
C
C Marker 1, dot (fill a large circular dot with markers of type 1).
C
C
C Position and radius of the dot outline.
C
X0 = .5
Y0 = .7
R = .08
JL = 8
AINC = R/REAL(JL)
CALL GSMK(1)
DO 10 J=0,JL
Y = Y0+REAL(J)*AINC
XE = X0+SQRT(MAX(R**2-(Y-Y0)**2,0.))
X = X0
20 CONTINUE
C
C Fill the circle with dot markers using symmetries.
C
CALL GPM(1,X,Y)
CALL GSPMCI(1)
CALL GPM(1,X,2*Y0-Y)
CALL GPM(1,2*X0-X,2*Y0-Y)
CALL GPM(1,2*X0-X,Y)
X = X+AINC
IF (X .GT. XE) GO TO 10
GO TO 20
10 CONTINUE
C
C Label the dot.
C
CALL PCSETI('CD',1)
CALL GSPLCI(1)
CALL PLCHHQ(X0,Y0+R+.05,'Marker 1 (dots)',.018,0.,0.)
C
C Marker 2, plus (make a plus from the plus markers.)
C
C
C Center of big plus.
C
X0 = .83
Y0 = .5
R = .1
JL = 7
AINC = R/REAL(JL)
DO 30 J=-JL,JL,1
Y = Y0+REAL(J)*AINC
IDX = J+JL+1
XM1(IDX) = X0
YM1(IDX) = Y
X = X0+REAL(J)*AINC
XM2(IDX) = X
YM2(IDX) = Y0
30 CONTINUE
CALL GSMK(2)
CALL GSPMCI(1)
C
C Put plus markers along the two axes of the big plus.
C
CALL GPM(2*JL+1,XM1,YM1)
CALL GPM(2*JL+1,XM2,YM2)
C
C Label the big plus.
C
CALL PCSETI('CD',1)
CALL GSPLCI(1)
CALL PLCHHQ(X0,Y0+R+.05,'Marker 2 (plus signs)',.018,0.,0.)
C
C Marker 3, asterisk (make an asterisk from the asterisk markers.)
C
X0 = .7
Y0 = .15
R = .1
JL = 5
AINC = R/REAL(JL)
DO 40 J=-JL,JL,1
Y = Y0+REAL(J)*AINC
IDX = J+JL+1
XM1(IDX) = X0
YM1(IDX) = Y
P = 0.5*SQRT(2.)*(Y-Y0)
IF (Y .GE. 0.) THEN
XM2(IDX) = X0+P
YM2(IDX) = Y0+P
XM3(IDX) = X0-P
YM3(IDX) = Y0+P
ELSE
XM2(IDX) = X0-P
YM2(IDX) = Y0-P
XM3(IDX) = X0+P
YM3(IDX) = Y0-P
ENDIF
40 CONTINUE
CALL GSMK(3)
CALL GSPMCI(1)
C
c Put asterisk markers along the axes of the big asterisk.
C
CALL GPM(2*JL+1,XM1,YM1)
CALL GPM(2*JL+1,XM2,YM2)
CALL GPM(2*JL+1,XM3,YM3)
C
C Label the big asterisk.
C
CALL PCSETI('CD',1)
CALL GSPLCI(1)
CALL PLCHHQ(X0,Y0+R+.05,'Marker 3 (asterisks)',.018,0.,0.)
C
C Marker 4, circle (make a big circle from the circle markers.)
C
X0 = .3
Y0 = .15
R = .1
JL = 50
RADINC = 2.*3.1415926/REAL(JL)
DO 50 J=1,JL
X = X0+R*COS(REAL(J)*RADINC)
Y = Y0+R*SIN(REAL(J)*RADINC)
XM1(J) = X
YM1(J) = Y
50 CONTINUE
CALL GSMK(4)
CALL GSPMCI(1)
CALL GSMKSC(2.)
CALL GPM(JL,XM1,YM1)
C
C Label the big circle.
C
CALL PCSETI('CD',1)
CALL GSPLCI(1)
CALL PLCHHQ(X0,Y0+R+.05,'Marker 4 (circles)',.018,0.,0.)
C
C Marker 5, cross (make a big cross from the cross markers.)
C
X0 = .17
Y0 = .5
R = .1
JL = 5
AINC = R/REAL(JL)
DO 60 J=-JL,JL,1
Y = Y0+REAL(J)*AINC
IDX = J+JL+1
P = 0.5*SQRT(2.)*(Y-Y0)
IF (Y .GE. 0.) THEN
XM2(IDX) = X0+P
YM2(IDX) = Y0+P
XM3(IDX) = X0-P
YM3(IDX) = Y0+P
ELSE
XM2(IDX) = X0-P
YM2(IDX) = Y0-P
XM3(IDX) = X0+P
YM3(IDX) = Y0-P
ENDIF
60 CONTINUE
CALL GSMK(5)
CALL GSPMCI(1)
C
C Plot cross markers along the axes of the big cross.
C
CALL GSMKSC(1.)
CALL GPM(2*JL+1,XM2,YM2)
CALL GPM(2*JL+1,XM3,YM3)
C
C Label the big cross.
C
CALL PCSETI('CD',1)
CALL GSPLCI(1)
CALL PLCHHQ(X0,Y0+R+.05,'Marker 5 (crosses)',.018,0.,0.)
C
C Draw a big circle in the center by applying a large marker size
C scale factor to the circle marker.
C
X0 = .5
Y0 = .46
CALL GSMK(4)
CALL GSPMCI(1)
CALL GSMKSC(15.)
CALL GPM(1,X0,Y0)
CALL PCSETI('CD',1)
CALL GSPLCI(1)
CALL PLCHHQ(X0,Y0+.028,'Circle',.015,0.,0.)
CALL PLCHHQ(X0,Y0 ,'Scaled',.015,0.,0.)
CALL PLCHHQ(X0,Y0-.028,'by 15.',.015,0.,0.)
C
C Label the plot (PLOTCHAR strokes its characters with lines, so the
C PLOTCHAR character attributes are controlled by the GKS polyline
C attributes).
C
CALL GSPLCI(1)
CALL PCSETI('CD',1)
CALL GSLWSC(2.)
CALL PLCHHQ(.5,.915,'Polymarkers',.025,0.,0.)
C
CALL FRAME
C
C Deactivate and close the workstation, close GKS.
C
CALL GDAWK (IWKID)
CALL GCLWK (IWKID)
CALL GCLKS
C
STOP
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ni/src/lib/nfpfort/plotgrids_var.f90 | 1 | 3331 | subroutine plotgrids_var(fname,plotvar)
implicit none
! Parameters
integer, parameter :: MAX_DOMAINS = 21
integer, parameter :: NVAR = 19
! Variables
integer :: i, j, funit, io_form_geogrid
integer :: interval_seconds
real, dimension(MAX_DOMAINS) :: parent_grid_ratio, parent_id, ixdim, jydim
real, dimension(MAX_DOMAINS) :: i_parent_start, j_parent_start, &
s_we, e_we, s_sn, e_sn, &
start_year, start_month, start_day, start_hour, &
end_year, end_month, end_day, end_hour
logical, dimension(MAX_DOMAINS) :: active_grid
logical :: is_used
real :: stand_lon, truelat1, truelat2, &
ref_lat, ref_lon, ref_x, ref_y, pole_lat, pole_lon
real :: dx, dy, mproj_int, max_dom
character (len=128) :: geog_data_path, opt_output_from_geogrid_path, opt_geogrid_tbl_path
character (len=128), dimension(MAX_DOMAINS) :: geog_data_res
character (len=128) :: map_proj
character (len=128), dimension(MAX_DOMAINS) :: start_date, end_date
character (len=3) :: wrf_core
character (*) :: fname
integer :: debug_level
real, dimension(NVAR,MAX_DOMAINS) :: plotvar(NVAR,MAX_DOMAINS)
namelist /share/ wrf_core, max_dom, start_date, end_date, &
start_year, end_year, start_month, end_month, &
start_day, end_day, start_hour, end_hour, &
interval_seconds, io_form_geogrid, opt_output_from_geogrid_path, &
debug_level, active_grid
namelist /geogrid/ parent_id, parent_grid_ratio, &
i_parent_start, j_parent_start, s_we, e_we, s_sn, e_sn, &
map_proj, ref_x, ref_y, ref_lat, ref_lon, &
truelat1, truelat2, stand_lon, dx, dy, pole_lat, pole_lon, &
geog_data_res, geog_data_path, opt_geogrid_tbl_path
!Initialize array
ref_x = -999.0
ref_y = -999.0
ref_lat = -999.0
ref_lon = -999.0
do i=1,NVAR
do j=1,MAX_DOMAINS
plotvar(i,j) = -999.0
end do
end do
! Read parameters from Fortran namelist
do funit=10,100
inquire(unit=funit, opened=is_used)
if (.not. is_used) exit
end do
open(funit,file=fname,status='old',form='formatted')
read(funit,share)
read(funit,geogrid)
close(funit)
!Assign integers to map projections
if (index(map_proj, 'lambert') /= 0) then
mproj_int = 1
else if (index(map_proj, 'mercator') /= 0) then
mproj_int = 2
else if (index(map_proj, 'polar') /= 0) then
mproj_int = 3
else if (index(map_proj, 'lat-lon') /= 0) then
mproj_int = 4
end if
!Put all the variables into an array
plotvar(1,1) = max_dom
plotvar(2,1) = dx
plotvar(3,1) = dy
plotvar(4,1) = ref_lat
plotvar(5,1) = ref_lon
plotvar(6,1) = ref_x
plotvar(7,1) = ref_y
plotvar(8,1) = truelat1
plotvar(9,1) = truelat2
plotvar(10,1) = stand_lon
plotvar(11,1) = mproj_int
plotvar(12,1) = pole_lat
plotvar(13,1) = pole_lon
do j=1,int(max_dom)
plotvar(14,j) = parent_id(j)
plotvar(15,j) = parent_grid_ratio(j)
plotvar(16,j) = i_parent_start(j)
plotvar(17,j) = j_parent_start(j)
plotvar(18,j) = e_we(j)
plotvar(19,j) = e_sn(j)
end do
end subroutine plotgrids_var
| gpl-2.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/g77/19990826-1.f | 210 | 8631 | c { dg-do compile }
* Date: Tue, 24 Aug 1999 12:25:41 +1200 (NZST)
* From: Jonathan Ravens <ravens@whio.gns.cri.nz>
* To: gcc-bugs@gcc.gnu.org
* Subject: g77 bug report
* X-UIDL: a0bf5ecc21487cde48d9104983ab04d6
! This fortran source will not compile - if the penultimate elseif block is 0
! included then the message appears :
!
! /usr/src/egcs//gcc-2.95.1/gcc/f/stw.c:308: failed assertion `b->uses_ > 0'
! g77: Internal compiler error: program f771 got fatal signal 6
!
! The command was : g77 -c <prog.f>
!
! The OS is Red Hat 6, and the output from uname -a is
! Linux grfw1452.gns.cri.nz 2.2.5-15 #1 Mon Apr 19 23:00:46 EDT 1999 i686 unknown
!
! The configure script I used was
! /usr/src/egcs/gcc/gcc-2.95.1/configure --enable-languages=f77 i585-unknown-linux
!
! I was installing 2.95 because under EGCS 2.1.1 none of my code was working
! with optimisation turned on, and there were still bugs with no optimisation
! (all of which code works fine under g77 0.5.21 and Sun/IBM/Dec/HP fortrans).
!
! The version of g77 is :
!
!g77 version 2.95.1 19990816 (release) (from FSF-g77 version 0.5.25 19990816 (release))
program main
if (i.eq.1) then
call abc(1)
else if (i.eq. 1) then
call abc( 1)
else if (i.eq. 2) then
call abc( 2)
else if (i.eq. 3) then
call abc( 3)
else if (i.eq. 4) then
call abc( 4)
else if (i.eq. 5) then
call abc( 5)
else if (i.eq. 6) then
call abc( 6)
else if (i.eq. 7) then
call abc( 7)
else if (i.eq. 8) then
call abc( 8)
else if (i.eq. 9) then
call abc( 9)
else if (i.eq. 10) then
call abc( 10)
else if (i.eq. 11) then
call abc( 11)
else if (i.eq. 12) then
call abc( 12)
else if (i.eq. 13) then
call abc( 13)
else if (i.eq. 14) then
call abc( 14)
else if (i.eq. 15) then
call abc( 15)
else if (i.eq. 16) then
call abc( 16)
else if (i.eq. 17) then
call abc( 17)
else if (i.eq. 18) then
call abc( 18)
else if (i.eq. 19) then
call abc( 19)
else if (i.eq. 20) then
call abc( 20)
else if (i.eq. 21) then
call abc( 21)
else if (i.eq. 22) then
call abc( 22)
else if (i.eq. 23) then
call abc( 23)
else if (i.eq. 24) then
call abc( 24)
else if (i.eq. 25) then
call abc( 25)
else if (i.eq. 26) then
call abc( 26)
else if (i.eq. 27) then
call abc( 27)
else if (i.eq. 28) then
call abc( 28)
else if (i.eq. 29) then
call abc( 29)
else if (i.eq. 30) then
call abc( 30)
else if (i.eq. 31) then
call abc( 31)
else if (i.eq. 32) then
call abc( 32)
else if (i.eq. 33) then
call abc( 33)
else if (i.eq. 34) then
call abc( 34)
else if (i.eq. 35) then
call abc( 35)
else if (i.eq. 36) then
call abc( 36)
else if (i.eq. 37) then
call abc( 37)
else if (i.eq. 38) then
call abc( 38)
else if (i.eq. 39) then
call abc( 39)
else if (i.eq. 40) then
call abc( 40)
else if (i.eq. 41) then
call abc( 41)
else if (i.eq. 42) then
call abc( 42)
else if (i.eq. 43) then
call abc( 43)
else if (i.eq. 44) then
call abc( 44)
else if (i.eq. 45) then
call abc( 45)
else if (i.eq. 46) then
call abc( 46)
else if (i.eq. 47) then
call abc( 47)
else if (i.eq. 48) then
call abc( 48)
else if (i.eq. 49) then
call abc( 49)
else if (i.eq. 50) then
call abc( 50)
else if (i.eq. 51) then
call abc( 51)
else if (i.eq. 52) then
call abc( 52)
else if (i.eq. 53) then
call abc( 53)
else if (i.eq. 54) then
call abc( 54)
else if (i.eq. 55) then
call abc( 55)
else if (i.eq. 56) then
call abc( 56)
else if (i.eq. 57) then
call abc( 57)
else if (i.eq. 58) then
call abc( 58)
else if (i.eq. 59) then
call abc( 59)
else if (i.eq. 60) then
call abc( 60)
else if (i.eq. 61) then
call abc( 61)
else if (i.eq. 62) then
call abc( 62)
else if (i.eq. 63) then
call abc( 63)
else if (i.eq. 64) then
call abc( 64)
else if (i.eq. 65) then
call abc( 65)
else if (i.eq. 66) then
call abc( 66)
else if (i.eq. 67) then
call abc( 67)
else if (i.eq. 68) then
call abc( 68)
else if (i.eq. 69) then
call abc( 69)
else if (i.eq. 70) then
call abc( 70)
else if (i.eq. 71) then
call abc( 71)
else if (i.eq. 72) then
call abc( 72)
else if (i.eq. 73) then
call abc( 73)
else if (i.eq. 74) then
call abc( 74)
else if (i.eq. 75) then
call abc( 75)
else if (i.eq. 76) then
call abc( 76)
else if (i.eq. 77) then
call abc( 77)
else if (i.eq. 78) then
call abc( 78)
else if (i.eq. 79) then
call abc( 79)
else if (i.eq. 80) then
call abc( 80)
else if (i.eq. 81) then
call abc( 81)
else if (i.eq. 82) then
call abc( 82)
else if (i.eq. 83) then
call abc( 83)
else if (i.eq. 84) then
call abc( 84)
else if (i.eq. 85) then
call abc( 85)
else if (i.eq. 86) then
call abc( 86)
else if (i.eq. 87) then
call abc( 87)
else if (i.eq. 88) then
call abc( 88)
else if (i.eq. 89) then
call abc( 89)
else if (i.eq. 90) then
call abc( 90)
else if (i.eq. 91) then
call abc( 91)
else if (i.eq. 92) then
call abc( 92)
else if (i.eq. 93) then
call abc( 93)
else if (i.eq. 94) then
call abc( 94)
else if (i.eq. 95) then
call abc( 95)
else if (i.eq. 96) then
call abc( 96)
else if (i.eq. 97) then
call abc( 97)
else if (i.eq. 98) then
call abc( 98)
else if (i.eq. 99) then
call abc( 99)
else if (i.eq. 100) then
call abc( 100)
else if (i.eq. 101) then
call abc( 101)
else if (i.eq. 102) then
call abc( 102)
else if (i.eq. 103) then
call abc( 103)
else if (i.eq. 104) then
call abc( 104)
else if (i.eq. 105) then
call abc( 105)
else if (i.eq. 106) then
call abc( 106)
else if (i.eq. 107) then
call abc( 107)
else if (i.eq. 108) then
call abc( 108)
else if (i.eq. 109) then
call abc( 109)
else if (i.eq. 110) then
call abc( 110)
else if (i.eq. 111) then
call abc( 111)
else if (i.eq. 112) then
call abc( 112)
else if (i.eq. 113) then
call abc( 113)
else if (i.eq. 114) then
call abc( 114)
else if (i.eq. 115) then
call abc( 115)
else if (i.eq. 116) then
call abc( 116)
else if (i.eq. 117) then
call abc( 117)
else if (i.eq. 118) then
call abc( 118)
else if (i.eq. 119) then
call abc( 119)
else if (i.eq. 120) then
call abc( 120)
else if (i.eq. 121) then
call abc( 121)
else if (i.eq. 122) then
call abc( 122)
else if (i.eq. 123) then
call abc( 123)
else if (i.eq. 124) then
call abc( 124)
else if (i.eq. 125) then !< Miscompiles if present
call abc( 125) !<
c else if (i.eq. 126) then
c call abc( 126)
endif
end
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/dgelq2.f | 15 | 3401 | SUBROUTINE DGELQ2( M, N, A, LDA, TAU, WORK, INFO )
*
* -- LAPACK 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 ..
INTEGER INFO, LDA, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DGELQ2 computes an LQ factorization of a real m by n matrix A:
* A = L * 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, the elements on and below the diagonal of the array
* contain the m by min(m,n) lower trapezoidal matrix L (L is
* lower triangular if m <= n); the elements above the diagonal,
* 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,M).
*
* TAU (output) DOUBLE PRECISION array, dimension (min(M,N))
* The scalar factors of the elementary reflectors (see Further
* Details).
*
* WORK (workspace) DOUBLE PRECISION array, dimension (M)
*
* 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(k) . . . H(2) H(1), where k = min(m,n).
*
* Each H(i) has the form
*
* H(i) = I - tau * v * v'
*
* where tau is a real scalar, and v is a real vector with
* v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n),
* and tau in TAU(i).
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, K
DOUBLE PRECISION AII
* ..
* .. External Subroutines ..
EXTERNAL DLARF, DLARFG, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. Executable Statements ..
*
* Test the input arguments
*
INFO = 0
IF( M.LT.0 ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
INFO = -4
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DGELQ2', -INFO )
RETURN
END IF
*
K = MIN( M, N )
*
DO 10 I = 1, K
*
* Generate elementary reflector H(i) to annihilate A(i,i+1:n)
*
CALL DLARFG( N-I+1, A( I, I ), A( I, MIN( I+1, N ) ), LDA,
$ TAU( I ) )
IF( I.LT.M ) THEN
*
* Apply H(i) to A(i+1:m,i:n) from the right
*
AII = A( I, I )
A( I, I ) = ONE
CALL DLARF( 'Right', M-I, N-I+1, A( I, I ), LDA, TAU( I ),
$ A( I+1, I ), LDA, WORK )
A( I, I ) = AII
END IF
10 CONTINUE
RETURN
*
* End of DGELQ2
*
END
| gpl-2.0 |
mtrbean/scipy | scipy/sparse/linalg/eigen/arpack/ARPACK/SRC/zsortc.f | 162 | 8112 | 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
| bsd-3-clause |
nealkruis/kiva | vendor/eigen-da9b4e14c255/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
| gpl-3.0 |
CompPhysics/ThesisProjects | doc/MSc/msc_students/former/SeanMiller/Thesis/Codes/CCD_prototype/CCD/eigen3/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
| cc0-1.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/alloc_comp_assign_10.f90 | 136 | 1944 | ! { dg-do run }
!
! Test the fix for PR39879, in which gfc gagged on the double
! defined assignment where the rhs had a default initialiser.
!
! Contributed by David Sagan <david.sagan@gmail.com>
!
module test_struct
interface assignment (=)
module procedure tao_lat_equal_tao_lat
end interface
type bunch_params_struct
integer n_live_particle
end type
type tao_lattice_struct
type (bunch_params_struct), allocatable :: bunch_params(:)
type (bunch_params_struct), allocatable :: bunch_params2(:)
end type
type tao_universe_struct
type (tao_lattice_struct), pointer :: model, design
character(200), pointer :: descrip => NULL()
end type
type tao_super_universe_struct
type (tao_universe_struct), allocatable :: u(:)
end type
type (tao_super_universe_struct), save, target :: s
contains
subroutine tao_lat_equal_tao_lat (lat1, lat2)
implicit none
type (tao_lattice_struct), intent(inout) :: lat1
type (tao_lattice_struct), intent(in) :: lat2
if (allocated(lat2%bunch_params)) then
lat1%bunch_params = lat2%bunch_params
end if
if (allocated(lat2%bunch_params2)) then
lat1%bunch_params2 = lat2%bunch_params2
end if
end subroutine
end module
program tao_program
use test_struct
implicit none
type (tao_universe_struct), pointer :: u
integer n, i
allocate (s%u(1))
u => s%u(1)
allocate (u%design, u%model)
n = 112
allocate (u%model%bunch_params(0:n), u%design%bunch_params(0:n))
u%design%bunch_params%n_live_particle = [(i, i = 0, n)]
u%model = u%design
u%model = u%design ! The double assignment was the cause of the ICE
if (.not. allocated (u%model%bunch_params)) call abort
if (any (u%model%bunch_params%n_live_particle .ne. [(i, i = 0, n)])) call abort
Deallocate (u%model%bunch_params, u%design%bunch_params)
deallocate (u%design, u%model)
deallocate (s%u)
end program
| gpl-2.0 |
marshallward/mom | src/shared/horiz_interp/horiz_interp_bicubic.F90 | 6 | 29322 | module horiz_interp_bicubic_mod
use mpp_mod, only: mpp_error, FATAL, stdout, mpp_pe, mpp_root_pe
use fms_mod, only: write_version_number
use horiz_interp_type_mod, only: horiz_interp_type
use constants_mod, only: PI
implicit none
! This module delivers methods for bicubic interpolation from a
! coarse regular grid on a fine regular grid.
! Subroutines
!
! bcuint
! bcucof
!
! are methods taken from
!
! W. H. Press, S. A. Teukolski, W. T. Vetterling and B. P. Flannery,
! Numerical Recipies in FORTRAN, The Art of Scientific Computing.
! Cambridge University Press, 1992
!
! written by
! martin.schmidt@io-warnemuende.de (2004)
! revied by
! martin.schmidt@io-warnemuende.de (2004)
!
! Version 1.0.0.2005-07-06
! The module is thought to interact with MOM-4.
! Alle benotigten Felder werden extern von MOM verwaltet, da sie
! nicht fur alle interpolierten Daten die gleiche Dimension haben mussen.
private
public :: horiz_interp_bicubic, horiz_interp_bicubic_new, horiz_interp_bicubic_del, fill_xy
public :: horiz_interp_bicubic_init
interface horiz_interp_bicubic_new
module procedure horiz_interp_bicubic_new_1d
module procedure horiz_interp_bicubic_new_1d_s
end interface
character(len=128) :: version="$Id$"
character(len=128) :: tagname = '$Name$'
logical :: module_is_initialized = .FALSE.
integer :: verbose_bicubic = 0
! Grid variables
! xc, yc : co-ordinates of the coarse grid
! xf, yf : co-ordinates of the fine grid
! fc : variable to be interpolated at the coarse grid
! dfc_x : x-derivative of fc at the coarse grid
! dfc_y : y-derivative of fc at the coarse grid
! dfc_xy : x-y-derivative of fc at the coarse grid
! ff : variable to be interpolated at the fine grid
! dff_x : x-derivative of fc at the fine grid
! dff_y : y-derivative of fc at the fine grid
! dff_xy : x-y-derivative of fc at the fine grid
logical :: initialized_bicubic = .false.
real, save :: missing = -1e33
real :: tpi
interface fill_xy
module procedure fill_xy
end interface
contains
!#######################################################################
! <SUBROUTINE NAME="horiz_interp_bicubic_init">
! <OVERVIEW>
! writes version number and tag name to logfile.out
! </OVERVIEW>
! <DESCRIPTION>
! writes version number and tag name to logfile.out
! </DESCRIPTION>
subroutine horiz_interp_bicubic_init
if(module_is_initialized) return
call write_version_number (version, tagname)
module_is_initialized = .true.
tpi = 2.0*PI
end subroutine horiz_interp_bicubic_init
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="horiz_interp_bicubic_new">
! <OVERVIEW>
! Initialization routine.
! </OVERVIEW>
! <DESCRIPTION>
! Allocates space and initializes a derived-type variable
! that contains pre-computed interpolation indices and weights.
! </DESCRIPTION>
! <TEMPLATE>
! call horiz_interp_bicubic_new ( Interp, lon_in, lat_in, lon_out, lat_out, verbose_bicubic, src_modulo )
! </TEMPLATE>
!
! <IN NAME="lon_in" TYPE="real, dimension(:,:)" UNITS="radians">
! Longitude (in radians) for source data grid.
! </IN>
! <IN NAME="lat_in" TYPE="real, dimension(:,:)" UNITS="radians">
! Latitude (in radians) for source data grid.
! </IN>
! <IN NAME="lon_out" TYPE="real, dimension(:,:)" UNITS="radians" >
! Longitude (in radians) for source data grid.
! </IN>
! <IN NAME="lat_out" TYPE="real, dimension(:,:)" UNITS="radians" >
! Latitude (in radians) for source data grid.
! </IN>
! <IN NAME="src_modulo" TYPE="logical, optional">
! logical variable to indicate if the boundary condition along zonal boundary
! is cyclic or not. When true, the zonal boundary condition is cyclic.
! </IN>
! <IN NAME="verbose_bicubic" TYPE="integer, optional" >
! flag for the amount of print output.
! </IN>
! <INOUT NAME="Interp" TYPE="type(horiz_interp_type)" >
! A derived-type variable containing indices and weights used for subsequent
! interpolations. To reinitialize this variable for a different grid-to-grid
! interpolation you must first use the "horiz_interp_bicubic_del" interface.
! </INOUT>
subroutine horiz_interp_bicubic_new_1d_s ( Interp, lon_in, lat_in, lon_out, lat_out, &
verbose, src_modulo )
!-----------------------------------------------------------------------
type(horiz_interp_type), intent(inout) :: Interp
real, intent(in), dimension(:) :: lon_in , lat_in
real, intent(in), dimension(:,:) :: lon_out, lat_out
integer, intent(in), optional :: verbose
logical, intent(in), optional :: src_modulo
integer :: i, j, ip1, im1, jp1, jm1
logical :: src_is_modulo
integer :: nlon_in, nlat_in, nlon_out, nlat_out
integer :: jcl, jcu, icl, icu, jj
real :: xz, yz
integer :: unit
if(present(verbose)) verbose_bicubic = verbose
src_is_modulo = .false.
if (present(src_modulo)) src_is_modulo = src_modulo
if(size(lon_out,1) /= size(lat_out,1) .or. size(lon_out,2) /= size(lat_out,2) ) &
call mpp_error(FATAL,'horiz_interp_bilinear_mod: when using bilinear ' // &
'interplation, the output grids should be geographical grids')
!--- get the grid size
nlon_in = size(lon_in) ; nlat_in = size(lat_in)
nlon_out = size(lon_out,1); nlat_out = size(lat_out,2)
Interp%nlon_src = nlon_in; Interp%nlat_src = nlat_in
Interp%nlon_dst = nlon_out; Interp%nlat_dst = nlat_out
! use wti(:,:,1) for x-derivative, wti(:,:,2) for y-derivative, wti(:,:,3) for xy-derivative
allocate ( Interp%wti (nlon_in, nlat_in, 3) )
allocate ( Interp%lon_in (nlon_in) )
allocate ( Interp%lat_in (nlat_in) )
allocate ( Interp%rat_x (nlon_out, nlat_out) )
allocate ( Interp%rat_y (nlon_out, nlat_out) )
allocate ( Interp%i_lon (nlon_out, nlat_out, 2) )
allocate ( Interp%j_lat (nlon_out, nlat_out, 2) )
Interp%lon_in = lon_in
Interp%lat_in = lat_in
if ( verbose_bicubic > 0 ) then
unit = stdout()
write (unit,'(/,"Initialising bicubic interpolation, interface horiz_interp_bicubic_new_1d_s")')
write (unit,'(/," Longitude of coarse grid points (radian): xc(i) i=1, ",i4)') Interp%nlon_src
write (unit,'(1x,10f10.4)') (Interp%lon_in(jj),jj=1,Interp%nlon_src)
write (unit,'(/," Latitude of coarse grid points (radian): yc(j) j=1, ",i4)') Interp%nlat_src
write (unit,'(1x,10f10.4)') (Interp%lat_in(jj),jj=1,Interp%nlat_src)
do i=1, Interp%nlat_dst
write (unit,*)
write (unit,'(/," Longitude of fine grid points (radian): xf(i) i=1, ",i4)') Interp%nlat_dst
write (unit,'(1x,10f10.4)') (lon_out(jj,i),jj=1,Interp%nlon_dst)
enddo
do i=1, Interp%nlon_dst
write (unit,*)
write (unit,'(/," Latitude of fine grid points (radian): yf(j) j=1, ",i4)') Interp%nlon_dst
write (unit,'(1x,10f10.4)') (lat_out(i,jj),jj=1,Interp%nlat_dst)
enddo
endif
!---------------------------------------------------------------------------
! Find the x-derivative. Use central differences and forward or
! backward steps at the boundaries
do j=1,nlat_in
do i=1,nlon_in
ip1=min(i+1,nlon_in)
im1=max(i-1,1)
Interp%wti(i,j,1) = 1./(Interp%lon_in(ip1)-Interp%lon_in(im1))
enddo
enddo
!---------------------------------------------------------------------------
! Find the y-derivative. Use central differences and forward or
! backward steps at the boundaries
do j=1,nlat_in
jp1=min(j+1,nlat_in)
jm1=max(j-1,1)
do i=1,nlon_in
Interp%wti(i,j,2) = 1./(Interp%lat_in(jp1)-Interp%lat_in(jm1))
enddo
enddo
!---------------------------------------------------------------------------
! Find the xy-derivative. Use central differences and forward or
! backward steps at the boundaries
do j=1,nlat_in
jp1=min(j+1,nlat_in)
jm1=max(j-1,1)
do i=1,nlon_in
ip1=min(i+1,nlon_in)
im1=max(i-1,1)
Interp%wti(i,j,3) = 1./((Interp%lon_in(ip1)-Interp%lon_in(im1))*(Interp%lat_in(jp1)-Interp%lat_in(jm1)))
enddo
enddo
!---------------------------------------------------------------------------
! Now for each point at the dest-grid find the boundary points of
! the source grid
do j=1, nlat_out
do i=1,nlon_out
yz = lat_out(i,j)
xz = lon_out(i,j)
jcl = 0
jcu = 0
if( yz .le. Interp%lat_in(1) ) then
jcl = 1
jcu = 1
else if( yz .ge. Interp%lat_in(nlat_in) ) then
jcl = nlat_in
jcu = nlat_in
else
jcl = indl(Interp%lat_in, yz)
jcu = indu(Interp%lat_in, yz)
endif
icl = 0
icu = 0
!--- cyclic condition, do we need to use do while
if( xz .gt. Interp%lon_in(nlon_in) ) xz = xz - tpi
if( xz .le. Interp%lon_in(1) ) xz = xz + tpi
if( xz .ge. Interp%lon_in(nlon_in) ) then
icl = nlon_in
icu = 1
Interp%rat_x(i,j) = (xz - Interp%lon_in(icl))/(Interp%lon_in(icu) - Interp%lon_in(icl) + tpi)
else
icl = indl(Interp%lon_in, xz)
icu = indu(Interp%lon_in, xz)
Interp%rat_x(i,j) = (xz - Interp%lon_in(icl))/(Interp%lon_in(icu) - Interp%lon_in(icl))
endif
Interp%j_lat(i,j,1) = jcl
Interp%j_lat(i,j,2) = jcu
Interp%i_lon(i,j,1) = icl
Interp%i_lon(i,j,2) = icu
if(jcl == jcu) then
Interp%rat_y(i,j) = 0.0
else
Interp%rat_y(i,j) = (yz - Interp%lat_in(jcl))/(Interp%lat_in(jcu) - Interp%lat_in(jcl))
endif
! if(yz.gt.Interp%lat_in(jcu)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d_s: yf < ycl, no valid boundary point')
! if(yz.lt.Interp%lat_in(jcl)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d_s: yf > ycu, no valid boundary point')
! if(xz.gt.Interp%lon_in(icu)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d_s: xf < xcl, no valid boundary point')
! if(xz.lt.Interp%lon_in(icl)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d_s: xf > xcu, no valid boundary point')
enddo
enddo
end subroutine horiz_interp_bicubic_new_1d_s
! </SUBROUTINE>
subroutine horiz_interp_bicubic_new_1d ( Interp, lon_in, lat_in, lon_out, lat_out, &
verbose, src_modulo )
!-----------------------------------------------------------------------
type(horiz_interp_type), intent(inout) :: Interp
real, intent(in), dimension(:) :: lon_in , lat_in
real, intent(in), dimension(:) :: lon_out, lat_out
integer, intent(in), optional :: verbose
logical, intent(in), optional :: src_modulo
integer :: i, j, ip1, im1, jp1, jm1
logical :: src_is_modulo
integer :: nlon_in, nlat_in, nlon_out, nlat_out
integer :: jcl, jcu, icl, icu, jj
real :: xz, yz
integer :: unit
if(present(verbose)) verbose_bicubic = verbose
src_is_modulo = .false.
if (present(src_modulo)) src_is_modulo = src_modulo
!--- get the grid size
nlon_in = size(lon_in) ; nlat_in = size(lat_in)
nlon_out = size(lon_out); nlat_out = size(lat_out)
Interp%nlon_src = nlon_in; Interp%nlat_src = nlat_in
Interp%nlon_dst = nlon_out; Interp%nlat_dst = nlat_out
allocate ( Interp%wti (nlon_in, nlat_in, 3) )
allocate ( Interp%lon_in (nlon_in) )
allocate ( Interp%lat_in (nlat_in) )
allocate ( Interp%rat_x (nlon_out, nlat_out) )
allocate ( Interp%rat_y (nlon_out, nlat_out) )
allocate ( Interp%i_lon (nlon_out, nlat_out, 2) )
allocate ( Interp%j_lat (nlon_out, nlat_out, 2) )
Interp%lon_in = lon_in
Interp%lat_in = lat_in
if ( verbose_bicubic > 0 ) then
unit = stdout()
write (unit,'(/,"Initialising bicubic interpolation, interface horiz_interp_bicubic_new_1d")')
write (unit,'(/," Longitude of coarse grid points (radian): xc(i) i=1, ",i4)') Interp%nlon_src
write (unit,'(1x,10f10.4)') (Interp%lon_in(jj),jj=1,Interp%nlon_src)
write (unit,'(/," Latitude of coarse grid points (radian): yc(j) j=1, ",i4)') Interp%nlat_src
write (unit,'(1x,10f10.4)') (Interp%lat_in(jj),jj=1,Interp%nlat_src)
write (unit,*)
write (unit,'(/," Longitude of fine grid points (radian): xf(i) i=1, ",i4)') Interp%nlat_dst
write (unit,'(1x,10f10.4)') (lon_out(jj),jj=1,Interp%nlon_dst)
write (unit,'(/," Latitude of fine grid points (radian): yf(j) j=1, ",i4)') Interp%nlon_dst
write (unit,'(1x,10f10.4)') (lat_out(jj),jj=1,Interp%nlat_dst)
endif
!---------------------------------------------------------------------------
! Find the x-derivative. Use central differences and forward or
! backward steps at the boundaries
do j=1,nlat_in
do i=1,nlon_in
ip1=min(i+1,nlon_in)
im1=max(i-1,1)
Interp%wti(i,j,1) = 1./(lon_in(ip1)-lon_in(im1))
enddo
enddo
!---------------------------------------------------------------------------
! Find the y-derivative. Use central differences and forward or
! backward steps at the boundaries
do j=1,nlat_in
jp1=min(j+1,nlat_in)
jm1=max(j-1,1)
do i=1,nlon_in
Interp%wti(i,j,2) = 1./(lat_in(jp1)-lat_in(jm1))
enddo
enddo
!---------------------------------------------------------------------------
! Find the xy-derivative. Use central differences and forward or
! backward steps at the boundaries
do j=1,nlat_in
jp1=min(j+1,nlat_in)
jm1=max(j-1,1)
do i=1,nlon_in
ip1=min(i+1,nlon_in)
im1=max(i-1,1)
Interp%wti(i,j,3) = 1./((lon_in(ip1)-lon_in(im1))*(lat_in(jp1)-lat_in(jm1)))
enddo
enddo
!---------------------------------------------------------------------------
! Now for each point at the dest-grid find the boundary points of
! the source grid
do j=1, nlat_out
yz = lat_out(j)
jcl = 0
jcu = 0
if( yz .le. lat_in(1) ) then
jcl = 1
jcu = 1
else if( yz .ge. lat_in(nlat_in) ) then
jcl = nlat_in
jcu = nlat_in
else
jcl = indl(lat_in, yz)
jcu = indu(lat_in, yz)
endif
do i=1,nlon_out
xz = lon_out(i)
icl = 0
icu = 0
!--- cyclic condition, do we need to use do while
if( xz .gt. lon_in(nlon_in) ) xz = xz - tpi
if( xz .le. lon_in(1) ) xz = xz + tpi
if( xz .ge. lon_in(nlon_in) ) then
icl = nlon_in
icu = 1
Interp%rat_x(i,j) = (xz - Interp%lon_in(icl))/(Interp%lon_in(icu) - Interp%lon_in(icl) + tpi)
else
icl = indl(lon_in, xz)
icu = indu(lon_in, xz)
Interp%rat_x(i,j) = (xz - Interp%lon_in(icl))/(Interp%lon_in(icu) - Interp%lon_in(icl))
endif
icl = indl(lon_in, xz)
icu = indu(lon_in, xz)
Interp%j_lat(i,j,1) = jcl
Interp%j_lat(i,j,2) = jcu
Interp%i_lon(i,j,1) = icl
Interp%i_lon(i,j,2) = icu
if(jcl == jcu) then
Interp%rat_y(i,j) = 0.0
else
Interp%rat_y(i,j) = (yz - Interp%lat_in(jcl))/(Interp%lat_in(jcu) - Interp%lat_in(jcl))
endif
! if(yz.gt.lat_in(jcu)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d: yf < ycl, no valid boundary point')
! if(yz.lt.lat_in(jcl)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d: yf > ycu, no valid boundary point')
! if(xz.gt.lon_in(icu)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d: xf < xcl, no valid boundary point')
! if(xz.lt.lon_in(icl)) call mpp_error(FATAL, ' horiz_interp_bicubic_new_1d: xf > xcu, no valid boundary point')
enddo
enddo
end subroutine horiz_interp_bicubic_new_1d
subroutine horiz_interp_bicubic( Interp, data_in, data_out, verbose, mask_in, mask_out, missing_value, missing_permit)
type (horiz_interp_type), intent(in) :: Interp
real, intent(in), dimension(:,:) :: data_in
real, intent(out), dimension(:,:) :: data_out
integer, intent(in), optional :: verbose
real, intent(in), dimension(:,:), optional :: mask_in
real, intent(out), dimension(:,:), optional :: mask_out
real, intent(in), optional :: missing_value
integer, intent(in), optional :: missing_permit
real :: yz, ycu, ycl
real :: xz, xcu, xcl
real :: val, val1, val2
real, dimension(4) :: y, y1, y2, y12
integer :: icl, icu, jcl, jcu
integer :: iclp1, icup1, jclp1, jcup1
integer :: iclm1, icum1, jclm1, jcum1
integer :: i,j
if ( present(verbose) ) verbose_bicubic = verbose
! fill_in = .false.
! if ( present(fill) ) fill_in = fill
! use dfc_x and dfc_y as workspace
! if ( fill_in ) call fill_xy(fc(ics:ice,jcs:jce), ics, ice, jcs, jce, maxpass=2)
! where ( data_in .le. missing ) data_in(:,:) = 0.
!!
do j=1, Interp%nlat_dst
do i=1, Interp%nlon_dst
yz = Interp%rat_y(i,j)
xz = Interp%rat_x(i,j)
jcl = Interp%j_lat(i,j,1)
jcu = Interp%j_lat(i,j,2)
icl = Interp%i_lon(i,j,1)
icu = Interp%i_lon(i,j,2)
if( icl > icu ) then
iclp1 = icu
icum1 = icl
xcl = Interp%lon_in(icl)
xcu = Interp%lon_in(icu)+tpi
else
iclp1 = min(icl+1,Interp%nlon_src)
icum1 = max(icu-1,1)
xcl = Interp%lon_in(icl)
xcu = Interp%lon_in(icu)
endif
iclm1 = max(icl-1,1)
icup1 = min(icu+1,Interp%nlon_src)
jclp1 = min(jcl+1,Interp%nlat_src)
jclm1 = max(jcl-1,1)
jcup1 = min(jcu+1,Interp%nlat_src)
jcum1 = max(jcu-1,1)
ycl = Interp%lat_in(jcl)
ycu = Interp%lat_in(jcu)
! xcl = Interp%lon_in(icl)
! xcu = Interp%lon_in(icu)
y(1) = data_in(icl,jcl)
y(2) = data_in(icu,jcl)
y(3) = data_in(icu,jcu)
y(4) = data_in(icl,jcu)
y1(1) = ( data_in(iclp1,jcl) - data_in(iclm1,jcl) ) * Interp%wti(icl,jcl,1)
y1(2) = ( data_in(icup1,jcl) - data_in(icum1,jcl) ) * Interp%wti(icu,jcl,1)
y1(3) = ( data_in(icup1,jcu) - data_in(icum1,jcu) ) * Interp%wti(icu,jcu,1)
y1(4) = ( data_in(iclp1,jcu) - data_in(iclm1,jcu) ) * Interp%wti(icl,jcu,1)
y2(1) = ( data_in(icl,jclp1) - data_in(icl,jclm1) ) * Interp%wti(icl,jcl,2)
y2(2) = ( data_in(icu,jclp1) - data_in(icu,jclm1) ) * Interp%wti(icu,jcl,2)
y2(3) = ( data_in(icu,jcup1) - data_in(icu,jcum1) ) * Interp%wti(icu,jcu,2)
y2(4) = ( data_in(icl,jcup1) - data_in(icl,jcum1) ) * Interp%wti(icl,jcu,2)
y12(1)= ( data_in(iclp1,jclp1) + data_in(iclm1,jclm1) - data_in(iclm1,jclp1) &
- data_in(iclp1,jclm1) ) * Interp%wti(icl,jcl,3)
y12(2)= ( data_in(icup1,jclp1) + data_in(icum1,jclm1) - data_in(icum1,jclp1) &
- data_in(icup1,jclm1) ) * Interp%wti(icu,jcl,3)
y12(3)= ( data_in(icup1,jcup1) + data_in(icum1,jcum1) - data_in(icum1,jcup1) &
- data_in(icup1,jcum1) ) * Interp%wti(icu,jcu,3)
y12(4)= ( data_in(iclp1,jcup1) + data_in(iclm1,jcum1) - data_in(iclm1,jcup1) &
- data_in(iclp1,jcum1) ) * Interp%wti(icl,jcu,3)
call bcuint(y,y1,y2,y12,xcl,xcu,ycl,ycu,xz,yz,val,val1,val2)
data_out (i,j) = val
if(present(mask_out)) mask_out(i,j) = 1.
!! dff_x(i,j) = val1
!! dff_y(i,j) = val2
enddo
enddo
return
end subroutine horiz_interp_bicubic
!---------------------------------------------------------------------------
subroutine bcuint(y,y1,y2,y12,x1l,x1u,x2l,x2u,t,u,ansy,ansy1,ansy2)
real ansy,ansy1,ansy2,x1l,x1u,x2l,x2u,y(4),y1(4),y12(4),y2(4)
! uses bcucof
integer i
real t,u,c(4,4)
call bcucof(y,y1,y2,y12,x1u-x1l,x2u-x2l,c)
ansy=0.
ansy2=0.
ansy1=0.
do i=4,1,-1
ansy=t*ansy+((c(i,4)*u+c(i,3))*u+c(i,2))*u+c(i,1)
! ansy2=t*ansy2+(3.*c(i,4)*u+2.*c(i,3))*u+c(i,2)
! ansy1=u*ansy1+(3.*c(4,i)*t+2.*c(3,i))*t+c(2,i)
enddo
! ansy1=ansy1/(x1u-x1l) ! could be used for accuracy checks
! ansy2=ansy2/(x2u-x2l) ! could be used for accuracy checks
return
! (c) copr. 1986-92 numerical recipes software -3#(-)f.
end subroutine bcuint
!---------------------------------------------------------------------------
subroutine bcucof(y,y1,y2,y12,d1,d2,c)
real d1,d2,c(4,4),y(4),y1(4),y12(4),y2(4)
integer i,j,k,l
real d1d2,xx,cl(16),wt(16,16),x(16)
save wt
data wt/1., 0., -3., 2., 4*0., -3., 0., 9., -6., 2., 0., -6., 4., 8*0., &
3., 0., -9., 6., -2., 0., 6., -4., 10*0., 9., -6., 2*0., -6., &
4., 2*0., 3., -2., 6*0., -9., 6., 2*0., 6., -4., 4*0., 1., 0., &
-3., 2., -2., 0., 6., -4., 1., 0., -3., 2., 8*0., -1., 0., 3., &
-2., 1., 0., -3., 2., 10*0., -3., 2., 2*0., 3., -2., 6*0., 3., &
-2., 2*0., -6., 4., 2*0., 3., -2., 0., 1., -2., 1., 5*0., -3., &
6., -3., 0., 2., -4., 2., 9*0., 3., -6., 3., 0., -2., 4., -2., &
10*0., -3., 3., 2*0., 2., -2., 2*0., -1., 1., 6*0., 3., -3., &
2*0., -2., 2., 5*0., 1., -2., 1., 0., -2., 4., -2., 0., 1., -2., &
1., 9*0., -1., 2., -1., 0., 1., -2., 1., 10*0., 1., -1., 2*0., &
-1., 1., 6*0., -1., 1., 2*0., 2., -2., 2*0., -1., 1./
d1d2=d1*d2
do i=1,4
x(i)=y(i)
x(i+4)=y1(i)*d1
x(i+8)=y2(i)*d2
x(i+12)=y12(i)*d1d2
enddo
do i=1,16
xx=0.
do k=1,16
xx=xx+wt(i,k)*x(k)
enddo
cl(i)=xx
enddo
l=0
do i=1,4
do j=1,4
l=l+1
c(i,j)=cl(l)
enddo
enddo
return
! (c) copr. 1986-92 numerical recipes software -3#(-)f.
end subroutine bcucof
!-----------------------------------------------------------------------
function indl(xc, xf)
! find the lower neighbour of xf in field xc, return is the index
real, intent(in) :: xc(1:)
real, intent(in) :: xf
integer :: indl
integer :: ii
indl = 1
do ii=1, size(xc)
if(xc(ii).gt.xf) return
indl = ii
enddo
call mpp_error(FATAL,'Error in indl')
return
end function indl
!-----------------------------------------------------------------------
function indu(xc, xf)
! find the upper neighbour of xf in field xc, return is the index
real, intent(in) :: xc(1:)
real, intent(in) :: xf
integer :: indu
integer :: ii
do ii=1, size(xc)
indu = ii
if(xc(ii).gt.xf) return
enddo
call mpp_error(FATAL,'Error in indu')
return
end function indu
!-----------------------------------------------------------------------
subroutine fill_xy(fi, ics, ice, jcs, jce, mask, maxpass)
integer, intent(in) :: ics,ice,jcs,jce
real, intent(inout) :: fi(ics:ice,jcs:jce)
real, intent(in), optional :: mask(ics:ice,jcs:jce)
integer, intent(in) :: maxpass
real :: work_old(ics:ice,jcs:jce)
real :: work_new(ics:ice,jcs:jce)
logical :: ready
real :: blank = -1.e30
real :: tavr
integer :: ipass = 0
integer :: inl, inr, jnl, jnu, i, j, is, js, iavr
ready = .false.
work_new(:,:) = fi(:,:)
work_old(:,:) = work_new(:,:)
ipass = 0
if ( present(mask) ) then
do while (.not.ready)
ipass = ipass+1
ready = .true.
do j=jcs, jce
do i=ics, ice
if (work_old(i,j).le.blank) then
tavr=0.
iavr=0
inl = max(i-1,ics)
inr = min(i+1,ice)
jnl = max(j-1,jcs)
jnu = min(j+1,jce)
do js=jnl,jnu
do is=inl,inr
if (work_old(is,js) .ne. blank .and. mask(is,js).ne.0.) then
tavr = tavr + work_old(is,js)
iavr = iavr+1
endif
enddo
enddo
if (iavr.gt.0) then
if (iavr.eq.1) then
! spreading is not allowed if the only valid neighbor is a corner point
! otherwise an ill posed cellular automaton is established leading to
! a spreading of constant values in diagonal direction
! if all corner points are blanked the valid neighbor must be a direct one
! and spreading is allowed
if (work_old(inl,jnu).eq.blank.and.&
work_old(inr,jnu).eq.blank.and.&
work_old(inr,jnl).eq.blank.and.&
work_old(inl,jnl).eq.blank) then
work_new(i,j)=tavr/iavr
ready = .false.
endif
else
work_new(i,j)=tavr/iavr
ready = .false.
endif
endif
endif
enddo ! j
enddo ! i
! save changes made during this pass to work_old
work_old(:,:)=work_new(:,:)
if(ipass.eq.maxpass) ready=.true.
enddo !while (.not.ready)
fi(:,:) = work_new(:,:)
else
do while (.not.ready)
ipass = ipass+1
ready = .true.
do j=jcs, jce
do i=ics, ice
if (work_old(i,j).le.blank) then
tavr=0.
iavr=0
inl = max(i-1,ics)
inr = min(i+1,ice)
jnl = max(j-1,jcs)
jnu = min(j+1,jce)
do is=inl,inr
do js=jnl,jnu
if (work_old(is,js).gt.blank) then
tavr = tavr + work_old(is,js)
iavr = iavr+1
endif
enddo
enddo
if (iavr.gt.0) then
if (iavr.eq.1) then
! spreading is not allowed if the only valid neighbor is a corner point
! otherwise an ill posed cellular automaton is established leading to
! a spreading of constant values in diagonal direction
! if all corner points are blanked the valid neighbor must be a direct one
! and spreading is allowed
if (work_old(inl,jnu).le.blank.and. &
work_old(inr,jnu).le.blank.and. &
work_old(inr,jnl).le.blank.and. &
work_old(inl,jnl).le.blank) then
work_new(i,j)=tavr/iavr
ready = .false.
endif
else
work_new(i,j)=tavr/iavr
ready = .false.
endif
endif
endif
enddo ! j
enddo ! i
! save changes made during this pass to work_old
work_old(:,:)=work_new(:,:)
if(ipass.eq.maxpass) ready=.true.
enddo !while (.not.ready)
fi(:,:) = work_new(:,:)
endif
return
end subroutine fill_xy
subroutine horiz_interp_bicubic_del( Interp )
type (horiz_interp_type), intent(inout) :: Interp
if(associated(Interp%rat_x)) deallocate ( Interp%rat_x )
if(associated(Interp%rat_y)) deallocate ( Interp%rat_y )
if(associated(Interp%lon_in)) deallocate ( Interp%lon_in )
if(associated(Interp%lat_in)) deallocate ( Interp%lat_in )
if(associated(Interp%i_lon)) deallocate ( Interp%i_lon )
if(associated(Interp%j_lat)) deallocate ( Interp%j_lat )
if(associated(Interp%wti)) deallocate ( Interp%wti )
end subroutine horiz_interp_bicubic_del
end module horiz_interp_bicubic_mod
| gpl-2.0 |
marshallward/mom | src/ocean_shared/generic_tracers/generic_miniBLING.F90 | 9 | 216944 | !----------------------------------------------------------------
! <CONTACT EMAIL="Eric.Galbraith@mcgill.ca"> Eric D. Galbraith
! </CONTACT>
!
! <CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> John P. Dunne
! </CONTACT>
!
! <CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> Anand Gnanandesikan
! </CONTACT>
!
! <CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> Niki Zadeh
! </CONTACT>
!
! <REVIEWER EMAIL="GFDL.Climate.Model.Info@noaa.gov"> Rick Slater
! </REVIEWER>
!
! <OVERVIEW>
! This module contains the generic version of miniBLING.
! It is designed so that both GFDL Ocean models, GOLD and MOM, can use it.
!
! WARNING: although the core components of the model (PO4, Fed, DOP, O2)
! have been reasonably well tested, the other components should be viewed as
! developmental at this point. There may still be some bugs.
!
! Also, the growth parameters have been tuned to produce a reasonable simulation
! of PO4 and chl in a 3-degree CORE-forced version of MOM4p1. It is unlikely that
! these parameter choices will produce satisfactory simulations in other physical
! model configurations, and may need to be adjusted.
! </OVERVIEW>
!
!<DESCRIPTION>
! Biogeochemistry with Light, Iron, Nutrient and Gas version zero (BLINGv0)
! includes an implicit ecological model of growth limitation by light,
! temperature, phosphate and iron, along with dissolved organic
! phosphorus and O2 pools.
! Food web processing in the euphotic zone and remineralization/
! dissolution through the ocean interior are handled as in Dunne et al.
! (2005). O2 equilibria and gas exchange follow OCMIP2 protocols.
! Additional functionality comes from an optional carbon cycle that is
! non-interactive, i.e. does not change the core miniBLING behaviour, as
! well as tracers for radiocarbon (14c), a decomposition of carbon
! components by gas exchange and remineralization (carbon_pre), a
! decomposition of oxygen as preformed and total (o2_pre), saturation and
! consumed, and a decomposition of phosphate as preformed and remineralized
! (po4_pre).
!</DESCRIPTION>
!
! <INFO>
! <REFERENCE>
! This model is available for public use.
! The current version is BLINGv0. The version number refers to the core
! model behaviour; additional tracers exist in different iterations of the
! module. In publications it should be referenced as:
! Galbraith, E.D., Gnanadesikan, A., Dunne, J. and Hiscock, M. 2010.
! Regional impacts of iron-light colimitation in a global
! biogeochemical model. Biogeosciences , 7, 1043-1064.
!
! All parameter values are as described in this paper.
! Note that this reference is only for the core model components, and
! does not include any of the additional functionalities, which remain
! undocumented. Please contact Eric Galbraith (eric.galbraith@mcgill.ca)
! for more information.
! </REFERENCE>
!
! <DEVELOPER_NOTES>
! This code was originally developed based on the template of Perth generic TOPAZ code.
! </DEVELOPER_NOTES>
! </INFO>
!
!<NAMELIST NAME="generic_miniBLING_nml">
!
! <DATA NAME="do_14c" TYPE="logical">
! If true, then simulate radiocarbon. Includes 2 prognostic tracers, DI14C
! and DO14C. Requires that do_carbon = .true.
! </DATA>
!
! <DATA NAME="do_carbon" TYPE="logical">
! If true, then simulate the carbon cycle based on strict stoichiometry
! of C:P. Includes 1 prognostic tracer, DIC.
! </DATA>
!
!</NAMELIST>
!
!----------------------------------------------------------------
#include <fms_platform.h>
module generic_miniBLING_mod
use coupler_types_mod, only: coupler_2d_bc_type
use field_manager_mod, only: fm_string_len, fm_path_name_len, fm_field_name_len
use mpp_mod, only: mpp_error, NOTE, FATAL
use mpp_mod, only: stdout
use time_manager_mod, only: time_type
use diag_manager_mod, only: register_diag_field, send_data
use constants_mod, only: WTMCO2, WTMO2
use data_override_mod, only: data_override
use g_tracer_utils, only : g_tracer_type,g_tracer_start_param_list,g_tracer_end_param_list
use g_tracer_utils, only : g_tracer_add,g_tracer_add_param, g_tracer_set_files
use g_tracer_utils, only : g_tracer_set_values,g_tracer_get_pointer
use g_tracer_utils, only : g_tracer_get_common
use g_tracer_utils, only : g_tracer_coupler_set,g_tracer_coupler_get
use g_tracer_utils, only : g_tracer_get_values, g_tracer_column_int, g_tracer_flux_at_depth
use FMS_ocmip2_co2calc_mod, only : FMS_ocmip2_co2calc, CO2_dope_vector
implicit none ; private
character(len=fm_string_len), parameter :: mod_name = 'generic_miniBLING'
character(len=fm_string_len), parameter :: package_name = 'generic_minibling'
public do_generic_miniBLING
public generic_miniBLING_register
public generic_miniBLING_init
public generic_miniBLING_register_diag
public generic_miniBLING_update_from_coupler
public generic_miniBLING_diag
public generic_miniBLING_update_from_source
public generic_miniBLING_update_from_bottom
public generic_miniBLING_set_boundary_values
public generic_miniBLING_end
!The following logical for using this module is overwritten
! generic_tracer_nml namelist
logical, save :: do_generic_miniBLING = .false.
logical, save :: module_is_initialized = .false.
real, parameter :: sperd = 24.0 * 3600.0
real, parameter :: spery = 365.25 * sperd
real, parameter :: epsln=1.0e-30
!
!The following two types contain all the parameters and arrays used in this module.
type generic_miniBLING_type
character(len=fm_string_len) :: name = '_'
character(len=fm_field_name_len) :: suffix = ' '
character(len=fm_field_name_len) :: long_suffix = ' '
logical :: prevent_neg_o2 = .true.
! Turn on additional complexity. Most relevant diagnostic variables and all
! tracers are not activated unless the appropriate switch is set to true.
logical :: do_14c = .true. ! Requires do_carbon = .true.
logical :: do_carbon = .true.
real :: min_frac_pop = 0.0 ! Set to 1 to turn off recycling
character(len=fm_string_len) :: alk_scheme = 'normal' ! Specify the scheme to use for calculating alkalinity
character(len=fm_string_len) :: biomass_type = 'single' ! Specify the scheme to use for calculating biomass
real :: alk_slope = 32.0e-06 ! Slope of alk:salt equation
real :: alk_intercept = 1200.0e-06 ! Intercept of alk:salt equation
real :: alpha_photo ! Quantum yield under low light
real :: c_2_p ! Carbon to Phosphorus ratio
real :: chl_min ! Minimum chl concentration allowed (for numerical stability)
logical :: fe_is_prognostic = .false. ! Set whether Fed is prognostic or diagnostic
logical :: fe_is_diagnostic = .false. ! Set whether Fed is diagnostic or data
real :: fe_restoring = 10.0 ! Restoring time scale, in days, if Fed is diagnostic
real :: fe_coastal = 2.0e-09 ! Coastal iron concentration, in mol/kg, if Fed is diagnostic
real :: fe_coastal_depth = 200.0 ! Coastal depth, in meters, if Fed is diagnostic
real :: fe_2_p_max ! Iron to Phosphate uptake ratio scaling
real :: def_fe_min = 0.0 ! Minimum for iron deficiency
real :: fe_2_p_sed ! Iron to Phosphorus ratio in sediments
real :: felig_bkg ! Iron ligand concentration
real :: gamma_biomass ! Biomass adjustment timescale
real :: gamma_irr_mem ! Photoadaptation timescale
real :: gamma_pop ! Patriculate Organic Phosphorus decay
real :: half_life_14c ! Radiocarbon half-life
real :: k_fe_2_p ! Fe:P half-saturation constant
real :: k_fe_uptake ! Iron half-saturation concentration
real :: k_o2 ! Oxygen half-saturation concentration
real :: k_po4 ! Phosphate half-saturation concentration
real :: k_po4_recycle ! Phosphate half-saturation concentration
real :: kappa_eppley ! Temperature dependence
real :: kappa_remin ! Temperature dependence for particle fractionation
real :: kfe_inorg ! Iron scavenging, 2nd order
real :: kfe_eq_lig_max ! Maximum light-dependent iron ligand stability constant
real :: kfe_eq_lig_min ! Minimum light-dependent iron ligand stability constant
real :: kfe_eq_lig_irr ! Irradiance scaling for iron ligand stability constant
real :: kfe_eq_lig_femin ! Low-iron threshold for ligand stability constant
real :: kfe_org ! Iron scavenging, 1st order
real :: lambda0 ! Total mortality rate constant
real :: lambda_14c ! Radiocarbon decay rate
real :: mass_2_p ! Organic matter mass to Phosphorus ratio
real :: o2_2_p ! Oxygen to Phosphorus ratio
real :: o2_min ! Anaerobic respiration threshold
real :: P_star ! Pivotal phytoplankton concentration
real :: pc_0 ! Maximum carbon-specific growth rate
real :: phi_lg ! Fraction of small phytoplankton converted to detritus
real :: phi_sm ! Fraction of large phytoplankton converted to detritus
real :: po4_min ! Minimum PO4 concentration
real :: remin_min ! Minimum remineralization under low O2
real :: thetamax_hi ! Maximum Chl:C ratio when iron-replete
real :: thetamax_lo ! Maximum Chl:C ratio when iron-limited
real :: wsink_acc ! Sinking rate acceleration with depth
real :: wsink0 ! Sinking rate at surface
real :: wsink0_z ! Depth to which sinking rate remains constant
real :: htotal_scale_lo
real :: htotal_scale_hi
real :: htotal_in
real :: Rho_0
real :: a_0
real :: a_1
real :: a_2
real :: a_3
real :: a_4
real :: a_5
real :: b_0
real :: b_1
real :: b_2
real :: b_3
real :: c_0
real :: a1_co2
real :: a2_co2
real :: a3_co2
real :: a4_co2
real :: a1_o2
real :: a2_o2
real :: a3_o2
real :: a4_o2
!
! the following arrays are used for calculation diagnostic integrals and fluxes at depth
!
real, dimension(:,:,:), _ALLOCATABLE :: wrk_3d _NULL
real, dimension(:,:), _ALLOCATABLE :: wrk_2d _NULL
integer, dimension(:,:), _ALLOCATABLE :: k_lev _NULL
real, dimension(:,:), _ALLOCATABLE :: integral _NULL
real, dimension(:,:), _ALLOCATABLE :: flux _NULL
! The prefix nomenclature is as follows:
! "f_t" = a "field", generally a working array for the concentration of tracer t
! "jt_process" = a source/sink term for tracer t due to a biogeochemical process.
! * Note, j terms are in units of mol kg-1 in the code, but are saved to the diagnostic
! file as layer integrals (i.e. multiplied by the layer thickness/density)
! "b_t" = the flux of tracer t out of the ocean bottom
! "p_t" = a pointer, generally to the concentration of a tracer t
real, dimension(:,:,:), _ALLOCATABLE :: biomass_p_ts _NULL
real, dimension(:,:,:), _ALLOCATABLE :: def_fe _NULL
real, dimension(:,:,:), _ALLOCATABLE :: expkT _NULL
real, dimension(:,:,:), pointer :: p_biomass_p => NULL()
real, dimension(:,:,:), _ALLOCATABLE :: f_chl _NULL
real, dimension(:,:,:), _ALLOCATABLE :: f_fed _NULL
real, dimension(:,:,:), _ALLOCATABLE :: f_fed_data _NULL
real, dimension(:,:,:), pointer :: p_phyto_lg => NULL()
real, dimension(:,:,:), pointer :: p_phyto_sm => NULL()
real, dimension(:,:,:), pointer :: p_htotal => NULL()
real, dimension(:,:,:), pointer :: p_irr_mem => NULL()
real, dimension(:,:,:), _ALLOCATABLE :: f_o2 _NULL
real, dimension(:,:,:), _ALLOCATABLE :: f_po4 _NULL
real, dimension(:,:,:), _ALLOCATABLE :: fe_2_p_uptake _NULL
real, dimension(:,:,:), _ALLOCATABLE :: feprime _NULL
real, dimension(:,:,:), _ALLOCATABLE :: fpofe _NULL
real, dimension(:,:,:), _ALLOCATABLE :: fpop _NULL
real, dimension(:,:,:), _ALLOCATABLE :: frac_lg _NULL
real, dimension(:,:,:), _ALLOCATABLE :: frac_pop _NULL
real, dimension(:,:,:), _ALLOCATABLE :: irr_inst _NULL
real, dimension(:,:,:), _ALLOCATABLE :: irr_mix _NULL
real, dimension(:,:,:), _ALLOCATABLE :: irrk _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jfe_ads_inorg _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jfe_ads_org _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jfe_recycle _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jfe_reminp _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jfe_uptake _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jo2 _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jp_recycle _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jp_reminp _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jp_uptake _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jpo4 _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jfeop _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jpop _NULL
real, dimension(:,:,:), _ALLOCATABLE :: kfe_eq_lig _NULL
real, dimension(:,:,:), _ALLOCATABLE :: mu _NULL
real, dimension(:,:,:), _ALLOCATABLE :: pc_m _NULL
real, dimension(:,:,:), _ALLOCATABLE :: theta _NULL
real, dimension(:,:,:), _ALLOCATABLE :: thetamax_fe _NULL
real, dimension(:,:,:), _ALLOCATABLE :: wsink _NULL
real, dimension(:,:,:), _ALLOCATABLE :: zremin _NULL
real, dimension(:,:,:), _ALLOCATABLE :: zbot _NULL
real, dimension(:,:), _ALLOCATABLE :: b_fed _NULL
real, dimension(:,:), _ALLOCATABLE :: b_o2 _NULL
real, dimension(:,:), _ALLOCATABLE :: b_po4 _NULL
real, dimension(:,:), _ALLOCATABLE :: fe_burial _NULL
real, dimension(:,:), _ALLOCATABLE :: ffe_sed _NULL
real, dimension(:,:), _ALLOCATABLE :: o2_saturation _NULL
real, dimension(:,:), _ALLOCATABLE :: b_dic _NULL
real, dimension(:,:), _ALLOCATABLE :: co2_alpha _NULL
real, dimension(:,:), _ALLOCATABLE :: co2_csurf _NULL
real, dimension(:,:), _ALLOCATABLE :: htotallo _NULL
real, dimension(:,:), _ALLOCATABLE :: htotalhi _NULL
real, dimension(:,:), _ALLOCATABLE :: pco2_surf _NULL
real, dimension(:,:), _ALLOCATABLE :: surf_temp _NULL
real, dimension(:,:), _ALLOCATABLE :: surf_salt _NULL
real, dimension(:,:), _ALLOCATABLE :: surf_alk _NULL
real, dimension(:,:), _ALLOCATABLE :: surf_po4 _NULL
real, dimension(:,:), _ALLOCATABLE :: surf_sio4 _NULL
real, dimension(:,:), _ALLOCATABLE :: surf_dic _NULL
real, dimension(:,:,:), _ALLOCATABLE :: c14_2_p _NULL
real, dimension(:,:,:), _ALLOCATABLE :: fpo14c _NULL
real, dimension(:,:,:), _ALLOCATABLE :: j14c_decay_dic _NULL
real, dimension(:,:,:), _ALLOCATABLE :: j14c_reminp _NULL
real, dimension(:,:,:), _ALLOCATABLE :: jdi14c _NULL
real, dimension(:,:), _ALLOCATABLE :: b_di14c _NULL
real, dimension(:,:), _ALLOCATABLE :: c14o2_alpha _NULL
real, dimension(:,:), _ALLOCATABLE :: c14o2_csurf _NULL
real, dimension(:,:,:,:), pointer :: p_fed => NULL()
real, dimension(:,:,:), pointer :: p_fed_diag => NULL()
real, dimension(:,:,:,:), pointer :: p_o2 => NULL()
real, dimension(:,:,:,:), pointer :: p_po4 => NULL()
real, dimension(:,:,:,:), pointer :: p_di14c => NULL()
real, dimension(:,:,:,:), pointer :: p_dic => NULL()
character(len=fm_string_len) :: ice_restart_file
character(len=fm_string_len) :: ocean_restart_file
character(len=fm_string_len) :: IC_file
real :: diag_depth = 100.0 ! Depth over which to integrate and at which to get flux
! for diagnostics
character(len=16) :: diag_depth_str = ' ' ! String to hold diag depth
integer :: id_b_dic = -1 ! Bottom flux of DIC
integer :: id_b_di14c = -1 ! Bottom flux of DI14C
integer :: id_b_fed = -1 ! Bottom flux of Fe
integer :: id_b_o2 = -1 ! Bottom flux of O2
integer :: id_b_po4 = -1 ! Bottom flux of PO4
integer :: id_biomass_p_ts = -1 ! Instantaneous P concentration in biomass
integer :: id_c14_2_p = -1 ! DI14C to PO4 uptake ratio
integer :: id_c14o2_csurf = -1 ! Surface water 14CO2*
integer :: id_c14o2_alpha = -1 ! Surface water 14CO2* solubility
integer :: id_co2_csurf = -1 ! Surface water CO2*
integer :: id_co2_alpha = -1 ! Surface water CO2* solubility
integer :: id_def_fe = -1 ! Iron deficiency term
integer :: id_expkT = -1 ! Temperature dependence
integer :: id_fe_2_p_uptake = -1 ! Fed:PO4 of instantaneous uptake
integer :: id_feprime = -1 ! Free (unbound) iron concentration
integer :: id_fe_burial = -1 ! Flux of iron to sediment as particulate
integer :: id_ffe_sed = -1 ! Sediment iron efflux
integer :: id_fpofe = -1 ! POFe sinking flux
integer :: id_fpo14c = -1 ! PO14C sinking flux
integer :: id_fpop = -1 ! POP sinking flux
integer :: id_fpop_depth = -1 ! POP sinking flux at depth
integer :: id_frac_lg = -1 ! Fraction of production by large phytoplankton
integer :: id_frac_pop = -1 ! Fraction of uptake converted to particulate
integer :: id_irr_inst = -1 ! Instantaneous irradiance
integer :: id_irr_mix = -1 ! Mixed layer irradiance
integer :: id_irrk = -1 ! Effective susceptibility to light limitation
integer :: id_j14c_decay_dic = -1 ! Radioactive decay of DI14C
integer :: id_j14c_reminp = -1 ! 14C particle remineralization layer integral
integer :: id_jdi14c = -1 ! DI14C source layer integral
integer :: id_jfe_ads_inorg = -1 ! Iron adsorption (2nd order) layer integral
integer :: id_jfe_ads_org = -1 ! Iron adsorption to fpop layer integral
integer :: id_jfe_recycle = -1 ! Iron fast recycling layer integral
integer :: id_jfe_reminp = -1 ! Iron particle remineralization layer integral
integer :: id_jfe_uptake = -1 ! Iron uptake layer integral
integer :: id_jo2 = -1 ! O2 source layer integral
integer :: id_jo2_depth = -1 ! Depth integral of O2 source
integer :: id_jp_recycle = -1 ! Phosphorus fast recycling layer integral
integer :: id_jp_recycle_depth = -1 ! Depth integral of Phosphorus fast recycling
integer :: id_jp_reminp = -1 ! Phosphorus particle remineralization layer integral
integer :: id_jp_reminp_depth = -1 ! Depth integral of Phosphorus particle remineralization
integer :: id_jp_uptake = -1 ! Phosphorus uptake layer integral
integer :: id_jp_uptake_depth = -1 ! Depth integral of Phosphorus uptake
integer :: id_jpo4 = -1 ! PO4 source layer integral
integer :: id_jpo4_depth = -1 ! Depth integral of PO4 source layer integral
integer :: id_jfeop = -1 ! Particulate organic iron source layer integral
integer :: id_jpop = -1 ! Particulate organic phosphorus source layer integral
integer :: id_kfe_eq_lig = -1 ! Iron-ligand stability constant
integer :: id_mu = -1 ! Growth rate after respiratory loss(carbon specific)
integer :: id_o2_saturation = -1 ! Surface water O2 saturation
integer :: id_pc_m = -1 ! Light-saturated maximum photosynthesis rate (carbon specific)
integer :: id_pco2_surf = -1 ! Surface water pCO2
integer :: id_temp_co2calc = -1 ! Surface temp for co2calc
integer :: id_salt_co2calc = -1 ! Surface salt for co2calc
integer :: id_alk_co2calc = -1 ! Surface temp for co2calc
integer :: id_po4_co2calc = -1 ! Surface temp for co2calc
integer :: id_sio4_co2calc = -1 ! Surface temp for co2calc
integer :: id_dic_co2calc = -1 ! Surface temp for co2calc
integer :: id_theta = -1 ! Chl:C ratio
integer :: id_thetamax_fe = -1 ! Iron-limited maximum Chl:C ratio
integer :: id_wsink = -1 ! Sinking rate
integer :: id_zremin = -1 ! Remineralization length scale
integer :: id_fed_data = -1 ! Dissolved Iron data
integer :: id_di14c_surf = -1 ! Surface dissolved inorganic radiocarbon Prognostic tracer
integer :: id_dic_surf = -1 ! Surface dissolved inorganic carbon Prognostic tracer
integer :: id_fed_surf = -1 ! Surface dissolved Iron Prognostic tracer
integer :: id_o2_surf = -1 ! Surface oxygen Prognostic tracer
integer :: id_po4_surf = -1 ! Surface phosphate Prognostic tracer
integer :: id_di14c_depth = -1 ! Depth integral of dissolved inorganic radiocarbon Prognostic tracer
integer :: id_dic_depth = -1 ! Depth integral of dissolved inorganic carbon Prognostic tracer
integer :: id_fed_depth = -1 ! Depth integral of dissolved Iron Prognostic tracer
integer :: id_o2_depth = -1 ! Depth integral of oxygen Prognostic tracer
integer :: id_po4_depth = -1 ! Depth integral of phosphate Prognostic tracer
integer :: id_fed_data_surf = -1 ! Surface dissolved Iron data
integer :: id_htotal_surf = -1 ! Surface hydrogen ion Diagnostic tracer
integer :: id_chl_surf = -1 ! Surface chlorophyll Diagnostic tracer
integer :: id_biomass_p_surf = -1 ! Surface biomass Diagnostic tracer
integer :: id_phyto_lg_surf = -1 ! Surface large phytoplankton
integer :: id_phyto_sm_surf = -1 ! Surface small phytoplankton
integer :: id_irr_mem_surf = -1 ! Surface irradiance Memory Diagnostic tracer
integer :: id_fed_data_depth = -1 ! Depth integral of dissolved Iron data
integer :: id_chl_depth = -1 ! Depth integral of chlorophyll Diagnostic tracer
integer :: id_biomass_p_depth = -1 ! Depth integral of biomass Diagnostic tracer
integer :: id_phyto_lg_depth = -1 ! Depth integral of large phytoplankton
integer :: id_phyto_sm_depth = -1 ! Depth integral of small phytoplankton
integer :: id_irr_mem_depth = -1 ! Depth integral of irradiance Memory Diagnostic tracer
logical :: override_surf_temp = .true. ! True if overriding surface properties
logical :: override_surf_salt = .true. ! Must be true for first try, and will then
logical :: override_surf_alk = .true. ! be set accordingly by data_override
logical :: override_surf_po4 = .true.
logical :: override_surf_sio4 = .true.
logical :: override_surf_dic = .true.
end type generic_miniBLING_type
!An auxiliary type for storing varible names and descriptions
type, public :: vardesc
character(len=fm_string_len) :: name ! The variable name in a NetCDF file.
character(len=fm_string_len) :: longname ! The long name of that variable.
character(len=1) :: hor_grid ! The hor. grid: u, v, h, q, or 1.
character(len=1) :: z_grid ! The vert. grid: L, i, or 1.
character(len=1) :: t_grid ! The time description: s, a, m, or 1.
character(len=fm_string_len) :: units ! The dimensions of the variable.
character(len=1) :: mem_size ! The size in memory: d or f.
end type vardesc
type(generic_miniBLING_type), save :: bling
integer, parameter :: num_instances = 1
!type(generic_miniBLING_type), dimension(:), pointer :: bling
!integer :: num_instances
type(CO2_dope_vector) :: CO2_dope_vec
contains
!#######################################################################
subroutine generic_miniBLING_register(tracer_list)
type(g_tracer_type), pointer, intent(inout) :: tracer_list
!-----------------------------------------------------------------------
! local parameters
!-----------------------------------------------------------------------
!
character(len=fm_string_len), parameter :: sub_name = 'generic_miniBLING_register'
character(len=256), parameter :: error_header = &
'==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
character(len=256), parameter :: warn_header = &
'==>Warning from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
integer :: n
integer :: stdout_unit
stdout_unit = stdout()
!Add here only the parameters that are required at the time of registeration
!(to make flux exchanging Ocean tracers known for all PE's)
!
call g_tracer_start_param_list(package_name)
call g_tracer_add_param('name', bling%name, '_')
! Turn on additional complexity. Most relevant diagnostic variables and all
! tracers are not activated unless the appropriate switch is set to true.
call g_tracer_add_param('do_14c', bling%do_14c, .true.)
call g_tracer_add_param('do_carbon', bling%do_carbon, .true.)
call g_tracer_add_param('ice_restart_file' , bling%ice_restart_file , 'ice_minibling.res.nc')
call g_tracer_add_param('ocean_restart_file', bling%ocean_restart_file, 'ocean_minibling.res.nc')
call g_tracer_add_param('IC_file' , bling%IC_file , '')
call g_tracer_end_param_list(package_name)
!-----------------------------------------------------------------------
! Set the suffixes for this instance
if (bling%name(1:1) .eq. '_') then
bling%suffix = ' '
bling%long_suffix = ' '
else !}{
bling%suffix = '_' // bling%name
bling%long_suffix = ' (' // trim(bling%name) // ')'
endif !}
! Check for some possible fatal problems in the namelist variables.
if ((bling%do_14c) .and. (bling%do_carbon)) then
write (stdout_unit,*) trim(note_header), 'Simulating radiocarbon for instance ' // trim(bling%name)
else if ((bling%do_14c) .and. .not. (bling%do_carbon)) then
call mpp_error(FATAL, trim(error_header) // &
' Do_14c requires do_carbon for instance ' // trim(bling%name))
endif
! Set Restart files
call g_tracer_set_files(ice_restart_file = bling%ice_restart_file,&
ocean_restart_file = bling%ocean_restart_file )
do n = 1, num_instances
!All tracer fields shall be registered for diag output.
!=====================================================
!Specify all prognostic tracers of this modules.
!=====================================================
!User adds one call for each prognostic tracer below!
!User should specify if fluxes must be extracted from boundary
!by passing one or more of the following methods as .true.
!and provide the corresponding parameters array
!methods: flux_gas,flux_runoff,flux_wetdep,flux_drydep
!
!Pass an init_value arg if the tracers should be initialized to a nonzero value everywhere
!otherwise they will be initialized to zero.
!
!===========================================================
!Prognostic Tracers
!===========================================================
!
! Dissolved Fe
!
if (bling%fe_is_prognostic) then
call g_tracer_add(tracer_list, package_name, &
name = 'fed' // bling%suffix, &
longname = 'Dissolved Iron' // bling%long_suffix, &
units = 'mol/kg', &
prog = .true., &
flux_runoff = .false., &
flux_wetdep = .true., &
flux_drydep = .true., &
flux_param = (/ 55.847e-03 /), &
flux_bottom = .true. )
elseif (bling%fe_is_diagnostic) then
call g_tracer_add(tracer_list, package_name, &
name = 'fed' // bling%suffix, &
longname = 'Dissolved Iron' // bling%long_suffix, &
units = 'mol/kg', &
prog = .false.)
else
call mpp_error(NOTE, trim(note_header) // ' Fe is data overridden for instance ' // trim(bling%name))
endif
! O2
!
call g_tracer_add(tracer_list, package_name, &
name = 'o2' // bling%suffix, &
longname = 'Oxygen' // bling%long_suffix, &
units = 'mol/kg', &
prog = .true., &
flux_gas = .true., &
flux_gas_type = 'air_sea_gas_flux_generic', &
flux_gas_name = 'o2_flux' // trim(bling%suffix), &
flux_gas_molwt = WTMO2, &
flux_gas_param = (/ 9.36e-07, 9.7561e-06 /), &
flux_bottom = .true., &
flux_gas_restart_file = 'ocean_minibling_airsea_flux.res.nc' )
! PO4
!
call g_tracer_add(tracer_list, package_name, &
name = 'po4' // bling%suffix, &
longname = 'Phosphate' // bling%long_suffix, &
units = 'mol/kg', &
prog = .true., &
flux_bottom = .true. )
!===========================================================
!Diagnostic Tracers
!===========================================================
! Chl (Chlorophyll)
!
call g_tracer_add(tracer_list, package_name, &
name = 'chl' // bling%suffix, &
longname = 'Chlorophyll' // bling%long_suffix, &
units = 'ug kg-1', &
prog = .false., &
init_value = 0.08 )
! Irr_mem (Irradiance Memory)
!
call g_tracer_add(tracer_list, package_name, &
name = 'irr_mem' // bling%suffix, &
longname = 'Irradiance memory' // bling%long_suffix, &
units = 'Watts/m^2', &
prog = .false.)
if (bling%biomass_type .eq. 'single') then
! Biomass
!
call g_tracer_add(tracer_list, package_name, &
name = 'biomass_p' // bling%suffix, &
longname = 'Biomass in P units' // bling%long_suffix, &
units = 'mol P kg-1', &
prog = .false.)
elseif (bling%biomass_type .eq. 'lg_sm_phyto') then
! Large phytoplankton biomass
!
call g_tracer_add(tracer_list, package_name, &
name = 'phyto_lg' // bling%suffix, &
longname = 'Large phytoplankton biomass in P units' // bling%long_suffix, &
units = 'mol P kg-1', &
prog = .false., &
init_value = 4.e-07 )
! Small phytoplankton biomass
!
call g_tracer_add(tracer_list, package_name, &
name = 'phyto_sm' // bling%suffix, &
longname = 'Small phytoplankton biomass in P units' // bling%long_suffix, &
units = 'mol P kg-1', &
prog = .false., &
init_value = 4.e-07 )
else
call mpp_error(FATAL, trim(error_header) // ' Unknown biomass type "' // trim(bling%biomass_type) // '"')
endif
if (bling%do_carbon) then !<<CARBON CYCLE
! DIC (Dissolved inorganic carbon)
!
call g_tracer_add(tracer_list, package_name, &
name = 'dic' // bling%suffix, &
longname = 'Dissolved Inorganic Carbon' // bling%long_suffix, &
units = 'mol/kg', &
prog = .true., &
flux_gas = .true., &
flux_gas_type = 'air_sea_gas_flux_generic', &
flux_gas_name = 'co2_flux' // trim(bling%suffix), &
flux_gas_molwt = WTMCO2, &
flux_gas_param = (/ 9.36e-07, 9.7561e-06 /), &
flux_gas_restart_file = 'ocean_minibling_airsea_flux.res.nc', &
flux_runoff = .false., &
flux_param = (/ 12.011e-03 /), &
flux_bottom = .true., &
init_value = 0.001)
!Diagnostic Tracers:
! Htotal (H+ ion concentration)
!
call g_tracer_add(tracer_list, package_name, &
name = 'htotal' // bling%suffix, &
longname = 'H+ ion concentration' // bling%long_suffix, &
units = 'mol/kg', &
prog = .false., &
init_value = bling%htotal_in)
if (bling%do_14c) then !<<RADIOCARBON
! DI14C (Dissolved inorganic radiocarbon)
!
call g_tracer_add(tracer_list, package_name, &
name = 'di14c' // bling%suffix, &
longname = 'Dissolved Inorganic Radiocarbon' // bling%long_suffix, &
units = 'mol/kg', &
prog = .true., &
flux_gas = .true., &
flux_gas_type = 'air_sea_gas_flux_generic', &
flux_gas_name = 'c14o2_flux' // trim(bling%suffix), &
flux_gas_molwt = WTMCO2, &
flux_gas_param = (/ 9.36e-07, 9.7561e-06 /), &
flux_gas_restart_file = 'ocean_minibling_airsea_flux.res.nc', &
flux_param = (/ 14.e-03 /), &
flux_bottom = .true., &
init_value = 0.001)
endif !} !RADIOCARBON>>
endif !} !CARBON CYCLE>>
enddo !} n
end subroutine generic_miniBLING_register
!#######################################################################
! <SUBROUTINE NAME="generic_miniBLING_init">
! <OVERVIEW>
! Initialize the generic miniBLING module
! </OVERVIEW>
! <DESCRIPTION>
! This subroutine:
! Adds all the miniBLING Tracers to the list of generic Tracers passed
! to it via utility subroutine g_tracer_add(). Adds all the parameters
! used by this module via utility subroutine g_tracer_add_param().
! Allocates all work arrays used in the module.
! </DESCRIPTION>
! <TEMPLATE>
! call generic_miniBLING_init
! </TEMPLATE>
! </SUBROUTINE>
subroutine generic_miniBLING_init(tracer_list)
type(g_tracer_type), pointer :: tracer_list
!-----------------------------------------------------------------------
! local parameters
!-----------------------------------------------------------------------
!
character(len=64), parameter :: sub_name = 'generic_miniBLING_init'
character(len=256) :: caller_str
character(len=256) :: error_header
character(len=256) :: warn_header
character(len=256) :: note_header
integer :: n
character(len=fm_field_name_len) :: name
integer :: nn
character(len=fm_field_name_len), pointer, dimension(:) :: names => NULL()
integer :: stdout_unit
character(len=fm_string_len) :: string
integer :: package_index
stdout_unit = stdout()
! Set up the field input
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')[]'
error_header = '==>Error from ' // trim(caller_str) // ':'
warn_header = '==>Warning from ' // trim(caller_str) // ':'
note_header = '==>Note from ' // trim(caller_str) // ':'
write (stdout_unit,*)
write (stdout_unit,*) trim(note_header), ' Processing generic tracer package miniBLING'
do n = 1, num_instances
!Specify all parameters used in this modules.
!==============================================================
!User adds one call for each parameter below!
!User also adds the definition of each parameter in generic_miniBLING_params type
!==============================================================
!Add the known experimental parameters used for calculations in this module.
!All the g_tracer_add_param calls must happen between
!g_tracer_start_param_list and g_tracer_end_param_list calls.
!This implementation enables runtime overwrite via field_table.
call g_tracer_start_param_list(package_name)
! Rho_0 is used in the Boussinesq
! approximation to calculations of pressure and
! pressure gradients, in units of kg m-3.
call g_tracer_add_param('RHO_0', bling%Rho_0, 1035.0)
!-----------------------------------------------------------------------
! Gas exchange
!-----------------------------------------------------------------------
! coefficients for O2 saturation
!-----------------------------------------------------------------------
call g_tracer_add_param('a_0', bling%a_0, 2.00907)
call g_tracer_add_param('a_1', bling%a_1, 3.22014)
call g_tracer_add_param('a_2', bling%a_2, 4.05010)
call g_tracer_add_param('a_3', bling%a_3, 4.94457)
call g_tracer_add_param('a_4', bling%a_4, -2.56847e-01)
call g_tracer_add_param('a_5', bling%a_5, 3.88767)
call g_tracer_add_param('b_0', bling%b_0, -6.24523e-03)
call g_tracer_add_param('b_1', bling%b_1, -7.37614e-03)
call g_tracer_add_param('b_2', bling%b_2, -1.03410e-02 )
call g_tracer_add_param('b_3', bling%b_3, -8.17083e-03)
call g_tracer_add_param('c_0', bling%c_0, -4.88682e-07)
!-----------------------------------------------------------------------
! Schmidt number coefficients
!-----------------------------------------------------------------------
! Compute the Schmidt number of CO2 in seawater using the
! formulation presented by Wanninkhof (1992, J. Geophys. Res., 97,
! 7373-7382).
!-----------------------------------------------------------------------
!New Wanninkhof numbers
call g_tracer_add_param('a1_co2', bling%a1_co2, 2068.9)
call g_tracer_add_param('a2_co2', bling%a2_co2, -118.63)
call g_tracer_add_param('a3_co2', bling%a3_co2, 2.9311)
call g_tracer_add_param('a4_co2', bling%a4_co2, -0.027)
!---------------------------------------------------------------------
! Compute the Schmidt number of O2 in seawater using the
! formulation proposed by Keeling et al. (1998, Global Biogeochem.
! Cycles, 12, 141-163).
!---------------------------------------------------------------------
!New Wanninkhof numbers
call g_tracer_add_param('a1_o2', bling%a1_o2, 1929.7)
call g_tracer_add_param('a2_o2', bling%a2_o2, -117.46)
call g_tracer_add_param('a3_o2', bling%a3_o2, 3.116)
call g_tracer_add_param('a4_o2', bling%a4_o2, -0.0306)
call g_tracer_add_param('htotal_scale_lo', bling%htotal_scale_lo, 0.01)
call g_tracer_add_param('htotal_scale_hi', bling%htotal_scale_hi, 100.0)
!-----------------------------------------------------------------------
! Uptake
!-----------------------------------------------------------------------
!
! Phytoplankton growth altered from Geider et al (1997)
! and Moore et al (2002).
! The factor of 6.022e17 is to convert
! from umol to quanta and 2.77e18 to convert from quanta/sec
! to Watts given the average energy spectrum for underwater
! PAR from the Seabird sensor.
!
call g_tracer_add_param('alk_scheme', bling%alk_scheme, 'normal')
call g_tracer_add_param('alk_slope', bling%alk_slope, 32.0e-06)
call g_tracer_add_param('alk_intercept', bling%alk_intercept, 1200.0e-06)
call g_tracer_add_param('biomass_type', bling%biomass_type, 'single')
call g_tracer_add_param('alpha_photo', bling%alpha_photo, 1.e-5 * 2.77e+18 / 6.022e+17) ! g C g Chl-1 m2 W-1 s-1
call g_tracer_add_param('kappa_eppley', bling%kappa_eppley, 0.063) ! deg C-1
call g_tracer_add_param('pc_0', bling%pc_0, 1.0e-5) ! s-1
call g_tracer_add_param('thetamax_hi', bling%thetamax_hi, 0.040) ! g Chl g C-1
call g_tracer_add_param('thetamax_lo', bling%thetamax_lo, 0.010) ! g Chl g C-1
!
! Chl:C response rate constant for phytoplankton calibrated to 1 d-1
! after Owens et al (1980, Diel Periodicity in cellular Chlorophyll
! content of marine diatoms, Mar. Biol, 59, 71-77).
!
call g_tracer_add_param('gamma_irr_mem', bling%gamma_irr_mem, 1.0 / sperd) ! s-1
! Introduce a minimum chlorophyll concentration for numerical stability.
! Value is an order of magnitude less than the minimum produced in topaz.
!
call g_tracer_add_param('chl_min', bling%chl_min, 1.e-5) ! ug kg-1
!
! The biomass reponds to changes in growth rate with an arbitrary 2 day lag.
!
call g_tracer_add_param('gamma_biomass', bling%gamma_biomass, 0.5 / sperd) ! s-1
!-----------------------------------------------------------------------
! Monod half saturation coefficient for phosphate. Value of Aumont (JGR, 2002)
! used for large phytoplankton.
call g_tracer_add_param('k_po4', bling%k_po4, 1.0e-7) ! mol PO4 kg-1
call g_tracer_add_param('po4_min', bling%po4_min, 1.0e-8) ! mol PO4 kg-1
!-----------------------------------------------------------------------
! Fe uptake and limitation.
! The uptake ratio of Fe:P is determined from a Monod constant and a
! scaling factor.
! The k_Fe_uptake is high, to provide luxury uptake of iron as a
! relatively linear function of iron concentrations under open-ocean
! conditions, consistent with the results of Sunda and Huntsman (Fig 1,
! Nature, 1997).
call g_tracer_add_param('k_fe_uptake', bling%k_fe_uptake, 0.8e-9) ! mol Fe kg-1
! This Monod term, which is nearly linear with [Fe], is multiplied by a
! scaling term to provide the actual Fe:P uptake ratio such that, at
! [Fe] = k_fe_uptake, Fe:P = fe_2_p_max / 2.
! This maximum value was set in accordance with the range of
! open-ocean Fe:C ratios summarized by Boyd et al. (Science, 2007) and
! converted to a Fe:P ratio.
! As a tuning parameter, it affects the amount of Fe that cycles via the
! organic matter pathway, and its ratio to k_fe_2_p determines the
! degree of iron limitation (the larger this ratio, the less iron
! limitation there will be).
call g_tracer_add_param('fe_2_p_max', bling%fe_2_p_max, 28.e-6 * 106.) ! mol Fed mol PO4-1
!
! New paramter to help with non-prognostic iron
!
call g_tracer_add_param('def_fe_min', bling%def_fe_min, 0.0) ! ?
!
! If fe_is_prognostic is true, then Fed will be a prognostic variable, otherwise
! if fe_is_diagnostic is true, then it will be diagnostic, restoring to a 3-d field with
! a time-scale of fe_restoring (in days), otherwise fed will be data driven
! with any coastal increase.
!
call g_tracer_add_param('fe_is_prognostic', bling%fe_is_prognostic, .false.)
call g_tracer_add_param('fe_is_diagnostic', bling%fe_is_diagnostic, .false.)
call g_tracer_add_param('fe_restoring', bling%fe_restoring, 10.0) ! days
call g_tracer_add_param('fe_coastal', bling%fe_coastal, 2.0e-09) ! mol/kg
call g_tracer_add_param('fe_coastal_depth', bling%fe_coastal_depth, 200.0) ! m
! The k_fe_2_p is the Fe:P at which the iron-limitation term has a
! value of 0.5, chosen according to Sunda and Huntsman (Fig. 2,
! Nature, 1997). Converted from Fe:C ratio.
call g_tracer_add_param('k_fe_2_p', bling%k_fe_2_p, 7.e-6 * 106.) ! mol Fe mol P-1
!-----------------------------------------------------------------------
! Mortality & Remineralization
!-----------------------------------------------------------------------
!
! T=0 phytoplankton specific total-mortality rate from the global
! synthesis of Dunne et al. (2005)
!
call g_tracer_add_param('lambda0', bling%lambda0, 0.19 / sperd) ! s-1
!
! Pivot phytoplankton concentration for grazing-based
! variation in ecosystem structure from the global
! synthesis of Dunne et al. (2005). Converted from mol C m-3.
!
call g_tracer_add_param('P_star', bling%P_star, 1.9e-3 / 1028. / 106.0) ! mol P kg-1
!
! Temperature-dependence of fractional detritus production
! from the global synthesis of Dunne et al. (2005)
!
call g_tracer_add_param('kappa_remin', bling%kappa_remin, -0.032) ! deg C-1
! Phytoplankton fractional detritus production by size class,
! from the global synthesis of Dunne et al. (2005)
call g_tracer_add_param('phi_lg', bling%phi_lg, 1.0) ! unitless
call g_tracer_add_param('phi_sm', bling%phi_sm, 0.18) ! unitless
! Half saturation constant for fast recycling of P, very low to act only in nutrient-poor waters
call g_tracer_add_param('k_po4_recycle', bling%k_po4_recycle, 2.0e-8) ! mol PO4 kg-1
!-----------------------------------------------------------------------
! Remineralization
!-----------------------------------------------------------------------
!
! Stoichiometric ratios taken from Anderson (1995) as discussed in
! Sarmiento and Gruber (2008), and Sarmiento et al. (2002) for Ca:P.
!
call g_tracer_add_param('c_2_p', bling%c_2_p, 106.0 ) ! mol C mol P-1
call g_tracer_add_param('o2_2_p', bling%o2_2_p, 150.0 ) ! mol O2 mol P-1
! Convert from mol P m-3 to mg C l-1
call g_tracer_add_param('mass_2_p', bling%mass_2_p, 106. * 12.001 ) ! g C mol P-1
! Radiocarbon
call g_tracer_add_param('half_life_14c', bling%half_life_14c, 5730.0 ) ! a
!
!-----------------------------------------------------------------------
! Remineralization length scales
!
! Values of parameters to approximate upper e-folding of the globally-tuned
! "Martin curve" used in the OCMIP-II Biotic configuration of (z/75)^-0.9
! that gives a value of exp(-1) at 228 m from 75 m for an e-folding scale
! of 188 m.
! Here these are given as a linear function of depth,
! wsink = wsink0 + wsink_acc * (z - wsink0_z)
call g_tracer_add_param('wsink_acc', bling%wsink_acc, 0.05 / sperd) ! s-1
call g_tracer_add_param('wsink0', bling%wsink0, 16.0 / sperd) ! m s-1
call g_tracer_add_param('wsink0_z', bling%wsink0_z, 80. ) ! m
call g_tracer_add_param('gamma_pop', bling%gamma_pop, 0.12 / sperd ) ! s-1
! Half saturation oxygen concentration for oxic remineralization rate.
!
call g_tracer_add_param('k_o2', bling%k_o2, 20.0e-6) ! mol O2 kg-1
!
! Remineralization rate under suboxic/anoxic conditions, as a fraction of the rate under
! fully oxidized conditions. As this code is currently intended for short, high-resolution runs,
! this value is set to zero to cause a cessation of remineralization under suboxia/anoxia.
! This will allow P to sink past the OMZ, which lead lead to a downward expansion of the OMZ,
! but it hopefully won't be a huge problem on the timescale of 100-200 years.
!
call g_tracer_add_param('remin_min', bling%remin_min, 0.0) ! dimensionless
!
! Minimum oxygen concentration for oxic remineralization.
! At O2 less than this, anaerobic remineralization occurs at remin_min rate.
!
call g_tracer_add_param('o2_min', bling%o2_min, 1.0e-06) ! mol O2 kg-1
!
! Prevent oxygen from becoming negative. Setting to false allows negative
! oxygen in anoxic zones, which can be thought of as equivalent to
! denitrification plus H2S production.
!
call g_tracer_add_param('prevent_neg_o2', bling%prevent_neg_o2, .true. )
!-----------------------------------------------------------------------
! Iron Cycling
!
! Global uniform iron ligand concentration.
! Taken from Parekh, P., M. J. Follows and E. A. Boyle (2005) Decoupling of iron
! and phosphate in the global ocean. Glob. Biogeochem. Cycles, 19,
! doi: 10.1029/2004GB002280.
!
call g_tracer_add_param('felig_bkg', bling%felig_bkg, 1.0e-9) ! mol ligand kg-1
!
! Ratio of iron efflux from bottom sediment boundaries to the sedimenting phosphorus flux.
! From Elrod et al. (2004), 0.68 mmol Fe mol C-1, after Moore et al (2008):
!
call g_tracer_add_param('fe_2_p_sed', bling%fe_2_p_sed, 1.e-4 * 106.0 ) ! mol Fe mol P-1
!
! 1.5-order iron scavenging in order to prevent high iron
! accumulations in high deposition regions (like the tropical
! Atlantic). This also helps prevent Fe accumulating in oligotrophic gyres and in
! the abyssal ocean, where organic fluxes are low.
!
call g_tracer_add_param('kfe_inorg', bling%kfe_inorg, 1.e3/sperd) ! mol.5 Fe-.5 kg s-1
!
! Equilibrium constant for (free and inorganically bound) iron binding with organic
! ligands taken from range similar to Parekh, P., M. J. Follows and E. A. Boyle
! (2005) Decoupling of iron and phosphate in the global ocean. Glob. Biogeochem.
! Cycles, 19, doi: 10.1029/2004GB002280.
!
call g_tracer_add_param('kfe_eq_lig_max', bling%kfe_eq_lig_max, 8.e10) ! mol lig-1 kg
!
! Minimum ligand strength under high light, to represent photodissociation of
! ligand-Fe complexes.
!
call g_tracer_add_param('kfe_eq_lig_min', bling%kfe_eq_lig_min, 0.8e10) ! mol lig-1 kg
!
! Photodecay irradiance scaling.
!
call g_tracer_add_param('kfe_eq_lig_irr', bling%kfe_eq_lig_irr, 0.1) ! W m-2
!
! Iron concentration near which photodecay is compensated by enhanced siderophore
! production.
!
call g_tracer_add_param('kfe_eq_lig_femin', bling%kfe_eq_lig_femin, 0.05e-9) ! W m-2
!
! Adsorption rate coefficient for detrital organic material.
!
call g_tracer_add_param('kfe_org', bling%kfe_org, 0.5/sperd) ! g org-1 m3 s-1
!
! Mimimum fraction of POP (for turning off recycling set to 1.0)
!
call g_tracer_add_param('min_frac_pop', bling%min_frac_pop, 0.0)
!
! Depth for integral and flux diagnostics
!
!-----------------------------------------------------------------------
! Miscellaneous
!-----------------------------------------------------------------------
!
call g_tracer_add_param('diag_depth', bling%diag_depth, 100.0) ! use nearest integer
!
call g_tracer_end_param_list(package_name)
!
! Check the diag depth and set a string for that depth
!
if (bling%diag_depth .gt. 0.0) then
bling%diag_depth = nint(bling%diag_depth)
write (bling%diag_depth_str, '(f10.0)') bling%diag_depth
bling%diag_depth_str = adjustl(bling%diag_depth_str)
bling%diag_depth_str = bling%diag_depth_str(1:len_trim(bling%diag_depth_str)-1) ! remove trailing decimal point
else
call mpp_error(FATAL, trim(error_header) // ' diag_depth <= 0 for instance ' // trim(bling%name))
endif
enddo !} n
! Allocate all the private work arrays used by this module.
call user_allocate_arrays
end subroutine generic_miniBLING_init
!#######################################################################
! Register diagnostic fields to be used in this module.
! Note that the tracer fields are automatically registered in user_add_tracers
! User adds only diagnostics for fields that are not a member of g_tracer_type
!
subroutine generic_miniBLING_register_diag
real, parameter :: missing_value1 = -1.0e+10
type(vardesc) :: vardesc_temp
integer :: isc
integer :: iec
integer :: jsc
integer :: jec
integer :: isd
integer :: ied
integer :: jsd
integer :: jed
integer :: nk
integer :: ntau
integer :: n
integer :: axes(3)
type(time_type) :: init_time
call g_tracer_get_common(isc, iec, jsc, jec, isd, ied, jsd, jed, nk, ntau, axes = axes, init_time = init_time)
! The following vardesc types contain a package of metadata about each tracer,
! including, in order, the following elements: name; longname; horizontal
! staggering ('h') for collocation with thickness points ; vertical staggering
! ('L') for a layer variable ; temporal staggering ('s' for snapshot) ; units ;
! and precision in non-restart output files ('f' for 32-bit float or 'd' for
! 64-bit doubles). For most tracers, only the name, longname and units should
! be changed.
!
! Register Diagnostics
!===========================================================
!
! Core diagnostics
do n = 1, num_instances
if (bling%fe_is_prognostic) then
vardesc_temp = vardesc&
("b_fed","Bottom flux of Fe into sediment",'h','1','s','mol m-2 s-1','f')
bling%id_b_fed = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
vardesc_temp = vardesc&
("b_o2","Bottom flux of O2 into sediment",'h','1','s','mol m-2 s-1','f')
bling%id_b_o2 = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("b_po4","Bottom flux of PO4 into sediment",'h','1','s','mol m-2 s-1','f')
bling%id_b_po4 = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (bling%biomass_type .eq. 'single') then
vardesc_temp = vardesc&
("biomass_p_ts","Instantaneous P concentration in biomass",'h','L','s','mol kg-1','f')
bling%id_biomass_p_ts = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
vardesc_temp = vardesc&
("def_Fe","Iron deficiency term",'h','L','s','unitless','f')
bling%id_def_fe = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("expkT","Temperature dependence",'h','L','s','unitless','f')
bling%id_expkT = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("fe_2_p_uptake","Uptake ratio of Fed:PO4",'h','L','s','mol Fe mol P-1','f')
bling%id_fe_2_p_uptake = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (bling%fe_is_prognostic) then
vardesc_temp = vardesc&
("fe_burial","Sedimenting iron flux",'h','1','s','mol m-2 s-1','f')
bling%id_fe_burial = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("feprime","Concentration of free, unbound iron",'h','L','s','mol kg-1','f')
bling%id_feprime = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("ffe_sed","Sediment iron efflux",'h','1','s','mol m-2 s-1','f')
bling%id_ffe_sed = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("fpofe","POFe sinking flux at layer bottom",'h','L','s','mol m-2 s-1','f')
bling%id_fpofe = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
vardesc_temp = vardesc&
("fpop_" // trim(bling%diag_depth_str),"POP sinking flux at " // trim(bling%diag_depth_str) // " m", &
'h','L','s','mol m-2 s-1','f')
bling%id_fpop_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("fpop","POP sinking flux at layer bottom",'h','L','s','mol m-2 s-1','f')
bling%id_fpop = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("frac_lg","Fraction of production by large phytoplankton",'h','L','s','unitless','f')
bling%id_frac_lg = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("frac_pop","Particulate fraction of total uptake",'h','L','s','unitless','f')
bling%id_frac_pop = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("irr_inst","Instantaneous light",'h','L','s','W m-2','f')
bling%id_irr_inst = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("irr_mix","Mixed layer light",'h','L','s','W m-2','f')
bling%id_irr_mix = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("irrk","Tendency to light limitation",'h','L','s','W m-2','f')
bling%id_irrk = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (bling%fe_is_prognostic) then
vardesc_temp = vardesc&
("jfe_ads_inorg","Iron adsorption (2nd order) layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jfe_ads_inorg = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jfe_ads_org","Iron adsorption to FPOP layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jfe_ads_org = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jfe_recycle","Fast recycling of iron layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jfe_recycle = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
if (bling%fe_is_prognostic .or. bling%fe_is_diagnostic) then
vardesc_temp = vardesc&
("jfe_reminp","Sinking particulate Fe decay layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jfe_reminp = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
vardesc_temp = vardesc&
("jfe_uptake","Iron production layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jfe_uptake = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jo2_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral of o2 source", &
'h','L','s','mol m-2 s-1','f')
bling%id_jo2_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jo2","O2 source layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jo2 = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jp_recycle_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral of fast recycling of PO4", &
'h','L','s','mol m-2 s-1','f')
bling%id_jp_recycle_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jp_recycle","Fast recycling of PO4 layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jp_recycle = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jp_reminp_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral of sinking particulate P decay", &
'h','L','s','mol m-2 s-1','f')
bling%id_jp_reminp_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jp_reminp","Sinking particulate P decay layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jp_reminp = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jp_uptake_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral of pO4 uptake", &
'h','L','s','mol m-2 s-1','f')
bling%id_jp_uptake_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jp_uptake","PO4 uptake layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jp_uptake = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jpo4_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral of PO4 source", &
'h','L','s','mol m-2 s-1','f')
bling%id_jpo4_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jpo4","PO4 source layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jpo4 = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jpop","Particulate P source layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jpop = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (bling%fe_is_prognostic) then
vardesc_temp = vardesc&
("jfeop","Particulate Fe source layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jfeop = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("kfe_eq_lig","Iron ligand stability constant",'h','L','s','mol-1 kg','f')
bling%id_kfe_eq_lig = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
vardesc_temp = vardesc&
("mu","Net growth rate after respiratory loss",'h','L','s','s-1','f')
bling%id_mu = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("o2_saturation","Saturation O2 concentration",'h','1','s','mol kg-1','f')
bling%id_o2_saturation = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("pc_m","Light-saturated photosynthesis rate (carbon specific)",'h','L','s','s-1','f')
bling%id_pc_m = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("theta","Chl:C ratio",'h','L','s','g Chl g C-1','f')
bling%id_theta = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("thetamax_fe","Fe-limited max Chl:C",'h','L','s','g Chl g C-1','f')
bling%id_thetamax_fe = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("wsink","Sinking rate",'h','L','s','m s-1','f')
bling%id_wsink = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("zremin","Remineralization lengthscale",'h','L','s','m','f')
bling%id_zremin = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("o2_surf","Surface O2 concentration",'h','1','s','mol kg-1','f')
bling%id_o2_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("o2_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral O2", &
'h','1','s','mol m-2','f')
bling%id_o2_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("fed_surf","Surface Fed concentration",'h','1','s','mol kg-1','f')
bling%id_fed_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("fed_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral Fed", &
'h','1','s','mol m-2','f')
bling%id_fed_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (.not. bling%fe_is_prognostic) then
vardesc_temp = vardesc&
("fed_data_surf","Surface Fed data concentration",'h','1','s','mol kg-1','f')
bling%id_fed_data_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("fed_data_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral Fedconcentration", &
'h','1','s','mol m-2','f')
bling%id_fed_data_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
vardesc_temp = vardesc&
("po4_surf","Surface PO4 concentration",'h','1','s','mol kg-1','f')
bling%id_po4_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("po4_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral PO4", &
'h','1','s','mol m-2','f')
bling%id_po4_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("htotal_surf","Surface H+ concentration",'h','1','s','mol kg-1','f')
bling%id_htotal_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (bling%biomass_type .eq. 'single') then
vardesc_temp = vardesc&
("biomass_p_surf","Surface Biomass-P concentration",'h','1','s','mol kg-1','f')
bling%id_biomass_p_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("biomass_p_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral BiomasP concentration", &
'h','1','s','mol m-2','f')
bling%id_biomass_p_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
elseif (bling%biomass_type .eq. 'lg_sm_phyto') then
vardesc_temp = vardesc&
("phyto_lg_surf","Surface large phytoplankton concentration",'h','1','s','mol kg-1','f')
bling%id_phyto_lg_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("phyto_lg_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral largeconcentration", &
'h','1','s','mol m-2','f')
bling%id_phyto_lg_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("phyto_sm_surf","Surface small phytoplankton concentration",'h','1','s','mol kg-1','f')
bling%id_phyto_sm_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("phyto_sm_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral smallconcentration", &
'h','1','s','mol m-2','f')
bling%id_phyto_sm_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
vardesc_temp = vardesc&
("chl_surf","Surface Chl concentration",'h','1','s','mol kg-1','f')
bling%id_chl_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("chl_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral Chl", &
'h','1','s','mol m-2','f')
bling%id_chl_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("irr_mem_surf","Surface IRR_mem concentration",'h','1','s','mol kg-1','f')
bling%id_irr_mem_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("irr_mem_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral IRR_mem", &
'h','1','s','mol m-2','f')
bling%id_irr_mem_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (.not. bling%fe_is_prognostic) then
vardesc_temp = vardesc&
("fed_data","Fed data concentration",'h','1','s','mol kg-1','f')
bling%id_fed_data = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif
if (bling%do_carbon) then !<<CARBON CYCLE
vardesc_temp = vardesc&
("dic_surf","Surface DIC concentration",'h','1','s','mol kg-1','f')
bling%id_dic_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("dic_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral DIC", &
'h','1','s','mol m-2','f')
bling%id_dic_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("b_dic","Bottom flux of DIC into sediment",'h','1','s','mol m-2 s-1','f')
bling%id_b_dic = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("co2_alpha","Saturation surface CO2* per uatm",'h','1','s','mol kg-1 atm-1','f')
bling%id_co2_alpha = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("co2_csurf","CO2* concentration at surface",'h','1','s','mol kg-1','f')
bling%id_co2_csurf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("pco2_surf","Seawater pCO2 in surface layer",'h','1','s','uatm','f')
bling%id_pco2_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("temp_co2calc","Surface temperature used for co2calc",'h','1','s','deg C','f')
bling%id_temp_co2calc = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("salt_co2calc","Surface salinity used for co2calc",'h','1','s','PSU','f')
bling%id_salt_co2calc = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("alk_co2calc","Surface alkalinity used for co2calc",'h','1','s','eq kg-1','f')
bling%id_alk_co2calc = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("po4_co2calc","Surface phosphate used for co2calc",'h','1','s','mol kg -1','f')
bling%id_po4_co2calc = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("sio4_co2calc","Surface silicate used for co2calc",'h','1','s','mol kg -1','f')
bling%id_sio4_co2calc = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("dic_co2calc","Surface DIC used for co2calc",'h','1','s','mol kg -1','f')
bling%id_dic_co2calc = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
if (bling%do_14c) then !<<RADIOCARBON
vardesc_temp = vardesc&
("di14c_surf","Surface DI14C concentration",'h','1','s','mol kg-1','f')
bling%id_di14c_surf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("di14c_" // trim(bling%diag_depth_str),trim(bling%diag_depth_str) // " m integral DI14C", &
'h','1','s','mol m-2','f')
bling%id_di14c_depth = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("b_di14c","Bottom flux of DI14C into sediment",'h','1','s','mol m-2 s-1','f')
bling%id_b_di14c = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("c14_2_p","Ratio of DI14C to PO4",'h','L','s','mol kg-1','f')
bling%id_c14_2_p = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("c14o2_alpha","Saturation surface 14CO2* per uatm",'h','1','s','mol kg-1 atm-1','f')
bling%id_c14o2_alpha = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("c14o2_csurf","14CO2* concentration at surface",'h','1','s','mol kg-1','f')
bling%id_c14o2_csurf = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:2), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("fpo14c","PO14C sinking flux at layer bottom",'h','L','s','mol m-2 s-1','f')
bling%id_fpo14c = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("j14c_decay_dic","DI14C radioactive decay layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_j14c_decay_dic = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("j14c_reminp","Sinking PO14C remineralization layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_j14c_reminp = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
vardesc_temp = vardesc&
("jdi14c","DI14C source layer integral",'h','L','s','mol m-2 s-1','f')
bling%id_jdi14c = register_diag_field(package_name, trim(vardesc_temp%name) // bling%suffix, &
axes(1:3), init_time, trim(vardesc_temp%longname) // bling%long_suffix, &
vardesc_temp%units, missing_value = missing_value1)
endif !} !RADIOCARBON>>
endif !} !CARBON CYCLE>>
enddo !} n
end subroutine generic_miniBLING_register_diag
!#######################################################################
! <SUBROUTINE NAME="generic_miniBLING_update_from_coupler">
! <OVERVIEW>
! Modify the values obtained from the coupler if necessary.
! </OVERVIEW>
! <DESCRIPTION>
! Some tracer fields could be modified after values are obtained from the
! coupler. This subroutine is the place for specific tracer manipulations.
! miniBLING currently does not use this.
! </DESCRIPTION>
! <TEMPLATE>
! call generic_miniBLING_update_from_coupler(tracer_list)
! </TEMPLATE>
! <IN NAME="tracer_list" TYPE="type(g_tracer_type), pointer">
! Pointer to the head of generic tracer list.
! </IN>
! </SUBROUTINE>
subroutine generic_miniBLING_update_from_coupler(tracer_list)
type(g_tracer_type), pointer, intent(inout) :: tracer_list
character(len=fm_string_len), parameter :: sub_name = 'generic_miniBLING_update_from_coupler'
end subroutine generic_miniBLING_update_from_coupler
!#######################################################################
! <SUBROUTINE NAME="generic_miniBLING_update_from_bottom">
! <OVERVIEW>
! Set values of bottom fluxes and reservoirs
! </OVERVIEW>
! <DESCRIPTION>
! Some tracers could have bottom fluxes and reservoirs.
! This subroutine is the place for specific tracer manipulations.
! miniBLING currently does not use this.
! </DESCRIPTION>
! <TEMPLATE>
! call generic_miniBLING_update_from_bottom(tracer_list,dt, tau)
! </TEMPLATE>
! <IN NAME="tracer_list" TYPE="type(g_tracer_type), pointer">
! Pointer to the head of generic tracer list.
! </IN>
! <IN NAME="dt" TYPE="real">
! Time step increment
! </IN>
! <IN NAME="tau" TYPE="integer">
! Time step index to be used for %field
! </IN>
! </SUBROUTINE>
subroutine generic_miniBLING_update_from_bottom(tracer_list, dt, tau)
type(g_tracer_type), pointer, intent(inout) :: tracer_list
real, intent(in) :: dt
integer, intent(in) :: tau
end subroutine generic_miniBLING_update_from_bottom
!#######################################################################
! <SUBROUTINE NAME="generic_miniBLING_diag">
! <OVERVIEW>
! Do things which must be done after tronsports and sources have been applied
! </OVERVIEW>
! <DESCRIPTION>
! This subroutine saves out surface diagnostic firlds for prognostic tracers
! after vertical transport has been calculated
! </DESCRIPTION>
! <TEMPLATE>
! call generic_miniBLING_diag(tracer_list,tau,model_time)
! </TEMPLATE>
! <IN NAME="tracer_list" TYPE="type(g_tracer_type), pointer">
! Pointer to the head of generic tracer list.
! </IN>
! <IN NAME="tau" TYPE="integer">
! Time step index of %field
! </IN>
! <IN NAME="model_time" TYPE="time_type">
! Model time
! </IN>
! </SUBROUTINE>
subroutine generic_miniBLING_diag(tracer_list, ilb, jlb, tau, model_time, dzt, rho_dzt, caller)
type(g_tracer_type), pointer, intent(inout) :: tracer_list
integer, intent(in) :: ilb
integer, intent(in) :: jlb
integer, intent(in) :: tau
type(time_type), intent(in) :: model_time
real, dimension(ilb:,jlb:,:), intent(in) :: dzt
real, dimension(ilb:,jlb:,:), intent(in) :: rho_dzt
character(len=*), intent(in), optional :: caller
!-----------------------------------------------------------------------
! local parameters
character(len=fm_string_len), parameter :: sub_name = 'generic_miniBLING_diag'
character(len=256) :: caller_str
character(len=256) :: error_header
character(len=256) :: warn_header
character(len=256) :: note_header
integer :: isc
integer :: iec
integer :: jsc
integer :: jec
integer :: isd
integer :: ied
integer :: jsd
integer :: jed
integer :: nk
integer :: ntau
integer :: i
integer :: j
integer :: k
integer :: n
real, dimension(:,:,:), pointer :: grid_tmask
logical :: used
integer :: k_int
logical :: diag_initialized
! Set up the headers for stdout messages.
if (present(caller)) then
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')[' // trim(caller) // ']'
else
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')[]'
endif
error_header = '==> Error from ' // trim(caller_str) // ':'
warn_header = '==> Warning from ' // trim(caller_str) // ':'
note_header = '==> Note from ' // trim(caller_str) // ':'
! Set up the module if not already done
call g_tracer_get_common(isc, iec, jsc, jec, isd, ied, jsd, jed, nk, ntau, &
grid_tmask = grid_tmask)
!
!-----------------------------------------------------------------------
! Save depth integrals and fluxes
!-----------------------------------------------------------------------
!
k_int = 0
diag_initialized = .false.
do n = 1, num_instances
if (bling%id_po4_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_po4(:,:,:,tau), dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_po4_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_o2_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_o2(:,:,:,tau), dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_o2_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_dic_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_dic(:,:,:,tau), dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_dic_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_di14c_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_di14c(:,:,:,tau), dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_di14c_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%fe_is_prognostic) then
if (bling%id_fed_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_fed(:,:,:,tau), dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_fed_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
elseif (bling%fe_is_diagnostic) then
if (bling%id_fed_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_fed_diag, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_fed_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
else
if (bling%id_fed_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%f_fed, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_fed_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
endif
if (.not. bling%fe_is_prognostic) then
if (bling%id_fed_data_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%f_fed_data, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_fed_data_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
endif !}
if (bling%id_chl_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%f_chl, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_chl_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_biomass_p_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_biomass_p, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_biomass_p_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_phyto_lg_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_phyto_lg, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_phyto_lg_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_phyto_sm_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_phyto_sm, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_phyto_sm_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_irr_mem_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%p_irr_mem, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_irr_mem_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_jp_uptake_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%jp_uptake, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_jp_uptake_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_jp_recycle_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%jp_recycle, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_jp_recycle_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_jp_reminp_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%jp_reminp, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_jp_reminp_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_jpo4_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%jpo4, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_jpo4_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_jo2_depth .gt. 0) then
call g_tracer_column_int(bling%diag_depth, isd, jsd, bling%jo2, dzt, rho_dzt, &
bling%wrk_3d, k_int, bling%integral)
used = send_data(bling%id_jo2_depth, bling%integral, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
if (bling%id_fpop_depth .gt. 0) then
call g_tracer_flux_at_depth(bling%diag_depth, isd, jsd, bling%fpop, dzt, &
bling%k_lev, bling%wrk_2d, diag_initialized, bling%flux)
used = send_data(bling%id_fpop_depth, bling%flux, &
model_time, rmask = grid_tmask(:,:,1), is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif !}
enddo
!
!-----------------------------------------------------------------------
! Save surface prognostic variables for diagnostics, after vertical diffusion
!-----------------------------------------------------------------------
!
do n = 1, num_instances
if (bling%id_po4_surf .gt. 0) &
used = send_data(bling%id_po4_surf, bling%p_po4(:,:,1,tau), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_o2_surf .gt. 0) &
used = send_data(bling%id_o2_surf, bling%p_o2(:,:,1,tau), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_dic_surf .gt. 0) &
used = send_data(bling%id_dic_surf, bling%p_dic(:,:,1,tau), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_di14c_surf .gt. 0) &
used = send_data(bling%id_di14c_surf, bling%p_di14c(:,:,1,tau), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%fe_is_prognostic) then
if (bling%id_fed_surf .gt. 0) &
used = send_data(bling%id_fed_surf, bling%p_fed(:,:,1,tau), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
elseif (bling%fe_is_diagnostic) then
if (bling%id_fed_surf .gt. 0) &
used = send_data(bling%id_fed_surf, bling%p_fed_diag(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
else
if (bling%id_fed_surf .gt. 0) &
used = send_data(bling%id_fed_surf, bling%f_fed(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
endif
enddo
return
end subroutine generic_miniBLING_diag
!#######################################################################
! <SUBROUTINE NAME="generic_miniBLING_update_from_source">
! <OVERVIEW>
! Update tracer concentration fields due to the source/sink contributions.
! </OVERVIEW>
! <DESCRIPTION>
! This subroutine contains most of the biogeochemistry for calculating the
! interaction of the core set of tracers with each other and with outside forcings.
! Additional tracers (e.g. carbon, isotopes) are calculated in other subroutines.
! </DESCRIPTION>
! <TEMPLATE>
! call generic_miniBLING_update_from_source(tracer_list,Temp,Salt,dzt,hblt_depth,&
! ilb,jlb,tau,dtts, grid_dat,sw_pen,opacity)
! </TEMPLATE>
! <IN NAME="tracer_list" TYPE="type(g_tracer_type), pointer">
! Pointer to the head of generic tracer list.
! </IN>
! <IN NAME="ilb,jlb" TYPE="integer">
! Lower bounds of x and y extents of input arrays on data domain
! </IN>
! <IN NAME="Temp" TYPE="real, dimension(ilb:,jlb:,:)">
! Ocean temperature
! </IN>
! <IN NAME="Salt" TYPE="real, dimension(ilb:,jlb:,:)">
! Ocean salinity
! </IN>
! <IN NAME="dzt" TYPE="real, dimension(ilb:,jlb:,:)">
! Ocean layer thickness (meters)
! </IN>
! <IN NAME="opacity" TYPE="real, dimension(ilb:,jlb:,:)">
! Ocean opacity
! </IN>
! <IN NAME="sw_pen" TYPE="real, dimension(ilb:,jlb:)">
! Shortwave peneteration
! </IN>
! <IN NAME="hblt_depth" TYPE="real, dimension(ilb:,jlb:)">
!
! </IN>
! <IN NAME="grid_dat" TYPE="real, dimension(ilb:,jlb:)">
! Grid area
! </IN>
! <IN NAME="tau" TYPE="integer">
! Time step index of %field
! </IN>
! <IN NAME="dtts" TYPE="real">
! Time step increment
! </IN>
! </SUBROUTINE>
subroutine generic_miniBLING_update_from_source(tracer_list, Temp, Salt, &
rho_dzt, dzt, hblt_depth, ilb, jlb, tau, dtts, grid_dat, model_time, nbands, &
max_wavelength_band, sw_pen_band, opacity_band, grid_ht)
type(g_tracer_type), pointer, intent(inout) :: tracer_list
real, dimension(ilb:,jlb:,:), intent(in) :: Temp
real, dimension(ilb:,jlb:,:), intent(in) :: Salt
real, dimension(ilb:,jlb:,:), intent(in) :: rho_dzt
real, dimension(ilb:,jlb:,:), intent(in) :: dzt
real, dimension(ilb:,jlb:), intent(in) :: hblt_depth
real, dimension(ilb:,jlb:), intent(in) :: grid_ht
integer, intent(in) :: ilb
integer, intent(in) :: jlb
integer, intent(in) :: tau
real, intent(in) :: dtts
real, dimension(ilb:,jlb:), intent(in) :: grid_dat
type(time_type), intent(in) :: model_time
integer, intent(in) :: nbands
real, dimension(:), intent(in) :: max_wavelength_band
real, dimension(:,ilb:,jlb:), intent(in) :: sw_pen_band
real, dimension(:,ilb:,jlb:,:), intent(in) :: opacity_band
!-----------------------------------------------------------------------
! local parameters
character(len=fm_string_len), parameter :: sub_name = 'generic_miniBLING_update_from_source'
character(len=256) :: caller_str
character(len=256) :: error_header
character(len=256) :: warn_header
character(len=256) :: note_header
integer :: isc
integer :: iec
integer :: jsc
integer :: jec
integer :: isd
integer :: ied
integer :: jsd
integer :: jed
integer :: nk
integer :: ntau
integer :: i
integer :: j
integer :: k
integer :: kblt
integer :: n
real, dimension(:,:,:), pointer :: grid_tmask
integer, dimension(:,:), pointer :: grid_kmt
logical :: used
integer :: nb
real :: tmp_hblt
real :: tmp_Irrad
real :: tmp_irrad_ML
real :: tmp_phyto_lg_ML
real :: tmp_phyto_sm_ML
real :: tmp_opacity
real, dimension(:), Allocatable :: tmp_irr_band
real :: s_over_p
! Set up the headers for stdout messages.
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')[]'
error_header = '==>Error from ' // trim(caller_str) // ':'
warn_header = '==>Warning from ' // trim(caller_str) // ':'
note_header = '==>Note from ' // trim(caller_str) // ':'
! Set up the module if not already done
call g_tracer_get_common(isc, iec, jsc, jec, isd, ied, jsd, jed, nk, ntau, &
grid_tmask = grid_tmask, grid_kmt = grid_kmt)
! SURFACE GAS FLUXES
!
! This subroutine coordinates the calculation of gas concentrations and solubilities
! in the surface layer. The concentration of a gas is written as csurf, while the
! solubility (in mol kg-1 atm-1 or mol m-3 atm-1) is written as alpha. These two
! quantities are passed to the coupler, which multiplies their difference by the
! gas exchange piston velocity over the mixed layer depth to provide the gas
! exchange flux,
! Flux = Kw/dz * (alpha - csurf)
!
! For CO2 and 14CO2, the carbon solubility and speciation are calculated by the
! subroutine co2calc, following the OCMIP2 protocol. These calculations are both made
! using total CO2, following which the surface CO2 concentration (CO2*, also known as
! H2CO3*) is scaled by the DI14C/DIC ratio to give the surface 14CO2 concentration.
! The speciation calculation uses in situ temperature, salinity, and PO4.
!
!
! Oxygen solubility is calculated here, using in situ temperature and salinity.
!---------------------------------------------------------------------
! Get positive tracer concentrations for carbon calculation
!---------------------------------------------------------------------
allocate(tmp_irr_band(nbands))
do n = 1, num_instances
bling%zbot = 0.0
s_over_p = 0.0
!---------------------------------------------------------------------
! Get positive concentrations for prognostic tracers
!---------------------------------------------------------------------
call g_tracer_get_values(tracer_list, 'po4' // bling%suffix, 'field', bling%f_po4, isd, jsd, &
ntau = tau, positive = .true.)
if (bling%fe_is_prognostic) then
call g_tracer_get_values(tracer_list, 'fed' // bling%suffix, 'field', bling%f_fed, isd, jsd, &
ntau = tau, positive = .true.)
else
call data_override('OCN', 'fed_data' // trim(bling%suffix), bling%f_fed_data, model_time)
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%f_fed_data(i,j,k) = &
max(bling%f_fed_data(i,j,k), &
bling%fe_coastal * (1.0 - grid_ht(i,j)/bling%fe_coastal_depth)) * grid_tmask(i,j,k)
enddo !} i
enddo !} j
enddo !} k
if (bling%fe_is_diagnostic) then
call g_tracer_get_values(tracer_list, 'fed' // bling%suffix, 'field', bling%f_fed, isd, jsd, &
positive = .true.)
else
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%f_fed(i,j,k) = bling%f_fed_data(i,j,k)
enddo !} i
enddo !} j
enddo !} k
endif
endif
call g_tracer_get_values(tracer_list, 'o2' // bling%suffix, 'field', bling%f_o2, isd, jsd, &
ntau = tau, positive = .true.)
!---------------------------------------------------------------------
! Assign pointers for diagnostic tracers
!---------------------------------------------------------------------
if (bling%biomass_type .eq. 'single') then
call g_tracer_get_pointer(tracer_list,'biomass_p' // bling%suffix,'field',bling%p_biomass_p)
elseif (bling%biomass_type .eq. 'lg_sm_phyto') then
call g_tracer_get_pointer(tracer_list,'phyto_lg'// bling%suffix,'field',bling%p_phyto_lg)
call g_tracer_get_pointer(tracer_list,'phyto_sm'// bling%suffix,'field',bling%p_phyto_sm)
endif
call g_tracer_get_pointer(tracer_list,'irr_mem' // bling%suffix,'field',bling%p_irr_mem)
if (bling%do_carbon) then !<<CARBON CYCLE
call g_tracer_get_pointer(tracer_list, 'htotal' // bling%suffix, 'field', bling%p_htotal)
call g_tracer_get_pointer(tracer_list, 'dic' // bling%suffix, 'field', bling%p_dic)
!---------------------------------------------------------------------
! Calculate co2 fluxes csurf and alpha for the next round of exchange
! Note a scaled value of the PO4, rather than SiOH3, is used for all
! calculations since there is no prognostic silica cycle.
! Alkalinity is calculated from salinity, since there is no prognostic
! alkalinity cycle.
!---------------------------------------------------------------------
k=1
do j = jsc, jec
do i = isc, iec
bling%htotallo(i,j) = bling%htotal_scale_lo * bling%p_htotal(i,j,k)
bling%htotalhi(i,j) = bling%htotal_scale_hi * bling%p_htotal(i,j,k)
enddo !} i
enddo !} j
do j = jsc, jec !{
do i = isc, iec !{
bling%surf_temp(i,j) = Temp(i,j,k)
bling%surf_salt(i,j) = Salt(i,j,k)
bling%surf_po4(i,j) = bling%f_po4(i,j,k)
bling%surf_sio4(i,j) = bling%f_po4(i,j,k)
bling%surf_dic(i,j) = bling%p_dic(i,j,k,tau)
enddo !} i
enddo !} j
! Optionally override surface values used in the gas exchange calculations
! Note that the data_override routine wants the array to be over the computational grid,
! so we need to pass only that part of the array (the arrays must be dimensioned on the data
! domain, as that is what is needed for the co2calc routine). Also note that we only call the
! data_override routine if we are actually overriding to avoid the implicit array copies implied
! by passing a sub-array into and out of the subroutine.
!
! There could be a problem with this scheme if the halo region values are actually used, as these may
! be inconsistent with the overridden values on adjacent processors. I do not believe that this is
! problem, however. -- Richard Slater (2012-02-07)
if (bling%override_surf_temp) then
call data_override('OCN', 'temp_co2_flux' // trim(bling%suffix),bling%surf_temp(isc:iec,jsc:jec),&
model_time, override = bling%override_surf_temp)
endif
if (bling%override_surf_salt) then
call data_override('OCN', 'salt_co2_flux' // trim(bling%suffix),bling%surf_salt(isc:iec,jsc:jec),&
model_time, override = bling%override_surf_salt)
endif
if (bling%override_surf_alk) then
call data_override('OCN', 'alk_co2_flux' // trim(bling%suffix),bling%surf_alk(isc:iec,jsc:jec), &
model_time, override = bling%override_surf_alk)
endif
if (bling%override_surf_po4) then
call data_override('OCN', 'po4_co2_flux' // trim(bling%suffix),bling%surf_po4(isc:iec,jsc:jec), &
model_time, override = bling%override_surf_po4)
endif
if (bling%override_surf_sio4) then
call data_override('OCN', 'sio4_co2_flux' // trim(bling%suffix),bling%surf_sio4(isc:iec,jsc:jec),&
model_time, override = bling%override_surf_sio4)
endif
if (bling%override_surf_dic) then
call data_override('OCN', 'dic_co2_flux' // trim(bling%suffix),bling%surf_dic(isc:iec,jsc:jec), &
model_time, override = bling%override_surf_dic)
endif
if (.not. bling%override_surf_alk) then
!
! Calculate the surface alkalinity if not overridden above
!
if (bling%alk_scheme .eq. 'normal') then
do j = jsc, jec !{
do i = isc, iec !{
! This is an ad hoc regression, eyeballed from GLODAP vs WOA in ferret, to give ALK from salinity.
! Intercept is large, to keep the Southern Ocean alkalinity close to obs. Note this makes
! the gyres low alkalinity, which will lead to outgassing there.
! Would probably be better to use an ALK/salinity map instead.
bling%surf_alk(i,j) = Salt(i,j,1) * bling%alk_slope + bling%alk_intercept
enddo !} i
enddo !} j
elseif (bling%alk_scheme .eq. 'ratios') then
call data_override('OCN', 'surf_alk' // trim(bling%suffix), bling%surf_alk(isc:iec,jsc:jec), model_time)
do j = jsc, jec !{
do i = isc, iec !{
! Use a map of the ratios of alkalinity to salinity and a constant intercept
! For this method, we use the data_override value for surf_alk to set the slopes
bling%surf_alk(i,j) = Salt(i,j,1) * bling%surf_alk(i,j) + bling%alk_intercept
enddo !} i
enddo !} j
elseif (bling%alk_scheme .eq. 'intercepts') then
call data_override('OCN', 'surf_alk' // trim(bling%suffix), bling%surf_alk(isc:iec,jsc:jec), model_time)
do j = jsc, jec !{
do i = isc, iec !{
! Use a map of the intercepts of alkalinity to salinity and a constant slope
! For this method, we use the data_override value for surf_alk to set the intercepts
bling%surf_alk(i,j) = Salt(i,j,1) * bling%alk_slope + bling%surf_alk(i,j)
enddo !} i
enddo !} j
else
call mpp_error(FATAL, trim(error_header) // &
' Illegal alk_scheme (' // trim(bling%alk_scheme) // ') for instance ' // trim(bling%name))
endif
endif
call FMS_ocmip2_co2calc(CO2_dope_vec, grid_tmask(:,:,k), &
bling%surf_temp(:,:), bling%surf_salt(:,:), &
bling%surf_dic(:,:), &
bling%surf_po4(:,:), &
bling%surf_sio4(:,:), &
bling%surf_alk(:,:), &
bling%htotallo, bling%htotalhi, &
!InOut
bling%p_htotal(:,:,k), &
!OUT
co2star=bling%co2_csurf(:,:), &
alpha=bling%co2_alpha(:,:), &
pCO2surf=bling%pco2_surf(:,:))
call g_tracer_set_values(tracer_list,'dic' // bling%suffix,'alpha',bling%co2_alpha ,isd,jsd)
call g_tracer_set_values(tracer_list,'dic' // bling%suffix,'csurf',bling%co2_csurf ,isd,jsd)
if (bling%do_14c) then !<<RADIOCARBON
call g_tracer_get_pointer(tracer_list,'di14c' // bling%suffix ,'field', bling%p_di14c)
do j = jsc, jec
do i = isc, iec
! The surface p14CO2* concentration is calculated by scaling the total CO2* by the
! surface water 14C/12C.
bling%c14o2_csurf(i,j) = bling%co2_csurf(i,j) * &
bling%p_di14c(i,j,1,tau) / (bling%p_dic(i,j,1,tau) + epsln)
! Alpha is here the same as co2. The air-sea flux depends on the atmospheric
! p14CO2 given in the data table entry (which may vary over time, reflecting
! both changes in atmospheric pCO2 and D14CO2).
bling%c14o2_alpha(i,j) = bling%co2_alpha(i,j)
enddo !} i
enddo !} j
call g_tracer_set_values(tracer_list,'di14c' // bling%suffix,'alpha',bling%c14o2_alpha ,isd,jsd)
call g_tracer_set_values(tracer_list,'di14c' // bling%suffix,'csurf',bling%c14o2_csurf ,isd,jsd)
endif !RADIOCARBON>>
endif !CARBON CYCLE>>
!--------------------------------------------------------------------------
! NUTRIENT UPTAKE
!--------------------------------------------------------------------------
! Available light calculation
!-----------------------------------------------------------------------
! There are multiple types of light.
! irr_inst is the instantaneous irradiance field.
! irr_mix is the same, but with the irr_inst averaged throughout the
! mixed layer as defined in the KPP routine plus one more vertical box
! to account for mixing directly below the boundary layer. This quantity
! is intended to represent the light to which phytoplankton subject to
! turbulent transport in the mixed-layer would be exposed.
! irr_mem is a temporally smoothed field carried between timesteps, to
! represent photoadaptation.
!-----------------------------------------------------------------------
if (bling%biomass_type .eq. 'single') then
do j = jsc, jec
do i = isc, iec
do nb = 1,nbands
if (max_wavelength_band(nb) .lt. 710) then
tmp_irr_band(nb) = max(0.0,sw_pen_band(nb,i,j))
else
tmp_irr_band(nb) = 0.0
endif
enddo !} nbands
kblt = 0
tmp_irrad_ML = 0.0
tmp_hblt = 0.0
do k = 1, nk
tmp_Irrad = 0.0
do nb = 1,nbands
tmp_opacity = opacity_band(nb,i,j,k)
tmp_Irrad = tmp_Irrad + tmp_irr_band(nb) * exp(-tmp_opacity * dzt(i,j,k) * 0.5)
! Change tmp_irr_band from being the value atop layer k to the value at the bottom of layer k.
tmp_irr_band(nb) = tmp_irr_band(nb) * exp(-tmp_opacity * dzt(i,j,k))
enddo !} nbands
bling%irr_inst(i,j,k) = tmp_Irrad * grid_tmask(i,j,k)
bling%irr_mix(i,j,k) = tmp_Irrad * grid_tmask(i,j,k)
if ((k == 1) .or. (tmp_hblt .lt. hblt_depth(i,j))) then
kblt = kblt+1
tmp_irrad_ML = tmp_irrad_ML + bling%irr_mix(i,j,k) * dzt(i,j,k)
tmp_hblt = tmp_hblt + dzt(i,j,k)
endif
enddo !} k
bling%irr_mix(i,j,1:kblt) = tmp_irrad_ML / max(1.0e-6,tmp_hblt)
enddo !} i
enddo !} j
elseif (bling%biomass_type .eq. 'lg_sm_phyto') then
do j = jsc, jec
do i = isc, iec
do nb = 1,nbands
if (max_wavelength_band(nb) .lt. 710) then
tmp_irr_band(nb) = max(0.0,sw_pen_band(nb,i,j))
else
tmp_irr_band(nb) = 0.0
endif
enddo !} nbands
kblt = 0
tmp_irrad_ML = 0.0
tmp_phyto_lg_ML = 0.0
tmp_phyto_sm_ML = 0.0
tmp_hblt = 0.0
do k = 1, nk
tmp_Irrad = 0.0
do nb = 1,nbands
tmp_opacity = opacity_band(nb,i,j,k)
tmp_Irrad = tmp_Irrad + tmp_irr_band(nb) * exp(-tmp_opacity * dzt(i,j,k) * 0.5)
! Change tmp_irr_band from being the value atop layer k to the value at the bottom of layer k.
tmp_irr_band(nb) = tmp_irr_band(nb) * exp(-tmp_opacity * dzt(i,j,k))
enddo !} nbands
bling%irr_inst(i,j,k) = tmp_Irrad * grid_tmask(i,j,k)
bling%irr_mix(i,j,k) = tmp_Irrad * grid_tmask(i,j,k)
if ((k == 1) .or. (tmp_hblt .lt. hblt_depth(i,j))) then
kblt = kblt+1
tmp_irrad_ML = tmp_irrad_ML + bling%irr_mix(i,j,k) * dzt(i,j,k)
tmp_phyto_lg_ML = tmp_phyto_lg_ML + bling%p_phyto_lg(i,j,k) * dzt(i,j,k)
tmp_phyto_sm_ML = tmp_phyto_sm_ML + bling%p_phyto_sm(i,j,k) * dzt(i,j,k)
tmp_hblt = tmp_hblt + dzt(i,j,k)
endif
enddo !} k
bling%irr_mix(i,j,1:kblt) = tmp_irrad_ML / max(1.0e-6,tmp_hblt)
bling%p_phyto_lg(i,j,1:kblt) = tmp_phyto_lg_ML / max(1.0e-6,tmp_hblt)
bling%p_phyto_lg(i,j,1:kblt) = tmp_phyto_sm_ML / max(1.0e-6,tmp_hblt)
enddo !} i
enddo !} j
endif
do k = 1, nk
do j = jsc, jec
do i = isc, iec
!--------------------------------------------------------------------
! Phytoplankton photoadaptation. This represents the fact that phytoplankton cells are
! adapted to the averaged light field to which they've been exposed over their lifetimes,
! rather than the instantaneous light. The timescale is set by gamma_irr_mem.
bling%p_irr_mem(i,j,k) = (bling%p_irr_mem(i,j,k) + &
(bling%irr_mix(i,j,k) - bling%p_irr_mem(i,j,k)) * min( 1.0 , &
bling%gamma_irr_mem * dtts)) * grid_tmask(i,j,k)
!--------------------------------------------------------------------
! Temperature functionality of growth and grazing
! NB The temperature effect of Eppley (1972) is used instead
! of that in Geider et al (1997) for both simplicity and
! to incorporate combined effects on uptake, incorporation
! into organic matter and photorespiration. Values of PCmax
! are normalized to 0C rather than 20C in Geider et al. (1997)
bling%expkT(i,j,k) = exp(bling%kappa_eppley * Temp(i,j,k))
enddo !} i
enddo !} j
enddo !} k
!-----------------------------------------------------------------------
! Phytoplankton are assumed to grow according to the general properties
! described in Geider (1997). This formulation gives a biomass-specific
! growthrate as a function of light, nutrient limitation, and
! temperature. We modify this relationship slightly here, as described
! below, and also use the assumption of steady state growth vs. loss to
! derive a simple relationship between growth rate, biomass and uptake.
!
!-----------------------------------------------------------------------
! First, we calculate the limitation terms for PO4 and Fe, and the
! Fe-limited Chl:C maximum.
! The light-saturated maximal photosynthesis rate term (pc_m) is simply
! the product of a prescribed maximal photosynthesis rate (pc_0), the
! Eppley temperature dependence, and a Liebig limitation (the minimum
! of Michaelis-Menton PO4-limitation, or iron-limitation). The iron
! limitation term is scaled by (k_fe_2_p + fe_2_p_max) / fe_2_p_max
! so that it approaches 1 as fed approaches infinity. Thus,
! it's of comparable magnitude to the PO4 limitation term.
!
! Fe limitation acts by reducing the maximum achievable Chl:C ratio
! (theta) below a prescribed, Fe-replete maximum value (thetamax), to
! approach a prescribed minimum Chl:C (thetamin) under extreme
! Fe-limitation.
!-----------------------------------------------------------------------
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%fe_2_p_uptake(i,j,k) = bling%fe_2_p_max * &
bling%f_fed(i,j,k) / (bling%k_fe_uptake + bling%f_fed(i,j,k))
bling%def_fe(i,j,k) = max(bling%def_fe_min, &
(bling%fe_2_p_uptake(i,j,k) / &
(bling%k_fe_2_p + bling%fe_2_p_uptake(i,j,k)) * &
(bling%k_fe_2_p + bling%fe_2_p_max) / bling%fe_2_p_max))
bling%pc_m(i,j,k) = bling%pc_0 * bling%expkT(i,j,k) * min( &
max(0.,((bling%f_po4(i,j,k) - bling%po4_min) / &
(bling%k_po4 + bling%f_po4(i,j,k) - bling%po4_min))) , &
bling%def_fe(i,j,k))
bling%thetamax_fe(i,j,k) = bling%thetamax_lo + &
(bling%thetamax_hi - bling%thetamax_lo) * bling%def_fe(i,j,k)
!-----------------------------------------------------------------------
! Next, the nutrient-limited efficiency of algal photosystems, Irrk, is
! calculated. This requires a prescribed quantum yield, alpha.
! The iron deficiency term is included here as a multiplier of the
! thetamax_fe to represent the importance of Fe in forming chlorophyll
! accessory antennae, which do not affect the Chl:C but still affect the
! phytoplankton ability to use light (eg Stzrepek & Harrison Nature
! 2004).
bling%irrk(i,j,k) = (bling%pc_m(i,j,k) / ( epsln + &
bling%alpha_photo * bling%thetamax_fe(i,j,k) )) + &
bling%p_irr_mem(i,j,k) * 0.5
!-----------------------------------------------------------------------
! We also calculate the Chl:C ratio here, although it does not enter
! into the uptake calculation and is only used for the diagnostic
! chlorophyll concentration, below.
bling%theta(i,j,k) = bling%thetamax_fe(i,j,k) / (1. + &
bling%thetamax_fe(i,j,k) * bling%alpha_photo * &
bling%p_irr_mem(i,j,k) / (epsln + 2. * bling%pc_m(i,j,k)))
!-----------------------------------------------------------------------
! Now we can calculate the carbon-specific photosynthesis rate, mu.
bling%mu(i,j,k) = bling%pc_m(i,j,k) * &
(1. - exp(-bling%irr_mix(i,j,k) / (epsln + bling%irrk(i,j,k))))
enddo !} i
enddo !} j
enddo !} k
!-----------------------------------------------------------------------
! We now must convert this net carbon-specific growth rate to nutrient
! uptake rates, the quantities we are interested in. Since we have no
! explicit biomass tracer, we use the result of Dunne et al. (GBC, 2005)
! to calculate an implicit biomass from the uptake rate through the
! application of a simple idealized grazing law. This has the effect of
! reducing uptake in low growth-rate regimes and increasing uptake in
! high growth-rate regimes - essentially a non-linear amplification of
! the growth rate variability. The result is:
if (bling%biomass_type .eq. 'single') then
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%biomass_p_ts(i,j,k) = &
((bling%mu(i,j,k)/(bling%lambda0 * bling%expkT(i,j,k)))**3 &
+ (bling%mu(i,j,k)/(bling%lambda0 * bling%expkT(i,j,k)))) &
* bling%p_star
bling%p_biomass_p(i,j,k) = bling%p_biomass_p(i,j,k) + &
(bling%biomass_p_ts(i,j,k) - bling%p_biomass_p(i,j,k)) * &
min(1.0, bling%gamma_biomass * dtts) * grid_tmask(i,j,k)
bling%jp_uptake(i,j,k) = bling%p_biomass_p(i,j,k) * &
bling%mu(i,j,k)
! We can now use the diagnostic biomass to calculate the chlorophyll
! concentration:
bling%f_chl(i,j,k) = max(bling%chl_min, bling%p_biomass_p(i,j,k) &
* bling%c_2_p * 12.011e6 * bling%theta(i,j,k)) * &
grid_tmask(i,j,k)
! As a helpful diagnostic, the implied fraction of production by large
! phytoplankton is calculated, also following Dunne et al. 2005. This
! could be done more simply, but is done here in a complicated way as
! a sanity check. Note the calculation is made in P units, rather than C.
s_over_p = ( -1. + ( 1. + 4. * bling%jp_uptake(i,j,k) / &
(bling%expkT(i,j,k) * bling%lambda0 * bling%p_star))**0.5) * .5
bling%frac_lg(i,j,k) = s_over_p / (1 + s_over_p)
enddo !} i
enddo !} j
enddo !} k
elseif (bling%biomass_type .eq. 'lg_sm_phyto') then
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%jp_uptake(i,j,k) = bling%mu(i,j,k) * &
(bling%p_phyto_lg(i,j,k) + bling%p_phyto_sm(i,j,k))
enddo !} i
enddo !} j
enddo !} k
endif
!-----------------------------------------------------------------------
! Iron is then taken up as a function of PO4 uptake and iron limitation,
! with a maximum Fe:P uptake ratio of fe2p_max:
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%jfe_uptake(i,j,k) = bling%jp_uptake(i,j,k) * &
bling%fe_2_p_uptake(i,j,k)
enddo !} i
enddo !} j
enddo !} k
!-------------------------------------------------------------------------
! PARTITIONING BETWEEN ORGANIC POOLS
!-------------------------------------------------------------------------
! The uptake of nutrients is assumed to contribute to the growth of
! phytoplankton, which subsequently die and are consumed by heterotrophs.
! This can involve the transfer of nutrient elements between many
! organic pools, both particulate and dissolved, with complex histories.
! We take a simple approach here, partitioning the total uptake into two
! fractions - sinking and non-sinking - as a function of temperature,
! following Dunne et al. (2005).
! The non-sinking fraction is recycled instantaneously to the inorganic
! nutrient pool,
! representing the fast turnover of labile dissolved organic matter via
! the microbial loop, and the remainder is converted to semi-labile
! dissolved organic matter. Iron and phosphorus are treated identically
! for the first step, but all iron is recycled instantaneously in the
! second step (i.e. there is no dissolved organic iron pool).
!-------------------------------------------------------------------------
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%frac_pop(i,j,k) = max((bling%phi_sm + bling%phi_lg * &
(bling%mu(i,j,k)/(bling%lambda0*bling%expkT(i,j,k)))**2.)/ &
(1. + (bling%mu(i,j,k)/(bling%lambda0*bling%expkT(i,j,k)))**2.)* &
exp(bling%kappa_remin * Temp(i,j,k)) * &
! Experimental! Reduce frac_pop under strong PO4 limitation
bling%f_po4(i,j,k) / (bling%k_po4_recycle + bling%f_po4(i,j,k)), &
bling%min_frac_pop)
bling%jpop(i,j,k) = bling%frac_pop(i,j,k) * bling%jp_uptake(i,j,k)
! Whatever isn't converted to sinking particulate is recycled to the dissolved pool.
bling%jp_recycle(i,j,k) = bling%jp_uptake(i,j,k) - &
bling%jpop(i,j,k)
enddo !] i
enddo !} j
enddo !} k
if (bling%biomass_type .eq. 'lg_sm_phyto') then
do k = 1, nk
do j = jsc, jec
do i = isc, iec
! Finally, update the biomass of total phytoplankton, and of diazotrophs.
! Use this to solve the Dunne et al. 2005 mortality term, with alpha=1/3 (eq. 5b).
! Then, add this to the pre-exisiting phytoplankton biomass and the total uptake to give
bling%p_phyto_lg(i,j,k) = bling%p_phyto_lg(i,j,k) + &
bling%p_phyto_lg(i,j,k) * (bling%mu(i,j,k) - &
bling%lambda0 * bling%expkT(i,j,k) * &
(bling%p_phyto_lg(i,j,k) / bling%p_star)**(1./3.) ) * dtts * grid_tmask(i,j,k)
bling%p_phyto_sm(i,j,k) = bling%p_phyto_sm(i,j,k) + &
bling%p_phyto_sm(i,j,k) * (bling%mu(i,j,k) - &
bling%lambda0 * bling%expkT(i,j,k) * &
(bling%p_phyto_sm(i,j,k) / bling%p_star) ) * dtts * grid_tmask(i,j,k)
bling%frac_lg(i,j,k) = bling%p_phyto_lg(i,j,k) / &
(epsln + bling%p_phyto_lg(i,j,k)+bling%p_phyto_sm(i,j,k))
! Calculate the chlorophyll concentration:
bling%f_chl(i,j,k) = max(bling%chl_min, &
bling%c_2_p * 12.011e6 * bling%theta(i,j,k) * &
(bling%p_phyto_lg(i,j,k) + bling%p_phyto_sm(i,j,k))) * grid_tmask(i,j,k)
enddo !] i
enddo !} j
enddo !} k
endif
!
! perform recycling, as above, for the prognostic Fed tracer
!
if (bling%fe_is_prognostic) then
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%jfeop(i,j,k) = bling%frac_pop(i,j,k)*bling%jfe_uptake(i,j,k)
bling%jfe_recycle(i,j,k) = bling%jfe_uptake(i,j,k) - &
bling%jfeop(i,j,k)
enddo !] i
enddo !} j
enddo !} k
endif
!-------------------------------------------------------------------------
! SINKING AND REMINERALIZATION
!-------------------------------------------------------------------------
! Calculate the depth of each grid cell (needs to be 3d for use with
! isopycnal co-ordinate model).
do j = jsc, jec
do i = isc, iec
bling%zbot(i,j,1) = dzt(i,j,1)
enddo !} i
enddo !} j
do k = 2, nk
do j = jsc, jec
do i = isc, iec
bling%zbot(i,j,k) = bling%zbot(i,j,k-1) + dzt(i,j,k)
enddo !} i
enddo !} j
enddo !} k
!-----------------------------------------------------------------------
! Calculate the remineralization lengthscale matrix, zremin, a function
! of z. Sinking rate (wsink) is constant over the upper wsink0_z metres,
! then increases linearly with depth.
! The remineralization rate is a function of oxygen concentrations,
! to slow remineralization under suboxia/anoxia. The remineralization rate
! approaches the remin_min as O2 approaches O2 min.
do k = 1, nk
do j = jsc, jec
do i = isc, iec
if (bling%zbot(i,j,k) .lt. bling%wsink0_z) then
bling%wsink(i,j,k) = bling%wsink0
else
bling%wsink(i,j,k) = (bling%wsink_acc * (bling%zbot(i,j,k) - &
bling%wsink0_z) + bling%wsink0)
endif
bling%zremin(i,j,k) = bling%gamma_pop * (bling%f_o2(i,j,k) / &
(bling%k_o2 + bling%f_o2(i,j,k)) * (1. - bling%remin_min)+ &
bling%remin_min) / (bling%wsink(i,j,k) + epsln)
enddo !} i
enddo !} j
enddo !} k
if (bling%do_carbon) then !<<CARBON CYCLE
if (bling%do_14c) then !<<RADIOCARBON
! Sinking particulate 14C is generated in the local ratio of 14C/12C
! to sinking 12C, which itself is strictly tied to P through a fixed
! C:P. Therefore, jpop can be used to calculate fpo14c.
do j = jsc, jec
do i = isc, iec
bling%c14_2_p(i,j,1) = bling%c_2_p * &
bling%p_di14c(i,j,1,tau) / (epsln + bling%p_dic(i,j,1,tau))
bling%fpo14c(i,j,1) = bling%jpop(i,j,1) * bling%c14_2_p(i,j,1) * &
rho_dzt(i,j,1) / (1.0 + dzt(i,j,1) * bling%zremin(i,j,1))
bling%j14c_reminp(i,j,1) = (bling%jpop(i,j,1) * &
bling%c14_2_p(i,j,1) * rho_dzt(i,j,1) - bling%fpo14c(i,j,1)) / &
(epsln + rho_dzt(i,j,1))
enddo !} i
enddo !} j
do k = 2, nk
do j = jsc, jec
do i = isc, iec
bling%fpo14c(i,j,k) = (bling%fpo14c(i,j,k-1) + &
bling%jpop(i,j,k) * bling%c14_2_p(i,j,k) * rho_dzt(i,j,k)) / &
(1.0 + dzt(i,j,k) * bling%zremin(i,j,k))
bling%j14c_reminp(i,j,k) = (bling%fpo14c(i,j,k-1) + &
bling%jpop(i,j,k) * bling%c14_2_p(i,j,k) * rho_dzt(i,j,k) - &
bling%fpo14c(i,j,k)) / (epsln + rho_dzt(i,j,k))
enddo !} i
enddo !} j
enddo !} k
! Decay the radiocarbon in DIC
bling%lambda_14c = log(2.0) / (bling%half_life_14c * spery)
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%j14c_decay_dic(i,j,k) = bling%p_di14c(i,j,k,tau) * &
bling%lambda_14c
enddo !} i
enddo !} j
enddo !} k
endif !RADIOCARBON>>
endif !CARBON CYCLE>>
if (bling%fe_is_prognostic) then
do k = 1, nk
do j = jsc, jec
do i = isc, iec
!---------------------------------------------------------------------
! Calculate free and inorganically associated iron concentration for
! scavenging.
! We assume that there is a
! spectrum of iron ligands present in seawater, with varying binding
! strengths and whose composition varies with light and iron
! concentrations. For example, photodissocation of ligand complexes
! occurs under bright light, weakening the binding strength
! (e.g. Barbeau et al., Nature 2001), while at very low iron
! concentrations (order kfe_eq_lig_femin), siderophores are thought
! to be produced as a response to extreme iron stress.
! In anoxic waters, iron should be reduced, and therefore mostly
! immune to scavenging. Easiest way to do this is to skip the feprime
! calculation if oxygen is less than 0.
if (bling%f_o2(i,j,k) .gt. bling%o2_min) then
bling%kfe_eq_lig(i,j,k) = bling%kfe_eq_lig_max - &
(bling%kfe_eq_lig_max - bling%kfe_eq_lig_min) * &
(bling%irr_inst(i,j,k)**2. / (bling%irr_inst(i,j,k)**2. + &
bling%kfe_eq_lig_irr **2.)) * max(0., min(1., (bling%f_fed(i,j,k) - &
bling%kfe_eq_lig_femin) / (epsln + bling%f_fed(i,j,k)) * 1.2))
bling%feprime(i,j,k) = 1.0 + bling%kfe_eq_lig(i,j,k) * &
(bling%felig_bkg - bling%f_fed(i,j,k))
bling%feprime(i,j,k) = (-bling%feprime(i,j,k) +(bling%feprime(i,j,k)* &
bling%feprime(i,j,k) + 4.0 * bling%kfe_eq_lig(i,j,k) * &
bling%f_fed(i,j,k))**(0.5)) /(2.0 * bling%kfe_eq_lig(i,j,k))
else !}{
bling%feprime(i,j,k) = 0.
endif !}
bling%jfe_ads_inorg(i,j,k) = min(0.5/dtts, bling%kfe_inorg * &
bling%feprime(i,j,k) ** 0.5) * bling%feprime(i,j,k)
enddo !} i
enddo !} j
enddo !} k
endif
!---------------------------------------------------------------------
! In general, the flux at the bottom of a grid cell should equal
! Fb = (Ft + Prod*dz) / (1 + zremin*dz)
! where Ft is the flux at the top, and prod*dz is the integrated
! production of new sinking particles within the layer.
! Since Ft=0 in the first layer,
do j = jsc, jec
do i = isc, iec
bling%fpop(i,j,1) = bling%jpop(i,j,1) * rho_dzt(i,j,1) / &
(1.0 + dzt(i,j,1) * bling%zremin(i,j,1))
!-----------------------------------------------------------------------
! Calculate remineralization terms
bling%jp_reminp(i,j,1) = &
(bling%jpop(i,j,1) * rho_dzt(i,j,1) - bling%fpop(i,j,1)) / &
(epsln + rho_dzt(i,j,1))
enddo !} i
enddo !} j
!-----------------------------------------------------------------------
! Then, for the rest of water column, include flux from above:
do k = 2, nk
do j = jsc, jec
do i = isc, iec
bling%fpop(i,j,k) = (bling%fpop(i,j,k-1) + &
bling%jpop(i,j,k) * rho_dzt(i,j,k)) / &
(1.0 + dzt(i,j,k) * bling%zremin(i,j,k))
!---------------------------------------------------------------------
! Calculate remineralization terms
bling%jp_reminp(i,j,k) = (bling%fpop(i,j,k-1) + &
bling%jpop(i,j,k) * rho_dzt(i,j,k) - bling%fpop(i,j,k)) / &
(epsln + rho_dzt(i,j,k))
enddo !} i
enddo !} j
enddo !} k
!---------------------------------------------------------------------
! BOTTOM LAYER
! Account for remineralization in bottom box, and bottom fluxes
do j = jsc, jec
do i = isc, iec
k = grid_kmt(i,j)
if (k .gt. 0) then
!---------------------------------------------------------------------
! Calculate external bottom fluxes for tracer_vertdiff. Positive fluxes
! are from the water column into the seafloor. For P, the bottom flux
! puts the sinking flux reaching the bottom cell into the water column
! through diffusion.
! For oxygen, the consumption of oxidant required to respire
! the settling flux of organic matter (in support of the
! PO4 bottom flux) diffuses from the bottom water into the sediment.
bling%b_po4(i,j) = - bling%fpop(i,j,k)
if (bling%f_o2(i,j,k) .gt. bling%o2_min) then
bling%b_o2(i,j) = bling%o2_2_p * bling%fpop(i,j,k)
else
bling%b_o2(i,j) = 0.0
endif
endif
enddo !} i
enddo !} j
if (bling%fe_is_prognostic) then
do j = jsc, jec
do i = isc, iec
!-----------------------------------------------------------------------
! Now, calculate the Fe adsorption using this fpop:
! The absolute first order rate constant is calculated from the
! concentration of organic particles, after Parekh et al. (2005). Never
! allowed to be greater than 1/2dt for numerical stability.
bling%jfe_ads_org(i,j,1) = min (0.5/dtts, &
bling%kfe_org * (bling%fpop(i,j,1) / (epsln + bling%wsink(i,j,1)) * &
bling%mass_2_p) ** 0.58) * bling%feprime(i,j,1)
bling%fpofe(i,j,1) = (bling%jfeop(i,j,1) +bling%jfe_ads_inorg(i,j,1) &
+ bling%jfe_ads_org(i,j,1)) * rho_dzt(i,j,1) / &
(1.0 + dzt(i,j,1) * bling%zremin(i,j,1))
!-----------------------------------------------------------------------
! Calculate remineralization terms
bling%jfe_reminp(i,j,1) = &
((bling%jfeop(i,j,1) + bling%jfe_ads_org(i,j,1) + &
bling%jfe_ads_inorg(i,j,1)) * rho_dzt(i,j,1) - &
bling%fpofe(i,j,1)) / (epsln + rho_dzt(i,j,1))
enddo !} i
enddo !} j
!-----------------------------------------------------------------------
! Then, for the rest of water column, include flux from above:
do k = 2, nk
do j = jsc, jec
do i = isc, iec
!-----------------------------------------------------------------------
! Again, calculate the Fe adsorption using this fpop:
bling%jfe_ads_org(i,j,k) = min (0.5/dtts, bling%kfe_org * &
(bling%fpop(i,j,k) / (epsln + bling%wsink(i,j,k)) * &
bling%mass_2_p) ** 0.58) * bling%feprime(i,j,k)
bling%fpofe(i,j,k) = (bling%fpofe(i,j,k-1) + &
(bling%jfe_ads_org(i,j,k) + bling%jfe_ads_inorg(i,j,k) + &
bling%jfeop(i,j,k)) *rho_dzt(i,j,k)) / &
(1.0 + dzt(i,j,k) * bling%zremin(i,j,k))
!---------------------------------------------------------------------
! Calculate remineralization terms
bling%jfe_reminp(i,j,k) = (bling%fpofe(i,j,k-1) + &
(bling%jfe_ads_org(i,j,k) + bling%jfe_ads_inorg(i,j,k) + &
bling%jfeop(i,j,k)) * rho_dzt(i,j,k) - &
bling%fpofe(i,j,k)) / (epsln + rho_dzt(i,j,k))
enddo !} i
enddo !} j
enddo !} k
!---------------------------------------------------------------------
! BOTTOM LAYER
! Account for remineralization in bottom box, and bottom fluxes
do j = jsc, jec
do i = isc, iec
k = grid_kmt(i,j)
if (k .gt. 0) then
!---------------------------------------------------------------------
! Calculate iron addition from sediments as a function of organic
! matter supply.
bling%ffe_sed(i,j) = bling%fe_2_p_sed * bling%fpop(i,j,k)
! Added the burial flux of sinking particulate iron here as a
! diagnostic, needed to calculate mass balance of iron.
bling%fe_burial(i,j) = bling%fpofe(i,j,k)
!---------------------------------------------------------------------
! Calculate external bottom fluxes for tracer_vertdiff. Positive fluxes
! are from the water column into the seafloor. For iron, the sinking flux disappears into the
! sediments if bottom waters are oxic (assumed adsorbed as oxides),
! while an efflux of dissolved iron occurs dependent on the supply of
! reducing organic matter (scaled by the org-P sedimentation rate).
! If bottom waters are anoxic, the sinking flux of Fe is returned to
! the water column. Note this is not appropriate for very long runs
! with an anoxic ocean (iron will keep accumulating forever).
if (bling%f_o2(i,j,k) .gt. bling%o2_min) then
bling%b_fed(i,j) = - bling%ffe_sed(i,j)
else
bling%b_fed(i,j) = - bling%ffe_sed(i,j) - bling%fpofe(i,j,k)
endif
endif
enddo !} i
enddo !} j
endif
if (bling%fe_is_prognostic) then
call g_tracer_set_values(tracer_list,'fed' // bling%suffix, 'btf', bling%b_fed ,isd,jsd)
endif
call g_tracer_set_values(tracer_list,'po4' // bling%suffix, 'btf', bling%b_po4 ,isd,jsd)
call g_tracer_set_values(tracer_list,'o2' // bling%suffix, 'btf', bling%b_o2 ,isd,jsd)
if (bling%do_carbon) then !<<CARBON CYCLE
! Do bottom box calcs for carbon cycle
do j = jsc, jec
do i = isc, iec
k = grid_kmt(i,j)
if (k .gt. 0) then
! Do not bury any C-org - all goes back to water column
bling%b_dic(i,j) = - bling%fpop(i,j,k) * bling%c_2_p
endif !}
enddo !} i
enddo !} j
call g_tracer_set_values(tracer_list,'dic' // bling%suffix, 'btf', bling%b_dic ,isd,jsd)
if (bling%do_14c) then !<<RADIOCARBON
do j = jsc, jec
do i = isc, iec
k = grid_kmt(i,j)
if (k .gt. 0) then
bling%b_di14c(i,j) = - bling%fpo14c(i,j,k)
endif !}
enddo !} i
enddo !} j
call g_tracer_set_values(tracer_list,'di14c' // bling%suffix,'btf',bling%b_di14c,isd,jsd)
endif !} !RADIOCARBON>>
endif !} !CARBON CYCLE>>
!-------------------------------------------------------------------------
! CALCULATE SOURCE/SINK TERMS FOR EACH TRACER
!-------------------------------------------------------------------------
!Update the prognostics tracer fields via their pointers.
if (bling%fe_is_prognostic) then
call g_tracer_get_pointer(tracer_list, 'fed' // bling%suffix, 'field', bling%p_fed)
elseif (bling%fe_is_diagnostic) then
call g_tracer_get_pointer(tracer_list, 'fed' // bling%suffix, 'field', bling%p_fed_diag)
endif
call g_tracer_get_pointer(tracer_list,'o2' // bling%suffix ,'field',bling%p_o2 )
call g_tracer_get_pointer(tracer_list,'po4' // bling%suffix ,'field',bling%p_po4 )
if (bling%do_carbon) then
call g_tracer_get_pointer(tracer_list,'dic' // bling%suffix,'field',bling%p_dic)
if (bling%do_14c) then
call g_tracer_get_pointer(tracer_list,'di14c' // bling%suffix,'field',bling%p_di14c)
endif !}
endif !}
do k = 1, nk
do j = jsc, jec
do i = isc, iec
!
! PO4
! Sum of fast recycling and decay of sinking POP, less uptake.
!
bling%jpo4(i,j,k) = bling%jp_recycle(i,j,k) + &
bling%jp_reminp(i,j,k) - bling%jp_uptake(i,j,k)
bling%p_po4(i,j,k,tau) = bling%p_po4(i,j,k,tau) + &
bling%jpo4(i,j,k) * dtts * grid_tmask(i,j,k)
!-----------------------------------------------------------------------
! O2
! Assuming constant P:O ratio.
! Optional prevention of negative oxygen (does not conserve ocean
! redox potential) or alternatively it can be allowed to go negative,
! keeping track of an implicit nitrate deficit
! plus sulfate reduction.
!-----------------------------------------------------------------------
if ( (bling%prevent_neg_o2) .and. &
(bling%f_o2(i,j,k) .lt. bling%o2_min) ) then
bling%jo2(i,j,k) = 0. * grid_tmask(i,j,k)
else
bling%jo2(i,j,k) = - bling%o2_2_p * bling%jpo4(i,j,k) &
* grid_tmask(i,j,k)
endif !}
bling%p_o2(i,j,k,tau) = bling%p_o2(i,j,k,tau) + bling%jo2(i,j,k) * &
dtts * grid_tmask(i,j,k)
enddo !} i
enddo !} j
enddo !} k
!
! Fed
!
if (bling%fe_is_prognostic) then
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%p_fed(i,j,k,tau) = bling%p_fed(i,j,k,tau) + &
(bling%jfe_recycle(i,j,k) + bling%jfe_reminp(i,j,k) - &
bling%jfe_uptake(i,j,k) - bling%jfe_ads_org(i,j,k) - &
bling%jfe_ads_inorg(i,j,k) ) * dtts * grid_tmask(i,j,k)
enddo !} i
enddo !} j
enddo !} k
elseif (bling%fe_is_diagnostic) then
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%p_fed_diag(i,j,k) = bling%p_fed_diag(i,j,k) - &
bling%jfe_uptake(i,j,k) * dtts * grid_tmask(i,j,k)
bling%jfe_reminp(i,j,k) = (bling%f_fed_data(i,j,k) - bling%p_fed_diag(i,j,k)) * &
(1.0 / (bling%fe_restoring * 86400.0)) * grid_tmask(i,j,k)
bling%p_fed_diag(i,j,k) = bling%p_fed_diag(i,j,k) + &
bling%jfe_reminp(i,j,k) * dtts
enddo !} i
enddo !} j
enddo !} k
endif
if (bling%do_carbon) then !<<CARBON CYCLE
do k = 1, nk
do j = jsc, jec
do i = isc, iec
bling%p_dic(i,j,k,tau) = bling%p_dic(i,j,k,tau) + &
(bling%jpo4(i,j,k) * bling%c_2_p) * dtts * grid_tmask(i,j,k)
if (bling%do_14c) then !<<RADIOCARBON
bling%jdi14c(i,j,k) = (bling%jp_recycle(i,j,k) - &
bling%jp_uptake(i,j,k)) * bling%c14_2_p(i,j,k) + &
bling%j14c_reminp(i,j,k)
bling%p_di14c(i,j,k,tau) = bling%p_di14c(i,j,k,tau) + &
(bling%jdi14c(i,j,k) - bling%j14c_decay_dic(i,j,k)) * dtts &
* grid_tmask(i,j,k)
endif !} !RADIOCARBON>>
enddo !} i
enddo !} j
enddo !} k
endif !CARBON CYCLE>>
!
!Set the diagnostics tracer fields.
!
call g_tracer_set_values(tracer_list,'chl' // bling%suffix,'field',bling%f_chl,isd,jsd, &
ntau=1)
!-----------------------------------------------------------------------
! Save variables for diagnostics
!-----------------------------------------------------------------------
!
if (.not. bling%fe_is_prognostic) then
if (bling%id_fed_data_surf .gt. 0) &
used = send_data(bling%id_fed_data_surf, bling%f_fed_data(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
endif
if (bling%id_htotal_surf .gt. 0) &
used = send_data(bling%id_htotal_surf, bling%p_htotal(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_chl_surf .gt. 0) &
used = send_data(bling%id_chl_surf, bling%f_chl(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%biomass_type .eq. 'single') then
if (bling%id_biomass_p_surf .gt. 0) &
used = send_data(bling%id_biomass_p_surf, bling%p_biomass_p(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
elseif (bling%biomass_type .eq. 'lg_sm_phyto') then
if (bling%id_phyto_lg_surf .gt. 0) &
used = send_data(bling%id_phyto_lg_surf, bling%p_phyto_lg(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_phyto_sm_surf .gt. 0) &
used = send_data(bling%id_phyto_sm_surf, bling%p_phyto_sm(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
endif
if (bling%id_irr_mem_surf .gt. 0) &
used = send_data(bling%id_irr_mem_surf, bling%p_irr_mem(:,:,1), &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_pco2_surf .gt. 0) &
used = send_data(bling%id_pco2_surf, bling%pco2_surf, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_temp_co2calc .gt. 0) &
used = send_data(bling%id_temp_co2calc, bling%surf_temp, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_salt_co2calc .gt. 0) &
used = send_data(bling%id_salt_co2calc, bling%surf_salt, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_po4_co2calc .gt. 0) &
used = send_data(bling%id_po4_co2calc, bling%surf_po4, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_alk_co2calc .gt. 0) &
used = send_data(bling%id_alk_co2calc, bling%surf_alk, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_sio4_co2calc .gt. 0) &
used = send_data(bling%id_sio4_co2calc, bling%surf_sio4, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_dic_co2calc .gt. 0) &
used = send_data(bling%id_dic_co2calc, bling%surf_dic, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%fe_is_prognostic) then
if (bling%id_b_fed .gt. 0) &
used = send_data(bling%id_b_fed, bling%b_fed, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
endif
if (bling%id_b_o2 .gt. 0) &
used = send_data(bling%id_b_o2, bling%b_o2, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_b_po4 .gt. 0) &
used = send_data(bling%id_b_po4, bling%b_po4, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%biomass_type .eq. 'single') then
if (bling%id_biomass_p_ts .gt. 0) &
used = send_data(bling%id_biomass_p_ts, bling%biomass_p_ts, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
endif
if (bling%id_def_fe .gt. 0) &
used = send_data(bling%id_def_fe, bling%def_fe, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_expkT .gt. 0) &
used = send_data(bling%id_expkT, bling%expkT, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_fe_2_p_uptake .gt. 0) &
used = send_data(bling%id_fe_2_p_uptake, bling%fe_2_p_uptake, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%fe_is_prognostic) then
if (bling%id_feprime .gt. 0) &
used = send_data(bling%id_feprime, bling%feprime, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_fe_burial .gt. 0) &
used = send_data(bling%id_fe_burial, bling%fe_burial, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_ffe_sed .gt. 0) &
used = send_data(bling%id_ffe_sed, bling%ffe_sed, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_fpofe .gt. 0) &
used = send_data(bling%id_fpofe, bling%fpofe, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
endif
if (bling%id_fpop .gt. 0) &
used = send_data(bling%id_fpop, bling%fpop, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_frac_lg .gt. 0) &
used = send_data(bling%id_frac_lg, bling%frac_lg, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_frac_pop .gt. 0) &
used = send_data(bling%id_frac_pop, bling%frac_pop, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_irr_inst .gt. 0) &
used = send_data(bling%id_irr_inst, bling%irr_inst, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_irr_mix .gt. 0) &
used = send_data(bling%id_irr_mix, bling%irr_mix, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_irrk .gt. 0) &
used = send_data(bling%id_irrk, bling%irrk, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%fe_is_prognostic) then
if (bling%id_jfe_ads_inorg .gt. 0) &
used = send_data(bling%id_jfe_ads_inorg, bling%jfe_ads_inorg*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jfe_ads_org .gt. 0) &
used = send_data(bling%id_jfe_ads_org, bling%jfe_ads_org*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jfe_recycle .gt. 0) &
used = send_data(bling%id_jfe_recycle, bling%jfe_recycle*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
endif
if (bling%fe_is_prognostic .or. bling%fe_is_diagnostic) then
if (bling%id_jfe_reminp .gt. 0) &
used = send_data(bling%id_jfe_reminp, bling%jfe_reminp*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
endif
if (bling%id_jfe_uptake .gt. 0) &
used = send_data(bling%id_jfe_uptake, bling%jfe_uptake*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jo2 .gt. 0) &
used = send_data(bling%id_jo2, bling%jo2*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jp_recycle .gt. 0) &
used = send_data(bling%id_jp_recycle, bling%jp_recycle*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jp_reminp .gt. 0) &
used = send_data(bling%id_jp_reminp, bling%jp_reminp*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jp_uptake .gt. 0) &
used = send_data(bling%id_jp_uptake, bling%jp_uptake*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jpo4 .gt. 0) &
used = send_data(bling%id_jpo4, bling%jpo4*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_jpop .gt. 0) &
used = send_data(bling%id_jpop, bling%jpop*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%fe_is_prognostic) then
if (bling%id_jfeop .gt. 0) &
used = send_data(bling%id_jfeop, bling%jfeop*rho_dzt, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_kfe_eq_lig .gt. 0) &
used = send_data(bling%id_kfe_eq_lig, bling%kfe_eq_lig, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
endif
if (bling%id_pc_m .gt. 0) &
used = send_data(bling%id_pc_m, bling%pc_m, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_mu .gt. 0) &
used = send_data(bling%id_mu, bling%mu, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_o2_saturation .gt. 0) &
used = send_data(bling%id_o2_saturation, bling%o2_saturation, &
model_time, rmask = grid_tmask(:,:,1), &
is_in=isc, js_in=jsc,ie_in=iec, je_in=jec)
if (bling%id_theta .gt. 0) &
used = send_data(bling%id_theta, bling%theta, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_thetamax_fe .gt. 0) &
used = send_data(bling%id_thetamax_fe, bling%thetamax_fe, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_wsink .gt. 0) &
used = send_data(bling%id_wsink, bling%wsink, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (bling%id_zremin .gt. 0) &
used = send_data(bling%id_zremin, bling%zremin, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
if (.not. bling%fe_is_prognostic) then
if (bling%id_fed_data .gt. 0) &
used = send_data(bling%id_fed_data, bling%f_fed_data, &
model_time, rmask = grid_tmask, &
is_in=isc, js_in=jsc, ks_in=1,ie_in=iec, je_in=jec, ke_in=nk)
endif
enddo !} n
deallocate(tmp_irr_band)
return
end subroutine generic_miniBLING_update_from_source
!#######################################################################
! <SUBROUTINE NAME="generic_miniBLING_set_boundary_values">
! <DESCRIPTION>
! Calculate and set coupler values at the surface / bottom of the ocean.
! </DESCRIPTION>
! <TEMPLATE>
! call generic_miniBLING_set_boundary_values(tracer_list,SST,SSS,rho,ilb,jlb,tau)
! </TEMPLATE>
! <IN NAME="tracer_list" TYPE="type(g_tracer_type), pointer">
! Pointer to the head of generic tracer list.
! </IN>
! <IN NAME="ilb,jlb" TYPE="integer">
! Lower bounds of x and y extents of input arrays on data domain
! </IN>
! <IN NAME="SST" TYPE="real, dimension(ilb:,jlb:)">
! Sea Surface Temperature
! </IN>
! <IN NAME="SSS" TYPE="real, dimension(ilb:,jlb:)">
! Sea Surface Salinity
! </IN>
! <IN NAME="rho" TYPE="real, dimension(ilb:,jlb:,:,:)">
! Ocean density
! </IN>
! <IN NAME="tau" TYPE="integer">
! Time step index of %field
! </IN>
! </SUBROUTINE>
!User must provide the calculations for these boundary values.
subroutine generic_miniBLING_set_boundary_values(tracer_list, SST, SSS, rho, ilb, jlb, tau)
type(g_tracer_type), pointer, intent(inout) :: tracer_list
real, dimension(ilb:,jlb:), intent(in) :: SST
real, dimension(ilb:,jlb:), intent(in) :: SSS
real, dimension(ilb:,jlb:,:,:), intent(in) :: rho
integer, intent(in) :: ilb
integer, intent(in) :: jlb
integer, intent(in) :: tau
integer :: isc
integer :: iec
integer :: jsc
integer :: jec
integer :: isd
integer :: ied
integer :: jsd
integer :: jed
integer :: nk
integer :: ntau
integer :: i
integer :: j
integer :: n
real :: sal
real :: ST
real :: sc_co2
real :: sc_o2
!real :: sc_no_term
real :: o2_saturation
real :: tt
real :: tk
real :: ts
real :: ts2
real :: ts3
real :: ts4
real :: ts5
real, dimension(:,:,:), pointer :: grid_tmask
real, dimension(:,:,:,:), pointer :: o2_field
real, dimension(:,:), pointer :: co2_alpha
real, dimension(:,:), pointer :: co2_csurf
real, dimension(:,:), pointer :: co2_schmidt
real, dimension(:,:), pointer :: o2_alpha
real, dimension(:,:), pointer :: o2_csurf
real, dimension(:,:), pointer :: o2_schmidt
real, dimension(:,:), pointer :: co2_sat_rate
real, dimension(:,:), pointer :: c14o2_alpha
real, dimension(:,:), pointer :: c14o2_csurf
real, dimension(:,:), pointer :: c14o2_schmidt
real :: surface_rho
character(len=fm_string_len), parameter :: sub_name = 'generic_miniBLING_set_boundary_values'
! SURFACE GAS FLUXES
!
! This subroutine coordinates the calculation of gas concentrations and solubilities
! in the surface layer. The concentration of a gas is written as csurf, while the
! solubility (in mol kg-1 atm-1 or mol m-3 atm-1) is written as alpha. These two
! quantities are passed to the coupler, which multiplies their difference by the
! gas exchange piston velocity over the mixed layer depth to provide the gas
! exchange flux,
! Flux = Kw/dz * (alpha - csurf)
! In order to simplify code flow, the Schmidt number parameters, which are part of
! the piston velocity, are calculated here and applied to each of csurf and alpha
! before being sent to the coupler.
!
! For CO2 and 14CO2, the carbon solubility and speciation are calculated by the
! subroutine co2calc, following the OCMIP2 protocol. These calculations are both made
! using total CO2, following which the surface CO2 concentration (CO2*, also known as
! H2CO3*) is scaled by the DI14C/DIC ratio to give the surface 14CO2 concentration.
! The speciation calculation uses in situ temperature, salinity, ALK, PO4 and SiO4.
!
! Oxygen solubility is calculated here, using in situ temperature and salinity.
!Get the necessary properties
call g_tracer_get_common(isc, iec, jsc, jec, isd, ied, jsd, jed, nk, ntau, grid_tmask = grid_tmask)
do n = 1, num_instances
call g_tracer_get_pointer(tracer_list, 'o2' // bling%suffix ,'field', o2_field)
call g_tracer_get_pointer(tracer_list, 'o2' // bling%suffix, 'alpha', o2_alpha)
call g_tracer_get_pointer(tracer_list, 'o2' // bling%suffix, 'csurf', o2_csurf)
call g_tracer_get_pointer(tracer_list, 'o2' // bling%suffix, 'sc_no', o2_schmidt)
do j = jsc, jec
do i = isc, iec
sal = SSS(i,j)
ST = SST(i,j)
surface_rho = bling%Rho_0
!---------------------------------------------------------------------
! O2
!---------------------------------------------------------------------
! Compute the oxygen saturation concentration at 1 atm total pressure in mol/kg
! given the temperature (T, in deg C) and the salinity (S, in permil).
!
! From Garcia and Gordon (1992), Limnology and Oceonography (page 1310, eq (8)).
! *** Note: the "a3*ts^2" term was erroneous, and not included here. ***
! Defined between T(freezing) <= T <= 40 deg C and 0 <= S <= 42 permil.
!
! check value: T = 10 deg C, S = 35 permil, o2_saturation = 0.282015 mol m-3
!---------------------------------------------------------------------
tt = 298.15 - ST
tk = 273.15 + ST
ts = log(tt / tk)
ts2 = ts * ts
ts3 = ts2 * ts
ts4 = ts3 * ts
ts5 = ts4 * ts
o2_saturation = (1000.0/22391.6) * grid_tmask(i,j,1) * & !convert from ml/l to mol m-3
exp(bling%a_0 + bling%a_1*ts + bling%a_2*ts2 + bling%a_3*ts3 + &
bling%a_4*ts4 + bling%a_5*ts5 + (bling%b_0 + bling%b_1*ts + &
bling%b_2*ts2 + bling%b_3*ts3 + bling%c_0 * sal) * sal)
!---------------------------------------------------------------------
! Compute the Schmidt number of O2 in seawater using the formulation proposed
! by Keeling et al. (1998, Global Biogeochem. Cycles, 12, 141-163).
!---------------------------------------------------------------------
sc_o2 = bling%a1_o2 + ST * (bling%a2_o2 + ST * (bling%a3_o2 + &
ST * bling%a4_o2 )) * grid_tmask(i,j,1)
o2_alpha(i,j) = o2_saturation
bling%o2_saturation(i,j) = o2_saturation / surface_rho
o2_csurf(i,j) = o2_field(i,j,1,tau) * surface_rho
o2_schmidt(i,j) = sc_o2
enddo !} i
enddo !} j
if (bling%do_carbon) then !<<CARBON CYCLE
call g_tracer_get_pointer(tracer_list, 'dic' // bling%suffix, 'alpha', co2_alpha)
call g_tracer_get_pointer(tracer_list, 'dic' // bling%suffix, 'csurf', co2_csurf)
call g_tracer_get_pointer(tracer_list, 'dic' // bling%suffix, 'sc_no', co2_schmidt)
do j = jsc, jec
do i = isc, iec
ST = SST(i,j)
surface_rho = bling%Rho_0
!---------------------------------------------------------------------
! CO2
!---------------------------------------------------------------------
!---------------------------------------------------------------------
! Compute the Schmidt number of CO2 in seawater using the formulation
! presented by Wanninkhof (1992, J. Geophys. Res., 97, 7373-7382).
!---------------------------------------------------------------------
sc_co2 = bling%a1_co2 + ST * (bling%a2_co2 + ST * &
(bling%a3_co2 + ST * bling%a4_co2)) * grid_tmask(i,j,1)
co2_alpha(i,j) = co2_alpha(i,j) * surface_rho
co2_csurf(i,j) = co2_csurf(i,j) * surface_rho
co2_schmidt(i,j) = sc_co2
enddo !} i
enddo !} j
if (bling%do_14c) then
call g_tracer_get_pointer(tracer_list, 'di14c' // bling%suffix, 'alpha', c14o2_alpha)
call g_tracer_get_pointer(tracer_list, 'di14c' // bling%suffix, 'csurf', c14o2_csurf)
call g_tracer_get_pointer(tracer_list, 'di14c' // bling%suffix, 'sc_no', c14o2_schmidt)
do j = jsc, jec
do i = isc, iec
ST = SST(i,j)
surface_rho = bling%Rho_0
sc_co2 = bling%a1_co2 + ST * (bling%a2_co2 + ST * (bling%a3_co2 + &
ST * bling%a4_co2)) * grid_tmask(i,j,1)
c14o2_alpha(i,j) = c14o2_alpha(i,j) * surface_rho
c14o2_csurf(i,j) = c14o2_csurf(i,j) * surface_rho
c14o2_schmidt(i,j) = sc_co2
enddo
enddo
endif
endif !CARBON CYCLE>>
enddo
return
end subroutine generic_miniBLING_set_boundary_values
!#######################################################################
! <SUBROUTINE NAME="generic_miniBLING_end">
! <DESCRIPTION>
! End the module. Deallocate all work arrays.
! </DESCRIPTION>
! </SUBROUTINE>
subroutine generic_miniBLING_end
character(len=fm_string_len), parameter :: sub_name = 'generic_miniBLING_end'
character(len=256), parameter :: error_header = &
'==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
character(len=256), parameter :: warn_header = &
'==>Warning from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
integer :: stdout_unit
stdout_unit = stdout()
call user_deallocate_arrays
return
end subroutine generic_miniBLING_end
!#######################################################################
!
! This is an internal sub, not a public interface.
! Allocate all the work arrays to be used in this module.
!
subroutine user_allocate_arrays
integer :: isc
integer :: iec
integer :: jsc
integer :: jec
integer :: isd
integer :: ied
integer :: jsd
integer :: jed
integer :: nk
integer :: ntau
integer :: n
call g_tracer_get_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau)
!Used in ocmip2_co2calc
CO2_dope_vec%isc = isc
CO2_dope_vec%iec = iec
CO2_dope_vec%jsc = jsc
CO2_dope_vec%jec = jec
CO2_dope_vec%isd = isd
CO2_dope_vec%ied = ied
CO2_dope_vec%jsd = jsd
CO2_dope_vec%jed = jed
do n = 1, num_instances
allocate(bling%wrk_3d (isd:ied, jsd:jed, 1:nk)); bling%wrk_3d=0.0
allocate(bling%wrk_2d (isd:ied, jsd:jed) ); bling%wrk_2d=0.0
allocate(bling%flux (isd:ied, jsd:jed) ); bling%flux=0.0
allocate(bling%integral (isd:ied, jsd:jed) ); bling%integral=0.0
allocate(bling%k_lev (isd:ied, jsd:jed) ); bling%k_lev=0.0
if (bling%biomass_type .eq. 'single') then
allocate(bling%biomass_p_ts (isd:ied, jsd:jed, 1:nk)); bling%biomass_p_ts=0.0
endif
allocate(bling%def_fe (isd:ied, jsd:jed, 1:nk)); bling%def_fe=0.0
allocate(bling%expkT (isd:ied, jsd:jed, 1:nk)); bling%expkT=0.0
allocate(bling%f_chl (isd:ied, jsd:jed, 1:nk)); bling%f_chl=0.0
allocate(bling%f_fed (isd:ied, jsd:jed, 1:nk)); bling%f_fed=0.0
if (.not. bling%fe_is_prognostic) then
allocate(bling%f_fed_data (isc:iec, jsc:jec, 1:nk)); bling%f_fed_data=0.0
endif
allocate(bling%f_o2 (isd:ied, jsd:jed, 1:nk)); bling%f_o2=0.0
allocate(bling%f_po4 (isd:ied, jsd:jed, 1:nk)); bling%f_po4=0.0
allocate(bling%fe_2_p_uptake (isd:ied, jsd:jed, 1:nk)); bling%fe_2_p_uptake=0.0
if (bling%fe_is_prognostic) then
allocate(bling%feprime (isd:ied, jsd:jed, 1:nk)); bling%feprime=0.0
allocate(bling%fpofe (isd:ied, jsd:jed, 1:nk)); bling%fpofe=0.0
endif
allocate(bling%fpop (isd:ied, jsd:jed, 1:nk)); bling%fpop=0.0
allocate(bling%frac_lg (isd:ied, jsd:jed, 1:nk)); bling%frac_lg=0.0
allocate(bling%frac_pop (isd:ied, jsd:jed, 1:nk)); bling%frac_pop=0.0
allocate(bling%irr_inst (isd:ied, jsd:jed, 1:nk)); bling%irr_inst=0.0
allocate(bling%irr_mix (isd:ied, jsd:jed, 1:nk)); bling%irr_mix=0.0
allocate(bling%irrk (isd:ied, jsd:jed, 1:nk)); bling%irrk=0.0
if (bling%fe_is_prognostic) then
allocate(bling%jfe_ads_inorg (isd:ied, jsd:jed, 1:nk)); bling%jfe_ads_inorg=0.0
allocate(bling%jfe_ads_org (isd:ied, jsd:jed, 1:nk)); bling%jfe_ads_org=0.0
allocate(bling%jfe_recycle (isd:ied, jsd:jed, 1:nk)); bling%jfe_recycle=0.0
endif
if (bling%fe_is_prognostic .or. bling%fe_is_diagnostic) then
allocate(bling%jfe_reminp (isd:ied, jsd:jed, 1:nk)); bling%jfe_reminp=0.0
endif
allocate(bling%jfe_uptake (isd:ied, jsd:jed, 1:nk)); bling%jfe_uptake=0.0
allocate(bling%jo2 (isd:ied, jsd:jed, 1:nk)); bling%jo2=0.0
allocate(bling%jp_recycle (isd:ied, jsd:jed, 1:nk)); bling%jp_recycle=0.0
allocate(bling%jp_reminp (isd:ied, jsd:jed, 1:nk)); bling%jp_reminp=0.0
allocate(bling%jp_uptake (isd:ied, jsd:jed, 1:nk)); bling%jp_uptake=0.0
allocate(bling%jpo4 (isd:ied, jsd:jed, 1:nk)); bling%jpo4=0.0
allocate(bling%jpop (isd:ied, jsd:jed, 1:nk)); bling%jpop=0.0
if (bling%fe_is_prognostic) then
allocate(bling%jfeop (isd:ied, jsd:jed, 1:nk)); bling%jfeop=0.0
allocate(bling%kfe_eq_lig (isd:ied, jsd:jed, 1:nk)); bling%kfe_eq_lig=0.0
endif
allocate(bling%mu (isd:ied, jsd:jed, 1:nk)); bling%mu=0.0
allocate(bling%pc_m (isd:ied, jsd:jed, 1:nk)); bling%pc_m=0.0
allocate(bling%theta (isd:ied, jsd:jed, 1:nk)); bling%theta=0.0
allocate(bling%thetamax_fe (isd:ied, jsd:jed, 1:nk)); bling%thetamax_fe=0.0
allocate(bling%wsink (isd:ied, jsd:jed, 1:nk)); bling%wsink=0.0
allocate(bling%zremin (isd:ied, jsd:jed, 1:nk)); bling%zremin=0.0
allocate(bling%zbot (isd:ied, jsd:jed, 1:nk)); bling%zbot=0.0
allocate(bling%b_o2 (isd:ied, jsd:jed)); bling%b_o2=0.0
allocate(bling%b_po4 (isd:ied, jsd:jed)); bling%b_po4=0.0
if (bling%fe_is_prognostic) then
allocate(bling%b_fed (isd:ied, jsd:jed)); bling%b_fed=0.0
allocate(bling%fe_burial (isd:ied, jsd:jed)); bling%fe_burial=0.0
allocate(bling%ffe_sed (isd:ied, jsd:jed)); bling%ffe_sed=0.0
endif
allocate(bling%o2_saturation (isd:ied, jsd:jed)); bling%o2_saturation=0.0
if (bling%do_carbon) then !<<CARBON CYCLE
allocate(bling%b_dic (isd:ied, jsd:jed)); bling%b_dic=0.0
allocate(bling%co2_alpha (isd:ied, jsd:jed)); bling%co2_alpha=0.0
allocate(bling%co2_csurf (isd:ied, jsd:jed)); bling%co2_csurf=0.0
allocate(bling%htotallo (isd:ied, jsd:jed))
allocate(bling%htotalhi (isd:ied, jsd:jed))
allocate(bling%pco2_surf (isd:ied, jsd:jed)); bling%pco2_surf=0.0
allocate(bling%surf_temp (isd:ied, jsd:jed)); bling%surf_temp=0.0
allocate(bling%surf_salt (isd:ied, jsd:jed)); bling%surf_salt=0.0
allocate(bling%surf_alk (isd:ied, jsd:jed)); bling%surf_alk=0.0
allocate(bling%surf_po4 (isd:ied, jsd:jed)); bling%surf_po4=0.0
allocate(bling%surf_sio4 (isd:ied, jsd:jed)); bling%surf_sio4=0.0
allocate(bling%surf_dic (isd:ied, jsd:jed)); bling%surf_dic=0.0
if (bling%do_14c) then !<<RADIOCARBON
allocate(bling%c14_2_p (isd:ied, jsd:jed, 1:nk)); bling%c14_2_p=0.0
allocate(bling%fpo14c (isd:ied, jsd:jed, 1:nk)); bling%fpo14c=0.0
allocate(bling%j14c_decay_dic (isd:ied, jsd:jed, 1:nk)); bling%j14c_decay_dic=0.0
allocate(bling%j14c_reminp (isd:ied, jsd:jed, 1:nk)); bling%j14c_reminp=0.0
allocate(bling%jdi14c (isd:ied, jsd:jed, 1:nk)); bling%jdi14c=0.0
allocate(bling%b_di14c (isd:ied, jsd:jed)); bling%b_di14c=0.0
allocate(bling%c14o2_alpha (isd:ied, jsd:jed)); bling%c14o2_alpha=0.0
allocate(bling%c14o2_csurf (isd:ied, jsd:jed)); bling%c14o2_csurf=0.0
endif !RADIOCARBON>>
endif !CARBON CYCLE>>
enddo
return
end subroutine user_allocate_arrays
!#######################################################################
!
! This is an internal sub, not a public interface.
! Deallocate all the work arrays allocated by user_allocate_arrays.
!
subroutine user_deallocate_arrays
integer :: n
do n = 1, num_instances
deallocate(bling%wrk_3d)
deallocate(bling%wrk_2d)
deallocate(bling%flux)
deallocate(bling%integral)
deallocate(bling%k_lev)
deallocate(bling%o2_saturation)
if (bling%biomass_type .eq. 'single') then
deallocate(bling%biomass_p_ts)
endif
deallocate(bling%def_fe)
deallocate(bling%expkT)
deallocate(bling%f_chl)
deallocate(bling%f_fed)
if (.not. bling%fe_is_prognostic) then
deallocate(bling%f_fed_data)
endif
deallocate(bling%f_o2)
deallocate(bling%f_po4)
deallocate(bling%fe_2_p_uptake)
if (bling%fe_is_prognostic) then
deallocate(bling%feprime)
deallocate(bling%fpofe)
endif
deallocate(bling%fpop)
deallocate(bling%frac_lg)
deallocate(bling%frac_pop)
deallocate(bling%irr_inst)
deallocate(bling%irr_mix)
deallocate(bling%irrk)
if (bling%fe_is_prognostic) then
deallocate(bling%jfe_ads_inorg)
deallocate(bling%jfe_ads_org)
deallocate(bling%jfe_recycle)
endif
if (bling%fe_is_prognostic .or. bling%fe_is_diagnostic) then
deallocate(bling%jfe_reminp)
endif
deallocate(bling%jfe_uptake)
deallocate(bling%jo2)
deallocate(bling%jp_recycle)
deallocate(bling%jp_reminp)
deallocate(bling%jp_uptake)
deallocate(bling%jpo4)
deallocate(bling%jpop)
if (bling%fe_is_prognostic) then
deallocate(bling%jfeop)
deallocate(bling%kfe_eq_lig)
endif
deallocate(bling%pc_m)
deallocate(bling%mu)
deallocate(bling%theta)
deallocate(bling%thetamax_fe)
deallocate(bling%wsink)
deallocate(bling%zremin)
deallocate(bling%zbot)
if (bling%fe_is_prognostic) then
deallocate(bling%fe_burial)
deallocate(bling%ffe_sed)
deallocate(bling%b_fed)
endif
deallocate(bling%b_o2)
deallocate(bling%b_po4)
if (bling%do_carbon) then !<<CARBON CYCLE
deallocate(bling%surf_temp)
deallocate(bling%surf_salt)
deallocate(bling%surf_alk)
deallocate(bling%surf_po4)
deallocate(bling%surf_sio4)
deallocate(bling%surf_dic)
deallocate(bling%co2_csurf)
deallocate(bling%pco2_surf)
deallocate(bling%co2_alpha)
deallocate(bling%htotallo)
deallocate(bling%htotalhi)
deallocate(bling%b_dic)
if (bling%do_14c) then !<<RADIOCARBON
deallocate(bling%c14_2_p)
deallocate(bling%fpo14c)
deallocate(bling%j14c_decay_dic)
deallocate(bling%j14c_reminp)
deallocate(bling%jdi14c)
deallocate(bling%c14o2_alpha)
deallocate(bling%c14o2_csurf)
deallocate(bling%b_di14c)
endif !} !RADIOCARBON>>
endif !} !CARBON CYCLE>>
enddo !} n
return
end subroutine user_deallocate_arrays
end module generic_miniBLING_mod
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/blas/strsm.f | 16 | 12281 | SUBROUTINE STRSM ( SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA,
$ B, LDB )
* .. Scalar Arguments ..
CHARACTER*1 SIDE, UPLO, TRANSA, DIAG
INTEGER M, N, LDA, LDB
REAL ALPHA
* .. Array Arguments ..
REAL A( LDA, * ), B( LDB, * )
* ..
*
* Purpose
* =======
*
* STRSM solves one of the matrix equations
*
* op( A )*X = alpha*B, or X*op( A ) = alpha*B,
*
* where alpha is a scalar, X and B are m by n matrices, A is a unit, or
* non-unit, upper or lower triangular matrix and op( A ) is one of
*
* op( A ) = A or op( A ) = A'.
*
* The matrix X is overwritten on B.
*
* Parameters
* ==========
*
* SIDE - CHARACTER*1.
* On entry, SIDE specifies whether op( A ) appears on the left
* or right of X as follows:
*
* SIDE = 'L' or 'l' op( A )*X = alpha*B.
*
* SIDE = 'R' or 'r' X*op( A ) = alpha*B.
*
* Unchanged on exit.
*
* UPLO - CHARACTER*1.
* On entry, UPLO specifies whether the matrix A is an upper or
* lower triangular matrix as follows:
*
* UPLO = 'U' or 'u' A is an upper triangular matrix.
*
* UPLO = 'L' or 'l' A is a lower triangular matrix.
*
* Unchanged on exit.
*
* TRANSA - CHARACTER*1.
* On entry, TRANSA specifies the form of op( A ) to be used in
* the matrix multiplication as follows:
*
* TRANSA = 'N' or 'n' op( A ) = A.
*
* TRANSA = 'T' or 't' op( A ) = A'.
*
* TRANSA = 'C' or 'c' op( A ) = A'.
*
* Unchanged on exit.
*
* DIAG - CHARACTER*1.
* On entry, DIAG specifies whether or not A is unit triangular
* as follows:
*
* DIAG = 'U' or 'u' A is assumed to be unit triangular.
*
* DIAG = 'N' or 'n' A is not assumed to be unit
* triangular.
*
* Unchanged on exit.
*
* M - INTEGER.
* On entry, M specifies the number of rows of B. M must be at
* least zero.
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the number of columns of B. N must be
* at least zero.
* Unchanged on exit.
*
* ALPHA - REAL .
* On entry, ALPHA specifies the scalar alpha. When alpha is
* zero then A is not referenced and B need not be set before
* entry.
* Unchanged on exit.
*
* A - REAL array of DIMENSION ( LDA, k ), where k is m
* when SIDE = 'L' or 'l' and is n when SIDE = 'R' or 'r'.
* Before entry with UPLO = 'U' or 'u', the leading k by k
* upper triangular part of the array A must contain the upper
* triangular matrix and the strictly lower triangular part of
* A is not referenced.
* Before entry with UPLO = 'L' or 'l', the leading k by k
* lower triangular part of the array A must contain the lower
* triangular matrix and the strictly upper triangular part of
* A is not referenced.
* Note that when DIAG = 'U' or 'u', the diagonal elements of
* A are not referenced either, but are assumed to be unity.
* Unchanged on exit.
*
* LDA - INTEGER.
* On entry, LDA specifies the first dimension of A as declared
* in the calling (sub) program. When SIDE = 'L' or 'l' then
* LDA must be at least max( 1, m ), when SIDE = 'R' or 'r'
* then LDA must be at least max( 1, n ).
* Unchanged on exit.
*
* B - REAL array of DIMENSION ( LDB, n ).
* Before entry, the leading m by n part of the array B must
* contain the right-hand side matrix B, and on exit is
* overwritten by the solution matrix X.
*
* LDB - INTEGER.
* On entry, LDB specifies the first dimension of B as declared
* in the calling (sub) program. LDB must be at least
* max( 1, m ).
* Unchanged on exit.
*
*
* Level 3 Blas routine.
*
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
*
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* .. External Subroutines ..
EXTERNAL XERBLA
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Local Scalars ..
LOGICAL LSIDE, NOUNIT, UPPER
INTEGER I, INFO, J, K, NROWA
REAL TEMP
* .. Parameters ..
REAL ONE , ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
LSIDE = LSAME( SIDE , 'L' )
IF( LSIDE )THEN
NROWA = M
ELSE
NROWA = N
END IF
NOUNIT = LSAME( DIAG , 'N' )
UPPER = LSAME( UPLO , 'U' )
*
INFO = 0
IF( ( .NOT.LSIDE ).AND.
$ ( .NOT.LSAME( SIDE , 'R' ) ) )THEN
INFO = 1
ELSE IF( ( .NOT.UPPER ).AND.
$ ( .NOT.LSAME( UPLO , 'L' ) ) )THEN
INFO = 2
ELSE IF( ( .NOT.LSAME( TRANSA, 'N' ) ).AND.
$ ( .NOT.LSAME( TRANSA, 'T' ) ).AND.
$ ( .NOT.LSAME( TRANSA, 'C' ) ) )THEN
INFO = 3
ELSE IF( ( .NOT.LSAME( DIAG , 'U' ) ).AND.
$ ( .NOT.LSAME( DIAG , 'N' ) ) )THEN
INFO = 4
ELSE IF( M .LT.0 )THEN
INFO = 5
ELSE IF( N .LT.0 )THEN
INFO = 6
ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN
INFO = 9
ELSE IF( LDB.LT.MAX( 1, M ) )THEN
INFO = 11
END IF
IF( INFO.NE.0 )THEN
CALL XERBLA( 'STRSM ', INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( N.EQ.0 )
$ RETURN
*
* And when alpha.eq.zero.
*
IF( ALPHA.EQ.ZERO )THEN
DO 20, J = 1, N
DO 10, I = 1, M
B( I, J ) = ZERO
10 CONTINUE
20 CONTINUE
RETURN
END IF
*
* Start the operations.
*
IF( LSIDE )THEN
IF( LSAME( TRANSA, 'N' ) )THEN
*
* Form B := alpha*inv( A )*B.
*
IF( UPPER )THEN
DO 60, J = 1, N
IF( ALPHA.NE.ONE )THEN
DO 30, I = 1, M
B( I, J ) = ALPHA*B( I, J )
30 CONTINUE
END IF
DO 50, K = M, 1, -1
IF( B( K, J ).NE.ZERO )THEN
IF( NOUNIT )
$ B( K, J ) = B( K, J )/A( K, K )
DO 40, I = 1, K - 1
B( I, J ) = B( I, J ) - B( K, J )*A( I, K )
40 CONTINUE
END IF
50 CONTINUE
60 CONTINUE
ELSE
DO 100, J = 1, N
IF( ALPHA.NE.ONE )THEN
DO 70, I = 1, M
B( I, J ) = ALPHA*B( I, J )
70 CONTINUE
END IF
DO 90 K = 1, M
IF( B( K, J ).NE.ZERO )THEN
IF( NOUNIT )
$ B( K, J ) = B( K, J )/A( K, K )
DO 80, I = K + 1, M
B( I, J ) = B( I, J ) - B( K, J )*A( I, K )
80 CONTINUE
END IF
90 CONTINUE
100 CONTINUE
END IF
ELSE
*
* Form B := alpha*inv( A' )*B.
*
IF( UPPER )THEN
DO 130, J = 1, N
DO 120, I = 1, M
TEMP = ALPHA*B( I, J )
DO 110, K = 1, I - 1
TEMP = TEMP - A( K, I )*B( K, J )
110 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/A( I, I )
B( I, J ) = TEMP
120 CONTINUE
130 CONTINUE
ELSE
DO 160, J = 1, N
DO 150, I = M, 1, -1
TEMP = ALPHA*B( I, J )
DO 140, K = I + 1, M
TEMP = TEMP - A( K, I )*B( K, J )
140 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/A( I, I )
B( I, J ) = TEMP
150 CONTINUE
160 CONTINUE
END IF
END IF
ELSE
IF( LSAME( TRANSA, 'N' ) )THEN
*
* Form B := alpha*B*inv( A ).
*
IF( UPPER )THEN
DO 210, J = 1, N
IF( ALPHA.NE.ONE )THEN
DO 170, I = 1, M
B( I, J ) = ALPHA*B( I, J )
170 CONTINUE
END IF
DO 190, K = 1, J - 1
IF( A( K, J ).NE.ZERO )THEN
DO 180, I = 1, M
B( I, J ) = B( I, J ) - A( K, J )*B( I, K )
180 CONTINUE
END IF
190 CONTINUE
IF( NOUNIT )THEN
TEMP = ONE/A( J, J )
DO 200, I = 1, M
B( I, J ) = TEMP*B( I, J )
200 CONTINUE
END IF
210 CONTINUE
ELSE
DO 260, J = N, 1, -1
IF( ALPHA.NE.ONE )THEN
DO 220, I = 1, M
B( I, J ) = ALPHA*B( I, J )
220 CONTINUE
END IF
DO 240, K = J + 1, N
IF( A( K, J ).NE.ZERO )THEN
DO 230, I = 1, M
B( I, J ) = B( I, J ) - A( K, J )*B( I, K )
230 CONTINUE
END IF
240 CONTINUE
IF( NOUNIT )THEN
TEMP = ONE/A( J, J )
DO 250, I = 1, M
B( I, J ) = TEMP*B( I, J )
250 CONTINUE
END IF
260 CONTINUE
END IF
ELSE
*
* Form B := alpha*B*inv( A' ).
*
IF( UPPER )THEN
DO 310, K = N, 1, -1
IF( NOUNIT )THEN
TEMP = ONE/A( K, K )
DO 270, I = 1, M
B( I, K ) = TEMP*B( I, K )
270 CONTINUE
END IF
DO 290, J = 1, K - 1
IF( A( J, K ).NE.ZERO )THEN
TEMP = A( J, K )
DO 280, I = 1, M
B( I, J ) = B( I, J ) - TEMP*B( I, K )
280 CONTINUE
END IF
290 CONTINUE
IF( ALPHA.NE.ONE )THEN
DO 300, I = 1, M
B( I, K ) = ALPHA*B( I, K )
300 CONTINUE
END IF
310 CONTINUE
ELSE
DO 360, K = 1, N
IF( NOUNIT )THEN
TEMP = ONE/A( K, K )
DO 320, I = 1, M
B( I, K ) = TEMP*B( I, K )
320 CONTINUE
END IF
DO 340, J = K + 1, N
IF( A( J, K ).NE.ZERO )THEN
TEMP = A( J, K )
DO 330, I = 1, M
B( I, J ) = B( I, J ) - TEMP*B( I, K )
330 CONTINUE
END IF
340 CONTINUE
IF( ALPHA.NE.ONE )THEN
DO 350, I = 1, M
B( I, K ) = ALPHA*B( I, K )
350 CONTINUE
END IF
360 CONTINUE
END IF
END IF
END IF
*
RETURN
*
* End of STRSM .
*
END
| gpl-2.0 |
marshallward/mom | src/accessom_coupler/ocean_solo.F90 | 1 | 30326 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! !!
!! GNU General Public License !!
!! !!
!! This file is part of the Flexible Modeling System (FMS). !!
!! !!
!! FMS is free software; you can redistribute it and/or modify !!
!! it and are expected to follow the terms of the GNU General Public !!
!! License as published by the Free Software Foundation. !!
!! !!
!! FMS 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 FMS; if not, write to: !!
!! Free Software Foundation, Inc. !!
!! 59 Temple Place, Suite 330 !!
!! Boston, MA 02111-1307 USA !!
!! or see: !!
!! http://www.gnu.org/licenses/gpl.txt !!
!! !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
program main
!
!<CONTACT EMAIL="Matthew.Harrison@noaa.gov"> Matt Harrison
!</CONTACT>
!
!<CONTACT EMAIL="Dave.Bi@csiro.au"> Dave Bi (for OASIS3 hooks)
!</CONTACT>
!
!<REVIEWER EMAIL="Niki.Zadeh@noaa.gov"> Niki Zadeh (for OASIS3 hooks)
!</REVIEWER>
!
!<REVIEWER EMAIL="V.Balaji@noaa.gov"> V. Balaji
!</REVIEWER>
!
!<REVIEWER EMAIL="Stephen.Griffies@noaa.gov"> Stephen Griffies
!</REVIEWER>
!
!<OVERVIEW>
! Driver for ocean-only simulations and prototype setup for OASIS3 driver.
!</OVERVIEW>
!
!<DESCRIPTION>
! Driver for the ocean-only simulations. Similar to the FMS coupler, but
! allows one to run the ocean model without compiling other models.
! Much simpler than the full FMS coupler.
!
! This driver also provides the prototype hooks for using MOM4p1 with OASIS3,
! with this code surrounded by the cpp-preprocessor option "ifdef OASIS3".
! The couping of MOM4p1 to OASIS3 has not been tested at GFDL. Rather,
! CSIRO in Australia uses MOM4p1 with OASIS3, with Dave.Bi@csiro.au the primary
! contact for questions regarding MOM4p1 and OASIS3.
! </DESCRIPTION>
!
! <NAMELIST NAME="ocean_solo_nml">
!
! <DATA NAME="n_mask" TYPE="integer">
! number of region to be masked out. Its value should be less than MAX_PES.
! </DATA>
! <DATA NAME="mask_list(2,MAXPES)" TYPE="integer, dimension(MAX_MASK_REGION,2)">
! The position of the region to be masked out. mask_list(1,:) is the x-layout position
! and mask_list(2,:) is y-layout position.
! </DATA>
! <DATA NAME="layout_mask" TYPE="integer, dimension(2)">
! Processor domain layout for all the component model. layout_mask need to be set when and only
! when n_mask is greater than 0 ( some domain region is masked out ). When this namelist is set,
! it will overload the layout in each component model. The default value is (0,0).
! Currently we require all the component model has the same layout and same grid size.
! </DATA>
! <DATA NAME="restart_interval" TYPE="integer, dimension(6)" DEFAULT="0">
! The time interval that write out intermediate restart file. The format is (yr,mo,day,hr,min,sec).
! When restart_interval is all zero, no intermediate restart file will be written out.
! </DATA>
!
! </NAMELIST>
!
use constants_mod, only: constants_init, SECONDS_PER_HOUR
use data_override_mod, only: data_override_init, data_override
use diag_manager_mod, only: diag_manager_init, diag_manager_end
use field_manager_mod, only: field_manager_init
use fms_mod, only: fms_init, fms_end, open_namelist_file, check_nml_error
use fms_mod, only: close_file, file_exist, uppercase
use fms_io_mod, only: fms_io_exit
use mpp_domains_mod, only: domain2d, mpp_get_compute_domain
use mpp_io_mod, only: mpp_open, MPP_RDONLY, MPP_ASCII, MPP_OVERWR, MPP_APPEND, mpp_close, MPP_SINGLE
use mpp_mod, only: mpp_init
use mpp_mod, only: mpp_error, FATAL, NOTE, mpp_pe, mpp_npes, mpp_set_current_pelist, mpp_sync
use mpp_mod, only: stdlog, stdout, mpp_root_pe, mpp_clock_id
use mpp_mod, only: mpp_clock_begin, mpp_clock_end, MPP_CLOCK_SYNC
use mpp_mod, only: MPP_CLOCK_DETAILED, CLOCK_COMPONENT, MAXPES
use mpp_mod, only: mpp_broadcast
use time_interp_external_mod, only: time_interp_external_init
use time_manager_mod, only: set_calendar_type, time_type, increment_date
use time_manager_mod, only: set_time, set_date, get_time, get_date, month_name, print_time
use time_manager_mod, only: GREGORIAN, JULIAN, NOLEAP, THIRTY_DAY_MONTHS, NO_CALENDAR
use time_manager_mod, only: operator( <= ), operator( < ), operator( >= )
use time_manager_mod, only: operator( + ), operator( - ), operator( / )
use time_manager_mod, only: operator( * ), operator( /= ), operator( > )
use time_manager_mod, only: date_to_string
use ocean_model_mod, only: ocean_model_init , update_ocean_model, ocean_model_end
use ocean_model_mod, only: ocean_model_restart, ocean_public_type, ocean_state_type
use ocean_types_mod, only: ice_ocean_boundary_type
use ocean_util_mod, only: write_chksum_2d
#ifdef ACCESS
use auscom_ice_parameters_mod, only: redsea_gulfbay_sfix, do_sfix_now, sfix_hours, int_sec
use accessom2_mod, only : accessom2_type => accessom2
use coupler_mod, only : coupler_type => coupler
#endif
implicit none
type (ocean_public_type) :: Ocean_sfc
type (ocean_state_type), pointer :: Ocean_state
type(ice_ocean_boundary_type), target :: Ice_ocean_boundary
type(accessom2_type) :: accessom2
type(coupler_type) :: coupler
! define some time types
type(time_type) :: Time_init ! initial time for experiment
type(time_type) :: Time_start ! start time for experiment
type(time_type) :: Time_end ! end time for experiment (as determined by dtts)
type(time_type) :: Run_len ! length of experiment
type(time_type) :: Time
type(time_type) :: Time_step_coupled
type(time_type) :: Time_restart_init
type(time_type) :: Time_restart
type(time_type) :: Time_restart_current
#ifdef ACCESS
type(time_type) :: Time_last_sfix
type(time_type) :: Time_sfix
integer :: sfix_seconds
#endif
character(len=17) :: calendar = 'julian'
integer :: num_cpld_calls = 0
integer :: nc
integer :: calendar_type=-1
integer :: date_init(6)=0, date(6)
integer :: date_restart(6)
integer :: years=0, months=0, days=0, hours=0, minutes=0, seconds=0
integer :: dt_cpld = 86400
integer :: yy, mm, dd, hh, mimi, ss
integer :: isc,iec,jsc,jec
integer :: unit, io_status, ierr
integer :: flags=0
integer :: init_clock, main_clock, term_clock
integer :: override_clock, coupler_init_clock
integer :: nfields
character(len=256) :: version = ''
character(len=256) :: tag = ''
character(len=9) :: month
character(len=64):: timestamp
integer :: n, m
integer :: layout_mask(2) = (/0 , 0/)
integer :: n_mask = 0
integer :: mask_list(2,MAXPES)
integer, parameter :: mp = 2*MAXPES
data ((mask_list(n,m),n=1, 2),m=1,MAXPES) /mp*0/
integer :: restart_interval(6) = (/0,0,0,0,0,0/)
integer :: mpi_comm_mom
integer :: stdoutunit, stdlogunit, tmp_unit
logical :: debug_this_module
character(len=1024) :: accessom2_config_dir = '../'
integer, dimension(6) :: date_array
namelist /ocean_solo_nml/ n_mask, layout_mask, mask_list, restart_interval, &
debug_this_module, accessom2_config_dir
! Initialise floating point exception error handler.
!call fpe_err_handler_init()
debug_this_module = .false.
open(newunit=tmp_unit, file='input.nml')
read(tmp_unit, nml=ocean_solo_nml)
close(tmp_unit)
call coupler%init_begin('mom5xx', config_dir=trim(accessom2_config_dir))
call mpp_init(localcomm=coupler%localcomm)
init_clock = mpp_clock_id('Initialization')
main_clock = mpp_clock_id('Main Loop')
term_clock = mpp_clock_id('Termination')
call mpp_clock_begin(init_clock)
call fms_init(coupler%localcomm)
call constants_init()
flags = MPP_CLOCK_SYNC
stdoutunit=stdout();stdlogunit=stdlog()
! provide for namelist over-ride
unit = open_namelist_file('input.nml')
read (unit, ocean_solo_nml,iostat=io_status)
write (stdoutunit,'(/)')
write (stdoutunit,'(/47x,a/)') '======== MODEL BEING DRIVEN BY OCEAN_SOLO_MOD ========'
write (stdoutunit, ocean_solo_nml)
write (stdlogunit, ocean_solo_nml)
ierr = check_nml_error(io_status,'ocean_solo_nml')
call close_file (unit)
! set the calendar
select case( uppercase(trim(calendar)) )
case( 'GREGORIAN' )
calendar_type = GREGORIAN
case( 'JULIAN' )
calendar_type = JULIAN
case( 'NOLEAP' )
calendar_type = NOLEAP
case( 'THIRTY_DAY' )
calendar_type = THIRTY_DAY_MONTHS
case( 'NO_CALENDAR' )
calendar_type = NO_CALENDAR
case default
call mpp_error(FATAL, &
'ocean_solo: ocean_solo_nml entry calendar must be one of GREGORIAN|JULIAN|NOLEAP|THIRTY_DAY|NO_CALENDAR.' )
end select
! Initialise libaccessom2
call accessom2%init('mom5xx', config_dir=trim(accessom2_config_dir))
! Tell libaccessom2 about any global configs/state
! Synchronise accessom2 'state' (i.e. configuration) between all models.
call accessom2%sync_config(coupler)
! Use accessom2 configuration to set calendar
if (index(accessom2%get_calendar_type(), 'noleap') > 0) then
calendar_type = NOLEAP
elseif (index(accessom2%get_calendar_type(), 'gregorian') > 0) then
calendar_type = GREGORIAN
else
call mpp_error(FATAL, 'ocean_solo: unsupported calendar type')
endif
! Use accessom2 configuration to initial date and runtime
date_init(:) = accessom2%get_cur_exp_date_array()
dt_cpld = accessom2%get_ice_ocean_timestep()
years = 0
months = 0
days = 0
hours = 0
minutes = 0
seconds = accessom2%get_total_runtime_in_seconds()
! get ocean_solo restart : this can override settings from namelist
if (file_exist('INPUT/ocean_solo.res')) then
call mpp_open(unit,'INPUT/ocean_solo.res',form=MPP_ASCII,action=MPP_RDONLY)
read(unit,*) calendar_type
read(unit,*) date_init
read(unit,*) date
call mpp_close(unit)
endif
if (file_exist('INPUT/ocean_solo.intermediate.res')) then
call mpp_open(unit,'INPUT/ocean_solo.intermediate.res',form=MPP_ASCII,action=MPP_RDONLY)
read(unit,*) date_restart
call mpp_close(unit)
else
date_restart = date_init
endif
call set_calendar_type (calendar_type)
call field_manager_init(nfields)
call diag_manager_init()
call time_interp_external_init()
if (sum(date_init) <= 0) then
call mpp_error(FATAL,&
'==>Error from ocean_solo_mod: date_init must be set either in ocean_solo.res or in ocean_solo_nml')
else
Time_init = set_date(date_init(1),date_init(2), date_init(3), &
date_init(4),date_init(5),date_init(6))
endif
if (file_exist('INPUT/ocean_solo.res')) then
Time_start = set_date(date(1),date(2),date(3),date(4),date(5),date(6))
else
Time_start = Time_init
date = date_init
endif
Time_end = increment_date(Time_start, years, months, days, hours, minutes, seconds)
Run_len = Time_end - Time_start
Time_step_coupled = set_time(dt_cpld, 0)
num_cpld_calls = Run_len / Time_step_coupled
Time = Time_start
Time_restart_init = set_date(date_restart(1), date_restart(2), date_restart(3), &
date_restart(4), date_restart(5), date_restart(6) )
Time_restart_current = Time_start
if(ALL(restart_interval == 0)) then
Time_restart = increment_date(Time_end, 1, 0, 0, 0, 0, 0) ! no intermediate restart
else
Time_restart = increment_date(Time_restart_init, restart_interval(1), restart_interval(2), &
restart_interval(3), restart_interval(4), restart_interval(5), restart_interval(6) )
if(Time_restart <= Time_start) call mpp_error(FATAL, &
'==>Error from program ocean_solo: The first intermediate restart time is no larger than the start time')
end if
!-----------------------------------------------------------------------
!------------------- some error checks ---------------------------------
if ( num_cpld_calls * Time_step_coupled /= Run_len ) call mpp_error(FATAL, &
'==>Error from program ocean_solo: run length must be multiple of cpld time step', FATAL)
call mpp_open (unit, 'time_stamp.out', form=MPP_ASCII, action=MPP_APPEND,threading=MPP_SINGLE)
month = month_name(date(2))
if ( mpp_pe() == mpp_root_pe() ) write (unit,'(6i4,2x,a3)') date, month(1:3)
call get_date (Time_end, date(1), date(2), date(3), date(4), date(5), date(6))
month = month_name(date(2))
if ( mpp_pe() == mpp_root_pe() ) write (unit,'(6i4,2x,a3)') date, month(1:3)
call mpp_close (unit)
!----- check the value of layout and setup the maskmap for domain layout.
if( n_mask > 0 ) then
if( layout_mask(1)*layout_mask(2) - n_mask .NE. mpp_npes() ) call mpp_error(FATAL, &
'==>Error from program ocean_solo: layout(1)*layout(2) - n_mask should equal to npes when n_mask>0')
call mpp_error(NOTE, &
'==>Error from program ocean_solo: layout_mask and mask_list is set in ocean_solo_nml, ' // &
'the value of layout_mask will override the layout specified in ocean_model_mod')
allocate(Ocean_sfc%maskmap(layout_mask(1), layout_mask(2)) )
Ocean_sfc%maskmap = .TRUE.
do n=1, n_mask
if (mask_list(1,n) .gt. layout_mask(1) ) &
call mpp_error( FATAL, &
'program ocean_solo: mask_list elements outside layout defines.' )
if (mask_list(2,n) .gt. layout_mask(2) ) &
call mpp_error( FATAL, &
'program ocean_solo: mask_list elements outside layout defines.' )
Ocean_sfc%maskmap(mask_list(1,n),mask_list(2,n)) = .false.
enddo
else
if( layout_mask(1)*layout_mask(2) .NE. 0 ) call mpp_error(NOTE, &
'program ocean_solo: when no region is masked out, layout_mask need not be set' )
end if
call ocean_model_init(Ocean_sfc, Ocean_state, Time_init, Time, &
accessom2%get_ice_ocean_timestep())
#ifdef ACCESS
if (redsea_gulfbay_sfix) then
! This must be called after ocean_model_init so sfix_hours is read in from namelist
sfix_seconds = sfix_hours * SECONDS_PER_HOUR
! Get current model time from Time_init in seconds (must be done like this otherwise
! can get an overflow in seconds)
call get_time(Time-Time_init,seconds=seconds,days=days)
! The last sfix time has to be determined from absolute model time, to ensure reproducibility
! across restarts
! Current time to nearest hour
hours = days*24 + int(seconds/SECONDS_PER_HOUR)
! Time of last sfix
hours = int(hours / sfix_hours) * sfix_hours
! Convert to days + hours
days = int(hours / 24)
hours = hours - days*24
Time_last_sfix = set_time(days=int(days),seconds=int(hours*SECONDS_PER_HOUR)) + Time_init
Time_sfix = set_time(seconds=int(sfix_seconds))
call print_time(Time_last_sfix,'Time_last_sfix: ')
end if
#endif
call data_override_init(Ocean_domain_in = Ocean_sfc%domain)
override_clock = mpp_clock_id('Override', flags=flags,grain=CLOCK_COMPONENT)
call mpp_get_compute_domain(Ocean_sfc%domain, isc, iec, jsc, jec)
allocate ( Ice_ocean_boundary% u_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% v_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% t_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% q_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% salt_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% lw_flux (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_vis_dir (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_vis_dif (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_nir_dir (isc:iec,jsc:jec), &
Ice_ocean_boundary% sw_flux_nir_dif (isc:iec,jsc:jec), &
Ice_ocean_boundary% lprec (isc:iec,jsc:jec), &
Ice_ocean_boundary% fprec (isc:iec,jsc:jec), &
Ice_ocean_boundary% runoff (isc:iec,jsc:jec), &
Ice_ocean_boundary% calving (isc:iec,jsc:jec), &
Ice_ocean_boundary% p (isc:iec,jsc:jec), &
Ice_ocean_boundary% aice(isc:iec,jsc:jec), &
Ice_ocean_boundary% mh_flux(isc:iec,jsc:jec), &
Ice_ocean_boundary% wfimelt(isc:iec,jsc:jec), &
Ice_ocean_boundary% wfiform(isc:iec,jsc:jec), &
Ice_ocean_boundary%wnd(isc:iec,jsc:jec))
Ice_ocean_boundary%u_flux = 0.0
Ice_ocean_boundary%v_flux = 0.0
Ice_ocean_boundary%t_flux = 0.0
Ice_ocean_boundary%q_flux = 0.0
Ice_ocean_boundary%salt_flux = 0.0
Ice_ocean_boundary%lw_flux = 0.0
Ice_ocean_boundary%sw_flux_vis_dir = 0.0
Ice_ocean_boundary%sw_flux_vis_dif = 0.0
Ice_ocean_boundary%sw_flux_nir_dir = 0.0
Ice_ocean_boundary%sw_flux_nir_dif = 0.0
Ice_ocean_boundary%lprec = 0.0
Ice_ocean_boundary%fprec = 0.0
Ice_ocean_boundary%runoff = 0.0
Ice_ocean_boundary%calving = 0.0
Ice_ocean_boundary%p = 0.0
Ice_ocean_boundary%aice = 0.0
Ice_ocean_boundary%mh_flux = 0.0
Ice_ocean_boundary% wfimelt = 0.0
Ice_ocean_boundary% wfiform = 0.0
Ice_ocean_boundary%wnd = 0.0
coupler_init_clock = mpp_clock_id('OASIS init', grain=CLOCK_COMPONENT)
call mpp_clock_begin(coupler_init_clock)
call external_coupler_sbc_init(Ocean_sfc%domain, dt_cpld, Run_len, &
accessom2%get_coupling_field_timesteps())
call mpp_clock_end(coupler_init_clock)
call mpp_clock_end(init_clock)
! loop over the coupled calls
call mpp_clock_begin(main_clock)
do nc=1, num_cpld_calls
call mpp_clock_begin(override_clock)
call ice_ocn_bnd_from_data(Ice_ocean_boundary)
call mpp_clock_end(override_clock)
call external_coupler_sbc_before(Ice_ocean_boundary, Ocean_sfc, nc, dt_cpld)
if (debug_this_module) then
call write_boundary_chksums(Ice_ocean_boundary)
endif
#ifdef ACCESS
if (redsea_gulfbay_sfix) then
if ((Time - Time_last_sfix) >= Time_sfix) then
do_sfix_now = .true.
Time_last_sfix = Time
else
do_sfix_now = .false.
end if
end if
#endif
call update_ocean_model(Ice_ocean_boundary, Ocean_state, Ocean_sfc, Time, Time_step_coupled)
Time = Time + Time_step_coupled
if ( mpp_pe() == mpp_root_pe() ) then
call accessom2%progress_date(int(dt_cpld))
endif
if( Time >= Time_restart ) then
Time_restart_current = Time
Time_restart = increment_date(Time, restart_interval(1), restart_interval(2), &
restart_interval(3), restart_interval(4), restart_interval(5), restart_interval(6) )
timestamp = date_to_string(time_restart_current)
write(stdoutunit,*) '=> NOTE from program ocean_solo: intermediate restart file is written and ', &
trim(timestamp),' is appended as prefix to each restart file name'
call ocean_model_restart(Ocean_state, timestamp)
call ocean_solo_restart(Time, Time_restart_current, timestamp)
end if
call external_coupler_sbc_after(Ice_ocean_boundary, Ocean_sfc, nc, dt_cpld )
enddo
call mpp_clock_end(main_clock)
call mpp_clock_begin(term_clock)
call external_coupler_restart( dt_cpld, num_cpld_calls, Ocean_sfc)
! close some of the main components
call ocean_model_end(Ocean_sfc, Ocean_state, Time)
call diag_manager_end(Time)
! need to reset pelist before calling mpp_clock_end
! call mpp_set_current_pelist()
! write restart file
call ocean_solo_restart(Time_end, Time_restart_current)
call fms_io_exit
call coupler%deinit()
! Allow libaccessom2 to check that all models are synchronised at the end of
! the run.
call get_date(Time, date_array(1), date_array(2), date_array(3), &
date_array(4), date_array(5), date_array(6))
call accessom2%deinit(cur_date_array=date_array)
call mpp_clock_end(term_clock)
call fms_end
call external_coupler_mpi_exit(coupler%localcomm, .true.)
print *, 'MOM5: --- completed ---'
contains
!--- writing restart file that contains running time and restart file writing time.
subroutine ocean_solo_restart(Time_run, Time_res, time_stamp)
type(time_type), intent(in) :: Time_run, Time_res
character(len=*), intent(in), optional :: time_stamp
character(len=128) :: file_run, file_res
integer :: yr, mon, day, hr, min, sec
! write restart file
if(present(time_stamp)) then
file_run = 'RESTART/'//trim(time_stamp)//'.ocean_solo.res'
file_res = 'RESTART/'//trim(time_stamp)//'.ocean_solo.intermediate.res'
else
file_run = 'RESTART/ocean_solo.res'
file_res = 'RESTART/ocean_solo.intermediate.res'
endif
call mpp_open( unit, file_run, nohdrs=.TRUE. )
if ( mpp_pe().EQ.mpp_root_pe() )then
write( unit, '(i6,8x,a)' )calendar_type, &
'(Calendar: no_calendar=0, thirty_day_months=1, julian=2, gregorian=3, noleap=4)'
call get_date(Time_init,yr,mon,day,hr,min,sec)
write( unit, '(6i6,8x,a)' )yr,mon,day,hr,min,sec, &
'Model start time: year, month, day, hour, minute, second'
call get_date(Time_run ,yr,mon,day,hr,min,sec)
write( unit, '(6i6,8x,a)' )yr,mon,day,hr,min,sec, &
'Current model time: year, month, day, hour, minute, second'
end if
call mpp_close(unit)
if(Time_res > Time_start) then
call mpp_open( unit, file_res, nohdrs=.TRUE. )
if ( mpp_pe().EQ.mpp_root_pe() )then
call get_date(Time_res ,yr,mon,day,hr,min,sec)
write( unit, '(6i6,8x,a)' )yr,mon,day,hr,min,sec, &
'Current intermediate restart time: year, month, day, hour, minute, second'
end if
call mpp_close(unit)
end if
end subroutine ocean_solo_restart
!====================================================================
! get forcing data from data_overide
subroutine ice_ocn_bnd_from_data(x)
type (ice_ocean_boundary_type) :: x
type(time_type) :: Time_next
Time_next = Time + Time_step_coupled
call data_override('OCN', 't_flux', x%t_flux , Time_next)
call data_override('OCN', 'u_flux', x%u_flux , Time_next)
call data_override('OCN', 'v_flux', x%v_flux , Time_next)
call data_override('OCN', 'q_flux', x%q_flux , Time_next)
call data_override('OCN', 'salt_flux', x%salt_flux , Time_next)
call data_override('OCN', 'lw_flux', x%lw_flux , Time_next)
call data_override('OCN', 'sw_flux_vis_dir', x%sw_flux_vis_dir, Time_next)
call data_override('OCN', 'sw_flux_vis_dif', x%sw_flux_vis_dif, Time_next)
call data_override('OCN', 'sw_flux_nir_dir', x%sw_flux_nir_dir, Time_next)
call data_override('OCN', 'sw_flux_nir_dif', x%sw_flux_nir_dif, Time_next)
call data_override('OCN', 'lprec', x%lprec , Time_next)
call data_override('OCN', 'fprec', x%fprec , Time_next)
call data_override('OCN', 'runoff', x%runoff , Time_next)
call data_override('OCN', 'calving', x%calving , Time_next)
call data_override('OCN', 'p', x%p , Time_next)
call data_override('OCN', 'aice', x%aice , Time_next)
call data_override('OCN', 'mh_flux', x%mh_flux , Time_next)
call mpp_sync()
end subroutine ice_ocn_bnd_from_data
! Here we provide some hooks for calling an interface between the OASIS3 coupler and MOM.
! The mom_oasis3_interface module is NOT general and it is expected that the user will
! heavily modify it depending on the coupling strategy.
! For clarity all variables should be passed as arguments rather than as globals.
! This may require changes to the argument lists.
! NOTE: libaccessom2 makes most of these functions redundant.
subroutine external_coupler_sbc_init(Dom, dt_cpld, Run_len, &
coupling_field_timesteps)
! Call to routine initializing arrays etc for transferring via coupler
! Perform sanity checks and make sure all inputs are compatible
use mom_oasis3_interface_mod, only : coupler_init
implicit none
type(domain2d) :: Dom
integer :: dt_cpld
type(time_type) :: Run_len
integer, dimension(:), intent(in) :: coupling_field_timesteps
call coupler_init(Dom, dt_cpld=dt_cpld, Run_len=Run_len, &
coupling_field_timesteps=coupling_field_timesteps)
end subroutine external_coupler_sbc_init
subroutine external_coupler_sbc_before(Ice_ocean_boundary, Ocean_sfc, nsteps, dt_cpld )
! Perform transfers before ocean time stepping
! May need special tratment on first call.
use mom_oasis3_interface_mod, only : from_coupler, into_coupler
implicit none
type (ice_ocean_boundary_type), intent(INOUT) :: Ice_ocean_boundary
type (ocean_public_type) , intent(INOUT) :: Ocean_sfc
integer , intent(IN) :: nsteps, dt_cpld
integer :: rtimestep ! Receive timestep
integer :: stimestep ! Send timestep
rtimestep = (nsteps-1) * dt_cpld ! runtime in this run segment!
stimestep = rtimestep
call from_coupler( rtimestep, Ocean_sfc, Ice_ocean_boundary )
call into_coupler( stimestep, Ocean_sfc, before_ocean_update = .true.)
end subroutine external_coupler_sbc_before
subroutine external_coupler_sbc_after(Ice_ocean_boundary, Ocean_sfc, nsteps, dt_cpld )
!Perform transfers after ocean time stepping
use mom_oasis3_interface_mod, only : into_coupler
implicit none
type (ice_ocean_boundary_type) :: Ice_ocean_boundary
type (ocean_public_type) :: Ocean_sfc
integer :: nsteps, dt_cpld
integer :: stimestep ! Send timestep
stimestep = nsteps * dt_cpld ! runtime in this run segment!
if (stimestep < num_cpld_calls*dt_cpld) call into_coupler(stimestep, Ocean_sfc, before_ocean_update = .false.)
end subroutine external_coupler_sbc_after
subroutine external_coupler_restart( dt_cpld, num_cpld_calls, Ocean_sfc)
!Clean up as appropriate and write a restart
use mom_oasis3_interface_mod, only : write_coupler_restart
implicit none
integer, intent(in) :: dt_cpld, num_cpld_calls
integer :: timestep
type (ocean_public_type) :: Ocean_sfc
timestep = num_cpld_calls * dt_cpld
call write_coupler_restart(timestep, Ocean_sfc, write_restart=.true.)
end subroutine external_coupler_restart
subroutine external_coupler_mpi_exit(mom_local_communicator, external_initialization)
! mpp_exit wont call MPI_FINALIZE if mom_local_communicator /= MPI_COMM_WORLD
implicit none
integer, intent(in) :: mom_local_communicator
logical, intent(in) :: external_initialization
integer :: ierr
call MPI_FINALIZE(ierr)
return
end subroutine external_coupler_mpi_exit
subroutine write_boundary_chksums(Ice_ocean_boundary)
type(ice_ocean_boundary_type), intent(in) :: Ice_ocean_boundary
call write_chksum_2d('Ice_ocean_boundary%u_flux', Ice_ocean_boundary%u_flux)
call write_chksum_2d('Ice_ocean_boundary%v_flux', Ice_ocean_boundary%v_flux)
call write_chksum_2d('Ice_ocean_boundary%t_flux', Ice_ocean_boundary%t_flux)
call write_chksum_2d('Ice_ocean_boundary%q_flux', Ice_ocean_boundary%q_flux)
call write_chksum_2d('Ice_ocean_boundary%salt_flux', Ice_ocean_boundary%salt_flux)
call write_chksum_2d('Ice_ocean_boundary%lw_flux', Ice_ocean_boundary%lw_flux)
call write_chksum_2d('Ice_ocean_boundary%sw_flux_vis_dir', Ice_ocean_boundary%sw_flux_vis_dir)
call write_chksum_2d('Ice_ocean_boundary%sw_flux_vis_dif', Ice_ocean_boundary%sw_flux_vis_dif)
call write_chksum_2d('Ice_ocean_boundary%sw_flux_nir_dir', Ice_ocean_boundary%sw_flux_nir_dir)
call write_chksum_2d('Ice_ocean_boundary%sw_flux_nir_dif', Ice_ocean_boundary%sw_flux_nir_dif)
call write_chksum_2d('Ice_ocean_boundary%lprec', Ice_ocean_boundary%lprec)
call write_chksum_2d('Ice_ocean_boundary%fprec', Ice_ocean_boundary%fprec)
call write_chksum_2d('Ice_ocean_boundary%runoff', Ice_ocean_boundary%runoff)
call write_chksum_2d('Ice_ocean_boundary%calving', Ice_ocean_boundary%calving)
call write_chksum_2d('Ice_ocean_boundary%p', Ice_ocean_boundary%p)
call write_chksum_2d('Ice_ocean_boundary%aice', Ice_ocean_boundary%aice)
call write_chksum_2d('Ice_ocean_boundary%mh_flux', Ice_ocean_boundary%mh_flux)
call write_chksum_2d('Ice_ocean_boundary%wfimelt', Ice_ocean_boundary%wfimelt)
call write_chksum_2d('Ice_ocean_boundary%wfiform', Ice_ocean_boundary%wfiform)
call write_chksum_2d('Ice_ocean_boundary%wnd', Ice_ocean_boundary%wnd)
end subroutine write_boundary_chksums
end program main
| gpl-2.0 |
marshallward/mom | src/land_lad2/shared/nf_utils/nf_utils.F90 | 10 | 1040 | module nf_utils_mod
use nfu_mod ! netcdf utilities
use nfc_mod ! netcdf utilities for compressed files
implicit none
private
! ==== public interfaces =====================================================
! export stuff from nfu_mod
public :: nfu_inq_dim, nfu_inq_var, nfu_inq_att
public :: nfu_def_dim, nfu_def_var
public :: nfu_put_att
public :: nfu_get_dim, nfu_get_dim_bounds
public :: nfu_put_var, nfu_put_rec
public :: nfu_get_var, nfu_get_rec
public :: nfu_get_valid_range, nfu_is_valid, nfu_validtype, nfu_validtype2ascii
! export stuff from nfc_mod
public :: nfu_inq_compressed_dim, nfu_inq_compressed_var
public :: nfu_get_compressed_var
public :: nfu_put_compressed_var
public :: nfu_get_compressed_rec
! ==== end of public interfaces ==============================================
! ==== module constants ======================================================
character(len=*), parameter :: &
version = '$Id: nf_utils.F90,v 17.0 2009/07/21 03:02:54 fms Exp $', &
tagname = '$Name: tikal $'
end module nf_utils_mod
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/sphere3.1_dp/ivrtes.f | 1 | 14743 | c
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c . .
c . copyright (c) 1998 by UCAR .
c . .
c . University Corporation for Atmospheric Research .
c . .
c . all rights reserved .
c . .
c . .
c . SPHEREPACK .
c . .
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c
c
c
c ... file ivrtes.f
c
c this file includes documentation and code for
c subroutine ivrtes i
c
c ... files which must be loaded with ivrtes.f
c
c sphcom.f, hrfft.f, vhses.f,shaes.f
c
c
c subroutine ivrtes(nlat,nlon,isym,nt,v,w,idvw,jdvw,a,b,mdab,ndab,
c + wvhses,lvhses,work,lwork,pertrb,ierror)
c
C*PL*ERROR* Comment line too long
c given the scalar spherical harmonic coefficients a and b, precomputed
C*PL*ERROR* Comment line too long
c by subroutine shaes for a scalar array vort, subroutine ivrtes computes
C*PL*ERROR* Comment line too long
c a divergence free vector field (v,w) whose vorticity is vort - pertrb.
C*PL*ERROR* Comment line too long
c w is the east longitude component and v is the colatitudinal component.
C*PL*ERROR* Comment line too long
c pertrb is a constant which must be subtracted from vort for (v,w) to
C*PL*ERROR* Comment line too long
c exist (see the description of pertrb below). usually pertrb is zero
C*PL*ERROR* Comment line too long
c or small relative to vort. the divergence of (v,w), as computed by
c ivrtes, is the zero scalar field. i.e., v(i,j) and w(i,j) are the
C*PL*ERROR* Comment line too long
c colaatitudinal and east longitude velocity components at colatitude
c
c theta(i) = (i-1)*pi/(nlat-1)
c
c and longitude
c
c lambda(j) = (j-1)*2*pi/nlon.
c
c the
c
c vorticity(v(i,j),w(i,j))
c
c = [-dv/dlambda + d(sint*w)/dtheta]/sint
c
c = vort(i,j) - pertrb
c
c and
c
c divergence(v(i,j),w(i,j))
c
c = [d(sint*v)/dtheta + dw/dlambda]/sint
c
c = 0.0
c
C*PL*ERROR* Comment line too long
c where sint = sin(theta(i)). required associated legendre polynomials
C*PL*ERROR* Comment line too long
c are stored rather than recomputed as they are in subroutine ivrtec.
c
c
c input parameters
c
c nlat the number of colatitudes on the full sphere including the
c poles. for example, nlat = 37 for a five degree grid.
c nlat determines the grid increment in colatitude as
c pi/(nlat-1). if nlat is odd the equator is located at
c grid point i=(nlat+1)/2. if nlat is even the equator is
c located half way between points i=nlat/2 and i=nlat/2+1.
c nlat must be at least 3. note: on the half sphere, the
c number of grid points in the colatitudinal direction is
c nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.
c
c nlon the number of distinct londitude points. nlon determines
c the grid increment in longitude as 2*pi/nlon. for example
c nlon = 72 for a five degree grid. nlon must be greater
c than 3. the axisymmetric case corresponds to nlon=1.
c the efficiency of the computation is improved when nlon
c is a product of small prime numbers.
c
c
c isym this has the same value as the isym that was input to
c subroutine shaes to compute the arrays a and b. isym
c determines whether (v,w) are computed on the full or half
c sphere as follows:
c
c = 0
c vort is not symmetric about the equator. in this case
c the vector field (v,w) is computed on the entire sphere.
c i.e., in the arrays v(i,j),w(i,j) for i=1,...,nlat and
c j=1,...,nlon.
c
c = 1
c
c vort is symmetric about the equator. in this case w is
c antiymmetric and v is symmetric about the equator. v
c and w are computed on the northern hemisphere only. i.e.,
c if nlat is odd they are computed for i=1,...,(nlat+1)/2
c and j=1,...,nlon. if nlat is even they are computed for
c i=1,...,nlat/2 and j=1,...,nlon.
c
c = 2
c
c vort is antisymmetric about the equator. in this case w is
c symmetric and v is antisymmetric about the equator. w
c and v are computed on the northern hemisphere only. i.e.,
c if nlat is odd they are computed for i=1,...,(nlat+1)/2
c and j=1,...,nlon. if nlat is even they are computed for
c i=1,...,nlat/2 and j=1,...,nlon.
c
c
C*PL*ERROR* Comment line too long
c nt in the program that calls ivrtes, nt is the number of vorticity
C*PL*ERROR* Comment line too long
c and vector fields. some computational efficiency is obtained
c for multiple fields. the arrays a,b,v, and w can be three
c dimensional and pertrb can be one dimensional corresponding
C*PL*ERROR* Comment line too long
c to an indexed multiple array vort. in this case, multiple vector
C*PL*ERROR* Comment line too long
c synthesis will be performed to compute each vector field. the
C*PL*ERROR* Comment line too long
c third index for a,b,v,w and first for pertrb is the synthesis
c index which assumes the values k=1,...,nt. for a single
C*PL*ERROR* Comment line too long
c synthesis set nt=1. the description of the remaining parameters
c is simplified by assuming that nt=1 or that a,b,v,w are two
c dimensional and pertrb is a constant.
c
c idvw the first dimension of the arrays v,w as it appears in
c the program that calls ivrtes. if isym = 0 then idvw
c must be at least nlat. if isym = 1 or 2 and nlat is
c even then idvw must be at least nlat/2. if isym = 1 or 2
c and nlat is odd then idvw must be at least (nlat+1)/2.
c
c jdvw the second dimension of the arrays v,w as it appears in
c the program that calls ivrtes. jdvw must be at least nlon.
c
c a,b two or three dimensional arrays (see input parameter nt)
c that contain scalar spherical harmonic coefficients
C*PL*ERROR* Comment line too long
c of the vorticity array vort as computed by subroutine shaes.
c *** a,b must be computed by shaes prior to calling ivrtes.
c
c mdab the first dimension of the arrays a and b as it appears in
c the program that calls ivrtes (and shaes). mdab must be at
c least min0(nlat,(nlon+2)/2) if nlon is even or at least
c min0(nlat,(nlon+1)/2) if nlon is odd.
c
c ndab the second dimension of the arrays a and b as it appears in
c the program that calls ivrtes (and shaes). ndab must be at
c least nlat.
c
c
c wvhses an array which must be initialized by subroutine vhsesi.
c once initialized
c wvhses can be used repeatedly by ivrtes as long as nlon
c and nlat remain unchanged. wvhses must not be altered
c between calls of ivrtes.
c
c
c lvhses the dimension of the array wvhses as it appears in the
c program that calls ivrtes. define
c
c l1 = min0(nlat,nlon/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c then lvhses must be at least
c
c (l1*l2*(nlat+nlat-l1+1))/2+nlon+15
c
c
c work a work array that does not have to be saved.
c
c lwork the dimension of the array work as it appears in the
c program that calls ivrtes. define
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c l1 = min0(nlat,nlon/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c if isym = 0 then lwork must be at least
c
c nlat*((2*nt+1)*nlon+2*l1*nt+1)
c
c if isym = 1 or 2 then lwork must be at least
c
c (2*nt+1)*l2*nlon+nlat*(2*nt*l1+1)
c
c **************************************************************
c
c output parameters
c
c
C*PL*ERROR* Comment line too long
c v,w two or three dimensional arrays (see input parameter nt) that
c contain a divergence free vector field whose vorticity is
C*PL*ERROR* Comment line too long
c vort - pertrb at the lattitude point theta(i)=pi/2-(i-1)*pi/(nlat-1)
C*PL*ERROR* Comment line too long
c and longitude point lambda(j)=(j-1)*2*pi/nlon. w is the east
C*PL*ERROR* Comment line too long
c longitude component and v is the colatitudinal component. the
c indices for v and w are defined at the input parameter isym.
c the divergence of (v,w) is the zero scalar field.
c
C*PL*ERROR* Comment line too long
c pertrb a nt dimensional array (see input parameter nt and assume nt=1
C*PL*ERROR* Comment line too long
c for the description that follows). vort - pertrb is a scalar
c field which can be the vorticity of a vector field (v,w).
c pertrb is related to the scalar harmonic coefficients a,b
c of vort (computed by shaes) by the formula
c
c pertrb = a(1,1)/(2.*sqrt(2.))
c
c an unperturbed vort can be the vorticity of a vector field
c only if a(1,1) is zero. if a(1,1) is nonzero (flagged by
c pertrb nonzero) then subtracting pertrb from vort yields a
c scalar field for which a(1,1) is zero.
c
c ierror = 0 no errors
c = 1 error in the specification of nlat
c = 2 error in the specification of nlon
c = 3 error in the specification of isym
c = 4 error in the specification of nt
c = 5 error in the specification of idvw
c = 6 error in the specification of jdvw
c = 7 error in the specification of mdab
c = 8 error in the specification of ndab
c = 9 error in the specification of lvhses
c = 10 error in the specification of lwork
c **********************************************************************
c
c
SUBROUTINE DIVRTES(NLAT,NLON,ISYM,NT,V,W,IDVW,JDVW,A,B,MDAB,NDAB,
+ WVHSES,LVHSES,WORK,LWORK,PERTRB,IERROR)
DOUBLE PRECISION V
DOUBLE PRECISION W
DOUBLE PRECISION A
DOUBLE PRECISION B
DOUBLE PRECISION WVHSES
DOUBLE PRECISION WORK
DOUBLE PRECISION PERTRB
DIMENSION V(IDVW,JDVW,NT),W(IDVW,JDVW,NT),PERTRB(NT)
DIMENSION A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)
DIMENSION WVHSES(LVHSES),WORK(LWORK)
c
c check input parameters
c
IERROR = 1
IF (NLAT.LT.3) RETURN
IERROR = 2
IF (NLON.LT.4) RETURN
IERROR = 3
IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN
IERROR = 4
IF (NT.LT.0) RETURN
IERROR = 5
IMID = (NLAT+1)/2
IF ((ISYM.EQ.0.AND.IDVW.LT.NLAT) .OR.
+ (ISYM.NE.0.AND.IDVW.LT.IMID)) RETURN
IERROR = 6
IF (JDVW.LT.NLON) RETURN
IERROR = 7
MMAX = MIN0(NLAT, (NLON+1)/2)
IF (MDAB.LT.MIN0(NLAT, (NLON+2)/2)) RETURN
IERROR = 8
IF (NDAB.LT.NLAT) RETURN
IERROR = 9
LZZ1 = 2*NLAT*IMID
LABC = 3* (MAX0(MMAX-2,0)* (NLAT+NLAT-MMAX-1))/2
L1 = MIN0(NLAT, (NLON+2)/2)
L2 = (NLAT+1)/2
LWMIN = (L1*L2* (NLAT+NLAT-L1+1))/2 + NLON + 15
IERROR = 10
c
c verify unsaved work space length
c
MN = MMAX*NLAT*NT
IF (ISYM.NE.0 .AND. LWORK.LT.NLAT* (2*NT*NLON+MAX0(6*IMID,NLON))+
+ 2*MN+NLAT) RETURN
IF (ISYM.EQ.0 .AND. LWORK.LT.IMID* (2*NT*NLON+MAX0(6*NLAT,NLON))+
+ 2*MN+NLAT) RETURN
IERROR = 0
c
c set work space pointers
c
ICR = 1
ICI = ICR + MN
IS = ICI + MN
IWK = IS + NLAT
LIWK = LWORK - 2*MN - NLAT
CALL DIVTES1(NLAT,NLON,ISYM,NT,V,W,IDVW,JDVW,WORK(ICR),WORK(ICI),
+ MMAX,WORK(IS),MDAB,NDAB,A,B,WVHSES,LVHSES,WORK(IWK),
+ LIWK,PERTRB,IERROR)
RETURN
END
SUBROUTINE DIVTES1(NLAT,NLON,ISYM,NT,V,W,IDVW,JDVW,CR,CI,MMAX,
+ SQNN,MDAB,NDAB,A,B,WSAV,LWSAV,WK,LWK,PERTRB,
+ IERROR)
DOUBLE PRECISION V
DOUBLE PRECISION W
DOUBLE PRECISION CR
DOUBLE PRECISION CI
DOUBLE PRECISION SQNN
DOUBLE PRECISION A
DOUBLE PRECISION B
DOUBLE PRECISION WSAV
DOUBLE PRECISION WK
DOUBLE PRECISION PERTRB
DOUBLE PRECISION FN
DOUBLE PRECISION BR
DOUBLE PRECISION BI
DIMENSION V(IDVW,JDVW,NT),W(IDVW,JDVW,NT),PERTRB(NT)
DIMENSION CR(MMAX,NLAT,NT),CI(MMAX,NLAT,NT),SQNN(NLAT)
DIMENSION A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)
DIMENSION WSAV(LWSAV),WK(LWK)
c
c preset coefficient multiplyers in vector
c
DO 1 N = 2,NLAT
FN = DBLE(N-1)
SQNN(N) = SQRT(FN* (FN+1.D0))
1 CONTINUE
c
c compute multiple vector fields coefficients
c
DO 2 K = 1,NT
c
c set vorticity field perturbation adjustment
c
PERTRB(K) = A(1,1,K)/ (2.D0*SQRT(2.D0))
c
c preset br,bi to 0.0
c
DO 3 N = 1,NLAT
DO 4 M = 1,MMAX
CR(M,N,K) = 0.0D0
CI(M,N,K) = 0.0D0
4 CONTINUE
3 CONTINUE
c
c compute m=0 coefficients
c
DO 5 N = 2,NLAT
CR(1,N,K) = A(1,N,K)/SQNN(N)
CI(1,N,K) = B(1,N,K)/SQNN(N)
5 CONTINUE
c
c compute m>0 coefficients
c
DO 6 M = 2,MMAX
DO 7 N = M,NLAT
CR(M,N,K) = A(M,N,K)/SQNN(N)
CI(M,N,K) = B(M,N,K)/SQNN(N)
7 CONTINUE
6 CONTINUE
2 CONTINUE
c
c set ityp for vector synthesis with divergence=0
c
IF (ISYM.EQ.0) THEN
ITYP = 2
ELSE IF (ISYM.EQ.1) THEN
ITYP = 5
ELSE IF (ISYM.EQ.2) THEN
ITYP = 8
END IF
c
c vector sythesize cr,ci into divergence free vector field (v,w)
c
CALL DVHSES(NLAT,NLON,ITYP,NT,V,W,IDVW,JDVW,BR,BI,CR,CI,MMAX,NLAT,
+ WSAV,LWSAV,WK,LWK,IERROR)
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/wmap/wmdrrg.f | 1 | 5927 | C
C $Id: wmdrrg.f,v 1.10 2008-07-27 00:17:36 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE WMDRRG(N,X,Y,ITYPE,NC,XC,YC)
C
C This subroutine draws a closed region filled as per the
C value of ITYPE. Legal values for ITYPE are:
C
C ITYPE = 'INDEXnnn' where "nnn" denotes a color index.
C = 'T' for thunderstorms.
C = 'SH' for showers.
C = 'R' for rain.
C = 'F' for flurries.
C = 'SN' for snow.
C = 'I' for ice.
C
C If NC is greater than 2, then the region resulting from the
C spline fit to (X(I),Y(I),I=1,N) will be clipped against the
C region in (XC(I),YC(I),I=1,NC) .
C
C X,Y and XC,YC are world coordinate values.
C
include 'wmcomn.h'
C
DIMENSION X(N),Y(N),XC(NC),YC(NC)
CHARACTER*(*) ITYPE
C
C Define necessary arrays and functions for the clipping calls.
C
COMMON /WMLGCM/IDRFLG
EXTERNAL WMLGFA
C
NPO = N
C
C Check error status.
C
IF (ICFELL('WMDRRG - Uncleared prior error',1) .NE. 0) RETURN
IF (NPO .LE. 1) THEN
CALL SETER (
+ 'WMDRRG - input region must have at least three points',
+ 1, 1)
RETURN
ENDIF
IF (NC.LT.1 .OR. NC.EQ.2) THEN
CALL SETER (
+ 'WMDRRG - fifth argument must be either 1 or greater than 2',
+ 1, 1)
RETURN
ENDIF
C
C If the original region has more than NPTS points, filter out NPTS
C points from it. Otherwise, keep the original points.
C
IF (NPO .GT. NPTS) THEN
NPO = NPTS
CALL WMFPTS(N,X,Y,NPTS,XO,YO)
ELSE
DO 100 I=1,N
XO(I) = X(I)
YO(I) = Y(I)
100 CONTINUE
ENDIF
C
C Construct a spline curve having NPTS points in it that represents
C the curve in (X,Y). We use Alan Cline's spline package for this.
C
IF (TNSION .EQ. -1.) THEN
TNSION = 0.001
ENDIF
C
C S is a common variable of maximal dimension NPTS.
C
CALL MSKRV1(NPO,XO,YO,SLOPE1,SLOPE2,XS,YS,TEMP,S,TNSION,4)
DO 10 I=1,NPTS
T = REAL(I-1)/REAL(NPTS-1)
IF (I.EQ.1) THEN
CALL MSKRV2(T,XOUT(I),YOUT(I),NPO,XO,YO,XS,YS,S,TNSION,1,
+ SLOPEL)
ELSE IF (I .EQ. NPTS) THEN
CALL MSKRV2(T,XOUT(I),YOUT(I),NPO,XO,YO,XS,YS,S,TNSION,0,SLP)
ELSE
CALL MSKRV2(T,XOUT(I),YOUT(I),NPO,XO,YO,XS,YS,S,TNSION,1,
+ SLOPER)
ENDIF
10 CONTINUE
C
C Convert spline curve to NDC space.
C
CALL WMW2NX(NPTS,XOUT,XS)
CALL WMW2NY(NPTS,YOUT,YS)
DO 20 I=1,NPTS
XOUT(I) = XS(I)
YOUT(I) = YS(I)
20 CONTINUE
C
C Convert clipping region to NDC.
C
IF (NC .GT. 2) THEN
CALL WMW2NX(NC,XC,RWORK(1))
CALL WMW2NY(NC,YC,RWORK(NC+1))
ENDIF
C
C Save the current normalization transformation number, and select
C transformation 0.
C
CALL GQCNTN(IER,NTRO)
CALL GSELNT(0)
CALL GQPLCI(IER,IPLLRO)
CALL GQFACI(IER,IFCLRO)
CALL GQFAIS(IER,INSTYO)
CALL GSFAIS(1)
C
C Draw the region.
C
IF (ITYPE(1:5).EQ.'INDEX' .OR. ITYPE(1:5).EQ.'index') THEN
C
C Get the color index.
C
ICLEN = LEN(ITYPE)
C
C Find the first non-blank character starting from the right
C of ITYPE and moving to the left. Adjust ICLEN accordingly.
C
DO 400 I=ICLEN,1,-1
IF (ITYPE(I:I) .NE. ' ') THEN
ICLEN = I
GO TO 405
ENDIF
400 CONTINUE
405 CONTINUE
IF (ICLEN .EQ. 6) THEN
READ(ITYPE(6:ICLEN),'(I1)') NDX
ELSE IF (ICLEN .EQ. 7) THEN
READ(ITYPE(6:ICLEN),'(I2)') NDX
ELSE IF (ICLEN .EQ. 8) THEN
READ(ITYPE(6:ICLEN),'(I3)') NDX
ELSE IF (ICLEN .EQ. 9) THEN
READ(ITYPE(6:ICLEN),'(I4)') NDX
ELSE IF (ICLEN .EQ. 10) THEN
READ(ITYPE(6:ICLEN),'(I5)') NDX
ELSE
NDX = 1
ENDIF
CALL GSFACI(NDX)
CALL GSPLCI(NDX)
C
C Draw the region.
C
IF (NC .EQ. 1) THEN
C
C No clipping to be done.
C
CALL GFA(NPTS,XOUT,YOUT)
ELSE
C
C Clip against the input poygon, set the value for IDRFLG so that
C no outline is drawn.
C
IDRFLG = 0
CALL PPINPO(RWORK(1),RWORK(NC+1),NC,XOUT,YOUT,NPTS,
+ RWORK(2*NC+1),IWORK(2*NC+1),NWRK-2*NC,WMLGFA,IER)
ENDIF
ELSE IF (ITYPE(1:1).EQ.'T' .OR. ITYPE(1:1).EQ.'t') THEN
C
C Thunderstorms.
C
CALL GSFACI(ICOLOR)
CALL GSPLCI(ICOLOR)
CALL WMRGWT(NPTS,XOUT,YOUT,37,102)
ELSE IF (ITYPE(1:2).EQ.'SH' .OR. ITYPE(1:2).EQ.'sh' .OR.
+ ITYPE(1:2).EQ.'Sh') THEN
C
C Showers.
C
CALL GSFACI(ICOLOR)
CALL GSPLCI(ICOLOR)
CALL WMRGWT(NPTS,XOUT,YOUT,37,101)
ELSE IF (ITYPE(1:1).EQ.'R' .OR. ITYPE(1:1).EQ.'r') THEN
C
C Rain.
C
CALL GSFACI(ICOLOR)
CALL GSPLCI(ICOLOR)
CALL WMRGWT(NPTS,XOUT,YOUT,37,103)
ELSE IF (ITYPE(1:1).EQ.'F' .OR. ITYPE(1:1).EQ.'f') THEN
C
C Flurries.
C
CALL GSFACI(ICOLOR)
CALL GSPLCI(ICOLOR)
CALL WMRGWT(NPTS,XOUT,YOUT,37,106)
ELSE IF (ITYPE(1:2).EQ.'SN' .OR. ITYPE(1:2).EQ.'sn' .OR.
+ ITYPE(1:2).EQ.'Sn') THEN
C
C Snow.
C
CALL GSFACI(ICOLOR)
CALL GSPLCI(ICOLOR)
CALL WMRGWT(NPTS,XOUT,YOUT,37,104)
ELSE IF (ITYPE(1:1).EQ.'I' .OR. ITYPE(1:1).EQ.'i') THEN
C
C Ice.
C
CALL GSFACI(ICOLOR)
CALL GSPLCI(ICOLOR)
CALL WMRGWT(NPTS,XOUT,YOUT,37,105)
ENDIF
C
C Restore original settings.
C
CALL GSELNT(NTRO)
CALL GSFAIS(INSTYO)
CALL GSFACI(IFCLRO)
CALL GSPLCI(IPLLRO)
C
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/plotchar/pcrset.f | 1 | 2344 | C
C $Id: pcrset.f,v 1.4 2008-07-27 00:17:20 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE PCRSET
C
C Calling PCRSET resets all internal parameters of PLOTCHAR to their
C default values.
C
C COMMON block declarations.
C
COMMON /PCPRMS/ ADDS,CONS,DSTB,DSTL,DSTR,DSTT,HPIC(3),IBNU,
+ IBXC(3),IBXF,ICEN,IORD,IOUC,IOUF,IPCC,IQUF,
+ ISHC,ISHF,ITEF,JCOD,LSCI(16),NFCC,NODF,RBXL,
+ RBXM,RBXX,RBXY,ROLW,RPLW,RSLW,SHDX,SHDY,SIZA,
+ SSIC,SSPR,SUBS,VPIC(3),WPIC(3),XBEG,XCEN,XEND,
+ XMUL(3),YBEG,YCEN,YEND,YMUL(3),ZINX,ZINY,ZINZ
SAVE /PCPRMS/
C
COMMON /PCSVEM/ ICOD,IDDA(8625),IDDL,RDGU(7000),IDPC(256),IERU,
+ INDA(789),INDL,INIT,IVCO,IVDU,NBPW,NPPW
SAVE /PCSVEM/
C
COMMON /PCPFLQ/ IMAP,OORV,RHTW
SAVE /PCPFLQ/
C
C Check for an uncleared prior error.
C
IF (ICFELL('PCRSET - UNCLEARED PRIOR ERROR',1).NE.0) RETURN
C
C Reset the values of internal parameters in common blocks.
C
ADDS=0.
CONS=0.
DSTB=0.
DSTL=0.
DSTR=0.
DSTT=0.
HPIC(1)=21.
HPIC(2)=13.
HPIC(3)= 9.
IBNU=3
IBXC(1)=-1
IBXC(2)=-1
IBXC(3)=-1
IBXF=0
ICEN=0
IMAP=0
IORD=1
IOUC=1
IOUF=0
IPCC=-1
IQUF=0
ISHC=0
ISHF=0
ITEF=0
JCOD=0
DO 101 I=1,16
LSCI(I)=-1
101 CONTINUE
NFCC=ICHAR(':')
NODF=0
OORV=0.
RBXL=0.
RBXM=.15
RBXX=-.05
RBXY=-.05
RHTW=1.75
ROLW=0.
RPLW=0.
RSLW=0.
SHDX=-.05
SHDY=-.05
SIZA=.888888888888888
SSIC=7.
SSPR=10.
SUBS=0.
VPIC(1)=32.
VPIC(2)=20.
VPIC(3)=14.
WPIC(1)=16.
WPIC(2)=12.
WPIC(3)= 8.
XBEG=0.
XCEN=0.
XEND=0.
XMUL(1)=1.
XMUL(2)=1.
XMUL(3)=1.
YBEG=0.
YCEN=0.
YEND=0.
YMUL(1)=1.
YMUL(2)=1.
YMUL(3)=1.
ZINX=1.
ZINY=1.
ZINZ=1.
C
C Done.
C
RETURN
C
END
| gpl-2.0 |
mtrbean/scipy | scipy/optimize/minpack/dpmpar.f | 155 | 5790 | double precision function dpmpar(i)
integer i
c **********
c
c Function dpmpar
c
c This function provides double precision machine parameters
c when the appropriate set of data statements is activated (by
c removing the c from column 1) and all other data statements are
c rendered inactive. Most of the parameter values were obtained
c from the corresponding Bell Laboratories Port Library function.
c
c The function statement is
c
c double precision function dpmpar(i)
c
c where
c
c i is an integer input variable set to 1, 2, or 3 which
c selects the desired machine parameter. If the machine has
c t base b digits and its smallest and largest exponents are
c emin and emax, respectively, then these parameters are
c
c dpmpar(1) = b**(1 - t), the machine precision,
c
c dpmpar(2) = b**(emin - 1), the smallest magnitude,
c
c dpmpar(3) = b**emax*(1 - b**(-t)), the largest magnitude.
c
c Argonne National Laboratory. MINPACK Project. November 1996.
c Burton S. Garbow, Kenneth E. Hillstrom, Jorge J. More'
c
c **********
integer mcheps(4)
integer minmag(4)
integer maxmag(4)
double precision dmach(3)
equivalence (dmach(1),mcheps(1))
equivalence (dmach(2),minmag(1))
equivalence (dmach(3),maxmag(1))
c
c Machine constants for the IBM 360/370 series,
c the Amdahl 470/V6, the ICL 2900, the Itel AS/6,
c the Xerox Sigma 5/7/9 and the Sel systems 85/86.
c
c data mcheps(1),mcheps(2) / z34100000, z00000000 /
c data minmag(1),minmag(2) / z00100000, z00000000 /
c data maxmag(1),maxmag(2) / z7fffffff, zffffffff /
c
c Machine constants for the Honeywell 600/6000 series.
c
c data mcheps(1),mcheps(2) / o606400000000, o000000000000 /
c data minmag(1),minmag(2) / o402400000000, o000000000000 /
c data maxmag(1),maxmag(2) / o376777777777, o777777777777 /
c
c Machine constants for the CDC 6000/7000 series.
c
c data mcheps(1) / 15614000000000000000b /
c data mcheps(2) / 15010000000000000000b /
c
c data minmag(1) / 00604000000000000000b /
c data minmag(2) / 00000000000000000000b /
c
c data maxmag(1) / 37767777777777777777b /
c data maxmag(2) / 37167777777777777777b /
c
c Machine constants for the PDP-10 (KA processor).
c
c data mcheps(1),mcheps(2) / "114400000000, "000000000000 /
c data minmag(1),minmag(2) / "033400000000, "000000000000 /
c data maxmag(1),maxmag(2) / "377777777777, "344777777777 /
c
c Machine constants for the PDP-10 (KI processor).
c
c data mcheps(1),mcheps(2) / "104400000000, "000000000000 /
c data minmag(1),minmag(2) / "000400000000, "000000000000 /
c data maxmag(1),maxmag(2) / "377777777777, "377777777777 /
c
c Machine constants for the PDP-11.
c
c data mcheps(1),mcheps(2) / 9472, 0 /
c data mcheps(3),mcheps(4) / 0, 0 /
c
c data minmag(1),minmag(2) / 128, 0 /
c data minmag(3),minmag(4) / 0, 0 /
c
c data maxmag(1),maxmag(2) / 32767, -1 /
c data maxmag(3),maxmag(4) / -1, -1 /
c
c Machine constants for the Burroughs 6700/7700 systems.
c
c data mcheps(1) / o1451000000000000 /
c data mcheps(2) / o0000000000000000 /
c
c data minmag(1) / o1771000000000000 /
c data minmag(2) / o7770000000000000 /
c
c data maxmag(1) / o0777777777777777 /
c data maxmag(2) / o7777777777777777 /
c
c Machine constants for the Burroughs 5700 system.
c
c data mcheps(1) / o1451000000000000 /
c data mcheps(2) / o0000000000000000 /
c
c data minmag(1) / o1771000000000000 /
c data minmag(2) / o0000000000000000 /
c
c data maxmag(1) / o0777777777777777 /
c data maxmag(2) / o0007777777777777 /
c
c Machine constants for the Burroughs 1700 system.
c
c data mcheps(1) / zcc6800000 /
c data mcheps(2) / z000000000 /
c
c data minmag(1) / zc00800000 /
c data minmag(2) / z000000000 /
c
c data maxmag(1) / zdffffffff /
c data maxmag(2) / zfffffffff /
c
c Machine constants for the Univac 1100 series.
c
c data mcheps(1),mcheps(2) / o170640000000, o000000000000 /
c data minmag(1),minmag(2) / o000040000000, o000000000000 /
c data maxmag(1),maxmag(2) / o377777777777, o777777777777 /
c
c Machine constants for the Data General Eclipse S/200.
c
c Note - it may be appropriate to include the following card -
c static dmach(3)
c
c data minmag/20k,3*0/,maxmag/77777k,3*177777k/
c data mcheps/32020k,3*0/
c
c Machine constants for the Harris 220.
c
c data mcheps(1),mcheps(2) / '20000000, '00000334 /
c data minmag(1),minmag(2) / '20000000, '00000201 /
c data maxmag(1),maxmag(2) / '37777777, '37777577 /
c
c Machine constants for the Cray-1.
c
c data mcheps(1) / 0376424000000000000000b /
c data mcheps(2) / 0000000000000000000000b /
c
c data minmag(1) / 0200034000000000000000b /
c data minmag(2) / 0000000000000000000000b /
c
c data maxmag(1) / 0577777777777777777777b /
c data maxmag(2) / 0000007777777777777776b /
c
c Machine constants for the Prime 400.
c
c data mcheps(1),mcheps(2) / :10000000000, :00000000123 /
c data minmag(1),minmag(2) / :10000000000, :00000100000 /
c data maxmag(1),maxmag(2) / :17777777777, :37777677776 /
c
c Machine constants for the VAX-11.
c
c data mcheps(1),mcheps(2) / 9472, 0 /
c data minmag(1),minmag(2) / 128, 0 /
c data maxmag(1),maxmag(2) / -32769, -1 /
c
c Machine constants for IEEE machines.
c
data dmach(1) /2.22044604926d-16/
data dmach(2) /2.22507385852d-308/
data dmach(3) /1.79769313485d+308/
c
dpmpar = dmach(i)
return
c
c Last card of function dpmpar.
c
end
| bsd-3-clause |
wilfeli/DMGameBasic | ExternalTools/Eigen/lapack/dlarf.f | 273 | 6167 | *> \brief \b DLARF
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DLARF + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarf.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarf.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarf.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DLARF( SIDE, M, N, V, INCV, TAU, C, LDC, WORK )
*
* .. Scalar Arguments ..
* CHARACTER SIDE
* INTEGER INCV, LDC, M, N
* DOUBLE PRECISION TAU
* ..
* .. Array Arguments ..
* DOUBLE PRECISION C( LDC, * ), V( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DLARF applies a real elementary reflector H to a real m by n matrix
*> C, from either the left or the right. H is represented in the form
*>
*> H = I - tau * v * v**T
*>
*> where tau is a real scalar and v is a real vector.
*>
*> If tau = 0, then H is taken to be the unit matrix.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] SIDE
*> \verbatim
*> SIDE is CHARACTER*1
*> = 'L': form H * C
*> = 'R': form C * H
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix C.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix C.
*> \endverbatim
*>
*> \param[in] V
*> \verbatim
*> V is DOUBLE PRECISION array, dimension
*> (1 + (M-1)*abs(INCV)) if SIDE = 'L'
*> or (1 + (N-1)*abs(INCV)) if SIDE = 'R'
*> The vector v in the representation of H. V is not used if
*> TAU = 0.
*> \endverbatim
*>
*> \param[in] INCV
*> \verbatim
*> INCV is INTEGER
*> The increment between elements of v. INCV <> 0.
*> \endverbatim
*>
*> \param[in] TAU
*> \verbatim
*> TAU is DOUBLE PRECISION
*> The value tau in the representation of H.
*> \endverbatim
*>
*> \param[in,out] C
*> \verbatim
*> C is DOUBLE PRECISION array, dimension (LDC,N)
*> On entry, the m by n matrix C.
*> On exit, C is overwritten by the matrix H * C if SIDE = 'L',
*> or C * H if SIDE = 'R'.
*> \endverbatim
*>
*> \param[in] LDC
*> \verbatim
*> LDC is INTEGER
*> The leading dimension of the array C. LDC >= max(1,M).
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension
*> (N) if SIDE = 'L'
*> or (M) if SIDE = 'R'
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup doubleOTHERauxiliary
*
* =====================================================================
SUBROUTINE DLARF( SIDE, M, N, V, INCV, TAU, C, LDC, WORK )
*
* -- LAPACK auxiliary routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
CHARACTER SIDE
INTEGER INCV, LDC, M, N
DOUBLE PRECISION TAU
* ..
* .. Array Arguments ..
DOUBLE PRECISION C( LDC, * ), V( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL APPLYLEFT
INTEGER I, LASTV, LASTC
* ..
* .. External Subroutines ..
EXTERNAL DGEMV, DGER
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILADLR, ILADLC
EXTERNAL LSAME, ILADLR, ILADLC
* ..
* .. Executable Statements ..
*
APPLYLEFT = LSAME( SIDE, 'L' )
LASTV = 0
LASTC = 0
IF( TAU.NE.ZERO ) THEN
! Set up variables for scanning V. LASTV begins pointing to the end
! of V.
IF( APPLYLEFT ) THEN
LASTV = M
ELSE
LASTV = N
END IF
IF( INCV.GT.0 ) THEN
I = 1 + (LASTV-1) * INCV
ELSE
I = 1
END IF
! Look for the last non-zero row in V.
DO WHILE( LASTV.GT.0 .AND. V( I ).EQ.ZERO )
LASTV = LASTV - 1
I = I - INCV
END DO
IF( APPLYLEFT ) THEN
! Scan for the last non-zero column in C(1:lastv,:).
LASTC = ILADLC(LASTV, N, C, LDC)
ELSE
! Scan for the last non-zero row in C(:,1:lastv).
LASTC = ILADLR(M, LASTV, C, LDC)
END IF
END IF
! Note that lastc.eq.0 renders the BLAS operations null; no special
! case is needed at this level.
IF( APPLYLEFT ) THEN
*
* Form H * C
*
IF( LASTV.GT.0 ) THEN
*
* w(1:lastc,1) := C(1:lastv,1:lastc)**T * v(1:lastv,1)
*
CALL DGEMV( 'Transpose', LASTV, LASTC, ONE, C, LDC, V, INCV,
$ ZERO, WORK, 1 )
*
* C(1:lastv,1:lastc) := C(...) - v(1:lastv,1) * w(1:lastc,1)**T
*
CALL DGER( LASTV, LASTC, -TAU, V, INCV, WORK, 1, C, LDC )
END IF
ELSE
*
* Form C * H
*
IF( LASTV.GT.0 ) THEN
*
* w(1:lastc,1) := C(1:lastc,1:lastv) * v(1:lastv,1)
*
CALL DGEMV( 'No transpose', LASTC, LASTV, ONE, C, LDC,
$ V, INCV, ZERO, WORK, 1 )
*
* C(1:lastc,1:lastv) := C(...) - w(1:lastc,1) * v(1:lastv,1)**T
*
CALL DGER( LASTC, LASTV, -TAU, WORK, 1, V, INCV, C, LDC )
END IF
END IF
RETURN
*
* End of DLARF
*
END
| mit |
likev/ncl | ncl_ncarg_src/external/lapack/dsysv.f | 3 | 5969 | SUBROUTINE DSYSV( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, WORK,
$ LWORK, INFO )
*
* -- LAPACK driver routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* June 30, 1999
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDA, LDB, LWORK, N, NRHS
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
DOUBLE PRECISION A( LDA, * ), B( LDB, * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DSYSV computes the solution to a real system of linear equations
* A * X = B,
* where A is an N-by-N symmetric matrix and X and B are N-by-NRHS
* matrices.
*
* The diagonal pivoting method is used to factor A as
* A = U * D * U**T, if UPLO = 'U', or
* A = L * D * L**T, if UPLO = 'L',
* where U (or L) is a product of permutation and unit upper (lower)
* triangular matrices, and D is symmetric and block diagonal with
* 1-by-1 and 2-by-2 diagonal blocks. The factored form of A is then
* used to solve the system of equations A * X = B.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* = 'U': Upper triangle of A is stored;
* = 'L': Lower triangle of A is stored.
*
* N (input) INTEGER
* The number of linear equations, i.e., the order of the
* matrix A. N >= 0.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrix B. NRHS >= 0.
*
* A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
* On entry, the symmetric matrix A. If UPLO = 'U', the leading
* N-by-N upper triangular part of A contains the upper
* triangular part of the matrix A, and the strictly lower
* triangular part of A is not referenced. If UPLO = 'L', the
* leading N-by-N lower triangular part of A contains the lower
* triangular part of the matrix A, and the strictly upper
* triangular part of A is not referenced.
*
* On exit, if INFO = 0, the block diagonal matrix D and the
* multipliers used to obtain the factor U or L from the
* factorization A = U*D*U**T or A = L*D*L**T as computed by
* DSYTRF.
*
* 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, as
* determined by DSYTRF. 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.
*
* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
* 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).
*
* 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 WORK. LWORK >= 1, and for best performance
* LWORK >= N*NB, where NB is the optimal blocksize for
* DSYTRF.
*
* If LWORK = -1, then a workspace query is assumed; the routine
* only calculates the optimal size of the WORK array, returns
* this value as the first entry of the WORK array, and no error
* message related to LWORK is issued by XERBLA.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, D(i,i) is exactly zero. The factorization
* has been completed, but the block diagonal matrix D is
* exactly singular, so the solution could not be computed.
*
* =====================================================================
*
* .. Local Scalars ..
LOGICAL LQUERY
INTEGER LWKOPT, NB
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILAENV
EXTERNAL LSAME, ILAENV
* ..
* .. External Subroutines ..
EXTERNAL DSYTRF, DSYTRS, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
LQUERY = ( LWORK.EQ.-1 )
IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( NRHS.LT.0 ) THEN
INFO = -3
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -5
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -8
ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
INFO = -10
END IF
*
IF( INFO.EQ.0 ) THEN
NB = ILAENV( 1, 'DSYTRF', UPLO, N, -1, -1, -1 )
LWKOPT = N*NB
WORK( 1 ) = LWKOPT
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DSYSV ', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Compute the factorization A = U*D*U' or A = L*D*L'.
*
CALL DSYTRF( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )
IF( INFO.EQ.0 ) THEN
*
* Solve the system A*X = B, overwriting B with X.
*
CALL DSYTRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
*
END IF
*
WORK( 1 ) = LWKOPT
*
RETURN
*
* End of DSYSV
*
END
| gpl-2.0 |
mtrbean/scipy | scipy/odr/odrpack/d_lpk.f | 109 | 39771 | *DCHEX
SUBROUTINE DCHEX(R,LDR,P,K,L,Z,LDZ,NZ,C,S,JOB)
C***BEGIN PROLOGUE DCHEX
C***DATE WRITTEN 780814 (YYMMDD)
C***REVISION DATE 820801 (YYMMDD)
C***CATEGORY NO. D7B
C***KEYWORDS CHOLESKY DECOMPOSITION,DOUBLE PRECISION,EXCHANGE,
C LINEAR ALGEBRA,LINPACK,MATRIX,POSITIVE DEFINITE
C***AUTHOR STEWART, G. W., (U. OF MARYLAND)
C***PURPOSE UPDATES THE CHOLESKY FACTORIZATION A=TRANS(R)*R OF A
C POSITIVE DEFINITE MATRIX A OF ORDER P UNDER DIAGONAL
C PERMUTATIONS OF THE FORM TRANS(E)*A*E WHERE E IS A
C PERMUTATION MATRIX.
C***DESCRIPTION
C DCHEX UPDATES THE CHOLESKY FACTORIZATION
C A = TRANS(R)*R
C OF A POSITIVE DEFINITE MATRIX A OF ORDER P UNDER DIAGONAL
C PERMUTATIONS OF THE FORM
C TRANS(E)*A*E
C WHERE E IS A PERMUTATION MATRIX. SPECIFICALLY, GIVEN
C AN UPPER TRIANGULAR MATRIX R AND A PERMUTATION MATRIX
C E (WHICH IS SPECIFIED BY K, L, AND JOB), DCHEX DETERMINES
C AN ORTHOGONAL MATRIX U SUCH THAT
C U*R*E = RR,
C WHERE RR IS UPPER TRIANGULAR. AT THE USERS OPTION, THE
C TRANSFORMATION U WILL BE MULTIPLIED INTO THE ARRAY Z.
C IF A = TRANS(X)*X, SO THAT R IS THE TRIANGULAR PART OF THE
C QR FACTORIZATION OF X, THEN RR IS THE TRIANGULAR PART OF THE
C QR FACTORIZATION OF X*E, I.E. X WITH ITS COLUMNS PERMUTED.
C FOR A LESS TERSE DESCRIPTION OF WHAT DCHEX DOES AND HOW
C IT MAY BE APPLIED, SEE THE LINPACK GUIDE.
C THE MATRIX Q IS DETERMINED AS THE PRODUCT U(L-K)*...*U(1)
C OF PLANE ROTATIONS OF THE FORM
C ( C(I) S(I) )
C ( ) ,
C ( -S(I) C(I) )
C WHERE C(I) IS DOUBLE PRECISION. THE ROWS THESE ROTATIONS OPERATE
C ON ARE DESCRIBED BELOW.
C THERE ARE TWO TYPES OF PERMUTATIONS, WHICH ARE DETERMINED
C BY THE VALUE OF JOB.
C 1. RIGHT CIRCULAR SHIFT (JOB = 1).
C THE COLUMNS ARE REARRANGED IN THE FOLLOWING ORDER.
C 1,...,K-1,L,K,K+1,...,L-1,L+1,...,P.
C U IS THE PRODUCT OF L-K ROTATIONS U(I), WHERE U(I)
C ACTS IN THE (L-I,L-I+1)-PLANE.
C 2. LEFT CIRCULAR SHIFT (JOB = 2).
C THE COLUMNS ARE REARRANGED IN THE FOLLOWING ORDER
C 1,...,K-1,K+1,K+2,...,L,K,L+1,...,P.
C U IS THE PRODUCT OF L-K ROTATIONS U(I), WHERE U(I)
C ACTS IN THE (K+I-1,K+I)-PLANE.
C ON ENTRY
C R DOUBLE PRECISION(LDR,P), WHERE LDR .GE. P.
C R CONTAINS THE UPPER TRIANGULAR FACTOR
C THAT IS TO BE UPDATED. ELEMENTS OF R
C BELOW THE DIAGONAL ARE NOT REFERENCED.
C LDR INTEGER.
C LDR IS THE LEADING DIMENSION OF THE ARRAY R.
C P INTEGER.
C P IS THE ORDER OF THE MATRIX R.
C K INTEGER.
C K IS THE FIRST COLUMN TO BE PERMUTED.
C L INTEGER.
C L IS THE LAST COLUMN TO BE PERMUTED.
C L MUST BE STRICTLY GREATER THAN K.
C Z DOUBLE PRECISION(LDZ,N)Z), WHERE LDZ .GE. P.
C Z IS AN ARRAY OF NZ P-VECTORS INTO WHICH THE
C TRANSFORMATION U IS MULTIPLIED. Z IS
C NOT REFERENCED IF NZ = 0.
C LDZ INTEGER.
C LDZ IS THE LEADING DIMENSION OF THE ARRAY Z.
C NZ INTEGER.
C NZ IS THE NUMBER OF COLUMNS OF THE MATRIX Z.
C JOB INTEGER.
C JOB DETERMINES THE TYPE OF PERMUTATION.
C JOB = 1 RIGHT CIRCULAR SHIFT.
C JOB = 2 LEFT CIRCULAR SHIFT.
C ON RETURN
C R CONTAINS THE UPDATED FACTOR.
C Z CONTAINS THE UPDATED MATRIX Z.
C C DOUBLE PRECISION(P).
C C CONTAINS THE COSINES OF THE TRANSFORMING ROTATIONS.
C S DOUBLE PRECISION(P).
C S CONTAINS THE SINES OF THE TRANSFORMING ROTATIONS.
C LINPACK. THIS VERSION DATED 08/14/78 .
C G. W. STEWART, UNIVERSITY OF MARYLAND, ARGONNE NATIONAL LAB.
C***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
C *LINPACK USERS GUIDE*, SIAM, 1979.
C***ROUTINES CALLED DROTG
C***END PROLOGUE DCHEX
C...SCALAR ARGUMENTS
INTEGER
+ JOB,K,L,LDR,LDZ,NZ,P
C...ARRAY ARGUMENTS
DOUBLE PRECISION
+ C(*),R(LDR,*),S(*),Z(LDZ,*)
C...LOCAL SCALARS
DOUBLE PRECISION
+ T,T1
INTEGER
+ I,II,IL,IU,J,JJ,KM1,KP1,LM1,LMK
C...EXTERNAL SUBROUTINES
EXTERNAL
+ DROTG
C...INTRINSIC FUNCTIONS
INTRINSIC
+ MAX0,MIN0
C***FIRST EXECUTABLE STATEMENT DCHEX
KM1 = K - 1
KP1 = K + 1
LMK = L - K
LM1 = L - 1
C PERFORM THE APPROPRIATE TASK.
GO TO (10,130), JOB
C RIGHT CIRCULAR SHIFT.
10 CONTINUE
C REORDER THE COLUMNS.
DO 20 I = 1, L
II = L - I + 1
S(I) = R(II,L)
20 CONTINUE
DO 40 JJ = K, LM1
J = LM1 - JJ + K
DO 30 I = 1, J
R(I,J+1) = R(I,J)
30 CONTINUE
R(J+1,J+1) = 0.0D0
40 CONTINUE
IF (K .EQ. 1) GO TO 60
DO 50 I = 1, KM1
II = L - I + 1
R(I,K) = S(II)
50 CONTINUE
60 CONTINUE
C CALCULATE THE ROTATIONS.
T = S(1)
DO 70 I = 1, LMK
T1 = S(I)
CALL DROTG(S(I+1),T,C(I),T1)
S(I) = T1
T = S(I+1)
70 CONTINUE
R(K,K) = T
DO 90 J = KP1, P
IL = MAX0(1,L-J+1)
DO 80 II = IL, LMK
I = L - II
T = C(II)*R(I,J) + S(II)*R(I+1,J)
R(I+1,J) = C(II)*R(I+1,J) - S(II)*R(I,J)
R(I,J) = T
80 CONTINUE
90 CONTINUE
C IF REQUIRED, APPLY THE TRANSFORMATIONS TO Z.
IF (NZ .LT. 1) GO TO 120
DO 110 J = 1, NZ
DO 100 II = 1, LMK
I = L - II
T = C(II)*Z(I,J) + S(II)*Z(I+1,J)
Z(I+1,J) = C(II)*Z(I+1,J) - S(II)*Z(I,J)
Z(I,J) = T
100 CONTINUE
110 CONTINUE
120 CONTINUE
GO TO 260
C LEFT CIRCULAR SHIFT
130 CONTINUE
C REORDER THE COLUMNS
DO 140 I = 1, K
II = LMK + I
S(II) = R(I,K)
140 CONTINUE
DO 160 J = K, LM1
DO 150 I = 1, J
R(I,J) = R(I,J+1)
150 CONTINUE
JJ = J - KM1
S(JJ) = R(J+1,J+1)
160 CONTINUE
DO 170 I = 1, K
II = LMK + I
R(I,L) = S(II)
170 CONTINUE
DO 180 I = KP1, L
R(I,L) = 0.0D0
180 CONTINUE
C REDUCTION LOOP.
DO 220 J = K, P
IF (J .EQ. K) GO TO 200
C APPLY THE ROTATIONS.
IU = MIN0(J-1,L-1)
DO 190 I = K, IU
II = I - K + 1
T = C(II)*R(I,J) + S(II)*R(I+1,J)
R(I+1,J) = C(II)*R(I+1,J) - S(II)*R(I,J)
R(I,J) = T
190 CONTINUE
200 CONTINUE
IF (J .GE. L) GO TO 210
JJ = J - K + 1
T = S(JJ)
CALL DROTG(R(J,J),T,C(JJ),S(JJ))
210 CONTINUE
220 CONTINUE
C APPLY THE ROTATIONS TO Z.
IF (NZ .LT. 1) GO TO 250
DO 240 J = 1, NZ
DO 230 I = K, LM1
II = I - KM1
T = C(II)*Z(I,J) + S(II)*Z(I+1,J)
Z(I+1,J) = C(II)*Z(I+1,J) - S(II)*Z(I,J)
Z(I,J) = T
230 CONTINUE
240 CONTINUE
250 CONTINUE
260 CONTINUE
RETURN
END
*DPODI
SUBROUTINE DPODI(A,LDA,N,DET,JOB)
C***BEGIN PROLOGUE DPODI
C***DATE WRITTEN 780814 (YYMMDD)
C***REVISION DATE 820801 (YYMMDD)
C***CATEGORY NO. D2B1B,D3B1B
C***KEYWORDS DETERMINANT,DOUBLE PRECISION,FACTOR,INVERSE,
C LINEAR ALGEBRA,LINPACK,MATRIX,POSITIVE DEFINITE
C***AUTHOR MOLER, C. B., (U. OF NEW MEXICO)
C***PURPOSE COMPUTES THE DETERMINANT AND INVERSE OF A CERTAIN DOUBLE
C PRECISION SYMMETRIC POSITIVE DEFINITE MATRIX (SEE ABSTRACT)
C USING THE FACTORS COMPUTED BY DPOCO, DPOFA OR DQRDC.
C***DESCRIPTION
C DPODI COMPUTES THE DETERMINANT AND INVERSE OF A CERTAIN
C DOUBLE PRECISION SYMMETRIC POSITIVE DEFINITE MATRIX (SEE BELOW)
C USING THE FACTORS COMPUTED BY DPOCO, DPOFA OR DQRDC.
C ON ENTRY
C A DOUBLE PRECISION(LDA, N)
C THE OUTPUT A FROM DPOCO OR DPOFA
C OR THE OUTPUT X FROM DQRDC.
C LDA INTEGER
C THE LEADING DIMENSION OF THE ARRAY A .
C N INTEGER
C THE ORDER OF THE MATRIX A .
C JOB INTEGER
C = 11 BOTH DETERMINANT AND INVERSE.
C = 01 INVERSE ONLY.
C = 10 DETERMINANT ONLY.
C ON RETURN
C A IF DPOCO OR DPOFA WAS USED TO FACTOR A , THEN
C DPODI PRODUCES THE UPPER HALF OF INVERSE(A) .
C IF DQRDC WAS USED TO DECOMPOSE X , THEN
C DPODI PRODUCES THE UPPER HALF OF INVERSE(TRANS(X)*X)
C WHERE TRANS(X) IS THE TRANSPOSE.
C ELEMENTS OF A BELOW THE DIAGONAL ARE UNCHANGED.
C IF THE UNITS DIGIT OF JOB IS ZERO, A IS UNCHANGED.
C DET DOUBLE PRECISION(2)
C DETERMINANT OF A OR OF TRANS(X)*X IF REQUESTED.
C OTHERWISE NOT REFERENCED.
C DETERMINANT = DET(1) * 10.0**DET(2)
C WITH 1.0 .LE. DET(1) .LT. 10.0
C OR DET(1) .EQ. 0.0 .
C ERROR CONDITION
C A DIVISION BY ZERO WILL OCCUR IF THE INPUT FACTOR CONTAINS
C A ZERO ON THE DIAGONAL AND THE INVERSE IS REQUESTED.
C IT WILL NOT OCCUR IF THE SUBROUTINES ARE CALLED CORRECTLY
C AND IF DPOCO OR DPOFA HAS SET INFO .EQ. 0 .
C LINPACK. THIS VERSION DATED 08/14/78 .
C CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.
C***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
C *LINPACK USERS GUIDE*, SIAM, 1979.
C***ROUTINES CALLED DAXPY,DSCAL
C***END PROLOGUE DPODI
C...SCALAR ARGUMENTS
INTEGER JOB,LDA,N
C...ARRAY ARGUMENTS
DOUBLE PRECISION A(LDA,*),DET(*)
C...LOCAL SCALARS
DOUBLE PRECISION S,T
INTEGER I,J,JM1,K,KP1
C...EXTERNAL SUBROUTINES
EXTERNAL DAXPY,DSCAL
C...INTRINSIC FUNCTIONS
INTRINSIC MOD
C***FIRST EXECUTABLE STATEMENT DPODI
IF (JOB/10 .EQ. 0) GO TO 70
DET(1) = 1.0D0
DET(2) = 0.0D0
S = 10.0D0
DO 50 I = 1, N
DET(1) = A(I,I)**2*DET(1)
C ...EXIT
IF (DET(1) .EQ. 0.0D0) GO TO 60
10 IF (DET(1) .GE. 1.0D0) GO TO 20
DET(1) = S*DET(1)
DET(2) = DET(2) - 1.0D0
GO TO 10
20 CONTINUE
30 IF (DET(1) .LT. S) GO TO 40
DET(1) = DET(1)/S
DET(2) = DET(2) + 1.0D0
GO TO 30
40 CONTINUE
50 CONTINUE
60 CONTINUE
70 CONTINUE
C COMPUTE INVERSE(R)
IF (MOD(JOB,10) .EQ. 0) GO TO 140
DO 100 K = 1, N
A(K,K) = 1.0D0/A(K,K)
T = -A(K,K)
CALL DSCAL(K-1,T,A(1,K),1)
KP1 = K + 1
IF (N .LT. KP1) GO TO 90
DO 80 J = KP1, N
T = A(K,J)
A(K,J) = 0.0D0
CALL DAXPY(K,T,A(1,K),1,A(1,J),1)
80 CONTINUE
90 CONTINUE
100 CONTINUE
C FORM INVERSE(R) * TRANS(INVERSE(R))
DO 130 J = 1, N
JM1 = J - 1
IF (JM1 .LT. 1) GO TO 120
DO 110 K = 1, JM1
T = A(K,J)
CALL DAXPY(K,T,A(1,J),1,A(1,K),1)
110 CONTINUE
120 CONTINUE
T = A(J,J)
CALL DSCAL(J,T,A(1,J),1)
130 CONTINUE
140 CONTINUE
RETURN
END
*DQRDC
SUBROUTINE DQRDC(X,LDX,N,P,QRAUX,JPVT,WORK,JOB)
C***BEGIN PROLOGUE DQRDC
C***DATE WRITTEN 780814 (YYMMDD)
C***REVISION DATE 820801 (YYMMDD)
C***CATEGORY NO. D5
C***KEYWORDS DECOMPOSITION,DOUBLE PRECISION,LINEAR ALGEBRA,LINPACK,
C MATRIX,ORTHOGONAL TRIANGULAR
C***AUTHOR STEWART, G. W., (U. OF MARYLAND)
C***PURPOSE USES HOUSEHOLDER TRANSFORMATIONS TO COMPUTE THE QR FACTORI-
C ZATION OF N BY P MATRIX X. COLUMN PIVOTING IS OPTIONAL.
C***DESCRIPTION
C DQRDC USES HOUSEHOLDER TRANSFORMATIONS TO COMPUTE THE QR
C FACTORIZATION OF AN N BY P MATRIX X. COLUMN PIVOTING
C BASED ON THE 2-NORMS OF THE REDUCED COLUMNS MAY BE
C PERFORMED AT THE USER'S OPTION.
C ON ENTRY
C X DOUBLE PRECISION(LDX,P), WHERE LDX .GE. N.
C X CONTAINS THE MATRIX WHOSE DECOMPOSITION IS TO BE
C COMPUTED.
C LDX INTEGER.
C LDX IS THE LEADING DIMENSION OF THE ARRAY X.
C N INTEGER.
C N IS THE NUMBER OF ROWS OF THE MATRIX X.
C P INTEGER.
C P IS THE NUMBER OF COLUMNS OF THE MATRIX X.
C JPVT INTEGER(P).
C JPVT CONTAINS INTEGERS THAT CONTROL THE SELECTION
C OF THE PIVOT COLUMNS. THE K-TH COLUMN X(K) OF X
C IS PLACED IN ONE OF THREE CLASSES ACCORDING TO THE
C VALUE OF JPVT(K).
C IF JPVT(K) .GT. 0, THEN X(K) IS AN INITIAL
C COLUMN.
C IF JPVT(K) .EQ. 0, THEN X(K) IS A FREE COLUMN.
C IF JPVT(K) .LT. 0, THEN X(K) IS A FINAL COLUMN.
C BEFORE THE DECOMPOSITION IS COMPUTED, INITIAL COLUMNS
C ARE MOVED TO THE BEGINNING OF THE ARRAY X AND FINAL
C COLUMNS TO THE END. BOTH INITIAL AND FINAL COLUMNS
C ARE FROZEN IN PLACE DURING THE COMPUTATION AND ONLY
C FREE COLUMNS ARE MOVED. AT THE K-TH STAGE OF THE
C REDUCTION, IF X(K) IS OCCUPIED BY A FREE COLUMN
C IT IS INTERCHANGED WITH THE FREE COLUMN OF LARGEST
C REDUCED NORM. JPVT IS NOT REFERENCED IF
C JOB .EQ. 0.
C WORK DOUBLE PRECISION(P).
C WORK IS A WORK ARRAY. WORK IS NOT REFERENCED IF
C JOB .EQ. 0.
C JOB INTEGER.
C JOB IS AN INTEGER THAT INITIATES COLUMN PIVOTING.
C IF JOB .EQ. 0, NO PIVOTING IS DONE.
C IF JOB .NE. 0, PIVOTING IS DONE.
C ON RETURN
C X X CONTAINS IN ITS UPPER TRIANGLE THE UPPER
C TRIANGULAR MATRIX R OF THE QR FACTORIZATION.
C BELOW ITS DIAGONAL X CONTAINS INFORMATION FROM
C WHICH THE ORTHOGONAL PART OF THE DECOMPOSITION
C CAN BE RECOVERED. NOTE THAT IF PIVOTING HAS
C BEEN REQUESTED, THE DECOMPOSITION IS NOT THAT
C OF THE ORIGINAL MATRIX X BUT THAT OF X
C WITH ITS COLUMNS PERMUTED AS DESCRIBED BY JPVT.
C QRAUX DOUBLE PRECISION(P).
C QRAUX CONTAINS FURTHER INFORMATION REQUIRED TO RECOVER
C THE ORTHOGONAL PART OF THE DECOMPOSITION.
C JPVT JPVT(K) CONTAINS THE INDEX OF THE COLUMN OF THE
C ORIGINAL MATRIX THAT HAS BEEN INTERCHANGED INTO
C THE K-TH COLUMN, IF PIVOTING WAS REQUESTED.
C LINPACK. THIS VERSION DATED 08/14/78 .
C G. W. STEWART, UNIVERSITY OF MARYLAND, ARGONNE NATIONAL LAB.
C***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
C *LINPACK USERS GUIDE*, SIAM, 1979.
C***ROUTINES CALLED DAXPY,DDOT,DNRM2,DSCAL,DSWAP
C***END PROLOGUE DQRDC
C...SCALAR ARGUMENTS
INTEGER
+ JOB,LDX,N,P
C...ARRAY ARGUMENTS
DOUBLE PRECISION
+ QRAUX(*),WORK(*),X(LDX,*)
INTEGER
+ JPVT(*)
C...LOCAL SCALARS
DOUBLE PRECISION
+ MAXNRM,NRMXL,T,TT
INTEGER
+ J,JJ,JP,L,LP1,LUP,MAXJ,PL,PU
LOGICAL
+ NEGJ,SWAPJ
C...EXTERNAL FUNCTIONS
DOUBLE PRECISION
+ DDOT,DNRM2
EXTERNAL
+ DDOT,DNRM2
C...EXTERNAL SUBROUTINES
EXTERNAL
+ DAXPY,DSCAL,DSWAP
C...INTRINSIC FUNCTIONS
INTRINSIC
+ DABS,DMAX1,DSIGN,DSQRT,MIN0
C***FIRST EXECUTABLE STATEMENT DQRDC
PL = 1
PU = 0
IF (JOB .EQ. 0) GO TO 60
C PIVOTING HAS BEEN REQUESTED. REARRANGE THE COLUMNS
C ACCORDING TO JPVT.
DO 20 J = 1, P
SWAPJ = JPVT(J) .GT. 0
NEGJ = JPVT(J) .LT. 0
JPVT(J) = J
IF (NEGJ) JPVT(J) = -J
IF (.NOT.SWAPJ) GO TO 10
IF (J .NE. PL) CALL DSWAP(N,X(1,PL),1,X(1,J),1)
JPVT(J) = JPVT(PL)
JPVT(PL) = J
PL = PL + 1
10 CONTINUE
20 CONTINUE
PU = P
DO 50 JJ = 1, P
J = P - JJ + 1
IF (JPVT(J) .GE. 0) GO TO 40
JPVT(J) = -JPVT(J)
IF (J .EQ. PU) GO TO 30
CALL DSWAP(N,X(1,PU),1,X(1,J),1)
JP = JPVT(PU)
JPVT(PU) = JPVT(J)
JPVT(J) = JP
30 CONTINUE
PU = PU - 1
40 CONTINUE
50 CONTINUE
60 CONTINUE
C COMPUTE THE NORMS OF THE FREE COLUMNS.
IF (PU .LT. PL) GO TO 80
DO 70 J = PL, PU
QRAUX(J) = DNRM2(N,X(1,J),1)
WORK(J) = QRAUX(J)
70 CONTINUE
80 CONTINUE
C PERFORM THE HOUSEHOLDER REDUCTION OF X.
LUP = MIN0(N,P)
DO 200 L = 1, LUP
IF (L .LT. PL .OR. L .GE. PU) GO TO 120
C LOCATE THE COLUMN OF LARGEST NORM AND BRING IT
C INTO THE PIVOT POSITION.
MAXNRM = 0.0D0
MAXJ = L
DO 100 J = L, PU
IF (QRAUX(J) .LE. MAXNRM) GO TO 90
MAXNRM = QRAUX(J)
MAXJ = J
90 CONTINUE
100 CONTINUE
IF (MAXJ .EQ. L) GO TO 110
CALL DSWAP(N,X(1,L),1,X(1,MAXJ),1)
QRAUX(MAXJ) = QRAUX(L)
WORK(MAXJ) = WORK(L)
JP = JPVT(MAXJ)
JPVT(MAXJ) = JPVT(L)
JPVT(L) = JP
110 CONTINUE
120 CONTINUE
QRAUX(L) = 0.0D0
IF (L .EQ. N) GO TO 190
C COMPUTE THE HOUSEHOLDER TRANSFORMATION FOR COLUMN L.
NRMXL = DNRM2(N-L+1,X(L,L),1)
IF (NRMXL .EQ. 0.0D0) GO TO 180
IF (X(L,L) .NE. 0.0D0) NRMXL = DSIGN(NRMXL,X(L,L))
CALL DSCAL(N-L+1,1.0D0/NRMXL,X(L,L),1)
X(L,L) = 1.0D0 + X(L,L)
C APPLY THE TRANSFORMATION TO THE REMAINING COLUMNS,
C UPDATING THE NORMS.
LP1 = L + 1
IF (P .LT. LP1) GO TO 170
DO 160 J = LP1, P
T = -DDOT(N-L+1,X(L,L),1,X(L,J),1)/X(L,L)
CALL DAXPY(N-L+1,T,X(L,L),1,X(L,J),1)
IF (J .LT. PL .OR. J .GT. PU) GO TO 150
IF (QRAUX(J) .EQ. 0.0D0) GO TO 150
TT = 1.0D0 - (DABS(X(L,J))/QRAUX(J))**2
TT = DMAX1(TT,0.0D0)
T = TT
TT = 1.0D0 + 0.05D0*TT*(QRAUX(J)/WORK(J))**2
IF (TT .EQ. 1.0D0) GO TO 130
QRAUX(J) = QRAUX(J)*DSQRT(T)
GO TO 140
130 CONTINUE
QRAUX(J) = DNRM2(N-L,X(L+1,J),1)
WORK(J) = QRAUX(J)
140 CONTINUE
150 CONTINUE
160 CONTINUE
170 CONTINUE
C SAVE THE TRANSFORMATION.
QRAUX(L) = X(L,L)
X(L,L) = -NRMXL
180 CONTINUE
190 CONTINUE
200 CONTINUE
RETURN
END
*DQRSL
SUBROUTINE DQRSL(X,LDX,N,K,QRAUX,Y,QY,QTY,B,RSD,XB,JOB,INFO)
C***BEGIN PROLOGUE DQRSL
C***DATE WRITTEN 780814 (YYMMDD)
C***REVISION DATE 820801 (YYMMDD)
C***CATEGORY NO. D9,D2A1
C***KEYWORDS DOUBLE PRECISION,LINEAR ALGEBRA,LINPACK,MATRIX,
C ORTHOGONAL TRIANGULAR,SOLVE
C***AUTHOR STEWART, G. W., (U. OF MARYLAND)
C***PURPOSE APPLIES THE OUTPUT OF DQRDC TO COMPUTE COORDINATE
C TRANSFORMATIONS, PROJECTIONS, AND LEAST SQUARES SOLUTIONS.
C***DESCRIPTION
C DQRSL APPLIES THE OUTPUT OF DQRDC TO COMPUTE COORDINATE
C TRANSFORMATIONS, PROJECTIONS, AND LEAST SQUARES SOLUTIONS.
C FOR K .LE. MIN(N,P), LET XK BE THE MATRIX
C XK = (X(JPVT(1)),X(JPVT(2)), ... ,X(JPVT(K)))
C FORMED FROM COLUMNNS JPVT(1), ... ,JPVT(K) OF THE ORIGINAL
C N X P MATRIX X THAT WAS INPUT TO DQRDC (IF NO PIVOTING WAS
C DONE, XK CONSISTS OF THE FIRST K COLUMNS OF X IN THEIR
C ORIGINAL ORDER). DQRDC PRODUCES A FACTORED ORTHOGONAL MATRIX Q
C AND AN UPPER TRIANGULAR MATRIX R SUCH THAT
C XK = Q * (R)
C (0)
C THIS INFORMATION IS CONTAINED IN CODED FORM IN THE ARRAYS
C X AND QRAUX.
C ON ENTRY
C X DOUBLE PRECISION(LDX,P).
C X CONTAINS THE OUTPUT OF DQRDC.
C LDX INTEGER.
C LDX IS THE LEADING DIMENSION OF THE ARRAY X.
C N INTEGER.
C N IS THE NUMBER OF ROWS OF THE MATRIX XK. IT MUST
C HAVE THE SAME VALUE AS N IN DQRDC.
C K INTEGER.
C K IS THE NUMBER OF COLUMNS OF THE MATRIX XK. K
C MUST NOT BE GREATER THAN MIN(N,P), WHERE P IS THE
C SAME AS IN THE CALLING SEQUENCE TO DQRDC.
C QRAUX DOUBLE PRECISION(P).
C QRAUX CONTAINS THE AUXILIARY OUTPUT FROM DQRDC.
C Y DOUBLE PRECISION(N)
C Y CONTAINS AN N-VECTOR THAT IS TO BE MANIPULATED
C BY DQRSL.
C JOB INTEGER.
C JOB SPECIFIES WHAT IS TO BE COMPUTED. JOB HAS
C THE DECIMAL EXPANSION ABCDE, WITH THE FOLLOWING
C MEANING.
C IF A .NE. 0, COMPUTE QY.
C IF B,C,D, OR E .NE. 0, COMPUTE QTY.
C IF C .NE. 0, COMPUTE B.
C IF D .NE. 0, COMPUTE RSD.
C IF E .NE. 0, COMPUTE XB.
C NOTE THAT A REQUEST TO COMPUTE B, RSD, OR XB
C AUTOMATICALLY TRIGGERS THE COMPUTATION OF QTY, FOR
C WHICH AN ARRAY MUST BE PROVIDED IN THE CALLING
C SEQUENCE.
C ON RETURN
C QY DOUBLE PRECISION(N).
C QY CONTAINS Q*Y, IF ITS COMPUTATION HAS BEEN
C REQUESTED.
C QTY DOUBLE PRECISION(N).
C QTY CONTAINS TRANS(Q)*Y, IF ITS COMPUTATION HAS
C BEEN REQUESTED. HERE TRANS(Q) IS THE
C TRANSPOSE OF THE MATRIX Q.
C B DOUBLE PRECISION(K)
C B CONTAINS THE SOLUTION OF THE LEAST SQUARES PROBLEM
C MINIMIZE NORM2(Y - XK*B),
C IF ITS COMPUTATION HAS BEEN REQUESTED. (NOTE THAT
C IF PIVOTING WAS REQUESTED IN DQRDC, THE J-TH
C COMPONENT OF B WILL BE ASSOCIATED WITH COLUMN JPVT(J)
C OF THE ORIGINAL MATRIX X THAT WAS INPUT INTO DQRDC.)
C RSD DOUBLE PRECISION(N).
C RSD CONTAINS THE LEAST SQUARES RESIDUAL Y - XK*B,
C IF ITS COMPUTATION HAS BEEN REQUESTED. RSD IS
C ALSO THE ORTHOGONAL PROJECTION OF Y ONTO THE
C ORTHOGONAL COMPLEMENT OF THE COLUMN SPACE OF XK.
C XB DOUBLE PRECISION(N).
C XB CONTAINS THE LEAST SQUARES APPROXIMATION XK*B,
C IF ITS COMPUTATION HAS BEEN REQUESTED. XB IS ALSO
C THE ORTHOGONAL PROJECTION OF Y ONTO THE COLUMN SPACE
C OF X.
C INFO INTEGER.
C INFO IS ZERO UNLESS THE COMPUTATION OF B HAS
C BEEN REQUESTED AND R IS EXACTLY SINGULAR. IN
C THIS CASE, INFO IS THE INDEX OF THE FIRST ZERO
C DIAGONAL ELEMENT OF R AND B IS LEFT UNALTERED.
C THE PARAMETERS QY, QTY, B, RSD, AND XB ARE NOT REFERENCED
C IF THEIR COMPUTATION IS NOT REQUESTED AND IN THIS CASE
C CAN BE REPLACED BY DUMMY VARIABLES IN THE CALLING PROGRAM.
C TO SAVE STORAGE, THE USER MAY IN SOME CASES USE THE SAME
C ARRAY FOR DIFFERENT PARAMETERS IN THE CALLING SEQUENCE. A
C FREQUENTLY OCCURING EXAMPLE IS WHEN ONE WISHES TO COMPUTE
C ANY OF B, RSD, OR XB AND DOES NOT NEED Y OR QTY. IN THIS
C CASE ONE MAY IDENTIFY Y, QTY, AND ONE OF B, RSD, OR XB, WHILE
C PROVIDING SEPARATE ARRAYS FOR ANYTHING ELSE THAT IS TO BE
C COMPUTED. THUS THE CALLING SEQUENCE
C CALL DQRSL(X,LDX,N,K,QRAUX,Y,DUM,Y,B,Y,DUM,110,INFO)
C WILL RESULT IN THE COMPUTATION OF B AND RSD, WITH RSD
C OVERWRITING Y. MORE GENERALLY, EACH ITEM IN THE FOLLOWING
C LIST CONTAINS GROUPS OF PERMISSIBLE IDENTIFICATIONS FOR
C A SINGLE CALLING SEQUENCE.
C 1. (Y,QTY,B) (RSD) (XB) (QY)
C 2. (Y,QTY,RSD) (B) (XB) (QY)
C 3. (Y,QTY,XB) (B) (RSD) (QY)
C 4. (Y,QY) (QTY,B) (RSD) (XB)
C 5. (Y,QY) (QTY,RSD) (B) (XB)
C 6. (Y,QY) (QTY,XB) (B) (RSD)
C IN ANY GROUP THE VALUE RETURNED IN THE ARRAY ALLOCATED TO
C THE GROUP CORRESPONDS TO THE LAST MEMBER OF THE GROUP.
C LINPACK. THIS VERSION DATED 08/14/78 .
C G. W. STEWART, UNIVERSITY OF MARYLAND, ARGONNE NATIONAL LAB.
C***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
C *LINPACK USERS GUIDE*, SIAM, 1979.
C***ROUTINES CALLED DAXPY,DCOPY,DDOT
C***END PROLOGUE DQRSL
C...SCALAR ARGUMENTS
INTEGER
+ INFO,JOB,K,LDX,N
C...ARRAY ARGUMENTS
DOUBLE PRECISION
+ B(*),QRAUX(*),QTY(*),QY(*),RSD(*),X(LDX,*),XB(*),
+ Y(*)
C...LOCAL SCALARS
DOUBLE PRECISION
+ T,TEMP
INTEGER
+ I,J,JJ,JU,KP1
LOGICAL
+ CB,CQTY,CQY,CR,CXB
C...EXTERNAL FUNCTIONS
DOUBLE PRECISION
+ DDOT
EXTERNAL
+ DDOT
C...EXTERNAL SUBROUTINES
EXTERNAL
+ DAXPY,DCOPY
C...INTRINSIC FUNCTIONS
INTRINSIC
+ MIN0,MOD
C***FIRST EXECUTABLE STATEMENT DQRSL
INFO = 0
C DETERMINE WHAT IS TO BE COMPUTED.
CQY = JOB/10000 .NE. 0
CQTY = MOD(JOB,10000) .NE. 0
CB = MOD(JOB,1000)/100 .NE. 0
CR = MOD(JOB,100)/10 .NE. 0
CXB = MOD(JOB,10) .NE. 0
JU = MIN0(K,N-1)
C SPECIAL ACTION WHEN N=1.
IF (JU .NE. 0) GO TO 40
IF (CQY) QY(1) = Y(1)
IF (CQTY) QTY(1) = Y(1)
IF (CXB) XB(1) = Y(1)
IF (.NOT.CB) GO TO 30
IF (X(1,1) .NE. 0.0D0) GO TO 10
INFO = 1
GO TO 20
10 CONTINUE
B(1) = Y(1)/X(1,1)
20 CONTINUE
30 CONTINUE
IF (CR) RSD(1) = 0.0D0
GO TO 250
40 CONTINUE
C SET UP TO COMPUTE QY OR QTY.
IF (CQY) CALL DCOPY(N,Y,1,QY,1)
IF (CQTY) CALL DCOPY(N,Y,1,QTY,1)
IF (.NOT.CQY) GO TO 70
C COMPUTE QY.
DO 60 JJ = 1, JU
J = JU - JJ + 1
IF (QRAUX(J) .EQ. 0.0D0) GO TO 50
TEMP = X(J,J)
X(J,J) = QRAUX(J)
T = -DDOT(N-J+1,X(J,J),1,QY(J),1)/X(J,J)
CALL DAXPY(N-J+1,T,X(J,J),1,QY(J),1)
X(J,J) = TEMP
50 CONTINUE
60 CONTINUE
70 CONTINUE
IF (.NOT.CQTY) GO TO 100
C COMPUTE TRANS(Q)*Y.
DO 90 J = 1, JU
IF (QRAUX(J) .EQ. 0.0D0) GO TO 80
TEMP = X(J,J)
X(J,J) = QRAUX(J)
T = -DDOT(N-J+1,X(J,J),1,QTY(J),1)/X(J,J)
CALL DAXPY(N-J+1,T,X(J,J),1,QTY(J),1)
X(J,J) = TEMP
80 CONTINUE
90 CONTINUE
100 CONTINUE
C SET UP TO COMPUTE B, RSD, OR XB.
IF (CB) CALL DCOPY(K,QTY,1,B,1)
KP1 = K + 1
IF (CXB) CALL DCOPY(K,QTY,1,XB,1)
IF (CR .AND. K .LT. N) CALL DCOPY(N-K,QTY(KP1),1,RSD(KP1),1)
IF (.NOT.CXB .OR. KP1 .GT. N) GO TO 120
DO 110 I = KP1, N
XB(I) = 0.0D0
110 CONTINUE
120 CONTINUE
IF (.NOT.CR) GO TO 140
DO 130 I = 1, K
RSD(I) = 0.0D0
130 CONTINUE
140 CONTINUE
IF (.NOT.CB) GO TO 190
C COMPUTE B.
DO 170 JJ = 1, K
J = K - JJ + 1
IF (X(J,J) .NE. 0.0D0) GO TO 150
INFO = J
C ......EXIT
GO TO 180
150 CONTINUE
B(J) = B(J)/X(J,J)
IF (J .EQ. 1) GO TO 160
T = -B(J)
CALL DAXPY(J-1,T,X(1,J),1,B,1)
160 CONTINUE
170 CONTINUE
180 CONTINUE
190 CONTINUE
IF (.NOT.CR .AND. .NOT.CXB) GO TO 240
C COMPUTE RSD OR XB AS REQUIRED.
DO 230 JJ = 1, JU
J = JU - JJ + 1
IF (QRAUX(J) .EQ. 0.0D0) GO TO 220
TEMP = X(J,J)
X(J,J) = QRAUX(J)
IF (.NOT.CR) GO TO 200
T = -DDOT(N-J+1,X(J,J),1,RSD(J),1)/X(J,J)
CALL DAXPY(N-J+1,T,X(J,J),1,RSD(J),1)
200 CONTINUE
IF (.NOT.CXB) GO TO 210
T = -DDOT(N-J+1,X(J,J),1,XB(J),1)/X(J,J)
CALL DAXPY(N-J+1,T,X(J,J),1,XB(J),1)
210 CONTINUE
X(J,J) = TEMP
220 CONTINUE
230 CONTINUE
240 CONTINUE
250 CONTINUE
RETURN
END
*DTRCO
SUBROUTINE DTRCO(T,LDT,N,RCOND,Z,JOB)
C***BEGIN PROLOGUE DTRCO
C***DATE WRITTEN 780814 (YYMMDD)
C***REVISION DATE 820801 (YYMMDD)
C***CATEGORY NO. D2A3
C***KEYWORDS CONDITION,DOUBLE PRECISION,FACTOR,LINEAR ALGEBRA,LINPACK,
C MATRIX,TRIANGULAR
C***AUTHOR MOLER, C. B., (U. OF NEW MEXICO)
C***PURPOSE ESTIMATES THE CONDITION OF A DOUBLE PRECISION TRIANGULAR
C MATRIX.
C***DESCRIPTION
C DTRCO ESTIMATES THE CONDITION OF A DOUBLE PRECISION TRIANGULAR
C MATRIX.
C ON ENTRY
C T DOUBLE PRECISION(LDT,N)
C T CONTAINS THE TRIANGULAR MATRIX. THE ZERO
C ELEMENTS OF THE MATRIX ARE NOT REFERENCED, AND
C THE CORRESPONDING ELEMENTS OF THE ARRAY CAN BE
C USED TO STORE OTHER INFORMATION.
C LDT INTEGER
C LDT IS THE LEADING DIMENSION OF THE ARRAY T.
C N INTEGER
C N IS THE ORDER OF THE SYSTEM.
C JOB INTEGER
C = 0 T IS LOWER TRIANGULAR.
C = NONZERO T IS UPPER TRIANGULAR.
C ON RETURN
C RCOND DOUBLE PRECISION
C AN ESTIMATE OF THE RECIPROCAL CONDITION OF T .
C FOR THE SYSTEM T*X = B , RELATIVE PERTURBATIONS
C IN T AND B OF SIZE EPSILON MAY CAUSE
C RELATIVE PERTURBATIONS IN X OF SIZE EPSILON/RCOND .
C IF RCOND IS SO SMALL THAT THE LOGICAL EXPRESSION
C 1.0 + RCOND .EQ. 1.0
C IS TRUE, THEN T MAY BE SINGULAR TO WORKING
C PRECISION. IN PARTICULAR, RCOND IS ZERO IF
C EXACT SINGULARITY IS DETECTED OR THE ESTIMATE
C UNDERFLOWS.
C Z DOUBLE PRECISION(N)
C A WORK VECTOR WHOSE CONTENTS ARE USUALLY UNIMPORTANT.
C IF T IS CLOSE TO A SINGULAR MATRIX, THEN Z IS
C AN APPROXIMATE NULL VECTOR IN THE SENSE THAT
C NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .
C LINPACK. THIS VERSION DATED 08/14/78 .
C CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.
C***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
C *LINPACK USERS GUIDE*, SIAM, 1979.
C***ROUTINES CALLED DASUM,DAXPY,DSCAL
C***END PROLOGUE DTRCO
C...SCALAR ARGUMENTS
DOUBLE PRECISION
+ RCOND
INTEGER
+ JOB,LDT,N
C...ARRAY ARGUMENTS
DOUBLE PRECISION
+ T(LDT,*),Z(*)
C...LOCAL SCALARS
DOUBLE PRECISION
+ EK,S,SM,TNORM,W,WK,WKM,YNORM
INTEGER
+ I1,J,J1,J2,K,KK,L
LOGICAL
+ LOWER
C...EXTERNAL FUNCTIONS
DOUBLE PRECISION
+ DASUM
EXTERNAL
+ DASUM
C...EXTERNAL SUBROUTINES
EXTERNAL
+ DAXPY,DSCAL
C...INTRINSIC FUNCTIONS
INTRINSIC
+ DABS,DMAX1,DSIGN
C***FIRST EXECUTABLE STATEMENT DTRCO
LOWER = JOB .EQ. 0
C COMPUTE 1-NORM OF T
TNORM = 0.0D0
DO 10 J = 1, N
L = J
IF (LOWER) L = N + 1 - J
I1 = 1
IF (LOWER) I1 = J
TNORM = DMAX1(TNORM,DASUM(L,T(I1,J),1))
10 CONTINUE
C RCOND = 1/(NORM(T)*(ESTIMATE OF NORM(INVERSE(T)))) .
C ESTIMATE = NORM(Z)/NORM(Y) WHERE T*Z = Y AND TRANS(T)*Y = E .
C TRANS(T) IS THE TRANSPOSE OF T .
C THE COMPONENTS OF E ARE CHOSEN TO CAUSE MAXIMUM LOCAL
C GROWTH IN THE ELEMENTS OF Y .
C THE VECTORS ARE FREQUENTLY RESCALED TO AVOID OVERFLOW.
C SOLVE TRANS(T)*Y = E
EK = 1.0D0
DO 20 J = 1, N
Z(J) = 0.0D0
20 CONTINUE
DO 100 KK = 1, N
K = KK
IF (LOWER) K = N + 1 - KK
IF (Z(K) .NE. 0.0D0) EK = DSIGN(EK,-Z(K))
IF (DABS(EK-Z(K)) .LE. DABS(T(K,K))) GO TO 30
S = DABS(T(K,K))/DABS(EK-Z(K))
CALL DSCAL(N,S,Z,1)
EK = S*EK
30 CONTINUE
WK = EK - Z(K)
WKM = -EK - Z(K)
S = DABS(WK)
SM = DABS(WKM)
IF (T(K,K) .EQ. 0.0D0) GO TO 40
WK = WK/T(K,K)
WKM = WKM/T(K,K)
GO TO 50
40 CONTINUE
WK = 1.0D0
WKM = 1.0D0
50 CONTINUE
IF (KK .EQ. N) GO TO 90
J1 = K + 1
IF (LOWER) J1 = 1
J2 = N
IF (LOWER) J2 = K - 1
DO 60 J = J1, J2
SM = SM + DABS(Z(J)+WKM*T(K,J))
Z(J) = Z(J) + WK*T(K,J)
S = S + DABS(Z(J))
60 CONTINUE
IF (S .GE. SM) GO TO 80
W = WKM - WK
WK = WKM
DO 70 J = J1, J2
Z(J) = Z(J) + W*T(K,J)
70 CONTINUE
80 CONTINUE
90 CONTINUE
Z(K) = WK
100 CONTINUE
S = 1.0D0/DASUM(N,Z,1)
CALL DSCAL(N,S,Z,1)
YNORM = 1.0D0
C SOLVE T*Z = Y
DO 130 KK = 1, N
K = N + 1 - KK
IF (LOWER) K = KK
IF (DABS(Z(K)) .LE. DABS(T(K,K))) GO TO 110
S = DABS(T(K,K))/DABS(Z(K))
CALL DSCAL(N,S,Z,1)
YNORM = S*YNORM
110 CONTINUE
IF (T(K,K) .NE. 0.0D0) Z(K) = Z(K)/T(K,K)
IF (T(K,K) .EQ. 0.0D0) Z(K) = 1.0D0
I1 = 1
IF (LOWER) I1 = K + 1
IF (KK .GE. N) GO TO 120
W = -Z(K)
CALL DAXPY(N-KK,W,T(I1,K),1,Z(I1),1)
120 CONTINUE
130 CONTINUE
C MAKE ZNORM = 1.0
S = 1.0D0/DASUM(N,Z,1)
CALL DSCAL(N,S,Z,1)
YNORM = S*YNORM
IF (TNORM .NE. 0.0D0) RCOND = YNORM/TNORM
IF (TNORM .EQ. 0.0D0) RCOND = 0.0D0
RETURN
END
*DTRSL
SUBROUTINE DTRSL(T,LDT,N,B,JOB,INFO)
C***BEGIN PROLOGUE DTRSL
C***DATE WRITTEN 780814 (YYMMDD)
C***REVISION DATE 820801 (YYMMDD)
C***CATEGORY NO. D2A3
C***KEYWORDS DOUBLE PRECISION,LINEAR ALGEBRA,LINPACK,MATRIX,SOLVE,
C TRIANGULAR
C***AUTHOR STEWART, G. W., (U. OF MARYLAND)
C***PURPOSE SOLVES SYSTEMS OF THE FORM T*X=B OR TRANS(T)*X=B WHERE T
C IS A TRIANGULAR MATRIX OF ORDER N.
C***DESCRIPTION
C DTRSL SOLVES SYSTEMS OF THE FORM
C T * X = B
C OR
C TRANS(T) * X = B
C WHERE T IS A TRIANGULAR MATRIX OF ORDER N. HERE TRANS(T)
C DENOTES THE TRANSPOSE OF THE MATRIX T.
C ON ENTRY
C T DOUBLE PRECISION(LDT,N)
C T CONTAINS THE MATRIX OF THE SYSTEM. THE ZERO
C ELEMENTS OF THE MATRIX ARE NOT REFERENCED, AND
C THE CORRESPONDING ELEMENTS OF THE ARRAY CAN BE
C USED TO STORE OTHER INFORMATION.
C LDT INTEGER
C LDT IS THE LEADING DIMENSION OF THE ARRAY T.
C N INTEGER
C N IS THE ORDER OF THE SYSTEM.
C B DOUBLE PRECISION(N).
C B CONTAINS THE RIGHT HAND SIDE OF THE SYSTEM.
C JOB INTEGER
C JOB SPECIFIES WHAT KIND OF SYSTEM IS TO BE SOLVED.
C IF JOB IS
C 00 SOLVE T*X=B, T LOWER TRIANGULAR,
C 01 SOLVE T*X=B, T UPPER TRIANGULAR,
C 10 SOLVE TRANS(T)*X=B, T LOWER TRIANGULAR,
C 11 SOLVE TRANS(T)*X=B, T UPPER TRIANGULAR.
C ON RETURN
C B B CONTAINS THE SOLUTION, IF INFO .EQ. 0.
C OTHERWISE B IS UNALTERED.
C INFO INTEGER
C INFO CONTAINS ZERO IF THE SYSTEM IS NONSINGULAR.
C OTHERWISE INFO CONTAINS THE INDEX OF
C THE FIRST ZERO DIAGONAL ELEMENT OF T.
C LINPACK. THIS VERSION DATED 08/14/78 .
C G. W. STEWART, UNIVERSITY OF MARYLAND, ARGONNE NATIONAL LAB.
C***REFERENCES DONGARRA J.J., BUNCH J.R., MOLER C.B., STEWART G.W.,
C *LINPACK USERS GUIDE*, SIAM, 1979.
C***ROUTINES CALLED DAXPY,DDOT
C***END PROLOGUE DTRSL
C...SCALAR ARGUMENTS
INTEGER
+ INFO,JOB,LDT,N
C...ARRAY ARGUMENTS
DOUBLE PRECISION
+ B(*),T(LDT,*)
C...LOCAL SCALARS
DOUBLE PRECISION
+ TEMP
INTEGER
+ CASE,J,JJ
C...EXTERNAL FUNCTIONS
DOUBLE PRECISION
+ DDOT
EXTERNAL
+ DDOT
C...EXTERNAL SUBROUTINES
EXTERNAL
+ DAXPY
C...INTRINSIC FUNCTIONS
INTRINSIC
+ MOD
C***FIRST EXECUTABLE STATEMENT DTRSL
C BEGIN BLOCK PERMITTING ...EXITS TO 150
C CHECK FOR ZERO DIAGONAL ELEMENTS.
DO 10 INFO = 1, N
C ......EXIT
IF (T(INFO,INFO) .EQ. 0.0D0) GO TO 150
10 CONTINUE
INFO = 0
C DETERMINE THE TASK AND GO TO IT.
CASE = 1
IF (MOD(JOB,10) .NE. 0) CASE = 2
IF (MOD(JOB,100)/10 .NE. 0) CASE = CASE + 2
GO TO (20,50,80,110), CASE
C SOLVE T*X=B FOR T LOWER TRIANGULAR
20 CONTINUE
B(1) = B(1)/T(1,1)
IF (N .LT. 2) GO TO 40
DO 30 J = 2, N
TEMP = -B(J-1)
CALL DAXPY(N-J+1,TEMP,T(J,J-1),1,B(J),1)
B(J) = B(J)/T(J,J)
30 CONTINUE
40 CONTINUE
GO TO 140
C SOLVE T*X=B FOR T UPPER TRIANGULAR.
50 CONTINUE
B(N) = B(N)/T(N,N)
IF (N .LT. 2) GO TO 70
DO 60 JJ = 2, N
J = N - JJ + 1
TEMP = -B(J+1)
CALL DAXPY(J,TEMP,T(1,J+1),1,B(1),1)
B(J) = B(J)/T(J,J)
60 CONTINUE
70 CONTINUE
GO TO 140
C SOLVE TRANS(T)*X=B FOR T LOWER TRIANGULAR.
80 CONTINUE
B(N) = B(N)/T(N,N)
IF (N .LT. 2) GO TO 100
DO 90 JJ = 2, N
J = N - JJ + 1
B(J) = B(J) - DDOT(JJ-1,T(J+1,J),1,B(J+1),1)
B(J) = B(J)/T(J,J)
90 CONTINUE
100 CONTINUE
GO TO 140
C SOLVE TRANS(T)*X=B FOR T UPPER TRIANGULAR.
110 CONTINUE
B(1) = B(1)/T(1,1)
IF (N .LT. 2) GO TO 130
DO 120 J = 2, N
B(J) = B(J) - DDOT(J-1,T(1,J),1,B(1),1)
B(J) = B(J)/T(J,J)
120 CONTINUE
130 CONTINUE
140 CONTINUE
150 CONTINUE
RETURN
END
| bsd-3-clause |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/string_length_2.f90 | 63 | 1844 | ! { dg-do run }
! { dg-options "-fdump-tree-original" }
! Test that all string length calculations are
! optimized away.
program main
character (len=999) :: c
character (len=5) :: unit
unit = ' '
read (unit=unit,fmt='(I5)') i ! Hide from optimizers
j = 7
c = '123456789'
if (len(c( 3 : 5 )) /= 3) call abort ! Case 1
if (len(c( i*(i+1) : (i+1)*i + 2 )) /= 3) call abort ! Case 2
if (len(c( i*(i+1) : 2 + (i+1)*i )) /= 3) call abort ! Case 3
if (len(c( i*(i+1) + 2 : (i+1)*i + 3 )) /= 2) call abort ! Case 4
if (len(c( 2 + i*(i+1) : (i+1)*i + 3 )) /= 2) call abort ! Case 5
if (len(c( i*(i+1) + 2 : 3 + (i+1)*i )) /= 2) call abort ! Case 6
if (len(c( 2 + i*(i+1) : 3 + (i+1)*i )) /= 2) call abort ! Case 7
if (len(c( i*(i+1) - 1 : (i+1)*i + 1 )) /= 3) call abort ! Case 8
if (len(c( i*(i+1) - 1 : 1 + (i+1)*i )) /= 3) call abort ! Case 9
if (len(c( i*(i+1) : (i+1)*i -(-1))) /= 2) call abort ! Case 10
if (len(c( i*(i+1) +(-2): (i+1)*i - 1 )) /= 2) call abort ! Case 11
if (len(c( i*(i+1) + 2 : (i+1)*i -(-4))) /= 3) call abort ! Case 12
if (len(c( i*(i+1) - 3 : (i+1)*i - 1 )) /= 3) call abort ! Case 13
if (len(c(13 - i*(i+1) :15 - (i+1)*i )) /= 3) call abort ! Case 14
if (len(c( i*(i+1) +(-1): (i+1)*i )) /= 2) call abort ! Case 15
if (len(c(-1 + i*(i+1) : (i+1)*i )) /= 2) call abort ! Case 16
if (len(c( i*(i+1) - 2 : (i+1)*i )) /= 3) call abort ! Case 17
if (len(c( (i-2)*(i-3) : (i-3)*(i-2) )) /= 1) call abort ! Case 18
end program main
! { dg-final { scan-tree-dump-times "_abort" 0 "original" } }
! { dg-final { cleanup-tree-dump "original" } }
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/sphere3.1_dp/divec.f | 1 | 12716 | c
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c . .
c . copyright (c) 1998 by UCAR .
c . .
c . University Corporation for Atmospheric Research .
c . .
c . all rights reserved .
c . .
c . .
c . SPHEREPACK .
c . .
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c
c
c
c ... file divec.f
c
c this file includes documentation and code for
c subroutine divec i
c
c ... files which must be loaded with divec.f
c
c sphcom.f, hrfft.f, vhaec.f,shsec.f
c
c
c subroutine divec(nlat,nlon,isym,nt,dv,idv,jdv,br,bi,mdb,ndb,
c + wshsec,lshsec,work,lwork,ierror)
c
C*PL*ERROR* Comment line too long
c given the vector spherical harmonic coefficients br and bi, precomputed
c by subroutine vhaec for a vector field (v,w), subroutine divec
C*PL*ERROR* Comment line too long
c computes the divergence of the vector field in the scalar array dv.
c dv(i,j) is the divergence at the colatitude
c
c theta(i) = (i-1)*pi/(nlat-1)
c
c and east longitude
c
c lambda(j) = (j-1)*2*pi/nlon
c
c on the sphere. i.e.
c
C*PL*ERROR* Comment line too long
c dv(i,j) = 1/sint*[ d(sint*v(i,j))/dtheta + d(w(i,j))/dlambda ]
c
c where sint = sin(theta(i)). w is the east longitudinal and v
c is the colatitudinal component of the vector field from which
c br,bi were precomputed. required associated legendre polynomials
c are recomputed rather than stored as they are in subroutine dives.
c
c
c input parameters
c
c nlat the number of colatitudes on the full sphere including the
c poles. for example, nlat = 37 for a five degree grid.
c nlat determines the grid increment in colatitude as
c pi/(nlat-1). if nlat is odd the equator is located at
c grid point i=(nlat+1)/2. if nlat is even the equator is
c located half way between points i=nlat/2 and i=nlat/2+1.
c nlat must be at least 3. note: on the half sphere, the
c number of grid points in the colatitudinal direction is
c nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.
c
c nlon the number of distinct londitude points. nlon determines
c the grid increment in longitude as 2*pi/nlon. for example
c nlon = 72 for a five degree grid. nlon must be greater than
c 3. the efficiency of the computation is improved when nlon
c is a product of small prime numbers.
c
c
c isym a parameter which determines whether the divergence is
c computed on the full or half sphere as follows:
c
c = 0
c
c the symmetries/antsymmetries described in isym=1,2 below
c do not exist in (v,w) about the equator. in this case the
c divergence is neither symmetric nor antisymmetric about
c the equator. the divergence is computed on the entire
c sphere. i.e., in the array dv(i,j) for i=1,...,nlat and
c j=1,...,nlon.
c
c = 1
c
c w is antisymmetric and v is symmetric about the equator.
c in this case the divergence is antisymmetyric about
c the equator and is computed for the northern hemisphere
c only. i.e., if nlat is odd the divergence is computed
c in the array dv(i,j) for i=1,...,(nlat+1)/2 and for
c j=1,...,nlon. if nlat is even the divergence is computed
c in the array dv(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c = 2
c w is symmetric and v is antisymmetric about the equator
c in this case the divergence is symmetyric about the
c equator and is computed for the northern hemisphere
c only. i.e., if nlat is odd the divergence is computed
c in the array dv(i,j) for i=1,...,(nlat+1)/2 and for
c j=1,...,nlon. if nlat is even the divergence is computed
c in the array dv(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c
c nt nt is the number of scalar and vector fields. some
c computational efficiency is obtained for multiple fields.
C*PL*ERROR* Comment line too long
c can be three dimensional corresponding to an indexed multiple
c vector field. in this case multiple scalar synthesis will
c be performed to compute the divergence for each field. the
c third index is the synthesis index which assumes the values
c k=1,...,nt. for a single synthesis set nt = 1. the
c description of the remaining parameters is simplified by
C*PL*ERROR* Comment line too long
c assuming that nt=1 or that all the arrays are two dimensional.
c
c idv the first dimension of the array dv as it appears in
c the program that calls divec. if isym = 0 then idv
c must be at least nlat. if isym = 1 or 2 and nlat is
c even then idv must be at least nlat/2. if isym = 1 or 2
c and nlat is odd then idv must be at least (nlat+1)/2.
c
c jdv the second dimension of the array dv as it appears in
c the program that calls divec. jdv must be at least nlon.
c
c br,bi two or three dimensional arrays (see input parameter nt)
c that contain vector spherical harmonic coefficients
c of the vector field (v,w) as computed by subroutine vhaec.
c *** br and bi must be computed by vhaec prior to calling
c divec.
c
c mdb the first dimension of the arrays br and bi as it
c appears in the program that calls divec. mdb must be at
c least min0(nlat,nlon/2) if nlon is even or at least
c min0(nlat,(nlon+1)/2) if nlon is odd.
c
c ndb the second dimension of the arrays br and bi as it
c appears in the program that calls divec. ndb must be at
c least nlat.
c
c
c wshsec an array which must be initialized by subroutine shseci.
c once initialized,
c wshsec can be used repeatedly by divec as long as nlon
c and nlat remain unchanged. wshsec must not be altered
c between calls of divec.
c
c
c lshsec the dimension of the array wshsec as it appears in the
c program that calls divec. define
c
c l1 = min0(nlat,(nlon+2)/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c then lshsec must be at least
c
c 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15
c
c
c work a work array that does not have to be saved.
c
c lwork the dimension of the array work as it appears in the
c program that calls divec. define
c
c l1 = min0(nlat,(nlon+2)/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c if isym is zero then lwork must be at least
c
c nlat*(nt*nlon+max0(3*l2,nlon)+2*nt*l1+1)
c
c if isym is not zero then lwork must be at least
c
c l2*(nt*nlon+max0(3*nlat,nlon)) + nlat*(2*nt*l1+1)
c
c
c **************************************************************
c
c output parameters
c
c
c dv a two or three dimensional array (see input parameter nt)
c that contains the divergence of the vector field (v,w)
c whose coefficients br,bi where computed by subroutine
c vhaec. dv(i,j) is the divergence at the colatitude point
c theta(i) = (i-1)*pi/(nlat-1) and longitude point
c lambda(j) = (j-1)*2*pi/nlon. the index ranges are defined
c above at the input parameter isym.
c
c
c ierror = 0 no errors
c = 1 error in the specification of nlat
c = 2 error in the specification of nlon
c = 3 error in the specification of isym
c = 4 error in the specification of nt
c = 5 error in the specification of idv
c = 6 error in the specification of jdv
c = 7 error in the specification of mdb
c = 8 error in the specification of ndb
c = 9 error in the specification of lshsec
c = 10 error in the specification of lwork
c **********************************************************************
c
SUBROUTINE DDIVEC(NLAT,NLON,ISYM,NT,DV,IDV,JDV,BR,BI,MDB,NDB,
+ WSHSEC,LSHSEC,WORK,LWORK,IERROR)
DOUBLE PRECISION DV
DOUBLE PRECISION BR
DOUBLE PRECISION BI
DOUBLE PRECISION WSHSEC
DOUBLE PRECISION WORK
DIMENSION DV(IDV,JDV,NT),BR(MDB,NDB,NT),BI(MDB,NDB,NT)
DIMENSION WSHSEC(LSHSEC),WORK(LWORK)
c
c check input parameters
c
IERROR = 1
IF (NLAT.LT.3) RETURN
IERROR = 2
IF (NLON.LT.4) RETURN
IERROR = 3
IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN
IERROR = 4
IF (NT.LT.0) RETURN
IERROR = 5
IMID = (NLAT+1)/2
IF ((ISYM.EQ.0.AND.IDV.LT.NLAT) .OR.
+ (ISYM.GT.0.AND.IDV.LT.IMID)) RETURN
IERROR = 6
IF (JDV.LT.NLON) RETURN
IERROR = 7
IF (MDB.LT.MIN0(NLAT, (NLON+1)/2)) RETURN
MMAX = MIN0(NLAT, (NLON+2)/2)
IERROR = 8
IF (NDB.LT.NLAT) RETURN
IERROR = 9
c
c verify saved work space (same as shsec)
c
IMID = (NLAT+1)/2
LZZ1 = 2*NLAT*IMID
LABC = 3* (MAX0(MMAX-2,0)* (NLAT+NLAT-MMAX-1))/2
LWMIN = LZZ1 + LABC + NLON + 15
IF (LSHSEC.LT.LWMIN) RETURN
c
c verify unsaved work space (add to what shec requires)
c
IERROR = 10
LS = NLAT
IF (ISYM.GT.0) LS = IMID
NLN = NT*LS*NLON
c
c set first dimension for a,b (as requried by shsec)
c
MAB = MIN0(NLAT,NLON/2+1)
MN = MAB*NLAT*NT
c if(lwork .lt. nln+max0(ls*nlon,3*nlat*imid)+2*mn+nlat) return
L1 = MIN0(NLAT, (NLON+2)/2)
L2 = (NLAT+1)/2
IF (ISYM.EQ.0) THEN
LWKMIN = NLAT* (NT*NLON+MAX0(3*L2,NLON)+2*NT*L1+1)
ELSE
LWKMIN = L2* (NT*NLON+MAX0(3*NLAT,NLON)) + NLAT* (2*NT*L1+1)
END IF
IF (LWORK.LT.LWKMIN) RETURN
IERROR = 0
c
c set work space pointers
c
IA = 1
IB = IA + MN
IS = IB + MN
IWK = IS + NLAT
LWK = LWORK - 2*MN - NLAT
CALL DDIVEC1(NLAT,NLON,ISYM,NT,DV,IDV,JDV,BR,BI,MDB,NDB,WORK(IA),
+ WORK(IB),MAB,WORK(IS),WSHSEC,LSHSEC,WORK(IWK),LWK,
+ IERROR)
RETURN
END
SUBROUTINE DDIVEC1(NLAT,NLON,ISYM,NT,DV,IDV,JDV,BR,BI,MDB,NDB,A,B,
+ MAB,SQNN,WSHSEC,LSHSEC,WK,LWK,IERROR)
DOUBLE PRECISION DV
DOUBLE PRECISION BR
DOUBLE PRECISION BI
DOUBLE PRECISION A
DOUBLE PRECISION B
DOUBLE PRECISION SQNN
DOUBLE PRECISION WSHSEC
DOUBLE PRECISION WK
DOUBLE PRECISION FN
DIMENSION DV(IDV,JDV,NT),BR(MDB,NDB,NT),BI(MDB,NDB,NT)
DIMENSION A(MAB,NLAT,NT),B(MAB,NLAT,NT),SQNN(NLAT)
DIMENSION WSHSEC(LSHSEC),WK(LWK)
c
c set coefficient multiplyers
c
DO 1 N = 2,NLAT
FN = DBLE(N-1)
SQNN(N) = SQRT(FN* (FN+1.D0))
1 CONTINUE
c
c compute divergence scalar coefficients for each vector field
c
DO 2 K = 1,NT
DO 3 N = 1,NLAT
DO 4 M = 1,MAB
A(M,N,K) = 0.0D0
B(M,N,K) = 0.0D0
4 CONTINUE
3 CONTINUE
c
c compute m=0 coefficients
c
DO 5 N = 2,NLAT
A(1,N,K) = -SQNN(N)*BR(1,N,K)
B(1,N,K) = -SQNN(N)*BI(1,N,K)
5 CONTINUE
c
c compute m>0 coefficients using vector spherepack value for mmax
c
MMAX = MIN0(NLAT, (NLON+1)/2)
DO 6 M = 2,MMAX
DO 7 N = M,NLAT
A(M,N,K) = -SQNN(N)*BR(M,N,K)
B(M,N,K) = -SQNN(N)*BI(M,N,K)
7 CONTINUE
6 CONTINUE
2 CONTINUE
c
c synthesize a,b into dv
c
CALL DSHSEC(NLAT,NLON,ISYM,NT,DV,IDV,JDV,A,B,MAB,NLAT,WSHSEC,
+ LSHSEC,WK,LWK,IERROR)
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/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
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/zheevr.f | 3 | 18695 | SUBROUTINE ZHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
$ ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
$ RWORK, LRWORK, IWORK, LIWORK, INFO )
*
* -- LAPACK driver routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* March 20, 2000
*
* .. Scalar Arguments ..
CHARACTER JOBZ, RANGE, UPLO
INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK,
$ M, N
DOUBLE PRECISION ABSTOL, VL, VU
* ..
* .. Array Arguments ..
INTEGER ISUPPZ( * ), IWORK( * )
DOUBLE PRECISION RWORK( * ), W( * )
COMPLEX*16 A( LDA, * ), WORK( * ), Z( LDZ, * )
* ..
*
* Purpose
* =======
*
* ZHEEVR computes selected eigenvalues and, optionally, eigenvectors
* of a complex Hermitian matrix T. Eigenvalues and eigenvectors can
* be selected by specifying either a range of values or a range of
* indices for the desired eigenvalues.
*
* Whenever possible, ZHEEVR calls ZSTEGR to compute the
* eigenspectrum using Relatively Robust Representations. ZSTEGR
* computes eigenvalues by the dqds algorithm, while orthogonal
* eigenvectors are computed from various "good" L D L^T representations
* (also known as Relatively Robust Representations). Gram-Schmidt
* orthogonalization is avoided as far as possible. More specifically,
* the various steps of the algorithm are as follows. For the i-th
* unreduced block of T,
* (a) Compute T - sigma_i = L_i D_i L_i^T, such that L_i D_i L_i^T
* is a relatively robust representation,
* (b) Compute the eigenvalues, lambda_j, of L_i D_i L_i^T to high
* relative accuracy by the dqds algorithm,
* (c) If there is a cluster of close eigenvalues, "choose" sigma_i
* close to the cluster, and go to step (a),
* (d) Given the approximate eigenvalue lambda_j of L_i D_i L_i^T,
* compute the corresponding eigenvector by forming a
* rank-revealing twisted factorization.
* The desired accuracy of the output can be specified by the input
* parameter ABSTOL.
*
* For more details, see "A new O(n^2) algorithm for the symmetric
* tridiagonal eigenvalue/eigenvector problem", by Inderjit Dhillon,
* Computer Science Division Technical Report No. UCB//CSD-97-971,
* UC Berkeley, May 1997.
*
*
* Note 1 : ZHEEVR calls ZSTEGR when the full spectrum is requested
* on machines which conform to the ieee-754 floating point standard.
* ZHEEVR calls DSTEBZ and ZSTEIN on non-ieee machines and
* when partial spectrum requests are made.
*
* Normal execution of ZSTEGR may create NaNs and infinities and
* hence may abort due to a floating point exception in environments
* which do not handle NaNs and infinities in the ieee standard default
* manner.
*
* Arguments
* =========
*
* JOBZ (input) CHARACTER*1
* = 'N': Compute eigenvalues only;
* = 'V': Compute eigenvalues and eigenvectors.
*
* RANGE (input) CHARACTER*1
* = 'A': all eigenvalues will be found.
* = 'V': all eigenvalues in the half-open interval (VL,VU]
* will be found.
* = 'I': the IL-th through IU-th eigenvalues will be found.
********** For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and
********** ZSTEIN are called
*
* 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*16 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. If UPLO = 'L',
* the leading N-by-N lower triangular part of A contains
* the lower triangular part of the matrix A.
* On exit, the lower triangle (if UPLO='L') or the upper
* triangle (if UPLO='U') of A, including the diagonal, is
* destroyed.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* VL (input) DOUBLE PRECISION
* VU (input) DOUBLE PRECISION
* If RANGE='V', the lower and upper bounds of the interval to
* be searched for eigenvalues. VL < VU.
* Not referenced if RANGE = 'A' or 'I'.
*
* IL (input) INTEGER
* IU (input) INTEGER
* If RANGE='I', the indices (in ascending order) of the
* smallest and largest eigenvalues to be returned.
* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
* Not referenced if RANGE = 'A' or 'V'.
*
* ABSTOL (input) DOUBLE PRECISION
* The absolute error tolerance for the eigenvalues.
* An approximate eigenvalue is accepted as converged
* when it is determined to lie in an interval [a,b]
* of width less than or equal to
*
* ABSTOL + EPS * max( |a|,|b| ) ,
*
* where EPS is the machine precision. If ABSTOL is less than
* or equal to zero, then EPS*|T| will be used in its place,
* where |T| is the 1-norm of the tridiagonal matrix obtained
* by reducing A to tridiagonal form.
*
* See "Computing Small Singular Values of Bidiagonal Matrices
* with Guaranteed High Relative Accuracy," by Demmel and
* Kahan, LAPACK Working Note #3.
*
* If high relative accuracy is important, set ABSTOL to
* DLAMCH( 'Safe minimum' ). Doing so will guarantee that
* eigenvalues are computed to high relative accuracy when
* possible in future releases. The current code does not
* make any guarantees about high relative accuracy, but
* furutre releases will. See J. Barlow and J. Demmel,
* "Computing Accurate Eigensystems of Scaled Diagonally
* Dominant Matrices", LAPACK Working Note #7, for a discussion
* of which matrices define their eigenvalues to high relative
* accuracy.
*
* M (output) INTEGER
* The total number of eigenvalues found. 0 <= M <= N.
* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
*
* W (output) DOUBLE PRECISION array, dimension (N)
* The first M elements contain the selected eigenvalues in
* ascending order.
*
* Z (output) COMPLEX*16 array, dimension (LDZ, max(1,M))
* If JOBZ = 'V', then if INFO = 0, the first M columns of Z
* contain the orthonormal eigenvectors of the matrix A
* corresponding to the selected eigenvalues, with the i-th
* column of Z holding the eigenvector associated with W(i).
* If JOBZ = 'N', then Z is not referenced.
* Note: the user must ensure that at least max(1,M) columns are
* supplied in the array Z; if RANGE = 'V', the exact value of M
* is not known in advance and an upper bound must be used.
*
* LDZ (input) INTEGER
* The leading dimension of the array Z. LDZ >= 1, and if
* JOBZ = 'V', LDZ >= max(1,N).
*
* ISUPPZ (output) INTEGER ARRAY, dimension ( 2*max(1,M) )
* The support of the eigenvectors in Z, i.e., the indices
* indicating the nonzero elements in Z. The i-th eigenvector
* is nonzero only in elements ISUPPZ( 2*i-1 ) through
* ISUPPZ( 2*i ).
********** Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
*
* WORK (workspace/output) COMPLEX*16 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,2*N).
* For optimal efficiency, LWORK >= (NB+1)*N,
* where NB is the max of the blocksize for ZHETRD and for
* ZUNMTR as returned by ILAENV.
*
* If LWORK = -1, then a workspace query is assumed; the routine
* only calculates the optimal size of the WORK array, returns
* this value as the first entry of the WORK array, and no error
* message related to LWORK is issued by XERBLA.
*
* RWORK (workspace/output) DOUBLE PRECISION array, dimension (LRWORK)
* On exit, if INFO = 0, RWORK(1) returns the optimal
* (and minimal) LRWORK.
*
* LRWORK (input) INTEGER
* The length of the array RWORK. LRWORK >= max(1,24*N).
*
* If LRWORK = -1, then a workspace query is assumed; the routine
* only calculates the optimal size of the RWORK array, returns
* this value as the first entry of the RWORK array, and no error
* message related to LRWORK is issued by XERBLA.
*
* IWORK (workspace/output) INTEGER array, dimension (LIWORK)
* On exit, if INFO = 0, IWORK(1) returns the optimal
* (and minimal) LIWORK.
*
* LIWORK (input) INTEGER
* The dimension of the array IWORK. LIWORK >= max(1,10*N).
*
* If LIWORK = -1, then a workspace query is assumed; the
* routine only calculates the optimal size of the IWORK array,
* returns this value as the first entry of the IWORK array, and
* no error message related to LIWORK is issued by XERBLA.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: Internal error
*
* Further Details
* ===============
*
* Based on contributions by
* Inderjit Dhillon, IBM Almaden, USA
* Osni Marques, LBNL/NERSC, USA
* Ken Stanley, Computer Science Division, University of
* California at Berkeley, USA
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, VALEIG, WANTZ
CHARACTER ORDER
INTEGER I, IEEEOK, IINFO, IMAX, INDIBL, INDIFL, INDISP,
$ INDIWO, INDRD, INDRDD, INDRE, INDREE, INDRWK,
$ INDTAU, INDWK, INDWKN, ISCALE, ITMP1, J, JJ,
$ LIWMIN, LLWORK, LLWRKN, LRWMIN, LWKOPT, LWMIN,
$ NB, NSPLIT
DOUBLE PRECISION ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
$ SIGMA, SMLNUM, TMP1, VLL, VUU
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILAENV
DOUBLE PRECISION DLAMCH, ZLANSY
EXTERNAL LSAME, ILAENV, DLAMCH, ZLANSY
* ..
* .. External Subroutines ..
EXTERNAL DCOPY, DSCAL, DSTEBZ, DSTERF, XERBLA, ZDSCAL,
$ ZHETRD, ZSTEGR, ZSTEIN, ZSWAP, ZUNMTR
* ..
* .. Intrinsic Functions ..
INTRINSIC DBLE, MAX, MIN, SQRT
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
IEEEOK = ILAENV( 10, 'ZHEEVR', 'N', 1, 2, 3, 4 )
*
LOWER = LSAME( UPLO, 'L' )
WANTZ = LSAME( JOBZ, 'V' )
ALLEIG = LSAME( RANGE, 'A' )
VALEIG = LSAME( RANGE, 'V' )
INDEIG = LSAME( RANGE, 'I' )
*
LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LRWORK.EQ.-1 ) .OR.
$ ( LIWORK.EQ.-1 ) )
*
LRWMIN = MAX( 1, 24*N )
LIWMIN = MAX( 1, 10*N )
LWMIN = MAX( 1, 2*N )
*
INFO = 0
IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
INFO = -1
ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
INFO = -2
ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -6
ELSE
IF( VALEIG ) THEN
IF( N.GT.0 .AND. VU.LE.VL )
$ INFO = -8
ELSE IF( INDEIG ) THEN
IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
INFO = -10
END IF
END IF
END IF
IF( INFO.EQ.0 ) THEN
IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
INFO = -15
ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
INFO = -18
ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
INFO = -20
ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
INFO = -22
END IF
END IF
*
IF( INFO.EQ.0 ) THEN
NB = ILAENV( 1, 'ZHETRD', UPLO, N, -1, -1, -1 )
NB = MAX( NB, ILAENV( 1, 'ZUNMTR', UPLO, N, -1, -1, -1 ) )
LWKOPT = MAX( ( NB+1 )*N, LWMIN )
WORK( 1 ) = LWKOPT
RWORK( 1 ) = LRWMIN
IWORK( 1 ) = LIWMIN
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZHEEVR', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Quick return if possible
*
M = 0
IF( N.EQ.0 ) THEN
WORK( 1 ) = 1
RETURN
END IF
*
IF( N.EQ.1 ) THEN
WORK( 1 ) = 7
IF( ALLEIG .OR. INDEIG ) THEN
M = 1
W( 1 ) = DBLE( A( 1, 1 ) )
ELSE
IF( VL.LT.DBLE( A( 1, 1 ) ) .AND. VU.GE.DBLE( A( 1, 1 ) ) )
$ THEN
M = 1
W( 1 ) = DBLE( A( 1, 1 ) )
END IF
END IF
IF( WANTZ )
$ Z( 1, 1 ) = ONE
RETURN
END IF
*
* Get machine constants.
*
SAFMIN = DLAMCH( 'Safe minimum' )
EPS = DLAMCH( 'Precision' )
SMLNUM = SAFMIN / EPS
BIGNUM = ONE / SMLNUM
RMIN = SQRT( SMLNUM )
RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
*
* Scale matrix to allowable range, if necessary.
*
ISCALE = 0
ABSTLL = ABSTOL
VLL = VL
VUU = VU
ANRM = ZLANSY( 'M', UPLO, N, A, LDA, RWORK )
IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
ISCALE = 1
SIGMA = RMIN / ANRM
ELSE IF( ANRM.GT.RMAX ) THEN
ISCALE = 1
SIGMA = RMAX / ANRM
END IF
IF( ISCALE.EQ.1 ) THEN
IF( LOWER ) THEN
DO 10 J = 1, N
CALL ZDSCAL( N-J+1, SIGMA, A( J, J ), 1 )
10 CONTINUE
ELSE
DO 20 J = 1, N
CALL ZDSCAL( J, SIGMA, A( 1, J ), 1 )
20 CONTINUE
END IF
IF( ABSTOL.GT.0 )
$ ABSTLL = ABSTOL*SIGMA
IF( VALEIG ) THEN
VLL = VL*SIGMA
VUU = VU*SIGMA
END IF
END IF
*
* Call ZHETRD to reduce Hermitian matrix to tridiagonal form.
*
INDTAU = 1
INDWK = INDTAU + N
*
INDRE = 1
INDRD = INDRE + N
INDREE = INDRD + N
INDRDD = INDREE + N
INDRWK = INDRDD + N
LLWORK = LWORK - INDWK + 1
CALL ZHETRD( UPLO, N, A, LDA, RWORK( INDRD ), RWORK( INDRE ),
$ WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
*
* If all eigenvalues are desired
* then call DSTERF or ZSTEGR and ZUNMTR.
*
IF( ( ALLEIG .OR. ( INDEIG .AND. IL.EQ.1 .AND. IU.EQ.N ) ) .AND.
$ IEEEOK.EQ.1 ) THEN
IF( .NOT.WANTZ ) THEN
CALL DCOPY( N, RWORK( INDRD ), 1, W, 1 )
CALL DCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 )
CALL DSTERF( N, W, RWORK( INDREE ), INFO )
ELSE
CALL DCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 )
CALL DCOPY( N, RWORK( INDRD ), 1, RWORK( INDRDD ), 1 )
*
CALL ZSTEGR( JOBZ, 'A', N, RWORK( INDRDD ),
$ RWORK( INDREE ), VL, VU, IL, IU, ABSTOL, M, W,
$ Z, LDZ, ISUPPZ, RWORK( INDRWK ), LWORK, IWORK,
$ LIWORK, INFO )
*
*
*
* Apply unitary matrix used in reduction to tridiagonal
* form to eigenvectors returned by ZSTEIN.
*
IF( WANTZ .AND. INFO.EQ.0 ) THEN
INDWKN = INDWK
LLWRKN = LWORK - INDWKN + 1
CALL ZUNMTR( 'L', UPLO, 'N', N, M, A, LDA,
$ WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
$ LLWRKN, IINFO )
END IF
END IF
*
*
IF( INFO.EQ.0 ) THEN
M = N
GO TO 30
END IF
INFO = 0
END IF
*
* Otherwise, call DSTEBZ and, if eigenvectors are desired, ZSTEIN.
* Also call DSTEBZ and ZSTEIN if CSTEGR fails.
*
IF( WANTZ ) THEN
ORDER = 'B'
ELSE
ORDER = 'E'
END IF
INDIFL = 1
INDIBL = INDIFL + N
INDISP = INDIBL + N
INDIWO = INDISP + N
CALL DSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
$ RWORK( INDRD ), RWORK( INDRE ), M, NSPLIT, W,
$ IWORK( INDIBL ), IWORK( INDISP ), RWORK( INDRWK ),
$ IWORK( INDIWO ), INFO )
*
IF( WANTZ ) THEN
CALL ZSTEIN( N, RWORK( INDRD ), RWORK( INDRE ), M, W,
$ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
$ RWORK( INDRWK ), IWORK( INDIWO ), IWORK( INDIFL ),
$ INFO )
*
* Apply unitary matrix used in reduction to tridiagonal
* form to eigenvectors returned by ZSTEIN.
*
INDWKN = INDWK
LLWRKN = LWORK - INDWKN + 1
CALL ZUNMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
$ LDZ, WORK( INDWKN ), LLWRKN, IINFO )
END IF
*
* If matrix was scaled, then rescale eigenvalues appropriately.
*
30 CONTINUE
IF( ISCALE.EQ.1 ) THEN
IF( INFO.EQ.0 ) THEN
IMAX = M
ELSE
IMAX = INFO - 1
END IF
CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
END IF
*
* If eigenvalues are not in order, then sort them, along with
* eigenvectors.
*
IF( WANTZ ) THEN
DO 50 J = 1, M - 1
I = 0
TMP1 = W( J )
DO 40 JJ = J + 1, M
IF( W( JJ ).LT.TMP1 ) THEN
I = JJ
TMP1 = W( JJ )
END IF
40 CONTINUE
*
IF( I.NE.0 ) THEN
ITMP1 = IWORK( INDIBL+I-1 )
W( I ) = W( J )
IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 )
W( J ) = TMP1
IWORK( INDIBL+J-1 ) = ITMP1
CALL ZSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
END IF
50 CONTINUE
END IF
*
* Set WORK(1) to optimal workspace size.
*
WORK( 1 ) = LWKOPT
RWORK( 1 ) = LRWMIN
IWORK( 1 ) = LIWMIN
*
RETURN
*
* End of ZHEEVR
*
END
| gpl-2.0 |
marshallward/mom | src/shared/diag_manager/diag_grid.F90 | 6 | 44090 | #include <fms_platform.h>
MODULE diag_grid_mod
! <CONTACT EMAIL="seth.underwood@noaa.gov">
! Seth Underwood
! </CONTACT>
! <HISTORY SRC="http://www.gfdl.noaa.gov/fms-cgi-bin/cvsweb.cgi/FMS/" />
! <OVERVIEW>
! <TT>diag_grid_mod</TT> is a set of procedures to work with the
! model's global grid to allow regional output.
! </OVERVIEW>
! <DESCRIPTION>
! <TT>diag_grid_mod</TT> contains useful utilities for dealing
! with, mostly, regional output for grids other than the standard
! lat/lon grid. This module contains three public procedures <TT>
! diag_grid_init</TT>, which is shared globably in the <TT>
! diag_manager_mod</TT>, <TT>diag_grid_end</TT> which will free
! up memory used during the register field calls, and
! <TT>get_local_indexes</TT>. The <TT>send_global_grid</TT>
! procedure is called by the model that creates the global grid.
! <TT>send_global_grid</TT> needs to be called before any fields
! are registered that will output only regions. <TT>get_local_indexes</TT>
! is to be called by the <TT>diag_manager_mod</TT> to discover the
! global indexes defining a subregion on the tile.
!
! <B>Change Log</B>
! <DL>
! <DT>September 2009</DT>
! <DD>
! <UL>
! <LI>Single point region in Cubed Sphere</LI>
! <LI>Single tile regions in the cubed sphere</LI>
! </UL>
! </DD>
! </DL>
! </DESCRIPTION>
! <INFO>
! <FUTURE>
! Multi-tile regional output in the cubed sphere.
! </FUTURE>
! <FUTURE>
! Single grid in the tri-polar grid.
! </FUTURE>
! <FUTURE>
! Multi-tile regional output in the tri-polar grid.
! </FUTURE>
! <FUTURE>
! Regional output using array masking. This should allow
! regional output to work on any current or future grid.
! </FUTURE>
! </INFO>
USE constants_mod, ONLY: DEG_TO_RAD, RAD_TO_DEG, RADIUS
USE fms_mod, ONLY: write_version_number, error_mesg, WARNING, FATAL,&
& mpp_pe
USE mpp_mod, ONLY: mpp_root_pe, mpp_npes, mpp_max, mpp_min
USE mpp_domains_mod, ONLY: domain2d, mpp_get_tile_id,&
& mpp_get_ntile_count, mpp_get_compute_domains
IMPLICIT NONE
! Parameters
CHARACTER(len=128), PARAMETER :: version =&
& '$Id$'
CHARACTER(len=128), PARAMETER :: tagname =&
& '$Name$'
! Derived data types
! <PRIVATE>
! <TYPE NAME="diag_global_grid_type">
! <DESCRIPTION>
! Contains the model's global grid data, and other grid information.
! </DESCRIPTION>
! <DATA NAME="glo_lat" TYPE="REAL, _ALLOCATABLE, DIMENSION(:,:)">
! The latitude values on the global grid.
! </DATA>
! <DATA NAME="glo_lon" TYPE="REAL, _ALLOCATABLE, DIMENSION(:,:)">
! The longitude values on the global grid.
! </DATA>
! <DATA NAME="aglo_lat" TYPE="REAL, _ALLOCATABLE, DIMENSION(:,:)">
! The latitude values on the global a-grid. Here we expect isc-1:iec+1 and
! jsc=1:jec+1 to be passed in.
! </DATA>
! <DATA NAME="aglo_lon" TYPE="REAL, _ALLOCATABLE, DIMENSION(:,:)">
! The longitude values on the global a-grid. Here we expec isc-1:iec+j and
! jsc-1:jec+1 to be passed in.
! </DATA>
! <DATA NAME="myXbegin" TYPE="INTEGER">
! The starting index of the compute domain on the current PE.
! </DATA>
! <DATA NAME="myYbegin" TYPE="INTEGER">
! The starting index of the compute domain on the cureent PE.
! </DATA>
! <DATA NAME="dimI" TYPE="INTEGER">
! The dimension of the global grid in the 'i' / longitudal direction.
! </DATA>
! <DATA NAME="dimJ" TYPE="INTEGER">
! The dimension of the global grid in the 'j' / latitudal direction.
! </DATA>
! <DATA NAME="adimI" TYPE="INTEGER">
! The dimension of the global a-grid in the 'i' / longitudal direction. Again,
! the expected dimension for diag_grid_mod is isc-1:iec+1.
! </DATA>
! <DATA NAME="adimJ" TYPE="INTEGER">
! The dimension of the global a-grid in the 'j' / latitudal direction. Again,
! the expected dimension for diag_grid_mod is jsc-1:jec+1.
! </DATA>
! <DATA NAME="tile_number" TYPE="INTEGER">
! The tile the <TT>glo_lat</TT> and <TT>glo_lon</TT> define.
! </DATA>
! <DATA NAME="ntimes" TYPE="INTEGER">
! The number of tiles.
! </DATA>
! <DATA NAME="peStart" TYPE="INTEGER">
! The starting PE number for the current tile.
! </DATA>
! <DATA NAME="peEnd" TYPE="INTEGER">
! The ending PE number for the current tile.
! </DATA>
! <DATA NAME="grid_type" TYPE="CHARACTER(len=128)">
! The global grid type.
! </DATA>
TYPE :: diag_global_grid_type
REAL, _ALLOCATABLE, DIMENSION(:,:) :: glo_lat, glo_lon
REAL, _ALLOCATABLE, DIMENSION(:,:) :: aglo_lat, aglo_lon
INTEGER :: myXbegin, myYbegin
INTEGER :: dimI, dimJ
INTEGER :: adimI, adimJ
INTEGER :: tile_number
INTEGER :: ntiles
INTEGER :: peStart, peEnd
CHARACTER(len=128) :: grid_type
END TYPE diag_global_grid_type
! </TYPE>
! </PRIVATE>
! <PRIVATE>
! <TYPE NAME="point">
! <DESCRIPTION>
! Private point type to hold the (x,y,z) location for a (lat,lon)
! location.
! </DESCRIPTION>
! <DATA NAME="x" TYPE="REAL">
! The x value of the (x,y,z) coordinates.
! </DATA>
! <DATA NAME="y" TYPE="REAL">
! The y value of the (x,y,z) coordinates.
! </DATA>
! <DATA NAME="z" TYPE="REAL">
! The z value of the (x,y,z) coordinates.
! </DATA>
TYPE :: point
REAL :: x,y,z
END TYPE point
! </TYPE>
! </PRIVATE>
! <PRIVATE>
! <DATA NAME="diag_global_grid" TYPE="TYPE(diag_global_grid_type)">
! Variable to hold the global grid data
! </DATA>
! </PRIVATE>
TYPE(diag_global_grid_type) :: diag_global_grid
! <PRIVATE>
! <DATA NAME="diag_grid_initialized" TYPE="LOGICAL" DEFAULT=".FALSE.">
! Indicates if the diag_grid_mod has been initialized.
! </DATA>
! </PRIVATE>
LOGICAL :: diag_grid_initialized = .FALSE.
PRIVATE
PUBLIC :: diag_grid_init, diag_grid_end, get_local_indexes, &
get_local_indexes2
CONTAINS
! <SUBROUTINE NAME="diag_grid_init">
! <OVERVIEW>
! Send the global grid to the <TT>diag_manager_mod</TT> for
! regional output.
! </OVERVIEW>
! <TEMPLATE>
! SUBROUTINE diag_grid_init(domain, glo_lat, glo_lon, aglo_lat, aglo_lon)
! </TEMPLATE>
! <DESCRIPTION>
! In order for the diag_manager to do regional output for grids
! other than the standard lat/lon grid, the <TT>
! diag_manager_mod</TT> needs to know the the latitude and
! longitude values for the entire global grid. This procedure
! is the mechanism the models will use to share their grid with
! the diagnostic manager.
!
! This procedure needs to be called after the grid is created,
! and before the first call to register the fields.
! </DESCRIPTION>
! <IN NAME="domain" TYPE="INTEGER">
! The domain to which the grid data corresponds.
! </IN>
! <IN NAME="glo_lat" TYPE="REAL, DIMENSION(:,:)">
! The latitude information for the grid tile.
! </IN>
! <IN NAME="glo_lon" TYPE="REAL, DIMENSION(:,:)">
! The longitude information for the grid tile.
! </IN>
! <IN NAME="aglo_lat" TYPE="REAL, DIMENSION(:,:)">
! The latitude information for the a-grid tile.
! </IN>
! <IN NAME="aglo_lon" TYPE="REAL, DIMENSION(:,:)">
! The longitude information for the a-grid tile.
! </IN>
SUBROUTINE diag_grid_init(domain, glo_lat, glo_lon, aglo_lat, aglo_lon)
TYPE(domain2d), INTENT(in) :: domain
REAL, INTENT(in), DIMENSION(:,:) :: glo_lat, glo_lon
REAL, INTENT(in), DIMENSION(:,:) :: aglo_lat, aglo_lon
INTEGER, DIMENSION(1) :: tile
INTEGER :: ntiles
INTEGER :: stat
INTEGER :: i_dim, j_dim
INTEGER :: ai_dim, aj_dim
INTEGER, DIMENSION(2) :: latDim, lonDim
INTEGER, DIMENSION(2) :: alatDim, alonDim
INTEGER :: myPe, npes, npesPerTile
INTEGER, ALLOCATABLE, DIMENSION(:) :: xbegin, xend, ybegin, yend
! Write the version and tagname to the logfile
CALL write_version_number(version, tagname)
! Verify all allocatable / pointers for diag_global_grid hare not
! allocated / associated.
IF ( ALLOCATED(xbegin) ) DEALLOCATE(xbegin)
IF ( ALLOCATED(ybegin) ) DEALLOCATE(ybegin)
IF ( ALLOCATED(xend) ) DEALLOCATE(xend)
IF ( ALLOCATED(yend) ) DEALLOCATE(yend)
! What is my PE
myPe = mpp_pe() -mpp_root_pe() + 1
! Get the domain/pe layout, and allocate the [xy]begin|end arrays/pointers
npes = mpp_npes()
ALLOCATE(xbegin(npes), &
& ybegin(npes), &
& xend(npes), &
& yend(npes), STAT=stat)
IF ( stat .NE. 0 ) THEN
CALL error_mesg('diag_grid_mod::diag_grid_init',&
&'Could not allocate memory for the compute grid indices&
&.', FATAL)
END IF
! Get tile information
ntiles = mpp_get_ntile_count(domain)
tile = mpp_get_tile_id(domain)
! Number of PEs per tile
npesPerTile = npes / ntiles
diag_global_grid%peEnd = npesPerTile * tile(1)
diag_global_grid%peStart = diag_global_grid%peEnd - npesPerTile + 1
! Get the compute domains
CALL mpp_get_compute_domains(domain,&
& XBEGIN=xbegin, XEND=xend,&
& YBEGIN=ybegin, YEND=yend)
! Module initialized
diag_grid_initialized = .TRUE.
! Get the size of the grids
latDim = SHAPE(glo_lat)
lonDim = SHAPE(glo_lon)
IF ( (latDim(1) == lonDim(1)) .AND.&
&(latDim(2) == lonDim(2)) ) THEN
i_dim = latDim(1)
j_dim = latDim(2)
ELSE
CALL error_mesg('diag_grid_mod::diag_grid_init',&
&'glo_lat and glo_lon must be the same shape.', FATAL)
END IF
! Same thing for the a-grid
alatDim = SHAPE(aglo_lat)
alonDim = SHAPE(aglo_lon)
IF ( (alatDim(1) == alonDim(1)) .AND. &
&(alatDim(2) == alonDim(2)) ) THEN
IF ( tile(1) == 4 .OR. tile(1) == 5 ) THEN
! These tiles need to be transposed.
ai_dim = alatDim(2)
aj_dim = alatDim(1)
ELSE
ai_dim = alatDim(1)
aj_dim = alatDim(2)
END IF
ELSE
CALL error_mesg('diag_grid_mod::diag_grid_init',&
& "a-grid's glo_lat and glo_lon must be the same shape.", FATAL)
END IF
! Allocate the grid arrays
IF ( _ALLOCATED(diag_global_grid%glo_lat) .OR.&
& _ALLOCATED(diag_global_grid%glo_lon) ) THEN
IF ( mpp_pe() == mpp_root_pe() ) &
& CALL error_mesg('diag_grid_mod::diag_grid_init',&
&'The global grid has already been initialized', WARNING)
ELSE
ALLOCATE(diag_global_grid%glo_lat(i_dim,j_dim),&
& diag_global_grid%glo_lon(i_dim,j_dim), STAT=stat)
IF ( stat .NE. 0 ) THEN
CALL error_mesg('diag_grid_mod::diag_grid_init',&
&'Could not allocate memory for the global grid.', FATAL)
END IF
END IF
! Same thing for the a-grid
IF ( _ALLOCATED(diag_global_grid%aglo_lat) .OR.&
& _ALLOCATED(diag_global_grid%aglo_lon) ) THEN
IF ( mpp_pe() == mpp_root_pe() ) &
& CALL error_mesg('diag_grid_mod::diag_grid_init',&
&'The global a-grid has already been initialized', WARNING)
ELSE
ALLOCATE(diag_global_grid%aglo_lat(0:ai_dim-1,0:aj_dim-1),&
& diag_global_grid%aglo_lon(0:ai_dim-1,0:aj_dim-1), STAT=stat)
IF ( stat .NE. 0 ) THEN
CALL error_mesg('diag_global_mod::diag_grid_init',&
&'Could not allocate memory for the global a-grid', FATAL)
END IF
END IF
! Set the values for diag_global_grid
! If we are on tile 4 or 5, we need to transpose the grid to get
! this to work.
IF ( tile(1) == 4 .OR. tile(1) == 5 ) THEN
diag_global_grid%aglo_lat = TRANSPOSE(aglo_lat)
diag_global_grid%aglo_lon = TRANSPOSE(aglo_lon)
ELSE
diag_global_grid%aglo_lat = aglo_lat
diag_global_grid%aglo_lon = aglo_lon
END IF
diag_global_grid%glo_lat = glo_lat
diag_global_grid%glo_lon = glo_lon
diag_global_grid%dimI = i_dim
diag_global_grid%dimJ = j_dim
diag_global_grid%adimI = ai_dim
diag_global_grid%adimJ = aj_dim
!--- For the nested model, the nested region only has 1 tile ( ntiles = 1) but
!--- the tile_id is 7 for the nested region. In the routine get_local_indexes,
!--- local variables ijMin and ijMax have dimesnion (ntiles) and will access
!--- ijMin(diag_global_grid%tile_number,:). For the nested region, ntiles = 1 and
!--- diag_global_grid%tile_number = 7 will cause out of bounds. So need to
!--- set diag_global_grid%tile_number = 1 when ntiles = 1 for the nested model.
if(ntiles == 1) then
diag_global_grid%tile_number = 1
else
diag_global_grid%tile_number = tile(1)
endif
diag_global_grid%ntiles = ntiles
diag_global_grid%myXbegin = xbegin(myPe)
diag_global_grid%myYbegin = ybegin(myPe)
! Unallocate arrays used here
DEALLOCATE(xbegin)
DEALLOCATE(ybegin)
DEALLOCATE(xend)
DEALLOCATE(yend)
END SUBROUTINE diag_grid_init
! </SUBROUTINE>
! <SUBROUTINE NAME="diag_grid_end">
! <OVERVIEW>
! Unallocate the diag_global_grid variable.
! </OVERVIEW>
! <TEMPLATE>
! SUBROUTINE diag_grid_end()
! </TEMPLATE>
! <DESCRIPTION>
! The <TT>diag_global_grid</TT> variable is only needed during
! the register field calls, and then only if there are fields
! requestion regional output. Once all the register fields
! calls are complete (before the first <TT>send_data</TT> call
! this procedure can be called to free up memory.
! </DESCRIPTION>
SUBROUTINE diag_grid_end()
IF ( diag_grid_initialized ) THEN
! De-allocate grid
IF ( _ALLOCATED(diag_global_grid%glo_lat) ) THEN
DEALLOCATE(diag_global_grid%glo_lat)
ELSE IF ( mpp_pe() == mpp_root_pe() ) THEN
CALL error_mesg('diag_grid_mod::diag_grid_end',&
&'diag_global_grid%glo_lat was not allocated.', WARNING)
END IF
IF ( _ALLOCATED(diag_global_grid%glo_lon) ) THEN
DEALLOCATE(diag_global_grid%glo_lon)
ELSE IF ( mpp_pe() == mpp_root_pe() ) THEN
CALL error_mesg('diag_grid_mod::diag_grid_end',&
&'diag_global_grid%glo_lon was not allocated.', WARNING)
END IF
! De-allocate a-grid
IF ( _ALLOCATED(diag_global_grid%aglo_lat) ) THEN
DEALLOCATE(diag_global_grid%aglo_lat)
ELSE IF ( mpp_pe() == mpp_root_pe() ) THEN
CALL error_mesg('diag_grid_mod::diag_grid_end',&
&'diag_global_grid%aglo_lat was not allocated.', WARNING)
END IF
IF ( _ALLOCATED(diag_global_grid%aglo_lon) ) THEN
DEALLOCATE(diag_global_grid%aglo_lon)
ELSE IF ( mpp_pe() == mpp_root_pe() ) THEN
CALL error_mesg('diag_grid_mod::diag_grid_end',&
&'diag_global_grid%aglo_lon was not allocated.', WARNING)
END IF
diag_grid_initialized = .FALSE.
END IF
END SUBROUTINE diag_grid_end
! </SUBROUTINE>
! <SUBROUTINE NAME="get_local_indexes">
! <OVERVIEW>
! Find the local start and local end indexes on the local PE
! for regional output.
! </OVERVIEW>
! <TEMPLATE>
! SUBROUTINE get_local_indexes(latStart, latEnd, lonStart,
! lonEnd, istart, iend, jstart, jend)
! </TEMPLATE>
! <DESCRIPTION>
! Given a defined region, find the local indexes on the local
! PE surrounding the region.
! </DESCRIPTION>
! <IN NAME="latStart" TYPE="REAL">
! The minimum latitude value defining the region. This value
! must be less than latEnd, and be in the range [-90,90]
! </IN>
! <IN NAME="latEnd" TYPE="REAL">
! The maximum latitude value defining the region. This value
! must be greater than latStart, and be in the range [-90,90]
! </IN>
! <IN NAME="lonStart" TYPE="REAL">
! The western most longitude value defining the region.
! Possible ranges are either [-180,180] or [0,360].
! </IN>
! <IN NAME="lonEnd" TYPE="REAL">
! The eastern most longitude value defining the region.
! Possible ranges are either [-180,180] or [0,360].
! </IN>
! <OUT NAME="istart" TYPE="INTEGER">
! The local start index on the local PE in the 'i' direction.
! </OUT>
! <OUT NAME="iend" TYPE="INTEGER">
! The local end index on the local PE in the 'i' direction.
! </OUT>
! <OUT NAME="jstart" TYPE="INTEGER">
! The local start index on the local PE in the 'j' direction.
! </OUT>
! <OUT NAME="jend" TYPE="INTEGER">
! The local end index on the local PE in the 'j' direction.
! </OUT>
SUBROUTINE get_local_indexes(latStart, latEnd, lonStart, lonEnd,&
& istart, iend, jstart, jend)
REAL, INTENT(in) :: latStart, lonStart !< lat/lon start angles
REAL, INTENT(in) :: latEnd, lonEnd !< lat/lon end angles
INTEGER, INTENT(out) :: istart, jstart !< i/j start indexes
INTEGER, INTENT(out) :: iend, jend !< i/j end indexes
REAL, ALLOCATABLE, DIMENSION(:,:) :: delta_lat, delta_lon, grid_lon
REAL, DIMENSION(4) :: dists_lon, dists_lat
REAL :: lonEndAdj, my_lonStart, my_lonEnd
INTEGER, ALLOCATABLE, DIMENSION(:,:) :: ijMin, ijMax
INTEGER :: myTile, ntiles, i, j, k, dimI, dimJ, istat
INTEGER :: count
LOGICAL :: onMyPe
IF ( .NOT. diag_grid_initialized )&
& CALL error_mesg('diag_grid_mod::get_local_indexes',&
&'Module not initialized, first initialze module with a call &
&to diag_grid_init', FATAL)
myTile = diag_global_grid%tile_number
ntiles = diag_global_grid%ntiles
! Arrays to home min/max for each tile
ALLOCATE(ijMin(ntiles,2), STAT=istat)
IF ( istat .NE. 0 )&
& CALL error_mesg('diag_grid_mod::get_local_indexes',&
&'Cannot allocate ijMin index array', FATAL)
ALLOCATE(ijMax(ntiles,2), STAT=istat)
IF ( istat .NE. 0 )&
& CALL error_mesg('diag_grid_mod::get_local_indexes',&
&'Cannot allocate ijMax index array', FATAL)
ijMin = 0
ijMax = 0
! Make adjustment for negative longitude values
if ( lonStart < 0. ) then
my_lonStart = lonStart + 360.
else
my_lonStart = lonStart
end if
if ( lonEnd < 0. ) then
my_lonEnd = lonEnd + 360.
else
my_lonEnd = lonEnd
end if
! There will be four points to define a region, find all four.
! Need to call the correct function depending on if the tile is a
! pole tile or not.
!
! Also, if looking for a single point, then use the a-grid
IF ( latStart == latEnd .AND. my_lonStart == my_lonEnd ) THEN
! single point
IF ( MOD(diag_global_grid%tile_number,3) == 0 ) THEN
ijMax(myTile,:) = find_pole_index_agrid(latStart,my_lonStart)
ELSE
ijMax(myTile,:) = find_equator_index_agrid(latStart,my_lonStart)
END IF
WHERE ( ijMax(:,1) .NE. 0 )
ijMax(:,1) = ijMax(:,1) + diag_global_grid%myXbegin - 1
END WHERE
WHERE ( ijMax(:,2) .NE. 0 )
ijMax(:,2) = ijMax(:,2) + diag_global_grid%myYbegin - 1
END WHERE
DO j = 1, 6 ! Each tile.
CALL mpp_max(ijMax(j,1))
CALL mpp_max(ijMax(j,2))
END DO
ijMin = ijMax
ELSE
! multi-point
dimI = diag_global_grid%dimI
dimJ = diag_global_grid%dimJ
! Build the delta array
ALLOCATE(delta_lat(dimI,dimJ), STAT=istat)
IF ( istat .NE. 0 )&
& CALL error_mesg('diag_grid_mod::get_local_indexes',&
&'Cannot allocate latitude delta array', FATAL)
ALLOCATE(delta_lon(dimI,dimJ), STAT=istat)
IF ( istat .NE. 0 )&
& CALL error_mesg('diag_grid_mod::get_local_indexes',&
&'Cannot allocate longitude delta array', FATAL)
DO j=1, dimJ
DO i=1, dimI
count = 0
dists_lon = 0.
dists_lat = 0.
IF ( i < dimI ) THEN
dists_lon(1) = ABS(diag_global_grid%glo_lon(i+1,j) - diag_global_grid%glo_lon(i,j))
dists_lat(1) = ABS(diag_global_grid%glo_lat(i+1,j) - diag_global_grid%glo_lat(i,j))
count = count+1
END IF
IF ( j < dimJ ) THEN
dists_lon(2) = ABS(diag_global_grid%glo_lon(i,j+1) - diag_global_grid%glo_lon(i,j))
dists_lat(2) = ABS(diag_global_grid%glo_lat(i,j+1) - diag_global_grid%glo_lat(i,j))
count = count+1
END IF
IF ( i > 1 ) THEN
dists_lon(3) = ABS(diag_global_grid%glo_lon(i,j) - diag_global_grid%glo_lon(i-1,j))
dists_lat(3) = ABS(diag_global_grid%glo_lat(i,j) - diag_global_grid%glo_lat(i-1,j))
count = count+1
END IF
IF ( j > 1 ) THEN
dists_lon(4) = ABS(diag_global_grid%glo_lon(i,j) - diag_global_grid%glo_lon(i,j-1))
dists_lat(4) = ABS(diag_global_grid%glo_lat(i,j) - diag_global_grid%glo_lat(i,j-1))
count = count+1
END IF
! Fix wrap around problem
DO k=1, 4
IF ( dists_lon(k) > 180.0 ) THEN
dists_lon(k) = 360.0 - dists_lon(k)
END IF
END DO
delta_lon(i,j) = SUM(dists_lon)/real(count)
delta_lat(i,j) = SUM(dists_lat)/real(count)
END DO
END DO
ijMin = HUGE(1)
ijMax = -HUGE(1)
! Adjusted longitude array
ALLOCATE(grid_lon(dimI,dimJ), STAT=istat)
IF ( istat .NE. 0 )&
& CALL error_mesg('diag_grid_mod::get_local_indexes',&
&'Cannot allocate temporary longitude array', FATAL)
grid_lon = diag_global_grid%glo_lon
! Make adjustments where required
IF ( my_lonStart > my_lonEnd ) THEN
WHERE ( grid_lon < my_lonStart )
grid_lon = grid_lon + 360.0
END WHERE
lonEndAdj = my_lonEnd + 360.0
ELSE
lonEndAdj = my_lonEnd
END IF
DO j=1, dimJ-1
DO i=1, dimI-1
onMyPe = .false.
IF ( latStart-delta_lat(i,j) <= diag_global_grid%glo_lat(i,j) .AND.&
& diag_global_grid%glo_lat(i,j) < latEnd+delta_lat(i,j) ) THEN
! Short-cut for the poles
IF ( (ABS(latStart)-delta_lat(i,j) <= 90.0 .AND.&
& 90.0 <= ABS(latEnd)+delta_lat(i,j)) .AND.&
& ABS(diag_global_grid%glo_lat(i,j)) == 90.0 ) THEN
onMyPe = .TRUE.
ELSE IF ( (my_lonStart-delta_lon(i,j) <= grid_lon(i,j) .AND.&
& grid_lon(i,j) < lonEndAdj+delta_lon(i,j)) ) THEN
onMyPe = .TRUE.
ELSE
onMyPe = .FALSE.
END IF
IF ( onMyPe ) THEN
ijMin(myTile,1) = MIN(ijMin(myTile,1),i + diag_global_grid%myXbegin - 1)
ijMax(myTile,1) = MAX(ijMax(myTile,1),i + diag_global_grid%myXbegin - 1)
ijMin(myTile,2) = MIN(ijMin(myTile,2),j + diag_global_grid%myYbegin - 1)
ijMax(myTile,2) = MAX(ijMax(myTile,2),j + diag_global_grid%myYbegin - 1)
END IF
END IF
END DO
END DO
DEALLOCATE(delta_lon)
DEALLOCATE(delta_lat)
DEALLOCATE(grid_lon)
! Global min/max reduce
DO i=1, ntiles
CALL mpp_min(ijMin(i,1))
CALL mpp_max(ijMax(i,1))
CALL mpp_min(ijMin(i,2))
CALL mpp_max(ijMax(i,2))
END DO
IF ( ijMin(myTile,1) == HUGE(1) .OR. ijMax(myTile,1) == -HUGE(1) ) THEN
ijMin(myTile,1) = 0
ijMax(myTile,1) = 0
END IF
IF ( ijMin(myTile,2) == HUGE(1) .OR. ijMax(myTile,2) == -HUGE(1) ) THEN
ijMin(myTile,2) = 0
ijMax(myTile,2) = 0
END IF
END IF
istart = ijMin(myTile,1)
jstart = ijMin(myTile,2)
iend = ijMax(myTile,1)
jend = ijMax(myTile,2)
DEALLOCATE(ijMin)
DEALLOCATE(ijMax)
END SUBROUTINE get_local_indexes
! </SUBROUTINE>
! <SUBROUTINE NAME="get_local_indexes2">
! <OVERVIEW>
! Find the indices of the nearest grid point of the a-grid to the
! specified (lon,lat) location on the local PE. if desired point not
! within domain of local PE, return (0,0) as the indices.
! </OVERVIEW>
! <TEMPLATE>
! SUBROUTINE get_local_indexes2 (lat, lon, iindex, jindex)
! </TEMPLATE>
! <DESCRIPTION>
! Given a specified location, find the nearest a-grid indices on
! the local PE.
! </DESCRIPTION>
! <IN NAME="lat" TYPE="REAL">
! The requested latitude. This value must be in the range [-90,90]
! </IN>
! <IN NAME="lon" TYPE="REAL">
! The requested longitude.
! Possible ranges are either [-180,180] or [0,360].
! </IN>
! <OUT NAME="iindex" TYPE="INTEGER">
! The local index on the local PE in the 'i' direction.
! </OUT>
! <OUT NAME="jindex" TYPE="INTEGER">
! The local index on the local PE in the 'j' direction.
! </OUT>
SUBROUTINE get_local_indexes2(lat, lon, iindex, jindex)
REAL, INTENT(in) :: lat, lon !< lat/lon location
INTEGER, INTENT(out) :: iindex, jindex !< i/j indexes
INTEGER :: indexes(2)
IF ( .NOT. diag_grid_initialized )&
& CALL error_mesg('diag_grid_mod::get_local_indexes2',&
&'Module not initialized, first initialze module with a call &
&to diag_grid_init', FATAL)
indexes = 0
IF ( MOD(diag_global_grid%tile_number,3) == 0 ) THEN
IF ( lat > 30.0 .AND. diag_global_grid%tile_number == 3 ) THEN
indexes(:) = find_pole_index_agrid(lat,lon)
ELSE IF ( lat < -30.0 .AND. diag_global_grid%tile_number == 6 ) THEN
indexes(:) = find_pole_index_agrid(lat,lon)
ENDIF
ELSE
indexes(:) = find_equator_index_agrid(lat,lon)
END IF
iindex = indexes(1)
jindex = indexes(2)
IF (iindex == diag_global_grid%adimI -1 .OR.&
jindex == diag_global_grid%adimJ -1 ) THEN
iindex = 0
jindex = 0
ENDIF
END SUBROUTINE get_local_indexes2
! </SUBROUTINE>
! <PRIVATE>
! <FUNCTION NAME="rad2deg">
! <OVERVIEW>
! Convert and angle in radian to degrees.
! </OVERVIEW>
! <TEMPLATE>
! PURE ELEMENTAL REAL FUNCTION rad2deg(angle)
! </TEMPLATE>
! <DESCRIPTION>
! Given a scalar, or an array of angles in radians this
! function will return a scalar or array (of the same
! dimension) of angles in degrees.
! </DESCRIPTION>
! <IN NAME="angle" TYPE="REAL">
! Scalar or array of angles in radians.
! </IN>
! <OUT NAME="rad2deg" TYPE="REAL">
! Scalar or array (depending on the size of angle) of angles in
! degrees.
! </OUT>
PURE ELEMENTAL REAL FUNCTION rad2deg(angle)
REAL, INTENT(in) :: angle
rad2deg = RAD_TO_DEG * angle
END FUNCTION rad2deg
! </FUNCTION>
! </PRIVATE>
! <PRIVATE>
! <FUNCTION NAME="deg2rad">
! <OVERVIEW>
! Convert an angle in degrees to radians.
! </OVERVIEW>
! <TEMPLATE>
! PURE ELEMENTAL REAL FUNCTION deg2rad(angle)
! </TEMPLATE>
! <DESCRIPTION>
! Given a scalar, or an array of angles in degrees this
! function will return a scalar or array (of the same
! dimension) of angles in radians.
! </DESCRIPTION>
! <IN NAME="angle" TYPE="REAL">
! Scalar or array of angles in degrees.
! </IN>
PURE ELEMENTAL REAL FUNCTION deg2rad(angle)
REAL, INTENT(in) :: angle
deg2rad = DEG_TO_RAD * angle
END FUNCTION deg2rad
! </FUNCTION>
! </PRIVATE>
! <PRIVATE>
! <FUNCTION NAME="find_pole_index_agrid">
! <OVERVIEW>
! Return the closest index (i,j) to the given (lat,lon) point.
! </OVERVIEW>
! <TEMPLATE>
! PURE FUNCTION find_pole_index_agrid(lat, lon)
! </TEMPLATE>
! <DESCRIPTION>
! This function searches a pole a-grid tile looking for the grid point
! closest to the give (lat, lon) location, and returns the i
! and j indexes of the point.
! </DESCRIPTION>
! <IN NAME="lat" TYPE="REAL">
! Latitude location
! </IN>
! <IN NAME="lon" TYPE="REAL">
! Longitude location
! </IN>
! <OUT NAME="find_pole_index" TYPE="INTEGER, DIMENSION(2)">
! The (i, j) location of the closest grid to the given (lat,
! lon) location.
! </OUT>
PURE FUNCTION find_pole_index_agrid(lat, lon)
INTEGER, DIMENSION(2) :: find_pole_index_agrid
REAL, INTENT(in) :: lat, lon
INTEGER :: indxI, indxJ !< Indexes to be returned.
INTEGER :: dimI, dimJ !< Size of the grid dimensions
INTEGER :: i,j !< Count indexes
INTEGER :: nearestCorner !< index of the nearest corner.
INTEGER, DIMENSION(4,2) :: ijArray !< indexes of the cornerPts and pntDistances arrays
REAL :: llat, llon
REAL :: maxCtrDist !< maximum distance to center of grid
REAL, DIMENSION(4) :: pntDistances !< distance from origPt to corner
TYPE(point) :: origPt !< Original point
REAL, DIMENSION(4,2) :: cornerPts !< Corner points using (lat,lon)
TYPE(point), DIMENSION(9) :: points !< xyz of 8 nearest neighbors
REAL, DIMENSION(9) :: distSqrd !< distance between origPt and points(:)
! Set the inital fail values for indxI and indxJ
indxI = 0
indxJ = 0
dimI = diag_global_grid%adimI
dimJ = diag_global_grid%adimJ
! Since the poles have an non-unique longitude value, make a small correction if looking for one of the poles.
IF ( lat == 90.0 ) THEN
llat = lat - .1
ELSE IF ( lat == -90.0 ) THEN
llat = lat + .1
ELSE
llat = lat
END IF
llon = lon
origPt = latlon2xyz(llat,llon)
iLoop: DO i=0, dimI-2
jLoop: DO j = 0, dimJ-2
cornerPts = RESHAPE( (/ diag_global_grid%aglo_lat(i, j), diag_global_grid%aglo_lon(i, j),&
& diag_global_grid%aglo_lat(i+1,j+1),diag_global_grid%aglo_lon(i+1,j+1),&
& diag_global_grid%aglo_lat(i+1,j), diag_global_grid%aglo_lon(i+1,j),&
& diag_global_grid%aglo_lat(i, j+1),diag_global_grid%aglo_lon(i, j+1) /),&
& (/ 4, 2 /), ORDER=(/2,1/) )
! Find the maximum half distance of the corner points
maxCtrDist = MAX(gCirDistance(cornerPts(1,1),cornerPts(1,2), cornerPts(2,1),cornerPts(2,2)),&
& gCirDistance(cornerPts(3,1),cornerPts(3,2), cornerPts(4,1),cornerPts(4,2)))
! Find the distance of the four corner points to the point of interest.
pntDistances = gCirDistance(cornerPts(:,1),cornerPts(:,2), llat,llon)
IF ( (MINVAL(pntDistances) <= maxCtrDist) .AND. (i*j.NE.0) ) THEN
! Set up the i,j index array
ijArray = RESHAPE( (/ i, j, i+1, j+1, i+1, j, i, j+1 /), (/ 4, 2 /), ORDER=(/2,1/) )
! the nearest point index
nearestCorner = MINLOC(pntDistances,1)
indxI = ijArray(nearestCorner,1)
indxJ = ijArray(nearestCorner,2)
EXIT iLoop
END IF
END DO jLoop
END DO iLoop
! Make sure we have indexes in the correct range
valid: IF ( (indxI <= 0 .OR. dimI-1 <= indxI) .OR. &
& (indxJ <= 0 .OR. dimJ-1 <= indxJ) ) THEN
indxI = 0
indxJ = 0
ELSE ! indxI and indxJ are valid.
! Since we are looking for the closest grid point to the
! (lat,lon) point, we need to check the surrounding
! points. The indexes for the variable points are as follows
!
! 1---4---7
! | | |
! 2---5---8
! | | |
! 3---6---9
! Set the 'default' values for points(:) x,y,z to some large
! value.
DO i=1, 9
points(i)%x = 1.0e20
points(i)%y = 1.0e20
points(i)%z = 1.0e20
END DO
! All the points around the i,j indexes
points(1) = latlon2xyz(diag_global_grid%aglo_lat(indxI-1,indxJ+1),&
& diag_global_grid%aglo_lon(indxI-1,indxJ+1))
points(2) = latlon2xyz(diag_global_grid%aglo_lat(indxI-1,indxJ),&
& diag_global_grid%aglo_lon(indxI-1,indxJ))
points(3) = latlon2xyz(diag_global_grid%aglo_lat(indxI-1,indxJ-1),&
& diag_global_grid%aglo_lon(indxI-1,indxJ-1))
points(4) = latlon2xyz(diag_global_grid%aglo_lat(indxI, indxJ+1),&
& diag_global_grid%aglo_lon(indxI, indxJ+1))
points(5) = latlon2xyz(diag_global_grid%aglo_lat(indxI, indxJ),&
& diag_global_grid%aglo_lon(indxI, indxJ))
points(6) = latlon2xyz(diag_global_grid%aglo_lat(indxI, indxJ-1),&
& diag_global_grid%aglo_lon(indxI, indxJ-1))
points(7) = latlon2xyz(diag_global_grid%aglo_lat(indxI+1,indxJ+1),&
& diag_global_grid%aglo_lon(indxI+1,indxJ+1))
points(8) = latlon2xyz(diag_global_grid%aglo_lat(indxI+1,indxJ),&
& diag_global_grid%aglo_lon(indxI+1,indxJ))
points(9) = latlon2xyz(diag_global_grid%aglo_lat(indxI+1,indxJ-1),&
& diag_global_grid%aglo_lon(indxI+1,indxJ-1))
! Calculate the distance squared between the points(:) and the origPt
distSqrd = distanceSqrd(origPt, points)
SELECT CASE (MINLOC(distSqrd,1))
CASE ( 1 )
indxI = indxI-1
indxJ = indxJ+1
CASE ( 2 )
indxI = indxI-1
indxJ = indxJ
CASE ( 3 )
indxI = indxI-1
indxJ = indxJ-1
CASE ( 4 )
indxI = indxI
indxJ = indxJ+1
CASE ( 5 )
indxI = indxI
indxJ = indxJ
CASE ( 6 )
indxI = indxI
indxJ = indxJ-1
CASE ( 7 )
indxI = indxI+1
indxJ = indxJ+1
CASE ( 8 )
indxI = indxI+1
indxJ = indxJ
CASE ( 9 )
indxI = indxI+1
indxJ = indxJ-1
CASE DEFAULT
indxI = 0
indxJ = 0
END SELECT
END IF valid
! Set the return value for the funtion
find_pole_index_agrid = (/indxI, indxJ/)
END FUNCTION find_pole_index_agrid
! </FUNCTION>
! </PRIVATE>
! <PRIVATE>
! <FUNCTION NAME="find_equator_index_agrid">
! <OVERVIEW>
! Return the closest index (i,j) to the given (lat,lon) point.
! </OVERVIEW>
! <TEMPLATE>
! PURE FUNCTION find_equator_index_agrid(lat, lon)
! </TEMPLATE>
! <DESCRIPTION>
! This function searches a equator grid tile looking for the grid point
! closest to the give (lat, lon) location, and returns the i
! and j indexes of the point.
! </DESCRIPTION>
! <IN NAME="lat" TYPE="REAL">
! Latitude location
! </IN>
! <IN NAME="lon" TYPE="REAL">
! Longitude location
! </IN>
! <OUT NAME="find_equator_index" TYPE="INTEGER, DIMENSION(2)">
! The (i, j) location of the closest grid to the given (lat,
! lon) location.
! </OUT>
PURE FUNCTION find_equator_index_agrid(lat, lon)
INTEGER, DIMENSION(2) :: find_equator_index_agrid
REAL, INTENT(in) :: lat, lon
INTEGER :: indxI, indxJ !< Indexes to be returned.
INTEGER :: indxI_tmp !< Hold the indxI value if on tile 3 or 4
INTEGER :: dimI, dimJ !< Size of the grid dimensions
INTEGER :: i,j !< Count indexes
INTEGER :: jstart, jend, nextj !< j counting variables
TYPE(point) :: origPt !< Original point
TYPE(point), DIMENSION(4) :: points !< xyz of 8 nearest neighbors
REAL, DIMENSION(4) :: distSqrd !< distance between origPt and points(:)
! Set the inital fail values for indxI and indxJ
indxI = 0
indxJ = 0
dimI = diag_global_grid%adimI
dimJ = diag_global_grid%adimJ
! check to see if the 'fix' for the latitude index is needed
IF ( diag_global_grid%aglo_lat(1,1) > &
&diag_global_grid%aglo_lat(1,2) ) THEN
! reverse the j search
jstart = dimJ-1
jend = 1
nextj = -1
ELSE
jstart = 0
jend = dimJ-2
nextJ = 1
END IF
! find the I index
iLoop: DO i=0, dimI-2
IF ( diag_global_grid%aglo_lon(i,0) >&
& diag_global_grid%aglo_lon(i+1,0) ) THEN
! We are at the 0 longitudal line
IF ( (diag_global_grid%aglo_lon(i,0) <= lon .AND. lon <= 360.) .OR.&
& (0. <= lon .AND. lon < diag_global_grid%aglo_lon(i+1, 0)) ) THEN
indxI = i
EXIT iLoop
END IF
ELSEIF ( diag_global_grid%aglo_lon(i,0) <= lon .AND.&
& lon <= diag_global_grid%aglo_lon(i+1,0) ) THEN
indxI = i
EXIT iLoop
END IF
END DO iLoop
! Find the J index
IF ( indxI > 0 ) THEN
jLoop: DO j=jstart, jend, nextj
IF ( diag_global_grid%aglo_lat(indxI,j) <= lat .AND.&
& lat <= diag_global_grid%aglo_lat(indxI,j+nextj) ) THEN
indxJ = j
EXIT jLoop
END IF
END DO jLoop
END IF
! Make sure we have indexes in the correct range
valid: IF ( (indxI <= 0 .OR. dimI-1 < indxI) .OR. &
& (indxJ <= 0 .OR. dimJ-1 < indxJ) ) THEN
indxI = 0
indxJ = 0
ELSE ! indxI and indxJ are valid.
! Since we are looking for the closest grid point to the
! (lat,lon) point, we need to check the surrounding
! points. The indexes for the variable points are as follows
!
! 1---3
! | |
! 2---4
! The original point
origPt = latlon2xyz(lat,lon)
! Set the 'default' values for points(:) x,y,z to some large
! value.
DO i=1, 4
points(i)%x = 1.0e20
points(i)%y = 1.0e20
points(i)%z = 1.0e20
END DO
! The original point
origPt = latlon2xyz(lat,lon)
points(1) = latlon2xyz(diag_global_grid%aglo_lat(indxI,indxJ),&
& diag_global_grid%aglo_lon(indxI,indxJ))
points(2) = latlon2xyz(diag_global_grid%aglo_lat(indxI,indxJ+nextj),&
& diag_global_grid%aglo_lon(indxI,indxJ+nextj))
points(3) = latlon2xyz(diag_global_grid%aglo_lat(indxI+1,indxJ+nextj),&
& diag_global_grid%aglo_lon(indxI+1,indxJ+nextj))
points(4) = latlon2xyz(diag_global_grid%aglo_lat(indxI+1,indxJ),&
& diag_global_grid%aglo_lon(indxI+1,indxJ))
! Find the distance between the original point and the four
! grid points
distSqrd = distanceSqrd(origPt, points)
SELECT CASE (MINLOC(distSqrd,1))
CASE ( 1 )
indxI = indxI;
indxJ = indxJ;
CASE ( 2 )
indxI = indxI;
indxJ = indxJ+nextj;
CASE ( 3 )
indxI = indxI+1;
indxJ = indxJ+nextj;
CASE ( 4 )
indxI = indxI+1;
indxJ = indxJ;
CASE DEFAULT
indxI = 0;
indxJ = 0;
END SELECT
! If we are on tile 3 or 4, then the indxI and indxJ are
! reversed due to the transposed grids.
IF ( diag_global_grid%tile_number == 4 .OR.&
& diag_global_grid%tile_number == 5 ) THEN
indxI_tmp = indxI
indxI = indxJ
indxJ = indxI_tmp
END IF
END IF valid
! Set the return value for the function
find_equator_index_agrid = (/indxI, indxJ/)
END FUNCTION find_equator_index_agrid
! </FUNCTION>
! </PRIVATE>
! <PRIVATE>
! <FUNCTION NAME="latlon2xyz">
! <OVERVIEW>
! Return the (x,y,z) position of a given (lat,lon) point.
! </OVERVIEW>
! <TEMPLATE>
! PURE ELEMENTAL TYPE(point) FUNCTION latlon2xyz(lat, lon)
! </TEMPLATE>
! <DESCRIPTION>
! Given a specific (lat, lon) point on the Earth, return the
! corresponding (x,y,z) location. The return of latlon2xyz
! will be either a scalar or an array of the same size as lat
! and lon.
! </DESCRIPTION>
! <IN NAME="lat" TYPE="REAL">
! The latitude of the (x,y,z) location to find. <TT>lat</TT>
! can be either a scalar or array. <TT>lat</TT> must be of the
! same rank / size as <TT>lon</TT>. This function assumes
! <TT>lat</TT> is in the range [-90,90].
! </IN>
! <IN NAME="lon" TYPE="REAL">
! The longitude of the (x,y,z) location to find. <TT>lon</TT>
! can be either a scalar or array. <TT>lon</TT> must be of the
! same rank / size as <TT>lat</TT>. This function assumes
! <TT>lon</TT> is in the range [0,360].
! </IN>
PURE ELEMENTAL TYPE(point) FUNCTION latlon2xyz(lat, lon)
REAL, INTENT(in) :: lat, lon
! lat/lon angles in radians
REAL :: theta, phi
! Convert the lat lon values to radians The lat values passed in
! are in the range [-90,90], but we need to have a radian range
! [0,pi], where 0 is at the north pole. This is the reason for
! the subtraction from 90
theta = deg2rad(90.-lat)
phi = deg2rad(lon)
! Calculate the x,y,z point
latlon2xyz%x = RADIUS * SIN(theta) * COS(phi)
latlon2xyz%y = RADIUS * SIN(theta) * SIN(phi)
latlon2xyz%z = RADIUS * COS(theta)
END FUNCTION latlon2xyz
! </FUNCTION>
! </PRIVATE>
! <PRIVATE>
! <FUNCTION NAME="distanceSqrd">
! <OVERVIEW>
! Find the distance between two points in the Cartesian
! coordinate space.
! </OVERVIEW>
! <TEMPLATE>
! PURE ELEMENTAL REAL FUNCTION distanceSqrd(pt1, pt2)
! </TEMPLATE>
! <DESCRIPTION>
! <TT>distanceSqrd</TT> will find the distance squared between
! two points in the xyz coordinate space. <TT>pt1</TT> and <TT>
! pt2</TT> can either be both scalars, both arrays of the same
! size, or one a scalar and one an array. The return value
! will be a scalar or array of the same size as the input array.
! </DESCRIPTION>
! <IN NAME="pt1" TYPE="TYPE(POINT)" />
! <IN NAME="pt2" TYPE="TYPE(POINT)" />
PURE ELEMENTAL REAL FUNCTION distanceSqrd(pt1, pt2)
TYPE(point), INTENT(in) :: pt1, pt2
distanceSqrd = (pt1%x-pt2%x)**2 +&
& (pt1%y-pt2%y)**2 +&
& (pt1%z-pt2%z)**2
END FUNCTION distanceSqrd
! </FUNCTION>
! </PRIVATE>
! <FUNCTION NAME="gCirDistance">
! <OVERVIEW>
! Find the distance, along the geodesic, between two points.
! </OVERVIEW>
! <TEMPLATE>
! PURE ELEMENTAL REAL FUNCTION gCirDistance(lat1, lon1, lat2, lon2)
! </TEMPLATE>
! <DESCRIPTION>
! <TT>aCirDistance</TT> will find the distance, along the geodesic, between two points defined by the (lat,lon) position of
! each point.
! </DESCRIPTION>
! <IN NAME="lat1" TYPE="REAL">Latitude of the first point</IN>
! <IN NAME="lon1" TYPE="REAL">Longitude of the first point</IN>
! <IN NAME="lat2" TYPE="REAL">Latitude of the second point</IN>
! <IN NAME="lon2" TYPE="REAL">Longitude of the second point</IN>
PURE ELEMENTAL REAL FUNCTION gCirDistance(lat1, lon1, lat2, lon2)
REAL, INTENT(in) :: lat1, lat2, lon1, lon2
REAL :: theta1, theta2
REAL :: deltaLambda !< Difference in longitude angles, in radians.
REAL :: deltaTheta !< Difference in latitude angels, in radians.
theta1 = deg2rad(lat1)
theta2 = deg2rad(lat2)
deltaLambda = deg2rad(lon2-lon1)
deltaTheta = deg2rad(lat2-lat1)
gCirDistance = RADIUS * 2. * ASIN(SQRT((SIN(deltaTheta/2.))**2 + COS(theta1)*COS(theta2)*(SIN(deltaLambda/2.))**2))
END FUNCTION gCirDistance
! </FUNCTION>
END MODULE diag_grid_mod
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/sphere3.1_dp/vhsgs.f | 1 | 48891 | c
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c . .
c . copyright (c) 1998 by UCAR .
c . .
c . University Corporation for Atmospheric Research .
c . .
c . all rights reserved .
c . .
c . .
c . SPHEREPACK .
c . .
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c
c
c
c ... file vhsgs.f
c
c this file contains code and documentation for subroutines
c vhsgs and vhsgsi
c
c ... files which must be loaded with vhsgs.f
c
c sphcom.f, hrfft.f, gaqd.f
c
c subroutine vhsgs(nlat,nlon,ityp,nt,v,w,idvw,jdvw,br,bi,cr,ci,
c + mdab,ndab,wvhsgs,lvhsgs,work,lwork,ierror)
c
c
c subroutine vhsgs performs the vector spherical harmonic synthesis
c of the arrays br, bi, cr, and ci and stores the result in the
c arrays v and w. the synthesis is performed on an equally spaced
c longitude grid and a gaussian colatitude grid (measured from
c the north pole). v(i,j) and w(i,j) are the colatitudinal and
c east longitudinal components respectively, located at the i(th)
c colatitude gaussian point (see nlat below) and longitude
c phi(j) = (j-1)*2*pi/nlon. the spectral respresentation of (v,w)
c is given below at output parameters v,w.
c
c input parameters
c
c nlat the number of points in the gaussian colatitude grid on the
C*PL*ERROR* Comment line too long
c full sphere. these lie in the interval (0,pi) and are computed
C*PL*ERROR* Comment line too long
c in radians in theta(1) <...< theta(nlat) by subroutine gaqd.
C*PL*ERROR* Comment line too long
c if nlat is odd the equator will be included as the grid point
c theta((nlat+1)/2). if nlat is even the equator will be
c excluded as a grid point and will lie half way between
c theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.
c note: on the half sphere, the number of grid points in the
c colatitudinal direction is nlat/2 if nlat is even or
c (nlat+1)/2 if nlat is odd.
c
c nlon the number of distinct londitude points. nlon determines
c the grid increment in longitude as 2*pi/nlon. for example
c nlon = 72 for a five degree grid. nlon must be greater
c than zero. the axisymmetric case corresponds to nlon=1.
c the efficiency of the computation is improved when nlon
c is a product of small prime numbers.
c
c ityp = 0 no symmetries exist about the equator. the synthesis
c is performed on the entire sphere. i.e. on the
c arrays v(i,j),w(i,j) for i=1,...,nlat and
c j=1,...,nlon.
c
c = 1 no symmetries exist about the equator. the synthesis
c is performed on the entire sphere. i.e. on the
c arrays v(i,j),w(i,j) for i=1,...,nlat and
c j=1,...,nlon. the curl of (v,w) is zero. that is,
c (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.
c the coefficients cr and ci are zero.
c
c = 2 no symmetries exist about the equator. the synthesis
c is performed on the entire sphere. i.e. on the
c arrays v(i,j),w(i,j) for i=1,...,nlat and
c j=1,...,nlon. the divergence of (v,w) is zero. i.e.,
c (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.
c the coefficients br and bi are zero.
c
c = 3 v is symmetric and w is antisymmetric about the
c equator. the synthesis is performed on the northern
c hemisphere only. i.e., if nlat is odd the synthesis
c is performed on the arrays v(i,j),w(i,j) for
c i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is
c even the synthesis is performed on the the arrays
c v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c = 4 v is symmetric and w is antisymmetric about the
c equator. the synthesis is performed on the northern
c hemisphere only. i.e., if nlat is odd the synthesis
c is performed on the arrays v(i,j),w(i,j) for
c i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is
c even the synthesis is performed on the the arrays
c v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c the curl of (v,w) is zero. that is,
c (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.
c the coefficients cr and ci are zero.
c
c = 5 v is symmetric and w is antisymmetric about the
c equator. the synthesis is performed on the northern
c hemisphere only. i.e., if nlat is odd the synthesis
c is performed on the arrays v(i,j),w(i,j) for
c i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is
c even the synthesis is performed on the the arrays
c v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c the divergence of (v,w) is zero. i.e.,
c (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.
c the coefficients br and bi are zero.
c
c = 6 v is antisymmetric and w is symmetric about the
c equator. the synthesis is performed on the northern
c hemisphere only. i.e., if nlat is odd the synthesis
c is performed on the arrays v(i,j),w(i,j) for
c i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is
c even the synthesis is performed on the the arrays
c v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c = 7 v is antisymmetric and w is symmetric about the
c equator. the synthesis is performed on the northern
c hemisphere only. i.e., if nlat is odd the synthesis
c is performed on the arrays v(i,j),w(i,j) for
c i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is
c even the synthesis is performed on the the arrays
c v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c the curl of (v,w) is zero. that is,
c (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.
c the coefficients cr and ci are zero.
c
c = 8 v is antisymmetric and w is symmetric about the
c equator. the synthesis is performed on the northern
c hemisphere only. i.e., if nlat is odd the synthesis
c is performed on the arrays v(i,j),w(i,j) for
c i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is
c even the synthesis is performed on the the arrays
c v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c the divergence of (v,w) is zero. i.e.,
c (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.
c the coefficients br and bi are zero.
c
c
c nt the number of syntheses. in the program that calls vhsgs,
c the arrays v,w,br,bi,cr, and ci can be three dimensional
c in which case multiple syntheses will be performed.
c the third index is the synthesis index which assumes the
c values k=1,...,nt. for a single synthesis set nt=1. the
c discription of the remaining parameters is simplified
c by assuming that nt=1 or that all the arrays are two
c dimensional.
c
c idvw the first dimension of the arrays v,w as it appears in
c the program that calls vhags. if ityp .le. 2 then idvw
c must be at least nlat. if ityp .gt. 2 and nlat is
c even then idvw must be at least nlat/2. if ityp .gt. 2
c and nlat is odd then idvw must be at least (nlat+1)/2.
c
c jdvw the second dimension of the arrays v,w as it appears in
c the program that calls vhsgs. jdvw must be at least nlon.
c
c br,bi two or three dimensional arrays (see input parameter nt)
c cr,ci that contain the vector spherical harmonic coefficients
c in the spectral representation of v(i,j) and w(i,j) given
c below at the discription of output parameters v and w.
c
c mdab the first dimension of the arrays br,bi,cr, and ci as it
c appears in the program that calls vhsgs. mdab must be at
c least min0(nlat,nlon/2) if nlon is even or at least
c min0(nlat,(nlon+1)/2) if nlon is odd.
c
c ndab the second dimension of the arrays br,bi,cr, and ci as it
c appears in the program that calls vhsgs. ndab must be at
c least nlat.
c
c wvhsgs an array which must be initialized by subroutine vhsgsi.
c once initialized, wvhsgs can be used repeatedly by vhsgs
c as long as nlon and nlat remain unchanged. wvhsgs must
c not be altered between calls of vhsgs.
c
c lvhsgs the dimension of the array wvhsgs as it appears in the
c program that calls vhsgs. define
c
c l1 = min0(nlat,nlon/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c then lvhsgs must be at least
c
c l1*l2*(nlat+nlat-l1+1)+nlon+15+2*nlat
c
c
c work a work array that does not have to be saved.
c
c lwork the dimension of the array work as it appears in the
c program that calls vhsgs. define
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c if ityp .le. 2 then lwork must be at least
c
c (2*nt+1)*nlat*nlon
c
c if ityp .gt. 2 then lwork must be at least
c
c (2*nt+1)*l2*nlon
c
c **************************************************************
c
c output parameters
c
c v,w two or three dimensional arrays (see input parameter nt)
c in which the synthesis is stored. v is the colatitudinal
c component and w is the east longitudinal component.
C*PL*ERROR* Comment line too long
c v(i,j),w(i,j) contain the components at the guassian colatitude
c point theta(i) and longitude phi(j) = (j-1)*2*pi/nlon.
c the index ranges are defined above at the input parameter
c ityp. v and w are computed from the formulas given below.
c
c
c define
c
c 1. theta is colatitude and phi is east longitude
c
c 2. the normalized associated legendre funnctions
c
c pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)
c /(2*factorial(n+m)))*sin(theta)**m/(2**n*
c factorial(n)) times the (n+m)th derivative
c of (x**2-1)**n with respect to x=cos(theta)
c
c 3. vbar(m,n,theta) = the derivative of pbar(m,n,theta) with
c respect to theta divided by the square
c root of n(n+1).
c
c vbar(m,n,theta) is more easily computed in the form
c
c vbar(m,n,theta) = (sqrt((n+m)*(n-m+1))*pbar(m-1,n,theta)
c -sqrt((n-m)*(n+m+1))*pbar(m+1,n,theta))/(2*sqrt(n*(n+1)))
c
c 4. wbar(m,n,theta) = m/(sin(theta))*pbar(m,n,theta) divided
c by the square root of n(n+1).
c
c wbar(m,n,theta) is more easily computed in the form
c
c wbar(m,n,theta) = sqrt((2n+1)/(2n-1))*(sqrt((n+m)*(n+m-1))
c *pbar(m-1,n-1,theta)+sqrt((n-m)*(n-m-1))*pbar(m+1,n-1,theta))
c /(2*sqrt(n*(n+1)))
c
c
c the colatitudnal dependence of the normalized surface vector
c spherical harmonics are defined by
c
c 5. bbar(m,n,theta) = (vbar(m,n,theta),i*wbar(m,n,theta))
c
c 6. cbar(m,n,theta) = (i*wbar(m,n,theta),-vbar(m,n,theta))
c
c
c the coordinate to index mappings
c
C*PL*ERROR* Comment line too long
c 7. theta(i) = i(th) gaussian grid point and phi(j) = (j-1)*2*pi/nlon
c
c
c the maximum (plus one) longitudinal wave number
c
c 8. mmax = min0(nlat,nlon/2) if nlon is even or
c mmax = min0(nlat,(nlon+1)/2) if nlon is odd.
c
c if we further define the output vector as
c
c 9. h(i,j) = (v(i,j),w(i,j))
c
c and the complex coefficients
c
c 10. b(m,n) = cmplx(br(m+1,n+1),bi(m+1,n+1))
c
c 11. c(m,n) = cmplx(cr(m+1,n+1),ci(m+1,n+1))
c
c
c then for i=1,...,nlat and j=1,...,nlon
c
c the expansion for real h(i,j) takes the form
c
c h(i,j) = the sum from n=1 to n=nlat-1 of the real part of
c
c .5*(b(0,n)*bbar(0,n,theta(i))+c(0,n)*cbar(0,n,theta(i)))
c
c plus the sum from m=1 to m=mmax-1 of the sum from n=m to
c n=nlat-1 of the real part of
c
c b(m,n)*bbar(m,n,theta(i))*exp(i*m*phi(j))
c +c(m,n)*cbar(m,n,theta(i))*exp(i*m*phi(j))
c
c *************************************************************
c
c in terms of real variables this expansion takes the form
c
c for i=1,...,nlat and j=1,...,nlon
c
c v(i,j) = the sum from n=1 to n=nlat-1 of
c
c .5*br(1,n+1)*vbar(0,n,theta(i))
c
c plus the sum from m=1 to m=mmax-1 of the sum from n=m to
c n=nlat-1 of the real part of
c
c (br(m+1,n+1)*vbar(m,n,theta(i))-ci(m+1,n+1)*wbar(m,n,theta(i)))
c *cos(m*phi(j))
c -(bi(m+1,n+1)*vbar(m,n,theta(i))+cr(m+1,n+1)*wbar(m,n,theta(i)))
c *sin(m*phi(j))
c
c and for i=1,...,nlat and j=1,...,nlon
c
c w(i,j) = the sum from n=1 to n=nlat-1 of
c
c -.5*cr(1,n+1)*vbar(0,n,theta(i))
c
c plus the sum from m=1 to m=mmax-1 of the sum from n=m to
c n=nlat-1 of the real part of
c
c -(cr(m+1,n+1)*vbar(m,n,theta(i))+bi(m+1,n+1)*wbar(m,n,theta(i)))
c *cos(m*phi(j))
c +(ci(m+1,n+1)*vbar(m,n,theta(i))-br(m+1,n+1)*wbar(m,n,theta(i)))
c *sin(m*phi(j))
c
c
c br(m+1,nlat),bi(m+1,nlat),cr(m+1,nlat), and ci(m+1,nlat) are
c assumed zero for m even.
c
c
c ierror = 0 no errors
c = 1 error in the specification of nlat
c = 2 error in the specification of nlon
c = 3 error in the specification of ityp
c = 4 error in the specification of nt
c = 5 error in the specification of idvw
c = 6 error in the specification of jdvw
c = 7 error in the specification of mdab
c = 8 error in the specification of ndab
c = 9 error in the specification of lvhsgs
c = 10 error in the specification of lwork
c
c
c subroutine vhsgsi(nlat,nlon,wvhsgs,lvhsgs,dwork,ldwork,ierror)
c
c subroutine vhsgsi initializes the array wvhsgs which can then be
c used repeatedly by subroutine vhsgs until nlat or nlon is changed.
c
c input parameters
c
c nlat the number of points in the gaussian colatitude grid on the
C*PL*ERROR* Comment line too long
c full sphere. these lie in the interval (0,pi) and are computed
C*PL*ERROR* Comment line too long
c in radians in theta(1) <...< theta(nlat) by subroutine gaqd.
C*PL*ERROR* Comment line too long
c if nlat is odd the equator will be included as the grid point
c theta((nlat+1)/2). if nlat is even the equator will be
c excluded as a grid point and will lie half way between
c theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.
c note: on the half sphere, the number of grid points in the
c colatitudinal direction is nlat/2 if nlat is even or
c (nlat+1)/2 if nlat is odd.
c
c nlon the number of distinct londitude points. nlon determines
c the grid increment in longitude as 2*pi/nlon. for example
c nlon = 72 for a five degree grid. nlon must be greater
c than zero. the axisymmetric case corresponds to nlon=1.
c the efficiency of the computation is improved when nlon
c is a product of small prime numbers.
c
c lvhsgs the dimension of the array wvhsgs as it appears in the
c program that calls vhsgs. define
c
c l1 = min0(nlat,nlon/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c then lvhsgs must be at least
c
c l1*l2*(nlat+nlat-l1+1)+nlon+15+2*nlat
c
c dwork a double precision work array that does not need to be saved
c
c ldwork the dimension of the array dwork as it appears in the
c program that calls vhsgsi. ldwork must be at least
c
c (3*nlat*(nlat+3)+2)/2
c
c **************************************************************
c
c output parameters
c
c wvhsgs an array which is initialized for use by subroutine vhsgs.
c once initialized, wvhsgs can be used repeatedly by vhsgs
c as long as nlat and nlon remain unchanged. wvhsgs must not
c be altered between calls of vhsgs.
c
c
c ierror = 0 no errors
c = 1 error in the specification of nlat
c = 2 error in the specification of nlon
c = 3 error in the specification of lvhsgs
c = 4 error in the specification of lwork
c
SUBROUTINE DVHSGS(NLAT,NLON,ITYP,NT,V,W,IDVW,JDVW,BR,BI,CR,CI,
+ MDAB,NDAB,WVHSGS,LVHSGS,WORK,LWORK,IERROR)
DOUBLE PRECISION V
DOUBLE PRECISION W
DOUBLE PRECISION BR
DOUBLE PRECISION BI
DOUBLE PRECISION CR
DOUBLE PRECISION CI
DOUBLE PRECISION WVHSGS
DOUBLE PRECISION WORK
DIMENSION V(IDVW,JDVW,1),W(IDVW,JDVW,1),BR(MDAB,NDAB,1),
+ BI(MDAB,NDAB,1),CR(MDAB,NDAB,1),CI(MDAB,NDAB,1),WORK(1),
+ WVHSGS(1)
IERROR = 1
IF (NLAT.LT.3) RETURN
IERROR = 2
IF (NLON.LT.1) RETURN
IERROR = 3
IF (ITYP.LT.0 .OR. ITYP.GT.8) RETURN
IERROR = 4
IF (NT.LT.0) RETURN
IERROR = 5
IMID = (NLAT+1)/2
IF ((ITYP.LE.2.AND.IDVW.LT.NLAT) .OR.
+ (ITYP.GT.2.AND.IDVW.LT.IMID)) RETURN
IERROR = 6
IF (JDVW.LT.NLON) RETURN
IERROR = 7
MMAX = MIN0(NLAT, (NLON+1)/2)
IF (MDAB.LT.MMAX) RETURN
IERROR = 8
IF (NDAB.LT.NLAT) RETURN
IERROR = 9
IDZ = (MMAX* (NLAT+NLAT-MMAX+1))/2
LZIMN = IDZ*IMID
IF (LVHSGS.LT.LZIMN+LZIMN+NLON+15) RETURN
IERROR = 10
IDV = NLAT
IF (ITYP.GT.2) IDV = IMID
LNL = NT*IDV*NLON
IF (LWORK.LT.LNL+LNL+IDV*NLON) RETURN
IERROR = 0
IST = 0
IF (ITYP.LE.2) IST = IMID
c
c set wvhsgs pointers
c
LMN = NLAT* (NLAT+1)/2
JW1 = 1
JW2 = JW1 + IMID*LMN
JW3 = JW2 + IMID*LMN
c
c set work pointers
c
IW1 = IST + 1
IW2 = LNL + 1
IW3 = IW2 + IST
IW4 = IW2 + LNL
CALL DVHSGS1(NLAT,NLON,ITYP,NT,IMID,IDVW,JDVW,V,W,MDAB,NDAB,BR,
+ BI,CR,CI,IDV,WORK,WORK(IW1),WORK(IW2),WORK(IW3),
+ WORK(IW4),IDZ,WVHSGS(JW1),WVHSGS(JW2),WVHSGS(JW3))
RETURN
END
SUBROUTINE DVHSGS1(NLAT,NLON,ITYP,NT,IMID,IDVW,JDVW,V,W,MDAB,NDAB,
+ BR,BI,CR,CI,IDV,VE,VO,WE,WO,WORK,IDZ,VB,WB,
+ WRFFT)
DOUBLE PRECISION V
DOUBLE PRECISION W
DOUBLE PRECISION BR
DOUBLE PRECISION BI
DOUBLE PRECISION CR
DOUBLE PRECISION CI
DOUBLE PRECISION VE
DOUBLE PRECISION VO
DOUBLE PRECISION WE
DOUBLE PRECISION WO
DOUBLE PRECISION WORK
DOUBLE PRECISION VB
DOUBLE PRECISION WB
DOUBLE PRECISION WRFFT
DIMENSION V(IDVW,JDVW,1),W(IDVW,JDVW,1),BR(MDAB,NDAB,1),
+ BI(MDAB,NDAB,1),CR(MDAB,NDAB,1),CI(MDAB,NDAB,1),
+ VE(IDV,NLON,1),VO(IDV,NLON,1),WE(IDV,NLON,1),
+ WO(IDV,NLON,1),WORK(1),WRFFT(1),VB(IMID,1),WB(IMID,1)
NLP1 = NLAT + 1
MLAT = MOD(NLAT,2)
MLON = MOD(NLON,2)
MMAX = MIN0(NLAT, (NLON+1)/2)
IMM1 = IMID
IF (MLAT.NE.0) IMM1 = IMID - 1
DO 10 K = 1,NT
DO 10 J = 1,NLON
DO 10 I = 1,IDV
VE(I,J,K) = 0.D0
WE(I,J,K) = 0.D0
10 CONTINUE
NDO1 = NLAT
NDO2 = NLAT
IF (MLAT.NE.0) NDO1 = NLAT - 1
IF (MLAT.EQ.0) NDO2 = NLAT - 1
18 ITYPP = ITYP + 1
GO TO (1,100,200,300,400,500,600,700,800) ITYPP
c
c case ityp=0 no symmetries
c
c case m = 0
c
1 CONTINUE
DO 15 K = 1,NT
DO 15 NP1 = 2,NDO2,2
DO 15 I = 1,IMID
VE(I,1,K) = VE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
WE(I,1,K) = WE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
15 CONTINUE
DO 16 K = 1,NT
DO 16 NP1 = 3,NDO1,2
DO 16 I = 1,IMM1
VO(I,1,K) = VO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
WO(I,1,K) = WO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
16 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 30 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP1.GT.NDO1) GO TO 26
DO 25 K = 1,NT
DO 24 NP1 = MP1,NDO1,2
MN = MB + NP1
DO 23 I = 1,IMM1
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
23 CONTINUE
IF (MLAT.EQ.0) GO TO 24
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(IMID,MN)
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(IMID,MN)
24 CONTINUE
25 CONTINUE
26 IF (MP2.GT.NDO2) GO TO 30
DO 29 K = 1,NT
DO 28 NP1 = MP2,NDO2,2
MN = MB + NP1
DO 27 I = 1,IMM1
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
27 CONTINUE
IF (MLAT.EQ.0) GO TO 28
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(IMID,MN)
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(IMID,MN)
28 CONTINUE
29 CONTINUE
30 CONTINUE
GO TO 950
c
c case ityp=1 no symmetries, cr and ci equal zero
c
c case m = 0
c
100 CONTINUE
DO 115 K = 1,NT
DO 115 NP1 = 2,NDO2,2
DO 115 I = 1,IMID
VE(I,1,K) = VE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
115 CONTINUE
DO 116 K = 1,NT
DO 116 NP1 = 3,NDO1,2
DO 116 I = 1,IMM1
VO(I,1,K) = VO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
116 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 130 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP1.GT.NDO1) GO TO 126
DO 125 K = 1,NT
DO 124 NP1 = MP1,NDO1,2
MN = MB + NP1
DO 123 I = 1,IMM1
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
123 CONTINUE
IF (MLAT.EQ.0) GO TO 124
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(IMID,MN)
124 CONTINUE
125 CONTINUE
126 IF (MP2.GT.NDO2) GO TO 130
DO 129 K = 1,NT
DO 128 NP1 = MP2,NDO2,2
MN = MB + NP1
DO 127 I = 1,IMM1
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
127 CONTINUE
IF (MLAT.EQ.0) GO TO 128
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(IMID,MN)
128 CONTINUE
129 CONTINUE
130 CONTINUE
GO TO 950
c
c case ityp=2 no symmetries, br and bi are equal to zero
c
c case m = 0
c
200 DO 215 K = 1,NT
DO 215 NP1 = 2,NDO2,2
DO 215 I = 1,IMID
WE(I,1,K) = WE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
215 CONTINUE
DO 216 K = 1,NT
DO 216 NP1 = 3,NDO1,2
DO 216 I = 1,IMM1
WO(I,1,K) = WO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
216 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 230 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP1.GT.NDO1) GO TO 226
DO 225 K = 1,NT
DO 224 NP1 = MP1,NDO1,2
MN = MB + NP1
DO 223 I = 1,IMM1
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
223 CONTINUE
IF (MLAT.EQ.0) GO TO 224
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(IMID,MN)
224 CONTINUE
225 CONTINUE
226 IF (MP2.GT.NDO2) GO TO 230
DO 229 K = 1,NT
DO 228 NP1 = MP2,NDO2,2
MN = MB + NP1
DO 227 I = 1,IMM1
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
227 CONTINUE
IF (MLAT.EQ.0) GO TO 228
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(IMID,MN)
228 CONTINUE
229 CONTINUE
230 CONTINUE
GO TO 950
c
c case ityp=3 v even, w odd
c
c case m = 0
c
300 DO 315 K = 1,NT
DO 315 NP1 = 2,NDO2,2
DO 315 I = 1,IMID
VE(I,1,K) = VE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
315 CONTINUE
DO 316 K = 1,NT
DO 316 NP1 = 3,NDO1,2
DO 316 I = 1,IMM1
WO(I,1,K) = WO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
316 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 330 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP1.GT.NDO1) GO TO 326
DO 325 K = 1,NT
DO 324 NP1 = MP1,NDO1,2
MN = MB + NP1
DO 323 I = 1,IMM1
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
323 CONTINUE
IF (MLAT.EQ.0) GO TO 324
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(IMID,MN)
324 CONTINUE
325 CONTINUE
326 IF (MP2.GT.NDO2) GO TO 330
DO 329 K = 1,NT
DO 328 NP1 = MP2,NDO2,2
MN = MB + NP1
DO 327 I = 1,IMM1
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
327 CONTINUE
IF (MLAT.EQ.0) GO TO 328
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(IMID,MN)
328 CONTINUE
329 CONTINUE
330 CONTINUE
GO TO 950
c
c case ityp=4 v even, w odd, and both cr and ci equal zero
c
c case m = 0
c
400 DO 415 K = 1,NT
DO 415 NP1 = 2,NDO2,2
DO 415 I = 1,IMID
VE(I,1,K) = VE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
415 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 430 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP2.GT.NDO2) GO TO 430
DO 429 K = 1,NT
DO 428 NP1 = MP2,NDO2,2
MN = MB + NP1
DO 427 I = 1,IMM1
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
427 CONTINUE
IF (MLAT.EQ.0) GO TO 428
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(IMID,MN)
428 CONTINUE
429 CONTINUE
430 CONTINUE
GO TO 950
c
c case ityp=5 v even, w odd, br and bi equal zero
c
c case m = 0
c
500 DO 516 K = 1,NT
DO 516 NP1 = 3,NDO1,2
DO 516 I = 1,IMM1
WO(I,1,K) = WO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
516 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 530 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP1.GT.NDO1) GO TO 530
DO 525 K = 1,NT
DO 524 NP1 = MP1,NDO1,2
MN = MB + NP1
DO 523 I = 1,IMM1
VE(I,2*MP1-2,K) = VE(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VE(I,2*MP1-1,K) = VE(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WO(I,2*MP1-2,K) = WO(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WO(I,2*MP1-1,K) = WO(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
523 CONTINUE
IF (MLAT.EQ.0) GO TO 524
VE(IMID,2*MP1-2,K) = VE(IMID,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(IMID,MN)
VE(IMID,2*MP1-1,K) = VE(IMID,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(IMID,MN)
524 CONTINUE
525 CONTINUE
530 CONTINUE
GO TO 950
c
c case ityp=6 v odd , w even
c
c case m = 0
c
600 DO 615 K = 1,NT
DO 615 NP1 = 2,NDO2,2
DO 615 I = 1,IMID
WE(I,1,K) = WE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
615 CONTINUE
DO 616 K = 1,NT
DO 616 NP1 = 3,NDO1,2
DO 616 I = 1,IMM1
VO(I,1,K) = VO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
616 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 630 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP1.GT.NDO1) GO TO 626
DO 625 K = 1,NT
DO 624 NP1 = MP1,NDO1,2
MN = MB + NP1
DO 623 I = 1,IMM1
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
623 CONTINUE
IF (MLAT.EQ.0) GO TO 624
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(IMID,MN)
624 CONTINUE
625 CONTINUE
626 IF (MP2.GT.NDO2) GO TO 630
DO 629 K = 1,NT
DO 628 NP1 = MP2,NDO2,2
MN = MB + NP1
DO 627 I = 1,IMM1
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
627 CONTINUE
IF (MLAT.EQ.0) GO TO 628
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(IMID,MN)
628 CONTINUE
629 CONTINUE
630 CONTINUE
GO TO 950
c
c case ityp=7 v odd, w even cr and ci equal zero
c
c case m = 0
c
700 DO 716 K = 1,NT
DO 716 NP1 = 3,NDO1,2
DO 716 I = 1,IMM1
VO(I,1,K) = VO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)
716 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 730 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP1.GT.NDO1) GO TO 730
DO 725 K = 1,NT
DO 724 NP1 = MP1,NDO1,2
MN = MB + NP1
DO 723 I = 1,IMM1
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) +
+ BR(MP1,NP1,K)*VB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ BI(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(I,MN)
723 CONTINUE
IF (MLAT.EQ.0) GO TO 724
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ BI(MP1,NP1,K)*WB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) +
+ BR(MP1,NP1,K)*WB(IMID,MN)
724 CONTINUE
725 CONTINUE
730 CONTINUE
GO TO 950
c
c case ityp=8 v odd, w even br and bi equal zero
c
c case m = 0
c
800 DO 815 K = 1,NT
DO 815 NP1 = 2,NDO2,2
DO 815 I = 1,IMID
WE(I,1,K) = WE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)
815 CONTINUE
c
c case m = 1 through nlat-1
c
IF (MMAX.LT.2) GO TO 950
DO 830 MP1 = 2,MMAX
M = MP1 - 1
c mb = m*(nlat-1)-(m*(m-1))/2
MB = M*NLAT - (M* (M+1))/2
MP2 = MP1 + 1
IF (MP2.GT.NDO2) GO TO 830
DO 829 K = 1,NT
DO 828 NP1 = MP2,NDO2,2
MN = MB + NP1
DO 827 I = 1,IMM1
VO(I,2*MP1-2,K) = VO(I,2*MP1-2,K) -
+ CI(MP1,NP1,K)*WB(I,MN)
VO(I,2*MP1-1,K) = VO(I,2*MP1-1,K) +
+ CR(MP1,NP1,K)*WB(I,MN)
WE(I,2*MP1-2,K) = WE(I,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(I,MN)
WE(I,2*MP1-1,K) = WE(I,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(I,MN)
827 CONTINUE
IF (MLAT.EQ.0) GO TO 828
WE(IMID,2*MP1-2,K) = WE(IMID,2*MP1-2,K) -
+ CR(MP1,NP1,K)*VB(IMID,MN)
WE(IMID,2*MP1-1,K) = WE(IMID,2*MP1-1,K) -
+ CI(MP1,NP1,K)*VB(IMID,MN)
828 CONTINUE
829 CONTINUE
830 CONTINUE
950 CONTINUE
DO 14 K = 1,NT
CALL DHRFFTB(IDV,NLON,VE(1,1,K),IDV,WRFFT,WORK)
CALL DHRFFTB(IDV,NLON,WE(1,1,K),IDV,WRFFT,WORK)
14 CONTINUE
IF (ITYP.GT.2) GO TO 12
DO 60 K = 1,NT
DO 60 J = 1,NLON
DO 60 I = 1,IMM1
V(I,J,K) = .5D0* (VE(I,J,K)+VO(I,J,K))
W(I,J,K) = .5D0* (WE(I,J,K)+WO(I,J,K))
V(NLP1-I,J,K) = .5D0* (VE(I,J,K)-VO(I,J,K))
W(NLP1-I,J,K) = .5D0* (WE(I,J,K)-WO(I,J,K))
60 CONTINUE
GO TO 13
12 DO 11 K = 1,NT
DO 11 J = 1,NLON
DO 11 I = 1,IMM1
V(I,J,K) = .5D0*VE(I,J,K)
W(I,J,K) = .5D0*WE(I,J,K)
11 CONTINUE
13 IF (MLAT.EQ.0) RETURN
DO 65 K = 1,NT
DO 65 J = 1,NLON
V(IMID,J,K) = .5D0*VE(IMID,J,K)
W(IMID,J,K) = .5D0*WE(IMID,J,K)
65 CONTINUE
RETURN
END
SUBROUTINE DVHSGSI(NLAT,NLON,WVHSGS,LVHSGS,DWORK,LDWORK,IERROR)
DOUBLE PRECISION WVHSGS
c
c subroutine vhsfsi computes the gaussian points theta, gauss
c weights wts, and the components vb and wb of the vector
c harmonics. all quantities are computed internally in double
c precision but returned in single precision and are therfore
c accurate to single precision.
c
c set imid = (nlat+1)/2 and lmn=(nlat*(nlat+1))/2 then
c wvhsgs must have 2*(imid*lmn+nlat)+nlon+15 locations
c
c double precision array dwork must have
c 3*nlat*(nlat+1)+5*nlat+1 = nlat*(3*nlat+8)+1
c locations which is determined by the size of dthet,
c dwts, dwork, and dpbar in vhsgs1
c
DIMENSION WVHSGS(*)
C*PT*WARNING* Already double-precision
DOUBLE PRECISION DWORK(*)
IERROR = 1
IF (NLAT.LT.3) RETURN
IERROR = 2
IF (NLON.LT.1) RETURN
IERROR = 3
IMID = (NLAT+1)/2
LMN = (NLAT* (NLAT+1))/2
IF (LVHSGS.LT.2* (IMID*LMN)+NLON+15) RETURN
IERROR = 4
IF (LDWORK.LT. (NLAT*3* (NLAT+3)+2)/2) RETURN
IERROR = 0
c
c set saved work space pointers
c
JW1 = 1
JW2 = JW1 + IMID*LMN
JW3 = JW2 + IMID*LMN
c
c set unsaved work space pointers
c
IW1 = 1
IW2 = IW1 + NLAT
IW3 = IW2 + NLAT
IW4 = IW3 + 3*IMID*NLAT
c iw2 = iw1+nlat+nlat
c iw3 = iw2+nlat+nlat
c iw4 = iw3+6*imid*nlat
CALL DVHGSI1(NLAT,IMID,WVHSGS(JW1),WVHSGS(JW2),DWORK(IW1),
+ DWORK(IW2),DWORK(IW3),DWORK(IW4))
CALL DHRFFTI(NLON,WVHSGS(JW3))
RETURN
END
SUBROUTINE DVHGSI1(NLAT,IMID,VB,WB,DTHET,DWTS,DPBAR,WORK)
DOUBLE PRECISION VB
DOUBLE PRECISION WB
DIMENSION VB(IMID,*),WB(IMID,*)
C*PT*WARNING* Already double-precision
DOUBLE PRECISION ABEL,BBEL,CBEL,SSQR2,DCF
C*PT*WARNING* Already double-precision
DOUBLE PRECISION DTHET(*),DWTS(*),DPBAR(IMID,NLAT,3),WORK(*)
C*PT*WARNING* Already double-precision
DOUBLE PRECISION DN,DM
c
c compute gauss points and weights
c use dpbar (length 3*nnlat*(nnlat+1)) as work space for gaqd
c
LWK = NLAT* (NLAT+2)
CALL DGAQD(NLAT,DTHET,DWTS,DPBAR,LWK,IERROR)
C*PT*WARNING* Constant already double-precision
c
c compute associated legendre functions
c
c compute m=n=0 legendre polynomials for all theta(i)
c
SSQR2 = 1.D0/DSQRT(2.d0)
DO 90 I = 1,IMID
DPBAR(I,1,1) = SSQR2
VB(I,1) = 0.D0
WB(I,1) = 0.D0
90 CONTINUE
c
c main loop for remaining vb, and wb
c
DO 100 N = 1,NLAT - 1
C*PT*WARNING* Already double-precision (DBLE)
DN = DBLE(N)
NM = MOD(N-2,3) + 1
NZ = MOD(N-1,3) + 1
NP = MOD(N,3) + 1
c
c compute dpbar for m=0
c
CALL DDNLFK(0,N,WORK)
MN = INDX(0,N,NLAT)
DO 105 I = 1,IMID
CALL DDNLFT(0,N,DTHET(I),WORK,DPBAR(I,1,NP))
c pbar(i,mn) = dpbar(i,1,np)
105 CONTINUE
c
c compute dpbar for m=1
c
CALL DDNLFK(1,N,WORK)
MN = INDX(1,N,NLAT)
DO 106 I = 1,IMID
CALL DDNLFT(1,N,DTHET(I),WORK,DPBAR(I,2,NP))
c pbar(i,mn) = dpbar(i,2,np)
106 CONTINUE
104 CONTINUE
c
c compute and store dpbar for m=2,n
c
IF (N.LT.2) GO TO 108
DO 107 M = 2,N
C*PT*WARNING* Already double-precision (DBLE)
DM = DBLE(M)
ABEL = DSQRT(((2*DN+1)* (DM+DN-2)* (DM+DN-3))/
+ ((2*DN-3)* (DM+DN-1)* (DM+DN)))
BBEL = DSQRT(((2*DN+1)* (DN-DM-1)* (DN-DM))/
+ ((2*DN-3)* (DM+DN-1)* (DM+DN)))
CBEL = DSQRT(((DN-DM+1)* (DN-DM+2))/ ((DM+DN-1)* (DM+DN)))
ID = INDX(M,N,NLAT)
IF (M.GE.N-1) GO TO 102
DO 103 I = 1,IMID
DPBAR(I,M+1,NP) = ABEL*DPBAR(I,M-1,NM) +
+ BBEL*DPBAR(I,M+1,NM) -
+ CBEL*DPBAR(I,M-1,NP)
c pbar(i,id) = dpbar(i,m+1,np)
103 CONTINUE
GO TO 107
102 DO 101 I = 1,IMID
DPBAR(I,M+1,NP) = ABEL*DPBAR(I,M-1,NM) -
+ CBEL*DPBAR(I,M-1,NP)
c pbar(i,id) = dpbar(i,m+1,np)
101 CONTINUE
107 CONTINUE
c
c compute the derivative of the functions
c
108 IX = INDX(0,N,NLAT)
IY = INDX(N,N,NLAT)
DO 125 I = 1,IMID
VB(I,IX) = -DPBAR(I,2,NP)
VB(I,IY) = DPBAR(I,N,NP)/DSQRT(2* (DN+1))
125 CONTINUE
c
IF (N.EQ.1) GO TO 131
DCF = DSQRT(4*DN* (DN+1))
DO 130 M = 1,N - 1
DM = DBLE(M)
IX = INDX(M,N,NLAT)
ABEL = DSQRT((DN+DM)* (DN-DM+1))/DCF
BBEL = DSQRT((DN-DM)* (DN+DM+1))/DCF
DO 130 I = 1,IMID
VB(I,IX) = ABEL*DPBAR(I,M,NP) - BBEL*DPBAR(I,M+2,NP)
130 CONTINUE
c
c compute the vector harmonic w(theta) = m*pbar/cos(theta)
c
c set wb=0 for m=0
c
131 IX = INDX(0,N,NLAT)
DO 220 I = 1,IMID
C*PT*WARNING* Constant already double-precision
WB(I,IX) = 0.d0
220 CONTINUE
c
c compute wb for m=1,n
c
DCF = DSQRT((DN+DN+1)/ (4*DN* (DN+1)* (DN+DN-1)))
DO 230 M = 1,N
DM = DBLE(M)
IX = INDX(M,N,NLAT)
ABEL = DCF*DSQRT((DN+DM)* (DN+DM-1))
BBEL = DCF*DSQRT((DN-DM)* (DN-DM-1))
IF (M.GE.N-1) GO TO 231
DO 229 I = 1,IMID
WB(I,IX) = ABEL*DPBAR(I,M,NZ) + BBEL*DPBAR(I,M+2,NZ)
229 CONTINUE
GO TO 230
231 DO 228 I = 1,IMID
WB(I,IX) = ABEL*DPBAR(I,M,NZ)
228 CONTINUE
230 CONTINUE
100 CONTINUE
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/sphere3.1_dp/vrtec.f | 1 | 12833 | c
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c . .
c . copyright (c) 1998 by UCAR .
c . .
c . University Corporation for Atmospheric Research .
c . .
c . all rights reserved .
c . .
c . .
c . SPHEREPACK .
c . .
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c
c
c
c
c ... file vrtec.f
c
c this file includes documentation and code for
c subroutine divec i
c
c ... files which must be loaded with vrtec.f
c
c sphcom.f, hrfft.f, vhaec.f,shsec.f
c
c subroutine vrtec(nlat,nlon,isym,nt,vt,ivrt,jvrt,cr,ci,mdc,ndc,
c + wshsec,lshsec,work,lwork,ierror)
c
C*PL*ERROR* Comment line too long
c given the vector spherical harmonic coefficients cr and ci, precomputed
c by subroutine vhaec for a vector field (v,w), subroutine vrtec
c computes the vorticity of the vector field in the scalar array
c vt. vt(i,j) is the vorticity at the colatitude
c
c theta(i) = (i-1)*pi/(nlat-1)
c
c and longitude
c
c lambda(j) = (j-1)*2*pi/nlon
c
c on the sphere. i.e.,
c
c vt(i,j) = [-dv/dlambda + d(sint*w)/dtheta]/sint
c
c where sint = sin(theta(i)). w is the east longitudinal and v
c is the colatitudinal component of the vector field from which
c cr,ci were precomputed. required associated legendre polynomials
c are recomputed rather than stored as they are in subroutine vrtes.
c
c
c input parameters
c
c nlat the number of colatitudes on the full sphere including the
c poles. for example, nlat = 37 for a five degree grid.
c nlat determines the grid increment in colatitude as
c pi/(nlat-1). if nlat is odd the equator is located at
c grid point i=(nlat+1)/2. if nlat is even the equator is
c located half way between points i=nlat/2 and i=nlat/2+1.
c nlat must be at least 3. note: on the half sphere, the
c number of grid points in the colatitudinal direction is
c nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.
c
c nlon the number of distinct londitude points. nlon determines
c the grid increment in longitude as 2*pi/nlon. for example
c nlon = 72 for a five degree grid. nlon must be greater
c than 3. the axisymmetric case corresponds to nlon=1.
c the efficiency of the computation is improved when nlon
c is a product of small prime numbers.
c
c
c isym a parameter which determines whether the vorticity is
c computed on the full or half sphere as follows:
c
c = 0
c the symmetries/antsymmetries described in isym=1,2 below
c do not exist in (v,w) about the equator. in this case the
c vorticity is neither symmetric nor antisymmetric about
c the equator. the vorticity is computed on the entire
c sphere. i.e., in the array vt(i,j) for i=1,...,nlat and
c j=1,...,nlon.
c
c = 1
c w is antisymmetric and v is symmetric about the equator.
c in this case the vorticity is symmetyric about the
c equator and is computed for the northern hemisphere
c only. i.e., if nlat is odd the vorticity is computed
c in the array vt(i,j) for i=1,...,(nlat+1)/2 and for
c j=1,...,nlon. if nlat is even the vorticity is computed
c in the array vt(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c = 2
c w is symmetric and v is antisymmetric about the equator
c in this case the vorticity is antisymmetric about the
c equator and is computed for the northern hemisphere
c only. i.e., if nlat is odd the vorticity is computed
c in the array vt(i,j) for i=1,...,(nlat+1)/2 and for
c j=1,...,nlon. if nlat is even the vorticity is computed
c in the array vt(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c
c nt nt is the number of scalar and vector fields. some
c computational efficiency is obtained for multiple fields.
c in the program that calls vrtec, the arrays cr,ci, and vort
C*PL*ERROR* Comment line too long
c can be three dimensional corresponding to an indexed multiple
c vector field. in this case multiple scalar synthesis will
c be performed to compute the vorticity for each field. the
c third index is the synthesis index which assumes the values
c k=1,...,nt. for a single synthesis set nt = 1. the
c description of the remaining parameters is simplified by
C*PL*ERROR* Comment line too long
c assuming that nt=1 or that all the arrays are two dimensional.
c
c ivrt the first dimension of the array vt as it appears in
c the program that calls vrtec. if isym = 0 then ivrt
c must be at least nlat. if isym = 1 or 2 and nlat is
c even then ivrt must be at least nlat/2. if isym = 1 or 2
c and nlat is odd then ivrt must be at least (nlat+1)/2.
c
c jvrt the second dimension of the array vt as it appears in
c the program that calls vrtec. jvrt must be at least nlon.
c
c cr,ci two or three dimensional arrays (see input parameter nt)
c that contain vector spherical harmonic coefficients
c of the vector field (v,w) as computed by subroutine vhaec.
c *** cr and ci must be computed by vhaec prior to calling
c vrtec.
c
c mdc the first dimension of the arrays cr and ci as it
c appears in the program that calls vrtec. mdc must be at
c least min0(nlat,nlon/2) if nlon is even or at least
c min0(nlat,(nlon+1)/2) if nlon is odd.
c
c ndc the second dimension of the arrays cr and ci as it
c appears in the program that calls vrtec. ndc must be at
c least nlat.
c
c wshsec an array which must be initialized by subroutine shseci.
c once initialized,
c wshsec can be used repeatedly by vrtec as long as nlon
c and nlat remain unchanged. wshsec must not be altered
c between calls of vrtec
c
c lshsec the dimension of the array wshsec as it appears in the
c program that calls vrtec. define
c
c l1 = min0(nlat,(nlon+2)/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c then lshsec must be at least
c
c 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15
c
c work a work array that does not have to be saved.
c
c lwork the dimension of the array work as it appears in the
c program that calls vrtec. define
c
c l1 = min0(nlat,nlon/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd.
c
c if isym is zero then lwork must be at least
c
c nlat*(nt*nlon+max0(3*l2,nlon)+2*nt*l1+1)
c
c if isym is not zero then lwork must be at least
c
c l2*(nt*nlon+max0(3*nlat,nlon)) + nlat*(2*nt*l1+1)
c
c
c
c **************************************************************
c
c output parameters
c
c
c vt a two or three dimensional array (see input parameter nt)
c that contains the vorticity of the vector field (v,w)
C*PL*ERROR* Comment line too long
c whose coefficients cr,ci where computed by subroutine vhaec.
c vt(i,j) is the vorticity at the colatitude point theta(i) =
c (i-1)*pi/(nlat-1) and longitude point lambda(j) =
c (j-1)*2*pi/nlon. the index ranges are defined above at the
c input parameter isym.
c
c
c ierror an error parameter which indicates fatal errors with input
c parameters when returned positive.
c = 0 no errors
c = 1 error in the specification of nlat
c = 2 error in the specification of nlon
c = 3 error in the specification of isym
c = 4 error in the specification of nt
c = 5 error in the specification of ivrt
c = 6 error in the specification of jvrt
c = 7 error in the specification of mdc
c = 8 error in the specification of ndc
c = 9 error in the specification of lshsec
c = 10 error in the specification of lwork
c **********************************************************************
c
c
SUBROUTINE DVRTEC(NLAT,NLON,ISYM,NT,VORT,IVRT,JVRT,CR,CI,MDC,NDC,
+ WSHSEC,LSHSEC,WORK,LWORK,IERROR)
DOUBLE PRECISION VORT
DOUBLE PRECISION CR
DOUBLE PRECISION CI
DOUBLE PRECISION WSHSEC
DOUBLE PRECISION WORK
DIMENSION VORT(IVRT,JVRT,NT),CR(MDC,NDC,NT),CI(MDC,NDC,NT)
DIMENSION WSHSEC(LSHSEC),WORK(LWORK)
c
c check input parameters
c
IERROR = 1
IF (NLAT.LT.3) RETURN
IERROR = 2
IF (NLON.LT.4) RETURN
IERROR = 3
IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN
IERROR = 4
IF (NT.LT.0) RETURN
IERROR = 5
IMID = (NLAT+1)/2
IF ((ISYM.EQ.0.AND.IVRT.LT.NLAT) .OR.
+ (ISYM.GT.0.AND.IVRT.LT.IMID)) RETURN
IERROR = 6
IF (JVRT.LT.NLON) RETURN
IERROR = 7
IF (MDC.LT.MIN0(NLAT, (NLON+1)/2)) RETURN
MMAX = MIN0(NLAT, (NLON+2)/2)
IERROR = 8
IF (NDC.LT.NLAT) RETURN
IERROR = 9
c
c verify saved work space (same as shec)
c
LZZ1 = 2*NLAT*IMID
LABC = 3* (MAX0(MMAX-2,0)* (NLAT+NLAT-MMAX-1))/2
IF (LSHSEC.LT.LZZ1+LABC+NLON+15) RETURN
IERROR = 10
c
c verify unsaved work space (add to what shec requires)
c
LS = NLAT
IF (ISYM.GT.0) LS = IMID
NLN = NT*LS*NLON
c
c set first dimension for a,b (as requried by shsec)
c
MAB = MIN0(NLAT,NLON/2+1)
MN = MAB*NLAT*NT
c if(lwork.lt.nln+max0(ls*nlon,3*nlat*imid)+2*mn+nlat) return
L1 = MIN0(NLAT, (NLON+2)/2)
L2 = (NLAT+1)/2
IF (ISYM.EQ.0) THEN
LWKMIN = NLAT* (NT*NLON+MAX0(3*L2,NLON)+2*NT*L1+1)
ELSE
LWKMIN = L2* (NT*NLON+MAX0(3*NLAT,NLON)) + NLAT* (2*NT*L1+1)
END IF
IF (LWORK.LT.LWKMIN) RETURN
IERROR = 0
c
c set work space pointers
c
IA = 1
IB = IA + MN
IS = IB + MN
IWK = IS + NLAT
LWK = LWORK - 2*MN - NLAT
CALL DVRTEC1(NLAT,NLON,ISYM,NT,VORT,IVRT,JVRT,CR,CI,MDC,NDC,
+ WORK(IA),WORK(IB),MAB,WORK(IS),WSHSEC,LSHSEC,
+ WORK(IWK),LWK,IERROR)
RETURN
END
SUBROUTINE DVRTEC1(NLAT,NLON,ISYM,NT,VORT,IVRT,JVRT,CR,CI,MDC,NDC,
+ A,B,MAB,SQNN,WSHSEC,LSHSEC,WK,LWK,IERROR)
DOUBLE PRECISION VORT
DOUBLE PRECISION CR
DOUBLE PRECISION CI
DOUBLE PRECISION A
DOUBLE PRECISION B
DOUBLE PRECISION SQNN
DOUBLE PRECISION WSHSEC
DOUBLE PRECISION WK
DOUBLE PRECISION FN
DIMENSION VORT(IVRT,JVRT,NT),CR(MDC,NDC,NT),CI(MDC,NDC,NT)
DIMENSION A(MAB,NLAT,NT),B(MAB,NLAT,NT),SQNN(NLAT)
DIMENSION WSHSEC(LSHSEC),WK(LWK)
c
c set coefficient multiplyers
c
DO 1 N = 2,NLAT
FN = DBLE(N-1)
SQNN(N) = SQRT(FN* (FN+1.D0))
1 CONTINUE
c
c compute vorticity scalar coefficients for each vector field
c
DO 2 K = 1,NT
DO 3 N = 1,NLAT
DO 4 M = 1,MAB
A(M,N,K) = 0.0D0
B(M,N,K) = 0.0D0
4 CONTINUE
3 CONTINUE
c
c compute m=0 coefficients
c
DO 5 N = 2,NLAT
A(1,N,K) = SQNN(N)*CR(1,N,K)
B(1,N,K) = SQNN(N)*CI(1,N,K)
5 CONTINUE
c
c compute m>0 coefficients, use mmax from vector coef range
c
MMAX = MIN0(NLAT, (NLON+1)/2)
DO 6 M = 2,MMAX
DO 7 N = M,NLAT
A(M,N,K) = SQNN(N)*CR(M,N,K)
B(M,N,K) = SQNN(N)*CI(M,N,K)
7 CONTINUE
6 CONTINUE
2 CONTINUE
c
c synthesize a,b into vort
c
CALL DSHSEC(NLAT,NLON,ISYM,NT,VORT,IVRT,JVRT,A,B,MAB,NLAT,WSHSEC,
+ LSHSEC,WK,LWK,IERROR)
RETURN
END
| gpl-2.0 |
FRidh/scipy | scipy/special/amos/dgamln.f | 178 | 8597 | DOUBLE PRECISION FUNCTION DGAMLN(Z,IERR)
C***BEGIN PROLOGUE DGAMLN
C***DATE WRITTEN 830501 (YYMMDD)
C***REVISION DATE 830501 (YYMMDD)
C***CATEGORY NO. B5F
C***KEYWORDS GAMMA FUNCTION,LOGARITHM OF GAMMA FUNCTION
C***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C***PURPOSE TO COMPUTE THE LOGARITHM OF THE GAMMA FUNCTION
C***DESCRIPTION
C
C **** A DOUBLE PRECISION ROUTINE ****
C DGAMLN COMPUTES THE NATURAL LOG OF THE GAMMA FUNCTION FOR
C Z.GT.0. THE ASYMPTOTIC EXPANSION IS USED TO GENERATE VALUES
C GREATER THAN ZMIN WHICH ARE ADJUSTED BY THE RECURSION
C G(Z+1)=Z*G(Z) FOR Z.LE.ZMIN. THE FUNCTION WAS MADE AS
C PORTABLE AS POSSIBLE BY COMPUTIMG ZMIN FROM THE NUMBER OF BASE
C 10 DIGITS IN A WORD, RLN=AMAX1(-ALOG10(R1MACH(4)),0.5E-18)
C LIMITED TO 18 DIGITS OF (RELATIVE) ACCURACY.
C
C SINCE INTEGER ARGUMENTS ARE COMMON, A TABLE LOOK UP ON 100
C VALUES IS USED FOR SPEED OF EXECUTION.
C
C DESCRIPTION OF ARGUMENTS
C
C INPUT Z IS D0UBLE PRECISION
C Z - ARGUMENT, Z.GT.0.0D0
C
C OUTPUT DGAMLN IS DOUBLE PRECISION
C DGAMLN - NATURAL LOG OF THE GAMMA FUNCTION AT Z.NE.0.0D0
C IERR - ERROR FLAG
C IERR=0, NORMAL RETURN, COMPUTATION COMPLETED
C IERR=1, Z.LE.0.0D0, NO COMPUTATION
C
C
C***REFERENCES COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C BY D. E. AMOS, SAND83-0083, MAY, 1983.
C***ROUTINES CALLED I1MACH,D1MACH
C***END PROLOGUE DGAMLN
DOUBLE PRECISION CF, CON, FLN, FZ, GLN, RLN, S, TLG, TRM, TST,
* T1, WDTOL, Z, ZDMY, ZINC, ZM, ZMIN, ZP, ZSQ, D1MACH
INTEGER I, IERR, I1M, K, MZ, NZ, I1MACH
DIMENSION CF(22), GLN(100)
C LNGAMMA(N), N=1,100
DATA GLN(1), GLN(2), GLN(3), GLN(4), GLN(5), GLN(6), GLN(7),
1 GLN(8), GLN(9), GLN(10), GLN(11), GLN(12), GLN(13), GLN(14),
2 GLN(15), GLN(16), GLN(17), GLN(18), GLN(19), GLN(20),
3 GLN(21), GLN(22)/
4 0.00000000000000000D+00, 0.00000000000000000D+00,
5 6.93147180559945309D-01, 1.79175946922805500D+00,
6 3.17805383034794562D+00, 4.78749174278204599D+00,
7 6.57925121201010100D+00, 8.52516136106541430D+00,
8 1.06046029027452502D+01, 1.28018274800814696D+01,
9 1.51044125730755153D+01, 1.75023078458738858D+01,
A 1.99872144956618861D+01, 2.25521638531234229D+01,
B 2.51912211827386815D+01, 2.78992713838408916D+01,
C 3.06718601060806728D+01, 3.35050734501368889D+01,
D 3.63954452080330536D+01, 3.93398841871994940D+01,
E 4.23356164607534850D+01, 4.53801388984769080D+01/
DATA GLN(23), GLN(24), GLN(25), GLN(26), GLN(27), GLN(28),
1 GLN(29), GLN(30), GLN(31), GLN(32), GLN(33), GLN(34),
2 GLN(35), GLN(36), GLN(37), GLN(38), GLN(39), GLN(40),
3 GLN(41), GLN(42), GLN(43), GLN(44)/
4 4.84711813518352239D+01, 5.16066755677643736D+01,
5 5.47847293981123192D+01, 5.80036052229805199D+01,
6 6.12617017610020020D+01, 6.45575386270063311D+01,
7 6.78897431371815350D+01, 7.12570389671680090D+01,
8 7.46582363488301644D+01, 7.80922235533153106D+01,
9 8.15579594561150372D+01, 8.50544670175815174D+01,
A 8.85808275421976788D+01, 9.21361756036870925D+01,
B 9.57196945421432025D+01, 9.93306124547874269D+01,
C 1.02968198614513813D+02, 1.06631760260643459D+02,
D 1.10320639714757395D+02, 1.14034211781461703D+02,
E 1.17771881399745072D+02, 1.21533081515438634D+02/
DATA GLN(45), GLN(46), GLN(47), GLN(48), GLN(49), GLN(50),
1 GLN(51), GLN(52), GLN(53), GLN(54), GLN(55), GLN(56),
2 GLN(57), GLN(58), GLN(59), GLN(60), GLN(61), GLN(62),
3 GLN(63), GLN(64), GLN(65), GLN(66)/
4 1.25317271149356895D+02, 1.29123933639127215D+02,
5 1.32952575035616310D+02, 1.36802722637326368D+02,
6 1.40673923648234259D+02, 1.44565743946344886D+02,
7 1.48477766951773032D+02, 1.52409592584497358D+02,
8 1.56360836303078785D+02, 1.60331128216630907D+02,
9 1.64320112263195181D+02, 1.68327445448427652D+02,
A 1.72352797139162802D+02, 1.76395848406997352D+02,
B 1.80456291417543771D+02, 1.84533828861449491D+02,
C 1.88628173423671591D+02, 1.92739047287844902D+02,
D 1.96866181672889994D+02, 2.01009316399281527D+02,
E 2.05168199482641199D+02, 2.09342586752536836D+02/
DATA GLN(67), GLN(68), GLN(69), GLN(70), GLN(71), GLN(72),
1 GLN(73), GLN(74), GLN(75), GLN(76), GLN(77), GLN(78),
2 GLN(79), GLN(80), GLN(81), GLN(82), GLN(83), GLN(84),
3 GLN(85), GLN(86), GLN(87), GLN(88)/
4 2.13532241494563261D+02, 2.17736934113954227D+02,
5 2.21956441819130334D+02, 2.26190548323727593D+02,
6 2.30439043565776952D+02, 2.34701723442818268D+02,
7 2.38978389561834323D+02, 2.43268849002982714D+02,
8 2.47572914096186884D+02, 2.51890402209723194D+02,
9 2.56221135550009525D+02, 2.60564940971863209D+02,
A 2.64921649798552801D+02, 2.69291097651019823D+02,
B 2.73673124285693704D+02, 2.78067573440366143D+02,
C 2.82474292687630396D+02, 2.86893133295426994D+02,
D 2.91323950094270308D+02, 2.95766601350760624D+02,
E 3.00220948647014132D+02, 3.04686856765668715D+02/
DATA GLN(89), GLN(90), GLN(91), GLN(92), GLN(93), GLN(94),
1 GLN(95), GLN(96), GLN(97), GLN(98), GLN(99), GLN(100)/
2 3.09164193580146922D+02, 3.13652829949879062D+02,
3 3.18152639620209327D+02, 3.22663499126726177D+02,
4 3.27185287703775217D+02, 3.31717887196928473D+02,
5 3.36261181979198477D+02, 3.40815058870799018D+02,
6 3.45379407062266854D+02, 3.49954118040770237D+02,
7 3.54539085519440809D+02, 3.59134205369575399D+02/
C COEFFICIENTS OF ASYMPTOTIC EXPANSION
DATA CF(1), CF(2), CF(3), CF(4), CF(5), CF(6), CF(7), CF(8),
1 CF(9), CF(10), CF(11), CF(12), CF(13), CF(14), CF(15),
2 CF(16), CF(17), CF(18), CF(19), CF(20), CF(21), CF(22)/
3 8.33333333333333333D-02, -2.77777777777777778D-03,
4 7.93650793650793651D-04, -5.95238095238095238D-04,
5 8.41750841750841751D-04, -1.91752691752691753D-03,
6 6.41025641025641026D-03, -2.95506535947712418D-02,
7 1.79644372368830573D-01, -1.39243221690590112D+00,
8 1.34028640441683920D+01, -1.56848284626002017D+02,
9 2.19310333333333333D+03, -3.61087712537249894D+04,
A 6.91472268851313067D+05, -1.52382215394074162D+07,
B 3.82900751391414141D+08, -1.08822660357843911D+10,
C 3.47320283765002252D+11, -1.23696021422692745D+13,
D 4.88788064793079335D+14, -2.13203339609193739D+16/
C
C LN(2*PI)
DATA CON / 1.83787706640934548D+00/
C
C***FIRST EXECUTABLE STATEMENT DGAMLN
IERR=0
IF (Z.LE.0.0D0) GO TO 70
IF (Z.GT.101.0D0) GO TO 10
NZ = INT(SNGL(Z))
FZ = Z - FLOAT(NZ)
IF (FZ.GT.0.0D0) GO TO 10
IF (NZ.GT.100) GO TO 10
DGAMLN = GLN(NZ)
RETURN
10 CONTINUE
WDTOL = D1MACH(4)
WDTOL = DMAX1(WDTOL,0.5D-18)
I1M = I1MACH(14)
RLN = D1MACH(5)*FLOAT(I1M)
FLN = DMIN1(RLN,20.0D0)
FLN = DMAX1(FLN,3.0D0)
FLN = FLN - 3.0D0
ZM = 1.8000D0 + 0.3875D0*FLN
MZ = INT(SNGL(ZM)) + 1
ZMIN = FLOAT(MZ)
ZDMY = Z
ZINC = 0.0D0
IF (Z.GE.ZMIN) GO TO 20
ZINC = ZMIN - FLOAT(NZ)
ZDMY = Z + ZINC
20 CONTINUE
ZP = 1.0D0/ZDMY
T1 = CF(1)*ZP
S = T1
IF (ZP.LT.WDTOL) GO TO 40
ZSQ = ZP*ZP
TST = T1*WDTOL
DO 30 K=2,22
ZP = ZP*ZSQ
TRM = CF(K)*ZP
IF (DABS(TRM).LT.TST) GO TO 40
S = S + TRM
30 CONTINUE
40 CONTINUE
IF (ZINC.NE.0.0D0) GO TO 50
TLG = DLOG(Z)
DGAMLN = Z*(TLG-1.0D0) + 0.5D0*(CON-TLG) + S
RETURN
50 CONTINUE
ZP = 1.0D0
NZ = INT(SNGL(ZINC))
DO 60 I=1,NZ
ZP = ZP*(Z+FLOAT(I-1))
60 CONTINUE
TLG = DLOG(ZDMY)
DGAMLN = ZDMY*(TLG-1.0D0) - DLOG(ZP) + 0.5D0*(CON-TLG) + S
RETURN
C
C
70 CONTINUE
IERR=1
RETURN
END
| bsd-3-clause |
marshallward/mom | src/ice_sis/mask.F90 | 11 | 4147 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!
! mask_mod reads the land/sea mask from netCDF file - Mike Winton (Michael.Winton)!
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!
module mask_mod
use rot_mod, only: rot_intrp_sclr
use fms_mod, only: error_mesg, FATAL
implicit none
include 'netcdf.inc'
private
public :: lonb, latb, mask, lonb_uv, latb_uv, mask_uv, make_mask
real, allocatable, dimension(: ) :: lonb, latb, lonb_uv, latb_uv
logical, allocatable, dimension(:,:) :: mask, mask_uv
real, allocatable, dimension(:,:) :: rmask
contains
!
! make_v_grid - makes B-grid longitudes, latitudes and mask for velocity-cells
!
subroutine make_v_grid(mask_t, mask_v, lon_t, lat_t, lon_v, lat_v)
logical, dimension (:,:), intent(in ) :: mask_t
logical, dimension (size(mask_t,1),size(mask_t,2)) :: mask_v
real, dimension (size(mask_t,1)+1), intent(in ) :: lon_t
real, dimension (size(mask_t,2)+1), intent(in ) :: lat_t
real, dimension (size(lon_t(:))) :: lon_v
real, dimension (size(lat_t(:))) :: lat_v
integer, dimension(size(mask_t,1)) :: wes
integer, dimension(size(mask_t,2)) :: sou
integer i,j
real, dimension(size(mask_t,1)) :: lon_tmp
real pi
sou = (/(j,j=1,size(sou(:)))/); wes = (/(i,i=1,size(wes(:)))/)
sou = cshift(sou, -1) ; wes = cshift(wes, -1)
mask_v = mask_t(:,:) .and. mask_t(wes,:) .and. &
mask_t(:,sou) .and. mask_t(wes,sou)
pi = 4*atan(1.0)
lon_tmp = lon_t(1:size(lon_tmp(:)))
lon_tmp = lon_tmp-0.5*mod(lon_tmp+2*pi-cshift(lon_tmp,-1),2*pi)
lon_v(1:size(lon_tmp(:))) = lon_tmp
lon_v(size(lon_v(:))) = lon_v(1)
lat_v = (lat_t+cshift(lat_t,-1))/2
lat_v(1) = lat_t(1) ! southernmost velocities not computed anyway
end subroutine make_v_grid
subroutine make_mask(lon_start, lon_end, lon_incr, lat_start, lat_end, lat_incr)
real :: lon_start, lon_end, lon_incr, lat_start, lat_end, lat_incr
integer :: dims(4), start(4), count(4), rcode
integer :: i, j, id, jd, im, jm
integer :: ncid, varid, xv_id, yv_id
real :: pi
real, dimension(: ), allocatable :: xd, yd, xt, yt
real, dimension(:,:), allocatable :: map
pi = 4*atan(1.0)
rcode = nf_open('INPUT/map.nc',0,ncid)
if (rcode/=0) call error_mesg ('mask_mod', &
'cannot open INPUT/map.nc', FATAL)
rcode = nf_inq_varid(ncid, 'MAP', varid)
rcode = nf_inq_vardimid(ncid, varid, dims)
rcode = nf_inq_dimlen(ncid, dims(1), id)
rcode = nf_inq_dimlen(ncid, dims(2), jd)
allocate(xd(id), yd(jd), map(id,jd))
start = 1; count = 1; count(1) = id;
rcode = nf_get_vara_double(ncid, dims(1), start, count, xd)
start = 1; count = 1; count(1) = jd;
rcode = nf_get_vara_double(ncid, dims(2), start, count, yd)
start = 1; count = 1; count(1) = id; count(2) = jd;
rcode = nf_get_vara_double(ncid, varid, start, count, map)
im = nint((lon_end-lon_start)/lon_incr)
jm = nint((lat_end-lat_start)/lat_incr)
allocate(rmask(im,jm), mask(im,jm), mask_uv(im,jm), xt(im), yt(jm) )
allocate(lonb(im+1), lonb_uv(im+1), latb(jm+1), latb_uv(jm+1))
xt = lon_start+(/(i-0.5,i=1,im)/)*lon_incr
yt = lat_start+(/(j-0.5,j=1,jm)/)*lat_incr
if (maxval(abs(yt))<45.0) then ! rotate poles onto equator
call rot_intrp_sclr(map, xd, yd, id, jd, rmask, xt, yt, size(xt(:)), &
size(yt(:)), 2*atan(1.0), -2*atan(1.0), atan(1.0) )
else
call rot_intrp_sclr(map, xd, yd, id, jd, rmask, xt, yt, size(xt(:)), &
size(yt(:)), 0.0, 0.0, 0.0 )
endif
deallocate(map, xd, yd, xt, yt)
lonb = (lon_start+(/(i,i=0,im)/)*lon_incr)*pi/180
latb = (lat_start+(/(j,j=0,jm)/)*lat_incr)*pi/180
mask = rmask > 0.5
call make_v_grid(mask, mask_uv, lonb, latb, lonb_uv, latb_uv)
end subroutine make_mask
end module mask_mod
| gpl-2.0 |
marshallward/mom | src/atmos_spectral/tools/spec_mpp.F90 | 10 | 5361 | module spec_mpp_mod
!Balaji (V.Balaji)
!This module holds the data for the domains used by the spectral transform module
!This is the version for the transpose method
use fms_mod, only: mpp_pe, mpp_root_pe, mpp_npes, write_version_number, mpp_error, FATAL
use mpp_domains_mod, only: mpp_domains_init, domain1D, domain2D, GLOBAL_DATA_DOMAIN, &
mpp_define_domains, mpp_get_compute_domain, mpp_get_compute_domains, &
mpp_get_domain_components, mpp_get_pelist
implicit none
private
character(len=128), private :: version = '$Id: spec_mpp.F90,v 14.0 2007/03/15 22:12:44 fms Exp $'
character(len=128), private :: tagname = '$Name: tikal $'
type(domain2D), save, public :: grid_domain, spectral_domain, global_spectral_domain
logical, private :: module_is_initialized=.FALSE.
integer, private :: pe, npes
public :: spec_mpp_init, get_grid_domain, get_spec_domain, spec_mpp_end, atmosphere_domain
contains
!=======================================================================================================================
subroutine spec_mpp_init( num_fourier, num_spherical, num_lon, lat_max, grid_layout, spectral_layout )
integer, intent(in) :: num_fourier, num_spherical, num_lon, lat_max
integer, intent(in), optional :: grid_layout(2), spectral_layout(2)
integer :: layout(2)
character(len=4) :: chtmp1, chtmp2
if( module_is_initialized ) return
call mpp_domains_init()
pe = mpp_pe()
npes = mpp_npes()
call write_version_number(version, tagname)
!grid domain: by default, 1D decomposition along Y
layout = (/1,npes/)
if( PRESENT(grid_layout) ) layout = grid_layout
call mpp_define_domains( (/1,num_lon,1,lat_max/), layout, grid_domain )
if(pe == mpp_root_pe()) call print_decomp (npes, layout, grid_domain )
!requirement of equal domains: can be generalized to retain mirror symmetry between N/S if unequal.
!the equal-domains requirement permits us to eliminate one buffer/unbuffer in the transpose_fourier routines.
if( mod(lat_max,layout(2)).NE.0 ) then
! call mpp_error( FATAL, 'SPEC_MPP_INIT: currently requires equal grid domains on all PEs.' )
write(chtmp1,'(i4)') layout(2)
write(chtmp2,'(i4)') lat_max
call mpp_error( FATAL, 'SPEC_MPP_INIT:Requires num_lat_rows/num_pes=int;num_pes='&
&//chtmp1//';num_lat_rows='//chtmp2 )
endif
!spectral domain: by default, 1D decomposition along M
layout=(/npes,1/)
if( PRESENT(spectral_layout) ) layout = spectral_layout
call mpp_define_domains( (/0,num_fourier,0,num_spherical/), layout, spectral_domain )
!global spectral domains (may be used for I/O) are the same as spectral domains, with global data boundaries
call mpp_define_domains( (/0,num_fourier,0,num_spherical/), layout, global_spectral_domain, &
xflags=GLOBAL_DATA_DOMAIN, yflags=GLOBAL_DATA_DOMAIN )
module_is_initialized=.TRUE.
return
end subroutine spec_mpp_init
!=======================================================================================================================
subroutine print_decomp (npes, layout, Domain)
integer, intent(in) :: npes, layout(2)
type(domain2d), intent(in) :: Domain
integer, dimension(0:npes-1) :: xsize, ysize
integer :: i, j, xlist(layout(1)), ylist(layout(2))
type (domain1D) :: Xdom, Ydom
call mpp_get_compute_domains ( Domain, xsize=xsize, ysize=ysize )
call mpp_get_domain_components ( Domain, Xdom, Ydom )
call mpp_get_pelist ( Xdom, xlist )
call mpp_get_pelist ( Ydom, ylist )
write (*,100)
write (*,110) (xsize(xlist(i)),i=1,layout(1))
write (*,120) (ysize(ylist(j)),j=1,layout(2))
100 format ('ATMOS MODEL DOMAIN DECOMPOSITION')
110 format (' X-AXIS = ',24i4,/,(11x,24i4))
120 format (' Y-AXIS = ',24i4,/,(11x,24i4))
end subroutine print_decomp
!=======================================================================================================================
subroutine get_grid_domain(is, ie, js, je)
integer, intent(out) :: is, ie, js, je
if(.not.module_is_initialized) call mpp_error( FATAL, 'subroutine get_grid_domain: spec_mpp is not initialized')
call mpp_get_compute_domain(grid_domain, is, ie, js, je)
return
end subroutine get_grid_domain
!=======================================================================================================================
subroutine get_spec_domain(ms, me, ns, ne)
integer, intent(out) :: ms, me, ns, ne
if(.not.module_is_initialized) call mpp_error( FATAL, 'subroutine get_spec_domain: spec_mpp is not initialized')
call mpp_get_compute_domain(spectral_domain, ms, me, ns, ne)
return
end subroutine get_spec_domain
!=======================================================================================================================
subroutine spec_mpp_end
module_is_initialized = .false.
return
end subroutine spec_mpp_end
!=======================================================================================================================
subroutine atmosphere_domain(Domain)
type(domain2d), intent(inout) :: Domain
Domain = grid_domain
end subroutine atmosphere_domain
!=======================================================================================================================
end module spec_mpp_mod
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg_gks/bwi/gputps.f | 1 | 3257 | C
C $Id: gputps.f,v 1.7 2008-07-27 00:21:06 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE GPUTPS (BUFFER, COUNT1, COUNT2, CONTIN, GKSERR)
C
C Put a character string into the metafile buffer. This subroutine
C can be called successively to put out long strings--on the
C first call the total count is put out and on subsequent calls
C just the characters are put out.
C
C INPUT
C BUFFER -- The character string to move (must be type CHARACTER).
C COUNT1 -- Total number of characters to be processed for the
C entire sequence.
C COUNT2 -- Number of characters to be processed this call.
C CONTIN -- If 0, COUNT1 is put out prior to the string itself;
C if 1, only the character string is put out.
C OUTPUT
C GKSERR -- Error status.
C
C All data is type integer unless otherwise indicated.
C
IMPLICIT INTEGER (A-Z)
DIMENSION CHARS(256)
CHARACTER*(*) BUFFER
C
INTEGER BITSPC
INTEGER GKASCI
C
include 'g01prm.h'
include 'g01ins.h'
SAVE
C
C Maximum number of characters allowed in the temporary buffer.
C
DATA MXCH/256/
C
C CGM uses 8-bit ASCII.
C
DATA BITSPC/8/, LSFLG/255/
C
C First call processing, set up count (or flag/count).
C
IF (CONTIN .EQ. 0) THEN
C
C The number of bytes for the COUNT+STRING depends on
C whether the string is encoded in the long or short form.
C
IF (COUNT1 .LE. 254) THEN
NBCCNT = 8
ELSE
NBCCNT = 16
CALL GMFLOD (LSFLG, 8, 1, GKSERR)
IF (GKSERR .NE. 0) RETURN
END IF
CALL GMFLOD (COUNT1, NBCCNT, 1, GKSERR)
IF (GKSERR .NE. 0) RETURN
END IF
C
CTEMP = COUNT2
IF (CTEMP .EQ. 0) RETURN
STRT = 1
C
10 CONTINUE
C
C Determine the number of characters that will fit
C in the current partition.
C
WCBYT = 1 + (MCCBYT*8-1)/BITSPC
C
C Compute and move the allowed number of characters.
C
MOVIT = MIN(WCBYT,CTEMP,MXCH)
C
C Move the character codes to the integer buffer.
C
DO 20 II = 1,MOVIT
NP = STRT + II - 1
C
C Get the ASCII equivalent of the character code.
C
CHARS(II) = GKASCI (ICHAR(BUFFER(NP:NP)))
20 CONTINUE
C
CALL GMFLOD (CHARS, BITSPC, MOVIT, GKSERR)
IF (GKSERR .NE. 0) RETURN
C
C Check if another partition has to be started.
C
CTEMP = CTEMP - MOVIT
MCCBYT = MCCBYT - (MOVIT*BITSPC)/8
IF (CTEMP .NE. 0) THEN
C
C Check if more room in partition.
C
IF (MCCBYT .NE. 0) THEN
C
C More room in the current partition.
C
STRT = STRT + MOVIT
ELSE
C
C New partition required, so set up the instruction.
C
STRT = STRT + MOVIT
C Take the remainder of the bytes left in the current partition
C (they must be used).
TCBYT = MCNBYT + MCCBYT
CALL GMPART (TCBYT, GKSERR)
IF (GKSERR .NE. 0) RETURN
END IF
C
C Move more operands into new partition.
C
GO TO 10
END IF
C
RETURN
END
| gpl-2.0 |
jcarlson23/lammps | lib/linalg/dlacn2.f | 7 | 5862 | SUBROUTINE DLACN2( N, V, X, ISGN, EST, KASE, ISAVE )
*
* -- 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 ..
INTEGER KASE, N
DOUBLE PRECISION EST
* ..
* .. Array Arguments ..
INTEGER ISGN( * ), ISAVE( 3 )
DOUBLE PRECISION V( * ), X( * )
* ..
*
* Purpose
* =======
*
* DLACN2 estimates the 1-norm of a square, real matrix A.
* Reverse communication is used for evaluating matrix-vector products.
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix. N >= 1.
*
* V (workspace) DOUBLE PRECISION array, dimension (N)
* On the final return, V = A*W, where EST = norm(V)/norm(W)
* (W is not returned).
*
* X (input/output) DOUBLE PRECISION array, dimension (N)
* On an intermediate return, X should be overwritten by
* A * X, if KASE=1,
* A' * X, if KASE=2,
* and DLACN2 must be re-called with all the other parameters
* unchanged.
*
* ISGN (workspace) INTEGER array, dimension (N)
*
* EST (input/output) DOUBLE PRECISION
* On entry with KASE = 1 or 2 and ISAVE(1) = 3, EST should be
* unchanged from the previous call to DLACN2.
* On exit, EST is an estimate (a lower bound) for norm(A).
*
* KASE (input/output) INTEGER
* On the initial call to DLACN2, KASE should be 0.
* On an intermediate return, KASE will be 1 or 2, indicating
* whether X should be overwritten by A * X or A' * X.
* On the final return from DLACN2, KASE will again be 0.
*
* ISAVE (input/output) INTEGER array, dimension (3)
* ISAVE is used to save variables between calls to DLACN2
*
* Further Details
* ======= =======
*
* Contributed by Nick Higham, University of Manchester.
* Originally named SONEST, dated March 16, 1988.
*
* Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of
* a real or complex matrix, with applications to condition estimation",
* ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988.
*
* This is a thread safe version of DLACON, which uses the array ISAVE
* in place of a SAVE statement, as follows:
*
* DLACON DLACN2
* JUMP ISAVE(1)
* J ISAVE(2)
* ITER ISAVE(3)
*
* =====================================================================
*
* .. Parameters ..
INTEGER ITMAX
PARAMETER ( ITMAX = 5 )
DOUBLE PRECISION ZERO, ONE, TWO
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, JLAST
DOUBLE PRECISION ALTSGN, ESTOLD, TEMP
* ..
* .. External Functions ..
INTEGER IDAMAX
DOUBLE PRECISION DASUM
EXTERNAL IDAMAX, DASUM
* ..
* .. External Subroutines ..
EXTERNAL DCOPY
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, NINT, SIGN
* ..
* .. Executable Statements ..
*
IF( KASE.EQ.0 ) THEN
DO 10 I = 1, N
X( I ) = ONE / DBLE( N )
10 CONTINUE
KASE = 1
ISAVE( 1 ) = 1
RETURN
END IF
*
GO TO ( 20, 40, 70, 110, 140 )ISAVE( 1 )
*
* ................ ENTRY (ISAVE( 1 ) = 1)
* FIRST ITERATION. X HAS BEEN OVERWRITTEN BY A*X.
*
20 CONTINUE
IF( N.EQ.1 ) THEN
V( 1 ) = X( 1 )
EST = ABS( V( 1 ) )
* ... QUIT
GO TO 150
END IF
EST = DASUM( N, X, 1 )
*
DO 30 I = 1, N
X( I ) = SIGN( ONE, X( I ) )
ISGN( I ) = NINT( X( I ) )
30 CONTINUE
KASE = 2
ISAVE( 1 ) = 2
RETURN
*
* ................ ENTRY (ISAVE( 1 ) = 2)
* FIRST ITERATION. X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X.
*
40 CONTINUE
ISAVE( 2 ) = IDAMAX( N, X, 1 )
ISAVE( 3 ) = 2
*
* MAIN LOOP - ITERATIONS 2,3,...,ITMAX.
*
50 CONTINUE
DO 60 I = 1, N
X( I ) = ZERO
60 CONTINUE
X( ISAVE( 2 ) ) = ONE
KASE = 1
ISAVE( 1 ) = 3
RETURN
*
* ................ ENTRY (ISAVE( 1 ) = 3)
* X HAS BEEN OVERWRITTEN BY A*X.
*
70 CONTINUE
CALL DCOPY( N, X, 1, V, 1 )
ESTOLD = EST
EST = DASUM( N, V, 1 )
DO 80 I = 1, N
IF( NINT( SIGN( ONE, X( I ) ) ).NE.ISGN( I ) )
$ GO TO 90
80 CONTINUE
* REPEATED SIGN VECTOR DETECTED, HENCE ALGORITHM HAS CONVERGED.
GO TO 120
*
90 CONTINUE
* TEST FOR CYCLING.
IF( EST.LE.ESTOLD )
$ GO TO 120
*
DO 100 I = 1, N
X( I ) = SIGN( ONE, X( I ) )
ISGN( I ) = NINT( X( I ) )
100 CONTINUE
KASE = 2
ISAVE( 1 ) = 4
RETURN
*
* ................ ENTRY (ISAVE( 1 ) = 4)
* X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X.
*
110 CONTINUE
JLAST = ISAVE( 2 )
ISAVE( 2 ) = IDAMAX( N, X, 1 )
IF( ( X( JLAST ).NE.ABS( X( ISAVE( 2 ) ) ) ) .AND.
$ ( ISAVE( 3 ).LT.ITMAX ) ) THEN
ISAVE( 3 ) = ISAVE( 3 ) + 1
GO TO 50
END IF
*
* ITERATION COMPLETE. FINAL STAGE.
*
120 CONTINUE
ALTSGN = ONE
DO 130 I = 1, N
X( I ) = ALTSGN*( ONE+DBLE( I-1 ) / DBLE( N-1 ) )
ALTSGN = -ALTSGN
130 CONTINUE
KASE = 1
ISAVE( 1 ) = 5
RETURN
*
* ................ ENTRY (ISAVE( 1 ) = 5)
* X HAS BEEN OVERWRITTEN BY A*X.
*
140 CONTINUE
TEMP = TWO*( DASUM( N, X, 1 ) / DBLE( 3*N ) )
IF( TEMP.GT.EST ) THEN
CALL DCOPY( N, X, 1, V, 1 )
EST = TEMP
END IF
*
150 CONTINUE
KASE = 0
RETURN
*
* End of DLACN2
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/srface/draws.f | 1 | 5308 | C
C $Id: draws.f,v 1.6 2008-07-27 00:17:25 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE DRAWS (MX1,MY1,MX2,MY2,IDRAW,IMARK)
C
C THIS ROUTINE DRAWS THE VISIBLE PART OF THE LINE CONNECTING
C (MX1,MY1) AND (MX2,MY2). IF IDRAW .NE. 0, THE LINE IS DRAWN.
C IF IMARK .NE. 0, THE VISIBILITY ARRAY IS MARKED.
C
LOGICAL VIS1 ,VIS2
DIMENSION PXS(2) ,PYS(2)
COMMON /SRFBLK/ LIMU(1024) ,LIML(1024) ,CL(41) ,NCL ,
1 LL ,FACT ,IROT ,NDRZ ,
2 NUPPER ,NRSWT ,BIGD ,UMIN ,
3 UMAX ,VMIN ,VMAX ,RZERO ,
4 IOFFP ,NSPVAL ,SPVAL ,BIGEST
DATA STEEP/5./
DATA MX,MY/0,0/
C
C Do a call forcing a BLOCKDATA to be loaded from a binary library.
C
CALL SRFABD
C
C MAKE LINE LEFT TO RIGHT.
C
MMX1 = MX1
MMY1 = MY1
MMX2 = MX2
MMY2 = MY2
IF (MMX1.EQ.NSPVAL .OR. MMX2.EQ.NSPVAL) RETURN
IF (MMX1 .GT. MMX2) GO TO 10
NX1 = MMX1
NY1 = MMY1
NX2 = MMX2
NY2 = MMY2
GO TO 20
10 NX1 = MMX2
NY1 = MMY2
NX2 = MMX1
NY2 = MMY1
20 IF (NUPPER .LT. 0) GO TO 180
C
C CHECK UPPER VISIBILITY.
C
VIS1 = NY1 .GE. (LIMU(NX1)-1)
VIS2 = NY2 .GE. (LIMU(NX2)-1)
C
C VIS1 AND VIS2 TRUE MEANS VISIBLE.
C
IF (VIS1 .AND. VIS2) GO TO 120
C
C VIS1 AND VIS2 FALSE MEANS INVISIBLE.
C
IF (.NOT.(VIS1 .OR. VIS2)) GO TO 180
C
C FIND CHANGE POINT.
C
IF (NX1 .EQ. NX2) GO TO 110
DY = REAL(NY2-NY1)/REAL(NX2-NX1)
NX1P1 = NX1+1
FNY1 = NY1
IF (VIS1) GO TO 60
DO 30 K=NX1P1,NX2
MX = K
MY = FNY1+REAL(K-NX1)*DY
IF (MY .GT. LIMU(K)) GO TO 40
30 CONTINUE
40 IF (ABS(DY) .GE. STEEP) GO TO 90
50 NX1 = MX
NY1 = MY
GO TO 120
60 DO 70 K=NX1P1,NX2
MX = K
MY = FNY1+REAL(K-NX1)*DY
IF (MY .LE. LIMU(K)) GO TO 80
70 CONTINUE
80 IF (ABS(DY) .GE. STEEP) GO TO 100
81 NX2 = MX-1
NY2 = MY
GO TO 120
90 IF (LIMU(MX) .EQ. 0) GO TO 50
NX1 = MX
NY1 = LIMU(NX1)
GO TO 120
100 IF (LIMU(MX-1).EQ.0) GO TO 81
NX2 = MX-1
NY2 = LIMU(NX2)
GO TO 120
110 IF (VIS1) NY2 = MIN(LIMU(NX1),LIMU(NX2))
IF (VIS2) NY1 = MIN(LIMU(NX1),LIMU(NX2))
120 IF (IDRAW .EQ. 0) GO TO 150
C
C DRAW VISIBLE PART OF LINE.
C
IF (IROT) 130,140,130
130 CONTINUE
PXS(1) = REAL(NY1)
PXS(2) = REAL(NY2)
PYS(1) = REAL(1024-NX1)
PYS(2) = REAL(1024-NX2)
CALL GPL (2,PXS,PYS)
GO TO 150
140 CONTINUE
PXS(1) = REAL(NX1)
PXS(2) = REAL(NX2)
PYS(1) = REAL(NY1)
PYS(2) = REAL(NY2)
CALL GPL (2,PXS,PYS)
150 IF (IMARK .EQ. 0) GO TO 180
IF (NX1 .EQ. NX2) GO TO 170
DY = REAL(NY2-NY1)/REAL(NX2-NX1)
FNY1 = NY1
DO 160 K=NX1,NX2
LTEMP = FNY1+REAL(K-NX1)*DY
IF (LTEMP .GT. LIMU(K)) LIMU(K) = LTEMP
160 CONTINUE
GO TO 180
170 LTEMP = MAX(NY1,NY2)
IF (LTEMP .GT. LIMU(NX1)) LIMU(NX1) = LTEMP
180 IF (NUPPER) 190,190,370
C
C SAME IDEA AS ABOVE, BUT FOR LOWER SIDE.
C
190 IF (MMX1 .GT. MMX2) GO TO 200
NX1 = MMX1
NY1 = MMY1
NX2 = MMX2
NY2 = MMY2
GO TO 210
200 NX1 = MMX2
NY1 = MMY2
NX2 = MMX1
NY2 = MMY1
210 VIS1 = NY1 .LE. (LIML(NX1)+1)
VIS2 = NY2 .LE. (LIML(NX2)+1)
IF (VIS1 .AND. VIS2) GO TO 310
IF (.NOT.(VIS1 .OR. VIS2)) GO TO 370
IF (NX1 .EQ. NX2) GO TO 300
DY = REAL(NY2-NY1)/REAL(NX2-NX1)
NX1P1 = NX1+1
FNY1 = NY1
IF (VIS1) GO TO 250
DO 220 K=NX1P1,NX2
MX = K
MY = FNY1+REAL(K-NX1)*DY
IF (MY .LT. LIML(K)) GO TO 230
220 CONTINUE
230 IF (ABS(DY) .GE. STEEP) GO TO 280
240 NX1 = MX
NY1 = MY
GO TO 310
250 DO 260 K=NX1P1,NX2
MX = K
MY = FNY1+REAL(K-NX1)*DY
IF (MY .GE. LIML(K)) GO TO 270
260 CONTINUE
270 IF (ABS(DY) .GE. STEEP) GO TO 290
271 NX2 = MX-1
NY2 = MY
GO TO 310
280 IF (LIML(MX) .EQ. 1024) GO TO 240
NX1 = MX
NY1 = LIML(NX1)
GO TO 310
290 IF (LIML(MX-1).EQ.1024) GO TO 271
NX2 = MX-1
NY2 = LIML(NX2)
GO TO 310
300 IF (VIS1) NY2 = MAX(LIML(NX1),LIML(NX2))
IF (VIS2) NY1 = MAX(LIML(NX1),LIML(NX2))
310 IF (IDRAW .EQ. 0) GO TO 340
IF (IROT) 320,330,320
320 CONTINUE
PXS(1) = REAL(NY1)
PXS(2) = REAL(NY2)
PYS(1) = REAL(1024-NX1)
PYS(2) = REAL(1024-NX2)
CALL GPL (2,PXS,PYS)
GO TO 340
330 CONTINUE
PXS(1) = REAL(NX1)
PXS(2) = REAL(NX2)
PYS(1) = REAL(NY1)
PYS(2) = REAL(NY2)
CALL GPL (2,PXS,PYS)
340 IF (IMARK .EQ. 0) GO TO 370
IF (NX1 .EQ. NX2) GO TO 360
DY = REAL(NY2-NY1)/REAL(NX2-NX1)
FNY1 = NY1
DO 350 K=NX1,NX2
LTEMP = FNY1+REAL(K-NX1)*DY
IF (LTEMP .LT. LIML(K)) LIML(K) = LTEMP
350 CONTINUE
RETURN
360 LTEMP = MIN(NY1,NY2)
IF (LTEMP .LT. LIML(NX1)) LIML(NX1) = LTEMP
370 RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/dlantr.f | 7 | 8868 | DOUBLE PRECISION FUNCTION DLANTR( NORM, UPLO, DIAG, M, N, A, LDA,
$ WORK )
*
* -- 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 ..
CHARACTER DIAG, NORM, UPLO
INTEGER LDA, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DLANTR returns the value of the one norm, or the Frobenius norm, or
* the infinity norm, or the element of largest absolute value of a
* trapezoidal or triangular matrix A.
*
* Description
* ===========
*
* DLANTR returns the value
*
* DLANTR = ( 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 DLANTR as described
* above.
*
* UPLO (input) CHARACTER*1
* Specifies whether the matrix A is upper or lower trapezoidal.
* = 'U': Upper trapezoidal
* = 'L': Lower trapezoidal
* Note that A is triangular instead of trapezoidal if M = N.
*
* DIAG (input) CHARACTER*1
* Specifies whether or not the matrix A has unit diagonal.
* = 'N': Non-unit diagonal
* = 'U': Unit diagonal
*
* M (input) INTEGER
* The number of rows of the matrix A. M >= 0, and if
* UPLO = 'U', M <= N. When M = 0, DLANTR is set to zero.
*
* N (input) INTEGER
* The number of columns of the matrix A. N >= 0, and if
* UPLO = 'L', N <= M. When N = 0, DLANTR is set to zero.
*
* A (input) DOUBLE PRECISION array, dimension (LDA,N)
* The trapezoidal matrix A (A is triangular if M = N).
* If UPLO = 'U', the leading m by n upper trapezoidal part of
* the array A contains the upper trapezoidal matrix, and the
* strictly lower triangular part of A is not referenced.
* If UPLO = 'L', the leading m by n lower trapezoidal part of
* the array A contains the lower trapezoidal matrix, and the
* strictly upper triangular part of A is not referenced. Note
* that when DIAG = 'U', the diagonal elements of A are not
* referenced and are assumed to be one.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(M,1).
*
* WORK (workspace) DOUBLE PRECISION array, dimension (LWORK),
* where LWORK >= M when NORM = 'I'; otherwise, WORK is not
* referenced.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL UDIAG
INTEGER I, J
DOUBLE PRECISION SCALE, SUM, VALUE
* ..
* .. External Subroutines ..
EXTERNAL DLASSQ
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, MIN, SQRT
* ..
* .. Executable Statements ..
*
IF( MIN( M, N ).EQ.0 ) THEN
VALUE = ZERO
ELSE IF( LSAME( NORM, 'M' ) ) THEN
*
* Find max(abs(A(i,j))).
*
IF( LSAME( DIAG, 'U' ) ) THEN
VALUE = ONE
IF( LSAME( UPLO, 'U' ) ) THEN
DO 20 J = 1, N
DO 10 I = 1, MIN( M, J-1 )
VALUE = MAX( VALUE, ABS( A( I, J ) ) )
10 CONTINUE
20 CONTINUE
ELSE
DO 40 J = 1, N
DO 30 I = J + 1, M
VALUE = MAX( VALUE, ABS( A( I, J ) ) )
30 CONTINUE
40 CONTINUE
END IF
ELSE
VALUE = ZERO
IF( LSAME( UPLO, 'U' ) ) THEN
DO 60 J = 1, N
DO 50 I = 1, MIN( M, J )
VALUE = MAX( VALUE, ABS( A( I, J ) ) )
50 CONTINUE
60 CONTINUE
ELSE
DO 80 J = 1, N
DO 70 I = J, M
VALUE = MAX( VALUE, ABS( A( I, J ) ) )
70 CONTINUE
80 CONTINUE
END IF
END IF
ELSE IF( ( LSAME( NORM, 'O' ) ) .OR. ( NORM.EQ.'1' ) ) THEN
*
* Find norm1(A).
*
VALUE = ZERO
UDIAG = LSAME( DIAG, 'U' )
IF( LSAME( UPLO, 'U' ) ) THEN
DO 110 J = 1, N
IF( ( UDIAG ) .AND. ( J.LE.M ) ) THEN
SUM = ONE
DO 90 I = 1, J - 1
SUM = SUM + ABS( A( I, J ) )
90 CONTINUE
ELSE
SUM = ZERO
DO 100 I = 1, MIN( M, J )
SUM = SUM + ABS( A( I, J ) )
100 CONTINUE
END IF
VALUE = MAX( VALUE, SUM )
110 CONTINUE
ELSE
DO 140 J = 1, N
IF( UDIAG ) THEN
SUM = ONE
DO 120 I = J + 1, M
SUM = SUM + ABS( A( I, J ) )
120 CONTINUE
ELSE
SUM = ZERO
DO 130 I = J, M
SUM = SUM + ABS( A( I, J ) )
130 CONTINUE
END IF
VALUE = MAX( VALUE, SUM )
140 CONTINUE
END IF
ELSE IF( LSAME( NORM, 'I' ) ) THEN
*
* Find normI(A).
*
IF( LSAME( UPLO, 'U' ) ) THEN
IF( LSAME( DIAG, 'U' ) ) THEN
DO 150 I = 1, M
WORK( I ) = ONE
150 CONTINUE
DO 170 J = 1, N
DO 160 I = 1, MIN( M, J-1 )
WORK( I ) = WORK( I ) + ABS( A( I, J ) )
160 CONTINUE
170 CONTINUE
ELSE
DO 180 I = 1, M
WORK( I ) = ZERO
180 CONTINUE
DO 200 J = 1, N
DO 190 I = 1, MIN( M, J )
WORK( I ) = WORK( I ) + ABS( A( I, J ) )
190 CONTINUE
200 CONTINUE
END IF
ELSE
IF( LSAME( DIAG, 'U' ) ) THEN
DO 210 I = 1, N
WORK( I ) = ONE
210 CONTINUE
DO 220 I = N + 1, M
WORK( I ) = ZERO
220 CONTINUE
DO 240 J = 1, N
DO 230 I = J + 1, M
WORK( I ) = WORK( I ) + ABS( A( I, J ) )
230 CONTINUE
240 CONTINUE
ELSE
DO 250 I = 1, M
WORK( I ) = ZERO
250 CONTINUE
DO 270 J = 1, N
DO 260 I = J, M
WORK( I ) = WORK( I ) + ABS( A( I, J ) )
260 CONTINUE
270 CONTINUE
END IF
END IF
VALUE = ZERO
DO 280 I = 1, M
VALUE = MAX( VALUE, WORK( I ) )
280 CONTINUE
ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
*
* Find normF(A).
*
IF( LSAME( UPLO, 'U' ) ) THEN
IF( LSAME( DIAG, 'U' ) ) THEN
SCALE = ONE
SUM = MIN( M, N )
DO 290 J = 2, N
CALL DLASSQ( MIN( M, J-1 ), A( 1, J ), 1, SCALE, SUM )
290 CONTINUE
ELSE
SCALE = ZERO
SUM = ONE
DO 300 J = 1, N
CALL DLASSQ( MIN( M, J ), A( 1, J ), 1, SCALE, SUM )
300 CONTINUE
END IF
ELSE
IF( LSAME( DIAG, 'U' ) ) THEN
SCALE = ONE
SUM = MIN( M, N )
DO 310 J = 1, N
CALL DLASSQ( M-J, A( MIN( M, J+1 ), J ), 1, SCALE,
$ SUM )
310 CONTINUE
ELSE
SCALE = ZERO
SUM = ONE
DO 320 J = 1, N
CALL DLASSQ( M-J+1, A( J, J ), 1, SCALE, SUM )
320 CONTINUE
END IF
END IF
VALUE = SCALE*SQRT( SUM )
END IF
*
DLANTR = VALUE
RETURN
*
* End of DLANTR
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ngmath/src/examples/eshgrid/shex03.f | 1 | 3063 |
PROGRAM SHEX03
C
C Create a tube-shaped isosurface.
C
C The number of input data points.
C
PARAMETER (NDATA=1000)
C
C The number of output data points in the X coordinate direction.
C
PARAMETER (NX=21)
C
C The number of output data points in the Y coordinate direction.
C
PARAMETER (NY=31)
C
C The number of output data points in the Z coordinate direction.
C
PARAMETER (NZ=41)
C
C The size of the workspace.
C
PARAMETER (NIWK=2*NDATA, NRWK=11*NDATA+6)
C
C Dimension the arrays.
C
DIMENSION X(NDATA), Y(NDATA), Z(NDATA), F(NDATA)
DIMENSION IWK(NIWK), RWK(NRWK)
C
C Define the error file, the Fortran unit number, the workstation type,
C and the workstation ID to be used in calls to GKS routines.
C
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript
C
PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1)
C
C Define arrays for use in plotting the isosurface.
C
REAL XO(NX), YO(NY), ZO(NZ), OUTPUT(NX,NY,NZ)
INTEGER I, J, K, IER
DATA XMIN,YMIN,ZMIN,XMAX,YMAX,ZMAX / -2., -2., -2., 2., 2., 2./
C
C Define the input data on random coordinates bounded by the
C above values.
C
DO 10 I=1,NDATA
X(I) = XMIN+(XMAX-XMIN)*DSRND1()
Y(I) = YMIN+(YMAX-YMIN)*DSRND1()
Z(I) = ZMIN+(ZMAX-ZMIN)*DSRND1()
F(I) = 0.75*X(I)**2 - 1.6*Y(I)**2 + 2.0*Z(I)**2.
10 CONTINUE
C
C Create the output grid.
C
DO 102 I=1,NX
XO(I) = XMIN+(REAL(I-1)/REAL(NX-1))*(XMAX-XMIN)
102 CONTINUE
DO 103 J =1,NY
YO(J)= YMIN+(REAL(J-1)/REAL(NY-1))*(YMAX-YMIN)
103 CONTINUE
DO 104 K=1,NZ
ZO(K) = ZMIN+(REAL(K-1)/REAL(NZ-1))*(ZMAX-ZMIN)
104 CONTINUE
C
C Find the approximating function values on the output grid.
C
CALL SHGRID (NDATA,X,Y,Z,F,NX,NY,NZ,XO,YO,ZO,OUTPUT,IWK,RWK,IER)
C
C Plot an isosurface.
C
C Open GKS and define the foreground and background color.
C
CALL GOPKS (IERRF, ISZDM)
CALL GOPWK (IWKID, LUNIT, IWTYPE)
CALL GACWK (IWKID)
C
CALL TDEZ3D(NX, NY, NZ, XO, YO, ZO,
+ OUTPUT, 0.7, 2.3, -13., 75., 6)
CALL FRAME()
C
C Close GKS.
C
CALL GDAWK (IWKID)
CALL GCLWK (IWKID)
CALL GCLKS
C
STOP
END
REAL FUNCTION DSRND1()
C
C Portable random number generator.
C
PARAMETER (MPLIER=16807,MODLUS=2147483647,MOBYMP=127773,
+ MOMDMP=2836)
C
INTEGER HVLUE, LVLUE, TESTV, NEXTN
SAVE NEXTN
DATA JSEED,IFRST/123456789,0/
C
IF (IFRST .EQ. 0) THEN
NEXTN = JSEED
IFRST = 1
ENDIF
C
HVLUE = NEXTN / MOBYMP
LVLUE = MOD(NEXTN, MOBYMP)
TESTV = MPLIER*LVLUE - MOMDMP*HVLUE
IF (TESTV .GT. 0) THEN
NEXTN = TESTV
ELSE
NEXTN = TESTV + MODLUS
ENDIF
DSRND1 = REAL(NEXTN)/REAL(MODLUS)
C
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/cgetc2.f | 2 | 4327 | SUBROUTINE CGETC2( N, A, LDA, IPIV, JPIV, 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 INFO, LDA, N
* ..
* .. Array Arguments ..
INTEGER IPIV( * ), JPIV( * )
COMPLEX A( LDA, * )
* ..
*
* Purpose
* =======
*
* CGETC2 computes an LU factorization, using complete pivoting, of the
* n-by-n matrix A. The factorization has the form A = P * L * U * Q,
* where P and Q are permutation matrices, L is lower triangular with
* unit diagonal elements and U is upper triangular.
*
* This is a level 1 BLAS version of the algorithm.
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* A (input/output) COMPLEX array, dimension (LDA, N)
* On entry, the n-by-n matrix to be factored.
* On exit, the factors L and U from the factorization
* A = P*L*U*Q; the unit diagonal elements of L are not stored.
* If U(k, k) appears to be less than SMIN, U(k, k) is given the
* value of SMIN, giving a nonsingular perturbed system.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1, N).
*
* IPIV (output) INTEGER array, dimension (N).
* The pivot indices; for 1 <= i <= N, row i of the
* matrix has been interchanged with row IPIV(i).
*
* JPIV (output) INTEGER array, dimension (N).
* The pivot indices; for 1 <= j <= N, column j of the
* matrix has been interchanged with column JPIV(j).
*
* INFO (output) INTEGER
* = 0: successful exit
* > 0: if INFO = k, U(k, k) is likely to produce overflow if
* one tries to solve for x in Ax = b. So U is perturbed
* to avoid the overflow.
*
* Further Details
* ===============
*
* Based on contributions by
* Bo Kagstrom and Peter Poromaa, Department of Computing Science,
* Umea University, S-901 87 Umea, Sweden.
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
INTEGER I, IP, IPV, J, JP, JPV
REAL BIGNUM, EPS, SMIN, SMLNUM, XMAX
* ..
* .. External Subroutines ..
EXTERNAL CGERU, CSWAP, SLABAD
* ..
* .. External Functions ..
REAL SLAMCH
EXTERNAL SLAMCH
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, CMPLX, MAX
* ..
* .. Executable Statements ..
*
* Set constants to control overflow
*
INFO = 0
EPS = SLAMCH( 'P' )
SMLNUM = SLAMCH( 'S' ) / EPS
BIGNUM = ONE / SMLNUM
CALL SLABAD( SMLNUM, BIGNUM )
*
* Factorize A using complete pivoting.
* Set pivots less than SMIN to SMIN
*
DO 40 I = 1, N - 1
*
* Find max element in matrix A
*
XMAX = ZERO
DO 20 IP = I, N
DO 10 JP = I, N
IF( ABS( A( IP, JP ) ).GE.XMAX ) THEN
XMAX = ABS( A( IP, JP ) )
IPV = IP
JPV = JP
END IF
10 CONTINUE
20 CONTINUE
IF( I.EQ.1 )
$ SMIN = MAX( EPS*XMAX, SMLNUM )
*
* Swap rows
*
IF( IPV.NE.I )
$ CALL CSWAP( N, A( IPV, 1 ), LDA, A( I, 1 ), LDA )
IPIV( I ) = IPV
*
* Swap columns
*
IF( JPV.NE.I )
$ CALL CSWAP( N, A( 1, JPV ), 1, A( 1, I ), 1 )
JPIV( I ) = JPV
*
* Check for singularity
*
IF( ABS( A( I, I ) ).LT.SMIN ) THEN
INFO = I
A( I, I ) = CMPLX( SMIN, ZERO )
END IF
DO 30 J = I + 1, N
A( J, I ) = A( J, I ) / A( I, I )
30 CONTINUE
CALL CGERU( N-I, N-I, -CMPLX( ONE ), A( I+1, I ), 1,
$ A( I, I+1 ), LDA, A( I+1, I+1 ), LDA )
40 CONTINUE
*
IF( ABS( A( N, N ) ).LT.SMIN ) THEN
INFO = N
A( N, N ) = CMPLX( SMIN, ZERO )
END IF
RETURN
*
* End of CGETC2
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/pwritx/pwritx.f | 1 | 47925 | C
C $Id: pwritx.f,v 1.7 2009-08-06 20:55:14 fred Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE PWRITX(X,Y,IDPC,NCHAR,JSIZE,JOR,JCTR)
C
C SUBROUTINE PWRITX (X,Y,IDPC,NCHAR,JSIZE,JOR,JCTR)
C
C LATEST REVISION October, 1988
C
C PURPOSE PWRITX is a character plotting routine. It
C produces high quality characters for annotating
C graphs, making movie titles, etc.
C
C USAGE CALL PWRITX (X,Y,IDPC,NCHAR,JSIZE,JOR,JCTR)
C
C ARGUMENTS
C
C COMMON BLOCK PUSER By default PWRITX uses the complex character
C set. A complete list of the characters
C contained in this font appears as the
C output from the PWRITX demo driver in
C the Examples section of the current
C graphics manual. PWRITX can be made to
C access one other font, called the duplex
C character set. The characters in the
C duplex font are somewhat simpler in
C appearance (no serifs, fewer curves, etc.),
C but are still of high-quality. Only the
C alphanumeric characters in the duplex
C font are different from the alphanumeric
C characters in the complex font. All other
C characters remain the same. To make
C PWRITX access the duplex character set, the user
C has to define in his main program a common block
C PUSER containing 1 integer variable. If this
C variable is initialized to 1 before the first
C call to PWRITX, the duplex character set is
C used by PWRITX.
C
C For example:
C
C .
C .
C .
C
C COMMON /PUSER/ MODE
C
C .
C .
C .
C
C MODE = 1
C
C .
C .
C .
C
C CALL PWRITX(.................)
C
C .
C .
C .
C
C NOTES
C The character set cannot be changed after
C the first call to PWRITX. To produce
C examples of the duplex character set,
C run the demo driver for pwritx (as supplied)
C with MODE set to 1 as described above.
C The demo driver for PWRITX also serves
C for examples of PWRITX calls (particularly
C the final plot.)
C
C ON INPUT X,Y
C Positioning coordinates for the characters to
C be drawn. These are world coordinates. See
C JCTR.
C
C IDPC
C Characters to be drawn and FUNCTION CODES
C (see below.) IDPC is TYPE CHARACTER.
C
C NCHAR
C The number of characters in IDPC, including
C characters to be drawn and function codes.
C
C JSIZE
C Size of the character.
C . If between 0 and 3, it is 1., 1.5, 2.,
C or 3. times digitized character width.
C (See FUNCTION CODES below for these
C sizes.)
C . If greater than 3 it is the desired plotter
C address units for principal character
C height, i.e. principal characters will be
C JSIZE plotter address units high, and
C indexical and cartographic characters will
C be scaled proportionally, such that
C
C Indexical = (13/21)*JSIZE PLA units high
C Cartographic = (9/21)*JSIZE PLA units high
C
C JOR
C Character string orientation in degrees
C counter-clockwise from the positive X axis.
C
C JCTR
C Centering option.
C = 0 (X,Y) is the center of the entire
C string.
C = -1 (X,Y) is the center of the left edge of
C the first character.
C = 1 (X,Y) is the center of the right edge of
C the last character.
C
C ON OUTPUT All arguments are unchanged.
C
C FUNCTION CODES Function codes may be included in the character
C string IDPC to change font, case, etc. within a
C string of text. All function instructions must
C be enclosed in apostrophes.
C No punctuation is needed between functions
C except for a comma between adjacent numbers;
C however, commas may be used between functions
C to improve readability. The following are the
C only legal function codes. Any other
C characters in a function string will be ignored
C except that an error message will be printed
C and, if more than 10 errors occur within a
C string, control will be returned to the main
C program. At the first call to PWRITX, size,type
C and case are Principal, Roman and Upper.
C
C PLA = plotter address (for resolution 10)
C UPA = user plotter address (resolution as
C defined by user )
C
C A. FONT DEFINITIONS
C R Roman type characters
C G Greek type characters
C
C B. SIZE DEFINITIONS
C P Principal size, digitized to be 21 PLA
C units high. The total character
C including white space is 32 PLA units
C high. A carriage return or a Y
C increment will space down 32 PLA units.
C A blank or an X increment will space
C across 16 PLA units. Note: Characters
C vary in width.
C I Indexical size, digitized to be 13 PLA
C units high (20 PLA units high
C including white space). A carriage
C return or a Y increment is 20 PLA units.
C Blanks or X increments are 12 PLA units.
C K Cartographic size, digitized to be 9 PLA
C units high (14 PLA units high
C including white space). Carriage return
C or Y increments are 14 PLA units. Blanks
C or X increments are 8 PLA units.
C
C C. CASE DEFINITIONS
C U or Un. Upper case
C If U is followed by a number n (not
C separated by a comma) then n characters
C will be drawn in upper case, subsequent
C characters will be in lower case. (The
C Un option is particularly useful for
C capitalizing sentences.)
C L or Ln. Lower case
C If L is followed by a number n, then n
C characters will be drawn in lower case
C and subsequent characters will be in
C upper case.
C
C D. LEVEL DEFINITIONS
C S or Sn. Superscript level.
C B or Bn. Subscript level.
C N or Nn. Normal level.
C
C When super or subscripting, the
C character size will change depending on
C the previous character drawn. Principal
C base characters will be subscripted or
C superscripted with indexical characters,
C with a 10 PLA unit shift (scaled to
C JSIZE) up or down. Indexical and
C cartographic base characters will be sub
C or superscripted with cartographic
C characters with a 7 PLA unit shift.
C
C The case of the indexing characters will
C generally be the same as that of the bas
C character unless otherwise specified.
C Exception: a lower case indexical base
C will be super or subscripted with upper
C case cartographic, as the cartographic
C type has no lower case alphabetic or
C numeric characters available.
C
C If S,B or N is followed by a number n,
C then n characters will be drawn as
C specified above, after which character
C size, case and position will be reset to
C that of the base character.
C If n is negative, its absolute value
C will be used instead (n cannot be 0.)
C Do not overlap level definitions given
C for a specified number of characters.
C The N option returns character case and
C size to that of the base but maintains
C the current character position.
C
C Example: 'U1'T'S1'EST
C E
C Will be written TST
C 'U1'T'S'E'N'ST
C E
C Will be written T ST
C
C E. COORDINATE DEFINITIONS (descriptions assume
C normal UPA unit
C space.)
C H,Hn,HnQ. Increment in the X direction.
C If this option appears without a number
C n, n will be taken to be 1. Hn will
C shift the present X position n UPA
C units. If n is positive the shift is to
C the right, if n is negative the shift is
C to the left. If Hn is followed by a Q,
C the X position will be incremented by n
C character widths (i.e., n blanks) either
C right or left.
C V,Vn,VnQ. Increment in the Y direction.
C If this option appears without a number
C n, n will be taken to be 1. Vn will
C shift the present Y position n UPA
C units. If n is positive the shift is
C up, if n is negative the shift is down.
C If Vn is followed by a Q, the Y position
C will be incremented by n lines up or
C down.
C X,Xn. Set X.
C If X appears without a number n, this
C will act as a do-nothing statement.
C Otherwise, the character position in the
C X direction will be set to the UPA
C coordinate n, so that the next character
C drawn will be centered on n and
C subsequent characters will be drawn from
C this position.
C Y,Yn. Set Y.
C This works the same as set X.
C C Carriage return.
C A carriage return will be done before
C the next character is plotted.
C
C F. DIRECTION DEFINITIONS
C D,Dn. Write down, rather than across the
C frame.
C If D appears without an n or if n=0, all
C characters will be written down, until
C an 'A' function is encountered. If D is
C followed by a number n, n characters
C will be written down and subsequent
C characters will be written across the
C frame.
C If n is negative, the absolute value of
C n is used instead.
C A Write across.
C Escape from the D option.
C
C G. DIRECT CHARACTER ACCESS
C NNN. Numeric character.
C Character number NNN will be drawn.
C NNN is base 8.
C
C NOTE . All characters in a given call are drawn in
C the same intensity. If JSIZE .LE. 2,
C characters are in low intensity, otherwise
C they are in high intensity. Return to the
C main program is always in high intensity.
C . On other than the first entry to PWRITX,
C font, case, etc. are in the state they
C were in when the program exited from the
C the last PWRITX call.
C . Font, size, and case are reset to previous
C values if they were only set for a specified
C number of characters in the previous call.
C . The previous case is always reset to upper
C for each new call to PWRITX.
C . The direction is always reset to across
C for each new call to PWRITX.
C . Numbers for direct character access must
C not be signed. All other numbers can be
C signed.
C
C PORTABILITY FORTRAN 77
C
C REQUIRED RESIDENT SQRT, SIN, COS.
C ROUTINES
C
C REQUIRED GKS LEVEL 0A
C
C ENTRY POINTS PWRITX, GTNUM, GTNUMB, XTCH, PWRXBD, GTSIGN,
C GTDGTS, HTABLE, GETHOL, CCHECK, DCECK, PWRX
C MKMSK, PWRXBDX
C
C COMMON BLOCKS PWRSV1, PSAV1, PSAV3, PUSER, PINIT, PINIT1,
C HOLTAB, PWRC0, PWRC1, PWRC2
C
C REQUIRED LIBRARY The ERPRT77 package and the SPPS.
C
C I/O Plots characters.
C
C PRECISION Single
C
C LANGUAGE FORTRAN 77
C
C HISTORY -Originally implemented to make the Hershey
C character sets more accessable.
C -Made portable in 1978.
C for use on all computer systems which support
C plotters with up to 15 bit resolution.
C -Made to be FORTRAN 77 and GKS compatible,
C August, 1984.
C
C INTERNAL PARAMETERS NAME DEFAULT FUNCTION
C ---- ------- --------
C
C All values below are for plotter address units.
C
C SPRIH 32. Height of principal characters
C SPRIW 16. Width of principal characters
C SINDH 20. Height of indexical chars.
C SINDW 12. Width of indexical chars.
C SCARH 14. Height of cartographic chars.
C SCARW 8. Width of cartographic chars.
C SSPR 10. Shift in case of super or
C subscripting for principal
C characters.
C SSIC 7. Shift in case of super or
C subscripting for indexical
C characters.
C
C **********************************************************************
C
C IMPLEMENTATION INSTRUCTIONS
C
C 1. Create the PWRITX binary database from the card-image files
C PWRITXC1, PWRITXC2, PWRITXD1, PWRITXD2 supplied. To do this,
C read the instructions in file PWRITXNT and execute that program.
C 2. Supply 3 machine dependent subprograms for bit manipulations,
C namely ISHIFT(I1,I2), IOR(I1,I2), and IAND(I1,I2).
C These subprograms can be the same routines used to implement the
C NCAR GKS plot package.
C 3. Set up a binary input file from which character data may be read
C (user input) and supply its number below.
C 4. Set the binary input file where PWRITX may read its data.
C **********************************************************************
C
C
C
C
C
C
C D E C L A R A T I O N S
C
CHARACTER IDPC*(*)
C
C IDPC contains the characters to be drawn, and the function codes.
C
C IDPC must be of type character on input.
C
C
C SAVE DATA VALUES FOR LATER PASSES
C
COMMON/PWRSV1/NBWD,NUM15,INDLEN,IDDLEN,NUNIT
C
C
C NOTE THE SIZE OF IDD AND IND MAY BE MODIFED TO CONTAIN THE
C NUMBER OF ELEMENTS EQUAL TO THE VALUE OF IDDLEN AND INDLEN
C COMPUTED BELOW.
C
COMMON/PWRC0/IDD(8625),IND(789)
C
C PWRC0 AND PWRC1 ARE FOR COMMUNICATION WITH SUBROUTINE XTCH.
C PWRC0 IS TO PASS VALUES TO XTCH AND PWRC1 IS TO PASS VALUES BACK.
COMMON /PWRC1/ LC(150)
C PWRC2 IS FOR COMMUNICATION WITH SUBROUTINE XTCH AND BLOCKDATA PWRXBDX.
COMMON /PWRC2/ INDZER
C VARIABLES WHICH HAVE TO BE SAVED FOR SUBSEQUENT CALLS TO PWRITX AND
C HAVE TO BE INITIALIZED.
C PSAV1 IS ALSO CONTAINED IN PWRXBDX.
COMMON /PSAV1/ FINIT,IFNT,IC,IT,ITO,RLX,RLY,RLOX,RLOY
C VARIABLES WHICH HAVE TO BE SAVED BUT NOT INITIALIZED.
C PSAV3 IS NOT CONTAINED IN ANY OTHER ROUTINE.
COMMON /PSAV3/ IAPOST, IQU
C
C COMMUNICATION WITH THE USER.
COMMON /PUSER/ MODE
C
LOGICAL NFLAG
LOGICAL FINIT
C
C Character constants
C
CHARACTER*1 IAPOST,IQU
C
C Storage for current character of string
C
CHARACTER*1 NC
C
C Value of the character in the character-to-hollerith table
C
INTEGER HOLIND
C
C C O N S T A N T D E F I N I T I O N S
C
C INFORMATION ABOUT THE SIZE OF THE FILES OF INTEGERS SUPPLIED BY NCAR
C TOGETHER WITH PWRITX.
C THESE CONSTANTS ARE NEVER USED IN THE CODE BUT REFERRED TO IN COMMENTS
C
C NUMBER OF CARD IMAGES NEEDED TO REPRESENT ARRAY IND.
DATA ICNUM1 /49/
C NUMBER OF CARD IMAGES NEEDED TO REPRESENT ARRAY IDD.
DATA ICNUM2 /575/
C
C DEFINE INDICES FOR FONT, SIZE, AND CASE DEFINITIONS.
C
C THESE INDICES ARE USED AS DISPLACEMENTS INTO THE ARRAY IND AND THEY
C DEFINE UNIQUELY FOR EACH CHARACTER TOGETHER WITH ITS REPRESENTATION
C IN DPC AN ENTRY IN THE ARRAY IND. THIS ENTRY CONTAINS A POINTER
C WHICH POINTS TO THE DIGITIZATION OF THE SYMBOL AS DEFINED BY FONT,
C SIZE, CASE, AND CHARACTER.
C
C DEFINE INDEX FOR ROMAN AND GREEK FONT.
DATA INDROM, INDGRE /0,384/
C DEFINE INDEX FOR PRINCIPAL, INDEXICAL, AND CARTOGRAPHIC SIZE.
DATA INDPRI, INDIND, INDCAR /0,128,256/
C DEFINE INDEX FOR UPPER AND LOWER CASE.
DATA INDUPP, INDLOW /0,64/
C
C DEFINE CHARACTER SIZES IN PLOTTER ADDRESS UNITS (FOR RESOLUTION 10)
C
C FOR PRINCIPAL CHARACTER SIZE - HEIGHT,WIDTH
DATA SPRIH, SPRIW /32.,16./
C FOR INDEXICAL SIZE - HEIGTH,WIDTH
DATA SINDH,SINDW /20.,12./
C FOR CARTOGRAPHIC SIZE - HEIGTH,WIDTH
DATA SCARH, SCARW /14.,8./
C
C SHIFTING FOR SUPER OR SUBSCRIPTING.
C
C NUMBER OF PLOTTER ADDRESS UNITS SHIFTED FOR PRINCIPAL CHARACTERS.
DATA SSPR /10./
C NUMBER OF PLOTTER ADDRESS UNITS SHIFTED FOR INDEXICAL OR CARTOGRAPHIC
C CHARACTERS.
DATA SSIC /7./
C
C CONSTANT USED TO CHANGE DEGREES INTO RADIANS.
C DEGRAD = 2*3.14/360
DATA DEGRAD /0.01745329/
C T2 = PI/2
DATA T2 /1.5707963/
C
C
C **********************************************************************
C
C IMPLEMENTATION-DEPENDENT CONSTANTS
C
C
C THE UNIT NUMBER WHERE THE BINARY FILE SUPPLIED TO PWRITX CAN BE READ.
C
C DATA INBIN /0/
DATA INBIN /3/
C
C
C END OF IMPLEMENTATION-DEPENDENT CONSTANTS
C
C
C **********************************************************************
C
C
C
C
C VARIABLES AND CONSTANTS USED IN PWRX:
C
C IND - POINTERS INTO ARRAY IDD
C IDD - DIGITIZED CHARACTERS
C LC - CONTAINS DIGITIZATION OF 1 CHARACTER, 1 DIGITIZATION UNIT PER
C WORD.
C DISPLACEMENTS INTO THE ARRAY IND
C INDROM - FOR ROMAN FONT
C INDGRE - FOR GREEK FONT
C INDPRI - FOR PRINCIPAL CHARACTER SIZE
C INDIND - FOR INDEXICAL CHARACTER SIZE
C INDCAR - FOR CARTOGRAPHIC CHARACTER SIZE
C INDUPP - FOR UPPER CASE
C INDLOW - FOR LOWER CASE
C CHARACTER SIZE AS DEFINED BY FUNCTION CODE (PLOTTER ADDRESS UNITS)
C SPRIH - HEIGHT OF PRINCIPAL CHARACTERS
C SPRIW - WIDTH OF PRINCIPAL CHARACTERS
C SINDH - HEIGHT OF INDEXICAL CHARACTERS
C SINDW - WIDTH OF INDEXICAL CHARACTERS
C SCARH - HEIGHT OF CARTOGRAPHIC CHARACTERS
C SCARW - WIDTH OF CARTOGRAPHIC CHARACTERS
C SHIFTING FOR SUPER OR SUBSCRIPTING (PLOTTER ADDRESS UNITS)
C SSPR - SHIFT FOR PRINCIPAL CHARACTERS
C SSIC - SHIFT FOR INDEXICAL OR CARTOGRAPHIC CHARACTERS
C II - THE POSITION OF THE CHARACTER CURRENTLY BEING PROCESSED
C NC - THE CHARACTER CURRENTLY BEING PROCESSED, RIGHT JUSTIFIED,
C ZERO FILLED, ASCII REPRESENTATION.
C NCHOL - CHARACTER NC IN HOLLERITH REPRESENTATION.
C INDPOI - THE POSITION OF THE POINTER IN IND WHICH POINTS TO THE
C DIGITIZATION OF CHARACTER NC IN THE ARRAY IDD.
C NUM - SIGNED INTEGER AS EXTRACTED FROM CHARACTER STRING IDPC
C IPASS = 1 : PASS TO CENTER THE STRING
C = 2 : PASS TO DRAW OUT THE CHARACTERS
C L1 - DISTANCE FROM THE CENTER OF A CHARACTER TO ITS LEFT END
C (AS A NEGATIVE NUMBER)
C L2 - DISTANCE FROM THE CENTER OF A CHARACTER TO ITS RIGHT END
C (AS A POSITIVE NUMBER)
C IERR- ERROR COUNT
C NFLAG = .FALSE. NORMAL
C = .TRUE. DIRECT CHARACTER ACCESS
C IT - REPRESENTS CHARACTER SIZE
C 0 = PRICIPAL 128 = INDEXICAL 256 = CARTOGRAPHIC
C ITO - REPRESENTS PREVIOUS CHARACTER SIZE
C IC - REPRESENTS LOWER CASE , UPPER CASE
C =0 UPPER CASE
C =64 LOWER CASE
C ICO - REPRESENTS PREVIOUS CASE
C IFNT = 0 ROMAN
C = 384 GREEK
C IFLG = 0 NORMAL
C = 1 DISTANCE BETWEEN CHARACTERS IS NOT TAKEN FROM DIGITIZATION
C POSITION INSTEAD DEFINED BY HIGHER PRIORITY FUNCTION CODE
C (C,Y,X)
C N - NUMBER OF CHARACTERS IN INPUT STRING
C IDFLG = 0 WRITE ACROSS THE FRAME
C = 1 WRITE DOWN THE FRAME
C FINIT = .TRUE. ONE TIME INITIALIZATION HAS BEEN DONE
C = .FALSE. ONE TIME INITIALIZATION HAS NOT BEEN DONE YET
C RLX - CHARACTER HEIGHT ACCORDING TO FUNCTION CODE AND SIZE PARAMETER
C RLY - CHARACTER WIDTH ACCORDING TO FUNCTION CODE AND SIZE PARAMETER
C RLOX - PREVIOUS CHARACTER HEIGHT
C RLOY - PREVIOUS CHARACTER WIDTH
C N4 = 0 NO CHARACTERS TO BE WRITTEN DOWN
C OTHERWISE NUMBER OF CHARACTERS TO BE WRITTEN DOWN
C IN4 - NUMBER OF CHARACTER CURRENTLY BEING WRITTEN DOWN
C N3 - NUMBER AS COMPUTED BY GTNUM FOR COORDINATE DEFINITIONS OR
C NUMBER AS COMPUTED BY GTNUMB FOR NUMERIC CHARACTER DEFINITIONS.
C N3T1 - TEMPORARY STORAGE FOR VARIABLE N3. ONLY USED IN SECTION FOR
C FUNCTION CODE H.
C N3T2 - LIKE N3T1, BUT FOR FUNCTION CODE V.
C N2 - NUMBER OF CHARACTERS TO BE WRITTEN AS SUPERSCRIPT OR SUBSCRIPT
C IN2 - NUMBER OF CHARACTER CURRENTLY BEING WRITTEN AS SUPERSCRIPT OR
C SUBSCRIPT
C N1 - NUMBER OF CHARACTERS TO BE WRITTEN IN LOWER CASE OR UPPER CASE
C IN1 - NUMBER OF CHARACTER CURRENTLY BEING WRITTEN IN LOWER CASE OR
C UPPER CASE
C NF =1 NORMAL LEVEL
C =0 FLAG FOR SUPERSCRIPTING OR SUBSCRIPTING
C NIX,NIY - IN PASS 1 THE PARAMETER COORDINATES X AND Y IN METACODE
C ADDRESS UNITS. IN PASS 2 THE ACTUAL COORDINATES OF THE FIRST
C CHARACTER IN THE STRING IN METACODE ADDRESS UNITS.
C IX,IY - SAME AS NIX,NIY AS LONG AS NO CARRIAGE RETURN IS ENCOUNTERED.
C AFTER EACH CARRIAGE RETURN THEY CONTAIN THE COORDINATES OF
C THE FIRST CHARACTER IN THE NEW LINE.
C NXX,NYY - THE PARAMETER COORDINATES X AND Y IN METACODE ADDRESS UNITS.
C NIX AND NIY CAN BE USED INSTEAD.
C XX,YY - THE CENTER OF THE CHARACTER TO BE DRAWN (CONSIDERED) NEXT
C XXO,YYO - THE CENTER OF THE LAST CHARACTER DRAWN (CONSIDERED)
C BEFORE SUPER OR SUBSCRIPTING STARTED
C MX - THE DISTANCE BETWEEN THE CHARACTER CURRENTLY BEING PROCESSED AND
C THE CENTER OF THE NEXT CHARACTER TO BE PROCESSED,
C IN DIGITIZATION UNITS
C MXO LAST DISTANCE COMPUTED BEFORE SUPER OR SUBSCRIPTING STARTED
C NN - INDEX VARIABLE IN THE LOOP FOR STRIKING OUT CHARACTERS
C JX,JY - CONTAIN COORDINATES WHEN CHARACTERS ARE BEING STROKED OUT
C MXEND,MYEND - TEMPORARY STORAGE FOR COORDINATES IN TERMINAL PORTION
C IAPOST - THE CHARACTER APOSTROPHE '
C IQU - THE CHARACTER Q
C NCCG - ONLY USED FOR COMPUTED GO TO IN FUNCTION MODE CONTROL SECTION.
C NUMDUN - THE NUMBER OF DIGITIZATION UNITS CONTAINED IN ARRAY LC
C =0 NO DIGITIZATION FOUND
C INDZER - AN INDICATION FOR AN ALL-0-BITS DIGITIZATION UNIT. INDICATES
C THAT NEXT MOVE IS PEN-UP.
C
C
C
C I N I T I A L I Z A T I O N
C
C
C INITIALIZATION - ONCE PER LOADING OF ROUTINE
C
C
C CHECK IF INITIALIZATION IS ALREADY DONE.
IF (FINIT) GOTO 100
C
C Do a call forcing a BLOCKDATA to be loaded from a binary library.
C
CALL PWRXBD
C Modification for UNIX Version.
CALL OPENPW(3)
C End of modification for UNIX Version.
C Modification for UNIX Version.
CALL OPENPW(3)
C End of modification for UNIX Version.
C Modification for UNIX Version.
CALL OPENPW(3)
C End of modification for UNIX Version.
C
C FIND THE NUMBER OF BITS PER WORD
C
NBWD = I1MACH(5)
C
C COMPUTE THE NUMBER OF 15-BIT PARCELS PER WORD
C
NUM15 = NBWD/15
C
C CALCULATE THE AMOUNT OF ARRAY IND REQUIRED ON THIS MACHINE
C
INDLEN = (ICNUM1*16-1)/NUM15+1
C
C CALCULATE THE AMOUNT OF ARRAY IDD REQUIRED ON THIS MACHINE
C
IDDLEN = (ICNUM2*16*15-1)/NBWD+1
C
C CHARACTERS USED FOR COMPARISONS.
C
IAPOST = ''''
IQU = 'Q'
C
C Define the error file logical unit number
C
NUNIT = I1MACH(4)
C
C Initialize the hash table for obtaining the hollerith code of a
C character.
C
CALL HTABLE
C
C READ IN POINTER ARRAY AND CHARACTER DIGITIZATIONS
C
IF (MODE .EQ. 1) GOTO 98
C
C READ IN COMPLEX SET.
REWIND INBIN
READ(INBIN) (IND(I),I=1,INDLEN)
READ(INBIN) (IDD(I),I=1,IDDLEN)
REWIND INBIN
GOTO 97
C
98 CONTINUE
C
C READ IN DUPLEX SET.
REWIND INBIN
READ(INBIN) DUMREA
READ(INBIN) DUMREA
READ(INBIN) (IND(I),I=1,INDLEN)
READ(INBIN) (IDD(I),I=1,IDDLEN)
REWIND INBIN
97 CONTINUE
C
C SHORT TEST IF ARRAYS IDD AND IND ARE LOADED CORRECTLY.
IF (MODE .EQ. 1) CALL DCHECK(LCHERR)
IF (MODE .NE. 1) CALL CCHECK(LCHERR)
IF (LCHERR .NE. 0) THEN
CALL SETER
+ ('PWRITX - ARRAY IND OR IDD NOT LOADED CORRECTLY',LCHERR,2)
ENDIF
99 CONTINUE
C
C SET FLAG THAT INITIALIZATION IS DONE.
FINIT = .TRUE.
C
100 CONTINUE
C
C
C INITIALIZATION - ONCE PER CALL TO ROUTINE
C
C
C RETRIEVE RESOLUTION.
C
CALL GETUSV('XF',LXSAVE)
CALL GETUSV('YF',LYSAVE)
C
C DEFINE FACTOR TO CHANGE PLOTTER ADDRESS UNITS INTO METACODE UNITS.
C
METPLA = ISHIFT(1,15-10)
C
C DEFINE FACTOR TO CHANGE USER PLOTTER ADDRESS UNITS INTO METACODE UNITS
C
METUPA = ISHIFT(1,15-LXSAVE)
C
C COPY ARGUMENTS INTO LOCAL VARIABLES
C
ICTR = JCTR
IOR = JOR
ISIZE = JSIZE
N = NCHAR
C INSIDE PWRITX WE WORK ONLY WITH METACODE ADDRESS UNITS
CALL FL2INT (X,Y,NIX,NIY)
C
C SAVE THE FOLLOWING CONSTANTS FOR PASS 2
C
ID1 = IFNT
ID2 = IC
ID3 = IT
ID4 = ITO
R1 = RLX
R2 = RLY
R3 = RLOX
R4 = RLOY
C
IPASS = 1
C ONLY 1 PASS REQUIRED IF THE CHARACTER STRING IS CENTERED TO THE LEFT
IF (ICTR .EQ. -1) IPASS = 2
C
C INITIALIZATION - ONCE PER PASS THROUGH ROUTINE
C
102 CONTINUE
C POSITION PEN
CALL PLOTIT(NIX,NIY,0)
C STORE CURRENT POSITION OF PEN
C IX AND IY ARE USED FOR CARRIAGE RETURNS. THEY DEFINE THE BEGINNING
C OF THE LINE CURRENTLY BEING WRITTEN.
IX = NIX
IY = NIY
RX = NIX
RY = NIY
XXO = NIX
YYO = NIY
XX = NIX
YY = NIY
C Z MULTIPLICATION OF DIGITIZED SIZE
Z = 1. + REAL(ISIZE)/2.
IF (ISIZE .EQ. 3) Z = 3.
IF (ISIZE .GT. 3) Z = REAL(ISIZE)/21.
C TRANSLATE SIZE FROM PLOTTER ADDRESS UNITS TO METACODE ADDRESS UNITS.
Z = Z*REAL(METPLA)
C SET INTENSITY
INT = 0
IF (Z .GT. 64.) INT = 1
C T - ORIENTATION IN RADIANS
T = REAL(IOR)*DEGRAD
C COMPUTE VALUES USED TO POSITION THE SUBSEQUENT CHARACTER DEPENDING
C ON ANGLE AND FUNCTION CODE.
C NORMAL CASE.
SIT = SIN(T)
COT = COS(T)
C USED FOR SUBSCRIPT, CARRIAGE RETURN, Y INCREMENT
SIM = SIN(T-T2)
COM = COS(T-T2)
C USED FOR SUPERSCRIPT AND Y INCREMENT
SIP = SIN(T+T2)
COP = COS(T+T2)
C MAKE POSITIONING ALSO DEPENDENT ON SIZE PARAMETER
CT = Z*COT
ST = Z*SIT
C ADJUST CHARACTER HEIGHT AND WIDTH ACCORDING TO SIZE PARAMETER
RLX = RLX*Z
RLY = RLY*Z
C
MX = 0
C START PROCESSING FROM BEGINNING OF STRING
II = 0
C FUNCTION CODES DEFINED ONLY FOR A SPECIFIED NUMBER OF CHARACTERS ARE
C NOT VALID ANY MORE. UNRESTRICTED FUNCTION CODES SET IN PREVIOUS CALLS
C TO PWRX ARE STILL VALID.
C CASE.
N1 = 0
IN1 = 0
C LEVEL.
N2 = 0
IN2 = 0
C DIRECTION.
N4 = 0
IN4 = 0
C THE FOLLOWING FUNCTIONS ARE RESET FOR EACH CALL TO PWRX.
C RESET PREVIOUS CASE TO UPPER.
ICO = 0
C WRITE ACROSS FRAME.
IDFLG = 0
C THE FOLLOWING INTERNAL FLAGS ARE RESET FOR EACH CALL TO PWRX.
C PROCEED NORMALLY IN X-DIRECTION
IFLG = 0
C NO DIRECT CHARACTER ACCESS
NFLAG = .FALSE.
NF = 0
C
C
C END INITIALIZATION
C
C-----------------------------------------------------------------------
C
C
C S T A R T T O P R O C E S S D A T A S T R I N G
C
C IF IN DIRECT CHARACTER ACCESS MODE, GO TO FUNCTION PROCESSOR SECTION
104 IF (NFLAG) GO TO 125
C LET II POINT TO THE NEXT CHARACTER IN IDPC
II = II + 1
C CHECK IF NO CHARACTER LEFT IN STRING.
IF (II .GT. N) GOTO 120
C RETRIEVE CHARACTER IN NC
NC = IDPC(II:II)
C IF CHARACTER INDICATES BEGINNING OF FUNCTION CODE, GO TO FUNCTION
C PROCESSOR SECTION.
IF (NC .EQ. IAPOST) GO TO 125
C FIND ENTRY IN POINTER TABLE POINTING TO DIGITIZATION OF CHARACTER NC
CALL GETHOL (NC,NCHOL,IER2)
C ERROR IF NC IS NOT A FORTRAN CHARACTER OR AN APOSTROPHE
IF (IER2 .NE. 0) GOTO 153
INDPOI = NCHOL + IFNT + IC + IT
C CHECK IF THIS CASE IS ONLY FOR SPECIFIED NUMBER OF CHARACTERS
IF (N1 .EQ. 0) GO TO 106
C INCREMENT COUNTER FOR CHARACTERS WRITTEN IN THIS CASE
IN1 = IN1+1
C CHECK IF THIS CHARACTER IS TO BE WRITTEN DOWN
106 IF (N4 .EQ. 0) GO TO 109
C ***** PROCESS WRITING DOWN *****
C INCREMENT COUNTER FOR CHARACTERS WRITTEN DOWN
IN4 = IN4+1
C CHECK IF ALL CHARACTERS SPECIFIED HAVE BEEN WRITTEN DOWN
IF (IN4 .GT. N4) GO TO 108
C
RX = XX+RAD*COM
RY = YY+RAD*SIM
C SET FLAG TO NOT PROCEED IN X DIRECTION
107 IFLG = 1
C
MX = 0
GO TO 109
C SET FLAG THAT ALL CHARACTERS SPECIFIED HAVE BEEN WRITTEN DOWN
108 N4 = 0
C ***** END OF WRITING DOWN PROCESSING *****
C
C PROCESS ONE CHARACTER
C ---------------------
C
C RETURN DIGITIZATION OF CHARACTER IN ARRAY LC
109 CONTINUE
CALL XTCH (INDPOI,IPASS,NUMDUN)
C IF NO DIGITIZATION WAS FOUND, JUST GET NEXT CHARACTER.
IF (NUMDUN .EQ. 0) GOTO 104
C DEFINE DISTANCE FROM CENTER TO LEFT END OF CHARACTER.
L1 = LC(1)
C DEFINE DISTANCE FROM CENTER TO RIGHT END OF CHARACTER.
L2 = LC(2)
C IN THE NORMAL CASE, JUMP
IF (IFLG .EQ. 0) GO TO 111
C FOR FUNCTION CODES C, Y, AND X NO BLANK SPACE IS LEFT
L1 = 0
C RESET FLAG TO NORMAL
IFLG = 0
111 CONTINUE
C FIND THE CENTER OF THE NEXT CHARACTER TO BE DRAWN.
MX = MX - L1
XX = RX+REAL(MX)*CT
YY = RY+REAL(MX)*ST
C DO NOT STROKE OUT CHARACTERS IN PASS 1.
IF (IPASS .EQ. 1) GO TO 117
C
C STROKE OUT CHARACTER
C
NN = 1
LC(1) = INDZER
DO 113 NN = 3,NUMDUN,2
C CHECK FOR INDICATION OF PEN-UP MOVE
IF (LC(NN) .EQ. INDZER) GOTO 113
C FIND COORDINATES FOR NEXT PEN MOVE
JX = XX + (REAL(LC(NN))*CT - REAL(LC(NN+1))*ST + .5)
JY = YY + (REAL(LC(NN))*ST + REAL(LC(NN+1))*CT + .5)
C CHECK FOR PEN-UP OR PEN-DOWN
IF (LC(NN-2) .NE. INDZER) GOTO 116
C PEN-UP MOVE.
CALL PLOTIT (JX,JY,0)
GOTO 113
C PEN-DOWN MOVE.
116 CALL PLOTIT (JX,JY,1)
C
113 CONTINUE
C
C RESET VARIABLES AFTER ONE CHARACTER HAS BEEN PROCESSED
C
C
117 CONTINUE
C FIND THE RIGHT END OF THE LAST CHARACTER DRAWN.
MX = MX + L2
C ***** FIND CASE DEFINTION OF NEXT CHARACTER *****
C CHECK IF THE CURRENT CASE IS ONLY FOR A SPECIFIED NUMBER.
IF (N1 .EQ. 0) GO TO 118
C CHECK IF SPECIFIED NUMBER OF CHARACTERS HAS ALREADY BEEN DRAWN.
IF (IN1 .LT. N1) GO TO 118
C RESET INDICATORS FOR CASE SPECIFICATION.
N1 = 0
IN1 = 0
C SET CASE TO PREVIOUS CASE.
IC = ICO
C CHECK IF THE CURRENT LEVEL IS ONLY FOR SPECIFIED NUMBER OF CHARACTERS.
118 IF (N2 .EQ. 0) GO TO 104
C CHECK IF SPECIFIED NUMBER OF CHARACTERS HAS ALREADY BEEN DRAWN.
IN2 = IN2+1
IF (IN2 .LT. N2) GO TO 104
C SET LEVEL TO PREVIOUS LEVEL.
IT = ITO
C
RX = RNX
RY = RNY
C SET CHARACTER HEIGHT AND WIDTH TO PREVIOUS VALUES
RLX = RLOX
RLY = RLOY
C STOP SUPER OR SUBSCRIPTING.
N2 = 0
C CHECK IF WE WERE IN SUPER OR SUBSCRIPTING MODE BEFORE.
IF (NF .EQ. 1) GO TO 119
C YES WE WERE. RETURN TO PREVIOUS CASE.
IC = ICO
C
XX = XXO
YY = YYO
C
119 MX = MXO
C RESET FLAG FOR SUPER OR SUBSCRIPTING TO NORMAL.
NF = 0
C
L2 = L2O
C
GO TO 104
C
C TERMINAL PORTION AFTER WHOLE STRING HAS BEEN PROCESSED
C ------------------------------------------------------
C
120 CONTINUE
C RESET CHARACTER HEIGHT AND WIDTH
RLX = RLX/Z
RLY = RLY/Z
IF (IPASS .EQ. 2) THEN
CALL PLOTIT(0,0,0)
RETURN
ENDIF
C
C GET READY FOR PASS 2
C
IPASS = 2
C GET COORDINATES PASSED TO PWRX IN METACODE ADDRESS UNITS
CALL FL2INT (X,Y,NXX,NYY)
C THE COORDINATES FOR THE END OF THE CHARACTER STRING IF THE FIRST
C CHARACTER HAD BEEN POSITIONED AT THE COORDINATES PASSED TO PWRX.
MXEND = XX + REAL(L2)*CT
MYEND = YY + REAL(L2)*ST
C COMPUTE LENGTH OF CHARACTER STRING TO BE DRAWN
R = SQRT(REAL(MXEND-NXX)**2 + REAL(MYEND-NYY)**2)
C CONSIDER CENTERING OPTION
WFAC = -1.
IF (ICTR .EQ. 0) WFAC = -0.5
C COMPUTE DISPLACEMENT FROM COORDINATES PASSED TO PWRX
RCT = WFAC*R*COT
RST = WFAC*R*SIT
C CHECK FOR WRITING DOWN OR ACROSS FRAME
IF (IDFLG .EQ. 1) GO TO 122
C GET COORDINATES WHERE FIRST CHARACTER IN STRING HAS TO BE CENTERED
XDIF = MXEND - NXX
NIX = REAL(NXX) + XDIF*WFAC
YDIF = MYEND - NYY
NIY = REAL(NYY) + YDIF*WFAC
GO TO 123
C GET COORDINATES WHERE FIRST CHARACTER IN STRING HAS TO BE CENTERED
122 NIX = REAL(NXX) + RST
NIY = REAL(NYY) - RCT
C
C REINITIALIZE VARIABLES FOR PASS 2
C SET ROMAN,UPPER CASE, PRINCIPAL
C SET PREVIOUS CHARACTER SIZE ALSO TO PRINCIPAL
123 IFNT = ID1
IC = ID2
IT = ID3
ITO = ID4
RLX = R1
RLY = R2
RLOX = R3
RLOY = R4
GO TO 102
C
C-----------------------------------------------------------------------
C
C F U N C T I O N P R O C E S S O R S E C T I O N
C
C
C
C
C
C
C
C
C
C
C FUNCTION MODE CONTROL SECTION
C -----------------------------
C
125 IERR = 0
NFLAG = .FALSE.
126 CONTINUE
II = II + 1
IF (II .GT. N) GOTO 120
NC = IDPC(II:II)
C Check for an invalid function character, and pr
C an error message if one is found.
CALL GETHOL(NC, HOLIND, NERR)
IF
+ (( HOLIND .EQ. 0) .OR. (HOLIND .EQ. 47) .OR.
+ (( HOLIND .GT. 34 ) .AND. ( HOLIND .LT. 46)) .OR.
+ ( HOLIND .GT. 52) )
+THEN
IERR = IERR + 1
WRITE( NUNIT, 1001) II, IERR
IF (IERR .GT. 9) GOTO 120
GOTO 126
ENDIF
C Check to see if the character is an octal digit
IF (( NC .GE. '0') .AND. (NC .LE. '7')) THEN
C
C NUMERIC CHARACTER DEFINITION
C ----------------------------
C
C SET FLAG FOR NUMERIC CHARACTER DEFINITION
NFLAG = .TRUE.
C RETRIEVE OCTAL NUMBER IN N3
CALL GTNUMB (IDPC,N,II,N3)
C IF END OF CHARACTER STRING REACHED GO TO TERMINAL PORTION
IF (II .GT. N) GO TO 120
C CHECK IF THIS CASE IS ONLY FOR A SPECIFIED NUMBER OF CHARACTERS.
IF (N1 .NE. 0) THEN
IN1 = IN1+1
IF (IN1 .GT. N1) THEN
N1 = 0
C RETURN TO PREVIOUS CASE.
IC = ICO
ENDIF
ENDIF
C
C SEE IF THE TERMINATING CHARACTER WAS AN APOSTROPHE OR NOT. IF SO,
C SET 'NFLAG' FALSE TO SUSPEND FUNCTION-CODE SCANNING.
C
NC = IDPC(II:II)
IF (NC .EQ. IAPOST) NFLAG = .FALSE.
INDPOI = N3
GOTO 106
ENDIF
C
IF (NC .EQ. IAPOST) GOTO 104
IF (NC .EQ. ',') GOTO 126
C
C Goto the appropriate section to process the
C alphabetic function code characters
C
GOTO
C A , B, C, D, E, F, G, H, I, J, K, L, M,
+ (145,140,146,144,127,127,129,147,131,127,132,134,127,
C N, O, P, Q, R, S, T, U, V, W, X, Y, Z
+ 141,127,130,126,128,135,127,133,148,127,149,150,127)
+ HOLIND
C
C Error handling section for invalid alphabeti
C function code.
C
127 IERR = IERR + 1
WRITE( NUNIT, 1001) II, IERR
IF (IERR .GT. 9) GOTO 120
GOTO 126
C
C FONT DEFINITION
C ---------------
C
C ROMAN R 22B
C
128 CONTINUE
C DEFINE INDEX INTO POINTER TABLE
IFNT = INDROM
C GO TO GET NEXT FUNCTION CODE
GO TO 126
C
C GREEK G 07B
C
C EQUIVALENT TO ROMAN
129 CONTINUE
IFNT = INDGRE
GO TO 126
C
C SIZE DEFINITION
C ---------------
C
C PRINCIPAL SIZE P 20B
C
130 CONTINUE
C DEFINE INDEX INTO POINTER TABLE
IT = INDPRI
C SET CHARACTER WIDTH
RLX = SPRIW*Z
C SET CHARACTER HEIGHT
RLY = SPRIH*Z
C GO TO GET NEXT FUNCTION CODE
GO TO 126
C
C INDEXICAL SIZE I 11B
C
C EQUIVALENT TO PRINCIPAL SIZE DEFINITION
131 CONTINUE
IT = INDIND
RLX = SINDW*Z
RLY = SINDH*Z
GO TO 126
C
C CARTOGRAPHIC SIZE K 13B
C
C EQUIVALENT TO PRINCIPAL SIZE DEFINITION
132 CONTINUE
IT = INDCAR
RLX = SCARW*Z
RLY = SCARH*Z
GO TO 126
C
C CASE DEFINITION
C ---------------
C
C UPPER CASE U 25B
C
133 CONTINUE
C Set previous case to lower, current case to
C upper, no characters drawn in this case yet.
ICO = INDLOW
IC = INDUPP
IN1 = 0
C Set the number of characters to be drawn in upper case.
C If no number is found, then all remaining characters
C should be in upper case.
CALL GTNUM (IDPC,N,II,N1)
IF (N1 .EQ. 0) N1 = N + 1 - II
GO TO 126
C
C LOWER CASE L 14B
C
134 CONTINUE
C Set previous case to upper, current case to
C lower, no characters drawn in this case yet.
ICO = INDUPP
IC = INDLOW
IN1 = 0
C Set the number of characters to be drawn in upper case.
C If no number is found, then all remaining characters
C should be in lower case.
CALL GTNUM (IDPC,N,II,N1)
IF (N1 .EQ. 0) N1 = N + 1 - II
GO TO 126
C
C LEVEL DEFINITION
C ----------------
C
C SUPERSCRIPT S 23B
C
135 CONTINUE
C DEFINE ANGLE FROM BASE TO FIRST SUPERSCRIPTED CHARACTER.
TS = SIP
TC = COP
GOTO 136
C
C SUBSCRIPT B 02B
C
140 CONTINUE
C DEFINE ANGLE FROM BASE TO FIRST SUBSCRIPTED CHARACTER.
TS = SIM
TC = COM
C
C FOR SUPERSCRIPT AND SUBSCRIPT.
C
136 CONTINUE
C DEFINE DISTANCE FROM BASE TO FIRST SUPER OR SUBSCRIPTED CHARACTER.
RAD = SSPR*Z
IF (IT .NE. INDPRI) RAD = SSIC*Z
C REMEMBER POSITION OF BASE CHARACTER.
XXO = XX
YYO = YY
C
C FOR SUPERSCRIPT, SUBSCRIPT, AND NORMAL.
C
137 CONTINUE
C REMEMBER POSITION OF LAST CHARACTER BEFORE LEVEL CHANGE.
RNX = RX
RNY = RY
C FIND THE POSITION OF THE FIRST CHARACTER AFTER LEVEL CHANGE.
RX = XX+RAD*TC
RY = YY+RAD*TS
C RETRIEVE FOR HOW MANY CHARACTERS THE LEVEL HAS TO BE CHANGED.
IN2 = 0
CALL GTNUM (IDPC,N,II,N2)
N2 = ABS(N2)
C REMEMBER SIZE OF CHARACTERS IN PREVIOUS LEVEL.
RLOX = RLX
RLOY = RLY
C
IF (TS .EQ. SIT) GO TO 142
MXO = MX
C
MX = L2
L2O = L2
NF = 0
C REMEMBER CASE DEFINITION OF BASE CHARACTER.
ICO = IC
C REMEMBER SIZE DEFINITION OF BASE CHARACTER
ITO = IT
C ***** FIND CHARACTER SIZE AFTER LEVEL CHANGE *****
C CHECK IF BASE CHARACTER HAS PRINCIPAL SIZE DEFINITION.
IF (IT .NE. INDPRI) GO TO 139
C BASE CHARACTER HAS PRINCIPAL SIZE. THEN SUPER OR SUBSCRIPT HAS
C INDEXICAL SIZE
138 CONTINUE
IT = INDIND
RLX = SINDW*Z
RLY = SINDH*Z
GO TO 126
C BASE CHARACTER HAS INDEXICAL OR CARTOGRAPHIC SIZE. THEN SUPER OR
C SUBSCRIPT HAS CARTOGRAPHIC SIZE.
139 CONTINUE
IT = INDCAR
RLX = SCARW*Z
RLY = SCARH*Z
C CASE IS SET TO UPPER SINCE CARTOGRAPHIC DOES NOT HAVE LOWER CASE
C CHARACTERS.
IC = INDUPP
GO TO 126
C ***** CHARACTER SIZE FOR AFTER LEVEL CHANGE DEFINED *****
C
C NORMAL N 16B
C
141 CONTINUE
C ANGLE BETWEEN LAST SUPER OR SUBSCRIPTED CHARACTER AND FIRST NORMAL
C CHARACTER.
TS = SIT
TC = COT
C DISTANCE BETWEEN LAST SUPER OR SUBSCRIPTED CHARACTER AND FIRST
C NORMAL CHARACTER.
RAD = 0
IF (IT .EQ. INDIND) RAD = SSPR*Z
IF (IT .EQ. INDCAR) RAD = SSIC*Z
C GET THE CASE OF THE BASE CHARACTER.
IC = ICO
C GET THE POSITION OF THE BASE CHARACTER.
XX = XXO
YY = YYO
NF = 1
GO TO 137
C
142 CONTINUE
C ***** RESET CHARACTER SIZE WHEN RETURNING TO NORMAL LEVEL *****
IF (IT .EQ. INDPRI) GO TO 126
C
IF (IT .EQ. INDCAR .AND. ITO .EQ. INDCAR) GO TO 126
C
IF (IT .EQ. INDIND) GO TO 143
C
ITO = IT
GO TO 138
C
143 CONTINUE
C RESET CHARACTER SIZE TO PRINCIPAL.
ITO = IT
IT = INDPRI
RLX = SPRIW*Z
RLY = SPRIH*Z
C *****CHARACTER SIZE IS RESET TO NORMAL *****
GO TO 126
C
C DIRECTION DEFINITION
C --------------------
C
C WRITE DOWN D 04B
C
144 RAD = RLY
C NO CHARACTER IS CURRENTLY BEING WRITTEN DOWN
IN4 = 0
C SET FLAG FOR WRITING DOWN
IDFLG = 1
C GET NUMBER OF CHARACTERS TO BE WRITTEN DOWN
CALL GTNUM (IDPC,N,II,N4)
C IF N APPEARS WITHOUT AN N OR IF N=0 , WRITE ALL CHARACTERS DOWN
C UNTIL AN 'A' IS ENCOUNTERED OR PWRX RETURNS.
IF (N4 .EQ. 0) N4 = N
C IF N IS NEGATIVE USE ITS ABSOLUTE VALUE INSTEAD.
N4 = ABS(N4)
C GO TO INTERPRET CHARACTER NC (ALREADY FETCHED)
GO TO 126
C
C ESCAPE FROM DOWN A 01B
C
145 CONTINUE
C 0 CHARACTERS TO BE WRITTEN DOWN
N4 = 0
C *****
C RESET FLAG TO WRITING ACROSS.
IDFLG = 0
C *****
GO TO 126
C
C COORDINATE DEFINITION
C ---------------------
C
C CARRIAGE RETURN C 03B
C
146 CONTINUE
C DEFINE DISTANCE TO NEXT LINE.
RAD = RLY
MX = 0
C DEFINE POSITION OF FIRST CHARACTER IN NEXT LINE.
RX = REAL(IX)+RAD*COM
RY = REAL(IY)+RAD*SIM
XX = RX
YY = RY
C DEFINE THE BEGINNING OF THE LINE CURRENTLY BEING WRITTEN.
IX = RX
IY = RY
GO TO 126
C
C INCREMENT X H OR H Q 10B
C
147 CONTINUE
C RETRIEVE NUMBER AFTER H IN N3
CALL GTNUM (IDPC,N,II,N3)
C IF NO NUMBER IS PROVIDED IT WILL BE TAKEN TO BE 1.
IF (N3 .EQ. 0) N3 = 1
N3T1 = N3
C TRANSFORM UPA UNITS INTO METACODE UNITS.
N3 = N3*METUPA
C IF HN IS FOLLOWED BY A Q THE SHIFT IS N CHARACTER WIDTHS
NC = IDPC(II:II)
IF (NC .EQ. IQU) N3 = RLX*REAL(N3T1)
C
RX = RX + REAL(N3)
C
XX = RX+REAL(MX)*CT
YY = RY+REAL(MX)*ST
GO TO 126
C
C INCREMENT Y V OR V Q 26B
C
148 CONTINUE
C RETRIEVE NUMBER AFTER V IN N3
CALL GTNUM (IDPC,N,II,N3)
C IF NO NUMBER IS PROVIDED IT WILL BE TAKEN TO BE 1.
IF (N3 .EQ. 0) N3 = 1
N3T2 = N3
C TRANSFORM USER PLOTTER ADDRESS UNITS INTO METACODE ADDRESS UNITS.
N3 = N3*METUPA
C IF VN IS FOLLOWED BY A Q THE SHIFT IS N CHARACTER HEIGHTS
NC = IDPC(II:II)
IF (NC .EQ. IQU) N3 = RLY*REAL(N3T2)
C
RY = RY + REAL(N3)
XX = RX + REAL(MX)*CT
YY = RY + REAL(MX)*ST
GO TO 126
C
C SET X (SPECIFY CRT UNIT) X 30B
C
149 CONTINUE
C RETRIEVE NUMBER AFTER X IN N3
CALL GTNUM (IDPC,N,II,N3)
C TRANSLATE USER PLOTTER ADDRESS UNITS INTO METACODE ADDRESS UNITS.
N3 = N3*METUPA
C
RX = N3
XX = RX
YY = RY + REAL(MX)*ST
C PREPARE TO NOT PROCEED IN X DIRECTION FOR NEXT CHARACTER DRAWN.
MX = 0
IFLG = 1
C
GO TO 126
C
C SET Y (SPECIFY CRT UNIT) Y 31B
C
150 CONTINUE
C RETRIEVE NUMBER AFTER Y IN N3
CALL GTNUM (IDPC,N,II,N3)
C TRANSLATE USER PLOTTER ADDRESS UNITS INTO METACODE ADDRESS UNITS.
N3 = N3*METUPA
RY = N3
XX = RX+REAL(MX)*CT
YY = RY
GO TO 126
C
C END FUNCTION MODE PROCESSING
C
C-----------------------------------------------------------------------
C
C ESCAPE CHARACTER ERROR
C
153 CONTINUE
WRITE(NUNIT,1002)II
GO TO 104
C
1001 FORMAT(' THE ',I5,'TH CHARACTER IN IDPC IS THE ',I3,
+ 'TH ILLEGAL FUNCTION CODE.')
1002 FORMAT(' THE ',I5,'TH CHARACTER IN IDPC IS ILLEGAL')
C
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/sphere3.1_dp/shagc.f | 1 | 26520 | c
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c . .
c . copyright (c) 1998 by UCAR .
c . .
c . University Corporation for Atmospheric Research .
c . .
c . all rights reserved .
c . .
c . .
c . SPHEREPACK .
c . .
c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
c
c
c
c ... file shagc.f
c
c this file contains code and documentation for subroutines
c shagc and shagci
c
c ... files which must be loaded with shagc.f
c
c sphcom.f, hrfft.f, gaqd.f
c
c
c subroutine shagc(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,
c + wshagc,lshagc,work,lwork,ierror)
c
c subroutine shagc performs the spherical harmonic analysis
c on the array g and stores the result in the arrays a and b.
c the analysis is performed on a gaussian grid in colatitude
c and an equally spaced grid in longitude. the associated
c legendre functions are recomputed rather than stored as they
c are in subroutine shags. the analysis is described below
c at output parameters a,b.
c
c input parameters
c
c nlat the number of points in the gaussian colatitude grid on the
c full sphere. these lie in the interval (0,pi) and are compu
c in radians in theta(1),...,theta(nlat) by subroutine gaqd.
c if nlat is odd the equator will be included as the grid poi
c theta((nlat+1)/2). if nlat is even the equator will be
c excluded as a grid point and will lie half way between
c theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.
c note: on the half sphere, the number of grid points in the
c colatitudinal direction is nlat/2 if nlat is even or
c (nlat+1)/2 if nlat is odd.
c
c nlon the number of distinct londitude points. nlon determines
c the grid increment in longitude as 2*pi/nlon. for example
c nlon = 72 for a five degree grid. nlon must be greater
c than or equal to 4. the efficiency of the computation is
c improved when nlon is a product of small prime numbers.
c
c isym = 0 no symmetries exist about the equator. the analysis
c is performed on the entire sphere. i.e. on the
c array g(i,j) for i=1,...,nlat and j=1,...,nlon.
c (see description of g below)
c
c = 1 g is antisymmetric about the equator. the analysis
c is performed on the northern hemisphere only. i.e.
c if nlat is odd the analysis is performed on the
c array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.
c if nlat is even the analysis is performed on the
c array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c
c = 2 g is symmetric about the equator. the analysis is
c performed on the northern hemisphere only. i.e.
c if nlat is odd the analysis is performed on the
c array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.
c if nlat is even the analysis is performed on the
c array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.
c
c nt the number of analyses. in the program that calls shagc,
c the arrays g,a and b can be three dimensional in which
c case multiple analyses will be performed. the third
c index is the analysis index which assumes the values
c k=1,...,nt. for a single analysis set nt=1. the
c discription of the remaining parameters is simplified
c by assuming that nt=1 or that the arrays g,a and b
c have only two dimensions.
c
c g a two or three dimensional array (see input parameter
c nt) that contains the discrete function to be analyzed.
c g(i,j) contains the value of the function at the gaussian
c point theta(i) and longitude point phi(j) = (j-1)*2*pi/nlon
c the index ranges are defined above at the input parameter
c isym.
c
c idg the first dimension of the array g as it appears in the
c program that calls shagc. if isym equals zero then idg
c must be at least nlat. if isym is nonzero then idg must
c be at least nlat/2 if nlat is even or at least (nlat+1)/2
c if nlat is odd.
c
c jdg the second dimension of the array g as it appears in the
c program that calls shagc. jdg must be at least nlon.
c
c mdab the first dimension of the arrays a and b as it appears
c in the program that calls shagc. mdab must be at least
c min0((nlon+2)/2,nlat) if nlon is even or at least
c min0((nlon+1)/2,nlat) if nlon is odd
c
c ndab the second dimension of the arrays a and b as it appears
c in the program that calls shaec. ndab must be at least nlat
c
c wshagc an array which must be initialized by subroutine shagci.
c once initialized, wshagc can be used repeatedly by shagc.
c as long as nlat and nlon remain unchanged. wshagc must
c not be altered between calls of shagc.
c
c lshagc the dimension of the array wshagc as it appears in the
c program that calls shagc. define
c
c l1 = min0(nlat,(nlon+2)/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c then lshagc must be at least
c
c nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15
c
c
c work a work array that does not have to be saved.
c
c lwork the dimension of the array work as it appears in the
c program that calls shagc. define
c
c l1 = min0(nlat,(nlon+2)/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c if isym is zero then lwork must be at least
c
c nlat*(nlon*nt+max0(3*l2,nlon))
c
c if isym is not zero then lwork must be at least
c
c l2*(nlon*nt+max0(3*nlat,nlon))
c
c **************************************************************
c
c output parameters
c
c a,b both a,b are two or three dimensional arrays (see input
c parameter nt) that contain the spherical harmonic
c coefficients in the representation of g(i,j) given in the
c discription of subroutine shagc. for isym=0, a(m,n) and
c b(m,n) are given by the equations listed below. symmetric
c versions are used when isym is greater than zero.
c
c definitions
c
c 1. the normalized associated legendre functions
c
c pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))
c *sin(theta)**m/(2**n*factorial(n)) times the
c (n+m)th derivative of (x**2-1)**n with respect
c to x=cos(theta).
c
c 2. the fourier transform of g(i,j).
c
c c(m,i) = 2/nlon times the sum from j=1 to j=nlon of
c g(i,j)*cos((m-1)*(j-1)*2*pi/nlon)
c (the first and last terms in this sum
c are divided by 2)
c
c s(m,i) = 2/nlon times the sum from j=2 to j=nlon of
c g(i,j)*sin((m-1)*(j-1)*2*pi/nlon)
c
c
c 3. the gaussian points and weights on the sphere
c (computed by subroutine gaqd).
c
c theta(1),...,theta(nlat) (gaussian pts in radians)
c wts(1),...,wts(nlat) (corresponding gaussian weights)
c
c 4. the maximum (plus one) longitudinal wave number
c
c mmax = min0(nlat,(nlon+2)/2) if nlon is even or
c mmax = min0(nlat,(nlon+1)/2) if nlon is odd.
c
c
c then for m=0,...,mmax-1 and n=m,...,nlat-1 the arrays a,b
c are given by
c
c a(m+1,n+1) = the sum from i=1 to i=nlat of
c c(m+1,i)*wts(i)*pbar(m,n,theta(i))
c
c b(m+1,n+1) = the sum from i=1 to nlat of
c s(m+1,i)*wts(i)*pbar(m,n,theta(i))
c
c ierror = 0 no errors
c = 1 error in the specification of nlat
c = 2 error in the specification of nlon
c = 3 error in the specification of isym
c = 4 error in the specification of nt
c = 5 error in the specification of idg
c = 6 error in the specification of jdg
c = 7 error in the specification of mdab
c = 8 error in the specification of ndab
c = 9 error in the specification of lshagc
c = 10 error in the specification of lwork
c
c
c ****************************************************************
c
c subroutine shagci(nlat,nlon,wshagc,lshagc,dwork,ldwork,ierror)
c
c subroutine shagci initializes the array wshagc which can then
c be used repeatedly by subroutines shagc. it precomputes
c and stores in wshagc quantities such as gaussian weights,
c legendre polynomial coefficients, and fft trigonometric tables.
c
c input parameters
c
c nlat the number of points in the gaussian colatitude grid on the
c full sphere. these lie in the interval (0,pi) and are compu
c in radians in theta(1),...,theta(nlat) by subroutine gaqd.
c if nlat is odd the equator will be included as the grid poi
c theta((nlat+1)/2). if nlat is even the equator will be
c excluded as a grid point and will lie half way between
c theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.
c note: on the half sphere, the number of grid points in the
c colatitudinal direction is nlat/2 if nlat is even or
c (nlat+1)/2 if nlat is odd.
c
c nlon the number of distinct londitude points. nlon determines
c the grid increment in longitude as 2*pi/nlon. for example
c nlon = 72 for a five degree grid. nlon must be greater
c than or equal to 4. the efficiency of the computation is
c improved when nlon is a product of small prime numbers.
c
c wshagc an array which must be initialized by subroutine shagci.
c once initialized, wshagc can be used repeatedly by shagc
c as long as nlat and nlon remain unchanged. wshagc must
c not be altered between calls of shagc.
c
c lshagc the dimension of the array wshagc as it appears in the
c program that calls shagc. define
c
c l1 = min0(nlat,(nlon+2)/2) if nlon is even or
c l1 = min0(nlat,(nlon+1)/2) if nlon is odd
c
c and
c
c l2 = nlat/2 if nlat is even or
c l2 = (nlat+1)/2 if nlat is odd
c
c then lshagc must be at least
c
c nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15
c
C*PL*ERROR* Comment line too long
c dwork a double precision work array that does not have to be saved.
c
c ldwork the dimension of the array dwork as it appears in the
c program that calls shagci. ldwork must be at least
c
c nlat*(nlat+4)
c
c output parameter
c
c wshagc an array which must be initialized before calling shagc or
c once initialized, wshagc can be used repeatedly by shagc or
c as long as nlat and nlon remain unchanged. wshagc must not
c altered between calls of shagc.
c
c ierror = 0 no errors
c = 1 error in the specification of nlat
c = 2 error in the specification of nlon
c = 3 error in the specification of lshagc
c = 4 error in the specification of ldwork
c = 5 failure in gaqd to compute gaussian points
c (due to failure in eigenvalue routine)
c
c
c ****************************************************************
SUBROUTINE DSHAGC(NLAT,NLON,ISYM,NT,G,IDG,JDG,A,B,MDAB,NDAB,
+ WSHAGC,LSHAGC,WORK,LWORK,IERROR)
DOUBLE PRECISION G
DOUBLE PRECISION A
DOUBLE PRECISION B
DOUBLE PRECISION WSHAGC
DOUBLE PRECISION WORK
c subroutine shagc performs the spherical harmonic analysis on
c a gaussian grid on the array(s) in g and returns the coefficients
c in array(s) a,b. the necessary legendre polynomials are computed
c as needed in this version.
c
DIMENSION G(IDG,JDG,1),A(MDAB,NDAB,1),B(MDAB,NDAB,1),
+ WSHAGC(LSHAGC),WORK(LWORK)
c check input parameters
IERROR = 1
IF (NLAT.LT.3) RETURN
IERROR = 2
IF (NLON.LT.4) RETURN
IERROR = 3
IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN
IERROR = 4
IF (NT.LT.1) RETURN
c set upper limit on m for spherical harmonic basis
L = MIN0((NLON+2)/2,NLAT)
c set gaussian point nearest equator pointer
LATE = (NLAT+MOD(NLAT,2))/2
c set number of grid points for analysis/synthesis
LAT = NLAT
IF (ISYM.NE.0) LAT = LATE
IERROR = 5
IF (IDG.LT.LAT) RETURN
IERROR = 6
IF (JDG.LT.NLON) RETURN
IERROR = 7
IF (MDAB.LT.L) RETURN
IERROR = 8
IF (NDAB.LT.NLAT) RETURN
L1 = L
L2 = LATE
IERROR = 9
c check permanent work space length
IF (LSHAGC.LT.NLAT* (2*L2+3*L1-2)+3*L1* (1-L1)/2+NLON+15) RETURN
IERROR = 10
c check temporary work space length
IF (ISYM.EQ.0) THEN
IF (LWORK.LT.NLAT* (NLON*NT+MAX0(3*L2,NLON))) RETURN
ELSE
c isym.ne.0
IF (LWORK.LT.L2* (NLON*NT+MAX0(3*NLAT,NLON))) RETURN
END IF
IERROR = 0
c starting address for gaussian wts in shigc and fft values
IWTS = 1
IFFT = NLAT + 2*NLAT*LATE + 3* (L* (L-1)/2+ (NLAT-L)* (L-1)) + 1
c set pointers for internal storage of g and legendre polys
IPMN = LAT*NLON*NT + 1
CALL DSHAGC1(NLAT,NLON,L,LAT,ISYM,G,IDG,JDG,NT,A,B,MDAB,NDAB,
+ WSHAGC,WSHAGC(IWTS),WSHAGC(IFFT),LATE,WORK(IPMN),
+ WORK)
RETURN
END
SUBROUTINE DSHAGC1(NLAT,NLON,L,LAT,MODE,GS,IDG,JDG,NT,A,B,MDAB,
+ NDAB,W,WTS,WFFT,LATE,PMN,G)
DOUBLE PRECISION GS
DOUBLE PRECISION A
DOUBLE PRECISION B
DOUBLE PRECISION W
DOUBLE PRECISION WTS
DOUBLE PRECISION WFFT
DOUBLE PRECISION PMN
DOUBLE PRECISION G
DOUBLE PRECISION SFN
DOUBLE PRECISION T1
DOUBLE PRECISION T2
DIMENSION GS(IDG,JDG,NT),A(MDAB,NDAB,NT),B(MDAB,NDAB,NT),
+ G(LAT,NLON,NT)
DIMENSION W(1),WTS(NLAT),WFFT(1),PMN(NLAT,LATE,3)
c set gs array internally in shagc1
DO 100 K = 1,NT
DO 100 J = 1,NLON
DO 100 I = 1,LAT
G(I,J,K) = GS(I,J,K)
100 CONTINUE
c do fourier transform
DO 101 K = 1,NT
CALL DHRFFTF(LAT,NLON,G(1,1,K),LAT,WFFT,PMN)
101 CONTINUE
c scale result
SFN = 2.0D0/DBLE(NLON)
DO 102 K = 1,NT
DO 102 J = 1,NLON
DO 102 I = 1,LAT
G(I,J,K) = SFN*G(I,J,K)
102 CONTINUE
c compute using gaussian quadrature
c a(n,m) = s (ga(theta,m)*pnm(theta)*sin(theta)*dtheta)
c b(n,m) = s (gb(theta,m)*pnm(theta)*sin(theta)*dtheta)
c here ga,gb are the cos(phi),sin(phi) coefficients of
c the fourier expansion of g(theta,phi) in phi. as a result
c of the above fourier transform they are stored in array
c g as follows:
c for each theta(i) and k= l-1
c ga(0),ga(1),gb(1),ga(2),gb(2),...,ga(k-1),gb(k-1),ga(k)
c correspond to (in the case nlon=l+l-2)
c g(i,1),g(i,2),g(i,3),g(i,4),g(i,5),...,g(i,2l-4),g(i,2l-3),g(i,2l-
c initialize coefficients to zero
DO 103 K = 1,NT
DO 103 NP1 = 1,NLAT
DO 103 MP1 = 1,L
A(MP1,NP1,K) = 0.0D0
B(MP1,NP1,K) = 0.0D0
103 CONTINUE
c set m+1 limit on b(m+1) calculation
LM1 = L
IF (NLON.EQ.L+L-2) LM1 = L - 1
IF (MODE.EQ.0) THEN
c for full sphere (mode=0) and even/odd reduction:
c overwrite g(i) with (g(i)+g(nlat-i+1))*wts(i)
c overwrite g(nlat-i+1) with (g(i)-g(nlat-i+1))*wts(i)
NL2 = NLAT/2
DO 104 K = 1,NT
DO 104 J = 1,NLON
DO 105 I = 1,NL2
IS = NLAT - I + 1
T1 = G(I,J,K)
T2 = G(IS,J,K)
G(I,J,K) = WTS(I)* (T1+T2)
G(IS,J,K) = WTS(I)* (T1-T2)
105 CONTINUE
c adjust equator if necessary(nlat odd)
IF (MOD(NLAT,2).NE.0) G(LATE,J,K) = WTS(LATE)*
+ G(LATE,J,K)
104 CONTINUE
c set m = 0 coefficients first
M = 0
CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)
DO 106 K = 1,NT
DO 106 I = 1,LATE
IS = NLAT - I + 1
DO 107 NP1 = 1,NLAT,2
c n even
A(1,NP1,K) = A(1,NP1,K) + G(I,1,K)*PMN(NP1,I,KM)
107 CONTINUE
DO 108 NP1 = 2,NLAT,2
c n odd
A(1,NP1,K) = A(1,NP1,K) + G(IS,1,K)*PMN(NP1,I,KM)
108 CONTINUE
106 CONTINUE
c compute coefficients for which b(m,n) is available
DO 109 MP1 = 2,LM1
M = MP1 - 1
MP2 = M + 2
c compute pmn for all i and n=m,...,l-1
CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)
DO 110 K = 1,NT
DO 111 I = 1,LATE
IS = NLAT - I + 1
c n-m even
DO 112 NP1 = MP1,NLAT,2
A(MP1,NP1,K) = A(MP1,NP1,K) +
+ G(I,2*M,K)*PMN(NP1,I,KM)
B(MP1,NP1,K) = B(MP1,NP1,K) +
+ G(I,2*M+1,K)*PMN(NP1,I,KM)
112 CONTINUE
c n-m odd
DO 113 NP1 = MP2,NLAT,2
A(MP1,NP1,K) = A(MP1,NP1,K) +
+ G(IS,2*M,K)*PMN(NP1,I,KM)
B(MP1,NP1,K) = B(MP1,NP1,K) +
+ G(IS,2*M+1,K)*PMN(NP1,I,KM)
113 CONTINUE
111 CONTINUE
110 CONTINUE
109 CONTINUE
IF (NLON.EQ.L+L-2) THEN
c compute a(l,np1) coefficients only
M = L - 1
CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)
DO 114 K = 1,NT
DO 114 I = 1,LATE
IS = NLAT - I + 1
c n-m even
DO 124 NP1 = L,NLAT,2
A(L,NP1,K) = A(L,NP1,K) +
+ 0.5D0*G(I,NLON,K)*PMN(NP1,I,KM)
124 CONTINUE
LP1 = L + 1
c n-m odd
DO 125 NP1 = LP1,NLAT,2
A(L,NP1,K) = A(L,NP1,K) +
+ 0.5D0*G(IS,NLON,K)*PMN(NP1,I,KM)
125 CONTINUE
114 CONTINUE
END IF
ELSE
c half sphere
c overwrite g(i) with wts(i)*(g(i)+g(i)) for i=1,...,nlate/2
NL2 = NLAT/2
DO 116 K = 1,NT
DO 116 J = 1,NLON
DO 115 I = 1,NL2
G(I,J,K) = WTS(I)* (G(I,J,K)+G(I,J,K))
115 CONTINUE
c adjust equator separately if a grid point
IF (NL2.LT.LATE) G(LATE,J,K) = WTS(LATE)*G(LATE,J,K)
116 CONTINUE
c set m = 0 coefficients first
M = 0
CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)
MS = 1
IF (MODE.EQ.1) MS = 2
DO 117 K = 1,NT
DO 117 I = 1,LATE
DO 117 NP1 = MS,NLAT,2
A(1,NP1,K) = A(1,NP1,K) + G(I,1,K)*PMN(NP1,I,KM)
117 CONTINUE
c compute coefficients for which b(m,n) is available
DO 118 MP1 = 2,LM1
M = MP1 - 1
MS = MP1
IF (MODE.EQ.1) MS = MP1 + 1
c compute pmn for all i and n=m,...,nlat-1
CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)
DO 119 K = 1,NT
DO 119 I = 1,LATE
DO 119 NP1 = MS,NLAT,2
A(MP1,NP1,K) = A(MP1,NP1,K) +
+ G(I,2*M,K)*PMN(NP1,I,KM)
B(MP1,NP1,K) = B(MP1,NP1,K) +
+ G(I,2*M+1,K)*PMN(NP1,I,KM)
119 CONTINUE
118 CONTINUE
IF (NLON.EQ.L+L-2) THEN
c compute coefficient a(l,np1) only
M = L - 1
CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)
NS = L
IF (MODE.EQ.1) NS = L + 1
DO 120 K = 1,NT
DO 120 I = 1,LATE
DO 120 NP1 = NS,NLAT,2
A(L,NP1,K) = A(L,NP1,K) +
+ 0.5D0*G(I,NLON,K)*PMN(NP1,I,KM)
120 CONTINUE
END IF
END IF
RETURN
END
SUBROUTINE DSHAGCI(NLAT,NLON,WSHAGC,LSHAGC,DWORK,LDWORK,IERROR)
DOUBLE PRECISION WSHAGC
c this subroutine must be called before calling shagc with
c fixed nlat,nlon. it precomputes quantites such as the gaussian
c points and weights, m=0,m=1 legendre polynomials, recursion
c recursion coefficients.
DIMENSION WSHAGC(LSHAGC)
C*PT*WARNING* Already double-precision
DOUBLE PRECISION DWORK(LDWORK)
IERROR = 1
IF (NLAT.LT.3) RETURN
IERROR = 2
IF (NLON.LT.4) RETURN
c set triangular truncation limit for spherical harmonic basis
L = MIN0((NLON+2)/2,NLAT)
c set equator or nearest point (if excluded) pointer
LATE = (NLAT+MOD(NLAT,2))/2
L1 = L
L2 = LATE
IERROR = 3
c check permanent work space length
IF (LSHAGC.LT.NLAT* (2*L2+3*L1-2)+3*L1* (1-L1)/2+NLON+15) RETURN
IERROR = 4
IF (LDWORK.LT.NLAT* (NLAT+4)) RETURN
IERROR = 0
c set pointers
I1 = 1
I2 = I1 + NLAT
I3 = I2 + NLAT*LATE
I4 = I3 + NLAT*LATE
I5 = I4 + L* (L-1)/2 + (NLAT-L)* (L-1)
I6 = I5 + L* (L-1)/2 + (NLAT-L)* (L-1)
I7 = I6 + L* (L-1)/2 + (NLAT-L)* (L-1)
c set indices in temp work for double precision gaussian wts and pts
IDTH = 1
IDWTS = IDTH + NLAT
IW = IDWTS + NLAT
CALL DSHAGCI1(NLAT,NLON,L,LATE,WSHAGC(I1),WSHAGC(I2),WSHAGC(I3),
+ WSHAGC(I4),WSHAGC(I5),WSHAGC(I6),WSHAGC(I7),
+ DWORK(IDTH),DWORK(IDWTS),DWORK(IW),IERROR)
IF (IERROR.NE.0) IERROR = 5
RETURN
END
SUBROUTINE DSHAGCI1(NLAT,NLON,L,LATE,WTS,P0N,P1N,ABEL,BBEL,CBEL,
+ WFFT,DTHETA,DWTS,WORK,IER)
DOUBLE PRECISION WTS
DOUBLE PRECISION P0N
DOUBLE PRECISION P1N
DOUBLE PRECISION ABEL
DOUBLE PRECISION BBEL
DOUBLE PRECISION CBEL
DOUBLE PRECISION WFFT
DOUBLE PRECISION FN
DOUBLE PRECISION FM
DIMENSION WTS(NLAT),P0N(NLAT,LATE),P1N(NLAT,LATE),ABEL(1),BBEL(1),
+ CBEL(1),WFFT(1)
C*PT*WARNING* Already double-precision
DOUBLE PRECISION PB,DTHETA(NLAT),DWTS(NLAT),WORK(*),W
c compute the nlat gaussian points and weights, the
c m=0,1 legendre polys for gaussian points and all n,
c and the legendre recursion coefficients
c define index function used in storing
c arrays for recursion coefficients (functions of (m,n))
c the index function indx(m,n) is defined so that
c the pairs (m,n) map to [1,2,...,indx(l-1,l-1)] with no
c "holes" as m varies from 2 to n and n varies from 2 to l-1.
c (m=0,1 are set from p0n,p1n for all n)
c define for 2.le.n.le.l-1
INDX(M,N) = (N-1)* (N-2)/2 + M - 1
c define index function for l.le.n.le.nlat
IMNDX(M,N) = L* (L-1)/2 + (N-L-1)* (L-1) + M - 1
c preset quantites for fourier transform
CALL DHRFFTI(NLON,WFFT)
c compute double precision gaussian points and weights
c lw = 4*nlat*(nlat+1)+2
LW = NLAT* (NLAT+2)
CALL DGAQD(NLAT,DTHETA,DWTS,W,LW,IER)
IF (IER.NE.0) RETURN
c store gaussian weights single precision to save computation
c in inner loops in analysis
DO 100 I = 1,NLAT
WTS(I) = DWTS(I)
100 CONTINUE
c initialize p0n,p1n using double precision dnlfk,dnlft
DO 101 NP1 = 1,NLAT
DO 101 I = 1,LATE
P0N(NP1,I) = 0.0D0
P1N(NP1,I) = 0.0D0
101 CONTINUE
c compute m=n=0 legendre polynomials for all theta(i)
NP1 = 1
N = 0
M = 0
CALL DDNLFK(M,N,WORK)
DO 103 I = 1,LATE
CALL DDNLFT(M,N,DTHETA(I),WORK,PB)
P0N(1,I) = PB
103 CONTINUE
c compute p0n,p1n for all theta(i) when n.gt.0
DO 104 NP1 = 2,NLAT
N = NP1 - 1
M = 0
CALL DDNLFK(M,N,WORK)
DO 105 I = 1,LATE
CALL DDNLFT(M,N,DTHETA(I),WORK,PB)
P0N(NP1,I) = PB
105 CONTINUE
c compute m=1 legendre polynomials for all n and theta(i)
M = 1
CALL DDNLFK(M,N,WORK)
DO 106 I = 1,LATE
CALL DDNLFT(M,N,DTHETA(I),WORK,PB)
P1N(NP1,I) = PB
106 CONTINUE
104 CONTINUE
c compute and store swarztrauber recursion coefficients
c for 2.le.m.le.n and 2.le.n.le.nlat in abel,bbel,cbel
DO 107 N = 2,NLAT
FN = DBLE(N)
MLIM = MIN0(N,L)
DO 107 M = 2,MLIM
FM = DBLE(M)
IMN = INDX(M,N)
IF (N.GE.L) IMN = IMNDX(M,N)
ABEL(IMN) = DSQRT(((2*FN+1)* (FM+FN-2)* (FM+FN-3))/
+ (((2*FN-3)* (FM+FN-1)* (FM+FN))))
BBEL(IMN) = DSQRT(((2*FN+1)* (FN-FM-1)* (FN-FM))/
+ (((2*FN-3)* (FM+FN-1)* (FM+FN))))
CBEL(IMN) = DSQRT(((FN-FM+1)* (FN-FM+2))/
+ (((FN+FM-1)* (FN+FM))))
107 CONTINUE
RETURN
END
| gpl-2.0 |
TApplencourt/quantum_package | src/determinants/fock_diag.irp.f | 1 | 2944 | subroutine build_fock_tmp(fock_diag_tmp,det_ref,Nint)
use bitmasks
implicit none
BEGIN_DOC
! Build the diagonal of the Fock matrix corresponding to a generator
! determinant. $F_{00}$ is $\langle i|H|i \rangle = E_0$.
END_DOC
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: det_ref(Nint,2)
double precision, intent(out) :: fock_diag_tmp(2,mo_num+1)
integer :: occ(Nint*bit_kind_size,2)
integer :: ne(2), i, j, ii, jj
double precision :: E0
! Compute Fock matrix diagonal elements
call bitstring_to_list_ab(det_ref,occ,Ne,Nint)
fock_diag_tmp = 0.d0
E0 = 0.d0
if (Ne(1) /= elec_alpha_num) then
print *, 'Error in build_fock_tmp (alpha)', Ne(1), Ne(2)
call debug_det(det_ref,N_int)
stop -1
endif
if (Ne(2) /= elec_beta_num) then
print *, 'Error in build_fock_tmp (beta)', Ne(1), Ne(2)
call debug_det(det_ref,N_int)
stop -1
endif
! Occupied MOs
do ii=1,elec_alpha_num
i = occ(ii,1)
fock_diag_tmp(1,i) = fock_diag_tmp(1,i) + mo_one_e_integrals(i,i)
E0 = E0 + mo_one_e_integrals(i,i)
do jj=1,elec_alpha_num
j = occ(jj,1)
if (i==j) cycle
fock_diag_tmp(1,i) = fock_diag_tmp(1,i) + mo_two_e_integrals_jj_anti(i,j)
E0 = E0 + 0.5d0*mo_two_e_integrals_jj_anti(i,j)
enddo
do jj=1,elec_beta_num
j = occ(jj,2)
fock_diag_tmp(1,i) = fock_diag_tmp(1,i) + mo_two_e_integrals_jj(i,j)
E0 = E0 + mo_two_e_integrals_jj(i,j)
enddo
enddo
do ii=1,elec_beta_num
i = occ(ii,2)
fock_diag_tmp(2,i) = fock_diag_tmp(2,i) + mo_one_e_integrals(i,i)
E0 = E0 + mo_one_e_integrals(i,i)
do jj=1,elec_beta_num
j = occ(jj,2)
if (i==j) cycle
fock_diag_tmp(2,i) = fock_diag_tmp(2,i) + mo_two_e_integrals_jj_anti(i,j)
E0 = E0 + 0.5d0*mo_two_e_integrals_jj_anti(i,j)
enddo
do jj=1,elec_alpha_num
j = occ(jj,1)
fock_diag_tmp(2,i) = fock_diag_tmp(2,i) + mo_two_e_integrals_jj(i,j)
enddo
enddo
! Virtual MOs
do i=1,mo_num
if (fock_diag_tmp(1,i) /= 0.d0) cycle
fock_diag_tmp(1,i) = fock_diag_tmp(1,i) + mo_one_e_integrals(i,i)
do jj=1,elec_alpha_num
j = occ(jj,1)
fock_diag_tmp(1,i) = fock_diag_tmp(1,i) + mo_two_e_integrals_jj_anti(i,j)
enddo
do jj=1,elec_beta_num
j = occ(jj,2)
fock_diag_tmp(1,i) = fock_diag_tmp(1,i) + mo_two_e_integrals_jj(i,j)
enddo
enddo
do i=1,mo_num
if (fock_diag_tmp(2,i) /= 0.d0) cycle
fock_diag_tmp(2,i) = fock_diag_tmp(2,i) + mo_one_e_integrals(i,i)
do jj=1,elec_beta_num
j = occ(jj,2)
fock_diag_tmp(2,i) = fock_diag_tmp(2,i) + mo_two_e_integrals_jj_anti(i,j)
enddo
do jj=1,elec_alpha_num
j = occ(jj,1)
fock_diag_tmp(2,i) = fock_diag_tmp(2,i) + mo_two_e_integrals_jj(i,j)
enddo
enddo
fock_diag_tmp(1,mo_num+1) = E0
fock_diag_tmp(2,mo_num+1) = E0
end
| gpl-3.0 |
mtrbean/scipy | scipy/integrate/odepack/xerrwv.f | 155 | 5250 | subroutine xerrwv (msg, nmes, nerr, level, ni, i1, i2, nr, r1, r2)
integer msg, nmes, nerr, level, ni, i1, i2, nr,
1 i, lun, lunit, mesflg, ncpw, nch, nwds
double precision r1, r2
dimension msg(nmes)
c-----------------------------------------------------------------------
c subroutines xerrwv, xsetf, and xsetun, as given here, constitute
c a simplified version of the slatec error handling package.
c written by a. c. hindmarsh at llnl. version of march 30, 1987.
c this version is in double precision.
c
c all arguments are input arguments.
c
c msg = the message (hollerith literal or integer array).
c nmes = the length of msg (number of characters).
c nerr = the error number (not used).
c level = the error level..
c 0 or 1 means recoverable (control returns to caller).
c 2 means fatal (run is aborted--see note below).
c ni = number of integers (0, 1, or 2) to be printed with message.
c i1,i2 = integers to be printed, depending on ni.
c nr = number of reals (0, 1, or 2) to be printed with message.
c r1,r2 = reals to be printed, depending on nr.
c
c note.. this routine is machine-dependent and specialized for use
c in limited context, in the following ways..
c 1. the number of hollerith characters stored per word, denoted
c by ncpw below, is a data-loaded constant.
c 2. the value of nmes is assumed to be at most 60.
c (multi-line messages are generated by repeated calls.)
c 3. if level = 2, control passes to the statement stop
c to abort the run. this statement may be machine-dependent.
c 4. r1 and r2 are assumed to be in double precision and are printed
c in d21.13 format.
c 5. the common block /eh0001/ below is data-loaded (a machine-
c dependent feature) with default values.
c this block is needed for proper retention of parameters used by
c this routine which the user can reset by calling xsetf or xsetun.
c the variables in this block are as follows..
c mesflg = print control flag..
c 1 means print all messages (the default).
c 0 means no printing.
c lunit = logical unit number for messages.
c the default is 6 (machine-dependent).
c-----------------------------------------------------------------------
c the following are instructions for installing this routine
c in different machine environments.
c
c to change the default output unit, change the data statement
c in the block data subprogram below.
c
c for a different number of characters per word, change the
c data statement setting ncpw below, and format 10. alternatives for
c various computers are shown in comment cards.
c
c for a different run-abort command, change the statement following
c statement 100 at the end.
c-----------------------------------------------------------------------
common /eh0001/ mesflg, lunit
c-----------------------------------------------------------------------
c the following data-loaded value of ncpw is valid for the cdc-6600
c and cdc-7600 computers.
c data ncpw/10/
c the following is valid for the cray-1 computer.
c data ncpw/8/
c the following is valid for the burroughs 6700 and 7800 computers.
c data ncpw/6/
c the following is valid for the pdp-10 computer.
c data ncpw/5/
c the following is valid for the vax computer with 4 bytes per integer,
c and for the ibm-360, ibm-370, ibm-303x, and ibm-43xx computers.
data ncpw/4/
c the following is valid for the pdp-11, or vax with 2-byte integers.
c data ncpw/2/
c-----------------------------------------------------------------------
if (mesflg .eq. 0) go to 100
c get logical unit number. ---------------------------------------------
lun = lunit
c get number of words in message. --------------------------------------
nch = min0(nmes,60)
nwds = nch/ncpw
if (nch .ne. nwds*ncpw) nwds = nwds + 1
c write the message. ---------------------------------------------------
write (lun, 10) (msg(i),i=1,nwds)
c-----------------------------------------------------------------------
c the following format statement is to have the form
c 10 format(1x,mmann)
c where nn = ncpw and mm is the smallest integer .ge. 60/ncpw.
c the following is valid for ncpw = 10.
c 10 format(1x,6a10)
c the following is valid for ncpw = 8.
c 10 format(1x,8a8)
c the following is valid for ncpw = 6.
c 10 format(1x,10a6)
c the following is valid for ncpw = 5.
c 10 format(1x,12a5)
c the following is valid for ncpw = 4.
10 format(1x,15a4)
c the following is valid for ncpw = 2.
c 10 format(1x,30a2)
c-----------------------------------------------------------------------
if (ni .eq. 1) write (lun, 20) i1
20 format(6x,'in above message, i1 =',i10)
if (ni .eq. 2) write (lun, 30) i1,i2
30 format(6x,'in above message, i1 =',i10,3x,'i2 =',i10)
if (nr .eq. 1) write (lun, 40) r1
40 format(6x,'in above message, r1 =',d21.13)
if (nr .eq. 2) write (lun, 50) r1,r2
50 format(6x,'in above, r1 =',d21.13,3x,'r2 =',d21.13)
c abort the run if level = 2. ------------------------------------------
100 if (level .ne. 2) return
stop
c----------------------- end of subroutine xerrwv ----------------------
end
| bsd-3-clause |
marshallward/mom | src/mom5/ocean_param/gotm-4.0/turbulence/cmue_sg.F90 | 10 | 3380 | #include"cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
! !ROUTINE: The Schumann and Gerz (1995) stability function\label{sec:sg}
!
! !INTERFACE:
subroutine cmue_sg(nlev)
!
! !DESCRIPTION:
! This subroutine computes stability functions according to
! \begin{equation}
! c_{\mu}=c_{\mu}^0,\qquad c'_{\mu}=\frac{c_{\mu}^0}{Pr_t}
! \end{equation}
! with constant $c_{\mu}^0$. Based simulation data on stratified homogeneous
! shear-flows, \cite{SchumannGerz95} proposed the empirical relation
! for the turbulent Prandtl--number,
! \begin{equation}
! Pr_t = Pr_t^0 \exp\left(-\frac{Ri}{Pr_t^0 Ri^{\infty}}\right)
! -\frac{Ri}{Ri^{\infty}}
! \comma
! \end{equation}
! where where $Ri$ is the gradient Richardson--number and $Pr_t^0$
! is the turbulent Prandtl--number for $Ri \rightarrow 0$. $Pr_t^0$
! and the fixed value $c_\mu^0$ have to be set in {\tt gotmturb.nml}.
! \cite{SchumannGerz95} suggested $Pr_t^0=0.74$ and $Ri^{\infty}=0.25$.
!
! !USES:
use turbulence, only: Prandtl0_fix,cm0_fix
use turbulence, only: cmue1,cmue2,as,an
IMPLICIT NONE
!
! !INPUT PARAMETERS:
integer, intent(in) :: nlev
!
! !REVISION HISTORY:
! Original author(s): Hans Burchard & Karsten Bolding
!
! $Log: cmue_sg.F90,v $
! Revision 20.0 2013/12/14 00:13:34 fms
! Merged revision 1.1.2.1 onto trunk
!
! Revision 1.1.2.1 2012/05/15 16:00:53 smg
! initial cvs ci for these modules to mom5.
! AUTHOR:Griffies
! REVIEWERS:
! TEST STATUS:
! CHANGES PUBLIC INTERFACES?
! CHANGES ANSWERS?
!
! Revision 1.1.2.1.390.1 2012/04/23 20:30:29 smg
! updated to the gotm-2012.03.09 CVS tag.
! AUTHOR:Martin Schmidt
! REVIEWERS:Griffies
! TEST STATUS:
! CHANGES PUBLIC INTERFACES?
! CHANGES ANSWERS?
!
! Revision 1.9 2010-09-17 12:53:52 jorn
! extensive code clean-up to ensure proper initialization and clean-up of all variables
!
! Revision 1.8 2007-01-06 11:49:15 kbk
! namelist file extension changed .inp --> .nml
!
! Revision 1.7 2005/11/15 11:35:02 lars
! documentation finish for print
!
! Revision 1.6 2005/07/18 08:54:56 lars
! changed docu for html compliance
!
! Revision 1.5 2005/06/27 13:44:07 kbk
! modified + removed traling blanks
!
! Revision 1.4 2004/08/18 12:53:07 lars
! updated documentation
!
! Revision 1.3 2003/03/28 09:20:35 kbk
! added new copyright to files
!
! Revision 1.2 2003/03/10 09:02:04 gotm
! Added new Generic Turbulence Model +
! improved documentation and cleaned up code
!
! Revision 1.1.1.1 2001/02/12 15:55:58 gotm
! initial import into CVS
!
!EOP
!
! !LOCAL VARIABLES:
integer :: i
REALTYPE :: Ri,Prandtl
REALTYPE,parameter :: limit=3.
!
!-----------------------------------------------------------------------
!BOC
do i=1,nlev-1
Ri=an(i)/(as(i)+1.e-8) ! Gradient Richardson number
if (Ri.ge.1e-10) then
Prandtl=Prandtl0_fix*exp(-Ri/(Prandtl0_fix*0.25))+Ri/0.25
else
Prandtl=Prandtl0_fix
end if
cmue1(i)=cm0_fix
cmue2(i)=cm0_fix/min(limit,Prandtl)
end do
return
end subroutine cmue_sg
!EOC
!-----------------------------------------------------------------------
! Copyright by the GOTM-team under the GNU Public License - www.gnu.org
!-----------------------------------------------------------------------
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/csyr.f | 2 | 5983 | SUBROUTINE CSYR( UPLO, N, ALPHA, X, INCX, A, LDA )
*
* -- 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 ..
CHARACTER UPLO
INTEGER INCX, LDA, N
COMPLEX ALPHA
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * ), X( * )
* ..
*
* Purpose
* =======
*
* CSYR performs the symmetric rank 1 operation
*
* A := alpha*x*( x' ) + A,
*
* where alpha is a complex scalar, x is an n element vector and A is an
* n by n symmetric matrix.
*
* Arguments
* ==========
*
* UPLO - CHARACTER*1
* On entry, UPLO specifies whether the upper or lower
* triangular part of the array A is to be referenced as
* follows:
*
* UPLO = 'U' or 'u' Only the upper triangular part of A
* is to be referenced.
*
* UPLO = 'L' or 'l' Only the lower triangular part of A
* is to be referenced.
*
* Unchanged on exit.
*
* N - INTEGER
* On entry, N specifies the order of the matrix A.
* N must be at least zero.
* Unchanged on exit.
*
* ALPHA - COMPLEX
* On entry, ALPHA specifies the scalar alpha.
* Unchanged on exit.
*
* X - 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.
*
* INCX - INTEGER
* On entry, INCX specifies the increment for the elements of
* X. INCX must not be zero.
* Unchanged on exit.
*
* A - COMPLEX array, dimension ( LDA, N )
* Before entry, with UPLO = 'U' or 'u', the leading n by n
* upper triangular part of the array A must contain the upper
* triangular part of the symmetric matrix and the strictly
* lower triangular part of A is not referenced. On exit, the
* upper triangular part of the array A is overwritten by the
* upper triangular part of the updated matrix.
* Before entry, with UPLO = 'L' or 'l', the leading n by n
* lower triangular part of the array A must contain the lower
* triangular part of the symmetric matrix and the strictly
* upper triangular part of A is not referenced. On exit, the
* lower triangular part of the array A is overwritten by the
* lower triangular part of the updated matrix.
*
* LDA - INTEGER
* On entry, LDA specifies the first dimension of A as declared
* in the calling (sub) program. LDA must be at least
* max( 1, N ).
* Unchanged on exit.
*
* =====================================================================
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
INTEGER I, INFO, IX, J, JX, KX
COMPLEX TEMP
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. 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
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = 7
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CSYR ', 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 A are
* accessed sequentially with one pass through the triangular part
* of A.
*
IF( LSAME( UPLO, 'U' ) ) THEN
*
* Form A when A is stored in upper triangle.
*
IF( INCX.EQ.1 ) THEN
DO 20 J = 1, N
IF( X( J ).NE.ZERO ) THEN
TEMP = ALPHA*X( J )
DO 10 I = 1, J
A( I, J ) = A( I, J ) + X( I )*TEMP
10 CONTINUE
END IF
20 CONTINUE
ELSE
JX = KX
DO 40 J = 1, N
IF( X( JX ).NE.ZERO ) THEN
TEMP = ALPHA*X( JX )
IX = KX
DO 30 I = 1, J
A( I, J ) = A( I, J ) + X( IX )*TEMP
IX = IX + INCX
30 CONTINUE
END IF
JX = JX + INCX
40 CONTINUE
END IF
ELSE
*
* Form A when A is stored in lower triangle.
*
IF( INCX.EQ.1 ) THEN
DO 60 J = 1, N
IF( X( J ).NE.ZERO ) THEN
TEMP = ALPHA*X( J )
DO 50 I = J, N
A( I, J ) = A( I, J ) + X( I )*TEMP
50 CONTINUE
END IF
60 CONTINUE
ELSE
JX = KX
DO 80 J = 1, N
IF( X( JX ).NE.ZERO ) THEN
TEMP = ALPHA*X( JX )
IX = JX
DO 70 I = J, N
A( I, J ) = A( I, J ) + X( IX )*TEMP
IX = IX + INCX
70 CONTINUE
END IF
JX = JX + INCX
80 CONTINUE
END IF
END IF
*
RETURN
*
* End of CSYR
*
END
| gpl-2.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/allocate_error_2.f90 | 181 | 1104 | ! { dg-do compile }
program main
type t1
integer, allocatable :: x(:)
integer, allocatable :: y(:)
end type t1
type(t1), allocatable :: v(:)
allocate (v(3), v(4)) ! { dg-error "Allocate-object at \\(1\\) also appears at \\(2\\)" }
allocate (v(1), v(1)%x(2)) ! { dg-error "Allocate-object at \\(1\\) is subobject of object at \\(2\\)" }
allocate (v(1)%x(2), v(1)) ! { dg-error "Allocate-object at \\(1\\) is subobject of object at \\(2\\)" }
allocate (v(1)%y(2), v(1)%x(1))
allocate (v(2)%x(3), v(2)%x(3)) ! { dg-error "Allocate-object at \\(1\\) also appears at \\(2\\)" }
allocate (v(1)%x(3), v(2)%x(3))
deallocate (v, v) ! { dg-error "Allocate-object at \\(1\\) also appears at \\(2\\)" }
deallocate (v, v(1)%x) ! { dg-error "Allocate-object at \\(1\\) is subobject of object at \\(2\\)" }
deallocate (v(1)%x, v) ! { dg-error "Allocate-object at \\(1\\) is subobject of object at \\(2\\)" }
deallocate (v(1)%y, v(1)%x)
deallocate (v(2)%x, v(2)%x) ! { dg-error "Allocate-object at \\(1\\) also appears at \\(2\\)" }
deallocate (v(1)%x, v(2)%x)
end program main
| gpl-2.0 |
alexchenfeng/mathcosmos | src/numerical/slatec/fortran/dqage.f | 14 | 14036 | *DECK DQAGE
SUBROUTINE DQAGE (F, A, B, EPSABS, EPSREL, KEY, LIMIT, RESULT,
+ ABSERR, NEVAL, IER, ALIST, BLIST, RLIST, ELIST, IORD, LAST)
C***BEGIN PROLOGUE DQAGE
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-RESLT).LE.MAX(EPSABS,EPSREL*ABS(I)).
C***LIBRARY SLATEC (QUADPACK)
C***CATEGORY H2A1A1
C***TYPE DOUBLE PRECISION (QAGE-S, DQAGE-D)
C***KEYWORDS AUTOMATIC INTEGRATOR, GAUSS-KRONROD RULES,
C GENERAL-PURPOSE, GLOBALLY ADAPTIVE, INTEGRAND EXAMINATOR,
C QUADPACK, QUADRATURE
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 a definite integral
C Standard fortran subroutine
C Double precision version
C
C PARAMETERS
C ON ENTRY
C F - Double precision
C Function subprogram defining the integrand
C function F(X). The actual name for F needs to be
C declared E X T E R N A L in the driver program.
C
C A - Double precision
C Lower limit of integration
C
C B - Double precision
C Upper limit of integration
C
C 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 KEY - Integer
C Key for choice of local integration rule
C A Gauss-Kronrod pair is used with
C 7 - 15 points if KEY.LT.2,
C 10 - 21 points if KEY = 2,
C 15 - 31 points if KEY = 3,
C 20 - 41 points if KEY = 4,
C 25 - 51 points if KEY = 5,
C 30 - 61 points if KEY.GT.5.
C
C LIMIT - Integer
C Gives an upper bound on the number of subintervals
C in the partition of (A,B), LIMIT.GE.1.
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 result and error are
C less reliable. It is assumed that the
C requested accuracy has not been achieved.
C ERROR MESSAGES
C IER = 1 Maximum number of subdivisions allowed
C has been achieved. One can allow more
C subdivisions by increasing the value
C of LIMIT.
C However, if this yields no improvement it
C is rather advised to analyze the integrand
C in order to determine the 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 the integrator on the
C subranges. If possible, an appropriate
C special-purpose integrator should be used
C which is designed for handling the type of
C difficulty involved.
C = 2 The occurrence of roundoff error is
C detected, which prevents the requested
C tolerance from being achieved.
C = 3 Extremely bad integrand behaviour occurs
C at some points of the integration
C interval.
C = 6 The input is invalid, because
C (EPSABS.LE.0 and
C EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
C RESULT, ABSERR, NEVAL, LAST, RLIST(1) ,
C ELIST(1) and IORD(1) are set to zero.
C ALIST(1) and BLIST(1) are set to A and B
C respectively.
C
C ALIST - Double precision
C Vector of dimension at least LIMIT, the first
C LAST elements of which are the left
C end points of the subintervals in the partition
C of the given integration range (A,B)
C
C BLIST - Double precision
C Vector of dimension at least LIMIT, the first
C LAST elements of which are the right
C end points of the subintervals in the partition
C of the given integration range (A,B)
C
C RLIST - Double precision
C Vector of dimension at least LIMIT, the first
C LAST elements of which are the
C integral approximations on the subintervals
C
C ELIST - Double precision
C Vector of dimension at least LIMIT, the first
C LAST elements of which are the moduli of the
C absolute error estimates on the subintervals
C
C IORD - Integer
C Vector of dimension at least LIMIT, the first K
C elements of which are pointers to the
C error estimates over the subintervals,
C such that ELIST(IORD(1)), ...,
C ELIST(IORD(K)) form a decreasing sequence,
C with K = LAST if LAST.LE.(LIMIT/2+2), and
C K = LIMIT+1-LAST otherwise
C
C LAST - Integer
C Number of subintervals actually produced in the
C subdivision process
C
C***REFERENCES (NONE)
C***ROUTINES CALLED D1MACH, DQK15, DQK21, DQK31, DQK41, DQK51, DQK61,
C DQPSRT
C***REVISION HISTORY (YYMMDD)
C 800101 DATE WRITTEN
C 890531 Changed all specific intrinsics to generic. (WRB)
C 890831 Modified array declarations. (WRB)
C 890831 REVISION DATE from Version 3.2
C 891214 Prologue converted to Version 4.0 format. (BAB)
C***END PROLOGUE DQAGE
C
DOUBLE PRECISION A,ABSERR,ALIST,AREA,AREA1,AREA12,AREA2,A1,A2,B,
1 BLIST,B1,B2,DEFABS,DEFAB1,DEFAB2,D1MACH,ELIST,EPMACH,
2 EPSABS,EPSREL,ERRBND,ERRMAX,ERROR1,ERROR2,ERRO12,ERRSUM,F,
3 RESABS,RESULT,RLIST,UFLOW
INTEGER IER,IORD,IROFF1,IROFF2,K,KEY,KEYF,LAST,LIMIT,MAXERR,NEVAL,
1 NRMAX
C
DIMENSION ALIST(*),BLIST(*),ELIST(*),IORD(*),
1 RLIST(*)
C
EXTERNAL F
C
C LIST OF MAJOR VARIABLES
C -----------------------
C
C ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
C CONSIDERED UP TO NOW
C BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
C CONSIDERED UP TO NOW
C RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER
C (ALIST(I),BLIST(I))
C ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)
C MAXERR - POINTER TO THE INTERVAL WITH LARGEST
C ERROR ESTIMATE
C ERRMAX - ELIST(MAXERR)
C AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
C ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS
C ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
C ABS(RESULT))
C *****1 - VARIABLE FOR THE LEFT SUBINTERVAL
C *****2 - VARIABLE FOR THE RIGHT SUBINTERVAL
C LAST - INDEX FOR SUBDIVISION
C
C
C MACHINE DEPENDENT CONSTANTS
C ---------------------------
C
C EPMACH IS THE LARGEST RELATIVE SPACING.
C UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
C
C***FIRST EXECUTABLE STATEMENT DQAGE
EPMACH = D1MACH(4)
UFLOW = D1MACH(1)
C
C TEST ON VALIDITY OF PARAMETERS
C ------------------------------
C
IER = 0
NEVAL = 0
LAST = 0
RESULT = 0.0D+00
ABSERR = 0.0D+00
ALIST(1) = A
BLIST(1) = B
RLIST(1) = 0.0D+00
ELIST(1) = 0.0D+00
IORD(1) = 0
IF(EPSABS.LE.0.0D+00.AND.
1 EPSREL.LT.MAX(0.5D+02*EPMACH,0.5D-28)) IER = 6
IF(IER.EQ.6) GO TO 999
C
C FIRST APPROXIMATION TO THE INTEGRAL
C -----------------------------------
C
KEYF = KEY
IF(KEY.LE.0) KEYF = 1
IF(KEY.GE.7) KEYF = 6
NEVAL = 0
IF(KEYF.EQ.1) CALL DQK15(F,A,B,RESULT,ABSERR,DEFABS,RESABS)
IF(KEYF.EQ.2) CALL DQK21(F,A,B,RESULT,ABSERR,DEFABS,RESABS)
IF(KEYF.EQ.3) CALL DQK31(F,A,B,RESULT,ABSERR,DEFABS,RESABS)
IF(KEYF.EQ.4) CALL DQK41(F,A,B,RESULT,ABSERR,DEFABS,RESABS)
IF(KEYF.EQ.5) CALL DQK51(F,A,B,RESULT,ABSERR,DEFABS,RESABS)
IF(KEYF.EQ.6) CALL DQK61(F,A,B,RESULT,ABSERR,DEFABS,RESABS)
LAST = 1
RLIST(1) = RESULT
ELIST(1) = ABSERR
IORD(1) = 1
C
C TEST ON ACCURACY.
C
ERRBND = MAX(EPSABS,EPSREL*ABS(RESULT))
IF(ABSERR.LE.0.5D+02*EPMACH*DEFABS.AND.ABSERR.GT.ERRBND) IER = 2
IF(LIMIT.EQ.1) IER = 1
IF(IER.NE.0.OR.(ABSERR.LE.ERRBND.AND.ABSERR.NE.RESABS)
1 .OR.ABSERR.EQ.0.0D+00) GO TO 60
C
C INITIALIZATION
C --------------
C
C
ERRMAX = ABSERR
MAXERR = 1
AREA = RESULT
ERRSUM = ABSERR
NRMAX = 1
IROFF1 = 0
IROFF2 = 0
C
C MAIN DO-LOOP
C ------------
C
DO 30 LAST = 2,LIMIT
C
C BISECT THE SUBINTERVAL WITH THE LARGEST ERROR ESTIMATE.
C
A1 = ALIST(MAXERR)
B1 = 0.5D+00*(ALIST(MAXERR)+BLIST(MAXERR))
A2 = B1
B2 = BLIST(MAXERR)
IF(KEYF.EQ.1) CALL DQK15(F,A1,B1,AREA1,ERROR1,RESABS,DEFAB1)
IF(KEYF.EQ.2) CALL DQK21(F,A1,B1,AREA1,ERROR1,RESABS,DEFAB1)
IF(KEYF.EQ.3) CALL DQK31(F,A1,B1,AREA1,ERROR1,RESABS,DEFAB1)
IF(KEYF.EQ.4) CALL DQK41(F,A1,B1,AREA1,ERROR1,RESABS,DEFAB1)
IF(KEYF.EQ.5) CALL DQK51(F,A1,B1,AREA1,ERROR1,RESABS,DEFAB1)
IF(KEYF.EQ.6) CALL DQK61(F,A1,B1,AREA1,ERROR1,RESABS,DEFAB1)
IF(KEYF.EQ.1) CALL DQK15(F,A2,B2,AREA2,ERROR2,RESABS,DEFAB2)
IF(KEYF.EQ.2) CALL DQK21(F,A2,B2,AREA2,ERROR2,RESABS,DEFAB2)
IF(KEYF.EQ.3) CALL DQK31(F,A2,B2,AREA2,ERROR2,RESABS,DEFAB2)
IF(KEYF.EQ.4) CALL DQK41(F,A2,B2,AREA2,ERROR2,RESABS,DEFAB2)
IF(KEYF.EQ.5) CALL DQK51(F,A2,B2,AREA2,ERROR2,RESABS,DEFAB2)
IF(KEYF.EQ.6) CALL DQK61(F,A2,B2,AREA2,ERROR2,RESABS,DEFAB2)
C
C IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL
C AND ERROR AND TEST FOR ACCURACY.
C
NEVAL = NEVAL+1
AREA12 = AREA1+AREA2
ERRO12 = ERROR1+ERROR2
ERRSUM = ERRSUM+ERRO12-ERRMAX
AREA = AREA+AREA12-RLIST(MAXERR)
IF(DEFAB1.EQ.ERROR1.OR.DEFAB2.EQ.ERROR2) GO TO 5
IF(ABS(RLIST(MAXERR)-AREA12).LE.0.1D-04*ABS(AREA12)
1 .AND.ERRO12.GE.0.99D+00*ERRMAX) IROFF1 = IROFF1+1
IF(LAST.GT.10.AND.ERRO12.GT.ERRMAX) IROFF2 = IROFF2+1
5 RLIST(MAXERR) = AREA1
RLIST(LAST) = AREA2
ERRBND = MAX(EPSABS,EPSREL*ABS(AREA))
IF(ERRSUM.LE.ERRBND) GO TO 8
C
C TEST FOR ROUNDOFF ERROR AND EVENTUALLY SET ERROR FLAG.
C
IF(IROFF1.GE.6.OR.IROFF2.GE.20) IER = 2
C
C SET ERROR FLAG IN THE CASE THAT THE NUMBER OF SUBINTERVALS
C EQUALS LIMIT.
C
IF(LAST.EQ.LIMIT) IER = 1
C
C SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
C AT A POINT OF THE INTEGRATION RANGE.
C
IF(MAX(ABS(A1),ABS(B2)).LE.(0.1D+01+0.1D+03*
1 EPMACH)*(ABS(A2)+0.1D+04*UFLOW)) IER = 3
C
C APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
C
8 IF(ERROR2.GT.ERROR1) GO TO 10
ALIST(LAST) = A2
BLIST(MAXERR) = B1
BLIST(LAST) = B2
ELIST(MAXERR) = ERROR1
ELIST(LAST) = ERROR2
GO TO 20
10 ALIST(MAXERR) = A2
ALIST(LAST) = A1
BLIST(LAST) = B1
RLIST(MAXERR) = AREA2
RLIST(LAST) = AREA1
ELIST(MAXERR) = ERROR2
ELIST(LAST) = ERROR1
C
C CALL SUBROUTINE DQPSRT TO MAINTAIN THE DESCENDING ORDERING
C IN THE LIST OF ERROR ESTIMATES AND SELECT THE SUBINTERVAL
C WITH THE LARGEST ERROR ESTIMATE (TO BE BISECTED NEXT).
C
20 CALL DQPSRT(LIMIT,LAST,MAXERR,ERRMAX,ELIST,IORD,NRMAX)
C ***JUMP OUT OF DO-LOOP
IF(IER.NE.0.OR.ERRSUM.LE.ERRBND) GO TO 40
30 CONTINUE
C
C COMPUTE FINAL RESULT.
C ---------------------
C
40 RESULT = 0.0D+00
DO 50 K=1,LAST
RESULT = RESULT+RLIST(K)
50 CONTINUE
ABSERR = ERRSUM
60 IF(KEYF.NE.1) NEVAL = (10*KEYF+1)*(2*NEVAL+1)
IF(KEYF.EQ.1) NEVAL = 30*NEVAL+15
999 RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/ezmap/mdinch.f | 1 | 1269 | C
C $Id: mdinch.f,v 1.8 2008-09-18 00:42:17 kennison Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE MDINCH (INUM,CHRS,NCHR)
C
C This routine, when given an integer INUM (which should be in the
C range from 0 to 999, inclusive) and a character buffer CHRS already
C containing NCHS characters, adds the character representation of
C the integer to the buffer.
C
INTEGER INUM
CHARACTER*(*) CHRS
INTEGER NCHR
C
C Declare local variables.
C
INTEGER IDIG,ITMP
C
C Don't trust the user ... :-)
C
ITMP=MAX(0,MIN(999,ABS(INUM)))
C
C Decide whether 3, 2, or 1 characters will be generated and increment
C NCHR appropriately.
C
IF (ITMP.GE.100) THEN
NCHR=NCHR+3
ELSE IF (ITMP.GE.10) THEN
NCHR=NCHR+2
ELSE
NCHR=NCHR+1
END IF
C
C Generate the characters (in reverse order) and store them.
C
IDIG=0
C
101 CHRS(NCHR-IDIG:NCHR-IDIG)=CHAR(ICHAR('0')+MOD(ITMP,10))
ITMP=ITMP/10
IDIG=IDIG+1
IF (ITMP.NE.0) GO TO 101
C
C Done.
C
RETURN
C
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/blas/ssymm.f | 11 | 9832 | SUBROUTINE SSYMM ( SIDE, UPLO, M, N, ALPHA, A, LDA, B, LDB,
$ BETA, C, LDC )
* .. Scalar Arguments ..
CHARACTER*1 SIDE, UPLO
INTEGER M, N, LDA, LDB, LDC
REAL ALPHA, BETA
* .. Array Arguments ..
REAL A( LDA, * ), B( LDB, * ), C( LDC, * )
* ..
*
* Purpose
* =======
*
* SSYMM performs one of the matrix-matrix operations
*
* C := alpha*A*B + beta*C,
*
* or
*
* C := alpha*B*A + beta*C,
*
* where alpha and beta are scalars, A is a symmetric matrix and B and
* C are m by n matrices.
*
* Parameters
* ==========
*
* SIDE - CHARACTER*1.
* On entry, SIDE specifies whether the symmetric matrix A
* appears on the left or right in the operation as follows:
*
* SIDE = 'L' or 'l' C := alpha*A*B + beta*C,
*
* SIDE = 'R' or 'r' C := alpha*B*A + beta*C,
*
* Unchanged on exit.
*
* UPLO - CHARACTER*1.
* On entry, UPLO specifies whether the upper or lower
* triangular part of the symmetric matrix A is to be
* referenced as follows:
*
* UPLO = 'U' or 'u' Only the upper triangular part of the
* symmetric matrix is to be referenced.
*
* UPLO = 'L' or 'l' Only the lower triangular part of the
* symmetric matrix is to be referenced.
*
* Unchanged on exit.
*
* M - INTEGER.
* On entry, M specifies the number of rows of the matrix C.
* M must be at least zero.
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the number of columns of the matrix C.
* N must be at least zero.
* Unchanged on exit.
*
* ALPHA - REAL .
* On entry, ALPHA specifies the scalar alpha.
* Unchanged on exit.
*
* A - REAL array of DIMENSION ( LDA, ka ), where ka is
* m when SIDE = 'L' or 'l' and is n otherwise.
* Before entry with SIDE = 'L' or 'l', the m by m part of
* the array A must contain the symmetric matrix, such that
* when UPLO = 'U' or 'u', the leading m by m upper triangular
* part of the array A must contain the upper triangular part
* of the symmetric matrix and the strictly lower triangular
* part of A is not referenced, and when UPLO = 'L' or 'l',
* the leading m by m lower triangular part of the array A
* must contain the lower triangular part of the symmetric
* matrix and the strictly upper triangular part of A is not
* referenced.
* Before entry with SIDE = 'R' or 'r', the n by n part of
* the array A must contain the symmetric matrix, such that
* when UPLO = 'U' or 'u', the leading n by n upper triangular
* part of the array A must contain the upper triangular part
* of the symmetric matrix and the strictly lower triangular
* part of A is not referenced, and when UPLO = 'L' or 'l',
* the leading n by n lower triangular part of the array A
* must contain the lower triangular part of the symmetric
* matrix and the strictly upper triangular part of A is not
* referenced.
* Unchanged on exit.
*
* LDA - INTEGER.
* On entry, LDA specifies the first dimension of A as declared
* in the calling (sub) program. When SIDE = 'L' or 'l' then
* LDA must be at least max( 1, m ), otherwise LDA must be at
* least max( 1, n ).
* Unchanged on exit.
*
* B - REAL array of DIMENSION ( LDB, n ).
* Before entry, the leading m by n part of the array B must
* contain the matrix B.
* Unchanged on exit.
*
* LDB - INTEGER.
* On entry, LDB specifies the first dimension of B as declared
* in the calling (sub) program. LDB must be at least
* max( 1, m ).
* Unchanged on exit.
*
* BETA - REAL .
* On entry, BETA specifies the scalar beta. When BETA is
* supplied as zero then C need not be set on input.
* Unchanged on exit.
*
* C - REAL array of DIMENSION ( LDC, n ).
* Before entry, the leading m by n part of the array C must
* contain the matrix C, except when beta is zero, in which
* case C need not be set on entry.
* On exit, the array C is overwritten by the m by n updated
* matrix.
*
* LDC - INTEGER.
* On entry, LDC specifies the first dimension of C as declared
* in the calling (sub) program. LDC must be at least
* max( 1, m ).
* Unchanged on exit.
*
*
* Level 3 Blas routine.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
*
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* .. External Subroutines ..
EXTERNAL XERBLA
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Local Scalars ..
LOGICAL UPPER
INTEGER I, INFO, J, K, NROWA
REAL TEMP1, TEMP2
* .. Parameters ..
REAL ONE , ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Executable Statements ..
*
* Set NROWA as the number of rows of A.
*
IF( LSAME( SIDE, 'L' ) )THEN
NROWA = M
ELSE
NROWA = N
END IF
UPPER = LSAME( UPLO, 'U' )
*
* Test the input parameters.
*
INFO = 0
IF( ( .NOT.LSAME( SIDE, 'L' ) ).AND.
$ ( .NOT.LSAME( SIDE, 'R' ) ) )THEN
INFO = 1
ELSE IF( ( .NOT.UPPER ).AND.
$ ( .NOT.LSAME( UPLO, 'L' ) ) )THEN
INFO = 2
ELSE IF( M .LT.0 )THEN
INFO = 3
ELSE IF( N .LT.0 )THEN
INFO = 4
ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN
INFO = 7
ELSE IF( LDB.LT.MAX( 1, M ) )THEN
INFO = 9
ELSE IF( LDC.LT.MAX( 1, M ) )THEN
INFO = 12
END IF
IF( INFO.NE.0 )THEN
CALL XERBLA( 'SSYMM ', INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.
$ ( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )
$ RETURN
*
* And when alpha.eq.zero.
*
IF( ALPHA.EQ.ZERO )THEN
IF( BETA.EQ.ZERO )THEN
DO 20, J = 1, N
DO 10, I = 1, M
C( I, J ) = ZERO
10 CONTINUE
20 CONTINUE
ELSE
DO 40, J = 1, N
DO 30, I = 1, M
C( I, J ) = BETA*C( I, J )
30 CONTINUE
40 CONTINUE
END IF
RETURN
END IF
*
* Start the operations.
*
IF( LSAME( SIDE, 'L' ) )THEN
*
* Form C := alpha*A*B + beta*C.
*
IF( UPPER )THEN
DO 70, J = 1, N
DO 60, I = 1, M
TEMP1 = ALPHA*B( I, J )
TEMP2 = ZERO
DO 50, K = 1, I - 1
C( K, J ) = C( K, J ) + TEMP1 *A( K, I )
TEMP2 = TEMP2 + B( K, J )*A( K, I )
50 CONTINUE
IF( BETA.EQ.ZERO )THEN
C( I, J ) = TEMP1*A( I, I ) + ALPHA*TEMP2
ELSE
C( I, J ) = BETA *C( I, J ) +
$ TEMP1*A( I, I ) + ALPHA*TEMP2
END IF
60 CONTINUE
70 CONTINUE
ELSE
DO 100, J = 1, N
DO 90, I = M, 1, -1
TEMP1 = ALPHA*B( I, J )
TEMP2 = ZERO
DO 80, K = I + 1, M
C( K, J ) = C( K, J ) + TEMP1 *A( K, I )
TEMP2 = TEMP2 + B( K, J )*A( K, I )
80 CONTINUE
IF( BETA.EQ.ZERO )THEN
C( I, J ) = TEMP1*A( I, I ) + ALPHA*TEMP2
ELSE
C( I, J ) = BETA *C( I, J ) +
$ TEMP1*A( I, I ) + ALPHA*TEMP2
END IF
90 CONTINUE
100 CONTINUE
END IF
ELSE
*
* Form C := alpha*B*A + beta*C.
*
DO 170, J = 1, N
TEMP1 = ALPHA*A( J, J )
IF( BETA.EQ.ZERO )THEN
DO 110, I = 1, M
C( I, J ) = TEMP1*B( I, J )
110 CONTINUE
ELSE
DO 120, I = 1, M
C( I, J ) = BETA*C( I, J ) + TEMP1*B( I, J )
120 CONTINUE
END IF
DO 140, K = 1, J - 1
IF( UPPER )THEN
TEMP1 = ALPHA*A( K, J )
ELSE
TEMP1 = ALPHA*A( J, K )
END IF
DO 130, I = 1, M
C( I, J ) = C( I, J ) + TEMP1*B( I, K )
130 CONTINUE
140 CONTINUE
DO 160, K = J + 1, N
IF( UPPER )THEN
TEMP1 = ALPHA*A( J, K )
ELSE
TEMP1 = ALPHA*A( K, J )
END IF
DO 150, I = 1, M
C( I, J ) = C( I, J ) + TEMP1*B( I, K )
150 CONTINUE
160 CONTINUE
170 CONTINUE
END IF
*
RETURN
*
* End of SSYMM .
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ngmath/src/examples/enatgrid/nnex02.f | 1 | 2197 |
PROGRAM NNEX02
C
C Simple example of natural neighbor linear regridding.
C
PARAMETER(ISLIM = 6, NUMXOUT = 21, NUMYOUT = 21)
C
C Dimension for the work space for the NCAR Graphics call to
C SRFACE to plot the interpolated grid.
C
PARAMETER(IDIM=2*NUMXOUT*NUMYOUT)
C
C Define the error file, the Fortran unit number, the workstation type,
C and the workstation ID to be used in calls to GKS routines.
C
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript
C
PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1)
C
C Input data arrays.
C
REAL X(ISLIM), Y(ISLIM), Z(ISLIM)
C
C Output grid arrays.
C
REAL XI(NUMXOUT), YI(NUMYOUT), ZI(NUMXOUT,NUMYOUT)
C
C Define the input data arrays.
C
DATA X/0.00, 1.00, 0.00, 1.00, 0.40, 0.75 /
DATA Y/0.00, 0.00, 1.00, 1.00, 0.20, 0.65 /
DATA Z/0.00, 0.00, 0.00, 0.00, 1.25, 0.80 /
C
DIMENSION IWORK(IDIM)
C
C Define the output grid.
C
XMIN = 0.
XMAX = 1.
XINC = (XMAX-XMIN)/(NUMXOUT-1.)
DO 20 I=1,NUMXOUT
XI(I) = XMIN+REAL(I-1) * XINC
20 CONTINUE
C
YMAX = 1.
YMIN = 0.
YINC = (YMAX-YMIN)/(NUMYOUT-1.)
DO 30 J=1,NUMYOUT
YI(J) = YMIN+REAL(J-1) * YINC
30 CONTINUE
C
C Set the flag for using estimated gradients.
C
CALL NNSETI('IGR',1)
C
C Do the regridding.
C
CALL NATGRIDS(ISLIM,X,Y,Z,NUMXOUT,NUMYOUT,XI,YI,ZI,IER)
IF (IER .NE. 0) THEN
WRITE (6,510) IER
510 FORMAT('Error return from NATGRIDS = ',I3)
ENDIF
C
C Draw a plot of the interpolated surface.
C
C
C Open GKS and define the foreground and background color.
C
CALL GOPKS (IERRF, ISZDM)
CALL GOPWK (IWKID, LUNIT, IWTYPE)
CALL GACWK (IWKID)
C
CALL GSCR(IWKID, 0, 1.00, 1.00, 1.00)
CALL GSCR(IWKID, 1, 0.00, 0.00, 0.00)
C
CALL DRWSRF(NUMXOUT,NUMYOUT,XI,YI,ZI,15.,-25.,90.,IWORK)
C
C Close GKS.
C
CALL GDAWK (IWKID)
CALL GCLWK (IWKID)
CALL GCLKS
C
STOP
END
| gpl-2.0 |
alexchenfeng/mathcosmos | share/lapack/lapack/fortran/zlaqr2.f | 9 | 17433 | *> \brief \b ZLAQR2
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ZLAQR2 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlaqr2.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlaqr2.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlaqr2.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE ZLAQR2( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
* IHIZ, Z, LDZ, NS, ND, SH, V, LDV, NH, T, LDT,
* NV, WV, LDWV, WORK, LWORK )
*
* .. Scalar Arguments ..
* INTEGER IHIZ, ILOZ, KBOT, KTOP, LDH, LDT, LDV, LDWV,
* $ LDZ, LWORK, N, ND, NH, NS, NV, NW
* LOGICAL WANTT, WANTZ
* ..
* .. Array Arguments ..
* COMPLEX*16 H( LDH, * ), SH( * ), T( LDT, * ), V( LDV, * ),
* $ WORK( * ), WV( LDWV, * ), Z( LDZ, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZLAQR2 is identical to ZLAQR3 except that it avoids
*> recursion by calling ZLAHQR instead of ZLAQR4.
*>
*> Aggressive early deflation:
*>
*> ZLAQR2 accepts as input an upper Hessenberg matrix
*> H and performs an unitary similarity transformation
*> designed to detect and deflate fully converged eigenvalues from
*> a trailing principal submatrix. On output H has been over-
*> written by a new Hessenberg matrix that is a perturbation of
*> an unitary similarity transformation of H. It is to be
*> hoped that the final version of H has many zero subdiagonal
*> entries.
*>
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] WANTT
*> \verbatim
*> WANTT is LOGICAL
*> If .TRUE., then the Hessenberg matrix H is fully updated
*> so that the triangular Schur factor may be
*> computed (in cooperation with the calling subroutine).
*> If .FALSE., then only enough of H is updated to preserve
*> the eigenvalues.
*> \endverbatim
*>
*> \param[in] WANTZ
*> \verbatim
*> WANTZ is LOGICAL
*> If .TRUE., then the unitary matrix Z is updated so
*> so that the unitary Schur factor may be computed
*> (in cooperation with the calling subroutine).
*> If .FALSE., then Z is not referenced.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix H and (if WANTZ is .TRUE.) the
*> order of the unitary matrix Z.
*> \endverbatim
*>
*> \param[in] KTOP
*> \verbatim
*> KTOP is INTEGER
*> It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
*> KBOT and KTOP together determine an isolated block
*> along the diagonal of the Hessenberg matrix.
*> \endverbatim
*>
*> \param[in] KBOT
*> \verbatim
*> KBOT is INTEGER
*> It is assumed without a check that either
*> KBOT = N or H(KBOT+1,KBOT)=0. KBOT and KTOP together
*> determine an isolated block along the diagonal of the
*> Hessenberg matrix.
*> \endverbatim
*>
*> \param[in] NW
*> \verbatim
*> NW is INTEGER
*> Deflation window size. 1 .LE. NW .LE. (KBOT-KTOP+1).
*> \endverbatim
*>
*> \param[in,out] H
*> \verbatim
*> H is COMPLEX*16 array, dimension (LDH,N)
*> On input the initial N-by-N section of H stores the
*> Hessenberg matrix undergoing aggressive early deflation.
*> On output H has been transformed by a unitary
*> similarity transformation, perturbed, and the returned
*> to Hessenberg form that (it is to be hoped) has some
*> zero subdiagonal entries.
*> \endverbatim
*>
*> \param[in] LDH
*> \verbatim
*> LDH is integer
*> Leading dimension of H just as declared in the calling
*> subroutine. N .LE. LDH
*> \endverbatim
*>
*> \param[in] ILOZ
*> \verbatim
*> ILOZ is INTEGER
*> \endverbatim
*>
*> \param[in] IHIZ
*> \verbatim
*> IHIZ is INTEGER
*> Specify the rows of Z to which transformations must be
*> applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N.
*> \endverbatim
*>
*> \param[in,out] Z
*> \verbatim
*> Z is COMPLEX*16 array, dimension (LDZ,N)
*> IF WANTZ is .TRUE., then on output, the unitary
*> similarity transformation mentioned above has been
*> accumulated into Z(ILOZ:IHIZ,ILO:IHI) from the right.
*> If WANTZ is .FALSE., then Z is unreferenced.
*> \endverbatim
*>
*> \param[in] LDZ
*> \verbatim
*> LDZ is integer
*> The leading dimension of Z just as declared in the
*> calling subroutine. 1 .LE. LDZ.
*> \endverbatim
*>
*> \param[out] NS
*> \verbatim
*> NS is integer
*> The number of unconverged (ie approximate) eigenvalues
*> returned in SR and SI that may be used as shifts by the
*> calling subroutine.
*> \endverbatim
*>
*> \param[out] ND
*> \verbatim
*> ND is integer
*> The number of converged eigenvalues uncovered by this
*> subroutine.
*> \endverbatim
*>
*> \param[out] SH
*> \verbatim
*> SH is COMPLEX*16 array, dimension KBOT
*> On output, approximate eigenvalues that may
*> be used for shifts are stored in SH(KBOT-ND-NS+1)
*> through SR(KBOT-ND). Converged eigenvalues are
*> stored in SH(KBOT-ND+1) through SH(KBOT).
*> \endverbatim
*>
*> \param[out] V
*> \verbatim
*> V is COMPLEX*16 array, dimension (LDV,NW)
*> An NW-by-NW work array.
*> \endverbatim
*>
*> \param[in] LDV
*> \verbatim
*> LDV is integer scalar
*> The leading dimension of V just as declared in the
*> calling subroutine. NW .LE. LDV
*> \endverbatim
*>
*> \param[in] NH
*> \verbatim
*> NH is integer scalar
*> The number of columns of T. NH.GE.NW.
*> \endverbatim
*>
*> \param[out] T
*> \verbatim
*> T is COMPLEX*16 array, dimension (LDT,NW)
*> \endverbatim
*>
*> \param[in] LDT
*> \verbatim
*> LDT is integer
*> The leading dimension of T just as declared in the
*> calling subroutine. NW .LE. LDT
*> \endverbatim
*>
*> \param[in] NV
*> \verbatim
*> NV is integer
*> The number of rows of work array WV available for
*> workspace. NV.GE.NW.
*> \endverbatim
*>
*> \param[out] WV
*> \verbatim
*> WV is COMPLEX*16 array, dimension (LDWV,NW)
*> \endverbatim
*>
*> \param[in] LDWV
*> \verbatim
*> LDWV is integer
*> The leading dimension of W just as declared in the
*> calling subroutine. NW .LE. LDV
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is COMPLEX*16 array, dimension LWORK.
*> On exit, WORK(1) is set to an estimate of the optimal value
*> of LWORK for the given values of N, NW, KTOP and KBOT.
*> \endverbatim
*>
*> \param[in] LWORK
*> \verbatim
*> LWORK is integer
*> The dimension of the work array WORK. LWORK = 2*NW
*> suffices, but greater efficiency may result from larger
*> values of LWORK.
*>
*> If LWORK = -1, then a workspace query is assumed; ZLAQR2
*> only estimates the optimal workspace size for the given
*> values of N, NW, KTOP and KBOT. The estimate is returned
*> in WORK(1). No error message related to LWORK is issued
*> by XERBLA. Neither H nor Z are accessed.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup complex16OTHERauxiliary
*
*> \par Contributors:
* ==================
*>
*> Karen Braman and Ralph Byers, Department of Mathematics,
*> University of Kansas, USA
*>
* =====================================================================
SUBROUTINE ZLAQR2( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
$ IHIZ, Z, LDZ, NS, ND, SH, V, LDV, NH, T, LDT,
$ NV, WV, LDWV, WORK, LWORK )
*
* -- LAPACK auxiliary routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
INTEGER IHIZ, ILOZ, KBOT, KTOP, LDH, LDT, LDV, LDWV,
$ LDZ, LWORK, N, ND, NH, NS, NV, NW
LOGICAL WANTT, WANTZ
* ..
* .. Array Arguments ..
COMPLEX*16 H( LDH, * ), SH( * ), T( LDT, * ), V( LDV, * ),
$ WORK( * ), WV( LDWV, * ), Z( LDZ, * )
* ..
*
* ================================================================
*
* .. Parameters ..
COMPLEX*16 ZERO, ONE
PARAMETER ( ZERO = ( 0.0d0, 0.0d0 ),
$ ONE = ( 1.0d0, 0.0d0 ) )
DOUBLE PRECISION RZERO, RONE
PARAMETER ( RZERO = 0.0d0, RONE = 1.0d0 )
* ..
* .. Local Scalars ..
COMPLEX*16 BETA, CDUM, S, TAU
DOUBLE PRECISION FOO, SAFMAX, SAFMIN, SMLNUM, ULP
INTEGER I, IFST, ILST, INFO, INFQR, J, JW, KCOL, KLN,
$ KNT, KROW, KWTOP, LTOP, LWK1, LWK2, LWKOPT
* ..
* .. External Functions ..
DOUBLE PRECISION DLAMCH
EXTERNAL DLAMCH
* ..
* .. External Subroutines ..
EXTERNAL DLABAD, ZCOPY, ZGEHRD, ZGEMM, ZLACPY, ZLAHQR,
$ ZLARF, ZLARFG, ZLASET, ZTREXC, ZUNMHR
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, INT, MAX, MIN
* ..
* .. Statement Functions ..
DOUBLE PRECISION CABS1
* ..
* .. Statement Function definitions ..
CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
* ..
* .. Executable Statements ..
*
* ==== Estimate optimal workspace. ====
*
JW = MIN( NW, KBOT-KTOP+1 )
IF( JW.LE.2 ) THEN
LWKOPT = 1
ELSE
*
* ==== Workspace query call to ZGEHRD ====
*
CALL ZGEHRD( JW, 1, JW-1, T, LDT, WORK, WORK, -1, INFO )
LWK1 = INT( WORK( 1 ) )
*
* ==== Workspace query call to ZUNMHR ====
*
CALL ZUNMHR( 'R', 'N', JW, JW, 1, JW-1, T, LDT, WORK, V, LDV,
$ WORK, -1, INFO )
LWK2 = INT( WORK( 1 ) )
*
* ==== Optimal workspace ====
*
LWKOPT = JW + MAX( LWK1, LWK2 )
END IF
*
* ==== Quick return in case of workspace query. ====
*
IF( LWORK.EQ.-1 ) THEN
WORK( 1 ) = DCMPLX( LWKOPT, 0 )
RETURN
END IF
*
* ==== Nothing to do ...
* ... for an empty active block ... ====
NS = 0
ND = 0
WORK( 1 ) = ONE
IF( KTOP.GT.KBOT )
$ RETURN
* ... nor for an empty deflation window. ====
IF( NW.LT.1 )
$ RETURN
*
* ==== Machine constants ====
*
SAFMIN = DLAMCH( 'SAFE MINIMUM' )
SAFMAX = RONE / SAFMIN
CALL DLABAD( SAFMIN, SAFMAX )
ULP = DLAMCH( 'PRECISION' )
SMLNUM = SAFMIN*( DBLE( N ) / ULP )
*
* ==== Setup deflation window ====
*
JW = MIN( NW, KBOT-KTOP+1 )
KWTOP = KBOT - JW + 1
IF( KWTOP.EQ.KTOP ) THEN
S = ZERO
ELSE
S = H( KWTOP, KWTOP-1 )
END IF
*
IF( KBOT.EQ.KWTOP ) THEN
*
* ==== 1-by-1 deflation window: not much to do ====
*
SH( KWTOP ) = H( KWTOP, KWTOP )
NS = 1
ND = 0
IF( CABS1( S ).LE.MAX( SMLNUM, ULP*CABS1( H( KWTOP,
$ KWTOP ) ) ) ) THEN
NS = 0
ND = 1
IF( KWTOP.GT.KTOP )
$ H( KWTOP, KWTOP-1 ) = ZERO
END IF
WORK( 1 ) = ONE
RETURN
END IF
*
* ==== Convert to spike-triangular form. (In case of a
* . rare QR failure, this routine continues to do
* . aggressive early deflation using that part of
* . the deflation window that converged using INFQR
* . here and there to keep track.) ====
*
CALL ZLACPY( 'U', JW, JW, H( KWTOP, KWTOP ), LDH, T, LDT )
CALL ZCOPY( JW-1, H( KWTOP+1, KWTOP ), LDH+1, T( 2, 1 ), LDT+1 )
*
CALL ZLASET( 'A', JW, JW, ZERO, ONE, V, LDV )
CALL ZLAHQR( .true., .true., JW, 1, JW, T, LDT, SH( KWTOP ), 1,
$ JW, V, LDV, INFQR )
*
* ==== Deflation detection loop ====
*
NS = JW
ILST = INFQR + 1
DO 10 KNT = INFQR + 1, JW
*
* ==== Small spike tip deflation test ====
*
FOO = CABS1( T( NS, NS ) )
IF( FOO.EQ.RZERO )
$ FOO = CABS1( S )
IF( CABS1( S )*CABS1( V( 1, NS ) ).LE.MAX( SMLNUM, ULP*FOO ) )
$ THEN
*
* ==== One more converged eigenvalue ====
*
NS = NS - 1
ELSE
*
* ==== One undeflatable eigenvalue. Move it up out of the
* . way. (ZTREXC can not fail in this case.) ====
*
IFST = NS
CALL ZTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, INFO )
ILST = ILST + 1
END IF
10 CONTINUE
*
* ==== Return to Hessenberg form ====
*
IF( NS.EQ.0 )
$ S = ZERO
*
IF( NS.LT.JW ) THEN
*
* ==== sorting the diagonal of T improves accuracy for
* . graded matrices. ====
*
DO 30 I = INFQR + 1, NS
IFST = I
DO 20 J = I + 1, NS
IF( CABS1( T( J, J ) ).GT.CABS1( T( IFST, IFST ) ) )
$ IFST = J
20 CONTINUE
ILST = I
IF( IFST.NE.ILST )
$ CALL ZTREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, INFO )
30 CONTINUE
END IF
*
* ==== Restore shift/eigenvalue array from T ====
*
DO 40 I = INFQR + 1, JW
SH( KWTOP+I-1 ) = T( I, I )
40 CONTINUE
*
*
IF( NS.LT.JW .OR. S.EQ.ZERO ) THEN
IF( NS.GT.1 .AND. S.NE.ZERO ) THEN
*
* ==== Reflect spike back into lower triangle ====
*
CALL ZCOPY( NS, V, LDV, WORK, 1 )
DO 50 I = 1, NS
WORK( I ) = DCONJG( WORK( I ) )
50 CONTINUE
BETA = WORK( 1 )
CALL ZLARFG( NS, BETA, WORK( 2 ), 1, TAU )
WORK( 1 ) = ONE
*
CALL ZLASET( 'L', JW-2, JW-2, ZERO, ZERO, T( 3, 1 ), LDT )
*
CALL ZLARF( 'L', NS, JW, WORK, 1, DCONJG( TAU ), T, LDT,
$ WORK( JW+1 ) )
CALL ZLARF( 'R', NS, NS, WORK, 1, TAU, T, LDT,
$ WORK( JW+1 ) )
CALL ZLARF( 'R', JW, NS, WORK, 1, TAU, V, LDV,
$ WORK( JW+1 ) )
*
CALL ZGEHRD( JW, 1, NS, T, LDT, WORK, WORK( JW+1 ),
$ LWORK-JW, INFO )
END IF
*
* ==== Copy updated reduced window into place ====
*
IF( KWTOP.GT.1 )
$ H( KWTOP, KWTOP-1 ) = S*DCONJG( V( 1, 1 ) )
CALL ZLACPY( 'U', JW, JW, T, LDT, H( KWTOP, KWTOP ), LDH )
CALL ZCOPY( JW-1, T( 2, 1 ), LDT+1, H( KWTOP+1, KWTOP ),
$ LDH+1 )
*
* ==== Accumulate orthogonal matrix in order update
* . H and Z, if requested. ====
*
IF( NS.GT.1 .AND. S.NE.ZERO )
$ CALL ZUNMHR( 'R', 'N', JW, NS, 1, NS, T, LDT, WORK, V, LDV,
$ WORK( JW+1 ), LWORK-JW, INFO )
*
* ==== Update vertical slab in H ====
*
IF( WANTT ) THEN
LTOP = 1
ELSE
LTOP = KTOP
END IF
DO 60 KROW = LTOP, KWTOP - 1, NV
KLN = MIN( NV, KWTOP-KROW )
CALL ZGEMM( 'N', 'N', KLN, JW, JW, ONE, H( KROW, KWTOP ),
$ LDH, V, LDV, ZERO, WV, LDWV )
CALL ZLACPY( 'A', KLN, JW, WV, LDWV, H( KROW, KWTOP ), LDH )
60 CONTINUE
*
* ==== Update horizontal slab in H ====
*
IF( WANTT ) THEN
DO 70 KCOL = KBOT + 1, N, NH
KLN = MIN( NH, N-KCOL+1 )
CALL ZGEMM( 'C', 'N', JW, KLN, JW, ONE, V, LDV,
$ H( KWTOP, KCOL ), LDH, ZERO, T, LDT )
CALL ZLACPY( 'A', JW, KLN, T, LDT, H( KWTOP, KCOL ),
$ LDH )
70 CONTINUE
END IF
*
* ==== Update vertical slab in Z ====
*
IF( WANTZ ) THEN
DO 80 KROW = ILOZ, IHIZ, NV
KLN = MIN( NV, IHIZ-KROW+1 )
CALL ZGEMM( 'N', 'N', KLN, JW, JW, ONE, Z( KROW, KWTOP ),
$ LDZ, V, LDV, ZERO, WV, LDWV )
CALL ZLACPY( 'A', KLN, JW, WV, LDWV, Z( KROW, KWTOP ),
$ LDZ )
80 CONTINUE
END IF
END IF
*
* ==== Return the number of deflations ... ====
*
ND = JW - NS
*
* ==== ... and the number of shifts. (Subtracting
* . INFQR from the spike length takes care
* . of the case of a rare QR failure while
* . calculating eigenvalues of the deflation
* . window.) ====
*
NS = NS - INFQR
*
* ==== Return optimal workspace. ====
*
WORK( 1 ) = DCMPLX( LWKOPT, 0 )
*
* ==== End of ZLAQR2 ====
*
END
| gpl-2.0 |
shivekkhurana/learning | c++/eigen-eigen-36fd1ba04c12/blas/stbmv.f | 184 | 11076 | SUBROUTINE STBMV(UPLO,TRANS,DIAG,N,K,A,LDA,X,INCX)
* .. Scalar Arguments ..
INTEGER INCX,K,LDA,N
CHARACTER DIAG,TRANS,UPLO
* ..
* .. Array Arguments ..
REAL A(LDA,*),X(*)
* ..
*
* Purpose
* =======
*
* STBMV performs one of the matrix-vector operations
*
* x := A*x, or x := A'*x,
*
* where x is an n element vector and A is an n by n unit, or non-unit,
* upper or lower triangular band matrix, with ( k + 1 ) diagonals.
*
* Arguments
* ==========
*
* UPLO - CHARACTER*1.
* On entry, UPLO specifies whether the matrix is an upper or
* lower triangular matrix as follows:
*
* UPLO = 'U' or 'u' A is an upper triangular matrix.
*
* UPLO = 'L' or 'l' A is a lower triangular matrix.
*
* Unchanged on exit.
*
* TRANS - CHARACTER*1.
* On entry, TRANS specifies the operation to be performed as
* follows:
*
* TRANS = 'N' or 'n' x := A*x.
*
* TRANS = 'T' or 't' x := A'*x.
*
* TRANS = 'C' or 'c' x := A'*x.
*
* Unchanged on exit.
*
* DIAG - CHARACTER*1.
* On entry, DIAG specifies whether or not A is unit
* triangular as follows:
*
* DIAG = 'U' or 'u' A is assumed to be unit triangular.
*
* DIAG = 'N' or 'n' A is not assumed to be unit
* triangular.
*
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the order of the matrix A.
* N must be at least zero.
* Unchanged on exit.
*
* K - INTEGER.
* On entry with UPLO = 'U' or 'u', K specifies the number of
* super-diagonals of the matrix A.
* On entry with UPLO = 'L' or 'l', K specifies the number of
* sub-diagonals of the matrix A.
* K must satisfy 0 .le. K.
* Unchanged on exit.
*
* A - REAL array of DIMENSION ( LDA, n ).
* Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )
* by n part of the array A must contain the upper triangular
* band part of the matrix of coefficients, supplied column by
* column, with the leading diagonal of the matrix in row
* ( k + 1 ) of the array, the first super-diagonal starting at
* position 2 in row k, and so on. The top left k by k triangle
* of the array A is not referenced.
* The following program segment will transfer an upper
* triangular band matrix from conventional full matrix storage
* to band storage:
*
* DO 20, J = 1, N
* M = K + 1 - J
* DO 10, I = MAX( 1, J - K ), J
* A( M + I, J ) = matrix( I, J )
* 10 CONTINUE
* 20 CONTINUE
*
* Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )
* by n part of the array A must contain the lower triangular
* band part of the matrix of coefficients, supplied column by
* column, with the leading diagonal of the matrix in row 1 of
* the array, the first sub-diagonal starting at position 1 in
* row 2, and so on. The bottom right k by k triangle of the
* array A is not referenced.
* The following program segment will transfer a lower
* triangular band matrix from conventional full matrix storage
* to band storage:
*
* DO 20, J = 1, N
* M = 1 - J
* DO 10, I = J, MIN( N, J + K )
* A( M + I, J ) = matrix( I, J )
* 10 CONTINUE
* 20 CONTINUE
*
* Note that when DIAG = 'U' or 'u' the elements of the array A
* corresponding to the diagonal elements of the matrix are not
* referenced, but are assumed to be unity.
* Unchanged on exit.
*
* LDA - INTEGER.
* On entry, LDA specifies the first dimension of A as declared
* in the calling (sub) program. LDA must be at least
* ( k + 1 ).
* Unchanged on exit.
*
* X - REAL array of dimension at least
* ( 1 + ( n - 1 )*abs( INCX ) ).
* Before entry, the incremented array X must contain the n
* element vector x. On exit, X is overwritten with the
* tranformed vector x.
*
* INCX - INTEGER.
* On entry, INCX specifies the increment for the elements of
* X. INCX must not be zero.
* Unchanged on exit.
*
* Further Details
* ===============
*
* Level 2 Blas routine.
*
* -- Written on 22-October-1986.
* Jack Dongarra, Argonne National Lab.
* Jeremy Du Croz, Nag Central Office.
* Sven Hammarling, Nag Central Office.
* Richard Hanson, Sandia National Labs.
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO
PARAMETER (ZERO=0.0E+0)
* ..
* .. Local Scalars ..
REAL TEMP
INTEGER I,INFO,IX,J,JX,KPLUS1,KX,L
LOGICAL NOUNIT
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX,MIN
* ..
*
* Test the input parameters.
*
INFO = 0
IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
INFO = 1
ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
+ .NOT.LSAME(TRANS,'C')) THEN
INFO = 2
ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
INFO = 3
ELSE IF (N.LT.0) THEN
INFO = 4
ELSE IF (K.LT.0) THEN
INFO = 5
ELSE IF (LDA.LT. (K+1)) THEN
INFO = 7
ELSE IF (INCX.EQ.0) THEN
INFO = 9
END IF
IF (INFO.NE.0) THEN
CALL XERBLA('STBMV ',INFO)
RETURN
END IF
*
* Quick return if possible.
*
IF (N.EQ.0) RETURN
*
NOUNIT = LSAME(DIAG,'N')
*
* Set up the start point in X if the increment is not unity. This
* will be ( N - 1 )*INCX too small for descending loops.
*
IF (INCX.LE.0) THEN
KX = 1 - (N-1)*INCX
ELSE IF (INCX.NE.1) THEN
KX = 1
END IF
*
* Start the operations. In this version the elements of A are
* accessed sequentially with one pass through A.
*
IF (LSAME(TRANS,'N')) THEN
*
* Form x := A*x.
*
IF (LSAME(UPLO,'U')) THEN
KPLUS1 = K + 1
IF (INCX.EQ.1) THEN
DO 20 J = 1,N
IF (X(J).NE.ZERO) THEN
TEMP = X(J)
L = KPLUS1 - J
DO 10 I = MAX(1,J-K),J - 1
X(I) = X(I) + TEMP*A(L+I,J)
10 CONTINUE
IF (NOUNIT) X(J) = X(J)*A(KPLUS1,J)
END IF
20 CONTINUE
ELSE
JX = KX
DO 40 J = 1,N
IF (X(JX).NE.ZERO) THEN
TEMP = X(JX)
IX = KX
L = KPLUS1 - J
DO 30 I = MAX(1,J-K),J - 1
X(IX) = X(IX) + TEMP*A(L+I,J)
IX = IX + INCX
30 CONTINUE
IF (NOUNIT) X(JX) = X(JX)*A(KPLUS1,J)
END IF
JX = JX + INCX
IF (J.GT.K) KX = KX + INCX
40 CONTINUE
END IF
ELSE
IF (INCX.EQ.1) THEN
DO 60 J = N,1,-1
IF (X(J).NE.ZERO) THEN
TEMP = X(J)
L = 1 - J
DO 50 I = MIN(N,J+K),J + 1,-1
X(I) = X(I) + TEMP*A(L+I,J)
50 CONTINUE
IF (NOUNIT) X(J) = X(J)*A(1,J)
END IF
60 CONTINUE
ELSE
KX = KX + (N-1)*INCX
JX = KX
DO 80 J = N,1,-1
IF (X(JX).NE.ZERO) THEN
TEMP = X(JX)
IX = KX
L = 1 - J
DO 70 I = MIN(N,J+K),J + 1,-1
X(IX) = X(IX) + TEMP*A(L+I,J)
IX = IX - INCX
70 CONTINUE
IF (NOUNIT) X(JX) = X(JX)*A(1,J)
END IF
JX = JX - INCX
IF ((N-J).GE.K) KX = KX - INCX
80 CONTINUE
END IF
END IF
ELSE
*
* Form x := A'*x.
*
IF (LSAME(UPLO,'U')) THEN
KPLUS1 = K + 1
IF (INCX.EQ.1) THEN
DO 100 J = N,1,-1
TEMP = X(J)
L = KPLUS1 - J
IF (NOUNIT) TEMP = TEMP*A(KPLUS1,J)
DO 90 I = J - 1,MAX(1,J-K),-1
TEMP = TEMP + A(L+I,J)*X(I)
90 CONTINUE
X(J) = TEMP
100 CONTINUE
ELSE
KX = KX + (N-1)*INCX
JX = KX
DO 120 J = N,1,-1
TEMP = X(JX)
KX = KX - INCX
IX = KX
L = KPLUS1 - J
IF (NOUNIT) TEMP = TEMP*A(KPLUS1,J)
DO 110 I = J - 1,MAX(1,J-K),-1
TEMP = TEMP + A(L+I,J)*X(IX)
IX = IX - INCX
110 CONTINUE
X(JX) = TEMP
JX = JX - INCX
120 CONTINUE
END IF
ELSE
IF (INCX.EQ.1) THEN
DO 140 J = 1,N
TEMP = X(J)
L = 1 - J
IF (NOUNIT) TEMP = TEMP*A(1,J)
DO 130 I = J + 1,MIN(N,J+K)
TEMP = TEMP + A(L+I,J)*X(I)
130 CONTINUE
X(J) = TEMP
140 CONTINUE
ELSE
JX = KX
DO 160 J = 1,N
TEMP = X(JX)
KX = KX + INCX
IX = KX
L = 1 - J
IF (NOUNIT) TEMP = TEMP*A(1,J)
DO 150 I = J + 1,MIN(N,J+K)
TEMP = TEMP + A(L+I,J)*X(IX)
IX = IX + INCX
150 CONTINUE
X(JX) = TEMP
JX = JX + INCX
160 CONTINUE
END IF
END IF
END IF
*
RETURN
*
* End of STBMV .
*
END
| mit |
marshallward/mom | src/mom5/ocean_param/gotm-4.0/util/diff_face.F90 | 10 | 4290 | #include"cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
! !ROUTINE: Diffusion schemes --- grid faces\label{sec:diffusionFace}
!
! !INTERFACE:
subroutine diff_face(N,dt,cnpar,h,Bcup,Bcdw,Yup,Ydw,nuY,Lsour,Qsour,Y)
!
! !DESCRIPTION:
!
! !USES:
use util, only : Dirichlet, Neumann
use mtridiagonal
IMPLICIT NONE
!
! !INPUT PARAMETERS:
! number of vertical layers
integer, intent(in) :: N
! time step (s)
REALTYPE, intent(in) :: dt
! "implicitness" parameter
REALTYPE, intent(in) :: cnpar
! layer thickness (m)
REALTYPE, intent(in) :: h(0:N)
! type of upper BC
integer, intent(in) :: Bcup
! type of lower BC
integer, intent(in) :: Bcdw
! value of upper BC
REALTYPE, intent(in) :: Yup
! value of lower BC
REALTYPE, intent(in) :: Ydw
! diffusivity of Y
REALTYPE, intent(in) :: nuY(0:N)
! linear source term
! (treated implicitly)
REALTYPE, intent(in) :: Lsour(0:N)
! constant source term
! (treated explicitly)
REALTYPE, intent(in) :: Qsour(0:N)
! !INPUT/OUTPUT PARAMETERS:
REALTYPE :: Y(0:N)
!
! !REVISION HISTORY:
! Original author(s): Lars Umlauf
!
! $Log: diff_face.F90,v $
! Revision 20.0 2013/12/14 00:14:00 fms
! Merged revision 1.1.2.1 onto trunk
!
! Revision 1.1.2.1 2012/05/15 16:01:18 smg
! initial cvs ci to mom5
! AUTHOR:Griffies
! REVIEWERS:
! TEST STATUS:
! CHANGES PUBLIC INTERFACES?
! CHANGES ANSWERS?
!
! Revision 1.1.2.1.390.1 2012/04/23 20:33:41 smg
! updated to gotm-2012.03.09 CVS tagged code.
! AUTHOR:Martin Schmidt
! REVIEWERS:Griffies
! TEST STATUS:
! CHANGES PUBLIC INTERFACES?
! CHANGES ANSWERS?
!
! Revision 1.3 2005-11-03 20:56:55 hb
! Source term linearisation now fully explicit again, reversion to old method
!
! Revision 1.2 2005/09/16 13:54:02 lars
! added missing IMPLICIT NONE
!
! Revision 1.1 2005/06/27 10:54:33 kbk
! new files needed
!
!
!EOP
!
! !LOCAL VARIABLES:
integer :: i
REALTYPE :: a,c,l
!
!-----------------------------------------------------------------------
!BOC
!
! set up matrix
do i=2,N-2
c = dt*( nuY(i+1) + nuY(i ) ) / ( h(i)+h(i+1) ) / h(i+1)
a = dt*( nuY(i ) + nuY(i-1) ) / ( h(i)+h(i+1) ) / h(i )
l = dt*Lsour(i)
cu(i) =-cnpar*c
au(i) =-cnpar*a
bu(i) = _ONE_ + cnpar*(a + c) - l
du(i) = (_ONE_ - (_ONE_-cnpar)*(a + c))*Y(i) &
+ (_ONE_ - cnpar)*( a*Y(i-1) + c*Y(i+1) ) + dt*Qsour(i)
end do
! set up upper boundary condition
select case(Bcup)
case(Neumann)
a = dt*( nuY(N-1) + nuY(N-2) ) / ( h(N-1)+h(N) ) / h(N-1)
l = dt*Lsour(N-1)
au(N-1) =-cnpar*a
bu(N-1) = _ONE_ + cnpar*a - l
du(N-1) = (_ONE_ - (_ONE_-cnpar)*a)*Y(N-1) &
+ (_ONE_ - cnpar)*a*Y(N-2) + dt*Qsour(N-1) &
+ 2.0*dt*Yup/( h(N-1)+h(N) )
case(Dirichlet)
au(N-1) = _ZERO_
bu(N-1) = _ONE_
du(N-1) = Yup
case default
FATAL 'invalid boundary condition type for upper boundary'
stop 'diff_face.F90'
end select
! set up lower boundary condition
select case(Bcdw)
case(Neumann)
c = dt*( nuY(2) + nuY(1) ) / ( h(1)+h(2) ) / h(2)
l = dt*Lsour(1)
cu(1) =-cnpar*c
bu(1) = _ONE_ + cnpar*c - l
du(1) = (_ONE_ - (_ONE_-cnpar)*c)*Y(1) &
+ (_ONE_ - cnpar)*c*Y(2) + dt*Qsour(1) &
+ 2.0*dt*Ydw/( h(1)+h(2) )
case(Dirichlet)
bu(1) = _ONE_
cu(1) = _ZERO_
du(1) = Ydw
case default
FATAL 'invalid boundary condition type for lower boundary'
stop 'diff_face.F90'
end select
! solve linear system
call tridiagonal(N,1,N-1,Y)
return
end subroutine diff_face
!EOC
!-----------------------------------------------------------------------
! Copyright by the GOTM-team under the GNU Public License - www.gnu.org
!-----------------------------------------------------------------------
| gpl-2.0 |
alexchenfeng/mathcosmos | share/lapack/lapack/fortran/dbdsqr.f | 17 | 23201 | SUBROUTINE DBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
$ LDU, C, LDC, WORK, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* October 31, 1999
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU
* ..
* .. Array Arguments ..
DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ),
$ VT( LDVT, * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DBDSQR computes the singular value decomposition (SVD) of a real
* N-by-N (upper or lower) bidiagonal matrix B: B = Q * S * P' (P'
* denotes the transpose of P), where S is a diagonal matrix with
* non-negative diagonal elements (the singular values of B), and Q
* and P are orthogonal matrices.
*
* The routine computes S, and optionally computes U * Q, P' * VT,
* or Q' * C, for given real input matrices U, VT, and C.
*
* See "Computing Small Singular Values of Bidiagonal Matrices With
* Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan,
* LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11,
* no. 5, pp. 873-912, Sept 1990) and
* "Accurate singular values and differential qd algorithms," by
* B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics
* Department, University of California at Berkeley, July 1992
* for a detailed description of the algorithm.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* = 'U': B is upper bidiagonal;
* = 'L': B is lower bidiagonal.
*
* N (input) INTEGER
* The order of the matrix B. N >= 0.
*
* NCVT (input) INTEGER
* The number of columns of the matrix VT. NCVT >= 0.
*
* NRU (input) INTEGER
* The number of rows of the matrix U. NRU >= 0.
*
* NCC (input) INTEGER
* The number of columns of the matrix C. NCC >= 0.
*
* D (input/output) DOUBLE PRECISION array, dimension (N)
* On entry, the n diagonal elements of the bidiagonal matrix B.
* On exit, if INFO=0, the singular values of B in decreasing
* order.
*
* E (input/output) DOUBLE PRECISION array, dimension (N)
* On entry, the elements of E contain the
* offdiagonal elements of the bidiagonal matrix whose SVD
* is desired. On normal exit (INFO = 0), E is destroyed.
* If the algorithm does not converge (INFO > 0), D and E
* will contain the diagonal and superdiagonal elements of a
* bidiagonal matrix orthogonally equivalent to the one given
* as input. E(N) is used for workspace.
*
* VT (input/output) DOUBLE PRECISION array, dimension (LDVT, NCVT)
* On entry, an N-by-NCVT matrix VT.
* On exit, VT is overwritten by P' * VT.
* VT is not referenced if NCVT = 0.
*
* LDVT (input) INTEGER
* The leading dimension of the array VT.
* LDVT >= max(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0.
*
* U (input/output) DOUBLE PRECISION array, dimension (LDU, N)
* On entry, an NRU-by-N matrix U.
* On exit, U is overwritten by U * Q.
* U is not referenced if NRU = 0.
*
* LDU (input) INTEGER
* The leading dimension of the array U. LDU >= max(1,NRU).
*
* C (input/output) DOUBLE PRECISION array, dimension (LDC, NCC)
* On entry, an N-by-NCC matrix C.
* On exit, C is overwritten by Q' * C.
* C is not referenced if NCC = 0.
*
* LDC (input) INTEGER
* The leading dimension of the array C.
* LDC >= max(1,N) if NCC > 0; LDC >=1 if NCC = 0.
*
* WORK (workspace) DOUBLE PRECISION array, dimension (4*N)
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: If INFO = -i, the i-th argument had an illegal value
* > 0: the algorithm did not converge; D and E contain the
* elements of a bidiagonal matrix which is orthogonally
* similar to the input matrix B; if INFO = i, i
* elements of E have not converged to zero.
*
* Internal Parameters
* ===================
*
* TOLMUL DOUBLE PRECISION, default = max(10,min(100,EPS**(-1/8)))
* TOLMUL controls the convergence criterion of the QR loop.
* If it is positive, TOLMUL*EPS is the desired relative
* precision in the computed singular values.
* If it is negative, abs(TOLMUL*EPS*sigma_max) is the
* desired absolute accuracy in the computed singular
* values (corresponds to relative accuracy
* abs(TOLMUL*EPS) in the largest singular value.
* abs(TOLMUL) should be between 1 and 1/EPS, and preferably
* between 10 (for fast convergence) and .1/EPS
* (for there to be some accuracy in the results).
* Default is to lose at either one eighth or 2 of the
* available decimal digits in each computed singular value
* (whichever is smaller).
*
* MAXITR INTEGER, default = 6
* MAXITR controls the maximum number of passes of the
* algorithm through its inner loop. The algorithms stops
* (and so fails to converge) if the number of passes
* through the inner loop exceeds MAXITR*N**2.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D0 )
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D0 )
DOUBLE PRECISION NEGONE
PARAMETER ( NEGONE = -1.0D0 )
DOUBLE PRECISION HNDRTH
PARAMETER ( HNDRTH = 0.01D0 )
DOUBLE PRECISION TEN
PARAMETER ( TEN = 10.0D0 )
DOUBLE PRECISION HNDRD
PARAMETER ( HNDRD = 100.0D0 )
DOUBLE PRECISION MEIGTH
PARAMETER ( MEIGTH = -0.125D0 )
INTEGER MAXITR
PARAMETER ( MAXITR = 6 )
* ..
* .. Local Scalars ..
LOGICAL LOWER, ROTATE
INTEGER I, IDIR, ISUB, ITER, J, LL, LLL, M, MAXIT, NM1,
$ NM12, NM13, OLDLL, OLDM
DOUBLE PRECISION ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU,
$ OLDCS, OLDSN, R, SHIFT, SIGMN, SIGMX, SINL,
$ SINR, SLL, SMAX, SMIN, SMINL, SMINLO, SMINOA,
$ SN, THRESH, TOL, TOLMUL, UNFL
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH
EXTERNAL LSAME, DLAMCH
* ..
* .. External Subroutines ..
EXTERNAL DLARTG, DLAS2, DLASQ1, DLASR, DLASV2, DROT,
$ DSCAL, DSWAP, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, MAX, MIN, SIGN, SQRT
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
LOWER = LSAME( UPLO, 'L' )
IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LOWER ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( NCVT.LT.0 ) THEN
INFO = -3
ELSE IF( NRU.LT.0 ) THEN
INFO = -4
ELSE IF( NCC.LT.0 ) THEN
INFO = -5
ELSE IF( ( NCVT.EQ.0 .AND. LDVT.LT.1 ) .OR.
$ ( NCVT.GT.0 .AND. LDVT.LT.MAX( 1, N ) ) ) THEN
INFO = -9
ELSE IF( LDU.LT.MAX( 1, NRU ) ) THEN
INFO = -11
ELSE IF( ( NCC.EQ.0 .AND. LDC.LT.1 ) .OR.
$ ( NCC.GT.0 .AND. LDC.LT.MAX( 1, N ) ) ) THEN
INFO = -13
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DBDSQR', -INFO )
RETURN
END IF
IF( N.EQ.0 )
$ RETURN
IF( N.EQ.1 )
$ GO TO 160
*
* ROTATE is true if any singular vectors desired, false otherwise
*
ROTATE = ( NCVT.GT.0 ) .OR. ( NRU.GT.0 ) .OR. ( NCC.GT.0 )
*
* If no singular vectors desired, use qd algorithm
*
IF( .NOT.ROTATE ) THEN
CALL DLASQ1( N, D, E, WORK, INFO )
RETURN
END IF
*
NM1 = N - 1
NM12 = NM1 + NM1
NM13 = NM12 + NM1
IDIR = 0
*
* Get machine constants
*
EPS = DLAMCH( 'Epsilon' )
UNFL = DLAMCH( 'Safe minimum' )
*
* If matrix lower bidiagonal, rotate to be upper bidiagonal
* by applying Givens rotations on the left
*
IF( LOWER ) THEN
DO 10 I = 1, N - 1
CALL DLARTG( D( I ), E( I ), CS, SN, R )
D( I ) = R
E( I ) = SN*D( I+1 )
D( I+1 ) = CS*D( I+1 )
WORK( I ) = CS
WORK( NM1+I ) = SN
10 CONTINUE
*
* Update singular vectors if desired
*
IF( NRU.GT.0 )
$ CALL DLASR( 'R', 'V', 'F', NRU, N, WORK( 1 ), WORK( N ), U,
$ LDU )
IF( NCC.GT.0 )
$ CALL DLASR( 'L', 'V', 'F', N, NCC, WORK( 1 ), WORK( N ), C,
$ LDC )
END IF
*
* Compute singular values to relative accuracy TOL
* (By setting TOL to be negative, algorithm will compute
* singular values to absolute accuracy ABS(TOL)*norm(input matrix))
*
TOLMUL = MAX( TEN, MIN( HNDRD, EPS**MEIGTH ) )
TOL = TOLMUL*EPS
*
* Compute approximate maximum, minimum singular values
*
SMAX = ZERO
DO 20 I = 1, N
SMAX = MAX( SMAX, ABS( D( I ) ) )
20 CONTINUE
DO 30 I = 1, N - 1
SMAX = MAX( SMAX, ABS( E( I ) ) )
30 CONTINUE
SMINL = ZERO
IF( TOL.GE.ZERO ) THEN
*
* Relative accuracy desired
*
SMINOA = ABS( D( 1 ) )
IF( SMINOA.EQ.ZERO )
$ GO TO 50
MU = SMINOA
DO 40 I = 2, N
MU = ABS( D( I ) )*( MU / ( MU+ABS( E( I-1 ) ) ) )
SMINOA = MIN( SMINOA, MU )
IF( SMINOA.EQ.ZERO )
$ GO TO 50
40 CONTINUE
50 CONTINUE
SMINOA = SMINOA / SQRT( DBLE( N ) )
THRESH = MAX( TOL*SMINOA, MAXITR*N*N*UNFL )
ELSE
*
* Absolute accuracy desired
*
THRESH = MAX( ABS( TOL )*SMAX, MAXITR*N*N*UNFL )
END IF
*
* Prepare for main iteration loop for the singular values
* (MAXIT is the maximum number of passes through the inner
* loop permitted before nonconvergence signalled.)
*
MAXIT = MAXITR*N*N
ITER = 0
OLDLL = -1
OLDM = -1
*
* M points to last element of unconverged part of matrix
*
M = N
*
* Begin main iteration loop
*
60 CONTINUE
*
* Check for convergence or exceeding iteration count
*
IF( M.LE.1 )
$ GO TO 160
IF( ITER.GT.MAXIT )
$ GO TO 200
*
* Find diagonal block of matrix to work on
*
IF( TOL.LT.ZERO .AND. ABS( D( M ) ).LE.THRESH )
$ D( M ) = ZERO
SMAX = ABS( D( M ) )
SMIN = SMAX
DO 70 LLL = 1, M - 1
LL = M - LLL
ABSS = ABS( D( LL ) )
ABSE = ABS( E( LL ) )
IF( TOL.LT.ZERO .AND. ABSS.LE.THRESH )
$ D( LL ) = ZERO
IF( ABSE.LE.THRESH )
$ GO TO 80
SMIN = MIN( SMIN, ABSS )
SMAX = MAX( SMAX, ABSS, ABSE )
70 CONTINUE
LL = 0
GO TO 90
80 CONTINUE
E( LL ) = ZERO
*
* Matrix splits since E(LL) = 0
*
IF( LL.EQ.M-1 ) THEN
*
* Convergence of bottom singular value, return to top of loop
*
M = M - 1
GO TO 60
END IF
90 CONTINUE
LL = LL + 1
*
* E(LL) through E(M-1) are nonzero, E(LL-1) is zero
*
IF( LL.EQ.M-1 ) THEN
*
* 2 by 2 block, handle separately
*
CALL DLASV2( D( M-1 ), E( M-1 ), D( M ), SIGMN, SIGMX, SINR,
$ COSR, SINL, COSL )
D( M-1 ) = SIGMX
E( M-1 ) = ZERO
D( M ) = SIGMN
*
* Compute singular vectors, if desired
*
IF( NCVT.GT.0 )
$ CALL DROT( NCVT, VT( M-1, 1 ), LDVT, VT( M, 1 ), LDVT, COSR,
$ SINR )
IF( NRU.GT.0 )
$ CALL DROT( NRU, U( 1, M-1 ), 1, U( 1, M ), 1, COSL, SINL )
IF( NCC.GT.0 )
$ CALL DROT( NCC, C( M-1, 1 ), LDC, C( M, 1 ), LDC, COSL,
$ SINL )
M = M - 2
GO TO 60
END IF
*
* If working on new submatrix, choose shift direction
* (from larger end diagonal element towards smaller)
*
IF( LL.GT.OLDM .OR. M.LT.OLDLL ) THEN
IF( ABS( D( LL ) ).GE.ABS( D( M ) ) ) THEN
*
* Chase bulge from top (big end) to bottom (small end)
*
IDIR = 1
ELSE
*
* Chase bulge from bottom (big end) to top (small end)
*
IDIR = 2
END IF
END IF
*
* Apply convergence tests
*
IF( IDIR.EQ.1 ) THEN
*
* Run convergence test in forward direction
* First apply standard test to bottom of matrix
*
IF( ABS( E( M-1 ) ).LE.ABS( TOL )*ABS( D( M ) ) .OR.
$ ( TOL.LT.ZERO .AND. ABS( E( M-1 ) ).LE.THRESH ) ) THEN
E( M-1 ) = ZERO
GO TO 60
END IF
*
IF( TOL.GE.ZERO ) THEN
*
* If relative accuracy desired,
* apply convergence criterion forward
*
MU = ABS( D( LL ) )
SMINL = MU
DO 100 LLL = LL, M - 1
IF( ABS( E( LLL ) ).LE.TOL*MU ) THEN
E( LLL ) = ZERO
GO TO 60
END IF
SMINLO = SMINL
MU = ABS( D( LLL+1 ) )*( MU / ( MU+ABS( E( LLL ) ) ) )
SMINL = MIN( SMINL, MU )
100 CONTINUE
END IF
*
ELSE
*
* Run convergence test in backward direction
* First apply standard test to top of matrix
*
IF( ABS( E( LL ) ).LE.ABS( TOL )*ABS( D( LL ) ) .OR.
$ ( TOL.LT.ZERO .AND. ABS( E( LL ) ).LE.THRESH ) ) THEN
E( LL ) = ZERO
GO TO 60
END IF
*
IF( TOL.GE.ZERO ) THEN
*
* If relative accuracy desired,
* apply convergence criterion backward
*
MU = ABS( D( M ) )
SMINL = MU
DO 110 LLL = M - 1, LL, -1
IF( ABS( E( LLL ) ).LE.TOL*MU ) THEN
E( LLL ) = ZERO
GO TO 60
END IF
SMINLO = SMINL
MU = ABS( D( LLL ) )*( MU / ( MU+ABS( E( LLL ) ) ) )
SMINL = MIN( SMINL, MU )
110 CONTINUE
END IF
END IF
OLDLL = LL
OLDM = M
*
* Compute shift. First, test if shifting would ruin relative
* accuracy, and if so set the shift to zero.
*
IF( TOL.GE.ZERO .AND. N*TOL*( SMINL / SMAX ).LE.
$ MAX( EPS, HNDRTH*TOL ) ) THEN
*
* Use a zero shift to avoid loss of relative accuracy
*
SHIFT = ZERO
ELSE
*
* Compute the shift from 2-by-2 block at end of matrix
*
IF( IDIR.EQ.1 ) THEN
SLL = ABS( D( LL ) )
CALL DLAS2( D( M-1 ), E( M-1 ), D( M ), SHIFT, R )
ELSE
SLL = ABS( D( M ) )
CALL DLAS2( D( LL ), E( LL ), D( LL+1 ), SHIFT, R )
END IF
*
* Test if shift negligible, and if so set to zero
*
IF( SLL.GT.ZERO ) THEN
IF( ( SHIFT / SLL )**2.LT.EPS )
$ SHIFT = ZERO
END IF
END IF
*
* Increment iteration count
*
ITER = ITER + M - LL
*
* If SHIFT = 0, do simplified QR iteration
*
IF( SHIFT.EQ.ZERO ) THEN
IF( IDIR.EQ.1 ) THEN
*
* Chase bulge from top to bottom
* Save cosines and sines for later singular vector updates
*
CS = ONE
OLDCS = ONE
DO 120 I = LL, M - 1
CALL DLARTG( D( I )*CS, E( I ), CS, SN, R )
IF( I.GT.LL )
$ E( I-1 ) = OLDSN*R
CALL DLARTG( OLDCS*R, D( I+1 )*SN, OLDCS, OLDSN, D( I ) )
WORK( I-LL+1 ) = CS
WORK( I-LL+1+NM1 ) = SN
WORK( I-LL+1+NM12 ) = OLDCS
WORK( I-LL+1+NM13 ) = OLDSN
120 CONTINUE
H = D( M )*CS
D( M ) = H*OLDCS
E( M-1 ) = H*OLDSN
*
* Update singular vectors
*
IF( NCVT.GT.0 )
$ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCVT, WORK( 1 ),
$ WORK( N ), VT( LL, 1 ), LDVT )
IF( NRU.GT.0 )
$ CALL DLASR( 'R', 'V', 'F', NRU, M-LL+1, WORK( NM12+1 ),
$ WORK( NM13+1 ), U( 1, LL ), LDU )
IF( NCC.GT.0 )
$ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCC, WORK( NM12+1 ),
$ WORK( NM13+1 ), C( LL, 1 ), LDC )
*
* Test convergence
*
IF( ABS( E( M-1 ) ).LE.THRESH )
$ E( M-1 ) = ZERO
*
ELSE
*
* Chase bulge from bottom to top
* Save cosines and sines for later singular vector updates
*
CS = ONE
OLDCS = ONE
DO 130 I = M, LL + 1, -1
CALL DLARTG( D( I )*CS, E( I-1 ), CS, SN, R )
IF( I.LT.M )
$ E( I ) = OLDSN*R
CALL DLARTG( OLDCS*R, D( I-1 )*SN, OLDCS, OLDSN, D( I ) )
WORK( I-LL ) = CS
WORK( I-LL+NM1 ) = -SN
WORK( I-LL+NM12 ) = OLDCS
WORK( I-LL+NM13 ) = -OLDSN
130 CONTINUE
H = D( LL )*CS
D( LL ) = H*OLDCS
E( LL ) = H*OLDSN
*
* Update singular vectors
*
IF( NCVT.GT.0 )
$ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCVT, WORK( NM12+1 ),
$ WORK( NM13+1 ), VT( LL, 1 ), LDVT )
IF( NRU.GT.0 )
$ CALL DLASR( 'R', 'V', 'B', NRU, M-LL+1, WORK( 1 ),
$ WORK( N ), U( 1, LL ), LDU )
IF( NCC.GT.0 )
$ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCC, WORK( 1 ),
$ WORK( N ), C( LL, 1 ), LDC )
*
* Test convergence
*
IF( ABS( E( LL ) ).LE.THRESH )
$ E( LL ) = ZERO
END IF
ELSE
*
* Use nonzero shift
*
IF( IDIR.EQ.1 ) THEN
*
* Chase bulge from top to bottom
* Save cosines and sines for later singular vector updates
*
F = ( ABS( D( LL ) )-SHIFT )*
$ ( SIGN( ONE, D( LL ) )+SHIFT / D( LL ) )
G = E( LL )
DO 140 I = LL, M - 1
CALL DLARTG( F, G, COSR, SINR, R )
IF( I.GT.LL )
$ E( I-1 ) = R
F = COSR*D( I ) + SINR*E( I )
E( I ) = COSR*E( I ) - SINR*D( I )
G = SINR*D( I+1 )
D( I+1 ) = COSR*D( I+1 )
CALL DLARTG( F, G, COSL, SINL, R )
D( I ) = R
F = COSL*E( I ) + SINL*D( I+1 )
D( I+1 ) = COSL*D( I+1 ) - SINL*E( I )
IF( I.LT.M-1 ) THEN
G = SINL*E( I+1 )
E( I+1 ) = COSL*E( I+1 )
END IF
WORK( I-LL+1 ) = COSR
WORK( I-LL+1+NM1 ) = SINR
WORK( I-LL+1+NM12 ) = COSL
WORK( I-LL+1+NM13 ) = SINL
140 CONTINUE
E( M-1 ) = F
*
* Update singular vectors
*
IF( NCVT.GT.0 )
$ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCVT, WORK( 1 ),
$ WORK( N ), VT( LL, 1 ), LDVT )
IF( NRU.GT.0 )
$ CALL DLASR( 'R', 'V', 'F', NRU, M-LL+1, WORK( NM12+1 ),
$ WORK( NM13+1 ), U( 1, LL ), LDU )
IF( NCC.GT.0 )
$ CALL DLASR( 'L', 'V', 'F', M-LL+1, NCC, WORK( NM12+1 ),
$ WORK( NM13+1 ), C( LL, 1 ), LDC )
*
* Test convergence
*
IF( ABS( E( M-1 ) ).LE.THRESH )
$ E( M-1 ) = ZERO
*
ELSE
*
* Chase bulge from bottom to top
* Save cosines and sines for later singular vector updates
*
F = ( ABS( D( M ) )-SHIFT )*( SIGN( ONE, D( M ) )+SHIFT /
$ D( M ) )
G = E( M-1 )
DO 150 I = M, LL + 1, -1
CALL DLARTG( F, G, COSR, SINR, R )
IF( I.LT.M )
$ E( I ) = R
F = COSR*D( I ) + SINR*E( I-1 )
E( I-1 ) = COSR*E( I-1 ) - SINR*D( I )
G = SINR*D( I-1 )
D( I-1 ) = COSR*D( I-1 )
CALL DLARTG( F, G, COSL, SINL, R )
D( I ) = R
F = COSL*E( I-1 ) + SINL*D( I-1 )
D( I-1 ) = COSL*D( I-1 ) - SINL*E( I-1 )
IF( I.GT.LL+1 ) THEN
G = SINL*E( I-2 )
E( I-2 ) = COSL*E( I-2 )
END IF
WORK( I-LL ) = COSR
WORK( I-LL+NM1 ) = -SINR
WORK( I-LL+NM12 ) = COSL
WORK( I-LL+NM13 ) = -SINL
150 CONTINUE
E( LL ) = F
*
* Test convergence
*
IF( ABS( E( LL ) ).LE.THRESH )
$ E( LL ) = ZERO
*
* Update singular vectors if desired
*
IF( NCVT.GT.0 )
$ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCVT, WORK( NM12+1 ),
$ WORK( NM13+1 ), VT( LL, 1 ), LDVT )
IF( NRU.GT.0 )
$ CALL DLASR( 'R', 'V', 'B', NRU, M-LL+1, WORK( 1 ),
$ WORK( N ), U( 1, LL ), LDU )
IF( NCC.GT.0 )
$ CALL DLASR( 'L', 'V', 'B', M-LL+1, NCC, WORK( 1 ),
$ WORK( N ), C( LL, 1 ), LDC )
END IF
END IF
*
* QR iteration finished, go back and check convergence
*
GO TO 60
*
* All singular values converged, so make them positive
*
160 CONTINUE
DO 170 I = 1, N
IF( D( I ).LT.ZERO ) THEN
D( I ) = -D( I )
*
* Change sign of singular vectors, if desired
*
IF( NCVT.GT.0 )
$ CALL DSCAL( NCVT, NEGONE, VT( I, 1 ), LDVT )
END IF
170 CONTINUE
*
* Sort the singular values into decreasing order (insertion sort on
* singular values, but only one transposition per singular vector)
*
DO 190 I = 1, N - 1
*
* Scan for smallest D(I)
*
ISUB = 1
SMIN = D( 1 )
DO 180 J = 2, N + 1 - I
IF( D( J ).LE.SMIN ) THEN
ISUB = J
SMIN = D( J )
END IF
180 CONTINUE
IF( ISUB.NE.N+1-I ) THEN
*
* Swap singular values and vectors
*
D( ISUB ) = D( N+1-I )
D( N+1-I ) = SMIN
IF( NCVT.GT.0 )
$ CALL DSWAP( NCVT, VT( ISUB, 1 ), LDVT, VT( N+1-I, 1 ),
$ LDVT )
IF( NRU.GT.0 )
$ CALL DSWAP( NRU, U( 1, ISUB ), 1, U( 1, N+1-I ), 1 )
IF( NCC.GT.0 )
$ CALL DSWAP( NCC, C( ISUB, 1 ), LDC, C( N+1-I, 1 ), LDC )
END IF
190 CONTINUE
GO TO 220
*
* Maximum number of iterations exceeded, failure to converge
*
200 CONTINUE
INFO = 0
DO 210 I = 1, N - 1
IF( E( I ).NE.ZERO )
$ INFO = INFO + 1
210 CONTINUE
220 CONTINUE
RETURN
*
* End of DBDSQR
*
END
| gpl-2.0 |
alexchenfeng/mathcosmos | share/lapack/lapack/fortran/dlarft.f | 59 | 7169 | SUBROUTINE DLARFT( DIRECT, STOREV, N, K, V, LDV, TAU, T, LDT )
*
* -- 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 DIRECT, STOREV
INTEGER K, LDT, LDV, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION T( LDT, * ), TAU( * ), V( LDV, * )
* ..
*
* Purpose
* =======
*
* DLARFT forms the triangular factor T of a real block reflector H
* of order n, which is defined as a product of k elementary reflectors.
*
* If DIRECT = 'F', H = H(1) H(2) . . . H(k) and T is upper triangular;
*
* If DIRECT = 'B', H = H(k) . . . H(2) H(1) and T is lower triangular.
*
* If STOREV = 'C', the vector which defines the elementary reflector
* H(i) is stored in the i-th column of the array V, and
*
* H = I - V * T * V'
*
* If STOREV = 'R', the vector which defines the elementary reflector
* H(i) is stored in the i-th row of the array V, and
*
* H = I - V' * T * V
*
* Arguments
* =========
*
* DIRECT (input) CHARACTER*1
* Specifies the order in which the elementary reflectors are
* multiplied to form the block reflector:
* = 'F': H = H(1) H(2) . . . H(k) (Forward)
* = 'B': H = H(k) . . . H(2) H(1) (Backward)
*
* STOREV (input) CHARACTER*1
* Specifies how the vectors which define the elementary
* reflectors are stored (see also Further Details):
* = 'C': columnwise
* = 'R': rowwise
*
* N (input) INTEGER
* The order of the block reflector H. N >= 0.
*
* K (input) INTEGER
* The order of the triangular factor T (= the number of
* elementary reflectors). K >= 1.
*
* V (input/output) DOUBLE PRECISION array, dimension
* (LDV,K) if STOREV = 'C'
* (LDV,N) if STOREV = 'R'
* The matrix V. See further details.
*
* LDV (input) INTEGER
* The leading dimension of the array V.
* If STOREV = 'C', LDV >= max(1,N); if STOREV = 'R', LDV >= K.
*
* TAU (input) DOUBLE PRECISION array, dimension (K)
* TAU(i) must contain the scalar factor of the elementary
* reflector H(i).
*
* T (output) DOUBLE PRECISION array, dimension (LDT,K)
* The k by k triangular factor T of the block reflector.
* If DIRECT = 'F', T is upper triangular; if DIRECT = 'B', T is
* lower triangular. The rest of the array is not used.
*
* LDT (input) INTEGER
* The leading dimension of the array T. LDT >= K.
*
* Further Details
* ===============
*
* 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 )
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, J
DOUBLE PRECISION VII
* ..
* .. External Subroutines ..
EXTERNAL DGEMV, DTRMV
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. Executable Statements ..
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
IF( LSAME( DIRECT, 'F' ) ) THEN
DO 20 I = 1, K
IF( TAU( I ).EQ.ZERO ) THEN
*
* H(i) = I
*
DO 10 J = 1, I
T( J, I ) = ZERO
10 CONTINUE
ELSE
*
* general case
*
VII = V( I, I )
V( I, I ) = ONE
IF( LSAME( STOREV, 'C' ) ) THEN
*
* T(1:i-1,i) := - tau(i) * V(i:n,1:i-1)' * V(i:n,i)
*
CALL DGEMV( 'Transpose', N-I+1, I-1, -TAU( I ),
$ V( I, 1 ), LDV, V( I, I ), 1, ZERO,
$ T( 1, I ), 1 )
ELSE
*
* T(1:i-1,i) := - tau(i) * V(1:i-1,i:n) * V(i,i:n)'
*
CALL DGEMV( 'No transpose', I-1, N-I+1, -TAU( I ),
$ V( 1, I ), LDV, V( I, I ), LDV, ZERO,
$ T( 1, I ), 1 )
END IF
V( I, I ) = VII
*
* T(1:i-1,i) := T(1:i-1,1:i-1) * T(1:i-1,i)
*
CALL DTRMV( 'Upper', 'No transpose', 'Non-unit', I-1, T,
$ LDT, T( 1, I ), 1 )
T( I, I ) = TAU( I )
END IF
20 CONTINUE
ELSE
DO 40 I = K, 1, -1
IF( TAU( I ).EQ.ZERO ) THEN
*
* H(i) = I
*
DO 30 J = I, K
T( J, I ) = ZERO
30 CONTINUE
ELSE
*
* general case
*
IF( I.LT.K ) THEN
IF( LSAME( STOREV, 'C' ) ) THEN
VII = V( N-K+I, I )
V( N-K+I, I ) = ONE
*
* T(i+1:k,i) :=
* - tau(i) * V(1:n-k+i,i+1:k)' * V(1:n-k+i,i)
*
CALL DGEMV( 'Transpose', N-K+I, K-I, -TAU( I ),
$ V( 1, I+1 ), LDV, V( 1, I ), 1, ZERO,
$ T( I+1, I ), 1 )
V( N-K+I, I ) = VII
ELSE
VII = V( I, N-K+I )
V( I, N-K+I ) = ONE
*
* T(i+1:k,i) :=
* - tau(i) * V(i+1:k,1:n-k+i) * V(i,1:n-k+i)'
*
CALL DGEMV( 'No transpose', K-I, N-K+I, -TAU( I ),
$ V( I+1, 1 ), LDV, V( I, 1 ), LDV, ZERO,
$ T( I+1, I ), 1 )
V( I, N-K+I ) = VII
END IF
*
* T(i+1:k,i) := T(i+1:k,i+1:k) * T(i+1:k,i)
*
CALL DTRMV( 'Lower', 'No transpose', 'Non-unit', K-I,
$ T( I+1, I+1 ), LDT, T( I+1, I ), 1 )
END IF
T( I, I ) = TAU( I )
END IF
40 CONTINUE
END IF
RETURN
*
* End of DLARFT
*
END
| gpl-2.0 |
marshallward/mom | src/atmos_param/donner_deep/nonfms_donner.F90 | 10 | 24523 | module nonfms_donner_mod
use sat_vapor_pres_k_mod, only: sat_vapor_pres_init_k ! replace with
! non-FMS interface
use donner_types_mod, only: donner_initialized_type, &
donner_save_type, donner_rad_type, &
donner_nml_type, donner_param_type, &
donner_budgets_type, &
donner_column_diag_type, &
MAXMAG, MAXVAL, MINMAG, MINVAL, &
DET_MASS_FLUX, MASS_FLUX, &
CELL_UPWARD_MASS_FLUX, TEMP_FORCING, &
MOIST_FORCING, PRECIP, FREEZING, &
RADON_TEND, &
donner_conv_type, donner_cape_type, &
donner_cem_type
implicit none
private
!--------------------------------------------------------------------
! donner_deep_mod diagnoses the location and computes the
! effects of deep convection on the model atmosphere
!--------------------------------------------------------------------
!---------------------------------------------------------------------
!----------- ****** VERSION NUMBER ******* ---------------------------
character(len=128) :: version = '$Id: nonfms_donner.F90,v 19.0 2012/01/06 20:08:40 fms Exp $'
character(len=128) :: tagname = '$Name: tikal $'
!--------------------------------------------------------------------
!---interfaces------
public &
nonfms_donner_process_nml, nonfms_donner_process_tracers, &
nonfms_donner_process_monitors, &
nonfms_donner_activate_diag, nonfms_donner_read_restart,&
nonfms_donner_col_diag, nonfms_donner_write_restart, &
nonfms_donner_column_control, nonfms_donner_deep_netcdf, &
nonfms_sat_vapor_pres, nonfms_get_pe_number, nonfms_error_mesg,&
nonfms_close_col_diag_units, &
nonfms_deallocate_variables, nonfms_constants
private &
! module subroutines called during initialization:
process_coldstart
!---------------------------------------------------------------------
!---namelist----
# include "donner_nml.h"
!--------------------------------------------------------------------
!--- public data ----------
!--------------------------------------------------------------------
!----private data-----------
!-----------------------------------------------------------------------
! miscellaneous variables
!
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!
! PUBLIC SUBROUTINES
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!#####################################################################
subroutine nonfms_donner_process_nml (Nml, kpar)
!---------------------------------------------------------------------
! nonfms_donner_process_nml si intended to process the
! donner_deep_nml file, using the procedure of the nonFMS model.
! for now, default values are reset here within the Fortran source
! and no nml read is done.
!---------------------------------------------------------------------
!--------------------------------------------------------------------
type(donner_nml_type), intent(inout) :: Nml
integer, intent(in) :: kpar
!---------------------------------------------------------------------
! intent(in) variables:
!
!
!-------------------------------------------------------------------
!-------------------------------------------------------------------
! local variables:
real, dimension(:), allocatable :: erat_loc, arat_loc
!-------------------------------------------------------------------
! local variables:
!
!
!-------------------------------------------------------------------
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 1. READ NAMELIST AND WRITE IT TO LOG FILE.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!--------------------------------------------------------------------
! here non-default values are reset (as desired) within the Fortran
! source. note that changes to arat / erat are handled at the end of
! this subroutine.
!--------------------------------------------------------------------
! THESE SETTINGS MAY BE USED FOR DONNER_LITE:
! SETTINGS USED IN DATABASE EXPT C48L24_AM3p5-gamma-B6:
parcel_launch_level = 2
model_levels_in_sfcbl = 0
donner_deep_freq = 1800
allow_mesoscale_circulation = .true.
do_donner_cape = .false.
do_donner_plume = .false.
do_donner_closure = .false.
do_donner_lscloud = .true.
do_dcape = .false.
do_lands = .false.
do_freezing_for_cape = .true.
do_freezing_for_closure = .true.
gama = 0.0
tau = 28800.
tke0 = 0.5
cape0 = 1000.
lochoice = 10
do_capetau_land = .false.
use_llift_criteria= .false.
do_ice = .true.
atopevap = 0.1
auto_rate = 1.e-3
auto_th = 0.5e-3
frac = 1.65
ttend_max = 0.005
EVAP_IN_DOWNDRAFTS = 0.00
EVAP_IN_ENVIRON = 0.00
ENTRAINED_INTO_MESO = 1.00
ANVIL_PRECIP_EFFICIENCY = 0.85
MESO_DOWN_EVAP_FRACTION = 0.1
MESO_UP_EVAP_FRACTION = 0.05
wmin_ratio = 0.05
arat(1:7) = (/ 1.0, 0.26, 0.35, 0.32, 0.3, 0.54, 0.66 /)
erat(1:7) = (/ 1.0, 1.30, 1.80, 2.50, 3.3, 4.50, 10.0 /)
frc_internal_enthalpy_conserv = .true.
limit_pztm_to_tropo = .true.
! THESE SETTINGS MAY BE USED FOR DONNER_FULL:
! parcel_launch_level = 2
! donner_deep_freq = 1800
! allow_mesoscale_circulation = .true.
! do_donner_cape = .true.
! do_donner_plume = .true.
! do_donner_closure = .true.
! do_donner_lscloud = .true.
! do_dcape = .true.
! do_freezing_for_cape = .false.
! do_freezing_for_closure = .false.
! gama = 0.0
! lochoice = 10
! use_llift_criteria= .true.
! EVAP_IN_DOWNDRAFTS = 0.25
! EVAP_IN_ENVIRON = 0.13
! ENTRAINED_INTO_MESO = 0.62
! ANVIL_PRECIP_EFFICIENCY = 0.5
! MESO_DOWN_EVAP_FRACTION = 0.4
! MESO_UP_EVAP_FRACTION = 0.1
! wmin_ratio = 0.05
! arat(1:7) = (/ 1.0, 0.26, 0.35, 0.32, 0.3, 0.54, 0.3 /)
! erat(1:7) = (/ 1.0, 1.30, 1.80, 2.50, 3.3, 4.50, 6.5 /)
! frc_internal_enthalpy_conserv = .true.
! limit_pztm_to_tropo = .true.
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 8. STORE THE NAMELIST VARIABLES THAT NEED TO BE MADE AVAILABLE
! OUTSIDE OF THIS MODULE INTO THE DONNER_NML_TYPE VARIABLE.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Nml%parcel_launch_level = parcel_launch_level
Nml%allow_mesoscale_circulation = allow_mesoscale_circulation
Nml%do_hires_cape_for_closure = do_hires_cape_for_closure
Nml%do_donner_cape = do_donner_cape !miz
Nml%do_donner_plume = do_donner_plume !miz
Nml%do_donner_closure = do_donner_closure !miz
Nml%do_dcape = do_dcape !miz
Nml%do_lands = do_lands !miz
Nml%tau = tau !miz
Nml%cape0 = cape0 !miz
Nml%rhavg0 = rhavg0 !miz
Nml%plev0 = plev0 !miz
Nml%do_rh_trig = do_rh_trig !miz
Nml%do_capetau_land = do_capetau_land !miz
Nml%pblht0 = pblht0 !miz
Nml%tke0 = tke0 !miz
Nml%lofactor0 = lofactor0 !miz
Nml%deephgt0 = deephgt0 !miz
Nml%lochoice = lochoice !miz
Nml%deep_closure = deep_closure !miz
Nml%gama = gama !miz
Nml%do_ice = do_ice !miz
Nml%atopevap = atopevap !miz
Nml%do_donner_lscloud = do_donner_lscloud !miz
Nml%auto_rate = auto_rate !miz
Nml%auto_th = auto_th !miz
Nml%frac = frac !miz
Nml%ttend_max = ttend_max !miz
Nml%mesofactor = mesofactor !miz
Nml%use_llift_criteria = use_llift_criteria
Nml%use_pdeep_cv = use_pdeep_cv
Nml%entrainment_constant_source = entrainment_constant_source
Nml%donner_deep_freq = donner_deep_freq
Nml%model_levels_in_sfcbl = model_levels_in_sfcbl
Nml%cell_liquid_size_type = cell_liquid_size_type
Nml%cell_ice_size_type = cell_ice_size_type
Nml%cell_liquid_eff_diam_input = cell_liquid_eff_diam_input
Nml%cell_ice_geneff_diam_input = cell_ice_geneff_diam_input
Nml%meso_liquid_eff_diam_input = meso_liquid_eff_diam_input
Nml%do_average = do_average
Nml%use_memphis_size_limits = use_memphis_size_limits
Nml%wmin_ratio = wmin_ratio
Nml%do_freezing_for_cape = do_freezing_for_cape
Nml%tfre_for_cape = tfre_for_cape
Nml%dfre_for_cape = dfre_for_cape
Nml%rmuz_for_cape = rmuz_for_cape
Nml%do_freezing_for_closure = do_freezing_for_closure
Nml%tfre_for_closure = tfre_for_closure
Nml%dfre_for_closure = dfre_for_closure
Nml%rmuz_for_closure = rmuz_for_closure
Nml%do_budget_analysis = do_budget_analysis
Nml%frc_internal_enthalpy_conserv = &
frc_internal_enthalpy_conserv
Nml%do_ensemble_diagnostics = do_ensemble_diagnostics
Nml%limit_pztm_to_tropo = limit_pztm_to_tropo
Nml%entrainment_scheme_for_closure = &
entrainment_scheme_for_closure
Nml%modify_closure_plume_condensate = &
modify_closure_plume_condensate
Nml%closure_plume_condensate = closure_plume_condensate
Nml%evap_in_downdrafts = evap_in_downdrafts
Nml%evap_in_environ = evap_in_environ
Nml%entrained_into_meso = entrained_into_meso
Nml%anvil_precip_efficiency = anvil_precip_efficiency
Nml%meso_down_evap_fraction = meso_down_evap_fraction
Nml%meso_up_evap_fraction = meso_up_evap_fraction
Nml%cdeep_cv = cdeep_cv
!---------------------------------------------------------------------
! if mods are desired for arat / erat when these values are being
! specified (option = 0), make them to arat_loc / erat_loc. these
! will be transferred to arat / erat later. if arat / erat come from
! optional formulae, they will be calculated here used nml-supplied
! input values.
!---------------------------------------------------------------------
allocate (arat_loc(kpar))
allocate (erat_loc(kpar))
if (arat_erat_option == 0) then
arat_loc = arat
erat_loc = erat
else
call define_arat_erat (arat_erat_option, kpar, eratb, erat0, &
erat_min, erat_max,erat_loc,arat_loc)
print *,'donner_deep_nml: redefined arat and erat using &
&arat_erat_option == ', arat_erat_option
print *,'donner_deep_nml: arat = ',arat_loc
print *,'donner_deep_nml: erat = ',erat_loc
endif
allocate (Nml%arat(kpar))
allocate (Nml%ensemble_entrain_factors_gate(kpar))
Nml%arat = arat_loc
Nml%ensemble_entrain_factors_gate = erat_loc
deallocate (arat_loc, erat_loc)
end subroutine nonfms_donner_process_nml
!#####################################################################
subroutine nonfms_donner_process_tracers
return
end subroutine nonfms_donner_process_tracers
!#####################################################################
subroutine nonfms_donner_process_monitors
return
end subroutine nonfms_donner_process_monitors
!#####################################################################
subroutine nonfms_donner_activate_diag (secs, days, axes, &
Don_save, Nml, n_water_budget, n_enthalpy_budget, &
n_precip_paths, n_precip_types, nlev_hires, kpar)
integer, intent(in) :: secs, days, n_water_budget, &
n_enthalpy_budget, n_precip_paths, n_precip_types, &
nlev_hires, kpar
integer, dimension(4), intent(in) :: axes
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 4. INITIALIZE THE NETCDF OUTPUT VARIABLES.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!--------------------------------------------------------------------
! activate the netcdf diagnostic fields.
!-------------------------------------------------------------------
! call register_fields (secs, days, axes, Don_save, Nml)
end subroutine nonfms_donner_activate_diag
!#####################################################################
subroutine nonfms_donner_read_restart (Initialized, ntracers, &
secs, days, Don_save, Nml)
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
integer, intent(in) :: secs, days, ntracers
!--------------------------------------------------------------------
! if no restart file is present, call subroutine process_coldstart
! to define the needed variables.
!--------------------------------------------------------------------
call process_coldstart (secs, days, Initialized, Nml, Don_save)
end subroutine nonfms_donner_read_restart
!#####################################################################
subroutine nonfms_donner_col_diag (lonb, latb, Col_diag, pref)
real, dimension(:,:), intent(in) :: lonb, latb
type(donner_column_diag_type), intent(inout) :: Col_diag
real, dimension(:), intent(in) :: pref
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 6. INITIALIZE VARIABLES NEEDED FOR COLUMN_DIAGNOSTICS_MOD OUTPUT.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!---------------------------------------------------------------------
! define the total number of columns for which diagnostics
! are desired.
!---------------------------------------------------------------------
Col_diag%num_diag_pts = num_diag_pts_ij + num_diag_pts_latlon
!---------------------------------------------------------------------
! initialize the value of the k index associated with diagnostics
! cutoff.
!---------------------------------------------------------------------
Col_diag%kstart = -99
end subroutine nonfms_donner_col_diag
!#####################################################################
subroutine nonfms_donner_write_restart (ntracers, Don_save, &
Initialized, Nml)
integer, intent(in) :: ntracers
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
!-------------------------------------------------------------------
! call subroutine to write restart file.
!-------------------------------------------------------------------
return
end subroutine nonfms_donner_write_restart
!#####################################################################
subroutine nonfms_get_pe_number (me, root_pe)
!--------------------------------------------------------------------
! define pe number (needed for column diagnostics and as dummy arg-
! ument for donner_lite diagnostics). For now, column
! diagnostics are unavailable outside of FMS, so the value is set
! to 0 for all pes.
!--------------------------------------------------------------------
integer, intent(out) :: me, root_pe
me = 0
root_pe = 0
end subroutine nonfms_get_pe_number
!#####################################################################
subroutine nonfms_error_mesg (ermesg)
character(len=*), intent(in) :: ermesg
! call error_mesg ('donner_deep_mod', ermesg, FATAL)
!! NOTE POTENTIAL HANG HERE : USE APPROPRIATE ERROR EXIT ON NONFMS
!! SYSTEM RATHER THAN 'STOP'
print *, 'STOPPING DUE TO ERROR:', ermesg
stop
end subroutine nonfms_error_mesg
!#####################################################################
subroutine nonfms_close_col_diag_units
return
end subroutine nonfms_close_col_diag_units
!#####################################################################
subroutine nonfms_deallocate_variables
return
end subroutine nonfms_deallocate_variables
!######################################################################
subroutine nonfms_sat_vapor_pres
!---------------------------------------------------------------------
! should contain needed calls to initialize nonfms saturation
! vapor pressure calculation. currently uses fms interface to allow
! testing.
!---------------------------------------------------------------------
integer, parameter :: TCMIN = -160
integer, parameter :: TCMAX = 100
integer, parameter :: ESRES = 10
real, parameter :: HLV = 2.500e6
real, parameter :: ES0 = 1.0
real, parameter :: RVGAS = 461.50
integer, parameter :: NSIZE = (TCMAX-TCMIN)*esres + 1
integer, parameter :: NLIM = NSIZE - 1
real, parameter :: TFREEZE = 273.16
logical, parameter :: use_exact_qs_input = .true.
logical, parameter :: do_simple = .false.
logical, parameter :: construct_table_wrt_liq = .false.
logical, parameter :: construct_table_wrt_liq_and_ice = .false.
real :: teps, tmin, dtinv
character(len=128) :: err_msg
! logical :: dum = .false.
call sat_vapor_pres_init_k (NSIZE, REAL(TCMIN), REAL(TCMAX), &
TFREEZE, HLV, RVGAS, ES0, err_msg, &
use_exact_qs_input, do_simple, &
construct_table_wrt_liq, &
construct_table_wrt_liq_and_ice, &
teps, tmin, dtinv)
end subroutine nonfms_sat_vapor_pres
!######################################################################
subroutine nonfms_constants (Param)
type(donner_param_type), intent(inout) :: Param
!----------------------------------------------------------------------
! define the components of Param that come from the fms module
! constants_mod. see donner_types.h for their definitions.
!----------------------------------------------------------------------
Param%dens_h2o = 1000.
Param%rdgas = 287.04
Param%kappa = 2. / 7.
Param%grav = 9.80
Param%cp_air = Param%rdgas/ Param%kappa
Param%pie = 3.14159265358979323846
Param%rvgas = 461.5
Param%seconds_per_day = 86400.
Param%hlv = 2.500e+06
Param%hlf = 3.34e+05
Param%hls = Param%hlv + Param%hlf
Param%kelvin = 273.15
!----------------------------------------------------------------------
end subroutine nonfms_constants
!######################################################################
subroutine nonfms_donner_column_control (is, ie, js, je, secs, &
days, Col_diag)
!---------------------------------------------------------------------
! subroutine fms_donner_column_control returns the number, location
! (processor and window indices) and output units associated with
! any diagnostic columns requested within the current physics window.
!---------------------------------------------------------------------
integer, intent(in) :: is, ie, js, je
integer, intent(in) :: secs, days
type(donner_column_diag_type), intent(inout) :: Col_diag
return
end subroutine nonfms_donner_column_control
subroutine nonfms_donner_deep_netcdf
return
end subroutine nonfms_donner_deep_netcdf
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!
! PRIVATE SUBROUTINES
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!
! 1. ROUTINES CALLED BY DONNER_DEEP_INIT
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!#####################################################################
!####################################################################
!#####################################################################
subroutine process_coldstart (secs, days, Initialized, Nml, Don_save)
!-----------------------------------------------------------------------
! subroutine process_coldstart provides initialization that is needed
! when the job is a donner_deep coldstart, or if the user-supplied
! restart file is not usable for a restart with the current code
! version.
!-----------------------------------------------------------------------
integer, intent(in) :: secs, days
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
!---------------------------------------------------------------------
! intent(in) variables:
!
!
!----------------------------------------------------------------------
!----------------------------------------------------------------------
! local variables:
!---------------------------------------------------------------------
! set the coldstart flag to .true.. set the time until the first cal-
! culation call to donner_deep_mod, donner_deep calculation calls will
! be every donner_deep_freq seconds after the start of the day.
!---------------------------------------------------------------------
Initialized%coldstart = .true.
if (secs == 0) then ! i.e., 00Z
Initialized%conv_alarm = Nml%donner_deep_freq
else
Initialized%conv_alarm = Nml%donner_deep_freq - &
MOD (secs, Nml%donner_deep_freq)
endif
!----------------------------------------------------------------------
! initialize the variables which must be returned from donner_deep_mod
! on the first step when coldstarting.
!----------------------------------------------------------------------
Don_save%cemetf = 0.
Don_save%cememf = 0.
Don_save%tracer_tends = 0.
Don_save%mass_flux = 0.
Don_save%mflux_up = 0.
Don_save%cell_up_mass_flux = 0.
Don_save%det_mass_flux = 0.
Don_save%dql_strat = 0.
Don_save%dqi_strat = 0.
Don_save%dqa_strat = 0.
Don_save%humidity_area = 0.
Don_save%humidity_factor = 0.
Don_save%tprea1 = 0.
Don_save%parcel_disp = 0.
!----------------------------------------------------------------------
end subroutine process_coldstart
!#####################################################################
end module nonfms_donner_mod
| gpl-2.0 |
mtrbean/scipy | scipy/optimize/minpack/r1updt.f | 125 | 5702 | subroutine r1updt(m,n,s,ls,u,v,w,sing)
integer m,n,ls
logical sing
double precision s(ls),u(m),v(n),w(m)
c **********
c
c subroutine r1updt
c
c given an m by n lower trapezoidal matrix s, an m-vector u,
c and an n-vector v, the problem is to determine an
c orthogonal matrix q such that
c
c t
c (s + u*v )*q
c
c is again lower trapezoidal.
c
c this subroutine determines q as the product of 2*(n - 1)
c transformations
c
c gv(n-1)*...*gv(1)*gw(1)*...*gw(n-1)
c
c where gv(i), gw(i) are givens rotations in the (i,n) plane
c which eliminate elements in the i-th and n-th planes,
c respectively. q itself is not accumulated, rather the
c information to recover the gv, gw rotations is returned.
c
c the subroutine statement is
c
c subroutine r1updt(m,n,s,ls,u,v,w,sing)
c
c where
c
c m is a positive integer input variable set to the number
c of rows of s.
c
c n is a positive integer input variable set to the number
c of columns of s. n must not exceed m.
c
c s is an array of length ls. on input s must contain the lower
c trapezoidal matrix s stored by columns. on output s contains
c the lower trapezoidal matrix produced as described above.
c
c ls is a positive integer input variable not less than
c (n*(2*m-n+1))/2.
c
c u is an input array of length m which must contain the
c vector u.
c
c v is an array of length n. on input v must contain the vector
c v. on output v(i) contains the information necessary to
c recover the givens rotation gv(i) described above.
c
c w is an output array of length m. w(i) contains information
c necessary to recover the givens rotation gw(i) described
c above.
c
c sing is a logical output variable. sing is set true if any
c of the diagonal elements of the output s are zero. otherwise
c sing is set false.
c
c subprograms called
c
c minpack-supplied ... dpmpar
c
c fortran-supplied ... dabs,dsqrt
c
c argonne national laboratory. minpack project. march 1980.
c burton s. garbow, kenneth e. hillstrom, jorge j. more,
c john l. nazareth
c
c **********
integer i,j,jj,l,nmj,nm1
double precision cos,cotan,giant,one,p5,p25,sin,tan,tau,temp,
* zero
double precision dpmpar
data one,p5,p25,zero /1.0d0,5.0d-1,2.5d-1,0.0d0/
c
c giant is the largest magnitude.
c
giant = dpmpar(3)
c
c initialize the diagonal element pointer.
c
jj = (n*(2*m - n + 1))/2 - (m - n)
c
c move the nontrivial part of the last column of s into w.
c
l = jj
do 10 i = n, m
w(i) = s(l)
l = l + 1
10 continue
c
c rotate the vector v into a multiple of the n-th unit vector
c in such a way that a spike is introduced into w.
c
nm1 = n - 1
if (nm1 .lt. 1) go to 70
do 60 nmj = 1, nm1
j = n - nmj
jj = jj - (m - j + 1)
w(j) = zero
if (v(j) .eq. zero) go to 50
c
c determine a givens rotation which eliminates the
c j-th element of v.
c
if (dabs(v(n)) .ge. dabs(v(j))) go to 20
cotan = v(n)/v(j)
sin = p5/dsqrt(p25+p25*cotan**2)
cos = sin*cotan
tau = one
if (dabs(cos)*giant .gt. one) tau = one/cos
go to 30
20 continue
tan = v(j)/v(n)
cos = p5/dsqrt(p25+p25*tan**2)
sin = cos*tan
tau = sin
30 continue
c
c apply the transformation to v and store the information
c necessary to recover the givens rotation.
c
v(n) = sin*v(j) + cos*v(n)
v(j) = tau
c
c apply the transformation to s and extend the spike in w.
c
l = jj
do 40 i = j, m
temp = cos*s(l) - sin*w(i)
w(i) = sin*s(l) + cos*w(i)
s(l) = temp
l = l + 1
40 continue
50 continue
60 continue
70 continue
c
c add the spike from the rank 1 update to w.
c
do 80 i = 1, m
w(i) = w(i) + v(n)*u(i)
80 continue
c
c eliminate the spike.
c
sing = .false.
if (nm1 .lt. 1) go to 140
do 130 j = 1, nm1
if (w(j) .eq. zero) go to 120
c
c determine a givens rotation which eliminates the
c j-th element of the spike.
c
if (dabs(s(jj)) .ge. dabs(w(j))) go to 90
cotan = s(jj)/w(j)
sin = p5/dsqrt(p25+p25*cotan**2)
cos = sin*cotan
tau = one
if (dabs(cos)*giant .gt. one) tau = one/cos
go to 100
90 continue
tan = w(j)/s(jj)
cos = p5/dsqrt(p25+p25*tan**2)
sin = cos*tan
tau = sin
100 continue
c
c apply the transformation to s and reduce the spike in w.
c
l = jj
do 110 i = j, m
temp = cos*s(l) + sin*w(i)
w(i) = -sin*s(l) + cos*w(i)
s(l) = temp
l = l + 1
110 continue
c
c store the information necessary to recover the
c givens rotation.
c
w(j) = tau
120 continue
c
c test for zero diagonal elements in the output s.
c
if (s(jj) .eq. zero) sing = .true.
jj = jj + (m - j + 1)
130 continue
140 continue
c
c move w back into the last column of the output s.
c
l = jj
do 150 i = n, m
s(l) = w(i)
l = l + 1
150 continue
if (s(jj) .eq. zero) sing = .true.
return
c
c last card of subroutine r1updt.
c
end
| bsd-3-clause |
LeChuck42/or1k-gcc | libgfortran/generated/_cos_r4.F90 | 35 | 1468 | ! Copyright (C) 2002-2014 Free Software Foundation, Inc.
! Contributed by Paul Brook <paul@nowt.org>
!
!This file is part of the GNU Fortran 95 runtime library (libgfortran).
!
!GNU libgfortran 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 3 of the License, or (at your option) any later version.
!GNU libgfortran 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.
!
!Under Section 7 of GPL version 3, you are granted additional
!permissions described in the GCC Runtime Library Exception, version
!3.1, as published by the Free Software Foundation.
!
!You should have received a copy of the GNU General Public License and
!a copy of the GCC Runtime Library Exception along with this program;
!see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
!<http://www.gnu.org/licenses/>.
!
!This file is machine generated.
#include "config.h"
#include "kinds.inc"
#include "c99_protos.inc"
#if defined (HAVE_GFC_REAL_4)
#ifdef HAVE_COSF
elemental function _gfortran_specific__cos_r4 (parm)
real (kind=4), intent (in) :: parm
real (kind=4) :: _gfortran_specific__cos_r4
_gfortran_specific__cos_r4 = cos (parm)
end function
#endif
#endif
| gpl-2.0 |
CompPhysics/ThesisProjects | doc/MSc/msc_students/former/SeanMiller/Thesis/Codes/CCD_prototype/CCD/eigen3/lapack/zlarf.f | 281 | 6278 | *> \brief \b ZLARF
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ZLARF + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlarf.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlarf.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlarf.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE ZLARF( SIDE, M, N, V, INCV, TAU, C, LDC, WORK )
*
* .. Scalar Arguments ..
* CHARACTER SIDE
* INTEGER INCV, LDC, M, N
* COMPLEX*16 TAU
* ..
* .. Array Arguments ..
* COMPLEX*16 C( LDC, * ), V( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZLARF applies a complex elementary reflector H to a complex M-by-N
*> matrix C, from either the left or the right. H is represented in the
*> form
*>
*> H = I - tau * v * v**H
*>
*> where tau is a complex scalar and v is a complex vector.
*>
*> If tau = 0, then H is taken to be the unit matrix.
*>
*> To apply H**H, supply conjg(tau) instead
*> tau.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] SIDE
*> \verbatim
*> SIDE is CHARACTER*1
*> = 'L': form H * C
*> = 'R': form C * H
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix C.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix C.
*> \endverbatim
*>
*> \param[in] V
*> \verbatim
*> V is COMPLEX*16 array, dimension
*> (1 + (M-1)*abs(INCV)) if SIDE = 'L'
*> or (1 + (N-1)*abs(INCV)) if SIDE = 'R'
*> The vector v in the representation of H. V is not used if
*> TAU = 0.
*> \endverbatim
*>
*> \param[in] INCV
*> \verbatim
*> INCV is INTEGER
*> The increment between elements of v. INCV <> 0.
*> \endverbatim
*>
*> \param[in] TAU
*> \verbatim
*> TAU is COMPLEX*16
*> The value tau in the representation of H.
*> \endverbatim
*>
*> \param[in,out] C
*> \verbatim
*> C is COMPLEX*16 array, dimension (LDC,N)
*> On entry, the M-by-N matrix C.
*> On exit, C is overwritten by the matrix H * C if SIDE = 'L',
*> or C * H if SIDE = 'R'.
*> \endverbatim
*>
*> \param[in] LDC
*> \verbatim
*> LDC is INTEGER
*> The leading dimension of the array C. LDC >= max(1,M).
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is COMPLEX*16 array, dimension
*> (N) if SIDE = 'L'
*> or (M) if SIDE = 'R'
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup complex16OTHERauxiliary
*
* =====================================================================
SUBROUTINE ZLARF( SIDE, M, N, V, INCV, TAU, C, LDC, WORK )
*
* -- LAPACK auxiliary routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
CHARACTER SIDE
INTEGER INCV, LDC, M, N
COMPLEX*16 TAU
* ..
* .. Array Arguments ..
COMPLEX*16 C( LDC, * ), V( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
COMPLEX*16 ONE, ZERO
PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ),
$ ZERO = ( 0.0D+0, 0.0D+0 ) )
* ..
* .. Local Scalars ..
LOGICAL APPLYLEFT
INTEGER I, LASTV, LASTC
* ..
* .. External Subroutines ..
EXTERNAL ZGEMV, ZGERC
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILAZLR, ILAZLC
EXTERNAL LSAME, ILAZLR, ILAZLC
* ..
* .. Executable Statements ..
*
APPLYLEFT = LSAME( SIDE, 'L' )
LASTV = 0
LASTC = 0
IF( TAU.NE.ZERO ) THEN
* Set up variables for scanning V. LASTV begins pointing to the end
* of V.
IF( APPLYLEFT ) THEN
LASTV = M
ELSE
LASTV = N
END IF
IF( INCV.GT.0 ) THEN
I = 1 + (LASTV-1) * INCV
ELSE
I = 1
END IF
* Look for the last non-zero row in V.
DO WHILE( LASTV.GT.0 .AND. V( I ).EQ.ZERO )
LASTV = LASTV - 1
I = I - INCV
END DO
IF( APPLYLEFT ) THEN
* Scan for the last non-zero column in C(1:lastv,:).
LASTC = ILAZLC(LASTV, N, C, LDC)
ELSE
* Scan for the last non-zero row in C(:,1:lastv).
LASTC = ILAZLR(M, LASTV, C, LDC)
END IF
END IF
* Note that lastc.eq.0 renders the BLAS operations null; no special
* case is needed at this level.
IF( APPLYLEFT ) THEN
*
* Form H * C
*
IF( LASTV.GT.0 ) THEN
*
* w(1:lastc,1) := C(1:lastv,1:lastc)**H * v(1:lastv,1)
*
CALL ZGEMV( 'Conjugate transpose', LASTV, LASTC, ONE,
$ C, LDC, V, INCV, ZERO, WORK, 1 )
*
* C(1:lastv,1:lastc) := C(...) - v(1:lastv,1) * w(1:lastc,1)**H
*
CALL ZGERC( LASTV, LASTC, -TAU, V, INCV, WORK, 1, C, LDC )
END IF
ELSE
*
* Form C * H
*
IF( LASTV.GT.0 ) THEN
*
* w(1:lastc,1) := C(1:lastc,1:lastv) * v(1:lastv,1)
*
CALL ZGEMV( 'No transpose', LASTC, LASTV, ONE, C, LDC,
$ V, INCV, ZERO, WORK, 1 )
*
* C(1:lastc,1:lastv) := C(...) - w(1:lastc,1) * v(1:lastv,1)**H
*
CALL ZGERC( LASTC, LASTV, -TAU, WORK, 1, V, INCV, C, LDC )
END IF
END IF
RETURN
*
* End of ZLARF
*
END
| cc0-1.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/whole_file_9.f90 | 169 | 1069 | ! { dg-do compile }
! { dg-options "-fwhole-file" }
! Test the fix for the fourth problem in PR40011, where the
! entries were not resolved, resulting in a segfault.
!
! Contributed by Dominique d'Humieres <dominiq@lps.ens.fr>
!
program test
interface
function bad_stuff(n)
integer :: bad_stuff (2)
integer :: n(2)
end function bad_stuff
recursive function rec_stuff(n) result (tmp)
integer :: n(2), tmp(2)
end function rec_stuff
end interface
integer :: res(2)
res = bad_stuff((/-19,-30/))
end program test
recursive function bad_stuff(n)
integer :: bad_stuff (2)
integer :: n(2), tmp(2), ent = 0, sent = 0
save ent, sent
ent = -1
entry rec_stuff(n) result (tmp)
if (ent == -1) then
sent = ent
ent = 0
end if
ent = ent + 1
tmp = 1
if(maxval (n) < 5) then
tmp = tmp + rec_stuff (n+1)
ent = ent - 1
endif
if (ent == 1) then
if (sent == -1) then
bad_stuff = tmp + bad_stuff (1)
end if
ent = 0
sent = 0
end if
end function bad_stuff
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ngmath/src/lib/gridpack/fitgrid/curv2.f | 1 | 2536 | C
C $Id: curv2.f,v 1.5 2008-07-27 03:10:10 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
C NOTE: If you make any changes to this software, please remember to
C make the same changes to the corresponding double precision routine.
C
function curv2 (t,n,x,y,yp,sigma)
c
integer n
real t,x(n),y(n),yp(n),sigma
c
c coded by alan kaylor cline
c from fitpack -- january 26, 1987
c a curve and surface fitting package
c a product of pleasant valley software
c 8603 altus cove, austin, texas 78759, usa
c
c this function interpolates a curve at a given point
c using a spline under tension. the subroutine curv1 should
c be called earlier to determine certain necessary
c parameters.
c
c on input--
c
c t contains a real value to be mapped onto the interpo-
c lating curve.
c
c n contains the number of points which were specified to
c determine the curve.
c
c x and y are arrays containing the abscissae and
c ordinates, respectively, of the specified points.
c
c yp is an array of second derivative values of the curve
c at the nodes.
c
c and
c
c sigma contains the tension factor (its sign is ignored).
c
c the parameters n, x, y, yp, and sigma should be input
c unaltered from the output of curv1.
c
c on output--
c
c curv2 contains the interpolated value.
c
c none of the input parameters are altered.
c
c this function references package modules intrvl and
c snhcsh.
c
c-----------------------------------------------------------
c
c determine interval
c
im1 = intrvl(t,x,n)
i = im1+1
c
c denormalize tension factor
c
sigmap = abs(sigma)*float(n-1)/(x(n)-x(1))
c
c set up and perform interpolation
c
del1 = t-x(im1)
del2 = x(i)-t
dels = x(i)-x(im1)
sum = (y(i)*del1+y(im1)*del2)/dels
if (sigmap .ne. 0.) go to 1
curv2 = sum-del1*del2*(yp(i)*(del1+dels)+yp(im1)*
* (del2+dels))/(6.*dels)
return
1 sigdel = sigmap*dels
call snhcsh (ss,dummy,sigdel,-1)
call snhcsh (s1,dummy,sigmap*del1,-1)
call snhcsh (s2,dummy,sigmap*del2,-1)
curv2 = sum+(yp(i)*del1*(s1-ss)+yp(im1)*del2*(s2-ss))/
* (sigdel*sigmap*(1.+ss))
return
end
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/dgebd2.f | 15 | 7994 | SUBROUTINE DGEBD2( M, N, A, LDA, D, E, TAUQ, TAUP, WORK, INFO )
*
* -- LAPACK 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 ..
INTEGER INFO, LDA, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), D( * ), E( * ), TAUP( * ),
$ TAUQ( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DGEBD2 reduces a real general m by n matrix A to upper or lower
* bidiagonal form B by an orthogonal transformation: Q' * A * P = B.
*
* If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal.
*
* Arguments
* =========
*
* M (input) INTEGER
* The number of rows in the matrix A. M >= 0.
*
* N (input) INTEGER
* The number of columns in the matrix A. N >= 0.
*
* A (input/output) 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.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,M).
*
* D (output) DOUBLE PRECISION array, dimension (min(M,N))
* The diagonal elements of the bidiagonal matrix B:
* D(i) = A(i,i).
*
* E (output) 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.
*
* TAUQ (output) DOUBLE PRECISION array dimension (min(M,N))
* The scalar factors of the elementary reflectors which
* represent the orthogonal matrix Q. See Further Details.
*
* TAUP (output) DOUBLE PRECISION array, dimension (min(M,N))
* The scalar factors of the elementary reflectors which
* represent the orthogonal matrix P. See Further Details.
*
* WORK (workspace) DOUBLE PRECISION array, dimension (max(M,N))
*
* INFO (output) INTEGER
* = 0: successful exit.
* < 0: if INFO = -i, the i-th argument had an illegal value.
*
* Further Details
* ===============
*
* 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' and G(i) = I - taup * u * u'
*
* 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' and G(i) = I - taup * u * u'
*
* 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).
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I
* ..
* .. External Subroutines ..
EXTERNAL DLARF, DLARFG, XERBLA
* ..
* .. 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.LT.0 ) THEN
CALL XERBLA( 'DGEBD2', -INFO )
RETURN
END IF
*
IF( M.GE.N ) THEN
*
* Reduce to upper bidiagonal form
*
DO 10 I = 1, N
*
* Generate elementary reflector H(i) to annihilate A(i+1:m,i)
*
CALL DLARFG( M-I+1, A( I, I ), A( MIN( I+1, M ), I ), 1,
$ TAUQ( I ) )
D( I ) = A( I, I )
A( I, I ) = ONE
*
* Apply H(i) to A(i:m,i+1:n) from the left
*
CALL DLARF( 'Left', M-I+1, N-I, A( I, I ), 1, TAUQ( I ),
$ A( I, I+1 ), LDA, WORK )
A( I, I ) = D( I )
*
IF( I.LT.N ) THEN
*
* Generate elementary reflector G(i) to annihilate
* A(i,i+2:n)
*
CALL DLARFG( N-I, A( I, I+1 ), A( I, MIN( I+2, N ) ),
$ LDA, TAUP( I ) )
E( I ) = A( I, I+1 )
A( I, I+1 ) = ONE
*
* Apply G(i) to A(i+1:m,i+1:n) from the right
*
CALL DLARF( 'Right', M-I, N-I, A( I, I+1 ), LDA,
$ TAUP( I ), A( I+1, I+1 ), LDA, WORK )
A( I, I+1 ) = E( I )
ELSE
TAUP( I ) = ZERO
END IF
10 CONTINUE
ELSE
*
* Reduce to lower bidiagonal form
*
DO 20 I = 1, M
*
* Generate elementary reflector G(i) to annihilate A(i,i+1:n)
*
CALL DLARFG( N-I+1, A( I, I ), A( I, MIN( I+1, N ) ), LDA,
$ TAUP( I ) )
D( I ) = A( I, I )
A( I, I ) = ONE
*
* Apply G(i) to A(i+1:m,i:n) from the right
*
CALL DLARF( 'Right', M-I, N-I+1, A( I, I ), LDA, TAUP( I ),
$ A( MIN( I+1, M ), I ), LDA, WORK )
A( I, I ) = D( I )
*
IF( I.LT.M ) THEN
*
* Generate elementary reflector H(i) to annihilate
* A(i+2:m,i)
*
CALL DLARFG( M-I, A( I+1, I ), A( MIN( I+2, M ), I ), 1,
$ TAUQ( I ) )
E( I ) = A( I+1, I )
A( I+1, I ) = ONE
*
* Apply H(i) to A(i+1:m,i+1:n) from the left
*
CALL DLARF( 'Left', M-I, N-I, A( I+1, I ), 1, TAUQ( I ),
$ A( I+1, I+1 ), LDA, WORK )
A( I+1, I ) = E( I )
ELSE
TAUQ( I ) = ZERO
END IF
20 CONTINUE
END IF
RETURN
*
* End of DGEBD2
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/examples/ewmap/wmex14.f | 1 | 34802 |
PROGRAM WMEX14
C
C An example of using the tools in the weather map library to
C create a color weather map.
C
C By default, the plot has a white background, to produce a plot
C with a black background, set IBTYPE=1 below.
C
PARAMETER (IBTYPE=0)
C
C Define the error file, the Fortran unit number, the workstation type,
C and the workstation ID to be used in calls to GKS routines.
C
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript
C
PARAMETER (IERRF=6, LUNIT=2, IWTYPE=26, IWKID=1)
C
INTEGER WMGTLN
C
C The MERGCM common block is used elsewhere in this code, but
C can be used for scratch space here in the main driver.
C
COMMON /MERGCM/ XTMP(9999),YTMP(9999),NDUM
C
C Set up all of the coordinate data for the fronts, temperature regions,
C cities, etc.
C
PARAMETER (ICDIM=6000)
DIMENSION USX(ICDIM),USY(ICDIM)
C
C Weather front arrays.
C
C NUMF - the number of fronts.
C NUMFP - the maximum number of control points for any front.
C LIMITF - the defined number of control points for each region.
C FRNSUX - X user coordinates for fronts.
C FRNSUY - Y user coordinates for fronts.
C
PARAMETER(NUMF=4,NUMFP=6)
DIMENSION LIMITF(NUMFP),
+ FRNSUX(NUMFP,NUMF),FRNSUY(NUMFP,NUMF),
+ FRNSWX(NUMFP),FRNSWY(NUMFP)
C
C Temperature and weather region arrays.
C
C NUMR - the number of regions
C NUMRP - the maximum number of control points for any region.
C LIMITS - the defined number of control points for each region.
C IRTYPE - the type of region.
C RGNSUX - X user coordinates for regions.
C RGNSUY - Y user coordinates for regions.
C
PARAMETER(NUMR=14,NUMRP=35)
CHARACTER*13 IRTYPE(NUMRP)
DIMENSION LIMITS(NUMRP),RGNSUX(NUMRP,NUMR),RGNSUY(NUMRP,NUMR),
+ RGNSWX(NUMRP),RGNSWY(NUMRP)
C
C Regional weather labels.
C
C NUMWL - the number of labels.
C CNDSUX - X user coordinates for labels.
C CNDSUY - Y user coordinates for labels.
C ICNDSL - Labels.
C
PARAMETER(NUMWL=5)
DIMENSION CNDSUX(NUMWL),CNDSUY(NUMWL)
CHARACTER*6 ICNDSL(NUMWL)
C
C LOW/HIGH arrays.
C
C NUML - the number of lows and highs to plot.
C FRNSUX - X user coordinates for symbols.
C FRNSUY - Y user coordinates for symbols.
C LOWHI - Array of Low/High flags (0=low; 1=hi).
C
PARAMETER(NUML=5)
DIMENSION RLOHUX(NUML),RLOHUY(NUML),LOWHI(NUML)
C
C City names, locations, daily hi/low labels.
C
C NUMC - the number of cities.
C ICITYS - City names.
C IDLYTS - Daily hi/low labels for cities.
C CITYUX - X user coordinates for city locations.
C CITYUY - Y user coordinates for city locations.
C TEMPUX - X user coordinates for daily hi/low locations.
C TEMPUY - Y user coordinates for daily hi/low locations.
C
PARAMETER(NUMC=14)
DIMENSION CITYUX(NUMC),CITYUY(NUMC),TEMPUX(NUMC),TEMPUY(NUMC)
CHARACTER*13 ICITYS(NUMC)
CHARACTER* 7 IDLYTS(NUMC)
C
C Front data.
C
C Front from Calif. to N. Dakota.
DATA LIMITF(1)/4/
DATA (FRNSUX(II,1),II=1,NUMFP)/
+ 41.0, 42.5, 44.5, 49.0, 00.0, 00.0 /
DATA (FRNSUY(II,1),II=1,NUMFP)/
+ -121.5, -111.0, -104.0, -098.0, 00.0, 00.0 /
C
C Front from N. Dakota to Virginia.
DATA LIMITF(2)/6/
DATA (FRNSUX(II,2),II=1,NUMFP)/
+ 49.0, 47.0, 45.0, 42.0, 38.8, 38.5 /
DATA (FRNSUY(II,2),II=1,NUMFP)/
+ -098.0, -096.0, -095.0, -093.0, -088.3, -080.5 /
C
C Front from Virginia out into the Atlantic.
DATA LIMITF(3)/3/
DATA (FRNSUX(II,3),II=1,NUMFP)/
+ 38.5, 39.0, 37.5, 00.0, 00.0, 00.0 /
DATA (FRNSUY(II,3),II=1,NUMFP)/
+ -080.5, -077.0, -071.0, 00.0, 00.0, 00.0 /
C
C Front from Virginia into Canada.
DATA LIMITF(4)/3/
DATA (FRNSUX(II,4),II=1,NUMFP)/
+ 38.5, 43.0, 49.0, 00.0, 00.0, 00.0 /
DATA (FRNSUY(II,4),II=1,NUMFP)/
+ -080.5, -077.5, -077.0, 00.0, 00.0, 00.0 /
C
C Region data.
C
C 60s in Calif. (must be plotted before the 70s region in Calif.)
DATA LIMITS(1),IRTYPE(1)/14,'INDEX6'/
DATA (RGNSUX(II,1),II=1,NUMRP)/
+ 32.0, 34.5, 35.5, 37.0, 40.0, 42.8, 46.0,
+ 49.0, 50.0, 49.0, 45.0, 40.0, 35.0, 32.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,1),II=1,NUMRP)/
+ -120.0, -120.0, -120.1, -121.0, -122.8, -123.4, -122.5,
+ -122.0, -124.0, -127.0, -126.0, -125.0, -123.0, -120.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C 90s in the south and west.
DATA LIMITS(2),IRTYPE(2)/32,'INDEX3'/
DATA (RGNSUX(II,2),II=1,NUMRP)/
+ 32.7, 34.5, 38.0, 42.0, 45.0, 47.5, 46.0,
+ 43.0, 39.5, 38.3, 40.0, 37.5, 35.5, 32.7,
+ 36.0, 41.0, 42.0, 44.5, 47.0, 48.0, 46.0,
+ 42.0, 39.0, 36.0, 37.3, 33.0, 37.5, 29.0,
+ 24.0, 20.0, 29.0, 32.7, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,2),II=1,NUMRP)/
+ -116.0, -117.0, -120.5, -122.7, -122.0, -118.0, -115.3,
+ -113.0, -107.5, -109.0, -115.0, -114.0, -111.5, -109.0,
+ -106.0, -105.0, -104.0, -107.0, -109.7, -104.0, -098.0,
+ -095.5, -096.0, -093.0, -088.5, -083.0, -076.0, -075.0,
+ -080.0, -097.0, -115.0, -116.0, 00.0, 00.0, 00.0 /
C
C 70s in Calif. and NW.
DATA LIMITS(3),IRTYPE(3)/25,'INDEX5'/
DATA (RGNSUX(II,3),II=1,NUMRP)/
+ 35.0, 36.0, 38.0, 40.0, 43.0, 46.5, 48.5,
+ 47.0, 44.0, 44.5, 46.0, 47.0, 49.0, 53.0,
+ 48.0, 46.0, 42.8, 40.0, 37.0, 35.5, 35.0,
+ 33.0, 28.0, 30.0, 32.7, 35.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,3),II=1,NUMRP)/
+ -118.7, -120.0, -121.5, -122.7, -123.1, -121.8, -118.0,
+ -114.5, -112.0, -110.5, -112.0, -113.2, -114.0, -122.0,
+ -123.5, -123.0, -123.5, -123.0, -121.5, -120.5, -120.9,
+ -122.0, -120.0, -116.0, -116.5, -118.7, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C 70s in Gt. Lakes area
DATA LIMITS(4),IRTYPE(4)/7,'INDEX5'/
DATA (RGNSUX(II,4),II=1,NUMRP)/
+ 49.0, 45.5, 46.0, 50.0, 53.0, 51.5, 49.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,4),II=1,NUMRP)/
+ -096.0, -090.5, -084.0, -082.0, -089.0, -095.0, -096.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C 70s in New England.
DATA LIMITS(5),IRTYPE(5)/7,'INDEX5'/
DATA (RGNSUX(II,5),II=1,NUMRP)/
+ 45.0, 43.2, 41.5, 43.0, 47.0, 49.0, 45.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,5),II=1,NUMRP)/
+ -073.3, -072.5, -070.5, -066.0, -065.0, -071.0, -073.3,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C 100s in Calif./Arizona (Must be plotted after 90s in southwest)
DATA LIMITS(6),IRTYPE(6)/8,'INDEX2'/
DATA (RGNSUX(II,6),II=1,NUMRP)/
+ 32.7, 35.0, 36.0, 35.3, 33.0, 31.3, 30.0,
+ 32.7, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,6),II=1,NUMRP)/
+ -115.0, -116.0, -115.3, -114.0, -111.0, -111.0, -113.0,
+ -115.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C 100s in Okla./Texas (must be plotted after 90s in Okla./Texas)
DATA LIMITS(7),IRTYPE(7)/5,'INDEX2'/
DATA (RGNSUX(II,7),II=1,NUMRP)/
+ 35.0, 33.0, 31.5, 33.0, 35.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,7),II=1,NUMRP)/
+ -097.5, -096.5, -097.5, -098.5, -097.5, 00.0, 000.0,
+ -080.0, -097.0, -115.0, -116.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C T-storms in the southwest.
DATA LIMITS(8),IRTYPE(8)/14,'THUNDERSTORMS'/
DATA (RGNSUX(II,8),II=1,NUMRP)/
+ 33.5, 35.5, 37.2, 38.5, 39.5, 39.5, 38.0,
+ 36.0, 34.5, 33.0, 30.0, 30.0, 31.0, 33.5,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,8),II=1,NUMRP)/
+ -110.2, -111.5, -113.0, -111.5, -108.5, -106.3, -105.5,
+ -106.0, -107.5, -108.0, -108.3, -109.6, -110.2, -110.2,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C T-storms in N. Minn.
DATA LIMITS(9),IRTYPE(9)/8,'THUNDERSTORMS'/
DATA (RGNSUX(II,9),II=1,NUMRP)/
+ 49.0, 50.5, 49.0, 47.0, 45.0, 45.0, 47.0,
+ 49.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,9),II=1,NUMRP)/
+ -097.0, -094.0, -090.0, -089.3, -091.5, -093.5, -096.0,
+ -097.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C T-storms in California.
DATA LIMITS(10),IRTYPE(10)/5,'THUNDERSTORMS'/
DATA (RGNSUX(II,10),II=1,NUMRP)/
+ 39.0, 38.0, 35.3, 37.0, 39.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,10),II=1,NUMRP)/
+ -120.0, -118.0, -116.5, -119.0, -120.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C Showers in Montana.
DATA LIMITS(11),IRTYPE(11)/8,'SHOWERS'/
DATA (RGNSUX(II,11),II=1,NUMRP)/
+ 50.0, 49.0, 48.0, 47.0, 46.7, 48.0, 50.0,
+ 50.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,11),II=1,NUMRP)/
+ -105.0, -105.0, -106.0, -108.0, -110.7, -110.0, -106.5,
+ -105.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C T-storms in southeast
DATA LIMITS(12),IRTYPE(12)/12,'THUNDERSTORMS'/
DATA (RGNSUX(II,12),II=1,NUMRP)/
+ 36.7, 35.0, 32.0, 31.0, 31.6, 32.2, 32.8,
+ 32.2, 32.2, 34.0, 36.0, 36.7, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,12),II=1,NUMRP)/
+ -076.0, -078.0, -081.5, -084.0, -088.0, -089.5, -088.0,
+ -085.0, -083.0, -080.4, -078.0, -076.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C T-storms from Missouri to New York.
DATA LIMITS(13),IRTYPE(13)/20,'THUNDERSTORMS'/
DATA (RGNSUX(II,13),II=1,NUMRP)/
+ 35.0, 36.5, 36.5, 37.7, 38.5, 41.0, 45.0,
+ 47.0, 49.0, 48.5, 47.0, 44.0, 42.8, 41.5,
+ 40.0, 38.0, 36.0, 34.5, 34.5, 35.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,13),II=1,NUMRP)/
+ -094.0, -092.0, -089.0, -084.0, -079.0, -077.0, -076.0,
+ -076.0, -075.7, -074.5, -073.3, -071.5, -070.3, -070.5,
+ -074.0, -077.5, -081.0, -087.0, -092.0, -094.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C Showers in extreme northeast
DATA LIMITS(14),IRTYPE(14)/8,'SHOWERS'/
DATA (RGNSUX(II,14),II=1,NUMRP)/
+ 49.5, 49.0, 47.0, 44.0, 44.0, 47.0, 48.5,
+ 49.5, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
DATA (RGNSUY(II,14),II=1,NUMRP)/
+ -073.8, -071.0, -069.5, -069.0, -071.0, -073.0, -074.0,
+ -073.8, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0,
+ 00.0, 00.0, 00.0, 00.0, 00.0, 00.0, 00.0 /
C
C LOWs and HIs.
C
DATA (RLOHUX(II),II=1,NUML) / 49.0, 38.5, 47.5, 44.0, 26.5 /
DATA (RLOHUY(II),II=1,NUML) /-099.0,-080.5,-127.0,-089.0,-088.0 /
DATA ( LOWHI(II),II=1,NUML) / 0, 0, 1, 1, 1 /
C
C Labels of regional conditions.
C
DATA (CNDSUX(II),II=1,NUMWL) / 45.5, 41.5, 31.5, 33.0, 45.5 /
DATA (CNDSUY(II),II=1,NUMWL) /-113.0,-099.0,-095.5,-113.2,-082.0 /
DATA (ICNDSL(II),II=1,NUMWL) /
+ 'BREEZY','HOT','STEAMY','HUMID','NICE'/
C
C Data on city locations and daily temperature labels.
C
DATA (ICITYS(II),II=1,NUMC)/
+ 'NCAR', 'Seattle', 'San Francisco',
+ 'Los Angeles', 'Billings', 'El Paso',
+ 'Houston', 'Kansas City', 'Minneapolis',
+ 'Chicago', 'Detroit', 'Atlanta',
+ 'Miami', 'New York' /
DATA (CITYUX(II),II=1,NUMC)/
+ 40.0, 47.6, 37.8, 34.1, 45.8, 31.8, 29.8,
+ 39.1, 45.0, 41.9, 42.3, 33.8, 25.8, 40.8 /
DATA (CITYUY(II),II=1,NUMC)/
+ -105.0, -122.3, -122.4, -118.3, -108.5, -106.5, -095.3,
+ -094.6, -093.8, -087.6, -083.1, -084.4, -080.2, -074.0 /
DATA (TEMPUX(II),II=1,NUMC)/
+ 38.8, 46.9, 38.6, 35.0, 46.0, 32.2, 28.8,
+ 37.7, 46.0, 40.7, 43.7, 32.4, 27.2, 40.5 /
DATA (TEMPUY(II),II=1,NUMC)/
+ -103.2, -119.6, -120.3, -116.0, -105.6, -104.2, -097.4,
+ -092.4, -091.2, -085.2, -082.8, -084.6, -081.3, -071.5 /
DATA (IDLYTS(II),II=1,NUMC)/
+ '92/58', '80/58', '68/54', '80/64', '91/58', '96/70', '98/76',
+ '88/70', '84/67', '84/66', '84/63', '90/72', '92/80', '83/70' /
C
C Set up color indices to use for temperature regions.
C
DATA IC60S,IC70S,IC80S,IC90S,IC100S/6,5,4,3,2/
C
DATA IWBACK,IBBACK/0,1/
C
C Open GKS.
C
CALL GOPKS (IERRF, ISZDM)
C
C Calls to position the output (applicable only to PostScript output).
C
CALL NGSETI('LX',-90)
CALL NGSETI('UX',710)
CALL NGSETI('LY',-15)
CALL NGSETI('UY',785)
CALL GOPWK (IWKID, LUNIT, IWTYPE)
C
C Set line caps to "butt" and fill the entire page for background (for
C color PostScript output only).
C
CALL NGSETI('WO',IWKID)
CALL NGSETI('FU',1)
CALL NGSETI('CA',0)
C
CALL GACWK (IWKID)
C
IF (IBTYPE .EQ. IWBACK) THEN
C
C White background.
CALL GSCR(IWKID, 0, 1.00, 1.00, 1.00)
CALL GSCR(IWKID, 1, 0.00, 0.00, 0.00)
ELSE
C
C Black background.
CALL GSCR(IWKID, 0, 0.00, 0.00, 0.00)
CALL GSCR(IWKID, 1, 1.00, 1.00, 1.00)
ENDIF
C
C Color for 100 degree temperature regions.
CALL GSCR(IWKID, 2, 1.00, 0.25, 0.00)
C
C Color for 90 degree temperature regions.
CALL GSCR(IWKID, 3, 1.00, 0.50, 0.00)
C
C Color for 80 degree temperature regions.
CALL GSCR(IWKID, 4, 1.00, 0.75, 0.00)
C
C Color for 70 degree temperature regions.
CALL GSCR(IWKID, 5, 1.00, 1.00, 0.00)
C
C Color for 60 degree temperature regions.
CALL GSCR(IWKID, 6, 0.25, 1.00, 0.50)
C
C Continental shadow and background for low and hi symbols.
CALL GSCR(IWKID, 7, 0.60, 0.60, 0.60)
C
C Color for cold front symbols.
IF (IBTYPE .EQ. IWBACK) THEN
CALL GSCR(IWKID, 8, 0.00, 0.00, 0.00)
ELSE
CALL GSCR(IWKID, 8, 0.20, 0.20, 1.00)
ENDIF
C
C Color for warm front symbols.
IF (IBTYPE .EQ. IWBACK) THEN
CALL GSCR(IWKID, 9, 0.00, 0.00, 0.00)
ELSE
CALL GSCR(IWKID, 9, 1.00, 0.00, 0.00)
ENDIF
C
C Color for temperature labels.
IF (IBTYPE .EQ. IWBACK) THEN
CALL GSCR(IWKID, 10, 1.00, 1.00, 1.00)
ELSE
CALL GSCR(IWKID, 10, 0.00, 1.00, 1.00)
ENDIF
C
C Regional weather patterns.
CALL GSCR(IWKID, 11, 0.00, 0.00, 0.00)
C
C Color for Highs
IF (IBTYPE .EQ. IWBACK) THEN
CALL GSCR(IWKID, 12, 0.00, 0.00, 0.00)
ELSE
CALL GSCR(IWKID, 12, 0.20, 0.20, 1.00)
ENDIF
C
C Dot color for marking cities.
CALL GSCR(IWKID, 13, 0.00, 0.00, 1.00)
C
C Get world coordinates for the U.S. continental boundary and store
C the U.S. state map in flash buffer 1. This takes some execution
C time.
C
CALL GOPWK(9,8,3)
CALL WMTINT(1,ICDIM,USX,USY,NO)
C
CALL GSFAIS(1)
CALL GSFACI(7)
C
C Get world coordinate extents, and plot a shaded offset of the
C continental U.S. boundary.
C
CALL TSTEXT(XEXT,YEXT)
DO 70 I=1,NO
XTMP(I) = USX(I)-.01*XEXT
YTMP(I) = USY(I)-.012*YEXT
70 CONTINUE
CALL GFA(NO,XTMP,YTMP)
CALL GSFACI(4)
CALL GFA(NO,USX,USY)
C
C-------------------------------
C Plot temperature regions. |
C-------------------------------
C
CALL WMGETI('COL',ICOLD)
DO 50 I=1,NUMR
INDXMX = LIMITS(I)
DO 60 J=1,INDXMX
CALL MAPTRN(RGNSUX(J,I),RGNSUY(J,I),RGNSWX(J),RGNSWY(J))
60 CONTINUE
IF (I .GE. 8) THEN
CALL WMSETI('COL',11)
ENDIF
CALL WMDRRG(LIMITS(I),RGNSWX,RGNSWY,IRTYPE(I),NO,USX,USY)
50 CONTINUE
CALL WMSETI('COL',ICOLD)
C
C------------------
C U.S. Map |
C------------------
C
CALL GFLAS3(1)
C
C----------------------------
C Plot the weather fronts. |
C----------------------------
C
DO 10 I=1,LIMITF(1)
CALL MAPTRN(FRNSUX(I,1),FRNSUY(I,1),FRNSWX(I),FRNSWY(I))
10 CONTINUE
CALL WMSETC('FRO','COLD')
CALL WMSETR('END',.040)
CALL WMSETI('WFC',9)
CALL WMSETI('CFC',8)
CALL WMDRFT(LIMITF(1),FRNSWX,FRNSWY)
CALL WMDFLT
C
C Convert to world coordinates.
DO 20 I=1,LIMITF(2)
CALL MAPTRN(FRNSUX(I,2),FRNSUY(I,2),FRNSWX(I),FRNSWY(I))
20 CONTINUE
C
C Define the type and direction of each symbol.
CALL WMSETI('PAI', 1)
CALL WMSETI('STY',-2)
CALL WMSETI('PAI', 2)
CALL WMSETI('STY',-2)
CALL WMSETI('PAI', 3)
CALL WMSETI('STY', 1)
CALL WMSETI('PAI', 4)
CALL WMSETI('STY',-2)
CALL WMSETI('PAI', 5)
CALL WMSETI('STY', 1)
C
C Define spacings.
CALL WMSETR('BEG',.03)
CALL WMSETR('END',.035)
CALL WMSETR('BET',.04)
CALL WMSETI('WFC',9)
CALL WMSETI('CFC',8)
C
C Draw front.
CALL WMDRFT(LIMITF(2),FRNSWX,FRNSWY)
C
C Reset parameters to default values.
CALL WMDFLT
C
DO 30 I=1,LIMITF(3)
CALL MAPTRN(FRNSUX(I,3),FRNSUY(I,3),FRNSWX(I),FRNSWY(I))
30 CONTINUE
CALL WMSETC('FRO','STA')
CALL WMSETR('BEG',.040)
CALL WMSETI('REV',1)
CALL WMSETI('WFC',9)
CALL WMSETI('CFC',8)
CALL WMDRFT(LIMITF(3),FRNSWX,FRNSWY)
CALL WMDFLT
C
DO 40 I=1,LIMITF(4)
CALL MAPTRN(FRNSUX(I,4),FRNSUY(I,4),FRNSWX(I),FRNSWY(I))
40 CONTINUE
CALL WMSETC('FRO','COLD')
CALL WMSETR('BEG',.040)
CALL WMSETR('BET',.030)
CALL WMSETI('WFC',9)
CALL WMSETI('CFC',8)
CALL WMDRFT(LIMITF(4),FRNSWX,FRNSWY)
CALL WMDFLT
C
C----------------
C LOs and HIs |
C----------------
C
CALL GSCLIP(0)
IF (IBTYPE .EQ. IBBACK) THEN
CALL WMSETI('LOS - shadow for low symbols',0)
CALL WMSETI('LOB - character background for low symbols',1)
CALL WMSETI('LOF - character color for low symbols',9)
CALL WMSETI('HIS - shadow for high symbols',7)
CALL WMSETI('HIB - character background for high symbols',1)
CALL WMSETI('HIF - character color for high symbols',12)
CALL WMSETI('HIC - character color circumscribed circle',0)
ENDIF
DO 80 I=1,NUML
CALL MAPTRN(RLOHUX(I),RLOHUY(I),XO,YO)
IF (LOWHI(I) .EQ. 0) THEN
CALL WMLABS(XO,YO,'LOW')
ELSE
CALL WMLABS(XO,YO,'HI')
ENDIF
80 CONTINUE
C
C-------------------------------
C Regional condition labels. |
C-------------------------------
C
IF (IBTYPE .EQ. IBBACK) THEN
CALL WMSETI('RC1',0)
CALL WMSETI('RC2',1)
CALL WMSETI('RC3',0)
CALL WMSETI('RC4',0)
ENDIF
DO 90 I=1,NUMWL
CALL MAPTRN(CNDSUX(I),CNDSUY(I),XO,YO)
LL = WMGTLN(ICNDSL(I),LEN(ICNDSL(I)),0)
CALL WMLABW(XO,YO,ICNDSL(I)(1:LL))
90 CONTINUE
C
C-----------------------------
C Cities and temperatures. |
C-----------------------------
C
C NUMC - the number of cities.
C ICITYS - City names.
C IDLYTS - Daily hi/low labels for cities.
C CITYUX - X user coordinates for city locations.
C CITYUY - Y user coordinates for city locations.
C TEMPUX - X user coordinates for daily hi/low locations.
C TEMPUY - Y user coordinates for daily hi/low locations.
CALL WMSETI('DTC',13)
IF (IBTYPE .EQ. IWBACK) THEN
CALL WMSETI('DBC- dot background color',0)
CALL WMSETI('RFC- foreground color for labels',1)
CALL WMSETI('CBC- background color for city labels',0)
ELSE
CALL WMSETI('DBC- dot background color',1)
CALL WMSETI('RFC- foreground color for labels',0)
CALL WMSETI('CBC- background color for city labels',1)
ENDIF
DO 110 I=1,NUMC
CALL MAPTRN(CITYUX(I),CITYUY(I),XO,YO)
CALL WMLABS(XO,YO,'D')
CALL MAPTRN(TEMPUX(I),TEMPUY(I),XO,YO)
LL = WMGTLN(ICITYS(I),LEN(ICITYS(I)),0)
MM = WMGTLN(IDLYTS(I),LEN(IDLYTS(I)),0)
CALL WMLABC(XO,YO,ICITYS(I)(1:LL),IDLYTS(I)(1:MM))
110 CONTINUE
CALL WMDFLT
C
C---------------------------------
C Regional temperature labels. |
C---------------------------------
C
CALL WMSETI('RFC - foreground color for labels',10)
CALL WMSETI('ASC - arrow shadow color',-1)
CALL GSLWSC(2.)
IF (IBTYPE .EQ. IWBACK) THEN
CALL WMSETI('AWC - arrow color',1)
CALL WMSETI('AOC - arrow outline color',-1)
CALL WMSETI('ROS - character outline color',1)
CALL WMSETI('RLS - shadow color',1)
ELSE
CALL WMSETI('AWC - arrow color',10)
CALL WMSETI('AOC - arrow outline color',0)
CALL WMSETI('ROS - character outline color',-1)
CALL WMSETI('RLS - shadow color',-1)
ENDIF
CALL GSLWSC(1.)
C
C S. Ariz.
CALL MAPTRN(32.,-112.,XO,YO)
CALL WMLABT(XO,YO,'100s',2)
C S. Calif.
CALL WMGETR('ARD',AANGO)
CALL WMGETR('ARL',ARLNO)
CALL WMSETR('ARD',65.)
CALL WMSETR('ARL',1.2)
CALL MAPTRN(34.9,-120.,XO,YO)
CALL WMLABS(XO,YO,'ARROW')
CALL WMSETR('ARD',AANGO)
CALL WMSETR('ARL',ARLNO)
CALL MAPTRN(32.8,-116.9,XO,YO)
CALL WMLABT(XO,YO,'70s',1)
C Oregon Pacific coast.
CALL MAPTRN(43.,-123.9,XO,YO)
CALL WMLABT(XO,YO,'60s',11)
C Idaho
CALL MAPTRN(48.25,-114.75,XO,YO)
CALL WMLABT(XO,YO,'70s',8)
C Gt. Lakes
CALL MAPTRN(47.7,-87.,XO,YO)
CALL WMLABT(XO,YO,'70s',8)
C N. Carolina
CALL MAPTRN(35.0,-78.,XO,YO)
CALL WMLABT(XO,YO,'90s',6)
C Maine
CALL MAPTRN(46.5,-68.5,XO,YO)
CALL WMLABT(XO,YO,'70s',9)
C Texas
IF (IBTYPE .EQ. IWBACK) THEN
CALL WMSETI('RLS - shadow color',1)
CALL WMSETI('ROS - character outline color',-1)
ELSE
CALL WMSETI('RLS - shadow color',0)
CALL WMSETI('ROS - character outline color',0)
ENDIF
C
CALL MAPTRN(31.25,-100.50,XO,YO)
CALL WMSETI('RBS',IC90S)
CALL WMLABT(XO,YO,'90s',0)
C S. of Okla.
CALL MAPTRN(34.3,-97.5,XO,YO)
CALL WMSETI('RBS',IC90S)
CALL WMLABT(XO,YO,'100s',11)
C N. Ariz./New Mexico
CALL MAPTRN(36.0,-109.0,XO,YO)
CALL WMSETI('RBS',IC80S)
CALL WMLABT(XO,YO,'80s',0)
C Oregon
CALL MAPTRN(43.7,-120.5,XO,YO)
CALL WMSETI('RBS',IC90S)
CALL WMLABT(XO,YO,'90s',0)
C Utah
CALL MAPTRN(40.0,-110.6,XO,YO)
CALL WMSETI('RBS',IC90S)
CALL WMLABT(XO,YO,'90s',0)
C N. Montana.
CALL MAPTRN(48.0,-111.,XO,YO)
CALL WMSETI('RBS',IC80S)
CALL WMLABT(XO,YO,'80s',0)
C S. Dakota
CALL MAPTRN(44.5,-100.0,XO,YO)
CALL WMSETI('RBS',IC90S)
CALL WMLABT(XO,YO,'90s',0)
C Iowa/Ill.
CALL MAPTRN(41.5,-89.6,XO,YO)
CALL WMSETI('RBS',IC80S)
CALL WMLABT(XO,YO,'80s',0)
C Miss.
CALL MAPTRN(33.4,-89.6,XO,YO)
CALL WMSETI('RBS',IC90S)
CALL WMLABT(XO,YO,'90s',0)
C Tenn.
CALL MAPTRN(35.7,-83.,XO,YO)
CALL WMSETI('RBS',IC80S)
CALL WMLABT(XO,YO,'80s',0)
C New York
CALL MAPTRN(42.7,-75.0,XO,YO)
CALL WMSETI('RBS',IC80S)
CALL WMLABT(XO,YO,'80s',0)
C
C-----------------
C Main title. |
C-----------------
C
CALL MAPTRN(53.,-98.0,XO,YO)
CALL WMSETI('RFC',1)
CALL WMSETI('RBS',-1)
CALL WMSETI('ROS',-1)
CALL WMSETI('RLS',-1)
CALL WMLABT(XO,YO,'July 18, 1994',0)
C--------------
C Legends. |
C--------------
C
CALL GQCNTN(IER,NTRO)
CALL GSELNT(0)
IF (IBTYPE .EQ. IWBACK) THEN
CALL WMSETI('COL',1)
ELSE
CALL WMSETI('COL',5)
ENDIF
CALL WMSETI('WFC',9)
CALL WMSETI('CFC',8)
CALL WMLGND(.05,0.16,1,6,1)
CALL WMLGND(.45,0.15,3,0,0)
CALL WMLGND(.90,0.15,2,0,0)
CALL GSELNT(NTRO)
C
CALL FRAME
C
CALL GDAWK (IWKID)
CALL GCLWK (9)
CALL GCLWK (IWKID)
CALL GCLKS
STOP
C
END
SUBROUTINE WMTINT(IBNUM,N,USX,USY,NO)
C
C Does some initialization. Stores a map of the U.S. state outlines
C in Flash buffer number IBNUM, and returns world coordinate values
C for the boundary of the U.S. in (USX(I),USY(I),I=1,NO). USX and
C USY are dimensioned for N and NO is returned as the actual number
C of coordinates in the dataset. N should be at least 6000.
C
C This routine also initializes the EZMAP parameters.
C
C Define space for the area map that is used to obtain the
C coordinates for the boundary of the continental U.S. Set up some
C arrays to be used by areas in obtaining the U.S. continental outline.
C The merged polygons from Areas are stored in common MERGCM.
C RTPTAR is a subroutine used by Areas to process the areas.
C
DIMENSION USX(N),USY(N)
C
COMMON /MEODCM/IEODF
PARAMETER (LAMA=100000)
DIMENSION IAMA(LAMA)
DIMENSION XCRA(10000),YCRA(10000),IAAI(10),IAGI(10)
COMMON /MERGCM/ XCMP(9999),YCMP(9999),NCMP
SAVE /MERGCM/
EXTERNAL RTPTAR
C
C Set up the parameters for drawing the U.S. state outlines.
C
C Position the plot.
C CALL MAPPOS(0.05, 0.95, 0.05, 0.95)
C
C Specify U.S. state outlines.
CALL MAPSTC('OU','US')
C
C Choose Lambert conformal projection with two standard parallels.
CALL MAPROJ('LC',30.,-100.,45.)
C
C Reduce the value of 'MV' to make what MAPDRW produces match what
C comes out of MAPBLA/ARSCAM.
CALL MAPSTI ('MV',1)
C
C Specify the corner points of the plot as lat/lon pairs.
CALL MAPSET('CO',22.6,-120.,46.9,-64.2)
C
C Initialize the transformations.
CALL MAPINT()
C
C Set the flag for MAPEOD to just consider boundary lines.
C
CALL GFLAS1(IBNUM)
IEODF = 1
CALL MAPLOT
C
C Initialize the area map, and put selected outlines in the area map.
C (A version of MAPEOD is supplied which causes anything not part of
C the outer boundary of the U.S. to be omitted).
C
CALL ARINAM (IAMA,LAMA)
CALL MAPBLA (IAMA)
NCMP=0
C
C Scan the area map using RTPTAR to fill all the polygons representing
C the U.S. Merge the polygons into a single polygon in MERGCM.
C
CALL ARSCAM (IAMA,XCRA,YCRA,10000,IAAI,IAGI,10,RTPTAR)
C
C Convert to world coordinates.
C
DO 101 I=1,NCMP
USX(I)=CFUX(XCMP(I))
USY(I)=CFUY(YCMP(I))
101 CONTINUE
IEODF = 0
CALL MAPLOT
CALL GFLAS2
NO = NCMP
C
RETURN
END
SUBROUTINE MAPEOD (NOUT,NSEG,IDLS,IDRS,NPTS,PNTS)
C
DIMENSION PNTS(*)
C
COMMON /MEODCM/IEODF
C
C This version of MAPEOD omits all parts of the 'US' outline dataset
C which are strictly internal, saving only those which are part of
C the external boundary. (The "border" has area identifier "223";
C we omit anything that is not on the "border".)
C
IF (IEODF .EQ. 1) THEN
IF (IDLS.NE.223 .AND. IDRS.NE.223) NPTS=0
ELSE
RETURN
ENDiF
C
END
SUBROUTINE RTPTAR (XCRA,YCRA,NCRA,IAAI,IAGI,NOFG)
C
C Calls MERGPO to merge all such polygons into one polygon.
C
DIMENSION XCRA(*),YCRA(*),IAAI(*),IAGI(*)
C
C Find the area identifier of the area relative to group 1.
C
IAG1=-1
C
DO 101 I=1,NOFG
IF (IAGI(I).EQ.1) IAG1=IAAI(I)
101 CONTINUE
C
C If the index of the area relative to group 1 is positive and not 223,
C fill it.
C
IF (IAG1.GT.0 .AND. IAG1.NE.223) THEN
CALL MERGPO (XCRA,YCRA,NCRA)
END IF
C
RETURN
END
SUBROUTINE MERGPO (XCRA,YCRA,NCRA)
C
DIMENSION XCRA(*),YCRA(*)
C
C This routine merges polygons into a single polygon.
C
C Merge polygons are formed in the common block MERGCM:
C
COMMON /MERGCM/ XCMP(9999),YCMP(9999),NCMP
SAVE /MERGCM/
C
C Copy the coordinates of the latest polygon into the merge polygon
C coordinate arrays and, if the polygon is not the first of the group,
C repeat the first point of the first polygon. (Actually, the code
C below does something a little more complicated: if necessary, it
C interpolates points to ensure that the connecting lines between
C polygons consist of horizontal and/or vertical steps; this tends
C to prevent problems caused by deficiencies in the fill algorithms
C on some devices.)
C
C The following statement is a quick-and-dirty patch to leave out all
C the off-shore islands, since they seem to cause some problems.
C
IF (NCRA.LT.100) RETURN
C
NTMP=NCMP
C
IF (NTMP+NCRA+4.LE.9999) THEN
IF (NCMP.NE.0) THEN
IF (XCMP(NTMP).NE.XCRA(1).AND.YCMP(NTMP).NE.YCRA(1)) THEN
IF (YCMP(NTMP).LT.YCRA(1)) THEN
NTMP=NTMP+1
XCMP(NTMP)=XCRA(1)
YCMP(NTMP)=YCMP(NTMP-1)
ELSE
NTMP=NTMP+1
XCMP(NTMP)=XCMP(NTMP-1)
YCMP(NTMP)=YCRA(1)
END IF
END IF
NTMP=NTMP+1
XCMP(NTMP)=XCRA(1)
YCMP(NTMP)=YCRA(1)
END IF
DO 102 ICRA=1,NCRA
XCMP(NTMP+ICRA)=XCRA(ICRA)
YCMP(NTMP+ICRA)=YCRA(ICRA)
102 CONTINUE
NTMP=NTMP+NCRA
IF (NCMP.NE.0) THEN
IF (XCMP(NTMP).NE.XCMP(1).AND.YCMP(NTMP).NE.YCMP(1)) THEN
IF (YCMP(NTMP).LT.YCMP(1)) THEN
NTMP=NTMP+1
XCMP(NTMP)=XCMP(1)
YCMP(NTMP)=YCMP(NTMP-1)
ELSE
NTMP=NTMP+1
XCMP(NTMP)=XCMP(NTMP-1)
YCMP(NTMP)=YCMP(1)
END IF
END IF
NTMP=NTMP+1
XCMP(NTMP)=XCMP(1)
YCMP(NTMP)=YCMP(1)
END IF
ELSE
NTMP=10000
END IF
C
NCMP=NTMP
C
RETURN
END
SUBROUTINE TSTEXT(XEXT,YEXT)
C
C Calculate the world coordinate extents.
C
REAL WINDOW(4),VIEWPT(4)
C
CALL GQCNTN(IER,NTR)
CALL GQNT(NTR,IER,WINDOW,VIEWPT)
XEXT = WINDOW(2)-WINDOW(1)
YEXT = WINDOW(4)-WINDOW(3)
C
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/dpbtrf.f | 3 | 11962 | SUBROUTINE DPBTRF( UPLO, N, KD, AB, LDAB, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* March 31, 1993
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, KD, LDAB, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION AB( LDAB, * )
* ..
*
* Purpose
* =======
*
* DPBTRF computes the Cholesky factorization of a real symmetric
* positive definite band matrix A.
*
* The factorization has the form
* A = U**T * U, if UPLO = 'U', or
* A = L * L**T, if UPLO = 'L',
* where U is an upper triangular matrix and L is lower triangular.
*
* 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.
*
* KD (input) INTEGER
* The number of superdiagonals of the matrix A if UPLO = 'U',
* or the number of subdiagonals if UPLO = 'L'. KD >= 0.
*
* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N)
* On entry, the upper or lower triangle of the symmetric band
* matrix A, stored in the first KD+1 rows of the array. The
* j-th column of A is stored in the j-th column of the array AB
* as follows:
* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
*
* On exit, if INFO = 0, the triangular factor U or L from the
* Cholesky factorization A = U**T*U or A = L*L**T of the band
* matrix A, in the same storage format as A.
*
* LDAB (input) INTEGER
* The leading dimension of the array AB. LDAB >= KD+1.
*
* 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 factorization could not be
* completed.
*
* Further Details
* ===============
*
* The band storage scheme is illustrated by the following example, when
* N = 6, KD = 2, and UPLO = 'U':
*
* On entry: On exit:
*
* * * a13 a24 a35 a46 * * u13 u24 u35 u46
* * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56
* a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66
*
* Similarly, if UPLO = 'L' the format of A is as follows:
*
* On entry: On exit:
*
* a11 a22 a33 a44 a55 a66 l11 l22 l33 l44 l55 l66
* a21 a32 a43 a54 a65 * l21 l32 l43 l54 l65 *
* a31 a42 a53 a64 * * l31 l42 l53 l64 * *
*
* Array elements marked * are not used by the routine.
*
* Contributed by
* Peter Mayes and Giuseppe Radicati, IBM ECSEC, Rome, March 23, 1989
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
INTEGER NBMAX, LDWORK
PARAMETER ( NBMAX = 32, LDWORK = NBMAX+1 )
* ..
* .. Local Scalars ..
INTEGER I, I2, I3, IB, II, J, JJ, NB
* ..
* .. Local Arrays ..
DOUBLE PRECISION WORK( LDWORK, NBMAX )
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILAENV
EXTERNAL LSAME, ILAENV
* ..
* .. External Subroutines ..
EXTERNAL DGEMM, DPBTF2, DPOTF2, DSYRK, DTRSM, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC 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( KD.LT.0 ) THEN
INFO = -3
ELSE IF( LDAB.LT.KD+1 ) THEN
INFO = -5
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DPBTRF', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Determine the block size for this environment
*
NB = ILAENV( 1, 'DPBTRF', UPLO, N, KD, -1, -1 )
*
* The block size must not exceed the semi-bandwidth KD, and must not
* exceed the limit set by the size of the local array WORK.
*
NB = MIN( NB, NBMAX )
*
IF( NB.LE.1 .OR. NB.GT.KD ) THEN
*
* Use unblocked code
*
CALL DPBTF2( UPLO, N, KD, AB, LDAB, INFO )
ELSE
*
* Use blocked code
*
IF( LSAME( UPLO, 'U' ) ) THEN
*
* Compute the Cholesky factorization of a symmetric band
* matrix, given the upper triangle of the matrix in band
* storage.
*
* Zero the upper triangle of the work array.
*
DO 20 J = 1, NB
DO 10 I = 1, J - 1
WORK( I, J ) = ZERO
10 CONTINUE
20 CONTINUE
*
* Process the band matrix one diagonal block at a time.
*
DO 70 I = 1, N, NB
IB = MIN( NB, N-I+1 )
*
* Factorize the diagonal block
*
CALL DPOTF2( UPLO, IB, AB( KD+1, I ), LDAB-1, II )
IF( II.NE.0 ) THEN
INFO = I + II - 1
GO TO 150
END IF
IF( I+IB.LE.N ) THEN
*
* Update the relevant part of the trailing submatrix.
* If A11 denotes the diagonal block which has just been
* factorized, then we need to update the remaining
* blocks in the diagram:
*
* A11 A12 A13
* A22 A23
* A33
*
* The numbers of rows and columns in the partitioning
* are IB, I2, I3 respectively. The blocks A12, A22 and
* A23 are empty if IB = KD. The upper triangle of A13
* lies outside the band.
*
I2 = MIN( KD-IB, N-I-IB+1 )
I3 = MIN( IB, N-I-KD+1 )
*
IF( I2.GT.0 ) THEN
*
* Update A12
*
CALL DTRSM( 'Left', 'Upper', 'Transpose',
$ 'Non-unit', IB, I2, ONE, AB( KD+1, I ),
$ LDAB-1, AB( KD+1-IB, I+IB ), LDAB-1 )
*
* Update A22
*
CALL DSYRK( 'Upper', 'Transpose', I2, IB, -ONE,
$ AB( KD+1-IB, I+IB ), LDAB-1, ONE,
$ AB( KD+1, I+IB ), LDAB-1 )
END IF
*
IF( I3.GT.0 ) THEN
*
* Copy the lower triangle of A13 into the work array.
*
DO 40 JJ = 1, I3
DO 30 II = JJ, IB
WORK( II, JJ ) = AB( II-JJ+1, JJ+I+KD-1 )
30 CONTINUE
40 CONTINUE
*
* Update A13 (in the work array).
*
CALL DTRSM( 'Left', 'Upper', 'Transpose',
$ 'Non-unit', IB, I3, ONE, AB( KD+1, I ),
$ LDAB-1, WORK, LDWORK )
*
* Update A23
*
IF( I2.GT.0 )
$ CALL DGEMM( 'Transpose', 'No Transpose', I2, I3,
$ IB, -ONE, AB( KD+1-IB, I+IB ),
$ LDAB-1, WORK, LDWORK, ONE,
$ AB( 1+IB, I+KD ), LDAB-1 )
*
* Update A33
*
CALL DSYRK( 'Upper', 'Transpose', I3, IB, -ONE,
$ WORK, LDWORK, ONE, AB( KD+1, I+KD ),
$ LDAB-1 )
*
* Copy the lower triangle of A13 back into place.
*
DO 60 JJ = 1, I3
DO 50 II = JJ, IB
AB( II-JJ+1, JJ+I+KD-1 ) = WORK( II, JJ )
50 CONTINUE
60 CONTINUE
END IF
END IF
70 CONTINUE
ELSE
*
* Compute the Cholesky factorization of a symmetric band
* matrix, given the lower triangle of the matrix in band
* storage.
*
* Zero the lower triangle of the work array.
*
DO 90 J = 1, NB
DO 80 I = J + 1, NB
WORK( I, J ) = ZERO
80 CONTINUE
90 CONTINUE
*
* Process the band matrix one diagonal block at a time.
*
DO 140 I = 1, N, NB
IB = MIN( NB, N-I+1 )
*
* Factorize the diagonal block
*
CALL DPOTF2( UPLO, IB, AB( 1, I ), LDAB-1, II )
IF( II.NE.0 ) THEN
INFO = I + II - 1
GO TO 150
END IF
IF( I+IB.LE.N ) THEN
*
* Update the relevant part of the trailing submatrix.
* If A11 denotes the diagonal block which has just been
* factorized, then we need to update the remaining
* blocks in the diagram:
*
* A11
* A21 A22
* A31 A32 A33
*
* The numbers of rows and columns in the partitioning
* are IB, I2, I3 respectively. The blocks A21, A22 and
* A32 are empty if IB = KD. The lower triangle of A31
* lies outside the band.
*
I2 = MIN( KD-IB, N-I-IB+1 )
I3 = MIN( IB, N-I-KD+1 )
*
IF( I2.GT.0 ) THEN
*
* Update A21
*
CALL DTRSM( 'Right', 'Lower', 'Transpose',
$ 'Non-unit', I2, IB, ONE, AB( 1, I ),
$ LDAB-1, AB( 1+IB, I ), LDAB-1 )
*
* Update A22
*
CALL DSYRK( 'Lower', 'No Transpose', I2, IB, -ONE,
$ AB( 1+IB, I ), LDAB-1, ONE,
$ AB( 1, I+IB ), LDAB-1 )
END IF
*
IF( I3.GT.0 ) THEN
*
* Copy the upper triangle of A31 into the work array.
*
DO 110 JJ = 1, IB
DO 100 II = 1, MIN( JJ, I3 )
WORK( II, JJ ) = AB( KD+1-JJ+II, JJ+I-1 )
100 CONTINUE
110 CONTINUE
*
* Update A31 (in the work array).
*
CALL DTRSM( 'Right', 'Lower', 'Transpose',
$ 'Non-unit', I3, IB, ONE, AB( 1, I ),
$ LDAB-1, WORK, LDWORK )
*
* Update A32
*
IF( I2.GT.0 )
$ CALL DGEMM( 'No transpose', 'Transpose', I3, I2,
$ IB, -ONE, WORK, LDWORK,
$ AB( 1+IB, I ), LDAB-1, ONE,
$ AB( 1+KD-IB, I+IB ), LDAB-1 )
*
* Update A33
*
CALL DSYRK( 'Lower', 'No Transpose', I3, IB, -ONE,
$ WORK, LDWORK, ONE, AB( 1, I+KD ),
$ LDAB-1 )
*
* Copy the upper triangle of A31 back into place.
*
DO 130 JJ = 1, IB
DO 120 II = 1, MIN( JJ, I3 )
AB( KD+1-JJ+II, JJ+I-1 ) = WORK( II, JJ )
120 CONTINUE
130 CONTINUE
END IF
END IF
140 CONTINUE
END IF
END IF
RETURN
*
150 CONTINUE
RETURN
*
* End of DPBTRF
*
END
| gpl-2.0 |
acquaman/acquaman | source/Eigen/blas/dtpsv.f | 28 | 9449 | SUBROUTINE DTPSV(UPLO,TRANS,DIAG,N,AP,X,INCX)
* .. Scalar Arguments ..
INTEGER INCX,N
CHARACTER DIAG,TRANS,UPLO
* ..
* .. Array Arguments ..
DOUBLE PRECISION AP(*),X(*)
* ..
*
* Purpose
* =======
*
* DTPSV solves one of the systems of equations
*
* A*x = b, or A'*x = b,
*
* where b and x are n element vectors and A is an n by n unit, or
* non-unit, upper or lower triangular matrix, supplied in packed form.
*
* No test for singularity or near-singularity is included in this
* routine. Such tests must be performed before calling this routine.
*
* Arguments
* ==========
*
* UPLO - CHARACTER*1.
* On entry, UPLO specifies whether the matrix is an upper or
* lower triangular matrix as follows:
*
* UPLO = 'U' or 'u' A is an upper triangular matrix.
*
* UPLO = 'L' or 'l' A is a lower triangular matrix.
*
* Unchanged on exit.
*
* TRANS - CHARACTER*1.
* On entry, TRANS specifies the equations to be solved as
* follows:
*
* TRANS = 'N' or 'n' A*x = b.
*
* TRANS = 'T' or 't' A'*x = b.
*
* TRANS = 'C' or 'c' A'*x = b.
*
* Unchanged on exit.
*
* DIAG - CHARACTER*1.
* On entry, DIAG specifies whether or not A is unit
* triangular as follows:
*
* DIAG = 'U' or 'u' A is assumed to be unit triangular.
*
* DIAG = 'N' or 'n' A is not assumed to be unit
* triangular.
*
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the order of the matrix A.
* N must be at least zero.
* Unchanged on exit.
*
* AP - DOUBLE PRECISION array of DIMENSION at least
* ( ( n*( n + 1 ) )/2 ).
* Before entry with UPLO = 'U' or 'u', the array AP must
* contain the upper triangular 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.
* Before entry with UPLO = 'L' or 'l', the array AP must
* contain the lower triangular 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.
* Note that when DIAG = 'U' or 'u', the diagonal elements of
* A are not referenced, but are assumed to be unity.
* Unchanged on exit.
*
* X - DOUBLE PRECISION array of dimension at least
* ( 1 + ( n - 1 )*abs( INCX ) ).
* Before entry, the incremented array X must contain the n
* element right-hand side vector b. On exit, X is overwritten
* with the solution vector x.
*
* INCX - INTEGER.
* On entry, INCX specifies the increment for the elements of
* X. INCX must not be zero.
* Unchanged on exit.
*
* Further Details
* ===============
*
* Level 2 Blas routine.
*
* -- Written on 22-October-1986.
* Jack Dongarra, Argonne National Lab.
* Jeremy Du Croz, Nag Central Office.
* Sven Hammarling, Nag Central Office.
* Richard Hanson, Sandia National Labs.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER (ZERO=0.0D+0)
* ..
* .. Local Scalars ..
DOUBLE PRECISION TEMP
INTEGER I,INFO,IX,J,JX,K,KK,KX
LOGICAL NOUNIT
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
*
* Test the input parameters.
*
INFO = 0
IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
INFO = 1
ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
+ .NOT.LSAME(TRANS,'C')) THEN
INFO = 2
ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
INFO = 3
ELSE IF (N.LT.0) THEN
INFO = 4
ELSE IF (INCX.EQ.0) THEN
INFO = 7
END IF
IF (INFO.NE.0) THEN
CALL XERBLA('DTPSV ',INFO)
RETURN
END IF
*
* Quick return if possible.
*
IF (N.EQ.0) RETURN
*
NOUNIT = LSAME(DIAG,'N')
*
* Set up the start point in X if the increment is not unity. This
* will be ( N - 1 )*INCX too small for descending loops.
*
IF (INCX.LE.0) THEN
KX = 1 - (N-1)*INCX
ELSE IF (INCX.NE.1) THEN
KX = 1
END IF
*
* Start the operations. In this version the elements of AP are
* accessed sequentially with one pass through AP.
*
IF (LSAME(TRANS,'N')) THEN
*
* Form x := inv( A )*x.
*
IF (LSAME(UPLO,'U')) THEN
KK = (N* (N+1))/2
IF (INCX.EQ.1) THEN
DO 20 J = N,1,-1
IF (X(J).NE.ZERO) THEN
IF (NOUNIT) X(J) = X(J)/AP(KK)
TEMP = X(J)
K = KK - 1
DO 10 I = J - 1,1,-1
X(I) = X(I) - TEMP*AP(K)
K = K - 1
10 CONTINUE
END IF
KK = KK - J
20 CONTINUE
ELSE
JX = KX + (N-1)*INCX
DO 40 J = N,1,-1
IF (X(JX).NE.ZERO) THEN
IF (NOUNIT) X(JX) = X(JX)/AP(KK)
TEMP = X(JX)
IX = JX
DO 30 K = KK - 1,KK - J + 1,-1
IX = IX - INCX
X(IX) = X(IX) - TEMP*AP(K)
30 CONTINUE
END IF
JX = JX - INCX
KK = KK - J
40 CONTINUE
END IF
ELSE
KK = 1
IF (INCX.EQ.1) THEN
DO 60 J = 1,N
IF (X(J).NE.ZERO) THEN
IF (NOUNIT) X(J) = X(J)/AP(KK)
TEMP = X(J)
K = KK + 1
DO 50 I = J + 1,N
X(I) = X(I) - TEMP*AP(K)
K = K + 1
50 CONTINUE
END IF
KK = KK + (N-J+1)
60 CONTINUE
ELSE
JX = KX
DO 80 J = 1,N
IF (X(JX).NE.ZERO) THEN
IF (NOUNIT) X(JX) = X(JX)/AP(KK)
TEMP = X(JX)
IX = JX
DO 70 K = KK + 1,KK + N - J
IX = IX + INCX
X(IX) = X(IX) - TEMP*AP(K)
70 CONTINUE
END IF
JX = JX + INCX
KK = KK + (N-J+1)
80 CONTINUE
END IF
END IF
ELSE
*
* Form x := inv( A' )*x.
*
IF (LSAME(UPLO,'U')) THEN
KK = 1
IF (INCX.EQ.1) THEN
DO 100 J = 1,N
TEMP = X(J)
K = KK
DO 90 I = 1,J - 1
TEMP = TEMP - AP(K)*X(I)
K = K + 1
90 CONTINUE
IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
X(J) = TEMP
KK = KK + J
100 CONTINUE
ELSE
JX = KX
DO 120 J = 1,N
TEMP = X(JX)
IX = KX
DO 110 K = KK,KK + J - 2
TEMP = TEMP - AP(K)*X(IX)
IX = IX + INCX
110 CONTINUE
IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
X(JX) = TEMP
JX = JX + INCX
KK = KK + J
120 CONTINUE
END IF
ELSE
KK = (N* (N+1))/2
IF (INCX.EQ.1) THEN
DO 140 J = N,1,-1
TEMP = X(J)
K = KK
DO 130 I = N,J + 1,-1
TEMP = TEMP - AP(K)*X(I)
K = K - 1
130 CONTINUE
IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
X(J) = TEMP
KK = KK - (N-J+1)
140 CONTINUE
ELSE
KX = KX + (N-1)*INCX
JX = KX
DO 160 J = N,1,-1
TEMP = X(JX)
IX = KX
DO 150 K = KK,KK - (N- (J+1)),-1
TEMP = TEMP - AP(K)*X(IX)
IX = IX - INCX
150 CONTINUE
IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
X(JX) = TEMP
JX = JX - INCX
KK = KK - (N-J+1)
160 CONTINUE
END IF
END IF
END IF
*
RETURN
*
* End of DTPSV .
*
END
| gpl-3.0 |
jcarlson23/lammps | tools/chain.f | 19 | 8319 | c Create LAMMPS data file for collection of
c polymer bead-spring chains of various lengths and bead sizes
c Syntax: chain < def.chain > data.file
c def.chain is input file that specifies the chains
c data.file is output file that will be input for LAMMPS
c includes image flags in data file so chains can be unraveled later
program chain
integer swaptype
integer, allocatable :: nchain(:),nmonomer(:)
integer, allocatable :: ntype(:),nbondtype(:)
integer, allocatable :: type(:),molecule(:)
integer, allocatable :: imagex(:),imagey(:),imagez(:)
real*8, allocatable :: x(:),y(:),z(:)
real*8, allocatable :: bondlength(:),restrict(:)
common xprd,yprd,zprd,xboundlo,xboundhi,
$ yboundlo,yboundhi,zboundlo,zboundhi
real*8 random
900 format(a)
901 format(2f10.6,a)
902 format(i3,f5.1)
903 format(i10,i8,i8,3f10.4,3i4)
904 format(i6,i3,2i6)
c read chain definitions
read (5,*)
read (5,*)
read (5,*) rhostar
read (5,*) iseed
read (5,*) nsets
read (5,*) swaptype
allocate(nchain(nsets))
allocate(nmonomer(nsets))
allocate(ntype(nsets))
allocate(nbondtype(nsets))
allocate(bondlength(nsets))
allocate(restrict(nsets))
do iset = 1,nsets
read (5,*)
read (5,*) nchain(iset)
read (5,*) nmonomer(iset)
read (5,*) ntype(iset)
read (5,*) nbondtype(iset)
read (5,*) bondlength(iset)
read (5,*) restrict(iset)
enddo
c natoms = total # of monomers
natoms = 0
do iset = 1,nsets
natoms = natoms + nchain(iset)*nmonomer(iset)
enddo
allocate(x(natoms))
allocate(y(natoms))
allocate(z(natoms))
allocate(type(natoms))
allocate(molecule(natoms))
allocate(imagex(natoms))
allocate(imagey(natoms))
allocate(imagez(natoms))
c setup box size (sigma = 1.0)
volume = natoms/rhostar
xprd = volume**(1.0/3.0)
yprd = xprd
zprd = xprd
xboundlo = -xprd/2.0
xboundhi = -xboundlo
yboundlo = xboundlo
yboundhi = xboundhi
zboundlo = xboundlo
zboundhi = xboundhi
c generate random chains
c loop over sets and chains in each set
n = 0
nmolecule = 0
do iset = 1,nsets
do ichain = 1,nchain(iset)
nmolecule = nmolecule + 1
c random starting point for the chain in the box
x1 = 0.0
y1 = 0.0
z1 = 0.0
x2 = xboundlo + random(iseed)*xprd
y2 = yboundlo + random(iseed)*yprd
z2 = zboundlo + random(iseed)*zprd
c store 1st monomer of chain
c 1st monomer is always in original box (image = 0)
call pbc(x2,y2,z2)
n = n + 1
x(n) = x2
y(n) = y2
z(n) = z2
type(n) = ntype(iset)
imagex(n) = 0
imagey(n) = 0
imagez(n) = 0
if (swaptype == 0) then
molecule(n) = nmolecule
else
molecule(n) = 1
endif
c generate rest of monomers in this chain
do imonomer = 2,nmonomer(iset)
x0 = x1
y0 = y1
z0 = z1
x1 = x2
y1 = y2
z1 = z2
c random point inside sphere of unit radius
10 xinner = 2.0*random(iseed) - 1.0
yinner = 2.0*random(iseed) - 1.0
zinner = 2.0*random(iseed) - 1.0
rsq = xinner*xinner + yinner*yinner + zinner*zinner
if (rsq > 1.0) goto 10
c project point to surface of sphere of unit radius
r = sqrt(rsq)
xsurf = xinner/r
ysurf = yinner/r
zsurf = zinner/r
c create new point by scaling unit offsets by bondlength (sigma = 1.0)
x2 = x1 + xsurf*bondlength(iset)
y2 = y1 + ysurf*bondlength(iset)
z2 = z1 + zsurf*bondlength(iset)
c check that new point meets restriction requirement
c only for 3rd monomer and beyond
dx = x2 - x0
dy = y2 - y0
dz = z2 - z0
r = sqrt(dx*dx + dy*dy + dz*dz)
if (imonomer > 2 .and. r <= restrict(iset)) goto 10
c store new point
c if delta to previous bead is large, then increment/decrement image flag
call pbc(x2,y2,z2)
n = n + 1
x(n) = x2
y(n) = y2
z(n) = z2
type(n) = ntype(iset)
if (abs(x(n)-x(n-1)) < 2.0*bondlength(iset)) then
imagex(n) = imagex(n-1)
else if (x(n) - x(n-1) < 0.0) then
imagex(n) = imagex(n-1) + 1
else if (x(n) - x(n-1) > 0.0) then
imagex(n) = imagex(n-1) - 1
endif
if (abs(y(n)-y(n-1)) < 2.0*bondlength(iset)) then
imagey(n) = imagey(n-1)
else if (y(n) - y(n-1) < 0.0) then
imagey(n) = imagey(n-1) + 1
else if (y(n) - y(n-1) > 0.0) then
imagey(n) = imagey(n-1) - 1
endif
if (abs(z(n)-z(n-1)) < 2.0*bondlength(iset)) then
imagez(n) = imagez(n-1)
else if (z(n) - z(n-1) < 0.0) then
imagez(n) = imagez(n-1) + 1
else if (z(n) - z(n-1) > 0.0) then
imagez(n) = imagez(n-1) - 1
endif
if (swaptype == 0) then
molecule(n) = nmolecule
else if (swaptype == 1) then
molecule(n) = imonomer
else if (swaptype == 2) then
if (imonomer <= nmonomer(iset)/2) then
molecule(n) = imonomer
else
molecule(n) = nmonomer(iset)+1-imonomer
endif
endif
enddo
enddo
enddo
c compute quantities needed for LAMMPS file
nbonds = 0
ntypes = 0
nbondtypes = 0
do iset = 1,nsets
nbonds = nbonds + nchain(iset)*(nmonomer(iset)-1)
if (ntype(iset) > ntypes) ntypes = ntype(iset)
if (nbondtype(iset) > nbondtypes)
$ nbondtypes = nbondtype(iset)
enddo
c write out LAMMPS file
write (6,900) 'LAMMPS FENE chain data file'
write (6,*)
write (6,*) natoms,' atoms'
write (6,*) nbonds,' bonds'
write (6,*) 0,' angles'
write (6,*) 0,' dihedrals'
write (6,*) 0,' impropers'
write (6,*)
write (6,*) ntypes,' atom types'
write (6,*) nbondtypes,' bond types'
write (6,*) 0,' angle types'
write (6,*) 0,' dihedral types'
write (6,*) 0,' improper types'
write (6,*)
write (6,901) xboundlo,xboundhi,' xlo xhi'
write (6,901) yboundlo,yboundhi,' ylo yhi'
write (6,901) zboundlo,zboundhi,' zlo zhi'
write (6,*)
write (6,900) 'Masses'
write (6,*)
do i = 1,ntypes
write (6,902) i,1.0
enddo
write (6,*)
write (6,900) 'Atoms'
write (6,*)
do i = 1,natoms
write (6,903) i,molecule(i),type(i),x(i),y(i),z(i),
$ imagex(i),imagey(i),imagez(i)
enddo
if (nbonds > 0) then
write (6,*)
write (6,900) 'Bonds'
write (6,*)
n = 0
m = 0
do iset = 1,nsets
do ichain = 1,nchain(iset)
do imonomer = 1,nmonomer(iset)
n = n + 1
if (imonomer /= nmonomer(iset)) then
m = m + 1
write (6,904) m,nbondtype(iset),n,n+1
endif
enddo
enddo
enddo
endif
end
c ************
c Subroutines
c ************
c periodic boundary conditions - map atom back into periodic box
subroutine pbc(x,y,z)
common xprd,yprd,zprd,xboundlo,xboundhi,
$ yboundlo,yboundhi,zboundlo,zboundhi
if (x < xboundlo) x = x + xprd
if (x >= xboundhi) x = x - xprd
if (y < yboundlo) y = y + yprd
if (y >= yboundhi) y = y - yprd
if (z < zboundlo) z = z + zprd
if (z >= zboundhi) z = z - zprd
return
end
c RNG from Numerical Recipes
real*8 function random(iseed)
real*8 aa,mm,sseed
parameter (aa=16807.0D0,mm=2147483647.0D0)
sseed = iseed
sseed = mod(aa*sseed,mm)
random = sseed/mm
iseed = sseed
return
end
| gpl-2.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/gomp/reduction3.f90 | 119 | 1410 | ! { dg-do compile }
module mreduction3
interface
function ior (a, b)
integer :: ior, a, b
end function
end interface
contains
function iand (a, b)
integer :: iand, a, b
iand = a + b
end function
end module mreduction3
subroutine f1
integer :: i, ior
ior = 6
i = 6
!$omp parallel reduction (ior:i) ! { dg-error "OMP DECLARE REDUCTION\[^\n\r\]*not found" }
!$omp end parallel
end subroutine f1
subroutine f2
integer :: i
interface
function ior (a, b)
integer :: ior, a, b
end function
end interface
i = 6
!$omp parallel reduction (ior:i) ! { dg-error "OMP DECLARE REDUCTION\[^\n\r\]*not found" }
i = ior (i, 3)
!$omp end parallel
end subroutine f2
subroutine f3
integer :: i
intrinsic ior
i = 6
!$omp parallel reduction (ior:i)
i = ior (i, 3)
!$omp end parallel
end subroutine f3
subroutine f4
integer :: i, ior
i = 6
!$omp parallel reduction (ior:i)
ior = 4 ! { dg-error "is not a variable" }
!$omp end parallel
end subroutine f4
subroutine f5
use mreduction3
integer :: i
i = 6
!$omp parallel reduction (ior:i) ! { dg-error "OMP DECLARE REDUCTION\[^\n\r\]*not found" }
i = ior (i, 7)
!$omp end parallel
end subroutine f5
subroutine f6
use mreduction3
integer :: i
i = 6
!$omp parallel reduction (iand:i) ! { dg-error "OMP DECLARE REDUCTION\[^\n\r\]*not found" }
i = iand (i, 18)
!$omp end parallel
end subroutine f6
| gpl-2.0 |
TApplencourt/quantum_package | src/iterations/print_summary.irp.f | 1 | 3685 | subroutine print_summary(e_,pt2_,error_,variance_,norm_,n_det_,n_occ_pattern_,n_st)
implicit none
BEGIN_DOC
! Print the extrapolated energy in the output
END_DOC
integer, intent(in) :: n_det_, n_occ_pattern_, n_st
double precision, intent(in) :: e_(n_st), pt2_(n_st), variance_(n_st), norm_(n_st), error_(n_st)
integer :: i, k
integer :: N_states_p
character*(9) :: pt2_string
character*(512) :: fmt
double precision :: f(n_st)
if (do_pt2) then
pt2_string = ' '
else
pt2_string = '(approx)'
endif
N_states_p = min(N_det_,n_st)
do i=1,N_states_p
f(i) = 1.d0/(1.d0+norm_(i))
enddo
print *, ''
print '(A,I12)', 'Summary at N_det = ', N_det_
print '(A)', '-----------------------------------'
print *, ''
write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=============================''))'
write(*,fmt)
write(fmt,*) '(12X,', N_states_p, '(6X,A7,1X,I6,10X))'
write(*,fmt) ('State',k, k=1,N_states_p)
write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=============================''))'
write(*,fmt)
write(fmt,*) '(A12,', N_states_p, '(1X,F14.8,15X))'
write(*,fmt) '# E ', e_(1:N_states_p)
if (N_states_p > 1) then
write(*,fmt) '# Excit. (au)', e_(1:N_states_p)-e_(1)
write(*,fmt) '# Excit. (eV)', (e_(1:N_states_p)-e_(1))*27.211396641308d0
endif
write(fmt,*) '(A13,', 2*N_states_p, '(1X,F14.8))'
write(*,fmt) '# PT2'//pt2_string, (pt2_(k), error_(k), k=1,N_states_p)
write(*,'(A)') '#'
write(*,fmt) '# E+PT2 ', (e_(k)+pt2_(k),error_(k), k=1,N_states_p)
write(*,fmt) '# E+rPT2 ', (e_(k)+pt2_(k)*f(k),error_(k)*f(k), k=1,N_states_p)
if (N_states_p > 1) then
write(*,fmt) '# Excit. (au)', ( (e_(k)+pt2_(k)-e_(1)-pt2_(1)), &
dsqrt(error_(k)*error_(k)+error_(1)*error_(1)), k=1,N_states_p)
write(*,fmt) '# Excit. (eV)', ( (e_(k)+pt2_(k)-e_(1)-pt2_(1))*27.211396641308d0, &
dsqrt(error_(k)*error_(k)+error_(1)*error_(1))*27.211396641308d0, k=1,N_states_p)
endif
write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=============================''))'
write(*,fmt)
print *, ''
print *, 'N_det = ', N_det_
print *, 'N_states = ', n_st
if (s2_eig) then
print *, 'N_sop = ', N_occ_pattern_
endif
print *, ''
do k=1, N_states_p
print*,'* State ',k
print *, 'Variance = ', variance_(k)
print *, 'PT norm = ', dsqrt(norm_(k))
print *, 'PT2 = ', pt2_(k)
print *, 'rPT2 = ', pt2_(k)*f(k)
print *, 'E = ', e_(k)
print *, 'E+PT2 '//pt2_string//' = ', e_(k)+pt2_(k), ' +/- ', error_(k)
print *, 'E+rPT2'//pt2_string//' = ', e_(k)+pt2_(k)*f(k), ' +/- ', error_(k)*f(k)
print *, ''
enddo
print *, '-----'
if(n_st.gt.1)then
print *, 'Variational Energy difference (au | eV)'
do i=2, N_states_p
print*,'Delta E = ', (e_(i) - e_(1)), &
(e_(i) - e_(1)) * 27.211396641308d0
enddo
print *, '-----'
print*, 'Variational + perturbative Energy difference (au | eV)'
do i=2, N_states_p
print*,'Delta E = ', (e_(i)+ pt2_(i) - (e_(1) + pt2_(1))), &
(e_(i)+ pt2_(i) - (e_(1) + pt2_(1))) * 27.211396641308d0
enddo
print *, '-----'
print*, 'Variational + renormalized perturbative Energy difference (au | eV)'
do i=2, N_states_p
print*,'Delta E = ', (e_(i)+ pt2_(i)*f(i) - (e_(1) + pt2_(1)*f(1))), &
(e_(i)+ pt2_(i)*f(i) - (e_(1) + pt2_(1)*f(1))) * 27.211396641308d0
enddo
endif
end subroutine
| gpl-3.0 |
likev/ncl | ncl_ncarg_src/external/lapack/clatrz.f | 2 | 4132 | SUBROUTINE CLATRZ( M, N, L, A, LDA, TAU, WORK )
*
* -- 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 ..
INTEGER L, LDA, M, N
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * ), TAU( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* CLATRZ factors the M-by-(M+L) complex upper trapezoidal matrix
* [ A1 A2 ] = [ A(1:M,1:M) A(1:M,N-L+1:N) ] as ( R 0 ) * Z by means
* of unitary transformations, where Z is an (M+L)-by-(M+L) unitary
* matrix and, R and A1 are M-by-M upper triangular matrices.
*
* 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.
*
* L (input) INTEGER
* The number of columns of the matrix A containing the
* meaningful part of the Householder vectors. N-M >= L >= 0.
*
* A (input/output) COMPLEX 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 N-L+1 to
* N of the first M rows of A, with the array TAU, represent the
* unitary matrix Z as a product of M elementary reflectors.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,M).
*
* TAU (output) COMPLEX array, dimension (M)
* The scalar factors of the elementary reflectors.
*
* WORK (workspace) COMPLEX array, dimension (M)
*
* Further Details
* ===============
*
* Based on contributions by
* A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
*
* 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 )', u( k ) = ( 1 ),
* ( 0 )
* ( z( k ) )
*
* tau is a scalar and z( k ) is an l element vector. tau and z( k )
* are chosen to annihilate the elements of the kth row of A2.
*
* The scalar tau is returned in the kth element of TAU and the vector
* u( k ) in the kth row of A2, such that the elements of z( k ) are
* in a( k, l + 1 ), ..., a( k, n ). The elements of R are returned in
* the upper triangular part of A1.
*
* Z is given by
*
* Z = Z( 1 ) * Z( 2 ) * ... * Z( m ).
*
* =====================================================================
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
INTEGER I
COMPLEX ALPHA
* ..
* .. External Subroutines ..
EXTERNAL CLACGV, CLARFG, CLARZ
* ..
* .. Intrinsic Functions ..
INTRINSIC CONJG
* ..
* .. Executable Statements ..
*
* Quick return if possible
*
IF( M.EQ.0 ) THEN
RETURN
ELSE IF( M.EQ.N ) THEN
DO 10 I = 1, N
TAU( I ) = ZERO
10 CONTINUE
RETURN
END IF
*
DO 20 I = M, 1, -1
*
* Generate elementary reflector H(i) to annihilate
* [ A(i,i) A(i,n-l+1:n) ]
*
CALL CLACGV( L, A( I, N-L+1 ), LDA )
ALPHA = CONJG( A( I, I ) )
CALL CLARFG( L+1, ALPHA, A( I, N-L+1 ), LDA, TAU( I ) )
TAU( I ) = CONJG( TAU( I ) )
*
* Apply H(i) to A(1:i-1,i:n) from the right
*
CALL CLARZ( 'Right', I-1, N-I+1, L, A( I, N-L+1 ), LDA,
$ CONJG( TAU( I ) ), A( 1, I ), LDA, WORK )
A( I, I ) = CONJG( ALPHA )
*
20 CONTINUE
*
RETURN
*
* End of CLATRZ
*
END
| gpl-2.0 |
nslu2/Build-gcc-3.2.1 | gcc/testsuite/g77.f-torture/compile/980419-2.f | 10 | 1650 | c SEGVs in loop.c with -O2.
character*80 function nxtlin(lun,ierr,itok)
character onechr*1,twochr*2,thrchr*3
itok=0
do while (.true.)
read (lun,'(a)',iostat=ierr) nxtlin
if (nxtlin(1:1).ne.'#') then
ito=0
do 10 it=1,79
if (nxtlin(it:it).ne.' ' .and. nxtlin(it+1:it+1).eq.' ')
$ then
itast=0
itstrt=0
do itt=ito+1,it
if (nxtlin(itt:itt).eq.'*') itast=itt
enddo
itstrt=ito+1
do while (nxtlin(itstrt:itstrt).eq.' ')
itstrt=itstrt+1
enddo
if (itast.gt.0) then
nchrs=itast-itstrt
if (nchrs.eq.1) then
onechr=nxtlin(itstrt:itstrt)
read (onechr,*) itokn
elseif (nchrs.eq.2) then
twochr=nxtlin(itstrt:itstrt+1)
read (twochr,*) itokn
elseif (nchrs.eq.3) then
thrchr=nxtlin(itstrt:itstrt+2)
read (thrchr,*) itokn
elseif (nchrs.eq.4) then
thrchr=nxtlin(itstrt:itstrt+3)
read (thrchr,*) itokn
endif
itok=itok+itokn
else
itok=itok+1
endif
ito=it+1
endif
10 continue
return
endif
enddo
return
end
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/cggbal.f | 2 | 13746 | SUBROUTINE CGGBAL( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
$ RSCALE, WORK, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
*
* .. Scalar Arguments ..
CHARACTER JOB
INTEGER IHI, ILO, INFO, LDA, LDB, N
* ..
* .. Array Arguments ..
REAL LSCALE( * ), RSCALE( * ), WORK( * )
COMPLEX A( LDA, * ), B( LDB, * )
* ..
*
* Purpose
* =======
*
* CGGBAL balances a pair of general complex matrices (A,B). This
* involves, first, permuting A and B by similarity transformations 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 matrices, and improve the
* accuracy of the computed eigenvalues and/or eigenvectors in the
* generalized eigenvalue problem A*x = lambda*B*x.
*
* Arguments
* =========
*
* JOB (input) CHARACTER*1
* Specifies the operations to be performed on A and B:
* = 'N': none: simply set ILO = 1, IHI = N, LSCALE(I) = 1.0
* and RSCALE(I) = 1.0 for i=1,...,N;
* = 'P': permute only;
* = 'S': scale only;
* = 'B': both permute and scale.
*
* N (input) INTEGER
* The order of the matrices A and B. N >= 0.
*
* A (input/output) COMPLEX 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.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* B (input/output) COMPLEX array, dimension (LDB,N)
* On entry, the input matrix B.
* On exit, B is overwritten by the balanced matrix.
* If JOB = 'N', B is not referenced.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* ILO (output) INTEGER
* IHI (output) INTEGER
* ILO and IHI are set to integers such that on exit
* A(i,j) = 0 and B(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.
*
* LSCALE (output) REAL array, dimension (N)
* Details of the permutations and scaling factors applied
* to the left side of A and B. If P(j) is the index of the
* row interchanged with row j, and D(j) is the scaling factor
* applied to row j, then
* LSCALE(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.
*
* RSCALE (output) REAL array, dimension (N)
* Details of the permutations and scaling factors applied
* to the right side of A and B. If P(j) is the index of the
* column interchanged with column j, and D(j) is the scaling
* factor applied to column j, then
* RSCALE(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.
*
* WORK (workspace) REAL array, dimension (6*N)
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value.
*
* Further Details
* ===============
*
* See R.C. WARD, Balancing the generalized eigenvalue problem,
* SIAM J. Sci. Stat. Comp. 2 (1981), 141-152.
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, HALF, ONE
PARAMETER ( ZERO = 0.0E+0, HALF = 0.5E+0, ONE = 1.0E+0 )
REAL THREE, SCLFAC
PARAMETER ( THREE = 3.0E+0, SCLFAC = 1.0E+1 )
COMPLEX CZERO
PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, J, JC, JP1,
$ K, KOUNT, L, LCAB, LM1, LRAB, LSFMAX, LSFMIN,
$ M, NR, NRP2
REAL ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,
$ COEF5, COR, EW, EWC, GAMMA, PGAMMA, RAB, SFMAX,
$ SFMIN, SUM, T, TA, TB, TC
COMPLEX CDUM
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ICAMAX
REAL SDOT, SLAMCH
EXTERNAL LSAME, ICAMAX, SDOT, SLAMCH
* ..
* .. External Subroutines ..
EXTERNAL CSSCAL, CSWAP, SAXPY, SSCAL, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, INT, LOG10, MAX, MIN, REAL, SIGN
* ..
* .. Statement Functions ..
REAL CABS1
* ..
* .. Statement Function definitions ..
CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( CDUM ) )
* ..
* .. Executable Statements ..
*
* 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
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -5
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CGGBAL', -INFO )
RETURN
END IF
*
K = 1
L = N
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
IF( LSAME( JOB, 'N' ) ) THEN
ILO = 1
IHI = N
DO 10 I = 1, N
LSCALE( I ) = ONE
RSCALE( I ) = ONE
10 CONTINUE
RETURN
END IF
*
IF( K.EQ.L ) THEN
ILO = 1
IHI = 1
LSCALE( 1 ) = ONE
RSCALE( 1 ) = ONE
RETURN
END IF
*
IF( LSAME( JOB, 'S' ) )
$ GO TO 190
*
GO TO 30
*
* Permute the matrices A and B to isolate the eigenvalues.
*
* Find row with one nonzero in columns 1 through L
*
20 CONTINUE
L = LM1
IF( L.NE.1 )
$ GO TO 30
*
RSCALE( 1 ) = 1
LSCALE( 1 ) = 1
GO TO 190
*
30 CONTINUE
LM1 = L - 1
DO 80 I = L, 1, -1
DO 40 J = 1, LM1
JP1 = J + 1
IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
$ GO TO 50
40 CONTINUE
J = L
GO TO 70
*
50 CONTINUE
DO 60 J = JP1, L
IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
$ GO TO 80
60 CONTINUE
J = JP1 - 1
*
70 CONTINUE
M = L
IFLOW = 1
GO TO 160
80 CONTINUE
GO TO 100
*
* Find column with one nonzero in rows K through N
*
90 CONTINUE
K = K + 1
*
100 CONTINUE
DO 150 J = K, L
DO 110 I = K, LM1
IP1 = I + 1
IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
$ GO TO 120
110 CONTINUE
I = L
GO TO 140
120 CONTINUE
DO 130 I = IP1, L
IF( A( I, J ).NE.CZERO .OR. B( I, J ).NE.CZERO )
$ GO TO 150
130 CONTINUE
I = IP1 - 1
140 CONTINUE
M = K
IFLOW = 2
GO TO 160
150 CONTINUE
GO TO 190
*
* Permute rows M and I
*
160 CONTINUE
LSCALE( M ) = I
IF( I.EQ.M )
$ GO TO 170
CALL CSWAP( N-K+1, A( I, K ), LDA, A( M, K ), LDA )
CALL CSWAP( N-K+1, B( I, K ), LDB, B( M, K ), LDB )
*
* Permute columns M and J
*
170 CONTINUE
RSCALE( M ) = J
IF( J.EQ.M )
$ GO TO 180
CALL CSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
CALL CSWAP( L, B( 1, J ), 1, B( 1, M ), 1 )
*
180 CONTINUE
GO TO ( 20, 90 )IFLOW
*
190 CONTINUE
ILO = K
IHI = L
*
IF( ILO.EQ.IHI )
$ RETURN
*
IF( LSAME( JOB, 'P' ) )
$ RETURN
*
* Balance the submatrix in rows ILO to IHI.
*
NR = IHI - ILO + 1
DO 200 I = ILO, IHI
RSCALE( I ) = ZERO
LSCALE( I ) = ZERO
*
WORK( I ) = ZERO
WORK( I+N ) = ZERO
WORK( I+2*N ) = ZERO
WORK( I+3*N ) = ZERO
WORK( I+4*N ) = ZERO
WORK( I+5*N ) = ZERO
200 CONTINUE
*
* Compute right side vector in resulting linear equations
*
BASL = LOG10( SCLFAC )
DO 240 I = ILO, IHI
DO 230 J = ILO, IHI
IF( A( I, J ).EQ.CZERO ) THEN
TA = ZERO
GO TO 210
END IF
TA = LOG10( CABS1( A( I, J ) ) ) / BASL
*
210 CONTINUE
IF( B( I, J ).EQ.CZERO ) THEN
TB = ZERO
GO TO 220
END IF
TB = LOG10( CABS1( B( I, J ) ) ) / BASL
*
220 CONTINUE
WORK( I+4*N ) = WORK( I+4*N ) - TA - TB
WORK( J+5*N ) = WORK( J+5*N ) - TA - TB
230 CONTINUE
240 CONTINUE
*
COEF = ONE / REAL( 2*NR )
COEF2 = COEF*COEF
COEF5 = HALF*COEF2
NRP2 = NR + 2
BETA = ZERO
IT = 1
*
* Start generalized conjugate gradient iteration
*
250 CONTINUE
*
GAMMA = SDOT( NR, WORK( ILO+4*N ), 1, WORK( ILO+4*N ), 1 ) +
$ SDOT( NR, WORK( ILO+5*N ), 1, WORK( ILO+5*N ), 1 )
*
EW = ZERO
EWC = ZERO
DO 260 I = ILO, IHI
EW = EW + WORK( I+4*N )
EWC = EWC + WORK( I+5*N )
260 CONTINUE
*
GAMMA = COEF*GAMMA - COEF2*( EW**2+EWC**2 ) - COEF5*( EW-EWC )**2
IF( GAMMA.EQ.ZERO )
$ GO TO 350
IF( IT.NE.1 )
$ BETA = GAMMA / PGAMMA
T = COEF5*( EWC-THREE*EW )
TC = COEF5*( EW-THREE*EWC )
*
CALL SSCAL( NR, BETA, WORK( ILO ), 1 )
CALL SSCAL( NR, BETA, WORK( ILO+N ), 1 )
*
CALL SAXPY( NR, COEF, WORK( ILO+4*N ), 1, WORK( ILO+N ), 1 )
CALL SAXPY( NR, COEF, WORK( ILO+5*N ), 1, WORK( ILO ), 1 )
*
DO 270 I = ILO, IHI
WORK( I ) = WORK( I ) + TC
WORK( I+N ) = WORK( I+N ) + T
270 CONTINUE
*
* Apply matrix to vector
*
DO 300 I = ILO, IHI
KOUNT = 0
SUM = ZERO
DO 290 J = ILO, IHI
IF( A( I, J ).EQ.CZERO )
$ GO TO 280
KOUNT = KOUNT + 1
SUM = SUM + WORK( J )
280 CONTINUE
IF( B( I, J ).EQ.CZERO )
$ GO TO 290
KOUNT = KOUNT + 1
SUM = SUM + WORK( J )
290 CONTINUE
WORK( I+2*N ) = REAL( KOUNT )*WORK( I+N ) + SUM
300 CONTINUE
*
DO 330 J = ILO, IHI
KOUNT = 0
SUM = ZERO
DO 320 I = ILO, IHI
IF( A( I, J ).EQ.CZERO )
$ GO TO 310
KOUNT = KOUNT + 1
SUM = SUM + WORK( I+N )
310 CONTINUE
IF( B( I, J ).EQ.CZERO )
$ GO TO 320
KOUNT = KOUNT + 1
SUM = SUM + WORK( I+N )
320 CONTINUE
WORK( J+3*N ) = REAL( KOUNT )*WORK( J ) + SUM
330 CONTINUE
*
SUM = SDOT( NR, WORK( ILO+N ), 1, WORK( ILO+2*N ), 1 ) +
$ SDOT( NR, WORK( ILO ), 1, WORK( ILO+3*N ), 1 )
ALPHA = GAMMA / SUM
*
* Determine correction to current iteration
*
CMAX = ZERO
DO 340 I = ILO, IHI
COR = ALPHA*WORK( I+N )
IF( ABS( COR ).GT.CMAX )
$ CMAX = ABS( COR )
LSCALE( I ) = LSCALE( I ) + COR
COR = ALPHA*WORK( I )
IF( ABS( COR ).GT.CMAX )
$ CMAX = ABS( COR )
RSCALE( I ) = RSCALE( I ) + COR
340 CONTINUE
IF( CMAX.LT.HALF )
$ GO TO 350
*
CALL SAXPY( NR, -ALPHA, WORK( ILO+2*N ), 1, WORK( ILO+4*N ), 1 )
CALL SAXPY( NR, -ALPHA, WORK( ILO+3*N ), 1, WORK( ILO+5*N ), 1 )
*
PGAMMA = GAMMA
IT = IT + 1
IF( IT.LE.NRP2 )
$ GO TO 250
*
* End generalized conjugate gradient iteration
*
350 CONTINUE
SFMIN = SLAMCH( 'S' )
SFMAX = ONE / SFMIN
LSFMIN = INT( LOG10( SFMIN ) / BASL+ONE )
LSFMAX = INT( LOG10( SFMAX ) / BASL )
DO 360 I = ILO, IHI
IRAB = ICAMAX( N-ILO+1, A( I, ILO ), LDA )
RAB = ABS( A( I, IRAB+ILO-1 ) )
IRAB = ICAMAX( N-ILO+1, B( I, ILO ), LDA )
RAB = MAX( RAB, ABS( B( I, IRAB+ILO-1 ) ) )
LRAB = INT( LOG10( RAB+SFMIN ) / BASL+ONE )
IR = LSCALE( I ) + SIGN( HALF, LSCALE( I ) )
IR = MIN( MAX( IR, LSFMIN ), LSFMAX, LSFMAX-LRAB )
LSCALE( I ) = SCLFAC**IR
ICAB = ICAMAX( IHI, A( 1, I ), 1 )
CAB = ABS( A( ICAB, I ) )
ICAB = ICAMAX( IHI, B( 1, I ), 1 )
CAB = MAX( CAB, ABS( B( ICAB, I ) ) )
LCAB = INT( LOG10( CAB+SFMIN ) / BASL+ONE )
JC = RSCALE( I ) + SIGN( HALF, RSCALE( I ) )
JC = MIN( MAX( JC, LSFMIN ), LSFMAX, LSFMAX-LCAB )
RSCALE( I ) = SCLFAC**JC
360 CONTINUE
*
* Row scaling of matrices A and B
*
DO 370 I = ILO, IHI
CALL CSSCAL( N-ILO+1, LSCALE( I ), A( I, ILO ), LDA )
CALL CSSCAL( N-ILO+1, LSCALE( I ), B( I, ILO ), LDB )
370 CONTINUE
*
* Column scaling of matrices A and B
*
DO 380 J = ILO, IHI
CALL CSSCAL( IHI, RSCALE( J ), A( 1, J ), 1 )
CALL CSSCAL( IHI, RSCALE( J ), B( 1, J ), 1 )
380 CONTINUE
*
RETURN
*
* End of CGGBAL
*
END
| gpl-2.0 |
wilfeli/DMGameBasic | ExternalTools/Eigen/lapack/ilaslc.f | 272 | 2941 | *> \brief \b ILASLC
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ILASLC + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ilaslc.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ilaslc.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ilaslc.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* INTEGER FUNCTION ILASLC( M, N, A, LDA )
*
* .. Scalar Arguments ..
* INTEGER M, N, LDA
* ..
* .. Array Arguments ..
* REAL A( LDA, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ILASLC scans A for its last non-zero column.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix A.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix A.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is REAL array, dimension (LDA,N)
*> The m by n matrix A.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,M).
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup realOTHERauxiliary
*
* =====================================================================
INTEGER FUNCTION ILASLC( M, N, A, LDA )
*
* -- LAPACK auxiliary routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
INTEGER M, N, LDA
* ..
* .. Array Arguments ..
REAL A( LDA, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I
* ..
* .. Executable Statements ..
*
* Quick test for the common case where one corner is non-zero.
IF( N.EQ.0 ) THEN
ILASLC = N
ELSE IF( A(1, N).NE.ZERO .OR. A(M, N).NE.ZERO ) THEN
ILASLC = N
ELSE
* Now scan each column from the end, returning with the first non-zero.
DO ILASLC = N, 1, -1
DO I = 1, M
IF( A(I, ILASLC).NE.ZERO ) RETURN
END DO
END DO
END IF
RETURN
END
| mit |
RobinsonLab/GlobalCurve | models/physiology/three_state_SS/three_state_SS.f90 | 2 | 6634 | function three_state_SS(current_model,current_data,g_save) result(species)
use h_struct
use h_routine_specific_vars
! USE ode_path
! use numerical_libraries, only: neqnf
! use nr, only: newt
implicit none
type(model_struct), pointer :: current_model
type (data_struct),pointer :: current_data
real,dimension(current_data%len),optional :: g_save
real,dimension(current_data%len,3) :: species
!interface
!subroutine three_state_SS_model(y, funcv, n)
! use h_routine_specific_vars
! implicit none
! real,intent(in) :: y(*)
! real,intent(out) :: funcv(*)
! integer, intent(in) :: n !n=2
!end subroutine
!end interface
! params
real,parameter :: err_tol=1E-4
real,parameter :: y3=1.0
real,parameter :: max_it=100
real,parameter :: lim=1E-3
integer,parameter :: n=2
! local variables
REAL, DIMENSION(n) :: y
real :: pCa
integer :: i
! real :: kon,koff,f,g,u,v,w,x,z,nu
! real :: koff_p,f_p,g_p
! real :: norm
! real :: eta,zeta,sumy
real :: sumy
real :: u,v,w,x,z
! LOGICAL :: check
! vars for IMSL routine
real :: errel = 0.0001
real,dimension(n) :: yguess,f
integer :: itmax=200
real :: fnorm
real :: xold
real,dimension(3) :: ny
real :: eta,zeta
! real,dimension(n) :: yguess !,fvec,yscale,fscale
!integer,dimension(n+1) :: iparam
!real,dimension(n) :: rparam
! real,dimension(n) :: fvec,xscale,fscale
! integer,dimension(6) :: iparam
! real,dimension(5) :: rparam
! begin
! if you want to save off the time course then set: save_steps = .true.
! save_steps = .true.
tsv%kon= param_list(current_model%model%param(1)%param_basis(1))%val
tsv%koff= param_list(current_model%model%param(1)%param_basis(2))%val
tsv%f= param_list(current_model%model%param(1)%param_basis(3))%val
tsv%g= param_list(current_model%model%param(1)%param_basis(4))%val
! made changes to u,v,w,x,z on 3/13/02
u= param_list(current_model%model%param(1)%param_basis(5))%val
v= param_list(current_model%model%param(1)%param_basis(6))%val
w= param_list(current_model%model%param(1)%param_basis(7))%val
x= param_list(current_model%model%param(1)%param_basis(8))%val
z= param_list(current_model%model%param(1)%param_basis(9))%val
tsv%u=exp(-u)
tsv%v=exp(-v)
tsv%w=exp(-w)
tsv%x=exp(-x)
tsv%z=exp(-z)
! nu= param_list(current_model%model%param(3)%param_basis(1))%val
! get an initial guess for the y's
! just calculate the nullspace of the rate matrix (eliminating eqn 2 of 3)
! using mathematica
! set up imsl
!xscale(:)=1
!fscale(:)=1.0
! y(3)=1
do i=1,current_data%len
pCa=current_data%x_pts(i)
tsv%Ca=10.**-pCa ! Ca is a global variable
if (i==1 ) then
y(1)=tsv%g*tsv%koff/(tsv%f*tsv%kon*tsv%Ca)
y(2)=tsv%g/tsv%f
! else
! yguess=y
endif
! call three_state_SS_model(yguess,f,n)
! if (sqrt(dot_product(f,f)) < 0.01) then
! write (*,*) 'He threre'
! y=yguess
! else
! CALL NEQNF (three_state_SS_model, errel, n, itmax, yguess, y, fnorm)
! endif
call find_zero(y)
! call neqbf(three_state_SS_model,n,yguess,xscale,fscale,iparam,rparam,y,fvec)
! call newt(y,check)
! call broydn(y,check)
sumy=(y(1)+y(2)+y3)/(1.0-tsv%alpha)
ny(1)=y(1)/sumy
ny(2)=y(2)/sumy
ny(3)=y3/sumy
species(i,1)=ny(1)
species(i,2)=ny(2)
species(i,3)=ny(3)
if (present(g_save)) then
eta=tsv%nu*(ny(2) + ny(3))
zeta=tsv%nu*tsv%nu2*ny(3)
g_save(i)=tsv%g * (1.+eta*(tsv%w2-1.))**2 * (1.+zeta*(tsv%w-1.))**2
endif
end do !i
end function
function funcv(y)
use h_routine_specific_vars
implicit none
real,dimension(2),intent(in) :: y
real,dimension(2) :: funcv
! integer, intent(in) :: n !n=2
! Params
real,parameter :: y3 = 1.0 ! arbitrarily set y(3)=1
! Var's
real :: Ca,koff,f,g
real :: eta,zeta
real :: sumy
real,dimension(3) :: ny
real :: f_not
! Begin
Ca=tsv%Ca
! so (1.0-tsv%alpha) is as normal.
! tsv%alpha is activated.
sumy=(y(1)+y(2)+y3)/(1.0-tsv%alpha)
ny(1)=y(1)/sumy
ny(2)=y(2)/sumy
ny(3)=y3/sumy+tsv%alpha
! ny(3)=ny(3)+tsv%alpha
eta=tsv%nu*(ny(2) + ny(3))
zeta=tsv%nu*tsv%nu2*ny(3)
koff=tsv%koff * (1.+eta*(tsv%u-1.))**2 * (1.+zeta*(tsv%x-1.))**2
f_not=tsv%f*(1.0-tsv%alpha)
f=f_not * (1.+eta*(tsv%v-1.))**2 * (1.+zeta*(tsv%z-1.))**2
g=tsv%g * (1.+eta*(tsv%w2-1.))**2 * (1.+zeta*(tsv%w-1.))**2
!koff=tsv%koff
!f=tsv%f
!g=tsv%g
funcv(1)=-tsv%kon*Ca*y(1)+koff*y(2)
funcv(2)=f*y(2)-g*y3
end function
subroutine find_zero(x)
use h_params !default
use h_utils
use numerical_libraries, only: lsgrr
! use nr, only: fdjac
implicit none
real,dimension(2),intent(inout) :: x
interface
function funcv(y)
implicit none
real,dimension(2),intent(in) :: y
real,dimension(2) :: funcv
end function
SUBROUTINE fdjac(x,fvec,df)
IMPLICIT NONE
REAL, DIMENSION(2), INTENT(IN) :: fvec
REAL, DIMENSION(2), INTENT(INOUT) :: x
REAL, DIMENSION(2,2), INTENT(OUT) :: df
end subroutine
end interface
! params
integer,parameter :: maxit=200
real,parameter :: tol=1E-3
integer,parameter :: n=2
! vars
integer :: i
real,dimension(n) :: f,dx,xold
real,dimension(n,n) :: df,ginva
real :: lambda
real :: val
integer :: rank
! Begin
do i=1,maxit
f=funcv(x)
! check for convergence
val=sqrt(dot_product(f,f))
if (val < tol) return
call fdjac(x,f,df)
! CALL LSLRG (n, df, n, -f, 1, dx)
! calculate the generalized inverse of df using SVD
! CALL LSGRR (NRA, NCA, A, LDA, TOL, IRANK, GINVA, LDGINV)
CALL LSGRR (n, n, df, n,real(default%svd_tol), rank, ginva, n)
dx=matmul(ginva,-f)
xold=x
lambda=1.
do
x=xold+lambda*dx
if (any(x<0)) then
lambda=lambda/2.
else
exit
endif
enddo
enddo
write (*,*) 'Maxit exceeded in find_zero',val
end subroutine find_zero
SUBROUTINE fdjac(x,fvec,df)
use nrtype
IMPLICIT NONE
REAL, DIMENSION(2), INTENT(IN) :: fvec
REAL, DIMENSION(2), INTENT(INOUT) :: x
REAL, DIMENSION(2,2), INTENT(OUT) :: df
INTERFACE
FUNCTION funcv(x)
IMPLICIT NONE
REAL, DIMENSION(2), INTENT(IN) :: x
REAL, DIMENSION(2) :: funcv
END FUNCTION funcv
END INTERFACE
REAL, PARAMETER :: EPS=1.0e-4
INTEGER(I4B) :: j,n
REAL(SP), DIMENSION(size(x)) :: xsav,xph,h
! n=assert_eq(size(x),size(fvec),size(df,1),size(df,2),'fdjac')
n=size(x)
xsav=x
h=EPS*abs(xsav)
where (h == 0.0) h=EPS
xph=xsav+h
h=xph-xsav
do j=1,n
x(j)=xph(j)
df(:,j)=(funcv(x)-fvec(:))/h(j)
x(j)=xsav(j)
end do
END SUBROUTINE fdjac
| apache-2.0 |
likev/ncl | ncl_ncarg_src/ni/src/examples/textitem/tx03f.f | 1 | 4929 | CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C C
C Copyright (C) 1995 C
C University Corporation for Atmospheric Research C
C all rights reserved C
C C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C File: tx03f.f
C
C Author: Bob Lackman (converted by Ed Stautler)
C National Center for Atmospheric Research
C PO 3000, Boulder, Colorado
C
C Date: Fri Jan 06 18:31:18 mdt 1995
C
C Description: Demonstrates the TextItem Object
C Writes "NCAR Graphics" in a series of
C different colors (using the default colormap.)
C
external NhlFAppClass
external NhlFCairoWindowWorkstationClass
external NhlFNcgmWorkstationClass
external NhlFPSWorkstationClass
external NhlFPDFWorkstationClass
external NhlFCairoPSPDFWorkstationClass
external NhlFCairoImageWorkstationClass
external NhlFTextItemClass
integer appid, wid, pid
integer srlist, grlist,ierr
integer i
character*7 wks_type
C
C Default is to create a metafile.
C
wks_type = "x11"
C
C Initialize the high level utility library
C
call NhlFInitialize
C
C Create an application context. Set the app dir to the current
C directory so the application looks for a resource file in the
C working directory. In this example the resource file supplies the
C plot title only.
C
call NhlFRLCreate(srlist,'setrl')
call NhlFRLClear(srlist)
call NhlFRLSetString(srlist,'appUsrDir','./',ierr)
call NhlFRLSetString(srlist,'appDefaultParent','True',ierr)
call NhlFCreate(appid,'tx03',NhlFAppClass,0,srlist,ierr)
if (wks_type.eq."ncgm".or.wks_type.eq."NCGM") then
C
C Create an NCGM workstation.
C
call NhlFRLClear(srlist)
call NhlFRLSetString(srlist,'wkMetaName','./tx03f.ncgm',ierr)
call NhlFCreate(wid,'tx03Work',NhlFNcgmWorkstationClass,0,
1 srlist,ierr)
else if (wks_type.eq."x11".or.wks_type.eq."X11") then
C
C Create an X Workstation.
C
call NhlFRLClear(srlist)
call NhlFRLSetString(srlist,'wkPause','True',ierr)
call NhlFCreate(wid,'tx03Work',
$ NhlFCairoWindowWorkstationClass,
$ 0,srlist,ierr)
else if (wks_type.eq."oldps".or.wks_type.eq."OLDPS") then
C
C Create an older-style PostScript workstation.
C
call NhlFRLClear(srlist)
call NhlFRLSetString(srlist,'wkPSFileName','./tx03f.ps',ierr)
call NhlFCreate(wid,'tx03Work',NhlFPSWorkstationClass,0,
1 srlist,ierr)
else if (wks_type.eq."oldpdf".or.wks_type.eq."OLDPDF") then
C
C Create an older-style PDF workstation.
C
call NhlFRLClear(srlist)
call NhlFRLSetString(srlist,'wkPDFFileName','./tx03f.pdf',ierr)
call NhlFCreate(wid,'tx03Work',NhlFPDFWorkstationClass,0,
1 srlist,ierr)
else if (wks_type.eq."pdf".or.wks_type.eq."PDF".or.
+ wks_type.eq."ps".or.wks_type.eq."PS") then
C
C Create a cairo PS/PDF object.
C
call NhlFRLClear(srlist)
call NhlFRLSetString(srlist,'wkFormat',wks_type,ierr)
call NhlFRLSetString(srlist,'wkFileName','./tx03f',ierr)
call NhlFCreate(wid,'tx03Work',
1 NhlFCairoPSPDFWorkstationClass,0,srlist,ierr)
else if (wks_type.eq."png".or.wks_type.eq."PNG") then
C
C Create a cairo PNG object.
C
call NhlFRLClear(srlist)
call NhlFRLSetString(srlist,'wkFormat',wks_type,ierr)
call NhlFRLSetString(srlist,'wkFileName','./tx03f',ierr)
call NhlFCreate(wid,'tx03Work',
1 NhlFCairoImageWorkstationClass,0,srlist,ierr)
endif
C
C Get the number of colors in the default color table.
C
call NhlFRLCreate(grlist,'getrl')
call NhlFRLClear(grlist)
call NhlFRLGetInteger(grlist,'wkColorMapLen',num_colors,ierr)
call NhlFGetValues(wid,grlist,ierr)
C
C
C Create a TextItem and then draw multiple frames varying the fill
C color of the text bounding box to all entries of the default
C workstation color map.
C
call NhlFRLClear(srlist)
call NhlFCreate(pid,'TextItems',NhlFTextItemClass,
$ wid,srlist,ierr)
do 10 i=1,num_colors,10
call NhlFRLClear(srlist)
call NhlFRLSetinteger(srlist,'txBackgroundFillColor',
$ i,ierr)
call NhlFSetValues(pid,srlist,ierr)
call NhlFDraw(pid,ierr)
call NhlFFrame(wid,ierr)
10 continue
C
call NhlFDestroy(pid,ierr)
call NhlFDestroy(wid,ierr)
call NhlFDestroy(appid,ierr)
call NhlFClose
C
stop
end
| gpl-2.0 |
raphaeldussin/brushcutter | brushcutter/f90/mod_drown_sosie.f90 | 1 | 16209 | MODULE MOD_DROWN
! USE io_ezcdf
! USE mod_manip
IMPLICIT none
PRIVATE
PUBLIC :: drown
LOGICAL, PARAMETER :: ldebug = .FALSE.
CONTAINS
SUBROUTINE DROWN(k_ew, Xin, mask, Xout, nb_inc, nb_smooth, ni, nj)
!!#############################################################################
!!
!! PURPOSE : fill continental areas of field X (defined by mask=0)
!! ------- using nearest surrounding sea points (defined by mask=1)
!! field X is absoluletly unchanged on mask=1 points
!!
!! k_ew : east-west periodicity on the input file/grid
!! k_ew = -1 --> no periodicity
!! k_ew >= 0 --> periodicity with overlap of k_ew points
!!
!! X : treated array (2D array)
!! mask : land-sea mask INTEGER !!!! (2D array)
!!
!! Optional:
!! * nb_inc : how far in terms of number of grid-point we extrapolate sea value into land
!! => default: nb_inc = 400
!! (will normally stop before 400 iterations, when all land points have been treated!!!)
!!
!! * nb_smooth : number of times the smoother is applied on masked region (mask=0)
!! => default: nb_smooth = 2
!!
!!
!! Author : Laurent BRODEAU, 2014
!!
!!#############################################################################
!! Arguments :
INTEGER, INTENT(in) :: k_ew
REAL(4), DIMENSION(ni,nj), INTENT(in) :: Xin
REAL(4), DIMENSION(ni,nj), INTENT(out) :: Xout
INTEGER(4), DIMENSION(ni,nj), INTENT(in) :: mask
INTEGER, INTENT(in) :: ni, nj
INTEGER, OPTIONAL, INTENT(in) :: nb_inc, nb_smooth
!! Local :
INTEGER(2), ALLOCATABLE, DIMENSION(:,:) :: maskv, mask_coast, mtmp
REAL(4), ALLOCATABLE, DIMENSION(:,:) :: dold, xtmp, X
INTEGER :: &
& ninc_max, &
& nsmooth_max, &
& jinc, &
& ji, jj, jci, &
& jim, jip, js
REAL(4), PARAMETER :: rr = 0.707
INTEGER, DIMENSION(2) :: ivi, vim_per, vip_per
INTEGER, PARAMETER :: jinc_debg = 2
ninc_max = 200 ! will stop before when all land points have been treated!!!
IF ( present(nb_inc) ) ninc_max = nb_inc
nsmooth_max = 2
IF ( present(nb_smooth) ) nsmooth_max = nb_smooth
IF ( (size(Xin,1) /= size(mask,1)).OR.(size(Xin,2) /= size(mask,2)) ) THEN
PRINT *, 'ERROR, mod_drown.F90 => DROWN : size of data and mask do not match!!!'; STOP
END IF
!! Backing up original mask into mask2(:,:)
ALLOCATE ( maskv(ni,nj), dold(ni,nj), xtmp(ni,nj), mask_coast(ni,nj), mtmp(ni,nj) )
ALLOCATE ( X(ni,nj) )
X = Xin
ivi = (/ 1 , ni /)
IF (k_ew >= 0) THEN
vim_per = (/ ni-k_ew , ni-1 /)
vip_per = (/ 2 , 1+k_ew /)
END IF
jinc = 0
maskv(:,:) = mask(:,:)
DO jinc = 1, ninc_max
!! Quiting if no land point left:
IF ( .NOT. (ANY(maskv == 0)) ) THEN
IF ( ldebug ) PRINT *, 'DROWN: No land points left! Leaving incursion loop at jinc =', jinc
EXIT
END IF
dold(:,:) = X(:,:)
!! Building mask of the coast-line (belonging to land points)
mask_coast(:,:) = 0
mask_coast(2:ni-1,2:nj-1) = (maskv(3:ni,2:nj-1) + maskv(2:ni-1,3:nj) + maskv(1:ni-2,2:nj-1) + maskv(2:ni-1,1:nj-2)) &
& *(-(maskv(2:ni-1,2:nj-1)-1))
!! West and East boundaries with periodicity
!! ------------------------------------------
IF (k_ew >= 0) THEN
DO jci = 1, 2
jim = vim_per(jci) ! ji-1
ji = ivi(jci) ! first ji = 1, then ji = ni
jip = vip_per(jci) ! ji+1
mask_coast(ji,2:nj-1) = (maskv(jip,2:nj-1) + maskv(ji,3:nj) + maskv(jim,2:nj-1) + maskv(ji,1:nj-2)) &
& *(-(maskv(ji,2:nj-1)-1))
END DO
ELSE
!! West LBC:
mask_coast(1,2:nj-1) = (maskv(2,2:nj-1) + maskv(1,3:nj) + maskv( 1,1:nj-2))*(-(maskv( 1,2:nj-1) -1))
!! East LBC:
mask_coast(ni,2:nj-1) = (maskv(ni,3:nj) + maskv(ni-1,2:nj-1) + maskv(ni,1:nj-2))*(-(maskv(ni,2:nj-1) -1))
END IF
! -------
! jj=1
! -------
mask_coast(2:ni-1,1) = (maskv(3:ni,1) + maskv(2:ni-1,2) + maskv(1:ni-2,1)) &
& *(-(maskv(2:ni-1,1)-1))
!!
!! ji=1, jj=1
IF (k_ew >= 0) THEN
mask_coast(1,1) = (maskv(2,1) + maskv(1,2) + maskv(ni-k_ew,1))*(-(maskv(1,1)-1))
ELSE
mask_coast(1,1) = (maskv(2,1) + maskv(1,2) )*(-(maskv(1,1)-1))
END IF
! ji=ni, jj=1
IF (k_ew >= 0) THEN
mask_coast(ni,1) = (maskv(1+k_ew,1) + maskv(ni,2) + maskv(ni,1))*(-(maskv(ni,1)-1))
ELSE
mask_coast(ni,1) = ( maskv(ni,2) + maskv(ni,1))*(-(maskv(ni,1)-1))
END IF
! jj=nj
! -------
mask_coast(2:ni-1,nj) = (maskv(3:ni,nj) + maskv(1:ni-2,nj) + maskv(2:ni-1,nj-1)) &
& *(-(maskv(2:ni-1,nj)-1))
!! ji=1, jj=nj
IF (k_ew >= 0) THEN
mask_coast(1,nj) = (maskv(2,nj) + maskv(ni-k_ew,nj) + maskv(1,nj-1) )*(-(maskv(1,nj) -1))
ELSE
mask_coast(1,nj) = (maskv(2,nj) + maskv(1,nj-1) )*(-(maskv(1,nj) -1))
END IF
!! ji=ni, jj=nj
IF (k_ew >= 0) THEN
mask_coast(ni,nj) = (maskv(k_ew+1,nj) + maskv(ni-1,nj) + maskv(ni-1,nj-1)) *(-(maskv(ni,nj) -1))
ELSE
mask_coast(ni,nj) = ( maskv(ni-1,nj) + maskv(ni-1,nj-1)) *(-(maskv(ni,nj) -1))
END IF
!! mask_coast is fine now
mtmp(:,:) = mask_coast(:,:)
mask_coast(:,:) = 0
WHERE ( mtmp(:,:) > 0 )
mask_coast = 1
END WHERE
!IF ( jinc == jinc_debg) CALL PRTMASK(REAL(maskv,4), 'maskv.nc', 'lsm')
!IF ( jinc == jinc_debg) CALL PRTMASK(REAL(mask_coast,4), 'mask_coast.nc', 'lsm') !; STOP 'mod_drown.F90 => boo!'
!IF ( jinc == jinc_debg) CALL PRTMASK(X, 'data_X_before.nc', 'lsm')
!STOP
!! mask_coast done, time to fill the coastline points with values from the nearest se points
!! -----------------------------------------------------------------------------------------
!! Center of the domain:
DO jj = 2, nj-1
DO ji = 2, ni-1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(ji+1,jj)+maskv(ji,jj+1)+maskv(ji-1,jj)+maskv(ji,jj-1) + &
& rr*(maskv(ji+1,jj+1)+maskv(ji-1,jj+1)+maskv(ji-1,jj-1)+maskv(ji+1,jj-1)))*( &
& maskv(ji+1,jj)*dold(ji+1,jj) + maskv(ji,jj+1)*dold(ji,jj+1) + &
& maskv(ji-1,jj)*dold(ji-1,jj) + maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(ji+1,jj+1)*dold(ji+1,jj+1) + rr*maskv(ji-1,jj+1)*dold(ji-1,jj+1) + &
& rr*maskv(ji-1,jj-1)*dold(ji-1,jj-1) + rr*maskv(ji+1,jj-1)*dold(ji+1,jj-1) )
END IF
END DO
END DO
DO jci = 1, 2
ji = ivi(jci) ! first ji = 1, then ji = ni
IF (k_ew >= 0) THEN
!! West and East boundaries with periodicity
jim = vim_per(jci) ! ji-1
jip = vip_per(jci) ! ji+1
DO jj = 2, nj-1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(jip,jj)+maskv(ji,jj+1)+maskv(jim,jj)+maskv(ji,jj-1) + &
& rr*(maskv(jip,jj+1)+maskv(jim,jj+1)+maskv(jim,jj-1)+maskv(jip,jj-1)))*( &
& maskv(jip,jj)*dold(jip,jj) + maskv(ji,jj+1)*dold(ji,jj+1) + &
& maskv(jim,jj)*dold(jim,jj) + maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(jip,jj+1)*dold(jip,jj+1) + rr*maskv(jim,jj+1)*dold(jim,jj+1) + &
& rr*maskv(jim,jj-1)*dold(jim,jj-1) + rr*maskv(jip,jj-1)*dold(jip,jj-1) )
END IF
END DO
ELSE
!! West & East LBCs when not east-west periodicity, extrapolating lineraly
IF ( ji == 1 ) THEN
DO jj = 2, nj-1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(2,jj)+maskv(ji,jj+1)+maskv(ji,jj-1) + &
& rr*maskv(2,jj+1)+rr*maskv(2,jj-1))*( &
& maskv(2,jj)*dold(2,jj) + maskv(ji,jj+1)*dold(ji,jj+1) + &
& maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(2,jj+1)*dold(2,jj+1) + &
& rr*maskv(2,jj-1)*dold(2,jj-1) )
END IF
END DO
END IF
IF ( ji == ni ) THEN
DO jj = 2, nj-1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./( maskv(ji,jj+1)+maskv(ni-1,jj)+maskv(ji,jj-1) + &
& rr*maskv(ni-1,jj+1)+rr*maskv(ni-1,jj-1))*( &
& maskv(ji,jj+1)*dold(ji,jj+1) + &
& maskv(ni-1,jj)*dold(ni-1,jj) + maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(ni-1,jj+1)*dold(ni-1,jj+1) + &
& rr*maskv(ni-1,jj-1)*dold(ni-1,jj-1) )
END IF
END DO
END IF
END IF
END DO
!! Center of Top row:
jj = nj
DO ji = 2, ni-1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./( maskv(ji+1,jj)+maskv(ji-1,jj)+maskv(ji,jj-1) + &
& rr*maskv(ji-1,jj-1)+rr*maskv(ji+1,jj-1) )*( &
& maskv(ji+1,jj)*dold(ji+1,jj) + &
& maskv(ji-1,jj)*dold(ji-1,jj) + maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(ji-1,jj-1)*dold(ji-1,jj-1) + rr*maskv(ji+1,jj-1)*dold(ji+1,jj-1) )
END IF
END DO
!! West and East corner of top row:
DO jci = 1, 2
ji = ivi(jci) ! first ji = 1, then ji = ni
IF (k_ew >= 0) THEN
jim = vim_per(jci) ! ji-1
jip = vip_per(jci) ! ji+1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(jip,jj)+maskv(jim,jj)+maskv(ji,jj-1) + &
& rr*maskv(jim,jj-1)+rr*maskv(jip,jj-1))*( &
& maskv(jip,jj)*dold(jip,jj) + &
& maskv(jim,jj)*dold(jim,jj) + maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(jim,jj-1)*dold(jim,jj-1) + rr*maskv(jip,jj-1)*dold(jip,jj-1) )
END IF
! No E-W periodicity:
ELSE
IF ( ji == 1 ) THEN
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(2,jj)+maskv(ji,jj-1) + &
& rr*maskv(2,jj-1))*( &
& maskv(2,jj)*dold(2,jj) + &
& maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(2,jj-1)*dold(2,jj-1) )
END IF
END IF
IF ( ji == ni ) THEN
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(ni-1,jj)+maskv(ji,jj-1) + &
& rr*maskv(ni-1,jj-1))*( &
& maskv(ni-1,jj)*dold(ni-1,jj) + maskv(ji,jj-1)*dold(ji,jj-1) + &
& rr*maskv(ni-1,jj-1)*dold(ni-1,jj-1) )
END IF
END IF
END IF
END DO
!! Center of Bottom row:
jj = 1
DO ji = 2, ni-1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(ji+1,jj)+maskv(ji,jj+1)+maskv(ji-1,jj) + &
& rr*maskv(ji+1,jj+1)+rr*maskv(ji-1,jj+1) )*( &
& maskv(ji+1,jj)*dold(ji+1,jj) + maskv(ji,jj+1)*dold(ji,jj+1) + &
& maskv(ji-1,jj)*dold(ji-1,jj) + &
& rr*maskv(ji+1,jj+1)*dold(ji+1,jj+1) + rr*maskv(ji-1,jj+1)*dold(ji-1,jj+1) )
END IF
END DO
!! West and East corner of bottom row:
DO jci = 1, 2
ji = ivi(jci) ! first ji = 1, then ji = ni
IF (k_ew >= 0) THEN
jim = vim_per(jci) ! ji-1
jip = vip_per(jci) ! ji+1
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(jip,jj)+maskv(ji,jj+1)+maskv(jim,jj) + &
& rr*maskv(jip,jj+1)+rr*maskv(jim,jj+1) )*( &
& maskv(jip,jj)*dold(jip,jj) + maskv(ji,jj+1)*dold(ji,jj+1) + &
& maskv(jim,jj)*dold(jim,jj) + &
& rr*maskv(jip,jj+1)*dold(jip,jj+1) + rr*maskv(jim,jj+1)*dold(jim,jj+1) )
END IF
!! No E-W periodicity:
ELSE
IF ( ji == 1 ) THEN
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(2,jj)+maskv(ji,jj+1) + &
& rr*maskv(2,jj+1) )*( &
& maskv(2,jj)*dold(2,jj) + maskv(ji,jj+1)*dold(ji,jj+1) + &
& rr*maskv(2,jj+1)*dold(2,jj+1) )
END IF
END IF
IF ( ji == ni ) THEN
IF ( mask_coast(ji,jj) == 1 ) THEN
X(ji,jj) = 1./(maskv(ji,jj+1)+maskv(ni-1,jj) + &
& rr*maskv(ni-1,jj+1) )*( &
& maskv(ji,jj+1)*dold(ji,jj+1) + &
& maskv(ni-1,jj)*dold(ni-1,jj) + &
& rr*maskv(ni-1,jj+1)*dold(ni-1,jj+1) )
END IF
END IF
END IF
END DO
!! Loosing land for the next iteration:
!! -----------------------------------
maskv = maskv + mask_coast
!! -----------------------------------
!IF ( jinc == jinc_debg) THEN
! CALL PRTMASK(X, 'data_X_after.nc', 'lsm')
! STOP 'after lolo'
!END IF
END DO
!! Time to smooth what's been drowned:
dold(:,:) = X(:,:)
DO js = 1, nsmooth_max
xtmp(:,:) = X(:,:)
!! Center of the domain:
X(2:ni-1,2:nj-1) = 0.35*xtmp(2:ni-1,2:nj-1) &
& + 0.65*0.25*(xtmp(3:ni,2:nj-1) + xtmp(2:ni-1,3:nj) + xtmp(1:ni-2,2:nj-1) + xtmp(2:ni-1,1:nj-2) )
!! we can use east-west periodicity:
IF (k_ew >= 0) THEN
DO jci = 1, 2
jim = vim_per(jci) ! ji-1
ji = ivi(jci) ! first ji = 1, then ji = ni
jip = vip_per(jci) ! ji+1
X(ji,2:nj-1) = 0.35*xtmp(ji,2:nj-1) &
& + 0.65*0.25*(xtmp(jip,2:nj-1) + xtmp(ji,3:nj) + xtmp(jim,2:nj-1) + xtmp(ji,1:nj-2) )
END DO
END IF
! Important to put original sea-values back on sea-domain at each
! iteration so they constrain correct values on coastal values on the
! continent during iteration.
X(:,2:nj-1) = mask(:,2:nj-1)*dold(:,2:nj-1) - (mask(:,2:nj-1) - 1)*X(:,2:nj-1)
END DO
!CALL PRTMASK(X, 'drowned_final.nc', 'lsm') ; STOP 'lolo'
DEALLOCATE ( maskv, mtmp, xtmp, dold, mask_coast )
!PRINT *, ''
!WRITE(*,'(" *** Applied DROWN with k_ew =",i2,", nb_inc =",i3,", nb_smooth =",i3)') k_ew, ninc_max, nsmooth_max
!PRINT *, ''
IF ( ldebug ) PRINT *, 'DROWN: jinc =', jinc
Xout = X
DEALLOCATE( X )
END SUBROUTINE DROWN
END MODULE MOD_DROWN
| gpl-3.0 |
likev/ncl | ncl_ncarg_src/external/lapack/zherfs.f | 2 | 11306 | SUBROUTINE ZHERFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
$ X, LDX, FERR, BERR, WORK, RWORK, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
$ WORK( * ), X( LDX, * )
* ..
*
* Purpose
* =======
*
* ZHERFS improves the computed solution to a system of linear
* equations when the coefficient matrix is Hermitian indefinite, and
* provides error bounds and backward error estimates for the solution.
*
* 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.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrices B and X. NRHS >= 0.
*
* A (input) COMPLEX*16 array, dimension (LDA,N)
* 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.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* AF (input) COMPLEX*16 array, dimension (LDAF,N)
* The factored form of the matrix A. AF contains the block
* diagonal matrix D and the multipliers used to obtain the
* factor U or L from the factorization A = U*D*U**H or
* A = L*D*L**H as computed by ZHETRF.
*
* LDAF (input) INTEGER
* The leading dimension of the array AF. LDAF >= max(1,N).
*
* IPIV (input) INTEGER array, dimension (N)
* Details of the interchanges and the block structure of D
* as determined by ZHETRF.
*
* B (input) COMPLEX*16 array, dimension (LDB,NRHS)
* The right hand side matrix B.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* X (input/output) COMPLEX*16 array, dimension (LDX,NRHS)
* On entry, the solution matrix X, as computed by ZHETRS.
* On exit, the improved solution matrix X.
*
* LDX (input) INTEGER
* The leading dimension of the array X. LDX >= max(1,N).
*
* FERR (output) DOUBLE PRECISION array, dimension (NRHS)
* The estimated forward error bound for each solution vector
* X(j) (the j-th column of the solution matrix X).
* If XTRUE is the true solution corresponding to X(j), FERR(j)
* is an estimated upper bound for the magnitude of the largest
* element in (X(j) - XTRUE) divided by the magnitude of the
* largest element in X(j). The estimate is as reliable as
* the estimate for RCOND, and is almost always a slight
* overestimate of the true error.
*
* BERR (output) DOUBLE PRECISION 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*16 array, dimension (2*N)
*
* 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
*
* Internal Parameters
* ===================
*
* ITMAX is the maximum number of steps of iterative refinement.
*
* =====================================================================
*
* .. Parameters ..
INTEGER ITMAX
PARAMETER ( ITMAX = 5 )
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D+0 )
COMPLEX*16 ONE
PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
DOUBLE PRECISION TWO
PARAMETER ( TWO = 2.0D+0 )
DOUBLE PRECISION THREE
PARAMETER ( THREE = 3.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER COUNT, I, J, K, KASE, NZ
DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
COMPLEX*16 ZDUM
* ..
* .. External Subroutines ..
EXTERNAL XERBLA, ZAXPY, ZCOPY, ZHEMV, ZHETRS, ZLACON
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, DIMAG, MAX
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH
EXTERNAL LSAME, DLAMCH
* ..
* .. Statement Functions ..
DOUBLE PRECISION CABS1
* ..
* .. Statement Function definitions ..
CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
* ..
* .. 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( NRHS.LT.0 ) THEN
INFO = -3
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -5
ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
INFO = -7
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -10
ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
INFO = -12
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZHERFS', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
DO 10 J = 1, NRHS
FERR( J ) = ZERO
BERR( J ) = ZERO
10 CONTINUE
RETURN
END IF
*
* NZ = maximum number of nonzero elements in each row of A, plus 1
*
NZ = N + 1
EPS = DLAMCH( 'Epsilon' )
SAFMIN = DLAMCH( 'Safe minimum' )
SAFE1 = NZ*SAFMIN
SAFE2 = SAFE1 / EPS
*
* Do for each right hand side
*
DO 140 J = 1, NRHS
*
COUNT = 1
LSTRES = THREE
20 CONTINUE
*
* Loop until stopping criterion is satisfied.
*
* Compute residual R = B - A * X
*
CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
CALL ZHEMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE, WORK, 1 )
*
* Compute componentwise relative backward error from formula
*
* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
*
* where abs(Z) is the componentwise absolute value of the matrix
* or vector Z. If the i-th component of the denominator is less
* than SAFE2, then SAFE1 is added to the i-th components of the
* numerator and denominator before dividing.
*
DO 30 I = 1, N
RWORK( I ) = CABS1( B( I, J ) )
30 CONTINUE
*
* Compute abs(A)*abs(X) + abs(B).
*
IF( UPPER ) THEN
DO 50 K = 1, N
S = ZERO
XK = CABS1( X( K, J ) )
DO 40 I = 1, K - 1
RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
40 CONTINUE
RWORK( K ) = RWORK( K ) + ABS( DBLE( A( K, K ) ) )*XK + S
50 CONTINUE
ELSE
DO 70 K = 1, N
S = ZERO
XK = CABS1( X( K, J ) )
RWORK( K ) = RWORK( K ) + ABS( DBLE( A( K, K ) ) )*XK
DO 60 I = K + 1, N
RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
60 CONTINUE
RWORK( K ) = RWORK( K ) + S
70 CONTINUE
END IF
S = ZERO
DO 80 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
ELSE
S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
$ ( RWORK( I )+SAFE1 ) )
END IF
80 CONTINUE
BERR( J ) = S
*
* Test stopping criterion. Continue iterating if
* 1) The residual BERR(J) is larger than machine epsilon, and
* 2) BERR(J) decreased by at least a factor of 2 during the
* last iteration, and
* 3) At most ITMAX iterations tried.
*
IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
$ COUNT.LE.ITMAX ) THEN
*
* Update solution and try again.
*
CALL ZHETRS( UPLO, N, 1, AF, LDAF, IPIV, WORK, N, INFO )
CALL ZAXPY( N, ONE, WORK, 1, X( 1, J ), 1 )
LSTRES = BERR( J )
COUNT = COUNT + 1
GO TO 20
END IF
*
* Bound error from formula
*
* norm(X - XTRUE) / norm(X) .le. FERR =
* norm( abs(inv(A))*
* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
*
* where
* norm(Z) is the magnitude of the largest component of Z
* inv(A) is the inverse of A
* abs(Z) is the componentwise absolute value of the matrix or
* vector Z
* NZ is the maximum number of nonzeros in any row of A, plus 1
* EPS is machine epsilon
*
* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
* is incremented by SAFE1 if the i-th component of
* abs(A)*abs(X) + abs(B) is less than SAFE2.
*
* Use ZLACON to estimate the infinity-norm of the matrix
* inv(A) * diag(W),
* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
*
DO 90 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
ELSE
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
$ SAFE1
END IF
90 CONTINUE
*
KASE = 0
100 CONTINUE
CALL ZLACON( N, WORK( N+1 ), WORK, FERR( J ), KASE )
IF( KASE.NE.0 ) THEN
IF( KASE.EQ.1 ) THEN
*
* Multiply by diag(W)*inv(A').
*
CALL ZHETRS( UPLO, N, 1, AF, LDAF, IPIV, WORK, N, INFO )
DO 110 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
110 CONTINUE
ELSE IF( KASE.EQ.2 ) THEN
*
* Multiply by inv(A)*diag(W).
*
DO 120 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
120 CONTINUE
CALL ZHETRS( UPLO, N, 1, AF, LDAF, IPIV, WORK, N, INFO )
END IF
GO TO 100
END IF
*
* Normalize error.
*
LSTRES = ZERO
DO 130 I = 1, N
LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
130 CONTINUE
IF( LSTRES.NE.ZERO )
$ FERR( J ) = FERR( J ) / LSTRES
*
140 CONTINUE
*
RETURN
*
* End of ZHERFS
*
END
| gpl-2.0 |
FRidh/scipy | scipy/integrate/quadpack/dqk15w.f | 138 | 6667 | subroutine dqk15w(f,w,p1,p2,p3,p4,kp,a,b,result,abserr,
* resabs,resasc)
c***begin prologue dqk15w
c***date written 810101 (yymmdd)
c***revision date 830518 (mmddyy)
c***category no. h2a2a2
c***keywords 15-point gauss-kronrod rules
c***author piessens,robert,appl. math. & progr. div. - k.u.leuven
c de doncker,elise,appl. math. & progr. div. - k.u.leuven
c***purpose to compute i = integral of f*w over (a,b), with error
c estimate
c j = integral of abs(f*w) over (a,b)
c***description
c
c integration rules
c standard fortran subroutine
c double precision version
c
c parameters
c on entry
c f - double precision
c function subprogram defining the integrand
c function f(x). the actual name for f needs to be
c declared e x t e r n a l in the driver program.
c
c w - double precision
c function subprogram defining the integrand
c weight function w(x). the actual name for w
c needs to be declared e x t e r n a l in the
c calling program.
c
c p1, p2, p3, p4 - double precision
c parameters in the weight function
c
c kp - integer
c key for indicating the type of weight function
c
c a - double precision
c lower limit of integration
c
c b - double precision
c upper limit of integration
c
c on return
c result - double precision
c approximation to the integral i
c result is computed by applying the 15-point
c kronrod rule (resk) obtained by optimal addition
c of abscissae to the 7-point gauss rule (resg).
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 resabs - double precision
c approximation to the integral of abs(f)
c
c resasc - double precision
c approximation to the integral of abs(f-i/(b-a))
c
c
c***references (none)
c***routines called d1mach
c***end prologue dqk15w
c
double precision a,absc,absc1,absc2,abserr,b,centr,dabs,dhlgth,
* dmax1,dmin1,d1mach,epmach,f,fc,fsum,fval1,fval2,fv1,fv2,hlgth,
* p1,p2,p3,p4,resabs,resasc,resg,resk,reskh,result,uflow,w,wg,wgk,
* xgk
integer j,jtw,jtwm1,kp
external f,w
c
dimension fv1(7),fv2(7),xgk(8),wgk(8),wg(4)
c
c the abscissae and weights are given for the interval (-1,1).
c because of symmetry only the positive abscissae and their
c corresponding weights are given.
c
c xgk - abscissae of the 15-point gauss-kronrod rule
c xgk(2), xgk(4), ... abscissae of the 7-point
c gauss rule
c xgk(1), xgk(3), ... abscissae which are optimally
c added to the 7-point gauss rule
c
c wgk - weights of the 15-point gauss-kronrod rule
c
c wg - weights of the 7-point gauss rule
c
data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8)/
* 0.9914553711208126d+00, 0.9491079123427585d+00,
* 0.8648644233597691d+00, 0.7415311855993944d+00,
* 0.5860872354676911d+00, 0.4058451513773972d+00,
* 0.2077849550078985d+00, 0.0000000000000000d+00/
c
data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8)/
* 0.2293532201052922d-01, 0.6309209262997855d-01,
* 0.1047900103222502d+00, 0.1406532597155259d+00,
* 0.1690047266392679d+00, 0.1903505780647854d+00,
* 0.2044329400752989d+00, 0.2094821410847278d+00/
c
data wg(1),wg(2),wg(3),wg(4)/
* 0.1294849661688697d+00, 0.2797053914892767d+00,
* 0.3818300505051889d+00, 0.4179591836734694d+00/
c
c
c list of major variables
c -----------------------
c
c centr - mid point of the interval
c hlgth - half-length of the interval
c absc* - abscissa
c fval* - function value
c resg - result of the 7-point gauss formula
c resk - result of the 15-point kronrod formula
c reskh - approximation to the mean value of f*w over (a,b),
c i.e. to i/(b-a)
c
c machine dependent constants
c ---------------------------
c
c epmach is the largest relative spacing.
c uflow is the smallest positive magnitude.
c
c***first executable statement dqk15w
epmach = d1mach(4)
uflow = d1mach(1)
c
centr = 0.5d+00*(a+b)
hlgth = 0.5d+00*(b-a)
dhlgth = dabs(hlgth)
c
c compute the 15-point kronrod approximation to the
c integral, and estimate the error.
c
fc = f(centr)*w(centr,p1,p2,p3,p4,kp)
resg = wg(4)*fc
resk = wgk(8)*fc
resabs = dabs(resk)
do 10 j=1,3
jtw = j*2
absc = hlgth*xgk(jtw)
absc1 = centr-absc
absc2 = centr+absc
fval1 = f(absc1)*w(absc1,p1,p2,p3,p4,kp)
fval2 = f(absc2)*w(absc2,p1,p2,p3,p4,kp)
fv1(jtw) = fval1
fv2(jtw) = fval2
fsum = fval1+fval2
resg = resg+wg(j)*fsum
resk = resk+wgk(jtw)*fsum
resabs = resabs+wgk(jtw)*(dabs(fval1)+dabs(fval2))
10 continue
do 15 j=1,4
jtwm1 = j*2-1
absc = hlgth*xgk(jtwm1)
absc1 = centr-absc
absc2 = centr+absc
fval1 = f(absc1)*w(absc1,p1,p2,p3,p4,kp)
fval2 = f(absc2)*w(absc2,p1,p2,p3,p4,kp)
fv1(jtwm1) = fval1
fv2(jtwm1) = fval2
fsum = fval1+fval2
resk = resk+wgk(jtwm1)*fsum
resabs = resabs+wgk(jtwm1)*(dabs(fval1)+dabs(fval2))
15 continue
reskh = resk*0.5d+00
resasc = wgk(8)*dabs(fc-reskh)
do 20 j=1,7
resasc = resasc+wgk(j)*(dabs(fv1(j)-reskh)+dabs(fv2(j)-reskh))
20 continue
result = resk*hlgth
resabs = resabs*dhlgth
resasc = resasc*dhlgth
abserr = dabs((resk-resg)*hlgth)
if(resasc.ne.0.0d+00.and.abserr.ne.0.0d+00)
* abserr = resasc*dmin1(0.1d+01,(0.2d+03*abserr/resasc)**1.5d+00)
if(resabs.gt.uflow/(0.5d+02*epmach)) abserr = dmax1((epmach*
* 0.5d+02)*resabs,abserr)
return
end
| bsd-3-clause |
RobinsonLab/GlobalCurve | header/h_binding_models.f90 | 2 | 1081 | module h_binding_models
interface
function hill(current_model,current_data) result(bind)
use h_struct
implicit none
type(model_struct), pointer :: current_model
type (data_struct),pointer :: current_data
real,dimension(current_data%len) :: bind
end function
function three_state_simple_model(current_model,current_data) result(bind)
use h_struct
implicit none
type(model_struct), pointer :: current_model
type (data_struct),pointer :: current_data
real,dimension(current_data%len) :: bind
end function
function simulate_ca_gr_titr(current_model,current_data) result(bind)
use h_struct
implicit none
type(model_struct), pointer :: current_model
type (data_struct),pointer :: current_data
real,dimension(current_data%len) :: bind
end function
function frac_sat(current_model,current_data) result(bind)
use h_struct
implicit none
type(model_struct), pointer :: current_model
type (data_struct),pointer :: current_data
real,dimension(current_data%len) :: bind
end function
end interface
end module h_binding_models | apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.