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 |
---|---|---|---|---|---|
CapeDrew/DITK | Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/double/dlatdf.f | 43 | 8540 | SUBROUTINE DLATDF( IJOB, N, Z, LDZ, RHS, RDSUM, RDSCAL, IPIV,
$ JPIV )
*
* -- 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 IJOB, LDZ, N
DOUBLE PRECISION RDSCAL, RDSUM
* ..
* .. Array Arguments ..
INTEGER IPIV( * ), JPIV( * )
DOUBLE PRECISION RHS( * ), Z( LDZ, * )
* ..
*
* Purpose
* =======
*
* DLATDF uses the LU factorization of the n-by-n matrix Z computed by
* DGETC2 and computes a contribution to the reciprocal Dif-estimate
* by solving Z * x = b for x, and choosing the r.h.s. b such that
* the norm of x is as large as possible. On entry RHS = b holds the
* contribution from earlier solved sub-systems, and on return RHS = x.
*
* The factorization of Z returned by DGETC2 has the form Z = P*L*U*Q,
* where P and Q are permutation matrices. L is lower triangular with
* unit diagonal elements and U is upper triangular.
*
* Arguments
* =========
*
* IJOB (input) INTEGER
* IJOB = 2: First compute an approximative null-vector e
* of Z using DGECON, e is normalized and solve for
* Zx = +-e - f with the sign giving the greater value
* of 2-norm(x). About 5 times as expensive as Default.
* IJOB .ne. 2: Local look ahead strategy where all entries of
* the r.h.s. b is choosen as either +1 or -1 (Default).
*
* N (input) INTEGER
* The number of columns of the matrix Z.
*
* Z (input) DOUBLE PRECISION array, dimension (LDZ, N)
* On entry, the LU part of the factorization of the n-by-n
* matrix Z computed by DGETC2: Z = P * L * U * Q
*
* LDZ (input) INTEGER
* The leading dimension of the array Z. LDA >= max(1, N).
*
* RHS (input/output) DOUBLE PRECISION array, dimension N.
* On entry, RHS contains contributions from other subsystems.
* On exit, RHS contains the solution of the subsystem with
* entries acoording to the value of IJOB (see above).
*
* RDSUM (input/output) DOUBLE PRECISION
* On entry, the sum of squares of computed contributions to
* the Dif-estimate under computation by DTGSYL, where the
* scaling factor RDSCAL (see below) has been factored out.
* On exit, the corresponding sum of squares updated with the
* contributions from the current sub-system.
* If TRANS = 'T' RDSUM is not touched.
* NOTE: RDSUM only makes sense when DTGSY2 is called by STGSYL.
*
* RDSCAL (input/output) DOUBLE PRECISION
* On entry, scaling factor used to prevent overflow in RDSUM.
* On exit, RDSCAL is updated w.r.t. the current contributions
* in RDSUM.
* If TRANS = 'T', RDSCAL is not touched.
* NOTE: RDSCAL only makes sense when DTGSY2 is called by
* DTGSYL.
*
* IPIV (input) INTEGER array, dimension (N).
* The pivot indices; for 1 <= i <= N, row i of the
* matrix has been interchanged with row IPIV(i).
*
* JPIV (input) INTEGER array, dimension (N).
* The pivot indices; for 1 <= j <= N, column j of the
* matrix has been interchanged with column JPIV(j).
*
* Further Details
* ===============
*
* Based on contributions by
* Bo Kagstrom and Peter Poromaa, Department of Computing Science,
* Umea University, S-901 87 Umea, Sweden.
*
* This routine is a further developed implementation of algorithm
* BSOLVE in [1] using complete pivoting in the LU factorization.
*
* [1] Bo Kagstrom and Lars Westin,
* Generalized Schur Methods with Condition Estimators for
* Solving the Generalized Sylvester Equation, IEEE Transactions
* on Automatic Control, Vol. 34, No. 7, July 1989, pp 745-751.
*
* [2] Peter Poromaa,
* On Efficient and Robust Estimators for the Separation
* between two Regular Matrix Pairs with Applications in
* Condition Estimation. Report IMINF-95.05, Departement of
* Computing Science, Umea University, S-901 87 Umea, Sweden, 1995.
*
* =====================================================================
*
* .. Parameters ..
INTEGER MAXDIM
PARAMETER ( MAXDIM = 8 )
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I, INFO, J, K
DOUBLE PRECISION BM, BP, PMONE, SMINU, SPLUS, TEMP
* ..
* .. Local Arrays ..
INTEGER IWORK( MAXDIM )
DOUBLE PRECISION WORK( 4*MAXDIM ), XM( MAXDIM ), XP( MAXDIM )
* ..
* .. External Subroutines ..
EXTERNAL DAXPY, DCOPY, DGECON, DGESC2, DLASSQ, DLASWP,
$ DSCAL
* ..
* .. External Functions ..
DOUBLE PRECISION DASUM, DDOT
EXTERNAL DASUM, DDOT
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, SQRT
* ..
* .. Executable Statements ..
*
IF( IJOB.NE.2 ) THEN
*
* Apply permutations IPIV to RHS
*
CALL DLASWP( 1, RHS, LDZ, 1, N-1, IPIV, 1 )
*
* Solve for L-part choosing RHS either to +1 or -1.
*
PMONE = -ONE
*
DO 10 J = 1, N - 1
BP = RHS( J ) + ONE
BM = RHS( J ) - ONE
SPLUS = ONE
*
* Look-ahead for L-part RHS(1:N-1) = + or -1, SPLUS and
* SMIN computed more efficiently than in BSOLVE [1].
*
SPLUS = SPLUS + DDOT( N-J, Z( J+1, J ), 1, Z( J+1, J ), 1 )
SMINU = DDOT( N-J, Z( J+1, J ), 1, RHS( J+1 ), 1 )
SPLUS = SPLUS*RHS( J )
IF( SPLUS.GT.SMINU ) THEN
RHS( J ) = BP
ELSE IF( SMINU.GT.SPLUS ) THEN
RHS( J ) = BM
ELSE
*
* In this case the updating sums are equal and we can
* choose RHS(J) +1 or -1. The first time this happens
* we choose -1, thereafter +1. This is a simple way to
* get good estimates of matrices like Byers well-known
* example (see [1]). (Not done in BSOLVE.)
*
RHS( J ) = RHS( J ) + PMONE
PMONE = ONE
END IF
*
* Compute the remaining r.h.s.
*
TEMP = -RHS( J )
CALL DAXPY( N-J, TEMP, Z( J+1, J ), 1, RHS( J+1 ), 1 )
*
10 CONTINUE
*
* Solve for U-part, look-ahead for RHS(N) = +-1. This is not done
* in BSOLVE and will hopefully give us a better estimate because
* any ill-conditioning of the original matrix is transfered to U
* and not to L. U(N, N) is an approximation to sigma_min(LU).
*
CALL DCOPY( N-1, RHS, 1, XP, 1 )
XP( N ) = RHS( N ) + ONE
RHS( N ) = RHS( N ) - ONE
SPLUS = ZERO
SMINU = ZERO
DO 30 I = N, 1, -1
TEMP = ONE / Z( I, I )
XP( I ) = XP( I )*TEMP
RHS( I ) = RHS( I )*TEMP
DO 20 K = I + 1, N
XP( I ) = XP( I ) - XP( K )*( Z( I, K )*TEMP )
RHS( I ) = RHS( I ) - RHS( K )*( Z( I, K )*TEMP )
20 CONTINUE
SPLUS = SPLUS + ABS( XP( I ) )
SMINU = SMINU + ABS( RHS( I ) )
30 CONTINUE
IF( SPLUS.GT.SMINU )
$ CALL DCOPY( N, XP, 1, RHS, 1 )
*
* Apply the permutations JPIV to the computed solution (RHS)
*
CALL DLASWP( 1, RHS, LDZ, 1, N-1, JPIV, -1 )
*
* Compute the sum of squares
*
CALL DLASSQ( N, RHS, 1, RDSCAL, RDSUM )
*
ELSE
*
* IJOB = 2, Compute approximate nullvector XM of Z
*
CALL DGECON( 'I', N, Z, LDZ, ONE, TEMP, WORK, IWORK, INFO )
CALL DCOPY( N, WORK( N+1 ), 1, XM, 1 )
*
* Compute RHS
*
CALL DLASWP( 1, XM, LDZ, 1, N-1, IPIV, -1 )
TEMP = ONE / SQRT( DDOT( N, XM, 1, XM, 1 ) )
CALL DSCAL( N, TEMP, XM, 1 )
CALL DCOPY( N, XM, 1, XP, 1 )
CALL DAXPY( N, ONE, RHS, 1, XP, 1 )
CALL DAXPY( N, -ONE, XM, 1, RHS, 1 )
CALL DGESC2( N, Z, LDZ, RHS, IPIV, JPIV, TEMP )
CALL DGESC2( N, Z, LDZ, XP, IPIV, JPIV, TEMP )
IF( DASUM( N, XP, 1 ).GT.DASUM( N, RHS, 1 ) )
$ CALL DCOPY( N, XP, 1, RHS, 1 )
*
* Compute the sum of squares
*
CALL DLASSQ( N, RHS, 1, RDSCAL, RDSUM )
*
END IF
*
RETURN
*
* End of DLATDF
*
END
| apache-2.0 |
itsimbal/gcc.cet | gcc/testsuite/gfortran.dg/interface_assignment_5.f90 | 155 | 1452 | ! { dg-do compile }
!
! PR 42677: [4.5 Regression] Bogus Error: Ambiguous interfaces '...' in intrinsic assignment operator
!
! Contributed by Harald Anlauf <anlauf@gmx.de>
module mod1
implicit none
type t_m
integer :: i = 0
end type t_m
!------------------------------------------------------------------------------
interface assignment (=)
module procedure assign_m
end interface
!------------------------------------------------------------------------------
contains
subroutine assign_m (y, x)
type(t_m) ,intent(inout) :: y
type(t_m) ,intent(in) :: x
end subroutine assign_m
end module mod1
!==============================================================================
module mod2
use mod1, only: t_m, assignment(=)
implicit none
type t_atm
integer :: k
end type t_atm
!------------------------------------------------------------------------------
interface assignment(=)
module procedure assign_to_atm
end interface
!------------------------------------------------------------------------------
interface
pure subroutine delete_m (x)
use mod1
type(t_m) ,intent(in) :: x
end subroutine delete_m
end interface
!------------------------------------------------------------------------------
contains
subroutine assign_to_atm (atm, r)
type(t_atm) ,intent(inout) :: atm
integer ,intent(in) :: r
end subroutine assign_to_atm
end module mod2
| gpl-2.0 |
CapeDrew/DITK | Modules/ThirdParty/VNL/src/vxl/v3p/netlib/blas/ztrsv.f | 68 | 10551 | SUBROUTINE ZTRSV ( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )
* .. Scalar Arguments ..
INTEGER INCX, LDA, N
CHARACTER*1 DIAG, TRANS, UPLO
* .. Array Arguments ..
COMPLEX*16 A( LDA, * ), X( * )
* ..
*
* Purpose
* =======
*
* ZTRSV solves one of the systems of equations
*
* A*x = b, or A'*x = b, or conjg( 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.
*
* No test for singularity or near-singularity is included in this
* routine. Such tests must be performed before calling this routine.
*
* Parameters
* ==========
*
* 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' conjg( 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.
*
* A - COMPLEX*16 array of DIMENSION ( LDA, n ).
* Before entry with UPLO = 'U' or 'u', the leading n by n
* upper triangular part of the array A must contain the upper
* triangular matrix and the strictly lower triangular part of
* A is not referenced.
* Before entry with UPLO = 'L' or 'l', the leading n by n
* 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. LDA must be at least
* max( 1, n ).
* 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 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.
*
*
* 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 ..
COMPLEX*16 ZERO
PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )
* .. Local Scalars ..
COMPLEX*16 TEMP
INTEGER I, INFO, IX, J, JX, KX
LOGICAL NOCONJ, NOUNIT
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* .. External Subroutines ..
EXTERNAL XERBLA
* .. Intrinsic Functions ..
INTRINSIC DCONJG, MAX
* ..
* .. Executable Statements ..
*
* 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( LDA.LT.MAX( 1, N ) )THEN
INFO = 6
ELSE IF( INCX.EQ.0 )THEN
INFO = 8
END IF
IF( INFO.NE.0 )THEN
CALL XERBLA( 'ZTRSV ', 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 := inv( A )*x.
*
IF( LSAME( UPLO, 'U' ) )THEN
IF( INCX.EQ.1 )THEN
DO 20, J = N, 1, -1
IF( X( J ).NE.ZERO )THEN
IF( NOUNIT )
$ X( J ) = X( J )/A( J, J )
TEMP = X( J )
DO 10, I = J - 1, 1, -1
X( I ) = X( I ) - TEMP*A( I, J )
10 CONTINUE
END IF
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 )/A( J, J )
TEMP = X( JX )
IX = JX
DO 30, I = J - 1, 1, -1
IX = IX - INCX
X( IX ) = X( IX ) - TEMP*A( I, J )
30 CONTINUE
END IF
JX = JX - INCX
40 CONTINUE
END IF
ELSE
IF( INCX.EQ.1 )THEN
DO 60, J = 1, N
IF( X( J ).NE.ZERO )THEN
IF( NOUNIT )
$ X( J ) = X( J )/A( J, J )
TEMP = X( J )
DO 50, I = J + 1, N
X( I ) = X( I ) - TEMP*A( I, J )
50 CONTINUE
END IF
60 CONTINUE
ELSE
JX = KX
DO 80, J = 1, N
IF( X( JX ).NE.ZERO )THEN
IF( NOUNIT )
$ X( JX ) = X( JX )/A( J, J )
TEMP = X( JX )
IX = JX
DO 70, I = J + 1, N
IX = IX + INCX
X( IX ) = X( IX ) - TEMP*A( I, J )
70 CONTINUE
END IF
JX = JX + INCX
80 CONTINUE
END IF
END IF
ELSE
*
* Form x := inv( A' )*x or x := inv( conjg( A' ) )*x.
*
IF( LSAME( UPLO, 'U' ) )THEN
IF( INCX.EQ.1 )THEN
DO 110, J = 1, N
TEMP = X( J )
IF( NOCONJ )THEN
DO 90, I = 1, J - 1
TEMP = TEMP - A( I, J )*X( I )
90 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/A( J, J )
ELSE
DO 100, I = 1, J - 1
TEMP = TEMP - DCONJG( A( I, J ) )*X( I )
100 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/DCONJG( A( J, J ) )
END IF
X( J ) = TEMP
110 CONTINUE
ELSE
JX = KX
DO 140, J = 1, N
IX = KX
TEMP = X( JX )
IF( NOCONJ )THEN
DO 120, I = 1, J - 1
TEMP = TEMP - A( I, J )*X( IX )
IX = IX + INCX
120 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/A( J, J )
ELSE
DO 130, I = 1, J - 1
TEMP = TEMP - DCONJG( A( I, J ) )*X( IX )
IX = IX + INCX
130 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/DCONJG( A( J, J ) )
END IF
X( JX ) = TEMP
JX = JX + INCX
140 CONTINUE
END IF
ELSE
IF( INCX.EQ.1 )THEN
DO 170, J = N, 1, -1
TEMP = X( J )
IF( NOCONJ )THEN
DO 150, I = N, J + 1, -1
TEMP = TEMP - A( I, J )*X( I )
150 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/A( J, J )
ELSE
DO 160, I = N, J + 1, -1
TEMP = TEMP - DCONJG( A( I, J ) )*X( I )
160 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/DCONJG( A( J, J ) )
END IF
X( J ) = TEMP
170 CONTINUE
ELSE
KX = KX + ( N - 1 )*INCX
JX = KX
DO 200, J = N, 1, -1
IX = KX
TEMP = X( JX )
IF( NOCONJ )THEN
DO 180, I = N, J + 1, -1
TEMP = TEMP - A( I, J )*X( IX )
IX = IX - INCX
180 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/A( J, J )
ELSE
DO 190, I = N, J + 1, -1
TEMP = TEMP - DCONJG( A( I, J ) )*X( IX )
IX = IX - INCX
190 CONTINUE
IF( NOUNIT )
$ TEMP = TEMP/DCONJG( A( J, J ) )
END IF
X( JX ) = TEMP
JX = JX - INCX
200 CONTINUE
END IF
END IF
END IF
*
RETURN
*
* End of ZTRSV .
*
END
| apache-2.0 |
emb-team/loongson-gccgo | libgfortran/generated/_exp_c4.F90 | 35 | 1478 | ! 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_4)
#ifdef HAVE_CEXPF
elemental function _gfortran_specific__exp_c4 (parm)
complex (kind=4), intent (in) :: parm
complex (kind=4) :: _gfortran_specific__exp_c4
_gfortran_specific__exp_c4 = exp (parm)
end function
#endif
#endif
| gpl-2.0 |
PHASTA/phasta | phSolver/compressible/getdiff.f | 1 | 11878 | subroutine getDiff (T, cp, rho, ycl,
& rmu, rlm, rlm2mu, con, shp,
& xmudmi, xl)
c----------------------------------------------------------------------
c
c This routine calculates the fluid material properties.
c
c input:
c T (npro) : temperature
c cp (npro) : specific heat at constant pressure
c **************************************************************
c rho (npro) : density
c ycl (npro,nshl,ndof): Y variables
c shp (npro,nshl) : element shape-functions
c *************************************************************
c output:
c rmu (npro) : Mu
c rlm (npro) : Lambda
c rlm2mu (npro) : Lambda + 2 Mu
c con (npro) : Conductivity
c
c Note: material type flags
c matflg(2):
c eq. 0, constant viscosity
c eq. 1, generalized Sutherland viscosity
c matflg(3):
c eq. 0, Stokes approximation
c eq. 1, shear proportional bulk viscosity
c
c
c Farzin Shakib, Winter 1987.
c Zdenek Johan, Winter 1991. (Fortran 90)
c----------------------------------------------------------------------
c
use turbSA
use pointer_data
include "common.h"
c
dimension T(npro), cp(npro),
& rho(npro), Sclr(npro),
& rmu(npro), rlm(npro),
& rlm2mu(npro), con(npro),
& ycl(npro,nshl,ndof), shp(npro,nshl),
& xmudmi(npro,ngauss), xl(npro,nenl,nsd),
& xx(npro)
c
dimension xmut(npro)
real*8 prop_blend(npro),test_it(npro)
integer n, e
integer wallmask(nshl)
real*8 xki, xki3, fv1, evisc, lvisc
xx=zero
do n=1,nenl
xx(:)=xx(:) + shp(:,n) * xl(:,n,1)
enddo
c
c
c.... constant viscosity
c
if (matflg(2,1) .eq. 0) then
c
if (iLSet .ne. 0)then !two fluid properties used in this model
Sclr = zero
isc=abs(iRANS)+6
do n = 1, nshl
Sclr = Sclr + shp(:,n) * ycl(:,n,isc)
enddo
test_it = 0.5*(one + Sclr/epsilon_ls +
& (sin(pi*Sclr/epsilon_ls))/pi )
prop_blend = max( min(test_it(:), one ), zero )
rmu = datmat(1,2,2) + (datmat(1,2,1)-datmat(1,2,2))
& *prop_blend
elseif(irampViscOutlet.eq.1)then ! increase viscosity near outlet
c.............ramp rmu near outlet (for a Duct geometry)
fmax=10.0
! fmax=2000.0
c if (myrank .eq. master)then
c write(*,*) 'viscosity', datmat(1,2,1)
c endif
c... geometry6
if(iDuctgeometryType .eq. 6)then
c if (myrank .eq. master) write(*,*) 'getdiff, geometry6'
where(xx(:).le. 0.42) !halfway btwn AIP and exit
rmu(:)= datmat(1,2,1)
elsewhere(xx(:).ge. 0.75) !2/3 of the way to the exit
rmu(:)=fmax*datmat(1,2,1)
elsewhere
rmu(:)= datmat(1,2,1)*(
& (55.65294821-55.65294821*fmax)*xx(:)*xx(:)*xx(:)
& +(-97.67092412+97.67092412*fmax)*xx(:)*xx(:)
& +(52.59203606-52.59203606*fmax)*xx(:)
& -7.982719760+8.982719760*fmax)
endwhere
c do i = 1,npro
c if(xx(i) .lt. 0.75 .and. xx(i) .gt. 0.42)
c & write(*,*) xx(i), rmu(i)
c enddo
c... geometry8
elseif (iDuctgeometryType .eq. 8)then
xstart=1.5 !1.6*4.5*0.0254+0.85*0.5
xmidwy=2.0 !1.6*4.5*0.0254+0.85*1.0
where(xx(:).le.xstart)
rmu(:)=datmat(1,2,1)
elsewhere(xx(:).ge.xmidwy)
rmu(:)=fmax*datmat(1,2,1)
elsewhere
rmu(:)=datmat(1,2,1)
& *(1+(fmax-1)*(0.5+
& tanh(5*(xx(:)-(xmidwy+xstart)/2)/(xmidwy-xstart))/2))
endwhere
endif
c.....................................................
else ! constant viscosity
rmu = datmat(1,2,1)
endif
!
! boundary layer thickening via molecular viscosity
!
scaleCntrl=1.0
Lvisc=0.2
xbltb=-0.2159-two*Lvisc
xblte=-0.2159-Lvisc
where((xx(:).gt.xbltb) .and. (xx(:).lt.xblte))
rmu(:)=scaleCntrl*datmat(1,2,1)
endwhere
! xvisc1 = -0.3048
! xvisc2 = -0.2159
! where(xx(:).lt.xvisc1)
! rmu(:)=scaleCntrl*datmat(1,2,1)
! elsewhere(xx(:).gt.xvisc1 .and. xx(:).lt.xvisc2)
! rmu(:)=( scaleCntrl - (scaleCntrl - 1)*
! & (xx(:) - xvisc1)/(xvisc2 - xvisc1))*datmat(1,2,1)
! endwhere
!if(myrank.eq.master) then
! write(*,*) 'adjusting viscosity in region by ', scaleCntrl
!endif
else
c
c.... generalized Sutherland viscosity
c
rmu = datmat(1,2,1) * (T/datmat(2,2,1))*sqrt(T/datmat(2,2,1))
& * ( datmat(2,2,1) + datmat(3,2,1) ) / (T + datmat(3,2,1))
c
endif
c
c.... calculate the second viscosity coefficient
c
if (matflg(3,1) .eq. 0) then
rlm = -pt66 * rmu
else
rlm = (datmat(1,3,1) - pt66) * rmu
endif
c
c.... calculate the remaining quantities
c
con = rmu * cp / pr
c
c-------------Eddy Viscosity Calculation-----------------
c
c.... dynamic model
c
if (iLES .gt. 0. and. iRANS.eq.0) then ! simple LES
xmut = xmudmi(:,intp)
else if (iRANS .eq. 0 .and. iLES.eq.0 ) then !DNS
xmut = zero
else if (iRANS .lt. 0) then ! calculate RANS viscosity
c
c.... RANS
c
do e = 1, npro
wallmask = 0
if(itwmod.eq.-2) then ! effective viscosity
c mark the wall nodes for this element, if there are any
do n = 1, nshl
c
c note that we are using ycl here so that means that these
c terms are not perturbed for MFG difference and therefore
c NOT in the LHS. As they only give the evisc near the wall
c I doubt this is a problem.
c
u1=ycl(e,n,2)
u2=ycl(e,n,3)
u3=ycl(e,n,4)
if((u1.eq.zero).and.(u2.eq.zero).and.(u3.eq.zero))
& then
wallmask(n)=1
endif
enddo
endif
c
if( any(wallmask.eq.1) ) then
c if there are wall nodes for this elt in an effective-viscosity wall
c modeled case,then eddy viscosity has been stored at the wall nodes
c in place of the spalart-allmaras variable; the eddy viscosity for
c the whole element is taken to be the avg of wall values
evisc = zero
nwnode=0
do n = 1, nshl
if(wallmask(n).eq.1) then
evisc = evisc + ycl(e,n,6)
nwnode = nwnode + 1
endif
enddo
evisc = evisc/nwnode
xmut(e)= abs(evisc)
c this is what we would use instead of the above if we were allowing
c the eddy viscosity to vary through the element based on non-wall nodes
c$$$ evisc = zero
c$$$ Turb = zero
c$$$ do n = 1, nshl
c$$$ if(wallmask(n).eq.1) then
c$$$ evisc = evisc + shape(e,n) * ycl(e,n,6)
c$$$ else
c$$$ Turb = Turb + shape(e,n) * ycl(e,n,6)
c$$$ endif
c$$$ enddo
c$$$ xki = abs(Turb)/rmu(e)
c$$$ xki3 = xki * xki * xki
c$$$ fv1 = xki3 / (xki3 + saCv1P3)
c$$$ rmu(e) = rmu(e) + fv1*abs(Turb)
c$$$ rmu(e) = rmu(e) + abs(evisc)
else
c else one of the following is the case:
c using effective-viscosity, but no wall nodes on this elt
c using slip-velocity
c using no model; walls are resolved
c in all of these cases, eddy viscosity is calculated normally
savar = zero
do n = 1, nshl
savar = savar + shp(e,n) * ycl(e,n,6)
enddo
xki = rho(e)*abs(savar)/rmu(e)
xki3 = xki * xki * xki
fv1 = xki3 / (xki3 + saCv1P3)
xmut(e) = fv1*abs(savar)*rho(e)
endif
enddo ! end loop over elts
if (iLES.gt.0) then ! this is DES so we have to blend in
! xmudmi based on max edge length of
! element
call EviscDES (xl,xmut,xmudmi)
endif
endif ! check for LES or RANS
rlm = rlm - pt66*xmuT
rmu = rmu + xmuT
rlm2mu = rlm + two * rmu
con = con + xmuT*cp/pr
c
c.... return
c
return
end
c
c
c
subroutine getDiffSclr (T, cp, rmu, rlm,
& rlm2mu, con, rho, Sclr)
c
c----------------------------------------------------------------------
c
c This routine calculates the fluid material properties.
c
c input:
c T (npro) : temperature
c cp (npro) : specific heat at constant pressure
c
c output:
c rmu (npro) : Mu
c rlm (npro) : Lambda
c rlm2mu (npro) : Lambda + 2 Mu
c con (npro) : Conductivity
c
c Note: material type flags
c matflg(2):
c eq. 0, constant viscosity
c eq. 1, generalized Sutherland viscosity
c matflg(3):
c eq. 0, Stokes approximation
c eq. 1, shear proportional bulk viscosity
c
c
c Farzin Shakib, Winter 1987.
c Zdenek Johan, Winter 1991. (Fortran 90)
c----------------------------------------------------------------------
c
include "common.h"
c
dimension T(npro), cp(npro),
& rmu(npro), rlm(npro),
& rlm2mu(npro), con(npro),
& rho(npro), Sclr(npro)
c
c
c.... constant viscosity
c
if (matflg(2,1) .eq. 0) then
c
rmu = datmat(1,2,1)
c
else
c
c.... generalized Sutherland viscosity
c
rmu = datmat(1,2,1) * (T/datmat(2,2,1))*sqrt(T/datmat(2,2,1))
& * ( datmat(2,2,1) + datmat(3,2,1) ) / (T + datmat(3,2,1))
c
endif
c
*************************check****************************
c if (iRANS(1).lt.zero) then
c rmu = saSigmaInv*rho*((rmu/rho)+Sclr)
c endif
c This augmentation of viscosity is performed in e3viscsclr
c The Spalart -Allmaras model will need molecular viscosity
c in subsequent calculations.
c.... calculate the second viscosity coefficient
c
if (matflg(3,1) .eq. 0) then
c
rlm = -pt66 * rmu
c
else
c
rlm = (datmat(1,3,1) - pt66) * rmu
c
endif
c
c.... calculate the remaining quantities
c
rlm2mu = rlm + two * rmu
con = rmu * cp / pr
c
c.... return
c
return
end
subroutine EviscDES(xl,xmut,xmudmi)
include "common.h"
real*8 xmut(npro),xl(npro,nenl,nsd),xmudmi(npro,ngauss)
do i=1,npro
dx=maxval(xl(i,:,1))-minval(xl(i,:,1))
dy=maxval(xl(i,:,2))-minval(xl(i,:,2))
dz=maxval(xl(i,:,3))-minval(xl(i,:,3))
emax=max(dx,max(dy,dz))
if(emax.lt.eles) then ! pure les
xmut(i)=xmudmi(i,intp)
else if(emax.lt.two*eles) then ! blend
xi=(emax-eles)/(eles)
xmut(i)=xi*xmut(i)+(one-xi)*xmudmi(1,intp)
endif ! leave at RANS value as edge is twice pure les
enddo
return
end
| bsd-3-clause |
thomasantony/CarND-Projects | Exercises/Term2/MPC-Quizzes/global_kinematic_model/src/Eigen-3.3/blas/testing/dblat3.f | 133 | 104262 | *> \brief \b DBLAT3
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* PROGRAM DBLAT3
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> Test program for the DOUBLE PRECISION Level 3 Blas.
*>
*> The program must be driven by a short data file. The first 14 records
*> of the file are read using list-directed input, the last 6 records
*> are read using the format ( A6, L2 ). An annotated example of a data
*> file can be obtained by deleting the first 3 characters from the
*> following 20 lines:
*> 'dblat3.out' NAME OF SUMMARY OUTPUT FILE
*> 6 UNIT NUMBER OF SUMMARY FILE
*> 'DBLAT3.SNAP' NAME OF SNAPSHOT OUTPUT FILE
*> -1 UNIT NUMBER OF SNAPSHOT FILE (NOT USED IF .LT. 0)
*> F LOGICAL FLAG, T TO REWIND SNAPSHOT FILE AFTER EACH RECORD.
*> F LOGICAL FLAG, T TO STOP ON FAILURES.
*> T LOGICAL FLAG, T TO TEST ERROR EXITS.
*> 16.0 THRESHOLD VALUE OF TEST RATIO
*> 6 NUMBER OF VALUES OF N
*> 0 1 2 3 5 9 VALUES OF N
*> 3 NUMBER OF VALUES OF ALPHA
*> 0.0 1.0 0.7 VALUES OF ALPHA
*> 3 NUMBER OF VALUES OF BETA
*> 0.0 1.0 1.3 VALUES OF BETA
*> DGEMM T PUT F FOR NO TEST. SAME COLUMNS.
*> DSYMM T PUT F FOR NO TEST. SAME COLUMNS.
*> DTRMM T PUT F FOR NO TEST. SAME COLUMNS.
*> DTRSM T PUT F FOR NO TEST. SAME COLUMNS.
*> DSYRK T PUT F FOR NO TEST. SAME COLUMNS.
*> DSYR2K T PUT F FOR NO TEST. SAME COLUMNS.
*>
*> Further Details
*> ===============
*>
*> See:
*>
*> Dongarra J. J., Du Croz J. J., Duff I. S. and Hammarling S.
*> A Set of Level 3 Basic Linear Algebra Subprograms.
*>
*> Technical Memorandum No.88 (Revision 1), Mathematics and
*> Computer Science Division, Argonne National Laboratory, 9700
*> South Cass Avenue, Argonne, Illinois 60439, US.
*>
*> -- Written on 8-February-1989.
*> Jack Dongarra, Argonne National Laboratory.
*> Iain Duff, AERE Harwell.
*> Jeremy Du Croz, Numerical Algorithms Group Ltd.
*> Sven Hammarling, Numerical Algorithms Group Ltd.
*>
*> 10-9-00: Change STATUS='NEW' to 'UNKNOWN' so that the testers
*> can be run multiple times without deleting generated
*> output files (susan)
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date April 2012
*
*> \ingroup double_blas_testing
*
* =====================================================================
PROGRAM DBLAT3
*
* -- Reference BLAS test routine (version 3.4.1) --
* -- Reference BLAS is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* April 2012
*
* =====================================================================
*
* .. Parameters ..
INTEGER NIN
PARAMETER ( NIN = 5 )
INTEGER NSUBS
PARAMETER ( NSUBS = 6 )
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
INTEGER NMAX
PARAMETER ( NMAX = 65 )
INTEGER NIDMAX, NALMAX, NBEMAX
PARAMETER ( NIDMAX = 9, NALMAX = 7, NBEMAX = 7 )
* .. Local Scalars ..
DOUBLE PRECISION EPS, ERR, THRESH
INTEGER I, ISNUM, J, N, NALF, NBET, NIDIM, NOUT, NTRA
LOGICAL FATAL, LTESTT, REWI, SAME, SFATAL, TRACE,
$ TSTERR
CHARACTER*1 TRANSA, TRANSB
CHARACTER*6 SNAMET
CHARACTER*32 SNAPS, SUMMRY
* .. Local Arrays ..
DOUBLE PRECISION AA( NMAX*NMAX ), AB( NMAX, 2*NMAX ),
$ ALF( NALMAX ), AS( NMAX*NMAX ),
$ BB( NMAX*NMAX ), BET( NBEMAX ),
$ BS( NMAX*NMAX ), C( NMAX, NMAX ),
$ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ),
$ G( NMAX ), W( 2*NMAX )
INTEGER IDIM( NIDMAX )
LOGICAL LTEST( NSUBS )
CHARACTER*6 SNAMES( NSUBS )
* .. External Functions ..
DOUBLE PRECISION DDIFF
LOGICAL LDE
EXTERNAL DDIFF, LDE
* .. External Subroutines ..
EXTERNAL DCHK1, DCHK2, DCHK3, DCHK4, DCHK5, DCHKE, DMMCH
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
COMMON /SRNAMC/SRNAMT
* .. Data statements ..
DATA SNAMES/'DGEMM ', 'DSYMM ', 'DTRMM ', 'DTRSM ',
$ 'DSYRK ', 'DSYR2K'/
* .. Executable Statements ..
*
* Read name and unit number for summary output file and open file.
*
READ( NIN, FMT = * )SUMMRY
READ( NIN, FMT = * )NOUT
OPEN( NOUT, FILE = SUMMRY, STATUS = 'UNKNOWN' )
NOUTC = NOUT
*
* Read name and unit number for snapshot output file and open file.
*
READ( NIN, FMT = * )SNAPS
READ( NIN, FMT = * )NTRA
TRACE = NTRA.GE.0
IF( TRACE )THEN
OPEN( NTRA, FILE = SNAPS, STATUS = 'UNKNOWN' )
END IF
* Read the flag that directs rewinding of the snapshot file.
READ( NIN, FMT = * )REWI
REWI = REWI.AND.TRACE
* Read the flag that directs stopping on any failure.
READ( NIN, FMT = * )SFATAL
* Read the flag that indicates whether error exits are to be tested.
READ( NIN, FMT = * )TSTERR
* Read the threshold value of the test ratio
READ( NIN, FMT = * )THRESH
*
* Read and check the parameter values for the tests.
*
* Values of N
READ( NIN, FMT = * )NIDIM
IF( NIDIM.LT.1.OR.NIDIM.GT.NIDMAX )THEN
WRITE( NOUT, FMT = 9997 )'N', NIDMAX
GO TO 220
END IF
READ( NIN, FMT = * )( IDIM( I ), I = 1, NIDIM )
DO 10 I = 1, NIDIM
IF( IDIM( I ).LT.0.OR.IDIM( I ).GT.NMAX )THEN
WRITE( NOUT, FMT = 9996 )NMAX
GO TO 220
END IF
10 CONTINUE
* Values of ALPHA
READ( NIN, FMT = * )NALF
IF( NALF.LT.1.OR.NALF.GT.NALMAX )THEN
WRITE( NOUT, FMT = 9997 )'ALPHA', NALMAX
GO TO 220
END IF
READ( NIN, FMT = * )( ALF( I ), I = 1, NALF )
* Values of BETA
READ( NIN, FMT = * )NBET
IF( NBET.LT.1.OR.NBET.GT.NBEMAX )THEN
WRITE( NOUT, FMT = 9997 )'BETA', NBEMAX
GO TO 220
END IF
READ( NIN, FMT = * )( BET( I ), I = 1, NBET )
*
* Report values of parameters.
*
WRITE( NOUT, FMT = 9995 )
WRITE( NOUT, FMT = 9994 )( IDIM( I ), I = 1, NIDIM )
WRITE( NOUT, FMT = 9993 )( ALF( I ), I = 1, NALF )
WRITE( NOUT, FMT = 9992 )( BET( I ), I = 1, NBET )
IF( .NOT.TSTERR )THEN
WRITE( NOUT, FMT = * )
WRITE( NOUT, FMT = 9984 )
END IF
WRITE( NOUT, FMT = * )
WRITE( NOUT, FMT = 9999 )THRESH
WRITE( NOUT, FMT = * )
*
* Read names of subroutines and flags which indicate
* whether they are to be tested.
*
DO 20 I = 1, NSUBS
LTEST( I ) = .FALSE.
20 CONTINUE
30 READ( NIN, FMT = 9988, END = 60 )SNAMET, LTESTT
DO 40 I = 1, NSUBS
IF( SNAMET.EQ.SNAMES( I ) )
$ GO TO 50
40 CONTINUE
WRITE( NOUT, FMT = 9990 )SNAMET
STOP
50 LTEST( I ) = LTESTT
GO TO 30
*
60 CONTINUE
CLOSE ( NIN )
*
* Compute EPS (the machine precision).
*
EPS = EPSILON(ZERO)
WRITE( NOUT, FMT = 9998 )EPS
*
* Check the reliability of DMMCH using exact data.
*
N = MIN( 32, NMAX )
DO 100 J = 1, N
DO 90 I = 1, N
AB( I, J ) = MAX( I - J + 1, 0 )
90 CONTINUE
AB( J, NMAX + 1 ) = J
AB( 1, NMAX + J ) = J
C( J, 1 ) = ZERO
100 CONTINUE
DO 110 J = 1, N
CC( J ) = J*( ( J + 1 )*J )/2 - ( ( J + 1 )*J*( J - 1 ) )/3
110 CONTINUE
* CC holds the exact result. On exit from DMMCH CT holds
* the result computed by DMMCH.
TRANSA = 'N'
TRANSB = 'N'
CALL DMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LDE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
TRANSB = 'T'
CALL DMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LDE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
DO 120 J = 1, N
AB( J, NMAX + 1 ) = N - J + 1
AB( 1, NMAX + J ) = N - J + 1
120 CONTINUE
DO 130 J = 1, N
CC( N - J + 1 ) = J*( ( J + 1 )*J )/2 -
$ ( ( J + 1 )*J*( J - 1 ) )/3
130 CONTINUE
TRANSA = 'T'
TRANSB = 'N'
CALL DMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LDE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
TRANSB = 'T'
CALL DMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LDE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
*
* Test each subroutine in turn.
*
DO 200 ISNUM = 1, NSUBS
WRITE( NOUT, FMT = * )
IF( .NOT.LTEST( ISNUM ) )THEN
* Subprogram is not to be tested.
WRITE( NOUT, FMT = 9987 )SNAMES( ISNUM )
ELSE
SRNAMT = SNAMES( ISNUM )
* Test error exits.
IF( TSTERR )THEN
CALL DCHKE( ISNUM, SNAMES( ISNUM ), NOUT )
WRITE( NOUT, FMT = * )
END IF
* Test computations.
INFOT = 0
OK = .TRUE.
FATAL = .FALSE.
GO TO ( 140, 150, 160, 160, 170, 180 )ISNUM
* Test DGEMM, 01.
140 CALL DCHK1( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test DSYMM, 02.
150 CALL DCHK2( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test DTRMM, 03, DTRSM, 04.
160 CALL DCHK3( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NMAX, AB,
$ AA, AS, AB( 1, NMAX + 1 ), BB, BS, CT, G, C )
GO TO 190
* Test DSYRK, 05.
170 CALL DCHK4( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test DSYR2K, 06.
180 CALL DCHK5( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, BB, BS, C, CC, CS, CT, G, W )
GO TO 190
*
190 IF( FATAL.AND.SFATAL )
$ GO TO 210
END IF
200 CONTINUE
WRITE( NOUT, FMT = 9986 )
GO TO 230
*
210 CONTINUE
WRITE( NOUT, FMT = 9985 )
GO TO 230
*
220 CONTINUE
WRITE( NOUT, FMT = 9991 )
*
230 CONTINUE
IF( TRACE )
$ CLOSE ( NTRA )
CLOSE ( NOUT )
STOP
*
9999 FORMAT( ' ROUTINES PASS COMPUTATIONAL TESTS IF TEST RATIO IS LES',
$ 'S THAN', F8.2 )
9998 FORMAT( ' RELATIVE MACHINE PRECISION IS TAKEN TO BE', 1P, D9.1 )
9997 FORMAT( ' NUMBER OF VALUES OF ', A, ' IS LESS THAN 1 OR GREATER ',
$ 'THAN ', I2 )
9996 FORMAT( ' VALUE OF N IS LESS THAN 0 OR GREATER THAN ', I2 )
9995 FORMAT( ' TESTS OF THE DOUBLE PRECISION LEVEL 3 BLAS', //' THE F',
$ 'OLLOWING PARAMETER VALUES WILL BE USED:' )
9994 FORMAT( ' FOR N ', 9I6 )
9993 FORMAT( ' FOR ALPHA ', 7F6.1 )
9992 FORMAT( ' FOR BETA ', 7F6.1 )
9991 FORMAT( ' AMEND DATA FILE OR INCREASE ARRAY SIZES IN PROGRAM',
$ /' ******* TESTS ABANDONED *******' )
9990 FORMAT( ' SUBPROGRAM NAME ', A6, ' NOT RECOGNIZED', /' ******* T',
$ 'ESTS ABANDONED *******' )
9989 FORMAT( ' ERROR IN DMMCH - IN-LINE DOT PRODUCTS ARE BEING EVALU',
$ 'ATED WRONGLY.', /' DMMCH WAS CALLED WITH TRANSA = ', A1,
$ ' AND TRANSB = ', A1, /' AND RETURNED SAME = ', L1, ' AND ',
$ 'ERR = ', F12.3, '.', /' THIS MAY BE DUE TO FAULTS IN THE ',
$ 'ARITHMETIC OR THE COMPILER.', /' ******* TESTS ABANDONED ',
$ '*******' )
9988 FORMAT( A6, L2 )
9987 FORMAT( 1X, A6, ' WAS NOT TESTED' )
9986 FORMAT( /' END OF TESTS' )
9985 FORMAT( /' ******* FATAL ERROR - TESTS ABANDONED *******' )
9984 FORMAT( ' ERROR-EXITS WILL NOT BE TESTED' )
*
* End of DBLAT3.
*
END
SUBROUTINE DCHK1( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests DGEMM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D0 )
* .. Scalar Arguments ..
DOUBLE PRECISION EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
DOUBLE PRECISION A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
DOUBLE PRECISION ALPHA, ALS, BETA, BLS, ERR, ERRMAX
INTEGER I, IA, IB, ICA, ICB, IK, IM, IN, K, KS, LAA,
$ LBB, LCC, LDA, LDAS, LDB, LDBS, LDC, LDCS, M,
$ MA, MB, MS, N, NA, NARGS, NB, NC, NS
LOGICAL NULL, RESET, SAME, TRANA, TRANB
CHARACTER*1 TRANAS, TRANBS, TRANSA, TRANSB
CHARACTER*3 ICH
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LDE, LDERES
EXTERNAL LDE, LDERES
* .. External Subroutines ..
EXTERNAL DGEMM, DMAKE, DMMCH
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICH/'NTC'/
* .. Executable Statements ..
*
NARGS = 13
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 110 IM = 1, NIDIM
M = IDIM( IM )
*
DO 100 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = M
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 100
LCC = LDC*N
NULL = N.LE.0.OR.M.LE.0
*
DO 90 IK = 1, NIDIM
K = IDIM( IK )
*
DO 80 ICA = 1, 3
TRANSA = ICH( ICA: ICA )
TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C'
*
IF( TRANA )THEN
MA = K
NA = M
ELSE
MA = M
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
* Generate the matrix A.
*
CALL DMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 70 ICB = 1, 3
TRANSB = ICH( ICB: ICB )
TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C'
*
IF( TRANB )THEN
MB = N
NB = K
ELSE
MB = K
NB = N
END IF
* Set LDB to 1 more than minimum value if room.
LDB = MB
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 70
LBB = LDB*NB
*
* Generate the matrix B.
*
CALL DMAKE( 'GE', ' ', ' ', MB, NB, B, NMAX, BB,
$ LDB, RESET, ZERO )
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL DMAKE( 'GE', ' ', ' ', M, N, C, NMAX,
$ CC, LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
TRANAS = TRANSA
TRANBS = TRANSB
MS = M
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BLS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ TRANSA, TRANSB, M, N, K, ALPHA, LDA, LDB,
$ BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL DGEMM( TRANSA, TRANSB, M, N, K, ALPHA,
$ AA, LDA, BB, LDB, BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 120
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = TRANSA.EQ.TRANAS
ISAME( 2 ) = TRANSB.EQ.TRANBS
ISAME( 3 ) = MS.EQ.M
ISAME( 4 ) = NS.EQ.N
ISAME( 5 ) = KS.EQ.K
ISAME( 6 ) = ALS.EQ.ALPHA
ISAME( 7 ) = LDE( AS, AA, LAA )
ISAME( 8 ) = LDAS.EQ.LDA
ISAME( 9 ) = LDE( BS, BB, LBB )
ISAME( 10 ) = LDBS.EQ.LDB
ISAME( 11 ) = BLS.EQ.BETA
IF( NULL )THEN
ISAME( 12 ) = LDE( CS, CC, LCC )
ELSE
ISAME( 12 ) = LDERES( 'GE', ' ', M, N, CS,
$ CC, LDC )
END IF
ISAME( 13 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report
* and return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 120
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result.
*
CALL DMMCH( TRANSA, TRANSB, M, N, K,
$ ALPHA, A, NMAX, B, NMAX, BETA,
$ C, NMAX, CT, G, CC, LDC, EPS,
$ ERR, FATAL, NOUT, .TRUE. )
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 120
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 130
*
120 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, TRANSA, TRANSB, M, N, K,
$ ALPHA, LDA, LDB, BETA, LDC
*
130 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(''', A1, ''',''', A1, ''',',
$ 3( I3, ',' ), F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', ',
$ 'C,', I3, ').' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of DCHK1.
*
END
SUBROUTINE DCHK2( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests DSYMM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D0 )
* .. Scalar Arguments ..
DOUBLE PRECISION EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
DOUBLE PRECISION A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
DOUBLE PRECISION ALPHA, ALS, BETA, BLS, ERR, ERRMAX
INTEGER I, IA, IB, ICS, ICU, IM, IN, LAA, LBB, LCC,
$ LDA, LDAS, LDB, LDBS, LDC, LDCS, M, MS, N, NA,
$ NARGS, NC, NS
LOGICAL LEFT, NULL, RESET, SAME
CHARACTER*1 SIDE, SIDES, UPLO, UPLOS
CHARACTER*2 ICHS, ICHU
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LDE, LDERES
EXTERNAL LDE, LDERES
* .. External Subroutines ..
EXTERNAL DMAKE, DMMCH, DSYMM
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHS/'LR'/, ICHU/'UL'/
* .. Executable Statements ..
*
NARGS = 12
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 100 IM = 1, NIDIM
M = IDIM( IM )
*
DO 90 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = M
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 90
LCC = LDC*N
NULL = N.LE.0.OR.M.LE.0
*
* Set LDB to 1 more than minimum value if room.
LDB = M
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 90
LBB = LDB*N
*
* Generate the matrix B.
*
CALL DMAKE( 'GE', ' ', ' ', M, N, B, NMAX, BB, LDB, RESET,
$ ZERO )
*
DO 80 ICS = 1, 2
SIDE = ICHS( ICS: ICS )
LEFT = SIDE.EQ.'L'
*
IF( LEFT )THEN
NA = M
ELSE
NA = N
END IF
* Set LDA to 1 more than minimum value if room.
LDA = NA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
DO 70 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
*
* Generate the symmetric matrix A.
*
CALL DMAKE( 'SY', UPLO, ' ', NA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL DMAKE( 'GE', ' ', ' ', M, N, C, NMAX, CC,
$ LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
SIDES = SIDE
UPLOS = UPLO
MS = M
NS = N
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BLS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME, SIDE,
$ UPLO, M, N, ALPHA, LDA, LDB, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL DSYMM( SIDE, UPLO, M, N, ALPHA, AA, LDA,
$ BB, LDB, BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 110
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = SIDES.EQ.SIDE
ISAME( 2 ) = UPLOS.EQ.UPLO
ISAME( 3 ) = MS.EQ.M
ISAME( 4 ) = NS.EQ.N
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LDE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = LDE( BS, BB, LBB )
ISAME( 9 ) = LDBS.EQ.LDB
ISAME( 10 ) = BLS.EQ.BETA
IF( NULL )THEN
ISAME( 11 ) = LDE( CS, CC, LCC )
ELSE
ISAME( 11 ) = LDERES( 'GE', ' ', M, N, CS,
$ CC, LDC )
END IF
ISAME( 12 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 110
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result.
*
IF( LEFT )THEN
CALL DMMCH( 'N', 'N', M, N, M, ALPHA, A,
$ NMAX, B, NMAX, BETA, C, NMAX,
$ CT, G, CC, LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL DMMCH( 'N', 'N', M, N, N, ALPHA, B,
$ NMAX, A, NMAX, BETA, C, NMAX,
$ CT, G, CC, LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 110
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 120
*
110 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, M, N, ALPHA, LDA,
$ LDB, BETA, LDC
*
120 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', C,', I3, ') ',
$ ' .' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of DCHK2.
*
END
SUBROUTINE DCHK3( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NMAX, A, AA, AS,
$ B, BB, BS, CT, G, C )
*
* Tests DTRMM and DTRSM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
* .. Scalar Arguments ..
DOUBLE PRECISION EPS, THRESH
INTEGER NALF, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
DOUBLE PRECISION A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
DOUBLE PRECISION ALPHA, ALS, ERR, ERRMAX
INTEGER I, IA, ICD, ICS, ICT, ICU, IM, IN, J, LAA, LBB,
$ LDA, LDAS, LDB, LDBS, M, MS, N, NA, NARGS, NC,
$ NS
LOGICAL LEFT, NULL, RESET, SAME
CHARACTER*1 DIAG, DIAGS, SIDE, SIDES, TRANAS, TRANSA, UPLO,
$ UPLOS
CHARACTER*2 ICHD, ICHS, ICHU
CHARACTER*3 ICHT
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LDE, LDERES
EXTERNAL LDE, LDERES
* .. External Subroutines ..
EXTERNAL DMAKE, DMMCH, DTRMM, DTRSM
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHU/'UL'/, ICHT/'NTC'/, ICHD/'UN'/, ICHS/'LR'/
* .. Executable Statements ..
*
NARGS = 11
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
* Set up zero matrix for DMMCH.
DO 20 J = 1, NMAX
DO 10 I = 1, NMAX
C( I, J ) = ZERO
10 CONTINUE
20 CONTINUE
*
DO 140 IM = 1, NIDIM
M = IDIM( IM )
*
DO 130 IN = 1, NIDIM
N = IDIM( IN )
* Set LDB to 1 more than minimum value if room.
LDB = M
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 130
LBB = LDB*N
NULL = M.LE.0.OR.N.LE.0
*
DO 120 ICS = 1, 2
SIDE = ICHS( ICS: ICS )
LEFT = SIDE.EQ.'L'
IF( LEFT )THEN
NA = M
ELSE
NA = N
END IF
* Set LDA to 1 more than minimum value if room.
LDA = NA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 130
LAA = LDA*NA
*
DO 110 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
*
DO 100 ICT = 1, 3
TRANSA = ICHT( ICT: ICT )
*
DO 90 ICD = 1, 2
DIAG = ICHD( ICD: ICD )
*
DO 80 IA = 1, NALF
ALPHA = ALF( IA )
*
* Generate the matrix A.
*
CALL DMAKE( 'TR', UPLO, DIAG, NA, NA, A,
$ NMAX, AA, LDA, RESET, ZERO )
*
* Generate the matrix B.
*
CALL DMAKE( 'GE', ' ', ' ', M, N, B, NMAX,
$ BB, LDB, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
SIDES = SIDE
UPLOS = UPLO
TRANAS = TRANSA
DIAGS = DIAG
MS = M
NS = N
ALS = ALPHA
DO 30 I = 1, LAA
AS( I ) = AA( I )
30 CONTINUE
LDAS = LDA
DO 40 I = 1, LBB
BS( I ) = BB( I )
40 CONTINUE
LDBS = LDB
*
* Call the subroutine.
*
IF( SNAME( 4: 5 ).EQ.'MM' )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA,
$ LDA, LDB
IF( REWI )
$ REWIND NTRA
CALL DTRMM( SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, AA, LDA, BB, LDB )
ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA,
$ LDA, LDB
IF( REWI )
$ REWIND NTRA
CALL DTRSM( SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, AA, LDA, BB, LDB )
END IF
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 150
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = SIDES.EQ.SIDE
ISAME( 2 ) = UPLOS.EQ.UPLO
ISAME( 3 ) = TRANAS.EQ.TRANSA
ISAME( 4 ) = DIAGS.EQ.DIAG
ISAME( 5 ) = MS.EQ.M
ISAME( 6 ) = NS.EQ.N
ISAME( 7 ) = ALS.EQ.ALPHA
ISAME( 8 ) = LDE( AS, AA, LAA )
ISAME( 9 ) = LDAS.EQ.LDA
IF( NULL )THEN
ISAME( 10 ) = LDE( BS, BB, LBB )
ELSE
ISAME( 10 ) = LDERES( 'GE', ' ', M, N, BS,
$ BB, LDB )
END IF
ISAME( 11 ) = LDBS.EQ.LDB
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 50 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
50 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 150
END IF
*
IF( .NOT.NULL )THEN
IF( SNAME( 4: 5 ).EQ.'MM' )THEN
*
* Check the result.
*
IF( LEFT )THEN
CALL DMMCH( TRANSA, 'N', M, N, M,
$ ALPHA, A, NMAX, B, NMAX,
$ ZERO, C, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL DMMCH( 'N', TRANSA, M, N, N,
$ ALPHA, B, NMAX, A, NMAX,
$ ZERO, C, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN
*
* Compute approximation to original
* matrix.
*
DO 70 J = 1, N
DO 60 I = 1, M
C( I, J ) = BB( I + ( J - 1 )*
$ LDB )
BB( I + ( J - 1 )*LDB ) = ALPHA*
$ B( I, J )
60 CONTINUE
70 CONTINUE
*
IF( LEFT )THEN
CALL DMMCH( TRANSA, 'N', M, N, M,
$ ONE, A, NMAX, C, NMAX,
$ ZERO, B, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .FALSE. )
ELSE
CALL DMMCH( 'N', TRANSA, M, N, N,
$ ONE, C, NMAX, A, NMAX,
$ ZERO, B, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .FALSE. )
END IF
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 150
END IF
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
120 CONTINUE
*
130 CONTINUE
*
140 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 160
*
150 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, LDA, LDB
*
160 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(', 4( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ', B,', I3, ') .' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of DCHK3.
*
END
SUBROUTINE DCHK4( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests DSYRK.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D0 )
* .. Scalar Arguments ..
DOUBLE PRECISION EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
DOUBLE PRECISION A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
DOUBLE PRECISION ALPHA, ALS, BETA, BETS, ERR, ERRMAX
INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, K, KS,
$ LAA, LCC, LDA, LDAS, LDC, LDCS, LJ, MA, N, NA,
$ NARGS, NC, NS
LOGICAL NULL, RESET, SAME, TRAN, UPPER
CHARACTER*1 TRANS, TRANSS, UPLO, UPLOS
CHARACTER*2 ICHU
CHARACTER*3 ICHT
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LDE, LDERES
EXTERNAL LDE, LDERES
* .. External Subroutines ..
EXTERNAL DMAKE, DMMCH, DSYRK
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHT/'NTC'/, ICHU/'UL'/
* .. Executable Statements ..
*
NARGS = 10
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 100 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = N
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 100
LCC = LDC*N
NULL = N.LE.0
*
DO 90 IK = 1, NIDIM
K = IDIM( IK )
*
DO 80 ICT = 1, 3
TRANS = ICHT( ICT: ICT )
TRAN = TRANS.EQ.'T'.OR.TRANS.EQ.'C'
IF( TRAN )THEN
MA = K
NA = N
ELSE
MA = N
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
* Generate the matrix A.
*
CALL DMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 70 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
UPPER = UPLO.EQ.'U'
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL DMAKE( 'SY', UPLO, ' ', N, N, C, NMAX, CC,
$ LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the subroutine.
*
UPLOS = UPLO
TRANSS = TRANS
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
BETS = BETA
DO 20 I = 1, LCC
CS( I ) = CC( I )
20 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO,
$ TRANS, N, K, ALPHA, LDA, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL DSYRK( UPLO, TRANS, N, K, ALPHA, AA, LDA,
$ BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9993 )
FATAL = .TRUE.
GO TO 120
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = UPLOS.EQ.UPLO
ISAME( 2 ) = TRANSS.EQ.TRANS
ISAME( 3 ) = NS.EQ.N
ISAME( 4 ) = KS.EQ.K
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LDE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = BETS.EQ.BETA
IF( NULL )THEN
ISAME( 9 ) = LDE( CS, CC, LCC )
ELSE
ISAME( 9 ) = LDERES( 'SY', UPLO, N, N, CS,
$ CC, LDC )
END IF
ISAME( 10 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 30 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
30 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 120
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result column by column.
*
JC = 1
DO 40 J = 1, N
IF( UPPER )THEN
JJ = 1
LJ = J
ELSE
JJ = J
LJ = N - J + 1
END IF
IF( TRAN )THEN
CALL DMMCH( 'T', 'N', LJ, 1, K, ALPHA,
$ A( 1, JJ ), NMAX,
$ A( 1, J ), NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL DMMCH( 'N', 'T', LJ, 1, K, ALPHA,
$ A( JJ, 1 ), NMAX,
$ A( J, 1 ), NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
IF( UPPER )THEN
JC = JC + LDC
ELSE
JC = JC + LDC + 1
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 110
40 CONTINUE
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 130
*
110 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9995 )J
*
120 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, ALPHA,
$ LDA, BETA, LDC
*
130 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ',', F4.1, ', C,', I3, ') .' )
9993 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of DCHK4.
*
END
SUBROUTINE DCHK5( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ AB, AA, AS, BB, BS, C, CC, CS, CT, G, W )
*
* Tests DSYR2K.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D0 )
* .. Scalar Arguments ..
DOUBLE PRECISION EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
DOUBLE PRECISION AA( NMAX*NMAX ), AB( 2*NMAX*NMAX ),
$ ALF( NALF ), AS( NMAX*NMAX ), BB( NMAX*NMAX ),
$ BET( NBET ), BS( NMAX*NMAX ), C( NMAX, NMAX ),
$ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ),
$ G( NMAX ), W( 2*NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
DOUBLE PRECISION ALPHA, ALS, BETA, BETS, ERR, ERRMAX
INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, JJAB,
$ K, KS, LAA, LBB, LCC, LDA, LDAS, LDB, LDBS,
$ LDC, LDCS, LJ, MA, N, NA, NARGS, NC, NS
LOGICAL NULL, RESET, SAME, TRAN, UPPER
CHARACTER*1 TRANS, TRANSS, UPLO, UPLOS
CHARACTER*2 ICHU
CHARACTER*3 ICHT
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LDE, LDERES
EXTERNAL LDE, LDERES
* .. External Subroutines ..
EXTERNAL DMAKE, DMMCH, DSYR2K
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHT/'NTC'/, ICHU/'UL'/
* .. Executable Statements ..
*
NARGS = 12
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 130 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = N
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 130
LCC = LDC*N
NULL = N.LE.0
*
DO 120 IK = 1, NIDIM
K = IDIM( IK )
*
DO 110 ICT = 1, 3
TRANS = ICHT( ICT: ICT )
TRAN = TRANS.EQ.'T'.OR.TRANS.EQ.'C'
IF( TRAN )THEN
MA = K
NA = N
ELSE
MA = N
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 110
LAA = LDA*NA
*
* Generate the matrix A.
*
IF( TRAN )THEN
CALL DMAKE( 'GE', ' ', ' ', MA, NA, AB, 2*NMAX, AA,
$ LDA, RESET, ZERO )
ELSE
CALL DMAKE( 'GE', ' ', ' ', MA, NA, AB, NMAX, AA, LDA,
$ RESET, ZERO )
END IF
*
* Generate the matrix B.
*
LDB = LDA
LBB = LAA
IF( TRAN )THEN
CALL DMAKE( 'GE', ' ', ' ', MA, NA, AB( K + 1 ),
$ 2*NMAX, BB, LDB, RESET, ZERO )
ELSE
CALL DMAKE( 'GE', ' ', ' ', MA, NA, AB( K*NMAX + 1 ),
$ NMAX, BB, LDB, RESET, ZERO )
END IF
*
DO 100 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
UPPER = UPLO.EQ.'U'
*
DO 90 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 80 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL DMAKE( 'SY', UPLO, ' ', N, N, C, NMAX, CC,
$ LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the subroutine.
*
UPLOS = UPLO
TRANSS = TRANS
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BETS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO,
$ TRANS, N, K, ALPHA, LDA, LDB, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL DSYR2K( UPLO, TRANS, N, K, ALPHA, AA, LDA,
$ BB, LDB, BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9993 )
FATAL = .TRUE.
GO TO 150
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = UPLOS.EQ.UPLO
ISAME( 2 ) = TRANSS.EQ.TRANS
ISAME( 3 ) = NS.EQ.N
ISAME( 4 ) = KS.EQ.K
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LDE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = LDE( BS, BB, LBB )
ISAME( 9 ) = LDBS.EQ.LDB
ISAME( 10 ) = BETS.EQ.BETA
IF( NULL )THEN
ISAME( 11 ) = LDE( CS, CC, LCC )
ELSE
ISAME( 11 ) = LDERES( 'SY', UPLO, N, N, CS,
$ CC, LDC )
END IF
ISAME( 12 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 150
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result column by column.
*
JJAB = 1
JC = 1
DO 70 J = 1, N
IF( UPPER )THEN
JJ = 1
LJ = J
ELSE
JJ = J
LJ = N - J + 1
END IF
IF( TRAN )THEN
DO 50 I = 1, K
W( I ) = AB( ( J - 1 )*2*NMAX + K +
$ I )
W( K + I ) = AB( ( J - 1 )*2*NMAX +
$ I )
50 CONTINUE
CALL DMMCH( 'T', 'N', LJ, 1, 2*K,
$ ALPHA, AB( JJAB ), 2*NMAX,
$ W, 2*NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
DO 60 I = 1, K
W( I ) = AB( ( K + I - 1 )*NMAX +
$ J )
W( K + I ) = AB( ( I - 1 )*NMAX +
$ J )
60 CONTINUE
CALL DMMCH( 'N', 'N', LJ, 1, 2*K,
$ ALPHA, AB( JJ ), NMAX, W,
$ 2*NMAX, BETA, C( JJ, J ),
$ NMAX, CT, G, CC( JC ), LDC,
$ EPS, ERR, FATAL, NOUT,
$ .TRUE. )
END IF
IF( UPPER )THEN
JC = JC + LDC
ELSE
JC = JC + LDC + 1
IF( TRAN )
$ JJAB = JJAB + 2*NMAX
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 140
70 CONTINUE
END IF
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
120 CONTINUE
*
130 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 160
*
140 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9995 )J
*
150 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, ALPHA,
$ LDA, LDB, BETA, LDC
*
160 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', C,', I3, ') ',
$ ' .' )
9993 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of DCHK5.
*
END
SUBROUTINE DCHKE( ISNUM, SRNAMT, NOUT )
*
* Tests the error exits from the Level 3 Blas.
* Requires a special version of the error-handling routine XERBLA.
* A, B and C should not need to be defined.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* 3-19-92: Initialize ALPHA and BETA (eca)
* 3-19-92: Fix argument 12 in calls to SSYMM with INFOT = 9 (eca)
*
* .. Scalar Arguments ..
INTEGER ISNUM, NOUT
CHARACTER*6 SRNAMT
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Parameters ..
DOUBLE PRECISION ONE, TWO
PARAMETER ( ONE = 1.0D0, TWO = 2.0D0 )
* .. Local Scalars ..
DOUBLE PRECISION ALPHA, BETA
* .. Local Arrays ..
DOUBLE PRECISION A( 2, 1 ), B( 2, 1 ), C( 2, 1 )
* .. External Subroutines ..
EXTERNAL CHKXER, DGEMM, DSYMM, DSYR2K, DSYRK, DTRMM,
$ DTRSM
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Executable Statements ..
* OK is set to .FALSE. by the special version of XERBLA or by CHKXER
* if anything is wrong.
OK = .TRUE.
* LERR is set to .TRUE. by the special version of XERBLA each time
* it is called, and is then tested and re-set by CHKXER.
LERR = .FALSE.
*
* Initialize ALPHA and BETA.
*
ALPHA = ONE
BETA = TWO
*
GO TO ( 10, 20, 30, 40, 50, 60 )ISNUM
10 INFOT = 1
CALL DGEMM( '/', 'N', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 1
CALL DGEMM( '/', 'T', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL DGEMM( 'N', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL DGEMM( 'T', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DGEMM( 'N', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DGEMM( 'N', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DGEMM( 'T', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DGEMM( 'T', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DGEMM( 'N', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DGEMM( 'N', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DGEMM( 'T', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DGEMM( 'T', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DGEMM( 'N', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DGEMM( 'N', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DGEMM( 'T', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DGEMM( 'T', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL DGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL DGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL DGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL DGEMM( 'T', 'T', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DGEMM( 'N', 'N', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DGEMM( 'N', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DGEMM( 'T', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL DGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL DGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL DGEMM( 'T', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL DGEMM( 'T', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
20 INFOT = 1
CALL DSYMM( '/', 'U', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL DSYMM( 'L', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYMM( 'L', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYMM( 'R', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYMM( 'L', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYMM( 'R', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYMM( 'L', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYMM( 'R', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYMM( 'L', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYMM( 'R', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYMM( 'L', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYMM( 'R', 'U', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYMM( 'L', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYMM( 'R', 'L', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
30 INFOT = 1
CALL DTRMM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL DTRMM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DTRMM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DTRMM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRMM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRMM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRMM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRMM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
40 INFOT = 1
CALL DTRSM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL DTRSM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DTRSM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DTRSM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL DTRSM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL DTRSM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DTRSM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL DTRSM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
50 INFOT = 1
CALL DSYRK( '/', 'N', 0, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL DSYRK( 'U', '/', 0, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYRK( 'U', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYRK( 'U', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYRK( 'L', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYRK( 'L', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYRK( 'U', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYRK( 'U', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYRK( 'L', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYRK( 'L', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYRK( 'U', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYRK( 'U', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYRK( 'L', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYRK( 'L', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DSYRK( 'U', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DSYRK( 'U', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DSYRK( 'L', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL DSYRK( 'L', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
60 INFOT = 1
CALL DSYR2K( '/', 'N', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL DSYR2K( 'U', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYR2K( 'U', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYR2K( 'U', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYR2K( 'L', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL DSYR2K( 'L', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYR2K( 'U', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYR2K( 'U', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYR2K( 'L', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL DSYR2K( 'L', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYR2K( 'U', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYR2K( 'U', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYR2K( 'L', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL DSYR2K( 'L', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYR2K( 'U', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL DSYR2K( 'L', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYR2K( 'U', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL DSYR2K( 'L', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
*
70 IF( OK )THEN
WRITE( NOUT, FMT = 9999 )SRNAMT
ELSE
WRITE( NOUT, FMT = 9998 )SRNAMT
END IF
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE TESTS OF ERROR-EXITS' )
9998 FORMAT( ' ******* ', A6, ' FAILED THE TESTS OF ERROR-EXITS *****',
$ '**' )
*
* End of DCHKE.
*
END
SUBROUTINE DMAKE( TYPE, UPLO, DIAG, M, N, A, NMAX, AA, LDA, RESET,
$ TRANSL )
*
* Generates values for an M by N matrix A.
* Stores the values in the array AA in the data structure required
* by the routine, with unwanted elements set to rogue value.
*
* TYPE is 'GE', 'SY' or 'TR'.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
DOUBLE PRECISION ROGUE
PARAMETER ( ROGUE = -1.0D10 )
* .. Scalar Arguments ..
DOUBLE PRECISION TRANSL
INTEGER LDA, M, N, NMAX
LOGICAL RESET
CHARACTER*1 DIAG, UPLO
CHARACTER*2 TYPE
* .. Array Arguments ..
DOUBLE PRECISION A( NMAX, * ), AA( * )
* .. Local Scalars ..
INTEGER I, IBEG, IEND, J
LOGICAL GEN, LOWER, SYM, TRI, UNIT, UPPER
* .. External Functions ..
DOUBLE PRECISION DBEG
EXTERNAL DBEG
* .. Executable Statements ..
GEN = TYPE.EQ.'GE'
SYM = TYPE.EQ.'SY'
TRI = TYPE.EQ.'TR'
UPPER = ( SYM.OR.TRI ).AND.UPLO.EQ.'U'
LOWER = ( SYM.OR.TRI ).AND.UPLO.EQ.'L'
UNIT = TRI.AND.DIAG.EQ.'U'
*
* Generate data in array A.
*
DO 20 J = 1, N
DO 10 I = 1, M
IF( GEN.OR.( UPPER.AND.I.LE.J ).OR.( LOWER.AND.I.GE.J ) )
$ THEN
A( I, J ) = DBEG( RESET ) + TRANSL
IF( I.NE.J )THEN
* Set some elements to zero
IF( N.GT.3.AND.J.EQ.N/2 )
$ A( I, J ) = ZERO
IF( SYM )THEN
A( J, I ) = A( I, J )
ELSE IF( TRI )THEN
A( J, I ) = ZERO
END IF
END IF
END IF
10 CONTINUE
IF( TRI )
$ A( J, J ) = A( J, J ) + ONE
IF( UNIT )
$ A( J, J ) = ONE
20 CONTINUE
*
* Store elements in array AS in data structure required by routine.
*
IF( TYPE.EQ.'GE' )THEN
DO 50 J = 1, N
DO 30 I = 1, M
AA( I + ( J - 1 )*LDA ) = A( I, J )
30 CONTINUE
DO 40 I = M + 1, LDA
AA( I + ( J - 1 )*LDA ) = ROGUE
40 CONTINUE
50 CONTINUE
ELSE IF( TYPE.EQ.'SY'.OR.TYPE.EQ.'TR' )THEN
DO 90 J = 1, N
IF( UPPER )THEN
IBEG = 1
IF( UNIT )THEN
IEND = J - 1
ELSE
IEND = J
END IF
ELSE
IF( UNIT )THEN
IBEG = J + 1
ELSE
IBEG = J
END IF
IEND = N
END IF
DO 60 I = 1, IBEG - 1
AA( I + ( J - 1 )*LDA ) = ROGUE
60 CONTINUE
DO 70 I = IBEG, IEND
AA( I + ( J - 1 )*LDA ) = A( I, J )
70 CONTINUE
DO 80 I = IEND + 1, LDA
AA( I + ( J - 1 )*LDA ) = ROGUE
80 CONTINUE
90 CONTINUE
END IF
RETURN
*
* End of DMAKE.
*
END
SUBROUTINE DMMCH( TRANSA, TRANSB, M, N, KK, ALPHA, A, LDA, B, LDB,
$ BETA, C, LDC, CT, G, CC, LDCC, EPS, ERR, FATAL,
$ NOUT, MV )
*
* Checks the results of the computational tests.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
* .. Scalar Arguments ..
DOUBLE PRECISION ALPHA, BETA, EPS, ERR
INTEGER KK, LDA, LDB, LDC, LDCC, M, N, NOUT
LOGICAL FATAL, MV
CHARACTER*1 TRANSA, TRANSB
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),
$ CC( LDCC, * ), CT( * ), G( * )
* .. Local Scalars ..
DOUBLE PRECISION ERRI
INTEGER I, J, K
LOGICAL TRANA, TRANB
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, SQRT
* .. Executable Statements ..
TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C'
TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C'
*
* Compute expected result, one column at a time, in CT using data
* in A, B and C.
* Compute gauges in G.
*
DO 120 J = 1, N
*
DO 10 I = 1, M
CT( I ) = ZERO
G( I ) = ZERO
10 CONTINUE
IF( .NOT.TRANA.AND..NOT.TRANB )THEN
DO 30 K = 1, KK
DO 20 I = 1, M
CT( I ) = CT( I ) + A( I, K )*B( K, J )
G( I ) = G( I ) + ABS( A( I, K ) )*ABS( B( K, J ) )
20 CONTINUE
30 CONTINUE
ELSE IF( TRANA.AND..NOT.TRANB )THEN
DO 50 K = 1, KK
DO 40 I = 1, M
CT( I ) = CT( I ) + A( K, I )*B( K, J )
G( I ) = G( I ) + ABS( A( K, I ) )*ABS( B( K, J ) )
40 CONTINUE
50 CONTINUE
ELSE IF( .NOT.TRANA.AND.TRANB )THEN
DO 70 K = 1, KK
DO 60 I = 1, M
CT( I ) = CT( I ) + A( I, K )*B( J, K )
G( I ) = G( I ) + ABS( A( I, K ) )*ABS( B( J, K ) )
60 CONTINUE
70 CONTINUE
ELSE IF( TRANA.AND.TRANB )THEN
DO 90 K = 1, KK
DO 80 I = 1, M
CT( I ) = CT( I ) + A( K, I )*B( J, K )
G( I ) = G( I ) + ABS( A( K, I ) )*ABS( B( J, K ) )
80 CONTINUE
90 CONTINUE
END IF
DO 100 I = 1, M
CT( I ) = ALPHA*CT( I ) + BETA*C( I, J )
G( I ) = ABS( ALPHA )*G( I ) + ABS( BETA )*ABS( C( I, J ) )
100 CONTINUE
*
* Compute the error ratio for this result.
*
ERR = ZERO
DO 110 I = 1, M
ERRI = ABS( CT( I ) - CC( I, J ) )/EPS
IF( G( I ).NE.ZERO )
$ ERRI = ERRI/G( I )
ERR = MAX( ERR, ERRI )
IF( ERR*SQRT( EPS ).GE.ONE )
$ GO TO 130
110 CONTINUE
*
120 CONTINUE
*
* If the loop completes, all results are at least half accurate.
GO TO 150
*
* Report fatal error.
*
130 FATAL = .TRUE.
WRITE( NOUT, FMT = 9999 )
DO 140 I = 1, M
IF( MV )THEN
WRITE( NOUT, FMT = 9998 )I, CT( I ), CC( I, J )
ELSE
WRITE( NOUT, FMT = 9998 )I, CC( I, J ), CT( I )
END IF
140 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9997 )J
*
150 CONTINUE
RETURN
*
9999 FORMAT( ' ******* FATAL ERROR - COMPUTED RESULT IS LESS THAN HAL',
$ 'F ACCURATE *******', /' EXPECTED RESULT COMPU',
$ 'TED RESULT' )
9998 FORMAT( 1X, I7, 2G18.6 )
9997 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
*
* End of DMMCH.
*
END
LOGICAL FUNCTION LDE( RI, RJ, LR )
*
* Tests if two arrays are identical.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER LR
* .. Array Arguments ..
DOUBLE PRECISION RI( * ), RJ( * )
* .. Local Scalars ..
INTEGER I
* .. Executable Statements ..
DO 10 I = 1, LR
IF( RI( I ).NE.RJ( I ) )
$ GO TO 20
10 CONTINUE
LDE = .TRUE.
GO TO 30
20 CONTINUE
LDE = .FALSE.
30 RETURN
*
* End of LDE.
*
END
LOGICAL FUNCTION LDERES( TYPE, UPLO, M, N, AA, AS, LDA )
*
* Tests if selected elements in two arrays are equal.
*
* TYPE is 'GE' or 'SY'.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER LDA, M, N
CHARACTER*1 UPLO
CHARACTER*2 TYPE
* .. Array Arguments ..
DOUBLE PRECISION AA( LDA, * ), AS( LDA, * )
* .. Local Scalars ..
INTEGER I, IBEG, IEND, J
LOGICAL UPPER
* .. Executable Statements ..
UPPER = UPLO.EQ.'U'
IF( TYPE.EQ.'GE' )THEN
DO 20 J = 1, N
DO 10 I = M + 1, LDA
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
10 CONTINUE
20 CONTINUE
ELSE IF( TYPE.EQ.'SY' )THEN
DO 50 J = 1, N
IF( UPPER )THEN
IBEG = 1
IEND = J
ELSE
IBEG = J
IEND = N
END IF
DO 30 I = 1, IBEG - 1
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
30 CONTINUE
DO 40 I = IEND + 1, LDA
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
40 CONTINUE
50 CONTINUE
END IF
*
LDERES = .TRUE.
GO TO 80
70 CONTINUE
LDERES = .FALSE.
80 RETURN
*
* End of LDERES.
*
END
DOUBLE PRECISION FUNCTION DBEG( RESET )
*
* Generates random numbers uniformly distributed between -0.5 and 0.5.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
LOGICAL RESET
* .. Local Scalars ..
INTEGER I, IC, MI
* .. Save statement ..
SAVE I, IC, MI
* .. Executable Statements ..
IF( RESET )THEN
* Initialize local variables.
MI = 891
I = 7
IC = 0
RESET = .FALSE.
END IF
*
* The sequence of values of I is bounded between 1 and 999.
* If initial I = 1,2,3,6,7 or 9, the period will be 50.
* If initial I = 4 or 8, the period will be 25.
* If initial I = 5, the period will be 10.
* IC is used to break up the period by skipping 1 value of I in 6.
*
IC = IC + 1
10 I = I*MI
I = I - 1000*( I/1000 )
IF( IC.GE.5 )THEN
IC = 0
GO TO 10
END IF
DBEG = ( I - 500 )/1001.0D0
RETURN
*
* End of DBEG.
*
END
DOUBLE PRECISION FUNCTION DDIFF( X, Y )
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
DOUBLE PRECISION X, Y
* .. Executable Statements ..
DDIFF = X - Y
RETURN
*
* End of DDIFF.
*
END
SUBROUTINE CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
*
* Tests whether XERBLA has detected an error when it should.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER INFOT, NOUT
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Executable Statements ..
IF( .NOT.LERR )THEN
WRITE( NOUT, FMT = 9999 )INFOT, SRNAMT
OK = .FALSE.
END IF
LERR = .FALSE.
RETURN
*
9999 FORMAT( ' ***** ILLEGAL VALUE OF PARAMETER NUMBER ', I2, ' NOT D',
$ 'ETECTED BY ', A6, ' *****' )
*
* End of CHKXER.
*
END
SUBROUTINE XERBLA( SRNAME, INFO )
*
* This is a special version of XERBLA to be used only as part of
* the test program for testing error exits from the Level 3 BLAS
* routines.
*
* XERBLA is an error handler for the Level 3 BLAS routines.
*
* It is called by the Level 3 BLAS routines if an input parameter is
* invalid.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER INFO
CHARACTER*6 SRNAME
* .. Scalars in Common ..
INTEGER INFOT, NOUT
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUT, OK, LERR
COMMON /SRNAMC/SRNAMT
* .. Executable Statements ..
LERR = .TRUE.
IF( INFO.NE.INFOT )THEN
IF( INFOT.NE.0 )THEN
WRITE( NOUT, FMT = 9999 )INFO, INFOT
ELSE
WRITE( NOUT, FMT = 9997 )INFO
END IF
OK = .FALSE.
END IF
IF( SRNAME.NE.SRNAMT )THEN
WRITE( NOUT, FMT = 9998 )SRNAME, SRNAMT
OK = .FALSE.
END IF
RETURN
*
9999 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6, ' INSTEAD',
$ ' OF ', I2, ' *******' )
9998 FORMAT( ' ******* XERBLA WAS CALLED WITH SRNAME = ', A6, ' INSTE',
$ 'AD OF ', A6, ' *******' )
9997 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6,
$ ' *******' )
*
* End of XERBLA
*
END
| mit |
emb-team/loongson-gccgo | gcc/testsuite/gfortran.dg/move_alloc_9.f90 | 136 | 1028 | ! { dg-do compile }
!
! Test diagnostic for MOVE_ALLOC:
! FROM=type, TO=class is OK
! FROM=class, TO=type is INVALID
!
module m2
type, abstract :: t2
contains
procedure(intf), deferred, nopass :: f
end type t2
interface
function intf()
import
class(t2), allocatable :: intf
end function intf
end interface
end module m2
module m3
use m2
type, extends(t2) :: t3
contains
procedure,nopass :: f => my_f
end type t3
contains
function my_f()
class(t2), allocatable :: my_f
end function my_f
end module m3
subroutine my_test
use m3
type(t3), allocatable :: x
class(t2), allocatable :: y
call move_alloc (x, y)
end subroutine my_test
program testmv1
type bar
end type
type, extends(bar) :: bar2
end type
class(bar), allocatable :: sm
type(bar2), allocatable :: sm2
allocate (sm2)
call move_alloc (sm,sm2) ! { dg-error "must be polymorphic if FROM is polymorphic" }
if (allocated(sm2)) call abort()
if (.not. allocated(sm)) call abort()
end program
| gpl-2.0 |
davidinouye/lpmrf | mexcode/eigen/lapack/clarfg.f | 273 | 5344 | *> \brief \b CLARFG
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CLARFG + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clarfg.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clarfg.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clarfg.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CLARFG( N, ALPHA, X, INCX, TAU )
*
* .. Scalar Arguments ..
* INTEGER INCX, N
* COMPLEX ALPHA, TAU
* ..
* .. Array Arguments ..
* COMPLEX X( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CLARFG generates a complex elementary reflector H of order n, such
*> that
*>
*> H**H * ( alpha ) = ( beta ), H**H * H = I.
*> ( x ) ( 0 )
*>
*> where alpha and beta are scalars, with beta real, and x is an
*> (n-1)-element complex vector. H is represented in the form
*>
*> H = I - tau * ( 1 ) * ( 1 v**H ) ,
*> ( v )
*>
*> where tau is a complex scalar and v is a complex (n-1)-element
*> vector. Note that H is not hermitian.
*>
*> If the elements of x are all zero and alpha is real, then tau = 0
*> and H is taken to be the unit matrix.
*>
*> Otherwise 1 <= real(tau) <= 2 and abs(tau-1) <= 1 .
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the elementary reflector.
*> \endverbatim
*>
*> \param[in,out] ALPHA
*> \verbatim
*> ALPHA is COMPLEX
*> On entry, the value alpha.
*> On exit, it is overwritten with the value beta.
*> \endverbatim
*>
*> \param[in,out] X
*> \verbatim
*> X is COMPLEX array, dimension
*> (1+(N-2)*abs(INCX))
*> On entry, the vector x.
*> On exit, it is overwritten with the vector v.
*> \endverbatim
*>
*> \param[in] INCX
*> \verbatim
*> INCX is INTEGER
*> The increment between elements of X. INCX > 0.
*> \endverbatim
*>
*> \param[out] TAU
*> \verbatim
*> TAU is COMPLEX
*> The value tau.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup complexOTHERauxiliary
*
* =====================================================================
SUBROUTINE CLARFG( N, ALPHA, X, INCX, TAU )
*
* -- 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 INCX, N
COMPLEX ALPHA, TAU
* ..
* .. Array Arguments ..
COMPLEX X( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ONE, ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Local Scalars ..
INTEGER J, KNT
REAL ALPHI, ALPHR, BETA, RSAFMN, SAFMIN, XNORM
* ..
* .. External Functions ..
REAL SCNRM2, SLAMCH, SLAPY3
COMPLEX CLADIV
EXTERNAL SCNRM2, SLAMCH, SLAPY3, CLADIV
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, CMPLX, REAL, SIGN
* ..
* .. External Subroutines ..
EXTERNAL CSCAL, CSSCAL
* ..
* .. Executable Statements ..
*
IF( N.LE.0 ) THEN
TAU = ZERO
RETURN
END IF
*
XNORM = SCNRM2( N-1, X, INCX )
ALPHR = REAL( ALPHA )
ALPHI = AIMAG( ALPHA )
*
IF( XNORM.EQ.ZERO .AND. ALPHI.EQ.ZERO ) THEN
*
* H = I
*
TAU = ZERO
ELSE
*
* general case
*
BETA = -SIGN( SLAPY3( ALPHR, ALPHI, XNORM ), ALPHR )
SAFMIN = SLAMCH( 'S' ) / SLAMCH( 'E' )
RSAFMN = ONE / SAFMIN
*
KNT = 0
IF( ABS( BETA ).LT.SAFMIN ) THEN
*
* XNORM, BETA may be inaccurate; scale X and recompute them
*
10 CONTINUE
KNT = KNT + 1
CALL CSSCAL( N-1, RSAFMN, X, INCX )
BETA = BETA*RSAFMN
ALPHI = ALPHI*RSAFMN
ALPHR = ALPHR*RSAFMN
IF( ABS( BETA ).LT.SAFMIN )
$ GO TO 10
*
* New BETA is at most 1, at least SAFMIN
*
XNORM = SCNRM2( N-1, X, INCX )
ALPHA = CMPLX( ALPHR, ALPHI )
BETA = -SIGN( SLAPY3( ALPHR, ALPHI, XNORM ), ALPHR )
END IF
TAU = CMPLX( ( BETA-ALPHR ) / BETA, -ALPHI / BETA )
ALPHA = CLADIV( CMPLX( ONE ), ALPHA-BETA )
CALL CSCAL( N-1, ALPHA, X, INCX )
*
* If ALPHA is subnormal, it may lose relative accuracy
*
DO 20 J = 1, KNT
BETA = BETA*SAFMIN
20 CONTINUE
ALPHA = BETA
END IF
*
RETURN
*
* End of CLARFG
*
END
| mit |
PHASTA/phasta | phSolver/compressible/e3ls.f | 2 | 33965 | subroutine e3LS (A1, A2, A3,
& rho, rmu, cp,
& cv, con, T,
& u1, u2, u3,
& rLyi, dxidx, tau,
& ri, rmi, rk,
& dui, aci, A0,
& divqi, shape, shg,
& EGmass, stiff, WdetJ,
& giju, rTLS, raLS,
& A0inv, dVdY, rerrl,
& compK, pres, PTau)
c
c----------------------------------------------------------------------
c
c This routine calculates the contribution of the least-squares
c operator to the RHS vector and LHS tangent matrix. The temporary
c results are put in ri.
c
c input:
c A1 (npro,nflow,nflow) : A_1
c A2 (npro,nflow,nflow) : A_2
c A3 (npro,nflow,nflow) : A_3
c rho (npro) : density
c T (npro) : temperature
c cp (npro) : specific heat at constant pressure
c u1 (npro) : x1-velocity component
c u2 (npro) : x2-velocity component
c u3 (npro) : x3-velocity component
c rLyi (npro,nflow) : least-squares residual vector
c dxidx (npro,nsd,nsd) : inverse of deformation gradient
c tau (npro,3) : stability parameter
c PTau (npro,5,5) : matrix of stability parameters
c rLyi (npro,nflow) : convective portion of least-squares
c residual vector
c divqi (npro,nflow-1) : divergence of diffusive flux
c shape (npro,nshl) : element shape functions
c shg (npro,nshl,nsd) : global element shape function grads
c WdetJ (npro) : weighted jacobian determinant
c stiff (npro,nsd*nflow,nsd*nflow) : stiffness matrix
c EGmass(npro,nedof,nedof) : partial mass matrix
c compK (npro,10) : K_ij in (eq.134) A new ... III
c
c output:
c ri (npro,nflow*(nsd+1)) : partial residual
c rmi (npro,nflow*(nsd+1)) : partial modified residual
c EGmass (npro,nedof,nedof) : partial mass matrix
c
c
c Zdenek Johan, Summer 1990. (Modified from e2ls.f)
c Zdenek Johan, Winter 1991. (Fortran 90)
c Kenneth Jansen, Winter 1997. Prim. Var. with Diag Tau
c----------------------------------------------------------------------
c
include "common.h"
c
c passed arrays
c
dimension A1(npro,nflow,nflow), A2(npro,nflow,nflow),
& A3(npro,nflow,nflow), cv(npro),
& A0(npro,nflow,nflow), rho(npro),
& con(npro), cp(npro),
& dui(npro,nflow), aci(npro,nflow),
& u1(npro), u2(npro),
& u3(npro), rk(npro),
& rLyi(npro,nflow), dxidx(npro,nsd,nsd),
& tau(npro,5), giju(npro,6),
& rTLS(npro), raLS(npro),
& ri(npro,nflow*(nsd+1)), rmi(npro,nflow*(nsd+1)),
& divqi(npro,nflow-1), stiff(npro,3*nflow,3*nflow),
& EGmass(npro,nedof,nedof),shape(npro,nshl),
& shg(npro,nshl,nsd), WdetJ(npro),
& PTau(npro,5,5), T(npro),
& pres(npro)
c
c local arrays
c
dimension rLymi(npro,nflow), Atau(npro,nflow,nflow),
& A1tauA0(npro,nflow,nflow), A2tauA0(npro,nflow,nflow),
& A3tauA0(npro,nflow,nflow), fact(npro),
& A0inv(npro,15), dVdY(npro,15),
& compK(npro,10), ac1(npro),
& ac2(npro), ac3(npro)
c
real*8 rerrl(npro,nshl,6), tmp(npro), tmp1(npro)
ttim(24) = ttim(24) - secs(0.0)
c
c
c last step to the least squares is adding the time term. So that we
c only have to localize one vector for each Krylov vector the modified
c residual is quite different from the total residual.
c
c
c the modified residual
c
fct1=almi/gami/alfi*dtgl
c
c add possibility of not including time term
c
c if(idiff.ne.-1)
if(ires.ne.1) rLymi = rLyi + fct1*dui
c
if(ires.eq.1 .or. ires .eq. 3) then
c rLymi = rLyi
rLyi(:,1) = rLyi(:,1)
& + A0(:,1,1)*aci(:,1)
c & + A0(:,1,2)*aci(:,2)
c & + A0(:,1,3)*aci(:,3)
c & + A0(:,1,4)*aci(:,4)
& + A0(:,1,5)*aci(:,5)
c
rLyi(:,2) = rLyi(:,2)
& + A0(:,2,1)*aci(:,1)
& + A0(:,2,2)*aci(:,2)
c & + A0(:,2,3)*aci(:,3)
c & + A0(:,2,4)*aci(:,4)
& + A0(:,2,5)*aci(:,5)
c
rLyi(:,3) = rLyi(:,3)
& + A0(:,3,1)*aci(:,1)
c & + A0(:,3,2)*aci(:,2)
& + A0(:,3,3)*aci(:,3)
c & + A0(:,3,4)*aci(:,4)
& + A0(:,3,5)*aci(:,5)
c
rLyi(:,4) = rLyi(:,4)
& + A0(:,4,1)*aci(:,1)
c & + A0(:,4,2)*aci(:,2)
c & + A0(:,4,3)*aci(:,3)
& + A0(:,4,4)*aci(:,4)
& + A0(:,4,5)*aci(:,5)
c
rLyi(:,5) = rLyi(:,5)
& + A0(:,5,1)*aci(:,1)
& + A0(:,5,2)*aci(:,2)
& + A0(:,5,3)*aci(:,3)
& + A0(:,5,4)*aci(:,4)
& + A0(:,5,5)*aci(:,5)
c
endif
c
c.... subtract div(q) from the least squares term
c
if ((idiff >= 1).and.(ires==3 .or. ires==1)) then
c
if (isurf.eq.zero) then
rLyi(:,2) = rLyi(:,2) - divqi(:,1)
rLyi(:,3) = rLyi(:,3) - divqi(:,2)
rLyi(:,4) = rLyi(:,4) - divqi(:,3)
rLyi(:,5) = rLyi(:,5) - divqi(:,4)
endif
endif
c
c.... -------------------> error calculation <-----------------
c
if((ierrcalc.eq.1).and.(nitr.eq.iter)) then
do ia=1,nshl
tmp=shape(:,ia)*WdetJ(:)
tmp1=shape(:,ia)*Qwt(lcsyst,intp)
rerrl(:,ia,1) = rerrl(:,ia,1) +
& tmp1(:)*rLyi(:,1)*rLyi(:,1)
rerrl(:,ia,2) = rerrl(:,ia,2) +
& tmp1(:)*rLyi(:,2)*rLyi(:,2)
rerrl(:,ia,3) = rerrl(:,ia,3) +
& tmp1(:)*rLyi(:,3)*rLyi(:,3)
rerrl(:,ia,4) = rerrl(:,ia,4) +
& tmp(:)*divqi(:,1)*divqi(:,1)
rerrl(:,ia,5) = rerrl(:,ia,5) +
& tmp(:)*divqi(:,2)*divqi(:,2)
! SAM wants a threshold here so we are going to take over this little used
! error indictor for that purpose
! commented for ShockError rerrl(:,ia,6) = rerrl(:,ia,6) +
! commented for ShockError & tmp(:)*divqi(:,3)*divqi(:,3)
enddo
endif
c
c
c.... ---------------------------> Tau <-----------------------------
c
c.... calculate the tau matrix
c
c.... in the first incarnation we will ONLY have a diagonal tau here
if (itau .lt. 10) then ! diagonal tau
call e3tau (rho, cp, rmu,
& u1, u2, u3,
& con, dxidx, rLyi,
& rLymi, tau, rk,
& giju, rTLS, raLS,
& A0inv, dVdY, cv)
else
c.... looks like need a non-diagonal, discribed in "A new ... III"
c.... by Hughes and Mallet. Original work - developed diffusive (and as
c.... well advective) correction factors for 1-D a-d equation w/ hier. b.
ac1(:) = aci(:,2)
ac2(:) = aci(:,3)
ac3(:) = aci(:,4)
call e3tau_nd (rho, cp, rmu, T,
& u1, u2, u3,
& ac1, ac2, ac3,
& con, dxidx, rLyi,
& rLymi, PTau, rk,
& giju, rTLS, raLS,
& cv, compK, pres,
& A0inv, dVdY)
endif
ttim(25) = ttim(25) + secs(0.0)
c
c Warning: to save space I have put the tau times the modified residual
c in rLymi and the tau times the total residual back in rLyi
c
c
c.... ----------------------------> RHS <----------------------------
c
c.... calculate (A_i^T tau Ly)
c
if(ires.ne.1) then
c
c A1 * Tau L(Y): to be hit on left with Na,x in e3wmlt
c
rmi(:,1) =
& A1(:,1,1) * rLymi(:,1)
& + A1(:,1,2) * rLymi(:,2)
c & + A1(:,1,3) * rLymi(:,3)
c & + A1(:,1,4) * rLymi(:,4)
& + A1(:,1,5) * rLymi(:,5)
& + rmi(:,1)
rmi(:,2) =
& A1(:,2,1) * rLymi(:,1)
& + A1(:,2,2) * rLymi(:,2)
c & + A1(:,2,3) * rLymi(:,3)
c & + A1(:,2,4) * rLymi(:,4)
& + A1(:,2,5) * rLymi(:,5)
& + rmi(:,2)
rmi(:,3) =
& A1(:,3,1) * rLymi(:,1)
& + A1(:,3,2) * rLymi(:,2)
& + A1(:,3,3) * rLymi(:,3)
c & + A1(:,3,4) * rLymi(:,4)
& + A1(:,3,5) * rLymi(:,5)
& + rmi(:,3)
rmi(:,4) =
& A1(:,4,1) * rLymi(:,1)
& + A1(:,4,2) * rLymi(:,2)
c & + A1(:,4,3) * rLymi(:,3)
& + A1(:,4,4) * rLymi(:,4)
& + A1(:,4,5) * rLymi(:,5)
& + rmi(:,4)
rmi(:,5) =
& A1(:,5,1) * rLymi(:,1)
& + A1(:,5,2) * rLymi(:,2)
& + A1(:,5,3) * rLymi(:,3)
& + A1(:,5,4) * rLymi(:,4)
& + A1(:,5,5) * rLymi(:,5)
& + rmi(:,5)
c
c A2 * Tau L(Y), to be hit on left with Na,y
c
rmi(:,6) =
& A2(:,1,1) * rLymi(:,1)
c & + A2(:,1,2) * rLymi(:,2)
& + A2(:,1,3) * rLymi(:,3)
c & + A2(:,1,4) * rLymi(:,4)
& + A2(:,1,5) * rLymi(:,5)
& + rmi(:,6)
rmi(:,7) =
& A2(:,2,1) * rLymi(:,1)
& + A2(:,2,2) * rLymi(:,2)
& + A2(:,2,3) * rLymi(:,3)
c & + A2(:,2,4) * rLymi(:,4)
& + A2(:,2,5) * rLymi(:,5)
& + rmi(:,7)
rmi(:,8) =
& A2(:,3,1) * rLymi(:,1)
c & + A2(:,3,2) * rLymi(:,2)
& + A2(:,3,3) * rLymi(:,3)
c & + A2(:,3,4) * rLymi(:,4)
& + A2(:,3,5) * rLymi(:,5)
& + rmi(:,8)
rmi(:,9) =
& A2(:,4,1) * rLymi(:,1)
c & + A2(:,4,2) * rLymi(:,2)
& + A2(:,4,3) * rLymi(:,3)
& + A2(:,4,4) * rLymi(:,4)
& + A2(:,4,5) * rLymi(:,5)
& + rmi(:,9)
rmi(:,10) =
& A2(:,5,1) * rLymi(:,1)
& + A2(:,5,2) * rLymi(:,2)
& + A2(:,5,3) * rLymi(:,3)
& + A2(:,5,4) * rLymi(:,4)
& + A2(:,5,5) * rLymi(:,5)
& + rmi(:,10)
c
c A3 * Tau L(Y) to be hit on left with Na,z
c
rmi(:,11) =
& A3(:,1,1) * rLymi(:,1)
c & + A3(:,1,2) * rLymi(:,2)
c & + A3(:,1,3) * rLymi(:,3)
& + A3(:,1,4) * rLymi(:,4)
& + A3(:,1,5) * rLymi(:,5)
& + rmi(:,11)
rmi(:,12) =
& A3(:,2,1) * rLymi(:,1)
& + A3(:,2,2) * rLymi(:,2)
c & + A3(:,2,3) * rLymi(:,3)
& + A3(:,2,4) * rLymi(:,4)
& + A3(:,2,5) * rLymi(:,5)
& + rmi(:,12)
rmi(:,13) =
& A3(:,3,1) * rLymi(:,1)
c & + A3(:,3,2) * rLymi(:,2)
& + A3(:,3,3) * rLymi(:,3)
& + A3(:,3,4) * rLymi(:,4)
& + A3(:,3,5) * rLymi(:,5)
& + rmi(:,13)
rmi(:,14) =
& A3(:,4,1) * rLymi(:,1)
c & + A3(:,4,2) * rLymi(:,2)
c & + A3(:,4,3) * rLymi(:,3)
& + A3(:,4,4) * rLymi(:,4)
& + A3(:,4,5) * rLymi(:,5)
& + rmi(:,14)
rmi(:,15) =
& A3(:,5,1) * rLymi(:,1)
& + A3(:,5,2) * rLymi(:,2)
& + A3(:,5,3) * rLymi(:,3)
& + A3(:,5,4) * rLymi(:,4)
& + A3(:,5,5) * rLymi(:,5)
& + rmi(:,15)
endif !ires.ne.1
c
c same thing for the real residual
c
if(ires.eq.3 .or. ires .eq. 1) then ! we need the total residual
ri(:,1) =
& A1(:,1,1) * rLyi(:,1)
& + A1(:,1,2) * rLyi(:,2)
c & + A1(:,1,3) * rLyi(:,3)
c & + A1(:,1,4) * rLyi(:,4)
& + A1(:,1,5) * rLyi(:,5)
& + ri(:,1)
ri(:,2) =
& A1(:,2,1) * rLyi(:,1)
& + A1(:,2,2) * rLyi(:,2)
c & + A1(:,2,3) * rLyi(:,3)
c & + A1(:,2,4) * rLyi(:,4)
& + A1(:,2,5) * rLyi(:,5)
& + ri(:,2)
ri(:,3) =
& A1(:,3,1) * rLyi(:,1)
& + A1(:,3,2) * rLyi(:,2)
& + A1(:,3,3) * rLyi(:,3)
c & + A1(:,3,4) * rLyi(:,4)
& + A1(:,3,5) * rLyi(:,5)
& + ri(:,3)
ri(:,4) =
& A1(:,4,1) * rLyi(:,1)
& + A1(:,4,2) * rLyi(:,2)
c & + A1(:,4,3) * rLyi(:,3)
& + A1(:,4,4) * rLyi(:,4)
& + A1(:,4,5) * rLyi(:,5)
& + ri(:,4)
ri(:,5) =
& A1(:,5,1) * rLyi(:,1)
& + A1(:,5,2) * rLyi(:,2)
& + A1(:,5,3) * rLyi(:,3)
& + A1(:,5,4) * rLyi(:,4)
& + A1(:,5,5) * rLyi(:,5)
& + ri(:,5)
c
ri(:,6) =
& A2(:,1,1) * rLyi(:,1)
c & + A2(:,1,2) * rLyi(:,2)
& + A2(:,1,3) * rLyi(:,3)
c & + A2(:,1,4) * rLyi(:,4)
& + A2(:,1,5) * rLyi(:,5)
& + ri(:,6)
ri(:,7) =
& A2(:,2,1) * rLyi(:,1)
& + A2(:,2,2) * rLyi(:,2)
& + A2(:,2,3) * rLyi(:,3)
c & + A2(:,2,4) * rLyi(:,4)
& + A2(:,2,5) * rLyi(:,5)
& + ri(:,7)
ri(:,8) =
& A2(:,3,1) * rLyi(:,1)
c & + A2(:,3,2) * rLyi(:,2)
& + A2(:,3,3) * rLyi(:,3)
c & + A2(:,3,4) * rLyi(:,4)
& + A2(:,3,5) * rLyi(:,5)
& + ri(:,8)
ri(:,9) =
& A2(:,4,1) * rLyi(:,1)
c & + A2(:,4,2) * rLyi(:,2)
& + A2(:,4,3) * rLyi(:,3)
& + A2(:,4,4) * rLyi(:,4)
& + A2(:,4,5) * rLyi(:,5)
& + ri(:,9)
ri(:,10) =
& A2(:,5,1) * rLyi(:,1)
& + A2(:,5,2) * rLyi(:,2)
& + A2(:,5,3) * rLyi(:,3)
& + A2(:,5,4) * rLyi(:,4)
& + A2(:,5,5) * rLyi(:,5)
& + ri(:,10)
ri(:,11) =
& A3(:,1,1) * rLyi(:,1)
c & + A3(:,1,2) * rLyi(:,2)
c & + A3(:,1,3) * rLyi(:,3)
& + A3(:,1,4) * rLyi(:,4)
& + A3(:,1,5) * rLyi(:,5)
& + ri(:,11)
ri(:,12) =
& A3(:,2,1) * rLyi(:,1)
& + A3(:,2,2) * rLyi(:,2)
c & + A3(:,2,3) * rLyi(:,3)
& + A3(:,2,4) * rLyi(:,4)
& + A3(:,2,5) * rLyi(:,5)
& + ri(:,12)
ri(:,13) =
& A3(:,3,1) * rLyi(:,1)
c & + A3(:,3,2) * rLyi(:,2)
& + A3(:,3,3) * rLyi(:,3)
& + A3(:,3,4) * rLyi(:,4)
& + A3(:,3,5) * rLyi(:,5)
& + ri(:,13)
ri(:,14) =
& A3(:,4,1) * rLyi(:,1)
c & + A3(:,4,2) * rLyi(:,2)
c & + A3(:,4,3) * rLyi(:,3)
& + A3(:,4,4) * rLyi(:,4)
& + A3(:,4,5) * rLyi(:,5)
& + ri(:,14)
ri(:,15) =
& A3(:,5,1) * rLyi(:,1)
& + A3(:,5,2) * rLyi(:,2)
& + A3(:,5,3) * rLyi(:,3)
& + A3(:,5,4) * rLyi(:,4)
& + A3(:,5,5) * rLyi(:,5)
& + ri(:,15)
c
endif ! for ires=3 or 1
c
c.... ----------------------------> LHS <----------------------------
c
if (lhs .eq. 1) then
c
c.... calculate (Atau) <-- (A_1 tau) (Recall that we are using a
c diagonal tau here)
c
if (itau.lt.10) then
do i = 1, nflow
Atau(:,i,1) = A1(:,i,1)*tau(:,1)
Atau(:,i,2) = A1(:,i,2)*tau(:,2)
Atau(:,i,3) = A1(:,i,3)*tau(:,2)
Atau(:,i,4) = A1(:,i,4)*tau(:,2)
Atau(:,i,5) = A1(:,i,5)*tau(:,3)
enddo
else
Atau = zero
do i = 1, nflow
do j = 1, nflow
do k = 1, nflow
Atau(:,i,j) =Atau(:,i,j) + A1(:,i,k)*PTau(:,k,j)
enddo
enddo
enddo
endif
c
c.... calculate (A_1 tau A_0) (for L.S. time term of EGmass)
c
do j = 1, nflow
do i = 1, nflow
A1tauA0(:,i,j) =
& Atau(:,i,1)*A0(:,1,j) +
& Atau(:,i,2)*A0(:,2,j) +
& Atau(:,i,3)*A0(:,3,j) +
& Atau(:,i,4)*A0(:,4,j) +
& Atau(:,i,5)*A0(:,5,j)
enddo
enddo
c
c.... add (A_1 tau A_1) to stiff [1,1]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i,j) = stiff(:,i,j) + (
& Atau(:,i,1)*A1(:,1,j)
& + Atau(:,i,2)*A1(:,2,j)
& + Atau(:,i,3)*A1(:,3,j)
& + Atau(:,i,4)*A1(:,4,j)
& + Atau(:,i,5)*A1(:,5,j)
& )
enddo
enddo
c
c.... add (A_1 tau A_2) to stiff [1,2]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i,j+5) = stiff(:,i,j+5) + (
& Atau(:,i,1)*A2(:,1,j)
& + Atau(:,i,2)*A2(:,2,j)
& + Atau(:,i,3)*A2(:,3,j)
& + Atau(:,i,4)*A2(:,4,j)
& + Atau(:,i,5)*A2(:,5,j)
& )
enddo
enddo
c
c.... add (A_1 tau A_3) to stiff [1,3]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i,j+10) = stiff(:,i,j+10) + (
& Atau(:,i,1)*A3(:,1,j)
& + Atau(:,i,2)*A3(:,2,j)
& + Atau(:,i,3)*A3(:,3,j)
& + Atau(:,i,4)*A3(:,4,j)
& + Atau(:,i,5)*A3(:,5,j)
& )
enddo
enddo
c
c.... calculate (Atau) <-- (A_2 tau) (Recall that we are using a
c diagonal tau here)
c
if (itau.lt.10) then
do i = 1, nflow
Atau(:,i,1) = A2(:,i,1)*tau(:,1)
Atau(:,i,2) = A2(:,i,2)*tau(:,2)
Atau(:,i,3) = A2(:,i,3)*tau(:,2)
Atau(:,i,4) = A2(:,i,4)*tau(:,2)
Atau(:,i,5) = A2(:,i,5)*tau(:,3)
enddo
else
Atau = zero
do i = 1, nflow
do j = 1, nflow
do k = 1, nflow
Atau(:,i,j) = Atau(:,i,j) + A2(:,i,k)*PTau(:,k,j)
enddo
enddo
enddo
endif
c
c.... calculate (A_2 tau A_0) (for L.S. time term of EGmass)
c
do j = 1, nflow
do i = 1, nflow
A2tauA0(:,i,j) =
& Atau(:,i,1)*A0(:,1,j) +
& Atau(:,i,2)*A0(:,2,j) +
& Atau(:,i,3)*A0(:,3,j) +
& Atau(:,i,4)*A0(:,4,j) +
& Atau(:,i,5)*A0(:,5,j)
enddo
enddo
c
c.... add (A_2 tau A_1) to stiff [2,1]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i+5,j) = stiff(:,i+5,j) + (
& Atau(:,i,1)*A1(:,1,j)
& + Atau(:,i,2)*A1(:,2,j)
& + Atau(:,i,3)*A1(:,3,j)
& + Atau(:,i,4)*A1(:,4,j)
& + Atau(:,i,5)*A1(:,5,j)
& )
enddo
enddo
c
c.... add (A_2 tau A_2) to stiff [2,2]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i+5,j+5) = stiff(:,i+5,j+5) + (
& Atau(:,i,1)*A2(:,1,j)
& + Atau(:,i,2)*A2(:,2,j)
& + Atau(:,i,3)*A2(:,3,j)
& + Atau(:,i,4)*A2(:,4,j)
& + Atau(:,i,5)*A2(:,5,j)
& )
enddo
enddo
c
c.... add (A_2 tau A_3) to stiff [2,3]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i+5,j+10) = stiff(:,i+5,j+10) + (
& Atau(:,i,1)*A3(:,1,j)
& + Atau(:,i,2)*A3(:,2,j)
& + Atau(:,i,3)*A3(:,3,j)
& + Atau(:,i,4)*A3(:,4,j)
& + Atau(:,i,5)*A3(:,5,j)
& )
enddo
enddo
c
c.... calculate (Atau) <-- (A_3 tau) (Recall that we are using a
c diagonal tau here)
c
if (itau.lt.10) then
do i = 1, nflow
Atau(:,i,1) = A3(:,i,1)*tau(:,1)
Atau(:,i,2) = A3(:,i,2)*tau(:,2)
Atau(:,i,3) = A3(:,i,3)*tau(:,2)
Atau(:,i,4) = A3(:,i,4)*tau(:,2)
Atau(:,i,5) = A3(:,i,5)*tau(:,3)
enddo
else
Atau = zero
do i = 1, nflow
do j = 1, nflow
do k = 1, nflow
Atau(:,i,j) = Atau(:,i,j) + A3(:,i,k)*PTau(:,k,j)
enddo
enddo
enddo
endif
c
c.... calculate (A_3 tau A_0) (for L.S. time term of EGmass)
c
do j = 1, nflow
do i = 1, nflow
A3tauA0(:,i,j) =
& Atau(:,i,1)*A0(:,1,j) +
& Atau(:,i,2)*A0(:,2,j) +
& Atau(:,i,3)*A0(:,3,j) +
& Atau(:,i,4)*A0(:,4,j) +
& Atau(:,i,5)*A0(:,5,j)
enddo
enddo
c
c.... add (A_3 tau A_1) to stiff [3,1]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i+10,j) = stiff(:,i+10,j) + (
& Atau(:,i,1)*A1(:,1,j)
& + Atau(:,i,2)*A1(:,2,j)
& + Atau(:,i,3)*A1(:,3,j)
& + Atau(:,i,4)*A1(:,4,j)
& + Atau(:,i,5)*A1(:,5,j)
& )
enddo
enddo
c
c.... add (A_3 tau A_2) to stiff [3,2]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i+10,j+5) = stiff(:,i+10,j+5) + (
& Atau(:,i,1)*A2(:,1,j)
& + Atau(:,i,2)*A2(:,2,j)
& + Atau(:,i,3)*A2(:,3,j)
& + Atau(:,i,4)*A2(:,4,j)
& + Atau(:,i,5)*A2(:,5,j)
& )
enddo
enddo
c
c.... add (A_3 tau A_3) to stiff [3,3]
c
do j = 1, nflow
do i = 1, nflow
stiff(:,i+10,j+10) = stiff(:,i+10,j+10) + (
& Atau(:,i,1)*A3(:,1,j)
& + Atau(:,i,2)*A3(:,2,j)
& + Atau(:,i,3)*A3(:,3,j)
& + Atau(:,i,4)*A3(:,4,j)
& + Atau(:,i,5)*A3(:,5,j)
& )
enddo
enddo
c
c.... add least squares time term to the LHS tangent mass matrix
c
c
c.... loop through rows (nodes i)
c
do i = 1, nshl
i0 = nflow * (i - 1)
c
c.... first calculate (Atau) <-- (N_a,i A_i tau A_0)
c ( use Atau to conserve space )
c
do idof = 1, nflow
do jdof = 1, nflow
Atau(:,idof,jdof) =
& shg(:,i,1) * A1tauA0(:,idof,jdof) +
& shg(:,i,2) * A2tauA0(:,idof,jdof) +
& shg(:,i,3) * A3tauA0(:,idof,jdof)
enddo
enddo
c
c.... loop through column nodes, add (N_a,i A_i tau N_b) to EGmass
c
do j = 1, nshl
j0 = nflow * (j - 1)
c
c.... compute the factors
c
fact = shape(:,j) * WdetJ * almi/gami/alfi*dtgl
c
c.... loop through d.o.f.'s
c
do idof = 1, nflow
il = i0 + idof
EGmass(:,il,j0+1) = EGmass(:,il,j0+1) +
& fact * Atau(:,idof,1)
EGmass(:,il,j0+2) = EGmass(:,il,j0+2) +
& fact * Atau(:,idof,2)
EGmass(:,il,j0+3) = EGmass(:,il,j0+3) +
& fact * Atau(:,idof,3)
EGmass(:,il,j0+4) = EGmass(:,il,j0+4) +
& fact * Atau(:,idof,4)
EGmass(:,il,j0+5) = EGmass(:,il,j0+5) +
& fact * Atau(:,idof,5)
enddo
c
c.... end loop on column nodes
c
enddo
c
c.... end loop on row nodes
c
enddo
c
c.... end LHS computation
c
endif
ttim(24) = ttim(24) + secs(0.0)
c
c.... return
c
return
end
c
c
c
subroutine e3LSSclr (A1t, A2t, A3t,
& rho, rmu, rTLSt,
& u1, u2, u3,
& rLyti, dxidx, raLSt,
& rti, rk, giju,
& acti, A0t,
& shape, shg,
& EGmasst, stifft, WdetJ,
& srcp)
c
c----------------------------------------------------------------------
c
c This routine calculates the contribution of the least-squares
c operator to the RHS vector and LHS tangent matrix. The temporary
c results are put in ri.
c
c input:
c A0t (npro) : A_0
c A1t (npro) : A_1
c A2t (npro) : A_2
c A3t (npro) : A_3
c acti (npro) : time-deriv. of Sclr
c rho (npro) : density
c rmu (npro) : molecular viscosity
c rk (npro) : kinetic energy
c u1 (npro) : x1-velocity component
c u2 (npro) : x2-velocity component
c u3 (npro) : x3-velocity component
c rLyti (npro) : least-squares residual vector
c dxidx (npro,nsd,nsd) : inverse of deformation gradient
c taut (npro) : stability parameter
c rLyti (npro) : convective portion of least-squares
c residual vector
c divqti (npro,1) : divergence of diffusive flux
c shape (npro,nshl) : element shape functions
c shg (npro,nshl,nsd) : global element shape function grads
c WdetJ (npro) : weighted jacobian determinant
c stifft (npro,nsd,nsd) : stiffness matrix
c EGmasst(npro,nshape,nshape): partial mass matrix
c
c output:
c rti (npro,nsd+1) : partial residual
c EGmasst(npro,nshape,nshape): partial mass matrix
c
c
c Zdenek Johan, Summer 1990. (Modified from e2ls.f)
c Zdenek Johan, Winter 1991. (Fortran 90)
c Kenneth Jansen, Winter 1997. Prim. Var. with Diag Tau
c----------------------------------------------------------------------
c
include "common.h"
c
c passed arrays
c
dimension A1t(npro), A2t(npro),
& A3t(npro),
& A0t(npro), rho(npro),
& acti(npro), rmu(npro),
& u1(npro), u2(npro),
& u3(npro), rk(npro),
& rLyti(npro), dxidx(npro,nsd,nsd),
& taut(npro), raLSt(npro),
& rti(npro,nsd+1), rTLSt(npro),
& stifft(npro,3,3), giju(npro,6),
& EGmasst(npro,nshape,nshape),
& shape(npro,nshl),
& shg(npro,nshl,nsd), WdetJ(npro),
& srcp(npro)
c
c local arrays
c
dimension rLymti(npro), Ataut(npro),
& A1tautA0(npro), A2tautA0(npro),
& A3tautA0(npro), fact(npro)
ttim(24) = ttim(24) - tmr()
c
if(ivart.lt.2) return
c
c last step to the least squares is adding the time term. So that we
c only have to localize one vector for each Krylov vector the modified
c residual is quite different from the total residual.
c
c
c the modified residual
c
fct1=almi/gami/alfi*dtgl
c
c add possibility of not including time term
c
c if(idiff.ne.-1)
c rLymti = rLyti + fct1*duti
if((ires.eq.1 .or. ires .eq. 3).and. idiff.ne.-1) then
rLyti(:) = rLyti(:) + A0t(:)*acti(:)
endif
c
c.... subtract div(q) from the least squares term
c
c if ((idiff >= 1).and.(ires==3 .or. ires==1)) then
c rLyi(:) = rLyi(:) - divqti(:)
c endif
c
c.... ---------------------------> Tau <-----------------------------
c
c.... calculate the tau matrix
c
c
c.... we will use the same tau as used for momentum equations here
c
ttim(25) = ttim(25) - tmr()
call e3tauSclr(rho, rmu, A0t,
& u1, u2, u3,
& dxidx, rLyti, rLymti,
& taut, rk, raLSt,
& rTLSt, giju)
ttim(25) = ttim(25) + tmr()
c
c Warning: to save space I have put the tau times the modified residual
c in rLymi and the tau times the total residual back in rLyi
c
c
c.... ----------------------------> RHS <----------------------------
c
c.... calculate (A_i^T tau Ly)
c
c if(ires.ne.1) then
c
c A1 * Tau L(Y): to be hit on left with Na,x in e3wmlt
c
c rmti(:,1) = A1t(:) * rLymti(:)
c
c
c A2 * Tau L(Y), to be hit on left with Na,y
c
c rmti(:,2) = A2t(:) * rLymti(:)
c
c
c A3 * Tau L(Y) to be hit on left with Na,z
c
c rmti(:,3) = A3t(:) * rLymti(:)
c
c endif !ires.ne.1
c
c same thing for the real residual
c
if(ires.eq.3 .or. ires .eq. 1) then ! we need the total residual
rti(:,1) = rti(:,1) + A1t(:) * rLyti(:)
rti(:,2) = rti(:,2) + A2t(:) * rLyti(:)
rti(:,3) = rti(:,3) + A3t(:) * rLyti(:)
endif ! for ires=3 or 1
c
c.... ----------------------------> LHS <----------------------------
c
if (lhs .eq. 1) then
c
c
c.... calculate (Atau) <-- (A_1 tau)
c
Ataut(:) = A1t(:)*taut(:)
c
c.... calculate (A_1 tau (A_0-srcp)) (for L.S. time term of EGmass)
c
A1tautA0(:) = Ataut(:)*(a0t(:)*fct1-srcp(:))
c
c.... add (A_1 tau A_1) to stiff [1,1]
c
stifft(:,1,1) = stifft(:,1,1) + Ataut(:)*A1t(:)
c stifft(:,1,1) = Ataut(:)*A1t(:)
c
c.... add (A_1 tau A_2) to stiff [1,2]
c
stifft(:,1,2) = stifft(:,1,2) + Ataut(:)*A2t(:)
c stifft(:,1,2) = Ataut(:)*A2t(:)
c
c.... add (A_1 tau A_3) to stiff [1,3]
c
stifft(:,1,3) = stifft(:,1,3) + Ataut(:)*A3t(:)
c stifft(:,1,3) = Ataut(:)*A3t(:)
c
c.... calculate (Atau) <-- (A_2 tau)
c
Ataut(:) = A2t(:)*taut(:)
c
c.... calculate (A_2 tau (A_0-srcp)) (for L.S. time term of EGmass)
c
A2tautA0(:) = Ataut(:)*(a0t(:)*fct1-srcp(:))
c
c.... add (A_2 tau A_1) to stiff [2,1]
c
stifft(:,2,1) = stifft(:,1,2)
c
c.... add (A_2 tau A_2) to stiff [2,2]
c
stifft(:,2,2) = stifft(:,2,2) + Ataut(:)*A2t(:)
c
c.... add (A_2 tau A_3) to stiff [2,3]
c
stifft(:,2,3) = stifft(:,2,3) + Ataut(:)*A3t(:)
c
c.... calculate (Atau) <-- (A_3 tau)
c
Ataut(:) = A3t(:)*taut(:)
c
c.... calculate (A_3 tau (A_0-srcp)) (for L.S. time term of EGmass)
c
A3tautA0(:) = Ataut(:)*(a0t(:)*fct1-srcp(:))
c
c.... add (A_3 tau A_1) to stiff [3,1]
c
stifft(:,3,1) = stifft(:,1,3)
c
c.... add (A_3 tau A_2) to stiff [3,2]
c
stifft(:,3,2) = stifft(:,2,3)
c
c.... add (A_3 tau A_3) to stiff [3,3]
c
stifft(:,3,3) = stifft(:,3,3) + Ataut(:)*A3t(:)
c
c.... add least squares time term to the LHS tangent mass matrix
c
c
c.... loop through rows (nodes i)
c
do ia = 1, nshl
c
c.... first calculate (Atau) <-- (N_a,i A_i tau A_0)
c ( use Atau to conserve space )
c
Ataut(:) =
& shg(:,ia,1) * A1tautA0(:) +
& shg(:,ia,2) * A2tautA0(:) +
& shg(:,ia,3) * A3tautA0(:)
c
c.... loop through column nodes, add (N_a,i A_i tau N_b) to EGmass
c
do jb = 1, nshl
fact = shape(:,jb) * WdetJ
EGmasst(:,ia,jb) = EGmasst(:,ia,jb) + fact * Ataut(:)
c
c.... end loop on column nodes
c
enddo
c
c.... end loop on row nodes
c
enddo
c
c.... end LHS computation
c
endif
ttim(24) = ttim(24) + tmr()
c
c.... return
c
return
end
| bsd-3-clause |
jrper/fluidity | femtools/Rotated_Boundary_Conditions.F90 | 2 | 11774 | ! Copyright (C) 2006 Imperial College London and others.
!
! Please see the AUTHORS file in the main source directory for a full list
! of copyright holders.
!
! Prof. C Pain
! Applied Modelling and Computation Group
! Department of Earth Science and Engineering
! Imperial College London
!
! amcgsoftware@imperial.ac.uk
!
! This library is free software; you can redistribute it and/or
! modify it under the terms of the GNU Lesser General Public
! License as published by the Free Software Foundation,
! version 2.1 of the License.
!
! This library is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! Lesser General Public License for more details.
!
! You should have received a copy of the GNU Lesser General Public
! License along with this library; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
! USA
#include "fdebug.h"
module rotated_boundary_conditions
use spud
use fldebug
use global_parameters, only: FIELD_NAME_LEN, OPTION_PATH_LEN
use parallel_tools
use sparse_tools
use parallel_fields, only: zero_non_owned
use fields
use sparse_tools_petsc
use state_module
use halos
use boundary_conditions
implicit none
private
public :: have_rotated_bcs, create_rotation_matrix, rotate_momentum_equation,&
rotate_ct_m, rotate_velocity, rotate_velocity_back
contains
function have_rotated_bcs(u)
type(vector_field), intent(in):: u
logical:: have_rotated_bcs
character(len=FIELD_NAME_LEN) :: bctype
character(len=OPTION_PATH_LEN):: bc_option_path
integer, dimension(:), pointer:: surface_node_list
integer:: i
do i=1, get_boundary_condition_count(u)
call get_boundary_condition(u, i, type=bctype, &
surface_node_list=surface_node_list, &
option_path=bc_option_path)
if (bctype=="dirichlet" .and. &
have_option(trim(bc_option_path)//"/type[0]/align_bc_with_surface")) then
have_rotated_bcs=.true.
return
end if
end do
have_rotated_bcs=.false.
end function have_rotated_bcs
subroutine create_rotation_matrix(rotation_m, u)
type(petsc_csr_matrix), intent(out):: rotation_m
type(vector_field), intent(in):: u
type(halo_type), pointer:: halo
type(vector_field), pointer:: normal, tangent1, tangent2
character(len=FIELD_NAME_LEN):: bctype
character(len=OPTION_PATH_LEN):: bc_option_path
integer, dimension(:), pointer:: surface_node_list
real, dimension(u%dim, u%dim):: local_rotation
integer, dimension(:), allocatable:: dnnz, onnz
integer:: i, j, node, nodes, mynodes
logical:: parallel
ewrite(1,*) "Inside create_rotation_matrix"
nodes=node_count(u)
if (associated(u%mesh%halos)) then
halo => u%mesh%halos(1)
mynodes=halo_nowned_nodes(halo)
else
nullify(halo)
mynodes=nodes
end if
parallel=IsParallel()
allocate(dnnz(1:mynodes*u%dim), onnz(1:mynodes*u%dim))
onnz=0
! default is just a 1.0 on the diagonal (no rotation)
dnnz=1
do i=1, get_boundary_condition_count(u)
call get_boundary_condition(u, i, type=bctype, &
surface_node_list=surface_node_list, &
option_path=bc_option_path)
if (bctype=="dirichlet" .and. &
have_option(trim(bc_option_path)//"/type[0]/align_bc_with_surface")) then
do j=1, size(surface_node_list)
node=surface_node_list(j)
if (parallel) then
if (node>mynodes) cycle
endif
if (any(dnnz( (node-1)*u%dim+1:node*u%dim )>1)) then
FLExit("Two rotated boundary condition specifications for the same node.")
end if
dnnz( (node-1)*u%dim+1:node*u%dim ) = u%dim
end do
end if
end do
call allocate(rotation_m, nodes, nodes, &
dnnz, onnz, (/ u%dim, u%dim /), group_size=(/u%dim, u%dim/), name="RotationMatrix", halo=halo)
! put a 1.0 on the diagonal for non-rotated nodes
do i=1, mynodes
! skip rotated nodes
if (dnnz(i*u%dim)/=1) cycle
do j=1, u%dim
call addto(rotation_m, j, j, i, i, 1.0)
end do
end do
! insert the local rotation matrix as a diagonal block for the rotated nodes
do i=1, get_boundary_condition_count(u)
call get_boundary_condition(u, i, type=bctype, &
surface_node_list=surface_node_list, &
option_path=bc_option_path)
if (bctype=="dirichlet" .and. &
have_option(trim(bc_option_path)//"/type[0]/align_bc_with_surface")) then
normal => extract_surface_field(u, i, "normal")
tangent1 => extract_surface_field(u, i, "tangent1")
tangent2 => extract_surface_field(u, i, "tangent2")
do j=1, size(surface_node_list)
node=surface_node_list(j)
if (node > mynodes) cycle
local_rotation(:,1)=node_val(normal, j)
local_rotation(:,2)=node_val(tangent1, j)
if (u%dim>2) then
local_rotation(:,3)=node_val(tangent2, j)
end if
call addto(rotation_m, node, node, local_rotation)
end do
end if
end do
call assemble(rotation_m)
end subroutine create_rotation_matrix
subroutine rotate_momentum_equation(big_m, rhs, u, state, dg)
type(petsc_csr_matrix), intent(inout):: big_m
type(vector_field), intent(inout):: rhs
type(vector_field), intent(inout):: u
type(state_type), intent(inout):: state
logical, intent(in) :: dg
type(petsc_csr_matrix), pointer:: rotation_m
type(petsc_csr_matrix):: rotated_big_m
type(vector_field):: result
integer:: stat
ewrite(1,*) "Inside rotate_momentum_equation"
rotation_m => extract_petsc_csr_matrix(state, "RotationMatrix", stat=stat)
if (stat/=0) then
allocate(rotation_m)
call create_rotation_matrix(rotation_m, u)
call insert(state, rotation_m, "RotationMatrix")
end if
!call assemble(big_m)
!call dump_matrix("bigm", big_m)
! rotate big_m:
call ptap(rotated_big_m, big_m, rotation_m)
!call dump_matrix("rotated_bigm", rotated_big_m)
! rotate rhs:
! need to have separate copy of the field, because of intent(out) and intent(in)
! of mult_T call, as result%val points at the same space as rhs%val, this directly
! puts the result in rhs as well
result=rhs
call mult_T(result, rotation_m, rhs)
if (dg) then
! We have just poluted the halo rows of the rhs. This is incorrect
! in the dg case due to the non-local assembly system employed.
call zero_non_owned(rhs)
end if
! rotate u:
if (dg) then
call zero_non_owned(u)
end if
result=u ! same story
call mult_T(result, rotation_m, u)
! throw out unrotated big_m and replace with rotated:
call deallocate(big_m)
big_m=rotated_big_m
if (stat/=0) then
call deallocate(rotation_m)
deallocate(rotation_m)
end if
end subroutine rotate_momentum_equation
subroutine rotate_ct_m(ct_m, u)
type(block_csr_matrix), intent(inout):: ct_m
type(vector_field), intent(in):: u
type(vector_field), pointer:: normal, tangent1, tangent2
character(len=FIELD_NAME_LEN):: bctype
character(len=OPTION_PATH_LEN):: bc_option_path
integer, dimension(:), pointer:: surface_node_list, rowcol
integer, dimension(:), allocatable:: node2rotated_node
real, dimension(u%dim, u%dim):: local_rotation
real, dimension(u%dim):: ct_xyz, ct_rot
real, dimension(:), pointer:: rowval
integer:: bc, i, j, k, rotated_node
ewrite(1,*) "Inside rotate_ct_m"
assert( all(blocks(ct_m) == (/ 1, u%dim /)) )
allocate( node2rotated_node(1:node_count(u)) )
do bc=1, get_boundary_condition_count(u)
call get_boundary_condition(u, bc, type=bctype, &
surface_node_list=surface_node_list, &
option_path=bc_option_path)
if (bctype=="dirichlet" .and. &
have_option(trim(bc_option_path)//"/type[0]/align_bc_with_surface")) then
normal => extract_surface_field(u, bc, "normal")
tangent1 => extract_surface_field(u, bc, "tangent1")
tangent2 => extract_surface_field(u, bc, "tangent2")
node2rotated_node=0
node2rotated_node(surface_node_list)=(/ (j, j=1, size(surface_node_list)) /)
do i=1, size(ct_m, 1)
rowcol => row_m_ptr(ct_m, i)
do j=1, size(rowcol)
rotated_node=node2rotated_node(rowcol(j))
if (rotated_node/=0) then
! construct local rotation matrix
local_rotation(1,:)=node_val(normal, rotated_node)
local_rotation(2,:)=node_val(tangent1, rotated_node)
if (u%dim>2) then
local_rotation(3,:)=node_val(tangent2, rotated_node)
end if
! look up ct_m values of row i, column rowcol(j) in xyz orientation
do k=1, blocks(ct_m,2)
rowval => row_val_ptr(ct_m, 1, k, i)
ct_xyz(k)=rowval(j)
end do
! rotate to normal, tangent1, tangent2 orientation
ct_rot=matmul( local_rotation, ct_xyz)
! put back in the matrix
do k=1, blocks(ct_m,2)
rowval => row_val_ptr(ct_m, 1, k, i)
rowval(j)=ct_rot(k)
end do
end if
end do
end do
end if
end do
deallocate(node2rotated_node)
end subroutine rotate_ct_m
subroutine rotate_velocity(vfield, state)
type(vector_field), intent(inout):: vfield
type(state_type), intent(inout):: state
type(vector_field), pointer:: u
type(vector_field):: result
type(petsc_csr_matrix), pointer:: rotation_m
integer:: stat
rotation_m => extract_petsc_csr_matrix(state, "RotationMatrix", stat=stat)
if (stat/=0) then
allocate(rotation_m)
! the vector field we are rotating might not have the bcs attached to it:
u => extract_vector_field(state, "Velocity")
call create_rotation_matrix(rotation_m, u)
call insert(state, rotation_m, "RotationMatrix")
end if
result=vfield ! see note in rotate_momentum_equation
call mult_T(result, rotation_m, vfield)
if (stat/=0) then
call deallocate(rotation_m)
deallocate(rotation_m)
end if
end subroutine rotate_velocity
subroutine rotate_velocity_back(vfield, state)
type(vector_field), intent(inout):: vfield
type(state_type), intent(inout):: state
type(vector_field), pointer:: u
type(vector_field):: result
type(petsc_csr_matrix), pointer:: rotation_m
integer:: stat
rotation_m => extract_petsc_csr_matrix(state, "RotationMatrix", stat=stat)
if (stat/=0) then
allocate(rotation_m)
! the vector field we are rotating might not have the bcs attached to it:
u => extract_vector_field(state, "Velocity")
call create_rotation_matrix(rotation_m, u)
call insert(state, rotation_m, "RotationMatrix")
end if
result=vfield ! see note in rotate_momentum_equation
call mult(result, rotation_m, vfield)
if (stat/=0) then
call deallocate(rotation_m)
deallocate(rotation_m)
end if
end subroutine rotate_velocity_back
end module rotated_boundary_conditions
| lgpl-2.1 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/char_result_6.f90 | 188 | 2214 | ! Like char_result_5.f90, but the function arguments are pointers to scalars.
! { 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
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
call test (f1 (ip), 200)
call test (f2 (rp), 100)
call test (f3 (lp), 50)
call test (f4 (cp), 10)
call test (f5 (chp), 11)
call test (f6 (pp), 145)
contains
function f1 (i)
integer, pointer :: i
character (len = abs (i) * 2) :: f1
f1 = ''
end function f1
function f2 (r)
real, pointer :: r
character (len = floor (r) * 2) :: f2
f2 = ''
end function f2
function f3 (l)
logical, pointer :: l
character (len = select (l, 50, 55)) :: f3
f3 = ''
end function f3
function f4 (c)
complex, pointer :: c
character (len = int (c)) :: f4
f4 = ''
end function f4
function f5 (c)
character, pointer :: c
character (len = scan ('123456789', c) + 10) :: f5
f5 = ''
end function f5
function f6 (p)
type (pair), pointer :: 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 |
tectronics/force-distribution-analysis.gromacs-4-5-3 | src/gmxlib/nonbonded/nb_kernel_f77_single/f77skernel203.f | 5 | 18063 | C
C This source code is part of
C
C G R O M A C S
C
C Copyright (c) 1991-2000, University of Groningen, The Netherlands.
C Copyright (c) 2001-2009, The GROMACS Development Team
C
C Gromacs is a library for molecular simulation and trajectory analysis,
C written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
C a full list of developers and information, check out http://www.gromacs.org
C
C This program is free software; you can redistribute it and/or modify it under
C the terms of the GNU Lesser General Public License as published by the Free
C Software Foundation; either version 2 of the License, or (at your option) any
C later version.
C As a special exception, you may use this file as part of a free software
C library without restriction. Specifically, if other files instantiate
C templates or use macros or inline functions from this file, or you compile
C this file and link it with other files to produce an executable, this
C file does not by itself cause the resulting executable to be covered by
C the GNU Lesser General Public License.
C
C In plain-speak: do not worry about classes/macros/templates either - only
C changes to the library have to be LGPL, not an application linking with it.
C
C To help fund GROMACS development, we humbly ask that you cite
C the papers people have written on it - you can find them on the website!
C
C
C Gromacs nonbonded kernel f77skernel203
C Coulomb interaction: Reaction field
C VdW interaction: Not calculated
C water optimization: TIP4P - other atoms
C Calculate forces: yes
C
subroutine f77skernel203(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
real*4 shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
real*4 charge(*),facel,krf,crf,Vc(*),vdwparam(*)
real*4 Vvdw(*),tabscale,VFtab(*)
real*4 invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
real*4 work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
real*4 shX,shY,shZ
real*4 fscal,tx,ty,tz
real*4 rinvsq
real*4 jq
real*4 qq,vcoul,vctot
real*4 krsq
real*4 ix2,iy2,iz2,fix2,fiy2,fiz2
real*4 ix3,iy3,iz3,fix3,fiy3,fiz3
real*4 ix4,iy4,iz4,fix4,fiy4,fiz4
real*4 jx1,jy1,jz1,fjx1,fjy1,fjz1
real*4 dx21,dy21,dz21,rsq21,rinv21
real*4 dx31,dy31,dz31,rsq31,rinv31
real*4 dx41,dy41,dz41,rsq41,rinv41
real*4 qH,qM
C Initialize water data
ii = iinr(1)+1
qH = facel*charge(ii+1)
qM = facel*charge(ii+3)
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call f77kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix2 = shX + pos(ii3+3)
iy2 = shY + pos(ii3+4)
iz2 = shZ + pos(ii3+5)
ix3 = shX + pos(ii3+6)
iy3 = shY + pos(ii3+7)
iz3 = shZ + pos(ii3+8)
ix4 = shX + pos(ii3+9)
iy4 = shY + pos(ii3+10)
iz4 = shZ + pos(ii3+11)
C Zero the potential energy for this list
vctot = 0
C Clear i atom forces
fix2 = 0
fiy2 = 0
fiz2 = 0
fix3 = 0
fiy3 = 0
fiz3 = 0
fix4 = 0
fiy4 = 0
fiz4 = 0
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx21 = ix2 - jx1
dy21 = iy2 - jy1
dz21 = iz2 - jz1
rsq21 = dx21*dx21+dy21*dy21+dz21*dz21
dx31 = ix3 - jx1
dy31 = iy3 - jy1
dz31 = iz3 - jz1
rsq31 = dx31*dx31+dy31*dy31+dz31*dz31
dx41 = ix4 - jx1
dy41 = iy4 - jy1
dz41 = iz4 - jz1
rsq41 = dx41*dx41+dy41*dy41+dz41*dz41
C Calculate 1/r and 1/r2
rinv21 = 1.0/sqrt(rsq21)
rinv31 = 1.0/sqrt(rsq31)
rinv41 = 1.0/sqrt(rsq41)
C Load parameters for j atom
jq = charge(jnr+0)
qq = qH*jq
rinvsq = rinv21*rinv21
C Coulomb reaction-field interaction
krsq = krf*rsq21
vcoul = qq*(rinv21+krsq-crf)
vctot = vctot+vcoul
fscal = (qq*(rinv21-2.0*krsq))*rinvsq
C Calculate temporary vectorial force
tx = fscal*dx21
ty = fscal*dy21
tz = fscal*dz21
C Increment i atom force
fix2 = fix2 + tx
fiy2 = fiy2 + ty
fiz2 = fiz2 + tz
C Decrement j atom force
fjx1 = faction(j3+0) - tx
fjy1 = faction(j3+1) - ty
fjz1 = faction(j3+2) - tz
C Load parameters for j atom
rinvsq = rinv31*rinv31
C Coulomb reaction-field interaction
krsq = krf*rsq31
vcoul = qq*(rinv31+krsq-crf)
vctot = vctot+vcoul
fscal = (qq*(rinv31-2.0*krsq))*rinvsq
C Calculate temporary vectorial force
tx = fscal*dx31
ty = fscal*dy31
tz = fscal*dz31
C Increment i atom force
fix3 = fix3 + tx
fiy3 = fiy3 + ty
fiz3 = fiz3 + tz
C Decrement j atom force
fjx1 = fjx1 - tx
fjy1 = fjy1 - ty
fjz1 = fjz1 - tz
C Load parameters for j atom
qq = qM*jq
rinvsq = rinv41*rinv41
C Coulomb reaction-field interaction
krsq = krf*rsq41
vcoul = qq*(rinv41+krsq-crf)
vctot = vctot+vcoul
fscal = (qq*(rinv41-2.0*krsq))*rinvsq
C Calculate temporary vectorial force
tx = fscal*dx41
ty = fscal*dy41
tz = fscal*dz41
C Increment i atom force
fix4 = fix4 + tx
fiy4 = fiy4 + ty
fiz4 = fiz4 + tz
C Decrement j atom force
faction(j3+0) = fjx1 - tx
faction(j3+1) = fjy1 - ty
faction(j3+2) = fjz1 - tz
C Inner loop uses 98 flops/iteration
end do
C Add i forces to mem and shifted force list
faction(ii3+3) = faction(ii3+3) + fix2
faction(ii3+4) = faction(ii3+4) + fiy2
faction(ii3+5) = faction(ii3+5) + fiz2
faction(ii3+6) = faction(ii3+6) + fix3
faction(ii3+7) = faction(ii3+7) + fiy3
faction(ii3+8) = faction(ii3+8) + fiz3
faction(ii3+9) = faction(ii3+9) + fix4
faction(ii3+10) = faction(ii3+10) + fiy4
faction(ii3+11) = faction(ii3+11) + fiz4
fshift(is3) = fshift(is3)+fix2+fix3+fix4
fshift(is3+1) = fshift(is3+1)+fiy2+fiy3+fiy4
fshift(is3+2) = fshift(is3+2)+fiz2+fiz3+fiz4
C Add potential energies to the group for this list
ggid = gid(n)+1
Vc(ggid) = Vc(ggid) + vctot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 28 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
C
C Gromacs nonbonded kernel f77skernel203nf
C Coulomb interaction: Reaction field
C VdW interaction: Not calculated
C water optimization: TIP4P - other atoms
C Calculate forces: no
C
subroutine f77skernel203nf(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
real*4 shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
real*4 charge(*),facel,krf,crf,Vc(*),vdwparam(*)
real*4 Vvdw(*),tabscale,VFtab(*)
real*4 invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
real*4 work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
real*4 shX,shY,shZ
real*4 jq
real*4 qq,vcoul,vctot
real*4 krsq
real*4 ix2,iy2,iz2
real*4 ix3,iy3,iz3
real*4 ix4,iy4,iz4
real*4 jx1,jy1,jz1
real*4 dx21,dy21,dz21,rsq21,rinv21
real*4 dx31,dy31,dz31,rsq31,rinv31
real*4 dx41,dy41,dz41,rsq41,rinv41
real*4 qH,qM
C Initialize water data
ii = iinr(1)+1
qH = facel*charge(ii+1)
qM = facel*charge(ii+3)
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call f77kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix2 = shX + pos(ii3+3)
iy2 = shY + pos(ii3+4)
iz2 = shZ + pos(ii3+5)
ix3 = shX + pos(ii3+6)
iy3 = shY + pos(ii3+7)
iz3 = shZ + pos(ii3+8)
ix4 = shX + pos(ii3+9)
iy4 = shY + pos(ii3+10)
iz4 = shZ + pos(ii3+11)
C Zero the potential energy for this list
vctot = 0
C Clear i atom forces
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx21 = ix2 - jx1
dy21 = iy2 - jy1
dz21 = iz2 - jz1
rsq21 = dx21*dx21+dy21*dy21+dz21*dz21
dx31 = ix3 - jx1
dy31 = iy3 - jy1
dz31 = iz3 - jz1
rsq31 = dx31*dx31+dy31*dy31+dz31*dz31
dx41 = ix4 - jx1
dy41 = iy4 - jy1
dz41 = iz4 - jz1
rsq41 = dx41*dx41+dy41*dy41+dz41*dz41
C Calculate 1/r and 1/r2
rinv21 = 1.0/sqrt(rsq21)
rinv31 = 1.0/sqrt(rsq31)
rinv41 = 1.0/sqrt(rsq41)
C Load parameters for j atom
jq = charge(jnr+0)
qq = qH*jq
C Coulomb reaction-field interaction
krsq = krf*rsq21
vcoul = qq*(rinv21+krsq-crf)
vctot = vctot+vcoul
C Load parameters for j atom
C Coulomb reaction-field interaction
krsq = krf*rsq31
vcoul = qq*(rinv31+krsq-crf)
vctot = vctot+vcoul
C Load parameters for j atom
qq = qM*jq
C Coulomb reaction-field interaction
krsq = krf*rsq41
vcoul = qq*(rinv41+krsq-crf)
vctot = vctot+vcoul
C Inner loop uses 56 flops/iteration
end do
C Add i forces to mem and shifted force list
C Add potential energies to the group for this list
ggid = gid(n)+1
Vc(ggid) = Vc(ggid) + vctot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 10 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/read_eof_all.f90 | 169 | 1987 | ! { dg-do run }
! PR43265 Followup patch for miscellaneous EOF conditions.
! Eaxamples from Tobius Burnus
use iso_fortran_env
character(len=2) :: str, str2(2)
integer :: a, b, c, ios
str = ''
str2 = ''
open(99,file='test.dat',access='stream',form='unformatted', status='replace')
write(99) ' '
close(99)
open(99,file='test.dat')
read(99, '(T7,i2)') i
close(99, status="delete")
if (i /= 0) call abort
read(str(1:0), '(T7,i1)') i
if (i /= 0) call abort
read(str,'(i2,/,i2)',end=111) a, b
call abort !stop 'ERROR: Expected EOF error (1)'
111 continue
read(str2,'(i2,/,i2)',end=112) a, b
read(str2,'(i2,/,i2,/,i2)',end=113) a, b, c
call abort !stop 'ERROR: Expected EOF error (2)'
112 call abort !stop 'ERROR: Unexpected EOF (3)'
113 continue
read(str,'(i2,/,i2)',end=121,pad='no') a, b
call abort !stop 'ERROR: Expected EOF error (1)'
121 continue
read(str2(:),'(i2,/,i2)', end=122, pad='no') a, b
goto 125
122 call abort !stop 'ERROR: Expected no EOF error (2)'
125 continue
read(str2(:),'(i2,/,i2,/,i2)',end=123,pad='no') a, b, c
call abort !stop 'ERROR: Expected EOF error (3)'
123 continue
read(str(2:1),'(i2,/,i2)',end=131, pad='no') a, b
call abort !stop 'ERROR: Expected EOF error (1)'
131 continue
read(str2(:)(2:1),'(i2,/,i2)',end=132, pad='no') a, b
call abort !stop 'ERROR: Expected EOF error (2)'
132 continue
read(str2(:)(2:1),'(i2,/,i2,/,i2)',end=133,pad='no') a, b, c
call abort !stop 'ERROR: Expected EOF error (3)'
133 continue
read(str(2:1),'(i2,/,i2)',iostat=ios, pad='no') a, b
if (ios /= IOSTAT_END) call abort !stop 'ERROR: expected iostat /= 0 (1)'
read(str2(:)(2:1),'(i2,/,i2)',iostat=ios, pad='no') a, b
if (ios /= IOSTAT_END) call abort !stop 'ERROR: expected iostat /= 0 (2)'
read(str2(:)(2:1),'(i2,/,i2,/,i2)',iostat=ios,pad='no') a, b, c
if (ios /= IOSTAT_END) call abort !stop 'ERROR: expected iostat /= 0 (2)'
! print *, "success"
end
| gpl-2.0 |
dbarbier/privot | lib/src/BlasLapack/dlabad.f | 10 | 1886 | SUBROUTINE DLABAD( SMALL, LARGE )
*
* -- 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 ..
DOUBLE PRECISION LARGE, SMALL
* ..
*
* Purpose
* =======
*
* DLABAD takes as input the values computed by DLAMCH for underflow and
* overflow, and returns the square root of each of these values if the
* log of LARGE is sufficiently large. This subroutine is intended to
* identify machines with a large exponent range, such as the Crays, and
* redefine the underflow and overflow limits to be the square roots of
* the values computed by DLAMCH. This subroutine is needed because
* DLAMCH does not compensate for poor arithmetic in the upper half of
* the exponent range, as is found on a Cray.
*
* Arguments
* =========
*
* SMALL (input/output) DOUBLE PRECISION
* On entry, the underflow threshold as computed by DLAMCH.
* On exit, if LOG10(LARGE) is sufficiently large, the square
* root of SMALL, otherwise unchanged.
*
* LARGE (input/output) DOUBLE PRECISION
* On entry, the overflow threshold as computed by DLAMCH.
* On exit, if LOG10(LARGE) is sufficiently large, the square
* root of LARGE, otherwise unchanged.
*
* =====================================================================
*
* .. Intrinsic Functions ..
INTRINSIC LOG10, SQRT
* ..
* .. Executable Statements ..
*
* If it looks like we're on a Cray, take the square root of
* SMALL and LARGE to avoid overflow and underflow problems.
*
IF( LOG10( LARGE ).GT.2000.D0 ) THEN
SMALL = SQRT( SMALL )
LARGE = SQRT( LARGE )
END IF
*
RETURN
*
* End of DLABAD
*
END
| lgpl-3.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/maxval_char_2.f90 | 19 | 1178 | ! { dg-do run }
program main
implicit none
integer, parameter :: n=5, m=3
character(kind=4,len=5), dimension(n) :: a
character(kind=4,len=5), dimension(n,m) :: b
character(kind=4,len=5) :: res
integer, dimension(n,m) :: v
real, dimension(n,m) :: r
integer :: i,j
logical, dimension(n,m) :: mask
character(kind=4,len=5), dimension(:,:), allocatable :: empty
character(kind=4,len=5) , parameter :: all_zero = achar(0) // achar(0) // achar(0) // achar(0) // achar(0)
logical :: smask
write (unit=a,fmt='(I5.5)') (21-i*i+6*i,i=1,n)
res = maxval(a)
if (res /= 4_'00030') STOP 1
do
call random_number(r)
v = int(r * 100)
if (count(v > 20) > 1) exit
end do
write (unit=b,fmt='(I5.5)') v
write (unit=res,fmt='(I5.5)') maxval(v)
if (res /= maxval(b)) STOP 2
smask = .true.
if (res /= maxval(b, smask)) STOP 3
smask = .false.
if (all_zero /= maxval(b, smask)) STOP 4
mask = v > 20
write (unit=res,fmt='(I5.5)') maxval(v,mask)
if (res /= maxval(b, mask)) STOP 5
mask = .false.
if (maxval(b, mask) /= all_zero) STOP 6
allocate (empty(0:3,0))
res = maxval(empty)
if (res /= all_zero) STOP 7
end program main
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/elemental_subroutine_11.f90 | 19 | 7124 | ! { dg-do run }
!
! Check error of pr65894 are fixed.
! Contributed by Juergen Reuter <juergen.reuter@desy.de>
! Andre Vehreschild <vehre@gcc.gnu.org>
module simple_string
! Minimal iso_varying_string implementation needed.
implicit none
type string_t
private
character(len=1), dimension(:), allocatable :: cs
end type string_t
contains
elemental function var_str(c) result (s)
character(*), intent(in) :: c
type(string_t) :: s
integer :: l,i
l = len(c)
allocate(s%cs(l))
forall(i = 1:l)
s%cs(i) = c(i:i)
end forall
end function var_str
end module simple_string
module model_data
use simple_string
implicit none
private
public :: field_data_t
public :: model_data_t
type :: field_data_t
!private
integer :: pdg = 0
type(string_t), dimension(:), allocatable :: name
contains
procedure :: init => field_data_init
procedure :: get_pdg => field_data_get_pdg
end type field_data_t
type :: model_data_t
!private
type(string_t) :: name
type(field_data_t), dimension(:), allocatable :: field
contains
generic :: init => model_data_init
procedure, private :: model_data_init
generic :: get_pdg => &
model_data_get_field_pdg_index
procedure, private :: model_data_get_field_pdg_index
generic :: get_field_ptr => &
model_data_get_field_ptr_pdg
procedure, private :: model_data_get_field_ptr_pdg
procedure :: get_field_ptr_by_index => model_data_get_field_ptr_index
procedure :: init_sm_test => model_data_init_sm_test
end type model_data_t
contains
subroutine field_data_init (prt, pdg)
class(field_data_t), intent(out) :: prt
integer, intent(in) :: pdg
prt%pdg = pdg
end subroutine field_data_init
elemental function field_data_get_pdg (prt) result (pdg)
integer :: pdg
class(field_data_t), intent(in) :: prt
pdg = prt%pdg
end function field_data_get_pdg
subroutine model_data_init (model, name, &
n_field)
class(model_data_t), intent(out) :: model
type(string_t), intent(in) :: name
integer, intent(in) :: n_field
model%name = name
allocate (model%field (n_field))
end subroutine model_data_init
function model_data_get_field_pdg_index (model, i) result (pdg)
class(model_data_t), intent(in) :: model
integer, intent(in) :: i
integer :: pdg
pdg = model%field(i)%get_pdg ()
end function model_data_get_field_pdg_index
function model_data_get_field_ptr_pdg (model, pdg, check) result (ptr)
class(model_data_t), intent(in), target :: model
integer, intent(in) :: pdg
logical, intent(in), optional :: check
type(field_data_t), pointer :: ptr
integer :: i, pdg_abs
if (pdg == 0) then
ptr => null ()
return
end if
pdg_abs = abs (pdg)
if (lbound(model%field, 1) /= 1) STOP 1
if (ubound(model%field, 1) /= 19) STOP 2
do i = 1, size (model%field)
if (model%field(i)%get_pdg () == pdg_abs) then
ptr => model%field(i)
return
end if
end do
ptr => null ()
end function model_data_get_field_ptr_pdg
function model_data_get_field_ptr_index (model, i) result (ptr)
class(model_data_t), intent(in), target :: model
integer, intent(in) :: i
type(field_data_t), pointer :: ptr
if (lbound(model%field, 1) /= 1) STOP 3
if (ubound(model%field, 1) /= 19) STOP 4
ptr => model%field(i)
end function model_data_get_field_ptr_index
subroutine model_data_init_sm_test (model)
class(model_data_t), intent(out) :: model
type(field_data_t), pointer :: field
integer, parameter :: n_field = 19
call model%init (var_str ("SM_test"), &
n_field)
field => model%get_field_ptr_by_index (1)
call field%init (1)
end subroutine model_data_init_sm_test
end module model_data
module flavors
use model_data
implicit none
private
public :: flavor_t
type :: flavor_t
private
integer :: f = 0
type(field_data_t), pointer :: field_data => null ()
contains
generic :: init => &
flavor_init0_model
procedure, private :: flavor_init0_model
end type flavor_t
contains
impure elemental subroutine flavor_init0_model (flv, f, model)
class(flavor_t), intent(inout) :: flv
integer, intent(in) :: f
class(model_data_t), intent(in), target :: model
! Check the field l/ubound at various stages, because w/o the patch
! the bounds get mixed up.
if (lbound(model%field, 1) /= 1) STOP 5
if (ubound(model%field, 1) /= 19) STOP 6
flv%f = f
flv%field_data => model%get_field_ptr (f, check=.true.)
end subroutine flavor_init0_model
end module flavors
module beams
use model_data
use flavors
implicit none
private
public :: beam_1
public :: beam_2
contains
subroutine beam_1 (u)
integer, intent(in) :: u
type(flavor_t), dimension(2) :: flv
real, dimension(2) :: pol_f
type(model_data_t), target :: model
call model%init_sm_test ()
call flv%init ([1,-1], model)
pol_f(1) = 0.5
end subroutine beam_1
subroutine beam_2 (u, model)
integer, intent(in) :: u
type(flavor_t), dimension(2) :: flv
real, dimension(2) :: pol_f
class(model_data_t), intent(in), target :: model
call flv%init ([1,-1], model)
pol_f(1) = 0.5
end subroutine beam_2
end module beams
module evaluators
! This module is just here for a compile check.
implicit none
private
type :: quantum_numbers_mask_t
contains
generic :: operator(.or.) => quantum_numbers_mask_or
procedure, private :: quantum_numbers_mask_or
end type quantum_numbers_mask_t
type :: index_map_t
integer, dimension(:), allocatable :: entry
end type index_map_t
type :: prt_mask_t
logical, dimension(:), allocatable :: entry
end type prt_mask_t
type :: qn_mask_array_t
type(quantum_numbers_mask_t), dimension(:), allocatable :: mask
end type qn_mask_array_t
contains
elemental function quantum_numbers_mask_or (mask1, mask2) result (mask)
type(quantum_numbers_mask_t) :: mask
class(quantum_numbers_mask_t), intent(in) :: mask1, mask2
end function quantum_numbers_mask_or
subroutine make_product_interaction &
(prt_is_connected, qn_mask_in, qn_mask_rest)
type(prt_mask_t), dimension(2), intent(in) :: prt_is_connected
type(qn_mask_array_t), dimension(2), intent(in) :: qn_mask_in
type(quantum_numbers_mask_t), intent(in) :: qn_mask_rest
type(index_map_t), dimension(2) :: prt_index_in
integer :: i
type(quantum_numbers_mask_t), dimension(:), allocatable :: qn_mask
allocate (qn_mask (2))
do i = 1, 2
qn_mask(prt_index_in(i)%entry) = &
pack (qn_mask_in(i)%mask, prt_is_connected(i)%entry) &
.or. qn_mask_rest
! Without the patch above line produced an ICE.
end do
end subroutine make_product_interaction
end module evaluators
program main
use beams
use model_data
type(model_data_t) :: model
call model%init_sm_test()
call beam_1 (6)
call beam_2 (6, model)
end program main
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/random_init_3.f90 | 17 | 1956 | ! { dg-do run }
! { dg-options "-fcoarray=single" }
program rantest
implicit none
logical, parameter :: debug = .false.
character(len=20) name
integer fd, i, n
integer, allocatable :: n1(:), n2(:), n3(:)
real x(4), y(4), z(4)
if (debug) then
write(name,'(A,I0)') 'dat', this_image()
open(newunit=fd, file=name)
end if
call random_seed(size=n)
allocate(n1(n), n2(n), n3(n))
!
! Setup repeatable sequences (if co-arrays the seeds should be distinct
! are different). Get the seeds.
!
call random_init(.true., .true.)
call random_seed(get=n1)
call random_number(x) ! This changes internal state.
if (debug) then
write(fd,'(A,4F12.6)') 'x = ', x
end if
call random_seed(get=n2) ! Grab current state.
!
! Use the gotten seed to reseed PRNG and grab sequence.
! It should be the same sequence.
!
call random_seed(put=n1)
call random_number(y)
if (debug) then
write(fd,'(A,4F12.6)') 'y = ', y
end if
!
! Setup repeatable sequences (if co-arrays the seeds should be distinct
! are different). Get the seeds. It should be the same sequence.
!
call random_init(.true., .true.)
call random_seed(get=n3)
call random_number(z)
if (debug) then
write(fd,'(A,4F12.6)') 'z = ', z
end if
x = int(1e6*x) ! Convert to integer with at most 6 digits.
y = int(1e6*y) ! Convert to integer with at most 6 digits.
z = int(1e6*z) ! Convert to integer with at most 6 digits.
if (any(x /= y)) call abort
if (any(x /= z)) call abort
if (debug) then
write(fd,*)
do i = 1, n
if (n1(i) - n2(i) /= 0) then
write(fd,*) 'n1 /= n2', i, n1(i), n2(i)
end if
end do
write(fd,*)
do i = 1, n
if (n1(i) - n3(i) /= 0) then
write(fd,*) 'n1 /= n3', i, n1(i), n3(i)
end if
end do
end if
end program rantest
| gpl-2.0 |
kito-cheng/riscv-gcc | libgfortran/generated/_sqrt_r4.F90 | 3 | 1473 | ! Copyright (C) 2002-2019 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_SQRTF
elemental function _gfortran_specific__sqrt_r4 (parm)
real (kind=4), intent (in) :: parm
real (kind=4) :: _gfortran_specific__sqrt_r4
_gfortran_specific__sqrt_r4 = sqrt (parm)
end function
#endif
#endif
| gpl-2.0 |
bgin/MissileSimulation | External/FFTPACK/sinqmi.f | 1 | 2536 | C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C * *
C * copyright (c) 2011 by UCAR *
C * *
C * University Corporation for Atmospheric Research *
C * *
C * all rights reserved *
C * *
C * FFTPACK version 5.1 *
C * *
C * A Fortran Package of Fast Fourier *
C * *
C * Subroutines and Example Programs *
C * *
C * by *
C * *
C * Paul Swarztrauber and Dick Valent *
C * *
C * of *
C * *
C * the National Center for Atmospheric Research *
C * *
C * Boulder, Colorado (80307) U.S.A. *
C * *
C * which is sponsored by *
C * *
C * the National Science Foundation *
C * *
C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
SUBROUTINE SINQMI (N, WSAVE, LENSAV, IER)
INTEGER N, LENSAV, IER
REAL WSAVE(LENSAV)
C
IER = 0
C
IF (LENSAV .LT. 2*N + INT(LOG(REAL(N))/LOG(2.)) +4) THEN
IER = 2
CALL XERFFT ('SINQMI', 3)
GO TO 300
ENDIF
C
CALL COSQMI (N, WSAVE, LENSAV, IER1)
IF (IER1 .NE. 0) THEN
IER = 20
CALL XERFFT ('SINQMI',-5)
ENDIF
300 CONTINUE
RETURN
END
| mit |
ars599/mom5 | src/atmos_param/cosp/cosp_io.F90 | 3 | 92481 | #include "cosp_defs.H"
#ifdef COSP_GFDL
!---------------------------------------------------------------------
!------------ FMS version number and tagname for this file -----------
! $Id: cosp_io.F90,v 20.0 2013/12/13 23:15:43 fms Exp $
! $Name: tikal $
! cosp_version = 1.3.2
#endif
! (c) British Crown Copyright 2008, the Met Office.
! All rights reserved.
!
! Redistribution and use in source and binary forms, with or without modification, are permitted
! provided that the following conditions are met:
!
! * Redistributions of source code must retain the above copyright notice, this list
! of conditions and the following disclaimer.
! * Redistributions in binary form must reproduce the above copyright notice, this list
! of conditions and the following disclaimer in the documentation and/or other materials
! provided with the distribution.
! * Neither the name of the Met Office nor the names of its contributors may be used
! to endorse or promote products derived from this software without specific prior written
! permission.
!
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
! IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
! CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
! IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
! OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!
! History:
! Jul 2008 - A. Bodas-Salcedo - Initial version
! Oct 2008 - S. Bony - In nc_write_cosp_1d and nc_write_cosp_2d :
! the label of layered cloud fractions was wrong -> corrected
! (before: low was actually mid, mid was high, high was total,
! total was low)
! Sep 2009 - A. Bodas-Salcedo - CMIP5 variable names implemented
!
!#include "cosp_defs.h"
#ifndef COSP_GFDL
#include "cosp_defs.h"
#endif
MODULE MOD_COSP_IO
USE MOD_COSP_CONSTANTS
USE MOD_COSP_TYPES
#ifndef COSP_GFDL
USE cmor_users_functions
#endif
USE netcdf
use MOD_COSP_Modis_Simulator
#ifdef COSP_GFDL
use mpp_mod, only: input_nml_file
use fms_mod, only: open_namelist_file, open_file, close_file, &
file_exist, mpp_pe, mpp_root_pe, &
error_mesg, FATAL, &
check_nml_error, write_version_number, stdlog
#endif
IMPLICIT NONE
#ifdef COSP_GFDL
!---------------------------------------------------------------------
!----------- version number for this module --------------------------
character(len=128) :: versiona = '$Id: cosp_io.F90,v 20.0 2013/12/13 23:15:43 fms Exp $'
character(len=128) :: tagnamea = '$Name: tikal $'
#endif
! Types to be used as arrays of pointers
TYPE var1d
character(len=16) :: name
character(len=16) :: units
integer :: dimsid(3)
integer :: dimssz(2)
real,pointer,dimension(:) :: pntr
END TYPE
TYPE var2d
character(len=16) :: name
character(len=16) :: units
integer :: dimsid(4)
integer :: dimssz(3)
real,pointer,dimension(:,:) :: pntr
END TYPE
TYPE var3d
character(len=16) :: name
character(len=16) :: units
integer :: dimsid(5)
integer :: dimssz(4)
real,pointer,dimension(:,:,:) :: pntr
END TYPE
CONTAINS
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!----------------- SUBROUTINE CONSTRUCT_VAR1D --------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE CONSTRUCT_VAR1D(name,dimsid,dimssz,pntr,y,units)
! Input arguments
character(len=*),intent(in) :: name
integer,intent(in) :: dimsid(3)
integer,intent(in) :: dimssz(2)
real,dimension(:),target,intent(in) :: pntr
type(var1d),intent(out) :: y
character(len=*),optional,intent(in) :: units
y%name = name
if (present(units)) y%units = units
y%dimsid = dimsid
y%dimssz = dimssz
y%pntr => pntr
END SUBROUTINE CONSTRUCT_VAR1D
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!----------------- SUBROUTINE CONSTRUCT_VAR2D --------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE CONSTRUCT_VAR2D(name,dimsid,dimssz,pntr,y,units)
! Input arguments
character(len=*),intent(in) :: name
integer,intent(in) :: dimsid(4)
integer,intent(in) :: dimssz(3)
real,dimension(:,:),target,intent(in) :: pntr
type(var2d),intent(out) :: y
character(len=*),optional,intent(in) :: units
y%name = name
if (present(units)) y%units = units
y%dimsid = dimsid
y%dimssz = dimssz
y%pntr => pntr
END SUBROUTINE CONSTRUCT_VAR2D
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!----------------- SUBROUTINE CONSTRUCT_VAR3D --------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE CONSTRUCT_VAR3D(name,dimsid,dimssz,pntr,y,units)
! Input arguments
character(len=*),intent(in) :: name
integer,intent(in) :: dimsid(5)
integer,intent(in) :: dimssz(4)
real,dimension(:,:,:),target,intent(in) :: pntr
type(var3d),intent(out) :: y
character(len=*),optional,intent(in) :: units
y%name = name
if (present(units)) y%units = units
y%dimsid = dimsid
y%dimssz = dimssz
y%pntr => pntr
END SUBROUTINE CONSTRUCT_VAR3D
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!----------------- SUBROUTINE MAP_POINT_TO_LL---------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE MAP_POINT_TO_LL(Nx,Ny,geomode,x1,x2,x3,x4,y2,y3,y4,y5)
! Input arguments
integer,intent(in) :: Nx,Ny,geomode
real,intent(in),optional :: x1(:),x2(:,:),x3(:,:,:), &
x4(:,:,:,:)
real,intent(out),optional :: y2(:,:),y3(:,:,:), &
y4(:,:,:,:),y5(:,:,:,:,:)
! Local variables
integer :: Npoints
integer :: px(Nx*Ny),py(Nx*Ny)
integer :: i,j,k,l,m
integer :: Ni,Nj,Nk,Nl
integer :: Mi,Mj,Mk,Ml,Mm
character(len=128) :: proname='MAP_POINT_TO_LL'
Npoints = Nx*Ny
px=0
py=0
! Obtain pointers to do the mapping
if (geomode == 2) then ! (lon,lat) mode
do j=1,Ny
do i=1,Nx
k = (j-1)*Nx+i
px(k) = i
py(k) = j
enddo
enddo
else if (geomode == 3) then ! (lon,lat) mode
do j=1,Nx
do i=1,Ny
k = (j-1)*Ny+i
px(k) = j
py(k) = i
enddo
enddo
else
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': geomode not supported, ', &
FATAL)
#else
print *, ' -- '//trim(proname)//': geomode not supported, ',geomode
stop
#endif
endif
if (present(x1).and.present(y2)) then
Ni = size(x1,1)
Mi = size(y2,1)
Mj = size(y2,2)
if (Mi*Mj /= Ni) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 1)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 1)'
stop
#endif
endif
do i=1,Npoints
y2(px(i),py(i)) = x1(i)
enddo
else if (present(x2).and.present(y3)) then
Ni = size(x2,1)
Nj = size(x2,2)
Mi = size(y3,1)
Mj = size(y3,2)
Mk = size(y3,3)
if (Mi*Mj /= Ni) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 2)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 2)'
stop
#endif
endif
if (Nj /= Mk) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nj /= Mk (opt 2)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nj /= Mk (opt 2)'
stop
#endif
endif
do k=1,Mk
do i=1,Npoints
y3(px(i),py(i),k) = x2(i,k)
enddo
enddo
else if (present(x3).and.present(y4)) then
Ni = size(x3,1)
Nj = size(x3,2)
Nk = size(x3,3)
Mi = size(y4,1)
Mj = size(y4,2)
Mk = size(y4,3)
Ml = size(y4,4)
if (Mi*Mj /= Ni) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 3)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 3)'
stop
#endif
endif
if (Nj /= Mk) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nj /= Mk (opt 3)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nj /= Mk (opt 3)'
stop
#endif
endif
if (Nk /= Ml) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nk /= Ml (opt 3)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nk /= Ml (opt 3)'
stop
#endif
endif
do l=1,Ml
do k=1,Mk
do i=1,Npoints
y4(px(i),py(i),k,l) = x3(i,k,l)
enddo
enddo
enddo
else if (present(x4).and.present(y5)) then
Ni = size(x4,1)
Nj = size(x4,2)
Nk = size(x4,3)
Nl = size(x4,4)
Mi = size(y5,1)
Mj = size(y5,2)
Mk = size(y5,3)
Ml = size(y5,4)
Mm = size(y5,5)
if (Mi*Mj /= Ni) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat /= Npoints (opt 4)'
stop
#endif
endif
if (Nj /= Mk) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nj /= Mk (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nj /= Mk (opt 4)'
stop
#endif
endif
if (Nk /= Ml) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nk /= Ml (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nk /= Ml (opt 4)'
stop
#endif
endif
if (Nl /= Mm) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': Nl /= Mm (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nl /= Mm (opt 4)'
stop
#endif
endif
do m=1,Mm
do l=1,Ml
do k=1,Mk
do i=1,Npoints
y5(px(i),py(i),k,l,m) = x4(i,k,l,m)
enddo
enddo
enddo
enddo
else
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_point_to_ll', &
' -- '//trim(proname)//': wrong option', &
FATAL)
#else
print *, ' -- '//trim(proname)//': wrong option'
stop
#endif
endif
END SUBROUTINE MAP_POINT_TO_LL
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!----------------- SUBROUTINE MAP_LL_TO_POINT---------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE MAP_LL_TO_POINT(Nx,Ny,Np,x2,x3,x4,x5,y1,y2,y3,y4)
! Input arguments
integer,intent(in) :: Nx,Ny,Np
real,intent(in),optional :: x2(:,:),x3(:,:,:), &
x4(:,:,:,:),x5(:,:,:,:,:)
real,intent(out),optional :: y1(:),y2(:,:),y3(:,:,:), &
y4(:,:,:,:)
! Local variables
integer :: px(Nx*Ny),py(Nx*Ny)
integer :: i,j,k,l,m
integer :: Ni,Nj,Nk,Nl,Nm
integer :: Mi,Mj,Mk,Ml
character(len=128) :: proname='MAP_LL_TO_POINT'
px=0
py=0
if (Nx*Ny < Np) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nx*Ny < Np', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nx*Ny < Np'
stop
#endif
endif
do j=1,Ny
do i=1,Nx
k = (j-1)*Nx+i
px(k) = i
py(k) = j
enddo
enddo
if (present(x2).and.present(y1)) then
Ni = size(x2,1)
Nj = size(x2,2)
Mi = size(y1,1)
if (Ni*Nj < Mi) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 1)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 1)'
stop
#endif
endif
do j=1,Np
y1(j) = x2(px(j),py(j))
enddo
else if (present(x3).and.present(y2)) then
Ni = size(x3,1)
Nj = size(x3,2)
Nk = size(x3,3)
Mi = size(y2,1)
Mj = size(y2,2)
if (Ni*Nj < Mi) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 2)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 2)'
stop
#endif
endif
if (Nk /= Mj) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nk /= Mj (opt 2)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nk /= Mj (opt 2)'
stop
#endif
endif
do k=1,Nk
do j=1,Np
y2(j,k) = x3(px(j),py(j),k)
enddo
enddo
else if (present(x4).and.present(y3)) then
Ni = size(x4,1)
Nj = size(x4,2)
Nk = size(x4,3)
Nl = size(x4,4)
Mi = size(y3,1)
Mj = size(y3,2)
Mk = size(y3,3)
if (Ni*Nj < Mi) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 3)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 3)'
stop
#endif
endif
if (Nk /= Mj) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nk /= Mj (opt 3)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nk /= Mj (opt 3)'
stop
#endif
endif
if (Nl /= Mk) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nl /= Mk (opt 3)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nl /= Mk (opt 3)'
stop
#endif
endif
do l=1,Nl
do k=1,Nk
do j=1,Np
y3(j,k,l) = x4(px(j),py(j),k,l)
enddo
enddo
enddo
else if (present(x5).and.present(y4)) then
Ni = size(x5,1)
Nj = size(x5,2)
Nk = size(x5,3)
Nl = size(x5,4)
Nm = size(x5,5)
Mi = size(y4,1)
Mj = size(y4,2)
Mk = size(y4,3)
Ml = size(y4,4)
if (Ni*Nj < Mi) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nlon*Nlat < Npoints (opt 4)'
stop
#endif
endif
if (Nk /= Mj) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nk /= Mj (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nk /= Mj (opt 4)'
stop
#endif
endif
if (Nl /= Mk) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nl /= Mk (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nl /= Mk (opt 4)'
stop
#endif
endif
if (Nm /= Ml) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': Nm /= Ml (opt 4)', &
FATAL)
#else
print *, ' -- '//trim(proname)//': Nm /= Ml (opt 4)'
stop
#endif
endif
do m=1,Nm
do l=1,Nl
do k=1,Nk
do j=1,Np
y4(j,k,l,m) = x5(px(j),py(j),k,l,m)
enddo
enddo
enddo
enddo
else
#ifdef COSP_GFDL
call error_mesg ('cosp_io:map_ll_to_point', &
' -- '//trim(proname)//': wrong option', &
FATAL)
#else
print *, ' -- '//trim(proname)//': wrong option'
stop
#endif
endif
END SUBROUTINE MAP_LL_TO_POINT
#ifndef COSP_GFDL
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!----------------- SUBROUTINE NC_READ_INPUT_FILE -----------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE NC_READ_INPUT_FILE(fname,Npnts,Nl,Nhydro,lon,lat,p,ph,z,zh,T,qv,rh,tca,cca, &
mr_lsliq,mr_lsice,mr_ccliq,mr_ccice,fl_lsrain,fl_lssnow,fl_lsgrpl, &
fl_ccrain,fl_ccsnow,Reff,dtau_s,dtau_c,dem_s,dem_c,skt,landmask,sfc_height, &
mr_ozone,u_wind,v_wind,sunlit,emsfc_lw,mode,Nlon,Nlat,verbosity)
!Arguments
character(len=512),intent(in) :: fname ! File name
integer,intent(in) :: Npnts,Nl,Nhydro
real,dimension(Npnts),intent(out) :: lon,lat
real,dimension(Npnts,Nl),target,intent(out) :: p,ph,z,zh,T,qv,rh,tca,cca, &
mr_lsliq,mr_lsice,mr_ccliq,mr_ccice,fl_lsrain,fl_lssnow,fl_lsgrpl, &
fl_ccrain,fl_ccsnow,dtau_s,dtau_c,dem_s,dem_c,mr_ozone
real,dimension(Npnts,Nl,Nhydro),intent(out) :: Reff
real,dimension(Npnts),intent(out) :: skt,landmask,sfc_height,u_wind,v_wind,sunlit
real,intent(out) :: emsfc_lw
integer,intent(out) :: mode,Nlon,Nlat
integer,optional :: verbosity
!Local variables
integer :: Npoints,Nlevels,i,j,k
character(len=128) :: vname
integer,parameter :: NMAX_DIM=5
integer :: vrank,vdimid(NMAX_DIM)
character(len=256) :: dimname(NMAX_DIM) ! 256 hardcoded, instead of MAXNCNAM. This works for NetCDF 3 and 4.
integer :: ncid,vid,ndims,nvars,ngatts,recdim,dimsize(NMAX_DIM)
integer :: errst
logical :: Llat,Llon,Lpoint
integer :: Na,Nb,Nc,Nd,Ne
real,dimension(Npnts) :: ll
integer,dimension(:),allocatable :: plon,plat
real,allocatable :: x1(:),x2(:,:),x3(:,:,:),x4(:,:,:,:),x5(:,:,:,:,:) ! Temporary arrays
character(len=64) :: routine_name='NC_READ_INPUT_FILE'
character(len=128) :: errmsg,straux
mode = 0
Nlon = 0
Nlat = 0
Npoints = Npnts
Nlevels = Nl
! Open file
errst = nf90_open(fname, nf90_nowrite, ncid)
if (errst /= 0) then
errmsg="Couldn't open "//trim(fname)
call cosp_error(routine_name,errmsg)
endif
! Get information about dimensions. Curtain mode or lat/lon mode?
Llat =.false.
Llon =.false.
Lpoint=.false.
errst = nf90_inquire(ncid, ndims, nvars, ngatts, recdim)
if (errst /= 0) then
errmsg="Error in nf90_inquire"
call cosp_error(routine_name,errmsg,errcode=errst)
endif
do i = 1,ndims
errst = nf90_Inquire_Dimension(ncid,i,name=dimname(i),len=dimsize(i))
if (errst /= 0) then
write(straux, *) i
errmsg="Error in nf90_Inquire_Dimension, i: "//trim(straux)
call cosp_error(routine_name,errmsg)
endif
if ((trim(dimname(i)).eq.'level').and.(Nlevels > dimsize(i))) then
errmsg='Number of levels selected is greater than in input file '//trim(fname)
call cosp_error(routine_name,errmsg)
endif
if (trim(dimname(i)).eq.'point') then
Lpoint = .true.
if (Npnts > dimsize(i)) then
errmsg='Number of points selected is greater than in input file '//trim(fname)
call cosp_error(routine_name,errmsg)
endif
endif
if (trim(dimname(i)).eq.'lon') then
Llon = .true.
Nlon = dimsize(i)
endif
if (trim(dimname(i)).eq.'lat') then
Llat = .true.
Nlat = dimsize(i)
endif
enddo
! Get lon and lat
if (Llon.and.Llat) then ! 2D mode
if ((Npnts) > Nlon*Nlat) Npoints=Nlon*Nlat
lon = R_UNDEF
lat = R_UNDEF
mode = 2 ! Don't know yet if (lon,lat) or (lat,lon) at this point
else if (Lpoint) then ! 1D mode
Nlon = Npoints
Nlat = Npoints
mode = 1
else
errmsg= trim(fname)//' file contains wrong dimensions'
call cosp_error(routine_name,errmsg)
endif
errst = nf90_inq_varid(ncid, 'lon', vid)
if (errst /= 0) then
errmsg="Error in nf90_inq_varid, var: lon"
call cosp_error(routine_name,errmsg,errcode=errst)
endif
errst = nf90_get_var(ncid, vid, lon, start = (/1/), count = (/Nlon/))
if (errst /= 0) then
errmsg="Error in nf90_get_var, var: lon"
call cosp_error(routine_name,errmsg,errcode=errst)
endif
errst = nf90_inq_varid(ncid, 'lat', vid)
if (errst /= 0) then
errmsg="Error in nf90_inq_varid, var: lat"
call cosp_error(routine_name,errmsg,errcode=errst)
endif
errst = nf90_get_var(ncid, vid, lat, start = (/1/), count = (/Nlat/))
if (errst /= 0) then
errmsg="Error in nf90_get_var, var: lat"
call cosp_error(routine_name,errmsg,errcode=errst)
endif
! Get all variables
do vid = 1,nvars
vdimid=0
errst = nf90_Inquire_Variable(ncid, vid, name=vname, ndims=vrank, dimids=vdimid)
if (errst /= 0) then
write(straux, *) vid
errmsg='Error in nf90_Inquire_Variable, vid '//trim(straux)
call cosp_error(routine_name,errmsg,errcode=errst)
endif
! Read in into temporary array of correct shape
if (present(verbosity).and.(verbosity == 1)) print *, 'Reading '//trim(vname)//' ...'
if (vrank == 1) then
Na = dimsize(vdimid(1))
allocate(x1(Na))
errst = nf90_get_var(ncid, vid, x1, start=(/1/), count=(/Na/))
endif
if (vrank == 2) then
Na = dimsize(vdimid(1))
Nb = dimsize(vdimid(2))
allocate(x2(Na,Nb))
errst = nf90_get_var(ncid, vid, x2, start=(/1,1/), count=(/Na,Nb/))
endif
if (vrank == 3) then
Na = dimsize(vdimid(1))
Nb = dimsize(vdimid(2))
Nc = dimsize(vdimid(3))
allocate(x3(Na,Nb,Nc))
errst = nf90_get_var(ncid, vid, x3, start=(/1,1,1/), count=(/Na,Nb,Nc/))
if ((mode == 2).or.(mode == 3)) then
if ((Na == Nlon).and.(Nb == Nlat)) then
mode = 2
else if ((Na == Nlat).and.(Nb == Nlon)) then
mode = 3
else
errmsg='Wrong mode for variable '//trim(vname)
call cosp_error(routine_name,errmsg)
endif
endif
endif
if (vrank == 4) then
Na = dimsize(vdimid(1))
Nb = dimsize(vdimid(2))
Nc = dimsize(vdimid(3))
Nd = dimsize(vdimid(4))
allocate(x4(Na,Nb,Nc,Nd))
errst = nf90_get_var(ncid, vid, x4, start=(/1,1,1,1/), count=(/Na,Nb,Nc,Nd/))
endif
if (vrank == 5) then
Na = dimsize(vdimid(1))
Nb = dimsize(vdimid(2))
Nc = dimsize(vdimid(3))
Nd = dimsize(vdimid(4))
Ne = dimsize(vdimid(5))
allocate(x5(Na,Nb,Nc,Nd,Ne))
errst = nf90_get_var(ncid, vid, x5, start=(/1,1,1,1,1/), count=(/Na,Nb,Nc,Nd,Ne/))
endif
if (errst /= 0) then
write(straux, *) vid
errmsg='Error in nf90_get_var, vid '//trim(straux)
call cosp_error(routine_name,errmsg,errcode=errst)
endif
! Map to the right input argument
select case (trim(vname))
case ('pfull')
if (Lpoint) then
p(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=p)
endif
case ('phalf')
if (Lpoint) then
ph(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=ph)
endif
case ('height')
if (Lpoint) then
z(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=z)
endif
case ('height_half')
if (Lpoint) then
zh(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=zh)
endif
case ('T_abs')
if (Lpoint) then
T(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=T)
endif
case ('qv')
if (Lpoint) then
qv(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=qv)
endif
case ('rh')
if (Lpoint) then
rh(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=rh)
endif
case ('tca')
if (Lpoint) then
tca(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=tca)
endif
tca = tca
case ('cca')
if (Lpoint) then
cca(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=cca)
endif
cca = cca
case ('mr_lsliq')
if (Lpoint) then
mr_lsliq(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_lsliq)
endif
case ('mr_lsice')
if (Lpoint) then
mr_lsice(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_lsice)
endif
case ('mr_ccliq')
if (Lpoint) then
mr_ccliq(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_ccliq)
endif
case ('mr_ccice')
if (Lpoint) then
mr_ccice(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_ccice)
endif
case ('fl_lsrain')
if (Lpoint) then
fl_lsrain(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_lsrain)
endif
case ('fl_lssnow')
if (Lpoint) then
fl_lssnow(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_lssnow)
endif
case ('fl_lsgrpl')
if (Lpoint) then
fl_lsgrpl(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_lsgrpl)
endif
case ('fl_ccrain')
if (Lpoint) then
fl_ccrain(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_ccrain)
endif
case ('fl_ccsnow')
if (Lpoint) then
fl_ccsnow(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_ccsnow)
endif
case ('dtau_s')
if (Lpoint) then
dtau_s(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dtau_s)
endif
case ('dtau_c')
if (Lpoint) then
dtau_c(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dtau_c)
endif
case ('dem_s')
if (Lpoint) then
dem_s(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dem_s)
endif
case ('dem_c')
if (Lpoint) then
dem_c(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dem_c)
endif
case ('Reff')
if (Lpoint) then
Reff(1:Npoints,:,:) = x3(1:Npoints,1:Nlevels,:)
else
call map_ll_to_point(Na,Nb,Npoints,x4=x4,y3=Reff)
endif
case ('skt')
if (Lpoint) then
skt(1:Npoints) = x1(1:Npoints)
else
call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=skt)
endif
case ('landmask')
if (Lpoint) then
landmask(1:Npoints) = x1(1:Npoints)
else
call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=landmask)
endif
case ('orography')
if (Lpoint) then
sfc_height(1:Npoints) = x1(1:Npoints)
else
call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=sfc_height)
endif
case ('mr_ozone')
if (Lpoint) then
mr_ozone(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
else
call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_ozone)
endif
case ('u_wind')
if (Lpoint) then
u_wind(1:Npoints) = x1(1:Npoints)
else
call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=u_wind)
endif
case ('v_wind')
if (Lpoint) then
v_wind(1:Npoints) = x1(1:Npoints)
else
call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=v_wind)
endif
case ('sunlit')
if (Lpoint) then
sunlit(1:Npoints) = x1(1:Npoints)
else
call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=sunlit)
endif
end select
! select case (trim(vname))
! case ('pfull')
! if (Lpoint) then
! p(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=p)
! endif
! case ('phalf')
! if (Lpoint) then
! ph(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=ph)
! endif
! case ('zfull')
! if (Lpoint) then
! z(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=z)
! endif
! case ('zhalf')
! if (Lpoint) then
! zh(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=zh)
! endif
! case ('ta')
! if (Lpoint) then
! T(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=T)
! endif
! case ('hus')
! if (Lpoint) then
! qv(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=qv)
! endif
! case ('hur')
! if (Lpoint) then
! rh(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=rh)
! endif
! case ('cl')
! if (Lpoint) then
! tca(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=tca)
! endif
! tca = tca/100.0
! case ('clc')
! if (Lpoint) then
! cca(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=cca)
! endif
! cca = cca/100.0
! case ('clws')
! if (Lpoint) then
! mr_lsliq(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_lsliq)
! endif
! case ('clis')
! if (Lpoint) then
! mr_lsice(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_lsice)
! endif
! case ('clwc')
! if (Lpoint) then
! mr_ccliq(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_ccliq)
! endif
! case ('clic')
! if (Lpoint) then
! mr_ccice(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_ccice)
! endif
! case ('prsprof')
! if (Lpoint) then
! fl_lsrain(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_lsrain)
! endif
! case ('prsns')
! if (Lpoint) then
! fl_lssnow(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_lssnow)
! endif
! case ('grplprof')
! if (Lpoint) then
! fl_lsgrpl(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_lsgrpl)
! endif
! case ('prcprof')
! if (Lpoint) then
! fl_ccrain(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_ccrain)
! endif
! case ('prsnc')
! if (Lpoint) then
! fl_ccsnow(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=fl_ccsnow)
! endif
! case ('dtaus')
! if (Lpoint) then
! dtau_s(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dtau_s)
! endif
! case ('dtauc')
! if (Lpoint) then
! dtau_c(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dtau_c)
! endif
! case ('dems')
! if (Lpoint) then
! dem_s(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dem_s)
! endif
! case ('demc')
! if (Lpoint) then
! dem_c(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=dem_c)
! endif
! case ('reff')
! if (Lpoint) then
! Reff(1:Npoints,:,:) = x3(1:Npoints,1:Nlevels,:)
! else
! call map_ll_to_point(Na,Nb,Npoints,x4=x4,y3=Reff)
! endif
! case ('ts')
! if (Lpoint) then
! skt(1:Npoints) = x1(1:Npoints)
! else
! call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=skt)
! endif
! case ('landmask')
! if (Lpoint) then
! landmask(1:Npoints) = x1(1:Npoints)
! else
! call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=landmask)
! endif
! case ('orog')
! if (Lpoint) then
! sfc_height(1:Npoints) = x1(1:Npoints)
! else
! call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=sfc_height)
! endif
! case ('mrozone')
! if (Lpoint) then
! mr_ozone(1:Npoints,:) = x2(1:Npoints,1:Nlevels)
! else
! call map_ll_to_point(Na,Nb,Npoints,x3=x3,y2=mr_ozone)
! endif
! case ('uas')
! if (Lpoint) then
! u_wind(1:Npoints) = x1(1:Npoints)
! else
! call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=u_wind)
! endif
! case ('vas')
! if (Lpoint) then
! v_wind(1:Npoints) = x1(1:Npoints)
! else
! call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=v_wind)
! endif
! case ('sunlit')
! if (Lpoint) then
! sunlit(1:Npoints) = x1(1:Npoints)
! else
! call map_ll_to_point(Na,Nb,Npoints,x2=x2,y1=sunlit)
! endif
! end select
! Free memory
if (vrank == 1) deallocate(x1)
if (vrank == 2) deallocate(x2)
if (vrank == 3) deallocate(x3)
if (vrank == 4) deallocate(x4)
if (vrank == 5) deallocate(x5)
enddo
! SFC emissivity
errst = nf90_inq_varid(ncid, 'emsfc_lw', vid)
if (errst /= 0) then
errmsg='Error in nf90_inq_varid, var: emsfc_lw'
call cosp_error(routine_name,errmsg,errcode=errst)
endif
errst = nf90_get_var(ncid, vid, emsfc_lw)
if (errst /= 0) then
errmsg='Error in nf90_get_var, var: emsfc_lw'
call cosp_error(routine_name,errmsg,errcode=errst)
endif
! Fill in the lat/lon vectors with the right values for 2D modes
! This might be helpful if the inputs are 2D (gridded) and
! you want outputs in 1D mode
allocate(plon(Npoints),plat(Npoints))
if (mode == 2) then !(lon,lat)
ll = lat
do j=1,Nb
do i=1,Na
k = (j-1)*Na + i
plon(k) = i
plat(k) = j
enddo
enddo
lon(1:Npoints) = lon(plon(1:Npoints))
lat(1:Npoints) = ll(plat(1:Npoints))
else if (mode == 3) then !(lat,lon)
ll = lon
do j=1,Nb
do i=1,Na
k = (j-1)*Na + i
lon(k) = ll(j)
lat(k) = lat(i)
enddo
enddo
lon(1:Npoints) = ll(plon(1:Npoints))
lat(1:Npoints) = lat(plat(1:Npoints))
endif
deallocate(plon,plat)
! Close file
errst = nf90_close(ncid)
if (errst /= 0) then
errmsg='Error in nf90_close'
call cosp_error(routine_name,errmsg,errcode=errst)
endif
END SUBROUTINE NC_READ_INPUT_FILE
#endif
#ifndef COSP_GFDL
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!--------------- SUBROUTINE NC_WRITE_COSP_1D ---------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#ifdef RTTOV
SUBROUTINE NC_WRITE_COSP_1D(cmor_nl,wmode,cfg,vgrid,gb,sg,sgradar,sglidar,isccp,misr,modis,rttov,stradar,stlidar)
#else
SUBROUTINE NC_WRITE_COSP_1D(cmor_nl,wmode,cfg,vgrid,gb,sg,sgradar,sglidar,isccp,misr,modis,stradar,stlidar)
#endif
! Input arguments
character(len=*),intent(in) :: cmor_nl
character(len=*) :: wmode ! Writing mode 'replace' or 'append'
type(cosp_config),intent(in) :: cfg
type(cosp_vgrid),intent(in) :: vgrid
type(cosp_gridbox),intent(in) :: gb
type(cosp_subgrid),intent(in) :: sg
type(cosp_sgradar),intent(in) :: sgradar ! Subgrid radar
type(cosp_sglidar),intent(in) :: sglidar ! Subgrid lidar
type(cosp_isccp),intent(in) :: isccp ! ISCCP outputs
type(cosp_misr),intent(in) :: misr ! MISR outputs
type(cosp_modis),intent(in) :: modis ! MODIS outputs
#ifdef RTTOV
type(cosp_rttov),intent(in) :: rttov ! RTTOV outputs
#endif
type(cosp_radarstats),intent(in) :: stradar ! Summary statistics from radar simulator
type(cosp_lidarstats),intent(inout) :: stlidar ! Summary statistics from lidar simulator
!--- Local variables ---
integer,parameter :: n3d = 8
#ifdef RTTOV
integer,parameter :: n2d = 7
#else
integer,parameter :: n2d = 6
#endif
integer,parameter :: n1d = 29
integer :: error_flag,i,j, nc_action
logical :: lfound
character(len=512) :: inpath,outpath,start_date,model_id,experiment_id,institution,institute_id,source,calendar, &
contact,history,comment,table,parent_experiment_id,parent_experiment_rip,forcing
character(len=2056) :: references
double precision :: branch_time
integer :: initialization_method,physics_version
integer :: realization,Npoints,Ncolumns,Nlevels,Nlvgrid,maxtsteps,Nchannels
namelist/CMOR/inpath,outpath,start_date,model_id,experiment_id,branch_time,parent_experiment_id,parent_experiment_rip, &
forcing,institution,institute_id,source,calendar,realization,initialization_method,physics_version, &
contact,history,comment,references,table,maxtsteps
real,dimension(:),allocatable :: profile_ax,column_ax,dbze_ax,channel_ax
real,dimension(:,:),allocatable :: dbze_bounds,vgrid_bounds,mgrid_bounds,sratio_bounds
integer :: profile_axid,column_axid,height_axid,dbze_axid,height_mlev_axid,sratio_axid, &
tau_axid,pressure2_axid,time_axid,sza_axid,MISR_CTH_axid,channel_axid
integer :: grid_id, latvar_id, lonvar_id, blatvar_id, blonvar_id
integer :: var3d_id(n3d),var2d_id(n2d),var1d_id(n1d)
type(var1d) :: v1d(n1d)
type(var2d) :: v2d(n2d)
type(var3d) :: v3d(n3d)
integer :: d2(2),d3(3),d4(4),d5(5)
logical,dimension(n1d) :: lout1d = .false.
logical,dimension(n2d) :: lout2d = .false.
logical,dimension(n3d) :: lout3d = .false.
double precision :: tbnds(2,1)
character(len=64) :: pro_name = 'NC_WRITE_COSP_1D'
! Initialise values of axis ids that may not be used
height_mlev_axid = 0
column_axid = 0
channel_axid = 0
tau_axid = 0
pressure2_axid = 0
misr_cth_axid = 0
Npoints = gb%Npoints
Ncolumns = gb%Ncolumns
Nlevels = gb%Nlevels
Nchannels = gb%Nchan
Nlvgrid = vgrid%Nlvgrid
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Allocate memory and initialise
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tbnds(:,1) = gb%time_bnds
allocate(profile_ax(Npoints),column_ax(Ncolumns),dbze_ax(DBZE_BINS), &
dbze_bounds(2,DBZE_BINS),vgrid_bounds(2,Nlvgrid),mgrid_bounds(2,Nlevels), &
sratio_bounds(2,SR_BINS), channel_ax(Nchannels))
! Profile
do i=1,Npoints
profile_ax(i) = i
enddo
! Column
do i=1,Ncolumns
column_ax(i) = i
enddo
! Channels
channel_ax = float(gb%ichan)
! Radar Ze
do i=1,DBZE_BINS
dbze_ax(i) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(i - 0.5)
enddo
do i=1,DBZE_BINS
dbze_bounds(1,i) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(i - 1)
dbze_bounds(2,i) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*i
enddo
! Height of model levels
do i=1,Nlevels
mgrid_bounds(1,i) = vgrid%mzl(i)
mgrid_bounds(2,i) = vgrid%mzu(i)
enddo
! Height of std grid
do i=1,Nlvgrid
vgrid_bounds(1,i) = vgrid%zl(i)
vgrid_bounds(2,i) = vgrid%zu(i)
enddo
! Lidar scattering ratio bounds (They are output by cosp_cfad_sr->diag_lidar in lmd_ipsl_stats.f90)
sratio_bounds(2,:) = stlidar%srbval(:) ! srbval contains the upper limits from lmd_ipsl_stats.f90
sratio_bounds(1,2:SR_BINS) = stlidar%srbval(1:SR_BINS-1)
sratio_bounds(1,1) = 0.0
sratio_bounds(2,SR_BINS) = 1.e5 ! This matches with Chepfer et al., JGR, 2009. However, it is not consistent
! with the upper limit in lmd_ipsl_stats.f90, which is LIDAR_UNDEF-1=998.999
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Read namelist with information for CMOR output file
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
open(10,file=cmor_nl,status='old')
read(10,nml=cmor)
close(10)
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Specify path for tables and set up other CMOR options
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifdef USE_CMOR1
error_flag = cmor_setup(inpath=trim(inpath),netcdf_file_action=trim(wmode))
#else
nc_action = CMOR_APPEND_3
if (trim(wmode) == 'replace') nc_action = CMOR_REPLACE_3
error_flag = cmor_setup(inpath=trim(inpath),netcdf_file_action=nc_action,create_subdirectories=0)
#endif
print *, '---------------Define dataset'
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Define dataset as output from COSP, and other model details
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifdef USE_CMOR1
error_flag = cmor_dataset(outpath=trim(outpath),experiment_id=trim(experiment_id),institution=trim(institution), &
source=trim(source),calendar=trim(calendar),realization=realization,contact=trim(contact), &
history=trim(history),comment=trim(comment),references=trim(references))
#else
error_flag = cmor_dataset(outpath=trim(outpath),experiment_id=trim(experiment_id),institution=trim(institution), &
source=trim(source),calendar=trim(calendar),realization=realization,contact=trim(contact), &
history=trim(history),comment=trim(comment),references=trim(references),model_id=trim(model_id), &
branch_time=branch_time,parent_experiment_id=trim(parent_experiment_id),forcing=trim(forcing), &
institute_id=trim(institute_id),parent_experiment_rip=trim(parent_experiment_rip), &
initialization_method=initialization_method,physics_version=physics_version)
error_flag = cmor_set_cur_dataset_attribute('cosp_version',trim(COSP_VERSION))
#endif
print *, '---------------Define axis'
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Define axis
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
profile_axid = cmor_axis(table=table, table_entry='location', units='1', length=Npoints, coord_vals=profile_ax)
height_axid = cmor_axis(table=table, table_entry='alt40', units='m', length=Nlvgrid, &
coord_vals=vgrid%z,cell_bounds=vgrid_bounds)
dbze_axid = cmor_axis(table=table, table_entry='dbze', units='dBZ', length=DBZE_BINS, & ! '10 lg(re 1.e-18 m3)'
coord_vals=dbze_ax,cell_bounds=dbze_bounds)
sratio_axid = cmor_axis(table=table, table_entry='scatratio', units='1', length=SR_BINS, &
coord_vals=(sratio_bounds(1,:)+sratio_bounds(2,:))/2.0,cell_bounds=sratio_bounds)
sza_axid = cmor_axis(table=table, table_entry='sza5', units='degree', length=PARASOL_NREFL, coord_vals=PARASOL_SZA)
time_axid = cmor_axis(table=table, table_entry='time1', units='days since '//trim(start_date), length=maxtsteps)
if ((trim(table) /= 'CMIP5_cf3hr').and.(trim(table) /= 'TAMIP_3hr_curt')) then
column_axid = cmor_axis(table=table, table_entry='column', units='1', length=Ncolumns, coord_vals=column_ax)
channel_axid = cmor_axis(table=table, table_entry='channel', units='1', length=Nchannels, coord_vals=channel_ax)
height_mlev_axid = cmor_axis(table=table, table_entry='alevel', &
units='1', length=Nlevels, coord_vals=vgrid%mz,cell_bounds=mgrid_bounds)
tau_axid = cmor_axis(table=table, table_entry='tau', units='1', length=7, &
coord_vals=ISCCP_TAU,cell_bounds=ISCCP_TAU_BNDS)
pressure2_axid = cmor_axis(table=table, table_entry='plev7', units='Pa', length=7, &
coord_vals=ISCCP_PC,cell_bounds=ISCCP_PC_BNDS)
MISR_CTH_axid = cmor_axis(table=table, table_entry='cth16', units='m', length=MISR_N_CTH, &
coord_vals=MISR_CTH,cell_bounds=MISR_CTH_BNDS)
endif
print *, '---------------Define grid'
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Define grid
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
grid_id = cmor_grid((/profile_axid, time_axid/))
latvar_id = cmor_time_varying_grid_coordinate(grid_id,'latitude','degrees_north',R_UNDEF)
lonvar_id = cmor_time_varying_grid_coordinate(grid_id,'longitude','degrees_east' ,R_UNDEF)
if (grid_id > 0) then
print *, '*********** Error, grid_id: ', grid_id
stop
endif
print *, '---------------Fill in var info'
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Fill in variable info and associate pointers
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! 1D variables
d3 = (/grid_id,0,0/)
d2 = (/Npoints,0/)
call construct_var1d('cllcalipso', d3, d2, stlidar%cldlayer(:,1),v1d(1),units='%') ! correction sb
call construct_var1d('clmcalipso', d3, d2, stlidar%cldlayer(:,2),v1d(2),units='%') ! correction sb
call construct_var1d('clhcalipso', d3, d2, stlidar%cldlayer(:,3),v1d(3),units='%') ! correction sb
call construct_var1d('cltcalipso', d3, d2, stlidar%cldlayer(:,4),v1d(4),units='%') ! correction sb
call construct_var1d('cltlidarradar', d3, d2, stradar%radar_lidar_tcc,v1d(5),units='%')
call construct_var1d('cltisccp', d3, d2, isccp%totalcldarea,v1d(6),units='%')
call construct_var1d('pctisccp', d3, d2, isccp%meanptop,v1d(7),units='Pa')
call construct_var1d('tauisccp', d3, d2, isccp%meantaucld,v1d(8),units='1')
call construct_var1d('albisccp', d3, d2, isccp%meanalbedocld,v1d(9),units='1')
call construct_var1d('meantbisccp', d3, d2, isccp%meantb,v1d(10),units='K')
call construct_var1d('meantbclrisccp', d3, d2, isccp%meantbclr,v1d(11),units='K')
call construct_var1d('cltmodis', d3, d2, modis%Cloud_Fraction_Total_Mean,v1d(12),units='%')
call construct_var1d('clwmodis', d3, d2, modis%Cloud_Fraction_Water_Mean,v1d(13),units='%')
call construct_var1d('climodis', d3, d2, modis%Cloud_Fraction_Ice_Mean, v1d(14),units='%')
call construct_var1d('clhmodis', d3, d2, modis%Cloud_Fraction_High_Mean,v1d(15),units='%')
call construct_var1d('clmmodis', d3, d2, modis%Cloud_Fraction_Mid_Mean,v1d(16),units='%')
call construct_var1d('cllmodis', d3, d2, modis%Cloud_Fraction_Low_Mean, v1d(17),units='%')
call construct_var1d('tautmodis', d3, d2, modis%Optical_Thickness_Total_Mean,v1d(18),units='1')
call construct_var1d('tauwmodis', d3, d2, modis%Optical_Thickness_Water_Mean,v1d(19),units='1')
call construct_var1d('tauimodis', d3, d2, modis%Optical_Thickness_Ice_Mean,v1d(20),units='1')
call construct_var1d('tautlogmodis', d3, d2, modis%Optical_Thickness_Total_LogMean,v1d(21),units='1')
call construct_var1d('tauwlogmodis', d3, d2, modis%Optical_Thickness_Water_LogMean,v1d(22),units='1')
call construct_var1d('tauilogmodis', d3, d2, modis%Optical_Thickness_Ice_LogMean,v1d(23),units='1')
call construct_var1d('reffclwmodis', d3, d2, modis%Cloud_Particle_Size_Water_Mean,v1d(24),units='m')
call construct_var1d('reffclimodis', d3, d2, modis%Cloud_Particle_Size_Ice_Mean, v1d(25),units='m')
call construct_var1d('pctmodis', d3, d2, modis%Cloud_Top_Pressure_Total_Mean, v1d(26),units='Pa')
call construct_var1d('lwpmodis', d3, d2, modis%Liquid_Water_Path_Mean, v1d(27),units='kg m-2')
call construct_var1d('iwpmodis', d3, d2, modis%Ice_Water_Path_Mean, v1d(28),units='kg m-2')
call construct_var1d('toffset', d3, d2, gb%toffset, v1d(29),units='day')
! 2D variables
d4 = (/grid_id,height_axid,0,0/)
d3 = (/Npoints,Nlvgrid,0/)
call construct_var2d('clcalipso', d4, d3, stlidar%lidarcld,v2d(1),units='%')
call construct_var2d('clcalipso2', d4, d3, stradar%lidar_only_freq_cloud,v2d(2),units='%')
d4 = (/grid_id,height_mlev_axid,0,0/)
d3 = (/Npoints,Nlevels,0/)
! reshape d4 = (/profile_axid,height_mlev_axid,time_axid,0/)
call construct_var2d('lidarBetaMol532', d4, d3, sglidar%beta_mol,v2d(3),units='m-1 sr-1')
d4 = (/grid_id,column_axid,0,0/)
! reshape d4 = (/profile_axid,column_axid,time_axid,0/)
d3 = (/Npoints,Ncolumns,0/)
call construct_var2d('boxtauisccp', d4, d3, isccp%boxtau,v2d(4),units='1')
call construct_var2d('boxptopisccp', d4, d3, isccp%boxptop,v2d(5),units='Pa')
d4 = (/grid_id,sza_axid,0,0/)
d3 = (/Npoints,PARASOL_NREFL,0/)
call construct_var2d('parasolRefl', d4, d3, stlidar%parasolrefl,v2d(6),units='1')
#ifdef RTTOV
!reshape d4 = (/profile_axid,channel_axid,time_axid,0/)
d4 = (/grid_id,channel_axid,0,0/)
d3 = (/Npoints,Nchannels,0/)
call construct_var2d('tbrttov', d4, d3, rttov%tbs,v2d(7),units='K')
#endif
! 3D variables
! reshape d5 = (/profile_axid,column_axid,height_mlev_axid,time_axid,0/)
d5 = (/grid_id,column_axid,height_mlev_axid,0,0/)
d4 = (/Npoints,Ncolumns,Nlevels,0/)
call construct_var3d('dbze94', d5, d4, sgradar%Ze_tot,v3d(1),units='1')
call construct_var3d('atb532', d5, d4, sglidar%beta_tot,v3d(2),units='m-1 sr-1')
call construct_var3d('fracout', d5, d4, sg%frac_out,v3d(3),units='1')
! reshape d5 = (/profile_axid,dbze_axid,height_axid,time_axid,0/)
d5 = (/grid_id,dbze_axid,height_axid,0,0/)
d4 = (/Npoints,DBZE_BINS,Nlvgrid,0/)
call construct_var3d('cfadDbze94', d5, d4, stradar%cfad_ze,v3d(4),units='1')
! reshape d5 = (/profile_axid,sratio_axid,height_axid,time_axid,0/)
d5 = (/grid_id,sratio_axid,height_axid,0,0/)
d4 = (/Npoints,SR_BINS,Nlvgrid,0/)
call construct_var3d('cfadLidarsr532', d5, d4, stlidar%cfad_sr,v3d(5),units='1')
! reshape d5 = (/profile_axid,tau_axid,pressure2_axid,time_axid,0/)
d5 = (/grid_id,tau_axid,pressure2_axid,0,0/)
d4 = (/Npoints,7,7,0/)
call construct_var3d('clisccp', d5, d4, isccp%fq_isccp,v3d(6),units='%')
call construct_var3d('clmodis', d5, d4, modis%Optical_Thickness_vs_Cloud_Top_Pressure, v3d(7), units='%')
! reshape d5 = (/profile_axid,tau_axid,MISR_CTH_axid,time_axid,0/)
d5 = (/grid_id,tau_axid,MISR_CTH_axid,0,0/)
d4 = (/Npoints,7,MISR_N_CTH,0/)
call construct_var3d('clMISR', d5, d4, misr%fq_MISR,v3d(8),units='%')
print *, '---------------Find list'
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Find list of outputs to be written
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
do i=1,N_OUT_LIST
lfound = .false.
if (trim(cfg%out_list(i)) /= '') then
do j=1,n1d
if (trim(v1d(j)%name) == trim(cfg%out_list(i))) then
lout1d(j) = .true.
lfound = .true.
exit
endif
enddo
if (.not.lfound) then
do j=1,n2d
if (trim(v2d(j)%name) == trim(cfg%out_list(i))) then
lout2d(j) = .true.
lfound = .true.
exit
endif
enddo
endif
if (.not.lfound) then
do j=1,n3d
if (trim(v3d(j)%name) == trim(cfg%out_list(i))) then
lout3d(j) = .true.
lfound = .true.
exit
endif
enddo
endif
endif
enddo
print *, '---------------Define variables'
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Define variables. Fill in dimensions table first if needed
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! 1D variables
do i=1,n1d
if (lout1d(i)) var1d_id(i) = cmor_variable(table=table, table_entry=v1d(i)%name, units=v1d(i)%units, &
axis_ids=v1d(i)%dimsid(1:1), missing_value=R_UNDEF)
enddo
! 2D variables
do i=1,n2d
if (lout2d(i)) var2d_id(i) = cmor_variable(table=table, table_entry=v2d(i)%name, units=v2d(i)%units, &
axis_ids=v2d(i)%dimsid(1:2), missing_value=R_UNDEF)
enddo
! 3D variables
do i=1,n3d
if (lout3d(i)) then
var3d_id(i) = cmor_variable(table=trim(table), table_entry=v3d(i)%name, units=v3d(i)%units, &
axis_ids=v3d(i)%dimsid(1:3), missing_value=R_UNDEF)
endif
enddo
print *, '---------------Write variables'
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Write variables to file
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! 1D variables
do i=1,n1d
if (lout1d(i)) then
error_flag = cmor_write(var_id=var1d_id(i), data=v1d(i)%pntr, &
ntimes_passed=1,time_vals=(/gb%time/),time_bnds=tbnds)
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing '//trim(v1d(i)%name)
stop
endif
error_flag = cmor_write(var_id=lonvar_id, data=gb%longitude,store_with=var1d_id(i), &
ntimes_passed=1,time_vals=(/gb%time/))
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing lon for '//trim(v1d(i)%name)
stop
endif
error_flag = cmor_write(var_id=latvar_id, data=gb%latitude,store_with=var1d_id(i), &
ntimes_passed=1,time_vals=(/gb%time/))
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing lat for '//trim(v1d(i)%name)
stop
endif
endif
enddo
! 2D variables
do i=1,n2d
if (lout2d(i)) then
error_flag = cmor_write(var_id=var2d_id(i), data=v2d(i)%pntr, &
ntimes_passed=1,time_vals=(/gb%time/),time_bnds=tbnds)
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing '//trim(v2d(i)%name)
stop
endif
error_flag = cmor_write(var_id=lonvar_id, data=gb%longitude,store_with=var2d_id(i), &
ntimes_passed=1,time_vals=(/gb%time/))
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing lon for '//trim(v2d(i)%name)
stop
endif
error_flag = cmor_write(var_id=latvar_id, data=gb%latitude,store_with=var2d_id(i), &
ntimes_passed=1,time_vals=(/gb%time/))
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing lat for '//trim(v2d(i)%name)
stop
endif
endif
enddo
! 3D variables
do i=1,n3d
if (lout3d(i)) then
error_flag = cmor_write(var_id=var3d_id(i), data=v3d(i)%pntr, &
ntimes_passed=1,time_vals=(/gb%time/),time_bnds=tbnds)
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing '//trim(v3d(i)%name)
stop
endif
error_flag = cmor_write(var_id=lonvar_id, data=gb%longitude,store_with=var3d_id(i), &
ntimes_passed=1,time_vals=(/gb%time/))
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing lon for '//trim(v3d(i)%name)
stop
endif
error_flag = cmor_write(var_id=latvar_id, data=gb%latitude,store_with=var3d_id(i), &
ntimes_passed=1,time_vals=(/gb%time/))
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing lat for '//trim(v3d(i)%name)
stop
endif
endif
enddo
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Close files
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error_flag = cmor_close()
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Deallocate memory
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
deallocate(profile_ax,column_ax,dbze_ax,dbze_bounds,sratio_bounds, &
vgrid_bounds,mgrid_bounds,channel_ax)
END SUBROUTINE NC_WRITE_COSP_1D
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!--------------- SUBROUTINE NC_WRITE_COSP_2D ---------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#ifdef RTTOV
SUBROUTINE NC_WRITE_COSP_2D(cmor_nl,wmode,cfg,vgrid,gb,sg,sgradar,sglidar,isccp,misr,modis,rttov, &
stradar,stlidar,geomode,Nlon,Nlat)
#else
SUBROUTINE NC_WRITE_COSP_2D(cmor_nl,wmode,cfg,vgrid,gb,sg,sgradar,sglidar,isccp,misr,modis, &
stradar,stlidar,geomode,Nlon,Nlat)
#endif
! Input arguments
character(len=*),intent(in) :: cmor_nl
character(len=*) :: wmode ! Writing mode 'replace' or 'append'
type(cosp_config),intent(in) :: cfg
type(cosp_vgrid),intent(in) :: vgrid
type(cosp_gridbox),intent(in) :: gb
type(cosp_subgrid),intent(in) :: sg
type(cosp_sgradar),intent(in) :: sgradar ! Subgrid radar
type(cosp_sglidar),intent(in) :: sglidar ! Subgrid lidar
type(cosp_isccp),intent(in) :: isccp ! ISCCP outputs
type(cosp_misr),intent(in) :: misr ! MISR outputs
type(cosp_modis),intent(in) :: modis ! MODIS outputs
#ifdef RTTOV
type(cosp_rttov),intent(in) :: rttov ! RTTOV outputs
#endif
type(cosp_radarstats),intent(in) :: stradar ! Summary statistics from radar simulator
type(cosp_lidarstats),intent(in) :: stlidar ! Summary statistics from lidar simulator
integer,intent(in) :: geomode,Nlon,Nlat
!--- Local variables ---
integer,parameter :: n3d = 8
#ifdef RTTOV
integer,parameter :: n2d = 7
#else
integer,parameter :: n2d = 6
#endif
integer,parameter :: n1d = 28
integer :: error_flag,i,j,Npoints,Ncolumns,Nlevels,Nlvgrid,maxtsteps,Nchannels
logical :: lfound
real :: lon_ax(Nlon),lat_ax(Nlat)
character(len=512) :: inpath,outpath,start_date,model_id,experiment_id,institution,institute_id,source,calendar, &
contact,history,comment,table,parent_experiment_id,parent_experiment_rip,forcing
character(len=2056) :: references
integer :: realization, nc_action,initialization_method,physics_version
double precision :: branch_time
namelist/CMOR/inpath,outpath,start_date,model_id,experiment_id,branch_time,parent_experiment_id,parent_experiment_rip, &
forcing,institution,institute_id,source,calendar,realization,initialization_method,physics_version, &
contact,history,comment,references,table,maxtsteps
real,dimension(:),allocatable :: column_ax,dbze_ax,channel_ax
real,dimension(:,:),allocatable :: dbze_bounds,vgrid_bounds,sratio_bounds, &
lon_bounds,lat_bounds,mgrid_bounds
integer :: column_axid,height_axid,dbze_axid,height_mlev_axid,sratio_axid, &
tau_axid,pressure2_axid,lon_axid,lat_axid,time_axid,sza_axid,MISR_CTH_axid, &
channel_axid
integer :: var3d_id(n3d),var2d_id(n2d),var1d_id(n1d)
type(var1d) :: v1d(n1d)
type(var2d) :: v2d(n2d)
type(var3d) :: v3d(n3d)
integer :: d2(2),d3(3),d4(4),d5(5)
logical,dimension(n1d) :: lout1d = .false.
logical,dimension(n2d) :: lout2d = .false.
logical,dimension(n3d) :: lout3d = .false.
real,allocatable :: y2(:,:),y3(:,:,:),y4(:,:,:,:)
double precision :: tbnds(2,1)
character(len=64) :: pro_name = 'NC_WRITE_COSP_2D'
Npoints = gb%Npoints
Ncolumns = gb%Ncolumns
Nlevels = gb%Nlevels
Nchannels = gb%Nchan
Nlvgrid = vgrid%Nlvgrid
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Safety checks
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (Npoints > Nlon*Nlat) then
Npoints = Nlon*Nlat
print *, ' -- '//trim(pro_name)//' Warning: Npoints > Nlon*Nlat'
endif
if (Npoints < Nlon*Nlat) then
print *, ' -- '//trim(pro_name)//': only Npoints >= Nlon*Nlat is supported'
stop
endif
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Allocate memory and compute axes and bounds
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tbnds(:,1) = gb%time_bnds
allocate(column_ax(Ncolumns),dbze_ax(DBZE_BINS),channel_ax(Nchannels), &
dbze_bounds(2,DBZE_BINS),vgrid_bounds(2,Nlvgrid),mgrid_bounds(2,Nlevels),sratio_bounds(2,SR_BINS), &
lon_bounds(2,Nlon),lat_bounds(2,Nlat))
! Column
do i=1,gb%Ncolumns
column_ax(i) = i
enddo
! Channels
channel_ax = float(gb%ichan)
! Radar Ze
do i=1,DBZE_BINS
dbze_ax(i) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(i - 0.5)
enddo
do i=1,DBZE_BINS
dbze_bounds(1,i) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*(i - 1)
dbze_bounds(2,i) = CFAD_ZE_MIN + CFAD_ZE_WIDTH*i
enddo
! Height of model levels
do i=1,Nlevels
mgrid_bounds(1,i) = vgrid%mzl(i)
mgrid_bounds(2,i) = vgrid%mzu(i)
enddo
! Height of std grid
do i=1,Nlvgrid
vgrid_bounds(1,i) = vgrid%zl(i)
vgrid_bounds(2,i) = vgrid%zu(i)
enddo
! Lidar scattering ratio bounds (They are output by cosp_cfad_sr->diag_lidar in lmd_ipsl_stats.f90)
sratio_bounds(2,:) = stlidar%srbval(:) ! srbval contains the upper limits from lmd_ipsl_stats.f90
sratio_bounds(1,2:SR_BINS) = stlidar%srbval(1:SR_BINS-1)
sratio_bounds(1,1) = 0.0
sratio_bounds(2,SR_BINS) = 1.e5 ! This matches with Chepfer et al., JGR, 2009. However, it is not consistent
! with the upper limit in lmd_ipsl_stats.f90, which is LIDAR_UNDEF-1=998.999
! Lat lon axes
if (geomode == 2) then
lon_ax = gb%longitude(1:Nlon)
lat_ax = gb%latitude(1:Npoints:Nlon)
else if (geomode == 3) then
lon_ax = gb%longitude(1:Npoints:Nlat)
lat_ax = gb%latitude(1:Nlat)
else if (geomode == 4) then
lon_ax = gb%longitude(1:Nlon)
lat_ax = gb%latitude(1:Nlat)
endif
lon_bounds(1,2:Nlon) = (lon_ax(1:Nlon-1) + lon_ax(2:Nlon))/2.0
lon_bounds(1,1) = lon_ax(1) - (lon_bounds(1,2) - lon_ax(1))
lon_bounds(2,1:Nlon-1) = lon_bounds(1,2:Nlon)
lon_bounds(2,Nlon) = lon_ax(Nlon) + (lon_ax(Nlon) - lon_bounds(2,Nlon-1))
lat_bounds(1,2:Nlat) = (lat_ax(1:Nlat-1) + lat_ax(2:Nlat))/2.0
lat_bounds(1,1) = lat_ax(1) - (lat_bounds(1,2) - lat_ax(1))
lat_bounds(2,1:Nlat-1) = lat_bounds(1,2:Nlat)
lat_bounds(2,Nlat) = lat_ax(Nlat) + (lat_ax(Nlat) - lat_bounds(2,Nlat-1))
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Read namelist with information for CMOR output file
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
open(10,file=cmor_nl,status='old')
read(10,nml=cmor)
close(10)
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Specify path for tables and set up other CMOR options
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifdef USE_CMOR1
error_flag = cmor_setup(inpath=trim(inpath),netcdf_file_action=trim(wmode))
#else
nc_action = CMOR_APPEND_3
if (trim(wmode) == 'replace') nc_action = CMOR_REPLACE_3
error_flag = cmor_setup(inpath=trim(inpath),netcdf_file_action=nc_action,create_subdirectories=0)
#endif
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Define dataset as output from COSP, and other model details
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifdef USE_CMOR1
error_flag = cmor_dataset(outpath=trim(outpath),experiment_id=trim(experiment_id),institution=trim(institution), &
source=trim(source),calendar=trim(calendar),realization=realization,contact=trim(contact), &
history=trim(history),comment=trim(comment),references=trim(references))
#else
error_flag = cmor_dataset(outpath=trim(outpath),experiment_id=trim(experiment_id),institution=trim(institution), &
source=trim(source),calendar=trim(calendar),realization=realization,contact=trim(contact), &
history=trim(history),comment=trim(comment),references=trim(references),model_id=trim(model_id), &
branch_time=branch_time,parent_experiment_id=trim(parent_experiment_id),forcing=trim(forcing), &
institute_id=trim(institute_id),parent_experiment_rip=trim(parent_experiment_rip), &
initialization_method=initialization_method,physics_version=physics_version)
error_flag = cmor_set_cur_dataset_attribute('cosp_version',trim(COSP_VERSION))
#endif
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Define axis
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lon_axid = cmor_axis(table=table, table_entry='longitude', units='degrees_east', length=Nlon, coord_vals=lon_ax, &
cell_bounds = lon_bounds)
lat_axid = cmor_axis(table=table, table_entry='latitude', units='degrees_north', length=Nlat, coord_vals=lat_ax, &
cell_bounds = lat_bounds)
column_axid = cmor_axis(table=table, table_entry='column', units='1', length=Ncolumns, coord_vals=column_ax)
channel_axid = cmor_axis(table=table, table_entry='channel', units='1', length=Nchannels, coord_vals=channel_ax)
height_axid = cmor_axis(table=table, table_entry='alt40', units='m', length=Nlvgrid, &
coord_vals=vgrid%z,cell_bounds=vgrid_bounds)
dbze_axid = cmor_axis(table=table, table_entry='dbze', units='dBZ', length=DBZE_BINS, &
coord_vals=dbze_ax,cell_bounds=dbze_bounds)
height_mlev_axid = cmor_axis(table=table, table_entry='alevel', units='1', length=Nlevels, &
coord_vals=vgrid%mz,cell_bounds=mgrid_bounds)
sratio_axid = cmor_axis(table=table, table_entry='scatratio', units='1', length=SR_BINS, &
coord_vals=(sratio_bounds(1,:)+sratio_bounds(2,:))/2.0,cell_bounds=sratio_bounds)
tau_axid = cmor_axis(table=table, table_entry='tau', units='1', length=7, &
coord_vals=ISCCP_TAU,cell_bounds=ISCCP_TAU_BNDS)
pressure2_axid = cmor_axis(table=table, table_entry='plev7', units='Pa', length=7, &
coord_vals=ISCCP_PC,cell_bounds=ISCCP_PC_BNDS)
sza_axid = cmor_axis(table=table, table_entry='sza5', units='degree', length=PARASOL_NREFL, coord_vals=PARASOL_SZA)
MISR_CTH_axid = cmor_axis(table=table, table_entry='cth16', units='m', length=MISR_N_CTH, &
coord_vals=MISR_CTH,cell_bounds=MISR_CTH_BNDS)
time_axid = cmor_axis(table=table, table_entry='time1', units='days since '//trim(start_date), length=maxtsteps)
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Fill in variable info and associate pointers
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! 1D variables
d3 = (/lon_axid,lat_axid,time_axid/)
d2 = (/Nlon,Nlat/)
call construct_var1d('cllcalipso', d3, d2, stlidar%cldlayer(:,1),v1d(1),units='%') ! correction sb
call construct_var1d('clmcalipso', d3, d2, stlidar%cldlayer(:,2),v1d(2),units='%') ! correction sb
call construct_var1d('clhcalipso', d3, d2, stlidar%cldlayer(:,3),v1d(3),units='%') ! correction sb
call construct_var1d('cltcalipso', d3, d2, stlidar%cldlayer(:,4),v1d(4),units='%') ! correction sb
call construct_var1d('cltlidarradar', d3, d2, stradar%radar_lidar_tcc,v1d(5),units='%')
call construct_var1d('cltisccp', d3, d2, isccp%totalcldarea,v1d(6),units='%')
call construct_var1d('pctisccp', d3, d2, isccp%meanptop,v1d(7),units='Pa')
call construct_var1d('tauisccp', d3, d2, isccp%meantaucld,v1d(8),units='1')
call construct_var1d('albisccp', d3, d2, isccp%meanalbedocld,v1d(9),units='1')
call construct_var1d('meantbisccp', d3, d2, isccp%meantb,v1d(10),units='K')
call construct_var1d('meantbclrisccp', d3, d2, isccp%meantbclr,v1d(11),units='K')
call construct_var1d('cltmodis', d3, d2, modis%Cloud_Fraction_Total_Mean,v1d(12),units='%')
call construct_var1d('clwmodis', d3, d2, modis%Cloud_Fraction_Water_Mean,v1d(13),units='%')
call construct_var1d('climodis', d3, d2, modis%Cloud_Fraction_Ice_Mean, v1d(14),units='%')
call construct_var1d('clhmodis', d3, d2, modis%Cloud_Fraction_High_Mean,v1d(15),units='%')
call construct_var1d('clmmodis', d3, d2, modis%Cloud_Fraction_Mid_Mean,v1d(16),units='%')
call construct_var1d('cllmodis', d3, d2, modis%Cloud_Fraction_Low_Mean, v1d(17),units='%')
call construct_var1d('tautmodis', d3, d2, modis%Optical_Thickness_Total_Mean,v1d(18),units='1')
call construct_var1d('tauwmodis', d3, d2, modis%Optical_Thickness_Water_Mean,v1d(19),units='1')
call construct_var1d('tauimodis', d3, d2, modis%Optical_Thickness_Ice_Mean,v1d(20),units='1')
call construct_var1d('tautlogmodis', d3, d2, modis%Optical_Thickness_Total_LogMean,v1d(21),units='1')
call construct_var1d('tauwlogmodis', d3, d2, modis%Optical_Thickness_Water_LogMean,v1d(22),units='1')
call construct_var1d('tauilogmodis', d3, d2, modis%Optical_Thickness_Ice_LogMean,v1d(23),units='1')
call construct_var1d('reffclwmodis', d3, d2, modis%Cloud_Particle_Size_Water_Mean,v1d(24),units='m')
call construct_var1d('reffclimodis', d3, d2, modis%Cloud_Particle_Size_Ice_Mean, v1d(25),units='m')
call construct_var1d('pctmodis', d3, d2, modis%Cloud_Top_Pressure_Total_Mean, v1d(26),units='Pa')
call construct_var1d('lwpmodis', d3, d2, modis%Liquid_Water_Path_Mean, v1d(27),units='kg m-2')
call construct_var1d('iwpmodis', d3, d2, modis%Ice_Water_Path_Mean, v1d(28),units='kg m-2')
! 2D variables
d4 = (/lon_axid,lat_axid,height_axid,time_axid/)
d3 = (/Nlon,Nlat,Nlvgrid/)
call construct_var2d('clcalipso', d4, d3, stlidar%lidarcld,v2d(1),units='%')
call construct_var2d('clcalipso2', d4, d3, stradar%lidar_only_freq_cloud,v2d(2),units='%')
d4 = (/lon_axid,lat_axid,height_mlev_axid,time_axid/)
d3 = (/Nlon,Nlat,Nlevels/)
call construct_var2d('lidarBetaMol532', d4, d3, sglidar%beta_mol,v2d(3),units='m-1 sr-1')
d4 = (/lon_axid,lat_axid,column_axid,time_axid/)
d3 = (/Nlon,Nlat,Ncolumns/)
call construct_var2d('boxtauisccp', d4, d3, isccp%boxtau,v2d(4),units='1')
call construct_var2d('boxptopisccp', d4, d3, isccp%boxptop,v2d(5),units='Pa')
d4 = (/lon_axid,lat_axid,sza_axid,time_axid/)
d3 = (/Nlon,Nlat,PARASOL_NREFL/)
call construct_var2d('parasolRefl', d4, d3, stlidar%parasolrefl,v2d(6),units='1')
#ifdef RTTOV
d4 = (/lon_axid,lat_axid,channel_axid,time_axid/)
d3 = (/Nlon,Nlat,Nchannels/)
call construct_var2d('tbrttov', d4, d3, rttov%tbs,v2d(7),units='K')
#endif
! 3D variables
d5 = (/lon_axid,lat_axid,column_axid,height_mlev_axid,time_axid/)
d4 = (/Nlon,Nlat,Ncolumns,Nlevels/)
call construct_var3d('dbze94', d5, d4, sgradar%Ze_tot,v3d(1),units='1')
call construct_var3d('atb532', d5, d4, sglidar%beta_tot,v3d(2),units='m-1 sr-1')
call construct_var3d('fracout', d5, d4, sg%frac_out,v3d(3),units='1')
d5 = (/lon_axid,lat_axid,dbze_axid,height_axid,time_axid/)
d4 = (/Nlon,Nlat,DBZE_BINS,Nlvgrid/)
call construct_var3d('cfadDbze94', d5, d4, stradar%cfad_ze,v3d(4),units='1')
d5 = (/lon_axid,lat_axid,sratio_axid,height_axid,time_axid/)
d4 = (/Nlon,Nlat,SR_BINS,Nlvgrid/)
call construct_var3d('cfadLidarsr532', d5, d4, stlidar%cfad_sr,v3d(5),units='1')
d5 = (/lon_axid,lat_axid,tau_axid,pressure2_axid,time_axid/)
d4 = (/Nlon,Nlat,7,7/)
call construct_var3d('clisccp', d5, d4, isccp%fq_isccp,v3d(6),units='%')
call construct_var3d('clmodis', d5, d4, modis%Optical_Thickness_vs_Cloud_Top_Pressure, v3d(7), units='%')
! call construct_var3d('clmodis', &
! (/lon_axid, lat_axid, modis_tau_axid, modis_p_axid, time_axid/), &
! (/Nlon, Nlat, numModisTauBins, numModisPressureBins/), &
! modis%Optical_Thickness_vs_Cloud_Top_Pressure, v3d(7), units='%')
d5 = (/lon_axid,lat_axid,tau_axid,MISR_CTH_axid,time_axid/)
d4 = (/Nlon,Nlat,7,MISR_N_CTH/)
call construct_var3d('clMISR', d5, d4, misr%fq_MISR,v3d(8),units='%')
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Find list of outputs to be written
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
do i=1,N_OUT_LIST
lfound = .false.
if (trim(cfg%out_list(i)) /= '') then
do j=1,n1d
if (trim(v1d(j)%name) == trim(cfg%out_list(i))) then
lout1d(j) = .true.
lfound = .true.
exit
endif
enddo
if (.not.lfound) then
do j=1,n2d
if (trim(v2d(j)%name) == trim(cfg%out_list(i))) then
lout2d(j) = .true.
lfound = .true.
exit
endif
enddo
endif
if (.not.lfound) then
do j=1,n3d
if (trim(v3d(j)%name) == trim(cfg%out_list(i))) then
lout3d(j) = .true.
lfound = .true.
exit
endif
enddo
endif
endif
enddo
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Define variables. Fill in dimensions table first if needed
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! 1D variables
do i=1,n1d
if (lout1d(i)) var1d_id(i) = cmor_variable(table=table, table_entry=v1d(i)%name, units=v1d(i)%units, &
axis_ids=v1d(i)%dimsid, missing_value=R_UNDEF)
enddo
! 2D variables
do i=1,n2d
if (lout2d(i)) var2d_id(i) = cmor_variable(table=table, table_entry=v2d(i)%name, units=v2d(i)%units, &
axis_ids=v2d(i)%dimsid, missing_value=R_UNDEF)
enddo
! 3D variables
do i=1,n3d
if (lout3d(i)) var3d_id(i) = cmor_variable(table=table, table_entry=v3d(i)%name, units=v3d(i)%units, &
axis_ids=v3d(i)%dimsid, missing_value=R_UNDEF)
enddo
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Write variables to file
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! 1D variables (2D output)
do i=1,n1d
if (lout1d(i)) then
allocate(y2(v1d(i)%dimssz(1),v1d(i)%dimssz(2)))
call map_point_to_ll(Nlon,Nlat,geomode,x1=v1d(i)%pntr,y2=y2) ! Regridding
error_flag = cmor_write(var_id=var1d_id(i), data=y2, &
ntimes_passed=1,time_vals=(/gb%time/),time_bnds=tbnds)
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing '//trim(v1d(i)%name)
stop
endif
deallocate(y2)
endif
enddo
! 2D variables (3D output)
do i=1,n2d
if (lout2d(i)) then
allocate(y3(v2d(i)%dimssz(1),v2d(i)%dimssz(2),v2d(i)%dimssz(3)))
call map_point_to_ll(Nlon,Nlat,geomode,x2=v2d(i)%pntr,y3=y3) ! Regridding
error_flag = cmor_write(var_id=var2d_id(i), data=y3, &
ntimes_passed=1,time_vals=(/gb%time/),time_bnds=tbnds)
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing '//trim(v2d(i)%name)
stop
endif
deallocate(y3)
endif
enddo
! 3D variables (4D output)
do i=1,n3d
if (lout3d(i)) then
allocate(y4(v3d(i)%dimssz(1),v3d(i)%dimssz(2),v3d(i)%dimssz(3),v3d(i)%dimssz(4)))
call map_point_to_ll(Nlon,Nlat,geomode,x3=v3d(i)%pntr,y4=y4) ! Regridding
error_flag = cmor_write(var_id=var3d_id(i), data=y4, &
ntimes_passed=1,time_vals=(/gb%time/),time_bnds=tbnds)
if (error_flag < 0) then
print *, trim(pro_name)//': Error writing '//trim(v3d(i)%name)
stop
endif
deallocate(y4)
endif
enddo
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Close files
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error_flag = cmor_close()
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Deallocate memory
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
deallocate(column_ax,dbze_ax,channel_ax,dbze_bounds,sratio_bounds, &
vgrid_bounds,mgrid_bounds,lon_bounds,lat_bounds)
END SUBROUTINE NC_WRITE_COSP_2D
#endif
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!--------------- SUBROUTINE READ_COSP_OUTPUT_NL -------------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE READ_COSP_OUTPUT_NL(cosp_nl,cfg)
character(len=*),intent(in) :: cosp_nl
type(cosp_config),intent(out) :: cfg
! Local variables
integer :: i
logical :: Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, &
Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94, &
LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp,Lcllcalipso, &
Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp,Lcltisccp, &
Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
Lfracout,LlidarBetaMol532,Ltbrttov, &
Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis,Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis, &
Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis, &
Liwpmodis,Lclmodis
namelist/COSP_OUTPUT/Lradar_sim,Llidar_sim,Lisccp_sim,Lmodis_sim,Lmisr_sim,Lrttov_sim, &
Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,LcfadDbze94, &
LcfadLidarsr532,Lclcalipso2,Lclcalipso,Lclhcalipso,Lclisccp, &
Lcllcalipso,Lclmcalipso,Lcltcalipso,Lcltlidarradar,Lpctisccp,Ldbze94,Ltauisccp, &
Lcltisccp,Ltoffset,LparasolRefl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
Lfracout,LlidarBetaMol532,Ltbrttov, &
Lcltmodis,Lclwmodis,Lclimodis,Lclhmodis,Lclmmodis,Lcllmodis,Ltautmodis,Ltauwmodis,Ltauimodis,Ltautlogmodis, &
Ltauwlogmodis,Ltauilogmodis,Lreffclwmodis,Lreffclimodis,Lpctmodis,Llwpmodis, &
Liwpmodis,Lclmodis
#ifdef COSP_GFDL
integer :: unit, io, ierr, logunit
#endif
do i=1,N_OUT_LIST
cfg%out_list(i)=''
enddo
#ifdef COSP_GFDL
!---------------------------------------------------------------------
! read namelist.
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=cosp_output, iostat=io)
ierr = check_nml_error(io,"cosp_output")
#else
!---------------------------------------------------------------------
if ( file_exist('input.nml')) then
unit = open_namelist_file ()
ierr=1; do while (ierr /= 0)
read (unit, nml=cosp_output, iostat=io, end=10)
ierr = check_nml_error(io,'cosp_output')
enddo
10 call close_file (unit)
endif
#endif
!---------------------------------------------------------------------
! write namelist to logfile.
!---------------------------------------------------------------------
call write_version_number (versiona, tagnamea)
logunit = stdlog()
if (mpp_pe() == mpp_root_pe() ) &
write (logunit, nml=cosp_output)
#else
open(10,file=cosp_nl,status='old')
read(10,nml=cosp_output)
close(10)
#endif
! Deal with dependencies
if (.not.Lradar_sim) then
LcfadDbze94 = .false.
Lclcalipso2 = .false.
Lcltlidarradar = .false. ! Needs radar & lidar
Ldbze94 = .false.
Lclcalipso2 = .false. ! Needs radar & lidar
endif
if (.not.Llidar_sim) then
Latb532 = .false.
LcfadLidarsr532 = .false.
Lclcalipso2 = .false. ! Needs radar & lidar
Lclcalipso = .false.
Lclhcalipso = .false.
Lcllcalipso = .false.
Lclmcalipso = .false.
Lcltcalipso = .false.
Lcltlidarradar = .false.
LparasolRefl = .false.
LlidarBetaMol532 = .false.
Lcltlidarradar = .false. ! Needs radar & lidar
endif
if (.not.Lisccp_sim) then
Lalbisccp = .false.
Lboxptopisccp = .false.
Lboxtauisccp = .false.
Lclisccp = .false.
Lpctisccp = .false.
Ltauisccp = .false.
Lcltisccp = .false.
Lmeantbisccp = .false.
Lmeantbclrisccp = .false.
endif
if (.not.Lmisr_sim) then
LclMISR = .false.
endif
if (.not.Lrttov_sim) then
Ltbrttov = .false.
endif
if ((.not.Lradar_sim).and.(.not.Llidar_sim).and. &
(.not.Lisccp_sim).and.(.not.Lmisr_sim)) then
Lfracout = .false.
endif
if (.not.Lmodis_sim) then
Lcltmodis=.false.
Lclwmodis=.false.
Lclimodis=.false.
Lclhmodis=.false.
Lclmmodis=.false.
Lcllmodis=.false.
Ltautmodis=.false.
Ltauwmodis=.false.
Ltauimodis=.false.
Ltautlogmodis=.false.
Ltauwlogmodis=.false.
Ltauilogmodis=.false.
Lreffclwmodis=.false.
Lreffclimodis=.false.
Lpctmodis=.false.
Llwpmodis=.false.
Liwpmodis=.false.
Lclmodis=.false.
endif
if (Lmodis_sim) Lisccp_sim = .true.
cfg%Lstats = .false.
if ((Lradar_sim).or.(Llidar_sim).or.(Lisccp_sim)) cfg%Lstats = .true.
! Copy instrument flags to cfg structure
cfg%Lradar_sim = Lradar_sim
cfg%Llidar_sim = Llidar_sim
cfg%Lisccp_sim = Lisccp_sim
cfg%Lmodis_sim = Lmodis_sim
cfg%Lmisr_sim = Lmisr_sim
cfg%Lrttov_sim = Lrttov_sim
! Flag to control output to file
cfg%Lwrite_output = .false.
if (cfg%Lstats.or.cfg%Lmisr_sim.or.cfg%Lrttov_sim) then
cfg%Lwrite_output = .true.
endif
! Output diagnostics
i = 1
if (Lalbisccp) cfg%out_list(i) = 'albisccp'
i = i+1
if (Latb532) cfg%out_list(i) = 'atb532'
i = i+1
if (Lboxptopisccp) cfg%out_list(i) = 'boxptopisccp'
i = i+1
if (Lboxtauisccp) cfg%out_list(i) = 'boxtauisccp'
i = i+1
if (LcfadDbze94) cfg%out_list(i) = 'cfadDbze94'
i = i+1
if (LcfadLidarsr532) cfg%out_list(i) = 'cfadLidarsr532'
i = i+1
if (Lclcalipso2) cfg%out_list(i) = 'clcalipso2'
i = i+1
if (Lclcalipso) cfg%out_list(i) = 'clcalipso'
i = i+1
if (Lclhcalipso) cfg%out_list(i) = 'clhcalipso'
i = i+1
if (Lclisccp) cfg%out_list(i) = 'clisccp'
i = i+1
if (Lcllcalipso) cfg%out_list(i) = 'cllcalipso'
i = i+1
if (Lclmcalipso) cfg%out_list(i) = 'clmcalipso'
i = i+1
if (Lcltcalipso) cfg%out_list(i) = 'cltcalipso'
i = i+1
if (Lcltlidarradar) cfg%out_list(i) = 'cltlidarradar'
i = i+1
if (Lpctisccp) cfg%out_list(i) = 'pctisccp'
i = i+1
if (Ldbze94) cfg%out_list(i) = 'dbze94'
i = i+1
if (Ltauisccp) cfg%out_list(i) = 'tauisccp'
i = i+1
if (Lcltisccp) cfg%out_list(i) = 'cltisccp'
i = i+1
if (Ltoffset) cfg%out_list(i) = 'toffset'
i = i+1
if (LparasolRefl) cfg%out_list(i) = 'parasolRefl'
i = i+1
if (LclMISR) cfg%out_list(i) = 'clMISR'
i = i+1
if (Lmeantbisccp) cfg%out_list(i) = 'meantbisccp'
i = i+1
if (Lmeantbclrisccp) cfg%out_list(i) = 'meantbclrisccp'
i = i+1
if (Lfracout) cfg%out_list(i) = 'fracout'
i = i+1
if (LlidarBetaMol532) cfg%out_list(i) = 'lidarBetaMol532'
i = i+1
if (Ltbrttov) cfg%out_list(i) = 'tbrttov'
i = i+1
if (Lcltmodis) cfg%out_list(i) = 'cltmodis'
i = i+1
if (Lclwmodis) cfg%out_list(i) = 'clwmodis'
i = i+1
if (Lclimodis) cfg%out_list(i) = 'climodis'
i = i+1
if (Lclhmodis) cfg%out_list(i) = 'clhmodis'
i = i+1
if (Lclmmodis) cfg%out_list(i) = 'clmmodis'
i = i+1
if (Lcllmodis) cfg%out_list(i) = 'cllmodis'
i = i+1
if (Ltautmodis) cfg%out_list(i) = 'tautmodis'
i = i+1
if (Ltauwmodis) cfg%out_list(i) = 'tauwmodis'
i = i+1
if (Ltauimodis) cfg%out_list(i) = 'tauimodis'
i = i+1
if (Ltautlogmodis) cfg%out_list(i) = 'tautlogmodis'
i = i+1
if (Ltauwlogmodis) cfg%out_list(i) = 'tauwlogmodis'
i = i+1
if (Ltauilogmodis) cfg%out_list(i) = 'tauilogmodis'
i = i+1
if (Lreffclwmodis) cfg%out_list(i) = 'reffclwmodis'
i = i+1
if (Lreffclimodis) cfg%out_list(i) = 'reffclimodis'
i = i+1
if (Lpctmodis) cfg%out_list(i) = 'pctmodis'
i = i+1
if (Llwpmodis) cfg%out_list(i) = 'lwpmodis'
i = i+1
if (Liwpmodis) cfg%out_list(i) = 'iwpmodis'
i = i+1
if (Lclmodis) cfg%out_list(i) = 'clmodis'
if (i /= N_OUT_LIST) then
#ifdef COSP_GFDL
call error_mesg ('cosp_io:read_cosp_output_nl', &
'COSP_IO: wrong number of output diagnostics', &
FATAL)
#else
print *, 'COSP_IO: wrong number of output diagnostics'
stop
#endif
endif
! Copy diagnostic flags to cfg structure
! ISCCP simulator
cfg%Lalbisccp = Lalbisccp
cfg%Latb532 = Latb532
cfg%Lboxptopisccp = Lboxptopisccp
cfg%Lboxtauisccp = Lboxtauisccp
cfg%Lmeantbisccp = Lmeantbisccp
cfg%Lmeantbclrisccp = Lmeantbclrisccp
cfg%Lclisccp = Lclisccp
cfg%Lpctisccp = Lpctisccp
cfg%Ltauisccp = Ltauisccp
cfg%Lcltisccp = Lcltisccp
! CloudSat simulator
cfg%Ldbze94 = Ldbze94
cfg%LcfadDbze94 = LcfadDbze94
! CALIPSO/PARASOL simulator
cfg%LcfadLidarsr532 = LcfadLidarsr532
cfg%Lclcalipso2 = Lclcalipso2
cfg%Lclcalipso = Lclcalipso
cfg%Lclhcalipso = Lclhcalipso
cfg%Lcllcalipso = Lcllcalipso
cfg%Lclmcalipso = Lclmcalipso
cfg%Lcltcalipso = Lcltcalipso
cfg%Lcltlidarradar = Lcltlidarradar
cfg%LparasolRefl = LparasolRefl
! MISR simulator
cfg%LclMISR = LclMISR
! Other
cfg%Ltoffset = Ltoffset
cfg%Lfracout = Lfracout
cfg%LlidarBetaMol532 = LlidarBetaMol532
! RTTOV
cfg%Ltbrttov = Ltbrttov
! MODIS simulator
cfg%Lcltmodis=Lcltmodis
cfg%Lclwmodis=Lclwmodis
cfg%Lclimodis=Lclimodis
cfg%Lclhmodis=Lclhmodis
cfg%Lclmmodis=Lclmmodis
cfg%Lcllmodis=Lcllmodis
cfg%Ltautmodis=Ltautmodis
cfg%Ltauwmodis=Ltauwmodis
cfg%Ltauimodis=Ltauimodis
cfg%Ltautlogmodis=Ltautlogmodis
cfg%Ltauwlogmodis=Ltauwlogmodis
cfg%Ltauilogmodis=Ltauilogmodis
cfg%Lreffclwmodis=Lreffclwmodis
cfg%Lreffclimodis=Lreffclimodis
cfg%Lpctmodis=Lpctmodis
cfg%Llwpmodis=Llwpmodis
cfg%Liwpmodis=Liwpmodis
cfg%Lclmodis=Lclmodis
END SUBROUTINE READ_COSP_OUTPUT_NL
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!--------------- SUBROUTINE ERROR_CONTROL ------------------------
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SUBROUTINE COSP_ERROR(routine_name,message,errcode)
character(len = *), intent(in) :: routine_name
character(len = *), intent(in) :: message
integer,optional :: errcode
write(6, *) " ********** Failure in ", trim(routine_name)
write(6, *) " ********** ", trim(message)
if (present(errcode)) write(6, *) " ********** errcode: ", errcode
flush(6)
stop
END SUBROUTINE COSP_ERROR
END MODULE MOD_COSP_IO
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_eoshift.f90 | 19 | 3749 | ! Program to test the eoshift intrinsic
program intrinsic_eoshift
integer, dimension(3, 3) :: a
integer, dimension(3, 3, 2) :: b
integer, dimension(3) :: bo, sh
! Scalar shift and scalar bound.
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, 1, 99, 1)
if (any (a .ne. reshape ((/2, 3, 99, 5, 6, 99, 8, 9, 99/), (/3, 3/)))) &
STOP 1
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, 9999, 99, 1)
if (any (a .ne. 99)) STOP 2
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, -2, dim = 2)
if (any (a .ne. reshape ((/0, 0, 0, 0, 0, 0, 1, 2, 3/), (/3, 3/)))) &
STOP 3
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, -9999, 99, 1)
if (any (a .ne. 99)) STOP 4
! Array shift and scalar bound.
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, (/1, 0, -1/), 99, 1)
if (any (a .ne. reshape ((/2, 3, 99, 4, 5, 6, 99, 7, 8/), (/3, 3/)))) &
STOP 5
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, (/9999, 0, -9999/), 99, 1)
if (any (a .ne. reshape ((/99, 99, 99, 4, 5, 6, 99, 99, 99/), (/3, 3/)))) &
STOP 6
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, (/2, -2, 0/), dim = 2)
if (any (a .ne. reshape ((/7, 0, 3, 0, 0, 6, 0, 2, 9/), (/3, 3/)))) &
STOP 7
! Scalar shift and array bound.
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, 1, (/99, -1, 42/), 1)
if (any (a .ne. reshape ((/2, 3, 99, 5, 6, -1, 8, 9, 42/), (/3, 3/)))) &
STOP 8
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, 9999, (/99, -1, 42/), 1)
if (any (a .ne. reshape ((/99, 99, 99, -1, -1, -1, 42, 42, 42/), &
(/3, 3/)))) STOP 9
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, -9999, (/99, -1, 42/), 1)
if (any (a .ne. reshape ((/99, 99, 99, -1, -1, -1, 42, 42, 42/), &
(/3, 3/)))) STOP 10
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, -2, (/99, -1, 42/), 2)
if (any (a .ne. reshape ((/99, -1, 42, 99, -1, 42, 1, 2, 3/), (/3, 3/)))) &
STOP 11
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
bo = (/99, -1, 42/)
a = eoshift (a, -2, bo, 2)
if (any (a .ne. reshape ((/99, -1, 42, 99, -1, 42, 1, 2, 3/), (/3, 3/)))) &
STOP 12
! Array shift and array bound.
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, (/1, 0, -1/), (/99, -1, 42/), 1)
if (any (a .ne. reshape ((/2, 3, 99, 4, 5, 6, 42, 7, 8/), (/3, 3/)))) &
STOP 13
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, (/2, -2, 0/), (/99, -1, 42/), 2)
if (any (a .ne. reshape ((/7, -1, 3, 99, -1, 6, 99, 2, 9/), (/3, 3/)))) &
STOP 14
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
sh = (/ 3, -1, -3 /)
bo = (/-999, -99, -9 /)
a = eoshift(a, shift=sh, boundary=bo)
if (any (a .ne. reshape ((/ -999, -999, -999, -99, 4, 5, -9, -9, -9 /), &
shape(a)))) STOP 15
a = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
a = eoshift (a, (/9999, -9999, 0/), (/99, -1, 42/), 2)
if (any (a .ne. reshape ((/99, -1, 3, 99, -1, 6, 99, -1, 9/), (/3, 3/)))) &
STOP 16
! Test arrays > rank 2
b(:, :, 1) = reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
b(:, :, 2) = 10 + reshape ((/1, 2, 3, 4, 5, 6, 7, 8, 9/), (/3, 3/))
b = eoshift (b, 1, 99, 1)
if (any (b(:, :, 1) .ne. reshape ((/2, 3, 99, 5, 6, 99, 8, 9, 99/), (/3, 3/)))) &
STOP 17
if (any (b(:, :, 2) .ne. reshape ((/12, 13, 99, 15, 16, 99, 18, 19, 99/), (/3, 3/)))) &
STOP 18
! TODO: Test array sections
end program
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/class_48.f90 | 144 | 3223 | ! { dg-do run }
!
! PR fortran/51972
! Also tests fixes for PR52102
!
! Check whether DT assignment with polymorphic components works.
!
subroutine test1 ()
type t
integer :: x
end type t
type t2
class(t), allocatable :: a
end type t2
type(t2) :: one, two
one = two
if (allocated (one%a)) call abort ()
allocate (two%a)
two%a%x = 7890
one = two
if (one%a%x /= 7890) call abort ()
deallocate (two%a)
one = two
if (allocated (one%a)) call abort ()
end subroutine test1
subroutine test2 ()
type t
integer, allocatable :: x(:)
end type t
type t2
class(t), allocatable :: a
end type t2
type(t2) :: one, two
one = two
if (allocated (one%a)) call abort ()
allocate (two%a)
one = two
if (.not.allocated (one%a)) call abort ()
if (allocated (one%a%x)) call abort ()
allocate (two%a%x(2))
two%a%x(:) = 7890
one = two
if (any (one%a%x /= 7890)) call abort ()
deallocate (two%a)
one = two
if (allocated (one%a)) call abort ()
end subroutine test2
subroutine test3 ()
type t
integer :: x
end type t
type t2
class(t), allocatable :: a(:)
end type t2
type(t2) :: one, two
! Test allocate with array source - PR52102
allocate (two%a(2), source = [t(4), t(6)])
if (allocated (one%a)) call abort ()
one = two
if (.not.allocated (one%a)) call abort ()
if ((one%a(1)%x /= 4)) call abort ()
if ((one%a(2)%x /= 6)) call abort ()
deallocate (two%a)
one = two
if (allocated (one%a)) call abort ()
! Test allocate with no source followed by assignments.
allocate (two%a(2))
two%a(1)%x = 5
two%a(2)%x = 7
if (allocated (one%a)) call abort ()
one = two
if (.not.allocated (one%a)) call abort ()
if ((one%a(1)%x /= 5)) call abort ()
if ((one%a(2)%x /= 7)) call abort ()
deallocate (two%a)
one = two
if (allocated (one%a)) call abort ()
end subroutine test3
subroutine test4 ()
type t
integer, allocatable :: x(:)
end type t
type t2
class(t), allocatable :: a(:)
end type t2
type(t2) :: one, two
if (allocated (one%a)) call abort ()
if (allocated (two%a)) call abort ()
allocate (two%a(2))
if (allocated (two%a(1)%x)) call abort ()
if (allocated (two%a(2)%x)) call abort ()
allocate (two%a(1)%x(3), source=[1,2,3])
allocate (two%a(2)%x(5), source=[5,6,7,8,9])
one = two
if (.not. allocated (one%a)) call abort ()
if (.not. allocated (one%a(1)%x)) call abort ()
if (.not. allocated (one%a(2)%x)) call abort ()
if (size(one%a) /= 2) call abort()
if (size(one%a(1)%x) /= 3) call abort()
if (size(one%a(2)%x) /= 5) call abort()
if (any (one%a(1)%x /= [1,2,3])) call abort ()
if (any (one%a(2)%x /= [5,6,7,8,9])) call abort ()
deallocate (two%a(1)%x)
one = two
if (.not. allocated (one%a)) call abort ()
if (allocated (one%a(1)%x)) call abort ()
if (.not. allocated (one%a(2)%x)) call abort ()
if (size(one%a) /= 2) call abort()
if (size(one%a(2)%x) /= 5) call abort()
if (any (one%a(2)%x /= [5,6,7,8,9])) call abort ()
deallocate (two%a)
one = two
if (allocated (one%a)) call abort ()
if (allocated (two%a)) call abort ()
end subroutine test4
call test1 ()
call test2 ()
call test3 ()
call test4 ()
end
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/function_optimize_2.f90 | 99 | 1513 | ! { dg-do compile }
! { dg-options "-O -faggressive-function-elimination -fdump-tree-original" }
program main
implicit none
real, dimension(2,2) :: a, b, c, d
real :: x, z
integer :: i
character(60) :: line
real, external :: ext_func
interface
elemental function element(x)
real, intent(in) :: x
real :: elem
end function element
pure function mypure(x)
real, intent(in) :: x
integer :: mypure
end function mypure
elemental impure function elem_impure(x)
real, intent(in) :: x
real :: elem_impure
end function elem_impure
end interface
data a /2., 3., 5., 7./
data b /11., 13., 17., 23./
write (unit=line, fmt='(4F7.2)') matmul(a,b) + matmul(a,b)
x = 1.2
z = sin(x) + cos(x) + sin(x) + cos(x)
print *,z
x = ext_func(a) + 23 + ext_func(a)
print *,d,x
z = element(x) + element(x)
print *,z
i = mypure(x) - mypure(x)
print *,i
z = elem_impure(x) - elem_impure(x)
print *,z
end program main
! { dg-final { scan-tree-dump-times "matmul_r4" 1 "original" } }
! { dg-final { scan-tree-dump-times "__builtin_sinf" 1 "original" } }
! { dg-final { scan-tree-dump-times "__builtin_cosf" 1 "original" } }
! { dg-final { scan-tree-dump-times "ext_func" 1 "original" } }
! { dg-final { scan-tree-dump-times "element" 1 "original" } }
! { dg-final { scan-tree-dump-times "mypure" 1 "original" } }
! { dg-final { scan-tree-dump-times "elem_impure" 1 "original" } }
! { dg-final { cleanup-tree-dump "original" } }
| gpl-2.0 |
tectronics/force-distribution-analysis.gromacs-4-5-3 | src/gmxlib/nonbonded/nb_kernel_f77_single/f77skernel103.f | 5 | 17572 | C
C This source code is part of
C
C G R O M A C S
C
C Copyright (c) 1991-2000, University of Groningen, The Netherlands.
C Copyright (c) 2001-2009, The GROMACS Development Team
C
C Gromacs is a library for molecular simulation and trajectory analysis,
C written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
C a full list of developers and information, check out http://www.gromacs.org
C
C This program is free software; you can redistribute it and/or modify it under
C the terms of the GNU Lesser General Public License as published by the Free
C Software Foundation; either version 2 of the License, or (at your option) any
C later version.
C As a special exception, you may use this file as part of a free software
C library without restriction. Specifically, if other files instantiate
C templates or use macros or inline functions from this file, or you compile
C this file and link it with other files to produce an executable, this
C file does not by itself cause the resulting executable to be covered by
C the GNU Lesser General Public License.
C
C In plain-speak: do not worry about classes/macros/templates either - only
C changes to the library have to be LGPL, not an application linking with it.
C
C To help fund GROMACS development, we humbly ask that you cite
C the papers people have written on it - you can find them on the website!
C
C
C Gromacs nonbonded kernel f77skernel103
C Coulomb interaction: Normal Coulomb
C VdW interaction: Not calculated
C water optimization: TIP4P - other atoms
C Calculate forces: yes
C
subroutine f77skernel103(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
real*4 shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
real*4 charge(*),facel,krf,crf,Vc(*),vdwparam(*)
real*4 Vvdw(*),tabscale,VFtab(*)
real*4 invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
real*4 work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
real*4 shX,shY,shZ
real*4 fscal,tx,ty,tz
real*4 rinvsq
real*4 jq
real*4 qq,vcoul,vctot
real*4 ix2,iy2,iz2,fix2,fiy2,fiz2
real*4 ix3,iy3,iz3,fix3,fiy3,fiz3
real*4 ix4,iy4,iz4,fix4,fiy4,fiz4
real*4 jx1,jy1,jz1,fjx1,fjy1,fjz1
real*4 dx21,dy21,dz21,rsq21,rinv21
real*4 dx31,dy31,dz31,rsq31,rinv31
real*4 dx41,dy41,dz41,rsq41,rinv41
real*4 qH,qM
C Initialize water data
ii = iinr(1)+1
qH = facel*charge(ii+1)
qM = facel*charge(ii+3)
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call f77kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix2 = shX + pos(ii3+3)
iy2 = shY + pos(ii3+4)
iz2 = shZ + pos(ii3+5)
ix3 = shX + pos(ii3+6)
iy3 = shY + pos(ii3+7)
iz3 = shZ + pos(ii3+8)
ix4 = shX + pos(ii3+9)
iy4 = shY + pos(ii3+10)
iz4 = shZ + pos(ii3+11)
C Zero the potential energy for this list
vctot = 0
C Clear i atom forces
fix2 = 0
fiy2 = 0
fiz2 = 0
fix3 = 0
fiy3 = 0
fiz3 = 0
fix4 = 0
fiy4 = 0
fiz4 = 0
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx21 = ix2 - jx1
dy21 = iy2 - jy1
dz21 = iz2 - jz1
rsq21 = dx21*dx21+dy21*dy21+dz21*dz21
dx31 = ix3 - jx1
dy31 = iy3 - jy1
dz31 = iz3 - jz1
rsq31 = dx31*dx31+dy31*dy31+dz31*dz31
dx41 = ix4 - jx1
dy41 = iy4 - jy1
dz41 = iz4 - jz1
rsq41 = dx41*dx41+dy41*dy41+dz41*dz41
C Calculate 1/r and 1/r2
rinv21 = 1.0/sqrt(rsq21)
rinv31 = 1.0/sqrt(rsq31)
rinv41 = 1.0/sqrt(rsq41)
C Load parameters for j atom
jq = charge(jnr+0)
qq = qH*jq
rinvsq = rinv21*rinv21
C Coulomb interaction
vcoul = qq*rinv21
vctot = vctot+vcoul
fscal = (vcoul)*rinvsq
C Calculate temporary vectorial force
tx = fscal*dx21
ty = fscal*dy21
tz = fscal*dz21
C Increment i atom force
fix2 = fix2 + tx
fiy2 = fiy2 + ty
fiz2 = fiz2 + tz
C Decrement j atom force
fjx1 = faction(j3+0) - tx
fjy1 = faction(j3+1) - ty
fjz1 = faction(j3+2) - tz
C Load parameters for j atom
rinvsq = rinv31*rinv31
C Coulomb interaction
vcoul = qq*rinv31
vctot = vctot+vcoul
fscal = (vcoul)*rinvsq
C Calculate temporary vectorial force
tx = fscal*dx31
ty = fscal*dy31
tz = fscal*dz31
C Increment i atom force
fix3 = fix3 + tx
fiy3 = fiy3 + ty
fiz3 = fiz3 + tz
C Decrement j atom force
fjx1 = fjx1 - tx
fjy1 = fjy1 - ty
fjz1 = fjz1 - tz
C Load parameters for j atom
qq = qM*jq
rinvsq = rinv41*rinv41
C Coulomb interaction
vcoul = qq*rinv41
vctot = vctot+vcoul
fscal = (vcoul)*rinvsq
C Calculate temporary vectorial force
tx = fscal*dx41
ty = fscal*dy41
tz = fscal*dz41
C Increment i atom force
fix4 = fix4 + tx
fiy4 = fiy4 + ty
fiz4 = fiz4 + tz
C Decrement j atom force
faction(j3+0) = fjx1 - tx
faction(j3+1) = fjy1 - ty
faction(j3+2) = fjz1 - tz
C Inner loop uses 80 flops/iteration
end do
C Add i forces to mem and shifted force list
faction(ii3+3) = faction(ii3+3) + fix2
faction(ii3+4) = faction(ii3+4) + fiy2
faction(ii3+5) = faction(ii3+5) + fiz2
faction(ii3+6) = faction(ii3+6) + fix3
faction(ii3+7) = faction(ii3+7) + fiy3
faction(ii3+8) = faction(ii3+8) + fiz3
faction(ii3+9) = faction(ii3+9) + fix4
faction(ii3+10) = faction(ii3+10) + fiy4
faction(ii3+11) = faction(ii3+11) + fiz4
fshift(is3) = fshift(is3)+fix2+fix3+fix4
fshift(is3+1) = fshift(is3+1)+fiy2+fiy3+fiy4
fshift(is3+2) = fshift(is3+2)+fiz2+fiz3+fiz4
C Add potential energies to the group for this list
ggid = gid(n)+1
Vc(ggid) = Vc(ggid) + vctot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 28 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
C
C Gromacs nonbonded kernel f77skernel103nf
C Coulomb interaction: Normal Coulomb
C VdW interaction: Not calculated
C water optimization: TIP4P - other atoms
C Calculate forces: no
C
subroutine f77skernel103nf(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
real*4 shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
real*4 charge(*),facel,krf,crf,Vc(*),vdwparam(*)
real*4 Vvdw(*),tabscale,VFtab(*)
real*4 invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
real*4 work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
real*4 shX,shY,shZ
real*4 jq
real*4 qq,vcoul,vctot
real*4 ix2,iy2,iz2
real*4 ix3,iy3,iz3
real*4 ix4,iy4,iz4
real*4 jx1,jy1,jz1
real*4 dx21,dy21,dz21,rsq21,rinv21
real*4 dx31,dy31,dz31,rsq31,rinv31
real*4 dx41,dy41,dz41,rsq41,rinv41
real*4 qH,qM
C Initialize water data
ii = iinr(1)+1
qH = facel*charge(ii+1)
qM = facel*charge(ii+3)
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call f77kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix2 = shX + pos(ii3+3)
iy2 = shY + pos(ii3+4)
iz2 = shZ + pos(ii3+5)
ix3 = shX + pos(ii3+6)
iy3 = shY + pos(ii3+7)
iz3 = shZ + pos(ii3+8)
ix4 = shX + pos(ii3+9)
iy4 = shY + pos(ii3+10)
iz4 = shZ + pos(ii3+11)
C Zero the potential energy for this list
vctot = 0
C Clear i atom forces
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx21 = ix2 - jx1
dy21 = iy2 - jy1
dz21 = iz2 - jz1
rsq21 = dx21*dx21+dy21*dy21+dz21*dz21
dx31 = ix3 - jx1
dy31 = iy3 - jy1
dz31 = iz3 - jz1
rsq31 = dx31*dx31+dy31*dy31+dz31*dz31
dx41 = ix4 - jx1
dy41 = iy4 - jy1
dz41 = iz4 - jz1
rsq41 = dx41*dx41+dy41*dy41+dz41*dz41
C Calculate 1/r and 1/r2
rinv21 = 1.0/sqrt(rsq21)
rinv31 = 1.0/sqrt(rsq31)
rinv41 = 1.0/sqrt(rsq41)
C Load parameters for j atom
jq = charge(jnr+0)
qq = qH*jq
C Coulomb interaction
vcoul = qq*rinv21
vctot = vctot+vcoul
C Load parameters for j atom
C Coulomb interaction
vcoul = qq*rinv31
vctot = vctot+vcoul
C Load parameters for j atom
qq = qM*jq
C Coulomb interaction
vcoul = qq*rinv41
vctot = vctot+vcoul
C Inner loop uses 47 flops/iteration
end do
C Add i forces to mem and shifted force list
C Add potential energies to the group for this list
ggid = gid(n)+1
Vc(ggid) = Vc(ggid) + vctot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 10 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
| gpl-2.0 |
mlandry1/CarND | Labs/Term2/CarND-MPC-Quizzes/polyfit/src/Eigen-3.3/blas/testing/sblat3.f | 133 | 104172 | *> \brief \b SBLAT3
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* PROGRAM SBLAT3
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> Test program for the REAL Level 3 Blas.
*>
*> The program must be driven by a short data file. The first 14 records
*> of the file are read using list-directed input, the last 6 records
*> are read using the format ( A6, L2 ). An annotated example of a data
*> file can be obtained by deleting the first 3 characters from the
*> following 20 lines:
*> 'sblat3.out' NAME OF SUMMARY OUTPUT FILE
*> 6 UNIT NUMBER OF SUMMARY FILE
*> 'SBLAT3.SNAP' NAME OF SNAPSHOT OUTPUT FILE
*> -1 UNIT NUMBER OF SNAPSHOT FILE (NOT USED IF .LT. 0)
*> F LOGICAL FLAG, T TO REWIND SNAPSHOT FILE AFTER EACH RECORD.
*> F LOGICAL FLAG, T TO STOP ON FAILURES.
*> T LOGICAL FLAG, T TO TEST ERROR EXITS.
*> 16.0 THRESHOLD VALUE OF TEST RATIO
*> 6 NUMBER OF VALUES OF N
*> 0 1 2 3 5 9 VALUES OF N
*> 3 NUMBER OF VALUES OF ALPHA
*> 0.0 1.0 0.7 VALUES OF ALPHA
*> 3 NUMBER OF VALUES OF BETA
*> 0.0 1.0 1.3 VALUES OF BETA
*> SGEMM T PUT F FOR NO TEST. SAME COLUMNS.
*> SSYMM T PUT F FOR NO TEST. SAME COLUMNS.
*> STRMM T PUT F FOR NO TEST. SAME COLUMNS.
*> STRSM T PUT F FOR NO TEST. SAME COLUMNS.
*> SSYRK T PUT F FOR NO TEST. SAME COLUMNS.
*> SSYR2K T PUT F FOR NO TEST. SAME COLUMNS.
*>
*> Further Details
*> ===============
*>
*> See:
*>
*> Dongarra J. J., Du Croz J. J., Duff I. S. and Hammarling S.
*> A Set of Level 3 Basic Linear Algebra Subprograms.
*>
*> Technical Memorandum No.88 (Revision 1), Mathematics and
*> Computer Science Division, Argonne National Laboratory, 9700
*> South Cass Avenue, Argonne, Illinois 60439, US.
*>
*> -- Written on 8-February-1989.
*> Jack Dongarra, Argonne National Laboratory.
*> Iain Duff, AERE Harwell.
*> Jeremy Du Croz, Numerical Algorithms Group Ltd.
*> Sven Hammarling, Numerical Algorithms Group Ltd.
*>
*> 10-9-00: Change STATUS='NEW' to 'UNKNOWN' so that the testers
*> can be run multiple times without deleting generated
*> output files (susan)
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date April 2012
*
*> \ingroup single_blas_testing
*
* =====================================================================
PROGRAM SBLAT3
*
* -- Reference BLAS test routine (version 3.4.1) --
* -- Reference BLAS is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* April 2012
*
* =====================================================================
*
* .. Parameters ..
INTEGER NIN
PARAMETER ( NIN = 5 )
INTEGER NSUBS
PARAMETER ( NSUBS = 6 )
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0, ONE = 1.0 )
INTEGER NMAX
PARAMETER ( NMAX = 65 )
INTEGER NIDMAX, NALMAX, NBEMAX
PARAMETER ( NIDMAX = 9, NALMAX = 7, NBEMAX = 7 )
* .. Local Scalars ..
REAL EPS, ERR, THRESH
INTEGER I, ISNUM, J, N, NALF, NBET, NIDIM, NOUT, NTRA
LOGICAL FATAL, LTESTT, REWI, SAME, SFATAL, TRACE,
$ TSTERR
CHARACTER*1 TRANSA, TRANSB
CHARACTER*6 SNAMET
CHARACTER*32 SNAPS, SUMMRY
* .. Local Arrays ..
REAL AA( NMAX*NMAX ), AB( NMAX, 2*NMAX ),
$ ALF( NALMAX ), AS( NMAX*NMAX ),
$ BB( NMAX*NMAX ), BET( NBEMAX ),
$ BS( NMAX*NMAX ), C( NMAX, NMAX ),
$ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ),
$ G( NMAX ), W( 2*NMAX )
INTEGER IDIM( NIDMAX )
LOGICAL LTEST( NSUBS )
CHARACTER*6 SNAMES( NSUBS )
* .. External Functions ..
REAL SDIFF
LOGICAL LSE
EXTERNAL SDIFF, LSE
* .. External Subroutines ..
EXTERNAL SCHK1, SCHK2, SCHK3, SCHK4, SCHK5, SCHKE, SMMCH
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
COMMON /SRNAMC/SRNAMT
* .. Data statements ..
DATA SNAMES/'SGEMM ', 'SSYMM ', 'STRMM ', 'STRSM ',
$ 'SSYRK ', 'SSYR2K'/
* .. Executable Statements ..
*
* Read name and unit number for summary output file and open file.
*
READ( NIN, FMT = * )SUMMRY
READ( NIN, FMT = * )NOUT
OPEN( NOUT, FILE = SUMMRY )
NOUTC = NOUT
*
* Read name and unit number for snapshot output file and open file.
*
READ( NIN, FMT = * )SNAPS
READ( NIN, FMT = * )NTRA
TRACE = NTRA.GE.0
IF( TRACE )THEN
OPEN( NTRA, FILE = SNAPS )
END IF
* Read the flag that directs rewinding of the snapshot file.
READ( NIN, FMT = * )REWI
REWI = REWI.AND.TRACE
* Read the flag that directs stopping on any failure.
READ( NIN, FMT = * )SFATAL
* Read the flag that indicates whether error exits are to be tested.
READ( NIN, FMT = * )TSTERR
* Read the threshold value of the test ratio
READ( NIN, FMT = * )THRESH
*
* Read and check the parameter values for the tests.
*
* Values of N
READ( NIN, FMT = * )NIDIM
IF( NIDIM.LT.1.OR.NIDIM.GT.NIDMAX )THEN
WRITE( NOUT, FMT = 9997 )'N', NIDMAX
GO TO 220
END IF
READ( NIN, FMT = * )( IDIM( I ), I = 1, NIDIM )
DO 10 I = 1, NIDIM
IF( IDIM( I ).LT.0.OR.IDIM( I ).GT.NMAX )THEN
WRITE( NOUT, FMT = 9996 )NMAX
GO TO 220
END IF
10 CONTINUE
* Values of ALPHA
READ( NIN, FMT = * )NALF
IF( NALF.LT.1.OR.NALF.GT.NALMAX )THEN
WRITE( NOUT, FMT = 9997 )'ALPHA', NALMAX
GO TO 220
END IF
READ( NIN, FMT = * )( ALF( I ), I = 1, NALF )
* Values of BETA
READ( NIN, FMT = * )NBET
IF( NBET.LT.1.OR.NBET.GT.NBEMAX )THEN
WRITE( NOUT, FMT = 9997 )'BETA', NBEMAX
GO TO 220
END IF
READ( NIN, FMT = * )( BET( I ), I = 1, NBET )
*
* Report values of parameters.
*
WRITE( NOUT, FMT = 9995 )
WRITE( NOUT, FMT = 9994 )( IDIM( I ), I = 1, NIDIM )
WRITE( NOUT, FMT = 9993 )( ALF( I ), I = 1, NALF )
WRITE( NOUT, FMT = 9992 )( BET( I ), I = 1, NBET )
IF( .NOT.TSTERR )THEN
WRITE( NOUT, FMT = * )
WRITE( NOUT, FMT = 9984 )
END IF
WRITE( NOUT, FMT = * )
WRITE( NOUT, FMT = 9999 )THRESH
WRITE( NOUT, FMT = * )
*
* Read names of subroutines and flags which indicate
* whether they are to be tested.
*
DO 20 I = 1, NSUBS
LTEST( I ) = .FALSE.
20 CONTINUE
30 READ( NIN, FMT = 9988, END = 60 )SNAMET, LTESTT
DO 40 I = 1, NSUBS
IF( SNAMET.EQ.SNAMES( I ) )
$ GO TO 50
40 CONTINUE
WRITE( NOUT, FMT = 9990 )SNAMET
STOP
50 LTEST( I ) = LTESTT
GO TO 30
*
60 CONTINUE
CLOSE ( NIN )
*
* Compute EPS (the machine precision).
*
EPS = EPSILON(ZERO)
WRITE( NOUT, FMT = 9998 )EPS
*
* Check the reliability of SMMCH using exact data.
*
N = MIN( 32, NMAX )
DO 100 J = 1, N
DO 90 I = 1, N
AB( I, J ) = MAX( I - J + 1, 0 )
90 CONTINUE
AB( J, NMAX + 1 ) = J
AB( 1, NMAX + J ) = J
C( J, 1 ) = ZERO
100 CONTINUE
DO 110 J = 1, N
CC( J ) = J*( ( J + 1 )*J )/2 - ( ( J + 1 )*J*( J - 1 ) )/3
110 CONTINUE
* CC holds the exact result. On exit from SMMCH CT holds
* the result computed by SMMCH.
TRANSA = 'N'
TRANSB = 'N'
CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LSE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
TRANSB = 'T'
CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LSE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
DO 120 J = 1, N
AB( J, NMAX + 1 ) = N - J + 1
AB( 1, NMAX + J ) = N - J + 1
120 CONTINUE
DO 130 J = 1, N
CC( N - J + 1 ) = J*( ( J + 1 )*J )/2 -
$ ( ( J + 1 )*J*( J - 1 ) )/3
130 CONTINUE
TRANSA = 'T'
TRANSB = 'N'
CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LSE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
TRANSB = 'T'
CALL SMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LSE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.ZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
*
* Test each subroutine in turn.
*
DO 200 ISNUM = 1, NSUBS
WRITE( NOUT, FMT = * )
IF( .NOT.LTEST( ISNUM ) )THEN
* Subprogram is not to be tested.
WRITE( NOUT, FMT = 9987 )SNAMES( ISNUM )
ELSE
SRNAMT = SNAMES( ISNUM )
* Test error exits.
IF( TSTERR )THEN
CALL SCHKE( ISNUM, SNAMES( ISNUM ), NOUT )
WRITE( NOUT, FMT = * )
END IF
* Test computations.
INFOT = 0
OK = .TRUE.
FATAL = .FALSE.
GO TO ( 140, 150, 160, 160, 170, 180 )ISNUM
* Test SGEMM, 01.
140 CALL SCHK1( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test SSYMM, 02.
150 CALL SCHK2( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test STRMM, 03, STRSM, 04.
160 CALL SCHK3( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NMAX, AB,
$ AA, AS, AB( 1, NMAX + 1 ), BB, BS, CT, G, C )
GO TO 190
* Test SSYRK, 05.
170 CALL SCHK4( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test SSYR2K, 06.
180 CALL SCHK5( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, BB, BS, C, CC, CS, CT, G, W )
GO TO 190
*
190 IF( FATAL.AND.SFATAL )
$ GO TO 210
END IF
200 CONTINUE
WRITE( NOUT, FMT = 9986 )
GO TO 230
*
210 CONTINUE
WRITE( NOUT, FMT = 9985 )
GO TO 230
*
220 CONTINUE
WRITE( NOUT, FMT = 9991 )
*
230 CONTINUE
IF( TRACE )
$ CLOSE ( NTRA )
CLOSE ( NOUT )
STOP
*
9999 FORMAT( ' ROUTINES PASS COMPUTATIONAL TESTS IF TEST RATIO IS LES',
$ 'S THAN', F8.2 )
9998 FORMAT( ' RELATIVE MACHINE PRECISION IS TAKEN TO BE', 1P, E9.1 )
9997 FORMAT( ' NUMBER OF VALUES OF ', A, ' IS LESS THAN 1 OR GREATER ',
$ 'THAN ', I2 )
9996 FORMAT( ' VALUE OF N IS LESS THAN 0 OR GREATER THAN ', I2 )
9995 FORMAT( ' TESTS OF THE REAL LEVEL 3 BLAS', //' THE F',
$ 'OLLOWING PARAMETER VALUES WILL BE USED:' )
9994 FORMAT( ' FOR N ', 9I6 )
9993 FORMAT( ' FOR ALPHA ', 7F6.1 )
9992 FORMAT( ' FOR BETA ', 7F6.1 )
9991 FORMAT( ' AMEND DATA FILE OR INCREASE ARRAY SIZES IN PROGRAM',
$ /' ******* TESTS ABANDONED *******' )
9990 FORMAT( ' SUBPROGRAM NAME ', A6, ' NOT RECOGNIZED', /' ******* T',
$ 'ESTS ABANDONED *******' )
9989 FORMAT( ' ERROR IN SMMCH - IN-LINE DOT PRODUCTS ARE BEING EVALU',
$ 'ATED WRONGLY.', /' SMMCH WAS CALLED WITH TRANSA = ', A1,
$ ' AND TRANSB = ', A1, /' AND RETURNED SAME = ', L1, ' AND ',
$ 'ERR = ', F12.3, '.', /' THIS MAY BE DUE TO FAULTS IN THE ',
$ 'ARITHMETIC OR THE COMPILER.', /' ******* TESTS ABANDONED ',
$ '*******' )
9988 FORMAT( A6, L2 )
9987 FORMAT( 1X, A6, ' WAS NOT TESTED' )
9986 FORMAT( /' END OF TESTS' )
9985 FORMAT( /' ******* FATAL ERROR - TESTS ABANDONED *******' )
9984 FORMAT( ' ERROR-EXITS WILL NOT BE TESTED' )
*
* End of SBLAT3.
*
END
SUBROUTINE SCHK1( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests SGEMM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
REAL ALPHA, ALS, BETA, BLS, ERR, ERRMAX
INTEGER I, IA, IB, ICA, ICB, IK, IM, IN, K, KS, LAA,
$ LBB, LCC, LDA, LDAS, LDB, LDBS, LDC, LDCS, M,
$ MA, MB, MS, N, NA, NARGS, NB, NC, NS
LOGICAL NULL, RESET, SAME, TRANA, TRANB
CHARACTER*1 TRANAS, TRANBS, TRANSA, TRANSB
CHARACTER*3 ICH
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LSE, LSERES
EXTERNAL LSE, LSERES
* .. External Subroutines ..
EXTERNAL SGEMM, SMAKE, SMMCH
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICH/'NTC'/
* .. Executable Statements ..
*
NARGS = 13
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 110 IM = 1, NIDIM
M = IDIM( IM )
*
DO 100 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = M
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 100
LCC = LDC*N
NULL = N.LE.0.OR.M.LE.0
*
DO 90 IK = 1, NIDIM
K = IDIM( IK )
*
DO 80 ICA = 1, 3
TRANSA = ICH( ICA: ICA )
TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C'
*
IF( TRANA )THEN
MA = K
NA = M
ELSE
MA = M
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
* Generate the matrix A.
*
CALL SMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 70 ICB = 1, 3
TRANSB = ICH( ICB: ICB )
TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C'
*
IF( TRANB )THEN
MB = N
NB = K
ELSE
MB = K
NB = N
END IF
* Set LDB to 1 more than minimum value if room.
LDB = MB
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 70
LBB = LDB*NB
*
* Generate the matrix B.
*
CALL SMAKE( 'GE', ' ', ' ', MB, NB, B, NMAX, BB,
$ LDB, RESET, ZERO )
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL SMAKE( 'GE', ' ', ' ', M, N, C, NMAX,
$ CC, LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
TRANAS = TRANSA
TRANBS = TRANSB
MS = M
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BLS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ TRANSA, TRANSB, M, N, K, ALPHA, LDA, LDB,
$ BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL SGEMM( TRANSA, TRANSB, M, N, K, ALPHA,
$ AA, LDA, BB, LDB, BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 120
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = TRANSA.EQ.TRANAS
ISAME( 2 ) = TRANSB.EQ.TRANBS
ISAME( 3 ) = MS.EQ.M
ISAME( 4 ) = NS.EQ.N
ISAME( 5 ) = KS.EQ.K
ISAME( 6 ) = ALS.EQ.ALPHA
ISAME( 7 ) = LSE( AS, AA, LAA )
ISAME( 8 ) = LDAS.EQ.LDA
ISAME( 9 ) = LSE( BS, BB, LBB )
ISAME( 10 ) = LDBS.EQ.LDB
ISAME( 11 ) = BLS.EQ.BETA
IF( NULL )THEN
ISAME( 12 ) = LSE( CS, CC, LCC )
ELSE
ISAME( 12 ) = LSERES( 'GE', ' ', M, N, CS,
$ CC, LDC )
END IF
ISAME( 13 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report
* and return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 120
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result.
*
CALL SMMCH( TRANSA, TRANSB, M, N, K,
$ ALPHA, A, NMAX, B, NMAX, BETA,
$ C, NMAX, CT, G, CC, LDC, EPS,
$ ERR, FATAL, NOUT, .TRUE. )
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 120
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 130
*
120 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, TRANSA, TRANSB, M, N, K,
$ ALPHA, LDA, LDB, BETA, LDC
*
130 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(''', A1, ''',''', A1, ''',',
$ 3( I3, ',' ), F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', ',
$ 'C,', I3, ').' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of SCHK1.
*
END
SUBROUTINE SCHK2( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests SSYMM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
REAL ALPHA, ALS, BETA, BLS, ERR, ERRMAX
INTEGER I, IA, IB, ICS, ICU, IM, IN, LAA, LBB, LCC,
$ LDA, LDAS, LDB, LDBS, LDC, LDCS, M, MS, N, NA,
$ NARGS, NC, NS
LOGICAL LEFT, NULL, RESET, SAME
CHARACTER*1 SIDE, SIDES, UPLO, UPLOS
CHARACTER*2 ICHS, ICHU
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LSE, LSERES
EXTERNAL LSE, LSERES
* .. External Subroutines ..
EXTERNAL SMAKE, SMMCH, SSYMM
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHS/'LR'/, ICHU/'UL'/
* .. Executable Statements ..
*
NARGS = 12
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 100 IM = 1, NIDIM
M = IDIM( IM )
*
DO 90 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = M
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 90
LCC = LDC*N
NULL = N.LE.0.OR.M.LE.0
*
* Set LDB to 1 more than minimum value if room.
LDB = M
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 90
LBB = LDB*N
*
* Generate the matrix B.
*
CALL SMAKE( 'GE', ' ', ' ', M, N, B, NMAX, BB, LDB, RESET,
$ ZERO )
*
DO 80 ICS = 1, 2
SIDE = ICHS( ICS: ICS )
LEFT = SIDE.EQ.'L'
*
IF( LEFT )THEN
NA = M
ELSE
NA = N
END IF
* Set LDA to 1 more than minimum value if room.
LDA = NA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
DO 70 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
*
* Generate the symmetric matrix A.
*
CALL SMAKE( 'SY', UPLO, ' ', NA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL SMAKE( 'GE', ' ', ' ', M, N, C, NMAX, CC,
$ LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
SIDES = SIDE
UPLOS = UPLO
MS = M
NS = N
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BLS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME, SIDE,
$ UPLO, M, N, ALPHA, LDA, LDB, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL SSYMM( SIDE, UPLO, M, N, ALPHA, AA, LDA,
$ BB, LDB, BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 110
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = SIDES.EQ.SIDE
ISAME( 2 ) = UPLOS.EQ.UPLO
ISAME( 3 ) = MS.EQ.M
ISAME( 4 ) = NS.EQ.N
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LSE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = LSE( BS, BB, LBB )
ISAME( 9 ) = LDBS.EQ.LDB
ISAME( 10 ) = BLS.EQ.BETA
IF( NULL )THEN
ISAME( 11 ) = LSE( CS, CC, LCC )
ELSE
ISAME( 11 ) = LSERES( 'GE', ' ', M, N, CS,
$ CC, LDC )
END IF
ISAME( 12 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 110
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result.
*
IF( LEFT )THEN
CALL SMMCH( 'N', 'N', M, N, M, ALPHA, A,
$ NMAX, B, NMAX, BETA, C, NMAX,
$ CT, G, CC, LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL SMMCH( 'N', 'N', M, N, N, ALPHA, B,
$ NMAX, A, NMAX, BETA, C, NMAX,
$ CT, G, CC, LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 110
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 120
*
110 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, M, N, ALPHA, LDA,
$ LDB, BETA, LDC
*
120 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', C,', I3, ') ',
$ ' .' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of SCHK2.
*
END
SUBROUTINE SCHK3( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NMAX, A, AA, AS,
$ B, BB, BS, CT, G, C )
*
* Tests STRMM and STRSM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0, ONE = 1.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
REAL ALPHA, ALS, ERR, ERRMAX
INTEGER I, IA, ICD, ICS, ICT, ICU, IM, IN, J, LAA, LBB,
$ LDA, LDAS, LDB, LDBS, M, MS, N, NA, NARGS, NC,
$ NS
LOGICAL LEFT, NULL, RESET, SAME
CHARACTER*1 DIAG, DIAGS, SIDE, SIDES, TRANAS, TRANSA, UPLO,
$ UPLOS
CHARACTER*2 ICHD, ICHS, ICHU
CHARACTER*3 ICHT
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LSE, LSERES
EXTERNAL LSE, LSERES
* .. External Subroutines ..
EXTERNAL SMAKE, SMMCH, STRMM, STRSM
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHU/'UL'/, ICHT/'NTC'/, ICHD/'UN'/, ICHS/'LR'/
* .. Executable Statements ..
*
NARGS = 11
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
* Set up zero matrix for SMMCH.
DO 20 J = 1, NMAX
DO 10 I = 1, NMAX
C( I, J ) = ZERO
10 CONTINUE
20 CONTINUE
*
DO 140 IM = 1, NIDIM
M = IDIM( IM )
*
DO 130 IN = 1, NIDIM
N = IDIM( IN )
* Set LDB to 1 more than minimum value if room.
LDB = M
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 130
LBB = LDB*N
NULL = M.LE.0.OR.N.LE.0
*
DO 120 ICS = 1, 2
SIDE = ICHS( ICS: ICS )
LEFT = SIDE.EQ.'L'
IF( LEFT )THEN
NA = M
ELSE
NA = N
END IF
* Set LDA to 1 more than minimum value if room.
LDA = NA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 130
LAA = LDA*NA
*
DO 110 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
*
DO 100 ICT = 1, 3
TRANSA = ICHT( ICT: ICT )
*
DO 90 ICD = 1, 2
DIAG = ICHD( ICD: ICD )
*
DO 80 IA = 1, NALF
ALPHA = ALF( IA )
*
* Generate the matrix A.
*
CALL SMAKE( 'TR', UPLO, DIAG, NA, NA, A,
$ NMAX, AA, LDA, RESET, ZERO )
*
* Generate the matrix B.
*
CALL SMAKE( 'GE', ' ', ' ', M, N, B, NMAX,
$ BB, LDB, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
SIDES = SIDE
UPLOS = UPLO
TRANAS = TRANSA
DIAGS = DIAG
MS = M
NS = N
ALS = ALPHA
DO 30 I = 1, LAA
AS( I ) = AA( I )
30 CONTINUE
LDAS = LDA
DO 40 I = 1, LBB
BS( I ) = BB( I )
40 CONTINUE
LDBS = LDB
*
* Call the subroutine.
*
IF( SNAME( 4: 5 ).EQ.'MM' )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA,
$ LDA, LDB
IF( REWI )
$ REWIND NTRA
CALL STRMM( SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, AA, LDA, BB, LDB )
ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA,
$ LDA, LDB
IF( REWI )
$ REWIND NTRA
CALL STRSM( SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, AA, LDA, BB, LDB )
END IF
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 150
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = SIDES.EQ.SIDE
ISAME( 2 ) = UPLOS.EQ.UPLO
ISAME( 3 ) = TRANAS.EQ.TRANSA
ISAME( 4 ) = DIAGS.EQ.DIAG
ISAME( 5 ) = MS.EQ.M
ISAME( 6 ) = NS.EQ.N
ISAME( 7 ) = ALS.EQ.ALPHA
ISAME( 8 ) = LSE( AS, AA, LAA )
ISAME( 9 ) = LDAS.EQ.LDA
IF( NULL )THEN
ISAME( 10 ) = LSE( BS, BB, LBB )
ELSE
ISAME( 10 ) = LSERES( 'GE', ' ', M, N, BS,
$ BB, LDB )
END IF
ISAME( 11 ) = LDBS.EQ.LDB
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 50 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
50 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 150
END IF
*
IF( .NOT.NULL )THEN
IF( SNAME( 4: 5 ).EQ.'MM' )THEN
*
* Check the result.
*
IF( LEFT )THEN
CALL SMMCH( TRANSA, 'N', M, N, M,
$ ALPHA, A, NMAX, B, NMAX,
$ ZERO, C, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL SMMCH( 'N', TRANSA, M, N, N,
$ ALPHA, B, NMAX, A, NMAX,
$ ZERO, C, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN
*
* Compute approximation to original
* matrix.
*
DO 70 J = 1, N
DO 60 I = 1, M
C( I, J ) = BB( I + ( J - 1 )*
$ LDB )
BB( I + ( J - 1 )*LDB ) = ALPHA*
$ B( I, J )
60 CONTINUE
70 CONTINUE
*
IF( LEFT )THEN
CALL SMMCH( TRANSA, 'N', M, N, M,
$ ONE, A, NMAX, C, NMAX,
$ ZERO, B, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .FALSE. )
ELSE
CALL SMMCH( 'N', TRANSA, M, N, N,
$ ONE, C, NMAX, A, NMAX,
$ ZERO, B, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .FALSE. )
END IF
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 150
END IF
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
120 CONTINUE
*
130 CONTINUE
*
140 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 160
*
150 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, LDA, LDB
*
160 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(', 4( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ', B,', I3, ') .' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of SCHK3.
*
END
SUBROUTINE SCHK4( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests SSYRK.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
REAL A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX ), G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
REAL ALPHA, ALS, BETA, BETS, ERR, ERRMAX
INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, K, KS,
$ LAA, LCC, LDA, LDAS, LDC, LDCS, LJ, MA, N, NA,
$ NARGS, NC, NS
LOGICAL NULL, RESET, SAME, TRAN, UPPER
CHARACTER*1 TRANS, TRANSS, UPLO, UPLOS
CHARACTER*2 ICHU
CHARACTER*3 ICHT
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LSE, LSERES
EXTERNAL LSE, LSERES
* .. External Subroutines ..
EXTERNAL SMAKE, SMMCH, SSYRK
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHT/'NTC'/, ICHU/'UL'/
* .. Executable Statements ..
*
NARGS = 10
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 100 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = N
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 100
LCC = LDC*N
NULL = N.LE.0
*
DO 90 IK = 1, NIDIM
K = IDIM( IK )
*
DO 80 ICT = 1, 3
TRANS = ICHT( ICT: ICT )
TRAN = TRANS.EQ.'T'.OR.TRANS.EQ.'C'
IF( TRAN )THEN
MA = K
NA = N
ELSE
MA = N
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
* Generate the matrix A.
*
CALL SMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 70 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
UPPER = UPLO.EQ.'U'
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL SMAKE( 'SY', UPLO, ' ', N, N, C, NMAX, CC,
$ LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the subroutine.
*
UPLOS = UPLO
TRANSS = TRANS
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
BETS = BETA
DO 20 I = 1, LCC
CS( I ) = CC( I )
20 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO,
$ TRANS, N, K, ALPHA, LDA, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL SSYRK( UPLO, TRANS, N, K, ALPHA, AA, LDA,
$ BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9993 )
FATAL = .TRUE.
GO TO 120
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = UPLOS.EQ.UPLO
ISAME( 2 ) = TRANSS.EQ.TRANS
ISAME( 3 ) = NS.EQ.N
ISAME( 4 ) = KS.EQ.K
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LSE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = BETS.EQ.BETA
IF( NULL )THEN
ISAME( 9 ) = LSE( CS, CC, LCC )
ELSE
ISAME( 9 ) = LSERES( 'SY', UPLO, N, N, CS,
$ CC, LDC )
END IF
ISAME( 10 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 30 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
30 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 120
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result column by column.
*
JC = 1
DO 40 J = 1, N
IF( UPPER )THEN
JJ = 1
LJ = J
ELSE
JJ = J
LJ = N - J + 1
END IF
IF( TRAN )THEN
CALL SMMCH( 'T', 'N', LJ, 1, K, ALPHA,
$ A( 1, JJ ), NMAX,
$ A( 1, J ), NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL SMMCH( 'N', 'T', LJ, 1, K, ALPHA,
$ A( JJ, 1 ), NMAX,
$ A( J, 1 ), NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
IF( UPPER )THEN
JC = JC + LDC
ELSE
JC = JC + LDC + 1
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 110
40 CONTINUE
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 130
*
110 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9995 )J
*
120 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, ALPHA,
$ LDA, BETA, LDC
*
130 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ',', F4.1, ', C,', I3, ') .' )
9993 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of SCHK4.
*
END
SUBROUTINE SCHK5( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ AB, AA, AS, BB, BS, C, CC, CS, CT, G, W )
*
* Tests SSYR2K.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
REAL AA( NMAX*NMAX ), AB( 2*NMAX*NMAX ),
$ ALF( NALF ), AS( NMAX*NMAX ), BB( NMAX*NMAX ),
$ BET( NBET ), BS( NMAX*NMAX ), C( NMAX, NMAX ),
$ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ),
$ G( NMAX ), W( 2*NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
REAL ALPHA, ALS, BETA, BETS, ERR, ERRMAX
INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, JJAB,
$ K, KS, LAA, LBB, LCC, LDA, LDAS, LDB, LDBS,
$ LDC, LDCS, LJ, MA, N, NA, NARGS, NC, NS
LOGICAL NULL, RESET, SAME, TRAN, UPPER
CHARACTER*1 TRANS, TRANSS, UPLO, UPLOS
CHARACTER*2 ICHU
CHARACTER*3 ICHT
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LSE, LSERES
EXTERNAL LSE, LSERES
* .. External Subroutines ..
EXTERNAL SMAKE, SMMCH, SSYR2K
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHT/'NTC'/, ICHU/'UL'/
* .. Executable Statements ..
*
NARGS = 12
NC = 0
RESET = .TRUE.
ERRMAX = ZERO
*
DO 130 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = N
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 130
LCC = LDC*N
NULL = N.LE.0
*
DO 120 IK = 1, NIDIM
K = IDIM( IK )
*
DO 110 ICT = 1, 3
TRANS = ICHT( ICT: ICT )
TRAN = TRANS.EQ.'T'.OR.TRANS.EQ.'C'
IF( TRAN )THEN
MA = K
NA = N
ELSE
MA = N
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 110
LAA = LDA*NA
*
* Generate the matrix A.
*
IF( TRAN )THEN
CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB, 2*NMAX, AA,
$ LDA, RESET, ZERO )
ELSE
CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB, NMAX, AA, LDA,
$ RESET, ZERO )
END IF
*
* Generate the matrix B.
*
LDB = LDA
LBB = LAA
IF( TRAN )THEN
CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB( K + 1 ),
$ 2*NMAX, BB, LDB, RESET, ZERO )
ELSE
CALL SMAKE( 'GE', ' ', ' ', MA, NA, AB( K*NMAX + 1 ),
$ NMAX, BB, LDB, RESET, ZERO )
END IF
*
DO 100 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
UPPER = UPLO.EQ.'U'
*
DO 90 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 80 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL SMAKE( 'SY', UPLO, ' ', N, N, C, NMAX, CC,
$ LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the subroutine.
*
UPLOS = UPLO
TRANSS = TRANS
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BETS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO,
$ TRANS, N, K, ALPHA, LDA, LDB, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL SSYR2K( UPLO, TRANS, N, K, ALPHA, AA, LDA,
$ BB, LDB, BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9993 )
FATAL = .TRUE.
GO TO 150
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = UPLOS.EQ.UPLO
ISAME( 2 ) = TRANSS.EQ.TRANS
ISAME( 3 ) = NS.EQ.N
ISAME( 4 ) = KS.EQ.K
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LSE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = LSE( BS, BB, LBB )
ISAME( 9 ) = LDBS.EQ.LDB
ISAME( 10 ) = BETS.EQ.BETA
IF( NULL )THEN
ISAME( 11 ) = LSE( CS, CC, LCC )
ELSE
ISAME( 11 ) = LSERES( 'SY', UPLO, N, N, CS,
$ CC, LDC )
END IF
ISAME( 12 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 150
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result column by column.
*
JJAB = 1
JC = 1
DO 70 J = 1, N
IF( UPPER )THEN
JJ = 1
LJ = J
ELSE
JJ = J
LJ = N - J + 1
END IF
IF( TRAN )THEN
DO 50 I = 1, K
W( I ) = AB( ( J - 1 )*2*NMAX + K +
$ I )
W( K + I ) = AB( ( J - 1 )*2*NMAX +
$ I )
50 CONTINUE
CALL SMMCH( 'T', 'N', LJ, 1, 2*K,
$ ALPHA, AB( JJAB ), 2*NMAX,
$ W, 2*NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
DO 60 I = 1, K
W( I ) = AB( ( K + I - 1 )*NMAX +
$ J )
W( K + I ) = AB( ( I - 1 )*NMAX +
$ J )
60 CONTINUE
CALL SMMCH( 'N', 'N', LJ, 1, 2*K,
$ ALPHA, AB( JJ ), NMAX, W,
$ 2*NMAX, BETA, C( JJ, J ),
$ NMAX, CT, G, CC( JC ), LDC,
$ EPS, ERR, FATAL, NOUT,
$ .TRUE. )
END IF
IF( UPPER )THEN
JC = JC + LDC
ELSE
JC = JC + LDC + 1
IF( TRAN )
$ JJAB = JJAB + 2*NMAX
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 140
70 CONTINUE
END IF
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
120 CONTINUE
*
130 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 160
*
140 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9995 )J
*
150 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, ALPHA,
$ LDA, LDB, BETA, LDC
*
160 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ', B,', I3, ',', F4.1, ', C,', I3, ') ',
$ ' .' )
9993 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of SCHK5.
*
END
SUBROUTINE SCHKE( ISNUM, SRNAMT, NOUT )
*
* Tests the error exits from the Level 3 Blas.
* Requires a special version of the error-handling routine XERBLA.
* A, B and C should not need to be defined.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* 3-19-92: Initialize ALPHA and BETA (eca)
* 3-19-92: Fix argument 12 in calls to SSYMM with INFOT = 9 (eca)
*
* .. Scalar Arguments ..
INTEGER ISNUM, NOUT
CHARACTER*6 SRNAMT
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Parameters ..
REAL ONE, TWO
PARAMETER ( ONE = 1.0E0, TWO = 2.0E0 )
* .. Local Scalars ..
REAL ALPHA, BETA
* .. Local Arrays ..
REAL A( 2, 1 ), B( 2, 1 ), C( 2, 1 )
* .. External Subroutines ..
EXTERNAL CHKXER, SGEMM, SSYMM, SSYR2K, SSYRK, STRMM,
$ STRSM
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Executable Statements ..
* OK is set to .FALSE. by the special version of XERBLA or by CHKXER
* if anything is wrong.
OK = .TRUE.
* LERR is set to .TRUE. by the special version of XERBLA each time
* it is called, and is then tested and re-set by CHKXER.
LERR = .FALSE.
*
* Initialize ALPHA and BETA.
*
ALPHA = ONE
BETA = TWO
*
GO TO ( 10, 20, 30, 40, 50, 60 )ISNUM
10 INFOT = 1
CALL SGEMM( '/', 'N', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 1
CALL SGEMM( '/', 'T', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL SGEMM( 'N', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL SGEMM( 'T', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SGEMM( 'N', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SGEMM( 'N', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SGEMM( 'T', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SGEMM( 'T', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SGEMM( 'N', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SGEMM( 'N', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SGEMM( 'T', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SGEMM( 'T', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL SGEMM( 'N', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL SGEMM( 'N', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL SGEMM( 'T', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL SGEMM( 'T', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL SGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL SGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL SGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL SGEMM( 'T', 'T', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SGEMM( 'N', 'N', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SGEMM( 'N', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SGEMM( 'T', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL SGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL SGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL SGEMM( 'T', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL SGEMM( 'T', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
20 INFOT = 1
CALL SSYMM( '/', 'U', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL SSYMM( 'L', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYMM( 'L', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYMM( 'R', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYMM( 'L', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYMM( 'R', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYMM( 'L', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYMM( 'R', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYMM( 'L', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYMM( 'R', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYMM( 'L', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYMM( 'R', 'U', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYMM( 'L', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYMM( 'R', 'L', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
30 INFOT = 1
CALL STRMM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL STRMM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL STRMM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL STRMM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRMM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRMM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRMM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRMM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
40 INFOT = 1
CALL STRSM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL STRSM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL STRSM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL STRSM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL STRSM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL STRSM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL STRSM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL STRSM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
50 INFOT = 1
CALL SSYRK( '/', 'N', 0, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL SSYRK( 'U', '/', 0, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYRK( 'U', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYRK( 'U', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYRK( 'L', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYRK( 'L', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYRK( 'U', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYRK( 'U', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYRK( 'L', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYRK( 'L', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYRK( 'U', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYRK( 'U', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYRK( 'L', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYRK( 'L', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SSYRK( 'U', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SSYRK( 'U', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SSYRK( 'L', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL SSYRK( 'L', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 70
60 INFOT = 1
CALL SSYR2K( '/', 'N', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL SSYR2K( 'U', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYR2K( 'U', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYR2K( 'U', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYR2K( 'L', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL SSYR2K( 'L', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYR2K( 'U', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYR2K( 'U', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYR2K( 'L', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL SSYR2K( 'L', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYR2K( 'U', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYR2K( 'U', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYR2K( 'L', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL SSYR2K( 'L', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYR2K( 'U', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL SSYR2K( 'L', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYR2K( 'U', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL SSYR2K( 'L', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
*
70 IF( OK )THEN
WRITE( NOUT, FMT = 9999 )SRNAMT
ELSE
WRITE( NOUT, FMT = 9998 )SRNAMT
END IF
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE TESTS OF ERROR-EXITS' )
9998 FORMAT( ' ******* ', A6, ' FAILED THE TESTS OF ERROR-EXITS *****',
$ '**' )
*
* End of SCHKE.
*
END
SUBROUTINE SMAKE( TYPE, UPLO, DIAG, M, N, A, NMAX, AA, LDA, RESET,
$ TRANSL )
*
* Generates values for an M by N matrix A.
* Stores the values in the array AA in the data structure required
* by the routine, with unwanted elements set to rogue value.
*
* TYPE is 'GE', 'SY' or 'TR'.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0, ONE = 1.0 )
REAL ROGUE
PARAMETER ( ROGUE = -1.0E10 )
* .. Scalar Arguments ..
REAL TRANSL
INTEGER LDA, M, N, NMAX
LOGICAL RESET
CHARACTER*1 DIAG, UPLO
CHARACTER*2 TYPE
* .. Array Arguments ..
REAL A( NMAX, * ), AA( * )
* .. Local Scalars ..
INTEGER I, IBEG, IEND, J
LOGICAL GEN, LOWER, SYM, TRI, UNIT, UPPER
* .. External Functions ..
REAL SBEG
EXTERNAL SBEG
* .. Executable Statements ..
GEN = TYPE.EQ.'GE'
SYM = TYPE.EQ.'SY'
TRI = TYPE.EQ.'TR'
UPPER = ( SYM.OR.TRI ).AND.UPLO.EQ.'U'
LOWER = ( SYM.OR.TRI ).AND.UPLO.EQ.'L'
UNIT = TRI.AND.DIAG.EQ.'U'
*
* Generate data in array A.
*
DO 20 J = 1, N
DO 10 I = 1, M
IF( GEN.OR.( UPPER.AND.I.LE.J ).OR.( LOWER.AND.I.GE.J ) )
$ THEN
A( I, J ) = SBEG( RESET ) + TRANSL
IF( I.NE.J )THEN
* Set some elements to zero
IF( N.GT.3.AND.J.EQ.N/2 )
$ A( I, J ) = ZERO
IF( SYM )THEN
A( J, I ) = A( I, J )
ELSE IF( TRI )THEN
A( J, I ) = ZERO
END IF
END IF
END IF
10 CONTINUE
IF( TRI )
$ A( J, J ) = A( J, J ) + ONE
IF( UNIT )
$ A( J, J ) = ONE
20 CONTINUE
*
* Store elements in array AS in data structure required by routine.
*
IF( TYPE.EQ.'GE' )THEN
DO 50 J = 1, N
DO 30 I = 1, M
AA( I + ( J - 1 )*LDA ) = A( I, J )
30 CONTINUE
DO 40 I = M + 1, LDA
AA( I + ( J - 1 )*LDA ) = ROGUE
40 CONTINUE
50 CONTINUE
ELSE IF( TYPE.EQ.'SY'.OR.TYPE.EQ.'TR' )THEN
DO 90 J = 1, N
IF( UPPER )THEN
IBEG = 1
IF( UNIT )THEN
IEND = J - 1
ELSE
IEND = J
END IF
ELSE
IF( UNIT )THEN
IBEG = J + 1
ELSE
IBEG = J
END IF
IEND = N
END IF
DO 60 I = 1, IBEG - 1
AA( I + ( J - 1 )*LDA ) = ROGUE
60 CONTINUE
DO 70 I = IBEG, IEND
AA( I + ( J - 1 )*LDA ) = A( I, J )
70 CONTINUE
DO 80 I = IEND + 1, LDA
AA( I + ( J - 1 )*LDA ) = ROGUE
80 CONTINUE
90 CONTINUE
END IF
RETURN
*
* End of SMAKE.
*
END
SUBROUTINE SMMCH( TRANSA, TRANSB, M, N, KK, ALPHA, A, LDA, B, LDB,
$ BETA, C, LDC, CT, G, CC, LDCC, EPS, ERR, FATAL,
$ NOUT, MV )
*
* Checks the results of the computational tests.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0, ONE = 1.0 )
* .. Scalar Arguments ..
REAL ALPHA, BETA, EPS, ERR
INTEGER KK, LDA, LDB, LDC, LDCC, M, N, NOUT
LOGICAL FATAL, MV
CHARACTER*1 TRANSA, TRANSB
* .. Array Arguments ..
REAL A( LDA, * ), B( LDB, * ), C( LDC, * ),
$ CC( LDCC, * ), CT( * ), G( * )
* .. Local Scalars ..
REAL ERRI
INTEGER I, J, K
LOGICAL TRANA, TRANB
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, SQRT
* .. Executable Statements ..
TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C'
TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C'
*
* Compute expected result, one column at a time, in CT using data
* in A, B and C.
* Compute gauges in G.
*
DO 120 J = 1, N
*
DO 10 I = 1, M
CT( I ) = ZERO
G( I ) = ZERO
10 CONTINUE
IF( .NOT.TRANA.AND..NOT.TRANB )THEN
DO 30 K = 1, KK
DO 20 I = 1, M
CT( I ) = CT( I ) + A( I, K )*B( K, J )
G( I ) = G( I ) + ABS( A( I, K ) )*ABS( B( K, J ) )
20 CONTINUE
30 CONTINUE
ELSE IF( TRANA.AND..NOT.TRANB )THEN
DO 50 K = 1, KK
DO 40 I = 1, M
CT( I ) = CT( I ) + A( K, I )*B( K, J )
G( I ) = G( I ) + ABS( A( K, I ) )*ABS( B( K, J ) )
40 CONTINUE
50 CONTINUE
ELSE IF( .NOT.TRANA.AND.TRANB )THEN
DO 70 K = 1, KK
DO 60 I = 1, M
CT( I ) = CT( I ) + A( I, K )*B( J, K )
G( I ) = G( I ) + ABS( A( I, K ) )*ABS( B( J, K ) )
60 CONTINUE
70 CONTINUE
ELSE IF( TRANA.AND.TRANB )THEN
DO 90 K = 1, KK
DO 80 I = 1, M
CT( I ) = CT( I ) + A( K, I )*B( J, K )
G( I ) = G( I ) + ABS( A( K, I ) )*ABS( B( J, K ) )
80 CONTINUE
90 CONTINUE
END IF
DO 100 I = 1, M
CT( I ) = ALPHA*CT( I ) + BETA*C( I, J )
G( I ) = ABS( ALPHA )*G( I ) + ABS( BETA )*ABS( C( I, J ) )
100 CONTINUE
*
* Compute the error ratio for this result.
*
ERR = ZERO
DO 110 I = 1, M
ERRI = ABS( CT( I ) - CC( I, J ) )/EPS
IF( G( I ).NE.ZERO )
$ ERRI = ERRI/G( I )
ERR = MAX( ERR, ERRI )
IF( ERR*SQRT( EPS ).GE.ONE )
$ GO TO 130
110 CONTINUE
*
120 CONTINUE
*
* If the loop completes, all results are at least half accurate.
GO TO 150
*
* Report fatal error.
*
130 FATAL = .TRUE.
WRITE( NOUT, FMT = 9999 )
DO 140 I = 1, M
IF( MV )THEN
WRITE( NOUT, FMT = 9998 )I, CT( I ), CC( I, J )
ELSE
WRITE( NOUT, FMT = 9998 )I, CC( I, J ), CT( I )
END IF
140 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9997 )J
*
150 CONTINUE
RETURN
*
9999 FORMAT( ' ******* FATAL ERROR - COMPUTED RESULT IS LESS THAN HAL',
$ 'F ACCURATE *******', /' EXPECTED RESULT COMPU',
$ 'TED RESULT' )
9998 FORMAT( 1X, I7, 2G18.6 )
9997 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
*
* End of SMMCH.
*
END
LOGICAL FUNCTION LSE( RI, RJ, LR )
*
* Tests if two arrays are identical.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER LR
* .. Array Arguments ..
REAL RI( * ), RJ( * )
* .. Local Scalars ..
INTEGER I
* .. Executable Statements ..
DO 10 I = 1, LR
IF( RI( I ).NE.RJ( I ) )
$ GO TO 20
10 CONTINUE
LSE = .TRUE.
GO TO 30
20 CONTINUE
LSE = .FALSE.
30 RETURN
*
* End of LSE.
*
END
LOGICAL FUNCTION LSERES( TYPE, UPLO, M, N, AA, AS, LDA )
*
* Tests if selected elements in two arrays are equal.
*
* TYPE is 'GE' or 'SY'.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER LDA, M, N
CHARACTER*1 UPLO
CHARACTER*2 TYPE
* .. Array Arguments ..
REAL AA( LDA, * ), AS( LDA, * )
* .. Local Scalars ..
INTEGER I, IBEG, IEND, J
LOGICAL UPPER
* .. Executable Statements ..
UPPER = UPLO.EQ.'U'
IF( TYPE.EQ.'GE' )THEN
DO 20 J = 1, N
DO 10 I = M + 1, LDA
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
10 CONTINUE
20 CONTINUE
ELSE IF( TYPE.EQ.'SY' )THEN
DO 50 J = 1, N
IF( UPPER )THEN
IBEG = 1
IEND = J
ELSE
IBEG = J
IEND = N
END IF
DO 30 I = 1, IBEG - 1
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
30 CONTINUE
DO 40 I = IEND + 1, LDA
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
40 CONTINUE
50 CONTINUE
END IF
*
LSERES = .TRUE.
GO TO 80
70 CONTINUE
LSERES = .FALSE.
80 RETURN
*
* End of LSERES.
*
END
REAL FUNCTION SBEG( RESET )
*
* Generates random numbers uniformly distributed between -0.5 and 0.5.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
LOGICAL RESET
* .. Local Scalars ..
INTEGER I, IC, MI
* .. Save statement ..
SAVE I, IC, MI
* .. Executable Statements ..
IF( RESET )THEN
* Initialize local variables.
MI = 891
I = 7
IC = 0
RESET = .FALSE.
END IF
*
* The sequence of values of I is bounded between 1 and 999.
* If initial I = 1,2,3,6,7 or 9, the period will be 50.
* If initial I = 4 or 8, the period will be 25.
* If initial I = 5, the period will be 10.
* IC is used to break up the period by skipping 1 value of I in 6.
*
IC = IC + 1
10 I = I*MI
I = I - 1000*( I/1000 )
IF( IC.GE.5 )THEN
IC = 0
GO TO 10
END IF
SBEG = ( I - 500 )/1001.0
RETURN
*
* End of SBEG.
*
END
REAL FUNCTION SDIFF( X, Y )
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
REAL X, Y
* .. Executable Statements ..
SDIFF = X - Y
RETURN
*
* End of SDIFF.
*
END
SUBROUTINE CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
*
* Tests whether XERBLA has detected an error when it should.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER INFOT, NOUT
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Executable Statements ..
IF( .NOT.LERR )THEN
WRITE( NOUT, FMT = 9999 )INFOT, SRNAMT
OK = .FALSE.
END IF
LERR = .FALSE.
RETURN
*
9999 FORMAT( ' ***** ILLEGAL VALUE OF PARAMETER NUMBER ', I2, ' NOT D',
$ 'ETECTED BY ', A6, ' *****' )
*
* End of CHKXER.
*
END
SUBROUTINE XERBLA( SRNAME, INFO )
*
* This is a special version of XERBLA to be used only as part of
* the test program for testing error exits from the Level 3 BLAS
* routines.
*
* XERBLA is an error handler for the Level 3 BLAS routines.
*
* It is called by the Level 3 BLAS routines if an input parameter is
* invalid.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER INFO
CHARACTER*6 SRNAME
* .. Scalars in Common ..
INTEGER INFOT, NOUT
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUT, OK, LERR
COMMON /SRNAMC/SRNAMT
* .. Executable Statements ..
LERR = .TRUE.
IF( INFO.NE.INFOT )THEN
IF( INFOT.NE.0 )THEN
WRITE( NOUT, FMT = 9999 )INFO, INFOT
ELSE
WRITE( NOUT, FMT = 9997 )INFO
END IF
OK = .FALSE.
END IF
IF( SRNAME.NE.SRNAMT )THEN
WRITE( NOUT, FMT = 9998 )SRNAME, SRNAMT
OK = .FALSE.
END IF
RETURN
*
9999 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6, ' INSTEAD',
$ ' OF ', I2, ' *******' )
9998 FORMAT( ' ******* XERBLA WAS CALLED WITH SRNAME = ', A6, ' INSTE',
$ 'AD OF ', A6, ' *******' )
9997 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6,
$ ' *******' )
*
* End of XERBLA
*
END
| mit |
ForestClaw/forestclaw | applications/paper/transport_torus/flag2refine2.f90 | 1 | 6195 | ! ::::::::::::::::::::: flag2refine ::::::::::::::::::::::::::::::::::
!
!> \callgraph
!! \callergraph
!! User routine to control flagging of points for refinement.
!!
!! Default version computes spatial difference dq in each direction and
!! for each component of q and flags any point where this is greater than
!! the tolerance tolsp.
!! This is consistent with what the routine errsp did in
!! earlier versions of amrclaw (4.2 and before).
!!
!! This routine can be copied to an application directory and modified to
!! implement some other desired refinement criterion.
!!
!! Points may also be flagged for refining based on a Richardson estimate
!! of the error, obtained by comparing solutions on the current grid and a
!! coarsened grid. Points are flagged if the estimated error is larger than
!! the parameter tol in amr2ez.data, provided flag_richardson is .true.,
!! otherwise the coarsening and Richardson estimation is not performed!
!! Points are flagged via Richardson in a separate routine.
!!
!! Once points are flagged via this routine and/or Richardson, the subroutine
!! flagregions is applied to check each point against the min_level and
!! max_level of refinement specified in any "region" set by the user.
!! So flags set here might be over-ruled by region constraints.
!!
!! **output**: amrflags
!!
!! \param mx number of cells in *i* direction
!! \param my number of cells in *j* direction
!! \param mbc width of ghost cell region
!! \param mbuff width of buffer region
!! \param meqn number of equations for the system
!! \param maux number of auxiliary variables
!! \param xlower x-coordinate of left physical boundary
!! \param ylower y-coordinate of lower physical boundary
!! \param dx spacing in *i* direction
!! \param dy spacing in *j* direction
!! \param t simulation time on this grid
!! \param level AMR level of this grid
!! \param tolsp tolerance specified by user in input file amr.data, used in default
!! version of this routine as a tolerance for spatial differences
!! \param q grid values including ghost cells (bndry vals at specified
!! time have already been set, so can use ghost cell values too)
!! \param aux auxiliary array on this grid patch
!! \param amrflags array to be flagged with either the value **DONTFLAG** or **DOFLAG** for each cell.
!! It is enlarged from grid size to include buffer regions around the grid.
!! \param DONTFLAG value to be assigned to amrflags for cells that need no refinement
!! \param DOFLAG value to be assigned to amrflags for cells that do need refinement
!
! ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
subroutine flag2refine2(mx,my,mbc,mbuff,meqn,maux,xlower,ylower,dx,dy,t,level, &
tolsp,q,aux,amrflags)
use regions_module
use amr_module, only : DOFLAG, UNSET
implicit none
! Subroutine arguments
integer, intent(in) :: mx,my,mbc,meqn,maux,level,mbuff
real(kind=8), intent(in) :: xlower,ylower,dx,dy,t,tolsp
real(kind=8), intent(in) :: q(meqn,1-mbc:mx+mbc,1-mbc:my+mbc)
real(kind=8), intent(in) :: aux(maux,1-mbc:mx+mbc,1-mbc:my+mbc)
! Flagging
real(kind=8),intent(inout) :: amrflags(1-mbuff:mx+mbuff,1-mbuff:my+mbuff)
logical :: allowflag
external allowflag
DOUBLE precision pi, pi2
COMMON /compi/ pi, pi2
DOUBLE PRECISION alpha, beta, theta_range(2), phi_range(2)
COMMON /torus_comm/ alpha, beta, theta_range, phi_range
INTEGER refine_pattern
COMMON /refine_comm/ refine_pattern
! Locals
integer :: i,j,m
real(kind=8) :: x_c,y_c,x_low,y_low,x_hi,y_hi
real(kind=8) :: dqi(meqn), dqj(meqn), dq(meqn)
REAL(kind=8) :: qmin, qmax, r, ravg, rw, th
LOGICAL constant_theta, constant_r
double precision xc,yc
logical refine
! Don't initialize flags, since they were already
! flagged by flagregions2
! amrflags = DONTFLAG
! Loop over interior points on this grid
! (i,j) grid cell is [x_low,x_hi] x [y_low,y_hi], cell center at (x_c,y_c)
! This information is not needed for the default flagging based on
! undivided differences, but might be needed in a user's version.
! Note that if you want to refine only in certain space-time regions,
! it may be easiest to use the "regions" feature. The flags set here or
! in the Richardson error estimator are modifing the flags set by
! min_level and max_level specified in any regions.
y_loop: do j=1,my
!y_low = ylower + (j - 1) * dy
!y_c = ylower + (j - 0.5d0) * dy
!y_hi = ylower + j * dy
x_loop: do i = 1,mx
!x_low = xlower + (i - 1) * dx
!x_c = xlower + (i - 0.5d0) * dx
!x_hi = xlower + i * dx
! -----------------------------------------------------------------
! Only check undivided differences if flag hasn't been set yet.
! If flag == DONTFLAG then refinement is forbidden by a region,
! if flag == DOFLAG checking is not needed
if(amrflags(i,j) == UNSET) then
if (refine_pattern .eq. -1) then
amrflags(i,j) = DOFLAG
else if (refine_pattern .eq. 0) then
refine = (q(1,i,j) .gt. tolsp) .and. (q(1,i,j) .lt. 1-tolsp)
if (refine) then
amrflags(i,j) = DOFLAG
endif
else
xc = xlower + (i-0.5)*dx
yc = ylower + (j-0.5)*dy
th = pi2*(theta_range(1) + (theta_range(2)-theta_range(1))*xc)
constant_theta = th .gt. pi/2
constant_r = abs(yc-0.5) .gt. 0.25
if (refine_pattern .eq. 1 .and. constant_theta) then
amrflags(i,j) = DOFLAG
cycle x_loop
elseif (refine_pattern .eq. 2 .and. constant_r) then
amrflags(i,j) = DOFLAG
cycle x_loop
endif
endif
endif
enddo x_loop
enddo y_loop
end subroutine flag2refine2
| bsd-2-clause |
tectronics/force-distribution-analysis.gromacs-4-5-3 | src/gmxlib/nonbonded/nb_kernel_power6/pwr6kernel010.F | 3 | 13380 | C
C This source code is part of
C
C G R O M A C S
C
C Copyright (c) 1991-2000, University of Groningen, The Netherlands.
C Copyright (c) 2001-2009, The GROMACS Development Team
C
C Gromacs is a library for molecular simulation and trajectory analysis,
C written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
C a full list of developers and information, check out http://www.gromacs.org
C
C This program is free software; you can redistribute it and/or modify it under
C the terms of the GNU Lesser General Public License as published by the Free
C Software Foundation; either version 2 of the License, or (at your option) any
C later version.
C As a special exception, you may use this file as part of a free software
C library without restriction. Specifically, if other files instantiate
C templates or use macros or inline functions from this file, or you compile
C this file and link it with other files to produce an executable, this
C file does not by itself cause the resulting executable to be covered by
C the GNU Lesser General Public License.
C
C In plain-speak: do not worry about classes/macros/templates either - only
C changes to the library have to be LGPL, not an application linking with it.
C
C To help fund GROMACS development, we humbly ask that you cite
C the papers people have written on it - you can find them on the website!
C
#ifdef HAVE_CONFIG_H
# include<config.h>
#endif
#ifdef GMX_DOUBLE
# define gmxreal real*8
#else
# define gmxreal real*4
#endif
C
C Gromacs nonbonded kernel pwr6kernel010
C Coulomb interaction: Not calculated
C VdW interaction: Lennard-Jones
C water optimization: No
C Calculate forces: yes
C
subroutine pwr6kernel010(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
gmxreal shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
gmxreal charge(*),facel,krf,crf,Vc(*),vdwparam(*)
gmxreal Vvdw(*),tabscale,VFtab(*)
gmxreal invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
gmxreal work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
gmxreal shX,shY,shZ
gmxreal fscal,tx,ty,tz
gmxreal rinvsq
integer*4 nti
integer*4 tj
gmxreal rinvsix
gmxreal Vvdw6,Vvdwtot
gmxreal Vvdw12
gmxreal ix1,iy1,iz1,fix1,fiy1,fiz1
gmxreal jx1,jy1,jz1
gmxreal dx11,dy11,dz11,rsq11
gmxreal c6,c12
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call pwr6kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix1 = shX + pos(ii3+0)
iy1 = shY + pos(ii3+1)
iz1 = shZ + pos(ii3+2)
C Load parameters for i atom
nti = 2*ntype*type(ii)
C Zero the potential energy for this list
Vvdwtot = 0
C Clear i atom forces
fix1 = 0
fiy1 = 0
fiz1 = 0
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx11 = ix1 - jx1
dy11 = iy1 - jy1
dz11 = iz1 - jz1
rsq11 = dx11*dx11+dy11*dy11+dz11*dz11
C Calculate 1/r and 1/r2
rinvsq = 1.0/rsq11
C Load parameters for j atom
tj = nti+2*type(jnr)+1
c6 = vdwparam(tj)
c12 = vdwparam(tj+1)
C Lennard-Jones interaction
rinvsix = rinvsq*rinvsq*rinvsq
Vvdw6 = c6*rinvsix
Vvdw12 = c12*rinvsix*rinvsix
Vvdwtot = Vvdwtot+Vvdw12-Vvdw6
fscal = (12.0*Vvdw12-6.0*Vvdw6)*rinvsq
C Calculate temporary vectorial force
tx = fscal*dx11
ty = fscal*dy11
tz = fscal*dz11
C Increment i atom force
fix1 = fix1 + tx
fiy1 = fiy1 + ty
fiz1 = fiz1 + tz
C Decrement j atom force
faction(j3+0) = faction(j3+0) - tx
faction(j3+1) = faction(j3+1) - ty
faction(j3+2) = faction(j3+2) - tz
C Inner loop uses 33 flops/iteration
end do
C Add i forces to mem and shifted force list
faction(ii3+0) = faction(ii3+0) + fix1
faction(ii3+1) = faction(ii3+1) + fiy1
faction(ii3+2) = faction(ii3+2) + fiz1
fshift(is3) = fshift(is3)+fix1
fshift(is3+1) = fshift(is3+1)+fiy1
fshift(is3+2) = fshift(is3+2)+fiz1
C Add potential energies to the group for this list
ggid = gid(n)+1
Vvdw(ggid) = Vvdw(ggid) + Vvdwtot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 10 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
C
C Gromacs nonbonded kernel pwr6kernel010nf
C Coulomb interaction: Not calculated
C VdW interaction: Lennard-Jones
C water optimization: No
C Calculate forces: no
C
subroutine pwr6kernel010nf(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
gmxreal shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
gmxreal charge(*),facel,krf,crf,Vc(*),vdwparam(*)
gmxreal Vvdw(*),tabscale,VFtab(*)
gmxreal invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
gmxreal work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
gmxreal shX,shY,shZ
gmxreal rinvsq
integer*4 nti
integer*4 tj
gmxreal rinvsix
gmxreal Vvdw6,Vvdwtot
gmxreal Vvdw12
gmxreal ix1,iy1,iz1
gmxreal jx1,jy1,jz1
gmxreal dx11,dy11,dz11,rsq11
gmxreal c6,c12
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call pwr6kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix1 = shX + pos(ii3+0)
iy1 = shY + pos(ii3+1)
iz1 = shZ + pos(ii3+2)
C Load parameters for i atom
nti = 2*ntype*type(ii)
C Zero the potential energy for this list
Vvdwtot = 0
C Clear i atom forces
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx11 = ix1 - jx1
dy11 = iy1 - jy1
dz11 = iz1 - jz1
rsq11 = dx11*dx11+dy11*dy11+dz11*dz11
C Calculate 1/r and 1/r2
rinvsq = 1.0/rsq11
C Load parameters for j atom
tj = nti+2*type(jnr)+1
c6 = vdwparam(tj)
c12 = vdwparam(tj+1)
C Lennard-Jones interaction
rinvsix = rinvsq*rinvsq*rinvsq
Vvdw6 = c6*rinvsix
Vvdw12 = c12*rinvsix*rinvsix
Vvdwtot = Vvdwtot+Vvdw12-Vvdw6
C Inner loop uses 19 flops/iteration
end do
C Add i forces to mem and shifted force list
C Add potential energies to the group for this list
ggid = gid(n)+1
Vvdw(ggid) = Vvdw(ggid) + Vvdwtot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 4 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
| gpl-2.0 |
tectronics/force-distribution-analysis.gromacs-4-5-3 | src/gmxlib/nonbonded/nb_kernel_f77_single/f77skernel301.f | 5 | 21890 | C
C This source code is part of
C
C G R O M A C S
C
C Copyright (c) 1991-2000, University of Groningen, The Netherlands.
C Copyright (c) 2001-2009, The GROMACS Development Team
C
C Gromacs is a library for molecular simulation and trajectory analysis,
C written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
C a full list of developers and information, check out http://www.gromacs.org
C
C This program is free software; you can redistribute it and/or modify it under
C the terms of the GNU Lesser General Public License as published by the Free
C Software Foundation; either version 2 of the License, or (at your option) any
C later version.
C As a special exception, you may use this file as part of a free software
C library without restriction. Specifically, if other files instantiate
C templates or use macros or inline functions from this file, or you compile
C this file and link it with other files to produce an executable, this
C file does not by itself cause the resulting executable to be covered by
C the GNU Lesser General Public License.
C
C In plain-speak: do not worry about classes/macros/templates either - only
C changes to the library have to be LGPL, not an application linking with it.
C
C To help fund GROMACS development, we humbly ask that you cite
C the papers people have written on it - you can find them on the website!
C
C
C Gromacs nonbonded kernel f77skernel301
C Coulomb interaction: Tabulated
C VdW interaction: Not calculated
C water optimization: SPC/TIP3P - other atoms
C Calculate forces: yes
C
subroutine f77skernel301(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
real*4 shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
real*4 charge(*),facel,krf,crf,Vc(*),vdwparam(*)
real*4 Vvdw(*),tabscale,VFtab(*)
real*4 invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
real*4 work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
real*4 shX,shY,shZ
real*4 fscal,tx,ty,tz
real*4 jq
real*4 qq,vcoul,vctot
real*4 r,rt,eps,eps2
integer*4 n0,nnn
real*4 Y,F,Geps,Heps2,Fp,VV
real*4 FF
real*4 fijC
real*4 ix1,iy1,iz1,fix1,fiy1,fiz1
real*4 ix2,iy2,iz2,fix2,fiy2,fiz2
real*4 ix3,iy3,iz3,fix3,fiy3,fiz3
real*4 jx1,jy1,jz1,fjx1,fjy1,fjz1
real*4 dx11,dy11,dz11,rsq11,rinv11
real*4 dx21,dy21,dz21,rsq21,rinv21
real*4 dx31,dy31,dz31,rsq31,rinv31
real*4 qO,qH
C Initialize water data
ii = iinr(1)+1
qO = facel*charge(ii)
qH = facel*charge(ii+1)
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call f77kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix1 = shX + pos(ii3+0)
iy1 = shY + pos(ii3+1)
iz1 = shZ + pos(ii3+2)
ix2 = shX + pos(ii3+3)
iy2 = shY + pos(ii3+4)
iz2 = shZ + pos(ii3+5)
ix3 = shX + pos(ii3+6)
iy3 = shY + pos(ii3+7)
iz3 = shZ + pos(ii3+8)
C Zero the potential energy for this list
vctot = 0
C Clear i atom forces
fix1 = 0
fiy1 = 0
fiz1 = 0
fix2 = 0
fiy2 = 0
fiz2 = 0
fix3 = 0
fiy3 = 0
fiz3 = 0
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx11 = ix1 - jx1
dy11 = iy1 - jy1
dz11 = iz1 - jz1
rsq11 = dx11*dx11+dy11*dy11+dz11*dz11
dx21 = ix2 - jx1
dy21 = iy2 - jy1
dz21 = iz2 - jz1
rsq21 = dx21*dx21+dy21*dy21+dz21*dz21
dx31 = ix3 - jx1
dy31 = iy3 - jy1
dz31 = iz3 - jz1
rsq31 = dx31*dx31+dy31*dy31+dz31*dz31
C Calculate 1/r and 1/r2
rinv11 = 1.0/sqrt(rsq11)
rinv21 = 1.0/sqrt(rsq21)
rinv31 = 1.0/sqrt(rsq31)
C Load parameters for j atom
jq = charge(jnr+0)
qq = qO*jq
C Calculate table index
r = rsq11*rinv11
C Calculate table index
rt = r*tabscale
n0 = rt
eps = rt-n0
eps2 = eps*eps
nnn = 4*n0+1
C Tabulated coulomb interaction
Y = VFtab(nnn)
F = VFtab(nnn+1)
Geps = eps*VFtab(nnn+2)
Heps2 = eps2*VFtab(nnn+3)
Fp = F+Geps+Heps2
VV = Y+eps*Fp
FF = Fp+Geps+2.0*Heps2
vcoul = qq*VV
fijC = qq*FF
vctot = vctot + vcoul
fscal = -((fijC)*tabscale)*rinv11
C Calculate temporary vectorial force
tx = fscal*dx11
ty = fscal*dy11
tz = fscal*dz11
C Increment i atom force
fix1 = fix1 + tx
fiy1 = fiy1 + ty
fiz1 = fiz1 + tz
C Decrement j atom force
fjx1 = faction(j3+0) - tx
fjy1 = faction(j3+1) - ty
fjz1 = faction(j3+2) - tz
C Load parameters for j atom
qq = qH*jq
C Calculate table index
r = rsq21*rinv21
C Calculate table index
rt = r*tabscale
n0 = rt
eps = rt-n0
eps2 = eps*eps
nnn = 4*n0+1
C Tabulated coulomb interaction
Y = VFtab(nnn)
F = VFtab(nnn+1)
Geps = eps*VFtab(nnn+2)
Heps2 = eps2*VFtab(nnn+3)
Fp = F+Geps+Heps2
VV = Y+eps*Fp
FF = Fp+Geps+2.0*Heps2
vcoul = qq*VV
fijC = qq*FF
vctot = vctot + vcoul
fscal = -((fijC)*tabscale)*rinv21
C Calculate temporary vectorial force
tx = fscal*dx21
ty = fscal*dy21
tz = fscal*dz21
C Increment i atom force
fix2 = fix2 + tx
fiy2 = fiy2 + ty
fiz2 = fiz2 + tz
C Decrement j atom force
fjx1 = fjx1 - tx
fjy1 = fjy1 - ty
fjz1 = fjz1 - tz
C Load parameters for j atom
C Calculate table index
r = rsq31*rinv31
C Calculate table index
rt = r*tabscale
n0 = rt
eps = rt-n0
eps2 = eps*eps
nnn = 4*n0+1
C Tabulated coulomb interaction
Y = VFtab(nnn)
F = VFtab(nnn+1)
Geps = eps*VFtab(nnn+2)
Heps2 = eps2*VFtab(nnn+3)
Fp = F+Geps+Heps2
VV = Y+eps*Fp
FF = Fp+Geps+2.0*Heps2
vcoul = qq*VV
fijC = qq*FF
vctot = vctot + vcoul
fscal = -((fijC)*tabscale)*rinv31
C Calculate temporary vectorial force
tx = fscal*dx31
ty = fscal*dy31
tz = fscal*dz31
C Increment i atom force
fix3 = fix3 + tx
fiy3 = fiy3 + ty
fiz3 = fiz3 + tz
C Decrement j atom force
faction(j3+0) = fjx1 - tx
faction(j3+1) = fjy1 - ty
faction(j3+2) = fjz1 - tz
C Inner loop uses 125 flops/iteration
end do
C Add i forces to mem and shifted force list
faction(ii3+0) = faction(ii3+0) + fix1
faction(ii3+1) = faction(ii3+1) + fiy1
faction(ii3+2) = faction(ii3+2) + fiz1
faction(ii3+3) = faction(ii3+3) + fix2
faction(ii3+4) = faction(ii3+4) + fiy2
faction(ii3+5) = faction(ii3+5) + fiz2
faction(ii3+6) = faction(ii3+6) + fix3
faction(ii3+7) = faction(ii3+7) + fiy3
faction(ii3+8) = faction(ii3+8) + fiz3
fshift(is3) = fshift(is3)+fix1+fix2+fix3
fshift(is3+1) = fshift(is3+1)+fiy1+fiy2+fiy3
fshift(is3+2) = fshift(is3+2)+fiz1+fiz2+fiz3
C Add potential energies to the group for this list
ggid = gid(n)+1
Vc(ggid) = Vc(ggid) + vctot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 28 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
C
C Gromacs nonbonded kernel f77skernel301nf
C Coulomb interaction: Tabulated
C VdW interaction: Not calculated
C water optimization: SPC/TIP3P - other atoms
C Calculate forces: no
C
subroutine f77skernel301nf(
& nri,
& iinr,
& jindex,
& jjnr,
& shift,
& shiftvec,
& fshift,
& gid,
& pos,
& faction,
& charge,
& facel,
& krf,
& crf,
& Vc,
& type,
& ntype,
& vdwparam,
& Vvdw,
& tabscale,
& VFtab,
& invsqrta,
& dvda,
& gbtabscale,
& GBtab,
& nthreads,
& count,
& mtx,
& outeriter,
& inneriter,
& work)
implicit none
integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*)
real*4 shiftvec(*),fshift(*),pos(*),faction(*)
integer*4 gid(*),type(*),ntype
real*4 charge(*),facel,krf,crf,Vc(*),vdwparam(*)
real*4 Vvdw(*),tabscale,VFtab(*)
real*4 invsqrta(*),dvda(*),gbtabscale,GBtab(*)
integer*4 nthreads,count,mtx,outeriter,inneriter
real*4 work(*)
integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid
integer*4 nn0,nn1,nouter,ninner
real*4 shX,shY,shZ
real*4 jq
real*4 qq,vcoul,vctot
real*4 r,rt,eps,eps2
integer*4 n0,nnn
real*4 Y,F,Geps,Heps2,Fp,VV
real*4 ix1,iy1,iz1
real*4 ix2,iy2,iz2
real*4 ix3,iy3,iz3
real*4 jx1,jy1,jz1
real*4 dx11,dy11,dz11,rsq11,rinv11
real*4 dx21,dy21,dz21,rsq21,rinv21
real*4 dx31,dy31,dz31,rsq31,rinv31
real*4 qO,qH
C Initialize water data
ii = iinr(1)+1
qO = facel*charge(ii)
qH = facel*charge(ii+1)
C Reset outer and inner iteration counters
nouter = 0
ninner = 0
C Loop over thread workunits
10 call f77kernelsync(mtx,count,nri,nthreads,nn0,nn1)
if(nn1.gt.nri) nn1=nri
C Start outer loop over neighborlists
do n=nn0+1,nn1
C Load shift vector for this list
is3 = 3*shift(n)+1
shX = shiftvec(is3)
shY = shiftvec(is3+1)
shZ = shiftvec(is3+2)
C Load limits for loop over neighbors
nj0 = jindex(n)+1
nj1 = jindex(n+1)
C Get outer coordinate index
ii = iinr(n)+1
ii3 = 3*ii-2
C Load i atom data, add shift vector
ix1 = shX + pos(ii3+0)
iy1 = shY + pos(ii3+1)
iz1 = shZ + pos(ii3+2)
ix2 = shX + pos(ii3+3)
iy2 = shY + pos(ii3+4)
iz2 = shZ + pos(ii3+5)
ix3 = shX + pos(ii3+6)
iy3 = shY + pos(ii3+7)
iz3 = shZ + pos(ii3+8)
C Zero the potential energy for this list
vctot = 0
C Clear i atom forces
do k=nj0,nj1
C Get j neighbor index, and coordinate index
jnr = jjnr(k)+1
j3 = 3*jnr-2
C load j atom coordinates
jx1 = pos(j3+0)
jy1 = pos(j3+1)
jz1 = pos(j3+2)
C Calculate distance
dx11 = ix1 - jx1
dy11 = iy1 - jy1
dz11 = iz1 - jz1
rsq11 = dx11*dx11+dy11*dy11+dz11*dz11
dx21 = ix2 - jx1
dy21 = iy2 - jy1
dz21 = iz2 - jz1
rsq21 = dx21*dx21+dy21*dy21+dz21*dz21
dx31 = ix3 - jx1
dy31 = iy3 - jy1
dz31 = iz3 - jz1
rsq31 = dx31*dx31+dy31*dy31+dz31*dz31
C Calculate 1/r and 1/r2
rinv11 = 1.0/sqrt(rsq11)
rinv21 = 1.0/sqrt(rsq21)
rinv31 = 1.0/sqrt(rsq31)
C Load parameters for j atom
jq = charge(jnr+0)
qq = qO*jq
C Calculate table index
r = rsq11*rinv11
C Calculate table index
rt = r*tabscale
n0 = rt
eps = rt-n0
eps2 = eps*eps
nnn = 4*n0+1
C Tabulated coulomb interaction
Y = VFtab(nnn)
F = VFtab(nnn+1)
Geps = eps*VFtab(nnn+2)
Heps2 = eps2*VFtab(nnn+3)
Fp = F+Geps+Heps2
VV = Y+eps*Fp
vcoul = qq*VV
vctot = vctot + vcoul
C Load parameters for j atom
qq = qH*jq
C Calculate table index
r = rsq21*rinv21
C Calculate table index
rt = r*tabscale
n0 = rt
eps = rt-n0
eps2 = eps*eps
nnn = 4*n0+1
C Tabulated coulomb interaction
Y = VFtab(nnn)
F = VFtab(nnn+1)
Geps = eps*VFtab(nnn+2)
Heps2 = eps2*VFtab(nnn+3)
Fp = F+Geps+Heps2
VV = Y+eps*Fp
vcoul = qq*VV
vctot = vctot + vcoul
C Load parameters for j atom
C Calculate table index
r = rsq31*rinv31
C Calculate table index
rt = r*tabscale
n0 = rt
eps = rt-n0
eps2 = eps*eps
nnn = 4*n0+1
C Tabulated coulomb interaction
Y = VFtab(nnn)
F = VFtab(nnn+1)
Geps = eps*VFtab(nnn+2)
Heps2 = eps2*VFtab(nnn+3)
Fp = F+Geps+Heps2
VV = Y+eps*Fp
vcoul = qq*VV
vctot = vctot + vcoul
C Inner loop uses 77 flops/iteration
end do
C Add i forces to mem and shifted force list
C Add potential energies to the group for this list
ggid = gid(n)+1
Vc(ggid) = Vc(ggid) + vctot
C Increment number of inner iterations
ninner = ninner + nj1 - nj0
C Outer loop uses 10 flops/iteration
end do
C Increment number of outer iterations
nouter = nouter + nn1 - nn0
if(nn1.lt.nri) goto 10
C Write outer/inner iteration count to pointers
outeriter = nouter
inneriter = ninner
return
end
| gpl-2.0 |
rhristov/gcc-modified | libgfortran/generated/_log10_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_LOG10L
elemental function _gfortran_specific__log10_r16 (parm)
real (kind=16), intent (in) :: parm
real (kind=16) :: _gfortran_specific__log10_r16
_gfortran_specific__log10_r16 = log10 (parm)
end function
#endif
#endif
| gpl-2.0 |
rhristov/gcc-modified | libgomp/testsuite/libgomp.fortran/omp_workshare2.f | 221 | 1523 | C******************************************************************************
C FILE: omp_workshare2.f
C DESCRIPTION:
C OpenMP Example - Sections Work-sharing - Fortran Version
C In this example, the OpenMP SECTION directive is used to assign
C different array operations to threads that execute a SECTION. Each
C thread receives its own copy of the result array to work with.
C AUTHOR: Blaise Barney 5/99
C LAST REVISED: 01/09/04
C******************************************************************************
PROGRAM WORKSHARE2
INTEGER N, I, NTHREADS, TID, OMP_GET_NUM_THREADS,
+ OMP_GET_THREAD_NUM
PARAMETER (N=50)
REAL A(N), B(N), C(N)
! Some initializations
DO I = 1, N
A(I) = I * 1.0
B(I) = A(I)
ENDDO
!$OMP PARALLEL SHARED(A,B,NTHREADS), PRIVATE(C,I,TID)
TID = OMP_GET_THREAD_NUM()
IF (TID .EQ. 0) THEN
NTHREADS = OMP_GET_NUM_THREADS()
PRINT *, 'Number of threads =', NTHREADS
END IF
PRINT *, 'Thread',TID,' starting...'
!$OMP SECTIONS
!$OMP SECTION
PRINT *, 'Thread',TID,' doing section 1'
DO I = 1, N
C(I) = A(I) + B(I)
WRITE(*,100) TID,I,C(I)
100 FORMAT(' Thread',I2,': C(',I2,')=',F8.2)
ENDDO
!$OMP SECTION
PRINT *, 'Thread',TID,' doing section 2'
DO I = 1+N/2, N
C(I) = A(I) * B(I)
WRITE(*,100) TID,I,C(I)
ENDDO
!$OMP END SECTIONS NOWAIT
PRINT *, 'Thread',TID,' done.'
!$OMP END PARALLEL
END
| gpl-2.0 |
rhristov/gcc-modified | libgfortran/generated/_dim_r10.F90 | 47 | 1458 | ! 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_10)
elemental function _gfortran_specific__dim_r10 (p1, p2)
real (kind=10), intent (in) :: p1, p2
real (kind=10) :: _gfortran_specific__dim_r10
_gfortran_specific__dim_r10 = dim (p1, p2)
end function
#endif
| gpl-2.0 |
ForestClaw/forestclaw | src/patches/clawpatch/fort_4.6/fclaw2d_clawpatch46_copy.f | 1 | 4013 | c # ----------------------------------------------------------
c> @file
c> Exchange routines - (i,j,mq) ordering
c # ----------------------------------------------------------
c # exchange_face_ghost
c # exchange_corner_ghost
c # exchange_phys_corner_ghost
c # ----------------------------------------------------------
c--------------------------------------------------------------------
c> @brief @copybrief ::clawpatch_fort_copy_face_t
c>
c> Implementation for clawpack 4.6
c>
c> @details @copydetails ::clawpatch_fort_copy_face_t
c--------------------------------------------------------------------
subroutine fclaw2d_clawpatch46_fort_copy_face(mx,my,mbc,
& meqn,qthis,
& qneighbor,
& iface,
& transform_ptr)
implicit none
integer mx,my,mbc,meqn,iface
integer*8 transform_ptr
double precision qthis(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)
double precision qneighbor(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)
integer i,j,ibc,jbc,mq, idir
integer i1,j1, i2, j2
idir = iface/2
c # High side of 'qthis' exchanges with low side of
c # 'qneighbor'
do mq = 1,meqn
if (idir .eq. 0) then
do j = 1,my
do ibc = 1,mbc
c # Exchange at low side of 'this' grid in
c # x-direction (idir == 0)
if (iface .eq. 0) then
i1 = 1-ibc
j1 = j
elseif (iface .eq. 1) then
i1 = mx+ibc
j1 = j
endif
call fclaw2d_clawpatch_transform_face(i1,j1,i2,j2,
& transform_ptr)
qthis(i1,j1,mq) = qneighbor(i2,j2,mq)
enddo
enddo
else
do jbc = 1,mbc
do i = 1,mx
c # Exchange at high side of 'this' grid in
c # y-direction (idir == 1)
if (iface .eq. 2) then
i1 = i
j1 = 1-jbc
elseif (iface .eq. 3) then
i1 = i
j1 = my+jbc
endif
call fclaw2d_clawpatch_transform_face(i1,j1,i2,j2,
& transform_ptr)
qthis(i1,j1,mq) = qneighbor(i2,j2,mq)
enddo
enddo
endif
enddo
end
c--------------------------------------------------------------------
c> @brief @copybrief ::clawpatch_fort_copy_corner_t
c>
c> Implementation for clawpack 4.6
c>
c> @details @copydetails ::clawpatch_fort_copy_corner_t
c--------------------------------------------------------------------
subroutine fclaw2d_clawpatch46_fort_copy_corner(mx,my,mbc,meqn,
& qthis, qneighbor, this_icorner,transform_ptr)
implicit none
integer mx, my, mbc, meqn, this_icorner
integer*8 transform_ptr
double precision qthis(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)
double precision qneighbor(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)
integer mq, ibc, jbc
integer i1, j1, i2, j2
c # Do exchanges for all corners
do mq = 1,meqn
do ibc = 1,mbc
do jbc = 1,mbc
if (this_icorner .eq. 0) then
i1 = 1-ibc
j1 = 1-jbc
elseif (this_icorner .eq. 1) then
i1 = mx+ibc
j1 = 1-jbc
elseif (this_icorner .eq. 2) then
i1 = 1 -ibc
j1 = my+jbc
else
i1 = mx+ibc
j1 = my+jbc
endif
c # this routine is not yet complete, but the complete one
c # can now be dropped in.
call fclaw2d_clawpatch_transform_corner(i1,j1,i2,j2,
& transform_ptr)
qthis(i1,j1,mq) = qneighbor(i2,j2,mq)
enddo
enddo
enddo
end
| bsd-2-clause |
fthoele/espresso-5.4.0 | CPV/src/pres_ai_mod.f90 | 21 | 2696 | !
! Copyright (C) 2002 FPMD group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!=----------------------------------------------------------------------------=!
MODULE pres_ai_mod
!=----------------------------------------------------------------------------=!
use kinds, only: dp
use parameters, only: nsx
IMPLICIT NONE
!
SAVE
!
logical :: abivol, abisur, pvar, fill_vac, scale_at, t_gauss, jellium
logical :: cntr(nsx)
real(dp), allocatable:: rho_gaus(:), posv(:,:), v_vol(:), f_vol(:,:,:)
real(dp) :: P_ext, P_in, P_fin, rho_thr, step_rad(nsx)
real(dp) :: Surf_t, dthr, volclu, surfclu, n_ele, nelect
real(dp) :: R_j, e_j, h_j
real(dp) :: stress_vol(3,3)
real(dp) :: delta_eps, delta_sigma
real(dp) :: xc0(500), weight(500)
integer :: n_cntr, axis
CONTAINS
!----------------------------------------------------------------------
SUBROUTINE pres_ai_init (abivol_, abisur_, pvar_, fill_vac_, &
scale_at_, t_gauss_, jellium_, cntr_, &
P_ext_, P_in_, P_fin_, rho_thr_, &
step_rad_, Surf_t_, dthr_, R_j_, h_j_, &
delta_eps_, delta_sigma_, n_cntr_, axis_)
!----------------------------------------------------------------------
!
USE constants, ONLY : au_gpa
!
IMPLICIT NONE
!
LOGICAL :: abivol_, abisur_, pvar_, fill_vac_, scale_at_, &
t_gauss_, jellium_, cntr_(nsx)
REAL(dp) :: P_ext_, P_in_, P_fin_, rho_thr_, step_rad_(nsx), &
Surf_t_, dthr_, R_j_, h_j_, delta_eps_, delta_sigma_
INTEGER :: n_cntr_, axis_
!
! Copy variables read from input into module
!
abivol = abivol_
abisur = abisur_
pvar = pvar_
fill_vac = fill_vac_
scale_at = scale_at_
t_gauss = t_gauss_
cntr_(:) = cntr_(:)
jellium = .false. ! provvisorio
rho_thr = rho_thr_
step_rad(:) = step_rad_(:)
Surf_t = Surf_t_
dthr = dthr_
R_j = R_j_
h_j = h_j_
delta_eps = delta_eps_
delta_sigma = delta_sigma_
n_cntr = n_cntr_
axis = axis_
!
! Correct (a.u.) units to pressure
!
P_ext = P_ext_ / au_gpa
P_in = P_in_ / au_gpa
P_fin = P_fin_ / au_gpa
if (pvar) P_ext = P_in
!
END SUBROUTINE pres_ai_init
!=----------------------------------------------------------------------------=!
END MODULE pres_ai_mod
!=----------------------------------------------------------------------------=!
| gpl-2.0 |
fthoele/espresso-5.4.0 | LAXlib/transto.f90 | 1 | 7391 | !
! Copyright (C) 2001 FPMD group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! OPTIMIZED DRIVER FOR MATRIX TRASPOSITION
!
! written by Carlo Cavazzoni
!
SUBROUTINE mytranspose(x, ldx, y, ldy, n, m)
!
! x input matrix (n by m) to be trasposed
! y output matrix (m by n), the transpose of x
!
IMPLICIT NONE
#include "la_param.f90"
INTEGER :: ldx, ldy, n, m, what
REAL(DP) :: x(ldx, m), y(ldy, n)
INTEGER :: i, j, k, d, nb, mb, ib, jb, ioff, joff
INTEGER :: iind, jind
INTEGER, PARAMETER :: bsiz = __BSIZ_VALUE
REAL(DP) :: buf(bsiz, bsiz), bswp
if( n>ldx ) then
write(6,fmt='("trasponi: inconsistent ldx and n: ",2I6)') ldx, n
end if
if( m>ldy ) then
write(6,fmt='("trasponi: inconsistent ldy and m: ",2I6)') ldy, m
end if
nb = n / bsiz
mb = m / bsiz
IF( nb < 2 .AND. mb < 2 ) THEN
what = 1
ELSE
what = 2
END IF
select case (what)
case (1)
do i=1,n
do j=1,m
y(j,i) = x(i,j)
enddo
enddo
case (2)
do ib = 1, nb
ioff = (ib-1) * bsiz
do jb = 1, mb
joff = (jb-1) * bsiz
do j = 1, bsiz
do i = 1, bsiz
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do j = 1, bsiz
do i = 1, j-1
bswp = buf(i,j)
buf(i,j) = buf(j,i)
buf(j,i) = bswp
enddo
enddo
do i=1,bsiz
do j=1,bsiz
y(j+joff, i+ioff) = buf(j,i)
enddo
enddo
enddo
enddo
IF( MIN(1, MOD(n, bsiz)) > 0 ) THEN
ioff = nb * bsiz
do jb = 1, mb
joff = (jb-1) * bsiz
do j = 1, bsiz
do i = 1, MIN(bsiz, n-ioff)
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do i = 1, MIN(bsiz, n-ioff)
do j = 1, bsiz
y(j+joff,i+ioff) = buf(i,j)
enddo
enddo
enddo
END IF
IF( MIN(1, MOD(m, bsiz)) > 0 ) THEN
joff = mb * bsiz
do ib = 1, nb
ioff = (ib-1) * bsiz
do j = 1, MIN(bsiz, m-joff)
do i = 1, bsiz
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do i = 1, bsiz
do j = 1, MIN(bsiz, m-joff)
y(j+joff,i+ioff) = buf(i,j)
enddo
enddo
enddo
END IF
IF( MIN(1,MOD(n,bsiz))>0 .AND. MIN(1,MOD(m,bsiz))>0 ) THEN
joff = mb * bsiz
ioff = nb * bsiz
do j = 1, MIN(bsiz, m-joff)
do i = 1, MIN(bsiz, n-ioff)
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do i = 1, MIN(bsiz, n-ioff)
do j = 1, MIN(bsiz, m-joff)
y(j+joff,i+ioff) = buf(i,j)
enddo
enddo
END IF
#if defined __ESSL
case (3)
CALL DGETMO (x, ldx, n, m, y, ldy)
#endif
case default
write(6,fmt='("trasponi: undefined method")')
end select
RETURN
END SUBROUTINE mytranspose
SUBROUTINE mytransposez(x, ldx, y, ldy, n, m)
!
! x input matrix (n by m) to be trasposed
! y output matrix (m by n), the transpose of x
!
IMPLICIT NONE
#include "la_param.f90"
INTEGER :: ldx, ldy, n, m, what
COMPLEX(DP) :: x(ldx, m), y(ldy, n)
INTEGER :: i, j, k, d, nb, mb, ib, jb, ioff, joff
INTEGER :: iind, jind
INTEGER, PARAMETER :: bsiz = __BSIZ_VALUE / 2
COMPLEX(DP) :: buf(bsiz, bsiz), bswp
if( n>ldx ) then
write(6,fmt='("trasponi: inconsistent ldx and n")')
end if
if( m>ldy ) then
write(6,fmt='("trasponi: inconsistent ldy and m")')
end if
nb = n / bsiz
mb = m / bsiz
IF( nb < 2 .AND. mb < 2 ) THEN
what = 1
ELSE
what = 2
END IF
select case (what)
case (1)
do i=1,n
do j=1,m
y(j,i) = x(i,j)
enddo
enddo
case (2)
do ib = 1, nb
ioff = (ib-1) * bsiz
do jb = 1, mb
joff = (jb-1) * bsiz
do j = 1, bsiz
do i = 1, bsiz
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do j = 1, bsiz
do i = 1, j-1
bswp = buf(i,j)
buf(i,j) = buf(j,i)
buf(j,i) = bswp
enddo
enddo
do i=1,bsiz
do j=1,bsiz
y(j+joff, i+ioff) = buf(j,i)
enddo
enddo
enddo
enddo
IF( MIN(1, MOD(n, bsiz)) > 0 ) THEN
ioff = nb * bsiz
do jb = 1, mb
joff = (jb-1) * bsiz
do j = 1, bsiz
do i = 1, MIN(bsiz, n-ioff)
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do i = 1, MIN(bsiz, n-ioff)
do j = 1, bsiz
y(j+joff,i+ioff) = buf(i,j)
enddo
enddo
enddo
END IF
IF( MIN(1, MOD(m, bsiz)) > 0 ) THEN
joff = mb * bsiz
do ib = 1, nb
ioff = (ib-1) * bsiz
do j = 1, MIN(bsiz, m-joff)
do i = 1, bsiz
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do i = 1, bsiz
do j = 1, MIN(bsiz, m-joff)
y(j+joff,i+ioff) = buf(i,j)
enddo
enddo
enddo
END IF
IF( MIN(1,MOD(n,bsiz))>0 .AND. MIN(1,MOD(m,bsiz))>0 ) THEN
joff = mb * bsiz
ioff = nb * bsiz
do j = 1, MIN(bsiz, m-joff)
do i = 1, MIN(bsiz, n-ioff)
buf(i,j) = x(i+ioff, j+joff)
enddo
enddo
do i = 1, MIN(bsiz, n-ioff)
do j = 1, MIN(bsiz, m-joff)
y(j+joff,i+ioff) = buf(i,j)
enddo
enddo
END IF
#if defined __ESSL
case (3)
CALL ZGETMO (x, ldx, n, m, y, ldy)
#endif
case default
write(6,fmt='("trasponi: undefined method")')
end select
RETURN
END SUBROUTINE mytransposez
| gpl-2.0 |
ForestClaw/forestclaw | applications/paper/transport_torus/qad_new.f90 | 2 | 11968 | !! For each coarse-fine interface, a Riemann problem between an inner
!! ghost cell value on the fine grid and cell value in the adjacent coarse
!! cell must be solved and added to corresponding location in
!! **node(ffluxptr, mptr)** for conservative fix later
!!
!! -------------------------------------------------------------
!!
SUBROUTINE qad_new(valbig,mitot,mjtot,nvar, &
svdflx,qc1d,lenbc,lratiox,lratioy,hx,hy, &
maux,auxbig,auxc1d,delt,mptr)
USE amr_module, only : timemult, nghost, max1d, maxaux, mwaves,nestlevel,rnode, &
auxtype, node, method, max1d
IMPLICIT NONE
INTEGER mitot, mjtot, nvar, lenbc, lratiox, lratioy, maux
INTEGER mptr
DOUBLE PRECISION hx,hy,delt
DOUBLE PRECISION, TARGET :: valbig(nvar,mitot,mjtot)
DOUBLE PRECISION, TARGET :: auxbig(maux,mitot,mjtot)
DOUBLE PRECISION qc1d(nvar,lenbc)
DOUBLE PRECISION svdflx(nvar,lenbc)
DOUBLE PRECISION auxc1d(maux,lenbc)
DOUBLE PRECISION, POINTER :: q(:,:,:)
DOUBLE PRECISION, POINTER :: aux(:,:,:)
!!
!! ::::::::::::::::::::::::::: QAD ::::::::::::::::::::::::::::::::::
!! are added in to coarse grid value, as a conservation fixup.
!! Done each fine grid time step. If source terms are present, the
!! coarse grid value is advanced by source terms each fine time step too.
!! No change needed in this sub. for spherical mapping: correctly
!! mapped vals already in bcs on this fine grid and coarse saved
!! vals also properly prepared
!!
!! Side 1 is the left side of the fine grid patch. Then go around clockwise.
!! ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
!!
!! # local storage
!! max1d is largest possible grid size (defined in amr_module.f90)
INTEGER :: max1dp1
DOUBLE PRECISION wave(nvar,mwaves,max1d+1)
DOUBLE PRECISION s(mwaves,max1d+1)
DOUBLE PRECISION amdq(nvar,max1d+1)
DOUBLE PRECISION apdq(nvar,max1d+1)
DOUBLE PRECISION, TARGET :: auxlbig(maxaux*(max1d+1))
DOUBLE PRECISION, TARGET :: auxrbig(maxaux*(max1d+1))
DOUBLE PRECISION, POINTER :: auxf(:,:)
DOUBLE PRECISION, POINTER :: auxc(:,:)
!! Temporary variables (used instead of ql,qr)
DOUBLE PRECISION qf(nvar,max1d+1)
DOUBLE PRECISION qc(nvar,max1d+1)
DOUBLE PRECISION tgrid
INTEGER nc, nr, level, index, l
INTEGER i,j,ma,lind, ncrse, ic, jc, ifine, jfine
INTEGER iaux
INTEGER mx,my,mbc,meqn, mxc, myc, mq
DOUBLE PRECISION dt, dx, dy, delta_fix
INTEGER iface, idir
LOGICAL prt
max1dp1 = max1d + 1
tgrid = rnode(timemult, mptr)
nr = mitot-2*nghost
nc = mjtot-2*nghost
level = node(nestlevel, mptr)
index = 0
!! Rename variables to use Clawpack convention
mbc = nghost
mx = nr
my = nc
meqn = nvar
dt = delt
dx = hx
dy = hy
mxc = mx/lratiox
myc = my/lratioy
!! Redimension arrays to use indexing that starts at 1-mbc, etc
q(1:meqn,1-mbc:mx+mbc,1-mbc:my+mbc) => valbig
if (maux .gt. 0) then
aux(1:maux,1-mbc:mx+mbc,1-mbc:my+mbc) => auxbig
auxf(1:maux,1:max1dp1) => auxlbig
auxc(1:maux,1:max1dp1) => auxrbig
endif
!! Counter for indexing into 1d arrays of coarse grid values
index = 0
!! ----------------------------------------------
!! Side 1
!! ----------------------------------------------
!!
!! iface = 0 (left edge)
!!
!! Fine grid is on the right; coarse grid is on the left
!!
!! auxf, qf : data for right (fine) cell
!! auxc, qc : data for left (coarse) cell
!!
DO j = 1,my
IF (maux .GT. 0) THEN
DO ma = 1,maux
IF (auxtype(ma) .EQ. "xleft") THEN
!! # Assuming velocity at left-face, this fix
!! # preserves conservation in incompressible flow:
auxf(ma,j) = aux(ma,1,j)
ELSE
!! # Normal case -- we set the aux arrays
!! # from the cell corresponding to q
auxf(ma,j) = aux(ma,0,j)
ENDIF
ENDDO
ENDIF
DO mq = 1,meqn
qf(mq,j) = q(mq,0,j)
ENDDO
ENDDO
!! Side 1
DO jc = 1,myc
DO l = 1,lratioy
jfine = (jc-1)*lratioy + l
IF (maux .GT. 0) THEN
DO ma = 1,maux
auxc(ma,jfine) = auxc1d(ma,index + jc)
ENDDO
ENDIF
DO mq = 1,meqn
qc(mq,jfine) = qc1d(mq,index + jc)
ENDDO
ENDDO
ENDDO
idir = 0
iface = 0 !! Face of Cartesian grid
CALL rpn2qad_new(my,meqn,maux,mbc, idir, iface, &
qf,qc,auxf,auxc,amdq,apdq)
!! Side 1
DO jc = 1,myc
DO l = 1,lratioy
jfine = (jc-1)*lratioy + l
DO mq = 1,meqn
delta_fix = amdq(mq,jfine) + apdq(mq,jfine)
svdflx(mq,index+jc) = svdflx(mq,index+jc) + dy*dt*delta_fix
ENDDO
ENDDO
ENDDO
index = myc
!! ----------------------------------------------
!! Side 2
!! ----------------------------------------------
!!
!! iface = 4 (top edge)
!!
!! Fine grid is on the left (bottom); coarse grid is on the right (top)
!!
!! auxf, qf : data for bottom (fine) cell
!! auxc, qc : data for top (coarse) cell
!!
IF (my .EQ. 1) THEN
!! # a single row of interior cells only happens when using the
!! # 2d amrclaw code to do a 1d problem with refinement.
!! # (feature added in Version 4.3)
!! # skip over sides 2 and 4 in this case
go to 299
ENDIF
!! Side 2
DO i = 1,mx
IF (maux .GT. 0) THEN
DO ma = 1,maux
auxf(ma,i) = aux(ma,i,my+1)
ENDDO
ENDIF
DO mq = 1,meqn
qf(mq,i) = q(mq,i,my+1)
ENDDO
ENDDO
!! Side 2
DO ic = 1, mxc
DO l = 1,lratiox
ifine = (ic-1)*lratiox + l
IF (maux .GT. 0) THEN
DO ma = 1,maux
IF (auxtype(ma) .EQ. "yleft") THEN
!! This only makes sense if coarse and fine grids align at their
!! shared boundary.
auxc(ma,ifine) = aux(ma,ifine,my+1)
ELSE
auxc(ma,ifine) = auxc1d(ma,index + ic)
ENDIF
ENDDO
ENDIF
DO mq = 1,meqn
qc(mq,ifine) = qc1d(mq,index + ic)
ENDDO
ENDDO
ENDDO
idir = 1
iface = 3
CALL rpn2qad_new(mx,meqn,maux,mbc, idir, iface, &
qf,qc,auxf,auxc,amdq,apdq)
!! Side 2
DO ic = 1,mxc
DO l = 1,lratiox
ifine = (ic-1)*lratiox + l
DO mq = 1,meqn
delta_fix = amdq(mq,ifine) + apdq(mq,ifine)
svdflx(mq,index+ic) = svdflx(mq,index+ic) + dx*dt*delta_fix
ENDDO
ENDDO
ENDDO
index = index + mxc
299 continue
!! ----------------------------------------------
!! Side 3
!! ----------------------------------------------
!!
!! iface = 1 (right edge)
!!
!! Fine grid is on the left; coarse grid is on the right
!!
!! auxf, qf : data for left (fine) cell
!! auxc, qc : data for right (coarse) cell
!!
DO j = 1, my
IF (maux .GT. 0) THEN
DO ma = 1,maux
auxf(ma,j) = aux(ma,mx+1,j)
ENDDO
ENDIF
DO mq = 1, meqn
qf(mq,j) = q(mq,mx+1,j)
ENDDO
ENDDO
!! Side 3
DO jc = 1,myc
DO l = 1,lratioy
jfine = (jc-1)*lratioy + l
IF (maux .GT. 0) THEN
DO ma = 1,maux
IF (auxtype(ma).EQ."xleft") THEN
!! This only makes sense if coarse and fine grids align at their
!! shared boundary.
auxc(ma,jfine) = aux(ma,mx+1,jfine)
ELSE
auxc(ma,jfine) = auxc1d(ma,index + jc)
ENDIF
ENDDO
ENDIF
DO mq = 1, meqn
qc(mq,jfine) = qc1d(mq,index + jc)
ENDDO
ENDDO
ENDDO
idir = 0
iface = 1
CALL rpn2qad_new(my,meqn,maux,mbc, idir, iface, &
qf,qc,auxf,auxc,amdq,apdq)
!! Side 3
DO jc = 1, myc
DO l = 1, lratioy
jfine = (jc-1)*lratioy + l
DO mq = 1, meqn
delta_fix = amdq(mq,jfine) + apdq(mq,jfine)
svdflx(mq,index + jc) = svdflx(mq,index + jc) + dy*dt*delta_fix
ENDDO
ENDDO
ENDDO
index = index + myc
!! ----------------------------------------------
!! Side 4
!! ----------------------------------------------
!!
!! iface = 2 (bottom edge)
!!
!! Fine grid is on the top (right); coarse grid is on the bottom (left)
!!
!! auxf, qf : data for right (fine) cell
!! auxc, qc : data for left (coarse) cell
!!
IF (my .EQ. 1) THEN
!! # a single row of interior cells only happens when using the
!! # 2d amrclaw code to do a 1d problem with refinement.
!! # (feature added in Version 4.3)
!! # skip over sides 2 and 4 in this case
go to 499
ENDIF
!! Side 4
DO i = 1, mx
IF (maux .GT. 0) THEN
!! Is this conditional needed? Loop won't do anything if maux == 0
DO ma = 1,maux
IF (auxtype(ma) .EQ. "yleft") THEN
auxf(ma,i) = aux(ma,i,1)
ELSE
auxf(ma,i) = aux(ma,i,0)
ENDIF
ENDDO
ENDIF
DO mq = 1, meqn
qf(mq,i) = q(mq,i,0)
ENDDO
ENDDO
!! Side 4
DO ic = 1,mxc
DO l = 1,lratiox
ifine = (ic-1)*lratiox + l
IF (maux .GT. 0) THEN
DO ma = 1,maux
auxc(ma,ifine) = auxc1d(ma,index + ic)
ENDDO
ENDIF
DO mq = 1, meqn
qc(mq,ifine) = qc1d(mq,index + ic)
ENDDO
ENDDO
ENDDO
idir = 1
iface = 2
CALL rpn2qad_new(mx,meqn,maux,mbc, idir, iface, &
qf,qc,auxf,auxc,amdq,apdq)
!! Side 4
DO ic = 1,mxc
DO l = 1,lratiox
ifine = (ic-1)*lratiox + l
DO mq = 1,meqn
delta_fix = amdq(mq,ifine) + apdq(mq,ifine)
svdflx(mq,index + ic) = svdflx(mq,index + ic) + dx*dt*delta_fix
ENDDO
ENDDO
ENDDO
499 continue
!! # for source terms:
IF (method(5) .NE. 0) THEN ! should I test here if index=0 and all skipped?
!! call src1d(meqn,nghost,lenbc,qc1d,maux,auxc1d,tgrid,delt)
!! # how can this be right - where is the integrated src term used?
ENDIF
RETURN
END SUBROUTINE qad_new
SUBROUTINE rpn2qad_new(mx,meqn,maux,mbc, idir, iface, &
qf,qc,auxf,auxc,amdq,apdq)
IMPLICIT NONE
INTEGER mx, meqn, maux, mbc, idir, iface
DOUBLE PRECISION qf(meqn,mx), qc(meqn,mx)
DOUBLE PRECISION auxf(maux,mx), auxc(maux,mx)
DOUBLE PRECISION amdq(meqn,mx)
DOUBLE PRECISION apdq(meqn,mx)
!! automatically allocated
DOUBLE PRECISION qvc(meqn), qvf(meqn)
DOUBLE PRECISION auxvc(maux), auxvf(maux)
DOUBLE PRECISION fluxf(meqn), fluxc(meqn)
DOUBLE PRECISION fd
INTEGER m,i, iface_cell, sgn
!! idir refers to direction of the Riemann solver
!! iface refers to the face of the Cartesian grid (not face of cell)
DO i = 1,mx
do m = 1,maux
auxvf(m) = auxf(m,i)
auxvc(m) = auxc(m,i)
end do
do m = 1,meqn
qvf(m) = qf(m,i)
qvc(m) = qc(m,i)
end do
!! Get face relative to ghost cell
!! Left face of Cartesian grid --> right edge of ghost cell
!! Right face of Cartesian grid --> left edge of ghost cell
!! Bottom face of Cartesian grid --> top edge of ghost cell
!! Top face of Cartesian grid --> bottom edge of ghost cell
if (idir .eq. 0) then
iface_cell = 1-iface !! Swap left and right edges
else
iface_cell = 5-iface !! Swap bottom and top edges
endif
!! Call user defined function to compute fluxes. The resulting
!! flux should be those projected onto face 'iface_cell' and
!! scaled by edgelength/dx or edgelength/dy.
call rpn2qad_flux(meqn,maux,idir,iface_cell,qvf,auxvf,fluxf)
call rpn2qad_flux(meqn,maux,idir,iface_cell,qvc,auxvc,fluxc)
do m = 1,meqn
fd = fluxf(m) - fluxc(m)
apdq(m,i) = 0.5*fd
amdq(m,i) = 0.5*fd
end do
ENDDO
END SUBROUTINE rpn2qad_new
| bsd-2-clause |
ars599/mom5 | src/mom5/ocean_param/vertical/ocean_vert_tidal_test.F90 | 3 | 106665 | module ocean_vert_tidal_test_mod
!
!<CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> S. M. Griffies
!</CONTACT>
!
!<REVIEWER EMAIL="hsimmons@iarc.uaf.edu"> Harper Simmons
!</REVIEWER>
!
!<REVIEWER EMAIL="GFDL.Climate.Model.Info@noaa.gov"> Hyun-Chul Lee
!</REVIEWER>
!
!<OVERVIEW>
! This module computes a vertical diffusivity and vertical
! viscosity deduced from barotropic and baroclinic tidal
! dissipation. Assume Prandtl number unity.
!</OVERVIEW>
!
!<DESCRIPTION>
! This module computes a vertical diffusivity and vertical
! viscosity deduced from barotropic and baroclinic tidal
! dissipation. For the baroclinic dissipation, we follow
! Simmons etal, and for the barotropic dissipation we follow
! Lee etal. Assume Prandtl number unity.
!
! This code is more general than that in the ocean_vert_kpp_mom4p0_mod.
! The KPP_mom4p0 code remains part of MOM for legacy purposes.
!
! There are some testing routines in this module that remain exploratory
! at GFDL.
!
!</DESCRIPTION>
!
! <INFO>
!
! <REFERENCE>
! Simmons, Jayne, St. Laurent, and Weaver, 2004:
! Tidally driven mixing in a numerical model of the ocean
! general circulation. Ocean Modelling, vol. 6,
! pages 245-263.
! </REFERENCE>
!
! <REFERENCE>
! Jayne and St. Laurent, 2001:
! Parameterizing tidal dissipation over rough topography.
! Geophysical Research Letters, vol. 28, pages 811-814.
! </REFERENCE>
!
! <REFERENCE>
! Hyun-Chul Lee, A. Rosati, and M.J. Spelman, 2006:
! Barotropic tidal mixing effects in a coupled climate model:
! ocean conditions in the northern Atlantic
! Ocean Modelling, vol 11, pages 464--477
! </REFERENCE>
!
! <REFERENCE>
! Osborn, T.R., 1980: Estimates of the local rate of vertical diffusion
! from dissipation measurements. JPO, vol. 10, pages 83-89.
! </REFERENCE>
!
! <REFERENCE>
! Munk and Anderson, 1948: Notes on a theory of the thermocline.
! Journal of Marine Research, vol 3. pages 276-295.
! </REFERENCE>
!
! <REFERENCE>
! S.M. Griffies, Elements of MOM (2012)
! </REFERENCE>
!
! </INFO>
!
!<NAMELIST NAME="ocean_vert_tidal_test_nml">
! <DATA NAME="use_this_module=" TYPE="logical">
! Must be .true. to use this module. Default is false.
! </DATA>
! <DATA NAME="debug_this_module" TYPE="logical">
! For debugging purposes.
! </DATA>
!
! <DATA NAME="use_wave_dissipation=" TYPE="logical">
! Set to .true. for using the Simmons etal scheme for
! obtaining a diffusivity and viscosity based on internal
! wave breaking. This is a general form of the KPP
! scheme "int_tidal_mix".
! Default use_wave_dissipation=.false.
! </DATA>
! <DATA NAME="use_drag_dissipation=" TYPE="logical">
! Set to .true. for using the Lee etal scheme for
! obtaining a diffusivity and viscosity based on drag
! of barotropic tides on bottom. This is a general
! form of the KPP scheme "coastal_tidal_mix".
! Default use_drag_dissipation=.false.
! </DATA>
! <DATA NAME="use_leewave_dissipation=" TYPE="logical">
! Set to .true. for using a prototype Nikurashin scheme for
! obtaining a diffusivity and viscosity based on breaking
! leewaves. This scheme is not related to tides, but it
! is incorporated to the baroclinic tide parameterization scheme
! as a prototype. It will be placed into ts own module when
! the parameterization matures.
! Default use_leewave_dissipation=.false.
! </DATA>
!
! <DATA NAME="read_leewave_dissipation" TYPE="logical">
! If .true. then read in leewave dissipation from a file.
! Default read_leewave_dissipation=.false.
! </DATA>
!
! <DATA NAME="read_wave_dissipation" TYPE="logical">
! If .true. then read in wave dissipation computed from
! Jayne and St.Laurent (2001) tide model (or another model).
! Default read_wave_dissipation=.false.
! </DATA>
! <DATA NAME="fixed_wave_dissipation" TYPE="logical">
! If .true. then fix the wave dissipation from that
! read in by the tide model, such as Jayne and St.Laurent (2001).
! This power dissipation will be employed
! for computing wave induced mixing.
! Default fixed_wave_dissipation=.false.
! </DATA>
!
! <DATA NAME="read_roughness" TYPE="logical">
! If .true. then read in bottom roughness amplitude h,
! where roughness_length = kappa*h^2, with kappa a
! representative roughness wavelength and h a
! representative topographic amplitude. This information is
! used for the Simmons etal wave dissipation parameterization.
! </DATA>
! <DATA NAME="reading_roughness_length" TYPE="logical">
! If .true., then the field in the roughness file is
! roughness_length = kappa*h^2, with kappa a
! representative roughness wavelength and h a
! representative topographic amplitude. This information is
! used for the Simmons etal wave dissipation parameterization.
! Default reading_roughness_length=.false.
! </DATA>
! <DATA NAME="reading_roughness_amp" TYPE="logical">
! If .true., then the field in the roughness file is
! roughness_amp=h, where roughness_length=kappa*h^2.
! This information is used for the Simmons etal wave
! dissipation parameterization.
! Default reading_roughness_amp=.false.
! </DATA>
! <DATA NAME="default_roughness_length" UNITS="m" TYPE="real">
! Default value for kappa*h^2 = roughness length for use
! in the absence of a roughness length dataset. MOM default
! is default_roughness_length=25.0m.
! </DATA>
!
! <DATA NAME="read_tide_speed" TYPE="logical">
! If .true. then read in tidal speed (m/s) from a tidal model.
! This information is used for the computing the energy dissipation
! from tides.
! scheme.
! </DATA>
! <DATA NAME="tide_speed_data_on_t_grid" TYPE="logical">
! To set the input tide speed data on T-grid, set to true.
! Otherwise, set to false.
! Default tide_speed_data_on_t_grid=.true.
! </DATA>
!
! <DATA NAME="roughness_scale" UNITS="m" TYPE="real">
! Scale for the roughness that characterizes the roughness
! affecting the tidal dissipation process. Used for setting
! roughness_length via roughness_length = kappa*h^2, with
! kappa = 2pi/(roughness_scale) and h=topography amplitude.
! Default roughness_scale=1e4 as in Jayne and St. Laurent (2001)
! </DATA>
! <DATA NAME="default_tide_speed" UNITS="m/s" TYPE="real">
! Default value for tidal speed for use in the absence of a
! value from a tidal model.
! </DATA>
! <DATA NAME="speed_min" UNITS="m/s" TYPE="real">
! For the drag scheme, we set the diffusivity as well as the
! Richardson number to zero if the tide speed is less than
! speed_min. This serves two purposes: 1/ to reduce overflows
! in some of the diagnostics; 2/ to set the drag induced diffusivity
! to zero in regions where the tide speed is small. Default
! speed_min=5e-3m/s.
! </DATA>
!
! <DATA NAME="shelf_depth_cutoff" UNITS="m" TYPE="real">
! For use in defining a mask for the Simmons scheme, with depths
! shallower than shelf_depth_cutoff removed from the scheme.
! shelf_depth_cutoff=1000m in Simmons etal.
! Default shelf_depth_cutoff=-1000m so there is no cutoff.
! </DATA>
!
! <DATA NAME="decay_scale" UNITS="m" TYPE="real">
! In the Simmons etal vertical profile function, the exponential decay
! scale is determined by this parameter. Default = 500m as in Simmons
! etal (2004). This vertical profile determines how to deposit the
! internal wave energy within a vertical column.
! </DATA>
!
! <DATA NAME="tidal_diss_efficiency" UNITS="dimensionless" TYPE="real">
! Fraction of barotropic tidal energy that is dissipated locally, as
! opposed to that which propagates away. Default=1/3 as in
! Simmons etal (2004).
! </DATA>
!
! <DATA NAME="mixing_efficiency" UNITS="dimensionless" TYPE="real">
! Fraction of energy that is dissipated which is converted into dianeutral
! diffusion of tracer. Default=0.2 based on Osborn (1980).
! </DATA>
! <DATA NAME="mixing_efficiency_n2depend" TYPE="logical">
! Allow for mixing efficiency to be a function of
! N^2/(N^2+Omega^2), which is close to unity except in
! regions where N is very small.
! Default mixing_efficiency_n2depend=.false.
! </DATA>
!
! <DATA NAME="wave_energy_flux_max" UNITS="W/m2" TYPE="real">
! The maximum mechanical energy from internal tides that is
! provided for mixing. Default wave_energy_flux_max=0.1Watt/m^2.
! </DATA>
!
! <DATA NAME="wave_diffusivity_monotonic" TYPE="logical">
! Enforce a monotonic decay of the wave dissipation diffusivity,
! with largest values near bottom and smaller as move to shallower
! water. This behaviour is not guaranteed in general, since the
! division by the buoyancy frequency can give non-monotone diffusivities.
! Default wave_diffusivity_monotonic=.true.
! </DATA>
!
! <DATA NAME="munk_anderson_p" UNITS="dimensionless" TYPE="real">
! The p constant in the Munk-Anderson scheme employed by Lee etal.
! This parameter is minus the "p_tide" parameter in the KPP schemes.
! Default munk_anderson_p=0.25
! </DATA>
! <DATA NAME="munk_anderson_sigma" UNITS="dimensionless" TYPE="real">
! The sigma constant in the Munk-Anderson scheme employed by Lee etal.
! This parameter is called "sigma_tide" in the KPP schemes.
! Default munk_anderson_sigma=3.0
! </DATA>
! <DATA NAME="drag_dissipation_use_cdbot" TYPE="logical">
! For using the cdbot_array computed from ocean_bbc.F90 module.
! Default drag_dissipation_use_cdbot=.false., as this is consistent
! with earlier simulations.
! </DATA>
! <DATA NAME="bottom_drag_cd" UNITS="dimensionless" TYPE="real">
! Bottom drag coefficient from Lee etal. Default bottom_drag_cd=2.4e-3
! </DATA>
!
! <DATA NAME="background_diffusivity" UNITS="m^2/s" TYPE="real">
! Background vertical diffusivity not accounted for by the tidal schemes
! nor any other scheme such as KPP. Default=0.1e-4.
! </DATA>
! <DATA NAME="background_viscosity" UNITS="m^2/s" TYPE="real">
! Background vertical viscosity not accounted for by the tidal schemes
! nor any other scheme such as KPP. Default=0.1e-4.
! </DATA>
! <DATA NAME="max_wave_diffusivity" UNITS="m^2/s" TYPE="real">
! Maximum tracer diffusivity deduced from the wave dissipation
! scheme from Simmons etal. Default = 5.e-3 m^2/sec.
! </DATA>
!
! <DATA NAME="max_drag_diffusivity" UNITS="m^2/s" TYPE="real">
! Maximum tracer diffusivity deduced from the drag dissipation scheme
! from Lee etal. Default = 5.e-3 m^2/sec.
! </DATA>
! <DATA NAME="drag_dissipation_efold" TYPE="logical">
! For setting an efolding whereby the drag dissipation diffusivity
! exponentially decreases as move upward in the water column.
! There are good reasons to set this logical to true, as the scheme
! can produce unreasonably large diffusivities far from the bottom, if
! there are tides in the deep ocean.
! Default drag_dissipation_efold=.true.
! </DATA>
! <DATA NAME="drag_dissipation_tide_period" UNITS="s" TYPE="real">
! Characteristic tide period for use in computing efolding depth for
! the tide drag scheme. Default = 12*60*60 = 12hours for semi-diurnal tide.
! </DATA>
! <DATA NAME="drag_mask_deep" TYPE="logical">
! For masking out the deep ocean regions for the drag dissipation
! scheme. This scheme is meant to apply only in shallow shelves,
! so it is physically relevant to mask it out. We apply a mask as
! determined by the ratio of the frictional tide depth scale and the
! total ocean depth.
! Default drag_mask_deep=.true.
! </DATA>
! <DATA NAME="drag_mask_deep_ratio" TYPE="real">
! For determining the drag dissipation mask.
! The mask = 0 in regions where
! tide_depth/total_depth < drag_mask_deep_ratio
! Default drag_mask_deep_ratio=0.1
! </DATA>
! <DATA NAME="smooth_ri_drag_cgrid" TYPE="logical">
! For smoothing the raw C-grid Richardson number computed for
! the drag scheme on the Cgrid. Default smooth_ri_drag_cgrid=.true.
! </DATA>
!
! <DATA NAME="use_legacy_methods" TYPE="logical">
! To compute all mixing coefficients using legacy methods.
! There are good reasons to prefer the newer approaches, which motivates
! setting the default use_legacy_methods=.false.
! </DATA>
! <DATA NAME="drhodz_min" UNITS="kg/m^3" TYPE="real">
! Minimum absolute value for the drhodz used to compute N^2 and rhoN2.
! This value is needed in order to regularize the diffusivity computed
! from the tide mixing schemes. Default is drhodz_min=1e-10, which
! is much smaller than the (N^2)min = 10^-8 sec^-2 used by Simmons
! etal. There is some sensitivity to the choice of drhodz_min, with
! larger values leading to reduced deep diffusivities, due to the
! N^-2 dependence in the diffusivity calculation.
! </DATA>
! <DATA NAME="smooth_bvfreq_bottom" TYPE="logical">
! For smoothing the buoyancy frequency at the bottom.
! Default smooth_bvfreq_bottom=.true.
! </DATA>
! <DATA NAME="vel_micom_smooth" UNITS="m/sec" TYPE="real">
! Velocity scale that is used for computing the MICOM Laplacian mixing
! coefficient used in the Laplacian smoothing of diffusivities.
! Default vel_micom_smooth=0.2.
! </DATA>
!
! <DATA NAME="smooth_rho_N2" TYPE="logical">
! For smoothing the rho_N2 field via a 1-2-1 filter in
! vertical. This is useful to produce smoother diffusivities.
! Default is smooth_rho_N2=.true.
! </DATA>
! <DATA NAME="num_121_passes" TYPE="integer">
! Number of passes of 1-2-1 filter in vertical for
! smoothing the rho_N2 field. Default num_121_passes=1.
! </DATA>
!
! <DATA NAME="repro_legacy_const_cdbot" TYPE="logical">
! for reproduce legacy results with constant cdbot.
! To reproduce the previous results, set;
! drag_dissipation_use_cdbot=.false., repro_legacy_const_cdbot=.true.
! If drag_dissipation_use_cdbot=.true., then results are reproduciable.
! Default repro_legacy_const_cdbot= .false.
! </DATA>
!
!
!</NAMELIST>
use constants_mod, only: pi, epsln
use diag_manager_mod, only: register_diag_field, register_static_field, send_data
use fms_mod, only: write_version_number, open_namelist_file, close_file, check_nml_error
use fms_mod, only: stdout, stdlog, read_data, NOTE, FATAL, WARNING
use mpp_domains_mod, only: mpp_update_domains
use mpp_mod, only: input_nml_file, mpp_error
use ocean_domains_mod, only: get_local_indices
use ocean_operators_mod, only: LAP_T
use ocean_parameters_mod, only: MOM_BGRID, MOM_CGRID
use ocean_parameters_mod, only: missing_value, onehalf, onefourth
use ocean_parameters_mod, only: von_karman, rho0, rho0r, omega_earth, grav
use ocean_types_mod, only: ocean_time_type, ocean_domain_type, ocean_grid_type, ocean_options_type
use ocean_types_mod, only: ocean_prog_tracer_type, ocean_thickness_type, ocean_density_type, ocean_velocity_type
use ocean_workspace_mod, only: wrk1, wrk2, wrk3, wrk1_2d
implicit none
private
! for diagnostics
integer :: id_tide_speed_wave =-1
integer :: id_tide_speed_drag =-1
integer :: id_tide_speed_mask =-1
integer :: id_tide_rescspeed_mask=-1
integer :: id_tide_deepspeed_mask=-1
integer :: id_roughness_length =-1
integer :: id_roughness_amp =-1
integer :: id_roughness_klevel =-1
integer :: id_energy_flux =-1
integer :: id_power_waves =-1
integer :: id_leewave_dissipation=-1
integer :: id_power_diss_wave =-1
integer :: id_power_diss_drag =-1
integer :: id_power_diss_tides =-1
integer :: id_power_diss_leewave =-1
integer :: id_rinumber_drag =-1
integer :: id_drag_dissipation =-1
integer :: id_bvfreq_bottom =-1
integer :: id_mix_efficiency =-1
integer :: id_bvfreq =-1
integer :: id_diff_cbt_wave =-1
integer :: id_diff_cbt_drag =-1
integer :: id_diff_cbt_leewave =-1
integer :: id_diff_cbt_tides =-1
integer :: id_visc_cbt_wave =-1
integer :: id_visc_cbt_drag =-1
integer :: id_visc_cbt_leewave =-1
integer :: id_visc_cbt_tides =-1
integer :: id_visc_cbu_wave =-1
integer :: id_visc_cbu_leewave =-1
integer :: id_visc_cbu_drag =-1
integer :: id_visc_cbu_tides =-1
integer :: id_drag_diss_efold =-1
integer :: id_tide_diff_cbt_back =-1
integer :: id_tide_visc_cbu_back =-1
logical :: used
#include <ocean_memory.h>
real, private, dimension(:,:), allocatable :: smooth_lap !2D array of micom diffusivities (m^2/sec) for smoothing
real, private, dimension(:,:), allocatable :: roughness_amp ! roughness amplitude (m) from topography
real, private, dimension(:,:), allocatable :: roughness_length ! roughness length (m) from topography
real, private, dimension(:,:), allocatable :: wave_dissipation ! wave dissipation (W/m2) from tide model
real, private, dimension(:,:), allocatable :: leewave_dissipation ! leewave dissipation (W/m2)
real, private, dimension(:,:), allocatable :: tide_speed_t ! T-cell speed (m/s) from barotropic tide model
real, private, dimension(:,:), allocatable :: tide_speed_u ! U-cell speed (m/s) from barotropic tide model
real, private, dimension(:,:), allocatable :: tide_speed_mask ! U-cell mask for rescaled speed, only for legacy
real, private, dimension(:,:), allocatable :: tide_rescspeed_mask ! U-cell mask for rescaled speed
real, private, dimension(:,:), allocatable :: tide_deepspeed_mask ! U-cell mask for deep ocean region
real, private, dimension(:,:), allocatable :: rescaled_speed_u ! U-cell speed (m/s) for Lee etal calculation of Ri
real, private, dimension(:,:), allocatable :: rescaled_speed_t ! T-cell speed (m/s) for Lee etal calculation of Ri
real, private, dimension(:,:), allocatable :: efold_depth_r ! T-cell inverse efold depth (1/m) for Lee etal
real, private, dimension(:,:), allocatable :: energy_flux ! energy flux (W/m^2) out of ext-tide to int-tide
real, private, dimension(:,:), allocatable :: wave_term ! static term in wave energy flux calculation
real, private, dimension(:,:), allocatable :: bvfreq_bottom ! buoyancy frequency (sec^-1) at ocean bottom
real, private, dimension(:,:,:), allocatable :: mix_efficiency ! dimensionless mixing efficiency
real, private, dimension(:,:,:), allocatable :: bvfreq ! buoyancy frequency (sec^-1)
real, private, dimension(:,:,:), allocatable :: rho_N2 ! rho*squared buoyancy frequency (kg/m^3)*(sec^-2)
real, private, dimension(:,:,:), allocatable :: drhodT ! partial rho / partial temperature
real, private, dimension(:,:,:), allocatable :: drhodS ! partial rho / partial salinity
real, private, dimension(:,:,:), allocatable :: diff_drag ! diffusivity (m^2/sec) from drag mixing scheme
real, private, dimension(:,:,:), allocatable :: diff_wave ! diffusivity (m^2/sec) from wave mixing scheme
real, private, dimension(:,:,:), allocatable :: diff_leewave ! diffusivity (m^2/sec) from leewave mixing scheme
real, private, dimension(:,:), allocatable :: tmask_deep ! nonzero for points deeper than shelf_depth_cutoff
type(ocean_domain_type), pointer :: Dom => NULL()
type(ocean_grid_type), pointer :: Grd => NULL()
character(len=128) :: version='$$'
character (len=128) :: tagname = '$Name: tikal $'
public vert_mix_tidal_test
public ocean_vert_tidal_test_init
private vert_mix_wave
private vert_mix_drag_bgrid
private vert_mix_drag_cgrid
private vert_mix_drag_legacy
private compute_bvfreq
integer :: index_temp=-1
integer :: index_salt=-1
! for Bgrid or Cgrid
integer :: horz_grid
real :: p5rho0
real :: decay_scale_inv
real :: sqrt_cd
real :: von_karman_inv
real :: dtime
real :: roughness_kappa
real :: omega_earth2
logical :: module_is_initialized = .false.
! nml parameters
logical :: use_this_module = .false.
logical :: use_legacy_methods = .false.
logical :: debug_this_module = .false.
logical :: use_wave_dissipation = .false.
logical :: use_drag_dissipation = .false.
logical :: use_leewave_dissipation = .false.
logical :: read_roughness = .false.
logical :: read_wave_dissipation = .false.
logical :: read_leewave_dissipation = .false.
logical :: reading_roughness_amp = .false.
logical :: reading_roughness_length = .false.
logical :: read_tide_speed = .false.
logical :: wave_diffusivity_monotonic = .true.
logical :: tide_speed_data_on_t_grid = .true.
logical :: fixed_wave_dissipation = .false.
logical :: mixing_efficiency_n2depend = .false.
logical :: drag_dissipation_efold = .true.
logical :: smooth_bvfreq_bottom = .true.
logical :: drag_mask_deep = .true.
logical :: smooth_ri_drag_cgrid = .true.
logical :: smooth_rho_N2 = .true. ! for smoothing the rho_N2 field in vertical with 1-2-1
integer :: num_121_passes = 1 ! number of 1-2-1 passes
real :: drag_mask_deep_ratio = 0.1
real :: roughness_scale = 85e3 ! (metre)
real :: default_roughness_length = 25.0 ! (metre)
real :: default_tide_speed = .01 ! (m/s)
real :: shelf_depth_cutoff = -1000.0 ! (metre)
real :: decay_scale = 500.0 ! (metre)
real :: tidal_diss_efficiency = 0.33333 ! (dimensionless) from Simmons etal
real :: mixing_efficiency = 0.2 ! (dimensionless) from Osborne
real :: munk_anderson_p = 0.25 ! (dimensionless) from Munk and Anderson
real :: munk_anderson_sigma = 3.0 ! (dimensionless) from Munk and Anderson
real :: bottom_drag_cd = 2.4e-3 ! (dimensionless) bottom drag from Lee etal
real :: background_diffusivity = 0.1e-4 ! (m^2/sec)
real :: background_viscosity = 0.1e-4 ! (m^2/sec)
real :: max_wave_diffusivity = 5.0e-3 ! (m^2/sec)
real :: max_drag_diffusivity = 5.0e-3 ! (m^2/sec)
real :: drhodz_min = 1.e-10 ! (kg/m^4) minimum abs(drhodz) used to compute N^2
real :: speed_min = 5.e-3 ! (m/s) below which set a mask=0 for drag mixing diffusivity
real :: wave_energy_flux_max = 0.1 ! (W/m^2)
real :: drag_dissipation_tide_period = 43200. ! seconds
real :: vel_micom_smooth = 0.2 ! m/sec for smoothing
logical :: drag_dissipation_use_cdbot = .false. ! for using cdbot_array from ocean_bbc
logical :: repro_legacy_const_cdbot = .false. ! for reproduce legacy results with constant cdbot
namelist /ocean_vert_tidal_test_nml/ use_this_module, use_legacy_methods, debug_this_module, &
use_wave_dissipation, use_drag_dissipation, &
read_roughness, read_tide_speed, &
default_roughness_length, default_tide_speed, &
shelf_depth_cutoff, decay_scale, roughness_scale, &
tidal_diss_efficiency, mixing_efficiency, &
mixing_efficiency_n2depend, &
munk_anderson_p, munk_anderson_sigma, &
drag_dissipation_efold, drag_dissipation_tide_period, &
drag_mask_deep, drag_mask_deep_ratio, &
bottom_drag_cd, drhodz_min, speed_min, &
background_diffusivity, background_viscosity, &
max_wave_diffusivity, max_drag_diffusivity, &
smooth_bvfreq_bottom, vel_micom_smooth, &
smooth_rho_N2, num_121_passes, wave_diffusivity_monotonic, &
tide_speed_data_on_t_grid, &
reading_roughness_amp, reading_roughness_length, &
read_wave_dissipation, fixed_wave_dissipation, &
wave_energy_flux_max, &
use_leewave_dissipation, read_leewave_dissipation, &
drag_dissipation_use_cdbot, repro_legacy_const_cdbot
contains
!#######################################################################
! <SUBROUTINE NAME="ocean_vert_tidal_test_init">
!
! <DESCRIPTION>
! Initialization for the ocean_vert_tidal module.
! </DESCRIPTION>
subroutine ocean_vert_tidal_test_init(Grid, Domain, Time, T_prog, Velocity, Ocean_options, dtime_t, vert_mix_scheme, hor_grid)
type(ocean_grid_type), intent(in), target :: Grid
type(ocean_domain_type), intent(in), target :: Domain
type(ocean_time_type), intent(in) :: Time
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_velocity_type), intent(in) :: Velocity
type(ocean_options_type), intent(inout) :: Ocean_options
real, intent(in) :: dtime_t
character(len=10), intent(in) :: vert_mix_scheme
integer, intent(in) :: hor_grid
real :: active_cells, temporary
integer :: unit, io_status, ierr
integer :: i,j,n
integer :: roughness_has_been_read=0
integer :: stdoutunit,stdlogunit
stdoutunit=stdout();stdlogunit=stdlog()
if ( module_is_initialized ) then
call mpp_error(FATAL,&
'==>Error from ocean_vert_tidal_test_mod (ocean_vert_tidal_test_init) module already initialized')
endif
module_is_initialized = .TRUE.
call write_version_number( version, tagname )
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=ocean_vert_tidal_test_nml, iostat=io_status)
!ierr = check_nml_error(io_status,'ocean_vert_tidal_test_nml')
#else
unit = open_namelist_file()
read(unit, ocean_vert_tidal_test_nml,iostat=io_status)
! ierr = check_nml_error(io_status, 'ocean_vert_tidal_test_nml')
call close_file(unit)
#endif
write (stdoutunit,'(/)')
write (stdoutunit,ocean_vert_tidal_test_nml)
write (stdlogunit,ocean_vert_tidal_test_nml)
Dom => Domain
Grd => Grid
dtime = dtime_t
#ifndef MOM_STATIC_ARRAYS
call get_local_indices(Domain, isd, ied, jsd, jed, isc, iec, jsc, jec)
nk = Grid%nk
#endif
if(use_this_module) then
call mpp_error(NOTE, '==>Note: USING ocean_vert_tidal_test_mod')
else
call mpp_error(NOTE, '==>Note: NOT using ocean_vert_tidal_test_mod')
Ocean_options%tidal_wave_mix = 'Did NOT use tidal wave mixing option for vertical mixing.'
Ocean_options%tidal_drag_mix = 'Did NOT use tidal drag mixing option for vertical mixing.'
return
endif
decay_scale_inv = 1.0/decay_scale
p5rho0 = 0.5*rho0
sqrt_cd = sqrt(bottom_drag_cd)
von_karman_inv = 1.0/von_karman
roughness_kappa = 2.0*pi/roughness_scale
omega_earth2 = omega_earth**2
horz_grid = hor_grid
do n=1, size(T_prog(:))
if (T_prog(n)%name == 'temp') index_temp = n
if (T_prog(n)%name == 'salt') index_salt = n
enddo
! allocate arrays needed for buoyancy frequency
allocate (mix_efficiency(isd:ied,jsd:jed,nk))
allocate (bvfreq_bottom(isd:ied,jsd:jed))
allocate (bvfreq(isd:ied,jsd:jed,nk))
allocate (rho_N2(isd:ied,jsd:jed,nk))
allocate (drhodT(isd:ied,jsd:jed,nk))
allocate (drhodS(isd:ied,jsd:jed,nk))
allocate (diff_drag(isd:ied,jsd:jed,nk))
allocate (diff_wave(isd:ied,jsd:jed,nk))
allocate (diff_leewave(isd:ied,jsd:jed,nk))
allocate (tmask_deep(isd:ied,jsd:jed))
mix_efficiency = 0.0
bvfreq_bottom = 0.0
bvfreq = 0.0
rho_N2 = 0.0
drhodT = 0.0
drhodS = 0.0
diff_drag = 0.0
diff_wave = 0.0
diff_leewave = 0.0
tmask_deep(:,:) = Grd%tmask(:,:,1)
allocate (smooth_lap(isd:ied,jsd:jed))
allocate (wave_term(isd:ied,jsd:jed))
allocate (energy_flux(isd:ied,jsd:jed))
allocate (wave_dissipation(isd:ied,jsd:jed))
allocate (leewave_dissipation(isd:ied,jsd:jed))
allocate (roughness_length(isd:ied,jsd:jed))
allocate (roughness_amp(isd:ied,jsd:jed))
allocate (tide_speed_t(isd:ied,jsd:jed))
allocate (tide_speed_u(isd:ied,jsd:jed))
allocate (tide_speed_mask(isd:ied,jsd:jed))
allocate (tide_rescspeed_mask(isd:ied,jsd:jed))
allocate (tide_deepspeed_mask(isd:ied,jsd:jed))
allocate (rescaled_speed_u(isd:ied,jsd:jed))
allocate (rescaled_speed_t(isd:ied,jsd:jed))
allocate (efold_depth_r(isd:ied,jsd:jed))
smooth_lap(:,:) = Grd%tmask(:,:,1)*vel_micom_smooth*2.0*Grd%dxt(:,:)*Grd%dyt(:,:)/(Grd%dxt(:,:)+Grd%dyt(:,:))
roughness_length(:,:) = Grd%tmask(:,:,1)*default_roughness_length
roughness_amp(:,:) = sqrt(Grd%tmask(:,:,1)/roughness_kappa)
tide_speed_t(:,:) = Grd%tmask(:,:,1)*default_tide_speed
tide_speed_u(:,:) = Grd%umask(:,:,1)*default_tide_speed
tide_speed_mask(:,:) = 0.0
tide_rescspeed_mask(:,:) = 0.0
tide_deepspeed_mask(:,:) = 0.0
rescaled_speed_u(:,:) = 0.0
rescaled_speed_t(:,:) = 0.0
efold_depth_r(:,:) = 0.0
wave_term(:,:) = 0.0
energy_flux(:,:) = 0.0
wave_dissipation(:,:) = 0.0
leewave_dissipation(:,:) = 0.0
if(use_wave_dissipation) then
write (stdoutunit,'(a)') &
'Using Simmons etal scheme to compute dia-surface diffusivity and viscosity based on internal wave breaking.'
Ocean_options%tidal_wave_mix = 'Used tidal wave mixing option for vertical mixing.'
else
write(stdoutunit,'(a)') 'NOT using Simmons etal scheme for dia-surface diffusivity and viscosity.'
Ocean_options%tidal_wave_mix = 'Did NOT use tidal wave mixing option for vertical mixing.'
endif
if(use_drag_dissipation) then
write (stdoutunit,'(a)') &
'Using Lee etal scheme to compute dia-surface diffusivity and viscosity based on barotropic tide drag on bottom.'
Ocean_options%tidal_drag_mix = 'Used tidal drag mixing option for vertical mixing.'
if(vert_mix_scheme == 'kpp_mom4p0') then
write (stdoutunit,'(a)') &
'===>WARNING: Using kpp_mom4p0, where Lee etal scheme can be enabled. Be sure not to double count!!!'
endif
else
write(stdoutunit,'(a)') 'NOT using Lee etal scheme from ocean_vert_tidal_test_mod for dia-surface mixing.'
Ocean_options%tidal_drag_mix = 'Did NOT use tidal drag mixing option for vertical mixing.'
endif
if(use_leewave_dissipation) then
write (stdoutunit,'(a)') &
'Using prototype for Nikurashin scheme to compute dia-surface diff and visc from breaking leewaves.'
Ocean_options%leewave_mix = 'Using prototype for leewave mixing option for vertical mixing.'
else
write(stdoutunit,'(a)') 'NOT using Nikurashin scheme for dia-surface diffusivity and viscosity.'
Ocean_options%leewave_mix = 'Did NOT use prototype breaking leewave paramaterization of vertical mixing.'
endif
if(.not. use_drag_dissipation .and. .not. use_wave_dissipation) then
call mpp_error(WARNING, &
'==>ocean_vert_tidal_test: No dissipation mechanism is set to determine dia-surface mixing.')
endif
if(.not. use_wave_dissipation .and. use_leewave_dissipation) then
call mpp_error(WARNING, &
'==>ocean_vert_tidal_test: The prototype leewave mixing scheme must run with use_wave_dissipation=.true.')
endif
! read in topographic amplitude ("h" in "kappa*h^2" from Simmons etal 2004) on T-grid
if(read_roughness) then
if(reading_roughness_length) then
roughness_has_been_read=roughness_has_been_read+1
call read_data('INPUT/roughness_length.nc','roughness_length', roughness_length, Domain%domain2d)
write (stdoutunit,*) '==>ocean_vert_tidal_test_mod: Completed read of topographic roughness length on T-grid.'
call mpp_update_domains(roughness_length(:,:), Dom%domain2d)
roughness_amp(:,:) = sqrt(roughness_length(:,:)/roughness_kappa)
endif
if(reading_roughness_amp) then
roughness_has_been_read=roughness_has_been_read+1
call read_data('INPUT/roughness_amp.nc','roughness_amp', roughness_amp, Domain%domain2d)
write (stdoutunit,*) '==>ocean_vert_tidal_test_mod: Completed read of topographic roughness amplitude on T-grid.'
call mpp_update_domains(roughness_amp(:,:), Dom%domain2d)
roughness_length(:,:) = roughness_kappa*roughness_amp(:,:)*roughness_amp(:,:)
endif
if(roughness_has_been_read > 1) then
call mpp_error(FATAL, &
'==>ocean_vert_tidal_test_mod: Read in both roughness_amp & roughness_length. Check to be sure what you wish.')
endif
if(roughness_has_been_read==0) then
call mpp_error(FATAL, &
'==>ocean_vert_tidal_test_mod: To read roughness, reading_roughness_amp or reading_roughness_length must be true.')
endif
else
write(stdoutunit,'(a)') &
'==>Note: NOT reading topographic roughness_length for ocean_vert_tidal_test_mod.'
endif
if(read_wave_dissipation) then
call read_data('INPUT/wave_dissipation.nc','wave_dissipation', wave_dissipation, Domain%domain2d)
write (stdoutunit,*) '==>ocean_vert_tidal_test_mod: Completed read of wave dissipation (W/m^2) on T-grid.'
call mpp_update_domains(wave_dissipation(:,:), Dom%domain2d)
else
write(stdoutunit,'(a)') &
'==>Note: NOT reading wave dissipation for ocean_vert_tidal_test_mod.'
endif
if(read_leewave_dissipation) then
call read_data('INPUT/leewave_dissipation.nc','leewave_dissipation', leewave_dissipation, Domain%domain2d)
write (stdoutunit,*) '==>ocean_vert_tidal_test_mod: Completed read of leewave dissipation (W/m^2) on T-grid.'
call mpp_update_domains(leewave_dissipation(:,:), Dom%domain2d)
else
write(stdoutunit,'(a)') &
'==>Note: NOT reading leewave dissipation for ocean_vert_tidal_test_mod.'
endif
! read tidal speed (m/s) from a tide model, such as the
! Global Inverse Solution TPX06.0 created by OSU.
if(read_tide_speed) then
if(tide_speed_data_on_t_grid) then
call read_data('INPUT/tideamp.nc','tideamp', tide_speed_t, Domain%domain2d)
write (stdoutunit,*) '==>ocean_vert_tidal_test_mod: Completed read of tide_speed on T-grid.'
call mpp_update_domains(tide_speed_t(:,:), Dom%domain2d)
else
call read_data('INPUT/tideamp.nc','tideamp', tide_speed_u, Domain%domain2d)
write (stdoutunit,*) '==>ocean_vert_tidal_test_mod: Completed read of tide_speed on U-grid.'
call mpp_update_domains(tide_speed_u(:,:), Dom%domain2d)
endif
else
write(stdoutunit,'(a)') &
'==>Note: NOT reading tide_speed for ocean_vert_tidal_test_mod.'
call mpp_error(NOTE, &
'==>ocean_vert_tidal_test_mod: Setting tide_speed to default value.')
endif
! map tide speed onto U-cell by 4-point average
if(tide_speed_data_on_t_grid) then
do j=jsc,jec
do i=isc,iec
tide_speed_u(i,j) = onefourth*Grd%umask(i,j,1) &
*(tide_speed_t(i,j) + tide_speed_t(i+1,j) &
+tide_speed_t(i,j+1) + tide_speed_t(i+1,j+1))
enddo
enddo
call mpp_update_domains(tide_speed_u(:,:), Dom%domain2d)
endif
! note for the bottom drag coefficient
if(drag_dissipation_use_cdbot) then
write(stdoutunit,'(a)') &
'==>Note from ocean_vert_tidal_test: using cdbot_array(i,j) for tide drag_dissipation scheme.'
else !if(drag_dissipation_use_cdbot)
write(stdoutunit,'(a)') &
'==>Note from ocean_vert_tidal_test: using constant bottom drag coefficient for tide drag_dissipation scheme.'
do j=jsd,jed
do i=isd,ied
rescaled_speed_u(i,j) = sqrt_cd*von_karman_inv*tide_speed_u(i,j)
rescaled_speed_t(i,j) = sqrt_cd*von_karman_inv*tide_speed_t(i,j)
tide_rescspeed_mask(i,j) = 0.0
if(rescaled_speed_u(i,j) > speed_min) then
tide_rescspeed_mask(i,j) = 1.0
endif
enddo
enddo
call mpp_update_domains(tide_rescspeed_mask(:,:), Dom%domain2d)
! compute efolding depth scale for use in Lee etal scheme.
! efold depth set as rescaled_speed/(radial tide frequency).
! Choose default radial tide frequency as 2pi/12hrs for semi-diurnal tide.
! let this efolding hold whether using Bgrid or Cgrid.
wrk1_2d(:,:) = 0.0
do j=jsc,jec
do i=isc,iec
active_cells = Grd%umask(i,j,1) + Grd%umask(i-1,j,1) &
+ Grd%umask(i,j-1,1) + Grd%umask(i-1,j-1,1) + epsln
temporary = (rescaled_speed_u(i,j) + rescaled_speed_u(i-1,j) + &
rescaled_speed_u(i,j-1) + rescaled_speed_u(i-1,j-1))/active_cells
wrk1_2d(i,j) = Grd%tmask(i,j,1)*temporary*drag_dissipation_tide_period/(2.0*pi)
efold_depth_r(i,j) = Grd%tmask(i,j,1)/(wrk1_2d(i,j) + epsln)
enddo
enddo
endif !if(drag_dissipation_use_cdbot)
! mask out the deep ocean regions for the drag scheme.
if(drag_mask_deep .and. .not. use_legacy_methods) then
! only to reproduce the previous results with const cdbot
if (repro_legacy_const_cdbot .and. .not. drag_dissipation_use_cdbot) then
do j=jsc,jec
do i=isc,iec
if(Grd%tmask(i,j,1) == 1.0) then
temporary = wrk1_2d(i,j)/(epsln+Grd%ht(i,j))
if(temporary > drag_mask_deep_ratio) then
tide_deepspeed_mask(i,j) = 1.0
else
tide_deepspeed_mask(i,j) = 0.0
endif
endif
enddo
enddo
else
do j=jsc,jec
do i=isc,iec
if(Grd%tmask(i,j,1) == 1.0) then
if(Grd%ht(i,j) <= shelf_depth_cutoff) tide_deepspeed_mask(i,j) = 1.0
endif
enddo
enddo
endif
else
tide_deepspeed_mask(:,:) = 1.0
endif
call mpp_update_domains(tide_deepspeed_mask(:,:), Dom%domain2d)
if(use_legacy_methods) then
if(drag_dissipation_use_cdbot) then
write(stdoutunit,'(a)') &
'==>Note from ocean_vert_tidal_test: using cdbot_array(i,j) for tide drag_dissipation scheme.'
do j=jsd,jed
do i=isd,ied
rescaled_speed_u(i,j) = sqrt(Velocity%cdbot_array(i,j))*von_karman_inv*tide_speed_u(i,j)
rescaled_speed_t(i,j) = sqrt(Velocity%cdbot_array(i,j))*von_karman_inv*tide_speed_t(i,j)
tide_speed_mask(i,j) = 0.0
if(rescaled_speed_u(i,j) > speed_min) then
tide_speed_mask(i,j) = 1.0
endif
enddo
enddo
else
write(stdoutunit,'(a)') &
'==>Note from ocean_vert_tidal_test: using constant bottom drag coefficient for tide drag_dissipation scheme.'
do j=jsd,jed
do i=isd,ied
rescaled_speed_u(i,j) = sqrt_cd*von_karman_inv*tide_speed_u(i,j)
rescaled_speed_t(i,j) = sqrt_cd*von_karman_inv*tide_speed_t(i,j)
tide_speed_mask(i,j) = 0.0
if(rescaled_speed_u(i,j) > speed_min) then
tide_speed_mask(i,j) = 1.0
endif
enddo
enddo
endif !if(drag_dissipation_use_cdbot)
endif !if(use_legacy_methods)
! compute static piece of the energy flux on T-grid for wave diffusivity
do j=jsd,jed
do i=isd,ied
wave_term(i,j) = Grd%tmask(i,j,1)*p5rho0*roughness_length(i,j)*tide_speed_t(i,j)**2
enddo
enddo
! diagnostics
id_tide_diff_cbt_back = -1
id_tide_diff_cbt_back = register_static_field ('ocean_model', 'tide_diff_cbt_back', &
Grid%tracer_axes(1:3), 'static background diff_cbt set in tide module',&
'm^2/s',missing_value=missing_value, range=(/-10.0,1e6/))
if (id_tide_diff_cbt_back > 0) then
wrk1(:,:,:) = background_diffusivity*Grid%tmask(:,:,:)
used = send_data (id_tide_diff_cbt_back, wrk1(isc:iec,jsc:jec,:), &
Time%model_time, rmask=Grid%tmask(isc:iec,jsc:jec,:))
endif
id_tide_visc_cbu_back = -1
id_tide_visc_cbu_back = register_static_field ('ocean_model', 'tide_visc_cbu_back', &
Grid%vel_axes_wu(1:3), 'static background visc_cbu set in tide module',&
'm^2/s',missing_value=missing_value, range=(/-10.0,1e6/))
if (id_tide_visc_cbu_back > 0) then
wrk1(:,:,:) = background_viscosity*Grid%umask(:,:,:)
used = send_data (id_tide_visc_cbu_back, wrk1(isc:iec,jsc:jec,:), &
Time%model_time, rmask=Grid%umask(isc:iec,jsc:jec,:))
endif
! e-folding depth for drag dissipation scheme
id_drag_diss_efold = register_static_field ('ocean_model', 'drag_diss_efold',&
Grid%tracer_axes(1:2), 'e-folding depth for drag dissipation scheme', &
'm', missing_value=missing_value, range=(/-1.0,1e10/))
id_tide_rescspeed_mask = register_diag_field ('ocean_model', 'tide_rescspeed_mask', &
Grid%vel_axes_uv(1:2), Time%model_time, 'mask based on tide_speed_drag for barotropic drag mixing', &
'dimensionless', missing_value=missing_value, range=(/-1e1,1e1/))
id_tide_deepspeed_mask = register_diag_field ('ocean_model', 'tide_deepspeed_mask', &
Grid%vel_axes_uv(1:2), Time%model_time, 'mask based on tide_speed_drag for deep ocean region', &
'dimensionless', missing_value=missing_value, range=(/-1e1,1e1/))
if(.not. drag_dissipation_use_cdbot) then
if (id_tide_rescspeed_mask > 0) then
used = send_data (id_tide_rescspeed_mask, tide_rescspeed_mask(:,:), &
Time%model_time, rmask=Grd%umask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_drag_diss_efold > 0) then
used = send_data (id_drag_diss_efold, wrk1_2d(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
endif !if(drag_dissipation_use_cdbot)
if (id_tide_deepspeed_mask > 0) then
used = send_data (id_tide_deepspeed_mask, tide_deepspeed_mask(:,:), &
Time%model_time, rmask=Grd%umask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
! static input of leewave breaking from Nikurashin
id_leewave_dissipation = register_static_field ('ocean_model', 'leewave_dissipation',&
Grid%tracer_axes(1:2), 'specified energy flux input from breaking leewaves', &
'W/m^2', missing_value=missing_value, range=(/-1e1,1e15/))
if (id_leewave_dissipation > 0) then
used = send_data (id_leewave_dissipation, leewave_dissipation(:,:),&
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
! tide speed for breaking internal wave dissipation scheme
id_tide_speed_wave = register_static_field ('ocean_model', 'tide_speed_wave', &
Grid%tracer_axes(1:2), 'tide speed from tide model for breaking internal wave mixing scheme',&
'm/s', missing_value=missing_value, range=(/-1e1,1e9/))
if (id_tide_speed_wave > 0) then
used = send_data (id_tide_speed_wave, tide_speed_t(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
! tide speed scale for barotropic bottom drag dissipation scheme
id_tide_speed_drag = register_static_field ('ocean_model', 'tide_speed_drag', &
Grid%vel_axes_uv(1:2), 'tide speed from tide model for barotropic drag mixing scheme',&
'm/s', missing_value=missing_value, range=(/-1e1,1e9/))
if (id_tide_speed_drag > 0) then
used = send_data (id_tide_speed_drag, rescaled_speed_u(:,:), &
Time%model_time, rmask=Grd%umask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
id_roughness_amp = register_static_field ('ocean_model', 'roughness_amp', &
Grid%tracer_axes(1:2), 'roughness amplitude for breaking internal wave mixing scheme',&
'metre', missing_value=missing_value, range=(/-1e1,1e9/))
if (id_roughness_amp > 0) then
used = send_data (id_roughness_amp, roughness_amp(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
! static roughness length
id_roughness_length = register_static_field ('ocean_model', 'roughness_length', &
Grid%tracer_axes(1:2), 'roughness length for breaking internal wave mixing scheme',&
'metre', missing_value=missing_value, range=(/-1e1,1e9/))
if (id_roughness_length > 0) then
used = send_data (id_roughness_length, roughness_length(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
id_roughness_klevel = register_diag_field ('ocean_model', 'roughness_klevel', &
Grid%tracer_axes(1:2), Time%model_time, &
'klevel at top of the bottom layer defined by roughness amplitude for internal tide mixing',&
'dimensionless', missing_value=missing_value, range=(/-1.0,1.e10/))
id_energy_flux = register_diag_field ('ocean_model', 'energy_flux', &
Grid%tracer_axes(1:2), Time%model_time, &
'energy flux out of barotropic tides for use w/ internal tide mixing',&
'W/m^2', missing_value=missing_value, range=(/-1e9,1e9/))
id_power_waves = register_diag_field ('ocean_model', 'power_waves', &
Grid%tracer_axes(1:2), Time%model_time, 'power from barotropic tides to internal tides', &
'Watt', missing_value=missing_value, range=(/-1e15,1e15/))
id_power_diss_leewave = register_diag_field ('ocean_model', 'power_diss_leewave', &
Grid%tracer_axes(1:3), Time%model_time, 'power dissipation from mixing due to breaking leewaves',&
'W/m^2', missing_value=missing_value, range=(/-1e15,1e15/))
id_power_diss_wave = register_diag_field ('ocean_model', 'power_diss_wave', &
Grid%tracer_axes(1:3), Time%model_time, 'power dissipation from internal wave induced mixing', &
'W/m^2', missing_value=missing_value, range=(/-1e15,1e15/))
id_power_diss_drag = register_diag_field ('ocean_model', 'power_diss_drag', &
Grid%tracer_axes(1:3), Time%model_time, 'power dissipation from barotropic tide drag', &
'W/m^2', missing_value=missing_value, range=(/-1e15,1e15/))
id_power_diss_tides = register_diag_field ('ocean_model', 'power_diss_tides',&
Grid%tracer_axes(1:3), Time%model_time, &
'power dissipation from barotropic tide drag and baroclinic wave drag', &
'W/m^2', missing_value=missing_value, range=(/-1e15,1e15/), &
standard_name='tendency_of_ocean_potential_energy_content_due_to_tides')
id_mix_efficiency = register_diag_field ('ocean_model', 'mix_efficiency', &
Grid%tracer_axes(1:3), Time%model_time, 'efficiency of internal wave dissipation going to mix tracer',&
'dimensionless', missing_value=missing_value, range=(/-1e5,1e5/))
id_bvfreq_bottom = register_diag_field ('ocean_model', 'bvfreq_bottom', &
Grid%tracer_axes(1:2), Time%model_time, 'absolute Brunt-Vaisala freq at ocean bottom', &
's^-1', missing_value=missing_value, range=(/-1e1,1e9/))
id_bvfreq = register_diag_field ('ocean_model', 'bvfreq', &
Grid%tracer_axes(1:3), Time%model_time, 'absolute Brunt-Vaisala freq at tracer cell bottom', &
's^-1', missing_value=missing_value, range=(/-1e1,1e9/))
id_rinumber_drag = register_diag_field ('ocean_model', 'rinumber_drag', &
Grid%tracer_axes(1:3), Time%model_time, 'Richardson number from Lee etal', &
'dimensionless', missing_value=missing_value, range=(/-1e1,1e18/))
id_diff_cbt_wave = register_diag_field ('ocean_model', 'diff_cbt_wave', &
Grid%tracer_axes(1:3), Time%model_time, 'diffusivity from breaking internal wave dissipation', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_diff_cbt_leewave = register_diag_field ('ocean_model', 'diff_cbt_leewave', &
Grid%tracer_axes(1:3), Time%model_time, 'diffusivity from breaking leewaves', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_diff_cbt_drag = register_diag_field ('ocean_model', 'diff_cbt_drag', &
Grid%tracer_axes(1:3), Time%model_time, 'diffusivity from drag of barotropic tides on bottom', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_visc_cbt_wave = register_diag_field ('ocean_model', 'visc_cbt_wave', &
Grid%tracer_axes(1:3), Time%model_time, 'viscosity from breaking internal wave dissipation', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_visc_cbt_leewave = register_diag_field ('ocean_model', 'visc_cbt_leewave', &
Grid%tracer_axes(1:3), Time%model_time, 'viscosity from breaking leewaves', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_visc_cbt_drag = register_diag_field ('ocean_model', 'visc_cbt_drag', &
Grid%tracer_axes(1:3), Time%model_time, 'viscosity from drag of barotropic tides on bottom', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_visc_cbu_wave = register_diag_field ('ocean_model', 'visc_cbu_wave', &
Grid%vel_axes_uv(1:3), Time%model_time, 'viscosity from breaking internal wave dissipation', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_visc_cbu_leewave = register_diag_field ('ocean_model', 'visc_cbu_leewave', &
Grid%vel_axes_uv(1:3), Time%model_time, 'viscosity from breaking leewaves ', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_visc_cbu_drag = register_diag_field ('ocean_model', 'visc_cbu_drag', &
Grid%vel_axes_uv(1:3), Time%model_time, 'viscosity from drag of barotropic tides on bottom', &
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/))
id_diff_cbt_tides = register_diag_field ('ocean_model', 'diff_cbt_tides', &
Grid%tracer_axes(1:3), Time%model_time, 'diffusivity from drag of barotropic tides on bottom + wave drag',&
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/), &
standard_name='ocean_vertical_tracer_diffusivity_due_to_tides')
id_visc_cbt_tides = register_diag_field ('ocean_model', 'visc_cbt_tides', &
Grid%tracer_axes(1:3), Time%model_time, 'viscosity from drag of barotropic tides on bottom + wave drag',&
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/), &
standard_name='ocean_vertical_tracer_diffusivity_due_to_tides')
id_visc_cbu_tides = register_diag_field ('ocean_model', 'visc_cbu_tides', &
Grid%vel_axes_uv(1:3), Time%model_time, 'viscosity from drag of barotropic tides on bottom + wave drag',&
'm^2/sec', missing_value=missing_value, range=(/-1.0,1e6/), &
standard_name='ocean_vertical_momentum_diffusivity_due_to_tides')
end subroutine ocean_vert_tidal_test_init
! </SUBROUTINE> NAME="ocean_vert_tidal_test_init"
!#######################################################################
! <SUBROUTINE NAME="vert_mix_tidal_test">
!
! <DESCRIPTION>
! This subroutine computes vertical tracer diffusivity and viscosity
! based on one or both of the following dissipation mechanisms:
!
! 1. internal wave breaking as parameterized by Simmons etal.
!
! 2. barotropic tides feeling the bottom drag, as parameterized by
! Lee etal.
!
! </DESCRIPTION>
!
subroutine vert_mix_tidal_test(Time, Thickness, Velocity, T_prog, Dens, diff_cbt, visc_cbu, visc_cbt, &
diff_cbt_wave, diff_cbt_leewave, diff_cbt_drag)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_velocity_type), intent(in) :: Velocity
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_density_type), intent(in) :: Dens
real, dimension(isd:,jsd:,:,:), intent(inout) :: diff_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbu
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_wave
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_leewave
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_drag
integer :: i, j, k, kp1
real :: tmp
if(.not. use_this_module) return
if(use_legacy_methods) then
call compute_bvfreq_legacy(Time, Thickness, T_prog, Dens)
if(use_wave_dissipation) then
call vert_mix_wave_legacy(Time, Thickness, diff_cbt, visc_cbu, visc_cbt, diff_cbt_wave)
endif
if(use_drag_dissipation) then
call vert_mix_drag_legacy(Time, Thickness, diff_cbt, visc_cbu, visc_cbt, diff_cbt_drag)
endif
diff_cbt_leewave(:,:,:) = 0.0
diff_leewave(:,:,:) = 0.0
else
call compute_bvfreq(Time, Thickness, T_prog, Dens)
if(use_wave_dissipation) then
call vert_mix_wave(Time, Thickness, Dens, diff_cbt, visc_cbu, visc_cbt, diff_cbt_wave, diff_cbt_leewave)
endif
if(use_drag_dissipation .and. horz_grid == MOM_BGRID) then
call vert_mix_drag_bgrid(Time, Thickness, Velocity, diff_cbt, visc_cbu, visc_cbt, diff_cbt_drag)
endif
if(use_drag_dissipation .and. horz_grid == MOM_CGRID) then
call vert_mix_drag_cgrid(Time, Thickness, Velocity, diff_cbt, visc_cbu, visc_cbt, diff_cbt_drag)
endif
endif
! add the background diffusivity and viscosity
do k=1,nk
kp1 = min(k+1,nk)
do j=jsc,jec
do i=isc,iec
diff_cbt(i,j,k,1) = Grd%tmask(i,j,kp1)*(diff_cbt(i,j,k,1) + background_diffusivity)
diff_cbt(i,j,k,2) = Grd%tmask(i,j,kp1)*(diff_cbt(i,j,k,2) + background_diffusivity)
visc_cbt(i,j,k) = Grd%tmask(i,j,kp1)*(visc_cbt(i,j,k) + background_viscosity)
visc_cbu(i,j,k) = Grd%umask(i,j,kp1)*(visc_cbu(i,j,k) + background_viscosity)
enddo
enddo
enddo
! compute power dissipated by mixing against stratification
if(id_power_diss_wave > 0 .or. id_power_diss_drag > 0 .or. &
id_power_diss_tides > 0 .or. id_power_diss_leewave > 0 ) then
wrk1(:,:,:) = 0.0
wrk2(:,:,:) = 0.0
wrk3(:,:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
tmp = Thickness%dzt(i,j,k)*rho_N2(i,j,k)*Grd%tmask(i,j,k)
wrk1(i,j,k) = tmp*diff_wave(i,j,k)
wrk2(i,j,k) = tmp*diff_drag(i,j,k)
wrk3(i,j,k) = tmp*diff_leewave(i,j,k)
enddo
enddo
enddo
if (id_power_diss_wave > 0) then
used = send_data (id_power_diss_wave, wrk1(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_power_diss_drag > 0) then
used = send_data (id_power_diss_drag, wrk2(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_power_diss_leewave > 0) then
used = send_data (id_power_diss_leewave, wrk3(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_power_diss_tides > 0) then
used = send_data (id_power_diss_tides, wrk1(:,:,:)+wrk2(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
endif
if (id_diff_cbt_tides > 0) then
used = send_data (id_diff_cbt_tides, diff_cbt_wave(:,:,:)+diff_cbt_drag(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
! recall unit Prandtl number
if (id_visc_cbt_tides > 0) then
used = send_data (id_visc_cbt_tides, diff_cbt_wave(:,:,:)+diff_cbt_drag(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbu_tides > 0) then
wrk1=0.0
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
wrk1(i,j,k) = Grd%umask(i,j,kp1)*onefourth &
*(diff_cbt_wave(i,j,k) +diff_cbt_wave(i+1,j,k) &
+diff_cbt_wave(i,j+1,k)+diff_cbt_wave(i+1,j+1,k)&
+diff_cbt_drag(i,j,k) +diff_cbt_drag(i+1,j,k) &
+diff_cbt_drag(i,j+1,k)+diff_cbt_drag(i+1,j+1,k))
enddo
enddo
enddo
used = send_data (id_visc_cbu_tides, wrk1(:,:,:), &
Time%model_time, rmask=Grd%umask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
end subroutine vert_mix_tidal_test
! </SUBROUTINE> NAME="vert_mix_tidal_test"
!#######################################################################
! <SUBROUTINE NAME="compute_bvfreq">
!
! <DESCRIPTION>
! This subroutine computes the absolute value of rho*N^2 and abs of
! N^2, with N^2 the squared Brunt-Vaisala (or buoyancy) frequency.
!
! </DESCRIPTION>
!
subroutine compute_bvfreq(Time, Thickness, T_prog, Dens)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_density_type), intent(in) :: Dens
real :: rho_inv, drhodz, bottom
real :: tmp, rho_N2_prev, rho_tmp
integer :: i, j, k, m, kp1, kbot
integer :: tau
real, dimension(isd:ied,jsd:jed) :: roughness_klevel
tau = Time%tau
wrk1(:,:,:) = 0.0
wrk2(:,:,:) = 0.0
bvfreq_bottom(:,:) = 0.0
! absolute(rho*N^2) computed from ocean_density module calculation.
! use the value at T-cell centre as this produces a smoother and
! better behaved bvfreq near the bottom, than does drhodz_wt.
do k=1,nk
do j=jsd,jed
do i=isd,ied
rho_N2(i,j,k) = max(0.0,-grav*Dens%drhodz_zt(i,j,k)*Grd%tmask(i,j,k))
enddo
enddo
enddo
! smooth rho_N2 in the vertical using a 1-2-1 filter
if (smooth_rho_N2) then
do m=1,num_121_passes
do j=jsd,jed
do i=isd,ied
rho_N2_prev = onefourth*rho_N2(i,j,1)
kbot=Grd%kmt(i,j)
if (kbot>3) then
do k=2,kbot-2
tmp = rho_N2(i,j,k)
rho_N2(i,j,k) = rho_N2_prev + onehalf*rho_N2(i,j,k) + onefourth*rho_N2(i,j,k+1)
rho_N2_prev = onefourth*tmp
enddo
endif
enddo
enddo
enddo
endif
! compute absolute value of buoyancy frequency,
! using rho0r as an approximation to 1/rho.
do k=1,nk
do j=jsd,jed
do i=isd,ied
bvfreq(i,j,k) = sqrt(rho0r*rho_N2(i,j,k))
enddo
enddo
enddo
! determine k-level at top of the bottom roughness boundary layer
wrk1_2d(:,:) = 0.0
do j=jsd,jed
do i=isd,ied
kbot = Grd%kmt(i,j)
roughness_klevel(:,:) = kbot
if(kbot > 1) then
bottom = Thickness%depth_zwt(i,j,kbot)
kloop: do k=kbot,1,-1
tmp = Thickness%depth_zwt(i,j,k) + roughness_amp(i,j)
if(tmp <= bottom) then
wrk1_2d(i,j) = k
roughness_klevel(i,j) = k
exit kloop
endif
enddo kloop
endif
enddo
enddo
! set bvfreq in bottom equal to value at kmt-1
do j=jsd,jed
do i=isd,ied
bvfreq_bottom(i,j) = 0.0
if(Grd%kmt(i,j) > 1) then
kbot=Grd%kmt(i,j)-1
bvfreq_bottom(i,j) = bvfreq(i,j,kbot)
endif
enddo
enddo
! horizontal laplacian smoothing on the bottom bvfreq
if(smooth_bvfreq_bottom) then
bvfreq_bottom(:,:) = bvfreq_bottom(:,:) + dtime*LAP_T(bvfreq_bottom(:,:),smooth_lap(:,:))
call mpp_update_domains(bvfreq_bottom(:,:), Dom%domain2d)
endif
! diagnostics
if (id_roughness_klevel > 0) then
used = send_data (id_roughness_klevel, wrk1_2d(:,:),&
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_bvfreq_bottom > 0) then
used = send_data (id_bvfreq_bottom, bvfreq_bottom(:,:),&
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_bvfreq > 0) then
used = send_data (id_bvfreq, bvfreq(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
end subroutine compute_bvfreq
! </SUBROUTINE> NAME="compute_bvfreq"
!#######################################################################
! <SUBROUTINE NAME="vert_mix_wave">
!
! <DESCRIPTION>
! This subroutine computes dia-surface tracer diffusivity based on the
! methods of Simmons et al., which consider dissipation from breaking
! internal gravity waves and their conversion into local dia-surface
! mixing, which is parameterized as diffusion.
!
! Also compute a prototype parameterization of mixing due to
! breaking leewaves from Nikurashin.
!
! We assume a unit Prandtl number.
!
! Note that if umask(i,j,k) is 1.0, then so is
! tmask(i,j,k), tmask(i+1,j,k), tmask(i,j+1,k), and tmask(i+1,j+1,k).
! So there is no need to compute the "active_cells" when doing the
! space average to go from t-cell to u-cell to compute visc_cbu.
!
! </DESCRIPTION>
!
subroutine vert_mix_wave(Time, Thickness, Dens, diff_cbt, visc_cbu, visc_cbt, diff_cbt_wave, diff_cbt_leewave)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_density_type), intent(in) :: Dens
real, dimension(isd:,jsd:,:,:), intent(inout) :: diff_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbu
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_wave
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_leewave
integer :: i, j, k, kbot, kp1, tau
real :: deposition, factor, tmp, rho_tmp
tau = Time%tau
diff_wave(:,:,:) = 0.0 ! diffusivity from wave scheme
diff_leewave(:,:,:) = 0.0 ! diffusivity from leewave scheme
wrk1(:,:,:) = 0.0 ! viscosity from wave scheme
wrk2(:,:,:) = 0.0 ! mix_efficiency / rho_N2
! compute mask for regions that are deemed too shallow for this scheme
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
tmask_deep(i,j) = 0.0
if(kbot > 1) then
if(Thickness%depth_zwt(i,j,kbot) > shelf_depth_cutoff) tmask_deep(i,j) = 1.0
endif
enddo
enddo
! energy flux array (W/m2) (Simmons etal equation (1))
if(fixed_wave_dissipation) then
do j=jsd,jed
do i=isd,ied
energy_flux(i,j) = min(wave_energy_flux_max, wave_dissipation(i,j)*tmask_deep(i,j))
enddo
enddo
else
do j=jsd,jed
do i=isd,ied
energy_flux(i,j) = min(wave_energy_flux_max, wave_term(i,j)*bvfreq_bottom(i,j)*tmask_deep(i,j))
enddo
enddo
endif
! compute mixing efficiency function
if(mixing_efficiency_n2depend) then
do k=1,nk
do j=jsd,jed
do i=isd,ied
rho_tmp = Dens%rho(i,j,k,tau) + epsln
mix_efficiency(i,j,k) = mixing_efficiency*Grd%tmask(i,j,k) &
*rho_N2(i,j,k)/(rho_N2(i,j,k) + rho_tmp*omega_earth2)
wrk2(i,j,k) = mixing_efficiency*Grd%tmask(i,j,k) &
/(rho_N2(i,j,k) + rho_tmp*omega_earth2)
enddo
enddo
enddo
else
do k=1,nk
do j=jsd,jed
do i=isd,ied
mix_efficiency(i,j,k) = mixing_efficiency*Grd%tmask(i,j,k)
wrk2(i,j,k) = mixing_efficiency*Grd%tmask(i,j,k) &
/(rho_N2(i,j,k) + epsln)
enddo
enddo
enddo
endif
! diffusivity calculation (Simmons etal equation (3))
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
if(kbot > 1) then
! normalization of vertical structure function.
! Ensure it integrates to unity on the discrete grid.
! "factor" approx decay_scale_inv/(exp[(H+eta)*decay_scale_inv]-1.0)
factor = 0.0
do k=1,kbot-1
factor = factor + Thickness%dzt(i,j,k)*exp(decay_scale_inv*Thickness%depth_zwt(i,j,k))
enddo
factor = 1.0/factor
do k=1,kbot-1
deposition = factor*exp(decay_scale_inv*Thickness%depth_zwt(i,j,k))
tmp = Grd%tmask(i,j,k+1)*wrk2(i,j,k)*tidal_diss_efficiency*deposition
diff_wave(i,j,k) = tmp*energy_flux(i,j)
diff_leewave(i,j,k) = tmp*leewave_dissipation(i,j)
diff_wave(i,j,k) = min(diff_wave(i,j,k),max_wave_diffusivity)
diff_leewave(i,j,k) = min(diff_leewave(i,j,k),max_wave_diffusivity)
enddo
endif
enddo
enddo
! ensure diffusivity monotonically decreases as move upward in column.
! recall that diff_wave(i,j,k) is the diffusivity at the bottom of cell-k,
! where diff_wave(i,j,kbot)=0.0 by definition. This prompts the kbot-2,1,-1
! loop limits.
if(wave_diffusivity_monotonic) then
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
if(kbot > 1) then
do k=kbot-2,1,-1
diff_wave(i,j,k) = min(diff_wave(i,j,k),diff_wave(i,j,k+1))
diff_leewave(i,j,k) = min(diff_leewave(i,j,k),diff_leewave(i,j,k+1))
enddo
endif
enddo
enddo
endif
! add wave induced diffusivity and viscosity to diff_cbt and visc_cbu
wrk1(:,:,:) = 0.0
wrk2(:,:,:) = 0.0
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_cbt_wave(i,j,k) = diff_wave(i,j,k)
diff_cbt_leewave(i,j,k) = diff_leewave(i,j,k)
diff_cbt(i,j,k,1) = diff_cbt(i,j,k,1) + diff_wave(i,j,k) + diff_leewave(i,j,k)
diff_cbt(i,j,k,2) = diff_cbt(i,j,k,2) + diff_wave(i,j,k) + diff_leewave(i,j,k)
visc_cbt(i,j,k) = visc_cbt(i,j,k) + diff_wave(i,j,k) + diff_leewave(i,j,k)
wrk1(i,j,k) = Grd%umask(i,j,kp1)*onefourth &
*(diff_wave(i,j,k) +diff_wave(i+1,j,k) &
+diff_wave(i,j+1,k) +diff_wave(i+1,j+1,k))
wrk2(i,j,k) = Grd%umask(i,j,kp1)*onefourth &
*(diff_leewave(i,j,k) +diff_leewave(i+1,j,k) &
+diff_leewave(i,j+1,k)+diff_leewave(i+1,j+1,k))
visc_cbu(i,j,k) = visc_cbu(i,j,k) + wrk1(i,j,k) + wrk2(i,j,k)
enddo
enddo
enddo
! send some diagnostics
if (id_mix_efficiency > 0) then
used = send_data (id_mix_efficiency, mix_efficiency(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_energy_flux > 0) then
used = send_data (id_energy_flux, energy_flux(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_power_waves > 0) then
used = send_data (id_power_waves, Grd%dat(:,:)*energy_flux(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_diff_cbt_wave > 0) then
used = send_data (id_diff_cbt_wave, diff_wave(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_diff_cbt_leewave > 0) then
used = send_data (id_diff_cbt_leewave, diff_leewave(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbt_wave > 0) then
used = send_data (id_visc_cbt_wave, diff_wave(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbt_leewave > 0) then
used = send_data (id_visc_cbt_leewave, diff_leewave(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbu_wave > 0) then
used = send_data (id_visc_cbu_wave, wrk1(:,:,:), &
Time%model_time, rmask=Grd%umask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbu_leewave > 0) then
used = send_data (id_visc_cbu_leewave, wrk2(:,:,:), &
Time%model_time, rmask=Grd%umask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
end subroutine vert_mix_wave
! </SUBROUTINE> NAME="vert_mix_wave"
!#######################################################################
! <SUBROUTINE NAME="vert_mix_drag_bgrid">
!
! <DESCRIPTION>
! This subroutine computes dia-surface tracer diffusivity based on the
! methods of Lee etal., which consider the dissipation from barotropic tides
! rubbing against the ocean bottom.
!
! We assume B-grid layout for the velocity
!
! We assume a unit Prandtl number, so compute the viscosity as a four-point
! average of the diffusivity.
!
! We perform various averages here in order to smooth Richardson number.
!
! 1. compute Richardson number on U-cell by averaging bvfreq from T-cell
! 2. average U-cell Richardson number to then get T-cell diffusivity
! 3. average T-cell diffusivity to get U-cell viscosity.
!
! Note that if umask(i,j,k)==1.0, then so is tmask(i,j,k), tmask(i+1,j,k),
! tmask(i,j+1,k), and tmask(i+1,j+1,k). So there is no need to compute
! active_cells when averaging from T-cell to U-cell.
!
! </DESCRIPTION>
!
subroutine vert_mix_drag_bgrid(Time, Thickness, Velocity, diff_cbt, visc_cbu, visc_cbt, diff_cbt_drag)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_velocity_type), intent(in) :: Velocity
real, dimension(isd:,jsd:,:,:), intent(inout) :: diff_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbu
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_drag
integer :: i, j, k, kbot, kp1
real :: height, bottom, efold
real :: bvfreq_u, speedr, active_cells, temporary
integer :: stdoutunit,stdlogunit
stdoutunit=stdout();stdlogunit=stdlog()
wrk1(:,:,:) =0.0 ! Richardson number on U-cell
wrk2(:,:,:) =0.0 ! Richardson number on T-cell
wrk3(:,:,:) =0.0 ! viscosity from drag scheme
diff_drag(:,:,:) =0.0 ! diffusivity from drag scheme
! speed scale for tides rubbing against bottom
! (defined following eq. (3) in Lee etal)
if(drag_dissipation_use_cdbot) then
do j=jsd,jed
do i=isd,ied
rescaled_speed_u(i,j) = sqrt(Velocity%cdbot_array(i,j))*von_karman_inv*tide_speed_u(i,j)
rescaled_speed_t(i,j) = sqrt(Velocity%cdbot_array(i,j))*von_karman_inv*tide_speed_t(i,j)
tide_rescspeed_mask(i,j) = 0.0
if(rescaled_speed_u(i,j) > speed_min) then
tide_rescspeed_mask(i,j) = 1.0
endif
enddo
enddo
! compute efolding depth scale for use in Lee etal scheme.
! efold depth set as rescaled_speed/(radial tide frequency).
! Choose default radial tide frequency as 2pi/12hrs for semi-diurnal tide.
! let this efolding hold whether using Bgrid or Cgrid.
wrk1_2d(:,:) = 0.0
do j=jsc,jec
do i=isc,iec
active_cells = Grd%umask(i,j,1) + Grd%umask(i-1,j,1) &
+ Grd%umask(i,j-1,1) + Grd%umask(i-1,j-1,1) + epsln
temporary = (rescaled_speed_u(i,j) + rescaled_speed_u(i-1,j) + &
rescaled_speed_u(i,j-1) + rescaled_speed_u(i-1,j-1))/active_cells
wrk1_2d(i,j) = Grd%tmask(i,j,1)*temporary*drag_dissipation_tide_period/(2.0*pi)
efold_depth_r(i,j) = Grd%tmask(i,j,1)/(wrk1_2d(i,j) + epsln)
enddo
enddo
endif ! if(drag_dissipation_use_cdbot)
! Richardson number on U-cell.
! perform a 4-point average of T-cell bvfreq
! and then divide by the U-cell tidal speed term.
! tide_speed_mask is useful to reduce overflows
! in later calculation of the diffusivity.
if(drag_mask_deep .and. .not. use_legacy_methods) then
! only to reproduce the previous results with const cdbot
! tide_deepspeed_mask(i,j) is the same as tide_speed_mask(i,j) of the previous
do j=jsd,jed-1
do i=isd,ied-1
kbot=Grd%kmu(i,j)
if(kbot>1) then
bottom = Thickness%depth_zwu(i,j,kbot)
speedr = tide_deepspeed_mask(i,j)/(epsln+rescaled_speed_u(i,j))
do k=1,kbot-1
kp1=k+1
height = bottom-Thickness%depth_zwu(i,j,k)
bvfreq_u = onefourth*(bvfreq(i,j,k)+bvfreq(i+1,j,k)+bvfreq(i,j+1,k)+bvfreq(i+1,j+1,k))
wrk1(i,j,k) = 2.0*Grd%umask(i,j,kp1)*(bvfreq_u*height*speedr)**2
enddo
endif
enddo
enddo
else
do j=jsd,jed-1
do i=isd,ied-1
kbot=Grd%kmu(i,j)
if(kbot>1) then
bottom = Thickness%depth_zwu(i,j,kbot)
speedr = tide_rescspeed_mask(i,j)*tide_deepspeed_mask(i,j)/(epsln+rescaled_speed_u(i,j))
do k=1,kbot-1
kp1=k+1
height = bottom-Thickness%depth_zwu(i,j,k)
bvfreq_u = onefourth*(bvfreq(i,j,k)+bvfreq(i+1,j,k)+bvfreq(i,j+1,k)+bvfreq(i+1,j+1,k))
wrk1(i,j,k) = 2.0*Grd%umask(i,j,kp1)*(bvfreq_u*height*speedr)**2
enddo
endif
enddo
enddo
endif
! Richardson number on bottom of T-cells.
! need active_cells for averaging operation.
do k=1,nk-1
do j=jsc,jec
do i=isc,iec
active_cells = Grd%umask(i,j,k) + Grd%umask(i-1,j,k) &
+ Grd%umask(i,j-1,k) + Grd%umask(i-1,j-1,k) + epsln
wrk2(i,j,k) = (wrk1(i,j,k) + wrk1(i-1,j,k) + wrk1(i,j-1,k) + wrk1(i-1,j-1,k))/active_cells
enddo
enddo
enddo
! compute drag induced diffusivity
! (Lee etal equations (1), (2), and (3))
! Multiply by tide_speed_mask so to zero out
! regions with tiny tide speeds, which are regions
! where we do not wish to have any enhanced mixing
! arising from the barotropic tide mixing parameterization
! anyhow.
if(drag_mask_deep .and. .not. use_legacy_methods) then
! only to reproduce the previous results with const cdbot
! tide_deepspeed_mask(i,j) is the same as tide_speed_mask(i,j) of the previous
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_drag(i,j,k) = Grd%tmask(i,j,kp1)*tide_deepspeed_mask(i,j) &
*max_drag_diffusivity*(1.0 + munk_anderson_sigma*wrk2(i,j,k))**(-munk_anderson_p)
enddo
enddo
enddo
else
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_drag(i,j,k) = Grd%tmask(i,j,kp1)*tide_rescspeed_mask(i,j)*tide_deepspeed_mask(i,j) &
*max_drag_diffusivity*(1.0 + munk_anderson_sigma*wrk2(i,j,k))**(-munk_anderson_p)
enddo
enddo
enddo
endif
if(drag_dissipation_efold) then
do j=jsc,jec
do i=isc,iec
kbot=Grd%kmt(i,j)
if(kbot>1) then
bottom = Thickness%depth_zwt(i,j,kbot)
do k=1,kbot-1
kp1=k+1
height = bottom-Thickness%depth_zwt(i,j,k)
diff_drag(i,j,k) = diff_drag(i,j,k)*exp(-height*efold_depth_r(i,j))
enddo
endif
enddo
enddo
endif
call mpp_update_domains(diff_drag(:,:,:), Dom%domain2d)
! add drag induced diffusivity and viscosity to diff_cbt and visc_cbu.
! average t-cell diffusivities to get u-cell viscosity.
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_cbt_drag(i,j,k) = diff_drag(i,j,k)
diff_cbt(i,j,k,1) = diff_cbt(i,j,k,1) + diff_drag(i,j,k)
diff_cbt(i,j,k,2) = diff_cbt(i,j,k,2) + diff_drag(i,j,k)
visc_cbt(i,j,k) = visc_cbt(i,j,k) + diff_drag(i,j,k)
wrk3(i,j,k) = Grd%umask(i,j,kp1)*onefourth &
*(diff_drag(i,j,k) +diff_drag(i+1,j,k) &
+diff_drag(i,j+1,k)+diff_drag(i+1,j+1,k))
visc_cbu(i,j,k) = visc_cbu(i,j,k) + wrk3(i,j,k)
enddo
enddo
enddo
if (id_rinumber_drag > 0) then
used = send_data (id_rinumber_drag, wrk2(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_diff_cbt_drag > 0) then
used = send_data (id_diff_cbt_drag, diff_drag(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbu_drag > 0) then
used = send_data (id_visc_cbu_drag, wrk3(:,:,:), &
Time%model_time, rmask=Grd%umask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if(drag_dissipation_use_cdbot) then
if (id_tide_rescspeed_mask > 0) then
used = send_data (id_tide_rescspeed_mask, tide_rescspeed_mask(:,:), &
Time%model_time, rmask=Grd%umask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_drag_diss_efold > 0) then
used = send_data (id_drag_diss_efold, wrk1_2d(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
endif !if(drag_dissipation_use_cdbot)
end subroutine vert_mix_drag_bgrid
! </SUBROUTINE> NAME="vert_mix_drag_bgrid"
!#######################################################################
! <SUBROUTINE NAME="vert_mix_drag_cgrid">
!
! <DESCRIPTION>
! This subroutine computes dia-surface tracer diffusivity based on the
! methods of Lee etal., which consider the dissipation from barotropic tides
! rubbing against the ocean bottom.
!
! We assume a unit Prandtl number, so compute the viscosity as a four-point
! average of the diffusivity.
!
! We assume C-grid layout for the velocity, which renders slight
! distinctions for the calculation of Richardson number. Otherwise, the
! calculations are the same as the Bgrid. We introduce this separate
! routine, however, to enable easier bitwise agreement with older
! model results. Also, further development of this scheme may lead
! to more distinctions from the Bgrid.
!
! </DESCRIPTION>
!
subroutine vert_mix_drag_cgrid(Time, Thickness, Velocity, diff_cbt, visc_cbu, visc_cbt, diff_cbt_drag)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_velocity_type), intent(in) :: Velocity
real, dimension(isd:,jsd:,:,:), intent(inout) :: diff_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbu
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_drag
integer :: i, j, k, kbot, kp1
real :: height, bottom, efold
real :: bvfreq_u, speedr, active_cells, temporary
integer :: stdoutunit,stdlogunit
stdoutunit=stdout();stdlogunit=stdlog()
wrk1(:,:,:) = 0.0 ! raw Richardson number on T-cell
wrk2(:,:,:) = 0.0 ! smoothed Richardson number on T-cell
wrk3(:,:,:) = 0.0 ! visc_cbu from drag scheme
diff_drag(:,:,:) = 0.0 ! diffusivity from drag scheme
! speed scale for tides rubbing against bottom
! (defined following eq. (3) in Lee etal)
if(drag_dissipation_use_cdbot) then
do j=jsd,jed
do i=isd,ied
rescaled_speed_u(i,j) = sqrt(Velocity%cdbot_array(i,j))*von_karman_inv*tide_speed_u(i,j)
rescaled_speed_t(i,j) = sqrt(Velocity%cdbot_array(i,j))*von_karman_inv*tide_speed_t(i,j)
tide_rescspeed_mask(i,j) = 0.0
if(rescaled_speed_u(i,j) > speed_min) then
tide_rescspeed_mask(i,j) = 1.0
endif
enddo
enddo
! call mpp_update_domains(tide_rescspeed_mask(:,:), Dom%domain2d)
! compute efolding depth scale for use in Lee etal scheme.
! efold depth set as rescaled_speed/(radial tide frequency).
! Choose default radial tide frequency as 2pi/12hrs for semi-diurnal tide.
! let this efolding hold whether using Bgrid or Cgrid.
wrk1_2d(:,:) = 0.0
do j=jsc,jec
do i=isc,iec
active_cells = Grd%umask(i,j,1) + Grd%umask(i-1,j,1) &
+ Grd%umask(i,j-1,1) + Grd%umask(i-1,j-1,1) + epsln
temporary = (rescaled_speed_u(i,j) + rescaled_speed_u(i-1,j) + &
rescaled_speed_u(i,j-1) + rescaled_speed_u(i-1,j-1))/active_cells
wrk1_2d(i,j) = Grd%tmask(i,j,1)*temporary*drag_dissipation_tide_period/(2.0*pi)
efold_depth_r(i,j) = Grd%tmask(i,j,1)/(wrk1_2d(i,j) + epsln)
enddo
enddo
endif !if(drag_dissipation_use_cdbot)
! Richardson number on T-cell.
if(drag_mask_deep .and. .not. use_legacy_methods) then
! only to reproduce the previous results with const cdbot
! tide_deepspeed_mask(i,j) is the same as tide_speed_mask(i,j) of the previous
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
if(kbot>1) then
bottom = Thickness%depth_zwt(i,j,kbot)
speedr = tide_deepspeed_mask(i,j)/(epsln+rescaled_speed_t(i,j))
do k=1,kbot-1
kp1=k+1
height = bottom-Thickness%depth_zwt(i,j,k)
wrk1(i,j,k) = 2.0*Grd%tmask(i,j,kp1)*(bvfreq(i,j,k)*height*speedr)**2
wrk2(i,j,k) = wrk1(i,j,k)
enddo
endif
enddo
enddo
else
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
if(kbot>1) then
bottom = Thickness%depth_zwt(i,j,kbot)
speedr = tide_rescspeed_mask(i,j)*tide_deepspeed_mask(i,j)/(epsln+rescaled_speed_t(i,j))
do k=1,kbot-1
kp1=k+1
height = bottom-Thickness%depth_zwt(i,j,k)
wrk1(i,j,k) = 2.0*Grd%tmask(i,j,kp1)*(bvfreq(i,j,k)*height*speedr)**2
wrk2(i,j,k) = wrk1(i,j,k)
enddo
endif
enddo
enddo
endif
! perform 9point average to smooth, and to be more consistent
! with the Bgrid approach.
! need active_cells for averaging operation.
if(smooth_ri_drag_cgrid) then
do k=1,nk-1
do j=jsc,jec
do i=isc,iec
active_cells = Grd%tmask(i-1,j-1,k) + Grd%tmask(i,j-1,k) + Grd%tmask(i+1,j-1,k) &
+ Grd%tmask(i,j-1,k) + Grd%tmask(i,j,k) + Grd%tmask(i+1,j,k) &
+ Grd%tmask(i-1,j+1,k) + Grd%tmask(i,j+1,k) + Grd%tmask(i+1,j+1,k) &
+ epsln
wrk2(i,j,k) = ( wrk1(i-1,j-1,k) + wrk1(i,j-1,k) + wrk1(i+1,j-1,k) &
+ wrk1(i,j-1,k) + wrk1(i,j,k) + wrk1(i+1,j,k) &
+ wrk1(i-1,j+1,k) + wrk1(i,j+1,k) + wrk1(i+1,j+1,k)) / active_cells
enddo
enddo
enddo
endif
! compute drag induced diffusivity
! (Lee etal equations (1), (2), and (3))
! Multiply by tide_speed_mask so to zero out
! regions with tiny tide speeds, which are regions
! where we do not wish to have any enhanced mixing
! arising from the barotropic tide mixing parameterization
! anyhow.
if(drag_mask_deep .and. .not. use_legacy_methods) then
! only to reproduce the previous results with const cdbot
! tide_deepspeed_mask(i,j) is the same as tide_speed_mask(i,j) of the previous
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_drag(i,j,k) = Grd%tmask(i,j,kp1)*tide_deepspeed_mask(i,j) &
*max_drag_diffusivity*(1.0 + munk_anderson_sigma*wrk2(i,j,k))**(-munk_anderson_p)
enddo
enddo
enddo
else
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_drag(i,j,k) = Grd%tmask(i,j,kp1)*tide_rescspeed_mask(i,j)*tide_deepspeed_mask(i,j) &
*max_drag_diffusivity*(1.0 + munk_anderson_sigma*wrk2(i,j,k))**(-munk_anderson_p)
enddo
enddo
enddo
endif
if(drag_dissipation_efold) then
do j=jsc,jec
do i=isc,iec
kbot=Grd%kmt(i,j)
if(kbot>1) then
bottom = Thickness%depth_zwt(i,j,kbot)
do k=1,kbot-1
kp1=k+1
height = bottom-Thickness%depth_zwt(i,j,k)
diff_drag(i,j,k) = diff_drag(i,j,k)*exp(-height*efold_depth_r(i,j))
enddo
endif
enddo
enddo
endif
call mpp_update_domains(diff_drag(:,:,:), Dom%domain2d)
! add drag induced diffusivity and viscosity to diff_cbt and visc_cbu.
! average t-cell diffusivities to get u-cell viscosity.
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_cbt_drag(i,j,k) = diff_drag(i,j,k)
diff_cbt(i,j,k,1) = diff_cbt(i,j,k,1) + diff_drag(i,j,k)
diff_cbt(i,j,k,2) = diff_cbt(i,j,k,2) + diff_drag(i,j,k)
visc_cbt(i,j,k) = visc_cbt(i,j,k) + diff_drag(i,j,k)
wrk3(i,j,k) = Grd%umask(i,j,kp1)*onefourth &
*(diff_drag(i,j,k) +diff_drag(i+1,j,k) &
+diff_drag(i,j+1,k)+diff_drag(i+1,j+1,k))
visc_cbu(i,j,k) = visc_cbu(i,j,k) + wrk3(i,j,k)
enddo
enddo
enddo
if (id_rinumber_drag > 0) then
used = send_data (id_rinumber_drag, wrk2(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_diff_cbt_drag > 0) then
used = send_data (id_diff_cbt_drag, diff_drag(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbu_drag > 0) then
used = send_data (id_visc_cbu_drag, wrk3(:,:,:), &
Time%model_time, rmask=Grd%umask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if(drag_dissipation_use_cdbot) then
if (id_tide_rescspeed_mask > 0) then
used = send_data (id_tide_rescspeed_mask, tide_rescspeed_mask(:,:), &
Time%model_time, rmask=Grd%umask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_drag_diss_efold > 0) then
used = send_data (id_drag_diss_efold, wrk1_2d(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
endif !if(drag_dissipation_use_cdbot)
end subroutine vert_mix_drag_cgrid
! </SUBROUTINE> NAME="vert_mix_drag_cgrid"
!#######################################################################
! <SUBROUTINE NAME="compute_bvfreq_legacy">
!
! <DESCRIPTION>
! This subroutine computes the absolute value of rho*N^2 and abs of
! N^2, with N^2 the squared Brunt-Vaisala (or buoyancy) frequency.
!
! This routine employs a legacy approach, which is not recommended.
! It remains solely to allow exact reproduction of older results.
!
! </DESCRIPTION>
!
subroutine compute_bvfreq_legacy(Time, Thickness, T_prog, Dens)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_density_type), intent(in) :: Dens
real :: rho_inv, drhodz
real :: tmp, rho_N2_prev, rho_tmp
integer :: i, j, k, m, kp1, kbot
integer :: tau
tau = Time%tau
wrk1(:,:,:) = 0.0
wrk2(:,:,:) = 0.0
! partial derivatives of density wrt to temperature and salinity
do k=1,nk
do j=jsd,jed
do i=isd,ied
drhodT(i,j,k) = Dens%drhodT(i,j,k)
drhodS(i,j,k) = Dens%drhodS(i,j,k)
enddo
enddo
enddo
! vertical derivative of temperature and salinity at bottom of tracer cells
do k=1,nk
kp1=min(k+1,nk)
do j=jsd,jed
do i=isd,ied
tmp = Grd%tmask(i,j,kp1)/Thickness%dzwt(i,j,k)
wrk1(i,j,k) = tmp*(T_prog(index_temp)%field(i,j,k,tau)-T_prog(index_temp)%field(i,j,kp1,tau))
wrk2(i,j,k) = tmp*(Dens%rho_salinity(i,j,k,tau)-Dens%rho_salinity(i,j,kp1,tau))
enddo
enddo
enddo
! absolute(rho*N^2) computed from vertical derivative of "neutral density"
do k=1,nk
kp1 = min(k+1,nk)
do j=jsd,jed
do i=isd,ied
drhodz = onehalf*( (drhodT(i,j,k)+drhodT(i,j,kp1))*wrk1(i,j,k) &
+(drhodS(i,j,k)+drhodS(i,j,kp1))*wrk2(i,j,k) )
drhodz = min(drhodz,-drhodz_min)*Grd%tmask(i,j,kp1)
rho_N2(i,j,k) = -grav*drhodz
enddo
enddo
enddo
! smooth rho_N2 in the vertical using a 1-2-1 filter
if (smooth_rho_N2) then
do m=1,num_121_passes
do j=jsd,jed
do i=isd,ied
rho_N2_prev = onefourth*rho_N2(i,j,1)
kbot=Grd%kmt(i,j)
if (kbot>3) then
do k=2,kbot-2
tmp = rho_N2(i,j,k)
rho_N2(i,j,k) = rho_N2_prev + onehalf*rho_N2(i,j,k) + onefourth*rho_N2(i,j,k+1)
rho_N2_prev = onefourth*tmp
enddo
endif
enddo
enddo
enddo
endif
! compute buoyancy frequency
do k=1,nk
kp1 = min(k+1,nk)
do j=jsd,jed
do i=isd,ied
rho_inv = 2.0/(epsln + Dens%rho(i,j,k,tau) + Dens%rho(i,j,kp1,tau))
bvfreq(i,j,k) = sqrt(rho_inv*rho_N2(i,j,k))
enddo
enddo
enddo
! bvfreq at the bottom.
! set kbot=kmt-1 rather than kbot=kmt, since N^2=0
! at bottom of bottom-most tracer cell, by definition.
do j=jsd,jed
do i=isd,ied
bvfreq_bottom(i,j) = 0.0
if(Grd%kmt(i,j) > 1) then
kbot=Grd%kmt(i,j)-1
bvfreq_bottom(i,j) = bvfreq(i,j,kbot)
endif
enddo
enddo
! horizontal laplacian smoothing on the bottom bvfreq to reduce noise
if(smooth_bvfreq_bottom) then
bvfreq_bottom(:,:) = bvfreq_bottom(:,:) + dtime*LAP_T(bvfreq_bottom(:,:),smooth_lap(:,:))
call mpp_update_domains(bvfreq_bottom(:,:), Dom%domain2d)
endif
! compute mixing efficiency
mix_efficiency(:,:,:) = mixing_efficiency
if(mixing_efficiency_n2depend) then
do k=1,nk
do j=jsd,jed
do i=isd,ied
rho_tmp = Dens%rho(i,j,k,tau) + epsln
mix_efficiency(i,j,k) = mixing_efficiency*rho_N2(i,j,k)/(rho_N2(i,j,k) + rho_tmp*omega_earth2)
enddo
enddo
enddo
endif
if (id_bvfreq_bottom > 0) then
used = send_data (id_bvfreq_bottom, bvfreq_bottom(:,:),&
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_bvfreq > 0) then
used = send_data (id_bvfreq, bvfreq(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_mix_efficiency > 0) then
used = send_data (id_mix_efficiency, mix_efficiency(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
end subroutine compute_bvfreq_legacy
! </SUBROUTINE> NAME="compute_bvfreq_legacy"
!#######################################################################
! <SUBROUTINE NAME="vert_mix_wave_legacy">
!
! <DESCRIPTION>
!
! Legacy routine maintained only to exactly reproduce older results.
! It is not recommended for new experiments, as it uses some obsolete
! methods.
!
! This subroutine computes dia-surface tracer diffusivity based on the
! methods of Simmons etal., which consider the dissipation from breaking
! internal gravity waves and their conversion into local dia-surface
! diffusion.
!
! We assume a unit Prandtl number, so compute the viscosity as a four-point
! average of the diffusivity.
!
! Note that if umask(i,j,k) is 1.0, then so is
! tmask(i,j,k), tmask(i+1,j,k), tmask(i,j+1,k), and tmask(i+1,j+1,k).
! So there is no need to compute the "active_cells" when doing the
! space average to go from t-cell to u-cell to compute viscosity.
!
! </DESCRIPTION>
!
subroutine vert_mix_wave_legacy(Time, Thickness, diff_cbt, visc_cbu, visc_cbt, diff_cbt_wave)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
real, dimension(isd:,jsd:,:,:), intent(inout) :: diff_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbu
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_wave
integer :: i, j, k, kbot, kp1
real :: deposition, factor
diff_wave(:,:,:) = 0.0 ! diffusivity from wave scheme
wrk1(:,:,:) = 0.0 ! viscosity from wave scheme
! compute mask for regions that are too shallow for this scheme
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
tmask_deep(i,j) = 0.0
if(kbot > 1) then
if(Thickness%depth_zwt(i,j,kbot) > shelf_depth_cutoff) tmask_deep(i,j) = 1.0
endif
enddo
enddo
! compute the wave energy flux array (W/m2) and save for diagnostics
! (Simmons etal equation (1))
if(fixed_wave_dissipation) then
do j=jsd,jed
do i=isd,ied
energy_flux(i,j) = min(wave_energy_flux_max, wave_dissipation(i,j)*tmask_deep(i,j))
enddo
enddo
else
do j=jsd,jed
do i=isd,ied
energy_flux(i,j) = min(wave_energy_flux_max, wave_term(i,j)*bvfreq_bottom(i,j)*tmask_deep(i,j))
enddo
enddo
endif
! compute wave induced diffusivity
! (Simmons etal equation (3))
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
if(kbot > 1) then
! normalization of vertical structure function...ensure it
! integrates to unity on the discrete grid.
factor = 0.0
do k=1,kbot-1
factor = factor + Thickness%dzt(i,j,k)*exp(decay_scale_inv*Thickness%depth_zwt(i,j,k))
enddo
factor = 1.0/factor
! calculate diffusivity
do k=1,kbot-1
deposition = factor*exp(decay_scale_inv*Thickness%depth_zwt(i,j,k))
diff_wave(i,j,k) = Grd%tmask(i,j,k+1)*mix_efficiency(i,j,k)*tidal_diss_efficiency &
*energy_flux(i,j)*deposition/(epsln+rho_N2(i,j,k))
diff_wave(i,j,k) = min(diff_wave(i,j,k),max_wave_diffusivity)
enddo
endif
enddo
enddo
! ensure diffusivity monotonically decreases as move upward in column.
! recall that diff_wave(i,j,k) is the diffusivity at the bottom of cell-k,
! where diff_wave(i,j,kbot)=0.0 by definition. This prompts the kbot-2,1,-1
! loop limits.
if(wave_diffusivity_monotonic) then
do j=jsd,jed
do i=isd,ied
kbot=Grd%kmt(i,j)
if(kbot > 1) then
do k=kbot-2,1,-1
diff_wave(i,j,k) = min(diff_wave(i,j,k),diff_wave(i,j,k+1))
enddo
endif
enddo
enddo
endif
! add wave induced diffusivity and viscosity to diff_cbt and visc_cbu
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_cbt_wave(i,j,k) = diff_wave(i,j,k)
diff_cbt(i,j,k,1) = diff_cbt(i,j,k,1) + diff_wave(i,j,k)
diff_cbt(i,j,k,2) = diff_cbt(i,j,k,2) + diff_wave(i,j,k)
visc_cbt(i,j,k) = visc_cbt(i,j,k) + diff_wave(i,j,k)
wrk1(i,j,k) = Grd%umask(i,j,kp1)*onefourth &
*(diff_wave(i,j,k) +diff_wave(i+1,j,k) &
+diff_wave(i,j+1,k)+diff_wave(i+1,j+1,k))
visc_cbu(i,j,k) = visc_cbu(i,j,k) + wrk1(i,j,k)
enddo
enddo
enddo
if (id_energy_flux > 0) then
used = send_data (id_energy_flux, energy_flux(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_power_waves > 0) then
used = send_data (id_power_waves, Grd%dat(:,:)*energy_flux(:,:), &
Time%model_time, rmask=Grd%tmask(:,:,1), &
is_in=isc, js_in=jsc, ie_in=iec, je_in=jec)
endif
if (id_diff_cbt_wave > 0) then
used = send_data (id_diff_cbt_wave, diff_wave(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbt_wave > 0) then
used = send_data (id_visc_cbt_wave, diff_wave(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbu_wave > 0) then
used = send_data (id_visc_cbu_wave, wrk1(:,:,:), &
Time%model_time, rmask=Grd%umask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
end subroutine vert_mix_wave_legacy
! </SUBROUTINE> NAME="vert_mix_wave_legacy"
!#######################################################################
! <SUBROUTINE NAME="vert_mix_drag_legacy">
!
! <DESCRIPTION>
!
! Legacy routine maintained only to exactly reproduce older results.
! It is not recommended for new experiments, as it uses some obsolete
! methods.
!
! This subroutine computes dia-surface tracer diffusivity based on the
! methods of Lee etal., which consider the dissipation from barotropic tides
! rubbing against the ocean bottom.
!
! We assume a unit Prandtl number, so compute the viscosity as a four-point
! average of the diffusivity.
!
! We perform various averages here in order to smooth Richardson number.
!
! 1. compute Richardson number on U-cell by averaging bvfreq from T-cell
! 2. average U-cell Richardson number to then get T-cell diffusivity
! 3. average T-cell diffusivity to get U-cell viscosity.
!
! Note that if umask(i,j,k)==1.0, then so is tmask(i,j,k), tmask(i+1,j,k),
! tmask(i,j+1,k), and tmask(i+1,j+1,k). So there is no need to compute
! active_cells when averaging from T-cell to U-cell.
!
! </DESCRIPTION>
!
subroutine vert_mix_drag_legacy(Time, Thickness, diff_cbt, visc_cbu, visc_cbt, diff_cbt_drag)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
real, dimension(isd:,jsd:,:,:), intent(inout) :: diff_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbu
real, dimension(isd:,jsd:,:), intent(inout) :: visc_cbt
real, dimension(isd:,jsd:,:), intent(inout) :: diff_cbt_drag
integer :: i, j, k, kbot, kp1
real :: height, bottom, bvfreq_u, speedr, active_cells
wrk1(:,:,:) =0.0 ! Richardson number on U-cell
wrk2(:,:,:) =0.0 ! Richardson number on T-cell
wrk3(:,:,:) =0.0 ! viscosity from drag scheme
diff_drag(:,:,:) =0.0 ! diffusivity from drag scheme
! Richardson number on U-cell.
! perform a 4-point average of T-cell bvfreq
! and then divide by the U-cell tidal speed term.
! tide_speed_mask is useful to reduce overflows
! in later calculation of the diffusivity.
do j=jsd,jed-1
do i=isd,ied-1
kbot=Grd%kmu(i,j)
if(kbot>1) then
bottom = Thickness%depth_zwu(i,j,kbot)
speedr = tide_speed_mask(i,j)/(epsln+rescaled_speed_u(i,j))
do k=1,kbot-1
kp1=k+1
height = bottom-Thickness%depth_zwu(i,j,k)
bvfreq_u = onefourth*(bvfreq(i,j,k)+bvfreq(i+1,j,k)+bvfreq(i,j+1,k)+bvfreq(i+1,j+1,k))
wrk1(i,j,k) = 2.0*Grd%umask(i,j,kp1)*(bvfreq_u*height*speedr)**2
enddo
endif
enddo
enddo
! Richardson number on bottom of T-cells.
! need active_cells for averaging operation.
do k=1,nk-1
do j=jsc,jec
do i=isc,iec
active_cells = Grd%umask(i,j,k) + Grd%umask(i-1,j,k) &
+ Grd%umask(i,j-1,k) + Grd%umask(i-1,j-1,k) + epsln
wrk2(i,j,k) = (wrk1(i,j,k) + wrk1(i-1,j,k) + wrk1(i,j-1,k) + wrk1(i-1,j-1,k))/active_cells
enddo
enddo
enddo
! compute drag induced diffusivity
! (Lee etal equations (1), (2), and (3))
! Multiply by tide_speed_mask so to zero out
! regions with tiny tide speeds, which are regions
! where we do not wish to have any enhanced mixing
! arising from the barotropic tide mixing parameterization
! anyhow.
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_drag(i,j,k) = Grd%tmask(i,j,kp1)*tide_speed_mask(i,j)*max_drag_diffusivity &
*(1.0 + munk_anderson_sigma*wrk2(i,j,k))**(-munk_anderson_p)
enddo
enddo
enddo
call mpp_update_domains(diff_drag(:,:,:), Dom%domain2d)
! add drag induced diffusivity and viscosity to diff_cbt and visc_cbu.
! average t-cell diffusivities to get u-cell viscosity.
do k=1,nk-1
kp1=k+1
do j=jsc,jec
do i=isc,iec
diff_cbt_drag(i,j,k) = diff_drag(i,j,k)
diff_cbt(i,j,k,1) = diff_cbt(i,j,k,1) + diff_drag(i,j,k)
diff_cbt(i,j,k,2) = diff_cbt(i,j,k,2) + diff_drag(i,j,k)
visc_cbt(i,j,k) = visc_cbt(i,j,k) + diff_drag(i,j,k)
wrk3(i,j,k) = Grd%umask(i,j,kp1)*onefourth &
*(diff_drag(i,j,k) +diff_drag(i+1,j,k) &
+diff_drag(i,j+1,k)+diff_drag(i+1,j+1,k))
visc_cbu(i,j,k) = visc_cbu(i,j,k) + wrk3(i,j,k)
enddo
enddo
enddo
if (id_rinumber_drag > 0) then
used = send_data (id_rinumber_drag, wrk2(:,:,:),&
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_diff_cbt_drag > 0) then
used = send_data (id_diff_cbt_drag, diff_drag(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbt_drag > 0) then
used = send_data (id_visc_cbt_drag, diff_drag(:,:,:), &
Time%model_time, rmask=Grd%tmask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
if (id_visc_cbu_drag > 0) then
used = send_data (id_visc_cbu_drag, wrk3(:,:,:), &
Time%model_time, rmask=Grd%umask(:,:,:), &
is_in=isc, js_in=jsc, ks_in=1, ie_in=iec, je_in=jec, ke_in=nk)
endif
end subroutine vert_mix_drag_legacy
! </SUBROUTINE> NAME="vert_mix_drag_legacy"
end module ocean_vert_tidal_test_mod
| gpl-2.0 |
rhristov/gcc-modified | libgomp/testsuite/libgomp.fortran/target6.f90 | 102 | 1232 | ! { dg-do run }
module target6
contains
subroutine foo (p, v, w, n)
double precision, pointer :: p(:), v(:), w(:)
double precision :: q(n)
integer :: i, n
!$omp target data if (n > 256) map (to: v(1:n), w(:n)) map (from: p(1:n), q)
!$omp target if (n > 256)
!$omp parallel do simd
do i = 1, n
p(i) = v(i) * w(i)
q(i) = p(i)
end do
!$omp end target
!$omp target update if (n > 256) from (p)
do i = 1, n
if (p(i) /= i * iand (i, 63)) call abort
v(i) = v(i) + 1
end do
!$omp target update if (n > 256) to (v(1:n))
!$omp target if (n > 256)
!$omp parallel do simd
do i = 1, n
p(i) = v(i) * w(i)
end do
!$omp end target
!$omp end target data
do i = 1, n
if (q(i) /= (v(i) - 1) * w(i)) call abort
if (p(i) /= q(i) + w(i)) call abort
end do
end subroutine
end module target6
use target6, only : foo
integer :: n, i
double precision, pointer :: p(:), v(:), w(:)
n = 10000
allocate (p(n), v(n), w(n))
do i = 1, n
v(i) = i
w(i) = iand (i, 63)
end do
call foo (p, v, w, n)
do i = 1, n
if (p(i) /= (i + 1) * iand (i, 63)) call abort
end do
deallocate (p, v, w)
end
| gpl-2.0 |
pschella/scipy | scipy/special/cdflib/ipmpar.f | 112 | 12380 | INTEGER FUNCTION ipmpar(i)
C-----------------------------------------------------------------------
C
C IPMPAR PROVIDES THE INTEGER MACHINE CONSTANTS FOR THE COMPUTER
C THAT IS USED. IT IS ASSUMED THAT THE ARGUMENT I IS AN INTEGER
C HAVING ONE OF THE VALUES 1-10. IPMPAR(I) HAS THE VALUE ...
C
C INTEGERS.
C
C ASSUME INTEGERS ARE REPRESENTED IN THE N-DIGIT, BASE-A FORM
C
C SIGN ( X(N-1)*A**(N-1) + ... + X(1)*A + X(0) )
C
C WHERE 0 .LE. X(I) .LT. A FOR I=0,...,N-1.
C
C IPMPAR(1) = A, THE BASE.
C
C IPMPAR(2) = N, THE NUMBER OF BASE-A DIGITS.
C
C IPMPAR(3) = A**N - 1, THE LARGEST MAGNITUDE.
C
C FLOATING-POINT NUMBERS.
C
C IT IS ASSUMED THAT THE SINGLE AND DOUBLE PRECISION FLOATING
C POINT ARITHMETICS HAVE THE SAME BASE, SAY B, AND THAT THE
C NONZERO NUMBERS ARE REPRESENTED IN THE FORM
C
C SIGN (B**E) * (X(1)/B + ... + X(M)/B**M)
C
C WHERE X(I) = 0,1,...,B-1 FOR I=1,...,M,
C X(1) .GE. 1, AND EMIN .LE. E .LE. EMAX.
C
C IPMPAR(4) = B, THE BASE.
C
C SINGLE-PRECISION
C
C IPMPAR(5) = M, THE NUMBER OF BASE-B DIGITS.
C
C IPMPAR(6) = EMIN, THE SMALLEST EXPONENT E.
C
C IPMPAR(7) = EMAX, THE LARGEST EXPONENT E.
C
C DOUBLE-PRECISION
C
C IPMPAR(8) = M, THE NUMBER OF BASE-B DIGITS.
C
C IPMPAR(9) = EMIN, THE SMALLEST EXPONENT E.
C
C IPMPAR(10) = EMAX, THE LARGEST EXPONENT E.
C
C-----------------------------------------------------------------------
C
C TO DEFINE THIS FUNCTION FOR THE COMPUTER BEING USED, ACTIVATE
C THE DATA STATMENTS FOR THE COMPUTER BY REMOVING THE C FROM
C COLUMN 1. (ALL THE OTHER DATA STATEMENTS SHOULD HAVE C IN
C COLUMN 1.)
C
C-----------------------------------------------------------------------
C
C IPMPAR IS AN ADAPTATION OF THE FUNCTION I1MACH, WRITTEN BY
C P.A. FOX, A.D. HALL, AND N.L. SCHRYER (BELL LABORATORIES).
C IPMPAR WAS FORMED BY A.H. MORRIS (NSWC). THE CONSTANTS ARE
C FROM BELL LABORATORIES, NSWC, AND OTHER SOURCES.
C
C-----------------------------------------------------------------------
C .. Scalar Arguments ..
INTEGER i
C ..
C .. Local Arrays ..
INTEGER imach(10)
C ..
C .. Data statements ..
C
C MACHINE CONSTANTS FOR AMDAHL MACHINES.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 16 /
C DATA IMACH( 5) / 6 /
C DATA IMACH( 6) / -64 /
C DATA IMACH( 7) / 63 /
C DATA IMACH( 8) / 14 /
C DATA IMACH( 9) / -64 /
C DATA IMACH(10) / 63 /
C
C MACHINE CONSTANTS FOR THE AT&T 3B SERIES, AT&T
C PC 7300, AND AT&T 6300.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -125 /
C DATA IMACH( 7) / 128 /
C DATA IMACH( 8) / 53 /
C DATA IMACH( 9) / -1021 /
C DATA IMACH(10) / 1024 /
C
C MACHINE CONSTANTS FOR THE BURROUGHS 1700 SYSTEM.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 33 /
C DATA IMACH( 3) / 8589934591 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -256 /
C DATA IMACH( 7) / 255 /
C DATA IMACH( 8) / 60 /
C DATA IMACH( 9) / -256 /
C DATA IMACH(10) / 255 /
C
C MACHINE CONSTANTS FOR THE BURROUGHS 5700 SYSTEM.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 39 /
C DATA IMACH( 3) / 549755813887 /
C DATA IMACH( 4) / 8 /
C DATA IMACH( 5) / 13 /
C DATA IMACH( 6) / -50 /
C DATA IMACH( 7) / 76 /
C DATA IMACH( 8) / 26 /
C DATA IMACH( 9) / -50 /
C DATA IMACH(10) / 76 /
C
C MACHINE CONSTANTS FOR THE BURROUGHS 6700/7700 SYSTEMS.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 39 /
C DATA IMACH( 3) / 549755813887 /
C DATA IMACH( 4) / 8 /
C DATA IMACH( 5) / 13 /
C DATA IMACH( 6) / -50 /
C DATA IMACH( 7) / 76 /
C DATA IMACH( 8) / 26 /
C DATA IMACH( 9) / -32754 /
C DATA IMACH(10) / 32780 /
C
C MACHINE CONSTANTS FOR THE CDC 6000/7000 SERIES
C 60 BIT ARITHMETIC, AND THE CDC CYBER 995 64 BIT
C ARITHMETIC (NOS OPERATING SYSTEM).
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 48 /
C DATA IMACH( 3) / 281474976710655 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 48 /
C DATA IMACH( 6) / -974 /
C DATA IMACH( 7) / 1070 /
C DATA IMACH( 8) / 95 /
C DATA IMACH( 9) / -926 /
C DATA IMACH(10) / 1070 /
C
C MACHINE CONSTANTS FOR THE CDC CYBER 995 64 BIT
C ARITHMETIC (NOS/VE OPERATING SYSTEM).
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 63 /
C DATA IMACH( 3) / 9223372036854775807 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 48 /
C DATA IMACH( 6) / -4096 /
C DATA IMACH( 7) / 4095 /
C DATA IMACH( 8) / 96 /
C DATA IMACH( 9) / -4096 /
C DATA IMACH(10) / 4095 /
C
C MACHINE CONSTANTS FOR THE CRAY 1, XMP, 2, AND 3.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 63 /
C DATA IMACH( 3) / 9223372036854775807 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 47 /
C DATA IMACH( 6) / -8189 /
C DATA IMACH( 7) / 8190 /
C DATA IMACH( 8) / 94 /
C DATA IMACH( 9) / -8099 /
C DATA IMACH(10) / 8190 /
C
C MACHINE CONSTANTS FOR THE DATA GENERAL ECLIPSE S/200.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 15 /
C DATA IMACH( 3) / 32767 /
C DATA IMACH( 4) / 16 /
C DATA IMACH( 5) / 6 /
C DATA IMACH( 6) / -64 /
C DATA IMACH( 7) / 63 /
C DATA IMACH( 8) / 14 /
C DATA IMACH( 9) / -64 /
C DATA IMACH(10) / 63 /
C
C MACHINE CONSTANTS FOR THE HARRIS 220.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 23 /
C DATA IMACH( 3) / 8388607 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 23 /
C DATA IMACH( 6) / -127 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 38 /
C DATA IMACH( 9) / -127 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE HONEYWELL 600/6000
C AND DPS 8/70 SERIES.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 35 /
C DATA IMACH( 3) / 34359738367 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 27 /
C DATA IMACH( 6) / -127 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 63 /
C DATA IMACH( 9) / -127 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE HP 2100
C 3 WORD DOUBLE PRECISION OPTION WITH FTN4
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 15 /
C DATA IMACH( 3) / 32767 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 23 /
C DATA IMACH( 6) / -128 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 39 /
C DATA IMACH( 9) / -128 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE HP 2100
C 4 WORD DOUBLE PRECISION OPTION WITH FTN4
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 15 /
C DATA IMACH( 3) / 32767 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 23 /
C DATA IMACH( 6) / -128 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 55 /
C DATA IMACH( 9) / -128 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE HP 9000.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -126 /
C DATA IMACH( 7) / 128 /
C DATA IMACH( 8) / 53 /
C DATA IMACH( 9) / -1021 /
C DATA IMACH(10) / 1024 /
C
C MACHINE CONSTANTS FOR THE IBM 360/370 SERIES,
C THE ICL 2900, THE ITEL AS/6, THE XEROX SIGMA
C 5/7/9 AND THE SEL SYSTEMS 85/86.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 16 /
C DATA IMACH( 5) / 6 /
C DATA IMACH( 6) / -64 /
C DATA IMACH( 7) / 63 /
C DATA IMACH( 8) / 14 /
C DATA IMACH( 9) / -64 /
C DATA IMACH(10) / 63 /
C
C MACHINE CONSTANTS FOR THE IBM PC.
C
C DATA imach(1)/2/
C DATA imach(2)/31/
C DATA imach(3)/2147483647/
C DATA imach(4)/2/
C DATA imach(5)/24/
C DATA imach(6)/-125/
C DATA imach(7)/128/
C DATA imach(8)/53/
C DATA imach(9)/-1021/
C DATA imach(10)/1024/
C
C MACHINE CONSTANTS FOR THE MACINTOSH II - ABSOFT
C MACFORTRAN II.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -125 /
C DATA IMACH( 7) / 128 /
C DATA IMACH( 8) / 53 /
C DATA IMACH( 9) / -1021 /
C DATA IMACH(10) / 1024 /
C
C MACHINE CONSTANTS FOR THE MICROVAX - VMS FORTRAN.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -127 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 56 /
C DATA IMACH( 9) / -127 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE PDP-10 (KA PROCESSOR).
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 35 /
C DATA IMACH( 3) / 34359738367 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 27 /
C DATA IMACH( 6) / -128 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 54 /
C DATA IMACH( 9) / -101 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE PDP-10 (KI PROCESSOR).
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 35 /
C DATA IMACH( 3) / 34359738367 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 27 /
C DATA IMACH( 6) / -128 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 62 /
C DATA IMACH( 9) / -128 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE PDP-11 FORTRAN SUPPORTING
C 32-BIT INTEGER ARITHMETIC.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -127 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 56 /
C DATA IMACH( 9) / -127 /
C DATA IMACH(10) / 127 /
C
C MACHINE CONSTANTS FOR THE SEQUENT BALANCE 8000.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -125 /
C DATA IMACH( 7) / 128 /
C DATA IMACH( 8) / 53 /
C DATA IMACH( 9) / -1021 /
C DATA IMACH(10) / 1024 /
C
C MACHINE CONSTANTS FOR THE SILICON GRAPHICS IRIS-4D
C SERIES (MIPS R3000 PROCESSOR).
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -125 /
C DATA IMACH( 7) / 128 /
C DATA IMACH( 8) / 53 /
C DATA IMACH( 9) / -1021 /
C DATA IMACH(10) / 1024 /
C
C MACHINE CONSTANTS FOR IEEE ARITHMETIC MACHINES, SUCH AS THE AT&T
C 3B SERIES, MOTOROLA 68000 BASED MACHINES (E.G. SUN 3 AND AT&T
C PC 7300), AND 8087 BASED MICROS (E.G. IBM PC AND AT&T 6300).
C
DATA IMACH( 1) / 2 /
DATA IMACH( 2) / 31 /
DATA IMACH( 3) / 2147483647 /
DATA IMACH( 4) / 2 /
DATA IMACH( 5) / 24 /
DATA IMACH( 6) / -125 /
DATA IMACH( 7) / 128 /
DATA IMACH( 8) / 53 /
DATA IMACH( 9) / -1021 /
DATA IMACH(10) / 1024 /
C
C MACHINE CONSTANTS FOR THE UNIVAC 1100 SERIES.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 35 /
C DATA IMACH( 3) / 34359738367 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 27 /
C DATA IMACH( 6) / -128 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 60 /
C DATA IMACH( 9) /-1024 /
C DATA IMACH(10) / 1023 /
C
C MACHINE CONSTANTS FOR THE VAX 11/780.
C
C DATA IMACH( 1) / 2 /
C DATA IMACH( 2) / 31 /
C DATA IMACH( 3) / 2147483647 /
C DATA IMACH( 4) / 2 /
C DATA IMACH( 5) / 24 /
C DATA IMACH( 6) / -127 /
C DATA IMACH( 7) / 127 /
C DATA IMACH( 8) / 56 /
C DATA IMACH( 9) / -127 /
C DATA IMACH(10) / 127 /
C
ipmpar = imach(i)
RETURN
END
| bsd-3-clause |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/pointer_array_8.f90 | 18 | 2086 | ! { dg-do run }
!
! Make sure that the fix for pr34640 works with class pointers.
!
type :: mytype
real :: r
integer :: i
end type
type :: thytype
real :: r
integer :: i
type(mytype) :: der
end type
type(thytype), dimension(0:2), target :: tgt
class(*), dimension(:), pointer :: cptr
class(mytype), dimension(:), pointer :: cptr1
integer :: i
integer(8) :: s1, s2
tgt = [(thytype(int(i), i, mytype(int(2*i), 2*i)), i= 1,3)]
cptr => tgt%i
if (lbound (cptr, 1) .ne. 1) STOP 1! Not a whole array target!
s1 = loc(cptr)
call foo (cptr, s2) ! Check bounds not changed...
if (s1 .ne. s2) STOP 2! ...and that the descriptor is passed.
select type (cptr)
type is (integer)
if (any (cptr .ne. [1,2,3])) STOP 3! Check the the scalarizer works.
if (cptr(2) .ne. 2) STOP 4! Check ordinary array indexing.
end select
cptr(1:3) => tgt%der%r ! Something a tad more complicated!
select type (cptr)
type is (real)
if (any (int(cptr) .ne. [2,4,6])) STOP 5
if (any (int(cptr([2,3,1])) .ne. [4,6,2])) STOP 6
if (int(cptr(3)) .ne. 6) STOP 7
end select
cptr1(1:3) => tgt%der
s1 = loc(cptr1)
call bar(cptr1, s2)
if (s1 .ne. s2) STOP 8! Check that the descriptor is passed.
select type (cptr1)
type is (mytype)
if (any (cptr1%i .ne. [2,4,6])) STOP 9
if (cptr1(2)%i .ne. 4) STOP 10
end select
contains
subroutine foo (arg, addr)
class(*), dimension(:), pointer :: arg
integer(8) :: addr
addr = loc(arg)
select type (arg)
type is (integer)
if (any (arg .ne. [1,2,3])) STOP 11! Check the the scalarizer works.
if (arg(2) .ne. 2) STOP 12! Check ordinary array indexing.
end select
end subroutine
subroutine bar (arg, addr)
class(mytype), dimension(:), pointer :: arg
integer(8) :: addr
addr = loc(arg)
select type (arg)
type is (mytype)
if (any (arg%i .ne. [2,4,6])) STOP 13
if (arg(2)%i .ne. 4) STOP 14
end select
end subroutine
end
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/assumed_charlen_function_1.f90 | 154 | 1971 | ! { dg-do compile }
! { dg-options "-std=legacy" }
! Tests the patch for PRs 25084, 20852, 25085 and 25086, all of
! which involve assumed character length functions.
! Compiled from original PR testcases, which were all contributed
! by Joost VandeVondele <jv244@cam.ac.uk>
!
! PR25084 - the error is not here but in any use of .IN.
! It is OK to define an assumed character length function
! in an interface but it cannot be invoked (5.1.1.5).
MODULE M1
TYPE SET
INTEGER CARD
END TYPE SET
END MODULE M1
MODULE INTEGER_SETS
INTERFACE OPERATOR (.IN.)
FUNCTION ELEMENT(X,A) ! { dg-error "cannot be assumed character length" }
USE M1
CHARACTER(LEN=*) :: ELEMENT
INTEGER, INTENT(IN) :: X
TYPE(SET), INTENT(IN) :: A
END FUNCTION ELEMENT
END INTERFACE
END MODULE
! 5.1.1.5 of the Standard: A function name declared with an asterisk
! char-len-param shall not be array-valued, pointer-valued, recursive
! or pure
!
! PR20852
RECURSIVE FUNCTION TEST() ! { dg-error "cannot be recursive" }
CHARACTER(LEN=*) :: TEST
TEST = ""
END FUNCTION
!PR25085
FUNCTION F1() ! { dg-error "cannot be array-valued" }
CHARACTER(LEN=*), DIMENSION(10) :: F1
F1 = ""
END FUNCTION F1
!PR25086
FUNCTION F2() result(f4) ! { dg-error "cannot be pointer-valued" }
CHARACTER(LEN=*), POINTER :: f4
f4 = ""
END FUNCTION F2
!PR?????
pure FUNCTION F3() ! { dg-error "cannot be pure" }
CHARACTER(LEN=*) :: F3
F3 = ""
END FUNCTION F3
function not_OK (ch)
character(*) not_OK, ch ! OK in an external function
not_OK = ch
end function not_OK
use m1
character(4) :: answer
character(*), external :: not_OK
integer :: i
type (set) :: z
interface
function ext (i)
character(*) :: ext
integer :: i
end function ext
end interface
answer = not_OK ("unOK") ! { dg-error "since it is not a dummy" }
END
| gpl-2.0 |
nvarini/espresso_adios | PHonon/PH/add_zstar_ue.f90 | 5 | 2573 | !
! Copyright (C) 2001-2012 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!-----------------------------------------------------------------------
subroutine add_zstar_ue (imode0, npe)
!-----------------------------------------------------------------------
! add the contribution of the modes imode0+1 -> imode+npe
! to the effective charges Z(Us,E) (Us=scf,E=bare)
!
! trans =.true. is needed for this calculation to be meaningful
!
USE kinds, only : DP
USE klist, ONLY : xk, wk
USE uspp, ONLY : vkb
USE wvfct, ONLY : npwx, npw, igk
USE wavefunctions_module, ONLY: evc
USE noncollin_module, ONLY: noncolin
USE io_files, ONLY: iunigk
USE buffers, ONLY : get_buffer
USE qpoint, ONLY: npwq, nksq
USE eqv, ONLY: dpsi, dvpsi
USE efield_mod, ONLY: zstarue0_rec
USE control_ph, ONLY : nbnd_occ
USE units_ph, ONLY : iudwf, lrdwf, iuwfc, lrwfc
implicit none
integer, intent(in) :: imode0, npe
integer :: ibnd, jpol, ipert, nrec, mode, ik
! counter on bands
! counter on polarization
! counter on pertubations
! counter on records
! counter on modes
! counter on k points
real(DP) :: weight
complex(DP), external :: zdotc
call start_clock('add_zstar_ue')
zstarue0_rec=(0.0_DP,0.0_DP)
if (nksq.gt.1) rewind (iunigk)
do ik = 1, nksq
if (nksq.gt.1) read (iunigk) npw, igk
npwq = npw
weight = wk (ik)
if (nksq.gt.1) call get_buffer (evc, lrwfc, iuwfc, ik)
call init_us_2 (npw, igk, xk (1, ik), vkb)
do jpol = 1, 3
!
! read/compute DeltaV*psi(bare) for electric field
!
call dvpsi_e (ik, jpol)
!
do ipert = 1, npe
mode = imode0 + ipert
nrec = (ipert - 1) * nksq + ik
!
! read dpsi(scf)/du for phonon mode # mode
!
call get_buffer (dpsi, lrdwf, iudwf, nrec)
do ibnd = 1, nbnd_occ(ik)
zstarue0_rec (mode, jpol) = zstarue0_rec (mode, jpol) - 2.d0 * weight * &
zdotc (npw, dpsi (1, ibnd), 1, dvpsi (1, ibnd), 1)
IF (noncolin) &
zstarue0_rec(mode,jpol)=zstarue0_rec (mode, jpol) - 2.d0 * weight * &
zdotc (npw, dpsi (1+npwx, ibnd), 1, dvpsi (1+npwx, ibnd), 1)
enddo
enddo
enddo
enddo
call stop_clock('add_zstar_ue')
return
end subroutine add_zstar_ue
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/use_only_3.f90 | 50 | 1300 | ! { dg-do compile }
! This tests the patch for PR34975, in which 'n', 'ipol', and 'i' would be
! determined to have 'no IMPLICIT type'. It turned out to be fiendishly
! difficult to write a testcase for this PR because even the smallest changes
! would make the bug disappear. This is the testcase provided in the PR, except
! that all the modules are put in 'use_only_3.inc' in the same order as the
! makefile. Even this has an effect; only 'n' is now determined to be
! improperly typed. All this is due to the richness of the symtree and the
! way in which the renaming inserted new symtree entries. Unless somenody can
! come up with a reduced version, this relatively large file will have to be added
! to the testsuite. Fortunately, it only has to be comiled once:)
!
! Reported by Tobias Burnus <burnus@gcc.gnu.org>
!
include 'use_only_3.inc'
subroutine dforceb(c0, i, betae, ipol, bec0, ctabin, gqq, gqqm, qmat, dq2, df)
use gvecs
use gvecw, only: ngw
use parameters
use electrons_base, only: nx => nbspx, n => nbsp, nspin, f
use constants
use cvan
use ions_base
use ions_base, only : nas => nax
implicit none
integer ipol, i, ctabin
complex c0(n), betae, df,&
& gqq,gqqm,&
& qmat
real bec0,&
& dq2, gmes
end subroutine dforceb
| gpl-2.0 |
fthoele/espresso-5.4.0 | CPV/src/smallbox_lib.f90 | 10 | 6836 | !
! Copyright (C) 2002-2011 Quantum ESPRESSO groups
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!-----------------------------------------------------------------------
SUBROUTINE initbox ( tau0, alat, at, ainv, taub, irb )
!-----------------------------------------------------------------------
!
! sets the indexes irb and positions taub for the small boxes
! around atoms
!
USE kinds, ONLY: DP
USE ions_base, ONLY: nsp, na, nat
USE control_flags, ONLY: iverbosity
USE io_global, ONLY: stdout
USE mp_global, ONLY: nproc_bgrp, me_bgrp, intra_bgrp_comm
USE fft_base, ONLY: dfftb, dfftp, dfftb, fft_dlay_descriptor
USE fft_types, ONLY: fft_box_set
IMPLICIT NONE
! input
REAL(DP), INTENT(in) :: tau0(3,nat), at(3,3), ainv(3,3), alat
! output
INTEGER, INTENT(out) :: irb(3,nat)
REAL(DP), INTENT(out) :: taub(3,nat)
! local
REAL(DP) :: x(3), xmod
INTEGER :: nr(3), nrb(3), xint, is, ia, i, isa
!
IF ( dfftb%nr1 < 1) CALL errore &
('initbox', 'incorrect value for box grid dimensions', 1)
IF ( dfftb%nr2 < 1) CALL errore &
('initbox', 'incorrect value for box grid dimensions', 2)
IF ( dfftb%nr3 < 1) CALL errore &
('initbox', 'incorrect value for box grid dimensions', 3)
nr (1)=dfftp%nr1
nr (2)=dfftp%nr2
nr (3)=dfftp%nr3
nrb(1)=dfftb%nr1
nrb(2)=dfftb%nr2
nrb(3)=dfftb%nr3
!
isa = 0
DO is=1,nsp
DO ia=1,na(is)
isa = isa + 1
!
DO i=1,3
!
! bring atomic positions to crystal axis
!
x(i) = ainv(i,1)*tau0(1,isa) + &
& ainv(i,2)*tau0(2,isa) + &
& ainv(i,3)*tau0(3,isa)
!
! bring x in the range between 0 and 1
!
x(i) = MOD(x(i),1.d0)
IF (x(i).LT.0.d0) x(i)=x(i)+1.d0
!
! case of nrb(i) even
!
IF (MOD(nrb(i),2).EQ.0) THEN
!
! find irb = index of the grid point at the corner of the small box
! (the indices of the small box run from irb to irb+nrb-1)
!
xint=INT(x(i)*nr(i))
irb (i,isa)=xint+1-nrb(i)/2+1
IF(irb(i,isa).LT.1) irb(i,isa)=irb(i,isa)+nr(i)
!
! x(i) are the atomic positions in crystal coordinates, where the
! "crystal lattice" is the small box lattice and the origin is at
! the corner of the small box. Used to calculate phases exp(iG*taub)
!
xmod=x(i)*nr(i)-xint
x(i)=(xmod+nrb(i)/2-1)/nr(i)
ELSE
!
! case of nrb(i) odd - see above for comments
!
xint=NINT(x(i)*nr(i))
irb (i,isa)=xint+1-(nrb(i)-1)/2
IF(irb(i,isa).LT.1) irb(i,isa)=irb(i,isa)+nr(i)
xmod=x(i)*nr(i)-xint
x(i)=(xmod+(nrb(i)-1)/2)/nr(i)
END IF
END DO
!
! bring back taub in cartesian coordinates
!
DO i=1,3
taub(i,isa)=(x(1)*at(i,1) + x(2)*at(i,2) + x(3)*at(i,3))*alat
END DO
END DO
END DO
! initialize FFT descriptor
CALL fft_box_set( dfftb, dfftb%nr1, dfftb%nr2, dfftb%nr3, dfftb%nr1x, dfftb%nr2x, dfftb%nr3x, &
nat, irb, dfftp%npp, dfftp%ipp )
IF( iverbosity > 1 ) THEN
isa = 1
DO is=1,nsp
WRITE( stdout, '( /, 2x, "species= ", i2 )' ) is
DO ia=1,na(is)
WRITE( stdout,2000) ia, (irb(i,isa),i=1,3)
2000 FORMAT(2x, 'atom= ', i3, ' irb1= ', i3, ' irb2= ', i3, ' irb3= ', i3)
isa = isa + 1
END DO
END DO
ENDIF
#ifdef __MPI
!
! for processor that do not call fft on the box
! artificially start the clock
!
CALL start_clock( 'fftb' )
CALL stop_clock( 'fftb' )
!
#endif
!
RETURN
END SUBROUTINE initbox
!
!-----------------------------------------------------------------------
SUBROUTINE phbox( taub, iverbosity, eigrb )
!-----------------------------------------------------------------------
! calculates the phase factors for the g's of the little box
! eigrt=exp(-i*g*tau) .
! Uses the same logic for fast calculation as in phfac
!
USE kinds, only: DP
use io_global, only: stdout
use ions_base, only: nsp, na, nat
use cell_base, only: r_to_s
use cp_interfaces, only: phfacs
use small_box, only: bgb, alatb
use smallbox_gvec, only: ngb, mill_b
use fft_base, only: dfftb
!
IMPLICIT NONE
REAL(DP), INTENT(IN) :: taub(3,nat)
COMPLEX(DP), INTENT(OUT) :: eigrb(ngb,nat)
INTEGER, INTENT(IN) :: iverbosity
! local
REAL(DP) :: ainvb(3,3)
integer :: i,j,k, is, ia, ig, isa
complex(dp), allocatable:: ei1b(:,:), ei2b(:,:), ei3b(:,:)
real(dp), allocatable :: taus(:,:)
!
allocate(ei1b(-dfftb%nr1:dfftb%nr1,nat))
allocate(ei2b(-dfftb%nr2:dfftb%nr2,nat))
allocate(ei3b(-dfftb%nr3:dfftb%nr3,nat))
allocate( taus( 3, nat ) )
!
if(iverbosity > 2) then
WRITE( stdout,*) ' phbox: taub '
WRITE( stdout,*) ( (taub(i,isa), i=1, 3 ), isa=1, nat )
endif
ainvb(1,:) = bgb(:,1)/alatb
ainvb(2,:) = bgb(:,2)/alatb
ainvb(3,:) = bgb(:,3)/alatb
CALL r_to_s( taub, taus, na, nsp, ainvb )
CALL phfacs( ei1b, ei2b, ei3b, eigrb, mill_b, taus, dfftb%nr1,dfftb%nr2,dfftb%nr3, nat )
!
if(iverbosity > 2) then
WRITE( stdout,*)
if(nsp.gt.1) then
isa = 0
do is=1,nsp
WRITE( stdout,'(33x,a,i4)') ' ei1b, ei2b, ei3b (is)',is
do ig=1,4
WRITE( stdout,'(6f9.4)') &
& ei1b(ig,1+isa),ei2b(ig,1+isa),ei3b(ig,1+isa)
end do
WRITE( stdout,*)
isa = isa + na(is)
end do
else
do ia=1,na(1)
WRITE( stdout,'(33x,a,i4)') ' ei1b, ei2b, ei3b (ia)',ia
do ig=1,4
WRITE( stdout,'(6f9.4)') &
& ei1b(ig,ia),ei2b(ig,ia),ei3b(ig,ia)
end do
WRITE( stdout,*)
end do
endif
endif
!
deallocate(ei3b)
deallocate(ei2b)
deallocate(ei1b)
deallocate( taus )
!
RETURN
END SUBROUTINE phbox
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/gomp/pr35786-1.f90 | 155 | 2006 | ! PR fortran/35786
! { dg-do compile }
! { dg-options "-fopenmp" }
module pr35768
real, parameter :: one = 1.0
contains
subroutine fn1
!$omp parallel firstprivate (one) ! { dg-error "is not a variable" }
!$omp end parallel
end subroutine fn1
subroutine fn2 (doit)
external doit
!$omp parallel firstprivate (doit) ! { dg-error "is not a variable" }
call doit ()
!$omp end parallel
end subroutine fn2
subroutine fn3
interface fn4
subroutine fn4 ()
end subroutine fn4
end interface
!$omp parallel private (fn4) ! { dg-error "is not a variable" }
call fn4 ()
!$omp end parallel
end subroutine fn3
subroutine fn5
interface fn6
function fn6 ()
integer :: fn6
end function fn6
end interface
integer :: x
!$omp parallel private (fn6, x) ! { dg-error "is not a variable" }
x = fn6 ()
!$omp end parallel
end subroutine fn5
function fn7 () result (re7)
integer :: re7
!$omp parallel private (fn7) ! { dg-error "is not a variable" }
!$omp end parallel
end function fn7
function fn8 () result (re8)
integer :: re8
call fn9
contains
subroutine fn9
!$omp parallel private (fn8) ! { dg-error "is not a variable" }
!$omp end parallel
end subroutine fn9
end function fn8
function fn10 () result (re10)
integer :: re10, re11
entry fn11 () result (re11)
!$omp parallel private (fn10) ! { dg-error "is not a variable" }
!$omp end parallel
!$omp parallel private (fn11) ! { dg-error "is not a variable" }
!$omp end parallel
end function fn10
function fn12 () result (re12)
integer :: re12, re13
entry fn13 () result (re13)
call fn14
contains
subroutine fn14
!$omp parallel private (fn12) ! { dg-error "is not a variable" }
!$omp end parallel
!$omp parallel private (fn13) ! { dg-error "is not a variable" }
!$omp end parallel
end subroutine fn14
end function fn12
end module
| gpl-2.0 |
nvarini/espresso_adios | TDDFPT/src/lr_test_restart.f90 | 5 | 5165 | !
! Copyright (C) 2001-2015 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!-----------------------------------------------------------------------
LOGICAL FUNCTION test_restart(test_this)
!
! This function tests whether the restart flag is applicable
! Written by O. B. Malcioglu
!
USE lr_variables, ONLY : n_ipol,LR_polarization,restart,bgz_suffix,eels
USE io_files, ONLY : prefix, tmp_dir, nd_nmbr, wfc_dir
USE mp, ONLY : mp_bcast, mp_barrier,mp_sum
USE mp_world, ONLY : world_comm
USE io_global, ONLY : ionode, ionode_id, stdout
IMPLICIT NONE
!
INTEGER, INTENT(in) :: test_this
CHARACTER(len=256) :: tempfile, filename, tmp_dir_saved
LOGICAL :: exst
CHARACTER(len=6), EXTERNAL :: int_to_char
INTEGER :: i, temp_restart
!
!test_this= 1 : d0psi files
!test_this= 2 : Lanczos restart files
!
temp_restart = 0
!
IF (.not.restart) THEN
test_restart = .false.
RETURN
ENDIF
!
test_restart = .true.
!
! d0psi files
!
IF (test_this == 1) THEN
!
! Check for parallel i/o files that are in wfc_dir
!
tmp_dir_saved = tmp_dir
!
IF ( wfc_dir /= 'undefined' ) tmp_dir = wfc_dir
!
IF ( n_ipol == 1 ) THEN
!
filename = trim(prefix)//'.d0psi.'//trim(int_to_char(LR_polarization))
tempfile = trim(tmp_dir) // trim(filename) //nd_nmbr
INQUIRE (file = tempfile, exist = exst)
IF (.not. exst) THEN
temp_restart = 1
ENDIF
!
ELSE
!
DO i = 1, n_ipol
!
filename = trim(prefix)//'.d0psi.'//trim(int_to_char(i))
tempfile = trim(tmp_dir) // trim(filename) //nd_nmbr
INQUIRE (file = tempfile, exist = exst)
IF (.not. exst) THEN
temp_restart = 1
ENDIF
!
ENDDO
!
ENDIF
!
tmp_dir = tmp_dir_saved
!
IF ( wfc_dir /= 'undefined' ) THEN
!
! Check if these files can be read from outdir instead of wfcdir
!
IF ( n_ipol == 1 ) THEN
!
filename = trim(prefix)//'.d0psi.'//trim(int_to_char(LR_polarization))
tempfile = trim(tmp_dir) // trim(filename) //nd_nmbr
INQUIRE (file = tempfile, exist = exst)
IF (exst) THEN
temp_restart = 0
ENDIF
!
ELSE
!
DO i = 1, n_ipol
!
filename = trim(prefix)//'.d0psi.'//trim(int_to_char(i))
tempfile = trim(tmp_dir) // trim(filename) //nd_nmbr
INQUIRE (file = tempfile, exist = exst)
IF (exst) THEN
temp_restart = 0
ENDIF
!
ENDDO
!
ENDIF
ENDIF
!
ENDIF ! for test_this = 1
!
! Lanczos restart files
!
IF (test_this == 2) THEN
!
! Restart files are always written in outdir
!
IF ( n_ipol == 1 ) THEN
filename = trim(prefix)//'.restart_lanczos.'//trim(int_to_char(LR_polarization))
tempfile = trim(tmp_dir) // trim(filename) //nd_nmbr
ELSE
filename = trim(prefix)//'.restart_lanczos.'//trim(int_to_char(LR_polarization))
tempfile = trim(tmp_dir) // trim(filename)//nd_nmbr
ENDIF
!
INQUIRE (file = tempfile, exist = exst)
!
IF (.not. exst) THEN
temp_restart = 1
ENDIF
!
! End of parallel file i/o
!
IF (eels) THEN
filename = trim(prefix) // trim(bgz_suffix) // trim("dat")
ELSE
IF ( n_ipol == 1 ) THEN
filename = trim(prefix) // trim(bgz_suffix) // trim(int_to_char(LR_polarization))
ELSE
filename = trim(prefix) // trim(bgz_suffix) // trim(int_to_char(LR_polarization))
ENDIF
ENDIF
!
tempfile = trim(tmp_dir) // trim(filename)
!
INQUIRE (file = tempfile, exist = exst)
!
IF (.not. exst) THEN
temp_restart = 1
ENDIF
!
ENDIF ! for test_this = 2
!
#ifdef __MPI
CALL mp_sum(temp_restart,world_comm)
#endif
!
IF (temp_restart > 0 ) THEN
!
WRITE(stdout,'(5X,"There are missing files!")')
!
IF (test_this==1) WRITE(stdout,'(5X,"d0psi files can not be found, &
& trying to recompansate")')
IF (test_this==2) WRITE(stdout,'(5X,"Lanczos restart files &
& can not be found, starting run from scratch")')
!
test_restart = .false.
!
ENDIF
!
RETURN
!
END FUNCTION test_restart
!-------------------------------------------------------------------------------
| gpl-2.0 |
pschella/scipy | scipy/interpolate/fitpack/fpinst.f | 148 | 2019 | subroutine fpinst(iopt,t,n,c,k,x,l,tt,nn,cc,nest)
c given the b-spline representation (knots t(j),j=1,2,...,n, b-spline
c coefficients c(j),j=1,2,...,n-k-1) of a spline of degree k, fpinst
c calculates the b-spline representation (knots tt(j),j=1,2,...,nn,
c b-spline coefficients cc(j),j=1,2,...,nn-k-1) of the same spline if
c an additional knot is inserted at the point x situated in the inter-
c val t(l)<=x<t(l+1). iopt denotes whether (iopt.ne.0) or not (iopt=0)
c the given spline is periodic. in case of a periodic spline at least
c one of the following conditions must be fulfilled: l>2*k or l<n-2*k.
c
c ..scalar arguments..
integer k,n,l,nn,iopt,nest
real*8 x
c ..array arguments..
real*8 t(nest),c(nest),tt(nest),cc(nest)
c ..local scalars..
real*8 fac,per,one
integer i,i1,j,k1,m,mk,nk,nk1,nl,ll
c ..
one = 0.1e+01
k1 = k+1
nk1 = n-k1
c the new knots
ll = l+1
i = n
do 10 j=ll,n
tt(i+1) = t(i)
i = i-1
10 continue
tt(ll) = x
do 20 j=1,l
tt(j) = t(j)
20 continue
c the new b-spline coefficients
i = nk1
do 30 j=l,nk1
cc(i+1) = c(i)
i = i-1
30 continue
i = l
do 40 j=1,k
m = i+k1
fac = (x-tt(i))/(tt(m)-tt(i))
i1 = i-1
cc(i) = fac*c(i)+(one-fac)*c(i1)
i = i1
40 continue
do 50 j=1,i
cc(j) = c(j)
50 continue
nn = n+1
if(iopt.eq.0) return
c incorporate the boundary conditions for a periodic spline.
nk = nn-k
nl = nk-k1
per = tt(nk)-tt(k1)
i = k1
j = nk
if(ll.le.nl) go to 70
do 60 m=1,k
mk = m+nl
cc(m) = cc(mk)
i = i-1
j = j-1
tt(i) = tt(j)-per
60 continue
return
70 if(ll.gt.(k1+k)) return
do 80 m=1,k
mk = m+nl
cc(mk) = cc(m)
i = i+1
j = j+1
tt(j) = tt(i)+per
80 continue
return
end
| bsd-3-clause |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/maxval_parameter_1.f90 | 19 | 2270 | ! { dg-do run }
! Test for run-time simplification of maxval
program main
implicit none
integer, dimension(2,3), parameter :: i = &
& reshape([-1,2,-3,5,-7,11], shape(i))
integer, dimension(3), parameter :: im1 = maxval(i,dim=1)
integer, parameter :: im2 = maxval(i,mask=i<0)
integer, dimension(2), parameter :: im3 = maxval(i,dim=2)
integer, parameter :: im4 = maxval(i, mask=i<-1)
integer, dimension(3), parameter :: im5 = maxval(i,dim=1,mask=i<-2)
integer, dimension(2), parameter :: im6 = maxval(i,dim=2,mask=i<0)
real, dimension(2,3), parameter :: r = &
& reshape([-1.,2.,-3.,5.,-7.,11.], shape(r))
real, dimension(3), parameter :: rm1 = maxval(r,dim=1)
real, parameter :: rm2 = maxval(r,mask=r<0)
real, dimension(2), parameter :: rm3 = maxval(r,dim=2)
real, parameter :: rm4 = maxval(r, mask=r<-1)
real, dimension(3), parameter :: rm5 = maxval(r,dim=1,mask=r<-2)
real, dimension(2), parameter :: rm6 = maxval(r,dim=2,mask=r<0)
character(len=3), parameter :: minv = achar(0) // achar(0) // achar(0)
character(len=3), dimension(2,3), parameter :: c = &
reshape(["asd", "fgh", "qwe", "jkl", "ert", "zui"], shape(c))
character(len=3), parameter :: cm1 = maxval(c)
character(len=3), dimension(3), parameter :: cm2 = maxval(c,dim=1)
character(len=3), dimension(2), parameter :: cm3 = maxval(c,dim=2)
character(len=3), parameter :: cm4 = maxval (c, c<"g")
character(len=3), dimension(3), parameter :: cm5 = maxval(c,dim=1,mask=c<"p")
if (any (im1 /= [ 2, 5, 11])) STOP 1
if (im2 /= -1) STOP 2
if (any (im3 /= [ -1,11])) STOP 3
if (im4 /= -3) STOP 4
if (any (im5 /= [-huge(im5)-1, -3, -7])) STOP 5! { dg-warning "Integer outside symmetric range" }
if (any (im6 /= [-1, -huge(im6)-1])) STOP 6! { dg-warning "Integer outside symmetric range" }
if (any (rm1 /= [ 2., 5., 11.])) STOP 7
if (rm2 /= -1.) STOP 8
if (any (rm3 /= [ -1.,11.])) STOP 9
if (rm4 /= -3.) STOP 10
if (any (rm5 /= [-huge(rm5), -3., -7.])) STOP 11
if (any (rm6 /= [-1.,-huge(rm6)])) STOP 12
if (cm1 /= "zui") STOP 13
if (any (cm2 /= ["fgh", "qwe", "zui" ])) STOP 14
if (any (cm3 /= ["qwe", "zui" ])) STOP 15
if (cm4 /= "fgh") STOP 16
if (any(cm5 /= [ "fgh", "jkl", "ert" ] )) STOP 17
end program main
| gpl-2.0 |
pschella/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 |
ars599/mom5 | src/mom5/ocean_diag/ocean_diagnostics.F90 | 6 | 6500 | module ocean_diagnostics_mod
!
!<CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> S.M. Griffies
!</CONTACT>
!
!<OVERVIEW>
! Routine that calls the various numerical diagnostics.
!</OVERVIEW>
!
!<DESCRIPTION>
! Routine that calls the various numerical diagnostics.
! </DESCRIPTION>
!
use diag_manager_mod, only: need_data
use fms_mod, only: open_namelist_file, check_nml_error, close_file, write_version_number
use fms_mod, only: FATAL, stdout, stdlog
use mpp_mod, only: input_nml_file, mpp_error
use mpp_mod, only: mpp_clock_id, mpp_clock_begin, mpp_clock_end, CLOCK_MODULE
use time_manager_mod, only: time_type, increment_time
use ocean_adv_vel_diag_mod, only: ocean_adv_vel_diag_init, ocean_adv_vel_diagnostics
use ocean_domains_mod, only: get_local_indices
use ocean_tracer_diag_mod, only: ocean_tracer_diag_init, ocean_tracer_diagnostics
use ocean_types_mod, only: ocean_prog_tracer_type, ocean_diag_tracer_type
use ocean_types_mod, only: ocean_domain_type, ocean_grid_type
use ocean_types_mod, only: ocean_adv_vel_type, ocean_velocity_type
use ocean_types_mod, only: ocean_time_type, ocean_time_steps_type
use ocean_types_mod, only: ocean_external_mode_type, ocean_density_type
use ocean_types_mod, only: ocean_thickness_type, ocean_lagrangian_type
use ocean_velocity_diag_mod, only: ocean_velocity_diag_init, ocean_velocity_diagnostics
implicit none
private
#include <ocean_memory.h>
integer :: num_prog_tracers = 0
integer :: index_temp = -1
integer :: index_salt = -1
! for diagnostics clocks
integer :: id_adv_vel_diag
integer :: id_tracer_diag
integer :: id_velocity_diag
logical :: module_is_initialized = .FALSE.
character(len=128) :: version=&
'$Id: ocean_diagnostics.F90,v 20.0 2013/12/14 00:12:51 fms Exp $'
character (len=128) :: tagname = &
'$Name: tikal $'
public :: ocean_diag_init, ocean_diagnostics
contains
!#######################################################################
! <SUBROUTINE NAME="ocean_diag_init">
!
! <DESCRIPTION>
! Initialize the ocean_diag module.
! </DESCRIPTION>
!
subroutine ocean_diag_init(Grid, Domain, Time, Time_steps, Thickness, T_prog, T_diag, Dens, &
vert_coordinate_class, horz_grid, have_obc, cmip_units, use_blobs)
type(ocean_grid_type), intent(in) :: Grid
type(ocean_domain_type), intent(in) :: Domain
type(ocean_time_type), intent(in) :: Time
type(ocean_time_steps_type), intent(in) :: Time_steps
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_diag_tracer_type), intent(in) :: T_diag(:)
type(ocean_density_type), intent(inout) :: Dens
integer, intent(in) :: vert_coordinate_class
integer, intent(in) :: horz_grid
logical, intent(in) :: have_obc
logical, intent(in) :: cmip_units
logical, intent(in) :: use_blobs
integer :: n
integer :: stdoutunit,stdlogunit
stdoutunit=stdout();stdlogunit=stdlog()
module_is_initialized = .TRUE.
call write_version_number(version, tagname)
#ifndef MOM_STATIC_ARRAYS
call get_local_indices(Domain, isd, ied, jsd, jed, isc, iec, jsc, jec)
nk = Grid%nk
#endif
num_prog_tracers = size(T_prog, 1)
do n = 1, num_prog_tracers
if (trim(T_prog(n)%name) == 'temp') index_temp = n
if (trim(T_prog(n)%name) == 'salt') index_salt = n
enddo
if (index_temp < 1 .or. index_salt < 1) then
call mpp_error(FATAL,'==>Error in ocean_diagnostics_mod (ocean_diag_init): temp and/or salt not in tracer array')
endif
id_adv_vel_diag = mpp_clock_id('(Ocean diagnostics: adv_vel)' ,grain=CLOCK_MODULE)
id_tracer_diag = mpp_clock_id('(Ocean diagnostics: tracer)' ,grain=CLOCK_MODULE)
id_velocity_diag = mpp_clock_id('(Ocean diagnostics: velocity)' ,grain=CLOCK_MODULE)
call ocean_adv_vel_diag_init (Grid, Domain, Time, Time_steps, T_prog, Dens, horz_grid, cmip_units)
call ocean_tracer_diag_init (Grid, Domain, Time, Time_steps, Thickness, T_prog, T_diag, Dens, &
vert_coordinate_class, use_blobs, have_obc)
call ocean_velocity_diag_init(Grid, Domain, Time, Time_steps, horz_grid)
end subroutine ocean_diag_init
! </SUBROUTINE> NAME="ocean_diag_init"
!#######################################################################
! <SUBROUTINE NAME="ocean_diagnostics">
!
! <DESCRIPTION>
! Call some ocean numerical diagnostics
! </DESCRIPTION>
!
subroutine ocean_diagnostics(Time, Thickness, T_prog, T_diag, Adv_vel,&
Ext_mode, Dens, Velocity, &
pme, melt, runoff, calving, visc_cbt, diff_cbt)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_diag_tracer_type), intent(in) :: T_diag(:)
type(ocean_adv_vel_type), intent(in) :: Adv_vel
type(ocean_external_mode_type), intent(in) :: Ext_mode
type(ocean_density_type), intent(inout) :: Dens
type(ocean_velocity_type), intent(inout) :: Velocity
real, dimension(isd:,jsd:), intent(in) :: pme
real, dimension(isd:,jsd:), intent(in) :: melt
real, dimension(isd:,jsd:), intent(in) :: runoff
real, dimension(isd:,jsd:), intent(in) :: calving
real, dimension(isd:,jsd:,:), intent(in) :: visc_cbt
real, dimension(isd:,jsd:,:,:),intent(in) :: diff_cbt
if (size(T_prog,1) /= num_prog_tracers) then
call mpp_error(FATAL, '==>Error from ocean_diagnostics_mod (ocean_diagnostics): wrong size for tracer array')
endif
call mpp_clock_begin(id_adv_vel_diag)
call ocean_adv_vel_diagnostics(Time, Thickness, Adv_vel, T_prog, Dens, visc_cbt)
call mpp_clock_end(id_adv_vel_diag)
call mpp_clock_begin(id_tracer_diag)
call ocean_tracer_diagnostics(Time, Thickness, T_prog, T_diag, Dens, &
Ext_mode, Velocity, Adv_vel, &
diff_cbt, pme, melt, runoff, calving)
call mpp_clock_end(id_tracer_diag)
call mpp_clock_begin(id_velocity_diag)
call ocean_velocity_diagnostics(Time, Thickness, Dens, Ext_mode, Velocity)
call mpp_clock_end(id_velocity_diag)
end subroutine ocean_diagnostics
! </SUBROUTINE> NAME="ocean_diagnostics"
end module ocean_diagnostics_mod
| gpl-2.0 |
nvarini/espresso_adios | PW/tools/kpoints.f90 | 12 | 7824 | !
! Copyright (C) 2010 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!
!-----------------------------------------------------------------------
program special_points
!-----======================--------------------------------------------
!
! calculates special points for any structure,
! the default definition for the mesh is a shift of 1/(2n_i)
! where the length of b_i is equal to 1
!_______________________________________________________________________
!
use kinds, only: dp
use cell_base, only: at, bg
use symm_base, only: set_sym_bl, s, nrot
implicit none
integer, parameter :: nptx=20000
character(len=30) :: filout
character(len=1) :: answer
real(dp) :: celldm(6), xk(3,nptx), xkw(nptx), omega
integer :: k(3,nptx), kw(nptx), ieq(nptx), i,j,l, n1,n2,n3
integer :: ibrav, nmax(3), nshift(3), nstart(3),n,n6,nf,nk,nptot
logical :: aflag, sflag
!
write(*,1)
1 format(/,5x,'***************************************************',/,&
5x,'* *',/,&
5x,'* Welcome to the special points world! *',/,&
5x,'*________________________________________________ *',/,&
5x,'* 1 = cubic p (sc ) 8 = orthor p (so ) *',/,&
5x,'* 2 = cubic f (fcc) 9 = orthor base-cent. *',/,&
5x,'* 3 = cubic i (bcc) 10 = orthor face-cent. *',/,&
5x,'* 4 = hex & trig p 11 = orthor body-cent. *',/,&
5x,'* 5 = trigonal r 12 = monoclinic p *',/,&
5x,'* 6 = tetrag p (st ) 13 = monocl base-cent. *',/,&
5x,'* 7 = tetrag i (bct) 14 = triclinic p *',/,&
5x,'***************************************************',/ )
!
!.....default values
!
celldm(1)=1.d0
do i=1,3
nshift(i)=0
enddo
!
write(*,'(5x,a)', advance="no") 'bravais lattice >> '
read(*,*) ibrav
!
write(*,'(5x,a)',advance="no") 'filout [mesh_k] >> '
read(*,'(a)') filout
if (filout.eq.' ') filout='mesh_k'
open(unit=1,file=filout,status='unknown')
open(unit=2,file='info',status='unknown')
!
if(ibrav.eq.4 .or. ibrav.gt.5) then
write(*,'(5x,a)',advance="no") 'enter celldm(3) >> '
read(*,*) celldm(3)
end if
if(ibrav.ge.8) then
write(*,'(5x,a)',advance="no") 'enter celldm(2) >> '
read(*,*) celldm(2)
end if
if(ibrav.eq.5 .or. ibrav.ge.12) then
write(*,'(5x,a)',advance="no") 'enter celldm(4) >> '
read(*,*) celldm(4)
end if
if(ibrav.eq.14) then
write(*,'(5x,a)') 'enter celldm(5) >> cos(ac)'
write(*,'(5x,a)',advance="no") 'enter celldm(5) >> '
read(*,*) celldm(5)
write(*,'(5x,a)') 'enter celldm(6) >> cos(ab)'
write(*,'(5x,a)',advance="no") 'enter celldm(6) >> '
read(*,*) celldm(6)
end if
!
write(*,'(5x,a)',advance="no") 'mesh: n1 n2 n3 >> '
read(*,*) nmax
nptot=nmax(1)*nmax(2)*nmax(3)
if(nptot.gt.nptx) then
write(*,'(5x,i6)') nptx
call errore('kpoints','nptx too small for this mesh',1)
endif
write(*,'(5x,a)',advance="no") 'mesh: k1 k2 k3 (0 no shift, 1 shifted) >> '
read(*,*) nshift(1), nshift(2), nshift(3)
!
write(*,'(5x,a)',advance="no") 'write all k? [f] >> '
read(*,'(a1)') answer
aflag= answer.eq.'t'.or.answer.eq.'T' .or. &
answer.eq.'y'.or.answer.eq.'Y' .or. &
answer.eq.'1'
!
call latgen(ibrav,celldm,at(1,1),at(1,2),at(1,3),omega)
!
! normalize at to celldm(1) ( a0 for cubic lattices )
!
do i = 1, 3
at( i, 1 ) = at( i, 1 ) / celldm( 1 )
at( i, 2 ) = at( i, 2 ) / celldm( 1 )
at( i, 3 ) = at( i, 3 ) / celldm( 1 )
enddo
!
call recips(at(1,1),at(1,2),at(1,3),bg(1,1),bg(1,2),bg(1,3))
!
write(2,'(2x,''crystal axis: ''/3(2x,''('',3f7.4,'') ''/) )') &
((at(i,j), i=1,3), j=1,3)
write(2,'(2x,''reciprocal axis: ''/3(2x,''('',3f7.4,'') ''/) )') &
((bg(i,j), i=1,3), j=1,3)
write(2,*)' Omega (in a^3 units) = ',omega
!
!.......................................................................
!
call set_sym_bl ( )
!
write(2,'(//,1x,i3,2x,a19)') nrot,'symmetry operations'
do n6=0,(nrot-1)/6
nf=min(nrot-6*n6,6)
write(2,'(1x)')
do i=1,3
write(2,'(6(3i3,2x))') ((s(i,j,n6*6+n), j=1,3), n=1,nf)
end do
end do
!
sflag=.false.
do i=1,3
! shifted grid
if(nshift(i).eq.1) then
nshift(i)=2
nmax(i)=nshift(i)*nmax(i)
nstart(i)=1
sflag=.true.
else
! unshifted grid
nstart(i)=0
nshift(i)=1
end if
enddo
!
n=0
do n3=nstart(3),nmax(3)-1,nshift(3)
do n2=nstart(2),nmax(2)-1,nshift(2)
do n1=nstart(1),nmax(1)-1,nshift(1)
n=n+1
k(1,n)=n1
k(2,n)=n2
k(3,n)=n3
kw(n)=1
ieq(n)=0
call check(n,k,kw,ieq,s,nrot,nmax)
enddo
enddo
enddo
!
nk=0
write(2,'(/)')
do j=1,n
if(kw(j).gt.0.or.aflag) then
nk=nk+1
xkw(nk)=kw(j)
do l=1,3
xk(l,nk)=0.d0
do i=1,3
xk(l,nk)=xk(l,nk)+k(i,j)*bg(l,i)/nmax(i)
enddo
end do
write(2,2) j,k(1,j),k(2,j),k(3,j),kw(j),ieq(j)
2 format(' k(',i3,')=( ',i2,' ',i2,' ',i2,' ) --- weight=', &
i3,' |folds in point #',i3)
endif
enddo
!
write(*,'(/5x,a)',advance="no") '# of k-points == '
write(*,'(i5,a5,i5)') nk,' of ',n
write(*,'(2x)')
!
write(1,'(i5)') nk
do j=1,nk
if(aflag.and.kw(j).eq.0) then
write(1,'(i5,1x,3f11.7,f7.2,i4)') j,(xk(l,j),l=1,3),xkw(j),ieq(j)
else
write(1,'(i5,1x,3f11.7,f7.2)') j,(xk(l,j),l=1,3),xkw(j)
end if
end do
!
if(.not.sflag.and.kw(1).ne.1) then
write(*,'(5x,a)') '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
write(*,'(5x,a)') '!the considered mesh has not the correct symmetry!!'
write(*,'(5x,a/)') '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
endif
!
close(unit=1)
close(unit=2)
!
end program special_points
!
!-----------------------------------------------------------------------
subroutine check(n,k,kw,ieq,s,nrot,nmax)
!-----------------------------------------------------------------------
!
integer k(3,n),kw(n), s(3,3,nrot),kr(3),ieq(n),nmax(3)
logical flag
!
irot=1
flag=.true.
do while(irot.le.nrot.and.flag)
kr(1)=0
kr(2)=0
kr(3)=0
call ruotaijk ( s(1,1,irot),k(1,n),k(2,n),k(3,n),kr(1),kr(2),kr(3) )
do j=1,3
do while(kr(j).ge.nmax(j))
kr(j)=kr(j)-nmax(j)
enddo
do while(kr(j).le.-1)
kr(j)=kr(j)+nmax(j)
enddo
enddo
np=1
do while(flag.and.np.le.n-1)
if( kr(1).eq.k(1,np) .and. &
kr(2).eq.k(2,np) .and. &
kr(3).eq.k(3,np) ) then
kw(n)=0
naux =np
do while(kw(naux).eq.0)
naux=ieq(naux)
enddo
ieq(n)=naux
kw(naux)=kw(naux)+1
flag=.false.
endif
np=np+1
enddo
irot=irot+1
enddo
!
return
end subroutine check
!
!-----------------------------------------------------------------------
subroutine ruotaijk(s,i,j,k,ri,rj,rk)
!-----------------------------------------------------------------------
!
implicit real*8 (a-h, o-z)
integer s(3,3),i,j,k,ri,rj,rk
!
ri=s(1,1)*i+s(1,2)*j+s(1,3)*k
rj=s(2,1)*i+s(2,2)*j+s(2,3)*k
rk=s(3,1)*i+s(3,2)*j+s(3,3)*k
!
return
end subroutine ruotaijk
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/host_assoc_call_4.f90 | 155 | 1708 | ! { dg-do compile }
!
! PR fortran/37445, in which the first version of the fix regressed on the
! calls to GetBasicElementData; picking up the local GetBasicElementData instead.
!
! Contributed by Norman S Clerman < clerman@fuse.net>
! and reduced by Tobias Burnus <burnus@gcc.gnu.org>
!
MODULE ErrElmnt
IMPLICIT NONE
TYPE :: TErrorElement
integer :: i
end type TErrorElement
contains
subroutine GetBasicData ( AnElement, ProcedureName, ErrorNumber, &
Level, Message, ReturnStat)
type (TErrorElement) :: AnElement
character (*, 1), optional :: &
ProcedureName
integer (4), optional :: ErrorNumber
character (*, 1), optional :: Level
character (*, 1), optional :: Message
integer (4), optional :: ReturnStat
end subroutine GetBasicData
end module ErrElmnt
MODULE ErrorMod
USE ErrElmnt, only: GetBasicElementData => GetBasicData , TErrorElement
IMPLICIT NONE
contains
subroutine GetBasicData ()
integer (4) :: CallingStat, LocalErrorNum
character (20, 1) :: LocalErrorMessage
character (20, 1) :: LocalProcName
character (20, 1) :: Locallevel
type (TErrorElement) :: AnElement
call GetBasicElementData (AnElement, LocalProcName, LocalErrorNum, LocalLevel, LocalErrorMessage, CallingStat)
end subroutine GetBasicData
SUBROUTINE WH_ERR ()
integer (4) :: ErrorNumber, CallingStat
character (20, 1) :: ProcedureName
character (20, 1) :: ErrorLevel
character (20, 1) :: ErrorMessage
type (TErrorElement) :: TargetElement
call GetBasicElementData (TargetElement, ProcedureName, ErrorNumber, ErrorLevel, ErrorMessage, CallingStat)
end subroutine WH_ERR
end module ErrorMod
| gpl-2.0 |
ForestClaw/forestclaw | applications/elliptic/heat/fortran/heat_output.f90 | 1 | 3044 | subroutine heat_fort_header_ascii(matname1,matname2, time,meqn,maux,ngrids)
implicit none
integer meqn,ngrids, maux
character*11 matname1
character*11 matname2
double precision time
integer matunit1, matunit2
integer mfields
matunit1 = 10
matunit2 = 15
open(unit=matunit2,file=matname2)
mfields = meqn + 2 !! include soln, error
write(matunit2,1000) time,mfields,ngrids,maux,2
1000 format(e30.20,' time', /, &
i5,' mfields'/, &
i5,' ngrids'/, &
i5,' num_aux'/, &
i5,' num_dim')
close(matunit2)
open(unit=matunit1,file=matname1,status='replace')
close(matunit1)
end subroutine heat_fort_header_ascii
subroutine heat_fort_output_ascii(matname1, &
mx,my,meqn,mbc, xlower,ylower, dx,dy, &
q,soln,error,patch_num,level,blockno,mpirank)
implicit none
character(len=11) matname1
integer meqn,mbc,mx,my
integer patch_num
integer level, blockno, mpirank
double precision xlower, ylower,dx,dy
double precision q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)
double precision error(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)
double precision soln(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)
double precision qvec(3), dmax, heat_eval_refinement
integer matunit1
integer i,j,mq
matunit1 = 10
open(matunit1,file=matname1,position='append');
call fclaw2d_clawpatch46_fort_write_grid_header(matunit1, &
mx,my,xlower,ylower, dx,dy,patch_num,level, &
blockno,mpirank)
if (meqn .gt. 5) then
write(6,'(A,A,A,I5,A)') &
'Warning (fclaw2d_fort_write_grid_header.f) ', &
': meqn > 5; change format statement 120.', &
'(meqn = ',meqn,')'
stop
endif
do j = 1,my
do i = 1,mx
do mq = 1,meqn
if (abs(q(i,j,mq)) .lt. 1d-99) then
q(i,j,mq) = 0.d0
elseif (abs(q(i,j,mq)) .gt. 1d99) then
q(i,j,mq) = 1d99
endif
end do
!! if (abs(error(i,j,1)) .lt. 1d-99) then
!! error(i,j,1) = 0.d0
!! elseif (abs(error(i,j,1)) .gt. 1d99) then
!! error(i,j,1) = 1d99
!! if (abs(soln(i,j,1)) .lt. 1d-99) then
!! soln(i,j,1) = 0.d0
!! elseif (abs(soln(i,j,1)) .gt. 1d99) then
!! soln(i,j,1) = 1d99
!! endif
!! write(matunit1,120) (q(i,j,mq),mq=1,meqn), qlap, error(i,j,1)
!! endif
qvec(1) = q(i,j,1)
qvec(2) = q(i-1,j,1)
qvec(3) = q(i,j-1,1)
dmax = heat_eval_refinement(qvec,dx,dy)
write(matunit1,120) (q(i,j,mq),mq=1,meqn), dmax
end do
write(matunit1,*) ' '
end do
close(matunit1)
120 format (5E26.16)
!!121 format (3I5,6E24.16)
!!122 format (2I5,6E24.16)
end subroutine heat_fort_output_ascii
| bsd-2-clause |
bgin/MissileSimulation | External/SLICOT/dhgeqz.f | 1 | 44066 | SUBROUTINE DHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
$ ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
$ LWORK, INFO )
*
* -- LAPACK routine (version 3.2) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER COMPQ, COMPZ, JOB
INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ),
$ H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
$ WORK( * ), Z( LDZ, * )
* ..
*
* Purpose
* =======
*
* DHGEQZ computes the eigenvalues of a real matrix pair (H,T),
* where H is an upper Hessenberg matrix and T is upper triangular,
* using the double-shift QZ method.
* Matrix pairs of this type are produced by the reduction to
* generalized upper Hessenberg form of a real matrix pair (A,B):
*
* A = Q1*H*Z1**T, B = Q1*T*Z1**T,
*
* as computed by DGGHRD.
*
* If JOB='S', then the Hessenberg-triangular pair (H,T) is
* also reduced to generalized Schur form,
*
* H = Q*S*Z**T, T = Q*P*Z**T,
*
* where Q and Z are orthogonal matrices, P is an upper triangular
* matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2
* diagonal blocks.
*
* The 1-by-1 blocks correspond to real eigenvalues of the matrix pair
* (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of
* eigenvalues.
*
* Additionally, the 2-by-2 upper triangular diagonal blocks of P
* corresponding to 2-by-2 blocks of S are reduced to positive diagonal
* form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0,
* P(j,j) > 0, and P(j+1,j+1) > 0.
*
* Optionally, the orthogonal matrix Q from the generalized Schur
* factorization may be postmultiplied into an input matrix Q1, and the
* orthogonal matrix Z may be postmultiplied into an input matrix Z1.
* If Q1 and Z1 are the orthogonal matrices from DGGHRD that reduced
* the matrix pair (A,B) to generalized upper Hessenberg form, then the
* output matrices Q1*Q and Z1*Z are the orthogonal factors from the
* generalized Schur factorization of (A,B):
*
* A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T.
*
* To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently,
* of (A,B)) are computed as a pair of values (alpha,beta), where alpha is
* complex and beta real.
* If beta is nonzero, lambda = alpha / beta is an eigenvalue of the
* generalized nonsymmetric eigenvalue problem (GNEP)
* A*x = lambda*B*x
* and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the
* alternate form of the GNEP
* mu*A*y = B*y.
* Real eigenvalues can be read directly from the generalized Schur
* form:
* alpha = S(i,i), beta = P(i,i).
*
* Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix
* Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973),
* pp. 241--256.
*
* Arguments
* =========
*
* JOB (input) CHARACTER*1
* = 'E': Compute eigenvalues only;
* = 'S': Compute eigenvalues and the Schur form.
*
* COMPQ (input) CHARACTER*1
* = 'N': Left Schur vectors (Q) are not computed;
* = 'I': Q is initialized to the unit matrix and the matrix Q
* of left Schur vectors of (H,T) is returned;
* = 'V': Q must contain an orthogonal matrix Q1 on entry and
* the product Q1*Q is returned.
*
* COMPZ (input) CHARACTER*1
* = 'N': Right Schur vectors (Z) are not computed;
* = 'I': Z is initialized to the unit matrix and the matrix Z
* of right Schur vectors of (H,T) is returned;
* = 'V': Z must contain an orthogonal matrix Z1 on entry and
* the product Z1*Z is returned.
*
* N (input) INTEGER
* The order of the matrices H, T, Q, and Z. N >= 0.
*
* ILO (input) INTEGER
* IHI (input) INTEGER
* ILO and IHI mark the rows and columns of H which are in
* Hessenberg form. It is assumed that A is already upper
* triangular in rows and columns 1:ILO-1 and IHI+1:N.
* If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0.
*
* H (input/output) DOUBLE PRECISION array, dimension (LDH, N)
* On entry, the N-by-N upper Hessenberg matrix H.
* On exit, if JOB = 'S', H contains the upper quasi-triangular
* matrix S from the generalized Schur factorization;
* 2-by-2 diagonal blocks (corresponding to complex conjugate
* pairs of eigenvalues) are returned in standard form, with
* H(i,i) = H(i+1,i+1) and H(i+1,i)*H(i,i+1) < 0.
* If JOB = 'E', the diagonal blocks of H match those of S, but
* the rest of H is unspecified.
*
* LDH (input) INTEGER
* The leading dimension of the array H. LDH >= max( 1, N ).
*
* T (input/output) DOUBLE PRECISION array, dimension (LDT, N)
* On entry, the N-by-N upper triangular matrix T.
* On exit, if JOB = 'S', T contains the upper triangular
* matrix P from the generalized Schur factorization;
* 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S
* are reduced to positive diagonal form, i.e., if H(j+1,j) is
* non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and
* T(j+1,j+1) > 0.
* If JOB = 'E', the diagonal blocks of T match those of P, but
* the rest of T is unspecified.
*
* LDT (input) INTEGER
* The leading dimension of the array T. LDT >= max( 1, N ).
*
* ALPHAR (output) DOUBLE PRECISION array, dimension (N)
* The real parts of each scalar alpha defining an eigenvalue
* of GNEP.
*
* ALPHAI (output) DOUBLE PRECISION array, dimension (N)
* The imaginary parts of each scalar alpha defining an
* eigenvalue of GNEP.
* If ALPHAI(j) is zero, then the j-th eigenvalue is real; if
* positive, then the j-th and (j+1)-st eigenvalues are a
* complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j).
*
* BETA (output) DOUBLE PRECISION array, dimension (N)
* The scalars beta that define the eigenvalues of GNEP.
* Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and
* beta = BETA(j) represent the j-th eigenvalue of the matrix
* pair (A,B), in one of the forms lambda = alpha/beta or
* mu = beta/alpha. Since either lambda or mu may overflow,
* they should not, in general, be computed.
*
* Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
* On entry, if COMPZ = 'V', the orthogonal matrix Q1 used in
* the reduction of (A,B) to generalized Hessenberg form.
* On exit, if COMPZ = 'I', the orthogonal matrix of left Schur
* vectors of (H,T), and if COMPZ = 'V', the orthogonal matrix
* of left Schur vectors of (A,B).
* Not referenced if COMPZ = 'N'.
*
* LDQ (input) INTEGER
* The leading dimension of the array Q. LDQ >= 1.
* If COMPQ='V' or 'I', then LDQ >= N.
*
* Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N)
* On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in
* the reduction of (A,B) to generalized Hessenberg form.
* On exit, if COMPZ = 'I', the orthogonal matrix of
* right Schur vectors of (H,T), and if COMPZ = 'V', the
* orthogonal matrix of right Schur vectors of (A,B).
* Not referenced if COMPZ = 'N'.
*
* LDZ (input) INTEGER
* The leading dimension of the array Z. LDZ >= 1.
* If COMPZ='V' or 'I', then LDZ >= N.
*
* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
* On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
*
* LWORK (input) INTEGER
* The dimension of the array WORK. LWORK >= max(1,N).
*
* If LWORK = -1, then a workspace query is assumed; the routine
* only calculates the optimal size of the WORK array, returns
* this value as the first entry of the WORK array, and no error
* message related to LWORK is issued by XERBLA.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* = 1,...,N: the QZ iteration did not converge. (H,T) is not
* in Schur form, but ALPHAR(i), ALPHAI(i), and
* BETA(i), i=INFO+1,...,N should be correct.
* = N+1,...,2*N: the shift calculation failed. (H,T) is not
* in Schur form, but ALPHAR(i), ALPHAI(i), and
* BETA(i), i=INFO-N+1,...,N should be correct.
*
* Further Details
* ===============
*
* Iteration counters:
*
* JITER -- counts iterations.
* IITER -- counts iterations run since ILAST was last
* changed. This is therefore reset only when a 1-by-1 or
* 2-by-2 block deflates off the bottom.
*
* =====================================================================
*
* .. Parameters ..
* $ SAFETY = 1.0E+0 )
DOUBLE PRECISION HALF, ZERO, ONE, SAFETY
PARAMETER ( HALF = 0.5D+0, ZERO = 0.0D+0, ONE = 1.0D+0,
$ SAFETY = 1.0D+2 )
* ..
* .. Local Scalars ..
LOGICAL ILAZR2, ILAZRO, ILPIVT, ILQ, ILSCHR, ILZ,
$ LQUERY
INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
$ ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
$ JR, MAXIT
DOUBLE PRECISION A11, A12, A1I, A1R, A21, A22, A2I, A2R, AD11,
$ AD11L, AD12, AD12L, AD21, AD21L, AD22, AD22L,
$ AD32L, AN, ANORM, ASCALE, ATOL, B11, B1A, B1I,
$ B1R, B22, B2A, B2I, B2R, BN, BNORM, BSCALE,
$ BTOL, C, C11I, C11R, C12, C21, C22I, C22R, CL,
$ CQ, CR, CZ, ESHIFT, S, S1, S1INV, S2, SAFMAX,
$ SAFMIN, SCALE, SL, SQI, SQR, SR, SZI, SZR, T1,
$ TAU, TEMP, TEMP2, TEMPI, TEMPR, U1, U12, U12L,
$ U2, ULP, VS, W11, W12, W21, W22, WABS, WI, WR,
$ WR2
* ..
* .. Local Arrays ..
DOUBLE PRECISION V( 3 )
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH, DLANHS, DLAPY2, DLAPY3
EXTERNAL LSAME, DLAMCH, DLANHS, DLAPY2, DLAPY3
* ..
* .. External Subroutines ..
EXTERNAL DLAG2, DLARFG, DLARTG, DLASET, DLASV2, DROT,
$ XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, MAX, MIN, SQRT
* ..
* .. Executable Statements ..
*
* Decode JOB, COMPQ, COMPZ
*
IF( LSAME( JOB, 'E' ) ) THEN
ILSCHR = .FALSE.
ISCHUR = 1
ELSE IF( LSAME( JOB, 'S' ) ) THEN
ILSCHR = .TRUE.
ISCHUR = 2
ELSE
ISCHUR = 0
END IF
*
IF( LSAME( COMPQ, 'N' ) ) THEN
ILQ = .FALSE.
ICOMPQ = 1
ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
ILQ = .TRUE.
ICOMPQ = 2
ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
ILQ = .TRUE.
ICOMPQ = 3
ELSE
ICOMPQ = 0
END IF
*
IF( LSAME( COMPZ, 'N' ) ) THEN
ILZ = .FALSE.
ICOMPZ = 1
ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
ILZ = .TRUE.
ICOMPZ = 2
ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
ILZ = .TRUE.
ICOMPZ = 3
ELSE
ICOMPZ = 0
END IF
*
* Check Argument Values
*
INFO = 0
WORK( 1 ) = MAX( 1, N )
LQUERY = ( LWORK.EQ.-1 )
IF( ISCHUR.EQ.0 ) THEN
INFO = -1
ELSE IF( ICOMPQ.EQ.0 ) THEN
INFO = -2
ELSE IF( ICOMPZ.EQ.0 ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( ILO.LT.1 ) THEN
INFO = -5
ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
INFO = -6
ELSE IF( LDH.LT.N ) THEN
INFO = -8
ELSE IF( LDT.LT.N ) THEN
INFO = -10
ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
INFO = -15
ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
INFO = -17
ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
INFO = -19
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DHGEQZ', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Quick return if possible
*
IF( N.LE.0 ) THEN
WORK( 1 ) = DBLE( 1 )
RETURN
END IF
*
* Initialize Q and Z
*
IF( ICOMPQ.EQ.3 )
$ CALL DLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
IF( ICOMPZ.EQ.3 )
$ CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
*
* Machine Constants
*
IN = IHI + 1 - ILO
SAFMIN = DLAMCH( 'S' )
SAFMAX = ONE / SAFMIN
ULP = DLAMCH( 'E' )*DLAMCH( 'B' )
ANORM = DLANHS( 'F', IN, H( ILO, ILO ), LDH, WORK )
BNORM = DLANHS( 'F', IN, T( ILO, ILO ), LDT, WORK )
ATOL = MAX( SAFMIN, ULP*ANORM )
BTOL = MAX( SAFMIN, ULP*BNORM )
ASCALE = ONE / MAX( SAFMIN, ANORM )
BSCALE = ONE / MAX( SAFMIN, BNORM )
*
* Set Eigenvalues IHI+1:N
*
DO 30 J = IHI + 1, N
IF( T( J, J ).LT.ZERO ) THEN
IF( ILSCHR ) THEN
DO 10 JR = 1, J
H( JR, J ) = -H( JR, J )
T( JR, J ) = -T( JR, J )
10 CONTINUE
ELSE
H( J, J ) = -H( J, J )
T( J, J ) = -T( J, J )
END IF
IF( ILZ ) THEN
DO 20 JR = 1, N
Z( JR, J ) = -Z( JR, J )
20 CONTINUE
END IF
END IF
ALPHAR( J ) = H( J, J )
ALPHAI( J ) = ZERO
BETA( J ) = T( J, J )
30 CONTINUE
*
* If IHI < ILO, skip QZ steps
*
IF( IHI.LT.ILO )
$ GO TO 380
*
* MAIN QZ ITERATION LOOP
*
* Initialize dynamic indices
*
* Eigenvalues ILAST+1:N have been found.
* Column operations modify rows IFRSTM:whatever.
* Row operations modify columns whatever:ILASTM.
*
* If only eigenvalues are being computed, then
* IFRSTM is the row of the last splitting row above row ILAST;
* this is always at least ILO.
* IITER counts iterations since the last eigenvalue was found,
* to tell when to use an extraordinary shift.
* MAXIT is the maximum number of QZ sweeps allowed.
*
ILAST = IHI
IF( ILSCHR ) THEN
IFRSTM = 1
ILASTM = N
ELSE
IFRSTM = ILO
ILASTM = IHI
END IF
IITER = 0
ESHIFT = ZERO
MAXIT = 30*( IHI-ILO+1 )
*
DO 360 JITER = 1, MAXIT
*
* Split the matrix if possible.
*
* Two tests:
* 1: H(j,j-1)=0 or j=ILO
* 2: T(j,j)=0
*
IF( ILAST.EQ.ILO ) THEN
*
* Special case: j=ILAST
*
GO TO 80
ELSE
IF( ABS( H( ILAST, ILAST-1 ) ).LE.ATOL ) THEN
H( ILAST, ILAST-1 ) = ZERO
GO TO 80
END IF
END IF
*
IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
T( ILAST, ILAST ) = ZERO
GO TO 70
END IF
*
* General case: j<ILAST
*
DO 60 J = ILAST - 1, ILO, -1
*
* Test 1: for H(j,j-1)=0 or j=ILO
*
IF( J.EQ.ILO ) THEN
ILAZRO = .TRUE.
ELSE
IF( ABS( H( J, J-1 ) ).LE.ATOL ) THEN
H( J, J-1 ) = ZERO
ILAZRO = .TRUE.
ELSE
ILAZRO = .FALSE.
END IF
END IF
*
* Test 2: for T(j,j)=0
*
IF( ABS( T( J, J ) ).LT.BTOL ) THEN
T( J, J ) = ZERO
*
* Test 1a: Check for 2 consecutive small subdiagonals in A
*
ILAZR2 = .FALSE.
IF( .NOT.ILAZRO ) THEN
TEMP = ABS( H( J, J-1 ) )
TEMP2 = ABS( H( J, J ) )
TEMPR = MAX( TEMP, TEMP2 )
IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
TEMP = TEMP / TEMPR
TEMP2 = TEMP2 / TEMPR
END IF
IF( TEMP*( ASCALE*ABS( H( J+1, J ) ) ).LE.TEMP2*
$ ( ASCALE*ATOL ) )ILAZR2 = .TRUE.
END IF
*
* If both tests pass (1 & 2), i.e., the leading diagonal
* element of B in the block is zero, split a 1x1 block off
* at the top. (I.e., at the J-th row/column) The leading
* diagonal element of the remainder can also be zero, so
* this may have to be done repeatedly.
*
IF( ILAZRO .OR. ILAZR2 ) THEN
DO 40 JCH = J, ILAST - 1
TEMP = H( JCH, JCH )
CALL DLARTG( TEMP, H( JCH+1, JCH ), C, S,
$ H( JCH, JCH ) )
H( JCH+1, JCH ) = ZERO
CALL DROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
$ H( JCH+1, JCH+1 ), LDH, C, S )
CALL DROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
$ T( JCH+1, JCH+1 ), LDT, C, S )
IF( ILQ )
$ CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
$ C, S )
IF( ILAZR2 )
$ H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
ILAZR2 = .FALSE.
IF( ABS( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
IF( JCH+1.GE.ILAST ) THEN
GO TO 80
ELSE
IFIRST = JCH + 1
GO TO 110
END IF
END IF
T( JCH+1, JCH+1 ) = ZERO
40 CONTINUE
GO TO 70
ELSE
*
* Only test 2 passed -- chase the zero to T(ILAST,ILAST)
* Then process as in the case T(ILAST,ILAST)=0
*
DO 50 JCH = J, ILAST - 1
TEMP = T( JCH, JCH+1 )
CALL DLARTG( TEMP, T( JCH+1, JCH+1 ), C, S,
$ T( JCH, JCH+1 ) )
T( JCH+1, JCH+1 ) = ZERO
IF( JCH.LT.ILASTM-1 )
$ CALL DROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
$ T( JCH+1, JCH+2 ), LDT, C, S )
CALL DROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
$ H( JCH+1, JCH-1 ), LDH, C, S )
IF( ILQ )
$ CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
$ C, S )
TEMP = H( JCH+1, JCH )
CALL DLARTG( TEMP, H( JCH+1, JCH-1 ), C, S,
$ H( JCH+1, JCH ) )
H( JCH+1, JCH-1 ) = ZERO
CALL DROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
$ H( IFRSTM, JCH-1 ), 1, C, S )
CALL DROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
$ T( IFRSTM, JCH-1 ), 1, C, S )
IF( ILZ )
$ CALL DROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
$ C, S )
50 CONTINUE
GO TO 70
END IF
ELSE IF( ILAZRO ) THEN
*
* Only test 1 passed -- work on J:ILAST
*
IFIRST = J
GO TO 110
END IF
*
* Neither test passed -- try next J
*
60 CONTINUE
*
* (Drop-through is "impossible")
*
INFO = N + 1
GO TO 420
*
* T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a
* 1x1 block.
*
70 CONTINUE
TEMP = H( ILAST, ILAST )
CALL DLARTG( TEMP, H( ILAST, ILAST-1 ), C, S,
$ H( ILAST, ILAST ) )
H( ILAST, ILAST-1 ) = ZERO
CALL DROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
$ H( IFRSTM, ILAST-1 ), 1, C, S )
CALL DROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
$ T( IFRSTM, ILAST-1 ), 1, C, S )
IF( ILZ )
$ CALL DROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
*
* H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI,
* and BETA
*
80 CONTINUE
IF( T( ILAST, ILAST ).LT.ZERO ) THEN
IF( ILSCHR ) THEN
DO 90 J = IFRSTM, ILAST
H( J, ILAST ) = -H( J, ILAST )
T( J, ILAST ) = -T( J, ILAST )
90 CONTINUE
ELSE
H( ILAST, ILAST ) = -H( ILAST, ILAST )
T( ILAST, ILAST ) = -T( ILAST, ILAST )
END IF
IF( ILZ ) THEN
DO 100 J = 1, N
Z( J, ILAST ) = -Z( J, ILAST )
100 CONTINUE
END IF
END IF
ALPHAR( ILAST ) = H( ILAST, ILAST )
ALPHAI( ILAST ) = ZERO
BETA( ILAST ) = T( ILAST, ILAST )
*
* Go to next block -- exit if finished.
*
ILAST = ILAST - 1
IF( ILAST.LT.ILO )
$ GO TO 380
*
* Reset counters
*
IITER = 0
ESHIFT = ZERO
IF( .NOT.ILSCHR ) THEN
ILASTM = ILAST
IF( IFRSTM.GT.ILAST )
$ IFRSTM = ILO
END IF
GO TO 350
*
* QZ step
*
* This iteration only involves rows/columns IFIRST:ILAST. We
* assume IFIRST < ILAST, and that the diagonal of B is non-zero.
*
110 CONTINUE
IITER = IITER + 1
IF( .NOT.ILSCHR ) THEN
IFRSTM = IFIRST
END IF
*
* Compute single shifts.
*
* At this point, IFIRST < ILAST, and the diagonal elements of
* T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in
* magnitude)
*
IF( ( IITER / 10 )*10.EQ.IITER ) THEN
*
* Exceptional shift. Chosen for no particularly good reason.
* (Single shift only.)
*
** IF( ( DBLE( MAXIT )*SAFMIN )*ABS( H( ILAST-1, ILAST ) ).LT.
** $ ABS( T( ILAST-1, ILAST-1 ) ) ) THEN
** ESHIFT = ESHIFT + H( ILAST-1, ILAST ) /
** $ T( ILAST-1, ILAST-1 )
** ELSE
** ESHIFT = ESHIFT + ONE / ( SAFMIN*DBLE( MAXIT ) )
** END IF
WR = ABS( H( ILAST-1, ILAST-2 ) / T( ILAST-1, ILAST-1 ) ) +
$ ABS( H( ILAST, ILAST-1 ) / T( ILAST-2, ILAST-2 ) )
ESHIFT = ABS( H( ILAST-1, ILAST-2 ) /
$ T( ILAST-2, ILAST-2 ) ) +
$ ABS( H( ILAST, ILAST-1 ) / T( ILAST-1, ILAST-1 ) )
ESHIFT = MIN( ESHIFT, WR )
S1 = ONE
WR = ESHIFT
*
ELSE
*
* Shifts based on the generalized eigenvalues of the
* bottom-right 2x2 block of A and B. The first eigenvalue
* returned by DLAG2 is the Wilkinson shift (AEP p.512),
*
CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
$ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
$ S2, WR, WR2, WI )
*
TEMP = MAX( S1, SAFMIN*MAX( ONE, ABS( WR ), ABS( WI ) ) )
IF( WI.NE.ZERO )
$ GO TO 200
END IF
*
* Fiddle with shift to avoid overflow
*
TEMP = MIN( ASCALE, ONE )*( HALF*SAFMAX )
IF( S1.GT.TEMP ) THEN
SCALE = TEMP / S1
ELSE
SCALE = ONE
END IF
*
TEMP = MIN( BSCALE, ONE )*( HALF*SAFMAX )
IF( ABS( WR ).GT.TEMP )
$ SCALE = MIN( SCALE, TEMP / ABS( WR ) )
S1 = SCALE*S1
WR = SCALE*WR
*
* Now check for two consecutive small subdiagonals.
*
DO 120 J = ILAST - 1, IFIRST + 1, -1
ISTART = J
TEMP = ABS( S1*H( J, J-1 ) )
TEMP2 = ABS( S1*H( J, J )-WR*T( J, J ) )
TEMPR = MAX( TEMP, TEMP2 )
IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
TEMP = TEMP / TEMPR
TEMP2 = TEMP2 / TEMPR
END IF
IF( ABS( ( ASCALE*H( J+1, J ) )*TEMP ).LE.( ASCALE*ATOL )*
$ TEMP2 )GO TO 130
120 CONTINUE
*
ISTART = IFIRST
130 CONTINUE
*
* Do an implicit single-shift QZ sweep.
*
* Initial Q
*
TEMP = S1*H( ISTART, ISTART ) - WR*T( ISTART, ISTART )
TEMP2 = S1*H( ISTART+1, ISTART )
CALL DLARTG( TEMP, TEMP2, C, S, TEMPR )
*
* Sweep
*
DO 190 J = ISTART, ILAST - 1
IF( J.GT.ISTART ) THEN
TEMP = H( J, J-1 )
CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
H( J+1, J-1 ) = ZERO
END IF
*
DO 140 JC = J, ILASTM
TEMP = C*H( J, JC ) + S*H( J+1, JC )
H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
H( J, JC ) = TEMP
TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
T( J, JC ) = TEMP2
140 CONTINUE
IF( ILQ ) THEN
DO 150 JR = 1, N
TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
Q( JR, J ) = TEMP
150 CONTINUE
END IF
*
TEMP = T( J+1, J+1 )
CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
T( J+1, J ) = ZERO
*
DO 160 JR = IFRSTM, MIN( J+2, ILAST )
TEMP = C*H( JR, J+1 ) + S*H( JR, J )
H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
H( JR, J+1 ) = TEMP
160 CONTINUE
DO 170 JR = IFRSTM, J
TEMP = C*T( JR, J+1 ) + S*T( JR, J )
T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
T( JR, J+1 ) = TEMP
170 CONTINUE
IF( ILZ ) THEN
DO 180 JR = 1, N
TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
Z( JR, J+1 ) = TEMP
180 CONTINUE
END IF
190 CONTINUE
*
GO TO 350
*
* Use Francis double-shift
*
* Note: the Francis double-shift should work with real shifts,
* but only if the block is at least 3x3.
* This code may break if this point is reached with
* a 2x2 block with real eigenvalues.
*
200 CONTINUE
IF( IFIRST+1.EQ.ILAST ) THEN
*
* Special case -- 2x2 block with complex eigenvectors
*
* Step 1: Standardize, that is, rotate so that
*
* ( B11 0 )
* B = ( ) with B11 non-negative.
* ( 0 B22 )
*
CALL DLASV2( T( ILAST-1, ILAST-1 ), T( ILAST-1, ILAST ),
$ T( ILAST, ILAST ), B22, B11, SR, CR, SL, CL )
*
IF( B11.LT.ZERO ) THEN
CR = -CR
SR = -SR
B11 = -B11
B22 = -B22
END IF
*
CALL DROT( ILASTM+1-IFIRST, H( ILAST-1, ILAST-1 ), LDH,
$ H( ILAST, ILAST-1 ), LDH, CL, SL )
CALL DROT( ILAST+1-IFRSTM, H( IFRSTM, ILAST-1 ), 1,
$ H( IFRSTM, ILAST ), 1, CR, SR )
*
IF( ILAST.LT.ILASTM )
$ CALL DROT( ILASTM-ILAST, T( ILAST-1, ILAST+1 ), LDT,
$ T( ILAST, ILAST+1 ), LDT, CL, SL )
IF( IFRSTM.LT.ILAST-1 )
$ CALL DROT( IFIRST-IFRSTM, T( IFRSTM, ILAST-1 ), 1,
$ T( IFRSTM, ILAST ), 1, CR, SR )
*
IF( ILQ )
$ CALL DROT( N, Q( 1, ILAST-1 ), 1, Q( 1, ILAST ), 1, CL,
$ SL )
IF( ILZ )
$ CALL DROT( N, Z( 1, ILAST-1 ), 1, Z( 1, ILAST ), 1, CR,
$ SR )
*
T( ILAST-1, ILAST-1 ) = B11
T( ILAST-1, ILAST ) = ZERO
T( ILAST, ILAST-1 ) = ZERO
T( ILAST, ILAST ) = B22
*
* If B22 is negative, negate column ILAST
*
IF( B22.LT.ZERO ) THEN
DO 210 J = IFRSTM, ILAST
H( J, ILAST ) = -H( J, ILAST )
T( J, ILAST ) = -T( J, ILAST )
210 CONTINUE
*
IF( ILZ ) THEN
DO 220 J = 1, N
Z( J, ILAST ) = -Z( J, ILAST )
220 CONTINUE
END IF
END IF
*
* Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.)
*
* Recompute shift
*
CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
$ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
$ TEMP, WR, TEMP2, WI )
*
* If standardization has perturbed the shift onto real line,
* do another (real single-shift) QR step.
*
IF( WI.EQ.ZERO )
$ GO TO 350
S1INV = ONE / S1
*
* Do EISPACK (QZVAL) computation of alpha and beta
*
A11 = H( ILAST-1, ILAST-1 )
A21 = H( ILAST, ILAST-1 )
A12 = H( ILAST-1, ILAST )
A22 = H( ILAST, ILAST )
*
* Compute complex Givens rotation on right
* (Assume some element of C = (sA - wB) > unfl )
* __
* (sA - wB) ( CZ -SZ )
* ( SZ CZ )
*
C11R = S1*A11 - WR*B11
C11I = -WI*B11
C12 = S1*A12
C21 = S1*A21
C22R = S1*A22 - WR*B22
C22I = -WI*B22
*
IF( ABS( C11R )+ABS( C11I )+ABS( C12 ).GT.ABS( C21 )+
$ ABS( C22R )+ABS( C22I ) ) THEN
T1 = DLAPY3( C12, C11R, C11I )
CZ = C12 / T1
SZR = -C11R / T1
SZI = -C11I / T1
ELSE
CZ = DLAPY2( C22R, C22I )
IF( CZ.LE.SAFMIN ) THEN
CZ = ZERO
SZR = ONE
SZI = ZERO
ELSE
TEMPR = C22R / CZ
TEMPI = C22I / CZ
T1 = DLAPY2( CZ, C21 )
CZ = CZ / T1
SZR = -C21*TEMPR / T1
SZI = C21*TEMPI / T1
END IF
END IF
*
* Compute Givens rotation on left
*
* ( CQ SQ )
* ( __ ) A or B
* ( -SQ CQ )
*
AN = ABS( A11 ) + ABS( A12 ) + ABS( A21 ) + ABS( A22 )
BN = ABS( B11 ) + ABS( B22 )
WABS = ABS( WR ) + ABS( WI )
IF( S1*AN.GT.WABS*BN ) THEN
CQ = CZ*B11
SQR = SZR*B22
SQI = -SZI*B22
ELSE
A1R = CZ*A11 + SZR*A12
A1I = SZI*A12
A2R = CZ*A21 + SZR*A22
A2I = SZI*A22
CQ = DLAPY2( A1R, A1I )
IF( CQ.LE.SAFMIN ) THEN
CQ = ZERO
SQR = ONE
SQI = ZERO
ELSE
TEMPR = A1R / CQ
TEMPI = A1I / CQ
SQR = TEMPR*A2R + TEMPI*A2I
SQI = TEMPI*A2R - TEMPR*A2I
END IF
END IF
T1 = DLAPY3( CQ, SQR, SQI )
CQ = CQ / T1
SQR = SQR / T1
SQI = SQI / T1
*
* Compute diagonal elements of QBZ
*
TEMPR = SQR*SZR - SQI*SZI
TEMPI = SQR*SZI + SQI*SZR
B1R = CQ*CZ*B11 + TEMPR*B22
B1I = TEMPI*B22
B1A = DLAPY2( B1R, B1I )
B2R = CQ*CZ*B22 + TEMPR*B11
B2I = -TEMPI*B11
B2A = DLAPY2( B2R, B2I )
*
* Normalize so beta > 0, and Im( alpha1 ) > 0
*
BETA( ILAST-1 ) = B1A
BETA( ILAST ) = B2A
ALPHAR( ILAST-1 ) = ( WR*B1A )*S1INV
ALPHAI( ILAST-1 ) = ( WI*B1A )*S1INV
ALPHAR( ILAST ) = ( WR*B2A )*S1INV
ALPHAI( ILAST ) = -( WI*B2A )*S1INV
*
* Step 3: Go to next block -- exit if finished.
*
ILAST = IFIRST - 1
IF( ILAST.LT.ILO )
$ GO TO 380
*
* Reset counters
*
IITER = 0
ESHIFT = ZERO
IF( .NOT.ILSCHR ) THEN
ILASTM = ILAST
IF( IFRSTM.GT.ILAST )
$ IFRSTM = ILO
END IF
GO TO 350
ELSE
*
* Usual case: 3x3 or larger block, using Francis implicit
* double-shift
*
* 2
* Eigenvalue equation is w - c w + d = 0,
*
* -1 2 -1
* so compute 1st column of (A B ) - c A B + d
* using the formula in QZIT (from EISPACK)
*
* We assume that the block is at least 3x3
*
AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
$ ( BSCALE*T( ILAST-1, ILAST-1 ) )
AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
$ ( BSCALE*T( ILAST-1, ILAST-1 ) )
AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
$ ( BSCALE*T( ILAST, ILAST ) )
AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
$ ( BSCALE*T( ILAST, ILAST ) )
U12 = T( ILAST-1, ILAST ) / T( ILAST, ILAST )
AD11L = ( ASCALE*H( IFIRST, IFIRST ) ) /
$ ( BSCALE*T( IFIRST, IFIRST ) )
AD21L = ( ASCALE*H( IFIRST+1, IFIRST ) ) /
$ ( BSCALE*T( IFIRST, IFIRST ) )
AD12L = ( ASCALE*H( IFIRST, IFIRST+1 ) ) /
$ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
AD22L = ( ASCALE*H( IFIRST+1, IFIRST+1 ) ) /
$ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
AD32L = ( ASCALE*H( IFIRST+2, IFIRST+1 ) ) /
$ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
U12L = T( IFIRST, IFIRST+1 ) / T( IFIRST+1, IFIRST+1 )
*
V( 1 ) = ( AD11-AD11L )*( AD22-AD11L ) - AD12*AD21 +
$ AD21*U12*AD11L + ( AD12L-AD11L*U12L )*AD21L
V( 2 ) = ( ( AD22L-AD11L )-AD21L*U12L-( AD11-AD11L )-
$ ( AD22-AD11L )+AD21*U12 )*AD21L
V( 3 ) = AD32L*AD21L
*
ISTART = IFIRST
*
CALL DLARFG( 3, V( 1 ), V( 2 ), 1, TAU )
V( 1 ) = ONE
*
* Sweep
*
DO 290 J = ISTART, ILAST - 2
*
* All but last elements: use 3x3 Householder transforms.
*
* Zero (j-1)st column of A
*
IF( J.GT.ISTART ) THEN
V( 1 ) = H( J, J-1 )
V( 2 ) = H( J+1, J-1 )
V( 3 ) = H( J+2, J-1 )
*
CALL DLARFG( 3, H( J, J-1 ), V( 2 ), 1, TAU )
V( 1 ) = ONE
H( J+1, J-1 ) = ZERO
H( J+2, J-1 ) = ZERO
END IF
*
DO 230 JC = J, ILASTM
TEMP = TAU*( H( J, JC )+V( 2 )*H( J+1, JC )+V( 3 )*
$ H( J+2, JC ) )
H( J, JC ) = H( J, JC ) - TEMP
H( J+1, JC ) = H( J+1, JC ) - TEMP*V( 2 )
H( J+2, JC ) = H( J+2, JC ) - TEMP*V( 3 )
TEMP2 = TAU*( T( J, JC )+V( 2 )*T( J+1, JC )+V( 3 )*
$ T( J+2, JC ) )
T( J, JC ) = T( J, JC ) - TEMP2
T( J+1, JC ) = T( J+1, JC ) - TEMP2*V( 2 )
T( J+2, JC ) = T( J+2, JC ) - TEMP2*V( 3 )
230 CONTINUE
IF( ILQ ) THEN
DO 240 JR = 1, N
TEMP = TAU*( Q( JR, J )+V( 2 )*Q( JR, J+1 )+V( 3 )*
$ Q( JR, J+2 ) )
Q( JR, J ) = Q( JR, J ) - TEMP
Q( JR, J+1 ) = Q( JR, J+1 ) - TEMP*V( 2 )
Q( JR, J+2 ) = Q( JR, J+2 ) - TEMP*V( 3 )
240 CONTINUE
END IF
*
* Zero j-th column of B (see DLAGBC for details)
*
* Swap rows to pivot
*
ILPIVT = .FALSE.
TEMP = MAX( ABS( T( J+1, J+1 ) ), ABS( T( J+1, J+2 ) ) )
TEMP2 = MAX( ABS( T( J+2, J+1 ) ), ABS( T( J+2, J+2 ) ) )
IF( MAX( TEMP, TEMP2 ).LT.SAFMIN ) THEN
SCALE = ZERO
U1 = ONE
U2 = ZERO
GO TO 250
ELSE IF( TEMP.GE.TEMP2 ) THEN
W11 = T( J+1, J+1 )
W21 = T( J+2, J+1 )
W12 = T( J+1, J+2 )
W22 = T( J+2, J+2 )
U1 = T( J+1, J )
U2 = T( J+2, J )
ELSE
W21 = T( J+1, J+1 )
W11 = T( J+2, J+1 )
W22 = T( J+1, J+2 )
W12 = T( J+2, J+2 )
U2 = T( J+1, J )
U1 = T( J+2, J )
END IF
*
* Swap columns if nec.
*
IF( ABS( W12 ).GT.ABS( W11 ) ) THEN
ILPIVT = .TRUE.
TEMP = W12
TEMP2 = W22
W12 = W11
W22 = W21
W11 = TEMP
W21 = TEMP2
END IF
*
* LU-factor
*
TEMP = W21 / W11
U2 = U2 - TEMP*U1
W22 = W22 - TEMP*W12
W21 = ZERO
*
* Compute SCALE
*
SCALE = ONE
IF( ABS( W22 ).LT.SAFMIN ) THEN
SCALE = ZERO
U2 = ONE
U1 = -W12 / W11
GO TO 250
END IF
IF( ABS( W22 ).LT.ABS( U2 ) )
$ SCALE = ABS( W22 / U2 )
IF( ABS( W11 ).LT.ABS( U1 ) )
$ SCALE = MIN( SCALE, ABS( W11 / U1 ) )
*
* Solve
*
U2 = ( SCALE*U2 ) / W22
U1 = ( SCALE*U1-W12*U2 ) / W11
*
250 CONTINUE
IF( ILPIVT ) THEN
TEMP = U2
U2 = U1
U1 = TEMP
END IF
*
* Compute Householder Vector
*
T1 = SQRT( SCALE**2+U1**2+U2**2 )
TAU = ONE + SCALE / T1
VS = -ONE / ( SCALE+T1 )
V( 1 ) = ONE
V( 2 ) = VS*U1
V( 3 ) = VS*U2
*
* Apply transformations from the right.
*
DO 260 JR = IFRSTM, MIN( J+3, ILAST )
TEMP = TAU*( H( JR, J )+V( 2 )*H( JR, J+1 )+V( 3 )*
$ H( JR, J+2 ) )
H( JR, J ) = H( JR, J ) - TEMP
H( JR, J+1 ) = H( JR, J+1 ) - TEMP*V( 2 )
H( JR, J+2 ) = H( JR, J+2 ) - TEMP*V( 3 )
260 CONTINUE
DO 270 JR = IFRSTM, J + 2
TEMP = TAU*( T( JR, J )+V( 2 )*T( JR, J+1 )+V( 3 )*
$ T( JR, J+2 ) )
T( JR, J ) = T( JR, J ) - TEMP
T( JR, J+1 ) = T( JR, J+1 ) - TEMP*V( 2 )
T( JR, J+2 ) = T( JR, J+2 ) - TEMP*V( 3 )
270 CONTINUE
IF( ILZ ) THEN
DO 280 JR = 1, N
TEMP = TAU*( Z( JR, J )+V( 2 )*Z( JR, J+1 )+V( 3 )*
$ Z( JR, J+2 ) )
Z( JR, J ) = Z( JR, J ) - TEMP
Z( JR, J+1 ) = Z( JR, J+1 ) - TEMP*V( 2 )
Z( JR, J+2 ) = Z( JR, J+2 ) - TEMP*V( 3 )
280 CONTINUE
END IF
T( J+1, J ) = ZERO
T( J+2, J ) = ZERO
290 CONTINUE
*
* Last elements: Use Givens rotations
*
* Rotations from the left
*
J = ILAST - 1
TEMP = H( J, J-1 )
CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
H( J+1, J-1 ) = ZERO
*
DO 300 JC = J, ILASTM
TEMP = C*H( J, JC ) + S*H( J+1, JC )
H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
H( J, JC ) = TEMP
TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
T( J, JC ) = TEMP2
300 CONTINUE
IF( ILQ ) THEN
DO 310 JR = 1, N
TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
Q( JR, J ) = TEMP
310 CONTINUE
END IF
*
* Rotations from the right.
*
TEMP = T( J+1, J+1 )
CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
T( J+1, J ) = ZERO
*
DO 320 JR = IFRSTM, ILAST
TEMP = C*H( JR, J+1 ) + S*H( JR, J )
H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
H( JR, J+1 ) = TEMP
320 CONTINUE
DO 330 JR = IFRSTM, ILAST - 1
TEMP = C*T( JR, J+1 ) + S*T( JR, J )
T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
T( JR, J+1 ) = TEMP
330 CONTINUE
IF( ILZ ) THEN
DO 340 JR = 1, N
TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
Z( JR, J+1 ) = TEMP
340 CONTINUE
END IF
*
* End of Double-Shift code
*
END IF
*
GO TO 350
*
* End of iteration loop
*
350 CONTINUE
360 CONTINUE
*
* Drop-through = non-convergence
*
INFO = ILAST
GO TO 420
*
* Successful completion of all QZ steps
*
380 CONTINUE
*
* Set Eigenvalues 1:ILO-1
*
DO 410 J = 1, ILO - 1
IF( T( J, J ).LT.ZERO ) THEN
IF( ILSCHR ) THEN
DO 390 JR = 1, J
H( JR, J ) = -H( JR, J )
T( JR, J ) = -T( JR, J )
390 CONTINUE
ELSE
H( J, J ) = -H( J, J )
T( J, J ) = -T( J, J )
END IF
IF( ILZ ) THEN
DO 400 JR = 1, N
Z( JR, J ) = -Z( JR, J )
400 CONTINUE
END IF
END IF
ALPHAR( J ) = H( J, J )
ALPHAI( J ) = ZERO
BETA( J ) = T( J, J )
410 CONTINUE
*
* Normal Termination
*
INFO = 0
*
* Exit (other than argument error) -- return optimal workspace size
*
420 CONTINUE
WORK( 1 ) = DBLE( N )
RETURN
*
* End of DHGEQZ
*
END
| mit |
fthoele/espresso-5.4.0 | S3DE/iotk/src/iotk_attr+INTEGER3_0.f90 | 5 | 23071 | ! Input/Output Tool Kit (IOTK)
! Copyright (C) 2004-2006 Giovanni Bussi
!
! This library is free software; you can redistribute it and/or
! modify it under the terms of the GNU Lesser General Public
! License as published by the Free Software Foundation; either
! version 2.1 of the License, or (at your option) any later version.
!
! This library is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! Lesser General Public License for more details.
!
! You should have received a copy of the GNU Lesser General Public
! License along with this library; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
!------------------------------------------------------------------------------!
! Inclusion of configuration file
#include "iotk_config.h"
!------------------------------------------------------------------------------!
#include "iotk_auxmacros.h"
#ifdef __IOTK_INTEGER3
#if 0 <= __IOTK_MAXRANK
! This is needed as a workaround for bugged pack
subroutine iotk_private_pack_INTEGER3(out,in,n,l)
use iotk_base
implicit none
integer, intent(in) :: n,l
INTEGER (kind=iotk_INTEGER3), intent(out) :: out(n)
INTEGER (kind=iotk_INTEGER3), intent(in) :: in(n)
out = in
end subroutine iotk_private_pack_INTEGER3
subroutine iotk_write_INTEGER3(val,string,fmt,ierr)
use iotk_base
use iotk_error_interf
use iotk_xtox_interf
use iotk_fmt_interf
use iotk_str_interf
use iotk_misc_interf
implicit none
INTEGER(kind=iotk_INTEGER3), intent(in) :: val(:)
#ifdef __IOTK_WORKAROUND6
character(len=*) :: string
#else
character(len=*), intent(out) :: string
#endif
character(len=*), intent(in) :: fmt
integer, intent(out) :: ierr
integer :: index,iostat
ierr = 0
iostat = 0
string(1:1) = iotk_eos
if(size(val)==0) return
if(len(string)==0) then
call iotk_error_issue(ierr,"iotk_write",__FILE__,__LINE__)
call iotk_error_msg(ierr,"CVS Revision: 1.21 ")
return
end if
do index=1,size(val)
call iotk_strcat(string,trim(iotk_itoa(val(index)))//" ",ierr)
if(ierr/=0) then
call iotk_error_issue(ierr,"iotk_write",__FILE__,__LINE__)
call iotk_error_msg(ierr,"CVS Revision: 1.21 ")
return
end if
end do
! the last blank is deleted
string(iotk_strlen(string):iotk_strlen(string)) = iotk_eos
end subroutine iotk_write_INTEGER3
subroutine iotk_read_INTEGER3(val,string,index,ierr)
use iotk_base
use iotk_error_interf
use iotk_xtox_interf
use iotk_misc_interf
implicit none
INTEGER(kind=iotk_INTEGER3), intent(inout) :: val(:)
character(len=*), intent(in) :: string
integer, intent(inout) :: index
integer, intent(out) :: ierr
logical :: check
integer :: pos,pos1,iostat
integer :: maxindex
#ifdef __IOTK_WORKAROUND9
character(len=100) :: tmpstr ! debug
#endif
pos = 0
pos1= 0
ierr = 0
iostat = 0
maxindex = size(val)
! for the moment, commas are considered as blanks
do
pos = verify(string(pos1+1:)," ,")+pos1
if(pos==pos1) exit
pos = pos - 1
pos1 = scan(string(pos+1:)," ,")+pos
if(pos1==pos) pos1 = len(string) + 1
!READ string(pos+1:pos1-1)
index = index+1
if(index>maxindex) then
call iotk_error_issue(ierr,"iotk_read",__FILE__,__LINE__)
call iotk_error_msg(ierr,"CVS Revision: 1.21 ")
call iotk_error_msg(ierr,'Too many data')
end if
call iotk_atoi(val(index),string(pos+1:pos1-1),check=check)
if(.not.check) then
call iotk_error_issue(ierr,"iotk_read",__FILE__,__LINE__)
call iotk_error_msg(ierr,"CVS Revision: 1.21 ")
call iotk_error_msg(ierr,'Wrong string')
call iotk_error_write(ierr,"string",string(pos+1:pos1-1))
return
end if
if(pos1>=len(string)) exit
end do
end subroutine iotk_read_INTEGER3
subroutine iotk_write_attr_INTEGER3_0(attr,name,val,dummy,first,newline,fmt,ierr)
use iotk_base
use iotk_error_interf
use iotk_attr_interf
use iotk_str_interf
use iotk_misc_interf
implicit none
character(*), intent(inout) :: attr
character(*), intent(in) :: name
INTEGER(kind=iotk_INTEGER3), intent(in) :: val
type(iotk_dummytype), optional :: dummy
logical, optional, intent(in) :: first
logical, optional, intent(in) :: newline
character(*), optional, intent(in) :: fmt
integer, optional, intent(out) :: ierr
integer :: ierrl
integer :: attlen
integer :: vallen
integer :: namlen
character :: delim
character(len=300) :: usefmt
character(iotk_vallenx) :: tmpval
logical :: nl
if(present(newline)) then
nl = newline
else
nl = .false.
endif
!-<
if (present(fmt)) then
usefmt = fmt
else
usefmt = "!"
end if
!->
ierrl = 0
if(present(first)) then
if(first) attr(1:1) = iotk_eos
end if
attlen = iotk_strlen_trim(attr)
namlen = iotk_strlen_trim(name)
if(.not.iotk_check_name(name)) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Wrong tag name')
call iotk_error_write(ierrl,"name",name(1:namlen))
goto 1
end if
delim = '"'
call iotk_write((/val/),tmpval,usefmt,ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
vallen = iotk_strlen(tmpval)
if(attlen+vallen+namlen+5>len(attr)) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute dummy argument is too short')
goto 1
end if
if(.not. nl) then
attr(attlen+1:attlen+vallen+namlen+5) = " "//name(1:namlen)//"="//delim//tmpval(1:vallen)//delim//iotk_eos
else
attr(attlen+1:attlen+vallen+namlen+len(iotk_newline)+5) &
= iotk_newline//" "//name(1:namlen)//"="//delim//tmpval(1:vallen)//delim//iotk_eos
endif
1 continue
if(present(ierr)) then
ierr = ierrl
else
if(ierrl/=0) call iotk_error_handler(ierrl)
end if
end subroutine iotk_write_attr_INTEGER3_0
subroutine iotk_scan_attr_INTEGER3_0(attr,name,val,dummy,found,default,eos,ierr)
use iotk_base
use iotk_error_interf
use iotk_attr_interf, only : iotk_read
use iotk_str_interf
use iotk_misc_interf
implicit none
character(*), intent(in) :: attr
character(*), intent(in) :: name
#ifdef __IOTK_WORKAROUND6
INTEGER(kind=iotk_INTEGER3) :: val
#else
INTEGER(kind=iotk_INTEGER3), intent(out) :: val
#endif
type(iotk_dummytype), optional :: dummy
logical, optional, intent(out) :: found
INTEGER(kind=iotk_INTEGER3), optional, intent(in) :: default
logical, optional, intent(in) :: eos
integer, optional, intent(out) :: ierr
integer :: ierrl
integer :: attlen,pos,equal,namlen
character :: delim
logical :: foundl
character(iotk_vallenx) :: valc
integer :: index
INTEGER(kind=iotk_INTEGER3), allocatable :: tmpval (:)
ierrl = 0
attlen=iotk_strlen(attr)
namlen=iotk_strlen_trim(name)
foundl = .false.
equal = 0
do
pos = verify(attr(equal+1:attlen)," ")
if(pos<=0) exit
equal = equal + pos
pos = scan(attr(equal+1:attlen),"=")
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'')
call iotk_error_write(ierrl,"attr",attr(equal+1:attlen))
goto 1
end if
equal = equal + pos
if(trim(attr(equal-pos:equal-1))==name(1:namlen)) foundl = .true.
pos = verify(attr(equal+1:attlen)," ")
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
equal = equal + pos
delim = attr(equal:equal)
if(delim/="'" .and. delim/='"') then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
pos = scan(attr(equal+1:attlen),delim)
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
if(foundl) exit
equal = equal + pos
end do
if(foundl) then
call iotk_strcpy(valc,attr(equal+1:equal+pos-1),ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
else
goto 1
end if
allocate(tmpval(1))
index = 0
call iotk_str_clean(valc)
call iotk_read(tmpval,valc(1:iotk_strlen(valc)),index,ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
if(index/=1) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute size does not match')
call iotk_error_write(ierrl,"attr",valc)
call iotk_error_write(ierrl,"size",size(tmpval))
goto 1
end if
val = tmpval(1)
deallocate(tmpval)
1 continue
if(ierrl/=0) foundl=.false.
if(present(found)) found = foundl
if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute not found')
call iotk_error_write(ierrl,"name",name)
ierrl = - ierrl
end if
if(present(default) .and. .not. foundl) then
val = default
end if
if(present(ierr)) then
ierr = ierrl
else
if(ierrl/=0) call iotk_error_handler(ierrl)
end if
end subroutine iotk_scan_attr_INTEGER3_0
#endif
#endif
subroutine iotk_attr_dummy_INTEGER3_0
write(0,*)
end subroutine iotk_attr_dummy_INTEGER3_0
!------------------------------------------------------------------------------!
! Inclusion of configuration file
#include "iotk_config.h"
!------------------------------------------------------------------------------!
#include "iotk_auxmacros.h"
#ifdef __IOTK_INTEGER3
#if 1 <= __IOTK_MAXRANK
subroutine iotk_write_attr_INTEGER3_1(attr,name,val,dummy,first,newline,fmt,ierr)
use iotk_base
use iotk_error_interf
use iotk_attr_interf
use iotk_str_interf
use iotk_misc_interf
implicit none
character(*), intent(inout) :: attr
character(*), intent(in) :: name
INTEGER(kind=iotk_INTEGER3), intent(in) :: val (:)
type(iotk_dummytype), optional :: dummy
logical, optional, intent(in) :: first
logical, optional, intent(in) :: newline
character(*), optional, intent(in) :: fmt
integer, optional, intent(out) :: ierr
integer :: ierrl
integer :: attlen
integer :: vallen
integer :: namlen
character :: delim
character(len=300) :: usefmt
character(iotk_vallenx) :: tmpval
logical :: nl
if(present(newline)) then
nl = newline
else
nl = .false.
endif
!-<
if (present(fmt)) then
usefmt = fmt
else
usefmt = "!"
end if
!->
ierrl = 0
if(present(first)) then
if(first) attr(1:1) = iotk_eos
end if
attlen = iotk_strlen_trim(attr)
namlen = iotk_strlen_trim(name)
if(.not.iotk_check_name(name)) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Wrong tag name')
call iotk_error_write(ierrl,"name",name(1:namlen))
goto 1
end if
delim = '"'
call iotk_write(pack(val,mask=.true.),tmpval,usefmt,ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
vallen = iotk_strlen(tmpval)
if(attlen+vallen+namlen+5>len(attr)) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute dummy argument is too short')
goto 1
end if
if(.not. nl) then
attr(attlen+1:attlen+vallen+namlen+5) = " "//name(1:namlen)//"="//delim//tmpval(1:vallen)//delim//iotk_eos
else
attr(attlen+1:attlen+vallen+namlen+len(iotk_newline)+5) &
= iotk_newline//" "//name(1:namlen)//"="//delim//tmpval(1:vallen)//delim//iotk_eos
endif
1 continue
if(present(ierr)) then
ierr = ierrl
else
if(ierrl/=0) call iotk_error_handler(ierrl)
end if
end subroutine iotk_write_attr_INTEGER3_1
subroutine iotk_scan_attr_INTEGER3_1(attr,name,val,dummy,found,default,eos,ierr)
use iotk_base
use iotk_error_interf
use iotk_attr_interf, only : iotk_read
use iotk_str_interf
use iotk_misc_interf
implicit none
character(*), intent(in) :: attr
character(*), intent(in) :: name
#ifdef __IOTK_WORKAROUND6
INTEGER(kind=iotk_INTEGER3) :: val (:)
#else
INTEGER(kind=iotk_INTEGER3), intent(out) :: val (:)
#endif
type(iotk_dummytype), optional :: dummy
logical, optional, intent(out) :: found
INTEGER(kind=iotk_INTEGER3), optional, intent(in) :: default (:)
logical, optional, intent(in) :: eos
integer, optional, intent(out) :: ierr
integer :: ierrl
integer :: attlen,pos,equal,namlen
character :: delim
logical :: foundl
character(iotk_vallenx) :: valc
integer :: index
INTEGER(kind=iotk_INTEGER3), allocatable :: tmpval (:)
ierrl = 0
attlen=iotk_strlen(attr)
namlen=iotk_strlen_trim(name)
foundl = .false.
equal = 0
do
pos = verify(attr(equal+1:attlen)," ")
if(pos<=0) exit
equal = equal + pos
pos = scan(attr(equal+1:attlen),"=")
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'')
call iotk_error_write(ierrl,"attr",attr(equal+1:attlen))
goto 1
end if
equal = equal + pos
if(trim(attr(equal-pos:equal-1))==name(1:namlen)) foundl = .true.
pos = verify(attr(equal+1:attlen)," ")
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
equal = equal + pos
delim = attr(equal:equal)
if(delim/="'" .and. delim/='"') then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
pos = scan(attr(equal+1:attlen),delim)
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
if(foundl) exit
equal = equal + pos
end do
if(foundl) then
call iotk_strcpy(valc,attr(equal+1:equal+pos-1),ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
else
goto 1
end if
allocate(tmpval(size(val)))
index = 0
call iotk_str_clean(valc)
call iotk_read(tmpval,valc(1:iotk_strlen(valc)),index,ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
if(index/=size(val)) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute size does not match')
call iotk_error_write(ierrl,"attr",valc)
call iotk_error_write(ierrl,"size",size(tmpval))
goto 1
end if
val = reshape (source=tmpval,shape=shape(val))
deallocate(tmpval)
1 continue
if(ierrl/=0) foundl=.false.
if(present(found)) found = foundl
if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute not found')
call iotk_error_write(ierrl,"name",name)
ierrl = - ierrl
end if
if(present(default) .and. .not. foundl) then
val = default
end if
if(present(ierr)) then
ierr = ierrl
else
if(ierrl/=0) call iotk_error_handler(ierrl)
end if
end subroutine iotk_scan_attr_INTEGER3_1
#endif
#endif
subroutine iotk_attr_dummy_INTEGER3_1
write(0,*)
end subroutine iotk_attr_dummy_INTEGER3_1
!------------------------------------------------------------------------------!
! Inclusion of configuration file
#include "iotk_config.h"
!------------------------------------------------------------------------------!
#include "iotk_auxmacros.h"
#ifdef __IOTK_INTEGER3
#if 2 <= __IOTK_MAXRANK
subroutine iotk_write_attr_INTEGER3_2(attr,name,val,dummy,first,newline,fmt,ierr)
use iotk_base
use iotk_error_interf
use iotk_attr_interf
use iotk_str_interf
use iotk_misc_interf
implicit none
character(*), intent(inout) :: attr
character(*), intent(in) :: name
INTEGER(kind=iotk_INTEGER3), intent(in) :: val (:,:)
type(iotk_dummytype), optional :: dummy
logical, optional, intent(in) :: first
logical, optional, intent(in) :: newline
character(*), optional, intent(in) :: fmt
integer, optional, intent(out) :: ierr
integer :: ierrl
integer :: attlen
integer :: vallen
integer :: namlen
character :: delim
character(len=300) :: usefmt
character(iotk_vallenx) :: tmpval
logical :: nl
if(present(newline)) then
nl = newline
else
nl = .false.
endif
!-<
if (present(fmt)) then
usefmt = fmt
else
usefmt = "!"
end if
!->
ierrl = 0
if(present(first)) then
if(first) attr(1:1) = iotk_eos
end if
attlen = iotk_strlen_trim(attr)
namlen = iotk_strlen_trim(name)
if(.not.iotk_check_name(name)) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Wrong tag name')
call iotk_error_write(ierrl,"name",name(1:namlen))
goto 1
end if
delim = '"'
call iotk_write(pack(val,mask=.true.),tmpval,usefmt,ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
vallen = iotk_strlen(tmpval)
if(attlen+vallen+namlen+5>len(attr)) then
call iotk_error_issue(ierrl,"iotk_write_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute dummy argument is too short')
goto 1
end if
if(.not. nl) then
attr(attlen+1:attlen+vallen+namlen+5) = " "//name(1:namlen)//"="//delim//tmpval(1:vallen)//delim//iotk_eos
else
attr(attlen+1:attlen+vallen+namlen+len(iotk_newline)+5) &
= iotk_newline//" "//name(1:namlen)//"="//delim//tmpval(1:vallen)//delim//iotk_eos
endif
1 continue
if(present(ierr)) then
ierr = ierrl
else
if(ierrl/=0) call iotk_error_handler(ierrl)
end if
end subroutine iotk_write_attr_INTEGER3_2
subroutine iotk_scan_attr_INTEGER3_2(attr,name,val,dummy,found,default,eos,ierr)
use iotk_base
use iotk_error_interf
use iotk_attr_interf, only : iotk_read
use iotk_str_interf
use iotk_misc_interf
implicit none
character(*), intent(in) :: attr
character(*), intent(in) :: name
#ifdef __IOTK_WORKAROUND6
INTEGER(kind=iotk_INTEGER3) :: val (:,:)
#else
INTEGER(kind=iotk_INTEGER3), intent(out) :: val (:,:)
#endif
type(iotk_dummytype), optional :: dummy
logical, optional, intent(out) :: found
INTEGER(kind=iotk_INTEGER3), optional, intent(in) :: default (:,:)
logical, optional, intent(in) :: eos
integer, optional, intent(out) :: ierr
integer :: ierrl
integer :: attlen,pos,equal,namlen
character :: delim
logical :: foundl
character(iotk_vallenx) :: valc
integer :: index
INTEGER(kind=iotk_INTEGER3), allocatable :: tmpval (:)
ierrl = 0
attlen=iotk_strlen(attr)
namlen=iotk_strlen_trim(name)
foundl = .false.
equal = 0
do
pos = verify(attr(equal+1:attlen)," ")
if(pos<=0) exit
equal = equal + pos
pos = scan(attr(equal+1:attlen),"=")
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'')
call iotk_error_write(ierrl,"attr",attr(equal+1:attlen))
goto 1
end if
equal = equal + pos
if(trim(attr(equal-pos:equal-1))==name(1:namlen)) foundl = .true.
pos = verify(attr(equal+1:attlen)," ")
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
equal = equal + pos
delim = attr(equal:equal)
if(delim/="'" .and. delim/='"') then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
pos = scan(attr(equal+1:attlen),delim)
if(pos<=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
if(foundl) exit
equal = equal + pos
end do
if(foundl) then
call iotk_strcpy(valc,attr(equal+1:equal+pos-1),ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
else
goto 1
end if
allocate(tmpval(size(val)))
index = 0
call iotk_str_clean(valc)
call iotk_read(tmpval,valc(1:iotk_strlen(valc)),index,ierrl)
if(ierrl/=0) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
goto 1
end if
if(index/=size(val)) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute size does not match')
call iotk_error_write(ierrl,"attr",valc)
call iotk_error_write(ierrl,"size",size(tmpval))
goto 1
end if
val = reshape (source=tmpval,shape=shape(val))
deallocate(tmpval)
1 continue
if(ierrl/=0) foundl=.false.
if(present(found)) found = foundl
if(ierrl==0 .and. .not. present(found) .and. .not. present(default) .and. .not. foundl) then
call iotk_error_issue(ierrl,"iotk_scan_attr",__FILE__,__LINE__)
call iotk_error_msg(ierrl,"CVS Revision: 1.21 ")
call iotk_error_msg(ierrl,'Attribute not found')
call iotk_error_write(ierrl,"name",name)
ierrl = - ierrl
end if
if(present(default) .and. .not. foundl) then
val = default
end if
if(present(ierr)) then
ierr = ierrl
else
if(ierrl/=0) call iotk_error_handler(ierrl)
end if
end subroutine iotk_scan_attr_INTEGER3_2
#endif
#endif
subroutine iotk_attr_dummy_INTEGER3_2
write(0,*)
end subroutine iotk_attr_dummy_INTEGER3_2
| gpl-2.0 |
nvarini/espresso_adios | PHonon/D3/allocate_pert_d3.f90 | 5 | 1031 | !
! Copyright (C) 2001-2009 PWSCF group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!
!-----------------------------------------------------------------------
subroutine allocate_pert_d3()
!-----------------------------------------------------------------------
!
! dynamical allocation of arrays: quantities depending on the
! maximum number of perturbations
!
USE kinds, only : DP
USE ions_base, ONLY : nat
USE modes, ONLY : npertx, t, tmq
USE modesg0, ONLY : tg0
USE control_ph, ONLY : lgamma
implicit none
!
! allocate space for the quantities with dimensions that depend
! on the maximum number of perturbations
!
ALLOCATE (t (npertx, npertx, 48, 3*nat))
ALLOCATE (tmq (npertx, npertx, 3*nat))
IF (lgamma) THEN
tg0 => t
ELSE
allocate (tg0( npertx, npertx, 48, 3*nat))
ENDIF
RETURN
END SUBROUTINE allocate_pert_d3
| gpl-2.0 |
bgin/MissileSimulation | External/CUBPACK/rule_t3.f90 | 3 | 17600 | ! This file is F-compatible, except for upper/lower case conventions.
!--------------------------------------------------------------------
Module CubatureRule_T3
USE Precision_Model, ONLY: stnd
Implicit NONE
PRIVATE
PUBLIC :: Rule_T3a
PRIVATE :: OrbT3_Sum
CONTAINS
SUBROUTINE Rule_T3a(VER,VOLUME,NUMFUN,Integrand,BASVAL,RGNERR,NUM)
!
!***BEGIN PROLOGUE Rule_T3a
!***REFER TO DCUTET
!***REVISION DATE 970324 (YYMMDD)
!***REVISION DATE 990528 (YYMMDD) (F conversion)
!***PURPOSE To compute basic integration rule values and
! corresponding error estimates.
!***DESCRIPTION Rule_T3a computes basic integration rule values
! for a vector of integrands over a tetrahedron.
! Rule_T3a also computes estimates for the errors by
! using several null rule approximations.
! ON ENTRY
!
! VER Real array of dimension (3,4).
! The coordinates of the vertices of the tetrahedron.
! vertex i -> ( ver(1,i),ver(2,i),ver(3,i) )
! NUMFUN Integer.
! Number of components of the vector integrand.
! Integrand Externally declared subroutine for computing
! all components of the integrand at the given
! evaluation point.
! It must have parameters (X)
! Input parameters:
! X(1) The x-coordinate of the evaluation point.
! X(2) The y-coordinate of the evaluation point.
! X(3) The z-coordinate of the evaluation point.
!
! ON RETURN
!
! BASVAL Real array of dimension NUMFUN.
! The values for the basic rule for each component
! of the integrand.
! RGNERR Real array of dimension NUMFUN.
! The error estimates for each component of the integrand.
! NUM Integer
! The number of function evaluations used.
!
!***REFERENCES M. Beckers and A. Haegemans,
! The construction of cubature formula for the tetrahedron
! Report TW128, K.U. Leuven (1990).
!***ROUTINES CALLED
! OrbT3_Sum,Integrand
!***END PROLOGUE Rule_T3a
!
! Parameters
!
! ORBITS Integer
! The number of orbits of the cubature formula and null rules
! CRIVAL Real
! The decision to choose the optimistic part of the error
! estimator is based on CRIVAL
! FACMED Real
! FACMED is the safety coefficient used in the non-optimistic
! part of the error estimator. FACMED is related to CRIVAL
! and FACOPT.
! FACOPT Real
! FACOPT is the safety coefficient used in the optimistic part
! of the error estimator.
! K Integer array of dimension (0:3) that contains the structure
! parameters. K(I) = number of orbits of type I.
! TYPE1 Real array of dimension (K(1)).
! Contains the first homogeneous coordinate of the generators
! of type 1
! TYPE2 Real array of dimension (K(2)).
! Contains the first homogeneous coordinate of the generators
! of type 2
! TYPE3 Real array of dimension (2,K(2)).
! Contains the first two homogeneous coordinates of
! the generators of type 3.
! WEIGHT Real array of dimension (9,ORBITS).
! The weights of the cubature formula and the null rules.
! WEIGHT(1,1) ,..., WEIGHT(1,ORBITS) are the weights of the
! cubature formula
! WEIGHT(I,1) ,..., WEIGHT(I,ORBITS) for I > 1, are the weights
! of the null rules
!
!
! Global variables.
!
INTEGER, INTENT(IN) :: NUMFUN
INTEGER, INTENT(OUT) :: NUM
REAL(kind=stnd), INTENT(IN) :: VOLUME
REAL(kind=stnd), DIMENSION(:,:), INTENT(IN) :: VER
REAL(kind=stnd), DIMENSION(:), INTENT(OUT) :: BASVAL, RGNERR
INTERFACE
FUNCTION Integrand(NUMFUN,X) RESULT(Value)
USE Precision_Model
INTEGER, INTENT(IN) :: NUMFUN
REAL(kind=stnd), DIMENSION(:), INTENT(IN) :: X
REAL(kind=stnd), DIMENSION(NUMFUN) :: Value
END FUNCTION Integrand
END INTERFACE
!
! Constants
!
INTEGER, PARAMETER :: ORBITS = 7
REAL(kind=stnd), PARAMETER:: CRIVAL=0.5_stnd, &
FACMED=5, &
FACOPT=FACMED/CRIVAL, &
TRES=50*EPSILON(crival)
!
! Cubature formula of degree 8 with 43 points
!
INTEGER, DIMENSION(0:3), PARAMETER :: &
K = (/1,3,1,2/) ! Rule structure parameters
!
! Information for the generators
!
REAL(kind=stnd), DIMENSION(1:3), PARAMETER :: &
TYPE1 = (/ 0.379510205167980387748057300876_stnd, &
0.753689235068359830728182577696_stnd, &
0.982654148484406008240470085259_stnd/)
REAL(kind=stnd), DIMENSION(1:1), PARAMETER :: &
TYPE2 = (/ 0.449467259981105775574375471447_stnd/)
REAL(kind=stnd), DIMENSION(1:2,1:2), PARAMETER :: &
TYPE3 = RESHAPE( SOURCE= &
(/ 0.506227344977843677082264893876_stnd, &
0.356395827885340437169173969841E-1_stnd, &
0.736298458958971696943019005441_stnd, &
0.190486041934633455699433285302_stnd/), &
SHAPE=(/2,2/), ORDER=(/1,2/) )
!
! Weights of the cubature formula
!
REAL(kind=stnd), DIMENSION(1:ORBITS), PARAMETER :: &
W1 = (/ &
-0.123001131951839495043519102752_stnd, &
0.855018349372014074906384482699E-1_stnd, &
0.118021998788034059253768205083E-1_stnd, &
0.101900465455732427902646736855E-2_stnd, &
0.274781029468036908044610867719E-1_stnd, &
0.342269148520915110408153517904E-1_stnd, &
0.128431148469725555789001180031E-1_stnd/)
!
! Weights of the null rule of degree 5
!
REAL(kind=stnd), DIMENSION(1:ORBITS), PARAMETER :: &
W2 = (/ &
0.211921237628032658308230999090_stnd, &
-0.660207516445726284649283745987E-1_stnd, &
0.225058824086711710443385047042E-1_stnd, &
-0.375962972067425589765730699401E-3_stnd, &
0.710066020561055159657284834784E-2_stnd, &
0.156515256061747694921427149028E-2_stnd, &
-0.814530839643584660306807872526E-2_stnd/)
!
! Weights of null rule of degree 4
!
REAL(kind=stnd), DIMENSION(1:ORBITS), PARAMETER :: &
W3 = (/ &
-0.508105488137100551376844924797E-1_stnd, &
0.104596681151665328209751420525E-1_stnd, &
0.927471438532788763594989973184E-1_stnd, &
0.210489990008917994323967321174E-2_stnd, &
0.379184172251962722213408547663E-1_stnd, &
-0.111747242913563605790923001557E-1_stnd, &
-0.386541758762774673113423570465E-1_stnd/)
!
! Weights of first null rule of degree 3
!
REAL(kind=stnd), DIMENSION(1:ORBITS), PARAMETER :: &
W4 = (/ &
-0.775992773232808462404390159802E-1_stnd, &
-0.527453289659022924847298408064E-1_stnd, &
0.145876238555932704488677626554E-1_stnd, &
0.739374873393616192857532718429E-2_stnd, &
-0.374618791364332892611678523428E-1_stnd, &
0.538502846550653076078817013885E-1_stnd, &
-0.183980865177843057548322735665E-1_stnd/)
!
! Weights of second null rule of degree 3
!
REAL(kind=stnd), DIMENSION(1:ORBITS), PARAMETER :: &
W5 = (/ &
0.181767621501470154602720474731E-1_stnd, &
0.179938831310058580533178529022E-1_stnd, &
0.713210362750414891598257378898E-1_stnd, &
-0.443935688958258805893448212636E-1_stnd, &
-0.657639036547720234169662790056E-1_stnd, &
-0.101551807522541414699808460583E-1_stnd, &
0.265486188970540796821750584204E-1_stnd/)
!
! Weights of null rule of degree 2
!
REAL(kind=stnd), DIMENSION(1:ORBITS), PARAMETER :: &
W6 = (/ &
-0.867629853722843888927184699428E-1_stnd, &
-0.715881271235661902772072127812E-1_stnd, &
0.886720767790426261677273459523E-2_stnd, &
-0.577885573028655167063092577589E-1_stnd, &
0.430310167581202031805055255554E-1_stnd, &
-0.606467834856775537069463817445E-2_stnd, &
0.319492443333738343104163265406E-1_stnd/)
!
! Weights of null rule of degree 1
!
REAL(kind=stnd), DIMENSION(1:ORBITS), PARAMETER :: &
W7 = (/ &
0.510374015624925451319499382594E-1_stnd, &
0.463998830432033721597269299429E-1_stnd, &
-0.191086148397852799983451475821E-1_stnd, &
-0.973768821003670776204287367278E-1_stnd, &
0.180352562073914141268335496511E-1_stnd, &
0.277129527093489643801598303110E-1_stnd, &
-0.176218263109360550515567818653E-1_stnd/)
!
REAL(kind=stnd), DIMENSION(1:7,1:ORBITS), PARAMETER :: &
WEIGHT = RESHAPE( SOURCE= (/ W1,W2,W3,W4,W5,W6,W7/), &
SHAPE=(/7,ORBITS/), ORDER=(/2,1/) )
!
! Local variables.
!
INTEGER :: J,NR,P,GENTYPE
REAL(kind=stnd):: NOISE,DEG4,DEG3,DEG1,R2,R1,R
REAL(kind=stnd), DIMENSION(NUMFUN) :: SUMVAL
REAL(kind=stnd), DIMENSION(NUMFUN,6) :: NullRule
REAL(kind=stnd), DIMENSION(3) :: Z
!
!***FIRST EXECUTABLE STATEMENT Rule_T3a
!
! The number of points used by the cubature formula is
! NUM = K(0) + 4*K(1) + 6*K(2) + 12*K(3) = 43
NUM = 43
!
! Initialise BASVAL and NullRule
!
BASVAL = 0
NullRule = 0
!
! Compute contributions from orbits with 1, 4, 6 and 12 points
!
P = 1
DO GENTYPE = 0,3
DO NR = 1,K(GENTYPE)
SELECT CASE (GENTYPE)
CASE (1) ! Generator ( z(1) , z(2), z(2) , z(2) )
Z(1) = TYPE1(NR)
Z(2) = (1-Z(1))/3
CASE (2) ! Generator ( z(1) , z(1), z(2) , z(2) )
Z(1) = TYPE2(NR)
Z(2) = (1-2*Z(1))/2
CASE (3) ! Generator ( z(1) , z(2), z(3) , z(3) )
Z(1:2) = TYPE3(1:2,NR)
Z(3) = (1-Z(1)-Z(2))/2
END SELECT
CALL OrbT3_Sum(GENTYPE,Z,VER,NUMFUN,Integrand,SUMVAL)
BASVAL = BASVAL + WEIGHT(1,P)*SUMVAL
DO J = 1,NUMFUN
NullRule(J,1:6) = NullRule(J,1:6) + WEIGHT(2:7,P)*SUMVAL(J)
END DO
P = P + 1
END DO
END DO
!
! Compute error estimates
!
DO J = 1,NUMFUN
NOISE = ABS(BASVAL(J))*TRES
DEG4 = SQRT(NullRule(J,1)**2+NullRule(J,2)**2)
DEG3 = SQRT(NullRule(J,3)**2+NullRule(J,4)**2)
IF (DEG4 <= NOISE) THEN
RGNERR(J) = NOISE
ELSE
DEG1 = SQRT(NullRule(J,5)**2+NullRule(J,6)**2)
IF (DEG3 /= 0) THEN
R1 = (DEG4/DEG3)**2
ELSE
R1 = 1
END IF
IF (DEG1 /= 0) THEN
R2 = DEG3/DEG1
ELSE
R2 = 1
END IF
R = MAX(R1,R2)
IF (R >= CRIVAL) THEN
RGNERR(J) = FACMED*R*DEG4
ELSE
RGNERR(J) = FACOPT*(R**2)*DEG4
END IF
RGNERR(J) = MAX(NOISE,RGNERR(J))
END IF
RGNERR(J) = VOLUME*RGNERR(J)
BASVAL(J) = VOLUME*BASVAL(J)
END DO
RETURN
END SUBROUTINE Rule_T3a
SUBROUTINE OrbT3_Sum(GENTYPE,GENER,VER,NUMFUN,Integrand,SUMVAL)
!***BEGIN PROLOGUE OrbT3_Sum
!***PURPOSE To compute the sum of function values over all points
! of an orbit.
!***DESCRIPTION
! ON ENTRY
!
! GENTYPE Integer
! The type of the orbit.
! GENER Integer array of dimension (3).
! The generator for the orbit in homogeneous coordinates.
! VER Real array of dimension (3,4).
! The coordinates of the vertices of the tetrahedron.
! vertex i -> ( ver(1,i),ver(2,i),ver(3,i) )
! NUMFUN Integer.
! Number of components of the vector integrand.
! Integrand Externally declared subroutine for computing
! all components of the integrand at the given
! evaluation point.
! It must have parameters (DIM,X,NUMFUN,FUNVLS)
! Input parameters:
! DIM = 3
! X(1) The x-coordinate of the evaluation point.
! X(2) The y-coordinate of the evaluation point.
! X(3) The z-coordinate of the evaluation point.
! NUMFUN Integer that defines the number of
! components of the vector integrand.
! Output parameter:
! FUNVLS Real array of dimension NUMFUN
! that defines NUMFUN components of the integrand.
! ON RETURN
!
! SUMVAL Real array of dimension (NUMFUN).
! The sum of function values over all points
! of the given orbit.
!
!***END PROLOGUE OrbT3_Sum
!
! Global variables
!
INTEGER, INTENT(IN) :: NUMFUN,GENTYPE
REAL(kind=stnd), DIMENSION(:), INTENT(IN) :: GENER
REAL(kind=stnd), DIMENSION(:), INTENT(OUT) :: SUMVAL
REAL(kind=stnd), DIMENSION(:,:), INTENT(IN) :: VER
INTERFACE
FUNCTION Integrand(NUMFUN,X) RESULT(Value)
USE Precision_Model
INTEGER, INTENT(IN) :: NUMFUN
REAL(kind=stnd), DIMENSION(:), INTENT(IN) :: X
REAL(kind=stnd), DIMENSION(NUMFUN) :: Value
END FUNCTION Integrand
END INTERFACE
!
! Local variables
!
INTEGER :: J,NUMBER
REAL(kind=stnd):: Z1,Z2,Z3
REAL(kind=stnd), DIMENSION(3,12) :: X
REAL(kind=stnd), DIMENSION(NUMFUN) :: WORK
!***FIRST EXECUTABLE STATEMENT OrbT3_Sum
SELECT CASE (GENTYPE)
!
! Generator with homogeneous coordinates (1/4,1/4,1/4,1/4)
!
CASE (0)
NUMBER = 1
X(:,1) = SUM( VER, DIM=2 )/4
!
! Generator with homogeneous coordinates (z1,z2,z2,z2)
!
CASE (1)
NUMBER = 4
Z1 = GENER(1)
Z2 = GENER(2)
X(:,1) = Z1*VER(:,1) + Z2* (VER(:,2)+VER(:,3)+VER(:,4))
X(:,2) = Z1*VER(:,2) + Z2* (VER(:,1)+VER(:,3)+VER(:,4))
X(:,3) = Z1*VER(:,3) + Z2* (VER(:,2)+VER(:,1)+VER(:,4))
X(:,4) = Z1*VER(:,4) + Z2* (VER(:,2)+VER(:,3)+VER(:,1))
!
! Generator with homogeneous coordinates (z1,z1,z2,z2)
!
CASE (2)
NUMBER = 6
Z1 = GENER(1)
Z2 = GENER(2)
X(:,1) = Z1* (VER(:,1)+VER(:,2)) + Z2* (VER(:,3)+VER(:,4))
X(:,2) = Z1* (VER(:,1)+VER(:,3)) + Z2* (VER(:,2)+VER(:,4))
X(:,3) = Z1* (VER(:,1)+VER(:,4)) + Z2* (VER(:,3)+VER(:,2))
X(:,4) = Z1* (VER(:,2)+VER(:,3)) + Z2* (VER(:,1)+VER(:,4))
X(:,5) = Z1* (VER(:,2)+VER(:,4)) + Z2* (VER(:,1)+VER(:,3))
X(:,6) = Z1* (VER(:,3)+VER(:,4)) + Z2* (VER(:,1)+VER(:,2))
!
! Generator with homogeneous coordinates (z1,z2,z3,z3)
!
CASE (3)
NUMBER = 12
Z1 = GENER(1)
Z2 = GENER(2)
Z3 = GENER(3)
X(:,1) = Z1*VER(:,1) + Z2*VER(:,2) + Z3* (VER(:,3)+VER(:,4))
X(:,2) = Z1*VER(:,1) + Z2*VER(:,3) + Z3* (VER(:,2)+VER(:,4))
X(:,3) = Z1*VER(:,1) + Z2*VER(:,4) + Z3* (VER(:,2)+VER(:,3))
X(:,4) = Z1*VER(:,2) + Z2*VER(:,1) + Z3* (VER(:,3)+VER(:,4))
X(:,5) = Z1*VER(:,2) + Z2*VER(:,3) + Z3* (VER(:,1)+VER(:,4))
X(:,6) = Z1*VER(:,2) + Z2*VER(:,4) + Z3* (VER(:,1)+VER(:,3))
X(:,7) = Z1*VER(:,3) + Z2*VER(:,1) + Z3* (VER(:,2)+VER(:,4))
X(:,8) = Z1*VER(:,3) + Z2*VER(:,2) + Z3* (VER(:,1)+VER(:,4))
X(:,9) = Z1*VER(:,3) + Z2*VER(:,4) + Z3* (VER(:,1)+VER(:,2))
X(:,10) = Z1*VER(:,4) + Z2*VER(:,1) + Z3* (VER(:,2)+VER(:,3))
X(:,11) = Z1*VER(:,4) + Z2*VER(:,2) + Z3* (VER(:,1)+VER(:,3))
X(:,12) = Z1*VER(:,4) + Z2*VER(:,3) + Z3* (VER(:,1)+VER(:,2))
END SELECT
SUMVAL = Integrand(NUMFUN,X(:,1))
DO J = 2,NUMBER
WORK = Integrand(NUMFUN,X(:,J))
SUMVAL(1:NUMFUN) = SUMVAL(1:NUMFUN) + WORK(1:NUMFUN)
END DO
RETURN
END SUBROUTINE OrbT3_Sum
END MODULE CubatureRule_T3
| mit |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/elemental_function_3.f90 | 16 | 1560 | ! { dg-do run }
!
! Test the fix for PR84109 in which the call to the elemental function
! 'adjustl' was being added before the scalarization loop in the assignment.
! Since the result temporary was being declared in the loop body, this
! drove the gimplifier crazy. It is sufficient to compile this testcase
! since it used to ICE. This is the intrinsic counterpart to PR87239,
! which is tested for the absence of an ICE in elemental_function_2.f90.
! In this fix, a further improvement was to keep scalar calls outside the
! scalarization loop and this is tested with 'my_adjustl'.
!
! Contributed by Willem Vermin <wvermin@gmail.com>
!
program prog
implicit none
character(len=:), allocatable :: c(:)
integer :: cnt = 0
allocate(character(len=20) :: c(10))
c = " ab "
c = adjustl(c) ! Used to ICE
if (trim (c(1)) .ne. "ab") stop 1
c = my_adjustl (" abcdefg ")
if (trim (c(1)) .ne. "abcdefg") stop 2
if (cnt .ne. 1) stop 3 ! Outside the scalarization loop
if (size (c, 1) .ne. 10) stop 4
if (len (c) .ne. 20) stop 5
cnt = 0
c = my_adjustl ([" uv ", " xy "])
if (trim (c(2)) .ne. "xy") stop 6
if (cnt .ne. size (c, 1)) stop 7 ! Inside the scalarization loop
if (size (c, 1) .ne. 2) stop 8
contains
impure elemental function my_adjustl(arg) result (res)
character(*), intent(in) :: arg
character(len = len (arg)) :: res
res = adjustl (arg)
cnt = cnt + 1 ! Test how many calls are made
end function
end program
| gpl-2.0 |
kito-cheng/riscv-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 |
surhudm/scipy | scipy/integrate/quadpack/dqawoe.f | 115 | 21404 | subroutine dqawoe (f,a,b,omega,integr,epsabs,epsrel,limit,icall,
* maxp1,result,abserr,neval,ier,last,alist,blist,rlist,elist,iord,
* nnlog,momcom,chebmo)
c***begin prologue dqawoe
c***date written 800101 (yymmdd)
c***revision date 830518 (yymmdd)
c***category no. h2a2a1
c***keywords automatic integrator, special-purpose,
c integrand with oscillatory cos or sin factor,
c clenshaw-curtis method, (end point) singularities,
c extrapolation, globally adaptive
c***author piessens,robert,appl. math. & progr. div. - k.u.leuven
c de doncker,elise,appl. math. & progr. div. - k.u.leuven
c***purpose the routine calculates an approximation result to a given
c definite integral
c i = integral of f(x)*w(x) over (a,b)
c where w(x) = cos(omega*x) or w(x)=sin(omega*x),
c hopefully satisfying following claim for accuracy
c abs(i-result).le.max(epsabs,epsrel*abs(i)).
c***description
c
c computation of oscillatory integrals
c standard fortran subroutine
c double precision version
c
c parameters
c on entry
c f - double precision
c function subprogram defining the integrand
c function f(x). the actual name for f needs to 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 omega - double precision
c parameter in the integrand weight function
c
c integr - integer
c indicates which of the weight functions is to be
c used
c integr = 1 w(x) = cos(omega*x)
c integr = 2 w(x) = sin(omega*x)
c if integr.ne.1 and integr.ne.2, the routine
c will end with ier = 6.
c
c epsabs - double precision
c absolute accuracy requested
c epsrel - double precision
c relative accuracy requested
c if epsabs.le.0
c and epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
c the routine will end with ier = 6.
c
c limit - integer
c gives an upper bound on the number of subdivisions
c in the partition of (a,b), limit.ge.1.
c
c icall - integer
c if dqawoe is to be used only once, icall must
c be set to 1. assume that during this call, the
c chebyshev moments (for clenshaw-curtis integration
c of degree 24) have been computed for intervals of
c lenghts (abs(b-a))*2**(-l), l=0,1,2,...momcom-1.
c if icall.gt.1 this means that dqawoe has been
c called twice or more on intervals of the same
c length abs(b-a). the chebyshev moments already
c computed are then re-used in subsequent calls.
c if icall.lt.1, the routine will end with ier = 6.
c
c maxp1 - integer
c gives an upper bound on the number of chebyshev
c moments which can be stored, i.e. for the
c intervals of lenghts abs(b-a)*2**(-l),
c l=0,1, ..., maxp1-2, maxp1.ge.1.
c if maxp1.lt.1, the routine will end with ier = 6.
c
c on return
c result - double precision
c approximation to the integral
c
c abserr - double precision
c estimate of the modulus of the absolute error,
c which should equal or exceed abs(i-result)
c
c neval - integer
c number of integrand evaluations
c
c ier - integer
c ier = 0 normal and reliable termination of the
c routine. it is assumed that the
c requested accuracy has been achieved.
c - ier.gt.0 abnormal termination of the routine.
c the estimates for integral and error are
c less reliable. it is assumed that the
c requested accuracy has not been achieved.
c error messages
c ier = 1 maximum number of subdivisions allowed
c has been achieved. one can allow more
c subdivisions by increasing the value of
c limit (and taking according dimension
c adjustments into account). however, if
c this yields no improvement it is advised
c to analyze the integrand, in order to
c determine the integration difficulties.
c if the position of a local difficulty can
c be determined (e.g. singularity,
c discontinuity within the interval) one
c will probably gain from splitting up the
c interval at this point and calling the
c integrator on the subranges. if possible,
c an appropriate special-purpose integrator
c should be used which is designed for
c handling the type of difficulty involved.
c = 2 the occurrence of roundoff error is
c detected, which prevents the requested
c tolerance from being achieved.
c the error may be under-estimated.
c = 3 extremely bad integrand behaviour occurs
c at some points of the integration
c interval.
c = 4 the algorithm does not converge.
c roundoff error is detected in the
c extrapolation table.
c it is presumed that the requested
c tolerance cannot be achieved due to
c roundoff in the extrapolation table,
c and that the returned result is the
c best which can be obtained.
c = 5 the integral is probably divergent, or
c slowly convergent. it must be noted that
c divergence can occur with any other value
c of ier.gt.0.
c = 6 the input is invalid, because
c (epsabs.le.0 and
c epsrel.lt.max(50*rel.mach.acc.,0.5d-28))
c or (integr.ne.1 and integr.ne.2) or
c icall.lt.1 or maxp1.lt.1.
c result, abserr, neval, last, rlist(1),
c elist(1), iord(1) and nnlog(1) are set
c to zero. alist(1) and blist(1) are set
c to a and b respectively.
c
c last - integer
c on return, last equals the number of
c subintervals produces in the subdivision
c process, which determines the number of
c significant elements actually in the
c work arrays.
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 integral
c approximations on the subintervals
c
c elist - double precision
c vector of dimension at least limit, the first
c last elements of which are the moduli of the
c absolute error estimates on the subintervals
c
c iord - integer
c vector of dimension at least limit, the first k
c elements of which are pointers to the error
c estimates over the subintervals,
c such that elist(iord(1)), ...,
c elist(iord(k)) form a decreasing sequence, with
c k = last if last.le.(limit/2+2), and
c k = limit+1-last otherwise.
c
c nnlog - integer
c vector of dimension at least limit, containing the
c subdivision levels of the subintervals, i.e.
c iwork(i) = l means that the subinterval
c numbered i is of length abs(b-a)*2**(1-l)
c
c on entry and return
c momcom - integer
c indicating that the chebyshev moments
c have been computed for intervals of lengths
c (abs(b-a))*2**(-l), l=0,1,2, ..., momcom-1,
c momcom.lt.maxp1
c
c chebmo - double precision
c array of dimension (maxp1,25) containing the
c chebyshev moments
c
c***references (none)
c***routines called d1mach,dqc25f,dqelg,dqpsrt
c***end prologue dqawoe
c
double precision a,abseps,abserr,alist,area,area1,area12,area2,a1,
* a2,b,blist,b1,b2,chebmo,correc,dabs,defab1,defab2,defabs,dmax1,
* domega,d1mach,dres,elist,epmach,epsabs,epsrel,erlarg,erlast,
* errbnd,errmax,error1,erro12,error2,errsum,ertest,f,oflow,
* omega,resabs,reseps,result,res3la,rlist,rlist2,small,uflow,width
integer icall,id,ier,ierro,integr,iord,iroff1,iroff2,iroff3,
* jupbnd,k,ksgn,ktmin,last,limit,maxerr,maxp1,momcom,nev,neval,
* nnlog,nres,nrmax,nrmom,numrl2
logical extrap,noext,extall
c
dimension alist(limit),blist(limit),rlist(limit),elist(limit),
* iord(limit),rlist2(52),res3la(3),chebmo(maxp1,25),nnlog(limit)
c
external f
c
c the dimension of rlist2 is determined by the value of
c limexp in subroutine dqelg (rlist2 should be of
c dimension (limexp+2) at least).
c
c list of major variables
c -----------------------
c
c alist - list of left end points of all subintervals
c considered up to now
c blist - list of right end points of all subintervals
c considered up to now
c rlist(i) - approximation to the integral over
c (alist(i),blist(i))
c rlist2 - array of dimension at least limexp+2
c containing the part of the epsilon table
c which is still needed for further computations
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 erlast - error on the interval currently subdivided
c area - sum of the integrals over the subintervals
c errsum - sum of the errors over the subintervals
c errbnd - requested accuracy max(epsabs,epsrel*
c abs(result))
c *****1 - variable for the left subinterval
c *****2 - variable for the right subinterval
c last - index for subdivision
c nres - number of calls to the extrapolation routine
c numrl2 - number of elements in rlist2. if an appropriate
c approximation to the compounded integral has
c been obtained it is put in rlist2(numrl2) after
c numrl2 has been increased by one
c small - length of the smallest interval considered
c up to now, multiplied by 1.5
c erlarg - sum of the errors over the intervals larger
c than the smallest interval considered up to now
c extrap - logical variable denoting that the routine is
c attempting to perform extrapolation, i.e. before
c subdividing the smallest interval we try to
c decrease the value of erlarg
c noext - logical variable denoting that extrapolation
c is no longer allowed (true value)
c
c machine dependent constants
c ---------------------------
c
c epmach is the largest relative spacing.
c uflow is the smallest positive magnitude.
c oflow is the largest positive magnitude.
c
c***first executable statement dqawoe
epmach = d1mach(4)
c
c test on validity of parameters
c ------------------------------
c
ier = 0
neval = 0
last = 0
result = 0.0d+00
abserr = 0.0d+00
alist(1) = a
blist(1) = b
rlist(1) = 0.0d+00
elist(1) = 0.0d+00
iord(1) = 0
nnlog(1) = 0
if((integr.ne.1.and.integr.ne.2).or.(epsabs.le.0.0d+00.and.
* epsrel.lt.dmax1(0.5d+02*epmach,0.5d-28)).or.icall.lt.1.or.
* maxp1.lt.1) ier = 6
if(ier.eq.6) go to 999
c
c first approximation to the integral
c -----------------------------------
c
domega = dabs(omega)
nrmom = 0
if (icall.gt.1) go to 5
momcom = 0
5 call dqc25f(f,a,b,domega,integr,nrmom,maxp1,0,result,abserr,
* neval,defabs,resabs,momcom,chebmo)
c
c test on accuracy.
c
dres = dabs(result)
errbnd = dmax1(epsabs,epsrel*dres)
rlist(1) = result
elist(1) = abserr
iord(1) = 1
if(abserr.le.0.1d+03*epmach*defabs.and.abserr.gt.errbnd) ier = 2
if(limit.eq.1) ier = 1
if(ier.ne.0.or.abserr.le.errbnd) go to 200
c
c initializations
c ---------------
c
uflow = d1mach(1)
oflow = d1mach(2)
errmax = abserr
maxerr = 1
area = result
errsum = abserr
abserr = oflow
nrmax = 1
extrap = .false.
noext = .false.
ierro = 0
iroff1 = 0
iroff2 = 0
iroff3 = 0
ktmin = 0
small = dabs(b-a)*0.75d+00
nres = 0
numrl2 = 0
extall = .false.
if(0.5d+00*dabs(b-a)*domega.gt.0.2d+01) go to 10
numrl2 = 1
extall = .true.
rlist2(1) = result
10 if(0.25d+00*dabs(b-a)*domega.le.0.2d+01) extall = .true.
ksgn = -1
if(dres.ge.(0.1d+01-0.5d+02*epmach)*defabs) ksgn = 1
c
c main do-loop
c ------------
c
do 140 last = 2,limit
c
c bisect the subinterval with the nrmax-th largest
c error estimate.
c
nrmom = nnlog(maxerr)+1
a1 = alist(maxerr)
b1 = 0.5d+00*(alist(maxerr)+blist(maxerr))
a2 = b1
b2 = blist(maxerr)
erlast = errmax
call dqc25f(f,a1,b1,domega,integr,nrmom,maxp1,0,
* area1,error1,nev,resabs,defab1,momcom,chebmo)
neval = neval+nev
call dqc25f(f,a2,b2,domega,integr,nrmom,maxp1,1,
* area2,error2,nev,resabs,defab2,momcom,chebmo)
neval = neval+nev
c
c improve previous approximations to integral
c and error and test for accuracy.
c
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 25
if(dabs(rlist(maxerr)-area12).gt.0.1d-04*dabs(area12)
* .or.erro12.lt.0.99d+00*errmax) go to 20
if(extrap) iroff2 = iroff2+1
if(.not.extrap) iroff1 = iroff1+1
20 if(last.gt.10.and.erro12.gt.errmax) iroff3 = iroff3+1
25 rlist(maxerr) = area1
rlist(last) = area2
nnlog(maxerr) = nrmom
nnlog(last) = nrmom
errbnd = dmax1(epsabs,epsrel*dabs(area))
c
c test for roundoff error and eventually set error flag.
c
if(iroff1+iroff2.ge.10.or.iroff3.ge.20) ier = 2
if(iroff2.ge.5) ierro = 3
c
c set error flag in the case that the number of
c subintervals equals limit.
c
if(last.eq.limit) ier = 1
c
c set error flag in the case of bad integrand behaviour
c at a point of the integration range.
c
if(dmax1(dabs(a1),dabs(b2)).le.(0.1d+01+0.1d+03*epmach)
* *(dabs(a2)+0.1d+04*uflow)) ier = 4
c
c append the newly-created intervals to the list.
c
if(error2.gt.error1) go to 30
alist(last) = a2
blist(maxerr) = b1
blist(last) = b2
elist(maxerr) = error1
elist(last) = error2
go to 40
30 alist(maxerr) = a2
alist(last) = a1
blist(last) = b1
rlist(maxerr) = area2
rlist(last) = area1
elist(maxerr) = error2
elist(last) = error1
c
c call subroutine dqpsrt to maintain the descending ordering
c in the list of error estimates and select the subinterval
c with nrmax-th largest error estimate (to bisected next).
c
40 call dqpsrt(limit,last,maxerr,errmax,elist,iord,nrmax)
c ***jump out of do-loop
if(errsum.le.errbnd) go to 170
if(ier.ne.0) go to 150
if(last.eq.2.and.extall) go to 120
if(noext) go to 140
if(.not.extall) go to 50
erlarg = erlarg-erlast
if(dabs(b1-a1).gt.small) erlarg = erlarg+erro12
if(extrap) go to 70
c
c test whether the interval to be bisected next is the
c smallest interval.
c
50 width = dabs(blist(maxerr)-alist(maxerr))
if(width.gt.small) go to 140
if(extall) go to 60
c
c test whether we can start with the extrapolation procedure
c (we do this if we integrate over the next interval with
c use of a gauss-kronrod rule - see subroutine dqc25f).
c
small = small*0.5d+00
if(0.25d+00*width*domega.gt.0.2d+01) go to 140
extall = .true.
go to 130
60 extrap = .true.
nrmax = 2
70 if(ierro.eq.3.or.erlarg.le.ertest) go to 90
c
c the smallest interval has the largest error.
c before bisecting decrease the sum of the errors over
c the larger intervals (erlarg) and perform extrapolation.
c
jupbnd = last
if (last.gt.(limit/2+2)) jupbnd = limit+3-last
id = nrmax
do 80 k = id,jupbnd
maxerr = iord(nrmax)
errmax = elist(maxerr)
if(dabs(blist(maxerr)-alist(maxerr)).gt.small) go to 140
nrmax = nrmax+1
80 continue
c
c perform extrapolation.
c
90 numrl2 = numrl2+1
rlist2(numrl2) = area
if(numrl2.lt.3) go to 110
call dqelg(numrl2,rlist2,reseps,abseps,res3la,nres)
ktmin = ktmin+1
if(ktmin.gt.5.and.abserr.lt.0.1d-02*errsum) ier = 5
if(abseps.ge.abserr) go to 100
ktmin = 0
abserr = abseps
result = reseps
correc = erlarg
ertest = dmax1(epsabs,epsrel*dabs(reseps))
c ***jump out of do-loop
if(abserr.le.ertest) go to 150
c
c prepare bisection of the smallest interval.
c
100 if(numrl2.eq.1) noext = .true.
if(ier.eq.5) go to 150
110 maxerr = iord(1)
errmax = elist(maxerr)
nrmax = 1
extrap = .false.
small = small*0.5d+00
erlarg = errsum
go to 140
120 small = small*0.5d+00
numrl2 = numrl2+1
rlist2(numrl2) = area
130 ertest = errbnd
erlarg = errsum
140 continue
c
c set the final result.
c ---------------------
c
150 if(abserr.eq.oflow.or.nres.eq.0) go to 170
if(ier+ierro.eq.0) go to 165
if(ierro.eq.3) abserr = abserr+correc
if(ier.eq.0) ier = 3
if(result.ne.0.0d+00.and.area.ne.0.0d+00) go to 160
if(abserr.gt.errsum) go to 170
if(area.eq.0.0d+00) go to 190
go to 165
160 if(abserr/dabs(result).gt.errsum/dabs(area)) go to 170
c
c test on divergence.
c
165 if(ksgn.eq.(-1).and.dmax1(dabs(result),dabs(area)).le.
* defabs*0.1d-01) go to 190
if(0.1d-01.gt.(result/area).or.(result/area).gt.0.1d+03
* .or.errsum.ge.dabs(area)) ier = 6
go to 190
c
c compute global integral sum.
c
170 result = 0.0d+00
do 180 k=1,last
result = result+rlist(k)
180 continue
abserr = errsum
190 if (ier.gt.2) ier=ier-1
200 if (integr.eq.2.and.omega.lt.0.0d+00) result=-result
999 return
end
| bsd-3-clause |
bgin/MissileSimulation | External/QUADPACK/dqawoe.f | 115 | 21404 | subroutine dqawoe (f,a,b,omega,integr,epsabs,epsrel,limit,icall,
* maxp1,result,abserr,neval,ier,last,alist,blist,rlist,elist,iord,
* nnlog,momcom,chebmo)
c***begin prologue dqawoe
c***date written 800101 (yymmdd)
c***revision date 830518 (yymmdd)
c***category no. h2a2a1
c***keywords automatic integrator, special-purpose,
c integrand with oscillatory cos or sin factor,
c clenshaw-curtis method, (end point) singularities,
c extrapolation, globally adaptive
c***author piessens,robert,appl. math. & progr. div. - k.u.leuven
c de doncker,elise,appl. math. & progr. div. - k.u.leuven
c***purpose the routine calculates an approximation result to a given
c definite integral
c i = integral of f(x)*w(x) over (a,b)
c where w(x) = cos(omega*x) or w(x)=sin(omega*x),
c hopefully satisfying following claim for accuracy
c abs(i-result).le.max(epsabs,epsrel*abs(i)).
c***description
c
c computation of oscillatory integrals
c standard fortran subroutine
c double precision version
c
c parameters
c on entry
c f - double precision
c function subprogram defining the integrand
c function f(x). the actual name for f needs to 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 omega - double precision
c parameter in the integrand weight function
c
c integr - integer
c indicates which of the weight functions is to be
c used
c integr = 1 w(x) = cos(omega*x)
c integr = 2 w(x) = sin(omega*x)
c if integr.ne.1 and integr.ne.2, the routine
c will end with ier = 6.
c
c epsabs - double precision
c absolute accuracy requested
c epsrel - double precision
c relative accuracy requested
c if epsabs.le.0
c and epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
c the routine will end with ier = 6.
c
c limit - integer
c gives an upper bound on the number of subdivisions
c in the partition of (a,b), limit.ge.1.
c
c icall - integer
c if dqawoe is to be used only once, icall must
c be set to 1. assume that during this call, the
c chebyshev moments (for clenshaw-curtis integration
c of degree 24) have been computed for intervals of
c lenghts (abs(b-a))*2**(-l), l=0,1,2,...momcom-1.
c if icall.gt.1 this means that dqawoe has been
c called twice or more on intervals of the same
c length abs(b-a). the chebyshev moments already
c computed are then re-used in subsequent calls.
c if icall.lt.1, the routine will end with ier = 6.
c
c maxp1 - integer
c gives an upper bound on the number of chebyshev
c moments which can be stored, i.e. for the
c intervals of lenghts abs(b-a)*2**(-l),
c l=0,1, ..., maxp1-2, maxp1.ge.1.
c if maxp1.lt.1, the routine will end with ier = 6.
c
c on return
c result - double precision
c approximation to the integral
c
c abserr - double precision
c estimate of the modulus of the absolute error,
c which should equal or exceed abs(i-result)
c
c neval - integer
c number of integrand evaluations
c
c ier - integer
c ier = 0 normal and reliable termination of the
c routine. it is assumed that the
c requested accuracy has been achieved.
c - ier.gt.0 abnormal termination of the routine.
c the estimates for integral and error are
c less reliable. it is assumed that the
c requested accuracy has not been achieved.
c error messages
c ier = 1 maximum number of subdivisions allowed
c has been achieved. one can allow more
c subdivisions by increasing the value of
c limit (and taking according dimension
c adjustments into account). however, if
c this yields no improvement it is advised
c to analyze the integrand, in order to
c determine the integration difficulties.
c if the position of a local difficulty can
c be determined (e.g. singularity,
c discontinuity within the interval) one
c will probably gain from splitting up the
c interval at this point and calling the
c integrator on the subranges. if possible,
c an appropriate special-purpose integrator
c should be used which is designed for
c handling the type of difficulty involved.
c = 2 the occurrence of roundoff error is
c detected, which prevents the requested
c tolerance from being achieved.
c the error may be under-estimated.
c = 3 extremely bad integrand behaviour occurs
c at some points of the integration
c interval.
c = 4 the algorithm does not converge.
c roundoff error is detected in the
c extrapolation table.
c it is presumed that the requested
c tolerance cannot be achieved due to
c roundoff in the extrapolation table,
c and that the returned result is the
c best which can be obtained.
c = 5 the integral is probably divergent, or
c slowly convergent. it must be noted that
c divergence can occur with any other value
c of ier.gt.0.
c = 6 the input is invalid, because
c (epsabs.le.0 and
c epsrel.lt.max(50*rel.mach.acc.,0.5d-28))
c or (integr.ne.1 and integr.ne.2) or
c icall.lt.1 or maxp1.lt.1.
c result, abserr, neval, last, rlist(1),
c elist(1), iord(1) and nnlog(1) are set
c to zero. alist(1) and blist(1) are set
c to a and b respectively.
c
c last - integer
c on return, last equals the number of
c subintervals produces in the subdivision
c process, which determines the number of
c significant elements actually in the
c work arrays.
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 integral
c approximations on the subintervals
c
c elist - double precision
c vector of dimension at least limit, the first
c last elements of which are the moduli of the
c absolute error estimates on the subintervals
c
c iord - integer
c vector of dimension at least limit, the first k
c elements of which are pointers to the error
c estimates over the subintervals,
c such that elist(iord(1)), ...,
c elist(iord(k)) form a decreasing sequence, with
c k = last if last.le.(limit/2+2), and
c k = limit+1-last otherwise.
c
c nnlog - integer
c vector of dimension at least limit, containing the
c subdivision levels of the subintervals, i.e.
c iwork(i) = l means that the subinterval
c numbered i is of length abs(b-a)*2**(1-l)
c
c on entry and return
c momcom - integer
c indicating that the chebyshev moments
c have been computed for intervals of lengths
c (abs(b-a))*2**(-l), l=0,1,2, ..., momcom-1,
c momcom.lt.maxp1
c
c chebmo - double precision
c array of dimension (maxp1,25) containing the
c chebyshev moments
c
c***references (none)
c***routines called d1mach,dqc25f,dqelg,dqpsrt
c***end prologue dqawoe
c
double precision a,abseps,abserr,alist,area,area1,area12,area2,a1,
* a2,b,blist,b1,b2,chebmo,correc,dabs,defab1,defab2,defabs,dmax1,
* domega,d1mach,dres,elist,epmach,epsabs,epsrel,erlarg,erlast,
* errbnd,errmax,error1,erro12,error2,errsum,ertest,f,oflow,
* omega,resabs,reseps,result,res3la,rlist,rlist2,small,uflow,width
integer icall,id,ier,ierro,integr,iord,iroff1,iroff2,iroff3,
* jupbnd,k,ksgn,ktmin,last,limit,maxerr,maxp1,momcom,nev,neval,
* nnlog,nres,nrmax,nrmom,numrl2
logical extrap,noext,extall
c
dimension alist(limit),blist(limit),rlist(limit),elist(limit),
* iord(limit),rlist2(52),res3la(3),chebmo(maxp1,25),nnlog(limit)
c
external f
c
c the dimension of rlist2 is determined by the value of
c limexp in subroutine dqelg (rlist2 should be of
c dimension (limexp+2) at least).
c
c list of major variables
c -----------------------
c
c alist - list of left end points of all subintervals
c considered up to now
c blist - list of right end points of all subintervals
c considered up to now
c rlist(i) - approximation to the integral over
c (alist(i),blist(i))
c rlist2 - array of dimension at least limexp+2
c containing the part of the epsilon table
c which is still needed for further computations
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 erlast - error on the interval currently subdivided
c area - sum of the integrals over the subintervals
c errsum - sum of the errors over the subintervals
c errbnd - requested accuracy max(epsabs,epsrel*
c abs(result))
c *****1 - variable for the left subinterval
c *****2 - variable for the right subinterval
c last - index for subdivision
c nres - number of calls to the extrapolation routine
c numrl2 - number of elements in rlist2. if an appropriate
c approximation to the compounded integral has
c been obtained it is put in rlist2(numrl2) after
c numrl2 has been increased by one
c small - length of the smallest interval considered
c up to now, multiplied by 1.5
c erlarg - sum of the errors over the intervals larger
c than the smallest interval considered up to now
c extrap - logical variable denoting that the routine is
c attempting to perform extrapolation, i.e. before
c subdividing the smallest interval we try to
c decrease the value of erlarg
c noext - logical variable denoting that extrapolation
c is no longer allowed (true value)
c
c machine dependent constants
c ---------------------------
c
c epmach is the largest relative spacing.
c uflow is the smallest positive magnitude.
c oflow is the largest positive magnitude.
c
c***first executable statement dqawoe
epmach = d1mach(4)
c
c test on validity of parameters
c ------------------------------
c
ier = 0
neval = 0
last = 0
result = 0.0d+00
abserr = 0.0d+00
alist(1) = a
blist(1) = b
rlist(1) = 0.0d+00
elist(1) = 0.0d+00
iord(1) = 0
nnlog(1) = 0
if((integr.ne.1.and.integr.ne.2).or.(epsabs.le.0.0d+00.and.
* epsrel.lt.dmax1(0.5d+02*epmach,0.5d-28)).or.icall.lt.1.or.
* maxp1.lt.1) ier = 6
if(ier.eq.6) go to 999
c
c first approximation to the integral
c -----------------------------------
c
domega = dabs(omega)
nrmom = 0
if (icall.gt.1) go to 5
momcom = 0
5 call dqc25f(f,a,b,domega,integr,nrmom,maxp1,0,result,abserr,
* neval,defabs,resabs,momcom,chebmo)
c
c test on accuracy.
c
dres = dabs(result)
errbnd = dmax1(epsabs,epsrel*dres)
rlist(1) = result
elist(1) = abserr
iord(1) = 1
if(abserr.le.0.1d+03*epmach*defabs.and.abserr.gt.errbnd) ier = 2
if(limit.eq.1) ier = 1
if(ier.ne.0.or.abserr.le.errbnd) go to 200
c
c initializations
c ---------------
c
uflow = d1mach(1)
oflow = d1mach(2)
errmax = abserr
maxerr = 1
area = result
errsum = abserr
abserr = oflow
nrmax = 1
extrap = .false.
noext = .false.
ierro = 0
iroff1 = 0
iroff2 = 0
iroff3 = 0
ktmin = 0
small = dabs(b-a)*0.75d+00
nres = 0
numrl2 = 0
extall = .false.
if(0.5d+00*dabs(b-a)*domega.gt.0.2d+01) go to 10
numrl2 = 1
extall = .true.
rlist2(1) = result
10 if(0.25d+00*dabs(b-a)*domega.le.0.2d+01) extall = .true.
ksgn = -1
if(dres.ge.(0.1d+01-0.5d+02*epmach)*defabs) ksgn = 1
c
c main do-loop
c ------------
c
do 140 last = 2,limit
c
c bisect the subinterval with the nrmax-th largest
c error estimate.
c
nrmom = nnlog(maxerr)+1
a1 = alist(maxerr)
b1 = 0.5d+00*(alist(maxerr)+blist(maxerr))
a2 = b1
b2 = blist(maxerr)
erlast = errmax
call dqc25f(f,a1,b1,domega,integr,nrmom,maxp1,0,
* area1,error1,nev,resabs,defab1,momcom,chebmo)
neval = neval+nev
call dqc25f(f,a2,b2,domega,integr,nrmom,maxp1,1,
* area2,error2,nev,resabs,defab2,momcom,chebmo)
neval = neval+nev
c
c improve previous approximations to integral
c and error and test for accuracy.
c
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 25
if(dabs(rlist(maxerr)-area12).gt.0.1d-04*dabs(area12)
* .or.erro12.lt.0.99d+00*errmax) go to 20
if(extrap) iroff2 = iroff2+1
if(.not.extrap) iroff1 = iroff1+1
20 if(last.gt.10.and.erro12.gt.errmax) iroff3 = iroff3+1
25 rlist(maxerr) = area1
rlist(last) = area2
nnlog(maxerr) = nrmom
nnlog(last) = nrmom
errbnd = dmax1(epsabs,epsrel*dabs(area))
c
c test for roundoff error and eventually set error flag.
c
if(iroff1+iroff2.ge.10.or.iroff3.ge.20) ier = 2
if(iroff2.ge.5) ierro = 3
c
c set error flag in the case that the number of
c subintervals equals limit.
c
if(last.eq.limit) ier = 1
c
c set error flag in the case of bad integrand behaviour
c at a point of the integration range.
c
if(dmax1(dabs(a1),dabs(b2)).le.(0.1d+01+0.1d+03*epmach)
* *(dabs(a2)+0.1d+04*uflow)) ier = 4
c
c append the newly-created intervals to the list.
c
if(error2.gt.error1) go to 30
alist(last) = a2
blist(maxerr) = b1
blist(last) = b2
elist(maxerr) = error1
elist(last) = error2
go to 40
30 alist(maxerr) = a2
alist(last) = a1
blist(last) = b1
rlist(maxerr) = area2
rlist(last) = area1
elist(maxerr) = error2
elist(last) = error1
c
c call subroutine dqpsrt to maintain the descending ordering
c in the list of error estimates and select the subinterval
c with nrmax-th largest error estimate (to bisected next).
c
40 call dqpsrt(limit,last,maxerr,errmax,elist,iord,nrmax)
c ***jump out of do-loop
if(errsum.le.errbnd) go to 170
if(ier.ne.0) go to 150
if(last.eq.2.and.extall) go to 120
if(noext) go to 140
if(.not.extall) go to 50
erlarg = erlarg-erlast
if(dabs(b1-a1).gt.small) erlarg = erlarg+erro12
if(extrap) go to 70
c
c test whether the interval to be bisected next is the
c smallest interval.
c
50 width = dabs(blist(maxerr)-alist(maxerr))
if(width.gt.small) go to 140
if(extall) go to 60
c
c test whether we can start with the extrapolation procedure
c (we do this if we integrate over the next interval with
c use of a gauss-kronrod rule - see subroutine dqc25f).
c
small = small*0.5d+00
if(0.25d+00*width*domega.gt.0.2d+01) go to 140
extall = .true.
go to 130
60 extrap = .true.
nrmax = 2
70 if(ierro.eq.3.or.erlarg.le.ertest) go to 90
c
c the smallest interval has the largest error.
c before bisecting decrease the sum of the errors over
c the larger intervals (erlarg) and perform extrapolation.
c
jupbnd = last
if (last.gt.(limit/2+2)) jupbnd = limit+3-last
id = nrmax
do 80 k = id,jupbnd
maxerr = iord(nrmax)
errmax = elist(maxerr)
if(dabs(blist(maxerr)-alist(maxerr)).gt.small) go to 140
nrmax = nrmax+1
80 continue
c
c perform extrapolation.
c
90 numrl2 = numrl2+1
rlist2(numrl2) = area
if(numrl2.lt.3) go to 110
call dqelg(numrl2,rlist2,reseps,abseps,res3la,nres)
ktmin = ktmin+1
if(ktmin.gt.5.and.abserr.lt.0.1d-02*errsum) ier = 5
if(abseps.ge.abserr) go to 100
ktmin = 0
abserr = abseps
result = reseps
correc = erlarg
ertest = dmax1(epsabs,epsrel*dabs(reseps))
c ***jump out of do-loop
if(abserr.le.ertest) go to 150
c
c prepare bisection of the smallest interval.
c
100 if(numrl2.eq.1) noext = .true.
if(ier.eq.5) go to 150
110 maxerr = iord(1)
errmax = elist(maxerr)
nrmax = 1
extrap = .false.
small = small*0.5d+00
erlarg = errsum
go to 140
120 small = small*0.5d+00
numrl2 = numrl2+1
rlist2(numrl2) = area
130 ertest = errbnd
erlarg = errsum
140 continue
c
c set the final result.
c ---------------------
c
150 if(abserr.eq.oflow.or.nres.eq.0) go to 170
if(ier+ierro.eq.0) go to 165
if(ierro.eq.3) abserr = abserr+correc
if(ier.eq.0) ier = 3
if(result.ne.0.0d+00.and.area.ne.0.0d+00) go to 160
if(abserr.gt.errsum) go to 170
if(area.eq.0.0d+00) go to 190
go to 165
160 if(abserr/dabs(result).gt.errsum/dabs(area)) go to 170
c
c test on divergence.
c
165 if(ksgn.eq.(-1).and.dmax1(dabs(result),dabs(area)).le.
* defabs*0.1d-01) go to 190
if(0.1d-01.gt.(result/area).or.(result/area).gt.0.1d+03
* .or.errsum.ge.dabs(area)) ier = 6
go to 190
c
c compute global integral sum.
c
170 result = 0.0d+00
do 180 k=1,last
result = result+rlist(k)
180 continue
abserr = errsum
190 if (ier.gt.2) ier=ier-1
200 if (integr.eq.2.and.omega.lt.0.0d+00) result=-result
999 return
end
| mit |
ForestClaw/forestclaw | applications/metric/2d/circles/mapc2m.f | 1 | 1035 | subroutine mapc2m(xc,yc,xp,yp,zp)
implicit none
double precision xc,yc,xp,yp,zp
double precision ll(2), ur(2)
logical isperiodic
c # This constructs mapping in [-1,-1]x[1,1]. To get
c # something in a box of a different size and location
c # translate below.
isperiodic = .false.
call mapc2m_inclusions(xc,yc,xp,yp,isperiodic)
c # Map to from [-1,1]x[-1,1] to [ll]x[ur]
c # The transformation below doesn't do anything, but demonstrates
c # how to translate and scale the output from the inclusions
c # maping.
ll(1) = -1
ll(2) = -1
ur(1) = 1
ur(2) = 1
call transform(xp,yp,ll,ur)
zp = 0
end
subroutine transform(xp,yp,ll,ur)
implicit none
double precision xp,yp,ll(2),ur(2)
xp = ll(1) + (ur(1) - ll(1))*(xp + 1.d0)/2.d0
yp = ll(2) + (ur(2) - ll(2))*(yp + 1.d0)/2.d0
end
double precision function exact_area()
implicit none
exact_area = 4.d0
end
| bsd-2-clause |
PUReIBM/PS3D | SRC/FLO/collision_mod.F90 | 1 | 62708 | ! PUReIBM-PS3D is a three-dimensional psudeo-spectral particle-resolved
! direct numerical simulation solver for detailed analysis of homogeneous
! fixed and freely evolving fluid-particle suspensions. PUReRIBM-PS3D
! is a continuum Navier-Stokes solver based on Cartesian grid that utilizes
! Immeresed Boundary method to represent particle surfuces.
! Copyright (C) 2015, Shankar Subramaniam, Rahul Garg, Sudheer Tenneti, Bo Sun, Mohammad Mehrabadi
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
! For acknowledgement, please refer to the following publications:
! (1) TENNETI, S. & SUBRAMANIAM, S., 2014, Particle-resolved direct numerical
! simulation for gas–solid flow model development. Annu. Rev. Fluid Mech.
! 46 (1), 199–230.
! (2) SUBRAMANIAM, S., MEHRABADI, M., HORWITZ, J. & MANI, A., 2014, Developing
! improved Lagrangian point particle models of gas–solid flow from
! particle-resolved direct numerical simulation. In Studying Turbulence
! Using Numerical Simulation Databases-XV, Proceedings of the CTR 2014
! Summer Program, pp. 5–14. Center for Turbulence Research, Stanford
! University, CA.
MODULE collision_mod
#include "ibm.h"
USE precision
USE constants
USE global_data
USE general_funcs
USE soft_spring
USE dem_mod
IMPLICIT NONE
INTEGER, ALLOCATABLE, DIMENSION(:) :: MINCOLLS
INTEGER, PRIVATE :: IFAC, FACTOR
Contains
SUBROUTINE des_time_march(initialize)
IMPLICIT NONE
LOGICAL, INTENT(in):: initialize
INTEGER :: LL, NP, I, shrink_trial, max_shrink_trials, L
logical :: test_ymaxval_tmp, shrink_tmp,free_evol_during_shrink
REAL(prcn) :: ymin, ymax, Ay, By, tstop_tmp
REAL(prcn):: ths, thcoll
max_shrink_trials = 5
shrink_trial = 0
test_ymaxval_tmp = test_ymaxval
tstop_tmp = tstop
shrink_tmp = shrink
free_evol_during_shrink = .true.
if(I_AM_NODE_ZERO) CALL screen_separator(80,'C')
if(I_AM_NODE_ZERO) WRITE(*,'(A20)')'IN COLLISION MODULES'
! WRITE(*,*) 'IN DES_TIME MARCH, iniiti, generpartconfig =', initialize, gener_config_case
IF(initialize)then
!!$ INITIALIZE COARSE GRID FOR DEM MODULES. The
!!$ particles will be moved based on this coarse grid.
CALL INITIALIZE_COARSE_GRID
!!$Allocate memory for the arrays used in DEM module
IF(.NOT.DES_ALLOC_CALLED) CALL DES_ALLOCATE_ARRAYS
!!$Initialize DEM arrays
CALL DES_INIT_ARRAYS
!!$Assign Particle properties
CALL CFASSIGN
if(.not.GENER_CONFIG_CASE)then
if(TRIM(collision_type).eq."softsphere")then
DTSOLID_ORIG = DTSOLID
end if
if(I_AM_NODE_ZERO)then
WRITE(*,'(A25,2(2x,g12.5))')'DES_EN_INPUT =', DES_EN_INPUT(1),DES_ET_INPUT(1)
Write(*,'(2(A30,(2x,g17.8)))')'DT FLUID = ', DT, 'DT COLLISIONAL&
& = ', DTSOLID_ORIG
end if
end if
CALL FIND_CELL_INDEX
CALL PARTICLES_IN_CELL
CALL GRID_BASED_NEIGHBOR_SEARCH
END IF
IF(.NOT.initialize)THEN
IF(GENER_CONFIG_CASE) THEN
10000 continue
CALL init_particles_jn
IF(TRIM(collision_type).eq."eventdriven")THEN
ALLOCATE( MINCOLLS(PARTICLES))
MINCOLLS = 0
do while (MINVAL(MINCOLLS(1:PARTICLES)).lt.min_colisions)
CALL HARD_SPHERE_COLLISION
CALL FIND_CELL_INDEX
CALL PARTICLES_IN_CELL
CALL GRID_BASED_NEIGHBOR_SEARCH
end do
DEALLOCATE(MINCOLLS)
ELSE IF(TRIM(collision_type).eq."softsphere") THEN
WRITE(*,*)'GENERATING INITIAL CONFIG BY SOFT SPHERE'
WRITE(*,'(A25,2x,g12.5)')'DES_EN_INPUT =', DES_EN_INPUT(1)
WRITE(*,*)'SHRINK, TESTYMAXVAL = ', SHRINK, TEST_YMAXVAL
FACTOR = NINT(TSTOP/DTSOLID)
WRITE(*,*)'FACTOR = ', FACTOR, TSTOP, DTSOLID
S_TIME = ZERO
DO IFAC = 1, FACTOR
!PRINT*,'SSCOLL, SHRINK, t =', SHRINK, S_TIME
CALL CFUPDATEOLD
CALL SOFT_SPHERE_COLLISION
IF(TEST_YMAXVAL.AND.(.NOT.SHRINK)) EXIT
CALL FIND_CELL_INDEX
CALL PARTICLES_IN_CELL
IF(MOD(IFAC,INT(NEIGHBOR_SEARCH_N)).EQ.0) CALL GRID_BASED_NEIGHBOR_SEARCH
end DO
IF(free_evol_during_shrink) then
test_ymaxval = test_ymaxval_tmp
shrink = shrink_tmp
tstop = tstop_tmp
end IF
IF(TEST_YMAXVAL.AND.SHRINK) THEN
IF(.not.free_evol_during_shrink) then
shrink_trial = shrink_trial + 1
IF(shrink_trial.gt.max_shrink_trials) then
WRITE(*,'(2(A20,2x,i4))') 'SHRINK TRIAL #', shrink_trial, 'GT THAN', MAX_SHRINK_TRIALS
WRITE(*,'(A)') 'FREELY EVOLVING THE SYSTEM FOR ONE STEP'
!Let the system evolve freely oncle
test_ymaxval = .false.
shrink = .false.
shrink_trial = 0
free_evol_during_shrink = .true.
tstop = 3.d0*tstop
ymin = MINVAL(DES_POS_NEW(1:PARTICLES,2)) - MAX_RADIUS
ymax = MAXVAL(DES_POS_NEW(1:PARTICLES,2)) + MAX_RADIUS
YLENGTH = ymax - ymin !+ 1.d0*MAX_RADIUS
Ay = YLENGTH/(ymax-ymin)
By = -Ay*ymin
DO L = 1, PARTICLES
DES_POS_NEW(L,2) = Ay*DES_POS_NEW(L,2) + By
end DO
XC_GENER(1:PARTICLES,1:3) = DES_POS_NEW(1:PARTICLES, 1:3)
RAD_GENER(1:PARTICLES) = DES_RADIUS(1:PARTICLES)
DES_EN_INPUT(:) = 0.5
DES_EN_WALL_INPUT(:) = 1.0
!!$ INITIALIZE COARSE GRID FOR DEM MODULES. The
!!$ particles will be moved based on this coarse grid.
CALL INITIALIZE_COARSE_GRID
!!$Allocate memory for the arrays used in DEM module
IF(.NOT.DES_ALLOC_CALLED) CALL DES_ALLOCATE_ARRAYS
!!$Initialize DEM arrays
CALL DES_INIT_ARRAYS
!!$Assign Particle properties
CALL CFASSIGN
CALL FIND_CELL_INDEX
CALL PARTICLES_IN_CELL
CALL GRID_BASED_NEIGHBOR_SEARCH
WRITE(*,'(A,2x,g17.8)') 'NEW YLENGTH = ', YLENGTH
ELSE
WRITE(*,'(A,i3,A)') 'SHRINKAGE NOT YET ACHEIVED AT',shrink_trial,' SO REDOING WITH NEW VELCOTIES'
end IF
ELSE
WRITE(*,'(A,i3,A)') 'FINISHED THE FREELY EVOLVING STEP DURING SHRINK: NOW BACK TO SHRINK'
DES_EN_INPUT = 0.3
DES_EN_WALL_INPUT = 1.0
XC_GENER(1:PARTICLES,1:3) = DES_POS_NEW(1:PARTICLES, 1:3)
RAD_GENER(1:PARTICLES) = DES_RADIUS(1:PARTICLES)
!!$ INITIALIZE COARSE GRID FOR DEM MODULES. The
!!$ particles will be moved based on this coarse grid.
CALL INITIALIZE_COARSE_GRID
!!$Allocate memory for the arrays used in DEM module
IF(.NOT.DES_ALLOC_CALLED) CALL DES_ALLOCATE_ARRAYS
!!$Initialize DEM arrays
CALL DES_INIT_ARRAYS
!!$Assign Particle properties
CALL CFASSIGN
CALL FIND_CELL_INDEX
CALL PARTICLES_IN_CELL
CALL GRID_BASED_NEIGHBOR_SEARCH
free_evol_during_shrink = .false.
end IF
goto 10000
end IF
IF(TEST_YMAXVAL) THEN
OPEN(1001, file=TRIM(RUN_NAME)//"_xc_post_ss_shrink.dat", form="formatted")
write(1001,*)'VARIABLES= ',' "X" ',' "Y" ',' "Z" ',' "UX" '
do NP = 1, PARTICLES
WRITE(1001,'(10(2x,g15.8))')( DES_POS_NEW(NP, i), i = 1, dimn), DES_RADIUS(NP)
ENDDO
CLOSE(1001,status="keep")
ELSE
OPEN(1001, file=TRIM(RUN_NAME)//"_xc_post_ss_mfp.dat", form="formatted")
write(1001,*)'VARIABLES= ',' "X" ',' "Y" ',' "Z" ',' "UX" '
do NP = 1, PARTICLES
WRITE(1001,'(10(2x,g15.8))')( DES_POS_NEW(NP, i), i = 1, dimn), DES_RADIUS(NP)
ENDDO
CLOSE(1001,status="keep")
ENDIF
end IF
ELSE
!DTSOLID = DT
IF(collision_type.eq."eventdriven")THEN
WRITE(*,'(A20)')'PERFORMING EVENTDRIVEN HARDSPHERE COLLISIONS'
ths = dt
thcoll = zero
Write(*,'(A40,(2x,g17.6))')'CURRENT FLOW TIME STEP = ', dt
Do While(thcoll.lt.ths)
dths = ths - thcoll
Write(*,'(A40,(2x,g17.6))')'REMAINING TIME IN HARD SPHERE = ', DTHS
DTSOLID = DTHS
CALL HARD_SPHERE_COLLISION
CALL FIND_CELL_INDEX
CALL PARTICLES_IN_CELL
CALL GRID_BASED_NEIGHBOR_SEARCH
CALL CFUPDATEOLD
thcoll = thcoll + dtsolid
WRITE(*,'(A40,2(2x,g17.6))')'CURRENT TIME IN HARD SPHERE = ', thcoll, ths-thcoll
End Do
ELSE IF(collision_type.eq."softsphere") THEN
FACTOR = INT(DT/DTSOLID_ORIG)
!JUST ADDED THIS TO LIMIT THE COLLISIONAL TIME STEP, ESPECIALLY FOR
!ZERO SLIP CASES.
if (FACTOR<50) then
factor = 50
dtsolid_ORIG = dt/factor
elseif (FACTOR>200) then
factor = 200
dtsolid_ORIG = dt/factor
endif
DTSOLID = DTSOLID_ORIG
if(FACTOR.LT.1)then
FACTOR = 1
DTSOLID = DT
end if
if (I_AM_NODE_ZERO) then
Write(*,'((A,3(2x,g12.5)))')'DT SOLID = ', DTSOLID
WRITE(*,'((A,3(2x,I8)))')'NO. OF SS TIME STEPS = ', FACTOR
endif
DO IFAC = 1, FACTOR
test_force(:) = zero
CALL SOFT_SPHERE_COLLISION
CALL CFUPDATEOLD
CALL FIND_CELL_INDEX
CALL PARTICLES_IN_CELL
!IF(MOD(IGLOBSTEP,INT(NEIGHBOR_SEARCH_N)).EQ.0) CALL GRID_BASED_NEIGHBOR_SEARCH
CALL GRID_BASED_NEIGHBOR_SEARCH
!WRITE(*,'(A,3(2x,g17.8)')'TOTAL FORCE = ', TEST_FORCE(:)
!READ(*,*)
END DO
ELSE IF(collision_type.eq."none")THEN
DTSOLID = dt
DO LL = 1, PARTICLES
WRITE(*,'(2(A,3(2x,g12.5)))')'FORCE = ', RHOF*FORCE(LL,:)/PMASS(LL),' GRAV = ',(ONE-RHOF/RHOS)*GRAV(:)
WRITE(*,'((A,3(2x,g12.5)))')'TORQUE = ', RHOF*OMOI(LL)*TORQ(LL,:)
! COMMENTING THIS, BECAUSE GRAVITY IS CHANGED TO MPG. IF BOTH GRAVITY AND MPG ARE AVAILABLE, THEN UNCOMMENT THIS
DES_VEL_NEW(LL,:) = RHOF*FORCE(LL,:)/PMASS(LL) !+ (one-rhof/rhos)*GRAV(:)
DES_VEL_NEW(LL,:) = DES_VEL_OLD(LL,:) !+
! DES_VEL_NEW(LL,:)*DTSOLID
OMEGA_NEW(LL,:) = OMEGA_OLD(LL,:) !+ RHOF*TORQ(LL,:)
!*OMOI(LL)*DTSOLID
Write(*,'(A30,3(2x,g17.8))')'DES_VEL_NEW =',&
& DES_VEL_NEW(LL,:)
! Write(*,'(A,3(2x,g17.8))')'DES_VEL_OLD =', DES_VEL_OLD(:)
Write(*,'(A30,3(2x,g17.8))')'OMEGA_NEW =',&
& OMEGA_NEW(LL,:)
CALL CFNEWVALUES(LL)
CALL CFUPDATEOLD
Write(*,'(A30,3(2x,g17.8))')'DES_POS_NEW =',&
& DES_POS_NEW(LL,:)/dx + one
!READ(*,*)
END DO
END IF
!!$ CALL CFUPDATEOLD
!!$
!!$ CALL FIND_CELL_INDEX
!!$ CALL PARTICLES_IN_CELL
!!$ CALL GRID_BASED_NEIGHBOR_SEARCH
CALL IBMUPDATE
end IF !GENER_CONFIG_CASE
END IF
if(I_AM_NODE_ZERO)then
Write(*,'(A20)')'LEAVING COLLISION MODULE'
CALL screen_separator(80,'C')
endif
!!$ DO I = 1, NBODY
!!$ PRINT*,'NEIGHS FOR I= ', I, ' ARE', NEIGHBOURS(I,1), NEIGHBOURS(I,2:NEIGHBOURS(I,1)+1)
!!$ END DO
END SUBROUTINE des_time_march
subroutine initialize_coarse_grid
implicit none
INTEGER :: i,j,k, ii, ll
REAL(prcn) :: dxeff
MMAX = 1
DIMN = NDIM
NWALLS = 2*DIMN
PARTICLES = NBODY
NEIGHBOR_SEARCH_N = 10
cgrid_fac = 1.5d0
if(nphases.gt.1)then
MN = 60
else
MN = 30
end if
FACTOR_RLM = 1.2d0
PARTICLES_FACTOR = 1.0
! CX,CY, CZ are the number of nodes of the coarse grid excluding ghost nodes
IF(GENER_CONFIG_CASE) THEN
dxeff = two*(MAXVAL(RAD_GENER(1:NBODY)))*cgrid_fac
!MAX_RADIUS = MAXVAL(RADBDY(1:NBODY))
ELSE
dxeff = two*(MAXVAL(RADBDY(1:NBODY)))*cgrid_fac*dx
!MAX_RADIUS = MAXVAL(RADBDY(1:NBODY))*
end IF
cy = MAX(NINT(YLENGTH/dxeff),2)
cx = MAX(NINT(XLENGTH/dxeff),2)
cz = MAX(NINT(ZLENGTH/dxeff),2)
!cz = cy
!cx = MAX(NINT(doml(1)/doml(2))*cy,2)
KN_W = 800000
KN = 800000
if(.not.GENER_CONFIG_CASE.and.(TRIM(collision_type).eq.'softsphere'))KN = 800000!20000
!if (zero_slip) then
! if (ReT>small_number) then
! kn = rhos * pi/6 * (ReT*vis)**2 / dia_phys / (0.01)**2 ! the last term is the maximum overlap
! if (I_AM_NODE_ZERO) write (*,*) "KN CHANGED TO ", kn, " TO LIMIT MAXIMUM OVERLAP TO 0.01"
! endif
!endif
MEW = 0.0
MEW_W = 0.0
DTSOLID_FACTOR = 1.d0
IF(allocated(cgrid)) then
DEALLOCATE(cgrid)
end IF
ALLOCATE(cgrid(cx,cy,cz,3))
dyc = YLENGTH/REAL(cy-1,prcn)
dxc = XLENGTH/REAL(cx-1,prcn)
dzc = ZLENGTH/REAL(cz-1,prcn)
DO k = 1, cz
do j = 1, cy
do i = 1, cx
cgrid(i,j,k,1) = (i-1)*dxc
cgrid(i,j,k,2) = (j-1)*dyc
cgrid(i,j,k,3) = (k-1)*dyc
end do
end do
end DO
!PRINT*,'doml ', doml(1), doml(2)
if (I_AM_NODE_ZERO) PRINT*,'cx, cy, cz = ', cx,cy,cz
!PRINT*,'dxc, dyc, dzc = ', dxc,dyc,dzc
! IMAX,JMAX,KMAX are the number of physical cells, excluding the ghost cells
IMAX = CX - 1
JMAX = CY - 1
KMAX = CZ - 1
! IMAX1,JMAX1,KMAX1 are the indices of the last physical CELL
IMAX1 = IMAX + 1
JMAX1 = JMAX + 1
KMAX1 = KMAX + 1
IMAX2 = IMAX1+1
JMAX2 = JMAX1+1
KMAX2 = KMAX1+1
IMAX3 = IMAX2
JMAX3 = JMAX2
KMAX3 = KMAX2
! IMIN1,JMIN1,KMIN1 are the indices of the first physical CELL
IMIN1 = 2
JMIN1 = 2
KMIN1 = 2
IMIN2 = 1
JMIN2 = 1
KMIN2 = 1
!!$ PRINT*,'IMAX, JMAX, KMAX = ', IMAX, JMAX, KMAX
!!$ PRINT*,'IMIN1, JMIN1, KMIN1 = ', IMIN1, JMIN1, KMIN1
!!$ PRINT*,'IMIN2, JMIN2, KMIN2 = ', IMIN2, JMIN2, KMIN2
!!$
!!$ PRINT*,'IMAX1, JMAX1, KMAX1 = ', IMAX1, JMAX1, KMAX1
!!$ PRINT*,'IMAX2, JMAX2, KMAX2 = ', IMAX2, JMAX2, KMAX2
!!$ PRINT*,'IMAX3, JMAX3, KMAX3 = ', IMAX3, JMAX3, KMAX3
IF(ALLOCATED(XE)) THEN
DEALLOCATE(XE,YN, ZT)
DEALLOCATE(pic, cnd)
end IF
ALLOCATE(XE(IMAX2), YN(JMAX2), ZT(KMAX2))
ALLOCATE(pic(IMAX2,JMAX2,KMAX2))
ALLOCATE(cnd(IMAX2,JMAX2,KMAX2))
DO k = 1,KMAX2!MAX(KMAX1-1,1)
DO j = 1,JMAX2
DO i = 1,IMAX2
NULLIFY(pic(i,j,k)%p)
cnd(i,j,k) = 0
end DO
end DO
end DO
XE = ZERO
YN = ZERO
ZT = ZERO
XE(1) = ZERO
YN(1) = ZERO
ZT(1) = ZERO
DO I = IMIN1, IMAX2
XE(I) = XE(I-1) + DXC
!PRINT*,'XE = ', I, XE(I)
END DO
DO J = JMIN1, JMAX2
YN(J) = YN(J-1) + DYC
END DO
DO K = KMIN1, KMAX2
ZT(K) = ZT(K-1) + DZC
END DO
if(I_AM_NODE_ZERO)then
WRITE(*,'(A40,2(2x,g17.8))') 'XLENGTH IN AND CALC =', XLENGTH, XE(IMAX1) - XE(IMIN2)
WRITE(*,'(A40,2(2x,g17.8))') 'YLENGTH IN AND CALC =', YLENGTH, YN(JMAX1) - YN(JMIN2)
WRITE(*,'(A40,2(2x,g17.8))') 'ZLENGTH IN AND CALC =', ZLENGTH, ZT(KMAX1) - ZT(KMIN2)
end if
end subroutine initialize_coarse_grid
SUBROUTINE DES_ALLOCATE_ARRAYS
IMPLICIT NONE
INTEGER NPARTICLES, I,J,K
INTEGER :: DIMENSION_I, DIMENSION_J, DIMENSION_K
DES_ALLOC_CALLED = .TRUE.
DIMENSION_I = IMAX3
DIMENSION_J = JMAX3
DIMENSION_K = KMAX3
!particles = npc*(imax)*(jmax)*kmax
NPARTICLES = PARTICLES * PARTICLES_FACTOR + NWALLS
MAXNEIGHBORS = MN + 1 + NWALLS
ALLOCATE(RO_S(MMAX), D_p0(MMAX))
Allocate( NEIGHBOURS (NPARTICLES, MAXNEIGHBORS) )
ALLOCATE(PIJK(PARTICLES,3))
ALLOCATE(IS_MOBILE(PARTICLES), CAUSE_MOTION(PARTICLES))
ALLOCATE(REAL_EN(MMAX,MMAX),REAL_ET(MMAX,MMAX))
ALLOCATE(REAL_EN_WALL(MMAX),REAL_ET_WALL(MMAX))
!
ALLOCATE(DES_ETAN(MMAX,MMAX))
ALLOCATE(DES_ETAT(MMAX,MMAX))
ALLOCATE(DES_ETAN_WALL(MMAX), DES_ETAT_WALL(MMAX))
Allocate( DES_RADIUS (NPARTICLES) )
Allocate( RO_Sol (NPARTICLES) )
Allocate( PVOL (NPARTICLES) )
Allocate( PMASS (NPARTICLES) )
Allocate( OMOI (NPARTICLES) )
!
! Old and new particle positions, velocities (translational and
! rotational) )
Allocate( DES_POS_OLD (NPARTICLES,DIMN) )
Allocate( DES_POS_NEW (NPARTICLES,DIMN) )
Allocate( DES_VEL_OLD (NPARTICLES,DIMN) )
Allocate( DES_VEL_NEW (NPARTICLES,DIMN) )
IF(DIMN.GT.2) THEN
Allocate( OMEGA_OLD (NPARTICLES,DIMN) )
Allocate( OMEGA_NEW (NPARTICLES,DIMN) )
ELSE
Allocate( OMEGA_OLD (NPARTICLES,1) )
Allocate( OMEGA_NEW (NPARTICLES,1) )
END IF
Allocate( PPOS (NPARTICLES,DIMN) )
!
! Total, normal and tangetial forces
Allocate( FC (NPARTICLES,DIMN) )
Allocate( FN (NPARTICLES,DIMN) )
Allocate( FT (NPARTICLES,DIMN) )
Allocate( FNS2 (DIMN) )
Allocate( FTS2 (DIMN) )
Allocate( FNS1 (DIMN) )
Allocate( FTS1 (DIMN) )
!
! Torque
IF(DIMN.EQ.3) THEN
Allocate( TOW (NPARTICLES,DIMN) )
ELSE
Allocate( TOW (NPARTICLES,1) )
END IF
!
! Accumulated spring forces
Allocate( PFN (NPARTICLES,MAXNEIGHBORS,DIMN) )
Allocate( PFT (NPARTICLES,MAXNEIGHBORS,DIMN) )
!
! Wall position, velocity and normal vector
Allocate( DES_WALL_POS (NWALLS,DIMN) )
Allocate( DES_WALL_VEL (NWALLS,DIMN) )
Allocate( WALL_NORMAL (NWALLS,DIMN) )
Allocate( PN (NPARTICLES, MAXNEIGHBORS) )
Allocate( PV (NPARTICLES, MAXNEIGHBORS) )
ALLOCATE(TEST_FORCE(DIMN))
! Particles in a computational cell (for volume fraction) )
!Allocate( PIJK (PARTICLES,5) )
end SUBROUTINE DES_ALLOCATE_ARRAYS
SUBROUTINE CFASSIGN
IMPLICIT NONE
LOGICAL:: filexist, isopen
INTEGER L, IJK, M, I,J, K, COUNT_E
DOUBLE PRECISION FOUR_BY_THREE, RAD2, MINMASS, MASS_I, MASS_J, MASS_EFF
DOUBLE PRECISION :: TCOLL, TCOLL_TMP, AVG_MASS, MAXMASS
!
!---------------------------------------------------------------------
! Assignments
!---------------------------------------------------------------------
!
WALLDTSPLIT = .FALSE.
FOUR_BY_THREE = 4.0d0/3.0d0
MINMASS = LARGE_NUMBER
MAXMASS = SMALL_NUMBER
MAX_RADIUS = ZERO
MIN_RADIUS = LARGE_NUMBER
TCOLL = LARGE_NUMBER
RMS_RAD = ZERO
!if(.not.gener_config_case)KN = 2.0E+04
DO L = 1, PARTICLES
if(GENER_CONFIG_CASE)then
Ro_Sol(L) = three/(four*pi*DES_RADIUS(L)**3.d0)
else
Ro_Sol(L) = RHOS!three/(four*pi*DES_RADIUS(L)**3.d0)
end if
RAD2 = DES_RADIUS(L)**2
PVOL(L) = FOUR_BY_THREE*Pi*RAD2*DES_RADIUS(L)
PMASS(L) = PVOL(L)*RO_Sol(L)
OMOI(L) = 2.5d0/(PMASS(L)*RAD2) !one over MOI
MAX_RADIUS = MAX(MAX_RADIUS, DES_RADIUS(L))
MIN_RADIUS = MIN(MIN_RADIUS, DES_RADIUS(L))
RMS_RAD = RMS_RAD + DES_RADIUS(L)**2.d0
IF(PMASS(L).LT.MINMASS) MINMASS = PMASS(L)
MAXMASS = MAX(PMASS(L), MAXMASS)
END DO
RMS_RAD = SQRT(RMS_RAD/PARTICLES)
AVG_MASS = SUM(PMASS(1:PARTICLES))/PARTICLES
AVG_RAD = SUM(DES_RADIUS(1:PARTICLES))/PARTICLES
KT = (2.d0/7.d0)*KN
KT_W = (2.d0/7.d0)*KN_W
IF(.NOT.XPERIODIC(1)) THEN
DES_PERIODIC_WALLS = .FALSE.
DES_PERIODIC_WALLS_X = .FALSE.
DES_PERIODIC_WALLS_Y = .FALSE.
DES_PERIODIC_WALLS_Z = .FALSE.
ELSE
DES_PERIODIC_WALLS = .TRUE.
DES_PERIODIC_WALLS_X = .TRUE.
DES_PERIODIC_WALLS_Y = .TRUE.
DES_PERIODIC_WALLS_Z = .TRUE.
ENDIF
RADIUS_EQ = DES_RADIUS(1)*1.05D0
NEIGHBOR_SEARCH_DIST = NEIGHBOR_SEARCH_RAD_RATIO * RADIUS_EQ
!DTSOLID = pi*SQRT(one/(KN/PMASS(1) - (ETA_DES_N**2)/4.d0))
!DTSOLID = DTSOLID/50
DTSOLID = DTSOLID_FACTOR*2.0D0*PI*SQRT((MINMASS)/(15*KN)) ! DTs - Rotational Constraint
#if 0
if(.not.GENER_CONFIG_CASE)then
PRINT*,' In CFASSIGN'
PRINT*,'MINMASS = ', MINMASS
PRINT*,'Kn = ', Kn
PRINT*,'DTSOLID FACTOR = ', DTSOLID_FACTOR
READ(*,*)
end if
! DTSOLID = DTSOLID_FACTOR*2D0*PI*SQRT(MINMASS/(6*KN)) ! DTs - Translational Constraint
!Print*,'DTSOLID = ', dtsolid
!Print*,'MAX_RADIUS = ', MAX_RADIUS
!read(*,*)
#endif
WX1 = ZERO
EX2 = XLENGTH
BY1 = ZERO
TY2 = YLENGTH
SZ1 = ZERO
NZ2 = ZLENGTH
!ARRANGE THE COEFF OF RESTITUTION MATRIX FROM INPUT EN VALUES
count_e = 0
DO I = 1, MMAX
DO J = I, MMAX
COUNT_E = COUNT_E + 1
REAL_EN(I,J) = DES_EN_INPUT(COUNT_E)
REAL_ET(I,J) = DES_ET_INPUT(COUNT_E)
MASS_I = (PI*(D_P0(I)**3.d0)*RO_S(I))/6.d0
MASS_J = (PI*(D_P0(J)**3.d0)*RO_S(J))/6.d0
MASS_EFF = (MASS_I*MASS_J)/(MASS_I + MASS_J)
DES_ETAN(I,J) = 2.D0*SQRT(KN*MASS_EFF)*ABS(LOG(REAL_EN(I,J)))
!PRINT*,'MASSI, MASSJ = ', MASS_I, MASS_J, MASS_EFF, KN
DES_ETAN(I,J) = DES_ETAN(I,J)/SQRT(PI*PI + (LOG(REAL_EN(I,J)))**2.0)
DES_ETAT(I,J) = HALF*DES_ETAN(I,J)
!new TCOLL_TMP = PI/SQRT(KN/MASS_EFF - ((DES_ETAN(I,J)/MASS_EFF)**2.d0)/4.d0)
TCOLL_TMP = 1./SQRT(KN/MASS_EFF)
!WRITE(*,*) 'KN, MASS EFF = ', KN, MASS_EFF, DES_ETAN(I,J)
TCOLL = MIN(TCOLL_TMP, TCOLL)
ENDDO
ENDDO
COUNT_E = 0
DO I = 1, MMAX
COUNT_E = COUNT_E + 1
REAL_EN_WALL(I) = DES_EN_WALL_INPUT(COUNT_E)
REAL_ET_WALL(I) = DES_ET_WALL_INPUT(COUNT_E)
MASS_I = (PI*(D_P0(I)**3.d0)*RO_S(I))/6.d0
MASS_J = MASS_I
MASS_EFF = (MASS_I*MASS_J)/(MASS_I + MASS_J)
DES_ETAN_WALL(I) = 2.d0*SQRT(KN_W*MASS_EFF)*ABS(LOG(REAL_EN_WALL(I)))
DES_ETAN_WALL(I) = DES_ETAN_WALL(I)/SQRT(PI*PI + (LOG(REAL_EN_WALL(I)))**2.0)
DES_ETAT_WALL(I) = HALF*DES_ETAN_WALL(I)
ENDDO
DO I = 1, MMAX
DO J = I, MMAX
REAL_EN(J, I) = REAL_EN(I,J)
REAL_ET(J, I) = REAL_ET(I,J)
DES_ETAN(J,I) = DES_ETAN(I,J)
DES_ETAT(J,I) = DES_ETAT(I,J)
ENDDO
ENDDO
!!$ DO I = 1, MMAX
!!$ DO J = 1, MMAX
!!$ WRITE(*,*) 'I AND J = ', I, J
!!$ WRITE(*,*) 'REAL_EN AND ET = ', REAL_EN(I,J), REAL_ET(I,J)
!!$ ENDDO
!!$ ENDDO
!!$
!!$
!!$ DO I = 1, MMAX
!!$ DO J = 1, MMAX
!!$ WRITE(*,*) 'I AND J = ', I, J
!!$ WRITE(*,*) 'ETA_N AND ETA_T = ', DES_ETAN(I,J), DES_ETAT(I,J)
!!$ ENDDO
!!$ ENDDO
DTSOLID = TCOLL/50.d0
if(I_AM_NODE_ZERO)WRITE(*,*) 'MIN TCOLL AND DTSOLID = ', TCOLL, DTSOLID
!READ(*,*)
RETURN
END SUBROUTINE CFASSIGN
subroutine find_cell_index
implicit none
integer :: ip
real(prcn) :: tempx, tempy, tempz
CND(:,:,:) = 0
DO IP = 1, PARTICLES
tempx = des_pos_new(IP,1)
tempy = des_pos_new(IP,2)
tempz = des_pos_new(IP,3)
!PRINT*,'tempx = ', tempx, dxc,tempx/dxc, int(tempx/dxc)
PIJK(IP,1) = MIN(INT(tempx/dxc)+2, IMAX1)
PIJK(IP,2) = MIN(INT(tempy/dyc)+2, JMAX1)
PIJK(IP,3) = MIN(INT(tempz/dzc)+2, KMAX1)
!PRINT*,'PC: ', PIJK(IP,1), PIJK(IP,2), PIJK(IP,3)
cnd(PIJK(IP,1),PIJK(IP,2),PIJK(IP,3)) = cnd(PIJK(IP,1),PIJK(IP,2),PIJK(IP,3)) + 1
end DO
end subroutine find_cell_index
subroutine particles_in_cell
implicit none
INTEGER :: PC(3), npic , i,j,k, ip, pos
INTEGER, DIMENSION(1:cx,1:cy,1:cz):: icount
DO k = 1,KMAX2 !MAX(KMAX1-1,1)
DO j = 1,JMAX2
DO i = 1,IMAX2
NPIC = CND(i,j,k)
!PRINT*,'NPIC = ', NPIC
IF (ASSOCIATED(pic(i,j,k)%p)) THEN
IF (npic.NE.SIZE(pic(i,j,k)%p)) THEN
DEALLOCATE(pic(i,j,k)%p)
IF (npic.GT.0) then
!PRINT*,'NPIC = ', NPIC, i,j,k
ALLOCATE(pic(i,j,k)%p(npic))
end IF
ENDIF
ELSE
IF(npic.GT.0) ALLOCATE(pic(i,j,k)%p(npic))
ENDIF
end DO
end DO
end DO
! PRINT*,'CND = ', CND
icount(:,:,:) = 1
DO ip = 1, NBODY
PC(:) = PIJK(IP,1:3)
!PRINT*,'PC = ', PC(:), SIZE(pic(PC(1), PC(2), PC(3))%p), CND(PC(1), PC(2), PC(3))
pos = icount(pc(1),pc(2),pc(3))
pic(pc(1),pc(2),pc(3))%p(pos) = ip
icount(pc(1),pc(2),pc(3)) = &
& icount(pc(1),pc(2),pc(3)) + 1
ENDDO
end subroutine particles_in_cell
SUBROUTINE GRID_BASED_NEIGHBOR_SEARCH
USE general_funcs
USE global_data
IMPLICIT NONE
LOGICAL PER_COND, ALREADY_NEIGHBOURS
INTEGER I, II, LL, CO, NI, TEMP, JJ, KK , J, K, NEIGH_L, L_MAX, PNO_MAX
INTEGER KM1, KP1, IM1, IP1, JM1, JP1, PNO, NPG, PC(3), IP2, NLIM
DOUBLE PRECISION DIST(NDIM), DISTMAG, R_LM, LX, LY, LZ, XPER_FAC, YPER_FAC, ZPER_FAC, CORD_PNO(NDIM), TMP_OVERLAP
!DOUBLE PRECISION :: DES_DOTPRDCT
!CALL screen_separator(80,'-')
!PRINT*, 'IN CELL LINKED LIST SEARCH'
DO I = 1, NBODY
DO II = 1, MAXNEIGHBORS
NEIGHBOURS(I,II) = -1
END DO
NEIGHBOURS(I,1) = 0
END DO
LX = XE(IMAX1) - XE(1)
LY = YN(JMAX1) - YN(1)
LZ = ZT(KMAX1) - ZT(1)
OVERLAP_MAX = SMALL_NUMBER
PNO_MAX = 0
L_MAX= 0
!!$ DO LL = 1, PARTICLES
!!$ DES_POS_NEW(LL,1) = (XC(LL,1)+foffset-one)*dx
!!$ DES_POS_NEW(LL,2) = (XC(LL,2)-one)*dy
!!$ DES_POS_NEW(LL,3) = (XC(LL,3)-one)*dz
!!$ DES_RADIUS(LL) = RADBDY(LL)*dx
!!$ end DO
!WRITE(*,'(A,/,3(2x,g12.5,/))') ' DOMAIN LENGTH = ', LX, LY, LZ
DO LL = 1, PARTICLES
NEIGHBOURS(LL,1) = NEIGHBOURS(LL,1) + 1
NLIM = NEIGHBOURS(LL,1) + 1
IF(NLIM.GT.MAXNEIGHBORS) THEN
WRITE(*,*) 'NLIM =', NLIM,' > MAXNEIGHBORS =', MAXNEIGHBORS, ' FOR PARTICLE ', LL
STOP
end IF
NEIGHBOURS(LL,NLIM) = LL
PC(:) = PIJK(LL,1:3)!+1
II = PC(1)
JJ = PC(2)
KK = PC(3)
IP1 = II+1
IM1 = II-1
JP1 = JJ+1
JM1 = JJ-1
IF(DIMN.EQ.3) THEN
KP1 = KK+1
KM1 = KK-1
end IF
DO KK = KM1, KP1
DO JJ = JM1, JP1
DO II = IM1, IP1
I = II
J = JJ
K = KK
XPER_FAC = 0
YPER_FAC = 0
ZPER_FAC = 0
PER_COND = .FALSE.
IF(II.GT.IMAX1) THEN
IF(INTX_PER) THEN
I = IMIN1
XPER_FAC = one
PER_COND = .true.
!WRITE(*,*) 'cond true EAST',I,J,K,SIZE(PIC(I,J,K)%p)
ELSE
I = IMAX1
ENDIF
ENDIF
IF(II.LT.IMIN1) THEN
IF(INTX_PER) THEN
I = IMAX1
XPER_FAC = -one
PER_COND = .true.
!WRITE(*,*) 'cond true WEST', I,J,K,SIZE(PIC(I,J,K)%p)
ELSE
I = IMIN1
ENDIF
ENDIF
IF(JJ.GT.JMAX1) THEN
IF(INTY_PER) THEN
J = JMIN1
YPER_FAC = one
PER_COND = .true.
!WRITE(*,*) 'cond true NORTH', I,J,K,SIZE(PIC(I,J,K)%p)
ELSE
J = JMAX1
ENDIF
ENDIF
IF(JJ.LT.JMIN1) THEN
IF(INTY_PER) THEN
J = JMAX1
YPER_FAC = -one
PER_COND = .true.
!WRITE(*,*) 'cond true SOUTH', I,J,K,SIZE(PIC(I,J,K)%p)
ELSE
J = JMIN1
ENDIF
ENDIF
IF(DIMN.EQ.3) THEN
IF(KK.GT.KMAX1) THEN
IF(INTZ_PER) THEN
K = KMIN1
ZPER_FAC = one
ELSE
K = KMAX1
ENDIF
ENDIF
IF(KK.LT.KMIN1) THEN
IF(INTZ_PER) THEN
K = KMAX1
ZPER_FAC = -one
ELSE
K = KMIN1
ENDIF
ENDIF
ENDIF
If (ASSOCIATED(PIC(I,J,K)%p)) then
NPG = SIZE(PIC(I,J,K)%p)
Else
NPG = 0
Endif
Do IP2 = 1,NPG
PNO = PIC(I,J,K)%p(ip2)
if(PNO.GT.LL) then
R_LM = DES_RADIUS(LL) + DES_RADIUS(PNO)!+1.5*dxc
R_LM = FACTOR_RLM*R_LM
CORD_PNO(1) = DES_POS_NEW(PNO,1) + XPER_FAC*(LX)
CORD_PNO(2) = DES_POS_NEW(PNO,2) + YPER_FAC*(LY)
IF(DIMN.EQ.3) THEN
CORD_PNO(3) = DES_POS_NEW(PNO,3) + ZPER_FAC*(LZ)
ENDIF
DIST(:) = CORD_PNO(:) - DES_POS_NEW(LL,:)
DISTMAG = SQRT(DES_DOTPRDCT(DIST,DIST))
ALREADY_NEIGHBOURS = .FALSE.
!!$ IF(LL.EQ.1.AND.PNO.EQ.2) THEN
!!$ WRITE(*,*)'CORD=', CORD_PNO(1)
!!$ Write(*,*)'POS1 : ', DES_POS_NEW(LL,2),DES_RADIUS(LL)
!!$ Write(*,*)'POS2 : ', DES_POS_NEW(PNO,2), DES_RADIUS(PNO)
!!$ WRITE(*,*)'DISTMAG', DISTMAG, R_LM!-DISTMAG
!!$ ENDIF
DO NEIGH_L = 2, NEIGHBOURS(LL,1)+1
IF(PNO.EQ. NEIGHBOURS(LL,NEIGH_L)) ALREADY_NEIGHBOURS=.true.
ENDDO
IF(R_LM - DISTMAG.gt.SMALL_NUMBER.AND.(.NOT.ALREADY_NEIGHBOURS)) THEN
TMP_OVERLAP = ((DES_RADIUS(LL) + DES_RADIUS(PNO))-DISTMAG)/(DES_RADIUS(LL) + DES_RADIUS(PNO))
TMP_OVERLAP = TMP_OVERLAP*100
IF(TMP_OVERLAP.GT.OVERLAP_MAX) THEN
OVERLAP_MAX = MAX(OVERLAP_MAX, TMP_OVERLAP)
L_MAX = LL
PNO_MAX = PNO
end IF
!!$ IF(PER_COND) THEN
!!$ WRITE(*,*) 'pC = ', pc
!!$ WRITE(*,*) 'II, JJ = ', II, JJ
!!$ WRITE(*,*) 'I, J = ', I, J
!!$ WRITE(*,*) 'XYPER_FAC ', XPER_FAC, YPER_FAC
!!$ WRITE(*,*) 'DES_VEL_NEW = ', DES_POS_NEW(PNO,:)
!!$ WRITE(*,*) 'MODIFIED POSITION = ', CORD_PNO(:)
!!$ ENDIF
NEIGHBOURS(LL,1) = NEIGHBOURS(LL,1) + 1
NLIM = NEIGHBOURS(LL,1) + 1
IF(NLIM.GT.MAXNEIGHBORS) THEN
if (I_AM_NODE_ZERO) WRITE(*,*) 'NLIM =', NLIM,' > MAXNEIGHBORS =', MAXNEIGHBORS, ' FOR PARTICLE LL', LL
if (I_AM_NODE_ZERO) WRITE(*,*) 'EITHER REDUCE THE R_LM FACTOR OR INCREASE MN IN MFIX.DAT'
if (I_AM_NODE_ZERO) PRINT*,'POSL = ',DES_POS_NEW(LL,:)
DO NEIGH_L = 2, NEIGHBOURS(LL,1)+1
DIST(:) = DES_POS_NEW(NEIGHBOURS(LL,NEIGH_L),:) - DES_POS_NEW(LL,:)
DISTMAG = SQRT(DES_DOTPRDCT(DIST,DIST))
if (I_AM_NODE_ZERO) PRINT*,'LL =',NEIGHBOURS(LL,NEIGH_L), DES_POS_NEW(NEIGHBOURS(LL,NEIGH_L),:)
if (I_AM_NODE_ZERO) PRINT*,DISTMAG, FACTOR_RLM*(DES_RADIUS(LL) + DES_RADIUS(NEIGHBOURS(LL,NEIGH_L))),DES_RADIUS(LL), DES_RADIUS(NEIGHBOURS(LL,NEIGH_L)), FACTOR_RLM
ENDDO
STOP
end IF
NEIGHBOURS(LL,NLIM) = PNO
NEIGHBOURS(PNO,1) = NEIGHBOURS(PNO,1) + 1
NLIM = NEIGHBOURS(PNO,1) + 1
IF(NLIM.GT.MAXNEIGHBORS) THEN
WRITE(*,*) 'NLIM =', NLIM,' > MAXNEIGHBORS =', MAXNEIGHBORS, ' FOR PARTICLE PNO', PNO
WRITE(*,*) 'EITHER REDUCE THE R_LM FACTOR OR INCREASE MN IN MFIX.DAT'
STOP
end IF
NEIGHBOURS(PNO,NLIM) = LL
end IF !contact condition
end if !PNO.GT.LL
end Do !IP2
end DO
end DO
end DO
end DO
!!$ do LL = 1, PARTICLES
!!$ PRINT*,'NEIGHBORS = ', NEIGHBOURS(LL,:)
!!$ end do
IF(L_MAX.NE.0.AND.(.not.gener_config_case))THEN
if (I_AM_NODE_ZERO) then
!CALL screen_separator(80,'@')
PRINT*,'MAXIMUM OVERLAP = @', OVERLAP_MAX, L_MAX, PNO_MAX, '@'
!CALL screen_separator(80,'@')
!Write(unit_overlap,'(I8,2x,g17.6)') totcolls, overlap_max
endif
DIST(:) = DES_POS_NEW(L_MAX, :) - DES_POS_NEW(PNO_MAX,:)
DISTMAG = SQRT(DES_DOTPRDCT(DIST,DIST))
!PRINT*, L_MAX, PNO_MAX, DISTMAG, DES_RADIUS(L_MAX)+DES_RADIUS(PNO_MAX)
!PRINT*,'MAXIMUM OVERLAP, PART POSs L', DES_POS_NEW(L_MAX,:)
!PRINT*,'MAXIMUM OVERLAP, PART POSs J', DES_POS_NEW(PNO_MAX,:)
!PRINT*,'MAXIMUM OVERLAP, PART CELLS L', PIJK(L_MAX,:)
!PRINT*,'MAXIMUM OVERLAP, PART CELLS J', PIJK(PNO_MAX,:)
!READ(*,*)
end IF
END SUBROUTINE GRID_BASED_NEIGHBOR_SEARCH
SUBROUTINE compute_vol_frac_cgrid
USE interpolation
IMPLICIT NONE
INTEGER :: i,j,k, n, m,l, pc(3), onew, ii,jj,kk &
& , ib,ie,jb,je,kb,ke, im, jm, km
REAL(prcn) :: pl,nll(ndim),onll(ndim),ppll(ndim),dfll(ndim), pos(3), ul(3), xl(3)
maxvolfrac = SMALL_NUMBER
!weightbar = 0.d0
im = cx
jm = cy
km = cz
if (I_AM_NODE_ZERO) PRINT*,'In compue vol_fracr, interp_scheme = ', interp_scheme
DO m=1,nbody
xl(1)=(xc(m,1))*dx
xl(2)=(xc(m,2))*dy
xl(3)=(xc(m,3))*dz
pc(:) = PIJK(m,:)
!WRITE(*,*)'PC = ',xl
SELECT CASE(interp_scheme)
CASE('lpi')
!print*, 'order in set stencil = ', order
ib = MAX(1 ,pc(1) - (ob2l - 1)) !non-periodic
ie = MIN(im,pc(1) + ob2r)
if(.not.intx_per) then
IF (ib.EQ.1 ) ie = ib + order - 1
IF (ie.EQ.im) ib = ie - order + 1
else
IF (ib.EQ.1 ) ib = ie - order + 1
IF (ie.EQ.im) ie = ib + order - 1
end if
jb = MAX(1 ,pc(2) - (ob2l - 1)) !non-periodic
je = MIN(jm,pc(2) + ob2r)
if(.not.inty_per) then
IF (jb.EQ.1 ) je = jb + order - 1
IF (je.EQ.jm) jb = je - order + 1
else
IF (jb.EQ.1 ) jb = je - order + 1
IF (je.EQ.jm) je = jb + order - 1
end if
kb = MAX(1 ,pc(3) - (ob2l - 1)) !non-periodic
ke = MIN(km,pc(3) + ob2r)
If(.not.intz_per) then
IF (kb.EQ.1 ) ke = kb + order - 1
IF (ke.EQ.km) kb = ke - order + 1
else
IF (kb.EQ.1 ) kb = ke - order + 1
IF (ke.EQ.km) ke = kb + order - 1
end If
end SELECT
onew = order
do k = 1, onew
do j = 1, onew
do i = 1, onew
ii = ib+i-1
jj = jb+j-1
kk = kb+k-1
gstencil(i,j,k,1) = (ii-1)*dxc
gstencil(i,j,k,2) = (jj-1)*dyc
gstencil(i,j,k,3) = (kk-1)*dzc
if(ii.lt.1.and.intx_per) ii = cx+ii !new-1
if(ii.gt.cx.and.intx_per) ii = ii-cx !new+1
if(jj.lt.1.and.inty_per) jj = cy+jj
if(jj.gt.cy.and.inty_per) jj = jj-cy
if(kk.lt.1.and.intz_per) kk = cz+kk
if(kk.gt.cz.and.intz_per) kk = kk-cz
!!$
vsten(i,j,k,1:ndim) = zero
end do
end do
end do
CALL interpolator(gstencil(1:onew,1:onew,1:onew,1:3),&
& vsten(1:onew,1:onew,1:onew,1:ndim),xl(1:ndim),ul(1:ndim),onew,&
& interp_scheme,weightp)
do k = 1, onew
do j = 1, onew
do i = 1, onew
DO n=1,ndim
ii = ib+i-1
jj = jb+j-1
kk = kb+k-1
if(ii.lt.1.and.intx_per) ii = cx+ii !new -1
if(ii.gt.cx.and.intx_per) ii = ii-cx !new +1
if(jj.lt.1.and.inty_per) jj = cy+jj
if(jj.gt.cy.and.inty_per) jj = jj-cy
if(kk.lt.1.and.intz_per) kk = cz+kk
if(kk.gt.cz.and.intz_per) kk = kk-cz
!weightbar(ii,jj,kk) = weightbar(ii,jj,kk) + (4.d0*pi*((radbdy(m)*dx)**3.d0)/(3.d0))*weightp(i,j,k)
ENDDO
ENDDO
ENDDO
ENDDO
end DO!CLOSE LOOP OVER ALL BODIES
!!$
do k = 1, cz
do j = 1, cy
do i = 1, cx
!weightbar(i,j,k) = weightbar(i,j,k)/(dxc*dyc*dzc)
!maxvolfrac = MAX(maxvolfrac, weightbar(i,j,k))
end do
end do
end do
if (I_AM_NODE_ZERO) PRINT*,'MAXVOLFRAC = ', maxvolfrac
open(1000, file="volfrac.dat", form="formatted")
write(1000,*)'VARIABLES= ',' "X" ',' "Y" ',' "Z" ',' "volfrac" '
write(1000,*)'ZONE F=POINT, I=', cx, ', J=', cy, ', K=', cz
!!$ do k = 1, cz
!!$ do j = 1, cy
!!$ do i = 1, cx
!!$ write(1000,'(3(2x,i4),2x,g12.5)')(i),(j),(k),weightbar(i,j,k)
!!$ enddo
!!$ enddo
!!$ enddo
! close(1000, status="keep")
end SUBROUTINE compute_vol_frac_cgrid
SUBROUTINE DES_INIT_ARRAYS
IMPLICIT NONE
!-----------------------------------------------
! G l o b a l P a r a m e t e r s
!-----------------------------------------------
!-----------------------------------------------
! L o c a l P a r a m e t e r s
!-----------------------------------------------
!-----------------------------------------------
! L o c a l V a r i a b l e s
!-----------------------------------------------
! loop counters
INTEGER :: M, N, K, LL
!
! Coefficient of restitution (old symbol)
DOUBLE PRECISION :: E, TEST_PART_REAL
!-----------------------------------------------
!
RO_S(1) = RHOS
D_p0(1) = dia_phys
DES_RADIUS(:) = ZERO
PMASS(:) = ZERO
PVOL(:) = ZERO
OMOI(:) = ZERO
RO_Sol(:) = ZERO
DES_POS_OLD(:,:) = ZERO
DES_POS_NEW(:,:) = ZERO
DES_VEL_OLD(:,:) = ZERO
DES_VEL_NEW(:,:) = ZERO
FC(:,:) = ZERO
FN(:,:) = ZERO
FT(:,:) = ZERO
TOW(:,:) = ZERO
OMEGA_OLD(:,:) = ZERO
OMEGA_NEW(:,:) = ZERO
FNS1(:) = ZERO
FTS1(:) = ZERO
NEIGHBOURS(:,:) = -1
PN(:,:) = -1
PV(:,:) = 1
PFN(:,:,:) = ZERO
PFT(:,:,:) = ZERO
NEIGHBOURS(:,1) = 0
PN(:,1) = 0
PV(:,1) = 1
PIJK(:,:) = ZERO
DES_WALL_POS(:,:) = ZERO
DES_WALL_VEL(:,:) = ZERO
IS_MOBILE(1:PARTICLES) = .TRUE.
CAUSE_MOTION(1:PARTICLES) = .TRUE.
IF(GENER_CONFIG_CASE) THEN
if(I_AM_NODE_ZERO)WRITE(*,*) 'DES_INIT ARRAYS: GENER_CONFIG_CASE', GENER_CONFIG_CASE
DO LL = 1, PARTICLES
DES_POS_OLD(LL,1) = XC_GENER(LL,1)
DES_POS_OLD(LL,2) = (XC_GENER(LL,2))
DES_POS_OLD(LL,3) = (XC_GENER(LL,3))
DES_RADIUS(LL) = RAD_GENER(LL)
DES_VEL_OLD(LL,:) = ZERO
OMEGA_OLD(LL,:) = ZERO
DES_POS_NEW(LL,:) = DES_POS_OLD(LL,:)
DES_VEL_NEW(LL,:) = DES_VEL_OLD(LL,:)
OMEGA_NEW(LL,:) = OMEGA_OLD(LL,:)
end DO
ELSE
if(I_AM_NODE_ZERO)WRITE(*,*) 'DES_INIT ARRAYS: GENER_CONFIG_CASE', GENER_CONFIG_CASE
!!$ CALL init_random_seed
!!$ CALL random_number(TEST_PART_REAL)
!!$ Write(*,*)'TEST_PART_REAL = ', TEST_PART_REAL
!!$ TEST_PART = 1 + INT((PARTICLES-1)*TEST_PART_REAL)
!!$ TEST_PART = PARTICLES/2
TEST_PART = 1
DO LL = 1, PARTICLES
DES_POS_OLD(LL,1) = (XC(LL,1)-one)*dx
DES_POS_OLD(LL,2) = (XC(LL,2)-one)*dy
DES_POS_OLD(LL,3) = (XC(LL,3)-one)*dz
DES_RADIUS(LL) = RADBDY(LL)*dx
DES_VEL_OLD(LL,:) = VELBDY(LL,:)
OMEGA_OLD(LL,:) = ZERO
DES_POS_NEW(LL,:) = DES_POS_OLD(LL,:)
DES_VEL_NEW(LL,:) = DES_VEL_OLD(LL,:)
OMEGA_NEW(LL,:) = OMEGA_OLD(LL,:)
end DO
if(CAGE_SIMUL.and.I_AM_NODE_ZERO)then
WRITE(*,'(A)')'CAGE SIMULATION FLAG IS TURNED ON '
WRITE(*,'(A30,2x,I6)')'INDEX OF THE TEST PARTICLE IS : ', TEST_PART
WRITE(*,'(A30,3(2x,I6))')'CELL OF THE TEST PARTICLE IS : ', PIJK(TEST_PART,:)
WRITE(*,'(A30,3(2x,g17.8))')'POSITION OF THE TEST PARTICLE IS : ', DES_POS_NEW(TEST_PART,:)
WRITE(*,'(A30,3(2x,g17.8))')'POSITION OF THE TEST PARTICLE IS : ', DES_VEL_OLD(TEST_PART,:)
IS_MOBILE(1:PARTICLES) = .FALSE.
IS_MOBILE(TEST_PART) = .TRUE.
CAUSE_MOTION(1:PARTICLES) = .FALSE.
CAUSE_MOTION(TEST_PART) = .TRUE.
!READ(*,*)
end if
if(CAGE_SIMUL)then
DO LL = 1, PARTICLES
DES_VEL_NEW(LL,:) = DES_VEL_OLD(LL,:)
if(LL.ne.TEST_PART)DES_VEL_OLD(LL,:) = ZERO
END DO
end if
end IF
RETURN
END SUBROUTINE DES_INIT_ARRAYS
SUBROUTINE CFUPDATEOLD
USE dem_mod
IMPLICIT NONE
INTEGER LL
!
!---------------------------------------------------------------------
DO LL = 1, PARTICLES
DES_POS_OLD(LL,:) = DES_POS_NEW(LL,:)
DES_VEL_OLD(LL,:) = DES_VEL_NEW(LL,:)
OMEGA_OLD(LL,:) = OMEGA_NEW(LL,:)
END DO
END SUBROUTINE CFUPDATEOLD
SUBROUTINE CFNEWVALUES(L)
IMPLICIT NONE
!DOUBLE PRECISION, EXTERNAL :: DES_DOTPRDCT
INTEGER L, KK, K, NSPLIT, CHECK
INTEGER IJK, I, J, KKK
DOUBLE PRECISION TEMPTIME, PASSTIME, D(DIMN), DIST, V, rhat(dimn), rhat2, force_tmpy
!
!---------------------------------------------------------------------
! Calculate new values
!---------------------------------------------------------------------
!
CHECK = 0
IF(shrink) THEN
rhat(2) = DES_POS_NEW(L,2) - YLENGTH/2.d0
!IF(ABS(rhat(2)).GT.2.d0*MAX_RADIUS) then
!PRINT*, 'SHRINKING'
rhat2 = rhat(2)*rhat(2)
rhat(2)= rhat(2)/ABS(rhat(2))
FC(L, 2) = FC(L,2) - 980.d0*PMASS(L)*rhat(2)*(1.d0-exp(-4.d0*rhat2/(YLENGTH**2.d0)))
!endif
ENDIF
IF(collision_type.eq."softsphere") THEN
if(.not.gener_config_case)then
if(L.eq.-1)WRITE(*,'(3(A,3(2x,g12.5),/))') 'FC = ', FC(L,:)/PMASS(L), 'FORCE = ',RHOF*FORCE(L,:)/PMASS(L),&
' GRAV = ',(ONE-RHOF/RHOS)*GRAV(:)
!test_force(:) = test_force(:) + FC(L,:)
if(only_dem)then
FC(L, :) = FC(L,:)/PMASS(L) !+ GRAV(:)
else
test_force(:) = test_force(:) + FC(L,:)
contact_force(L,:) = FC(L,:)
!FC(L,:) = FC(L,:)/PMASS(L)+ RHOF*FORCE(L,:)/PMASS(L) + (one-rhof/rhos)*GRAV(:) - frame_accln(:)
FC(L,:) = FC(L,:)/PMASS(L)+ RHOF*(PRES(L,:) + VISC(L,:))/PMASS(L) - frame_accln(:) - mpg(:)*PVOL(L)/PMASS(L)
! COMMENTING THIS, BECAUSE GRAVITY IS CHANGED TO MPG. IF BOTH GRAVITY AND MPG ARE AVAILABLE, THEN UNCOMMENT THIS
! FC(L,:) = FC(L,:) + (one-rhof/rhos)*GRAV(:)
end if
else
FC(L, :) = FC(L,:)/PMASS(L) !+ GRAV(:)
end if
if (IS_MOBILE(L)) then
DES_VEL_NEW(L,:) = FC(L,:)
DES_VEL_NEW(L,:) = DES_VEL_OLD(L,:) + DES_VEL_NEW(L,:)*DTSOLID
OMEGA_NEW(L,:) = OMEGA_OLD(L,:)! + TOW(L,:)*OMOI(L)*DTSOLID
else
DES_VEL_NEW(L,:) = zero
OMEGA_NEW(L,:) = zero
endif
if(.not.gener_config_case)then
if(L.eq.-1)then
WRITE(*,'(4(A,3(2x,g12.5),/))')&
'FORCE = ', FORCE(L,:),&
'FORCE = ', FC(L,:),&
'OLD = ', DES_VEL_OLD(L,:),&
'NEW = ', DES_VEL_NEW(L,:)
READ(*,*)
end if
end if
FC(L,:) = ZERO
TOW(L,:) = ZERO
end IF
if(IS_MOBILE(L))then
DES_POS_NEW(L,:) = DES_POS_OLD(L,:) + DES_VEL_NEW(L,:)*DTSOLID
else
DES_POS_NEW(L,:) = DES_POS_OLD(L,:)
end if
IF(DES_POS_NEW(L,2).LT.ZERO.AND..NOT.DES_PERIODIC_WALLS) THEN
if (I_AM_NODE_ZERO) PRINT*,'POSITION LE ZERO FOR L = ', L, DES_VEL_NEW(L,:), DES_POS_NEW(L,:)
ENDIF
!PRINT*,'grav = ', GRAV(2), pgrad(2)*PVOL(L)/PMASS(L), RO_sol(L)
!!$ IF(.NOT.DO_NSEARCH) THEN
!!$ D(:) = DES_POS_NEW(L,:) - PPOS(L,:)
!!$ DIST = SQRT(DES_DOTPRDCT(D,D))
!!$
!!$ NEIGHBOR_SEARCH_DIST = NEIGHBOR_SEARCH_RAD_RATIO*DES_RADIUS(L)
!!$ IF(DIST.GE.NEIGHBOR_SEARCH_DIST) DO_NSEARCH = .TRUE.
!!$ END IF
! Chacking if the partcile moved more than a dia in a solid time step
D(:) = DES_POS_NEW(L,:) - DES_POS_OLD(L,:)
DIST = SQRT(DES_DOTPRDCT(D,D))
IF(DIST.GE.DES_RADIUS(L)) THEN
if (I_AM_NODE_ZERO) then
PRINT *,'MOVEMENT UNDESIRED: PARTICLE', L
PRINT*, 'DES POS NEW : ', DES_POS_NEW(L,:)
PRINT*, 'DES POS OLD : ', DES_POS_OLD(L,:)
endif
STOP
END IF
! Periodic treatment
IF(DES_PERIODIC_WALLS) THEN
IF(DES_PERIODIC_WALLS_X) THEN
IF(DES_POS_NEW(L,1).GT.EX2) THEN
DES_POS_NEW(L,1) = DES_POS_NEW(L,1) - (EX2 - WX1)
PIJK(L,1) = 2
ELSE IF(DES_POS_NEW(L,1).LT.WX1) THEN
DES_POS_NEW(L,1) = DES_POS_NEW(L,1) + (EX2 - WX1)
PIJK(L,1) = IMAX1
END IF
END IF
IF(DES_PERIODIC_WALLS_Y) THEN
IF(DES_POS_NEW(L,2).GT.TY2) THEN
DES_POS_NEW(L,2) = DES_POS_NEW(L,2) - (TY2 - BY1)
PIJK(L,2) = 2
ELSE IF(DES_POS_NEW(L,2).LT.BY1) THEN
DES_POS_NEW(L,2) = DES_POS_NEW(L,2) + (TY2 - BY1)
PIJK(L,2) = JMAX1
END IF
END IF
IF(DES_PERIODIC_WALLS_Z) THEN
IF(DES_POS_NEW(L,3).GT.NZ2) THEN
DES_POS_NEW(L,3) = DES_POS_NEW(L,3) - (NZ2 - SZ1)
PIJK(L,3) = 2
ELSE IF(DES_POS_NEW(L,3).LT.SZ1) THEN
DES_POS_NEW(L,3) = DES_POS_NEW(L,3) + (NZ2 - SZ1)
PIJK(L,3) = KMAX1
END IF
END IF
END IF
RETURN
END SUBROUTINE CFNEWVALUES
SUBROUTINE IBMUPDATE
IMPLICIT NONE
INTEGER M
DO M=1,NBODY
XC(M,1) = DES_POS_NEW(M,1)/dx + one
XC(M,2) = DES_POS_NEW(M,2)/dy + one
XC(M,3) = DES_POS_NEW(M,3)/dz + one
VELBDY(M,:) = DES_VEL_NEW(M,:)
ANGV(M,:,1) = OMEGA_NEW(M,:)
END DO
END SUBROUTINE IBMUPDATE
SUBROUTINE HARD_SPHERE_COLLISION
IMPLICIT NONE
INTEGER :: LL,IP, idim, COLL_I(1), COLL_J,PNO
REAL(prcn) :: tij, rij(dimn),vij(dimn),tempr, rmax(dimn),rijsq,rpijsq,bij, discr, vijsq,tij_min, tij_tmp
!DOUBLE PRECISION, EXTERNAL :: DES_DOTPRDCT
REAL(prcn) :: COLLTIME(PARTICLES),tmin, DLENGTH(dimn)
INTEGER :: PARTNER(PARTICLES),COUNT
COLLTIME(:) = LARGE_NUMBER
PARTNER(:) = PARTICLES
DLENGTH(1) = XE(IMAX1) - XE(1)
DLENGTH(2) = YN(JMAX1) - YN(1)
DLENGTH(3) = ZT(KMAX1) - ZT(1)
rmax(:) = DLENGTH(:)/two
DO LL=1,PARTICLES
IF(NEIGHBOURS(LL,1).GT.1)THEN
DO IP = 2, NEIGHBOURS(LL,1)+1
PNO = NEIGHBOURS(LL,IP)
rijsq = zero ! separation
vijsq = zero
!!$ PRINT*,'IN HS, PNO = ', PNO
IF(PNO.GT.LL)THEN
do idim = 1, dimn
tempr = DES_POS_NEW(LL,idim) - DES_POS_NEW(PNO,idim) ! compute the separation
! in each dimension
if((ABS(tempr)).gt.rmax(idim)) then
if(tempr.lt.zero) then
tempr = tempr + DLENGTH(idim)
else
tempr = tempr - DLENGTH(idim)
end if
!!$ PRINT*,'tempr =', tempr
end if
rij(idim) = tempr
vij(idim) = DES_VEL_NEW(LL,idim)-DES_VEL_NEW(PNO,idim)
rijsq = rijsq + tempr**2.d0
vijsq = vijsq + vij(idim)**2.d0
end do
!!$ PRINT*,'rij=',rij(1:dimn), 'vij=',vij(1:dimn)
!!$ bij = DES_DOTPRDCT(rij,vij)
bij = rij(1)*vij(1)+rij(2)*vij(2)+rij(3)*vij(3)
!!$ PRINT*,'bij1 = ', bij, rij, vij
!!$ READ(*,*)
IF(bij.lt.zero) THEN
rpijsq = (DES_RADIUS(LL)+DES_RADIUS(PNO))**2.d0
discr = bij ** 2 - vijsq * ( rijsq - rpijsq )
!!$ PRINT*,'bijsq = ', bij**2.d0
!!$ PRINT*,'vijsq = ', vijsq
!!$ PRINT*,'rijsq = ', rijsq
!!$ PRINT*,'rpijsq = ', rpijsq
!!$ PRINT*,'discr =' ,discr
if ( discr .gt. 0.d0 ) then
tij = ( -bij - sqrt ( discr ) ) / vijsq
if(tij.lt.colltime(LL))then
COLLTIME(LL) = tij
PARTNER(LL) = PNO
end if
end if
end IF
END IF
END DO
END IF
END DO
tij_min = MINVAL(COLLTIME(1:PARTICLES))
Write(*,'(A,2x,g17.6,2x,A,2x,g17.6)')'COLLISION TIME = ', tij_min, 'DTSOLID = ', dths
COLL_I = MINLOC(COLLTIME(1:PARTICLES))
COLL_J = PARTNER(COLL_I(1))
Write(*,'(A,2(2x, I6))')'MINIMUM COLLISION TIME FOR PARTICLE Nos', COLL_I(1),COLL_J
!PRINT*,'VELOCITY OF THE PARTICLES', DES_VEL_NEW(COLL_I(1),:),DES_VEL_NEW(COLL_J,:)
!READ(*,*)
! If minimum collision time is less than the time remaining in hardsphere, then set DTSOLID to minimum collision time so that the particle positions are updated for this time
IF(tij_min.lt.dths) DTSOLID = tij_min
DO LL=1, PARTICLES
CALL CFNEWVALUES(LL)
END DO
IF(tij_min.lt.dths)THEN
COUNT = PARTICLES
Do While(COUNT.gt.1)
tmin = MINVAL(COLLTIME(1:COUNT))
COLL_I = MINLOC(COLLTIME(1:COUNT))
COLL_J = PARTNER(COLL_I(1))
! PRINT*,'DISTANCE BETWEEN PARTICLES = ', DES_POS_NEW(COLL_I(1),1)-DES_POS_NEW(COLL_J,1)
! READ(*,*)
if(tmin.eq.tij_min)THEN
PRINT*,'CALLING BUMP FOR PARTICLES', COLL_I(1),COLL_J
!READ(*,*)
CALL BUMP(COLL_I(1),COLL_J)
tij_tmp = COLLTIME(COUNT)
COLLTIME(count) = COLLTIME(coll_i(1))
COLLTIME(coll_i(1)) = tij_tmp
COUNT = COUNT-1
IF(GENER_CONFIG_CASE)THEN
MINCOLLS(COLL_I(1)) = MINCOLLS(COLL_I(1))+1
MINCOLLS(COLL_J) = MINCOLLS(COLL_J)+1
ELSE
TOTCOLLS = TOTCOLLS + 1
END IF
else
goto 222
end if
end Do
END IF
222 CONTINUE
PRINT*,'DONE WITH HARD SPHERE COLLISION', dt, tij_min
END SUBROUTINE HARD_SPHERE_COLLISION
SUBROUTINE BUMP ( I, J )
! *******************************************************************
! ** COMPUTES COLLISION DYNAMICS FOR PARTICLES I AND J. **
! ** **
! ** IT IS ASSUMED THAT I AND J ARE IN CONTACT. **
! *******************************************************************
IMPLICIT NONE
INTEGER:: I, J, idim
DOUBLE PRECISION :: m1, m2
double precision rij(dimn), factor, tempr, rpijsq, normal(dimn)
double precision vij(dimn), delv(dimn)
double precision vijsq, rmax(dimn), DLENGTH(dimn)
!DOUBLE PRECISION :: DES_DOTPRDCT
! *******************************************************************
m1 = PMASS(I)
m2 = PMASS(J)
vijsq = zero
DLENGTH(1) = XE(IMAX1) - XE(1)
DLENGTH(2) = YN(JMAX1) - YN(1)
DLENGTH(3) = ZT(KMAX1) - ZT(1)
rmax(:) = DLENGTH(:)/two
if (I_AM_NODE_ZERO) PRINT*,'MASS = ', m1, m2
do idim = 1, dimn
tempr = DES_POS_NEW(I,idim) - DES_POS_NEW(J,idim) ! compute the separation
! in each dimension
if((ABS(tempr)).gt.rmax(idim)) then
if(tempr.lt.zero) then
tempr = tempr + DLENGTH(idim)
else
tempr = tempr - DLENGTH(idim)
end if
end if
rij(idim) = tempr
vij(idim) = DES_VEL_NEW(I,idim)-DES_VEL_NEW(J,idim)
vijsq = vijsq + vij(idim)**2.d0
end do
normal(:) = rij(:)/DSQRT(rij(1)**2.d0 + rij(2)**2.d0+rij(3)**2.d0)
!!$ PRINT*,'rij,vij = ', rij, vij
!!$ rpijsq = (DES_RADIUS(I)+DES_RADIUS(J))**2.d0
factor = DOT_PRODUCT(normal(1:DIMN),vij(1:DIMN))
!!$ factor = factor/rpijsq
!!$ factor = DES_DOTPRDCT(rij,vij)/rpijsq
!!$ PRINT*, 'FACTOR=', factor
IF(factor.GT.0.d0) THEN
WRITE(*,*)'ACHTUNG'
WRITE(*,*) 'factor in bump GT zero = ', factor
!STOP
ENDIF
if (I_AM_NODE_ZERO) PRINT*,'coeff_rest = ', coeff_rest
do idim=1,dimn
delv(idim) = -factor * normal(idim)
DES_VEL_NEW(i,idim) = DES_VEL_NEW(i,idim) + delv(idim) * m2 *(1.d0+ coeff_rest)/(m1+m2)
DES_VEL_NEW(j,idim) = DES_VEL_NEW(j,idim) - delv(idim) * m1 *(1.d0+ coeff_rest)/(m1+m2)
end do
!PRINT*,'NEW VELOCITIES=',DES_VEL_NEW(i,:),DES_VEL_NEW(j,:)
!READ(*,*)
return
END SUBROUTINE BUMP
SUBROUTINE SOFT_SPHERE_COLLISION
IMPLICIT NONE
!-----------------------------------------------
! L o c a l V a r i a b l e s
!-----------------------------------------------
!
INTEGER NN, LN, I, J, K, NSN, NP, L, IJK, GTC_COUNT, GTC_FACTOR, idim
DOUBLE PRECISION TEMP_DTS, DTSOLIDTEMP , MEAN_VEL(ndim)
!CHARACTER*5 FILENAME
! Logical to see whether this is the first entry to this routine
LOGICAL,SAVE:: FIRST_PASS = .TRUE.
LOGICAL DES_CONTINUUM_COUPLED_FT
DOUBLE PRECISION pgrad_tmp(1:DIMN), GRAV_TMP(1:DIMN), grantemp
DOUBLE PRECISION:: xmintmp, xmax, ymin, ymax, Ax, bx, ay, by, az, bz , mean_free_path, t_mfp
! Force calculation
!IF(DES_PERIODIC_WALLS) THEN
CALL CALC_FORCE_DES
DO LN = 1, PARTICLES
CALL CFNEWVALUES(LN)
END DO
!!$ do ln = 1, ndim
!!$ WRITE(*,*) 'USMEAN = ', SUM(des_vel_new(1:nbody,ln))/real(nbody,prcn)
!!$ end do
!CALL FIND_CELL_INDEX
!CALL PARTICLES_IN_CELL
!CALL GRID_BASED_NEIGHBOUR_SEARCH
IF(GENER_CONFIG_CASE.AND.(MOD(IFAC,1000).EQ.0)) THEN
do idim = 1, ndim
mean_vel(idim) = SUM(DES_VEL_NEW(1:PARTICLES,idim))/real(particles,prcn)
end do
mean_vel = zero
grantemp = zero
do LN = 1, PARTICLES
do idim = 1, ndim
grantemp = grantemp + half*PMASS(LN)*(DES_VEL_NEW(LN,idim)-mean_vel(idim))**2.d0
end do
end do
grantemp = grantemp/real(particles,prcn)
WRITE(*,*) 'MAX_OVERLAP, IFAC = ', OVERLAP_MAX, IFAC, grantemp
end IF
if(TRIM(input_type).eq.'lubtest')then
WRITE(*,'(3(A,3(2x,g12.5),/))')&
'FORCE = ', FORCE(1,:),&
'OLD = ', DES_VEL_NEW(1,:),&
'NEW = ', DES_VEL_NEW(2,:)
WRITE(*,*)'POSITIONS = ', DES_POS_NEW(2,:)-DES_POS_NEW(1,:)
READ(*,*)
end if
IF(TEST_YMAXVAL) THEN
IF((MOD(IFAC,1000).EQ.0)) THEN
if (I_AM_NODE_ZERO) PRINT*,'MAX - MIN = ', MAXVAL(DES_POS_NEW(1:PARTICLES,2))-MINVAL(DES_POS_NEW(1:PARTICLES,2))
end IF
IF(IFAC.EQ.1) WRITE(*,*) 'TARGET MAX-MIN =', YMAXVAL-2.d0*MAX_RADIUS
!WRITE(*,*)'DEKHO', MAXVAL(DES_POS_NEW(1:PARTICLES,2)),MINVAL(DES_POS_NEW(1:PARTICLES,2)),YMAXVAL, MAX_RADIUS*2.d0
IF(MAXVAL(DES_POS_NEW(1:PARTICLES,2))-MINVAL(DES_POS_NEW(1:PARTICLES,2)).LT.(YMAXVAL-2.d0*MAX_RADIUS)) THEN
WRITE(*,*) 'STOPPING THE SIMULATION BECAUSE MAX Y LT YMAXVAL'
!WRITE(*,*) 'DES POS MAX = ', MAXVAL(DES_POS_NEW(1:PARTICLES,2))
!WRITE(*,*) 'DES POS MIN = ', MINVAL(DES_POS_NEW(1:PARTICLES,2))
WRITE(*,*) 'YMAXVAL = ', YMAXVAL
ymin = MINVAL(DES_POS_NEW(1:PARTICLES,2)) - MAX_RADIUS
ymax = MAXVAL(DES_POS_NEW(1:PARTICLES,2)) + MAX_RADIUS
Ay = YMAXVAL/(ymax-ymin)
By = -Ay*ymin
DO L = 1, PARTICLES
DES_POS_NEW(L,2) = Ay*DES_POS_NEW(L,2) + By
end DO
GOTO 100
end IF
end IF
! Write Restart for DEM only case
S_TIME = S_TIME + DTSOLID
!END DO ! end do NN = 1, FACTOR
return
100 continue
SHRINK = .FALSE.
if (I_AM_NODE_ZERO) PRINT*,'MAX - MIN = ', MAXVAL(DES_POS_NEW(1:PARTICLES,2))-MINVAL(DES_POS_NEW(1:PARTICLES,2))
WRITE(*,*) 'TARGET MAX-MIN =', YMAXVAL-2.d0*MAX_RADIUS
RETURN
!IF(TEST_YMAXVAL) THEN
!ENDIF
END SUBROUTINE SOFT_SPHERE_COLLISION
SUBROUTINE init_particles_jn
USE randomno
USE dem_mod
IMPLICIT NONE
INTEGER :: i,j, k , ip, idim
REAL*8 :: umf0(dimn), rsf(DIMN, DIMN), rhat(3), mean_vel(ndim), grantemp
WRITE(*,*) 'INITIALIZING NORMAL VELOCITY DISTRIBUTION'
WRITE(*,*) 'MEAN = ', ZERO, ' AND VARIANCE = ', pvel_var
do j=1,DIMN
umf0(j)=zero
do i=1,dimn
if(i.eq.j)then
rsf(i,j)=pvel_var/three
else
rsf(i,j)=0.0
endif
enddo
enddo
CALL jn_dist(DES_VEL_OLD(1:PARTICLES, 1:DIMN),particles,dimn,umf0,rsf)
DO ip = 1, particles
IF(SHRINK) THEN
rhat(2) = DES_POS_NEW(ip,2) - YLENGTH/2.d0
rhat(2)= rhat(2)/ABS(rhat(2))
DES_VEL_OLD(ip,2) = ABS(DES_VEL_OLD(ip,2))*rhat(2) !Direct the y- velocity inwards
ENDIF
DES_VEL_NEW(ip,:) = DES_VEL_OLD(ip,:)
end DO
grantemp = zero
mean_vel = zero
do IP = 1, PARTICLES
do idim = 1, ndim
grantemp = grantemp + half*PMASS(IP)*(DES_VEL_NEW(IP,idim)-mean_vel(idim))**2.d0
end do
end do
grantemp = grantemp/real(particles,prcn)
!WRITE(*,*) 'TOTAL INITIAL KE = ', grantemp
!READ(*,*)
end SUBROUTINE init_particles_jn
SUBROUTINE init_random_seed
Implicit None
INTEGER :: isize,idate(8)
INTEGER,ALLOCATABLE :: iseed(:)
CALL DATE_AND_TIME(VALUES=idate)
CALL RANDOM_SEED(SIZE=isize)
ALLOCATE( iseed(isize) )
CALL RANDOM_SEED(GET=iseed)
iseed = iseed * (idate(8)-500) ! idate(8) contains millisecond
CALL RANDOM_SEED(PUT=iseed)
DEALLOCATE( iseed )
END SUBROUTINE init_random_seed
end MODULE collision_mod
| gpl-3.0 |
kito-cheng/riscv-gcc | libgomp/testsuite/libgomp.fortran/target6.f90 | 7 | 1216 | ! { dg-do run }
module target6
contains
subroutine foo (p, v, w, n)
double precision, pointer :: p(:), v(:), w(:)
double precision :: q(n)
integer :: i, n
!$omp target data if (n > 256) map (to: v(1:n), w(:n)) map (from: p(1:n), q)
!$omp target if (n > 256)
!$omp parallel do simd
do i = 1, n
p(i) = v(i) * w(i)
q(i) = p(i)
end do
!$omp end target
!$omp target update if (n > 256) from (p)
do i = 1, n
if (p(i) /= i * iand (i, 63)) STOP 1
v(i) = v(i) + 1
end do
!$omp target update if (n > 256) to (v(1:n))
!$omp target if (n > 256)
!$omp parallel do simd
do i = 1, n
p(i) = v(i) * w(i)
end do
!$omp end target
!$omp end target data
do i = 1, n
if (q(i) /= (v(i) - 1) * w(i)) STOP 2
if (p(i) /= q(i) + w(i)) STOP 3
end do
end subroutine
end module target6
use target6, only : foo
integer :: n, i
double precision, pointer :: p(:), v(:), w(:)
n = 10000
allocate (p(n), v(n), w(n))
do i = 1, n
v(i) = i
w(i) = iand (i, 63)
end do
call foo (p, v, w, n)
do i = 1, n
if (p(i) /= (i + 1) * iand (i, 63)) STOP 4
end do
deallocate (p, v, w)
end
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/namelist_23.f90 | 174 | 1731 | !{ dg-do run { target fd_truncate } }
! PR26136 Filling logical variables from namelist read when object list is not
! complete. Test case derived from PR.
! Contributed by Jerry DeLisle <jvdelisle@gcc.gnu.org>
program read_logical
implicit none
logical, dimension(4) :: truely
integer, dimension(4) :: truely_a_very_long_variable_name
namelist /mynml/ truely
namelist /mynml/ truely_a_very_long_variable_name
truely = .false.
truely_a_very_long_variable_name = 0
open(10, status="scratch")
write(10,*) "&mynml"
write(10,*) "truely = trouble, traffic .true"
write(10,*) "truely_a_very_long_variable_name = 4, 4, 4"
write(10,*) "/"
rewind(10)
read (10, nml=mynml, err = 1000)
if (.not.all(truely(1:3))) call abort()
if (.not.all(truely_a_very_long_variable_name(1:3).eq.4)) call abort()
truely = .false.
truely_a_very_long_variable_name = 0
rewind(10)
write(10,*) "&mynml"
write(10,*) "truely = .true., .true.,"
write(10,*) "truely_a_very_long_variable_name = 4, 4, 4"
write(10,*) "/"
rewind(10)
read (10, nml=mynml, err = 1000)
if (.not.all(truely(1:2))) call abort()
if (.not.all(truely_a_very_long_variable_name(1:3).eq.4)) call abort()
truely = .true.
truely_a_very_long_variable_name = 0
rewind(10)
write(10,*) "&mynml"
write(10,*) "truely = .false., .false.,"
write(10,*) "truely_a_very_long_variable_name = 4, 4, 4"
write(10,*) "/"
rewind(10)
read (10, nml=mynml, err = 1000)
if (all(truely(1:2))) call abort()
if (.not.all(truely_a_very_long_variable_name(1:3).eq.4)) call abort()
close(10)
stop
1000 call abort()
end program read_logical
| gpl-2.0 |
ars599/mom5 | src/land_lad/vegetation/vegetation.F90 | 3 | 23765 | ! ============================================================================
! vegetation-related processes
! ============================================================================
module vegetation_mod
! <CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov">
! Christopher Milly
! </CONTACT>
! <REVIEWER EMAIL="GFDL.Climate.Model.Info@noaa.gov">
! Elena Shevliakova
! </REVIEWER>
! <REVIEWER EMAIL="GFDL.Climate.Model.Info@noaa.gov">
! Sergey Malyshev
! </REVIEWER>
! <OVERVIEW>
! Module containing processes relating to vegetation.
! </OVERVIEW>
! <DESCRIPTION>
! Vegetation type describing vegetation characteristics is defined.
! Vegetation data is allocated and the initial value for canopy air
! humidity is set up. Updates vegetation and boundary data on the slow
! and fast time-scales. Deallocates vegetation data, empties memory and
! cleans up, if necessary.
! </DESCRIPTION>
! things from the other modules we use in the interface part of this module
use time_manager_mod, only: time_type, get_time
use mpp_domains_mod, only: domain2d, mpp_get_compute_domain
use land_types_mod, only: land_data_type
use soil_mod, only: soil_type
use constants_mod, only: rdgas, rvgas
use fms_mod, only: write_version_number, error_mesg, FATAL, &
file_exist, open_restart_file, close_file, &
read_data, write_data, set_domain, mpp_pe, &
open_namelist_file, check_nml_error, mpp_pe, &
NOTE, mpp_root_pe, mpp_error, stdlog
use fms_io_mod, only: get_restart_io_mode
use sat_vapor_pres_mod, only: escomp
use field_manager_mod, only: MODEL_LAND
use tracer_manager_mod, only: get_tracer_index, NO_TRACER
implicit none
private
! ==== public interfaces =====================================================
public :: vegetation_type
public :: vegetation_init ! initialize vegetation data
public :: vegetation_end ! finish using vegetation data
public :: update_vegetation_slow ! slow time-scale vegetation update
public :: update_vegetation_fast_up ! fast time-scale update of veg. state
public :: update_vegetation_fast_down ! fast time-scale update of veg. state
public :: update_vegetation_bnd_fast
public :: update_vegetation_bnd_slow
public :: vegetation_stock_pe ! calculate and return total amount of
! requested quantitiy per PE
! ==== end of public interfaces ==============================================
! <TYPE NAME="vegetation_type">
type vegetation_type
private
! <DESCRIPTION>
! Private data type describing vegetation characteristics.
! </DESCRIPTION>
type(domain2d) :: domain ! computational domain
real :: dt ! fast time step, s
! <DATA NAME="domain" TYPE="domain2d" DIM="2">
! Computational domain
! </DATA>
! <DATA NAME="dt" UNITS="s" TYPE="real">
! Fast time step
! </DATA>
integer :: is,ie,js,je ! computational domain bounds
integer :: n_tiles ! number of tiles
! <DATA NAME="is" TYPE="integer">
! Computational domain bounds
! </DATA>
! <DATA NAME="ie" TYPE="integer">
! Computational domain bounds
! </DATA>
! <DATA NAME="js" TYPE="integer">
! Computational domain bounds
! </DATA>
! <DATA NAME="je" TYPE="integer">
! Computational domain bounds
! </DATA>
! <DATA NAME="n_tiles" TYPE="integer">
! Number of tiles
! </DATA>
logical, pointer, dimension(:,:,:) :: &
mask =>NULL(), & ! land mask
bonedry =>NULL() ! true if the "bone dry" conditions occur (evaporation
! during time step larger than available water)
! <DATA NAME="mask" TYPE="logical, pointer" DIM="3">
! Land mask
! </DATA>
! <DATA NAME="bonedry" TYPE="logical, pointer" DIM="3">
! True if the "bone dry" conditions occur (evaporation during time step
! is larger than the available water)
! </DATA>
real, pointer, dimension(:,:,:) :: &
q_ca =>NULL() ! specific humidity of canopy air
! <DATA NAME="q_ca" UNITS="kg/kg" TYPE="real, pointer" DIM="3">
! Specific humidity of canopy air
! </DATA>
real, pointer, dimension(:,:,:) :: &
t_surf =>NULL(), & ! soil surface temperature, degK
evap =>NULL(), & ! explicit estimate of the water vapor flux
c_surf =>NULL(), & ! conductance between surface and canopy air
dqsatdt =>NULL(), & ! derivative of sat. humidity over T surface
e_q =>NULL(), & ! implicit scheme coefficient
f_q =>NULL(), & ! implicit scheme coefficient
beta =>NULL() ! water availability for evaporation
! <DATA NAME="t_surf" UNITS="K" TYPE="real, pointer" DIM="3">
! Soil surface temperature
! </DATA>
! <DATA NAME="evap" UNITS="kg/m2/s" TYPE="real, pointer" DIM="3">
! Explicit estimate of the water vapor flux
! </DATA>
! <DATA NAME="c_surf" UNITS="kg/m2/s" TYPE="real, pointer" DIM="3">
! Conductance between surface and canopy air
! </DATA>
! <DATA NAME="dqsatdt" UNITS="kg/kg/degK" TYPE="real, pointer" DIM="3">
! Derivative of sat. humidity over T surface
! </DATA>
! <DATA NAME="e_q" TYPE="real, pointer" DIM="3">
! Implicit scheme coefficient
! </DATA>
! <DATA NAME="f_q" TYPE="real, pointer" DIM="3">
! Implicit scheme coefficient
! </DATA>
! <DATA NAME="beta" TYPE="real, pointer" DIM="3">
! Water availability for evaporation
! </DATA>
end type vegetation_type
! </TYPE>
! some names, for information only
logical :: module_is_initialized =.FALSE.
character(len=*), private, parameter :: module_name = 'vegetation_mod'
character(len=128), private, parameter :: version = '$Id: vegetation.F90,v 15.0 2007/08/14 04:00:20 fms Exp $'
character(len=128), private, parameter :: tagname = '$Name: tikal $'
! module constants
real, parameter :: d622 = rdgas/rvgas
real, parameter :: d378 = 1.0-d622
real, parameter :: d608 = d378/d622
! <NAMELIST NAME="vegetation_nml">
! <DATA NAME="klev" TYPE="integer" DEFAULT="0">
! Soil level at which to specify frozen-soil factor for modifying beta.
! </DATA>
! <DATA NAME="do_netcdf_restart" TYPE="logical" DEFAULT=".true.">
! Do netcdf restart.
! </DATA>
! ---- namelist variables and their default values ---------------------------
integer :: klev = 0
logical :: do_netcdf_restart = .true.
namelist /vegetation_nml/ klev, do_netcdf_restart
! </NAMELIST>
! for diagnostics only
integer :: i
integer, parameter :: iwatch = 38, jwatch=60
! module variables
integer :: isphum ! index of specific humidity in the tracer table
contains
! <SUBROUTINE NAME="vegetation_init">
! <OVERVIEW>
! Initializes vegetation data.
! </OVERVIEW>
! <DESCRIPTION>
! Allocates vegetation data and sets up initial value for canopy air
! humidity.
! </DESCRIPTION>
! <TEMPLATE>
! call vegetation_init &
! ( veg, gblon, gblat, garea, gfrac, time, dt_fast, dt_slow, domain, &
! frac, mask, id_lon, id_lat )
! </TEMPLATE>
! <PUBLICROUTINE>
subroutine vegetation_init &
( veg, gblon, gblat, garea, gfrac, time, dt_fast, dt_slow, domain, &
frac, mask, id_lon, id_lat )
type(vegetation_type),intent(inout) :: veg ! state of a particular
! realization to initialize
real, intent(in) :: gblon(:,:) ! longitude corners of the
! grid cells
real, intent(in) :: gblat(:,:) ! latitude corners of the
! grid cells
real, intent(in) :: garea(:,:) ! grid cell area
real, intent(in) :: gfrac(:,:) ! fraction of grid cell
! covered by land
type(time_type), intent(in) :: time ! current time
type(time_type), intent(in) :: dt_fast ! fast time step
type(time_type), intent(in) :: dt_slow ! slow time step
type(domain2d), intent(in) :: domain ! our domain
real, intent(in) :: frac(:,:,:)! fractional area of tiles
logical, intent(in) :: mask(:,:,:)! land mask
integer, intent(in) :: id_lon ! ID of X (longitude) diag
! axis
integer, intent(in) :: id_lat ! ID of Y (latitude) diag
! axis
! </PUBLICROUTINE>
! ---- local vars ---------------------------------------------------------
integer :: unit, ierr, io ! restart file unit
integer :: sec, day ! components of time
if ( file_exist( 'input.nml' ) ) then
unit = open_namelist_file ( )
ierr = 1
do while ( ierr /= 0 )
read ( unit, nml = vegetation_nml, iostat = io, end = 10 )
ierr = check_nml_error ( io, 'vegetation_nml' )
enddo
10 continue
call close_file (unit)
endif
call get_restart_io_mode(do_netcdf_restart)
! write version and tag information to logfile
call write_version_number(version,tagname)
! write the namelist to a log file
if( mpp_pe()==0 ) then
unit = stdlog( )
write (unit, nml=vegetation_nml)
call close_file (unit)
endif
! copy specified domain to our data
veg % domain = domain
! get the size of our domain
call mpp_get_compute_domain ( veg%domain, veg%is, veg%ie, veg%js, veg%je )
veg%n_tiles = size(frac, 3)
! setup time-related data
call get_time(dt_fast, sec, day); veg%dt = day*86400.0+sec
! allocate data
allocate ( &
veg%mask (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%q_ca (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%evap (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%t_surf (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%c_surf (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%dqsatdt (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%e_q (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%f_q (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%beta (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles), &
veg%bonedry (veg%is:veg%ie, veg%js:veg%je, veg%n_tiles) )
veg%mask = mask
! set up initial value for canopy air humidity
veg%q_ca = 0
call set_domain ( veg%domain )
if (file_exist('INPUT/vegetation.res.nc') .or. file_exist('INPUT/vegetation.res.tile1.nc') ) then
if (mpp_pe() == mpp_root_pe()) call mpp_error ('vegetation_mod', &
'Reading NetCDF formatted restart file: INPUT/vegetation.res.nc', NOTE)
call read_data( 'INPUT/vegetation.res.nc', 'q_ca', veg%q_ca)
else
if (file_exist('INPUT/vegetation.res')) then
if (mpp_pe() == mpp_root_pe()) call mpp_error ('vegetation_mod', &
'Reading native formatted restart file.', NOTE)
unit = open_restart_file ( 'INPUT/vegetation.res', 'read')
call read_data ( unit, veg%q_ca )
call close_file ( unit )
endif
endif
! initialize tracers
#ifdef LAND_BND_TRACERS
isphum = get_tracer_index ( MODEL_LAND, 'sphum' )
if (isphum==NO_TRACER) then
call error_mesg('vegetation_init','no required "sphum" tracer',FATAL)
endif
#else
isphum = NO_TRACER
#endif
module_is_initialized =.TRUE.
end subroutine vegetation_init
! </SUBROUTINE>
! <SUBROUTINE NAME="vegetation_end">
! <OVERVIEW>
! Deallocates vegetation data; empty memory and do clean-up, if
! necessary.
! </OVERVIEW>
! <DESCRIPTION>
! Deallocates vegetation data; empty memory and do clean-up, if
! necessary.
! </DESCRIPTION>
! <TEMPLATE>
! call vegetation_end ( veg )
! </TEMPLATE>
! <PUBLICROUTINE>
subroutine vegetation_end ( veg )
type(vegetation_type), intent(inout) :: veg ! data to finish using
! </PUBLICROUTINE>
! ---- local vars ----------------------------------------------------------
integer :: unit ! restart file unit
! save restart file
call set_domain ( veg%domain )
if( do_netcdf_restart) then
if (mpp_pe() == mpp_root_pe()) call mpp_error ('vegetation_mod', &
'Writing NetCDF formatted restart file: RESTART/vegetation.res.nc', NOTE)
call write_data('RESTART/vegetation.res.nc', 'q_ca', veg%q_ca)
else
if (mpp_pe() == mpp_root_pe()) call mpp_error ('vegetation_mod', &
'Writing native formatted restart file.', NOTE)
unit = open_restart_file ( 'RESTART/vegetation.res', 'write' )
call write_data ( unit, veg%q_ca )
call close_file ( unit )
endif
! deallocate data
deallocate ( &
veg%mask, &
veg%q_ca, &
veg%evap, &
veg%t_surf, &
veg%c_surf, &
veg%dqsatdt, &
veg%e_q, &
veg%f_q, &
veg%beta, &
veg%bonedry )
module_is_initialized =.FALSE.
end subroutine vegetation_end
! </SUBROUTINE>
! <SUBROUTINE NAME="update_vegetation_slow">
! <OVERVIEW>
! Slow time-scale vegetation update.
! </OVERVIEW>
! <DESCRIPTION>
! Slow time-scale vegetation update.
! </DESCRIPTION>
! <TEMPLATE>
! call update_vegetation_slow ( veg )
! </TEMPLATE>
! <PUBLICROUTINE>
subroutine update_vegetation_slow ( veg )
type(vegetation_type), intent(inout) :: veg ! data to update
! </PUBLICROUTINE>
! call diagnostics_slow ( veg )
end subroutine update_vegetation_slow
! </SUBROUTINE>
! <SUBROUTINE NAME="update_vegetation_fast_down">
! <OVERVIEW>
! Fast time-scale vegetation update given soil data inputs.
! </OVERVIEW>
! <DESCRIPTION>
! Fast time-scale vegetation update given soil data inputs. Calculates
! water availability for evapotranspiration. Calculates saturated specific
! humidity at the surface and its derivative over the surface temperature.
! Air density is calculated here using surface q and T; in principle we
! should use canopy q and T, but surface values are the only ones we have
! available in this particular implementation.
! </DESCRIPTION>
! <TEMPLATE>
! call update_vegetation_fast_down( veg, soil, evap, dedq, drag_q, psurf, evap1, dedt)
! </TEMPLATE>
! <PUBLICROUTINE>
subroutine update_vegetation_fast_down( veg, soil, evap, dedq, drag_q, psurf, evap1, dedt)
type(vegetation_type), intent(inout) :: veg ! data to update
type(soil_type), intent(in) :: soil ! soil data inputs
real, intent(in) :: &
evap (veg%is:veg%ie,veg%js:veg%je,veg%n_tiles),&! evaporation from the
! surface into the atm
drag_q (:,:,:),& ! drag coefficient
dedq (:,:,:),& ! derivative of evap
! over q_ca
psurf (veg%is:veg%ie,veg%js:veg%je,veg%n_tiles) ! surface pressure
real, intent(out) :: &
dedt (:,:,:), & ! derivative of evap
! over T
evap1 (veg%is:veg%ie,veg%js:veg%je,veg%n_tiles) ! evaporation from
! stomatal into sfc
! </PUBLICROUTINE>
! ---- local vars ----------------------------------------------------------
real, dimension(veg%is:veg%ie,veg%js:veg%je,veg%n_tiles) :: &
qsat, &
qsat1, &
rho, & ! canopy air density
fusion_factor ! frozen-soil factor for modifying beta
real, parameter :: del_temp = 0.1 ! temperature increment for q_sat derivative calc.
! save soil surface temperature for future use in update_vegetation_fast_up
where (veg%mask)
veg%t_surf = soil%temp(:,:,:,1)
elsewhere
veg%t_surf = 200.0 ! safeguards to avoid errors in escomp
endwhere
if (klev == 0) then
fusion_factor= 1.
else
where (soil%mask)
fusion_factor= 1. - (soil%fusion(:,:,:,klev)/soil%max_fusion(klev))
endwhere
endif
! calculate water availability for evapotranspiration
if (soil%conserve_glacier_mass) then
where(soil%mask .and. (.not.soil%snow>0))
where (soil%glacier)
veg%beta = 0.0
elsewhere
veg%beta = max(0.0, min(1.0, soil%water/(0.75*soil%max_water)))* &
fusion_factor
endwhere
elsewhere
veg%beta = 1
endwhere
else
where(soil%mask .and. (.not.soil%glacier) .and. (.not.soil%snow>0))
veg%beta = max(0.0, min(1.0, soil%water/(0.75*soil%max_water)))* &
fusion_factor
elsewhere
veg%beta = 1
endwhere
endif
! calculate saturated specific humidity at the surface and its derivative
! over T sfc.
call escomp(veg%t_surf, qsat ) ! calculate sat water vapor pressure
call escomp(veg%t_surf+del_temp,qsat1) ! calculate sat water vapor pressure
evap1 = 0 ! + slm, Mar 29 2002, for some reason if I do not do it, model crashes in bone_dry
where (soil%mask)
! conversion is placed here because psurf does not have to be defined
! outside of land mask
qsat = d622*qsat /(psurf-d378*qsat ) ! convert pres. to spec. humidity
qsat1 = d622*qsat1/(psurf-d378*qsat1) ! convert pres. to spec. humidity
! air density is calculated here using surface q and T; in principle
! we should use canopy q and T, but surface values are the only ones we
! have available in this particular implementation, and that should do
rho = psurf / (rdgas* veg%t_surf * (1.0 + d608*veg%q_ca))
veg%dqsatdt = (qsat1 - qsat)/del_temp
where (soil%stomatal > 0.0)
veg%c_surf = rho * veg%beta/(soil%stomatal+(1-veg%beta)/drag_q)
veg%evap = veg%c_surf * (qsat - veg%q_ca)
evap1 = veg%evap + veg%c_surf*(evap - veg%evap)/(veg%c_surf + dedq)
dedt = veg%dqsatdt*veg%c_surf*(1.0-veg%c_surf/(veg%c_surf + dedq))
elsewhere
veg%e_q = 1 - dedq / ( rho*drag_q )
veg%f_q = evap * veg%e_q / ( rho*drag_q*( 1 - veg%e_q ) )
evap1 = evap + dedq * (1-veg%beta) * veg%f_q / (1-(1-veg%beta)*veg%e_q)
dedt = dedq * veg%beta * veg%dqsatdt / (1-(1-veg%beta)*veg%e_q)
endwhere
endwhere
! pcm fixed for glacier-mass conservation. however, this will not catch cases
! where explicit evap1 is ok but implicit evap_new is excessive. i think it
! might be cleaner to delete this section and instead allow negative stores of
! snow and/or soil water, as slm once suggested
veg%bonedry = .false.
if (soil%conserve_glacier_mass) then
where (soil%mask)
where ( evap1*veg%dt > soil%water+soil%snow )
veg%bonedry = .true.
evap1 = (soil%water+soil%snow)/veg%dt
veg%evap = evap1
dedt = 0
endwhere
endwhere
else
where (soil%mask)
where ( (.not.soil%glacier) .and. (evap1*veg%dt > soil%water+soil%snow ) )
veg%bonedry = .true.
evap1 = (soil%water+soil%snow)/veg%dt
veg%evap = evap1
dedt = 0
endwhere
endwhere
endif
! diagnostic output
if (veg%is<=iwatch.and.iwatch<=veg%ie.and.veg%js<=jwatch.and.jwatch<=veg%je) then
!!$ do i = 1, size(veg%mask,3)
!!$ write(*,'(i2,2L2,100g14.4)') i, &
!!$ veg%mask (iwatch,jwatch,i), &
!!$ soil%glacier (iwatch,jwatch,i), &
!!$ soil%stomatal(iwatch,jwatch,i), &
!!$ soil%water (iwatch,jwatch,i), &
!!$ veg%beta (iwatch,jwatch,i), &
!!$ veg%t_surf (iwatch,jwatch,i), &
!!$ veg%q_ca (iwatch,jwatch,i), &
!!$ qsat (iwatch,jwatch,i), &
!!$ evap (iwatch,jwatch,i), &
!!$ evap1 (iwatch,jwatch,i)
!!$ dedt (iwatch,jwatch,i), &
!!$ psurf (iwatch,jwatch,i), &
!!$ veg%dqsatdt (iwatch,jwatch,i)
!!$ enddo
endif
end subroutine update_vegetation_fast_down
! </SUBROUTINE>
! <SUBROUTINE NAME="update_vegetation_fast_up">
! <OVERVIEW>
! Fast time-scale vegetation update given soil data inputs.
! </OVERVIEW>
! <DESCRIPTION>
! Fast time-scale vegetation update given soil data inputs.
! </DESCRIPTION>
! <TEMPLATE>
! call update_vegetation_fast_up( veg, soil, drag_q, evap, dedq )
! </TEMPLATE>
! <PUBLICROUTINE>
subroutine update_vegetation_fast_up( veg, soil, drag_q, evap, dedq )
type(vegetation_type), intent(inout) :: veg ! data to update
type(soil_type), intent(in) :: soil ! soil data inputs
real, intent(in) :: &
drag_q (:,:,:), & ! drag coefficient for atmosphere (above vegetation)
evap (:,:,:), & ! evaporation from surface into the atmosphere
dedq (:,:,:) ! derivative of evap over q_ca
! </PUBLICROUTINE>
! -----local variables-------------------------------------------------------
real, dimension(veg%is:veg%ie,veg%js:veg%je,veg%n_tiles) :: &
delta_q_ca, & ! change in the surface humidity
delta_t_surf ! change in surface temperature
where (veg%mask)
delta_t_surf = soil%temp(:,:,:,1) - veg%t_surf
where ( veg%bonedry )
delta_q_ca = (veg%evap-evap)/dedq
elsewhere
where ( soil%stomatal > 0.0 )
delta_q_ca = (veg%evap - evap + veg%c_surf*veg%dqsatdt*delta_t_surf) &
/(veg%c_surf+dedq)
elsewhere ! bare soil or glacier (beta=1)
delta_q_ca = (veg%beta*veg%dqsatdt*delta_t_surf+(1-veg%beta)*veg%f_q) &
/(1-(1-veg%beta)*veg%e_q)
endwhere
endwhere
veg%q_ca = veg%q_ca + delta_q_ca
endwhere
end subroutine update_vegetation_fast_up
! </SUBROUTINE>
! <SUBROUTINE NAME="update_vegetation_bnd_fast">
! <OVERVIEW>
! Updates vegetation boundary data on the fast time-scale.
! </OVERVIEW>
! <DESCRIPTION>
! Updates vegetation boundary data on the fast time-scale.
! </DESCRIPTION>
! <TEMPLATE>
! call update_vegetation_bnd_fast ( veg, bnd )
! </TEMPLATE>
! <PUBLICROUTINE INTERFACE="">
subroutine update_vegetation_bnd_fast ( veg, bnd )
type(vegetation_type), intent(in) :: veg ! vegetation data
type(land_data_type), intent(inout) :: bnd ! boundary data
! </PUBLICROUTINE>
#ifdef LAND_BND_TRACERS
bnd%tr(:,:,:,isphum) = veg%q_ca
#else
bnd%q_ca = veg%q_ca
#endif
end subroutine update_vegetation_bnd_fast
! </SUBROUTINE>
! <SUBROUTINE NAME="update_vegetation_bnd_slow">
! <OVERVIEW>
! Updates vegetation boundary data on the slow time-scale.
! </OVERVIEW>
! <DESCRIPTION>
! Updates vegetation boundary data on the slow time-scale.
! </DESCRIPTION>
! <TEMPLATE>
! call update_vegetation_bnd_slow ( veg, bnd )
! </TEMPLATE>
! <PUBLICROUTINE>
subroutine update_vegetation_bnd_slow ( veg, bnd )
type(vegetation_type), intent(in) :: veg ! vegetation data
type(land_data_type), intent(inout) :: bnd ! boundary data
! </PUBLICROUTINE>
end subroutine update_vegetation_bnd_slow
! </SUBROUTINE>
subroutine vegetation_stock_pe ( veg, index, value )
type(vegetation_type), intent(in) :: veg ! vegetation state
integer , intent(in) :: index ! ID of the stock to calculate
real , intent(out) :: value ! calculated value of the stock
value = 0 ! vegetation doesn't have any capacity
end subroutine vegetation_stock_pe
end module vegetation_mod
| gpl-2.0 |
ForestClaw/forestclaw | applications/clawpack/transport/2d/all/velocity_wind.f | 1 | 1136 | double precision function psi(xd,yd,zd,t)
implicit none
double precision xd, yd, zd, t
double precision kappa,tfinal
common /windparms/ kappa,tfinal
double precision pi, pi2
common /compi/ pi, pi2
double precision l, th, lp
c call get_wind_parms(kappa,tfinal)
call map2polar(xd,yd,zd,l,th)
lp = l - 2*pi*t/tfinal
psi = kappa*sin(lp)**2*cos(th)**2*cos(pi*t/Tfinal) -
& 2*pi*sin(th)/Tfinal
c # Sign difference from Benchmark problem
psi = -psi
end
subroutine map2polar(x,y,z,lambda,th)
implicit none
double precision x,y,z,th,lambda
double precision r
double precision pi, pi2
common /compi/ pi, pi2
r = sqrt(x**2 + y**2 + z**2)
th = asin(z/r)
lambda = atan2(y,x)
if (lambda .lt. 0) then
lambda = lambda + 2*pi
endif
end
subroutine get_psi_vel(xd1,xd2,ds,vn,t)
implicit none
double precision xd1(3),xd2(3), ds, vn, psi,t
vn = (psi(xd1(1),xd1(2),xd1(3),t) -
& psi(xd2(1),xd2(2),xd2(3),t))/ds
end
| bsd-2-clause |
ForestClaw/forestclaw | applications/paper/sphere/user_4.6/qinit.f | 1 | 1431 | subroutine clawpack46_qinit(maxmx,maxmy, meqn,mbc,mx,my,
& xlower,ylower,dx,dy,q,maux,aux)
implicit none
integer meqn, mbc, mx, my, maux, maxmx, maxmy
double precision xlower, ylower, dx, dy
double precision q(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, meqn)
double precision aux(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, maux)
integer i, j, mq, blockno, fc2d_clawpack46_get_block
double precision xc,yc, xp, yp, zp, xlow, ylow, w, tol
double precision dxc,xm,ym
double precision q0_physical
integer*8 cont, get_context
logical fclaw2d_map_is_used
integer ii,jj
integer initchoice
common /initchoice_comm/ initchoice
cont = get_context()
blockno = fc2d_clawpack46_get_block()
do i = 1-mbc,mx+mbc
xc = xlower + (i-0.5d0)*dx
do j = 1-mbc,my+mbc
yc = ylower + (j-0.5d0)*dy
if (initchoice .eq. 0) then
c # Discontinuous solution
xlow = xlower + (i-1)*dx
ylow = ylower + (j-1)*dy
call cellave2(blockno,xlow,ylow,dx,dy,w)
q(i,j,1) = w
else
call fclaw2d_map_c2m(cont,blockno,xc,yc,xp,yp,zp)
q(i,j,1) = q0_physical(xp,yp,zp)
endif
enddo
enddo
return
end
| bsd-2-clause |
pschella/scipy | scipy/interpolate/fitpack/fptrnp.f | 148 | 2961 | subroutine fptrnp(m,mm,idim,n,nr,sp,p,b,z,a,q,right)
c subroutine fptrnp reduces the (m+n-7) x (n-4) matrix a to upper
c triangular form and applies the same givens transformations to
c the (m) x (mm) x (idim) matrix z to obtain the (n-4) x (mm) x
c (idim) matrix q
c ..
c ..scalar arguments..
real*8 p
integer m,mm,idim,n
c ..array arguments..
real*8 sp(m,4),b(n,5),z(m*mm*idim),a(n,5),q((n-4)*mm*idim),
* right(mm*idim)
integer nr(m)
c ..local scalars..
real*8 cos,pinv,piv,sin,one
integer i,iband,irot,it,ii,i2,i3,j,jj,l,mid,nmd,m2,m3,
* nrold,n4,number,n1
c ..local arrays..
real*8 h(7)
c ..subroutine references..
c fpgivs,fprota
c ..
one = 1
if(p.gt.0.) pinv = one/p
n4 = n-4
mid = mm*idim
m2 = m*mm
m3 = n4*mm
c reduce the matrix (a) to upper triangular form (r) using givens
c rotations. apply the same transformations to the rows of matrix z
c to obtain the mm x (n-4) matrix g.
c store matrix (r) into (a) and g into q.
c initialization.
nmd = n4*mid
do 50 i=1,nmd
q(i) = 0.
50 continue
do 100 i=1,n4
do 100 j=1,5
a(i,j) = 0.
100 continue
nrold = 0
c iband denotes the bandwidth of the matrices (a) and (r).
iband = 4
do 750 it=1,m
number = nr(it)
150 if(nrold.eq.number) go to 300
if(p.le.0.) go to 700
iband = 5
c fetch a new row of matrix (b).
n1 = nrold+1
do 200 j=1,5
h(j) = b(n1,j)*pinv
200 continue
c find the appropriate column of q.
do 250 j=1,mid
right(j) = 0.
250 continue
irot = nrold
go to 450
c fetch a new row of matrix (sp).
300 h(iband) = 0.
do 350 j=1,4
h(j) = sp(it,j)
350 continue
c find the appropriate column of q.
j = 0
do 400 ii=1,idim
l = (ii-1)*m2+(it-1)*mm
do 400 jj=1,mm
j = j+1
l = l+1
right(j) = z(l)
400 continue
irot = number
c rotate the new row of matrix (a) into triangle.
450 do 600 i=1,iband
irot = irot+1
piv = h(i)
if(piv.eq.0.) go to 600
c calculate the parameters of the givens transformation.
call fpgivs(piv,a(irot,1),cos,sin)
c apply that transformation to the rows of matrix q.
j = 0
do 500 ii=1,idim
l = (ii-1)*m3+irot
do 500 jj=1,mm
j = j+1
call fprota(cos,sin,right(j),q(l))
l = l+n4
500 continue
c apply that transformation to the columns of (a).
if(i.eq.iband) go to 650
i2 = 1
i3 = i+1
do 550 j=i3,iband
i2 = i2+1
call fprota(cos,sin,h(j),a(irot,i2))
550 continue
600 continue
650 if(nrold.eq.number) go to 750
700 nrold = nrold+1
go to 150
750 continue
return
end
| bsd-3-clause |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/intrinsic_optional_char_arg_1.f90 | 126 | 1064 | ! { dg-do compile }
! { dg-options "-fdump-tree-original" }
! PR fortran/36403
! Check that string lengths of optional arguments are added to the library-call
! even if those arguments are missing.
PROGRAM main
IMPLICIT NONE
CHARACTER(len=1) :: vect(4)
CHARACTER(len=1) :: matrix(2, 2)
matrix(1, 1) = ""
matrix(2, 1) = "a"
matrix(1, 2) = "b"
matrix(2, 2) = ""
vect = (/ "w", "x", "y", "z" /)
! Call the affected intrinsics
vect = EOSHIFT (vect, 2)
vect = PACK (matrix, matrix /= "")
matrix = RESHAPE (vect, (/ 2, 2 /))
END PROGRAM main
! All library function should be called with *two* trailing arguments "1" for
! the string lengths of both the main array and the optional argument:
! { dg-final { scan-tree-dump "_eoshift\[0-9_\]+char \\(\[&a-zA-Z0-9._, \]+, 1, 0\\)" "original" } }
! { dg-final { scan-tree-dump "_reshape\[0-9_\]+char \\(\[&a-zA-Z0-9._, \]+, 1, 0\\)" "original" } }
! { dg-final { scan-tree-dump "_pack\[0-9_\]+char \\(\[&a-zA-Z0-9._, \]+, 1, 0\\)" "original" } }
! { dg-final { cleanup-tree-dump "original" } }
| gpl-2.0 |
surhudm/scipy | scipy/optimize/lbfgsb/lbfgsb.f | 53 | 128595 | c=========== L-BFGS-B (version 3.0. April 25, 2011 ===================
c
c This is a modified version of L-BFGS-B. Minor changes in the updated
c code appear preceded by a line comment as follows
c
c c-jlm-jn
c
c Major changes are described in the accompanying paper:
c
c Jorge Nocedal and Jose Luis Morales, Remark on "Algorithm 778:
c L-BFGS-B: Fortran Subroutines for Large-Scale Bound Constrained
c Optimization" (2011). To appear in ACM Transactions on
c Mathematical Software,
c
c The paper describes an improvement and a correction to Algorithm 778.
c It is shown that the performance of the algorithm can be improved
c significantly by making a relatively simple modication to the subspace
c minimization phase. The correction concerns an error caused by the use
c of routine dpmeps to estimate machine precision.
c
c The total work space **wa** required by the new version is
c
c 2*m*n + 11m*m + 5*n + 8*m
c
c the old version required
c
c 2*m*n + 12m*m + 4*n + 12*m
c
c
c J. Nocedal Department of Electrical Engineering and
c Computer Science.
c Northwestern University. Evanston, IL. USA
c
c
c J.L Morales Departamento de Matematicas,
c Instituto Tecnologico Autonomo de Mexico
c Mexico D.F. Mexico.
c
c March 2011
c
c=============================================================================
subroutine setulb(n, m, x, l, u, nbd, f, g, factr, pgtol, wa, iwa,
+ task, iprint, csave, lsave, isave, dsave, maxls)
character*60 task, csave
logical lsave(4)
integer n, m, iprint, maxls,
+ nbd(n), iwa(3*n), isave(44)
double precision f, factr, pgtol, x(n), l(n), u(n), g(n),
c
c-jlm-jn
+ wa(2*m*n + 5*n + 11*m*m + 8*m), dsave(29)
c ************
c
c Subroutine setulb
c
c This subroutine partitions the working arrays wa and iwa, and
c then uses the limited memory BFGS method to solve the bound
c constrained optimization problem by calling mainlb.
c (The direct method will be used in the subspace minimization.)
c
c n is an integer variable.
c On entry n is the dimension of the problem.
c On exit n is unchanged.
c
c m is an integer variable.
c On entry m is the maximum number of variable metric corrections
c used to define the limited memory matrix.
c On exit m is unchanged.
c
c x is a double precision array of dimension n.
c On entry x is an approximation to the solution.
c On exit x is the current approximation.
c
c l is a double precision array of dimension n.
c On entry l is the lower bound on x.
c On exit l is unchanged.
c
c u is a double precision array of dimension n.
c On entry u is the upper bound on x.
c On exit u is unchanged.
c
c nbd is an integer array of dimension n.
c On entry nbd represents the type of bounds imposed on the
c variables, and must be specified as follows:
c nbd(i)=0 if x(i) is unbounded,
c 1 if x(i) has only a lower bound,
c 2 if x(i) has both lower and upper bounds, and
c 3 if x(i) has only an upper bound.
c On exit nbd is unchanged.
c
c f is a double precision variable.
c On first entry f is unspecified.
c On final exit f is the value of the function at x.
c
c g is a double precision array of dimension n.
c On first entry g is unspecified.
c On final exit g is the value of the gradient at x.
c
c factr is a double precision variable.
c On entry factr >= 0 is specified by the user. The iteration
c will stop when
c
c (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch
c
c where epsmch is the machine precision, which is automatically
c generated by the code. Typical values for factr: 1.d+12 for
c low accuracy; 1.d+7 for moderate accuracy; 1.d+1 for extremely
c high accuracy.
c On exit factr is unchanged.
c
c pgtol is a double precision variable.
c On entry pgtol >= 0 is specified by the user. The iteration
c will stop when
c
c max{|proj g_i | i = 1, ..., n} <= pgtol
c
c where pg_i is the ith component of the projected gradient.
c On exit pgtol is unchanged.
c
c wa is a double precision working array of length
c (2mmax + 5)nmax + 12mmax^2 + 12mmax.
c
c iwa is an integer working array of length 3nmax.
c
c task is a working string of characters of length 60 indicating
c the current job when entering and quitting this subroutine.
c
c iprint is an integer variable that must be set by the user.
c It controls the frequency and type of output generated:
c iprint<0 no output is generated;
c iprint=0 print only one line at the last iteration;
c 0<iprint<99 print also f and |proj g| every iprint iterations;
c iprint=99 print details of every iteration except n-vectors;
c iprint=100 print also the changes of active set and final x;
c iprint>100 print details of every iteration including x and g;
c
c
c csave is a working string of characters of length 60.
c
c lsave is a logical working array of dimension 4.
c On exit with 'task' = NEW_X, the following information is
c available:
c If lsave(1) = .true. then the initial X has been replaced by
c its projection in the feasible set;
c If lsave(2) = .true. then the problem is constrained;
c If lsave(3) = .true. then each variable has upper and lower
c bounds;
c
c isave is an integer working array of dimension 44.
c On exit with 'task' = NEW_X, the following information is
c available:
c isave(22) = the total number of intervals explored in the
c search of Cauchy points;
c isave(26) = the total number of skipped BFGS updates before
c the current iteration;
c isave(30) = the number of current iteration;
c isave(31) = the total number of BFGS updates prior the current
c iteration;
c isave(33) = the number of intervals explored in the search of
c Cauchy point in the current iteration;
c isave(34) = the total number of function and gradient
c evaluations;
c isave(36) = the number of function value or gradient
c evaluations in the current iteration;
c if isave(37) = 0 then the subspace argmin is within the box;
c if isave(37) = 1 then the subspace argmin is beyond the box;
c isave(38) = the number of free variables in the current
c iteration;
c isave(39) = the number of active constraints in the current
c iteration;
c n + 1 - isave(40) = the number of variables leaving the set of
c active constraints in the current iteration;
c isave(41) = the number of variables entering the set of active
c constraints in the current iteration.
c
c dsave is a double precision working array of dimension 29.
c On exit with 'task' = NEW_X, the following information is
c available:
c dsave(1) = current 'theta' in the BFGS matrix;
c dsave(2) = f(x) in the previous iteration;
c dsave(3) = factr*epsmch;
c dsave(4) = 2-norm of the line search direction vector;
c dsave(5) = the machine precision epsmch generated by the code;
c dsave(7) = the accumulated time spent on searching for
c Cauchy points;
c dsave(8) = the accumulated time spent on
c subspace minimization;
c dsave(9) = the accumulated time spent on line search;
c dsave(11) = the slope of the line search function at
c the current point of line search;
c dsave(12) = the maximum relative step length imposed in
c line search;
c dsave(13) = the infinity norm of the projected gradient;
c dsave(14) = the relative step length in the line search;
c dsave(15) = the slope of the line search function at
c the starting point of the line search;
c dsave(16) = the square of the 2-norm of the line search
c direction vector.
c
c Subprograms called:
c
c L-BFGS-B Library ... mainlb.
c
c
c References:
c
c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
c memory algorithm for bound constrained optimization'',
c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
c
c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: a
c limited memory FORTRAN code for solving bound constrained
c optimization problems'', Tech. Report, NAM-11, EECS Department,
c Northwestern University, 1994.
c
c (Postscript files of these papers are available via anonymous
c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
c-jlm-jn
integer lws,lr,lz,lt,ld,lxp,lwa,
+ lwy,lsy,lss,lwt,lwn,lsnd
if (task .eq. 'START') then
isave(1) = m*n
isave(2) = m**2
isave(3) = 4*m**2
isave(4) = 1 ! ws m*n
isave(5) = isave(4) + isave(1) ! wy m*n
isave(6) = isave(5) + isave(1) ! wsy m**2
isave(7) = isave(6) + isave(2) ! wss m**2
isave(8) = isave(7) + isave(2) ! wt m**2
isave(9) = isave(8) + isave(2) ! wn 4*m**2
isave(10) = isave(9) + isave(3) ! wsnd 4*m**2
isave(11) = isave(10) + isave(3) ! wz n
isave(12) = isave(11) + n ! wr n
isave(13) = isave(12) + n ! wd n
isave(14) = isave(13) + n ! wt n
isave(15) = isave(14) + n ! wxp n
isave(16) = isave(15) + n ! wa 8*m
endif
lws = isave(4)
lwy = isave(5)
lsy = isave(6)
lss = isave(7)
lwt = isave(8)
lwn = isave(9)
lsnd = isave(10)
lz = isave(11)
lr = isave(12)
ld = isave(13)
lt = isave(14)
lxp = isave(15)
lwa = isave(16)
call mainlb(n,m,x,l,u,nbd,f,g,factr,pgtol,
+ wa(lws),wa(lwy),wa(lsy),wa(lss), wa(lwt),
+ wa(lwn),wa(lsnd),wa(lz),wa(lr),wa(ld),wa(lt),wa(lxp),
+ wa(lwa),
+ iwa(1),iwa(n+1),iwa(2*n+1),task,iprint,
+ csave,lsave,isave(22),dsave, maxls)
return
end
c======================= The end of setulb =============================
subroutine mainlb(n, m, x, l, u, nbd, f, g, factr, pgtol, ws, wy,
+ sy, ss, wt, wn, snd, z, r, d, t, xp, wa,
+ index, iwhere, indx2, task,
+ iprint, csave, lsave, isave, dsave, maxls)
implicit none
character*60 task, csave
logical lsave(4)
integer n, m, iprint, nbd(n), index(n),
+ iwhere(n), indx2(n), isave(23),
+ maxls
double precision f, factr, pgtol,
+ x(n), l(n), u(n), g(n), z(n), r(n), d(n), t(n),
c-jlm-jn
+ xp(n),
+ wa(8*m),
+ ws(n, m), wy(n, m), sy(m, m), ss(m, m),
+ wt(m, m), wn(2*m, 2*m), snd(2*m, 2*m), dsave(29)
c ************
c
c Subroutine mainlb
c
c This subroutine solves bound constrained optimization problems by
c using the compact formula of the limited memory BFGS updates.
c
c n is an integer variable.
c On entry n is the number of variables.
c On exit n is unchanged.
c
c m is an integer variable.
c On entry m is the maximum number of variable metric
c corrections allowed in the limited memory matrix.
c On exit m is unchanged.
c
c x is a double precision array of dimension n.
c On entry x is an approximation to the solution.
c On exit x is the current approximation.
c
c l is a double precision array of dimension n.
c On entry l is the lower bound of x.
c On exit l is unchanged.
c
c u is a double precision array of dimension n.
c On entry u is the upper bound of x.
c On exit u is unchanged.
c
c nbd is an integer array of dimension n.
c On entry nbd represents the type of bounds imposed on the
c variables, and must be specified as follows:
c nbd(i)=0 if x(i) is unbounded,
c 1 if x(i) has only a lower bound,
c 2 if x(i) has both lower and upper bounds,
c 3 if x(i) has only an upper bound.
c On exit nbd is unchanged.
c
c f is a double precision variable.
c On first entry f is unspecified.
c On final exit f is the value of the function at x.
c
c g is a double precision array of dimension n.
c On first entry g is unspecified.
c On final exit g is the value of the gradient at x.
c
c factr is a double precision variable.
c On entry factr >= 0 is specified by the user. The iteration
c will stop when
c
c (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch
c
c where epsmch is the machine precision, which is automatically
c generated by the code.
c On exit factr is unchanged.
c
c pgtol is a double precision variable.
c On entry pgtol >= 0 is specified by the user. The iteration
c will stop when
c
c max{|proj g_i | i = 1, ..., n} <= pgtol
c
c where pg_i is the ith component of the projected gradient.
c On exit pgtol is unchanged.
c
c ws, wy, sy, and wt are double precision working arrays used to
c store the following information defining the limited memory
c BFGS matrix:
c ws, of dimension n x m, stores S, the matrix of s-vectors;
c wy, of dimension n x m, stores Y, the matrix of y-vectors;
c sy, of dimension m x m, stores S'Y;
c ss, of dimension m x m, stores S'S;
c yy, of dimension m x m, stores Y'Y;
c wt, of dimension m x m, stores the Cholesky factorization
c of (theta*S'S+LD^(-1)L'); see eq.
c (2.26) in [3].
c
c wn is a double precision working array of dimension 2m x 2m
c used to store the LEL^T factorization of the indefinite matrix
c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
c [L_a -R_z theta*S'AA'S ]
c
c where E = [-I 0]
c [ 0 I]
c
c snd is a double precision working array of dimension 2m x 2m
c used to store the lower triangular part of
c N = [Y' ZZ'Y L_a'+R_z']
c [L_a +R_z S'AA'S ]
c
c z(n),r(n),d(n),t(n), xp(n),wa(8*m) are double precision working arrays.
c z is used at different times to store the Cauchy point and
c the Newton point.
c xp is used to safeguard the projected Newton direction
c
c sg(m),sgo(m),yg(m),ygo(m) are double precision working arrays.
c
c index is an integer working array of dimension n.
c In subroutine freev, index is used to store the free and fixed
c variables at the Generalized Cauchy Point (GCP).
c
c iwhere is an integer working array of dimension n used to record
c the status of the vector x for GCP computation.
c iwhere(i)=0 or -3 if x(i) is free and has bounds,
c 1 if x(i) is fixed at l(i), and l(i) .ne. u(i)
c 2 if x(i) is fixed at u(i), and u(i) .ne. l(i)
c 3 if x(i) is always fixed, i.e., u(i)=x(i)=l(i)
c -1 if x(i) is always free, i.e., no bounds on it.
c
c indx2 is an integer working array of dimension n.
c Within subroutine cauchy, indx2 corresponds to the array iorder.
c In subroutine freev, a list of variables entering and leaving
c the free set is stored in indx2, and it is passed on to
c subroutine formk with this information.
c
c task is a working string of characters of length 60 indicating
c the current job when entering and leaving this subroutine.
c
c iprint is an INTEGER variable that must be set by the user.
c It controls the frequency and type of output generated:
c iprint<0 no output is generated;
c iprint=0 print only one line at the last iteration;
c 0<iprint<99 print also f and |proj g| every iprint iterations;
c iprint=99 print details of every iteration except n-vectors;
c iprint=100 print also the changes of active set and final x;
c iprint>100 print details of every iteration including x and g;
c
c
c csave is a working string of characters of length 60.
c
c lsave is a logical working array of dimension 4.
c
c isave is an integer working array of dimension 23.
c
c dsave is a double precision working array of dimension 29.
c
c
c Subprograms called
c
c L-BFGS-B Library ... cauchy, subsm, lnsrlb, formk,
c
c errclb, prn1lb, prn2lb, prn3lb, active, projgr,
c
c freev, cmprlb, matupd, formt.
c
c Minpack2 Library ... timer
c
c Linpack Library ... dcopy, ddot.
c
c
c References:
c
c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
c memory algorithm for bound constrained optimization'',
c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
c
c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN
c Subroutines for Large Scale Bound Constrained Optimization''
c Tech. Report, NAM-11, EECS Department, Northwestern University,
c 1994.
c
c [3] R. Byrd, J. Nocedal and R. Schnabel "Representations of
c Quasi-Newton Matrices and their use in Limited Memory Methods'',
c Mathematical Programming 63 (1994), no. 4, pp. 129-156.
c
c (Postscript files of these papers are available via anonymous
c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
logical prjctd,cnstnd,boxed,updatd,wrk
character*3 word
integer i,k,nintol,iback,nskip,
+ head,col,iter,itail,iupdat,
+ nseg,nfgv,info,ifun,
+ iword,nfree,nact,ileave,nenter
double precision theta,fold,ddot,dr,rr,tol,
+ xstep,sbgnrm,ddum,dnorm,dtd,epsmch,
+ cpu1,cpu2,cachyt,sbtime,lnscht,time1,time2,
+ gd,gdold,stp,stpmx,time
double precision one,zero
double precision dlamch
external dlamch
parameter (one=1.0d0,zero=0.0d0)
if (task .eq. 'START') then
epsmch = 2 * dlamch('e')
call timer(time1)
c Initialize counters and scalars when task='START'.
c for the limited memory BFGS matrices:
col = 0
head = 1
theta = one
iupdat = 0
updatd = .false.
iback = 0
itail = 0
iword = 0
nact = 0
ileave = 0
nenter = 0
fold = zero
dnorm = zero
cpu1 = zero
gd = zero
stpmx = zero
sbgnrm = zero
stp = zero
gdold = zero
dtd = zero
c for operation counts:
iter = 0
nfgv = 0
nseg = 0
nintol = 0
nskip = 0
nfree = n
ifun = 0
c for stopping tolerance:
tol = factr*epsmch
c for measuring running time:
cachyt = 0
sbtime = 0
lnscht = 0
c 'word' records the status of subspace solutions.
word = '---'
c 'info' records the termination information.
info = 0
c Check the input arguments for errors.
call errclb(n,m,factr,l,u,nbd,task,info,k)
if (task(1:5) .eq. 'ERROR') then
call prn3lb(n,x,f,task,iprint,info,
+ iter,nfgv,nintol,nskip,nact,sbgnrm,
+ zero,nseg,word,iback,stp,xstep,k,
+ cachyt,sbtime,lnscht)
return
endif
call prn1lb(n,m,l,u,x,iprint,epsmch)
c Initialize iwhere & project x onto the feasible set.
call active(n,l,u,nbd,x,iwhere,iprint,prjctd,cnstnd,boxed)
c The end of the initialization.
else
c restore local variables.
prjctd = lsave(1)
cnstnd = lsave(2)
boxed = lsave(3)
updatd = lsave(4)
nintol = isave(1)
iback = isave(4)
nskip = isave(5)
head = isave(6)
col = isave(7)
itail = isave(8)
iter = isave(9)
iupdat = isave(10)
nseg = isave(12)
nfgv = isave(13)
info = isave(14)
ifun = isave(15)
iword = isave(16)
nfree = isave(17)
nact = isave(18)
ileave = isave(19)
nenter = isave(20)
theta = dsave(1)
fold = dsave(2)
tol = dsave(3)
dnorm = dsave(4)
epsmch = dsave(5)
cpu1 = dsave(6)
cachyt = dsave(7)
sbtime = dsave(8)
lnscht = dsave(9)
time1 = dsave(10)
gd = dsave(11)
stpmx = dsave(12)
sbgnrm = dsave(13)
stp = dsave(14)
gdold = dsave(15)
dtd = dsave(16)
c After returning from the driver go to the point where execution
c is to resume.
if (task(1:5) .eq. 'FG_LN') goto 666
if (task(1:5) .eq. 'NEW_X') goto 777
if (task(1:5) .eq. 'FG_ST') goto 111
if (task(1:4) .eq. 'STOP') then
if (task(7:9) .eq. 'CPU') then
c restore the previous iterate.
call dcopy(n,t,1,x,1)
call dcopy(n,r,1,g,1)
f = fold
endif
goto 999
endif
endif
c Compute f0 and g0.
task = 'FG_START'
c return to the driver to calculate f and g; reenter at 111.
goto 1000
111 continue
nfgv = 1
c Compute the infinity norm of the (-) projected gradient.
call projgr(n,l,u,nbd,x,g,sbgnrm)
if (iprint .ge. 1) then
write (6,1002) iter,f,sbgnrm
endif
if (sbgnrm .le. pgtol) then
c terminate the algorithm.
task = 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
goto 999
endif
c ----------------- the beginning of the loop --------------------------
222 continue
if (iprint .ge. 99) write (6,1001) iter + 1
iword = -1
c
if (.not. cnstnd .and. col .gt. 0) then
c skip the search for GCP.
call dcopy(n,x,1,z,1)
wrk = updatd
nseg = 0
goto 333
endif
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c Compute the Generalized Cauchy Point (GCP).
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
call timer(cpu1)
call cauchy(n,x,l,u,nbd,g,indx2,iwhere,t,d,z,
+ m,wy,ws,sy,wt,theta,col,head,
+ wa(1),wa(2*m+1),wa(4*m+1),wa(6*m+1),nseg,
+ iprint, sbgnrm, info, epsmch)
if (info .ne. 0) then
c singular triangular system detected; refresh the lbfgs memory.
if(iprint .ge. 1) write (0, 1005)
info = 0
col = 0
head = 1
theta = one
iupdat = 0
updatd = .false.
call timer(cpu2)
cachyt = cachyt + cpu2 - cpu1
goto 222
endif
call timer(cpu2)
cachyt = cachyt + cpu2 - cpu1
nintol = nintol + nseg
c Count the entering and leaving variables for iter > 0;
c find the index set of free and active variables at the GCP.
call freev(n,nfree,index,nenter,ileave,indx2,
+ iwhere,wrk,updatd,cnstnd,iprint,iter)
nact = n - nfree
333 continue
c If there are no free variables or B=theta*I, then
c skip the subspace minimization.
if (nfree .eq. 0 .or. col .eq. 0) goto 555
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c Subspace minimization.
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
call timer(cpu1)
c Form the LEL^T factorization of the indefinite
c matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
c [L_a -R_z theta*S'AA'S ]
c where E = [-I 0]
c [ 0 I]
if (wrk) call formk(n,nfree,index,nenter,ileave,indx2,iupdat,
+ updatd,wn,snd,m,ws,wy,sy,theta,col,head,info)
if (info .ne. 0) then
c nonpositive definiteness in Cholesky factorization;
c refresh the lbfgs memory and restart the iteration.
if(iprint .ge. 1) write (0, 1006)
info = 0
col = 0
head = 1
theta = one
iupdat = 0
updatd = .false.
call timer(cpu2)
sbtime = sbtime + cpu2 - cpu1
goto 222
endif
c compute r=-Z'B(xcp-xk)-Z'g (using wa(2m+1)=W'(xcp-x)
c from 'cauchy').
call cmprlb(n,m,x,g,ws,wy,sy,wt,z,r,wa,index,
+ theta,col,head,nfree,cnstnd,info)
if (info .ne. 0) goto 444
c-jlm-jn call the direct method.
call subsm( n, m, nfree, index, l, u, nbd, z, r, xp, ws, wy,
+ theta, x, g, col, head, iword, wa, wn, iprint, info)
444 continue
if (info .ne. 0) then
c singular triangular system detected;
c refresh the lbfgs memory and restart the iteration.
if(iprint .ge. 1) write (0, 1005)
info = 0
col = 0
head = 1
theta = one
iupdat = 0
updatd = .false.
call timer(cpu2)
sbtime = sbtime + cpu2 - cpu1
goto 222
endif
call timer(cpu2)
sbtime = sbtime + cpu2 - cpu1
555 continue
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c Line search and optimality tests.
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Generate the search direction d:=z-x.
do 40 i = 1, n
d(i) = z(i) - x(i)
40 continue
call timer(cpu1)
666 continue
call lnsrlb(n,l,u,nbd,x,f,fold,gd,gdold,g,d,r,t,z,stp,dnorm,
+ dtd,xstep,stpmx,iter,ifun,iback,nfgv,info,task,
+ boxed,cnstnd,csave,isave(22),dsave(17), iprint)
if (info .ne. 0 .or. iback .ge. maxls) then
c restore the previous iterate.
call dcopy(n,t,1,x,1)
call dcopy(n,r,1,g,1)
f = fold
if (col .eq. 0) then
c abnormal termination.
if (info .eq. 0) then
info = -9
c restore the actual number of f and g evaluations etc.
nfgv = nfgv - 1
ifun = ifun - 1
iback = iback - 1
endif
task = 'ABNORMAL_TERMINATION_IN_LNSRCH'
iter = iter + 1
goto 999
else
c refresh the lbfgs memory and restart the iteration.
if(iprint .ge. 1) write (0, 1008)
if (info .eq. 0) nfgv = nfgv - 1
info = 0
col = 0
head = 1
theta = one
iupdat = 0
updatd = .false.
task = 'RESTART_FROM_LNSRCH'
call timer(cpu2)
lnscht = lnscht + cpu2 - cpu1
goto 222
endif
else if (task(1:5) .eq. 'FG_LN') then
c return to the driver for calculating f and g; reenter at 666.
goto 1000
else
c calculate and print out the quantities related to the new X.
call timer(cpu2)
lnscht = lnscht + cpu2 - cpu1
iter = iter + 1
c Compute the infinity norm of the projected (-)gradient.
call projgr(n,l,u,nbd,x,g,sbgnrm)
c Print iteration information.
call prn2lb(n,x,f,g,iprint,iter,nfgv,nact,
+ sbgnrm,nseg,word,iword,iback,stp,xstep)
goto 1000
endif
777 continue
c Test for termination.
if (sbgnrm .le. pgtol) then
c terminate the algorithm.
task = 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
goto 999
endif
ddum = max(abs(fold), abs(f), one)
if ((fold - f) .le. tol*ddum) then
c terminate the algorithm.
task = 'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
if (iback .ge. 10) info = -5
c i.e., to issue a warning if iback>10 in the line search.
goto 999
endif
c Compute d=newx-oldx, r=newg-oldg, rr=y'y and dr=y's.
do 42 i = 1, n
r(i) = g(i) - r(i)
42 continue
rr = ddot(n,r,1,r,1)
if (stp .eq. one) then
dr = gd - gdold
ddum = -gdold
else
dr = (gd - gdold)*stp
call dscal(n,stp,d,1)
ddum = -gdold*stp
endif
if (dr .le. epsmch*ddum) then
c skip the L-BFGS update.
nskip = nskip + 1
updatd = .false.
if (iprint .ge. 1) write (6,1004) dr, ddum
goto 888
endif
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c Update the L-BFGS matrix.
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
updatd = .true.
iupdat = iupdat + 1
c Update matrices WS and WY and form the middle matrix in B.
call matupd(n,m,ws,wy,sy,ss,d,r,itail,
+ iupdat,col,head,theta,rr,dr,stp,dtd)
c Form the upper half of the pds T = theta*SS + L*D^(-1)*L';
c Store T in the upper triangular of the array wt;
c Cholesky factorize T to J*J' with
c J' stored in the upper triangular of wt.
call formt(m,wt,sy,ss,col,theta,info)
if (info .ne. 0) then
c nonpositive definiteness in Cholesky factorization;
c refresh the lbfgs memory and restart the iteration.
if(iprint .ge. 1) write (0, 1007)
info = 0
col = 0
head = 1
theta = one
iupdat = 0
updatd = .false.
goto 222
endif
c Now the inverse of the middle matrix in B is
c [ D^(1/2) O ] [ -D^(1/2) D^(-1/2)*L' ]
c [ -L*D^(-1/2) J ] [ 0 J' ]
888 continue
c -------------------- the end of the loop -----------------------------
goto 222
999 continue
call timer(time2)
time = time2 - time1
call prn3lb(n,x,f,task,iprint,info,
+ iter,nfgv,nintol,nskip,nact,sbgnrm,
+ time,nseg,word,iback,stp,xstep,k,
+ cachyt,sbtime,lnscht)
1000 continue
c Save local variables.
lsave(1) = prjctd
lsave(2) = cnstnd
lsave(3) = boxed
lsave(4) = updatd
isave(1) = nintol
isave(4) = iback
isave(5) = nskip
isave(6) = head
isave(7) = col
isave(8) = itail
isave(9) = iter
isave(10) = iupdat
isave(12) = nseg
isave(13) = nfgv
isave(14) = info
isave(15) = ifun
isave(16) = iword
isave(17) = nfree
isave(18) = nact
isave(19) = ileave
isave(20) = nenter
dsave(1) = theta
dsave(2) = fold
dsave(3) = tol
dsave(4) = dnorm
dsave(5) = epsmch
dsave(6) = cpu1
dsave(7) = cachyt
dsave(8) = sbtime
dsave(9) = lnscht
dsave(10) = time1
dsave(11) = gd
dsave(12) = stpmx
dsave(13) = sbgnrm
dsave(14) = stp
dsave(15) = gdold
dsave(16) = dtd
1001 format (//,'ITERATION ',i5)
1002 format
+ (/,'At iterate',i5,4x,'f= ',1p,d12.5,4x,'|proj g|= ',1p,d12.5)
1003 format (2(1x,i4),5x,'-',5x,'-',3x,'-',5x,'-',5x,'-',8x,'-',3x,
+ 1p,2(1x,d10.3))
1004 format (' ys=',1p,e10.3,' -gs=',1p,e10.3,' BFGS update SKIPPED')
1005 format (/,
+' Singular triangular system detected;',/,
+' refresh the lbfgs memory and restart the iteration.')
1006 format (/,
+' Nonpositive definiteness in Cholesky factorization in formk;',/,
+' refresh the lbfgs memory and restart the iteration.')
1007 format (/,
+' Nonpositive definiteness in Cholesky factorization in formt;',/,
+' refresh the lbfgs memory and restart the iteration.')
1008 format (/,
+' Bad direction in the line search;',/,
+' refresh the lbfgs memory and restart the iteration.')
return
end
c======================= The end of mainlb =============================
subroutine active(n, l, u, nbd, x, iwhere, iprint,
+ prjctd, cnstnd, boxed)
logical prjctd, cnstnd, boxed
integer n, iprint, nbd(n), iwhere(n)
double precision x(n), l(n), u(n)
c ************
c
c Subroutine active
c
c This subroutine initializes iwhere and projects the initial x to
c the feasible set if necessary.
c
c iwhere is an integer array of dimension n.
c On entry iwhere is unspecified.
c On exit iwhere(i)=-1 if x(i) has no bounds
c 3 if l(i)=u(i)
c 0 otherwise.
c In cauchy, iwhere is given finer gradations.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer nbdd,i
double precision zero
parameter (zero=0.0d0)
c Initialize nbdd, prjctd, cnstnd and boxed.
nbdd = 0
prjctd = .false.
cnstnd = .false.
boxed = .true.
c Project the initial x to the easible set if necessary.
do 10 i = 1, n
if (nbd(i) .gt. 0) then
if (nbd(i) .le. 2 .and. x(i) .le. l(i)) then
if (x(i) .lt. l(i)) then
prjctd = .true.
x(i) = l(i)
endif
nbdd = nbdd + 1
else if (nbd(i) .ge. 2 .and. x(i) .ge. u(i)) then
if (x(i) .gt. u(i)) then
prjctd = .true.
x(i) = u(i)
endif
nbdd = nbdd + 1
endif
endif
10 continue
c Initialize iwhere and assign values to cnstnd and boxed.
do 20 i = 1, n
if (nbd(i) .ne. 2) boxed = .false.
if (nbd(i) .eq. 0) then
c this variable is always free
iwhere(i) = -1
c otherwise set x(i)=mid(x(i), u(i), l(i)).
else
cnstnd = .true.
if (nbd(i) .eq. 2 .and. u(i) - l(i) .le. zero) then
c this variable is always fixed
iwhere(i) = 3
else
iwhere(i) = 0
endif
endif
20 continue
if (iprint .ge. 0) then
if (prjctd) write (0,*)
+ 'The initial X is infeasible. Restart with its projection.'
if (.not. cnstnd)
+ write (0,*) 'This problem is unconstrained.'
endif
if (iprint .gt. 0) write (6,1001) nbdd
1001 format (/,'At X0 ',i9,' variables are exactly at the bounds')
return
end
c======================= The end of active =============================
subroutine bmv(m, sy, wt, col, v, p, info)
integer m, col, info
double precision sy(m, m), wt(m, m), v(2*col), p(2*col)
c ************
c
c Subroutine bmv
c
c This subroutine computes the product of the 2m x 2m middle matrix
c in the compact L-BFGS formula of B and a 2m vector v;
c it returns the product in p.
c
c m is an integer variable.
c On entry m is the maximum number of variable metric corrections
c used to define the limited memory matrix.
c On exit m is unchanged.
c
c sy is a double precision array of dimension m x m.
c On entry sy specifies the matrix S'Y.
c On exit sy is unchanged.
c
c wt is a double precision array of dimension m x m.
c On entry wt specifies the upper triangular matrix J' which is
c the Cholesky factor of (thetaS'S+LD^(-1)L').
c On exit wt is unchanged.
c
c col is an integer variable.
c On entry col specifies the number of s-vectors (or y-vectors)
c stored in the compact L-BFGS formula.
c On exit col is unchanged.
c
c v is a double precision array of dimension 2col.
c On entry v specifies vector v.
c On exit v is unchanged.
c
c p is a double precision array of dimension 2col.
c On entry p is unspecified.
c On exit p is the product Mv.
c
c info is an integer variable.
c On entry info is unspecified.
c On exit info = 0 for normal return,
c = nonzero for abnormal return when the system
c to be solved by dtrsl is singular.
c
c Subprograms called:
c
c Linpack ... dtrsl.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i,k,i2
double precision sum
if (col .eq. 0) return
c PART I: solve [ D^(1/2) O ] [ p1 ] = [ v1 ]
c [ -L*D^(-1/2) J ] [ p2 ] [ v2 ].
c solve Jp2=v2+LD^(-1)v1.
p(col + 1) = v(col + 1)
do 20 i = 2, col
i2 = col + i
sum = 0.0d0
do 10 k = 1, i - 1
sum = sum + sy(i,k)*v(k)/sy(k,k)
10 continue
p(i2) = v(i2) + sum
20 continue
c Solve the triangular system
call dtrsl(wt,m,col,p(col+1),11,info)
if (info .ne. 0) return
c solve D^(1/2)p1=v1.
do 30 i = 1, col
p(i) = v(i)/sqrt(sy(i,i))
30 continue
c PART II: solve [ -D^(1/2) D^(-1/2)*L' ] [ p1 ] = [ p1 ]
c [ 0 J' ] [ p2 ] [ p2 ].
c solve J^Tp2=p2.
call dtrsl(wt,m,col,p(col+1),01,info)
if (info .ne. 0) return
c compute p1=-D^(-1/2)(p1-D^(-1/2)L'p2)
c =-D^(-1/2)p1+D^(-1)L'p2.
do 40 i = 1, col
p(i) = -p(i)/sqrt(sy(i,i))
40 continue
do 60 i = 1, col
sum = 0.d0
do 50 k = i + 1, col
sum = sum + sy(k,i)*p(col+k)/sy(i,i)
50 continue
p(i) = p(i) + sum
60 continue
return
end
c======================== The end of bmv ===============================
subroutine cauchy(n, x, l, u, nbd, g, iorder, iwhere, t, d, xcp,
+ m, wy, ws, sy, wt, theta, col, head, p, c, wbp,
+ v, nseg, iprint, sbgnrm, info, epsmch)
implicit none
integer n, m, head, col, nseg, iprint, info,
+ nbd(n), iorder(n), iwhere(n)
double precision theta, epsmch,
+ x(n), l(n), u(n), g(n), t(n), d(n), xcp(n),
+ wy(n, col), ws(n, col), sy(m, m),
+ wt(m, m), p(2*m), c(2*m), wbp(2*m), v(2*m)
c ************
c
c Subroutine cauchy
c
c For given x, l, u, g (with sbgnrm > 0), and a limited memory
c BFGS matrix B defined in terms of matrices WY, WS, WT, and
c scalars head, col, and theta, this subroutine computes the
c generalized Cauchy point (GCP), defined as the first local
c minimizer of the quadratic
c
c Q(x + s) = g's + 1/2 s'Bs
c
c along the projected gradient direction P(x-tg,l,u).
c The routine returns the GCP in xcp.
c
c n is an integer variable.
c On entry n is the dimension of the problem.
c On exit n is unchanged.
c
c x is a double precision array of dimension n.
c On entry x is the starting point for the GCP computation.
c On exit x is unchanged.
c
c l is a double precision array of dimension n.
c On entry l is the lower bound of x.
c On exit l is unchanged.
c
c u is a double precision array of dimension n.
c On entry u is the upper bound of x.
c On exit u is unchanged.
c
c nbd is an integer array of dimension n.
c On entry nbd represents the type of bounds imposed on the
c variables, and must be specified as follows:
c nbd(i)=0 if x(i) is unbounded,
c 1 if x(i) has only a lower bound,
c 2 if x(i) has both lower and upper bounds, and
c 3 if x(i) has only an upper bound.
c On exit nbd is unchanged.
c
c g is a double precision array of dimension n.
c On entry g is the gradient of f(x). g must be a nonzero vector.
c On exit g is unchanged.
c
c iorder is an integer working array of dimension n.
c iorder will be used to store the breakpoints in the piecewise
c linear path and free variables encountered. On exit,
c iorder(1),...,iorder(nleft) are indices of breakpoints
c which have not been encountered;
c iorder(nleft+1),...,iorder(nbreak) are indices of
c encountered breakpoints; and
c iorder(nfree),...,iorder(n) are indices of variables which
c have no bound constraits along the search direction.
c
c iwhere is an integer array of dimension n.
c On entry iwhere indicates only the permanently fixed (iwhere=3)
c or free (iwhere= -1) components of x.
c On exit iwhere records the status of the current x variables.
c iwhere(i)=-3 if x(i) is free and has bounds, but is not moved
c 0 if x(i) is free and has bounds, and is moved
c 1 if x(i) is fixed at l(i), and l(i) .ne. u(i)
c 2 if x(i) is fixed at u(i), and u(i) .ne. l(i)
c 3 if x(i) is always fixed, i.e., u(i)=x(i)=l(i)
c -1 if x(i) is always free, i.e., it has no bounds.
c
c t is a double precision working array of dimension n.
c t will be used to store the break points.
c
c d is a double precision array of dimension n used to store
c the Cauchy direction P(x-tg)-x.
c
c xcp is a double precision array of dimension n used to return the
c GCP on exit.
c
c m is an integer variable.
c On entry m is the maximum number of variable metric corrections
c used to define the limited memory matrix.
c On exit m is unchanged.
c
c ws, wy, sy, and wt are double precision arrays.
c On entry they store information that defines the
c limited memory BFGS matrix:
c ws(n,m) stores S, a set of s-vectors;
c wy(n,m) stores Y, a set of y-vectors;
c sy(m,m) stores S'Y;
c wt(m,m) stores the
c Cholesky factorization of (theta*S'S+LD^(-1)L').
c On exit these arrays are unchanged.
c
c theta is a double precision variable.
c On entry theta is the scaling factor specifying B_0 = theta I.
c On exit theta is unchanged.
c
c col is an integer variable.
c On entry col is the actual number of variable metric
c corrections stored so far.
c On exit col is unchanged.
c
c head is an integer variable.
c On entry head is the location of the first s-vector (or y-vector)
c in S (or Y).
c On exit col is unchanged.
c
c p is a double precision working array of dimension 2m.
c p will be used to store the vector p = W^(T)d.
c
c c is a double precision working array of dimension 2m.
c c will be used to store the vector c = W^(T)(xcp-x).
c
c wbp is a double precision working array of dimension 2m.
c wbp will be used to store the row of W corresponding
c to a breakpoint.
c
c v is a double precision working array of dimension 2m.
c
c nseg is an integer variable.
c On exit nseg records the number of quadratic segments explored
c in searching for the GCP.
c
c sg and yg are double precision arrays of dimension m.
c On entry sg and yg store S'g and Y'g correspondingly.
c On exit they are unchanged.
c
c iprint is an INTEGER variable that must be set by the user.
c It controls the frequency and type of output generated:
c iprint<0 no output is generated;
c iprint=0 print only one line at the last iteration;
c 0<iprint<99 print also f and |proj g| every iprint iterations;
c iprint=99 print details of every iteration except n-vectors;
c iprint=100 print also the changes of active set and final x;
c iprint>100 print details of every iteration including x and g;
c
c
c sbgnrm is a double precision variable.
c On entry sbgnrm is the norm of the projected gradient at x.
c On exit sbgnrm is unchanged.
c
c info is an integer variable.
c On entry info is 0.
c On exit info = 0 for normal return,
c = nonzero for abnormal return when the the system
c used in routine bmv is singular.
c
c Subprograms called:
c
c L-BFGS-B Library ... hpsolb, bmv.
c
c Linpack ... dscal dcopy, daxpy.
c
c
c References:
c
c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
c memory algorithm for bound constrained optimization'',
c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
c
c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN
c Subroutines for Large Scale Bound Constrained Optimization''
c Tech. Report, NAM-11, EECS Department, Northwestern University,
c 1994.
c
c (Postscript files of these papers are available via anonymous
c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
logical xlower,xupper,bnded
integer i,j,col2,nfree,nbreak,pointr,
+ ibp,nleft,ibkmin,iter
double precision f1,f2,dt,dtm,tsum,dibp,zibp,dibp2,bkmin,
+ tu,tl,wmc,wmp,wmw,ddot,tj,tj0,neggi,sbgnrm,
+ f2_org
double precision one,zero
parameter (one=1.0d0,zero=0.0d0)
c Check the status of the variables, reset iwhere(i) if necessary;
c compute the Cauchy direction d and the breakpoints t; initialize
c the derivative f1 and the vector p = W'd (for theta = 1).
if (sbgnrm .le. zero) then
if (iprint .ge. 0) write (6,*) 'Subgnorm = 0. GCP = X.'
call dcopy(n,x,1,xcp,1)
return
endif
bnded = .true.
nfree = n + 1
nbreak = 0
ibkmin = 0
bkmin = zero
col2 = 2*col
f1 = zero
if (iprint .ge. 99) write (6,3010)
c We set p to zero and build it up as we determine d.
do 20 i = 1, col2
p(i) = zero
20 continue
c In the following loop we determine for each variable its bound
c status and its breakpoint, and update p accordingly.
c Smallest breakpoint is identified.
do 50 i = 1, n
neggi = -g(i)
if (iwhere(i) .ne. 3 .and. iwhere(i) .ne. -1) then
c if x(i) is not a constant and has bounds,
c compute the difference between x(i) and its bounds.
if (nbd(i) .le. 2) tl = x(i) - l(i)
if (nbd(i) .ge. 2) tu = u(i) - x(i)
c If a variable is close enough to a bound
c we treat it as at bound.
xlower = nbd(i) .le. 2 .and. tl .le. zero
xupper = nbd(i) .ge. 2 .and. tu .le. zero
c reset iwhere(i).
iwhere(i) = 0
if (xlower) then
if (neggi .le. zero) iwhere(i) = 1
else if (xupper) then
if (neggi .ge. zero) iwhere(i) = 2
else
if (abs(neggi) .le. zero) iwhere(i) = -3
endif
endif
pointr = head
if (iwhere(i) .ne. 0 .and. iwhere(i) .ne. -1) then
d(i) = zero
else
d(i) = neggi
f1 = f1 - neggi*neggi
c calculate p := p - W'e_i* (g_i).
do 40 j = 1, col
p(j) = p(j) + wy(i,pointr)* neggi
p(col + j) = p(col + j) + ws(i,pointr)*neggi
pointr = mod(pointr,m) + 1
40 continue
if (nbd(i) .le. 2 .and. nbd(i) .ne. 0
+ .and. neggi .lt. zero) then
c x(i) + d(i) is bounded; compute t(i).
nbreak = nbreak + 1
iorder(nbreak) = i
t(nbreak) = tl/(-neggi)
if (nbreak .eq. 1 .or. t(nbreak) .lt. bkmin) then
bkmin = t(nbreak)
ibkmin = nbreak
endif
else if (nbd(i) .ge. 2 .and. neggi .gt. zero) then
c x(i) + d(i) is bounded; compute t(i).
nbreak = nbreak + 1
iorder(nbreak) = i
t(nbreak) = tu/neggi
if (nbreak .eq. 1 .or. t(nbreak) .lt. bkmin) then
bkmin = t(nbreak)
ibkmin = nbreak
endif
else
c x(i) + d(i) is not bounded.
nfree = nfree - 1
iorder(nfree) = i
if (abs(neggi) .gt. zero) bnded = .false.
endif
endif
50 continue
c The indices of the nonzero components of d are now stored
c in iorder(1),...,iorder(nbreak) and iorder(nfree),...,iorder(n).
c The smallest of the nbreak breakpoints is in t(ibkmin)=bkmin.
if (theta .ne. one) then
c complete the initialization of p for theta not= one.
call dscal(col,theta,p(col+1),1)
endif
c Initialize GCP xcp = x.
call dcopy(n,x,1,xcp,1)
if (nbreak .eq. 0 .and. nfree .eq. n + 1) then
c is a zero vector, return with the initial xcp as GCP.
if (iprint .gt. 100) write (6,1010) (xcp(i), i = 1, n)
return
endif
c Initialize c = W'(xcp - x) = 0.
do 60 j = 1, col2
c(j) = zero
60 continue
c Initialize derivative f2.
f2 = -theta*f1
f2_org = f2
if (col .gt. 0) then
call bmv(m,sy,wt,col,p,v,info)
if (info .ne. 0) return
f2 = f2 - ddot(col2,v,1,p,1)
endif
dtm = -f1/f2
tsum = zero
nseg = 1
if (iprint .ge. 99)
+ write (6,*) 'There are ',nbreak,' breakpoints '
c If there are no breakpoints, locate the GCP and return.
if (nbreak .eq. 0) goto 888
nleft = nbreak
iter = 1
tj = zero
c------------------- the beginning of the loop -------------------------
777 continue
c Find the next smallest breakpoint;
c compute dt = t(nleft) - t(nleft + 1).
tj0 = tj
if (iter .eq. 1) then
c Since we already have the smallest breakpoint we need not do
c heapsort yet. Often only one breakpoint is used and the
c cost of heapsort is avoided.
tj = bkmin
ibp = iorder(ibkmin)
else
if (iter .eq. 2) then
c Replace the already used smallest breakpoint with the
c breakpoint numbered nbreak > nlast, before heapsort call.
if (ibkmin .ne. nbreak) then
t(ibkmin) = t(nbreak)
iorder(ibkmin) = iorder(nbreak)
endif
c Update heap structure of breakpoints
c (if iter=2, initialize heap).
endif
call hpsolb(nleft,t,iorder,iter-2)
tj = t(nleft)
ibp = iorder(nleft)
endif
dt = tj - tj0
if (dt .ne. zero .and. iprint .ge. 100) then
write (6,4011) nseg,f1,f2
write (6,5010) dt
write (6,6010) dtm
endif
c If a minimizer is within this interval, locate the GCP and return.
if (dtm .lt. dt) goto 888
c Otherwise fix one variable and
c reset the corresponding component of d to zero.
tsum = tsum + dt
nleft = nleft - 1
iter = iter + 1
dibp = d(ibp)
d(ibp) = zero
if (dibp .gt. zero) then
zibp = u(ibp) - x(ibp)
xcp(ibp) = u(ibp)
iwhere(ibp) = 2
else
zibp = l(ibp) - x(ibp)
xcp(ibp) = l(ibp)
iwhere(ibp) = 1
endif
if (iprint .ge. 100) write (6,*) 'Variable ',ibp,' is fixed.'
if (nleft .eq. 0 .and. nbreak .eq. n) then
c all n variables are fixed,
c return with xcp as GCP.
dtm = dt
goto 999
endif
c Update the derivative information.
nseg = nseg + 1
dibp2 = dibp**2
c Update f1 and f2.
c temporarily set f1 and f2 for col=0.
f1 = f1 + dt*f2 + dibp2 - theta*dibp*zibp
f2 = f2 - theta*dibp2
if (col .gt. 0) then
c update c = c + dt*p.
call daxpy(col2,dt,p,1,c,1)
c choose wbp,
c the row of W corresponding to the breakpoint encountered.
pointr = head
do 70 j = 1,col
wbp(j) = wy(ibp,pointr)
wbp(col + j) = theta*ws(ibp,pointr)
pointr = mod(pointr,m) + 1
70 continue
c compute (wbp)Mc, (wbp)Mp, and (wbp)M(wbp)'.
call bmv(m,sy,wt,col,wbp,v,info)
if (info .ne. 0) return
wmc = ddot(col2,c,1,v,1)
wmp = ddot(col2,p,1,v,1)
wmw = ddot(col2,wbp,1,v,1)
c update p = p - dibp*wbp.
call daxpy(col2,-dibp,wbp,1,p,1)
c complete updating f1 and f2 while col > 0.
f1 = f1 + dibp*wmc
f2 = f2 + 2.0d0*dibp*wmp - dibp2*wmw
endif
f2 = max(epsmch*f2_org,f2)
if (nleft .gt. 0) then
dtm = -f1/f2
goto 777
c to repeat the loop for unsearched intervals.
else if(bnded) then
f1 = zero
f2 = zero
dtm = zero
else
dtm = -f1/f2
endif
c------------------- the end of the loop -------------------------------
888 continue
if (iprint .ge. 99) then
write (6,*)
write (6,*) 'GCP found in this segment'
write (6,4010) nseg,f1,f2
write (6,6010) dtm
endif
if (dtm .le. zero) dtm = zero
tsum = tsum + dtm
c Move free variables (i.e., the ones w/o breakpoints) and
c the variables whose breakpoints haven't been reached.
call daxpy(n,tsum,d,1,xcp,1)
999 continue
c Update c = c + dtm*p = W'(x^c - x)
c which will be used in computing r = Z'(B(x^c - x) + g).
if (col .gt. 0) call daxpy(col2,dtm,p,1,c,1)
if (iprint .gt. 100) write (6,1010) (xcp(i),i = 1,n)
if (iprint .ge. 99) write (6,2010)
1010 format ('Cauchy X = ',/,(4x,1p,6(1x,d11.4)))
2010 format (/,'---------------- exit CAUCHY----------------------',/)
3010 format (/,'---------------- CAUCHY entered-------------------')
4010 format ('Piece ',i3,' --f1, f2 at start point ',1p,2(1x,d11.4))
4011 format (/,'Piece ',i3,' --f1, f2 at start point ',
+ 1p,2(1x,d11.4))
5010 format ('Distance to the next break point = ',1p,d11.4)
6010 format ('Distance to the stationary point = ',1p,d11.4)
return
end
c====================== The end of cauchy ==============================
subroutine cmprlb(n, m, x, g, ws, wy, sy, wt, z, r, wa, index,
+ theta, col, head, nfree, cnstnd, info)
logical cnstnd
integer n, m, col, head, nfree, info, index(n)
double precision theta,
+ x(n), g(n), z(n), r(n), wa(4*m),
+ ws(n, m), wy(n, m), sy(m, m), wt(m, m)
c ************
c
c Subroutine cmprlb
c
c This subroutine computes r=-Z'B(xcp-xk)-Z'g by using
c wa(2m+1)=W'(xcp-x) from subroutine cauchy.
c
c Subprograms called:
c
c L-BFGS-B Library ... bmv.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i,j,k,pointr
double precision a1,a2
if (.not. cnstnd .and. col .gt. 0) then
do 26 i = 1, n
r(i) = -g(i)
26 continue
else
do 30 i = 1, nfree
k = index(i)
r(i) = -theta*(z(k) - x(k)) - g(k)
30 continue
call bmv(m,sy,wt,col,wa(2*m+1),wa(1),info)
if (info .ne. 0) then
info = -8
return
endif
pointr = head
do 34 j = 1, col
a1 = wa(j)
a2 = theta*wa(col + j)
do 32 i = 1, nfree
k = index(i)
r(i) = r(i) + wy(k,pointr)*a1 + ws(k,pointr)*a2
32 continue
pointr = mod(pointr,m) + 1
34 continue
endif
return
end
c======================= The end of cmprlb =============================
subroutine errclb(n, m, factr, l, u, nbd, task, info, k)
character*60 task
integer n, m, info, k, nbd(n)
double precision factr, l(n), u(n)
c ************
c
c Subroutine errclb
c
c This subroutine checks the validity of the input data.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i
double precision one,zero
parameter (one=1.0d0,zero=0.0d0)
c Check the input arguments for errors.
if (n .le. 0) task = 'ERROR: N .LE. 0'
if (m .le. 0) task = 'ERROR: M .LE. 0'
if (factr .lt. zero) task = 'ERROR: FACTR .LT. 0'
c Check the validity of the arrays nbd(i), u(i), and l(i).
do 10 i = 1, n
if (nbd(i) .lt. 0 .or. nbd(i) .gt. 3) then
c return
task = 'ERROR: INVALID NBD'
info = -6
k = i
endif
if (nbd(i) .eq. 2) then
if (l(i) .gt. u(i)) then
c return
task = 'ERROR: NO FEASIBLE SOLUTION'
info = -7
k = i
endif
endif
10 continue
return
end
c======================= The end of errclb =============================
subroutine formk(n, nsub, ind, nenter, ileave, indx2, iupdat,
+ updatd, wn, wn1, m, ws, wy, sy, theta, col,
+ head, info)
integer n, nsub, m, col, head, nenter, ileave, iupdat,
+ info, ind(n), indx2(n)
double precision theta, wn(2*m, 2*m), wn1(2*m, 2*m),
+ ws(n, m), wy(n, m), sy(m, m)
logical updatd
c ************
c
c Subroutine formk
c
c This subroutine forms the LEL^T factorization of the indefinite
c
c matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
c [L_a -R_z theta*S'AA'S ]
c where E = [-I 0]
c [ 0 I]
c The matrix K can be shown to be equal to the matrix M^[-1]N
c occurring in section 5.1 of [1], as well as to the matrix
c Mbar^[-1] Nbar in section 5.3.
c
c n is an integer variable.
c On entry n is the dimension of the problem.
c On exit n is unchanged.
c
c nsub is an integer variable
c On entry nsub is the number of subspace variables in free set.
c On exit nsub is not changed.
c
c ind is an integer array of dimension nsub.
c On entry ind specifies the indices of subspace variables.
c On exit ind is unchanged.
c
c nenter is an integer variable.
c On entry nenter is the number of variables entering the
c free set.
c On exit nenter is unchanged.
c
c ileave is an integer variable.
c On entry indx2(ileave),...,indx2(n) are the variables leaving
c the free set.
c On exit ileave is unchanged.
c
c indx2 is an integer array of dimension n.
c On entry indx2(1),...,indx2(nenter) are the variables entering
c the free set, while indx2(ileave),...,indx2(n) are the
c variables leaving the free set.
c On exit indx2 is unchanged.
c
c iupdat is an integer variable.
c On entry iupdat is the total number of BFGS updates made so far.
c On exit iupdat is unchanged.
c
c updatd is a logical variable.
c On entry 'updatd' is true if the L-BFGS matrix is updatd.
c On exit 'updatd' is unchanged.
c
c wn is a double precision array of dimension 2m x 2m.
c On entry wn is unspecified.
c On exit the upper triangle of wn stores the LEL^T factorization
c of the 2*col x 2*col indefinite matrix
c [-D -Y'ZZ'Y/theta L_a'-R_z' ]
c [L_a -R_z theta*S'AA'S ]
c
c wn1 is a double precision array of dimension 2m x 2m.
c On entry wn1 stores the lower triangular part of
c [Y' ZZ'Y L_a'+R_z']
c [L_a+R_z S'AA'S ]
c in the previous iteration.
c On exit wn1 stores the corresponding updated matrices.
c The purpose of wn1 is just to store these inner products
c so they can be easily updated and inserted into wn.
c
c m is an integer variable.
c On entry m is the maximum number of variable metric corrections
c used to define the limited memory matrix.
c On exit m is unchanged.
c
c ws, wy, sy, and wtyy are double precision arrays;
c theta is a double precision variable;
c col is an integer variable;
c head is an integer variable.
c On entry they store the information defining the
c limited memory BFGS matrix:
c ws(n,m) stores S, a set of s-vectors;
c wy(n,m) stores Y, a set of y-vectors;
c sy(m,m) stores S'Y;
c wtyy(m,m) stores the Cholesky factorization
c of (theta*S'S+LD^(-1)L')
c theta is the scaling factor specifying B_0 = theta I;
c col is the number of variable metric corrections stored;
c head is the location of the 1st s- (or y-) vector in S (or Y).
c On exit they are unchanged.
c
c info is an integer variable.
c On entry info is unspecified.
c On exit info = 0 for normal return;
c = -1 when the 1st Cholesky factorization failed;
c = -2 when the 2st Cholesky factorization failed.
c
c Subprograms called:
c
c Linpack ... dcopy, dpofa, dtrsl.
c
c
c References:
c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
c memory algorithm for bound constrained optimization'',
c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
c
c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: a
c limited memory FORTRAN code for solving bound constrained
c optimization problems'', Tech. Report, NAM-11, EECS Department,
c Northwestern University, 1994.
c
c (Postscript files of these papers are available via anonymous
c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer m2,ipntr,jpntr,iy,is,jy,js,is1,js1,k1,i,k,
+ col2,pbegin,pend,dbegin,dend,upcl
double precision ddot,temp1,temp2,temp3,temp4
double precision one,zero
parameter (one=1.0d0,zero=0.0d0)
c Form the lower triangular part of
c WN1 = [Y' ZZ'Y L_a'+R_z']
c [L_a+R_z S'AA'S ]
c where L_a is the strictly lower triangular part of S'AA'Y
c R_z is the upper triangular part of S'ZZ'Y.
if (updatd) then
if (iupdat .gt. m) then
c shift old part of WN1.
do 10 jy = 1, m - 1
js = m + jy
call dcopy(m-jy,wn1(jy+1,jy+1),1,wn1(jy,jy),1)
call dcopy(m-jy,wn1(js+1,js+1),1,wn1(js,js),1)
call dcopy(m-1,wn1(m+2,jy+1),1,wn1(m+1,jy),1)
10 continue
endif
c put new rows in blocks (1,1), (2,1) and (2,2).
pbegin = 1
pend = nsub
dbegin = nsub + 1
dend = n
iy = col
is = m + col
ipntr = head + col - 1
if (ipntr .gt. m) ipntr = ipntr - m
jpntr = head
do 20 jy = 1, col
js = m + jy
temp1 = zero
temp2 = zero
temp3 = zero
c compute element jy of row 'col' of Y'ZZ'Y
do 15 k = pbegin, pend
k1 = ind(k)
temp1 = temp1 + wy(k1,ipntr)*wy(k1,jpntr)
15 continue
c compute elements jy of row 'col' of L_a and S'AA'S
do 16 k = dbegin, dend
k1 = ind(k)
temp2 = temp2 + ws(k1,ipntr)*ws(k1,jpntr)
temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
16 continue
wn1(iy,jy) = temp1
wn1(is,js) = temp2
wn1(is,jy) = temp3
jpntr = mod(jpntr,m) + 1
20 continue
c put new column in block (2,1).
jy = col
jpntr = head + col - 1
if (jpntr .gt. m) jpntr = jpntr - m
ipntr = head
do 30 i = 1, col
is = m + i
temp3 = zero
c compute element i of column 'col' of R_z
do 25 k = pbegin, pend
k1 = ind(k)
temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
25 continue
ipntr = mod(ipntr,m) + 1
wn1(is,jy) = temp3
30 continue
upcl = col - 1
else
upcl = col
endif
c modify the old parts in blocks (1,1) and (2,2) due to changes
c in the set of free variables.
ipntr = head
do 45 iy = 1, upcl
is = m + iy
jpntr = head
do 40 jy = 1, iy
js = m + jy
temp1 = zero
temp2 = zero
temp3 = zero
temp4 = zero
do 35 k = 1, nenter
k1 = indx2(k)
temp1 = temp1 + wy(k1,ipntr)*wy(k1,jpntr)
temp2 = temp2 + ws(k1,ipntr)*ws(k1,jpntr)
35 continue
do 36 k = ileave, n
k1 = indx2(k)
temp3 = temp3 + wy(k1,ipntr)*wy(k1,jpntr)
temp4 = temp4 + ws(k1,ipntr)*ws(k1,jpntr)
36 continue
wn1(iy,jy) = wn1(iy,jy) + temp1 - temp3
wn1(is,js) = wn1(is,js) - temp2 + temp4
jpntr = mod(jpntr,m) + 1
40 continue
ipntr = mod(ipntr,m) + 1
45 continue
c modify the old parts in block (2,1).
ipntr = head
do 60 is = m + 1, m + upcl
jpntr = head
do 55 jy = 1, upcl
temp1 = zero
temp3 = zero
do 50 k = 1, nenter
k1 = indx2(k)
temp1 = temp1 + ws(k1,ipntr)*wy(k1,jpntr)
50 continue
do 51 k = ileave, n
k1 = indx2(k)
temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
51 continue
if (is .le. jy + m) then
wn1(is,jy) = wn1(is,jy) + temp1 - temp3
else
wn1(is,jy) = wn1(is,jy) - temp1 + temp3
endif
jpntr = mod(jpntr,m) + 1
55 continue
ipntr = mod(ipntr,m) + 1
60 continue
c Form the upper triangle of WN = [D+Y' ZZ'Y/theta -L_a'+R_z' ]
c [-L_a +R_z S'AA'S*theta]
m2 = 2*m
do 70 iy = 1, col
is = col + iy
is1 = m + iy
do 65 jy = 1, iy
js = col + jy
js1 = m + jy
wn(jy,iy) = wn1(iy,jy)/theta
wn(js,is) = wn1(is1,js1)*theta
65 continue
do 66 jy = 1, iy - 1
wn(jy,is) = -wn1(is1,jy)
66 continue
do 67 jy = iy, col
wn(jy,is) = wn1(is1,jy)
67 continue
wn(iy,iy) = wn(iy,iy) + sy(iy,iy)
70 continue
c Form the upper triangle of WN= [ LL' L^-1(-L_a'+R_z')]
c [(-L_a +R_z)L'^-1 S'AA'S*theta ]
c first Cholesky factor (1,1) block of wn to get LL'
c with L' stored in the upper triangle of wn.
call dpofa(wn,m2,col,info)
if (info .ne. 0) then
info = -1
return
endif
c then form L^-1(-L_a'+R_z') in the (1,2) block.
col2 = 2*col
do 71 js = col+1 ,col2
call dtrsl(wn,m2,col,wn(1,js),11,info)
71 continue
c Form S'AA'S*theta + (L^-1(-L_a'+R_z'))'L^-1(-L_a'+R_z') in the
c upper triangle of (2,2) block of wn.
do 72 is = col+1, col2
do 74 js = is, col2
wn(is,js) = wn(is,js) + ddot(col,wn(1,is),1,wn(1,js),1)
74 continue
72 continue
c Cholesky factorization of (2,2) block of wn.
call dpofa(wn(col+1,col+1),m2,col,info)
if (info .ne. 0) then
info = -2
return
endif
return
end
c======================= The end of formk ==============================
subroutine formt(m, wt, sy, ss, col, theta, info)
integer m, col, info
double precision theta, wt(m, m), sy(m, m), ss(m, m)
c ************
c
c Subroutine formt
c
c This subroutine forms the upper half of the pos. def. and symm.
c T = theta*SS + L*D^(-1)*L', stores T in the upper triangle
c of the array wt, and performs the Cholesky factorization of T
c to produce J*J', with J' stored in the upper triangle of wt.
c
c Subprograms called:
c
c Linpack ... dpofa.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i,j,k,k1
double precision ddum
double precision zero
parameter (zero=0.0d0)
c Form the upper half of T = theta*SS + L*D^(-1)*L',
c store T in the upper triangle of the array wt.
do 52 j = 1, col
wt(1,j) = theta*ss(1,j)
52 continue
do 55 i = 2, col
do 54 j = i, col
k1 = min(i,j) - 1
ddum = zero
do 53 k = 1, k1
ddum = ddum + sy(i,k)*sy(j,k)/sy(k,k)
53 continue
wt(i,j) = ddum + theta*ss(i,j)
54 continue
55 continue
c Cholesky factorize T to J*J' with
c J' stored in the upper triangle of wt.
call dpofa(wt,m,col,info)
if (info .ne. 0) then
info = -3
endif
return
end
c======================= The end of formt ==============================
subroutine freev(n, nfree, index, nenter, ileave, indx2,
+ iwhere, wrk, updatd, cnstnd, iprint, iter)
integer n, nfree, nenter, ileave, iprint, iter,
+ index(n), indx2(n), iwhere(n)
logical wrk, updatd, cnstnd
c ************
c
c Subroutine freev
c
c This subroutine counts the entering and leaving variables when
c iter > 0, and finds the index set of free and active variables
c at the GCP.
c
c cnstnd is a logical variable indicating whether bounds are present
c
c index is an integer array of dimension n
c for i=1,...,nfree, index(i) are the indices of free variables
c for i=nfree+1,...,n, index(i) are the indices of bound variables
c On entry after the first iteration, index gives
c the free variables at the previous iteration.
c On exit it gives the free variables based on the determination
c in cauchy using the array iwhere.
c
c indx2 is an integer array of dimension n
c On entry indx2 is unspecified.
c On exit with iter>0, indx2 indicates which variables
c have changed status since the previous iteration.
c For i= 1,...,nenter, indx2(i) have changed from bound to free.
c For i= ileave+1,...,n, indx2(i) have changed from free to bound.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer iact,i,k
nenter = 0
ileave = n + 1
if (iter .gt. 0 .and. cnstnd) then
c count the entering and leaving variables.
do 20 i = 1, nfree
k = index(i)
c write(6,*) ' k = index(i) ', k
c write(6,*) ' index = ', i
if (iwhere(k) .gt. 0) then
ileave = ileave - 1
indx2(ileave) = k
if (iprint .ge. 100) write (6,*)
+ 'Variable ',k,' leaves the set of free variables'
endif
20 continue
do 22 i = 1 + nfree, n
k = index(i)
if (iwhere(k) .le. 0) then
nenter = nenter + 1
indx2(nenter) = k
if (iprint .ge. 100) write (6,*)
+ 'Variable ',k,' enters the set of free variables'
endif
22 continue
if (iprint .ge. 99) write (6,*)
+ n+1-ileave,' variables leave; ',nenter,' variables enter'
endif
wrk = (ileave .lt. n+1) .or. (nenter .gt. 0) .or. updatd
c Find the index set of free and active variables at the GCP.
nfree = 0
iact = n + 1
do 24 i = 1, n
if (iwhere(i) .le. 0) then
nfree = nfree + 1
index(nfree) = i
else
iact = iact - 1
index(iact) = i
endif
24 continue
if (iprint .ge. 99) write (6,*)
+ nfree,' variables are free at GCP ',iter + 1
return
end
c======================= The end of freev ==============================
subroutine hpsolb(n, t, iorder, iheap)
integer iheap, n, iorder(n)
double precision t(n)
c ************
c
c Subroutine hpsolb
c
c This subroutine sorts out the least element of t, and puts the
c remaining elements of t in a heap.
c
c n is an integer variable.
c On entry n is the dimension of the arrays t and iorder.
c On exit n is unchanged.
c
c t is a double precision array of dimension n.
c On entry t stores the elements to be sorted,
c On exit t(n) stores the least elements of t, and t(1) to t(n-1)
c stores the remaining elements in the form of a heap.
c
c iorder is an integer array of dimension n.
c On entry iorder(i) is the index of t(i).
c On exit iorder(i) is still the index of t(i), but iorder may be
c permuted in accordance with t.
c
c iheap is an integer variable specifying the task.
c On entry iheap should be set as follows:
c iheap .eq. 0 if t(1) to t(n) is not in the form of a heap,
c iheap .ne. 0 if otherwise.
c On exit iheap is unchanged.
c
c
c References:
c Algorithm 232 of CACM (J. W. J. Williams): HEAPSORT.
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c ************
integer i,j,k,indxin,indxou
double precision ddum,out
if (iheap .eq. 0) then
c Rearrange the elements t(1) to t(n) to form a heap.
do 20 k = 2, n
ddum = t(k)
indxin = iorder(k)
c Add ddum to the heap.
i = k
10 continue
if (i.gt.1) then
j = i/2
if (ddum .lt. t(j)) then
t(i) = t(j)
iorder(i) = iorder(j)
i = j
goto 10
endif
endif
t(i) = ddum
iorder(i) = indxin
20 continue
endif
c Assign to 'out' the value of t(1), the least member of the heap,
c and rearrange the remaining members to form a heap as
c elements 1 to n-1 of t.
if (n .gt. 1) then
i = 1
out = t(1)
indxou = iorder(1)
ddum = t(n)
indxin = iorder(n)
c Restore the heap
30 continue
j = i+i
if (j .le. n-1) then
if (t(j+1) .lt. t(j)) j = j+1
if (t(j) .lt. ddum ) then
t(i) = t(j)
iorder(i) = iorder(j)
i = j
goto 30
endif
endif
t(i) = ddum
iorder(i) = indxin
c Put the least member in t(n).
t(n) = out
iorder(n) = indxou
endif
return
end
c====================== The end of hpsolb ==============================
subroutine lnsrlb(n, l, u, nbd, x, f, fold, gd, gdold, g, d, r, t,
+ z, stp, dnorm, dtd, xstep, stpmx, iter, ifun,
+ iback, nfgv, info, task, boxed, cnstnd, csave,
+ isave, dsave, iprint)
character*60 task, csave
logical boxed, cnstnd
integer n, iter, ifun, iback, nfgv, info,
+ nbd(n), isave(2), iprint
double precision f, fold, gd, gdold, stp, dnorm, dtd, xstep,
+ stpmx, x(n), l(n), u(n), g(n), d(n), r(n), t(n),
+ z(n), dsave(13)
c **********
c
c Subroutine lnsrlb
c
c This subroutine calls subroutine dcsrch from the Minpack2 library
c to perform the line search. Subroutine dscrch is safeguarded so
c that all trial points lie within the feasible region.
c
c Subprograms called:
c
c Minpack2 Library ... dcsrch.
c
c Linpack ... dtrsl, ddot.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c **********
integer i
double precision ddot,a1,a2
double precision one,zero,big
parameter (one=1.0d0,zero=0.0d0,big=1.0d+10)
double precision ftol,gtol,xtol
parameter (ftol=1.0d-3,gtol=0.9d0,xtol=0.1d0)
if (task(1:5) .eq. 'FG_LN') goto 556
dtd = ddot(n,d,1,d,1)
dnorm = sqrt(dtd)
c Determine the maximum step length.
stpmx = big
if (cnstnd) then
if (iter .eq. 0) then
stpmx = one
else
do 43 i = 1, n
a1 = d(i)
if (nbd(i) .ne. 0) then
if (a1 .lt. zero .and. nbd(i) .le. 2) then
a2 = l(i) - x(i)
if (a2 .ge. zero) then
stpmx = zero
else if (a1*stpmx .lt. a2) then
stpmx = a2/a1
endif
else if (a1 .gt. zero .and. nbd(i) .ge. 2) then
a2 = u(i) - x(i)
if (a2 .le. zero) then
stpmx = zero
else if (a1*stpmx .gt. a2) then
stpmx = a2/a1
endif
endif
endif
43 continue
endif
endif
if (iter .eq. 0 .and. .not. boxed) then
stp = min(one/dnorm, stpmx)
else
stp = one
endif
call dcopy(n,x,1,t,1)
call dcopy(n,g,1,r,1)
fold = f
ifun = 0
iback = 0
csave = 'START'
556 continue
gd = ddot(n,g,1,d,1)
if (ifun .eq. 0) then
gdold=gd
if (gd .ge. zero) then
c the directional derivative >=0.
c Line search is impossible.
if (iprint .ge. 0) then
write(0,*)' ascent direction in projection gd = ', gd
endif
info = -4
return
endif
endif
call dcsrch(f,gd,stp,ftol,gtol,xtol,zero,stpmx,csave,isave,dsave)
xstep = stp*dnorm
if (csave(1:4) .ne. 'CONV' .and. csave(1:4) .ne. 'WARN') then
task = 'FG_LNSRCH'
ifun = ifun + 1
nfgv = nfgv + 1
iback = ifun - 1
if (stp .eq. one) then
call dcopy(n,z,1,x,1)
else
do 41 i = 1, n
x(i) = stp*d(i) + t(i)
41 continue
endif
else
task = 'NEW_X'
endif
return
end
c======================= The end of lnsrlb =============================
subroutine matupd(n, m, ws, wy, sy, ss, d, r, itail,
+ iupdat, col, head, theta, rr, dr, stp, dtd)
integer n, m, itail, iupdat, col, head
double precision theta, rr, dr, stp, dtd, d(n), r(n),
+ ws(n, m), wy(n, m), sy(m, m), ss(m, m)
c ************
c
c Subroutine matupd
c
c This subroutine updates matrices WS and WY, and forms the
c middle matrix in B.
c
c Subprograms called:
c
c Linpack ... dcopy, ddot.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer j,pointr
double precision ddot
double precision one
parameter (one=1.0d0)
c Set pointers for matrices WS and WY.
if (iupdat .le. m) then
col = iupdat
itail = mod(head+iupdat-2,m) + 1
else
itail = mod(itail,m) + 1
head = mod(head,m) + 1
endif
c Update matrices WS and WY.
call dcopy(n,d,1,ws(1,itail),1)
call dcopy(n,r,1,wy(1,itail),1)
c Set theta=yy/ys.
theta = rr/dr
c Form the middle matrix in B.
c update the upper triangle of SS,
c and the lower triangle of SY:
if (iupdat .gt. m) then
c move old information
do 50 j = 1, col - 1
call dcopy(j,ss(2,j+1),1,ss(1,j),1)
call dcopy(col-j,sy(j+1,j+1),1,sy(j,j),1)
50 continue
endif
c add new information: the last row of SY
c and the last column of SS:
pointr = head
do 51 j = 1, col - 1
sy(col,j) = ddot(n,d,1,wy(1,pointr),1)
ss(j,col) = ddot(n,ws(1,pointr),1,d,1)
pointr = mod(pointr,m) + 1
51 continue
if (stp .eq. one) then
ss(col,col) = dtd
else
ss(col,col) = stp*stp*dtd
endif
sy(col,col) = dr
return
end
c======================= The end of matupd =============================
subroutine prn1lb(n, m, l, u, x, iprint, epsmch)
integer n, m, iprint
double precision epsmch, x(n), l(n), u(n)
c ************
c
c Subroutine prn1lb
c
c This subroutine prints the input data, initial point, upper and
c lower bounds of each variable, machine precision, as well as
c the headings of the output.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i
if (iprint .ge. 0) then
write (6,7001) epsmch
write (6,*) 'N = ',n,' M = ',m
if (iprint .ge. 1) then
if (iprint .gt. 100) then
write (6,1004) 'L =',(l(i),i = 1,n)
write (6,1004) 'X0 =',(x(i),i = 1,n)
write (6,1004) 'U =',(u(i),i = 1,n)
endif
endif
endif
1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2001 format ('RUNNING THE L-BFGS-B CODE',/,/,
+ 'it = iteration number',/,
+ 'nf = number of function evaluations',/,
+ 'nseg = number of segments explored during the Cauchy search',/,
+ 'nact = number of active bounds at the generalized Cauchy point'
+ ,/,
+ 'sub = manner in which the subspace minimization terminated:'
+ ,/,' con = converged, bnd = a bound was reached',/,
+ 'itls = number of iterations performed in the line search',/,
+ 'stepl = step length used',/,
+ 'tstep = norm of the displacement (total step)',/,
+ 'projg = norm of the projected gradient',/,
+ 'f = function value',/,/,
+ ' * * *',/,/,
+ 'Machine precision =',1p,d10.3)
7001 format ('RUNNING THE L-BFGS-B CODE',/,/,
+ ' * * *',/,/,
+ 'Machine precision =',1p,d10.3)
9001 format (/,3x,'it',3x,'nf',2x,'nseg',2x,'nact',2x,'sub',2x,'itls',
+ 2x,'stepl',4x,'tstep',5x,'projg',8x,'f')
return
end
c======================= The end of prn1lb =============================
subroutine prn2lb(n, x, f, g, iprint, iter, nfgv, nact,
+ sbgnrm, nseg, word, iword, iback, stp, xstep)
character*3 word
integer n, iprint, iter, nfgv, nact, nseg,
+ iword, iback
double precision f, sbgnrm, stp, xstep, x(n), g(n)
c ************
c
c Subroutine prn2lb
c
c This subroutine prints out new information after a successful
c line search.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i,imod
c 'word' records the status of subspace solutions.
if (iword .eq. 0) then
c the subspace minimization converged.
word = 'con'
else if (iword .eq. 1) then
c the subspace minimization stopped at a bound.
word = 'bnd'
else if (iword .eq. 5) then
c the truncated Newton step has been used.
word = 'TNT'
else
word = '---'
endif
if (iprint .ge. 99) then
write (6,*) 'LINE SEARCH',iback,' times; norm of step = ',xstep
write (6,2001) iter,f,sbgnrm
if (iprint .gt. 100) then
write (6,1004) 'X =',(x(i), i = 1, n)
write (6,1004) 'G =',(g(i), i = 1, n)
endif
else if (iprint .gt. 0) then
imod = mod(iter,iprint)
if (imod .eq. 0) write (6,2001) iter,f,sbgnrm
endif
1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2001 format
+ (/,'At iterate',i5,4x,'f= ',1p,d12.5,4x,'|proj g|= ',1p,d12.5)
3001 format(2(1x,i4),2(1x,i5),2x,a3,1x,i4,1p,2(2x,d7.1),1p,2(1x,d10.3))
return
end
c======================= The end of prn2lb =============================
subroutine prn3lb(n, x, f, task, iprint, info,
+ iter, nfgv, nintol, nskip, nact, sbgnrm,
+ time, nseg, word, iback, stp, xstep, k,
+ cachyt, sbtime, lnscht)
character*60 task
character*3 word
integer n, iprint, info, iter, nfgv, nintol,
+ nskip, nact, nseg, iback, k
double precision f, sbgnrm, time, stp, xstep, cachyt, sbtime,
+ lnscht, x(n)
c ************
c
c Subroutine prn3lb
c
c This subroutine prints out information when either a built-in
c convergence test is satisfied or when an error message is
c generated.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i
if (task(1:5) .eq. 'ERROR') goto 999
if (iprint .ge. 0) then
write (6,3003)
write (6,3004)
write(6,3005) n,iter,nfgv,nintol,nskip,nact,sbgnrm,f
if (iprint .ge. 100) then
write (6,1004) 'X =',(x(i),i = 1,n)
endif
if (iprint .ge. 1) write (6,*) ' F =',f
endif
999 continue
if (iprint .ge. 0) then
write (6,3009) task
if (info .ne. 0) then
if (info .eq. -1) write (0,9011)
if (info .eq. -2) write (0,9012)
if (info .eq. -3) write (0,9013)
if (info .eq. -4) write (0,9014)
if (info .eq. -5) write (0,9015)
if (info .eq. -6) write (0,*)' Input nbd(',k,') is invalid.'
if (info .eq. -7)
+ write (6,*)' l(',k,') > u(',k,'). No feasible solution.'
if (info .eq. -8) write (0,9018)
if (info .eq. -9) write (0,9019)
endif
if (iprint .ge. 1) write (6,3007) cachyt,sbtime,lnscht
write (6,3008) time
endif
1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
3002 format(2(1x,i4),2(1x,i5),2x,a3,1x,i4,1p,2(2x,d7.1),6x,'-',10x,'-')
3003 format (/,
+ ' * * *',/,/,
+ 'Tit = total number of iterations',/,
+ 'Tnf = total number of function evaluations',/,
+ 'Tnint = total number of segments explored during',
+ ' Cauchy searches',/,
+ 'Skip = number of BFGS updates skipped',/,
+ 'Nact = number of active bounds at final generalized',
+ ' Cauchy point',/,
+ 'Projg = norm of the final projected gradient',/,
+ 'F = final function value',/,/,
+ ' * * *')
3004 format (/,3x,'N',4x,'Tit',5x,'Tnf',2x,'Tnint',2x,
+ 'Skip',2x,'Nact',5x,'Projg',8x,'F')
3005 format (i5,2(1x,i6),(1x,i6),(2x,i4),(1x,i5),1p,2(2x,d10.3))
3007 format (/,' Cauchy time',1p,e10.3,' seconds.',/
+ ' Subspace minimization time',1p,e10.3,' seconds.',/
+ ' Line search time',1p,e10.3,' seconds.')
3008 format (/,' Total User time',1p,e10.3,' seconds.',/)
3009 format (/,a60)
9011 format (/,
+' Matrix in 1st Cholesky factorization in formk is not Pos. Def.')
9012 format (/,
+' Matrix in 2st Cholesky factorization in formk is not Pos. Def.')
9013 format (/,
+' Matrix in the Cholesky factorization in formt is not Pos. Def.')
9014 format (/,
+' Derivative >= 0, backtracking line search impossible.',/,
+' Previous x, f and g restored.',/,
+' Possible causes: 1 error in function or gradient evaluation;',/,
+' 2 rounding errors dominate computation.')
9015 format (/,
+' Warning: more than 10 function and gradient',/,
+' evaluations in the last line search. Termination',/,
+' may possibly be caused by a bad search direction.')
9018 format (/,' The triangular system is singular.')
9019 format (/,
+' Line search cannot locate an adequate point after 20 function',/
+,' and gradient evaluations. Previous x, f and g restored.',/,
+' Possible causes: 1 error in function or gradient evaluation;',/,
+' 2 rounding error dominate computation.')
return
end
c======================= The end of prn3lb =============================
subroutine projgr(n, l, u, nbd, x, g, sbgnrm)
integer n, nbd(n)
double precision sbgnrm, x(n), l(n), u(n), g(n)
c ************
c
c Subroutine projgr
c
c This subroutine computes the infinity norm of the projected
c gradient.
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer i
double precision gi
double precision one,zero
parameter (one=1.0d0,zero=0.0d0)
sbgnrm = zero
do 15 i = 1, n
gi = g(i)
if (nbd(i) .ne. 0) then
if (gi .lt. zero) then
if (nbd(i) .ge. 2) gi = max((x(i)-u(i)),gi)
else
if (nbd(i) .le. 2) gi = min((x(i)-l(i)),gi)
endif
endif
sbgnrm = max(sbgnrm,abs(gi))
15 continue
return
end
c======================= The end of projgr =============================
subroutine subsm ( n, m, nsub, ind, l, u, nbd, x, d, xp, ws, wy,
+ theta, xx, gg,
+ col, head, iword, wv, wn, iprint, info )
implicit none
integer n, m, nsub, col, head, iword, iprint, info,
+ ind(nsub), nbd(n)
double precision theta,
+ l(n), u(n), x(n), d(n), xp(n), xx(n), gg(n),
+ ws(n, m), wy(n, m),
+ wv(2*m), wn(2*m, 2*m)
c **********************************************************************
c
c This routine contains the major changes in the updated version.
c The changes are described in the accompanying paper
c
c Jose Luis Morales, Jorge Nocedal
c "Remark On Algorithm 788: L-BFGS-B: Fortran Subroutines for Large-Scale
c Bound Constrained Optimization". Decemmber 27, 2010.
c
c J.L. Morales Departamento de Matematicas,
c Instituto Tecnologico Autonomo de Mexico
c Mexico D.F.
c
c J, Nocedal Department of Electrical Engineering and
c Computer Science.
c Northwestern University. Evanston, IL. USA
c
c January 17, 2011
c
c **********************************************************************
c
c
c Subroutine subsm
c
c Given xcp, l, u, r, an index set that specifies
c the active set at xcp, and an l-BFGS matrix B
c (in terms of WY, WS, SY, WT, head, col, and theta),
c this subroutine computes an approximate solution
c of the subspace problem
c
c (P) min Q(x) = r'(x-xcp) + 1/2 (x-xcp)' B (x-xcp)
c
c subject to l<=x<=u
c x_i=xcp_i for all i in A(xcp)
c
c along the subspace unconstrained Newton direction
c
c d = -(Z'BZ)^(-1) r.
c
c The formula for the Newton direction, given the L-BFGS matrix
c and the Sherman-Morrison formula, is
c
c d = (1/theta)r + (1/theta*2) Z'WK^(-1)W'Z r.
c
c where
c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
c [L_a -R_z theta*S'AA'S ]
c
c Note that this procedure for computing d differs
c from that described in [1]. One can show that the matrix K is
c equal to the matrix M^[-1]N in that paper.
c
c n is an integer variable.
c On entry n is the dimension of the problem.
c On exit n is unchanged.
c
c m is an integer variable.
c On entry m is the maximum number of variable metric corrections
c used to define the limited memory matrix.
c On exit m is unchanged.
c
c nsub is an integer variable.
c On entry nsub is the number of free variables.
c On exit nsub is unchanged.
c
c ind is an integer array of dimension nsub.
c On entry ind specifies the coordinate indices of free variables.
c On exit ind is unchanged.
c
c l is a double precision array of dimension n.
c On entry l is the lower bound of x.
c On exit l is unchanged.
c
c u is a double precision array of dimension n.
c On entry u is the upper bound of x.
c On exit u is unchanged.
c
c nbd is a integer array of dimension n.
c On entry nbd represents the type of bounds imposed on the
c variables, and must be specified as follows:
c nbd(i)=0 if x(i) is unbounded,
c 1 if x(i) has only a lower bound,
c 2 if x(i) has both lower and upper bounds, and
c 3 if x(i) has only an upper bound.
c On exit nbd is unchanged.
c
c x is a double precision array of dimension n.
c On entry x specifies the Cauchy point xcp.
c On exit x(i) is the minimizer of Q over the subspace of
c free variables.
c
c d is a double precision array of dimension n.
c On entry d is the reduced gradient of Q at xcp.
c On exit d is the Newton direction of Q.
c
c xp is a double precision array of dimension n.
c used to safeguard the projected Newton direction
c
c xx is a double precision array of dimension n
c On entry it holds the current iterate
c On output it is unchanged
c gg is a double precision array of dimension n
c On entry it holds the gradient at the current iterate
c On output it is unchanged
c
c ws and wy are double precision arrays;
c theta is a double precision variable;
c col is an integer variable;
c head is an integer variable.
c On entry they store the information defining the
c limited memory BFGS matrix:
c ws(n,m) stores S, a set of s-vectors;
c wy(n,m) stores Y, a set of y-vectors;
c theta is the scaling factor specifying B_0 = theta I;
c col is the number of variable metric corrections stored;
c head is the location of the 1st s- (or y-) vector in S (or Y).
c On exit they are unchanged.
c
c iword is an integer variable.
c On entry iword is unspecified.
c On exit iword specifies the status of the subspace solution.
c iword = 0 if the solution is in the box,
c 1 if some bound is encountered.
c
c wv is a double precision working array of dimension 2m.
c
c wn is a double precision array of dimension 2m x 2m.
c On entry the upper triangle of wn stores the LEL^T factorization
c of the indefinite matrix
c
c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
c [L_a -R_z theta*S'AA'S ]
c where E = [-I 0]
c [ 0 I]
c On exit wn is unchanged.
c
c iprint is an INTEGER variable that must be set by the user.
c It controls the frequency and type of output generated:
c iprint<0 no output is generated;
c iprint=0 print only one line at the last iteration;
c 0<iprint<99 print also f and |proj g| every iprint iterations;
c iprint=99 print details of every iteration except n-vectors;
c iprint=100 print also the changes of active set and final x;
c iprint>100 print details of every iteration including x and g;
c
c
c info is an integer variable.
c On entry info is unspecified.
c On exit info = 0 for normal return,
c = nonzero for abnormal return
c when the matrix K is ill-conditioned.
c
c Subprograms called:
c
c Linpack dtrsl.
c
c
c References:
c
c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
c memory algorithm for bound constrained optimization'',
c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
c
c
c
c * * *
c
c NEOS, November 1994. (Latest revision June 1996.)
c Optimization Technology Center.
c Argonne National Laboratory and Northwestern University.
c Written by
c Ciyou Zhu
c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
c
c
c ************
integer pointr,m2,col2,ibd,jy,js,i,j,k
double precision alpha, xk, dk, temp1, temp2
double precision one,zero
parameter (one=1.0d0,zero=0.0d0)
c
double precision dd_p
if (nsub .le. 0) return
if (iprint .ge. 99) write (6,1001)
c Compute wv = W'Zd.
pointr = head
do 20 i = 1, col
temp1 = zero
temp2 = zero
do 10 j = 1, nsub
k = ind(j)
temp1 = temp1 + wy(k,pointr)*d(j)
temp2 = temp2 + ws(k,pointr)*d(j)
10 continue
wv(i) = temp1
wv(col + i) = theta*temp2
pointr = mod(pointr,m) + 1
20 continue
c Compute wv:=K^(-1)wv.
m2 = 2*m
col2 = 2*col
call dtrsl(wn,m2,col2,wv,11,info)
if (info .ne. 0) return
do 25 i = 1, col
wv(i) = -wv(i)
25 continue
call dtrsl(wn,m2,col2,wv,01,info)
if (info .ne. 0) return
c Compute d = (1/theta)d + (1/theta**2)Z'W wv.
pointr = head
do 40 jy = 1, col
js = col + jy
do 30 i = 1, nsub
k = ind(i)
d(i) = d(i) + wy(k,pointr)*wv(jy)/theta
+ + ws(k,pointr)*wv(js)
30 continue
pointr = mod(pointr,m) + 1
40 continue
call dscal( nsub, one/theta, d, 1 )
c
c-----------------------------------------------------------------
c Let us try the projection, d is the Newton direction
iword = 0
call dcopy ( n, x, 1, xp, 1 )
c
do 50 i=1, nsub
k = ind(i)
dk = d(i)
xk = x(k)
if ( nbd(k) .ne. 0 ) then
c
if ( nbd(k).eq.1 ) then ! lower bounds only
x(k) = max( l(k), xk + dk )
if ( x(k).eq.l(k) ) iword = 1
else
c
if ( nbd(k).eq.2 ) then ! upper and lower bounds
xk = max( l(k), xk + dk )
x(k) = min( u(k), xk )
if ( x(k).eq.l(k) .or. x(k).eq.u(k) ) iword = 1
else
c
if ( nbd(k).eq.3 ) then ! upper bounds only
x(k) = min( u(k), xk + dk )
if ( x(k).eq.u(k) ) iword = 1
end if
end if
end if
c
else ! free variables
x(k) = xk + dk
end if
50 continue
c
if ( iword.eq.0 ) then
go to 911
end if
c
c check sign of the directional derivative
c
dd_p = zero
do 55 i=1, n
dd_p = dd_p + (x(i) - xx(i))*gg(i)
55 continue
if ( dd_p .gt.zero ) then
call dcopy( n, xp, 1, x, 1 )
if (iprint .ge. 0) then
write(6,*) ' Positive dir derivative in projection '
write(6,*) ' Using the backtracking step '
endif
else
go to 911
endif
c
c-----------------------------------------------------------------
c
alpha = one
temp1 = alpha
ibd = 0
do 60 i = 1, nsub
k = ind(i)
dk = d(i)
if (nbd(k) .ne. 0) then
if (dk .lt. zero .and. nbd(k) .le. 2) then
temp2 = l(k) - x(k)
if (temp2 .ge. zero) then
temp1 = zero
else if (dk*alpha .lt. temp2) then
temp1 = temp2/dk
endif
else if (dk .gt. zero .and. nbd(k) .ge. 2) then
temp2 = u(k) - x(k)
if (temp2 .le. zero) then
temp1 = zero
else if (dk*alpha .gt. temp2) then
temp1 = temp2/dk
endif
endif
if (temp1 .lt. alpha) then
alpha = temp1
ibd = i
endif
endif
60 continue
if (alpha .lt. one) then
dk = d(ibd)
k = ind(ibd)
if (dk .gt. zero) then
x(k) = u(k)
d(ibd) = zero
else if (dk .lt. zero) then
x(k) = l(k)
d(ibd) = zero
endif
endif
do 70 i = 1, nsub
k = ind(i)
x(k) = x(k) + alpha*d(i)
70 continue
cccccc
911 continue
if (iprint .ge. 99) write (6,1004)
1001 format (/,'----------------SUBSM entered-----------------',/)
1004 format (/,'----------------exit SUBSM --------------------',/)
return
end
c====================== The end of subsm ===============================
subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
+ task,isave,dsave)
character*(*) task
integer isave(2)
double precision f,g,stp,ftol,gtol,xtol,stpmin,stpmax
double precision dsave(13)
c **********
c
c Subroutine dcsrch
c
c This subroutine finds a step that satisfies a sufficient
c decrease condition and a curvature condition.
c
c Each call of the subroutine updates an interval with
c endpoints stx and sty. The interval is initially chosen
c so that it contains a minimizer of the modified function
c
c psi(stp) = f(stp) - f(0) - ftol*stp*f'(0).
c
c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
c interval is chosen so that it contains a minimizer of f.
c
c The algorithm is designed to find a step that satisfies
c the sufficient decrease condition
c
c f(stp) <= f(0) + ftol*stp*f'(0),
c
c and the curvature condition
c
c abs(f'(stp)) <= gtol*abs(f'(0)).
c
c If ftol is less than gtol and if, for example, the function
c is bounded below, then there is always a step which satisfies
c both conditions.
c
c If no step can be found that satisfies both conditions, then
c the algorithm stops with a warning. In this case stp only
c satisfies the sufficient decrease condition.
c
c A typical invocation of dcsrch has the following outline:
c
c task = 'START'
c 10 continue
c call dcsrch( ... )
c if (task .eq. 'FG') then
c Evaluate the function and the gradient at stp
c goto 10
c end if
c
c NOTE: The user must no alter work arrays between calls.
c
c The subroutine statement is
c
c subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
c task,isave,dsave)
c where
c
c f is a double precision variable.
c On initial entry f is the value of the function at 0.
c On subsequent entries f is the value of the
c function at stp.
c On exit f is the value of the function at stp.
c
c g is a double precision variable.
c On initial entry g is the derivative of the function at 0.
c On subsequent entries g is the derivative of the
c function at stp.
c On exit g is the derivative of the function at stp.
c
c stp is a double precision variable.
c On entry stp is the current estimate of a satisfactory
c step. On initial entry, a positive initial estimate
c must be provided.
c On exit stp is the current estimate of a satisfactory step
c if task = 'FG'. If task = 'CONV' then stp satisfies
c the sufficient decrease and curvature condition.
c
c ftol is a double precision variable.
c On entry ftol specifies a nonnegative tolerance for the
c sufficient decrease condition.
c On exit ftol is unchanged.
c
c gtol is a double precision variable.
c On entry gtol specifies a nonnegative tolerance for the
c curvature condition.
c On exit gtol is unchanged.
c
c xtol is a double precision variable.
c On entry xtol specifies a nonnegative relative tolerance
c for an acceptable step. The subroutine exits with a
c warning if the relative difference between sty and stx
c is less than xtol.
c On exit xtol is unchanged.
c
c stpmin is a double precision variable.
c On entry stpmin is a nonnegative lower bound for the step.
c On exit stpmin is unchanged.
c
c stpmax is a double precision variable.
c On entry stpmax is a nonnegative upper bound for the step.
c On exit stpmax is unchanged.
c
c task is a character variable of length at least 60.
c On initial entry task must be set to 'START'.
c On exit task indicates the required action:
c
c If task(1:2) = 'FG' then evaluate the function and
c derivative at stp and call dcsrch again.
c
c If task(1:4) = 'CONV' then the search is successful.
c
c If task(1:4) = 'WARN' then the subroutine is not able
c to satisfy the convergence conditions. The exit value of
c stp contains the best point found during the search.
c
c If task(1:5) = 'ERROR' then there is an error in the
c input arguments.
c
c On exit with convergence, a warning or an error, the
c variable task contains additional information.
c
c isave is an integer work array of dimension 2.
c
c dsave is a double precision work array of dimension 13.
c
c Subprograms called
c
c MINPACK-2 ... dcstep
c
c MINPACK-1 Project. June 1983.
c Argonne National Laboratory.
c Jorge J. More' and David J. Thuente.
c
c MINPACK-2 Project. October 1993.
c Argonne National Laboratory and University of Minnesota.
c Brett M. Averick, Richard G. Carter, and Jorge J. More'.
c
c **********
double precision zero,p5,p66
parameter(zero=0.0d0,p5=0.5d0,p66=0.66d0)
double precision xtrapl,xtrapu
parameter(xtrapl=1.1d0,xtrapu=4.0d0)
logical brackt
integer stage
double precision finit,ftest,fm,fx,fxm,fy,fym,ginit,gtest,
+ gm,gx,gxm,gy,gym,stx,sty,stmin,stmax,width,width1
c Initialization block.
if (task(1:5) .eq. 'START') then
c Check the input arguments for errors.
if (stp .lt. stpmin) task = 'ERROR: STP .LT. STPMIN'
if (stp .gt. stpmax) task = 'ERROR: STP .GT. STPMAX'
if (g .ge. zero) task = 'ERROR: INITIAL G .GE. ZERO'
if (ftol .lt. zero) task = 'ERROR: FTOL .LT. ZERO'
if (gtol .lt. zero) task = 'ERROR: GTOL .LT. ZERO'
if (xtol .lt. zero) task = 'ERROR: XTOL .LT. ZERO'
if (stpmin .lt. zero) task = 'ERROR: STPMIN .LT. ZERO'
if (stpmax .lt. stpmin) task = 'ERROR: STPMAX .LT. STPMIN'
c Exit if there are errors on input.
if (task(1:5) .eq. 'ERROR') return
c Initialize local variables.
brackt = .false.
stage = 1
finit = f
ginit = g
gtest = ftol*ginit
width = stpmax - stpmin
width1 = width/p5
c The variables stx, fx, gx contain the values of the step,
c function, and derivative at the best step.
c The variables sty, fy, gy contain the value of the step,
c function, and derivative at sty.
c The variables stp, f, g contain the values of the step,
c function, and derivative at stp.
stx = zero
fx = finit
gx = ginit
sty = zero
fy = finit
gy = ginit
stmin = zero
stmax = stp + xtrapu*stp
task = 'FG'
goto 1000
else
c Restore local variables.
if (isave(1) .eq. 1) then
brackt = .true.
else
brackt = .false.
endif
stage = isave(2)
ginit = dsave(1)
gtest = dsave(2)
gx = dsave(3)
gy = dsave(4)
finit = dsave(5)
fx = dsave(6)
fy = dsave(7)
stx = dsave(8)
sty = dsave(9)
stmin = dsave(10)
stmax = dsave(11)
width = dsave(12)
width1 = dsave(13)
endif
c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
c algorithm enters the second stage.
ftest = finit + stp*gtest
if (stage .eq. 1 .and. f .le. ftest .and. g .ge. zero)
+ stage = 2
c Test for warnings.
if (brackt .and. (stp .le. stmin .or. stp .ge. stmax))
+ task = 'WARNING: ROUNDING ERRORS PREVENT PROGRESS'
if (brackt .and. stmax - stmin .le. xtol*stmax)
+ task = 'WARNING: XTOL TEST SATISFIED'
if (stp .eq. stpmax .and. f .le. ftest .and. g .le. gtest)
+ task = 'WARNING: STP = STPMAX'
if (stp .eq. stpmin .and. (f .gt. ftest .or. g .ge. gtest))
+ task = 'WARNING: STP = STPMIN'
c Test for convergence.
if (f .le. ftest .and. abs(g) .le. gtol*(-ginit))
+ task = 'CONVERGENCE'
c Test for termination.
if (task(1:4) .eq. 'WARN' .or. task(1:4) .eq. 'CONV') goto 1000
c A modified function is used to predict the step during the
c first stage if a lower function value has been obtained but
c the decrease is not sufficient.
if (stage .eq. 1 .and. f .le. fx .and. f .gt. ftest) then
c Define the modified function and derivative values.
fm = f - stp*gtest
fxm = fx - stx*gtest
fym = fy - sty*gtest
gm = g - gtest
gxm = gx - gtest
gym = gy - gtest
c Call dcstep to update stx, sty, and to compute the new step.
call dcstep(stx,fxm,gxm,sty,fym,gym,stp,fm,gm,
+ brackt,stmin,stmax)
c Reset the function and derivative values for f.
fx = fxm + stx*gtest
fy = fym + sty*gtest
gx = gxm + gtest
gy = gym + gtest
else
c Call dcstep to update stx, sty, and to compute the new step.
call dcstep(stx,fx,gx,sty,fy,gy,stp,f,g,
+ brackt,stmin,stmax)
endif
c Decide if a bisection step is needed.
if (brackt) then
if (abs(sty-stx) .ge. p66*width1) stp = stx + p5*(sty - stx)
width1 = width
width = abs(sty-stx)
endif
c Set the minimum and maximum steps allowed for stp.
if (brackt) then
stmin = min(stx,sty)
stmax = max(stx,sty)
else
stmin = stp + xtrapl*(stp - stx)
stmax = stp + xtrapu*(stp - stx)
endif
c Force the step to be within the bounds stpmax and stpmin.
stp = max(stp,stpmin)
stp = min(stp,stpmax)
c If further progress is not possible, let stp be the best
c point obtained during the search.
if (brackt .and. (stp .le. stmin .or. stp .ge. stmax)
+ .or. (brackt .and. stmax-stmin .le. xtol*stmax)) stp = stx
c Obtain another function and derivative.
task = 'FG'
1000 continue
c Save local variables.
if (brackt) then
isave(1) = 1
else
isave(1) = 0
endif
isave(2) = stage
dsave(1) = ginit
dsave(2) = gtest
dsave(3) = gx
dsave(4) = gy
dsave(5) = finit
dsave(6) = fx
dsave(7) = fy
dsave(8) = stx
dsave(9) = sty
dsave(10) = stmin
dsave(11) = stmax
dsave(12) = width
dsave(13) = width1
return
end
c====================== The end of dcsrch ==============================
subroutine dcstep(stx,fx,dx,sty,fy,dy,stp,fp,dp,brackt,
+ stpmin,stpmax)
logical brackt
double precision stx,fx,dx,sty,fy,dy,stp,fp,dp,stpmin,stpmax
c **********
c
c Subroutine dcstep
c
c This subroutine computes a safeguarded step for a search
c procedure and updates an interval that contains a step that
c satisfies a sufficient decrease and a curvature condition.
c
c The parameter stx contains the step with the least function
c value. If brackt is set to .true. then a minimizer has
c been bracketed in an interval with endpoints stx and sty.
c The parameter stp contains the current step.
c The subroutine assumes that if brackt is set to .true. then
c
c min(stx,sty) < stp < max(stx,sty),
c
c and that the derivative at stx is negative in the direction
c of the step.
c
c The subroutine statement is
c
c subroutine dcstep(stx,fx,dx,sty,fy,dy,stp,fp,dp,brackt,
c stpmin,stpmax)
c
c where
c
c stx is a double precision variable.
c On entry stx is the best step obtained so far and is an
c endpoint of the interval that contains the minimizer.
c On exit stx is the updated best step.
c
c fx is a double precision variable.
c On entry fx is the function at stx.
c On exit fx is the function at stx.
c
c dx is a double precision variable.
c On entry dx is the derivative of the function at
c stx. The derivative must be negative in the direction of
c the step, that is, dx and stp - stx must have opposite
c signs.
c On exit dx is the derivative of the function at stx.
c
c sty is a double precision variable.
c On entry sty is the second endpoint of the interval that
c contains the minimizer.
c On exit sty is the updated endpoint of the interval that
c contains the minimizer.
c
c fy is a double precision variable.
c On entry fy is the function at sty.
c On exit fy is the function at sty.
c
c dy is a double precision variable.
c On entry dy is the derivative of the function at sty.
c On exit dy is the derivative of the function at the exit sty.
c
c stp is a double precision variable.
c On entry stp is the current step. If brackt is set to .true.
c then on input stp must be between stx and sty.
c On exit stp is a new trial step.
c
c fp is a double precision variable.
c On entry fp is the function at stp
c On exit fp is unchanged.
c
c dp is a double precision variable.
c On entry dp is the the derivative of the function at stp.
c On exit dp is unchanged.
c
c brackt is an logical variable.
c On entry brackt specifies if a minimizer has been bracketed.
c Initially brackt must be set to .false.
c On exit brackt specifies if a minimizer has been bracketed.
c When a minimizer is bracketed brackt is set to .true.
c
c stpmin is a double precision variable.
c On entry stpmin is a lower bound for the step.
c On exit stpmin is unchanged.
c
c stpmax is a double precision variable.
c On entry stpmax is an upper bound for the step.
c On exit stpmax is unchanged.
c
c MINPACK-1 Project. June 1983
c Argonne National Laboratory.
c Jorge J. More' and David J. Thuente.
c
c MINPACK-2 Project. October 1993.
c Argonne National Laboratory and University of Minnesota.
c Brett M. Averick and Jorge J. More'.
c
c **********
double precision zero,p66,two,three
parameter(zero=0.0d0,p66=0.66d0,two=2.0d0,three=3.0d0)
double precision gamma,p,q,r,s,sgnd,stpc,stpf,stpq,theta
sgnd = dp*(dx/abs(dx))
c First case: A higher function value. The minimum is bracketed.
c If the cubic step is closer to stx than the quadratic step, the
c cubic step is taken, otherwise the average of the cubic and
c quadratic steps is taken.
if (fp .gt. fx) then
theta = three*(fx - fp)/(stp - stx) + dx + dp
s = max(abs(theta),abs(dx),abs(dp))
gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
if (stp .lt. stx) gamma = -gamma
p = (gamma - dx) + theta
q = ((gamma - dx) + gamma) + dp
r = p/q
stpc = stx + r*(stp - stx)
stpq = stx + ((dx/((fx - fp)/(stp - stx) + dx))/two)*
+ (stp - stx)
if (abs(stpc-stx) .lt. abs(stpq-stx)) then
stpf = stpc
else
stpf = stpc + (stpq - stpc)/two
endif
brackt = .true.
c Second case: A lower function value and derivatives of opposite
c sign. The minimum is bracketed. If the cubic step is farther from
c stp than the secant step, the cubic step is taken, otherwise the
c secant step is taken.
else if (sgnd .lt. zero) then
theta = three*(fx - fp)/(stp - stx) + dx + dp
s = max(abs(theta),abs(dx),abs(dp))
gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
if (stp .gt. stx) gamma = -gamma
p = (gamma - dp) + theta
q = ((gamma - dp) + gamma) + dx
r = p/q
stpc = stp + r*(stx - stp)
stpq = stp + (dp/(dp - dx))*(stx - stp)
if (abs(stpc-stp) .gt. abs(stpq-stp)) then
stpf = stpc
else
stpf = stpq
endif
brackt = .true.
c Third case: A lower function value, derivatives of the same sign,
c and the magnitude of the derivative decreases.
else if (abs(dp) .lt. abs(dx)) then
c The cubic step is computed only if the cubic tends to infinity
c in the direction of the step or if the minimum of the cubic
c is beyond stp. Otherwise the cubic step is defined to be the
c secant step.
theta = three*(fx - fp)/(stp - stx) + dx + dp
s = max(abs(theta),abs(dx),abs(dp))
c The case gamma = 0 only arises if the cubic does not tend
c to infinity in the direction of the step.
gamma = s*sqrt(max(zero,(theta/s)**2-(dx/s)*(dp/s)))
if (stp .gt. stx) gamma = -gamma
p = (gamma - dp) + theta
q = (gamma + (dx - dp)) + gamma
r = p/q
if (r .lt. zero .and. gamma .ne. zero) then
stpc = stp + r*(stx - stp)
else if (stp .gt. stx) then
stpc = stpmax
else
stpc = stpmin
endif
stpq = stp + (dp/(dp - dx))*(stx - stp)
if (brackt) then
c A minimizer has been bracketed. If the cubic step is
c closer to stp than the secant step, the cubic step is
c taken, otherwise the secant step is taken.
if (abs(stpc-stp) .lt. abs(stpq-stp)) then
stpf = stpc
else
stpf = stpq
endif
if (stp .gt. stx) then
stpf = min(stp+p66*(sty-stp),stpf)
else
stpf = max(stp+p66*(sty-stp),stpf)
endif
else
c A minimizer has not been bracketed. If the cubic step is
c farther from stp than the secant step, the cubic step is
c taken, otherwise the secant step is taken.
if (abs(stpc-stp) .gt. abs(stpq-stp)) then
stpf = stpc
else
stpf = stpq
endif
stpf = min(stpmax,stpf)
stpf = max(stpmin,stpf)
endif
c Fourth case: A lower function value, derivatives of the same sign,
c and the magnitude of the derivative does not decrease. If the
c minimum is not bracketed, the step is either stpmin or stpmax,
c otherwise the cubic step is taken.
else
if (brackt) then
theta = three*(fp - fy)/(sty - stp) + dy + dp
s = max(abs(theta),abs(dy),abs(dp))
gamma = s*sqrt((theta/s)**2 - (dy/s)*(dp/s))
if (stp .gt. sty) gamma = -gamma
p = (gamma - dp) + theta
q = ((gamma - dp) + gamma) + dy
r = p/q
stpc = stp + r*(sty - stp)
stpf = stpc
else if (stp .gt. stx) then
stpf = stpmax
else
stpf = stpmin
endif
endif
c Update the interval which contains a minimizer.
if (fp .gt. fx) then
sty = stp
fy = fp
dy = dp
else
if (sgnd .lt. zero) then
sty = stx
fy = fx
dy = dx
endif
stx = stp
fx = fp
dx = dp
endif
c Compute the new step.
stp = stpf
return
end
| bsd-3-clause |
rhristov/gcc-modified | libgomp/testsuite/libgomp.fortran/lib3.f | 112 | 2487 | C { dg-do run }
INCLUDE "omp_lib.h"
DOUBLE PRECISION :: D, E
LOGICAL :: L
INTEGER (KIND = OMP_LOCK_KIND) :: LCK
INTEGER (KIND = OMP_NEST_LOCK_KIND) :: NLCK
D = OMP_GET_WTIME ()
CALL OMP_INIT_LOCK (LCK)
CALL OMP_SET_LOCK (LCK)
IF (OMP_TEST_LOCK (LCK)) CALL ABORT
CALL OMP_UNSET_LOCK (LCK)
IF (.NOT. OMP_TEST_LOCK (LCK)) CALL ABORT
IF (OMP_TEST_LOCK (LCK)) CALL ABORT
CALL OMP_UNSET_LOCK (LCK)
CALL OMP_DESTROY_LOCK (LCK)
CALL OMP_INIT_NEST_LOCK (NLCK)
IF (OMP_TEST_NEST_LOCK (NLCK) .NE. 1) CALL ABORT
CALL OMP_SET_NEST_LOCK (NLCK)
IF (OMP_TEST_NEST_LOCK (NLCK) .NE. 3) CALL ABORT
CALL OMP_UNSET_NEST_LOCK (NLCK)
CALL OMP_UNSET_NEST_LOCK (NLCK)
IF (OMP_TEST_NEST_LOCK (NLCK) .NE. 2) CALL ABORT
CALL OMP_UNSET_NEST_LOCK (NLCK)
CALL OMP_UNSET_NEST_LOCK (NLCK)
CALL OMP_DESTROY_NEST_LOCK (NLCK)
CALL OMP_SET_DYNAMIC (.TRUE.)
IF (.NOT. OMP_GET_DYNAMIC ()) CALL ABORT
CALL OMP_SET_DYNAMIC (.FALSE.)
IF (OMP_GET_DYNAMIC ()) CALL ABORT
CALL OMP_SET_NESTED (.TRUE.)
IF (.NOT. OMP_GET_NESTED ()) CALL ABORT
CALL OMP_SET_NESTED (.FALSE.)
IF (OMP_GET_NESTED ()) CALL ABORT
CALL OMP_SET_NUM_THREADS (5)
IF (OMP_GET_NUM_THREADS () .NE. 1) CALL ABORT
IF (OMP_GET_MAX_THREADS () .NE. 5) CALL ABORT
IF (OMP_GET_THREAD_NUM () .NE. 0) CALL ABORT
CALL OMP_SET_NUM_THREADS (3)
IF (OMP_GET_NUM_THREADS () .NE. 1) CALL ABORT
IF (OMP_GET_MAX_THREADS () .NE. 3) CALL ABORT
IF (OMP_GET_THREAD_NUM () .NE. 0) CALL ABORT
L = .FALSE.
C$OMP PARALLEL REDUCTION (.OR.:L)
L = OMP_GET_NUM_THREADS () .NE. 3
L = L .OR. (OMP_GET_THREAD_NUM () .LT. 0)
L = L .OR. (OMP_GET_THREAD_NUM () .GE. 3)
C$OMP MASTER
L = L .OR. (OMP_GET_THREAD_NUM () .NE. 0)
C$OMP END MASTER
C$OMP END PARALLEL
IF (L) CALL ABORT
IF (OMP_GET_NUM_PROCS () .LE. 0) CALL ABORT
IF (OMP_IN_PARALLEL ()) CALL ABORT
C$OMP PARALLEL REDUCTION (.OR.:L)
L = .NOT. OMP_IN_PARALLEL ()
C$OMP END PARALLEL
C$OMP PARALLEL REDUCTION (.OR.:L) IF (.TRUE.)
L = .NOT. OMP_IN_PARALLEL ()
C$OMP END PARALLEL
IF (L) CALL ABORT
E = OMP_GET_WTIME ()
IF (D .GT. E) CALL ABORT
D = OMP_GET_WTICK ()
C Negative precision is definitely wrong,
C bigger than 1s clock resolution is also strange
IF (D .LE. 0 .OR. D .GT. 1.) CALL ABORT
END
| gpl-2.0 |
ramirezfranciscof/lio | dat/ambermod/qm2_extern_lio_module.dif.f90 | 3 | 4918 | !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
! MODULES
!
! Add line 4 starting with "use memory_module"
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
subroutine get_lio_forces( do_grad, nstep, ntpr_default, id, nqmatoms, qmcoords,&
nclatoms, clcoords, escf, dxyzqm, dxyzcl)
use memory_module, only:x,lvel
use constants, only: CODATA08_AU_TO_KCAL, CODATA08_A_TO_BOHRS, ZERO
use file_io_dat
use qmmm_module, only : qmmm_struct, qmmm_nml
! use garcha_mod
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
!
!
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
! DECLARATIONS
!
! Add lines 3 (include...), 11 (qmvels) and 21 (nn declaration).
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
implicit none
# include "../include/md.h"
logical, intent(in) :: do_grad ! Return gradient/not
integer, intent(in) :: nstep ! MD step number
integer, intent(in) :: ntpr_default ! frequency of printing
character(len=3), intent(in) :: id ! ID number for PIMD or REMD
integer, intent(in) :: nqmatoms ! Number of QM atoms
_REAL_, intent(in) :: qmcoords(3,nqmatoms) ! QM atom coordinates
_REAL_ :: qmvels(3,nqmatoms) ! QM atom velocities (of previous step)
integer, intent(in) :: nclatoms ! Number of MM atoms
_REAL_, intent(in) :: clcoords(4,nclatoms) ! MM atom coordinates and charges in au
_REAL_, intent(out) :: escf ! SCF energy
_REAL_, intent(out) :: dxyzqm(3,nqmatoms) ! SCF QM force
_REAL_, intent(out) :: dxyzcl(3,nclatoms) ! SCF MM force
_REAL_ :: dipxyz(3), dipole ! Dipole moment
type(lio_nml_type), save :: lio_nml
logical, save :: first_call = .true.
integer :: nn,i
integer :: printed =-1 ! Used to tell if we have printed this step yet
! since the same step may be called multiple times
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
!
!
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
! COMMANDS
!
! Replace with the following blocks between lines.
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
! Setup on first call
if ( first_call ) then
first_call = .false.
write (6,'(/,a,/)') ' >>> Running calculations with Lio <<<'
call get_namelist_lio(lio_nml)
call print_namelist(lio_nml)
!------------------------------------------------------------------------------!
! FFR - EHRENFEST ADAPTATION
!------------------------------------------------------------------------------!
write (6,'(/,a,/)') ' >>> Using code in /LioDevelop/Amber14eh2 <<<'
! call init_lio_amber(nqmatoms,qmmm_struct%iqm_atomic_numbers,nclatoms, &
call init_lioamber_ehren(nqmatoms,qmmm_struct%iqm_atomic_numbers,nclatoms, &
qmmm_nml%qmcharge, lio_nml%basis, lio_nml%output, lio_nml%fcoord, &
lio_nml%fmulliken, lio_nml%frestart, lio_nml%frestartin, &
lio_nml%verbose, lio_nml%OPEN, lio_nml%NMAX, lio_nml%NUNP, &
lio_nml%VCINP, lio_nml%GOLD, lio_nml%told, lio_nml%rmax, &
lio_nml%rmaxs, lio_nml%predcoef, lio_nml%idip, lio_nml%writexyz, &
lio_nml%intsoldouble, lio_nml%DIIS, lio_nml%ndiis, lio_nml%dgtrig, &
lio_nml%Iexch, lio_nml%integ, lio_nml%DENS, lio_nml%IGRID, &
lio_nml%IGRID2, lio_nml%timedep, lio_nml%tdstep, lio_nml%ntdstep, &
lio_nml%field, lio_nml%exter, lio_nml%a0, lio_nml%epsilon, &
lio_nml%Fx, lio_nml%Fy, lio_nml%Fz, lio_nml%NBCH, &
! lio_nml%propagator, lio_nml%writedens, lio_nml%tdrestart)
lio_nml%propagator, lio_nml%writedens, lio_nml%tdrestart,dt)
!------------------------------------------------------------------------------!
end if
!------------------------------------------------------------------------------!
! FFR - EHRENFEST ADAPTATION
!------------------------------------------------------------------------------!
do nn=1,nqmatoms
qmvels(1,nn)=x(lvel+3*qmmm_struct%iqmatoms(nn)-3)
qmvels(2,nn)=x(lvel+3*qmmm_struct%iqmatoms(nn)-2)
qmvels(3,nn)=x(lvel+3*qmmm_struct%iqmatoms(nn)-1)
enddo
! call SCF_in(escf,qmcoords,clcoords,nclatoms,dipxyz)
call ehren_in( qmcoords, qmvels, clcoords, nclatoms, dipxyz, escf)
!------------------------------------------------------------------------------!
escf=escf*CODATA08_AU_TO_KCAL
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
| gpl-2.0 |
rhristov/gcc-modified | libgomp/testsuite/libgomp.fortran/vla1.f90 | 202 | 7391 | ! { dg-do run }
call test
contains
subroutine check (x, y, l)
integer :: x, y
logical :: l
l = l .or. x .ne. y
end subroutine check
subroutine foo (c, d, e, f, g, h, i, j, k, n)
use omp_lib
integer :: n
character (len = *) :: c
character (len = n) :: d
integer, dimension (2, 3:5, n) :: e
integer, dimension (2, 3:n, n) :: f
character (len = *), dimension (5, 3:n) :: g
character (len = n), dimension (5, 3:n) :: h
real, dimension (:, :, :) :: i
double precision, dimension (3:, 5:, 7:) :: j
integer, dimension (:, :, :) :: k
logical :: l
integer :: p, q, r
character (len = n) :: s
integer, dimension (2, 3:5, n) :: t
integer, dimension (2, 3:n, n) :: u
character (len = n), dimension (5, 3:n) :: v
character (len = 2 * n + 24) :: w
integer :: x
character (len = 1) :: y
s = 'PQRSTUV'
forall (p = 1:2, q = 3:5, r = 1:7) t(p, q, r) = -10 + p - q + 2 * r
forall (p = 1:2, q = 3:7, r = 1:7) u(p, q, r) = 30 - p + q - 2 * r
forall (p = 1:5, q = 3:7, p + q .le. 8) v(p, q) = '_+|/Oo_'
forall (p = 1:5, q = 3:7, p + q .gt. 8) v(p, q) = '///|||!'
l = .false.
!$omp parallel default (none) firstprivate (c, d, e, f, g, h, i, j, k) &
!$omp & firstprivate (s, t, u, v) reduction (.or.:l) num_threads (6) &
!$omp private (p, q, r, w, x, y)
l = l .or. c .ne. 'abcdefghijkl'
l = l .or. d .ne. 'ABCDEFG'
l = l .or. s .ne. 'PQRSTUV'
do 100, p = 1, 2
do 100, q = 3, 7
do 100, r = 1, 7
if (q .lt. 6) l = l .or. e(p, q, r) .ne. 5 + p + q + 2 * r
l = l .or. f(p, q, r) .ne. 25 + p + q + 2 * r
if (r .lt. 6 .and. q + r .le. 8) l = l .or. g(r, q) .ne. '0123456789AB'
if (r .lt. 6 .and. q + r .gt. 8) l = l .or. g(r, q) .ne. '9876543210ZY'
if (r .lt. 6 .and. q + r .le. 8) l = l .or. h(r, q) .ne. '0123456'
if (r .lt. 6 .and. q + r .gt. 8) l = l .or. h(r, q) .ne. '9876543'
if (q .lt. 6) l = l .or. t(p, q, r) .ne. -10 + p - q + 2 * r
l = l .or. u(p, q, r) .ne. 30 - p + q - 2 * r
if (r .lt. 6 .and. q + r .le. 8) l = l .or. v(r, q) .ne. '_+|/Oo_'
if (r .lt. 6 .and. q + r .gt. 8) l = l .or. v(r, q) .ne. '///|||!'
100 continue
do 101, p = 3, 5
do 101, q = 2, 6
do 101, r = 1, 7
l = l .or. i(p - 2, q - 1, r) .ne. 7.5 * p * q * r
l = l .or. j(p, q + 3, r + 6) .ne. 9.5 * p * q * r
101 continue
do 102, p = 1, 5
do 102, q = 4, 6
l = l .or. k(p, 1, q - 3) .ne. 19 + p + 7 + 3 * q
102 continue
x = omp_get_thread_num ()
w = ''
if (x .eq. 0) w = 'thread0thr_number_0THREAD0THR_NUMBER_0'
if (x .eq. 1) w = 'thread1thr_number_1THREAD1THR_NUMBER_1'
if (x .eq. 2) w = 'thread2thr_number_2THREAD2THR_NUMBER_2'
if (x .eq. 3) w = 'thread3thr_number_3THREAD3THR_NUMBER_3'
if (x .eq. 4) w = 'thread4thr_number_4THREAD4THR_NUMBER_4'
if (x .eq. 5) w = 'thread5thr_number_5THREAD5THR_NUMBER_5'
c = w(8:19)
d = w(1:7)
forall (p = 1:2, q = 3:5, r = 1:7) e(p, q, r) = 5 * x + p + q + 2 * r
forall (p = 1:2, q = 3:7, r = 1:7) f(p, q, r) = 25 * x + p + q + 2 * r
forall (p = 1:5, q = 3:7, p + q .le. 8) g(p, q) = w(8:19)
forall (p = 1:5, q = 3:7, p + q .gt. 8) g(p, q) = w(27:38)
forall (p = 1:5, q = 3:7, p + q .le. 8) h(p, q) = w(1:7)
forall (p = 1:5, q = 3:7, p + q .gt. 8) h(p, q) = w(20:26)
forall (p = 3:5, q = 2:6, r = 1:7) i(p - 2, q - 1, r) = (7.5 + x) * p * q * r
forall (p = 3:5, q = 2:6, r = 1:7) j(p, q + 3, r + 6) = (9.5 + x) * p * q * r
forall (p = 1:5, q = 7:7, r = 4:6) k(p, q - 6, r - 3) = 19 + x + p + q + 3 * r
s = w(20:26)
forall (p = 1:2, q = 3:5, r = 1:7) t(p, q, r) = -10 + x + p - q + 2 * r
forall (p = 1:2, q = 3:7, r = 1:7) u(p, q, r) = 30 - x - p + q - 2 * r
forall (p = 1:5, q = 3:7, p + q .le. 8) v(p, q) = w(1:7)
forall (p = 1:5, q = 3:7, p + q .gt. 8) v(p, q) = w(20:26)
!$omp barrier
y = ''
if (x .eq. 0) y = '0'
if (x .eq. 1) y = '1'
if (x .eq. 2) y = '2'
if (x .eq. 3) y = '3'
if (x .eq. 4) y = '4'
if (x .eq. 5) y = '5'
l = l .or. w(7:7) .ne. y
l = l .or. w(19:19) .ne. y
l = l .or. w(26:26) .ne. y
l = l .or. w(38:38) .ne. y
l = l .or. c .ne. w(8:19)
l = l .or. d .ne. w(1:7)
l = l .or. s .ne. w(20:26)
do 103, p = 1, 2
do 103, q = 3, 7
do 103, r = 1, 7
if (q .lt. 6) l = l .or. e(p, q, r) .ne. 5 * x + p + q + 2 * r
l = l .or. f(p, q, r) .ne. 25 * x + p + q + 2 * r
if (r .lt. 6 .and. q + r .le. 8) l = l .or. g(r, q) .ne. w(8:19)
if (r .lt. 6 .and. q + r .gt. 8) l = l .or. g(r, q) .ne. w(27:38)
if (r .lt. 6 .and. q + r .le. 8) l = l .or. h(r, q) .ne. w(1:7)
if (r .lt. 6 .and. q + r .gt. 8) l = l .or. h(r, q) .ne. w(20:26)
if (q .lt. 6) l = l .or. t(p, q, r) .ne. -10 + x + p - q + 2 * r
l = l .or. u(p, q, r) .ne. 30 - x - p + q - 2 * r
if (r .lt. 6 .and. q + r .le. 8) l = l .or. v(r, q) .ne. w(1:7)
if (r .lt. 6 .and. q + r .gt. 8) l = l .or. v(r, q) .ne. w(20:26)
103 continue
do 104, p = 3, 5
do 104, q = 2, 6
do 104, r = 1, 7
l = l .or. i(p - 2, q - 1, r) .ne. (7.5 + x) * p * q * r
l = l .or. j(p, q + 3, r + 6) .ne. (9.5 + x) * p * q * r
104 continue
do 105, p = 1, 5
do 105, q = 4, 6
l = l .or. k(p, 1, q - 3) .ne. 19 + x + p + 7 + 3 * q
105 continue
call check (size (e, 1), 2, l)
call check (size (e, 2), 3, l)
call check (size (e, 3), 7, l)
call check (size (e), 42, l)
call check (size (f, 1), 2, l)
call check (size (f, 2), 5, l)
call check (size (f, 3), 7, l)
call check (size (f), 70, l)
call check (size (g, 1), 5, l)
call check (size (g, 2), 5, l)
call check (size (g), 25, l)
call check (size (h, 1), 5, l)
call check (size (h, 2), 5, l)
call check (size (h), 25, l)
call check (size (i, 1), 3, l)
call check (size (i, 2), 5, l)
call check (size (i, 3), 7, l)
call check (size (i), 105, l)
call check (size (j, 1), 4, l)
call check (size (j, 2), 5, l)
call check (size (j, 3), 7, l)
call check (size (j), 140, l)
call check (size (k, 1), 5, l)
call check (size (k, 2), 1, l)
call check (size (k, 3), 3, l)
call check (size (k), 15, l)
!$omp end parallel
if (l) call abort
end subroutine foo
subroutine test
character (len = 12) :: c
character (len = 7) :: d
integer, dimension (2, 3:5, 7) :: e
integer, dimension (2, 3:7, 7) :: f
character (len = 12), dimension (5, 3:7) :: g
character (len = 7), dimension (5, 3:7) :: h
real, dimension (3:5, 2:6, 1:7) :: i
double precision, dimension (3:6, 2:6, 1:7) :: j
integer, dimension (1:5, 7:7, 4:6) :: k
integer :: p, q, r
c = 'abcdefghijkl'
d = 'ABCDEFG'
forall (p = 1:2, q = 3:5, r = 1:7) e(p, q, r) = 5 + p + q + 2 * r
forall (p = 1:2, q = 3:7, r = 1:7) f(p, q, r) = 25 + p + q + 2 * r
forall (p = 1:5, q = 3:7, p + q .le. 8) g(p, q) = '0123456789AB'
forall (p = 1:5, q = 3:7, p + q .gt. 8) g(p, q) = '9876543210ZY'
forall (p = 1:5, q = 3:7, p + q .le. 8) h(p, q) = '0123456'
forall (p = 1:5, q = 3:7, p + q .gt. 8) h(p, q) = '9876543'
forall (p = 3:5, q = 2:6, r = 1:7) i(p, q, r) = 7.5 * p * q * r
forall (p = 3:6, q = 2:6, r = 1:7) j(p, q, r) = 9.5 * p * q * r
forall (p = 1:5, q = 7:7, r = 4:6) k(p, q, r) = 19 + p + q + 3 * r
call foo (c, d, e, f, g, h, i, j, k, 7)
end subroutine test
end
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/elemental_subroutine_10.f90 | 72 | 2245 | ! { dg-do run }
!
! PR fortran/60066
!
! Contributed by F Martinez Fadrique <fmartinez@gmv.com>
!
! Fixed by the patch for PR59906 but adds another, different test.
!
module m_assertion_character
implicit none
type :: t_assertion_character
character(len=8) :: name
contains
procedure :: assertion_character
procedure :: write => assertion_array_write
end type t_assertion_character
contains
impure elemental subroutine assertion_character( ast, name )
class(t_assertion_character), intent(out) :: ast
character(len=*), intent(in) :: name
ast%name = name
end subroutine assertion_character
subroutine assertion_array_write( ast, unit )
class(t_assertion_character), intent(in) :: ast
character(*), intent(inOUT) :: unit
write(unit,*) trim (unit(2:len(unit)))//trim (ast%name)
end subroutine assertion_array_write
end module m_assertion_character
module m_assertion_array_character
use m_assertion_character
implicit none
type :: t_assertion_array_character
type(t_assertion_character), dimension(:), allocatable :: rast
contains
procedure :: assertion_array_character
procedure :: write => assertion_array_character_write
end type t_assertion_array_character
contains
subroutine assertion_array_character( ast, name, nast )
class(t_assertion_array_character), intent(out) :: ast
character(len=*), intent(in) :: name
integer, intent(in) :: nast
integer :: i
allocate ( ast%rast(nast) )
call ast%rast%assertion_character ( name )
end subroutine assertion_array_character
subroutine assertion_array_character_write( ast, unit )
class(t_assertion_array_character), intent(in) :: ast
CHARACTER(*), intent(inOUT) :: unit
integer :: i
do i = 1, size (ast%rast)
call ast%rast(i)%write (unit)
end do
end subroutine assertion_array_character_write
end module m_assertion_array_character
program main
use m_assertion_array_character
implicit none
type(t_assertion_array_character) :: ast
character(len=8) :: name
character (26) :: line = ''
name = 'test'
call ast%assertion_array_character ( name, 5 )
call ast%write (line)
if (line(2:len (line)) .ne. "testtesttesttesttest") call abort
end program main
| gpl-2.0 |
ForestClaw/forestclaw | applications/clawpack/shallow/2d/radialdam_cuda/user_5.0/setaux.f90 | 2 | 1493 | SUBROUTINE user5_setaux_manifold(mbc,mx,my, &
xlower,ylower,dx,dy,maux,aux, &
xnormals,xtangents,ynormals,ytangents, &
surfnormals,area)
IMPLICIT NONE
INTEGER mx,my,mbc,maux
DOUBLE PRECISION xlower,ylower,dx,dy
DOUBLE PRECISION aux(maux,1-mbc:mx+mbc,1-mbc:my+mbc)
!! Still hoping to be able to include this using 'fclaw2d_metric_terms.i'
DOUBLE PRECISION area(-mbc:mx+mbc+1,-mbc:my+mbc+1)
DOUBLE PRECISION surfnormals(-mbc:mx+mbc+1,-mbc:my+mbc+1,3)
DOUBLE PRECISION xnormals(-mbc:mx+mbc+2,-mbc:my+mbc+2,3)
DOUBLE PRECISION ynormals(-mbc:mx+mbc+2,-mbc:my+mbc+2,3)
DOUBLE PRECISION xtangents(-mbc:mx+mbc+2,-mbc:my+mbc+2,3)
DOUBLE PRECISION ytangents(-mbc:mx+mbc+2,-mbc:my+mbc+2,3)
INTEGER i,j
DO j = 1-mbc,my+mbc
DO i = 1-mbc,mx+mbc
aux(1,i,j) = area(i,j)/(dx*dy)
aux(2,i,j) = xnormals(i,j,1)
aux(3,i,j) = xnormals(i,j,2)
aux(4,i,j) = xnormals(i,j,3)
aux(5,i,j) = xtangents(i,j,1)
aux(6,i,j) = xtangents(i,j,2)
aux(7,i,j) = xtangents(i,j,3)
aux(8,i,j) = ynormals(i,j,1)
aux(9,i,j) = ynormals(i,j,2)
aux(10,i,j) = ynormals(i,j,3)
aux(11,i,j) = ytangents(i,j,1)
aux(12,i,j) = ytangents(i,j,2)
aux(13,i,j) = ytangents(i,j,3)
aux(14,i,j) = surfnormals(i,j,1)
aux(15,i,j) = surfnormals(i,j,2)
aux(16,i,j) = surfnormals(i,j,3)
ENDDO
ENDDO
END SUBROUTINE user5_setaux_manifold
| bsd-2-clause |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/pr32738.f90 | 155 | 1129 | ! { dg-do compile }
! PR fortran/32738
!
! A regression that mysteriously appeared and disappeared again.
! Added to the testsuite "just in case".
!
! Contributed by Michael Richmond <michael DOT a DOT richmond AT nasa DT gov>
!
module cluster_definition
implicit none
integer, parameter, public:: cluster_size = 1000
end module cluster_definition
module cluster_tree
use cluster_definition, only: ct_cluster_size => cluster_size
implicit none
private
private:: ct_initialize, ct_dealloc, ct_tree_size
public:: initialize, dealloc, tree_size
interface initialize
module procedure ct_initialize
end interface
interface dealloc
module procedure ct_dealloc
end interface
interface tree_size
module procedure ct_tree_size
end interface
contains
subroutine ct_initialize()
end subroutine ct_initialize
subroutine ct_dealloc()
end subroutine ct_dealloc
function ct_tree_size(t) result(s)
integer :: t
integer :: s
s = 0
end function ct_tree_size
end module cluster_tree
program example
use cluster_tree
implicit none
print *, tree_size(1)
end program example
| gpl-2.0 |
nvarini/espresso_adios | CPV/src/berryion.f90 | 21 | 3697 | !
! Copyright (C) 2002-2005 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
subroutine berryion( tau0,fion, tfor,ipol,evalue,enbi)
! this subroutine returns the berry phase energy
! = L/2*Pi*Im(log Sum_R exp(i*(2pi/L)*R_i*rho_i))
! of the ions and the constant force on the ions
! now only for orthorombic primitive cell
! tau0 : input, positions of ions
! fion : input,output, forces on ions
! tfor : input, flag for force calculation
! ipol : input, electric field polarization
! evalue : input, scale for electric field
! enbi : output, berry phase energy of the ions
use kinds, only : dp
use constants, only : pi
use ions_base, ONLY : nsp, na, zv
use cell_base, only : alat, at
implicit none
real(dp) tau0(3,*)
real(dp) fion(3,*)
real(dp) enbi, evalue
integer ipol, isa
logical tfor
!local variables
real(dp) :: gmes, pola
integer is, ia
complex(dp) temp, ci
real(dp), external:: g_mes
temp = (0.0_dp,0.0_dp)
ci = (0.0_dp,1.0_dp)
gmes = g_mes ( ipol, at, alat)
pola=0.0_dp
isa = 0
do is=1,nsp
do ia=1,na(is)
isa = isa + 1
!this force term is along ipol-direction
if( tfor) then
fion(ipol,isa)=fion(ipol,isa)+evalue*zv(is)
endif
temp = temp - ci*gmes*tau0(ipol,isa)*zv(is)
pola=pola+evalue*zv(is)*tau0(ipol,isa)!this is just the center of ionic charge
enddo
enddo
enbi=AIMAG(log(exp(temp)))/gmes!this sounds stupid it's just a Riemann plane
return
end subroutine berryion
!-------------------------------------------------------------------------
subroutine cofcharge(tau,cdz)
!-----------------------------------------------------------------------
!this subroutine gives the center of the ionic charge
use kinds, only : dp
use ions_base, only: na, nsp, zv
!
implicit none
real(dp) tau(3,*), cdz(3)
! local variables
real(dp) zmas
integer is,i,ia,isa
!
zmas=0.0d0
do is=1,nsp
zmas=zmas+na(is)*zv(is)
end do
!
isa = 0
do i=1,3
cdz(i)=0.0d0
do is=1,nsp
do ia=1,na(is)
isa = isa + 1
cdz(i)=cdz(i)+tau(i,isa)*zv(is)
end do
end do
cdz(i)=cdz(i)/zmas
end do
! write(6,*) 'Center of charge', cdz(3)!ATTENZIONE
!
return
end subroutine cofcharge
!
!----------------------------------------------------
subroutine noforce(fion, ipol)
!----------------------------------------------------
! this subroutine adds an electric force, in order
! to keep steady the center of mass along the electric
! field direction
use kinds, only : dp
use ions_base, ONLY : na, nsp, zv
implicit none
real(dp) fion(3,*)
integer ipol!el. field polarization
integer i,ia,is,isa
real(dp) fcm!force appplied on center of mass
real(dp) tch!total charge
fcm=0.d0
tch=0.d0
isa = 0
do is=1,nsp
do ia=1,na(is)
isa = isa + 1
fcm=fcm+fion(ipol,isa)
tch=tch+zv(is)
enddo
enddo
fcm=fcm/tch
isa = 0
do is=1,nsp
do ia=1,na(is)
isa = isa + 1
fion(ipol,isa)=fion(ipol,isa)-fcm*zv(is)
enddo
enddo
return
end subroutine noforce
| gpl-2.0 |
ramirezfranciscof/lio | lioamber/liosubs_math/funct.f90 | 1 | 3918 | !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
!
! This small program is taken from old version of gdfmol
! it is the implementation of the Obara-Saika method for
! the evaluation of F(m,T), using a 2 branch calculation
! DEBUGGING VERSION, this is the attempt to generalize
! and improve previous version ( up to F16 ).
! Ref: JCP 84 3963 (1986)
! it seems to work
!
! This is the version that should be included in definitive
! program
! 11 March 1992
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
subroutine init_math
use math_data, only: STR, FAC
implicit none
integer :: icount, jcount
double precision :: T, Y, U, F, W
double precision, parameter :: SQPI = 1.77245385090551588D0
! Loop over T values in the table ( 0. to 43.95 , interval 0.05)
do icount = 1, 880
T = 0.05D0 * DFLOAT(icount -1)
Y = DEXP(-T)
U = T + T
F = FMCH(22,T)
! loop over order of incomple Gamma functions ( 0 to 21, the ones
! necessary for evaluating orders 0-16)
do jcount = 21, 0, -1
W = 2.0D0 * DFLOAT(jcount) + 1.0D0
STR(icount,jcount) = (Y + U * F) / W
F = STR(icount,jcount)
enddo
enddo
! Calculation of the function [(v+1/2)/2**v+1*sqrt(pi) ]
FAC(0) = SQPI / 2.0D0
do icount = 1, 16
FAC(icount) = FAC(icount -1) * (2 * icount -1) / 2
enddo
end subroutine init_math
function FMCH(M,X)
implicit none
integer , intent(in) :: M
double precision, intent(in) :: X
double precision :: Y, A, PTLSUM, TERM, B, XD, APPROX, FIMULT, FMCH, FIPROP,&
NOTRMS
integer :: I
double precision, parameter :: SQPI = 1.77245385090551588D0
Y = DEXP(-X)
if (.not. (X .gt. 10.0D0)) then
A = DFLOAT(M) + 0.5D0
TERM = 1.0D0 / A
PTLSUM = TERM
do I = 2, 50
TERM = TERM * X / (A + DFLOAT(I-1))
PTLSUM = PTLSUM + TERM
if ((TERM / PTLSUM) .LT. 1.0D-12) exit
enddo
FMCH = 0.5D0 * PTLSUM * Y
return
else
A = DFLOAT(M)
B = A + 0.5D0
XD = 1.0D0 / X
APPROX = 0.886226925452758D0 * DSQRT(XD) * XD**M
do I = 1, M
APPROX = APPROX * (B - DFLOAT(I))
enddo
FIMULT = 0.5D0 * Y * XD
PTLSUM = 0.0D0
if (FIMULT .eq. 0.0D0 ) then
FMCH = APPROX
return
endif
FIPROP = FIMULT / APPROX
TERM = 1.0D0
PTLSUM = TERM
NOTRMS = X
NOTRMS = NOTRMS + M
do I = 2, int(NOTRMS)
A = B - DFLOAT(I-1)
TERM = TERM * A * XD
PTLSUM = PTLSUM + TERM
if (DABS(TERM * FIPROP / PTLSUM) .le. 1.0D-10) exit
enddo
FMCH = APPROX - FIMULT * PTLSUM
endif
return
end function FMCH
function funct(N, T)
use math_data, only: STR, FAC
implicit none
integer , intent(in) :: N
double precision, intent(inout) :: T
integer :: IT
double precision :: TI, DELT, DELT2, DELT3, DELT4, DELT5, TF0, TF1, TF2, &
TF3, TF4, TF5, funct
if (T .lt. 0.0D0) then
write(*,'(A)') 'Problems with Boys function'
T = abs(T)
endif
if (T .le. 43.975D0) then
IT = 20.0D0 * (T + 0.025D0)
TI = DFLOAT(IT)
IT = IT + 1
DELT = T - 0.05D0 * TI
DELT3 = DELT * 0.333333333333333D0
DELT4 = 0.25D0 * DELT
DELT2 = DELT4 + DELT4
DELT5 = 0.20D0 * DELT
TF0 = STR(IT,N)
TF1 = STR(IT,N+1)
TF2 = STR(IT,N+2)
TF3 = STR(IT,N+3)
TF4 = STR(IT,N+4)
TF5 = STR(IT,N+5)
FUNCT = TF0 - DELT * (TF1 - DELT2 * (TF2 - DELT3 * (TF3 - DELT4 * &
(TF4 - DELT5 * TF5))))
else
FUNCT = FAC(N) * 1.D0 / (T**N * dsqrt(T))
endif
end function funct
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!
| gpl-2.0 |
kito-cheng/riscv-gcc | libgomp/testsuite/libgomp.oacc-fortran/asyncwait-1.f90 | 15 | 4370 | ! { dg-do run }
program asyncwait
integer, parameter :: N = 64
real, allocatable :: a(:), b(:), c(:), d(:), e(:)
integer i
allocate (a(N))
allocate (b(N))
allocate (c(N))
allocate (d(N))
allocate (e(N))
a(:) = 3.0
b(:) = 0.0
!$acc data copy (a(1:N)) copy (b(1:N))
!$acc parallel async
!$acc loop
do i = 1, N
b(i) = a(i)
end do
!$acc end parallel
!$acc wait
!$acc end data
do i = 1, N
if (a(i) .ne. 3.0) STOP 1
if (b(i) .ne. 3.0) STOP 2
end do
a(:) = 2.0
b(:) = 0.0
!$acc data copy (a(1:N)) copy (b(1:N))
!$acc parallel async (1)
!$acc loop
do i = 1, N
b(i) = a(i)
end do
!$acc end parallel
!$acc wait (1)
!$acc end data
do i = 1, N
if (a(i) .ne. 2.0) STOP 3
if (b(i) .ne. 2.0) STOP 4
end do
a(:) = 3.0
b(:) = 0.0
c(:) = 0.0
d(:) = 0.0
!$acc data copy (a(1:N)) copy (b(1:N)) copy (c(1:N)) copy (d(1:N))
!$acc parallel async (1)
do i = 1, N
b(i) = (a(i) * a(i) * a(i)) / a(i)
end do
!$acc end parallel
!$acc parallel async (1)
do i = 1, N
c(i) = (a(i) * 4) / a(i)
end do
!$acc end parallel
!$acc parallel async (1)
!$acc loop
do i = 1, N
d(i) = ((a(i) * a(i) + a(i)) / a(i)) - a(i)
end do
!$acc end parallel
!$acc wait (1)
!$acc end data
do i = 1, N
if (a(i) .ne. 3.0) STOP 5
if (b(i) .ne. 9.0) STOP 6
if (c(i) .ne. 4.0) STOP 7
if (d(i) .ne. 1.0) STOP 8
end do
a(:) = 2.0
b(:) = 0.0
c(:) = 0.0
d(:) = 0.0
e(:) = 0.0
!$acc data copy (a(1:N), b(1:N), c(1:N), d(1:N), e(1:N))
!$acc parallel async (1)
do i = 1, N
b(i) = (a(i) * a(i) * a(i)) / a(i)
end do
!$acc end parallel
!$acc parallel async (1)
!$acc loop
do i = 1, N
c(i) = (a(i) * 4) / a(i)
end do
!$acc end parallel
!$acc parallel async (1)
!$acc loop
do i = 1, N
d(i) = ((a(i) * a(i) + a(i)) / a(i)) - a(i)
end do
!$acc end parallel
!$acc parallel wait (1) async (1)
!$acc loop
do i = 1, N
e(i) = a(i) + b(i) + c(i) + d(i)
end do
!$acc end parallel
!$acc wait (1)
!$acc end data
do i = 1, N
if (a(i) .ne. 2.0) STOP 9
if (b(i) .ne. 4.0) STOP 10
if (c(i) .ne. 4.0) STOP 11
if (d(i) .ne. 1.0) STOP 12
if (e(i) .ne. 11.0) STOP 13
end do
a(:) = 3.0
b(:) = 0.0
!$acc data copy (a(1:N)) copy (b(1:N))
!$acc kernels async
!$acc loop
do i = 1, N
b(i) = a(i)
end do
!$acc end kernels
!$acc wait
!$acc end data
do i = 1, N
if (a(i) .ne. 3.0) STOP 14
if (b(i) .ne. 3.0) STOP 15
end do
a(:) = 2.0
b(:) = 0.0
!$acc data copy (a(1:N)) copy (b(1:N))
!$acc kernels async (1)
!$acc loop
do i = 1, N
b(i) = a(i)
end do
!$acc end kernels
!$acc wait (1)
!$acc end data
do i = 1, N
if (a(i) .ne. 2.0) STOP 16
if (b(i) .ne. 2.0) STOP 17
end do
a(:) = 3.0
b(:) = 0.0
c(:) = 0.0
d(:) = 0.0
!$acc data copy (a(1:N)) copy (b(1:N)) copy (c(1:N)) copy (d(1:N))
!$acc kernels async (1)
do i = 1, N
b(i) = (a(i) * a(i) * a(i)) / a(i)
end do
!$acc end kernels
!$acc kernels async (1)
do i = 1, N
c(i) = (a(i) * 4) / a(i)
end do
!$acc end kernels
!$acc kernels async (1)
!$acc loop
do i = 1, N
d(i) = ((a(i) * a(i) + a(i)) / a(i)) - a(i)
end do
!$acc end kernels
!$acc wait (1)
!$acc end data
do i = 1, N
if (a(i) .ne. 3.0) STOP 18
if (b(i) .ne. 9.0) STOP 19
if (c(i) .ne. 4.0) STOP 20
if (d(i) .ne. 1.0) STOP 21
end do
a(:) = 2.0
b(:) = 0.0
c(:) = 0.0
d(:) = 0.0
e(:) = 0.0
!$acc data copy (a(1:N), b(1:N), c(1:N), d(1:N), e(1:N))
!$acc kernels async (1)
do i = 1, N
b(i) = (a(i) * a(i) * a(i)) / a(i)
end do
!$acc end kernels
!$acc kernels async (1)
!$acc loop
do i = 1, N
c(i) = (a(i) * 4) / a(i)
end do
!$acc end kernels
!$acc kernels async (1)
!$acc loop
do i = 1, N
d(i) = ((a(i) * a(i) + a(i)) / a(i)) - a(i)
end do
!$acc end kernels
!$acc kernels wait (1) async (1)
!$acc loop
do i = 1, N
e(i) = a(i) + b(i) + c(i) + d(i)
end do
!$acc end kernels
!$acc wait (1)
!$acc end data
do i = 1, N
if (a(i) .ne. 2.0) STOP 22
if (b(i) .ne. 4.0) STOP 23
if (c(i) .ne. 4.0) STOP 24
if (d(i) .ne. 1.0) STOP 25
if (e(i) .ne. 11.0) STOP 26
end do
end program asyncwait
| gpl-2.0 |
nvarini/espresso_adios | flib/erf.f90 | 22 | 4495 | !
! Copyright (C) 2002-2009 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!---------------------------------------------------------------------
function qe_erf (x)
!---------------------------------------------------------------------
!
! Error function - computed from the rational approximations of
! W. J. Cody, Math. Comp. 22 (1969), pages 631-637.
!
! for abs(x) le 0.47 erf is calculated directly
! for abs(x) gt 0.47 erf is calculated via erf(x)=1-erfc(x)
!
use kinds, only : DP
implicit none
real(DP), intent(in) :: x
real(DP) :: x2, p1 (4), q1 (4)
real(DP), external :: qe_erfc
real(DP) :: qe_erf
data p1 / 2.426679552305318E2_DP, 2.197926161829415E1_DP, &
6.996383488619136_DP, -3.560984370181538E-2_DP /
data q1 / 2.150588758698612E2_DP, 9.116490540451490E1_DP, &
1.508279763040779E1_DP, 1.000000000000000_DP /
!
if (abs (x) > 6.0_DP) then
!
! erf(6)=1-10^(-17) cannot be distinguished from 1
!
qe_erf = sign (1.0_DP, x)
else
if (abs (x) <= 0.47_DP) then
x2 = x**2
qe_erf=x *(p1 (1) + x2 * (p1 (2) + x2 * (p1 (3) + x2 * p1 (4) ) ) ) &
/ (q1 (1) + x2 * (q1 (2) + x2 * (q1 (3) + x2 * q1 (4) ) ) )
else
qe_erf = 1.0_DP - qe_erfc (x)
endif
endif
!
return
end function qe_erf
!
!---------------------------------------------------------------------
function qe_erfc (x)
!---------------------------------------------------------------------
!
! erfc(x) = 1-erf(x) - See comments in erf
!
use kinds, only : DP
implicit none
real(DP),intent(in) :: x
real(DP) :: qe_erfc
real(DP) :: ax, x2, xm2, p2 (8), q2 (8), p3 (5), q3 (5), pim1
real(DP), external :: qe_erf
data p2 / 3.004592610201616E2_DP, 4.519189537118719E2_DP, &
3.393208167343437E2_DP, 1.529892850469404E2_DP, &
4.316222722205674E1_DP, 7.211758250883094_DP, &
5.641955174789740E-1_DP,-1.368648573827167E-7_DP /
data q2 / 3.004592609569833E2_DP, 7.909509253278980E2_DP, &
9.313540948506096E2_DP, 6.389802644656312E2_DP, &
2.775854447439876E2_DP, 7.700015293522947E1_DP, &
1.278272731962942E1_DP, 1.000000000000000_DP /
data p3 /-2.996107077035422E-3_DP,-4.947309106232507E-2_DP, &
-2.269565935396869E-1_DP,-2.786613086096478E-1_DP, &
-2.231924597341847E-2_DP /
data q3 / 1.062092305284679E-2_DP, 1.913089261078298E-1_DP, &
1.051675107067932_DP, 1.987332018171353_DP, &
1.000000000000000_DP /
data pim1 / 0.56418958354775629_DP /
! ( pim1= sqrt(1/pi) )
ax = abs (x)
if (ax > 26.0_DP) then
!
! erfc(26.0)=10^(-296); erfc( 9.0)=10^(-37);
!
qe_erfc = 0.0_DP
elseif (ax > 4.0_DP) then
x2 = x**2
xm2 = (1.0_DP / ax) **2
qe_erfc = (1.0_DP / ax) * exp ( - x2) * (pim1 + xm2 * (p3 (1) &
+ xm2 * (p3 (2) + xm2 * (p3 (3) + xm2 * (p3 (4) + xm2 * p3 (5) &
) ) ) ) / (q3 (1) + xm2 * (q3 (2) + xm2 * (q3 (3) + xm2 * &
(q3 (4) + xm2 * q3 (5) ) ) ) ) )
elseif (ax > 0.47_DP) then
x2 = x**2
qe_erfc = exp ( - x2) * (p2 (1) + ax * (p2 (2) + ax * (p2 (3) &
+ ax * (p2 (4) + ax * (p2 (5) + ax * (p2 (6) + ax * (p2 (7) &
+ ax * p2 (8) ) ) ) ) ) ) ) / (q2 (1) + ax * (q2 (2) + ax * &
(q2 (3) + ax * (q2 (4) + ax * (q2 (5) + ax * (q2 (6) + ax * &
(q2 (7) + ax * q2 (8) ) ) ) ) ) ) )
else
qe_erfc = 1.0_DP - qe_erf (ax)
endif
!
! erf(-x)=-erf(x) => erfc(-x) = 2-erfc(x)
!
if (x < 0.0_DP) qe_erfc = 2.0_DP - qe_erfc
!
return
end function qe_erfc
!
!---------------------------------------------------------------------
function gauss_freq (x)
!---------------------------------------------------------------------
!
! gauss_freq(x) = (1+erf(x/sqrt(2)))/2 = erfc(-x/sqrt(2))/2
! - See comments in erf
!
use kinds, only : DP
implicit none
real(DP),intent(in) :: x
real(DP) :: gauss_freq
real(DP), parameter :: c = 0.7071067811865475_DP
! ( c= sqrt(1/2) )
real(DP), external :: qe_erfc
!
gauss_freq = 0.5_DP * qe_erfc ( - x * c)
!
return
end function gauss_freq
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/g77/980310-2.f | 209 | 2053 | c { dg-do compile }
C unable to confirm this bug on egcs 1.0.1 for i586-pc-sco3.2v5.0.4 robertl
C
C Date: Sat, 23 Aug 1997 00:47:53 -0400 (EDT)
C From: David Bristow <dbristow@lynx.dac.neu.edu>
C To: egcs-bugs@cygnus.com
C Subject: g77 crashes compiling Dungeon
C Message-ID: <Pine.OSF.3.91.970823003521.11281A-100000@lynx.dac.neu.edu>
C
C The following small segment of Dungeon (the adventure that became the
C commercial hit Zork) causes an internal error in f771. The platform is
C i586-pc-linux-gnulibc1, the compiler is egcs-ss-970821 (g77-GNU Fortran
C 0.5.21-19970811)
C
C --cut here--cut here--cut here--cut here--cut here--cut here--
C g77 --verbose -fugly -fvxt -c subr_.f
C g77 version 0.5.21-19970811
C gcc --verbose -fugly -fvxt -xf77 subr_.f -xnone -lf2c -lm
C Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.01/specs
C gcc version egcs-2.90.01 970821 (gcc2-970802 experimental)
C /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.01/f771 subr_.f -fset-g77-defaults -quiet -dumpbase subr_.f -version -fversion -fugly -fvxt -o /tmp/cca23974.s
C f771: warning: -fugly is overloaded with meanings and likely to be removed;
C f771: warning: use only the specific -fugly-* options you need
C GNU F77 version egcs-2.90.01 970821 (gcc2-970802 experimental) (i586-pc-linux-gnulibc1) compiled by GNU C version egcs-2.90.01 970821 (gcc2-970802 experimental).
C GNU Fortran Front End version 0.5.21-19970811
C f/com.c:941: failed assertion `TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (e))'
C gcc: Internal compiler error: program f771 got fatal signal 6
C --cut here--cut here--cut here--cut here--cut here--cut here--
C
C Here's the FORTRAN code, it's basically a single subroutine from subr.f
C in the Dungeon source, slightly altered (the original calls RAN(), which
C doesn't exist in the g77 runtime)
C
C RND - Return a random integer mod n
C
INTEGER FUNCTION RND (N)
IMPLICIT INTEGER (A-Z)
REAL RAND
COMMON /SEED/ RNSEED
RND = RAND(RNSEED)*FLOAT(N)
RETURN
END
| gpl-2.0 |
nvarini/espresso_adios | Modules/control_flags.f90 | 1 | 14440 | !
! Copyright (C) 2002-2011 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!=----------------------------------------------------------------------------=!
MODULE control_flags
!=--------------------------------------------------------------------------=!
!
! ... this module contains all basic variables that controls the
! ... execution flow
!----------------------------------------------
!
USE kinds
USE parameters
!
IMPLICIT NONE
!
SAVE
!
PRIVATE
!
TYPE convergence_criteria
!
LOGICAL :: active
INTEGER :: nstep
REAL(DP) :: ekin
REAL(DP) :: derho
REAL(DP) :: force
!
END TYPE convergence_criteria
!
PUBLIC :: tbeg, nomore, nbeg, isave, iprint, tv0rd, tzeroc, tzerop, &
tfor, tpre, tzeroe, tsde, tsdp, tsdc, taurdr, &
ndr, ndw, tortho, ortho_eps, ortho_max, tstress, tprnfor, &
timing, memchk, tprnsfac, &
trane,dt_old,ampre, tranp, amprp, t_diis, t_diis_simple, &
t_diis_rot, tnosee, tnosep, tnoseh, tcp, tcap, tdamp, tdampions, &
tconvthrs, tolp, convergence_criteria, tionstep, nstepe, &
tsteepdesc, tatomicwfc, tscreen, gamma_only, force_pairing, &
lecrpa, tddfpt, smallmem
!
PUBLIC :: fix_dependencies, check_flags
PUBLIC :: tksw, trhor, thdyn, trhow
PUBLIC :: twfcollect, printwfc
PUBLIC :: lkpoint_dir
PUBLIC :: program_name
!
! ... declare execution control variables
!
CHARACTER(LEN=4) :: program_name = ' ' ! used to control execution flow
! inside module: 'PW' or 'CP'
!
LOGICAL :: trhor = .FALSE. ! read rho from unit 47 (only cp, seldom used)
LOGICAL :: trhow = .FALSE. ! CP code, write rho to restart dir
LOGICAL :: tksw = .FALSE. ! CP: write Kohn-Sham states to restart dir
!
LOGICAL :: tsde = .FALSE. ! electronic steepest descent
LOGICAL :: tzeroe = .FALSE. ! set to zero the electronic velocities
LOGICAL :: tfor = .FALSE. ! move the ions ( calculate forces )
LOGICAL :: tsdp = .FALSE. ! ionic steepest descent
LOGICAL :: tzerop = .FALSE. ! set to zero the ionic velocities
LOGICAL :: tprnfor = .FALSE. ! print forces to standard output
LOGICAL :: taurdr = .FALSE. ! read ionic position from standard input
LOGICAL :: tv0rd = .FALSE. ! read ionic velocities from standard input
LOGICAL :: tpre = .FALSE. ! calculate stress, and (in fpmd) variable cell dynamic
LOGICAL :: thdyn = .FALSE. ! variable-cell dynamics (only cp)
LOGICAL :: tsdc = .FALSE. ! cell geometry steepest descent
LOGICAL :: tzeroc = .FALSE. ! set to zero the cell geometry velocities
LOGICAL :: tstress = .FALSE. ! print stress to standard output
LOGICAL :: tortho = .FALSE. ! use iterative orthogonalization
LOGICAL :: timing = .FALSE. ! print out timing information
LOGICAL :: memchk = .FALSE. ! check for memory leakage
LOGICAL :: tprnsfac = .FALSE. ! print out structure factor
LOGICAL :: tdamp = .FALSE. ! Use damped dynamics for electrons
LOGICAL :: tdampions = .FALSE. ! Use damped dynamics for ions
LOGICAL :: tatomicwfc = .FALSE. ! Use atomic wavefunctions as starting guess for ch. density
LOGICAL :: tscreen = .FALSE. ! Use screened coulomb potentials for cluster calculations
LOGICAL :: twfcollect = .FALSE. ! Collect wave function in the restart file at the end of run.
LOGICAL :: lkpoint_dir = .TRUE. ! save each k point in a different directory
INTEGER :: printwfc = -1 ! Print wave functions, temporarely used only by ensemble-dft
LOGICAL :: force_pairing = .FALSE. ! Force pairing
LOGICAL :: lecrpa = .FALSE. ! RPA correlation energy request
LOGICAL :: tddfpt = .FALSE. ! use tddfpt specific tweaks to ph.x routines
LOGICAL :: smallmem = .FALSE. ! the memory per task is small
INTEGER :: adios_mode = 0 ! adios io mode
!
TYPE (convergence_criteria) :: tconvthrs
! thresholds used to check GS convergence
!
! ... Ionic vs Electronic step frequency
! ... When "ion_nstep > 1" and "electron_dynamics = 'md' | 'sd' ", ions are
! ... propagated every "ion_nstep" electronic step only if the electronic
! ... "ekin" is lower than "ekin_conv_thr"
!
LOGICAL :: tionstep = .FALSE.
INTEGER :: nstepe = 1
! parameters to control how many electronic steps
! between ions move
LOGICAL :: tsteepdesc = .FALSE.
! parameters for electronic steepest desceent
INTEGER :: nbeg = 0 ! internal code for initialization ( -1, 0, 1, 2, .. )
INTEGER :: ndw = 0 !
INTEGER :: ndr = 0 !
INTEGER :: nomore = 0 !
INTEGER :: iprint =10 ! print output every iprint step
INTEGER :: isave = 0 ! write restart to ndr unit every isave step
!
! ... .TRUE. if only gamma point is used
!
LOGICAL :: gamma_only = .TRUE.
!
! This variable is used whenever a timestep change is requested
!
REAL(DP) :: dt_old = -1.0_DP
!
! ... Wave function randomization
!
LOGICAL :: trane = .FALSE.
REAL(DP) :: ampre = 0.0_DP
!
! ... Ionic position randomization
!
LOGICAL :: tranp(nsx) = .FALSE.
REAL(DP) :: amprp(nsx) = 0.0_DP
!
! ... Read the cell from standard input
!
LOGICAL :: tbeg = .FALSE.
!
! ... Flags that controls DIIS electronic minimization
!
LOGICAL :: t_diis = .FALSE.
LOGICAL :: t_diis_simple = .FALSE.
LOGICAL :: t_diis_rot = .FALSE.
!
! ... Flag controlling the Nose thermostat for electrons
!
LOGICAL :: tnosee = .FALSE.
!
! ... Flag controlling the Nose thermostat for the cell
!
LOGICAL :: tnoseh = .FALSE.
!
! ... Flag controlling the Nose thermostat for ions
!
LOGICAL :: tnosep = .FALSE.
LOGICAL :: tcap = .FALSE.
LOGICAL :: tcp = .FALSE.
REAL(DP) :: tolp = 0.0_DP ! tolerance for temperature variation
!
REAL(DP), PUBLIC :: &
ekin_conv_thr = 0.0_DP, &! conv. threshold for fictitious e. kinetic energy
etot_conv_thr = 0.0_DP, &! conv. threshold for DFT energy
forc_conv_thr = 0.0_DP ! conv. threshold for atomic forces
INTEGER, PUBLIC :: &
ekin_maxiter = 100, &! max number of iter. for ekin convergence
etot_maxiter = 100, &! max number of iter. for etot convergence
forc_maxiter = 100 ! max number of iter. for atomic forces conv.
!
! ... Several variables controlling the run ( used mainly in PW calculations )
!
! ... logical flags controlling the execution
!
LOGICAL, PUBLIC :: &
lscf =.FALSE., &! if .TRUE. the calc. is selfconsistent
lbfgs =.FALSE., &! if .TRUE. the calc. is a relaxation based on BFGS
lmd =.FALSE., &! if .TRUE. the calc. is a dynamics
llang =.FALSE., &! if .TRUE. the calc. is Langevin dynamics
use_SMC =.FALSE., &! if .TRUE. use the Smart Monte Carlo method
lwf =.FALSE., &! if .TRUE. the calc. is with wannier functions
!=================================================================
!exx_wf related
lwfnscf =.FALSE., &
lwfpbe0nscf=.FALSE.,&
!=================================================================
lbands =.FALSE., &! if .TRUE. the calc. is band structure
lconstrain=.FALSE.,&! if .TRUE. the calc. is constraint
ldamped =.FALSE., &! if .TRUE. the calc. is a damped dynamics
llondon =.FALSE., & ! if .TRUE. compute Grimme D2 dispersion corrections
ts_vdw =.FALSE., & ! as above for Tkatchenko-Scheffler disp.corrections
lxdm =.FALSE., & ! if .TRUE. compute XDM dispersion corrections
restart =.FALSE. ! if .TRUE. restart from results of a preceding run
!
! ... pw self-consistency
!
INTEGER, PUBLIC :: &
ngm0, &! used in mix_rho
niter, &! the maximum number of iteration
nmix, &! the number of iteration kept in the history
imix ! the type of mixing (0=plain,1=TF,2=local-TF)
REAL(DP), PUBLIC :: &
mixing_beta, &! the mixing parameter
tr2 ! the convergence threshold for potential
LOGICAL, PUBLIC :: &
conv_elec ! if .TRUE. electron convergence has been reached
! next 3 variables used for EXX calculations
LOGICAL, PUBLIC :: &
adapt_thr ! if .TRUE. an adaptive convergence threshold is used
! for the scf cycle in an EXX calculation.
REAL(DP), PUBLIC :: &
tr2_init, &! initial value of tr2 for adaptive thresholds
tr2_multi ! the dexx multiplier for adaptive thresholds
! tr2 = tr2_multi * dexx after each V_exx update
LOGICAL, PUBLIC :: scf_must_converge
!
! ... pw diagonalization
!
REAL(DP), PUBLIC :: &
ethr ! the convergence threshold for eigenvalues
INTEGER, PUBLIC :: &
david, &! max dimension of subspace in Davidson diagonalization
isolve, &! Davidson or CG or DIIS diagonalization
max_cg_iter, &! maximum number of iterations in a CG di
diis_buff, &! dimension of the buffer in diis
diis_ndim ! dimension of reduced basis in DIIS
LOGICAL, PUBLIC :: &
diago_full_acc = .FALSE. ! if true, empty eigenvalues have the same
! accuracy of the occupied ones
!
! ... wfc and rho extrapolation
!
REAL(DP), PUBLIC :: &
alpha0, &! the mixing parameters for the extrapolation
beta0 ! of the starting potential
INTEGER, PUBLIC :: &
history, &! number of old steps available for potential updating
pot_order = 0, &! type of potential updating ( see update_pot )
wfc_order = 0 ! type of wavefunctions updating ( see update_pot )
!
! ... ionic dynamics
!
INTEGER, PUBLIC :: &
nstep = 1, &! number of ionic steps
istep = 0 ! current ionic step
LOGICAL, PUBLIC :: &
conv_ions ! if .TRUE. ionic convergence has been reached
REAL(DP), PUBLIC :: &
upscale ! maximum reduction of convergence threshold
!
! ... system's symmetries
!
LOGICAL, PUBLIC :: &
noinv = .FALSE. ! if .TRUE. q=>-q symmetry not used in k-point generation
!
! ... phonon calculation
!
INTEGER, PUBLIC :: &
modenum ! for single mode phonon calculation
!
! ... printout control
!
INTEGER, PUBLIC :: &
io_level = 1 ! variable controlling the amount of I/O to file
INTEGER, PUBLIC :: & ! variable controlling the amount of I/O to output
iverbosity = 0 ! -1 minimal, 0 low, 1 medium, 2 high, 3 debug
!
! ... miscellany
!
LOGICAL, PUBLIC :: &
use_para_diag = .FALSE. ! if .TRUE. a fully distributed memory iteration
! algorithm and parallel Householder algorithm are used
!
LOGICAL, PUBLIC :: &
remove_rigid_rot = .FALSE. ! if .TRUE. the total torque acting on the atoms
! is removed
LOGICAL, PUBLIC :: &
do_makov_payne = .FALSE. ! if .TRUE. makov-payne correction for isolated
! system is used
!
INTEGER :: ortho_max = 0 ! maximum number of iterations in routine ortho
REAL(DP) :: ortho_eps = 0.0_DP ! threshold for convergence in routine ortho
!
! ... Number of neighbouring cell to consider in ewald sum
!
INTEGER, PUBLIC :: iesr = 1
!
! ... Real-sapce algorithms
!
LOGICAL, PUBLIC :: tqr=.FALSE. ! if true the Q are in real space
!LOGICAL, PUBLIC :: real_space=.false. ! beta functions in real space
!
! ... External Forces on Ions
!
LOGICAL, PUBLIC :: textfor = .FALSE.
!
! ... end of module-scope declarations
!
!=--------------------------------------------------------------------------=!
CONTAINS
!=--------------------------------------------------------------------------=!
!
!------------------------------------------------------------------------
SUBROUTINE fix_dependencies()
!------------------------------------------------------------------------
!
IMPLICIT NONE
!
! ... if thdyn = .FALSE. set TSDC and TZEROC to .FALSE. too.
!
IF ( .NOT. thdyn ) THEN
!
tsdc = .FALSE.
tzeroc = .FALSE.
!
END IF
!
IF ( .NOT. tfor ) THEN
!
tzerop = .FALSE.
tv0rd = .FALSE.
tsdp = .FALSE.
tcp = .FALSE.
tcap = .FALSE.
tnosep = .FALSE.
!
ELSE
!
IF ( tsdp ) THEN
!
tcp = .FALSE.
tcap = .FALSE.
tnosep = .FALSE.
tv0rd = .FALSE.
!
END IF
!
IF ( tv0rd ) tzerop = .TRUE.
!
END IF
!
IF ( tsde ) tnosee = .FALSE.
!
CALL check_flags()
!
RETURN
!
END SUBROUTINE fix_dependencies
!
!------------------------------------------------------------------------
SUBROUTINE check_flags()
!------------------------------------------------------------------------
!
! ... do some checks for consistency
!
IF ( tnosee .AND. t_diis ) &
CALL errore( ' control_flags ', 'DIIS + ELECT. NOSE ? ', 0 )
!
!IF ( tortho .AND. t_diis ) &
! CALL errore(' control_flags ','DIIS, ORTHO NOT PERMITTED',0)
!
IF ( tnosep .AND. tcp ) &
CALL errore( ' control_flags ', ' TCP AND TNOSEP BOTH TRUE', 0 )
!
IF ( tnosep .AND. tcap ) &
CALL errore( ' control_flags ', ' TCAP AND TNOSEP BOTH TRUE', 0 )
!
IF ( tcp .AND. tcap ) &
CALL errore( ' control_flags ', ' TCP AND TCAP BOTH TRUE', 0 )
!
IF ( tv0rd .AND. tsdp ) &
CALL errore( ' control_flags ', &
& ' READING IONS VELOCITY WITH STEEPEST D.', 0 )
!
RETURN
!
END SUBROUTINE check_flags
!
END MODULE control_flags
| gpl-2.0 |
nvarini/espresso_adios | PWCOND/src/free_mem.f90 | 14 | 1382 | !
! Copyright (C) 2003 A. Smogunov
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
subroutine free_mem
!
! Deallocates memory
!
use cond
implicit none
!
! From allocate_cond
!
deallocate(psiperl)
deallocate(zkl)
deallocate(zkrl)
deallocate(psipers)
deallocate(zks)
deallocate(zkrs)
deallocate(psiperr)
deallocate(zkr)
deallocate(zkrr)
deallocate(newbg)
deallocate(fun0)
deallocate(fun1)
deallocate(fund0)
deallocate(fund1)
IF (lorb) THEN
deallocate( funz0 )
deallocate( korbl )
deallocate( korbr )
ENDIF
IF (norbf>0) THEN
deallocate(funl0)
deallocate(funl1)
deallocate(fundl0)
deallocate(fundl1)
deallocate(intw1)
deallocate(intw2)
END IF
deallocate(kvall)
deallocate(kfunl)
deallocate(kfundl)
IF (nocrosl>0) THEN
deallocate(kintl)
deallocate(kcoefl)
END IF
if (ikind.ne.0) then
deallocate(kvalr)
deallocate(kfunr)
deallocate(kfundr)
IF (nocrosr>0) THEN
deallocate(kintr)
deallocate(kcoefr)
END IF
endif
!
! From init_gper
!
if (lorb) deallocate( nl_2ds )
if (lorb) deallocate( nl_2d )
deallocate(gper)
deallocate(ninsh)
deallocate(gnsh)
return
end subroutine free_mem
| gpl-2.0 |
rhristov/gcc-modified | libgomp/testsuite/libgomp.oacc-fortran/reduction-3.f90 | 44 | 3225 | ! { dg-do run }
! double precision reductions
program reduction_3
implicit none
integer, parameter :: n = 10, vl = 2
integer :: i
double precision, parameter :: e = .001
double precision :: vresult, result
logical :: lresult, lvresult
double precision, dimension (n) :: array
do i = 1, n
array(i) = i
end do
result = 0
vresult = 0
! '+' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(+:result)
do i = 1, n
result = result + array(i)
end do
!$acc end parallel
! Verify the results
do i = 1, n
vresult = vresult + array(i)
end do
if (abs (result - vresult) .ge. e) call abort
result = 1
vresult = 1
! '*' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(*:result)
do i = 1, n
result = result * array(i)
end do
!$acc end parallel
! Verify the results
do i = 1, n
vresult = vresult * array(i)
end do
if (result.ne.vresult) call abort
result = 0
vresult = 0
! 'max' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(max:result)
do i = 1, n
result = max (result, array(i))
end do
!$acc end parallel
! Verify the results
do i = 1, n
vresult = max (vresult, array(i))
end do
if (result.ne.vresult) call abort
result = 1
vresult = 1
! 'min' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(min:result)
do i = 1, n
result = min (result, array(i))
end do
!$acc end parallel
! Verify the results
do i = 1, n
vresult = min (vresult, array(i))
end do
if (result.ne.vresult) call abort
result = 1
vresult = 1
! '.and.' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(.and.:lresult)
do i = 1, n
lresult = lresult .and. (array(i) .ge. 5)
end do
!$acc end parallel
! Verify the results
do i = 1, n
lvresult = lvresult .and. (array(i) .ge. 5)
end do
if (result.ne.vresult) call abort
lresult = .false.
lvresult = .false.
! '.or.' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(.or.:lresult)
do i = 1, n
lresult = lresult .or. (array(i) .ge. 5)
end do
!$acc end parallel
! Verify the results
do i = 1, n
lvresult = lvresult .or. (array(i) .ge. 5)
end do
if (result.ne.vresult) call abort
lresult = .false.
lvresult = .false.
! '.eqv.' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(.eqv.:lresult)
do i = 1, n
lresult = lresult .eqv. (array(i) .ge. 5)
end do
!$acc end parallel
! Verify the results
do i = 1, n
lvresult = lvresult .eqv. (array(i) .ge. 5)
end do
if (result.ne.vresult) call abort
lresult = .false.
lvresult = .false.
! '.neqv.' reductions
!$acc parallel vector_length(vl) num_gangs(1)
!$acc loop reduction(.neqv.:lresult)
do i = 1, n
lresult = lresult .neqv. (array(i) .ge. 5)
end do
!$acc end parallel
! Verify the results
do i = 1, n
lvresult = lvresult .neqv. (array(i) .ge. 5)
end do
if (result.ne.vresult) call abort
end program reduction_3
| gpl-2.0 |
surhudm/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 |
bgin/MissileSimulation | External/FFTPACK/cfft1i.f | 1 | 2472 | C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C * *
C * copyright (c) 2011 by UCAR *
C * *
C * University Corporation for Atmospheric Research *
C * *
C * all rights reserved *
C * *
C * FFTPACK version 5.1 *
C * *
C * A Fortran Package of Fast Fourier *
C * *
C * Subroutines and Example Programs *
C * *
C * by *
C * *
C * Paul Swarztrauber and Dick Valent *
C * *
C * of *
C * *
C * the National Center for Atmospheric Research *
C * *
C * Boulder, Colorado (80307) U.S.A. *
C * *
C * which is sponsored by *
C * *
C * the National Science Foundation *
C * *
C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
SUBROUTINE CFFT1I (N, WSAVE, LENSAV, IER)
INTEGER N, LENSAV, IER
REAL WSAVE(LENSAV)
C
IER = 0
C
IF (LENSAV .LT. 2*N + INT(LOG(REAL(N))/LOG(2.)) + 4) THEN
IER = 2
CALL XERFFT ('CFFTMI ', 3)
ENDIF
C
IF (N .EQ. 1) RETURN
C
IW1 = N+N+1
CALL MCFTI1 (N,WSAVE,WSAVE(IW1),WSAVE(IW1+1))
C
RETURN
END
| mit |
rhristov/gcc-modified | gcc/testsuite/gfortran.fortran-torture/execute/forall_1.f90 | 191 | 1679 | ! Program to test FORALL construct
program forall_1
call actual_variable ()
call negative_stride ()
call forall_index ()
contains
subroutine actual_variable ()
integer:: x = -1
integer a(3,4)
j = 100
! Actual variable 'x' and 'j' used as FORALL index
forall (x = 1:3, j = 1:4)
a (x,j) = j
end forall
if (any (a.ne.reshape ((/1,1,1,2,2,2,3,3,3,4,4,4/), (/3,4/)))) call abort
if ((x.ne.-1).or.(j.ne.100)) call abort
call actual_variable_2 (x, j, a)
end subroutine
subroutine actual_variable_2(x, j, a)
integer x,j,x1,j1
integer a(3,4), b(3,4)
! Actual variable 'x' and 'j' used as FORALL index.
forall (x=3:1:-1, j=4:1:-1)
a(x,j) = j
b(x,j) = j
end forall
if (any (a.ne.reshape ((/1,1,1,2,2,2,3,3,3,4,4,4/), (/3,4/)))) call abort
if (any (b.ne.reshape ((/1,1,1,2,2,2,3,3,3,4,4,4/), (/3,4/)))) call abort
if ((x.ne.-1).or.(j.ne.100)) call abort
end subroutine
subroutine negative_stride ()
integer a(3,4)
integer x, j
! FORALL with negative stride
forall (x = 3:1:-1, j = 4:1:-1)
a(x,j) = j + x
end forall
if (any (a.ne.reshape ((/2,3,4,3,4,5,4,5,6,5,6,7/), (/3,4/)))) call abort
end subroutine
subroutine forall_index
integer a(32,32)
! FORALL with arbitrary number indexes
forall (i1=1:2,i2=1:2,i3=1:2,i4=1:2,i5=1:2,i6=1:2,i7=1:2,i8=1:2,i9=1:2,&
i10=1:2)
a(i1+2*i3+4*i5+8*i7+16*i9-30,i2+2*i4+4*i6+8*i8+16*i10-30) = 1
end forall
if ((a(5,5).ne.1).or. (a(32,32).ne.1)) call abort
end subroutine
end
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/intrinsic_modulo_1.f90 | 190 | 1101 | ! { dg-do run }
! testcase from PR 19032 adapted for testsuite
! Our implementation of modulo was wrong for P = 1 and P = -1,
! both in the real and the integer case
program main
integer, parameter :: n=16
real, dimension(n) :: ar, br, modulo_result, floor_result
integer, dimension(n) :: ai, bi , imodulo_result, ifloor_result
ai(1:4) = 5
ai(5:8) = -5
ai(9:12) = 1
ai(13:16) = -1
bi(1:4) = (/ 3,-3, 1, -1/)
bi(5:8) = bi(1:4)
bi(9:12) = bi(1:4)
bi(13:16) = bi(1:4)
ar = ai
br = bi
modulo_result = modulo(ar,br)
imodulo_result = modulo(ai,bi)
floor_result = ar-floor(ar/br)*br
ifloor_result = nint(real(ai-floor(real(ai)/real(bi))*bi))
do i=1,n
if (modulo_result(i) /= floor_result(i) ) then
! print "(A,4F5.0)" ,"real case failed: ", &
! ar(i),br(i), modulo_result(i), floor_result(i)
call abort()
end if
if (imodulo_result(i) /= ifloor_result(i)) then
! print "(A,4I5)", "int case failed: ", &
! ai(i), bi(i), imodulo_result(i), ifloor_result(i)
call abort ()
end if
end do
end program main
| gpl-2.0 |
kito-cheng/riscv-gcc | libgfortran/generated/_abs_i16.F90 | 3 | 1461 | ! Copyright (C) 2002-2019 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_INTEGER_16)
elemental function _gfortran_specific__abs_i16 (parm)
integer (kind=16), intent (in) :: parm
integer (kind=16) :: _gfortran_specific__abs_i16
_gfortran_specific__abs_i16 = abs (parm)
end function
#endif
| gpl-2.0 |
fthoele/espresso-5.4.0 | Modules/read_upf_v2.f90 | 16 | 29113 | !
! Copyright (C) 2008-2011 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!=----------------------------------------------------------------------------=!
MODULE read_upf_v2_module
!=----------------------------------------------------------------------------=!
! this module handles the reading of pseudopotential data
! ... declare modules
USE kinds, ONLY: DP
USE pseudo_types, ONLY: pseudo_upf
USE radial_grids, ONLY: radial_grid_type
USE parser, ONLY : version_compare
USE iotk_module
!
PRIVATE
PUBLIC :: read_upf_v2
CONTAINS
!------------------------------------------------+
SUBROUTINE read_upf_v2(u, upf, grid, ierr) !
!---------------------------------------------+
! Read pseudopotential in UPF format version 2, uses iotk
!
USE pseudo_types, ONLY: nullify_pseudo_upf, deallocate_pseudo_upf
USE radial_grids, ONLY: radial_grid_type, nullify_radial_grid
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
TYPE(radial_grid_type),OPTIONAL,INTENT(INOUT),TARGET :: grid
!
INTEGER,OPTIONAL,INTENT(OUT):: ierr ! /= 0 if something went wrong
CHARACTER(len=iotk_namlenx) :: root
CHARACTER(len=iotk_attlenx) :: attr
INTEGER :: ierr_
LOGICAL :: found
LOGICAL,EXTERNAL :: matches
CHARACTER(len=6),PARAMETER :: max_version = '2.0.1'
!
! Prepare the type . Should be done where upf is instantiated
! CALL deallocate_pseudo_upf(upf)
! CALL nullify_pseudo_upf(upf)
!
! IF(present(grid)) call nullify_radial_grid(grid)
! nullify(upf%grid)
!
! Initialize the file
CALL iotk_open_read(u, attr=attr, root=root, ierr=ierr_)
!
IF((abs(ierr_)>0) .or. .not. matches('UPF',root) ) THEN
!
CALL iotk_close_read(u,ierr=ierr_)
IF(.not. present(ierr)) &
CALL errore('read_upf_v2','Cannot open UPF file.',1)
ierr = 1
RETURN
ENDIF
CALL iotk_scan_attr(attr, 'version', upf%nv)
IF (version_compare(upf%nv, max_version) == 'newer') &
CALL errore('read_upf_v2',&
'Unknown UPF format version: '//TRIM(upf%nv),1)
!
! Skip human-readable header
CALL iotk_scan_begin(u,'PP_INFO',found=found)
if(found) CALL iotk_scan_end(u,'PP_INFO')
!
! Read machine-readable header
CALL read_upf_header(u, upf)
IF(upf%tpawp .and. .not. present(grid)) &
CALL errore('read_upf_v2', 'PAW requires a radial_grid_type.', 1)
!
! CHECK for bug in version 2.0.0 of UPF file
IF ( version_compare(upf%nv, '2.0.1') == 'older' .and. upf%tvanp .and. &
.not. upf%tpawp ) CALL errore('read_upf_v2',&
'Ultrasoft pseudopotentials in UPF format v.2.0.0 are &
& affected by a bug compromising their quality. Please &
& regenerate pseudopotential file for '//TRIM(upf%psd), 1)
! Read radial grid mesh
CALL read_upf_mesh(u, upf, grid)
! Read non-linear core correction charge
ALLOCATE( upf%rho_atc(upf%mesh) )
IF(upf%nlcc) THEN
CALL iotk_scan_dat(u, 'PP_NLCC', upf%rho_atc)
ELSE
! A null core charge simplifies several functions, mostly in PAW
upf%rho_atc(1:upf%mesh) = 0._dp
ENDIF
! Read local potential
IF(.not. upf%tcoulombp) THEN
ALLOCATE( upf%vloc(upf%mesh) )
CALL iotk_scan_dat(u, 'PP_LOCAL', upf%vloc)
ENDIF
! Read nonlocal components: projectors, augmentation, hamiltonian elements
CALL read_upf_nonlocal(u, upf)
! Read initial pseudo wavefunctions
! (usually only wfcs with occupancy > 0)
CALL read_upf_pswfc(u, upf)
! Read all-electron and pseudo wavefunctions
CALL read_upf_full_wfc(u, upf)
! Read valence atomic density (used for initial density)
ALLOCATE( upf%rho_at(upf%mesh) )
CALL iotk_scan_dat(u, 'PP_RHOATOM', upf%rho_at)
! Read additional info for full-relativistic calculation
CALL read_upf_spin_orb(u, upf)
! Read additional data for PAW (All-electron charge, wavefunctions, vloc..)
CALL read_upf_paw(u, upf)
! Read data for gipaw reconstruction
CALL read_upf_gipaw(u, upf)
!
! Close the file (not the unit!)
CALL iotk_close_read(u)
!
IF( present(ierr) ) ierr=0
RETURN
CONTAINS
!
SUBROUTINE read_upf_header(u, upf)
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
INTEGER :: ierr ! /= 0 if something went wrong
CHARACTER(len=iotk_attlenx) :: attr
CHARACTER(len=256) :: dft_buffer ! needed to allow the string defining the
! DFT flavor to be longer than upf%dft
! (currntly 25) without getting iotk upset.
! An error message is issued if trimmed
! dft_buffer exceeds upf%dft size.
INTEGER :: len_buffer
!
INTEGER :: nw
!
! Read HEADER section with some initialization data
CALL iotk_scan_empty(u, 'PP_HEADER', attr=attr)
CALL iotk_scan_attr(attr, 'generated', upf%generated, default=' ')
CALL iotk_scan_attr(attr, 'author', upf%author, default='anonymous')
CALL iotk_scan_attr(attr, 'date', upf%date, default=' ')
CALL iotk_scan_attr(attr, 'comment', upf%comment, default=' ')
!
CALL iotk_scan_attr(attr, 'element', upf%psd)
CALL iotk_scan_attr(attr, 'pseudo_type', upf%typ)
CALL iotk_scan_attr(attr, 'relativistic', upf%rel)
!
CALL iotk_scan_attr(attr, 'is_ultrasoft', upf%tvanp)
CALL iotk_scan_attr(attr, 'is_paw', upf%tpawp)
CALL iotk_scan_attr(attr, 'is_coulomb', upf%tcoulombp, default=.false.)
!
CALL iotk_scan_attr(attr, 'has_so', upf%has_so, default=.false.)
CALL iotk_scan_attr(attr, 'has_wfc', upf%has_wfc, default=upf%tpawp)
CALL iotk_scan_attr(attr, 'has_gipaw', upf%has_gipaw, default=.false.)
!EMINE
CALL iotk_scan_attr(attr, 'paw_as_gipaw', upf%paw_as_gipaw, default=.false.)
!
CALL iotk_scan_attr(attr, 'core_correction',upf%nlcc)
! CALL iotk_scan_attr(attr, 'functional', upf%dft)
CALL iotk_scan_attr(attr, 'functional', dft_buffer)
len_buffer=len_trim(dft_buffer)
if (len_buffer > len(upf%dft)) &
call errore('read_upf_v2','String defining DFT is too long',len_buffer)
upf%dft=TRIM(dft_buffer)
CALL iotk_scan_attr(attr, 'z_valence', upf%zp)
CALL iotk_scan_attr(attr, 'total_psenergy', upf%etotps, default=0._dp)
CALL iotk_scan_attr(attr, 'wfc_cutoff', upf%ecutwfc, default=0._dp)
CALL iotk_scan_attr(attr, 'rho_cutoff', upf%ecutrho, default=0._dp)
CALL iotk_scan_attr(attr, 'l_max', upf%lmax, default=0)
CALL iotk_scan_attr(attr, 'l_max_rho', upf%lmax_rho, default=2*upf%lmax)
CALL iotk_scan_attr(attr, 'l_local', upf%lloc, default=0)
CALL iotk_scan_attr(attr, 'mesh_size', upf%mesh)
CALL iotk_scan_attr(attr, 'number_of_wfc', upf%nwfc)
CALL iotk_scan_attr(attr, 'number_of_proj', upf%nbeta)
!
!CALL iotk_scan_end(u, 'PP_HEADER')
!CALL debug_pseudo_upf(upf)
!
RETURN
END SUBROUTINE read_upf_header
!
SUBROUTINE read_upf_mesh(u, upf, grid)
USE radial_grids, ONLY: allocate_radial_grid
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
TYPE(radial_grid_type),OPTIONAL,INTENT(INOUT),TARGET :: grid
!
INTEGER :: ierr ! /= 0 if something went wrong
CHARACTER(len=iotk_attlenx) :: attr
LOGICAL :: found
!
CALL iotk_scan_begin(u, 'PP_MESH', attr=attr)
CALL iotk_scan_attr(attr, 'dx', upf%dx, default=0._dp)
CALL iotk_scan_attr(attr, 'mesh', upf%mesh, default=upf%mesh)
CALL iotk_scan_attr(attr, 'xmin', upf%xmin, default=0._dp)
CALL iotk_scan_attr(attr, 'rmax', upf%rmax, default=0._dp)
CALL iotk_scan_attr(attr, 'zmesh',upf%zmesh, default=0._dp)
IF (present(grid)) THEN
CALL allocate_radial_grid(grid, upf%mesh)
!
grid%dx = upf%dx
grid%mesh = upf%mesh
grid%xmin = upf%xmin
grid%rmax = upf%rmax
grid%zmesh = upf%zmesh
!
upf%grid => grid
upf%r => upf%grid%r
upf%rab => upf%grid%rab
ELSE
ALLOCATE( upf%r( upf%mesh ), upf%rab( upf%mesh ) )
ENDIF
!
CALL iotk_scan_dat(u, 'PP_R', upf%r(1:upf%mesh))
CALL iotk_scan_dat(u, 'PP_RAB', upf%rab(1:upf%mesh))
!
IF (present(grid)) THEN
! Reconstruct additional grids
upf%grid%r2 = upf%r**2
upf%grid%sqr = sqrt(upf%r)
upf%grid%rm1 = upf%r**(-1)
upf%grid%rm2 = upf%r**(-2)
upf%grid%rm3 = upf%r**(-3)
ENDIF
CALL iotk_scan_end(u, 'PP_MESH')
!
RETURN
END SUBROUTINE read_upf_mesh
!
SUBROUTINE read_upf_nonlocal(u, upf)
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
CHARACTER(len=iotk_attlenx) :: attr
!
INTEGER :: nb,mb,ln,lm,l,nmb,ierr=0
!INTEGER :: nb_=-1,mb_=-1,l_=-1,nmb_=-1
REAL(DP):: zeros(upf%mesh)
LOGICAL :: isnull, found
zeros=0._dp
!
! modified by AF
!IF (upf%tcoulombp) RETURN
IF (upf%tcoulombp) upf%nbeta = 0
!
! Allocate space for non-local part
IF ( upf%nbeta == 0) then
upf%nqf = 0
upf%nqlc= 0
upf%qqq_eps= -1._dp
upf%kkbeta = 0
ALLOCATE( upf%kbeta(1), &
upf%lll(1), &
upf%beta(upf%mesh,1), &
upf%dion(1,1), &
upf%rinner(1), &
upf%qqq(1,1), &
upf%qfunc(upf%mesh,1),&
upf%qfcoef(1,1,1,1), &
upf%rcut(1), &
upf%rcutus(1), &
upf%els_beta(1) )
! <AF>
!CALL iotk_scan_end(u, 'PP_NONLOCAL')
RETURN
END IF
!
! <AF>
CALL iotk_scan_begin(u, 'PP_NONLOCAL')
!
ALLOCATE( upf%kbeta(upf%nbeta), &
upf%lll(upf%nbeta), &
upf%beta(upf%mesh, upf%nbeta), &
upf%dion(upf%nbeta, upf%nbeta),&
upf%rcut(upf%nbeta), &
upf%rcutus(upf%nbeta), &
upf%els_beta(upf%nbeta) )
!
! Read the projectors:
DO nb = 1,upf%nbeta
CALL iotk_scan_dat(u, 'PP_BETA'//iotk_index( nb ), &
upf%beta(:,nb), attr=attr)
CALL iotk_scan_attr(attr, 'label', upf%els_beta(nb), default='Xn')
CALL iotk_scan_attr(attr, 'angular_momentum', upf%lll(nb))
CALL iotk_scan_attr(attr, 'cutoff_radius_index', upf%kbeta(nb), default=upf%mesh)
CALL iotk_scan_attr(attr, 'cutoff_radius', upf%rcut(nb), default=0._dp)
CALL iotk_scan_attr(attr, 'ultrasoft_cutoff_radius', upf%rcutus(nb), default=0._dp)
!
! Old version of UPF PPs v.2 contained an error in the tag.
! To be able to read the old PPs we need the following
!
IF ( upf%rcutus(nb)==0._DP) &
CALL iotk_scan_attr(attr,'norm_conserving_radius',upf%rcutus(nb), &
default=0._dp)
ENDDO
!
! Read the hamiltonian terms D_ij
CALL iotk_scan_dat(u, 'PP_DIJ', upf%dion, attr=attr)
! CALL iotk_scan_attr(attr, 'non_zero_elements', upf%nd)
!
! Read the augmentation charge section
augmentation : &
IF(upf%tvanp .or. upf%tpawp) THEN
!
CALL iotk_scan_begin(u, 'PP_AUGMENTATION', attr=attr)
CALL iotk_scan_attr(attr, 'q_with_l', upf%q_with_l)
CALL iotk_scan_attr(attr, 'nqf', upf%nqf)
CALL iotk_scan_attr(attr, 'nqlc', upf%nqlc, default=2*upf%lmax+1)
IF (upf%tpawp) THEN
CALL iotk_scan_attr(attr,'shape', upf%paw%augshape, default='UNKNOWN')
CALL iotk_scan_attr(attr,'cutoff_r', upf%paw%raug, default=0._dp)
CALL iotk_scan_attr(attr,'cutoff_r_index', upf%paw%iraug, default=upf%mesh)
CALL iotk_scan_attr(attr,'l_max_aug', upf%paw%lmax_aug, default=upf%lmax_rho)
ENDIF
! a negative number means that all qfunc are stored
CALL iotk_scan_attr(attr,'augmentation_epsilon',upf%qqq_eps, default=-1._dp)
!
ALLOCATE( upf%rinner( upf%nqlc ) )
ALLOCATE( upf%qqq ( upf%nbeta, upf%nbeta ) )
IF ( upf%q_with_l ) THEN
ALLOCATE( upf%qfuncl ( upf%mesh, upf%nbeta*(upf%nbeta+1)/2, 0:2*upf%lmax ) )
upf%qfuncl=0._dp
ELSE
ALLOCATE( upf%qfunc (upf%mesh, upf%nbeta*(upf%nbeta+1)/2) )
ENDIF
!
! Read the integrals of the Q functions
CALL iotk_scan_dat(u, 'PP_Q',upf%qqq )
!
! read charge multipoles (only if PAW)
IF( upf%tpawp ) THEN
ALLOCATE(upf%paw%augmom(upf%nbeta,upf%nbeta, 0:2*upf%lmax))
CALL iotk_scan_dat(u, 'PP_MULTIPOLES', upf%paw%augmom)
ENDIF
!
! Read polinomial coefficients for Q_ij expansion at small radius
IF(upf%nqf <= 0) THEN
upf%rinner(:) = 0._dp
ALLOCATE( upf%qfcoef(1,1,1,1) )
upf%qfcoef = 0._dp
ELSE
ALLOCATE( upf%qfcoef( MAX( upf%nqf,1 ), upf%nqlc, upf%nbeta, upf%nbeta ) )
CALL iotk_scan_dat(u, 'PP_QFCOEF',upf%qfcoef, attr=attr)
CALL iotk_scan_dat(u, 'PP_RINNER',upf%rinner, attr=attr)
ENDIF
!
! Read augmentation charge Q_ij
ultrasoft_or_paw : &
IF( upf%tvanp) THEN
DO nb = 1,upf%nbeta
ln = upf%lll(nb)
DO mb = nb,upf%nbeta
lm = upf%lll(mb)
nmb = mb * (mb-1) /2 + nb
q_with_l : &
IF( upf%q_with_l ) THEN
DO l = abs(ln-lm),ln+lm,2 ! only even terms
CALL iotk_scan_dat(u, 'PP_QIJL'//iotk_index((/nb,mb,l/)),&
upf%qfuncl(:,nmb,l),default=zeros,attr=attr)
IF( upf%tpawp) upf%qfuncl(upf%paw%iraug+1:,nmb,l) = 0._dp
ENDDO
ELSE q_with_l
CALL iotk_scan_dat(u, 'PP_QIJ'//iotk_index((/nb,mb/)),&
upf%qfunc(:,nmb),attr=attr,default=zeros)
ENDIF q_with_l
ENDDO
ENDDO
!
ENDIF ultrasoft_or_paw
!
CALL iotk_scan_end(u, 'PP_AUGMENTATION')
!
ENDIF augmentation
!
! Maximum radius of beta projector: outer radius to integrate
upf%kkbeta = MAXVAL(upf%kbeta(1:upf%nbeta))
! For PAW augmentation charge may extend a bit further:
IF(upf%tpawp) upf%kkbeta = MAX(upf%kkbeta, upf%paw%iraug)
!
CALL iotk_scan_end(u, 'PP_NONLOCAL')
!
RETURN
END SUBROUTINE read_upf_nonlocal
!
SUBROUTINE read_upf_pswfc(u, upf)
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
INTEGER :: ierr ! /= 0 if something went wrong
CHARACTER(len=iotk_attlenx) :: attr
!
INTEGER :: nw
!
CALL iotk_scan_begin(u, 'PP_PSWFC')
!
ALLOCATE( upf%chi(upf%mesh,upf%nwfc) )
ALLOCATE( upf%els(upf%nwfc), &
upf%oc(upf%nwfc), &
upf%lchi(upf%nwfc), &
upf%nchi(upf%nwfc), &
upf%rcut_chi(upf%nwfc), &
upf%rcutus_chi(upf%nwfc), &
upf%epseu(upf%nwfc) &
)
!
DO nw = 1,upf%nwfc
CALL iotk_scan_dat(u, 'PP_CHI'//iotk_index(nw), &
upf%chi(:,nw), attr=attr)
CALL iotk_scan_attr(attr, 'label', upf%els(nw), default='Xn')
CALL iotk_scan_attr(attr, 'l', upf%lchi(nw))
CALL iotk_scan_attr(attr, 'occupation', upf%oc(nw))
CALL iotk_scan_attr(attr, 'n', upf%nchi(nw), default=upf%lchi(nw)-1)
CALL iotk_scan_attr(attr, 'pseudo_energy', upf%epseu(nw), default=0._dp)
CALL iotk_scan_attr(attr, 'cutoff_radius', upf%rcut_chi(nw),default=0._dp)
CALL iotk_scan_attr(attr, 'ultrasoft_cutoff_radius', upf%rcutus_chi(nw),default=0._dp)
ENDDO
!
CALL iotk_scan_end(u, 'PP_PSWFC')
!
RETURN
END SUBROUTINE read_upf_pswfc
SUBROUTINE read_upf_full_wfc(u, upf)
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
INTEGER :: ierr ! /= 0 if something went wrong
CHARACTER(len=iotk_attlenx) :: attr
LOGICAL :: exst
!
INTEGER :: nb
!
IF(.not. upf%has_wfc) RETURN
!
CALL iotk_scan_begin(u, 'PP_FULL_WFC')
!
ALLOCATE( upf%aewfc(upf%mesh, upf%nbeta) )
DO nb = 1,upf%nbeta
CALL iotk_scan_dat(u, 'PP_AEWFC'//iotk_index(nb), &
upf%aewfc(:,nb), attr=attr)
ENDDO
IF (upf%has_so .and. upf%tpawp) THEN
ALLOCATE( upf%paw%aewfc_rel(upf%mesh, upf%nbeta) )
nb_loop: DO nb = 1,upf%nbeta
CALL iotk_scan_dat(u, 'PP_AEWFC_REL'//iotk_index(nb), &
upf%paw%aewfc_rel(:,nb), attr=attr, found=exst)
IF (.not.exst) THEN
upf%paw%aewfc_rel=0.0_DP
EXIT nb_loop
ENDIF
ENDDO nb_loop
ENDIF
ALLOCATE( upf%pswfc(upf%mesh, upf%nbeta) )
DO nb = 1,upf%nbeta
CALL iotk_scan_dat(u, 'PP_PSWFC'//iotk_index(nb), &
upf%pswfc(:,nb), attr=attr)
ENDDO
CALL iotk_scan_end(u, 'PP_FULL_WFC')
!
END SUBROUTINE read_upf_full_wfc
!
SUBROUTINE read_upf_spin_orb(u, upf)
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
INTEGER :: ierr ! /= 0 if something went wrong
CHARACTER(len=iotk_attlenx) :: attr
!
INTEGER :: nw, nb
!
IF (.not. upf%has_so) RETURN
!
CALL iotk_scan_begin(u, 'PP_SPIN_ORB')
!
ALLOCATE (upf%nn(upf%nwfc))
ALLOCATE (upf%jchi(upf%nwfc))
!
DO nw = 1,upf%nwfc
CALL iotk_scan_empty(u, 'PP_RELWFC'//iotk_index(nw),&
attr=attr)
!CALL iotk_scan_attr(attr, 'els', upf%els(nw)) ! already read
CALL iotk_scan_attr(attr, 'nn', upf%nn(nw))
!CALL iotk_scan_attr(attr, 'lchi', upf%lchi(nw)) ! already read
CALL iotk_scan_attr(attr, 'jchi', upf%jchi(nw))
!CALL iotk_scan_attr(attr, 'oc', upf%oc(nw)) ! already read
ENDDO
!
ALLOCATE(upf%jjj(upf%nbeta))
!
DO nb = 1,upf%nbeta
CALL iotk_scan_empty(u, 'PP_RELBETA'//iotk_index(nb),&
attr=attr)
CALL iotk_scan_attr(attr, 'lll', upf%lll(nb))
CALL iotk_scan_attr(attr, 'jjj', upf%jjj(nb))
ENDDO
!
CALL iotk_scan_end(u, 'PP_SPIN_ORB')
!
RETURN
END SUBROUTINE read_upf_spin_orb
!
SUBROUTINE read_upf_paw(u, upf)
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
INTEGER :: ierr ! /= 0 if something went wrong
!
CHARACTER(len=iotk_attlenx) :: attr
!
INTEGER :: nb,nb1
IF (.not. upf%tpawp ) RETURN
CALL iotk_scan_begin(u, 'PP_PAW', attr=attr)
CALL iotk_scan_attr(attr, 'paw_data_format', upf%paw_data_format)
IF(upf%paw_data_format /= 2) &
CALL errore('read_upf_v2::paw',&
'Unknown format of PAW data.',1)
CALL iotk_scan_attr(attr, 'core_energy', upf%paw%core_energy, default=0._dp)
!
! Full occupation (not only > 0 ones)
ALLOCATE( upf%paw%oc(upf%nbeta) )
CALL iotk_scan_dat(u, 'PP_OCCUPATIONS',upf%paw%oc)
!
! All-electron core charge
ALLOCATE( upf%paw%ae_rho_atc(upf%mesh) )
CALL iotk_scan_dat(u, 'PP_AE_NLCC', upf%paw%ae_rho_atc)
!
! All-electron local potential
ALLOCATE( upf%paw%ae_vloc(upf%mesh) )
CALL iotk_scan_dat(u, 'PP_AE_VLOC', upf%paw%ae_vloc)
!
ALLOCATE(upf%paw%pfunc(upf%mesh, upf%nbeta,upf%nbeta) )
upf%paw%pfunc(:,:,:) = 0._dp
IF (upf%has_so) THEN
ALLOCATE(upf%paw%pfunc_rel(upf%mesh, upf%nbeta,upf%nbeta) )
upf%paw%pfunc_rel(:,:,:) = 0._dp
ENDIF
DO nb=1,upf%nbeta
DO nb1=1,nb
upf%paw%pfunc (1:upf%mesh, nb, nb1) = &
upf%aewfc(1:upf%mesh, nb) * upf%aewfc(1:upf%mesh, nb1)
IF (upf%has_so) THEN
upf%paw%pfunc_rel (1:upf%paw%iraug, nb, nb1) = &
upf%paw%aewfc_rel(1:upf%paw%iraug, nb) * &
upf%paw%aewfc_rel(1:upf%paw%iraug, nb1)
!
! The small component is added to pfunc. pfunc_rel is useful only
! to add a small magnetic contribution
!
upf%paw%pfunc (1:upf%paw%iraug, nb, nb1) = &
upf%paw%pfunc (1:upf%paw%iraug, nb, nb1) + &
upf%paw%pfunc_rel (1:upf%paw%iraug, nb, nb1)
ENDIF
upf%paw%pfunc(upf%paw%iraug+1:,nb,nb1) = 0._dp
!
upf%paw%pfunc (1:upf%mesh, nb1, nb) = upf%paw%pfunc (1:upf%mesh, nb, nb1)
IF (upf%has_so) upf%paw%pfunc_rel (1:upf%mesh, nb1, nb) = &
upf%paw%pfunc_rel (1:upf%mesh, nb, nb1)
ENDDO
ENDDO
!
! Pseudo wavefunctions (not only the ones for oc > 0)
! All-electron wavefunctions
ALLOCATE(upf%paw%ptfunc(upf%mesh, upf%nbeta,upf%nbeta) )
upf%paw%ptfunc(:,:,:) = 0._dp
DO nb=1,upf%nbeta
DO nb1=1,upf%nbeta
upf%paw%ptfunc (1:upf%mesh, nb, nb1) = &
upf%pswfc(1:upf%mesh, nb) * upf%pswfc(1:upf%mesh, nb1)
upf%paw%ptfunc(upf%paw%iraug+1:,nb,nb1) = 0._dp
!
upf%paw%ptfunc (1:upf%mesh, nb1, nb) = upf%paw%ptfunc (1:upf%mesh, nb, nb1)
ENDDO
ENDDO
!
! Finalize
CALL iotk_scan_end(u, 'PP_PAW')
RETURN
END SUBROUTINE read_upf_paw
!
SUBROUTINE read_upf_gipaw(u, upf)
IMPLICIT NONE
INTEGER,INTENT(IN) :: u ! i/o unit
TYPE(pseudo_upf),INTENT(INOUT) :: upf ! the pseudo data
INTEGER :: ierr ! /= 0 if something went wrong
!
CHARACTER(len=iotk_attlenx) :: attr
!
INTEGER :: nb
IF (.not. upf%has_gipaw ) RETURN
CALL iotk_scan_begin(u, 'PP_GIPAW', attr=attr)
CALL iotk_scan_attr(attr, 'gipaw_data_format', upf%gipaw_data_format)
IF(upf%gipaw_data_format /= 2) &
CALL infomsg('read_upf_v2::gipaw','Unknown format version')
!
CALL iotk_scan_begin(u, 'PP_GIPAW_CORE_ORBITALS', attr=attr)
CALL iotk_scan_attr(attr, 'number_of_core_orbitals', upf%gipaw_ncore_orbitals)
ALLOCATE ( upf%gipaw_core_orbital_n(upf%gipaw_ncore_orbitals) )
ALLOCATE ( upf%gipaw_core_orbital_el(upf%gipaw_ncore_orbitals) )
ALLOCATE ( upf%gipaw_core_orbital_l(upf%gipaw_ncore_orbitals) )
ALLOCATE ( upf%gipaw_core_orbital(upf%mesh,upf%gipaw_ncore_orbitals) )
DO nb = 1,upf%gipaw_ncore_orbitals
CALL iotk_scan_dat(u, 'PP_GIPAW_CORE_ORBITAL'//iotk_index(nb), &
upf%gipaw_core_orbital(:,nb), attr=attr)
CALL iotk_scan_attr(attr, 'label', upf%gipaw_core_orbital_el(nb))
CALL iotk_scan_attr(attr, 'n', upf%gipaw_core_orbital_n(nb))
CALL iotk_scan_attr(attr, 'l', upf%gipaw_core_orbital_l(nb))
ENDDO
CALL iotk_scan_end(u, 'PP_GIPAW_CORE_ORBITALS')
!
! Read valence all-electron and pseudo orbitals and their labels
!
IF (upf%paw_as_gipaw) THEN
!READ PAW DATA INSTEAD OF GIPAW
upf%gipaw_wfs_nchannels = upf%nbeta
ALLOCATE ( upf%gipaw_wfs_el(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ll(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_rcut(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_rcutus(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ae(upf%mesh,upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ps(upf%mesh,upf%gipaw_wfs_nchannels) )
DO nb = 1,upf%gipaw_wfs_nchannels
upf%gipaw_wfs_el(nb) = upf%els_beta(nb)
upf%gipaw_wfs_ll(nb) = upf%lll(nb)
upf%gipaw_wfs_ae(:,nb) = upf%aewfc(:,nb)
ENDDO
DO nb = 1,upf%gipaw_wfs_nchannels
upf%gipaw_wfs_ps(:,nb) = upf%pswfc(:,nb)
ENDDO
ALLOCATE ( upf%gipaw_vlocal_ae(upf%mesh) )
ALLOCATE ( upf%gipaw_vlocal_ps(upf%mesh) )
upf%gipaw_vlocal_ae(:)= upf%paw%ae_vloc(:)
upf%gipaw_vlocal_ps(:)= upf%vloc(:)
DO nb = 1,upf%gipaw_wfs_nchannels
upf%gipaw_wfs_rcut(nb)=upf%rcut(nb)
upf%gipaw_wfs_rcutus(nb)=upf%rcutus(nb)
ENDDO
ELSEIF (upf%tcoulombp) THEN
upf%gipaw_wfs_nchannels = 1
ALLOCATE ( upf%gipaw_wfs_el(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ll(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_rcut(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_rcutus(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ae(upf%mesh,upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ps(upf%mesh,upf%gipaw_wfs_nchannels) )
DO nb = 1,upf%gipaw_wfs_nchannels
upf%gipaw_wfs_el(nb) = "1S"
upf%gipaw_wfs_ll(nb) = 0
upf%gipaw_wfs_ae(:,nb) = 0.0d0
upf%gipaw_wfs_ps(:,nb) = 0.0d0
ENDDO
ALLOCATE ( upf%gipaw_vlocal_ae(upf%mesh) )
ALLOCATE ( upf%gipaw_vlocal_ps(upf%mesh) )
upf%gipaw_vlocal_ae(:)= 0.0d0
upf%gipaw_vlocal_ps(:)= 0.0d0
DO nb = 1,upf%gipaw_wfs_nchannels
upf%gipaw_wfs_rcut(nb)=1.0d0
upf%gipaw_wfs_rcutus(nb)=1.0d0
ENDDO
ELSE
CALL iotk_scan_begin(u, 'PP_GIPAW_ORBITALS', attr=attr)
CALL iotk_scan_attr(attr, 'number_of_valence_orbitals', upf%gipaw_wfs_nchannels)
ALLOCATE ( upf%gipaw_wfs_el(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ll(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_rcut(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_rcutus(upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ae(upf%mesh,upf%gipaw_wfs_nchannels) )
ALLOCATE ( upf%gipaw_wfs_ps(upf%mesh,upf%gipaw_wfs_nchannels) )
DO nb = 1,upf%gipaw_wfs_nchannels
CALL iotk_scan_begin(u, 'PP_GIPAW_ORBITAL'//iotk_index(nb), attr=attr)
CALL iotk_scan_attr(attr, 'label', upf%gipaw_wfs_el(nb))
CALL iotk_scan_attr(attr, 'l', upf%gipaw_wfs_ll(nb))
CALL iotk_scan_attr(attr, 'cutoff_radius', upf%gipaw_wfs_rcut(nb))
CALL iotk_scan_attr(attr, 'ultrasoft_cutoff_radius', upf%gipaw_wfs_rcutus(nb),&
default=upf%gipaw_wfs_rcut(nb))
! read all-electron orbital
CALL iotk_scan_dat(u, 'PP_GIPAW_WFS_AE', upf%gipaw_wfs_ae(:,nb))
! read pseudo orbital
CALL iotk_scan_dat(u, 'PP_GIPAW_WFS_PS', upf%gipaw_wfs_ps(:,nb))
!
CALL iotk_scan_end(u, 'PP_GIPAW_ORBITAL'//iotk_index(nb))
ENDDO
CALL iotk_scan_end(u, 'PP_GIPAW_ORBITALS')
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Read all-electron and pseudo local potentials
ALLOCATE ( upf%gipaw_vlocal_ae(upf%mesh) )
ALLOCATE ( upf%gipaw_vlocal_ps(upf%mesh) )
CALL iotk_scan_begin(u, 'PP_GIPAW_VLOCAL')
CALL iotk_scan_dat(u, 'PP_GIPAW_VLOCAL_AE',upf%gipaw_vlocal_ae(:))
CALL iotk_scan_dat(u, 'PP_GIPAW_VLOCAL_PS',upf%gipaw_vlocal_ps(:))
CALL iotk_scan_end(u, 'PP_GIPAW_VLOCAL')
ENDIF
CALL iotk_scan_end(u, 'PP_GIPAW')
RETURN
END SUBROUTINE read_upf_gipaw
!
END SUBROUTINE read_upf_v2
!
END MODULE read_upf_v2_module
| gpl-2.0 |
nvarini/espresso_adios | TDDFPT/src/lr_sm1_psi.f90 | 3 | 32006 | !
! Copyright (C) 2001-2015 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!----------------------------------------------------------------------------
SUBROUTINE sm1_psi(recalculate, ik, lda, n, m, psi, spsi)
!----------------------------------------------------------------------------
!
! This subroutine applies the S^{-1} matrix to m wavefunctions psi
! and puts the results in spsi.
! See Eq.(13) in B. Walker and R. Gebauer, J. Chem. Phys. 127, 164106 (2007).
! Requires the products of psi with all beta functions
! in array becp(nkb,m) (calculated in h_psi or by ccalbec)
! input:
! recalculate decides if the overlap of beta functions is recalculated or not.
! this is needed e.g. if ions are moved and the overlap changes accordingly.
! ik k point under consideration
! lda leading dimension of arrays psi, spsi
! n true dimension of psi, spsi
! m number of states psi
! psi
! output:
! spsi = S^{-1}*psi
!
! Original routine written by R. Gebauer
! Modified by Osman Baris Malcioglu (2009)
! Modified by Iurii Timrov (2013)
!
USE kinds, ONLY : DP
USE control_flags, ONLY : gamma_only
USE uspp, ONLY : okvan, vkb, nkb, qq
USE uspp_param, ONLY : nh, upf
USE wvfct, ONLY : igk, g2kin
USE ions_base, ONLY : ityp,nat,ntyp=>nsp
USE mp, ONLY : mp_sum
USE mp_global, ONLY : inter_pool_comm, intra_bgrp_comm
USE lr_variables, ONLY : lr_verbosity, eels, LR_iteration,itermax
USE io_global, ONLY : stdout
USE noncollin_module, ONLY : noncolin, npol
!
IMPLICIT NONE
!
! ... First the dummy variables
!
LOGICAL, INTENT(in) :: recalculate
INTEGER, INTENT(in) :: lda, n, m, ik
COMPLEX(kind=DP), INTENT(in) :: psi(lda*npol,m)
COMPLEX(kind=DP), INTENT(out) :: spsi(lda*npol,m)
!
LOGICAL ::recalc
!
IF (lr_verbosity > 5) THEN
WRITE(stdout,'("<lr_sm1_psi>")')
ENDIF
!
CALL start_clock( 'lr_sm1_psi' )
!
recalc = recalculate
!
IF (eels) THEN
!
IF ( gamma_only ) THEN
CALL errore( 'sm1_psi', 'EELS + gamma_only is not supported', 1 )
ELSEIF (noncolin) THEN
CALL sm1_psi_eels_nc()
ELSE
CALL sm1_psi_eels_k()
ENDIF
!
ELSE
!
IF ( gamma_only ) THEN
CALL sm1_psi_gamma()
ELSE
CALL sm1_psi_k()
ENDIF
!
ENDIF
!
CALL stop_clock( 'lr_sm1_psi' )
!
RETURN
!
CONTAINS
SUBROUTINE sm1_psi_gamma()
!-----------------------------------------------------------------------
!
! Optical case : gamma_only
!
USE becmod, ONLY : bec_type,becp,calbec
USE realus, ONLY : real_space, invfft_orbital_gamma, initialisation_level, &
fwfft_orbital_gamma, calbec_rs_gamma, add_vuspsir_gamma, &
v_loc_psir, s_psir_gamma, real_space_debug
!
IMPLICIT NONE
!
! ... local variables
!
INTEGER :: ikb, jkb, ih, jh, na, nt, ijkb0, ibnd, ii
! counters
REAL(kind=DP), ALLOCATABLE :: ps(:,:)
REAL(kind=dp), ALLOCATABLE, SAVE :: BB_(:,:)
LOGICAL, SAVE :: first_entry = .true.
!
! Initialize spsi : spsi = psi
!
CALL ZCOPY( lda * npol * m, psi, 1, spsi, 1 )
!
IF ( nkb == 0 .OR. .NOT. okvan ) RETURN
!
! If this is the first entry, we calculate and save the coefficients B from Eq.(15)
! B. Walker and R. Gebauer, J. Chem. Phys. 127, 164106 (2007).
! If this is not the first entry, we do not recalculate the coefficients B but
! use the ones which were already calculated and saved (if recalc=.false.).
!
IF (first_entry) THEN
!
IF (allocated(BB_)) DEALLOCATE(BB_)
first_entry = .false.
recalc = .true.
!
ENDIF
!
IF (.not.allocated(BB_)) recalc = .true.
IF (recalc .and. allocated(BB_)) DEALLOCATE(BB_)
!
IF (recalc) THEN
!
ALLOCATE(BB_(nkb,nkb))
BB_=0.d0
!
CALL errore('sm1_psi','recalculating BB_ matrix',-1) ! it does nothing
!
IF (lr_verbosity > 1) THEN
WRITE(stdout,'(5X,"Calculating S^-1")')
ENDIF
!
! The beta-functions vkb were already calculated elsewhere
! (in the routine lr_solve_e). So there is no need to call
! the routine init_us_2.
!
! Calculate the coefficients B_ij defined by Eq.(15).
! B_ij = <beta(i)|beta(j)>, where beta(i) = vkb(i).
!
CALL calbec (n,vkb,vkb,BB_,nkb)
!
ALLOCATE( ps( nkb, nkb ) )
!
ps(:,:) = 0.d0
!
! Calculate the product of q_nm and B_ij of Eq.(16).
!
ijkb0 = 0
DO nt=1,ntyp
IF (upf(nt)%tvanp) THEN
DO na=1,nat
IF(ityp(na)==nt) THEN
DO ii=1,nkb
DO jh=1,nh(nt)
jkb=ijkb0 + jh
DO ih=1,nh(nt)
ikb = ijkb0 + ih
ps(ikb,ii) = ps(ikb,ii) + qq(ih,jh,nt)*BB_(jkb,ii)
ENDDO
ENDDO
ENDDO
ijkb0 = ijkb0+nh(nt)
ENDIF
ENDDO
ELSE
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
ENDDO
ENDIF
ENDDO
!
! Add identity to q_nm * B_ij [see Eq.(16)].
! ps = (1 + q*B)
!
DO ii=1,nkb
ps(ii,ii) = ps(ii,ii) + 1.d0
ENDDO
!
! Invert matrix: (1 + q*B)^{-1}
!
CALL dinv_matrix(ps,nkb)
!
BB_(:,:) = 0.d0
!
! Finally, let us calculate lambda_nm = -(1+q*B)^{-1} * q
!
ijkb0 = 0
DO nt=1,ntyp
IF (upf(nt)%tvanp) THEN
DO na=1,nat
IF(ityp(na)==nt) THEN
DO ii=1,nkb
DO jh=1,nh(nt)
jkb=ijkb0 + jh
DO ih=1,nh(nt)
ikb = ijkb0 + ih
BB_(ii,jkb) = BB_(ii,jkb) - ps(ii,ikb)*qq(ih,jh,nt)
ENDDO
ENDDO
ENDDO
ijkb0 = ijkb0+nh(nt)
ENDIF
ENDDO
ELSE
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
ENDDO
ENDIF
ENDDO
DEALLOCATE(ps)
ENDIF
!
! Compute the product of the beta-functions vkb with the functions psi,
! and put the result in becp.
! becp(ikb,jbnd) = \sum_G vkb^*(ikb,G) psi(G,jbnd) = <beta|psi>
!
IF (real_space_debug>3) THEN
!
DO ibnd=1,m,2
CALL invfft_orbital_gamma(psi,ibnd,m)
CALL calbec_rs_gamma(ibnd,m,becp%r)
ENDDO
!
ELSE
CALL calbec(n,vkb,psi,becp,m)
ENDIF
!
ALLOCATE( ps( nkb, m ) )
!
ps(:,:) = 0.D0
!
! Now let us apply the operator S^{-1}, given by Eq.(13), to the functions psi.
! Let's do this in 2 steps.
!
! Step 1 : ps = lambda * <beta|psi>
! Here, lambda = BB_, and <beta|psi> = becp%r
!
call DGEMM( 'N','N',nkb,m,nkb,1.d0,BB_,nkb,becp%r,nkb,0.d0,ps,nkb)
!
! Step 2 : |spsi> = S^{-1} * |psi> = |psi> + ps * |beta>
!
call DGEMM('N','N',2*n,m,nkb,1.d0,vkb,2*lda,ps,nkb,1.d0,spsi,2*lda)
!
DEALLOCATE( ps )
!
IF (LR_iteration==itermax) DEALLOCATE(BB_)
!
RETURN
!
END SUBROUTINE sm1_psi_gamma
SUBROUTINE sm1_psi_k()
!-----------------------------------------------------------------------
!
! Optical case : k-points version
!
USE becmod, ONLY : bec_type,becp,calbec
USE realus, ONLY : igk_k,npw_k
USE klist, ONLY : nks, xk
!
IMPLICIT NONE
!
! ... local variables
!
INTEGER :: ikb, jkb, ih, jh, na, nt, ijkb0, ibnd, ii, ik1
! counters
COMPLEX(kind=DP), ALLOCATABLE :: ps(:,:)
COMPLEX(kind=dp), ALLOCATABLE, SAVE :: BB_(:,:,:)
!
! Initialize spsi : spsi = psi
!
CALL ZCOPY( lda * npol * m, psi, 1, spsi, 1 )
!
IF ( nkb == 0 .OR. .NOT. okvan ) RETURN
!
! If this is the first entry, we calculate and save the coefficients B from Eq.(15)
! B. Walker and R. Gebauer, J. Chem. Phys. 127, 164106 (2007).
! If this is not the first entry, we do not recalculate the coefficients B
! (they are already allocated) but use the ones which were already calculated
! and saved (if recalc=.false.).
!
IF (.NOT.ALLOCATED(BB_)) recalc = .true.
IF (recalc .AND. ALLOCATED(BB_)) DEALLOCATE(BB_)
!
! If recalc=.true. we (re)calculate the coefficients lambda_nm defined by Eq.(16).
!
IF (recalc) THEN
!
ALLOCATE(BB_(nkb,nkb,nks))
BB_ = (0.d0,0.d0)
!
CALL errore('sm1_psi','recalculating BB_ matrix',-1) ! it does nothing
!
ALLOCATE( ps( nkb, nkb ) )
!
DO ik1 = 1, nks
!
! Calculate beta-functions vkb for a given k point.
!
CALL init_us_2(npw_k(ik1),igk_k(:,ik1),xk(1,ik1),vkb)
!
! Calculate the coefficients B_ij defined by Eq.(15).
! B_ij = <beta(i)|beta(j)>, where beta(i) = vkb(i).
!
CALL zgemm('C','N',nkb,nkb,npw_k(ik1),(1.d0,0.d0),vkb,lda,vkb,lda,(0.d0,0.d0),BB_(1,1,ik1),nkb)
!
#ifdef __MPI
CALL mp_sum(BB_(:,:,ik1), intra_bgrp_comm)
#endif
!
ps(:,:) = (0.d0,0.d0)
!
! Calculate the product of q_nm and B_ij of Eq.(16).
!
ijkb0 = 0
DO nt=1,ntyp
IF (upf(nt)%tvanp) THEN
DO na=1,nat
IF(ityp(na)==nt) THEN
DO ii=1,nkb
DO jh=1,nh(nt)
jkb=ijkb0 + jh
DO ih=1,nh(nt)
ikb = ijkb0 + ih
ps(ikb,ii) = ps(ikb,ii) + BB_(jkb,ii, ik1)*qq(ih,jh,nt)
ENDDO
ENDDO
ENDDO
ijkb0 = ijkb0+nh(nt)
ENDIF
ENDDO
ELSE
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
ENDDO
ENDIF
ENDDO
!
! Add an identity to q_nm * B_ij [see Eq.(16)].
! ps = (1 + q*B)
!
DO ii = 1, nkb
ps(ii,ii) = ps(ii,ii) + (1.d0,0.d0)
ENDDO
!
! Invert matrix: (1 + q*B)^{-1}
!
CALL zinv_matrix(ps,nkb)
!
! Now let's use BB_ as a work space (in order to save the memory).
!
BB_(:,:,ik1) = (0.d0,0.d0)
!
! Finally, let us calculate lambda_nm = -(1+q*B)^{-1} * q
!
ijkb0 = 0
DO nt=1,ntyp
IF (upf(nt)%tvanp) THEN
DO na=1,nat
IF(ityp(na)==nt) THEN
DO ii=1,nkb
DO jh=1,nh(nt)
jkb=ijkb0 + jh
DO ih=1,nh(nt)
ikb = ijkb0 + ih
BB_(ii,jkb,ik1) = BB_(ii,jkb,ik1) - ps(ii,ikb)*qq(ih,jh,nt)
ENDDO
ENDDO
ENDDO
ijkb0 = ijkb0+nh(nt)
ENDIF
ENDDO
ELSE
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
ENDDO
ENDIF
ENDDO
!
ENDDO ! loop on k points
DEALLOCATE(ps)
!
ENDIF
!
! Calculate beta-functions vkb for a given k point 'ik'.
!
CALL init_us_2(npw_k(ik),igk_k(:,ik),xk(1,ik),vkb)
!
! Compute the product of the beta-functions vkb with the functions psi
! at point k, and put the result in becp%k.
! becp%k(ikb,jbnd) = \sum_G vkb^*(ikb,G) psi(G,jbnd) = <beta|psi>
!
CALL calbec(n,vkb,psi,becp,m)
!
! Let's use ps as a work space.
!
ALLOCATE( ps( nkb, m ) )
ps(:,:) = (0.d0,0.d0)
!
! Now let us apply the operator S^{-1}, given by Eq.(13), to the functions
! psi.
! Let's do this in 2 steps.
!
! Step 1 : calculate the product
! ps = lambda * <beta|psi>
!
DO ibnd=1,m
DO jkb=1,nkb
DO ii=1,nkb
ps(jkb,ibnd) = ps(jkb,ibnd) + BB_(jkb,ii,ik) * becp%k(ii,ibnd)
ENDDO
ENDDO
ENDDO
!
! Step 2 : |spsi> = S^{-1} * |psi> = |psi> + ps * |beta>
!
CALL ZGEMM( 'N', 'N', n, m, nkb, (1.D0, 0.D0), vkb, &
& lda, ps, nkb, (1.D0, 0.D0), spsi, lda )
!
DEALLOCATE( ps )
!
IF (LR_iteration==itermax .AND. ik==nks) DEALLOCATE(BB_)
!
RETURN
!
END SUBROUTINE sm1_psi_k
SUBROUTINE sm1_psi_eels_k()
!-----------------------------------------------------------------------
!
! EELS : k-points version
!
USE becmod, ONLY : bec_type, becp, calbec
USE klist, only : xk
USE qpoint, ONLY : npwq, igkq, ikks, ikqs, nksq
use lr_variables, only : lr_periodic
use gvect, only : ngm, g
use wvfct, only : g2kin, ecutwfc
use cell_base, only : tpiba2
!
IMPLICIT NONE
!
! ... local variables
!
INTEGER :: ikb, jkb, ih, jh, na, nt, ijkb0, ibnd, ii, ik1,&
ikk, ikq, nbnd_eff
! counters
complex(KIND=DP), ALLOCATABLE :: ps(:,:)
complex(kind=dp), allocatable, save :: BB_(:,:,:)
!
! Initialize spsi : spsi = psi
!
CALL ZCOPY( lda * m, psi, 1, spsi, 1 )
!
IF ( nkb == 0 .OR. .NOT. okvan ) RETURN
!
! If this is the first entry, we calculate and save the coefficients B from Eq.(15)
! B. Walker and R. Gebauer, J. Chem. Phys. 127, 164106 (2007).
! If this is not the first entry, we do not recalculate the coefficients B
! (they are already allocated) but use the ones which were already
! calculated and saved (if recalc=.false.).
!
IF (.NOT.ALLOCATED(BB_)) recalc = .true.
IF (recalc .AND. ALLOCATED(BB_)) DEALLOCATE(BB_)
!
! If recalc=.true. we (re)calculate the coefficients lambda_nm defined by Eq.(16).
!
IF ( recalc ) THEN
!
ALLOCATE(BB_(nkb,nkb,nksq))
BB_ = (0.0d0,0.0d0)
!
CALL errore('sm1_psi','recalculating BB_ matrix',-1) ! it does nothing
!
ALLOCATE( ps(nkb,nkb) )
!
DO ik1 = 1, nksq
!
IF (lr_periodic) THEN
ikk = ik1
ikq = ik1
ELSE
ikk = ikks(ik1)
ikq = ikqs(ik1)
ENDIF
!
! Determination of npwq, igkq; g2kin is used here as a workspace.
!
CALL gk_sort( xk(1,ikq), ngm, g, ( ecutwfc / tpiba2 ), npwq, igkq, g2kin )
!
! Calculate beta-functions vkb for a given k+q point.
!
CALL init_us_2 (npwq, igkq, xk(1,ikq), vkb)
!
! Calculate the coefficients B_ij defined by Eq.(15).
! B_ij = <beta(i)|beta(j)>, where beta(i) = vkb(i).
!
CALL zgemm('C','N',nkb,nkb,npwq,(1.d0,0.d0),vkb,lda,vkb,lda,(0.d0,0.d0),BB_(1,1,ik1),nkb)
!
#ifdef __MPI
CALL mp_sum(BB_(:,:,ik1), intra_bgrp_comm)
#endif
!
ps(:,:) = (0.d0,0.d0)
!
! Calculate the product of q_nm and B_ij of Eq.(16).
!
ijkb0 = 0
do nt=1,ntyp
if (upf(nt)%tvanp) then
do na=1,nat
if(ityp(na).eq.nt) then
do ii=1,nkb
do jh=1,nh(nt)
!
jkb=ijkb0 + jh
!
do ih=1,nh(nt)
!
ikb = ijkb0 + ih
!
ps(ikb,ii) = ps(ikb,ii) + BB_(jkb,ii,ik1)*qq(ih,jh,nt)
!
enddo
enddo
enddo
ijkb0 = ijkb0+nh(nt)
endif
enddo
else
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
END DO
endif
enddo
!
! Add an identity to q_nm * B_ij [see Eq.(16)].
! ps = (1 + q*B)
!
DO ii=1,nkb
ps(ii,ii) = ps(ii,ii) + (1.d0,0.d0)
ENDDO
!
! Invert matrix: (1 + q*B)^{-1}
!
CALL zinv_matrix(ps,nkb)
!
! Now let's use BB_ as a work space (in order to save the memory).
!
BB_(:,:,ik1) = (0.d0,0.d0)
!
! Finally, let us calculate lambda_nm = -(1+q*B)^{-1} * q
! Let us use the array BB_ and put there the values of the lambda
! coefficients.
!
ijkb0 = 0
do nt=1,ntyp
if (upf(nt)%tvanp) then
do na=1,nat
if(ityp(na).eq.nt) then
do ii=1,nkb
do jh=1,nh(nt)
!
jkb=ijkb0 + jh
!
do ih=1,nh(nt)
!
ikb = ijkb0 + ih
!
BB_(ii,jkb,ik1) = BB_(ii,jkb,ik1) - ps(ii,ikb)*qq(ih,jh,nt)
!
enddo
enddo
enddo
ijkb0 = ijkb0+nh(nt)
endif
enddo
else
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
END DO
endif
enddo
!
enddo ! loop on k points
!
DEALLOCATE(ps)
!
ENDIF
!
IF (lr_periodic) THEN
ikk = ik
ikq = ik
ELSE
ikk = ikks(ik)
ikq = ikqs(ik)
ENDIF
!
! Determination of npwq, igkq; g2kin is used here as a workspace.
!
CALL gk_sort( xk(1,ikq), ngm, g, ( ecutwfc / tpiba2 ), npwq, igkq, g2kin )
!
! Calculate beta-functions vkb for a given k+q point.
!
CALL init_us_2 (npwq, igkq, xk(1,ikq), vkb)
!
! Compute the product of the beta-functions vkb with the functions psi
! at point k+q, and put the result in becp%k.
! becp%k(ikb,jbnd) = \sum_G vkb^*(ikb,G) psi(G,jbnd) = <beta|psi>
!
CALL calbec(n, vkb, psi, becp, m)
!
! Let's use ps as a work space.
!
ALLOCATE(ps(nkb,m))
!
ps(:,:) = (0.d0,0.d0)
!
! Now let us apply the operator S^{-1}, given by Eq.(13), to the functions psi.
! Let's do this in 2 steps.
!
! Step 1 : calculate the product
! ps = lambda * <beta|psi>
!
DO ibnd=1,m
DO jkb=1,nkb
DO ii=1,nkb
ps(jkb,ibnd) = ps(jkb,ibnd) + BB_(jkb,ii,ik) * becp%k(ii,ibnd)
ENDDO
ENDDO
ENDDO
!
! Step 2 : |spsi> = S^{-1} * |psi> = |psi> + ps * |beta>
!
CALL zgemm( 'N', 'N', n, m, nkb, (1.D0, 0.D0), vkb, lda, ps, nkb, (1.D0, 0.D0), spsi, lda )
!
DEALLOCATE(ps)
!
IF (LR_iteration==itermax .AND. ik==nksq) DEALLOCATE(BB_)
!
RETURN
!
END SUBROUTINE sm1_psi_eels_k
SUBROUTINE sm1_psi_eels_nc()
!-----------------------------------------------------------------------
!
! EELS : noncollinear case
!
USE becmod, ONLY : bec_type, becp, calbec
USE klist, ONLY : xk
USE qpoint, ONLY : npwq, igkq, ikks, ikqs, nksq
USE lr_variables, ONLY : lr_periodic
USE gvect, ONLY : ngm, g
USE wvfct, ONLY : g2kin, ecutwfc
USE cell_base, ONLY : tpiba2
USE uspp, ONLY : qq_so
USE spin_orb, ONLY : lspinorb
!
IMPLICIT NONE
!
! ... local variables
!
INTEGER :: ikb, jkb, ih, jh, na, nt, ijkb0, ibnd, ii, ik1, ikk, ikq, ipol
! counters
complex(KIND=DP), ALLOCATABLE :: ps(:,:,:)
complex(kind=dp), allocatable, save :: BB_(:,:,:,:)
!
! Initialize spsi : spsi = psi
!
CALL ZCOPY( lda * npol * m, psi, 1, spsi, 1 )
!
IF ( nkb == 0 .OR. .NOT. okvan ) RETURN
!
CALL errore( 'sm1_psi_eels_nc', 'US pseudopotentials + Spin-orbit not tested', 1 )
!
! If this is the first entry, we calculate and save the coefficients B from Eq.(15)
! B. Walker and R. Gebauer, J. Chem. Phys. 127, 164106 (2007).
! If this is not the first entry, we do not recalculate the coefficients B
! (they are already allocated) but use the ones which were already calculated
! and saved (if recalc=.false.).
!
IF (.NOT.ALLOCATED(BB_)) recalc = .true.
IF (recalc .AND. ALLOCATED(BB_)) DEALLOCATE(BB_)
!
! If recalc=.true. we (re)calculate the coefficients lambda_nm defined by Eq.(16).
!
IF ( recalc ) THEN
!
IF (lspinorb) THEN
ALLOCATE(BB_(nkb,nkb,4,nksq))
ELSE
ALLOCATE(BB_(nkb,nkb,1,nksq))
ENDIF
BB_ = (0.0d0,0.0d0)
!
CALL errore('sm1_psi','recalculating BB_ matrix',-1) ! it does nothing
!
IF (lspinorb) THEN
ALLOCATE(ps(nkb,nkb,4))
ELSE
ALLOCATE(ps(nkb,nkb,1))
ENDIF
!
DO ik1 = 1, nksq
!
IF (lr_periodic) THEN
ikk = ik1
ikq = ik1
ELSE
ikk = ikks(ik1)
ikq = ikqs(ik1)
ENDIF
!
! Determination of npwq, igkq; g2kin is used here as a workspace.
!
CALL gk_sort( xk(1,ikq), ngm, g, ( ecutwfc / tpiba2 ), npwq, igkq, g2kin )
!
! Calculate beta-functions vkb for a given k+q point.
!
CALL init_us_2 (npwq, igkq, xk(1,ikq), vkb)
!
! Calculate the coefficients B_ij defined by Eq.(15).
! B_ij = <beta(i)|beta(j)>, where beta(i) = vkb(i).
!
CALL ZGEMM('C','N',nkb,nkb,npwq,(1.d0,0.d0),vkb,lda,vkb,lda,(0.d0,0.d0),BB_(1,1,1,ik1),nkb)
!
IF (lspinorb) THEN
BB_(:,:,2,ik1) = BB_(:,:,1,ik1)
BB_(:,:,3,ik1) = BB_(:,:,1,ik1)
BB_(:,:,4,ik1) = BB_(:,:,1,ik1)
ENDIF
!
#ifdef __MPI
CALL mp_sum(BB_(:,:,:,ik1), intra_bgrp_comm)
#endif
!
ps(:,:,:) = (0.d0,0.d0)
!
! Calculate the product of q_nm and B_ij of Eq.(16).
!
ijkb0 = 0
do nt=1,ntyp
if (upf(nt)%tvanp) then
do na=1,nat
if(ityp(na).eq.nt) then
do ii=1,nkb
do jh=1,nh(nt)
!
jkb=ijkb0 + jh
!
do ih=1,nh(nt)
!
ikb = ijkb0 + ih
!
if (lspinorb) then
do ipol=1,4
ps(ikb,ii,ipol) = ps(ikb,ii,ipol) + BB_(jkb,ii,ipol,ik1)*qq_so(ih,jh,ipol,nt)
enddo
else
ps(ikb,ii,1) = ps(ikb,ii,1) + BB_(jkb,ii,1,ik1)*qq(ih,jh,nt)
endif
!
enddo
enddo
enddo
ijkb0 = ijkb0+nh(nt)
endif
enddo
else
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
END DO
endif
enddo
!
! Add identity to q_nm * B_ij [see Eq.(16)].
! ps = (1 + q*B)
!
DO ii=1,nkb
IF (lspinorb) THEN
DO ipol=1,4
ps(ii,ii,ipol) = ps(ii,ii,ipol) + (1.d0,0.d0)
ENDDO
ELSE
ps(ii,ii,1) = ps(ii,ii,1) + (1.d0,0.d0)
ENDIF
ENDDO
!
! Invert matrix: (1 + q*B)^{-1}
! WARNING: How to do the invertion of the matrix in the spin-orbit case,
! when there are 4 components?
!
IF (lspinorb) THEN
DO ipol=1,4
CALL zinv_matrix(ps(1,1,ipol),nkb)
ENDDO
ELSE
CALL zinv_matrix(ps(1,1,1),nkb)
ENDIF
!
! Finally, let us calculate lambda_nm = -(1+q*B)^{-1} * q
! Let us use the array BB_ and put there the values of the lambda coefficients.
!
BB_(:,:,:,ik1) = (0.d0,0.d0)
!
ijkb0 = 0
do nt=1,ntyp
if (upf(nt)%tvanp) then
do na=1,nat
if(ityp(na).eq.nt) then
do ii=1,nkb
do jh=1,nh(nt)
jkb=ijkb0 + jh
do ih=1,nh(nt)
ikb = ijkb0 + ih
if (lspinorb) then
BB_(ii,jkb,1,ik1) = BB_(ii,jkb,1,ik1) - ps(ii,ikb,1) * qq_so(ih,jh,1,nt) &
- ps(ii,ikb,2) * qq_so(ih,jh,3,nt)
!
BB_(ii,jkb,2,ik1) = BB_(ii,jkb,2,ik1) - ps(ii,ikb,1) * qq_so(ih,jh,2,nt) &
- ps(ii,ikb,2) * qq_so(ih,jh,4,nt)
!
BB_(ii,jkb,3,ik1) = BB_(ii,jkb,3,ik1) - ps(ii,ikb,3) * qq_so(ih,jh,1,nt) &
- ps(ii,ikb,4) * qq_so(ih,jh,3,nt)
!
BB_(ii,jkb,4,ik1) = BB_(ii,jkb,4,ik1) - ps(ii,ikb,3) * qq_so(ih,jh,2,nt) &
- ps(ii,ikb,4) * qq_so(ih,jh,4,nt)
else
BB_(ii,jkb,1,ik1) = BB_(ii,jkb,1,ik1) - ps(ii,ikb,1)*qq(ih,jh,nt)
endif
!
enddo
enddo
enddo
ijkb0 = ijkb0+nh(nt)
endif
enddo
else
DO na = 1, nat
IF ( ityp(na) == nt ) ijkb0 = ijkb0 + nh(nt)
END DO
endif
enddo
!
enddo ! loop on k points
!
deallocate(ps)
!
endif
!
IF (lr_periodic) THEN
ikk = ik
ikq = ik
ELSE
ikk = ikks(ik)
ikq = ikqs(ik)
ENDIF
!
! Determination of npwq, igkq; g2kin is used here as a workspace.
!
CALL gk_sort( xk(1,ikq), ngm, g, ( ecutwfc / tpiba2 ), npwq, igkq, g2kin )
!
! Calculate beta-functions vkb for a given k+q point.
!
CALL init_us_2 (npwq, igkq, xk(1,ikq), vkb)
!
! Compute the product of the beta-functions vkb with the functions psi
! at point k+q, and put the result in becp%k.
! becp%k(ikb,jbnd) = \sum_G vkb^*(ikb,G) psi(G,jbnd) = <beta|psi>
!
CALL calbec(n, vkb, psi, becp, m)
!
! Let's use ps as a work space.
!
ALLOCATE(ps(nkb,npol,m))
ps(:,:,:) = (0.d0,0.d0)
!
! Now let us apply the operator S^{-1}, given by Eq.(13), to the functions psi.
! Let's do this in 2 steps.
!
! Step 1 : calculate the product
! ps = lambda * <beta|psi>
!
DO ibnd=1,m
DO jkb=1,nkb
DO ii=1,nkb
IF (lspinorb) THEN
!
ps(jkb,1,ibnd) = ps(jkb,1,ibnd) + BB_(jkb,ii,1,ik) * becp%nc(ii,1,ibnd) &
+ BB_(jkb,ii,2,ik) * becp%nc(ii,2,ibnd)
!
ps(jkb,2,ibnd) = ps(jkb,2,ibnd) + BB_(jkb,ii,3,ik) * becp%nc(ii,1,ibnd) &
+ BB_(jkb,ii,4,ik) * becp%nc(ii,2,ibnd)
!
ELSE
DO ipol=1,npol
ps(jkb,ipol,ibnd) = ps(jkb,ipol,ibnd) + BB_(jkb,ii,1,ik) * becp%nc(ii,ipol,ibnd)
ENDDO
ENDIF
ENDDO
ENDDO
ENDDO
!
! Step 2 : |spsi> = S^{-1} * |psi> = |psi> + ps * |beta>
!
CALL ZGEMM( 'N', 'N', n, m*npol, nkb, (1.D0, 0.D0), vkb, lda, ps, nkb, (1.D0, 0.D0), spsi, lda )
!
DEALLOCATE(ps)
!
IF (LR_iteration==itermax .AND. ik==nksq) DEALLOCATE(BB_)
!
RETURN
!
END SUBROUTINE sm1_psi_eels_nc
END SUBROUTINE sm1_psi
SUBROUTINE dinv_matrix(M,N)
!-----------------------------------------------------------------------
!
! This subroutine inverts a real matrix M with the dimension NxN.
! See also flib/invmat.f90
!
USE kinds, ONLY : DP
!
IMPLICIT NONE
!
INTEGER :: N ! matrix dimension
REAL(kind=dp), DIMENSION(0:N-1,0:N-1) :: M ! matrix to be inverted
REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: work
INTEGER, DIMENSION(:), ALLOCATABLE :: ipiv
INTEGER :: i,lwork,info
INTEGER, SAVE :: lworkfact
!
data lworkfact /64/
!
lwork = lworkfact*N
!
ALLOCATE(ipiv(0:N-1))
ALLOCATE(work(1:lwork))
!
! Factorize matrix M
!
CALL dgetrf( N, N, M, N, ipiv, info )
!
IF (info/=0) THEN
CALL errore('dinv_matrix','error in dgetrf',info)
ENDIF
!
! Invert matrix
!
CALL dgetri( N, M, N, ipiv, work, lwork, info )
!
IF (info/=0) THEN
CALL errore('dinv_matrix','error in dgetri',info)
ELSE
lworkfact = int(work(1)/N)
ENDIF
!
DEALLOCATE(work)
DEALLOCATE(ipiv)
!
RETURN
!
END SUBROUTINE dinv_matrix
SUBROUTINE zinv_matrix(M,N)
!-----------------------------------------------------------------------
!
! This subroutine inverts a complex matrix M with the dimension NxN.
! See also flib/invmat_complex.f90
!
USE kinds, ONLY : DP
!
IMPLICIT NONE
!
INTEGER :: N ! matrix dimension
COMPLEX(kind=dp), DIMENSION(0:N-1,0:N-1) :: M ! matrix to be inverted
COMPLEX(kind=dp), DIMENSION(:), ALLOCATABLE :: work
INTEGER, DIMENSION(:), ALLOCATABLE :: ipiv
INTEGER :: i,lwork,info
INTEGER, SAVE :: lworkfact
!
data lworkfact /64/
!
lwork = lworkfact*N
!
ALLOCATE(ipiv(0:N-1))
ALLOCATE(work(1:lwork))
!
! Factorize matrix M
!
CALL zgetrf( N, N, M, N, ipiv, info )
!
IF (info/=0) THEN
CALL errore('zinv_matrix','error in zgetrf',info)
ENDIF
!
! Invert matrix
!
CALL zgetri( N, M, N, ipiv, work, lwork, info )
!
IF (info/=0) THEN
CALL errore('zinv_matrix','error in zgetri',info)
ELSE
lworkfact = int(work(1)/N)
ENDIF
!
DEALLOCATE(work)
DEALLOCATE(ipiv)
!
RETURN
!
END SUBROUTINE zinv_matrix
| gpl-2.0 |
ars599/mom5 | src/mom5/ocean_bgc/ocean_bgc_restore.F90 | 10 | 197447 | #include <fms_platform.h>
! ----------------------------------------------------------------
! GNU General Public License
! This file is a part of MOM.
!
! MOM 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; either version 2 of
! the License, or (at your option) any later version.
!
! MOM 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.
!
! For the full text of the GNU General Public License,
! write to: Free Software Foundation, Inc.,
! 675 Mass Ave, Cambridge, MA 02139, USA.
! or see: http://www.gnu.org/licenses/gpl.html
!-----------------------------------------------------------------------
!
!<CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> Richard D. Slater
!</CONTACT>
!
!<REVIEWER EMAIL="GFDL.Climate.Model.Info@noaa.gov"> John P. Dunne
!</REVIEWER>
!
!<OVERVIEW>
! Ocean Carbon Model Intercomparison Study II: Biotic module
!</OVERVIEW>
!
!<DESCRIPTION>
! Implementation of routines to solve the OCMIP-2 Biotic
! simulations as outlined in the Biotic-HOWTO documentation,
! revision 1.7, 1999/10/05.
!</DESCRIPTION>
!
! <INFO>
! <REFERENCE>
! http://www.ipsl.jussieu.fr/OCMIP/phase2/simulations/Biotic/HOWTO-Biotic.html
! </REFERENCE>
!
! <REFERENCE>
! Press, W. H., S. A. Teukosky, W. T. Vetterling, B. P. Flannery, 1992.
! Numerical Recipes in FORTRAN, Second Edition, Cambridge University Press.
! </REFERENCE>
!
! <REFERENCE>
! Enting, I.G., T. M. L. Wigley, M. Heimann, 1994. Future Emissions
! and concentrations of carbon dioxide: key ocean / atmosphere /
! land analyses, CSIRO Aust. Div. Atmos. Res. Tech. Pap. No. 31,
! 118 pp.
! </REFERENCE>
! </INFO>
!
!------------------------------------------------------------------
!
! Module ocean_bgc_restore_mod
!
! Implementation of routines to solve the OCMIP-2 Biotic
! simulations as outlined in the Biotic-HOWTO documentation,
! revision 1.7, 1999/10/05.
!
!------------------------------------------------------------------
!
module ocean_bgc_restore_mod
use time_manager_mod, only: time_type
use diag_manager_mod, only: register_diag_field, diag_axis_init
use field_manager_mod, only: fm_field_name_len, fm_path_name_len, fm_string_len
use field_manager_mod, only: fm_get_length, fm_get_value, fm_new_value, fm_get_index
use fms_mod, only: field_exist, file_exist
use fms_io_mod, only: register_restart_field, save_restart, restore_state
use fms_io_mod, only: restart_file_type
use mpp_mod, only: stdout, stdlog, mpp_error, mpp_sum, FATAL
use time_manager_mod, only: get_date
use time_interp_external_mod, only: time_interp_external, init_external_field
use mpp_domains_mod, only: domain2d
use constants_mod, only: WTMCO2, WTMO2
use ocean_tpm_util_mod, only: otpm_set_tracer_package, otpm_set_prog_tracer, otpm_set_diag_tracer
use fm_util_mod, only: fm_util_check_for_bad_fields, fm_util_set_value
use fm_util_mod, only: fm_util_get_string, fm_util_get_logical, fm_util_get_integer, fm_util_get_real
use fm_util_mod, only: fm_util_get_logical_array, fm_util_get_real_array, fm_util_get_string_array
use fm_util_mod, only: fm_util_start_namelist, fm_util_end_namelist
use coupler_types_mod, only: ind_alpha, ind_csurf, coupler_2d_bc_type, ind_flux
use ocean_types_mod, only: ocean_prog_tracer_type, ocean_diag_tracer_type, ocean_grid_type, ocean_time_type
use ocmip2_co2calc_mod, only: ocmip2_co2calc
use ocean_util_mod, only: diagnose_2d, diagnose_2d_comp, diagnose_3d_comp
implicit none
private
public :: ocean_bgc_restore_bbc
public :: ocean_bgc_restore_end
public :: ocean_bgc_restore_init
public :: ocean_bgc_restore_flux_init
public :: ocean_bgc_restore_sbc
public :: ocean_bgc_restore_source
public :: ocean_bgc_restore_start
public :: ocean_bgc_restore_init_sfc
public :: ocean_bgc_restore_avg_sfc
public :: ocean_bgc_restore_sum_sfc
public :: ocean_bgc_restore_zero_sfc
public :: ocean_bgc_restore_sfc_end
public :: ocean_bgc_restore_restart
private :: allocate_arrays
private :: locate
private :: set_array
character(len=32), parameter :: package_name = 'ocean_bgc_restore'
character(len=48), parameter :: mod_name = 'ocean_bgc_restore_mod'
character(len=48), parameter :: diag_name = 'ocean_bgc_restore'
character(len=fm_string_len), parameter :: default_restart_file = 'ocean_bgc_restore.res.nc'
character(len=fm_string_len), parameter :: default_local_restart_file = 'ocean_bgc_restore_local.res.nc'
character(len=fm_string_len), parameter :: default_ice_restart_file = 'ice_bgc_restore.res.nc'
character(len=fm_string_len), parameter :: default_ocean_restart_file = 'ocean_bgc_restore_airsea_flux.res.nc'
! coefficients for O2 saturation
real, parameter :: a_0 = 2.00907
real, parameter :: a_1 = 3.22014
real, parameter :: a_2 = 4.05010
real, parameter :: a_3 = 4.94457
real, parameter :: a_4 = -2.56847e-01
real, parameter :: a_5 = 3.88767
real, parameter :: b_0 = -6.24523e-03
real, parameter :: b_1 = -7.37614e-03
real, parameter :: b_2 = -1.03410e-02
real, parameter :: b_3 = -8.17083e-03
real, parameter :: c_0 = -4.88682e-07
! add_phosphate : if true, then add sufficient PO4 to keep
! the predicted PO4 the same as if no depletion
! or changed uptake rate were in effect
type mask_region_type
real, dimension(:,:,:), pointer :: mask => NULL()
real, dimension(:), pointer :: elon => NULL()
real, dimension(:), pointer :: nlat => NULL()
real, dimension(:), pointer :: slat => NULL()
real, dimension(:), pointer :: wlon => NULL()
logical :: coastal_only
real :: factor
logical, dimension(:), pointer :: t_mask => NULL()
end type mask_region_type
type biotic_type
real :: bio_tau
real :: bio_tau_don
real :: bio_tau_dop
real :: bio_tau_fix
real :: bio_tau_ldoc
real :: bio_tau_nh4
real :: bio_tau_nitrif_d
real :: bio_tau_nitrif_s
real :: c_2_n
real :: ca_remin_depth
real :: si_remin_depth
real :: compensation_depth
real, _ALLOCATABLE, dimension(:,:) :: comp_depth_frac _NULL
real, _ALLOCATABLE, dimension(:,:) :: alpha _NULL
real, _ALLOCATABLE, dimension(:,:) :: csurf _NULL
logical :: fe_ballast_assoc
real, _ALLOCATABLE, dimension(:,:,:) :: fpon _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: fpop _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: fcaco3 _NULL
real :: fdetL0
real :: fdetS0
character(len=fm_string_len) :: local_restart_file
real, _ALLOCATABLE, dimension(:,:) :: flux_caco3 _NULL
real, _ALLOCATABLE, dimension(:,:) :: flux_pon _NULL
real, _ALLOCATABLE, dimension(:,:) :: flux_pop _NULL
real, _ALLOCATABLE, dimension(:,:) :: flux_sio2 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: fracl _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: fsio2 _NULL
real :: gamma_det
real :: global_wrk_duration = 0.0
real, _ALLOCATABLE, dimension(:,:) :: htotal _NULL
integer :: id_alpha = -1
integer :: id_csurf = -1
integer :: id_fpon = -1
integer :: id_fpop = -1
integer :: id_fcaco3 = -1
integer :: id_flux_caco3 = -1
integer :: id_flux_pon = -1
integer :: id_flux_pop = -1
integer :: id_flux_sio2 = -1
integer :: id_fracl = -1
integer :: id_fsio2 = -1
integer :: id_htotal = -1
integer :: id_jcaco3 = -1
integer :: id_jdenit = -1
integer :: id_jdon = -1
integer :: id_jdop = -1
integer :: id_jfe_ads = -1
integer :: id_jfe_des = -1
integer :: id_jfe_graz = -1
integer :: id_jfe_sink = -1
integer :: id_jldoc = -1
integer :: id_jnh4 = -1
integer :: id_jnh4_graz = -1
integer :: id_jno3 = -1
integer :: id_jo2 = -1
integer :: id_jpo4 = -1
integer :: id_jpo4_graz = -1
integer :: id_jpofe = -1
integer :: id_jpon = -1
integer :: id_jpop = -1
integer :: id_jprod_alk = -1
integer :: id_jprod_fed = -1
integer :: id_jprod_n_fix = -1
integer :: id_jprod_nh4 = -1
integer :: id_jprod_no3 = -1
integer :: id_jprod_n_norm = -1
integer :: id_jprod_p_norm = -1
integer :: id_jprod_p_fix = -1
integer :: id_jprod_po4 = -1
integer :: id_jprod_pofe = -1
integer :: id_jprod_pon = -1
integer :: id_jprod_pop = -1
integer :: id_jprod_sio4 = -1
integer :: id_jsio4 = -1
integer :: id_pco2surf = -1
integer :: id_sfc_flux_co2 = -1
integer :: id_sfc_flux_o2 = -1
integer :: id_sfc_flux_fed = -1
integer :: ind_alk
integer :: ind_dic
integer :: ind_don
integer :: ind_dop
integer :: ind_fed
integer :: ind_fep
integer :: ind_ldoc
integer :: ind_nh4
integer :: ind_no3
integer :: ind_o2
integer :: ind_po4
integer :: ind_sio4
integer :: ind_co2_flux
integer :: ind_o2_flux
real, _ALLOCATABLE, dimension(:,:,:) :: jcaco3 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jdenit _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jdon _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jdop _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jfe_ads _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jfe_des _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jfe_graz _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jfe_sink _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jldoc _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jnh4 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jnh4_graz _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jno3 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jo2 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jpo4 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jpo4_graz _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jpofe _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jpon _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jpop _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_alk _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_fed _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_n_fix _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_nh4 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_no3 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_n_norm _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_p_norm _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_p_fix _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_po4 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_pofe _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_pon _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_pop _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jprod_sio4 _NULL
real, _ALLOCATABLE, dimension(:,:,:) :: jsio4 _NULL
real :: kappa_eppley
real :: kappa_remin
integer :: km_c
real :: kfe_bal
real :: kfe_des
real :: kfe_max_prime
real :: kfe_org
real :: martin_coeff
real :: mass_2_n
real :: n_2_p
real :: n_2_p_fix
character(len=fm_field_name_len) :: name
real :: o2_min
real :: o_2_c
real :: o_2_no3
real :: o_2_nh4
real :: o_2_nitrif
real, _ALLOCATABLE, dimension(:,:) :: pco2surf _NULL
real :: phi_wet
real :: phi_dry
real :: phi_don
real :: phi_dop
real :: phi_ldoc
real :: Prodstar
real, _ALLOCATABLE, dimension(:) :: r_1plusintzscale_si _NULL
real, _ALLOCATABLE, dimension(:) :: r_1plusintzscale_ca _NULL
real, _ALLOCATABLE, dimension(:) :: r_1plusintzscale_n _NULL
real :: r_bio_tau
real :: r_bio_tau_don
real :: r_bio_tau_dop
real :: r_bio_tau_fix
real :: r_bio_tau_ldoc
real :: r_bio_tau_nh4
real :: r_bio_tau_nitrif_d
real :: r_bio_tau_nitrif_s
type(mask_region_type) :: r_bio_tau_prod
type(mask_region_type) :: nut_depl
type(mask_region_type) :: norm_remin
type(mask_region_type) :: no_caco3
real, _ALLOCATABLE, dimension(:) :: r_intzscale_n _NULL
real :: r_wsink
logical :: remin_density
logical :: remin_lability
logical :: remin_ocmip2
logical :: remin_protection
logical :: remin_simple
logical :: remin_temp
logical :: remin_viscosity
logical :: remin_zoop_resp
real :: rpcaco3
real :: rpsio2
logical :: soft_tissue_pump
real :: stp_alkalinity
real :: stp_salinity
real :: stp_temperature
integer :: id_sc_co2 = -1
integer :: id_sc_o2 = -1
real, _ALLOCATABLE, dimension(:,:) :: sc_co2 _NULL
real :: sc_co2_0
real :: sc_co2_1
real :: sc_co2_2
real :: sc_co2_3
real, _ALLOCATABLE, dimension(:,:) :: sc_o2 _NULL
real :: sc_o2_0
real :: sc_o2_1
real :: sc_o2_2
real :: sc_o2_3
real :: wsink
real, _ALLOCATABLE, dimension(:) :: zforg _NULL
end type biotic_type
logical, public :: do_ocean_bgc_restore
integer :: indsal
integer :: indtemp
integer :: package_index
logical :: module_initialized = .false.
character(len=128) :: version = '$Id: ocean_bgc_restore.F90,v 20.0 2013/12/14 00:09:28 fms Exp $'
character(len=128) :: tagname = '$Name: tikal $'
! Input parameters:
!
! htotal_in = default value for htotal for an initial run
! htotal_scale_lo = scaling parameter to chose htotallo
! htotal_scale_hi = scaling parameter to chose htotalhi
real :: htotal_in
real, allocatable, dimension(:,:) :: htotal_scale_hi
real :: htotal_scale_hi_in
real, allocatable, dimension(:,:) :: htotal_scale_lo
real :: htotal_scale_lo_in
! Calculated parameters (with possible initial input values):
!
! global_wrk_duration = total time during calculation of global
! variables
character*128 :: alk_star_file
integer :: alk_star_id
character*128 :: alk_star_name
real, allocatable, dimension(:,:,:) :: alk_star_t
integer :: dep_wet_id
character*128 :: dep_wet_file
character*128 :: dep_wet_name
real, allocatable, dimension(:,:) :: dep_wet_t
integer :: dep_dry_id
character*128 :: dep_dry_file
character*128 :: dep_dry_name
real, allocatable, dimension(:,:) :: dep_dry_t
character*128 :: fed_star_file
integer :: fed_star_id
character*128 :: fed_star_name
real, allocatable, dimension(:,:,:) :: fed_star_t
integer :: id_o2_sat
integer :: km_c_max
character*128 :: no3_star_file
integer :: no3_star_id
character*128 :: no3_star_name
real, allocatable, dimension(:,:,:) :: no3_star_t
character*128 :: po4_star_file
integer :: po4_star_id
character*128 :: po4_star_name
real, allocatable, dimension(:,:,:) :: po4_star_t
real, allocatable, dimension(:,:) :: sc_no_term
character*128 :: sio4_star_file
integer :: sio4_star_id
character*128 :: sio4_star_name
real, allocatable, dimension(:,:,:) :: sio4_star_t
type(biotic_type), allocatable, dimension(:) :: biotic
integer :: instances
real, allocatable, dimension(:,:) :: o2_saturation
real, allocatable, dimension(:) :: tk
real, allocatable, dimension(:) :: ts
real, allocatable, dimension(:) :: ts2
real, allocatable, dimension(:) :: ts3
real, allocatable, dimension(:) :: ts4
real, allocatable, dimension(:) :: ts5
real, allocatable, dimension(:) :: tt
! for restart
integer :: num_restart = 0
type(restart_file_type), allocatable :: restart(:)
contains
!#######################################################################
! <SUBROUTINE NAME="allocate_arrays">
!
! <DESCRIPTION>
! Dynamically allocate arrays
! </DESCRIPTION>
!
subroutine allocate_arrays(isc, iec, jsc, jec, nk, isd, ied, jsd, jed)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
integer, intent(in) :: nk
integer :: i, j, k, l, m, n
allocate( dep_wet_t(isd:ied,jsd:jed) )
allocate( dep_dry_t(isd:ied,jsd:jed) )
allocate( sc_no_term(isc:iec,jsc:jec) )
allocate( htotal_scale_lo(isc:iec,jsc:jec) )
allocate( htotal_scale_hi(isc:iec,jsc:jec) )
allocate( o2_saturation(isc:iec,jsc:jec) )
allocate( tt(isc:iec) )
allocate( tk(isc:iec) )
allocate( ts(isc:iec) )
allocate( ts2(isc:iec) )
allocate( ts3(isc:iec) )
allocate( ts4(isc:iec) )
allocate( ts5(isc:iec) )
!allocate( po4_star_t(isd:ied,jsd:jed,km_c_max) )
! this should be dimensioned as above, but the time_interp routine
! requires that the array dimensions match the datasets dimensions
allocate( alk_star_t(isd:ied,jsd:jed,nk) )
allocate( fed_star_t(isd:ied,jsd:jed,nk) )
allocate( no3_star_t(isd:ied,jsd:jed,nk) )
allocate( po4_star_t(isd:ied,jsd:jed,nk) )
allocate( sio4_star_t(isd:ied,jsd:jed,nk) )
! initialize some arrays
dep_wet_t(:,:) = 0.0
dep_dry_t(:,:) = 0.0
sc_no_term(:,:) = 0.0
htotal_scale_lo(:,:) = 0.0
htotal_scale_hi(:,:) = 0.0
o2_saturation(:,:) = 0.0
tt(:) = 0.0
tk(:) = 0.0
ts(:) = 0.0
ts2(:) = 0.0
ts3(:) = 0.0
ts4(:) = 0.0
ts5(:) = 0.0
alk_star_t(:,:,:) = 0.0
fed_star_t(:,:,:) = 0.0
no3_star_t(:,:,:) = 0.0
po4_star_t(:,:,:) = 0.0
sio4_star_t(:,:,:) = 0.0
! allocate biotic array elements
do n = 1, instances
allocate( biotic(n)%sc_co2(isc:iec,jsc:jec) )
allocate( biotic(n)%sc_o2(isc:iec,jsc:jec) )
allocate( biotic(n)%htotal(isc:iec,jsc:jec) )
allocate( biotic(n)%csurf(isc:iec,jsc:jec) )
allocate( biotic(n)%alpha(isc:iec,jsc:jec) )
allocate( biotic(n)%comp_depth_frac(isc:iec,jsc:jec) )
allocate( biotic(n)%pco2surf(isc:iec,jsc:jec) )
allocate( biotic(n)%r_1plusintzscale_si(nk) )
allocate( biotic(n)%r_1plusintzscale_ca(nk) )
allocate( biotic(n)%r_1plusintzscale_n(nk) )
allocate( biotic(n)%r_intzscale_n(nk) )
allocate( biotic(n)%jfe_ads(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jfe_des(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jfe_graz(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jfe_sink(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jnh4(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jnh4_graz(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jno3(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jpo4(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jpo4_graz(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jpofe(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jpon(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jpop(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_alk(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_fed(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_n_fix(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_nh4(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_no3(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_n_norm(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_p_norm(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_p_fix(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_po4(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_pofe(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_pon(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_pop(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jprod_sio4(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jsio4(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jdenit(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jdon(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jdop(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jldoc(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jo2(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%jcaco3(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%fpon(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%fpop(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%fracl(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%fsio2(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%fcaco3(isc:iec,jsc:jec,nk) )
allocate( biotic(n)%flux_pon(isc:iec,jsc:jec) )
allocate( biotic(n)%flux_pop(isc:iec,jsc:jec) )
allocate( biotic(n)%flux_sio2(isc:iec,jsc:jec) )
allocate( biotic(n)%flux_caco3(isc:iec,jsc:jec) )
allocate( biotic(n)%nut_depl%mask(isc:iec,jsc:jec,12) )
allocate( biotic(n)%no_caco3%mask(isc:iec,jsc:jec,12) )
allocate( biotic(n)%norm_remin%mask(isc:iec,jsc:jec,12) )
allocate( biotic(n)%r_bio_tau_prod%mask(isc:iec,jsc:jec,12) )
allocate( biotic(n)%zforg(nk) )
enddo
! initialize bgc_restore array elements
do n = 1, instances
do j = jsc, jec
do i = isc, iec
biotic(n)%sc_co2(i,j) = 0.0
biotic(n)%sc_o2(i,j) = 0.0
biotic(n)%alpha(i,j) = 0.0
biotic(n)%comp_depth_frac(i,j) = 0.0
biotic(n)%pco2surf(i,j) = 0.0
biotic(n)%csurf(i,j) = 0.0
biotic(n)%htotal(i,j) = 0.0
do k = 1, nk
biotic(n)%jprod_alk(i,j,k) = 0.0
biotic(n)%jprod_fed(i,j,k) = 0.0
biotic(n)%jprod_n_fix(i,j,k) = 0.0
biotic(n)%jprod_nh4(i,j,k) = 0.0
biotic(n)%jprod_no3(i,j,k) = 0.0
biotic(n)%jprod_n_norm(i,j,k) = 0.0
biotic(n)%jprod_p_norm(i,j,k) = 0.0
biotic(n)%jprod_p_fix(i,j,k) = 0.0
biotic(n)%jprod_po4(i,j,k) = 0.0
biotic(n)%jprod_pofe(i,j,k) = 0.0
biotic(n)%jprod_pon(i,j,k) = 0.0
biotic(n)%jprod_pop(i,j,k) = 0.0
biotic(n)%jprod_sio4(i,j,k) = 0.0
biotic(n)%jfe_ads(i,j,k) = 0.0
biotic(n)%jfe_des(i,j,k) = 0.0
biotic(n)%jfe_graz(i,j,k) = 0.0
biotic(n)%jfe_sink(i,j,k) = 0.0
biotic(n)%jpo4(i,j,k) = 0.0
biotic(n)%jpofe(i,j,k) = 0.0
biotic(n)%jpon(i,j,k) = 0.0
biotic(n)%jpop(i,j,k) = 0.0
biotic(n)%jsio4(i,j,k) = 0.0
biotic(n)%jdenit(i,j,k) = 0.0
biotic(n)%jdon(i,j,k) = 0.0
biotic(n)%jdop(i,j,k) = 0.0
biotic(n)%jldoc(i,j,k) = 0.0
biotic(n)%jo2(i,j,k) = 0.0
biotic(n)%jcaco3(i,j,k) = 0.0
biotic(n)%fpon(i,j,k) = 0.0
biotic(n)%fpop(i,j,k) = 0.0
biotic(n)%fracl(i,j,k) = 0.0
biotic(n)%fsio2(i,j,k) = 0.0
biotic(n)%fcaco3(i,j,k) = 0.0
enddo
enddo
enddo
enddo
return
end subroutine allocate_arrays
! </SUBROUTINE> NAME="allocate_arrays"
!#######################################################################
! <SUBROUTINE NAME="locate">
!
! <DESCRIPTION>
! After Numerical recipes:
!
! Given an array XX of length N, and a given value of X, returns a
! value of J such that X is between XX(J) and XX(J+1). XX must be
! monotonic, either increasing or decreasing. J=0 or J=N is
! returned to indicate that X is out of range.
! New features:
!
! If "period" is specified, then the array, xx, is considered
! to be periodic with a period of "period". If "x_in" is out
! of range, then add or subtract "period" once to attempt to
! make "x_in" be in range.
!
! If "nearest" is specified, and true, then return "j" such
! that it is the element of "xx" which is nearest to the value
! of "x_in" (where "x_in" may have been modified by the value
! "period", above). With this option, "j" will be in
! the range 1 <= j <= n.
! </DESCRIPTION>
!
subroutine locate(xx , n, x_in, j, period, nearest)
integer, intent(in) :: n
real, intent(in) :: x_in
real, dimension(n), intent(in) :: xx
integer, intent(out) :: j
real, optional, intent(in) :: period
logical, optional, intent(in) :: nearest
integer :: jl, ju, jm
real :: x, xt
logical :: increasing
increasing = xx(1) .lt. xx(n)
if (present(period)) then
if (increasing) then
! increasing array
if (x_in .lt. xx(1)) then
! original value less than start, therefore add period
xt = x_in + period
if (xt .gt. xx(n)) then
! new value greater than end
if (abs(x_in - xx(1)) .gt. abs(xt - xx(n))) then
! new value closer to end than original value to start
! use new value
x = xt
else
! original value closer to start than new value to end
! use original value
x = x_in
endif
else
! new value in range
! use new value
x = xt
endif
elseif (x_in .gt. xx(n)) then
! original value greater than end, therefore subtract period
xt = x_in - period
if (xt .lt. xx(1)) then
! new value less than start
if (abs(xt - xx(1)) .lt. abs(x_in - xx(n))) then
! new value closer to start than original value to end
! use new value
x = xt
else
! original value closer to end than new value to start
! use original value
x = x_in
endif
else
! new value in range
! use new value
x = xt
endif
else
! original value in range
! use original value
x = x_in
endif
else
! decreasing array
if (x_in .gt. xx(1)) then
! original value greater than start, therefore subtract period
xt = x_in - period
if (xt .lt. xx(n)) then
! new value less than end
if (abs(x_in - xx(1)) .gt. abs(xt - xx(n))) then
! new value closer to end than original value to start
! use new value
x = xt
else
! original value closer to start than new value to end
! use original value
x = x_in
endif
else
! new value in range
! use new value
x = xt
endif
elseif (x_in .lt. xx(n)) then
! original value less than end, therefore add period
xt = x_in + period
if (xt .gt. xx(1)) then
! new value greater than start
if (abs(xt - xx(1)) .lt. abs(x_in - xx(n))) then
! new value closer to start than original value to end
! use new value
x = xt
else
! original value closer to end than new value to start
! use original value
x = x_in
endif
else
! new value in range
! use new value
x = xt
endif
else
! original value in range
! use original value
x = x_in
endif
endif
else
! no period specified
! use original value
x = x_in
endif
jl = 0
ju = n+1
10 continue
if (ju - jl .gt. 1) then
jm = (ju + jl) / 2
if (increasing .eqv. (x .gt. xx(jm))) then
jl = jm
else
ju = jm
endif
go to 10
endif
j = jl
if (present(nearest)) then
if (nearest) then
if (j .eq. 0) then
j = 1
elseif (j .lt. n) then
if (abs(x - xx(j)) .gt. abs(x - xx(j+1))) then
j = j + 1
endif
endif
endif
endif
return
end subroutine locate
! </SUBROUTINE> NAME="locate"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_bbc">
!
! <DESCRIPTION>
! calculate the surface boundary conditions
! </DESCRIPTION>
subroutine ocean_bgc_restore_bbc(isc, iec, jsc, jec, isd, ied, jsd, jed, T_prog, grid_kmt)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
type(ocean_prog_tracer_type), intent(inout), dimension(:) :: T_prog
integer, dimension(isd:,jsd:), intent(in) :: grid_kmt
integer :: i, j, n, kz
! set the bottom flux of the column for phosphate to reflect a
! regenerative flux from the sediments where the compensation
! depth is greater than the bottom depth
do n = 1, instances
if(biotic(n)%remin_ocmip2) then
do j = jsc, jec
do i = isc, iec
kz = grid_kmt(i,j)
if (kz .le. biotic(n)%km_c .and. kz .gt. 0) then
t_prog(biotic(n)%ind_po4)%btf(i,j) = &
t_prog(biotic(n)%ind_po4)%btf(i,j) - &
biotic(n)%flux_pop(i,j)
t_prog(biotic(n)%ind_nh4)%btf(i,j) = &
t_prog(biotic(n)%ind_nh4)%btf(i,j) - &
biotic(n)%flux_pon(i,j)
t_prog(biotic(n)%ind_sio4)%btf(i,j) = &
t_prog(biotic(n)%ind_sio4)%btf(i,j) - &
biotic(n)%flux_sio2(i,j)
t_prog(biotic(n)%ind_o2)%btf(i,j) = &
t_prog(biotic(n)%ind_o2)%btf(i,j) + &
biotic(n)%o_2_nh4 * biotic(n)%flux_pon(i,j)
t_prog(biotic(n)%ind_dic)%btf(i,j) = &
t_prog(biotic(n)%ind_dic)%btf(i,j) + &
biotic(n)%flux_caco3(i,j) - biotic(n)%c_2_n * &
biotic(n)%flux_pon(i,j)
t_prog(biotic(n)%ind_alk)%btf(i,j) = &
t_prog(biotic(n)%ind_alk)%btf(i,j) + &
biotic(n)%flux_pon(i,j) - 2.0 * biotic(n)%flux_caco3(i,j)
endif
enddo
enddo
endif
enddo
return
end subroutine ocean_bgc_restore_bbc
! </SUBROUTINE> NAME="ocean_bgc_restore_bbc"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_end">
!
! <DESCRIPTION>
! Clean up various BIOTIC quantities for this run.
! </DESCRIPTION>
subroutine ocean_bgc_restore_end(isc, iec, jsc, jec, nk, isd, ied, jsd, jed, &
T_prog, T_diag, grid_dat, grid_tmask, mpp_domain2d, rho_dzt, taup1)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: nk
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
type(ocean_prog_tracer_type), intent(in), dimension(:) :: T_prog
type(ocean_diag_tracer_type), intent(in), dimension(:) :: T_diag
integer, intent(in) :: taup1
real, dimension(isd:,jsd:), intent(in) :: grid_dat
real, dimension(isd:,jsd:,:), intent(in) :: grid_tmask
type(domain2d), intent(in) :: mpp_domain2d
real, dimension(isd:,jsd:,:,:), intent(in) :: rho_dzt
character(len=64), parameter :: sub_name = 'ocean_bgc_restore_end'
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
integer :: i, j, k, n
integer :: lun
character(len=fm_field_name_len+1) :: suffix
real :: total_alkalinity
real :: total_ammonia
real :: total_dic
real :: total_don
real :: total_dop
real :: total_fediss
real :: total_fepart
real :: total_ldoc
real :: total_o2
real :: total_nitrate
real :: total_phosphate
real :: total_silicate
integer :: stdoutunit
stdoutunit=stdout()
! integrate the total concentrations of some tracers
! for the end of the run
! Use taup1 time index for the start of a run, and taup1 time
! index for the end of a run so that we are integrating the
! same time level and should therefore get identical results
do n = 1, instances
total_alkalinity = 0.0
total_ammonia = 0.0
total_dic = 0.0
total_don = 0.0
total_dop = 0.0
total_fediss = 0.0
total_fepart = 0.0
total_ldoc = 0.0
total_nitrate = 0.0
total_o2 = 0.0
total_phosphate = 0.0
total_silicate = 0.0
do k = 1,nk
do j = jsc, jec
do i = isc, iec
total_nitrate = total_nitrate + &
t_prog(biotic(n)%ind_no3)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_ammonia = total_ammonia + &
t_prog(biotic(n)%ind_nh4)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_phosphate = total_phosphate + &
t_prog(biotic(n)%ind_po4)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_fediss = total_fediss + &
t_prog(biotic(n)%ind_fed)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_fepart = total_fepart + &
t_diag(biotic(n)%ind_fep)%field(i,j,k) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_silicate = total_silicate + &
t_prog(biotic(n)%ind_sio4)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_don = total_don + &
t_prog(biotic(n)%ind_don)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_dop = total_dop + &
t_prog(biotic(n)%ind_dop)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_ldoc = total_ldoc + &
t_prog(biotic(n)%ind_ldoc)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_o2 = total_o2 + &
t_prog(biotic(n)%ind_o2)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_dic = total_dic + &
t_prog(biotic(n)%ind_dic)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_alkalinity = total_alkalinity + &
t_prog(biotic(n)%ind_alk)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
enddo
enddo
enddo
call mpp_sum(total_nitrate)
call mpp_sum(total_ammonia)
call mpp_sum(total_phosphate)
call mpp_sum(total_fediss)
call mpp_sum(total_fepart)
call mpp_sum(total_silicate)
call mpp_sum(total_don)
call mpp_sum(total_dop)
call mpp_sum(total_ldoc)
call mpp_sum(total_o2)
call mpp_sum(total_dic)
call mpp_sum(total_alkalinity)
write (stdoutunit,*) ' Instance ', trim(biotic(n)%name)
write (stdoutunit, &
'(/'' Total nitrate = '',es19.12,'' Gmol-N'')') &
total_nitrate * 1.0e-09
write (stdoutunit, &
'(/'' Total ammonia = '',es19.12,'' Gmol-N'')') &
total_ammonia * 1.0e-09
write (stdoutunit, &
'(/'' Total phosphate = '',es19.12,'' Gmol-P'')') &
total_phosphate * 1.0e-09
write (stdoutunit, &
'(/'' Total fediss = '',es19.12,'' Gmol-Fe'')') &
total_fediss * 1.0e-09
write (stdoutunit, &
'(/'' Total fepart = '',es19.12,'' Gmol-Fe'')') &
total_fepart * 1.0e-09
write (stdoutunit, &
'(/'' Total silicate = '',es19.12,'' Gmol-Si'')') &
total_silicate * 1.0e-09
write (stdoutunit, &
'(/'' Total DON = '',es19.12,'' Gmol-C'')') &
total_DON * 1.0e-09
write (stdoutunit, &
'(/'' Total DOP = '',es19.12,'' Gmol-P'')') &
total_DOP * 1.0e-09
write (stdoutunit, &
'(/'' Total LDOC = '',es19.12,'' Gmol-C'')') &
total_LDOC * 1.0e-09
write (stdoutunit, &
'(/'' Total O2 = '',es19.12,'' Gmol-O'')') &
total_o2 * 1.0e-09
write (stdoutunit, &
'(/'' Total DIC = '',es19.12,'' Gmol-C'')') &
total_dic * 1.0e-09
write (stdoutunit, &
'(/'' Total alkalinity = '',es19.12,'' Geq'')') &
total_alkalinity * 1.0e-09
write (stdoutunit, &
'(/'' Total nitrogen = '',es19.12,'' Gmol-N'')') &
(total_nitrate + total_don) * 1.0e-09
write (stdoutunit, &
'(/'' Total phosphorus = '',es19.12,'' Gmol-P'')') &
(total_phosphate + total_dop) * 1.0e-09
write (stdoutunit, &
'(/'' Total real O2 = '',es19.12,'' Gmol-O'')') &
(total_o2 + biotic(n)%o_2_no3 * total_nitrate) * 1.0e-09
write (stdoutunit, &
'(/'' Total Carbon = '',es19.12,'' Gmol-C'')') &
(total_dic + biotic(n)%c_2_n * total_don + total_ldoc) * 1.0e-09
write (stdoutunit, &
'(/'' Total real alkalinity = '',es19.12,'' Geq'')') &
(total_alkalinity + total_nitrate) * 1.0e-09
enddo
! save out additional information for a restart
write(stdoutunit,*)
call ocean_bgc_restore_restart
do n = 1, instances
write(stdoutunit,*) trim(note_header), &
'Writing additional restart information for instance ', &
trim(biotic(n)%name)
write (stdoutunit,*) trim(note_header), &
'Done writing additional restart information for instance ',&
trim(biotic(n)%name)
enddo
return
end subroutine ocean_bgc_restore_end
! </SUBROUTINE> NAME="ocean_bgc_restore_end"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_restart">
! <DESCRIPTION>
! Write out restart files registered through register_restart_file
! </DESCRIPTION>
subroutine ocean_bgc_restore_restart(time_stamp)
character(len=*), intent(in), optional :: time_stamp
integer :: n
do n=1, num_restart
call save_restart(restart(n), time_stamp)
end do
end subroutine ocean_bgc_restore_restart
! </SUBROUTINE> NAME="ocean_bgc_restore_restart"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_sbc">
!
! <DESCRIPTION>
! Calculate the surface boundary conditions
! </DESCRIPTION>
subroutine ocean_bgc_restore_sbc(isc, iec, jsc, jec, nk, isd, ied, jsd, jed, &
isc_bnd, iec_bnd, jsc_bnd, jec_bnd, &
T_prog, tau, Time, Grid, ice_ocean_boundary_fluxes)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: nk
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
integer, intent(in) :: isc_bnd
integer, intent(in) :: iec_bnd
integer, intent(in) :: jsc_bnd
integer, intent(in) :: jec_bnd
type(ocean_prog_tracer_type), intent(inout), dimension(:) :: T_prog
integer, intent(in) :: tau
type(ocean_time_type), intent(in) :: Time
type(ocean_grid_type), intent(in) :: Grid
type(coupler_2d_bc_type), intent(in) :: ice_ocean_boundary_fluxes
integer :: i, j, n
integer :: i_bnd_off
integer :: j_bnd_off
logical :: used
! calculate interpolated iron deposition
call time_interp_external(dep_dry_id, Time%model_time, dep_dry_t)
! use the surface fluxes from the coupler
! stf is in mol/m^2/s, flux from coupler is positive upwards
i_bnd_off = isc - isc_bnd
j_bnd_off = jsc - jsc_bnd
do n = 1, instances
do j = jsc, jec
do i = isc, iec
t_prog(biotic(n)%ind_dic)%stf(i,j) = &
-ice_ocean_boundary_fluxes%bc(biotic(n)%ind_co2_flux)%field(ind_flux)%values(i-i_bnd_off,j-j_bnd_off)
t_prog(biotic(n)%ind_o2)%stf(i,j) = &
-ice_ocean_boundary_fluxes%bc(biotic(n)%ind_o2_flux)%field(ind_flux)%values(i-i_bnd_off,j-j_bnd_off)
enddo
enddo
! surface iron deposition fluxes from Ginoux et al (JGR, Sources
! and distributions of dust aerosols simulated with the GOCART
! model, 2001) and converted by Gregg et al (GRL, Ocean primary
! producion and climate: Global decadal changes, in press) assuming a 2%
! solubility of Fe in dust.
! For additional source from extraterrestrial dust after Johnson
! (GBC, Iron supply and demand in the upper ocean: Is extraterrestrial
! dust a significant source of bioavailable iron?), add a constant flux
! of 9.51e-15.
do j = jsc, jec
do i = isc, iec
t_prog(biotic(n)%ind_fed)%stf(i,j) = dep_dry_t(i,j)
enddo
enddo
enddo
! Save variables for diagnostics
do n = 1, instances
call diagnose_2d(Time, Grid, biotic(n)%id_sfc_flux_co2, t_prog(biotic(n)%ind_dic)%stf(:,:))
call diagnose_2d(Time, Grid, biotic(n)%id_sfc_flux_o2, t_prog(biotic(n)%ind_o2)%stf(:,:))
call diagnose_2d(Time, Grid, biotic(n)%id_sfc_flux_fed, t_prog(biotic(n)%ind_fed)%stf(:,:))
enddo
return
end subroutine ocean_bgc_restore_sbc
! </SUBROUTINE> NAME="ocean_bgc_restore_sbc"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_flux_init">
!
! <DESCRIPTION>
! Set up any extra fields needed by the ocean-atmosphere gas fluxes
! </DESCRIPTION>
subroutine ocean_bgc_restore_flux_init
use atmos_ocean_fluxes_mod, only: aof_set_coupler_flux
character(len=64), parameter :: sub_name = 'ocean_bgc_restore_flux_init'
character(len=256), parameter :: error_header = &
'==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
integer :: n
character(len=fm_field_name_len) :: name
character(len=fm_path_name_len) :: path_to_names
character(len=fm_field_name_len+1) :: suffix
character(len=256) :: caller_str
integer :: stdoutunit
stdoutunit=stdout()
! First, perform some initialization if this module has not been
! initialized because the normal initialization routine will
! not have been called as part of the normal ocean model
! initialization if this is an Atmosphere pe of a coupled
! model running in concurrent mode
if (.not. module_initialized) then
! Initialize the package
package_index = otpm_set_tracer_package(package_name, &
restart_file = default_restart_file, &
caller = trim(mod_name) // '(' // trim(sub_name) // ')')
! Check whether to use this package
path_to_names = '/ocean_mod/tracer_packages/' // trim(package_name) // '/names'
instances = fm_get_length(path_to_names)
if (instances .lt. 0) then
call mpp_error(FATAL, trim(error_header) // ' Could not get number of instances')
endif
write (stdoutunit,*)
if (instances .eq. 0) then
write (stdoutunit,*) trim(note_header), ' No instances'
do_ocean_bgc_restore = .false.
else
if (instances .eq. 1) then
write (stdoutunit,*) trim(note_header), ' ', instances, ' instance'
else
write (stdoutunit,*) trim(note_header), ' ', instances, ' instances'
endif
do_ocean_bgc_restore = .true.
endif
module_initialized = .true.
endif
! Return if we don't want to use this package
if (.not. do_ocean_bgc_restore) then
return
endif
if (.not. allocated(biotic)) then
! allocate storage for biotic array
allocate ( biotic(instances) )
! loop over the names, saving them into the biotic array
do n = 1, instances
if (fm_get_value(path_to_names, name, index = n)) then
biotic(n)%name = name
else
write (name,*) n
call mpp_error(FATAL, trim(error_header) // &
'Bad field name for index ' // trim(name))
endif
enddo
endif
! Set up the ocean-atmosphere gas flux fields
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')'
do n = 1, instances
name = biotic(n)%name
if (name(1:1) .eq. '_') then
suffix = ' '
else
suffix = '_' // name
endif
! Coupler fluxes
biotic(n)%ind_co2_flux = aof_set_coupler_flux('co2_flux' // suffix, &
flux_type = 'air_sea_gas_flux', implementation = 'ocmip2', &
mol_wt = WTMCO2, param = (/ 9.36e-07, 9.7561e-06 /), &
ice_restart_file = default_ice_restart_file, &
ocean_restart_file = default_ocean_restart_file, &
caller = caller_str)
biotic(n)%ind_o2_flux = aof_set_coupler_flux('o2_flux' // suffix, &
flux_type = 'air_sea_gas_flux', implementation = 'ocmip2', &
mol_wt = WTMO2, param = (/ 9.36e-07, 9.7561e-06 /), &
ice_restart_file = default_ice_restart_file, &
ocean_restart_file = default_ocean_restart_file, &
caller = caller_str)
enddo
return
end subroutine ocean_bgc_restore_flux_init
!</SUBROUTINE> NAME="ocean_bgc_restore_flux_init"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_init">
!
! <DESCRIPTION>
! Set up any extra fields needed by the tracer packages
!
! Save pointers to various "types", such as Grid and Domains.
! </DESCRIPTION>
subroutine ocean_bgc_restore_init
character(len=64), parameter :: sub_name = 'ocean_bgc_restore_init'
character(len=256), parameter :: error_header = &
'==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
real, parameter :: rho_avg = 1024.5
real, parameter :: sperd = 24.0 * 3600.0
integer :: n
character(len=fm_field_name_len) :: name
character(len=fm_path_name_len) :: path_to_names
character(len=fm_field_name_len+1) :: suffix
character(len=fm_field_name_len+3) :: long_suffix
logical, dimension(12) :: t_mask
character(len=256) :: caller_str
character(len=fm_string_len), pointer, dimension(:) :: good_list
integer :: stdoutunit
stdoutunit=stdout()
! Initialize the restoring package
package_index = otpm_set_tracer_package(package_name, &
restart_file = default_restart_file, &
caller = trim(mod_name) // '(' // trim(sub_name) // ')')
! Check whether to use this package
path_to_names = '/ocean_mod/tracer_packages/' // trim(package_name) // '/names'
instances = fm_get_length(path_to_names)
if (instances .lt. 0) then
call mpp_error(FATAL, trim(error_header) // ' Could not get number of instances')
endif
write (stdoutunit,*)
if (instances .eq. 0) then
write (stdoutunit,*) trim(note_header), ' No instances'
do_ocean_bgc_restore = .false.
else
if (instances .eq. 1) then
write (stdoutunit,*) trim(note_header), ' ', instances, ' instance'
else
write (stdoutunit,*) trim(note_header), ' ', instances, ' instances'
endif
do_ocean_bgc_restore = .true.
endif
module_initialized = .true.
! Return if we don't want to use this package,
! after changing the list back
if (.not. do_ocean_bgc_restore) then
return
endif
! allocate storage for biotic array
allocate ( biotic(instances) )
! loop over the names, saving them into the biotic array
do n = 1, instances
if (fm_get_value(path_to_names, name, index = n)) then
biotic(n)%name = name
else
write (name,*) n
call mpp_error(FATAL, trim(error_header) // &
'Bad field name for index ' // trim(name))
endif
enddo
! Set up the field input
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')'
do n = 1, instances
name = biotic(n)%name
if (name(1:1) .eq. '_') then
suffix = ' '
long_suffix = ' '
else
suffix = '_' // name
long_suffix = ' (' // trim(name) // ')'
endif
! NO3
biotic(n)%ind_no3 = otpm_set_prog_tracer('no3' // suffix, package_name, &
longname = 'Nitrate' // trim(long_suffix), &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! NH4
biotic(n)%ind_nh4 = otpm_set_prog_tracer('nh4' // suffix, package_name, &
longname = 'Ammonia' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! PO4
biotic(n)%ind_po4 = otpm_set_prog_tracer('po4' // suffix, package_name, &
longname = 'Phosphate' // trim(long_suffix), &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! Dissolved Fe (assumed to be all available to phytoplankton)
biotic(n)%ind_fed = otpm_set_prog_tracer('fed' // suffix, package_name, &
longname = 'Dissolved Iron' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! Fep (Sinking detrital/particulate iron)
biotic(n)%ind_fep = otpm_set_diag_tracer('fep' // suffix, package_name, &
longname = 'Particulate Iron' // '(' // trim(name) // ')', &
restart_file = default_restart_file, units = 'mol/kg')
! SiO4
biotic(n)%ind_sio4 = otpm_set_prog_tracer('sio4' // suffix, package_name, &
longname = 'Silicate' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! DON
biotic(n)%ind_don = otpm_set_prog_tracer('don' // suffix, package_name, &
longname = 'DON' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! DOP
biotic(n)%ind_dop = otpm_set_prog_tracer('dop' // suffix, package_name, &
longname = 'DOP' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! LDOC
biotic(n)%ind_ldoc = otpm_set_prog_tracer('ldoc' // suffix, package_name, &
longname = 'labile DOC' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! DIC
biotic(n)%ind_dic = otpm_set_prog_tracer('dic' // suffix, package_name, &
longname = 'DIC' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! O2
biotic(n)%ind_o2 = otpm_set_prog_tracer('o2' // suffix, package_name, &
longname = 'Oxygen' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
! ALK (Total carbonate alkalinity)
biotic(n)%ind_alk = otpm_set_prog_tracer('alk' // suffix, package_name, &
longname = 'Alkalinity' // '(' // trim(name) // ')', &
units = 'mol/kg', flux_units = 'mol/m^2/s', &
caller = caller_str)
enddo
! Process the namelists
! Add the package name to the list of good namelists, to be used
! later for a consistency check
if (fm_new_value('/ocean_mod/GOOD/good_namelists', package_name, append = .true.) .le. 0) then
call mpp_error(FATAL, trim(error_header) // &
' Could not add ' // trim(package_name) // ' to "good_namelists" list')
endif
! Set up the *global* namelist
call fm_util_start_namelist(package_name, '*global*', caller = caller_str, no_overwrite = .true., &
check = .true.)
call fm_util_set_value('dep_dry_file', 'INPUT/fe_dep_bc.nc')
call fm_util_set_value('dep_dry_name', 'fe_dep')
call fm_util_set_value('dep_wet_file', 'INPUT/fe_dep_bc.nc')
call fm_util_set_value('dep_wet_name', 'fe_dep')
call fm_util_set_value('no3_star_file', 'INPUT/no3_star.nc')
call fm_util_set_value('no3_star_name', 'no3_star')
call fm_util_set_value('po4_star_file', 'INPUT/po4_star.nc')
call fm_util_set_value('po4_star_name', 'po4_star')
call fm_util_set_value('sio4_star_file', 'INPUT/sio4_star.nc')
call fm_util_set_value('sio4_star_name', 'sio4_star')
call fm_util_set_value('alk_star_file', 'INPUT/alk_star.nc')
call fm_util_set_value('alk_star_name', 'alk_star')
call fm_util_set_value('fed_star_file', 'INPUT/fed_star.nc')
call fm_util_set_value('fed_star_name', 'fed_star')
call fm_util_set_value('htotal_scale_lo_in', 0.01 ) ! scale
call fm_util_set_value('htotal_scale_hi_in', 100.0) ! scale
call fm_util_set_value('htotal_in', 1.0e-08)
call fm_util_end_namelist(package_name, '*global*', caller = caller_str, check = .true.)
! Set up the instance namelists
t_mask(:) = .true.
do n = 1, instances
! create the instance namelist
call fm_util_start_namelist(package_name, biotic(n)%name, caller = caller_str, no_overwrite = .true., &
check = .true.)
call fm_util_set_value('compensation_depth', 75.0) ! m
call fm_util_set_value('martin_coeff', 0.9)
call fm_util_set_value('ca_remin_depth', 3500.0)
call fm_util_set_value('si_remin_depth', 1000.0)
call fm_util_set_value('soft_tissue_pump', .false.)
call fm_util_set_value('stp_temperature', 10.0)
call fm_util_set_value('stp_salinity', 34.7)
! alkalinity is in ueq/kg, converted to eq/m^3
call fm_util_set_value('stp_alkalinity', 2370.0 * 1024.5 * 1.0e-06)
call fm_util_set_value('local_restart_file', default_local_restart_file)
call fm_util_set_value('fe_ballast_assoc', .false.)
call fm_util_set_value('phi_dry', 0.03)
call fm_util_set_value('phi_wet', 0.03)
call fm_util_set_value('kfe_org', 0.005/sperd)
call fm_util_set_value('kfe_bal', 0.005/sperd)
call fm_util_set_value('kfe_des', 0.0/sperd)
call fm_util_set_value('kfe_max_prime', 1.0/sperd)
call fm_util_set_value('mass_2_n', 117.0/16.0*12.0*1.87)
call fm_util_set_value('n_2_p', 16.0)
call fm_util_set_value('n_2_p_fix', 40.0)
call fm_util_set_value('c_2_n', 117.0/16.0)
call fm_util_set_value('o_2_c', 170.0/16.0)
call fm_util_set_value('o_2_no3', 255.0/16.0)
call fm_util_set_value('o_2_nh4', 207.0/16.0)
call fm_util_set_value('o_2_nitrif', 3.0)
call fm_util_set_value('o2_min', 4.0 * rho_avg * 1.0e-06)
call fm_util_set_value('bio_tau', 30.0 * sperd)
call fm_util_set_value('bio_tau_don', 30.0*365.0*sperd)
call fm_util_set_value('bio_tau_dop', 30.0*365.0*sperd)
call fm_util_set_value('bio_tau_fix', 90.0*sperd)
call fm_util_set_value('bio_tau_ldoc', 0.5*365.0*sperd)
call fm_util_set_value('bio_tau_nh4', 3.0*sperd)
call fm_util_set_value('bio_tau_nitrif_d', 10.0*sperd)
call fm_util_set_value('bio_tau_nitrif_s', 1e20*sperd)
call fm_util_set_value('kappa_eppley', 0.063)
call fm_util_set_value('kappa_remin', -0.032)
call fm_util_set_value('Prodstar', 0.37/1000*16/117/sperd)
call fm_util_set_value('fdets0', 0.14)
call fm_util_set_value('fdetl0', 0.74)
call fm_util_set_value('phi_don', 0.04)
call fm_util_set_value('phi_dop', 0.04)
call fm_util_set_value('phi_ldoc', 0.04)
call fm_util_set_value('gamma_det', 0.0116/sperd)
call fm_util_set_value('remin_density', .false.)
call fm_util_set_value('remin_lability', .false.)
call fm_util_set_value('remin_ocmip2', .false.)
call fm_util_set_value('remin_protection', .true.)
call fm_util_set_value('remin_simple', .false.)
call fm_util_set_value('remin_temp', .false.)
call fm_util_set_value('remin_viscosity', .false.)
call fm_util_set_value('remin_zoop_resp', .false.)
call fm_util_set_value('rpcaco3', 0.070/12*16/117*100)
call fm_util_set_value('rpsio2', 0.026/12*16/117*60)
call fm_util_set_value('wsink', 3.0/sperd)
! Wanninkhof numbers
call fm_util_set_value('sc_co2_0', 2068.9)
call fm_util_set_value('sc_co2_1', -118.63)
call fm_util_set_value('sc_co2_2', 2.9311)
call fm_util_set_value('sc_co2_3', -0.027)
call fm_util_set_value('sc_o2_0', 1929.7)
call fm_util_set_value('sc_o2_1', -117.46)
call fm_util_set_value('sc_o2_2', 3.116)
call fm_util_set_value('sc_o2_3', -0.0306)
call fm_util_end_namelist(package_name, biotic(n)%name, check = .true., caller = caller_str)
! create some sub-namelists
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+norm_remin', &
caller = caller_str, no_overwrite = .true., &
check = .true.)
call fm_util_set_value('factor', 0.0)
call fm_util_set_value('coastal_only', .false.)
call fm_util_set_value('t_mask', t_mask, size(t_mask))
call fm_util_set_value('wlon', 0.0, index = 0)
call fm_util_set_value('elon', 0.0, index = 0)
call fm_util_set_value('slat', 0.0, index = 0)
call fm_util_set_value('nlat', 0.0, index = 0)
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+norm_remin', caller = caller_str)
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+no_caco3', &
caller = caller_str, no_overwrite = .true., &
check = .true.)
call fm_util_set_value('factor', 0.0)
call fm_util_set_value('coastal_only', .false.)
call fm_util_set_value('t_mask', t_mask, size(t_mask))
call fm_util_set_value('wlon', 0.0, index = 0)
call fm_util_set_value('elon', 0.0, index = 0)
call fm_util_set_value('slat', 0.0, index = 0)
call fm_util_set_value('nlat', 0.0, index = 0)
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+no_caco3', caller = caller_str)
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+nut_depl', &
caller = caller_str, no_overwrite = .true., &
check = .true.)
call fm_util_set_value('factor', 0.0)
call fm_util_set_value('coastal_only', .false.)
call fm_util_set_value('t_mask', t_mask, size(t_mask))
call fm_util_set_value('wlon', 0.0, index = 0)
call fm_util_set_value('elon', 0.0, index = 0)
call fm_util_set_value('slat', 0.0, index = 0)
call fm_util_set_value('nlat', 0.0, index = 0)
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+nut_depl', caller = caller_str)
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+r_bio_tau_prod', &
caller = caller_str, no_overwrite = .true., &
check = .true.)
call fm_util_set_value('factor', 0.0)
call fm_util_set_value('coastal_only', .false.)
call fm_util_set_value('t_mask', t_mask, size(t_mask))
call fm_util_set_value('wlon', 0.0, index = 0)
call fm_util_set_value('elon', 0.0, index = 0)
call fm_util_set_value('slat', 0.0, index = 0)
call fm_util_set_value('nlat', 0.0, index = 0)
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+r_bio_tau_prod', caller = caller_str)
enddo
! Check for any errors in the number of fields in the namelists for this package
good_list => fm_util_get_string_array('/ocean_mod/GOOD/namelists/' // trim(package_name) // '/good_values', &
caller = trim(mod_name) // '(' // trim(sub_name) // ')')
if (associated(good_list)) then
call fm_util_check_for_bad_fields('/ocean_mod/namelists/' // trim(package_name), good_list, &
caller = trim(mod_name) // '(' // trim(sub_name) // ')')
deallocate(good_list)
else
call mpp_error(FATAL,trim(error_header) // ' Empty "' // trim(package_name) // '" list')
endif
return
end subroutine ocean_bgc_restore_init
! </SUBROUTINE> NAME="ocean_bgc_restore_init"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_init_sfc">
!
! <DESCRIPTION>
! Initialize surface fields for flux calculations
!
! Note: this subroutine should be merged into ocean_bgc_restore_start
! </DESCRIPTION>
subroutine ocean_bgc_restore_init_sfc(isc, iec, jsc, jec, nk, isd, ied, jsd, jed, &
isc_bnd, iec_bnd, jsc_bnd, jec_bnd, &
Ocean_fields, T_prog, rho, taum1, model_time, grid_tmask)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: nk
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
integer, intent(in) :: isc_bnd
integer, intent(in) :: iec_bnd
integer, intent(in) :: jsc_bnd
integer, intent(in) :: jec_bnd
type(coupler_2d_bc_type), intent(inout) :: Ocean_fields
type(ocean_prog_tracer_type), dimension(:), intent(in) :: T_prog
real, dimension(isd:,jsd:,:,:), intent(in) :: rho
integer, intent(in) :: taum1
type(time_type), intent(in) :: model_time
real, dimension(isd:,jsd:,:), intent(in) :: grid_tmask
integer :: i, j, m, n
integer :: i_bnd_off
integer :: j_bnd_off
integer :: nn
integer :: ind
real :: epsln=1.0e-30
i_bnd_off = isc - isc_bnd
j_bnd_off = jsc - jsc_bnd
do n = 1, instances
! CO2 flux
ind = biotic(n)%ind_co2_flux
if (.not. field_exist('INPUT/'//trim(ocean_fields%bc(ind)%ocean_restart_file), &
ocean_fields%bc(ind)%field(ind_alpha)%name)) then
call ocmip2_co2calc(isd, jsd, isc, iec, jsc, jec, &
grid_tmask(isd:ied,jsd:jed,1), &
t_prog(indtemp)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(indsal)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_dic)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_alk)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_po4)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_sio4)%field(isd:ied,jsd:jed,1,taum1), &
htotal_scale_lo, htotal_scale_hi, biotic(n)%htotal, &
co2star = biotic(n)%csurf, alpha = biotic(n)%alpha, &
pco2surf = biotic(n)%pco2surf)
! Compute the Schmidt number of CO2 in seawater using the
! formulation presented by Wanninkhof (1992, J. Geophys. Res., 97,
! 7373-7382).
do j = jsc, jec
do i = isc, iec
biotic(n)%sc_co2(i,j) = &
biotic(n)%sc_co2_0 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_co2_1 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_co2_2 + t_prog(indtemp)%field(i,j,1,taum1) * &
biotic(n)%sc_co2_3)) * grid_tmask(i,j,1)
sc_no_term(i,j) = sqrt(660.0 / (biotic(n)%sc_co2(i,j) + epsln)) * grid_tmask(i,j,1)
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) = &
biotic(n)%alpha(i,j) * sc_no_term(i,j) * rho(i,j,1,taum1)
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) = &
biotic(n)%csurf(i,j) * sc_no_term(i,j) * rho(i,j,1,taum1)
enddo
enddo
endif
! O2 flux
ind = biotic(n)%ind_o2_flux
if (.not. field_exist('INPUT/'//trim(ocean_fields%bc(ind)%ocean_restart_file), &
ocean_fields%bc(ind)%field(ind_alpha)%name)) then
! Compute the oxygen saturation concentration at 1 atm total
! pressure in mol/m^3 given the temperature (t, in deg C) and
! the salinity (s, in permil)
!
! From Garcia and Gordon (1992), Limnology and Oceonography.
! The formula used is from page 1310, eq (8).
!
! *** Note: the "a3*ts^2" term (in the paper) is incorrect. ***
! *** It shouldn't be there. ***
!
! o2_saturation is defined between T(freezing) <= T <= 40 deg C and
! 0 permil <= S <= 42 permil
!
! check value: T = 10 deg C, S = 35 permil,
! o2_saturation = 0.282015 mol/m^3
do j = jsc, jec
do i = isc, iec
tt(i) = 298.15 - t_prog(indtemp)%field(i,j,1,taum1)
tk(i) = 273.15 + t_prog(indtemp)%field(i,j,1,taum1)
ts(i) = log(tt(i) / tk(i))
ts2(i) = ts(i) * ts(i)
ts3(i) = ts2(i) * ts(i)
ts4(i) = ts3(i) * ts(i)
ts5(i) = ts4(i) * ts(i)
o2_saturation(i,j) = &
exp(a_0 + a_1*ts(i) + a_2*ts2(i) + &
a_3*ts3(i) + a_4*ts4(i) + a_5*ts5(i) + &
t_prog(indsal)%field(i,j,1,taum1) * &
(b_0 + b_1*ts(i) + b_2*ts2(i) + b_3*ts3(i) + &
c_0*t_prog(indsal)%field(i,j,1,taum1))) * grid_tmask(i,j,1)
enddo
enddo
! convert from ml/l to mol/m^3
do j = jsc, jec
do i = isc, iec
o2_saturation(i,j) = o2_saturation(i,j) * (1000.0/22391.6)
enddo
enddo
! Compute the Schmidt number of O2 in seawater using the
! formulation proposed by Keeling et al. (1998, Global Biogeochem.
! Cycles, 12, 141-163).
do j = jsc, jec
do i = isc, iec
biotic(n)%sc_o2(i,j) = &
biotic(n)%sc_o2_0 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_o2_1 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_o2_2 + t_prog(indtemp)%field(i,j,1,taum1) * &
biotic(n)%sc_o2_3)) * grid_tmask(i,j,1)
sc_no_term(i,j) = sqrt(660.0 / (biotic(n)%sc_o2(i,j) + epsln)) * grid_tmask(i,j,1)
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) = &
o2_saturation(i,j) * sc_no_term(i,j)
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) = &
t_prog(biotic(n)%ind_o2)%field(i,j,1,taum1) * sc_no_term(i,j) * rho(i,j,1,taum1)
enddo
enddo
endif
enddo
return
end subroutine ocean_bgc_restore_init_sfc
! </SUBROUTINE> NAME="ocean_bgc_restore_init_sfc"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_sum_sfc">
!
! <DESCRIPTION>
! Sum surface fields for flux calculations
! </DESCRIPTION>
subroutine ocean_bgc_restore_sum_sfc(isc, iec, jsc, jec, nk, isd, ied, jsd, jed, &
isc_bnd, iec_bnd, jsc_bnd, jec_bnd, &
Ocean_fields, T_prog, rho, taum1, model_time, grid_tmask)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: nk
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
integer, intent(in) :: isc_bnd
integer, intent(in) :: iec_bnd
integer, intent(in) :: jsc_bnd
integer, intent(in) :: jec_bnd
type(coupler_2d_bc_type), intent(inout) :: Ocean_fields
type(ocean_prog_tracer_type), intent(in), dimension(:) :: T_prog
real, dimension(isd:,jsd:,:,:), intent(in) :: rho
integer, intent(in) :: taum1
type(time_type), intent(in) :: model_time
real, dimension(isd:,jsd:,:), intent(in) :: grid_tmask
integer :: i
integer :: i_bnd_off
integer :: j_bnd_off
integer :: j
integer :: n
integer :: nn
integer :: ind
real :: epsln=1.0e-30
i_bnd_off = isc - isc_bnd
j_bnd_off = jsc - jsc_bnd
do n = 1, instances
ind = biotic(n)%ind_co2_flux
call ocmip2_co2calc(isd, jsd, isc, iec, jsc, jec, &
grid_tmask(isd:ied,jsd:jed,1), &
t_prog(indtemp)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(indsal)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_dic)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_alk)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_po4)%field(isd:ied,jsd:jed,1,taum1), &
t_prog(biotic(n)%ind_sio4)%field(isd:ied,jsd:jed,1,taum1), &
htotal_scale_lo, htotal_scale_hi, biotic(n)%htotal, &
co2star = biotic(n)%csurf, alpha = biotic(n)%alpha, &
pco2surf = biotic(n)%pco2surf)
! Compute the Schmidt number of CO2 in seawater using the
! formulation presented by Wanninkhof (1992, J. Geophys. Res., 97,
! 7373-7382).
do j = jsc, jec
do i = isc, iec
biotic(n)%sc_co2(i,j) = &
biotic(n)%sc_co2_0 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_co2_1 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_co2_2 + t_prog(indtemp)%field(i,j,1,taum1) * &
biotic(n)%sc_co2_3)) * grid_tmask(i,j,1)
sc_no_term(i,j) = sqrt(660.0 / (biotic(n)%sc_co2(i,j) + epsln)) * grid_tmask(i,j,1)
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) + &
biotic(n)%alpha(i,j) * sc_no_term(i,j) * rho(i,j,1,taum1)
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) + &
biotic(n)%csurf(i,j) * sc_no_term(i,j) * rho(i,j,1,taum1)
enddo
enddo
ind = biotic(n)%ind_o2_flux
! Compute the oxygen saturation concentration at 1 atm total
! pressure in mol/m^3 given the temperature (t, in deg C) and
! the salinity (s, in permil)
!
! From Garcia and Gordon (1992), Limnology and Oceonography.
! The formula used is from page 1310, eq (8).
!
! *** Note: the "a3*ts^2" term (in the paper) is incorrect. ***
! *** It shouldn't be there. ***
!
! o2_saturation is defined between T(freezing) <= T <= 40 deg C and
! 0 permil <= S <= 42 permil
!
! check value: T = 10 deg C, S = 35 permil,
! o2_saturation = 0.282015 mol/m^3
do j = jsc, jec
do i = isc, iec
tt(i) = 298.15 - t_prog(indtemp)%field(i,j,1,taum1)
tk(i) = 273.15 + t_prog(indtemp)%field(i,j,1,taum1)
ts(i) = log(tt(i) / tk(i))
ts2(i) = ts(i) * ts(i)
ts3(i) = ts2(i) * ts(i)
ts4(i) = ts3(i) * ts(i)
ts5(i) = ts4(i) * ts(i)
o2_saturation(i,j) = &
exp(a_0 + a_1*ts(i) + a_2*ts2(i) + &
a_3*ts3(i) + a_4*ts4(i) + a_5*ts5(i) + &
t_prog(indsal)%field(i,j,1,taum1) * &
(b_0 + b_1*ts(i) + b_2*ts2(i) + b_3*ts3(i) + &
c_0*t_prog(indsal)%field(i,j,1,taum1))) * grid_tmask(i,j,1)
enddo
enddo
! convert from ml/l to mol/m^3
do j = jsc, jec
do i = isc, iec
o2_saturation(i,j) = o2_saturation(i,j) * (1000.0/22391.6)
enddo
enddo
! Compute the Schmidt number of O2 in seawater using the
! formulation proposed by Keeling et al. (1998, Global Biogeochem.
! Cycles, 12, 141-163).
do j = jsc, jec
do i = isc, iec
biotic(n)%sc_o2(i,j) = &
biotic(n)%sc_o2_0 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_o2_1 + t_prog(indtemp)%field(i,j,1,taum1) * &
(biotic(n)%sc_o2_2 + t_prog(indtemp)%field(i,j,1,taum1) * &
biotic(n)%sc_o2_3)) * grid_tmask(i,j,1)
sc_no_term(i,j) = sqrt(660.0 / (biotic(n)%sc_o2(i,j) + epsln)) * grid_tmask(i,j,1)
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) + &
o2_saturation(i,j) * sc_no_term(i,j)
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) + &
t_prog(biotic(n)%ind_o2)%field(i,j,1,taum1) * sc_no_term(i,j) * rho(i,j,1,taum1)
enddo
enddo
enddo
return
end subroutine ocean_bgc_restore_sum_sfc
! </SUBROUTINE> NAME="ocean_bgc_restore_sum_sfc"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_zero_sfc">
!
! <DESCRIPTION>
! Sum surface fields for flux calculations
! </DESCRIPTION>
subroutine ocean_bgc_restore_zero_sfc(Ocean_fields)
type(coupler_2d_bc_type), intent(inout) :: Ocean_fields
integer :: n
integer :: ind
do n = 1, instances
ind = biotic(n)%ind_co2_flux
ocean_fields%bc(ind)%field(ind_alpha)%values = 0.0
ocean_fields%bc(ind)%field(ind_csurf)%values = 0.0
ind = biotic(n)%ind_o2_flux
ocean_fields%bc(ind)%field(ind_alpha)%values = 0.0
ocean_fields%bc(ind)%field(ind_csurf)%values = 0.0
enddo
return
end subroutine ocean_bgc_restore_zero_sfc
! </SUBROUTINE> NAME="ocean_bgc_restore_zero_sfc"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_avg_sfc">
!
! <DESCRIPTION>
! Sum surface fields for flux calculations
! </DESCRIPTION>
subroutine ocean_bgc_restore_avg_sfc(isc, iec, jsc, jec, nk, isd, ied, jsd, jed, &
isc_bnd, iec_bnd, jsc_bnd, jec_bnd, Ocean_fields, Ocean_avg_kount, grid_tmask)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: nk
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
integer, intent(in) :: isc_bnd
integer, intent(in) :: iec_bnd
integer, intent(in) :: jsc_bnd
integer, intent(in) :: jec_bnd
type(coupler_2d_bc_type), intent(inout) :: Ocean_fields
integer :: Ocean_avg_kount
real, dimension(isd:,jsd:,:), intent(in) :: grid_tmask
integer :: i_bnd_off
integer :: j_bnd_off
integer :: i, j, n
integer :: ind
real :: divid
i_bnd_off = isc - isc_bnd
j_bnd_off = jsc - jsc_bnd
divid = 1./float(ocean_avg_kount)
do n = 1, instances
ind = biotic(n)%ind_co2_flux
do j = jsc, jec
do i = isc, iec
if (grid_tmask(i,j,1) == 1.0) then
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) * divid
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) * divid
endif
enddo
enddo
ind = biotic(n)%ind_o2_flux
do j = jsc, jec
do i = isc, iec
if (grid_tmask(i,j,1) == 1.0) then
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_alpha)%values(i-i_bnd_off,j-j_bnd_off) * divid
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) = &
ocean_fields%bc(ind)%field(ind_csurf)%values(i-i_bnd_off,j-j_bnd_off) * divid
endif
enddo
enddo
enddo
return
end subroutine ocean_bgc_restore_avg_sfc
! </SUBROUTINE> NAME="ocean_bgc_restore_avg_sfc"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_sfc_end">
!
! <DESCRIPTION>
! Initialize surface fields for flux calculations
! </DESCRIPTION>
subroutine ocean_bgc_restore_sfc_end
end subroutine ocean_bgc_restore_sfc_end
! </SUBROUTINE> NAME="ocean_bgc_restore_sfc_end"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_source">
!
! <DESCRIPTION>
! compute the source terms for the BIOTICs, including boundary
! conditions (not done in setvbc, to minimize number
! of hooks required in MOM base code)
! </DESCRIPTION>
subroutine ocean_bgc_restore_source(isc, iec, jsc, jec, nk, isd, ied, jsd, jed, &
T_prog, T_diag, taum1, model_time, Grid, Time, grid_kmt, rho_dzt, dtts)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: nk
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
type(ocean_prog_tracer_type), intent(inout), dimension(:) :: T_prog
type(ocean_diag_tracer_type), intent(inout), dimension(:) :: T_diag
integer, intent(in) :: taum1
type(time_type), intent(in) :: model_time
type(ocean_grid_type), intent(in) :: Grid
type(ocean_time_type), intent(in) :: Time
integer, dimension(isd:,jsd:), intent(in) :: grid_kmt
real, dimension(isd:,jsd:,:,:), intent(in) :: rho_dzt
real, intent(in) :: dtts
integer :: i, j, k, kmax, n
integer :: ind_no3
integer :: ind_nh4
integer :: ind_po4
integer :: ind_fed
integer :: ind_fep
integer :: ind_sio4
integer :: ind_alk
integer :: ind_ldoc
integer :: ind_don
integer :: ind_dop
integer :: ind_dic
integer :: ind_o2
integer :: km_c
logical :: used
integer :: day
integer :: month
integer :: year
integer :: hour
integer :: minute
integer :: second
real :: jtot
real :: SoverPstar2
real :: expkT
real :: fpon_protected
integer :: stdoutunit
stdoutunit=stdout()
! get the model month
call get_date(model_time, year, month, day, &
hour, minute, second)
! calculate the source terms for BIOTICs
! calculate interpolated NO3_star, PO4_star, SiO4_star and Alk_star
call time_interp_external(no3_star_id, model_time, no3_star_t)
call time_interp_external(po4_star_id, model_time, po4_star_t)
call time_interp_external(fed_star_id, model_time, fed_star_t)
call time_interp_external(sio4_star_id, model_time, sio4_star_t)
call time_interp_external(alk_star_id, model_time, alk_star_t)
! Loop over multiple instances
do n = 1, instances
ind_no3 = biotic(n)%ind_no3
ind_nh4 = biotic(n)%ind_nh4
ind_po4 = biotic(n)%ind_po4
ind_fed = biotic(n)%ind_fed
ind_fep = biotic(n)%ind_fep
ind_sio4 = biotic(n)%ind_sio4
ind_alk = biotic(n)%ind_alk
ind_ldoc = biotic(n)%ind_ldoc
ind_don = biotic(n)%ind_don
ind_dop = biotic(n)%ind_dop
ind_dic = biotic(n)%ind_dic
ind_o2 = biotic(n)%ind_o2
km_c = biotic(n)%km_c
! Production
! compute NO3 restoring term and correct for partial
! production in the bottom box
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
if (t_prog(ind_no3)%field(i,j,k,taum1) .gt. &
no3_star_t(i,j,k) * &
biotic(n)%nut_depl%mask(i,j,month)) then
biotic(n)%jprod_no3(i,j,k) = &
(t_prog(ind_no3)%field(i,j,k,taum1) - &
no3_star_t(i,j,k) * &
biotic(n)%nut_depl%mask(i,j,month)) * &
biotic(n)%r_bio_tau_prod%mask(i,j,month) * Grid%tmask(i,j,k)
else
biotic(n)%jprod_no3(i,j,k) = 0.0
endif
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_no3(i,j,km_c) = biotic(n)%jprod_no3(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
enddo
enddo
! compute NH4 restoring term and correct for partial
! production in the bottom box
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
if (t_prog(ind_nh4)%field(i,j,k,taum1) .gt. 0.0) then
biotic(n)%jprod_nh4(i,j,k) = &
t_prog(ind_nh4)%field(i,j,k,taum1) * &
biotic(n)%r_bio_tau_nh4 * Grid%tmask(i,j,k)
else
biotic(n)%jprod_nh4(i,j,k) = 0.0
endif
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_nh4(i,j,km_c) = biotic(n)%jprod_nh4(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
enddo
enddo
! compute PO4 restoring term and correct for partial
! production in the bottom box
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
if (t_prog(ind_po4)%field(i,j,k,taum1) .gt. &
po4_star_t(i,j,k) * &
biotic(n)%nut_depl%mask(i,j,month)) then
biotic(n)%jprod_po4(i,j,k) = &
(t_prog(ind_po4)%field(i,j,k,taum1) - &
po4_star_t(i,j,k) * &
biotic(n)%nut_depl%mask(i,j,month)) * &
biotic(n)%r_bio_tau_prod%mask(i,j,month) * Grid%tmask(i,j,k)
else
biotic(n)%jprod_po4(i,j,k) = 0.0
endif
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_po4(i,j,km_c) = biotic(n)%jprod_po4(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
enddo
enddo
! compute Fed restoring term and correct for partial
! production in the bottom box
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
if (t_prog(ind_fed)%field(i,j,k,taum1) .gt. &
fed_star_t(i,j,k) * &
biotic(n)%nut_depl%mask(i,j,month)) then
biotic(n)%jprod_fed(i,j,k) = &
(t_prog(ind_fed)%field(i,j,k,taum1) - &
fed_star_t(i,j,k) * &
biotic(n)%nut_depl%mask(i,j,month)) * &
biotic(n)%r_bio_tau_prod%mask(i,j,month) * Grid%tmask(i,j,k)
else
biotic(n)%jprod_fed(i,j,k) = 0.0
endif
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_fed(i,j,km_c) = biotic(n)%jprod_fed(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
enddo
enddo
! compute nitrogen fixation
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_n_norm(i,j,k) = biotic(n)%jprod_nh4(i,j,k) + &
biotic(n)%jprod_no3(i,j,k)
biotic(n)%jprod_p_norm(i,j,k) = biotic(n)%jprod_po4(i,j,k)
biotic(n)%jprod_p_fix(i,j,k) = 0.0
biotic(n)%jprod_n_fix(i,j,k) = 0.0
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_p_norm(i,j,km_c) = biotic(n)%jprod_p_norm(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
biotic(n)%jprod_p_fix(i,j,km_c) = biotic(n)%jprod_p_fix(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
biotic(n)%jprod_n_fix(i,j,km_c) = biotic(n)%jprod_n_fix(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
enddo
enddo
! compute SiO4 restoring term and correct for partial
! production in the bottom box
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
if (t_prog(ind_sio4)%field(i,j,k,taum1) .gt. &
sio4_star_t(i,j,k)) then
biotic(n)%jprod_sio4(i,j,k) = &
(t_prog(ind_sio4)%field(i,j,k,taum1) - &
sio4_star_t(i,j,k)) * &
biotic(n)%r_bio_tau * Grid%tmask(i,j,k)
else
biotic(n)%jprod_sio4(i,j,k) = 0.0
endif
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_sio4(i,j,km_c) = &
biotic(n)%jprod_sio4(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
enddo
enddo
! compute Alk restoring term and correct for partial
! production in the bottom box
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
if ((t_prog(ind_alk)%field(i,j,k,taum1) + &
t_prog(ind_no3)%field(i,j,k,taum1)) * 35.0 / &
(t_prog(indsal)%field(i,j,k,taum1) + 1e-40) .gt. &
alk_star_t(i,j,k)) then
biotic(n)%jprod_alk(i,j,k) = &
((t_prog(ind_alk)%field(i,j,k,taum1) + &
t_prog(ind_no3)%field(i,j,k,taum1)) * 35.0 / &
(t_prog(indsal)%field(i,j,k,taum1) + 1e-40) - &
alk_star_t(i,j,k)) * &
biotic(n)%r_bio_tau * Grid%tmask(i,j,k)
else
biotic(n)%jprod_alk(i,j,k) = 0.0
endif
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_alk(i,j,km_c) = &
biotic(n)%jprod_alk(i,j,km_c) * &
biotic(n)%comp_depth_frac(i,j)
enddo
enddo
! Do not allow production in bottom level
do j = jsc, jec
do i = isc, iec
biotic(n)%jprod_no3(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_nh4(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_po4(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_n_norm(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_p_norm(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_n_fix(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_p_fix(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_fed(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_sio4(i,j,grid_kmt(i,j)) = 0.0
biotic(n)%jprod_alk(i,j,grid_kmt(i,j)) = 0.0
enddo
enddo
! Food Web Processing
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
jtot=max(biotic(n)%jprod_n_norm(i,j,k) + &
biotic(n)%jprod_n_fix(i,j,k),1.0e-30)
expkT = exp(biotic(n)%kappa_eppley * t_prog(indtemp)%field(i,j,k,taum1))
SoverPstar2=-0.5 + 0.5 * sqrt(1.0 + 4.0 * jtot / &
(expkT * biotic(n)%Prodstar))
biotic(n)%fracl(i,j,k) = SoverPstar2 / (1.0 + SoverPstar2) * &
Grid%tmask(i,j,k)
biotic(n)%jprod_pon(i,j,k) = max(0.0,jtot * (exp(biotic(n)%kappa_remin *&
t_prog(indtemp)%field(i,j,k,taum1)) * &
(biotic(n)%fdetl0 * biotic(n)%fracl(i,j,k) + biotic(n)%fdets0 * &
(1.0 - biotic(n)%fracl(i,j,k))) - biotic(n)%phi_don)) * &
Grid%tmask(i,j,k)
biotic(n)%jprod_pop(i,j,k) = biotic(n)%jprod_pon(i,j,k) / jtot * &
(biotic(n)%jprod_p_norm(i,j,k) + biotic(n)%jprod_p_fix(i,j,k))
biotic(n)%jprod_pofe(i,j,k) = biotic(n)%jprod_pon(i,j,k) / jtot * &
biotic(n)%jprod_fed(i,j,k)
biotic(n)%jldoc(i,j,k) = jtot * biotic(n)%phi_ldoc * Grid%tmask(i,j,k)
biotic(n)%jdon(i,j,k) = jtot * biotic(n)%phi_don * Grid%tmask(i,j,k)
biotic(n)%jdop(i,j,k) = (biotic(n)%jprod_p_norm(i,j,k) + &
biotic(n)%jprod_p_fix(i,j,k)) * biotic(n)%phi_dop * &
Grid%tmask(i,j,k)
biotic(n)%jnh4_graz(i,j,k) = (jtot - biotic(n)%jprod_pon(i,j,k) - &
biotic(n)%jdon(i,j,k)) * Grid%tmask(i,j,k)
biotic(n)%jpo4_graz(i,j,k) = (biotic(n)%jprod_p_norm(i,j,k) + &
biotic(n)%jprod_p_fix(i,j,k) - biotic(n)%jprod_pop(i,j,k) - &
biotic(n)%jdop(i,j,k)) * Grid%tmask(i,j,k)
biotic(n)%jfe_graz(i,j,k) = (biotic(n)%jprod_fed(i,j,k) &
- biotic(n)%jprod_pofe(i,j,k)) * Grid%tmask(i,j,k)
enddo
enddo
enddo
! Accumulate first level of flux
do j=jsc,jec
do i=isc,iec
biotic(n)%fsio2(i,j,1) = biotic(n)%jprod_sio4(i,j,1) * &
rho_dzt(i,j,1,taum1) * Grid%tmask(i,j,1)
biotic(n)%fcaco3(i,j,1) = 0.5 * biotic(n)%jprod_alk(i,j,1) * &
rho_dzt(i,j,1,taum1) * Grid%tmask(i,j,1)
biotic(n)%fpon(i,j,1) = biotic(n)%jprod_pon(i,j,1) * &
rho_dzt(i,j,1,taum1) * Grid%tmask(i,j,1)
biotic(n)%fpop(i,j,1) = biotic(n)%jprod_pop(i,j,1) * &
rho_dzt(i,j,1,taum1) * Grid%tmask(i,j,1)
biotic(n)%jfe_ads(i,j,1)=min(biotic(n)%kfe_max_prime, &
(biotic(n)%kfe_org / 2.0 * biotic(n)%fpon(i,j,1) * &
biotic(n)%mass_2_n + biotic(n)%kfe_bal / 2.0 * &
(biotic(n)%fsio2(i,j,1) * 60.0 + biotic(n)%fcaco3(i,j,1) * &
100.0)) * biotic(n)%r_wsink) * &
max(0.0,t_prog(ind_fed)%field(i,j,1,taum1))
biotic(n)%jfe_des(i,j,1) = biotic(n)%kfe_des * &
max(0.0,t_diag(ind_fep)%field(i,j,1))
biotic(n)%jpon(i,j,1) = 0.0
biotic(n)%jpop(i,j,1) = 0.0
biotic(n)%jpofe(i,j,1) = 0.0
biotic(n)%jsio4(i,j,1) = 0.0
biotic(n)%jcaco3(i,j,1) = 0.0
enddo
enddo
do k=2,nk-1
do j=jsc,jec
do i=isc,iec
biotic(n)%fsio2(i,j,k) = biotic(n)%fsio2(i,j,k-1) * &
biotic(n)%r_1plusintzscale_si(k) * Grid%tmask(i,j,k)
! Calculate regeneration term
biotic(n)%jsio4(i,j,k) = (biotic(n)%fsio2(i,j,k-1) * Grid%tmask(i,j,k) &
- biotic(n)%fsio2(i,j,k) * Grid%tmask(i,j,k+1)) / rho_dzt(i,j,k,taum1)
! Add production within box to flux
biotic(n)%fsio2(i,j,k) = biotic(n)%fsio2(i,j,k) + &
biotic(n)%jprod_sio4(i,j,k) * &
rho_dzt(i,j,k,taum1) * Grid%tmask(i,j,k)
enddo
enddo
enddo
do k=2,nk-1
do j=jsc,jec
do i=isc,iec
biotic(n)%fcaco3(i,j,k) = biotic(n)%fcaco3(i,j,k-1) * &
biotic(n)%r_1plusintzscale_ca(k) * Grid%tmask(i,j,k)
! Calculate regeneration term
biotic(n)%jcaco3(i,j,k) = (biotic(n)%fcaco3(i,j,k-1) * Grid%tmask(i,j,k) &
- biotic(n)%fcaco3(i,j,k) * Grid%tmask(i,j,k+1)) / rho_dzt(i,j,k,taum1)
! Add production within box to flux
biotic(n)%fcaco3(i,j,k) = biotic(n)%fcaco3(i,j,k) + 0.5 * &
biotic(n)%jprod_alk(i,j,k) * &
rho_dzt(i,j,k,taum1) * Grid%tmask(i,j,k)
enddo
enddo
enddo
if(biotic(n)%remin_ocmip2) then
! OCMIP2 Interior Remineralization Scheme
! F(z) = F75 * (z / 75)^-0.9
do k = 2, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%fpon(i,j,k) = biotic(n)%fpon(i,j,k-1) + &
biotic(n)%jprod_pon(i,j,k) * &
rho_dzt(i,j,k,taum1) * Grid%tmask(i,j,k)
biotic(n)%fpop(i,j,k) = biotic(n)%fpop(i,j,k-1) + &
biotic(n)%jprod_pop(i,j,k) * &
rho_dzt(i,j,k,taum1) * Grid%tmask(i,j,k)
enddo
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%flux_pon(i,j) = biotic(n)%fpon(i,j,km_c)
biotic(n)%flux_pop(i,j) = biotic(n)%fpop(i,j,km_c)
enddo
enddo
do k = km_c, nk
do j = jsc, jec
do i = isc, iec
! Calculate the flux at the base of each layer below the
! compensation depth
biotic(n)%fpon(i,j,k) = biotic(n)%flux_pon(i,j) * &
Grid%tmask(i,j,k) * biotic(n)%zforg(k)
biotic(n)%fpop(i,j,k) = biotic(n)%flux_pop(i,j) * &
Grid%tmask(i,j,k) * biotic(n)%zforg(k)
! Calculate regeneration term
biotic(n)%jpon(i,j,k) = (biotic(n)%fpon(i,j,k-1) * Grid%tmask(i,j,k) &
- biotic(n)%fpon(i,j,k) * Grid%tmask(i,j,k+1)) / rho_dzt(i,j,k,taum1)
biotic(n)%jpop(i,j,k) = (biotic(n)%fpop(i,j,k-1) * Grid%tmask(i,j,k) &
- biotic(n)%fpop(i,j,k) * Grid%tmask(i,j,k+1)) / rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
elseif(biotic(n)%remin_protection) then
! Ballast Protection Interior Remineralization Scheme
! remin = g * max(0.0 , Forg - rpcaco3 * Fcaco3 - rpsio2 * Fsio2)
do k=2,nk-1
do j=jsc,jec
do i=isc,iec
! Remineralization of unprotected organic material and
! previously protected particulate organic material
fpon_protected = biotic(n)%rpsio2 * biotic(n)%fsio2(i,j,k-1) + &
biotic(n)%rpcaco3 * biotic(n)%fcaco3(i,j,k-1) + 1.0e-30
biotic(n)%fpon(i,j,k) = min(biotic(n)%fpon(i,j,k-1), &
((biotic(n)%fpon(i,j,k-1) + biotic(n)%r_intzscale_n(k) * &
fpon_protected) * biotic(n)%r_1plusintzscale_n(k)) - &
(biotic(n)%rpsio2 * (biotic(n)%fsio2(i,j,k-1) - &
biotic(n)%fsio2(i,j,k)) + biotic(n)%rpcaco3 * &
(biotic(n)%fcaco3(i,j,k-1) - biotic(n)%fcaco3(i,j,k))) * &
min(biotic(n)%fpon(i,j,k-1),fpon_protected) / &
fpon_protected * biotic(n)%r_1plusintzscale_n(k)) * Grid%tmask(i,j,k)
! Apply N change to P assuming equal partitioning between protected,
! previously protected and unprotected particulate organic material
biotic(n)%fpop(i,j,k) = biotic(n)%fpon(i,j,k) / &
max(biotic(n)%fpon(i,j,k-1),1e-30) * biotic(n)%fpop(i,j,k-1)
! Calculate regeneration term
biotic(n)%jpon(i,j,k) = (biotic(n)%fpon(i,j,k-1) * Grid%tmask(i,j,k) &
- biotic(n)%fpon(i,j,k) * Grid%tmask(i,j,k+1)) / rho_dzt(i,j,k,taum1)
biotic(n)%jpop(i,j,k) = (biotic(n)%fpop(i,j,k-1) * Grid%tmask(i,j,k) &
- biotic(n)%fpop(i,j,k) * Grid%tmask(i,j,k+1)) / rho_dzt(i,j,k,taum1)
! Add production within box to flux
biotic(n)%fpon(i,j,k) = biotic(n)%fpon(i,j,k) + &
biotic(n)%jprod_pon(i,j,k) * &
rho_dzt(i,j,k,taum1) * Grid%tmask(i,j,k)
biotic(n)%fpop(i,j,k) = biotic(n)%fpop(i,j,k) + &
biotic(n)%jprod_pop(i,j,k) * &
rho_dzt(i,j,k,taum1) * Grid%tmask(i,j,k)
enddo
enddo
enddo
elseif (biotic(n)%remin_density) then
elseif (biotic(n)%remin_lability) then
elseif (biotic(n)%remin_temp) then
elseif (biotic(n)%remin_viscosity) then
elseif (biotic(n)%remin_zoop_resp) then
endif
! Choose between associating particulate Fe with ballast and organic matter,
! or just with organic matter
if (biotic(n)%fe_ballast_assoc) then
do k=2,nk-1
do j = jsc, jec
do i = isc, iec
! Apply N change to Fe incorporating adsorption and desorption
biotic(n)%jfe_ads(i,j,k)=min(biotic(n)%kfe_max_prime , (biotic(n)%kfe_org &
/ 2.0 * (biotic(n)%fpon(i,j,k-1)+biotic(n)%fpon(i,j,k)) * &
biotic(n)%mass_2_n + biotic(n)%kfe_bal / 2.0 * &
((biotic(n)%fsio2(i,j,k-1) + biotic(n)%fsio2(i,j,k)) * &
60.0 + (biotic(n)%fcaco3(i,j,k-1) + biotic(n)%fcaco3(i,j,k)) * 100.0))&
* biotic(n)%r_wsink ) * max(0.0,t_prog(ind_fed)%field(i,j,k,taum1))
biotic(n)%jfe_des(i,j,k)=biotic(n)%kfe_des * &
max(0.0,t_diag(ind_fep)%field(i,j,k))
biotic(n)%jpofe(i,j,k) = (biotic(n)%jpon(i,j,k) * &
biotic(n)%mass_2_n + biotic(n)%jsio4(i,j,k) * 60.0 + &
biotic(n)%jcaco3(i,j,k) * 100.0) / &
max(1.0e-30,biotic(n)%fpon(i,j,k-1) * biotic(n)%mass_2_n + &
biotic(n)%fsio2(i,j,k-1) * 60.0 + biotic(n)%fcaco3(i,j,k-1) &
* 100.0) * max(0.0,t_diag(ind_fep)%field(i,j,k)) &
* biotic(n)%wsink * &
(1.0 - Grid%tmask(i,j,k) + Grid%tmask(i,j,k+1))
enddo
enddo
enddo
else
do k=2,nk-1
do j=jsc,jec
do i=isc,iec
! Apply N change to Fe incorporating adsorption and desorption
biotic(n)%jfe_ads(i,j,k)=min(biotic(n)%kfe_max_prime , (biotic(n)%kfe_org &
/ 2.0 * (biotic(n)%fpon(i,j,k-1)+biotic(n)%fpon(i,j,k)) * &
biotic(n)%mass_2_n + biotic(n)%kfe_bal / 2.0 * &
((biotic(n)%fsio2(i,j,k-1) + biotic(n)%fsio2(i,j,k)) * &
60.0 + (biotic(n)%fcaco3(i,j,k-1) + biotic(n)%fcaco3(i,j,k)) * 100.0))&
* biotic(n)%r_wsink ) * max(0.0,t_prog(ind_fed)%field(i,j,k,taum1))
biotic(n)%jfe_des(i,j,k)=biotic(n)%kfe_des * &
max(0.0,t_diag(ind_fep)%field(i,j,k))
biotic(n)%jpofe(i,j,k) = biotic(n)%jpon(i,j,k) / &
max(1.0e-30,biotic(n)%fpon(i,j,k-1)) * &
max(0.0,t_diag(ind_fep)%field(i,j,k)) * biotic(n)%wsink * &
(1.0 - Grid%tmask(i,j,k) + Grid%tmask(i,j,k+1))
enddo
enddo
enddo
endif
do j=jsc,jec
do i=isc,iec
biotic(n)%fsio2(i,j,nk) = 0.0
biotic(n)%fcaco3(i,j,nk) = 0.0
biotic(n)%fpon(i,j,nk) = 0.0
biotic(n)%fpop(i,j,nk) = 0.0
biotic(n)%jfe_ads(i,j,nk) = min(biotic(n)%kfe_max_prime , &
(biotic(n)%kfe_org / 2.0 * (biotic(n)%fpon(i,j,nk-1) + &
biotic(n)%fpon(i,j,nk)) * biotic(n)%mass_2_n + &
biotic(n)%kfe_bal / 2.0 * ((biotic(n)%fsio2(i,j,nk-1) + &
biotic(n)%fsio2(i,j,nk)) * 60.0 + &
(biotic(n)%fcaco3(i,j,nk-1) + biotic(n)%fcaco3(i,j,nk))&
* 100.0)) * biotic(n)%r_wsink ) * &
max(0.0,t_prog(ind_fed)%field(i,j,nk,taum1))
biotic(n)%jfe_des(i,j,nk)=biotic(n)%kfe_des * &
max(0.0,t_diag(ind_fep)%field(i,j,nk))
! Calculate regeneration term
biotic(n)%jsio4(i,j,nk) = (biotic(n)%fsio2(i,j,nk-1) - &
biotic(n)%fsio2(i,j,nk)) / rho_dzt(i,j,nk,taum1)
biotic(n)%jcaco3(i,j,nk) = (biotic(n)%fcaco3(i,j,nk-1) - &
biotic(n)%fcaco3(i,j,nk)) / rho_dzt(i,j,nk,taum1)
biotic(n)%jpon(i,j,nk) = (biotic(n)%fpon(i,j,nk-1) - &
biotic(n)%fpon(i,j,nk)) / rho_dzt(i,j,nk,taum1)
biotic(n)%jpop(i,j,nk) = (biotic(n)%fpop(i,j,nk-1) - &
biotic(n)%fpop(i,j,nk)) / rho_dzt(i,j,nk,taum1)
biotic(n)%jpofe(i,j,nk) = 0.0
enddo
enddo
do j = jsc, jec
do i = isc, iec
kmax=min(km_c,grid_kmt(i,j))
biotic(n)%flux_sio2(i,j) = biotic(n)%fsio2(i,j,kmax)
biotic(n)%flux_caco3(i,j) = biotic(n)%fcaco3(i,j,kmax)
biotic(n)%flux_pon(i,j) = biotic(n)%fpon(i,j,kmax)
biotic(n)%flux_pop(i,j) = biotic(n)%fpop(i,j,kmax)
enddo
enddo
do j = jsc, jec
do i = isc, iec
biotic(n)%jfe_sink(i,j,1)= &
- max(0.0,t_diag(ind_fep)%field(i,j,1)) * &
biotic(n)%wsink / rho_dzt(i,j,1,taum1) * Grid%tmask(i,j,1)
enddo
enddo
do k = 2, nk
do j = jsc, jec
do i = isc, iec
biotic(n)%jfe_sink(i,j,k)= &
(max(0.0,t_diag(ind_fep)%field(i,j,k-1)) - &
max(0.0,t_diag(ind_fep)%field(i,j,k))) * &
biotic(n)%wsink / rho_dzt(i,j,k,taum1) * Grid%tmask(i,j,k)
enddo
enddo
enddo
! CALCULATE SOURCE/SINK TERMS FOR EACH TRACER
! NO3
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jdenit(i,j,k) = 0.0
biotic(n)%jno3(i,j,k) = biotic(n)%r_bio_tau_nitrif_s * &
max(0.0,t_prog(ind_nh4)%field(i,j,k,taum1)) - &
biotic(n)%jprod_no3(i,j,k) - biotic(n)%jdenit(i,j,k)
enddo
enddo
enddo
do k=km_c + 1, nk
do j = jsc, jec
do i = isc, iec
biotic(n)%jdenit(i,j,k) = 0.0
biotic(n)%jno3(i,j,k) = biotic(n)%r_bio_tau_nitrif_d * &
max(0.0,t_prog(ind_nh4)%field(i,j,k,taum1)) - &
biotic(n)%jdenit(i,j,k)
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_no3)%th_tendency(i,j,k) = t_prog(ind_no3)%th_tendency(i,j,k) + &
biotic(n)%jno3(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! NH4
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jnh4(i,j,k) = biotic(n)%jnh4_graz(i,j,k) &
- biotic(n)%jprod_nh4(i,j,k) &
+ biotic(n)%r_bio_tau_don * max(0.0,t_prog(ind_don)%field(i,j,k,taum1)) &
- biotic(n)%r_bio_tau_nitrif_s * &
max(0.0,t_prog(ind_nh4)%field(i,j,k,taum1)) &
+(1.0 - biotic(n)%phi_don)*biotic(n)%jpon(i,j,k)
enddo
enddo
enddo
do k=km_c + 1, nk
do j = jsc, jec
do i = isc, iec
biotic(n)%jnh4(i,j,k) =(1.0 - biotic(n)%phi_don) * &
biotic(n)%jpon(i,j,k) &
+ biotic(n)%r_bio_tau_don * max(0.0,t_prog(ind_don)%field(i,j,k,taum1)) &
- biotic(n)%r_bio_tau_nitrif_d * &
max(0.0,t_prog(ind_nh4)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_nh4)%th_tendency(i,j,k) = t_prog(ind_nh4)%th_tendency(i,j,k) + &
biotic(n)%jnh4(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! PO4
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jpo4(i,j,k) = - biotic(n)%jprod_p_norm(i,j,k) - &
biotic(n)%jprod_p_fix(i,j,k) + biotic(n)%jpo4_graz(i,j,k) + &
biotic(n)%r_bio_tau_dop * max(0.0,t_prog(ind_dop)%field(i,j,k,taum1)) + &
(1.0 - biotic(n)%phi_dop) * biotic(n)%jpop(i,j,k)
enddo
enddo
enddo
do k=km_c + 1, nk
do j = jsc, jec
do i = isc, iec
biotic(n)%jpo4(i,j,k) = (1.0 - biotic(n)%phi_dop) * &
biotic(n)%jpop(i,j,k) + biotic(n)%r_bio_tau_dop * &
max(0.0,t_prog(ind_dop)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_po4)%th_tendency(i,j,k) = t_prog(ind_po4)%th_tendency(i,j,k) + &
biotic(n)%jpo4(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! Fe dissolved
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
t_prog(ind_fed)%th_tendency(i,j,k) = t_prog(ind_fed)%th_tendency(i,j,k) + &
(biotic(n)%jfe_graz(i,j,k) - biotic(n)%jprod_fed(i,j,k) &
- biotic(n)%jfe_ads(i,j,k) + biotic(n)%jfe_des(i,j,k) + &
biotic(n)%jpofe(i,j,k)) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
do k=km_c + 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_fed)%th_tendency(i,j,k) = t_prog(ind_fed)%th_tendency(i,j,k) + &
(biotic(n)%jfe_des(i,j,k) - biotic(n)%jfe_ads(i,j,k) + &
biotic(n)%jpofe(i,j,k)) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! Fe particulate
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_diag(ind_fep)%field(i,j,k) = t_diag(ind_fep)%field(i,j,k) + &
(biotic(n)%jprod_pofe(i,j,k) + biotic(n)%jfe_ads(i,j,k) - &
biotic(n)%jfe_des(i,j,k) - biotic(n)%jpofe(i,j,k) + &
biotic(n)%jfe_sink(i,j,k)) * dtts
enddo
enddo
enddo
! LDOC
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jldoc(i,j,k) = biotic(n)%jldoc(i,j,k) &
- biotic(n)%r_bio_tau_ldoc * max(0.0,t_prog(ind_ldoc)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = km_c + 1, nk
do j = jsc, jec
do i = isc, iec
biotic(n)%jldoc(i,j,k) = &
- biotic(n)%r_bio_tau_ldoc * max(0.0,t_prog(ind_ldoc)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_ldoc)%th_tendency(i,j,k) = t_prog(ind_ldoc)%th_tendency(i,j,k) + &
biotic(n)%jldoc(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! DON
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jdon(i,j,k) = biotic(n)%jdon(i,j,k) &
+ biotic(n)%phi_don * biotic(n)%jpon(i,j,k) &
- biotic(n)%r_bio_tau_don * max(0.0,t_prog(ind_don)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = km_c + 1, nk
do j = jsc, jec
do i = isc, iec
biotic(n)%jdon(i,j,k) = biotic(n)%phi_don * biotic(n)%jpon(i,j,k) &
- biotic(n)%r_bio_tau_don * max(0.0,t_prog(ind_don)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_don)%th_tendency(i,j,k) = t_prog(ind_don)%th_tendency(i,j,k) + &
biotic(n)%jdon(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! DOP
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jdop(i,j,k) = biotic(n)%jdop(i,j,k) &
+ biotic(n)%phi_dop * biotic(n)%jpop(i,j,k) &
- biotic(n)%r_bio_tau_dop * max(0.0,t_prog(ind_dop)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = km_c + 1, nk
do j = jsc, jec
do i = isc, iec
biotic(n)%jdop(i,j,k) = biotic(n)%phi_dop * biotic(n)%jpop(i,j,k) &
- biotic(n)%r_bio_tau_dop * max(0.0,t_prog(ind_dop)%field(i,j,k,taum1))
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_dop)%th_tendency(i,j,k) = t_prog(ind_dop)%th_tendency(i,j,k) + &
biotic(n)%jdop(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! SiO4
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
biotic(n)%jsio4(i,j,k) = biotic(n)%jsio4(i,j,k) - &
biotic(n)%jprod_sio4(i,j,k)
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_sio4)%th_tendency(i,j,k) = t_prog(ind_sio4)%th_tendency(i,j,k) + &
biotic(n)%jsio4(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! ALK
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
t_prog(ind_alk)%th_tendency(i,j,k) = t_prog(ind_alk)%th_tendency(i,j,k) + &
(2.0 * biotic(n)%jcaco3(i,j,k) - biotic(n)%jprod_alk(i,j,k) &
- biotic(n)%jno3(i,j,k) + biotic(n)%jnh4(i,j,k)) * &
rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
do k = km_c + 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_alk)%th_tendency(i,j,k) = t_prog(ind_alk)%th_tendency(i,j,k) + &
(2.0 * biotic(n)%jcaco3(i,j,k) - biotic(n)%jno3(i,j,k) + &
biotic(n)%jnh4(i,j,k)) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! O2
! O2 production from nitrate, ammonia and nitrogen fixation and
! O2 consumption from production of NH4 from non-sinking particles,
! and DOM
do k = 1, km_c
do j =jsc, jec
do i = isc, iec
biotic(n)%jo2(i,j,k) = (biotic(n)%o_2_no3 * &
biotic(n)%jprod_no3(i,j,k) &
+ biotic(n)%o_2_nh4 * (biotic(n)%jprod_nh4(i,j,k) + &
biotic(n)%jprod_n_fix(i,j,k))) * Grid%tmask(i,j,k)
! If O2 is present
if (t_prog(ind_o2)%field(i,j,k,taum1) .gt. biotic(n)%o2_min) &
then
biotic(n)%jo2(i,j,k) = biotic(n)%jo2(i,j,k) - biotic(n)%o_2_nh4 *&
(biotic(n)%jnh4_graz(i,j,k) + biotic(n)%r_bio_tau_don * &
max(0.0,t_prog(ind_don)%field(i,j,k,taum1)) + (1.0 - biotic(n)%phi_don) &
* biotic(n)%jpon(i,j,k)) + &
biotic(n)%o_2_c * biotic(n)%jldoc(i,j,k) - &
biotic(n)%o_2_nitrif * biotic(n)%r_bio_tau_nitrif_s * &
max(0.0,t_prog(ind_nh4)%field(i,j,k,taum1))
endif
enddo
enddo
enddo
! O2 consumption from production of NH4 from sinking particles and DOM
! O2 consumption from nitrification
do k = km_c + 1, nk
do j = jsc, jec
do i = isc, iec
! If O2 is present
if (t_prog(ind_o2)%field(i,j,k,taum1) .gt. biotic(n)%o2_min) then
biotic(n)%jo2(i,j,k) = - biotic(n)%o_2_nh4 * &
((1.0 - biotic(n)%phi_don) * biotic(n)%jpon(i,j,k) + &
biotic(n)%r_bio_tau_don * max(0.0,t_prog(ind_don)%field(i,j,k,taum1))) + &
biotic(n)%o_2_c * biotic(n)%jldoc(i,j,k) - &
biotic(n)%o_2_nitrif * biotic(n)%r_bio_tau_nitrif_d * &
max(0.0,t_prog(ind_nh4)%field(i,j,k,taum1))
else
biotic(n)%jo2(i,j,k) = 0.0
endif
enddo
enddo
enddo
do k = 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_o2)%th_tendency(i,j,k) = t_prog(ind_o2)%th_tendency(i,j,k) + &
biotic(n)%jo2(i,j,k) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
! DIC
do k = 1, km_c
do j = jsc, jec
do i = isc, iec
t_prog(ind_dic)%th_tendency(i,j,k) = t_prog(ind_dic)%th_tendency(i,j,k) + &
(biotic(n)%c_2_n * (biotic(n)%jno3(i,j,k) + &
biotic(n)%jnh4(i,j,k)) - biotic(n)%jldoc(i,j,k) + &
biotic(n)%jcaco3(i,j,k) - 0.5 * biotic(n)%jprod_alk(i,j,k)) * &
rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
do k = km_c + 1, nk
do j = jsc, jec
do i = isc, iec
t_prog(ind_dic)%th_tendency(i,j,k) = t_prog(ind_dic)%th_tendency(i,j,k) + &
(biotic(n)%c_2_n * (biotic(n)%jno3(i,j,k) &
+ biotic(n)%jnh4(i,j,k)) - biotic(n)%jldoc(i,j,k) + &
biotic(n)%jcaco3(i,j,k)) * rho_dzt(i,j,k,taum1)
enddo
enddo
enddo
enddo
! Save variables for diagnostics
call diagnose_2d_comp(Time, Grid, id_o2_sat, o2_saturation(:,:))
do n = 1, instances
call diagnose_2d_comp(Time, Grid, biotic(n)%id_sc_co2, biotic(n)%sc_co2(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_sc_o2, biotic(n)%sc_o2(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_alpha, biotic(n)%alpha(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_csurf, biotic(n)%csurf(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_pco2surf, biotic(n)%pco2surf(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_flux_pon, biotic(n)%flux_pon(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_flux_pop, biotic(n)%flux_pop(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_flux_sio2, biotic(n)%flux_sio2(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_flux_caco3, biotic(n)%flux_caco3(:,:))
call diagnose_2d_comp(Time, Grid, biotic(n)%id_htotal, biotic(n)%htotal(:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_alk, biotic(n)%jprod_alk(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_fed, biotic(n)%jprod_fed(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_n_fix, biotic(n)%jprod_n_fix(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_no3, biotic(n)%jprod_no3(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_nh4, biotic(n)%jprod_nh4(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_p_fix, biotic(n)%jprod_p_fix(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_po4, biotic(n)%jprod_po4(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_pofe, biotic(n)%jprod_pofe(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_pon, biotic(n)%jprod_pon(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_pop, biotic(n)%jprod_pop(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jprod_sio4,biotic(n)%jprod_sio4(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jcaco3,biotic(n)%jcaco3(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jfe_ads, biotic(n)%jfe_ads(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jfe_des, biotic(n)%jfe_des(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jfe_graz, biotic(n)%jfe_graz(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jfe_sink, biotic(n)%jfe_sink(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jno3, biotic(n)%jno3(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jnh4, biotic(n)%jnh4(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jnh4_graz, biotic(n)%jnh4_graz(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jpo4, biotic(n)%jpo4(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jpo4_graz, biotic(n)%jpo4_graz(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jpofe, biotic(n)%jpofe(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jpon, biotic(n)%jpon(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jpop, biotic(n)%jpop(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jsio4, biotic(n)%jsio4(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jdenit, biotic(n)%jdenit(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jdon, biotic(n)%jdon(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jdop, biotic(n)%jdop(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jldoc, biotic(n)%jldoc(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_jo2, biotic(n)%jo2(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_fpon, biotic(n)%fpon(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_fpop, biotic(n)%fpop(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_fracl, biotic(n)%fracl(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_fsio2, biotic(n)%fsio2(:,:,:))
call diagnose_3d_comp(Time, Grid, biotic(n)%id_fcaco3, biotic(n)%fcaco3(:,:,:))
enddo
return
end subroutine ocean_bgc_restore_source
! </SUBROUTINE> NAME="ocean_bgc_restore_source"
!#######################################################################
! <SUBROUTINE NAME="ocean_bgc_restore_start">
!
! <DESCRIPTION>
! Initialize variables, read in namelists, calculate constants for a given run
! and allocate diagnostic arrays
! </DESCRIPTION>
subroutine ocean_bgc_restore_start(isc, iec, jsc, jec, nk, isd, ied, jsd, jed, &
T_prog, T_diag, taup1, model_time, grid_dat, grid_tmask, grid_kmt, &
grid_xt, grid_yt, grid_zt, grid_zw, grid_dzt, grid_name, grid_tracer_axes, &
mpp_domain2d, rho_dzt)
integer, intent(in) :: isc
integer, intent(in) :: iec
integer, intent(in) :: jsc
integer, intent(in) :: jec
integer, intent(in) :: nk
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
type(ocean_prog_tracer_type), dimension(:), intent(in) :: T_prog
type(ocean_diag_tracer_type), dimension(:), intent(in) :: T_diag
integer, intent(in) :: taup1
type(time_type), intent(in) :: model_time
real, dimension(isd:,jsd:), intent(in) :: grid_dat
real, dimension(isd:,jsd:,:), intent(in) :: grid_tmask
integer, dimension(isd:,jsd:), intent(in) :: grid_kmt
real, dimension(isd:,jsd:), intent(in) :: grid_xt
real, dimension(isd:,jsd:), intent(in) :: grid_yt
real, dimension(nk), intent(in) :: grid_zt
real, dimension(nk), intent(in) :: grid_zw
real, dimension(nk), intent(in) :: grid_dzt
character(len=*), intent(in) :: grid_name
integer, dimension(3), intent(in) :: grid_tracer_axes
type(domain2d), intent(in) :: mpp_domain2d
real, dimension(isd:,jsd:,:,:), intent(in) :: rho_dzt
character(len=64), parameter :: sub_name = 'ocean_bgc_restore_start'
character(len=256), parameter :: error_header = &
'==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '): '
!----------------------------------------------------------------------
!
! Global values to apply the following inhibitions
! and depletions
!
! coastal_only : if true, then only apply the changes in
! coastal boxes
! t_mask_len : parameter giving the number of elements in
! the time mask per year (eg., 12 would
! imply monthly)
! t_mask_array : logical array controlling whether to apply
! the following inhibitions and depletions to
! each time-period (true means set the masks,
! false means use the defaults everywhere)
! num_reg : number of regions
! factor : factor by which to scale the field
! : in the selected regions
! wlon : western longitude of region
! elon : eastern longitude of region
! slat : southern latitude of region
! nlat : northern latitude of region
! mask(imt,jmt) : mask array (0.0 - alternate, 1.0 - normal)
!
! Set up a mask array using wlon,elon,nlat,slat
! (any box with its lon,lat inside the box bounded by
! wlon,elon,nlat,slat value in mask set to factor).
!
!----------------------------------------------------------------------
integer :: done
integer :: i, j, k, l, m, n
character(len=fm_field_name_len) :: name
character(len=fm_field_name_len+1) :: suffix
character(len=fm_field_name_len+3) :: long_suffix
character(len=256) :: caller_str
integer :: len_w
integer :: len_e
integer :: len_s
integer :: len_n
real :: total_alkalinity
real :: total_ammonia
real :: total_dic
real :: total_don
real :: total_dop
real :: total_fediss
real :: total_fepart
real :: total_ldoc
real :: total_o2
real :: total_nitrate
real :: total_phosphate
real :: total_silicate
character(len=fm_string_len), allocatable :: local_restart_file(:)
logical :: fld_exist
integer :: ind
integer :: id_restart
integer :: stdoutunit
stdoutunit=stdout()
write(stdoutunit,*)
write(stdoutunit,*) trim(note_header), &
'Starting ', trim(package_name), ' module'
! Determine indices for temperature and salinity
indtemp = fm_get_index('/ocean_mod/prog_tracers/temp')
if (indtemp .le. 0) then
call mpp_error(FATAL,trim(error_header) // ' Could not get the temperature index')
endif
indsal = fm_get_index('/ocean_mod/prog_tracers/salt')
if (indsal .le. 0) then
call mpp_error(FATAL,trim(error_header) // ' Could not get the salinity index')
endif
! dynamically allocate the global BIOTIC arrays
call allocate_arrays(isc, iec, jsc, jec, nk, isd, ied, jsd, jed)
! save the *global* namelist values
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')'
call fm_util_start_namelist(package_name, '*global*', caller = caller_str)
dep_dry_file = fm_util_get_string ('dep_dry_file', scalar = .true.)
dep_dry_name = fm_util_get_string ('dep_dry_name', scalar = .true.)
dep_wet_file = fm_util_get_string ('dep_wet_file', scalar = .true.)
dep_wet_name = fm_util_get_string ('dep_wet_name', scalar = .true.)
no3_star_file = fm_util_get_string ('no3_star_file', scalar = .true.)
no3_star_name = fm_util_get_string ('no3_star_name', scalar = .true.)
po4_star_file = fm_util_get_string ('po4_star_file', scalar = .true.)
po4_star_name = fm_util_get_string ('po4_star_name', scalar = .true.)
sio4_star_file = fm_util_get_string ('sio4_star_file', scalar = .true.)
sio4_star_name = fm_util_get_string ('sio4_star_name', scalar = .true.)
alk_star_file = fm_util_get_string ('alk_star_file', scalar = .true.)
alk_star_name = fm_util_get_string ('alk_star_name', scalar = .true.)
fed_star_file = fm_util_get_string ('fed_star_file', scalar = .true.)
fed_star_name = fm_util_get_string ('fed_star_name', scalar = .true.)
htotal_scale_lo_in = fm_util_get_real ('htotal_scale_lo_in', scalar = .true.)
htotal_scale_hi_in = fm_util_get_real ('htotal_scale_hi_in', scalar = .true.)
htotal_in = fm_util_get_real ('htotal_in', scalar = .true.)
call fm_util_end_namelist(package_name, '*global*', caller = caller_str)
! Open up the Alk file for restoring
alk_star_id = init_external_field(alk_star_file, &
alk_star_name, &
domain = mpp_domain2d)
if (alk_star_id .eq. 0) then
call mpp_error(FATAL, &
trim(sub_name) // &
': Error: could not open alk_star file: ' // &
trim(alk_star_file))
endif
! Open up the Fed file for restoring
fed_star_id = init_external_field(fed_star_file, &
fed_star_name, &
domain = mpp_domain2d)
if (alk_star_id .eq. 0) then
call mpp_error(FATAL, &
trim(sub_name) // &
': Error: could not open fed_star file: ' // &
trim(fed_star_file))
endif
! Open up the NO3 file for restoring
no3_star_id = init_external_field(no3_star_file, &
no3_star_name, &
domain = mpp_domain2d)
if (no3_star_id .eq. 0) then
call mpp_error(FATAL, &
trim(sub_name) // &
': Error: could not open no3_star file: ' // &
trim(no3_star_file))
endif
! Open up the PO4 file for restoring
po4_star_id = init_external_field(po4_star_file, &
po4_star_name, &
domain = mpp_domain2d)
if (po4_star_id .eq. 0) then
call mpp_error(FATAL, &
trim(sub_name) // &
': Error: could not open po4_star file: ' // &
trim(po4_star_file))
endif
! Open up the SiO4 file for restoring
sio4_star_id = init_external_field(sio4_star_file, &
sio4_star_name, &
domain = mpp_domain2d)
if (sio4_star_id .eq. 0) then
call mpp_error(FATAL, &
trim(sub_name) // &
': Error: could not open sio4_star file: ' // &
trim(sio4_star_file))
endif
! Open up the files for boundary conditions
dep_wet_id = init_external_field(dep_wet_file, &
dep_wet_name, &
domain = mpp_domain2d)
if (dep_wet_id .eq. 0) then
call mpp_error(FATAL, trim(error_header) // &
'Could not open wet deposition file: ' // &
trim(dep_wet_file))
endif
dep_dry_id = init_external_field(dep_dry_file, &
dep_dry_name, &
domain = mpp_domain2d)
if (dep_dry_id .eq. 0) then
call mpp_error(FATAL, trim(error_header) // &
'Could not open dry deposition file: ' // &
trim(dep_dry_file))
endif
! set default values for htotal_scale bounds
htotal_scale_lo(:,:) = htotal_scale_lo_in
htotal_scale_hi(:,:) = htotal_scale_hi_in
! read in the namelists for each instance
do n = 1, instances
call fm_util_start_namelist(package_name, biotic(n)%name, caller = caller_str)
biotic(n)%compensation_depth = fm_util_get_real ('compensation_depth', scalar = .true.)
biotic(n)%martin_coeff = fm_util_get_real ('martin_coeff', scalar = .true.)
biotic(n)%ca_remin_depth = fm_util_get_real ('ca_remin_depth', scalar = .true.)
biotic(n)%si_remin_depth = fm_util_get_real ('si_remin_depth', scalar = .true.)
biotic(n)%soft_tissue_pump = fm_util_get_logical('soft_tissue_pump', scalar = .true.)
biotic(n)%stp_temperature = fm_util_get_real ('stp_temperature', scalar = .true.)
biotic(n)%stp_salinity = fm_util_get_real ('stp_salinity', scalar = .true.)
biotic(n)%stp_alkalinity = fm_util_get_real ('stp_alkalinity', scalar = .true.)
biotic(n)%local_restart_file = fm_util_get_string ('local_restart_file', scalar = .true.)
biotic(n)%fe_ballast_assoc = fm_util_get_logical('fe_ballast_assoc', scalar = .true.)
biotic(n)%phi_dry = fm_util_get_real ('phi_dry', scalar = .true.)
biotic(n)%phi_wet = fm_util_get_real ('phi_wet', scalar = .true.)
biotic(n)%kfe_org = fm_util_get_real ('kfe_org', scalar = .true.)
biotic(n)%kfe_bal = fm_util_get_real ('kfe_bal', scalar = .true.)
biotic(n)%kfe_des = fm_util_get_real ('kfe_des', scalar = .true.)
biotic(n)%kfe_max_prime = fm_util_get_real ('kfe_max_prime', scalar = .true.)
biotic(n)%mass_2_n = fm_util_get_real ('mass_2_n', scalar = .true.)
biotic(n)%n_2_p = fm_util_get_real ('n_2_p', scalar = .true.)
biotic(n)%n_2_p_fix = fm_util_get_real ('n_2_p_fix', scalar = .true.)
biotic(n)%c_2_n = fm_util_get_real ('c_2_n', scalar = .true.)
biotic(n)%o_2_c = fm_util_get_real ('o_2_c', scalar = .true.)
biotic(n)%o_2_no3 = fm_util_get_real ('o_2_no3', scalar = .true.)
biotic(n)%o_2_nh4 = fm_util_get_real ('o_2_nh4', scalar = .true.)
biotic(n)%o_2_nitrif = fm_util_get_real ('o_2_nitrif', scalar = .true.)
biotic(n)%o2_min = fm_util_get_real ('o2_min', scalar = .true.)
biotic(n)%bio_tau = fm_util_get_real ('bio_tau', scalar = .true.)
biotic(n)%bio_tau_don = fm_util_get_real ('bio_tau_don', scalar = .true.)
biotic(n)%bio_tau_dop = fm_util_get_real ('bio_tau_dop', scalar = .true.)
biotic(n)%bio_tau_fix = fm_util_get_real ('bio_tau_fix', scalar = .true.)
biotic(n)%bio_tau_ldoc = fm_util_get_real ('bio_tau_ldoc', scalar = .true.)
biotic(n)%bio_tau_nh4 = fm_util_get_real ('bio_tau_nh4', scalar = .true.)
biotic(n)%bio_tau_nitrif_d = fm_util_get_real ('bio_tau_nitrif_d', scalar = .true.)
biotic(n)%bio_tau_nitrif_s = fm_util_get_real ('bio_tau_nitrif_s', scalar = .true.)
biotic(n)%kappa_eppley = fm_util_get_real ('kappa_eppley', scalar = .true.)
biotic(n)%kappa_remin = fm_util_get_real ('kappa_remin', scalar = .true.)
biotic(n)%Prodstar = fm_util_get_real ('Prodstar', scalar = .true.)
biotic(n)%fdets0 = fm_util_get_real ('fdets0', scalar = .true.)
biotic(n)%fdetl0 = fm_util_get_real ('fdetl0', scalar = .true.)
biotic(n)%phi_don = fm_util_get_real ('phi_don', scalar = .true.)
biotic(n)%phi_dop = fm_util_get_real ('phi_dop', scalar = .true.)
biotic(n)%phi_ldoc = fm_util_get_real ('phi_ldoc', scalar = .true.)
biotic(n)%gamma_det = fm_util_get_real ('gamma_det', scalar = .true.)
biotic(n)%remin_density = fm_util_get_logical('remin_density', scalar = .true.)
biotic(n)%remin_lability = fm_util_get_logical('remin_lability', scalar = .true.)
biotic(n)%remin_ocmip2 = fm_util_get_logical('remin_ocmip2', scalar = .true.)
biotic(n)%remin_protection = fm_util_get_logical('remin_protection', scalar = .true.)
biotic(n)%remin_simple = fm_util_get_logical('remin_simple', scalar = .true.)
biotic(n)%remin_temp = fm_util_get_logical('remin_temp', scalar = .true.)
biotic(n)%remin_viscosity = fm_util_get_logical('remin_viscosity', scalar = .true.)
biotic(n)%remin_zoop_resp = fm_util_get_logical('remin_zoop_resp', scalar = .true.)
biotic(n)%rpcaco3 = fm_util_get_real ('rpcaco3', scalar = .true.)
biotic(n)%rpsio2 = fm_util_get_real ('rpsio2', scalar = .true.)
biotic(n)%wsink = fm_util_get_real ('wsink', scalar = .true.)
biotic(n)%sc_co2_0 = fm_util_get_real ('sc_co2_0', scalar = .true.)
biotic(n)%sc_co2_1 = fm_util_get_real ('sc_co2_1', scalar = .true.)
biotic(n)%sc_co2_2 = fm_util_get_real ('sc_co2_2', scalar = .true.)
biotic(n)%sc_co2_3 = fm_util_get_real ('sc_co2_3', scalar = .true.)
biotic(n)%sc_o2_0 = fm_util_get_real ('sc_o2_0', scalar = .true.)
biotic(n)%sc_o2_1 = fm_util_get_real ('sc_o2_1', scalar = .true.)
biotic(n)%sc_o2_2 = fm_util_get_real ('sc_o2_2', scalar = .true.)
biotic(n)%sc_o2_3 = fm_util_get_real ('sc_o2_3', scalar = .true.)
call fm_util_end_namelist(package_name, biotic(n)%name, caller = caller_str)
biotic(n)%r_bio_tau = 1.0 / biotic(n)%bio_tau
biotic(n)%r_bio_tau_don = 1.0 / biotic(n)%bio_tau_don
biotic(n)%r_bio_tau_dop = 1.0 / biotic(n)%bio_tau_dop
biotic(n)%r_bio_tau_ldoc = 1.0 / biotic(n)%bio_tau_ldoc
biotic(n)%r_bio_tau_nh4 = 1.0 / biotic(n)%bio_tau_nh4
biotic(n)%r_bio_tau_fix = 1.0 / biotic(n)%bio_tau_fix
biotic(n)%r_wsink = 1.0 / biotic(n)%wsink
biotic(n)%r_bio_tau_nitrif_s = 1.0 / biotic(n)%bio_tau_nitrif_s
biotic(n)%r_bio_tau_nitrif_d = 1.0 / biotic(n)%bio_tau_nitrif_d
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+norm_remin', caller = caller_str)
biotic(n)%norm_remin%factor = fm_util_get_real ('factor', scalar = .true.)
biotic(n)%norm_remin%coastal_only = fm_util_get_logical ('coastal_only', scalar = .true.)
biotic(n)%norm_remin%wlon => fm_util_get_real_array ('wlon')
biotic(n)%norm_remin%elon => fm_util_get_real_array ('elon')
biotic(n)%norm_remin%slat => fm_util_get_real_array ('slat')
biotic(n)%norm_remin%nlat => fm_util_get_real_array ('nlat')
biotic(n)%norm_remin%t_mask => fm_util_get_logical_array ('t_mask')
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+norm_remin', caller = caller_str)
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+no_caco3', caller = caller_str)
biotic(n)%no_caco3%factor = fm_util_get_real ('factor', scalar = .true.)
biotic(n)%no_caco3%coastal_only = fm_util_get_logical ('coastal_only', scalar = .true.)
biotic(n)%no_caco3%wlon => fm_util_get_real_array ('wlon')
biotic(n)%no_caco3%elon => fm_util_get_real_array ('elon')
biotic(n)%no_caco3%slat => fm_util_get_real_array ('slat')
biotic(n)%no_caco3%nlat => fm_util_get_real_array ('nlat')
biotic(n)%no_caco3%t_mask => fm_util_get_logical_array ('t_mask')
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+no_caco3', caller = caller_str)
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+nut_depl', caller = caller_str)
biotic(n)%nut_depl%factor = fm_util_get_real ('factor', scalar = .true.)
biotic(n)%nut_depl%coastal_only = fm_util_get_logical ('coastal_only', scalar = .true.)
biotic(n)%nut_depl%wlon => fm_util_get_real_array ('wlon')
biotic(n)%nut_depl%elon => fm_util_get_real_array ('elon')
biotic(n)%nut_depl%slat => fm_util_get_real_array ('slat')
biotic(n)%nut_depl%nlat => fm_util_get_real_array ('nlat')
biotic(n)%nut_depl%t_mask => fm_util_get_logical_array ('t_mask')
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+nut_depl', caller = caller_str)
call fm_util_start_namelist(trim(package_name), trim(biotic(n)%name) // '+r_bio_tau_prod', caller = caller_str)
biotic(n)%r_bio_tau_prod%factor = fm_util_get_real ('factor', scalar = .true.)
biotic(n)%r_bio_tau_prod%coastal_only = fm_util_get_logical ('coastal_only', scalar = .true.)
biotic(n)%r_bio_tau_prod%wlon => fm_util_get_real_array ('wlon')
biotic(n)%r_bio_tau_prod%elon => fm_util_get_real_array ('elon')
biotic(n)%r_bio_tau_prod%slat => fm_util_get_real_array ('slat')
biotic(n)%r_bio_tau_prod%nlat => fm_util_get_real_array ('nlat')
biotic(n)%r_bio_tau_prod%t_mask => fm_util_get_logical_array ('t_mask')
call fm_util_end_namelist(trim(package_name), trim(biotic(n)%name) // '+r_bio_tau_prod', caller = caller_str)
enddo
! calculate the index for the box containing the compensation depth
km_c_max = 0
do n = 1, instances
call locate(grid_zw, nk, biotic(n)%compensation_depth, &
biotic(n)%km_c, nearest = .true.)
if (grid_zw(biotic(n)%km_c) .lt. &
biotic(n)%compensation_depth) then
biotic(n)%km_c = biotic(n)%km_c + 1
endif
write (stdoutunit,*) trim(note_header), &
'The compensation depth for instance ', &
n, ', ', biotic(n)%compensation_depth, &
' m, occurs in box ', biotic(n)%km_c , &
' between depths ', &
grid_zw(biotic(n)%km_c-1), &
' m and ', grid_zw(biotic(n)%km_c), ' m'
km_c_max = max(km_c_max, biotic(n)%km_c)
enddo
! read in the norm_remin namelist data
do n = 1, instances
if (associated(biotic(n)%norm_remin%wlon)) then
len_w = size(biotic(n)%norm_remin%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%norm_remin%elon)) then
len_e = size(biotic(n)%norm_remin%elon)
else
len_e = 0
endif
if (associated(biotic(n)%norm_remin%slat)) then
len_s = size(biotic(n)%norm_remin%slat)
else
len_s = 0
endif
if (associated(biotic(n)%norm_remin%nlat)) then
len_n = size(biotic(n)%norm_remin%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%norm_remin%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%norm_remin%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process norm_remin array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%norm_remin%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%norm_remin%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%norm_remin%wlon, &
biotic(n)%norm_remin%elon, &
biotic(n)%norm_remin%slat, &
biotic(n)%norm_remin%nlat, &
biotic(n)%norm_remin%factor, 1.0, &
'Normal remineralization', biotic(n)%norm_remin%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%norm_remin%mask(:,:,l) = biotic(n)%norm_remin%mask(:,:,done)
endif
endif
enddo
endif
enddo
! read in the no_caco3 namelist data
do n = 1, instances
if (associated(biotic(n)%no_caco3%wlon)) then
len_w = size(biotic(n)%no_caco3%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%no_caco3%elon)) then
len_e = size(biotic(n)%no_caco3%elon)
else
len_e = 0
endif
if (associated(biotic(n)%no_caco3%slat)) then
len_s = size(biotic(n)%no_caco3%slat)
else
len_s = 0
endif
if (associated(biotic(n)%no_caco3%nlat)) then
len_n = size(biotic(n)%no_caco3%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%no_caco3%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%no_caco3%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process no_caco3 array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%no_caco3%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%no_caco3%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%no_caco3%wlon, &
biotic(n)%no_caco3%elon, &
biotic(n)%no_caco3%slat, &
biotic(n)%no_caco3%nlat, &
biotic(n)%no_caco3%factor, 1.0, &
'Carbonate inhibition', biotic(n)%no_caco3%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%no_caco3%mask(:,:,l) = biotic(n)%no_caco3%mask(:,:,done)
endif
endif
enddo
endif
enddo
! read in the nut_depl namelist data
do n = 1, instances
if (associated(biotic(n)%nut_depl%wlon)) then
len_w = size(biotic(n)%nut_depl%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%nut_depl%elon)) then
len_e = size(biotic(n)%nut_depl%elon)
else
len_e = 0
endif
if (associated(biotic(n)%nut_depl%slat)) then
len_s = size(biotic(n)%nut_depl%slat)
else
len_s = 0
endif
if (associated(biotic(n)%nut_depl%nlat)) then
len_n = size(biotic(n)%nut_depl%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%nut_depl%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%nut_depl%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process nut_depl array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%nut_depl%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%nut_depl%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%nut_depl%wlon, &
biotic(n)%nut_depl%elon, &
biotic(n)%nut_depl%slat, &
biotic(n)%nut_depl%nlat, &
biotic(n)%nut_depl%factor, 1.0, &
'Nutrient depletion', biotic(n)%nut_depl%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%nut_depl%mask(:,:,l) = biotic(n)%nut_depl%mask(:,:,done)
endif
endif
enddo
endif
enddo
! read in the r_bio_tau_prod namelist data
do n = 1, instances
if (associated(biotic(n)%r_bio_tau_prod%wlon)) then
len_w = size(biotic(n)%r_bio_tau_prod%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%r_bio_tau_prod%elon)) then
len_e = size(biotic(n)%r_bio_tau_prod%elon)
else
len_e = 0
endif
if (associated(biotic(n)%r_bio_tau_prod%slat)) then
len_s = size(biotic(n)%r_bio_tau_prod%slat)
else
len_s = 0
endif
if (associated(biotic(n)%r_bio_tau_prod%nlat)) then
len_n = size(biotic(n)%r_bio_tau_prod%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%r_bio_tau_prod%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%r_bio_tau_prod%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process r_bio_tau_prod array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%r_bio_tau_prod%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%r_bio_tau_prod%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%r_bio_tau_prod%wlon, &
biotic(n)%r_bio_tau_prod%elon, &
biotic(n)%r_bio_tau_prod%slat, &
biotic(n)%r_bio_tau_prod%nlat, &
biotic(n)%r_bio_tau_prod%factor, 1.0, &
'Primary production limitation', biotic(n)%r_bio_tau_prod%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%r_bio_tau_prod%mask(:,:,l) = biotic(n)%r_bio_tau_prod%mask(:,:,done)
endif
endif
enddo
endif
enddo
! multiply by the restoring factor
do n = 1, instances
biotic(n)%r_bio_tau_prod%mask(:,:,:) = &
biotic(n)%r_bio_tau * biotic(n)%r_bio_tau_prod%mask(:,:,:)
enddo
! calculate the index for the box containing the compensation depth
km_c_max = 0
do n = 1, instances
call locate(grid_zw, nk, biotic(n)%compensation_depth, &
biotic(n)%km_c, nearest = .true.)
if (grid_zw(biotic(n)%km_c) .lt. &
biotic(n)%compensation_depth) then
biotic(n)%km_c = biotic(n)%km_c + 1
endif
write (stdoutunit,*) trim(note_header), &
'The compensation depth for instance ', &
n, ', ', biotic(n)%compensation_depth, &
' m, occurs in box ', biotic(n)%km_c , &
' between depths ', &
grid_zw(biotic(n)%km_c-1), &
' m and ', grid_zw(biotic(n)%km_c), ' m'
km_c_max = max(km_c_max, biotic(n)%km_c)
enddo
! read in the norm_remin namelist data
do n = 1, instances
if (associated(biotic(n)%norm_remin%wlon)) then
len_w = size(biotic(n)%norm_remin%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%norm_remin%elon)) then
len_e = size(biotic(n)%norm_remin%elon)
else
len_e = 0
endif
if (associated(biotic(n)%norm_remin%slat)) then
len_s = size(biotic(n)%norm_remin%slat)
else
len_s = 0
endif
if (associated(biotic(n)%norm_remin%nlat)) then
len_n = size(biotic(n)%norm_remin%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%norm_remin%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%norm_remin%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process norm_remin array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%norm_remin%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%norm_remin%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%norm_remin%wlon, &
biotic(n)%norm_remin%elon, &
biotic(n)%norm_remin%slat, &
biotic(n)%norm_remin%nlat, &
biotic(n)%norm_remin%factor, 1.0, &
'Normal remineralization', biotic(n)%norm_remin%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%norm_remin%mask(:,:,l) = biotic(n)%norm_remin%mask(:,:,done)
endif
endif
enddo
endif
enddo
! read in the no_caco3 namelist data
do n = 1, instances
if (associated(biotic(n)%no_caco3%wlon)) then
len_w = size(biotic(n)%no_caco3%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%no_caco3%elon)) then
len_e = size(biotic(n)%no_caco3%elon)
else
len_e = 0
endif
if (associated(biotic(n)%no_caco3%slat)) then
len_s = size(biotic(n)%no_caco3%slat)
else
len_s = 0
endif
if (associated(biotic(n)%no_caco3%nlat)) then
len_n = size(biotic(n)%no_caco3%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%no_caco3%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%no_caco3%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process no_caco3 array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%no_caco3%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%no_caco3%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%no_caco3%wlon, &
biotic(n)%no_caco3%elon, &
biotic(n)%no_caco3%slat, &
biotic(n)%no_caco3%nlat, &
biotic(n)%no_caco3%factor, 1.0, &
'Carbonate inhibition', biotic(n)%no_caco3%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%no_caco3%mask(:,:,l) = biotic(n)%no_caco3%mask(:,:,done)
endif
endif
enddo
endif
enddo
! read in the nut_depl namelist data
do n = 1, instances
if (associated(biotic(n)%nut_depl%wlon)) then
len_w = size(biotic(n)%nut_depl%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%nut_depl%elon)) then
len_e = size(biotic(n)%nut_depl%elon)
else
len_e = 0
endif
if (associated(biotic(n)%nut_depl%slat)) then
len_s = size(biotic(n)%nut_depl%slat)
else
len_s = 0
endif
if (associated(biotic(n)%nut_depl%nlat)) then
len_n = size(biotic(n)%nut_depl%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%nut_depl%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%nut_depl%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process nut_depl array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%nut_depl%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%nut_depl%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%nut_depl%wlon, &
biotic(n)%nut_depl%elon, &
biotic(n)%nut_depl%slat, &
biotic(n)%nut_depl%nlat, &
biotic(n)%nut_depl%factor, 1.0, &
'Nutrient depletion', biotic(n)%nut_depl%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%nut_depl%mask(:,:,l) = biotic(n)%nut_depl%mask(:,:,done)
endif
endif
enddo
endif
enddo
! read in the r_bio_tau_prod namelist data
do n = 1, instances
if (associated(biotic(n)%r_bio_tau_prod%wlon)) then
len_w = size(biotic(n)%r_bio_tau_prod%wlon)
else
len_w = 0
endif
if (associated(biotic(n)%r_bio_tau_prod%elon)) then
len_e = size(biotic(n)%r_bio_tau_prod%elon)
else
len_e = 0
endif
if (associated(biotic(n)%r_bio_tau_prod%slat)) then
len_s = size(biotic(n)%r_bio_tau_prod%slat)
else
len_s = 0
endif
if (associated(biotic(n)%r_bio_tau_prod%nlat)) then
len_n = size(biotic(n)%r_bio_tau_prod%nlat)
else
len_n = 0
endif
if (len_e .ne. len_w .or. len_w .ne. len_s .or. len_s .ne. len_n) then
call mpp_error(FATAL, trim(error_header) // ' Region sizes are not equal for ' // trim(biotic(n)%name))
endif
if (size(biotic(n)%r_bio_tau_prod%t_mask) .ne. 12) then
call mpp_error(FATAL, trim(error_header) // ' t_mask size is not 12 for ' // trim(biotic(n)%name))
endif
! set all of the values to the default
biotic(n)%r_bio_tau_prod%mask(:,:,:) = 1.0
if (len_w .gt. 0) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), 'Process r_bio_tau_prod array for ', trim(biotic(n)%name)
write (stdoutunit,*)
! set values for this time-level
done = 0
do l = 1, 12
if (biotic(n)%r_bio_tau_prod%t_mask(l)) then
if (done .eq. 0) then
! set the values via the input values, saving this time index
! afterwards
write (stdoutunit,*) 'Assigning month ', l
call set_array(biotic(n)%r_bio_tau_prod%mask(:,:,l), &
isd, ied, jsd, jed, grid_xt, grid_yt, grid_kmt, &
len_w, biotic(n)%r_bio_tau_prod%wlon, &
biotic(n)%r_bio_tau_prod%elon, &
biotic(n)%r_bio_tau_prod%slat, &
biotic(n)%r_bio_tau_prod%nlat, &
biotic(n)%r_bio_tau_prod%factor, 1.0, &
'Primary production limitation', biotic(n)%r_bio_tau_prod%coastal_only)
done = l
else
! Duplicate the values for a previous time-level
write (stdoutunit,*) 'Duplicating month ', done, ' as ', l
biotic(n)%r_bio_tau_prod%mask(:,:,l) = biotic(n)%r_bio_tau_prod%mask(:,:,done)
endif
endif
enddo
endif
enddo
! multiply by the restoring factor
do n = 1, instances
biotic(n)%r_bio_tau_prod%mask(:,:,:) = &
biotic(n)%r_bio_tau * biotic(n)%r_bio_tau_prod%mask(:,:,:)
enddo
! initialize special arrays for remineralization
do n = 1, instances
do k = 1, nk
biotic(n)%r_intzscale_n(k) = biotic(n)%gamma_det / &
biotic(n)%wsink * grid_dzt(k)
biotic(n)%r_1plusintzscale_n(k) = 1.0 / (1.0 + &
biotic(n)%r_intzscale_n(k))
biotic(n)%r_1plusintzscale_si(k) = 1.0 / (1.0 + &
grid_dzt(k) / biotic(n)%si_remin_depth)
biotic(n)%r_1plusintzscale_ca(k) = 1.0 / (1.0 + &
grid_dzt(k) / biotic(n)%ca_remin_depth)
biotic(n)%zforg(k) = (grid_zw(k) / &
biotic(n)%compensation_depth) ** (-biotic(n)%martin_coeff)
enddo
enddo
! Read in additional information for a restart.
! We must process all of the instances before restoring any files
! as all fields must be registered before the fields are
! restored, and fields from different instances may be in the
! same file.
! Note that the restart file names here must be different from
! those for the tracer values.
allocate(restart(instances))
allocate(local_restart_file(instances))
write(stdoutunit,*)
do n = 1, instances
! Set the suffix for this instance (if instance name is "_",
! then use a blank suffix).
if (biotic(n)%name(1:1) .eq. '_') then
suffix = ' '
else
suffix = '_' // biotic(n)%name
endif
! Check whether we are already using this restart file, if so,
! we do not want to duplicate it in the list of restart files
! since we only read each restart file once.
ind = 0
do l = 1, num_restart
if (biotic(n)%local_restart_file == local_restart_file(l)) then
ind = l
exit
endif
end do
if (ind .eq. 0) then
num_restart = num_restart + 1
ind = num_restart
local_restart_file(ind) = trim(biotic(n)%local_restart_file)
end if
! Check whether the field already exists in the restart file.
! If not, then set a default value.
fld_exist = field_exist('INPUT/' // trim(biotic(n)%local_restart_file), 'htotal' // trim(suffix) )
if ( fld_exist ) then
write (stdoutunit,*) trim(note_header), &
'Reading additional information for instance ', &
': Initializing instance ', trim(biotic(n)%name)
else
write (stdoutunit,*) trim(note_header), &
'Initializing instance ', trim(biotic(n)%name)
biotic(n)%htotal(:,:) = htotal_in
endif
! Register the field for restart
id_restart = register_restart_field(restart(ind), biotic(n)%local_restart_file, &
'htotal' // trim(suffix), biotic(n)%htotal, &
domain=mpp_domain2d, mandatory=fld_exist )
enddo
! Restore the restart fields if the file exists
do l = 1, num_restart
if (file_exist('INPUT/' // trim(local_restart_file(l)))) then
call restore_state(restart(l))
end if
end do
deallocate(local_restart_file)
! Set up analyses
! register the fields
suffix = '_' // package_name
long_suffix = ' (' // trim(package_name) // ')'
id_o2_sat = register_diag_field(trim(diag_name), &
'o2_saturation' // trim(suffix), grid_tracer_axes(1:2), &
model_time, 'O2 saturation' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
do n = 1, instances
if (biotic(n)%name(1:1) .eq. '_') then
suffix = ' '
long_suffix = ' '
else
suffix = '_' // biotic(n)%name
long_suffix = ' (' // trim(biotic(n)%name) // ')'
endif
biotic(n)%id_sc_co2 = register_diag_field(trim(diag_name), &
'sc_co2' // trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Schmidt number - CO2' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_sc_o2 = register_diag_field(trim(diag_name), &
'sc_o2' // trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Schmidt number - O2' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_sfc_flux_co2 = register_diag_field(trim(diag_name), &
'sfc_flux_co2' // trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Surface Flux - CO2' // trim(long_suffix), 'mol m^-2 s^-1', &
missing_value = -1.0e+10)
biotic(n)%id_sfc_flux_o2 = register_diag_field(trim(diag_name), &
'sfc_flux_o2' // trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Surface Flux - O2' // trim(long_suffix), 'mol m^-2 s^-1', &
missing_value = -1.0e+10)
biotic(n)%id_sfc_flux_fed = register_diag_field(trim(diag_name), &
'sfc_flux_fed' // trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Surface Flux - Fed' // trim(long_suffix), 'mol m^-2 s^-1', &
missing_value = -1.0e+10)
biotic(n)%id_alpha = register_diag_field(trim(diag_name), &
'alpha'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Alpha CO2' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_csurf = register_diag_field(trim(diag_name), &
'csurf'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'CO2* water' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_pco2surf = register_diag_field(trim(diag_name), &
'pco2surf'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Oceanic pCO2' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_flux_pon = register_diag_field(trim(diag_name), &
'flux_pon'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'PON flux' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_flux_pop = register_diag_field(trim(diag_name), &
'flux_pop'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'POP flux' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_flux_sio2 = register_diag_field(trim(diag_name), &
'flux_sio2'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'Si flux' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_flux_caco3 = register_diag_field(trim(diag_name), &
'flux_caco3'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'CaCO3 flux' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_htotal = register_diag_field(trim(diag_name), &
'htotal'// trim(suffix), grid_tracer_axes(1:2), &
model_time, 'H+ ion concentration' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_alk = register_diag_field(trim(diag_name), &
'jprod_alk'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Restoring alkalinity-based production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_fed = register_diag_field(trim(diag_name), &
'jprod_fed'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Restoring iron-based production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_n_fix = register_diag_field(trim(diag_name), &
'jprod_n_fix'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Nitrogen fixation' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_no3 = register_diag_field(trim(diag_name), &
'jprod_no3'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Restoring NO3-based production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_nh4 = register_diag_field(trim(diag_name), &
'jprod_nh4'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'NH4-based production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_p_fix = register_diag_field(trim(diag_name), &
'jprod_p_fix'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'PO4 in nitrogen fixation' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_po4 = register_diag_field(trim(diag_name), &
'jprod_po4'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Restoring PO4-based production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_pofe = register_diag_field(trim(diag_name), &
'jprod_pofe'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Detrital iron production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_pon = register_diag_field(trim(diag_name), &
'jprod_pon'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Detrital nitrogen production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_pop = register_diag_field(trim(diag_name), &
'jprod_pop'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Detrital phosphorus production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jprod_sio4 = register_diag_field(trim(diag_name), &
'jprod_sio4'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Restoring Si-based production' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jcaco3 = register_diag_field(trim(diag_name), &
'jcaco3'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'CaCO3 change' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jfe_ads = register_diag_field(trim(diag_name), &
'jfe_ads'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Iron adsorption' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jfe_des = register_diag_field(trim(diag_name), &
'jfe_des'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Iron desorption' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jfe_graz = register_diag_field(trim(diag_name), &
'jfe_graz'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Dissolved iron source from grazing' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jfe_sink = register_diag_field(trim(diag_name), &
'jfe_sink'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Particulate iron sinking' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jno3 = register_diag_field(trim(diag_name), &
'jno3'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'NO3 source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jnh4 = register_diag_field(trim(diag_name), &
'jnh4'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'NH4 source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jnh4_graz = register_diag_field(trim(diag_name), &
'jnh4_graz'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'NH4 source from grazing' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jpo4_graz = register_diag_field(trim(diag_name), &
'jpo4_graz'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'PO4 source from grazing' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jpo4 = register_diag_field(trim(diag_name), &
'jpo4'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'PO4 source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jpofe = register_diag_field(trim(diag_name), &
'jpofe'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Loss of sinking iron' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jpon = register_diag_field(trim(diag_name), &
'jpon'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Loss of sinking nitrogen' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jpop = register_diag_field(trim(diag_name), &
'jpop'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Loss of sinking phosphorus' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jsio4 = register_diag_field(trim(diag_name), &
'jsio4'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'SiO4 source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jdenit = register_diag_field(trim(diag_name), &
'jdenit'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Denitrification' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jdon = register_diag_field(trim(diag_name), &
'jdon'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'DON source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jdop = register_diag_field(trim(diag_name), &
'jdop'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'DOP source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jldoc = register_diag_field(trim(diag_name), &
'jldoc'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Labile DOC source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_jo2 = register_diag_field(trim(diag_name), &
'jo2'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'O2 source' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_fpon = register_diag_field(trim(diag_name), &
'fpon'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'PON change' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_fpop = register_diag_field(trim(diag_name), &
'fpop'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'POP change' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_fracl = register_diag_field(trim(diag_name), &
'fracl'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Fraction large phytoplankton' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_fsio2 = register_diag_field(trim(diag_name), &
'fsio2'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'Si change' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
biotic(n)%id_fcaco3 = register_diag_field(trim(diag_name), &
'fcaco3'// trim(suffix), grid_tracer_axes(1:3), &
model_time, 'CaCO3 change' // trim(long_suffix), ' ', &
missing_value = -1.0e+10)
enddo
! integrate the total concentrations of some tracers
! for the start of the run
! Use taup1 time index for the start of a run, and taup1 time
! index for the end of a run so that we are integrating the
! same time level and should therefore get identical results
do n = 1, instances
total_alkalinity = 0.0
total_ammonia = 0.0
total_dic = 0.0
total_don = 0.0
total_dop = 0.0
total_fediss = 0.0
total_fepart = 0.0
total_ldoc = 0.0
total_nitrate = 0.0
total_o2 = 0.0
total_phosphate = 0.0
total_silicate = 0.0
do k = 1,nk
do j = jsc, jec
do i = isc, iec
total_nitrate = total_nitrate + &
t_prog(biotic(n)%ind_no3)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_ammonia = total_ammonia + &
t_prog(biotic(n)%ind_nh4)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_phosphate = total_phosphate + &
t_prog(biotic(n)%ind_po4)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_fediss = total_fediss + &
t_prog(biotic(n)%ind_fed)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_fepart = total_fepart + &
t_diag(biotic(n)%ind_fep)%field(i,j,k) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_silicate = total_silicate + &
t_prog(biotic(n)%ind_sio4)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_don = total_don + &
t_prog(biotic(n)%ind_don)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_dop = total_dop + &
t_prog(biotic(n)%ind_dop)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_ldoc = total_ldoc + &
t_prog(biotic(n)%ind_ldoc)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_o2 = total_o2 + &
t_prog(biotic(n)%ind_o2)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_dic = total_dic + &
t_prog(biotic(n)%ind_dic)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
total_alkalinity = total_alkalinity + &
t_prog(biotic(n)%ind_alk)%field(i,j,k,taup1) * &
grid_dat(i,j) * grid_tmask(i,j,k) * rho_dzt(i,j,k,taup1)
enddo
enddo
enddo
call mpp_sum(total_nitrate)
call mpp_sum(total_ammonia)
call mpp_sum(total_phosphate)
call mpp_sum(total_fediss)
call mpp_sum(total_fepart)
call mpp_sum(total_silicate)
call mpp_sum(total_don)
call mpp_sum(total_dop)
call mpp_sum(total_ldoc)
call mpp_sum(total_o2)
call mpp_sum(total_dic)
call mpp_sum(total_alkalinity)
write (stdoutunit,*) ' Instance ', trim(biotic(n)%name)
write (stdoutunit, &
'(/'' Total nitrate = '',es19.12,'' Gmol-N'')') &
total_nitrate * 1.0e-09
write (stdoutunit, &
'(/'' Total ammonia = '',es19.12,'' Gmol-N'')') &
total_ammonia * 1.0e-09
write (stdoutunit, &
'(/'' Total phosphate = '',es19.12,'' Gmol-P'')') &
total_phosphate * 1.0e-09
write (stdoutunit, &
'(/'' Total fediss = '',es19.12,'' Gmol-Fe'')') &
total_fediss * 1.0e-09
write (stdoutunit, &
'(/'' Total fepart = '',es19.12,'' Gmol-Fe'')') &
total_fepart * 1.0e-09
write (stdoutunit, &
'(/'' Total silicate = '',es19.12,'' Gmol-Si'')') &
total_silicate * 1.0e-09
write (stdoutunit, &
'(/'' Total DON = '',es19.12,'' Gmol-C'')') &
total_DON * 1.0e-09
write (stdoutunit, &
'(/'' Total DOP = '',es19.12,'' Gmol-P'')') &
total_DOP * 1.0e-09
write (stdoutunit, &
'(/'' Total LDOC = '',es19.12,'' Gmol-C'')') &
total_LDOC * 1.0e-09
write (stdoutunit, &
'(/'' Total O2 = '',es19.12,'' Gmol-O'')') &
total_o2 * 1.0e-09
write (stdoutunit, &
'(/'' Total DIC = '',es19.12,'' Gmol-C'')') &
total_dic * 1.0e-09
write (stdoutunit, &
'(/'' Total alkalinity = '',es19.12,'' Geq'')') &
total_alkalinity * 1.0e-09
write (stdoutunit, &
'(/'' Total nitrogen = '',es19.12,'' Gmol-N'')') &
(total_nitrate + total_don) * 1.0e-09
write (stdoutunit, &
'(/'' Total phosphorus = '',es19.12,'' Gmol-P'')') &
(total_phosphate + total_dop) * 1.0e-09
write (stdoutunit, &
'(/'' Total real O2 = '',es19.12,'' Gmol-O'')') &
(total_o2 + biotic(n)%o_2_no3 * total_nitrate) * 1.0e-09
write (stdoutunit, &
'(/'' Total Carbon = '',es19.12,'' Gmol-C'')') &
(total_dic + biotic(n)%c_2_n * total_don + total_ldoc) * 1.0e-09
write (stdoutunit, &
'(/'' Total real alkalinity = '',es19.12,'' Geq'')') &
(total_alkalinity + total_nitrate) * 1.0e-09
enddo
write(stdoutunit,*)
write(stdoutunit,*) trim(note_header), 'Tracer runs initialized'
write(stdoutunit,*)
return
end subroutine ocean_bgc_restore_start
! </SUBROUTINE> NAME="ocean_bgc_restore_start"
!#######################################################################
! <SUBROUTINE NAME="set_array">
!
! <DESCRIPTION>
! Set up an array covering the model domain with a user-specified
! value, in user-specified regions. There are a given number of
! 2-d regions specified by the values slat, nlat, wlon and elon.
! The longitudes are for a cyclic domain, and if wlon and elon
! are on opposite sides of the cut, the correct thing will
! be done. Elon is considered to be east of wlon, so if elon is
! less than wlon, then the region east of elon to the cut will be
! filled, and the region from the cut to wlon will be filled.
!
! After setting up the array in this routine, it may prove useful
! to allow fine-tuning the settings via an array in a namelist.
!
! Arguments:
! Input:
! num_regions = number of user-specified regions which will be
! filled
!
! wlon = 1-d array of western (starting) longitudes for the
! rectangular regions
!
! elon = 1-d array of eastern (ending) longitudes for the
! rectangular regions
!
! slat = 1-d array of southern (starting) latitudes for the
! rectangular regions
!
! nlat = 1-d array of northern (ending) latitudes for the
! rectangular regions
!
! Note: if slat >= nlat, then nothing is done
! for that region
!
! set_value = the value to assign to array in the user-specified
! regions
!
! unset_value = the value to assign to array outside of the
! user-specified regions
!
! name = character variable used in informative messages
!
! coastal_only = true to limit changes only to coastal points
! (i.e., at least one bordering point is land)
!
! Output:
!
! array = 2-d array which will contain the set- and unset-
! values. The array is assumed to have a border
! one unit wide on all edges, ala MOM. A cyclic
! boundary condition will be set if requested.
! </DESCRIPTION>
!
subroutine set_array(array, isd, ied, jsd, jed, &
xt, yt, kmt, &
num_regions, wlon_in, elon_in, slat, nlat, &
set_value, unset_value, name, &
coastal_only)
integer, intent(in) :: isd
integer, intent(in) :: ied
integer, intent(in) :: jsd
integer, intent(in) :: jed
integer, intent(in) :: num_regions
real, dimension(isd:,jsd:), intent(out) :: array
logical, intent(in) :: coastal_only
real, dimension(num_regions), intent(in) :: elon_in
integer, dimension(isd:,jsd:), intent(in) :: kmt
character(len=*), intent(in) :: name
real, dimension(num_regions), intent(in) :: nlat
real, intent(in) :: set_value
real, dimension(num_regions), intent(in) :: slat
real, intent(in) :: unset_value
real, dimension(num_regions), intent(in) :: wlon_in
real, dimension(isd:,jsd:), intent(in) :: xt
real, dimension(isd:,jsd:), intent(in) :: yt
character(len=64), parameter :: sub_name = 'set_array'
character(len=256), parameter :: error_header = &
'==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
integer :: i, j, n
real, dimension(:), allocatable :: wlon
real, dimension(:), allocatable :: elon
integer :: stdoutunit
stdoutunit=stdout()
! save the longitudes in case they need to be modified
allocate(wlon(num_regions))
allocate(elon(num_regions))
wlon(:) = wlon_in(:)
elon(:) = elon_in(:)
! loop over the regions, applying changes as necessary
do n = 1, num_regions
if (nlat(n) .ge. slat(n)) then
write (stdoutunit,*)
write (stdoutunit,*) trim(note_header), &
trim(name), ' region: ', n
! make sure that all longitudes are in the range [0,360]
do while (wlon(n) .gt. 360.0)
wlon(n) = wlon(n) - 360.0
enddo
do while (wlon(n) .lt. 0.0)
wlon(n) = wlon(n) + 360.0
enddo
do while (elon(n) .gt. 360.0)
elon(n) = elon(n) - 360.0
enddo
do while (elon(n) .lt. 0.0)
elon(n) = elon(n) + 360.0
enddo
! if the southern and northern latitudes are the same, then
! find the grid box which encompasses them ...
if (slat(n) .eq. nlat(n)) then
call mpp_error(FATAL, trim(error_header) // &
'Equal latitudes not supported')
elseif (wlon(n) .eq. elon(n)) then
call mpp_error(FATAL, trim(error_header) // &
'Equal longitudes not supported')
else
! ... else find all boxes where the center lies in the
! rectangular region
do j = jsd, jed
do i = isd, ied
if (nlat(n) .ge. yt(i,j) .and. &
slat(n) .le. yt(i,j) .and. &
lon_between(xt(i,j), wlon(n), elon(n))) then
array(i,j) = set_value
endif
enddo
enddo
endif
endif
enddo
! if desired only apply mask to coastal regions
if (coastal_only) then
do j = jsd, jed
do i = isd, ied
if (kmt(i,j) .ne. 0 .and. &
array(i,j) .eq. set_value) then
! if all the surrounding points are ocean, then this is not
! a coastal point, therefore reset the mask
if (kmt(i-1,j) .ne. 0 .and. &
kmt(i+1,j) .ne. 0 .and. &
kmt(i,j-1) .ne. 0 .and. &
kmt(i,j+1) .ne. 0) then
array(i,j) = unset_value
endif
endif
enddo
enddo
endif
! clean up
deallocate(wlon)
deallocate(elon)
return
contains
!
! Return true if w <= x_in <= e, taking into account the
! periodicity of longitude.
!
! x_in = value to test
!
! w = west longitude of boundary
!
! e = east longitude of boundary
!
function lon_between(x_in, w, e)
logical :: lon_between
real, intent(in) :: x_in
real, intent(in) :: w
real, intent(in) :: e
real :: x
! Save input values so we may modify them safely
x = x_in
! make sure that all longitudes are in the range [0,360]
do while (x .gt. 360.0)
x = x - 360.0
enddo
do while (x .lt. 0.0)
x = x + 360.0
enddo
if (w .gt. e) then
lon_between = w .le. x .or. x .le. e
else
lon_between = w .le. x .and. x .le. e
endif
return
end function lon_between
end subroutine set_array
! </SUBROUTINE> NAME="set_array"
end module ocean_bgc_restore_mod
| gpl-2.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/widechar_intrinsics_4.f90 | 19 | 3865 | ! { dg-do run }
! { dg-options "-fbackslash" }
character(kind=1,len=20) :: s1
character(kind=4,len=20) :: s4
call test_adjust1 (" foo bar ", 4_" foo bar ")
s1 = " foo bar " ; s4 = 4_" foo bar "
call test_adjust2 (s1, s4)
call test_adjust1 (" foo bar \xFF", 4_" foo bar \xFF")
s1 = " foo bar \xFF" ; s4 = 4_" foo bar \xFF"
call test_adjust2 (s1, s4)
call test_adjust1 ("\0 foo bar \xFF", 4_"\0 foo bar \xFF")
s1 = "\0 foo bar \xFF" ; s4 = 4_"\0 foo bar \xFF"
call test_adjust2 (s1, s4)
s4 = "\0 foo bar \xFF"
if (adjustl (s4) /= adjustl (4_"\0 foo bar \xFF ")) STOP 1
if (adjustr (s4) /= adjustr (4_"\0 foo bar \xFF ")) STOP 2
s4 = " \0 foo bar \xFF"
if (adjustl (s4) /= adjustl (4_" \0 foo bar \xFF ")) STOP 3
if (adjustr (s4) /= adjustr (4_" \0 foo bar \xFF ")) STOP 4
s4 = 4_" \U12345678\xeD bar \ufd30"
if (adjustl (s4) /= &
adjustl (4_" \U12345678\xeD bar \ufd30 ")) STOP 5
if (adjustr (s4) /= &
adjustr (4_" \U12345678\xeD bar \ufd30 ")) STOP 6
contains
subroutine test_adjust1 (s1, s4)
character(kind=1,len=*) :: s1
character(kind=4,len=*) :: s4
character(kind=1,len=len(s4)) :: t1
character(kind=4,len=len(s1)) :: t4
if (len(s1) /= len(s4)) STOP 7
if (len(t1) /= len(t4)) STOP 8
if (len_trim(s1) /= len_trim (s4)) STOP 9
t1 = adjustl (s4)
t4 = adjustl (s1)
if (t1 /= adjustl (s1)) STOP 10
if (t4 /= adjustl (s4)) STOP 11
if (len_trim (t1) /= len_trim (t4)) STOP 12
if (len_trim (adjustl (s1)) /= len_trim (t4)) STOP 13
if (len_trim (adjustl (s4)) /= len_trim (t1)) STOP 14
if (len_trim (t1) /= len (trim (t1))) STOP 15
if (len_trim (s1) /= len (trim (s1))) STOP 16
if (len_trim (t4) /= len (trim (t4))) STOP 17
if (len_trim (s4) /= len (trim (s4))) STOP 18
t1 = adjustr (s4)
t4 = adjustr (s1)
if (t1 /= adjustr (s1)) STOP 19
if (t4 /= adjustr (s4)) STOP 20
if (len_trim (t1) /= len_trim (t4)) STOP 21
if (len_trim (adjustr (s1)) /= len_trim (t4)) STOP 22
if (len_trim (adjustr (s4)) /= len_trim (t1)) STOP 23
if (len (t1) /= len_trim (t1)) STOP 24
if (len (t4) /= len_trim (t4)) STOP 25
if (len_trim (t1) /= len (trim (t1))) STOP 26
if (len_trim (s1) /= len (trim (s1))) STOP 27
if (len_trim (t4) /= len (trim (t4))) STOP 28
if (len_trim (s4) /= len (trim (s4))) STOP 29
end subroutine test_adjust1
subroutine test_adjust2 (s1, s4)
character(kind=1,len=20) :: s1
character(kind=4,len=20) :: s4
character(kind=1,len=len(s4)) :: t1
character(kind=4,len=len(s1)) :: t4
if (len(s1) /= len(s4)) STOP 30
if (len(t1) /= len(t4)) STOP 31
if (len_trim(s1) /= len_trim (s4)) STOP 32
t1 = adjustl (s4)
t4 = adjustl (s1)
if (t1 /= adjustl (s1)) STOP 33
if (t4 /= adjustl (s4)) STOP 34
if (len_trim (t1) /= len_trim (t4)) STOP 35
if (len_trim (adjustl (s1)) /= len_trim (t4)) STOP 36
if (len_trim (adjustl (s4)) /= len_trim (t1)) STOP 37
if (len_trim (t1) /= len (trim (t1))) STOP 38
if (len_trim (s1) /= len (trim (s1))) STOP 39
if (len_trim (t4) /= len (trim (t4))) STOP 40
if (len_trim (s4) /= len (trim (s4))) STOP 41
t1 = adjustr (s4)
t4 = adjustr (s1)
if (t1 /= adjustr (s1)) STOP 42
if (t4 /= adjustr (s4)) STOP 43
if (len_trim (t1) /= len_trim (t4)) STOP 44
if (len_trim (adjustr (s1)) /= len_trim (t4)) STOP 45
if (len_trim (adjustr (s4)) /= len_trim (t1)) STOP 46
if (len (t1) /= len_trim (t1)) STOP 47
if (len (t4) /= len_trim (t4)) STOP 48
if (len_trim (t1) /= len (trim (t1))) STOP 49
if (len_trim (s1) /= len (trim (s1))) STOP 50
if (len_trim (t4) /= len (trim (t4))) STOP 51
if (len_trim (s4) /= len (trim (s4))) STOP 52
end subroutine test_adjust2
end
| gpl-2.0 |
nvarini/espresso_adios | TDDFPT/src/lr_apply_liouvillian_eels.f90 | 2 | 17956 | !
! Copyright (C) 2001-2015 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!--------------------------------------------------------------------------------
SUBROUTINE lr_apply_liouvillian_eels ( evc1, evc1_new, sevc1_new, interaction )
!------------------------------------------------------------------------------
!
! This subroutine applies the linear response operator to response wavefunctions.
! (H - E)*psi(k+q) + V_HXC(q)*psi0(k)
!
! Inspired by PH/solve_linter.f90
!
! Written by Iurii Timrov (2013)
!
USE ions_base, ONLY : ityp, nat, ntyp=>nsp
USE cell_base, ONLY : tpiba2
USE fft_base, ONLY : dfftp, dffts, tg_cgather
USE fft_interfaces, ONLY : fwfft, invfft
USE gvecs, ONLY : nls, nlsm, ngms, doublegrid
USE gvect, ONLY : nl, nlm, ngm, g, gg
USE io_global, ONLY : stdout
USE kinds, ONLY : dp
USE klist, ONLY : nks, xk
USE lr_variables, ONLY : evc0, no_hxc, lr_periodic
USE lsda_mod, ONLY : nspin, current_spin
USE wvfct, ONLY : nbnd, npwx, g2kin, et, npw, igk, ecutwfc
USE io_global, ONLY : stdout
USE uspp, ONLY : vkb
USE qpoint, ONLY : npwq, igkq, ikks, ikqs, nksq
USE eqv, ONLY : evq, dpsi, dvpsi
USE io_files, ONLY : iunigk
USE wavefunctions_module, ONLY : evc, psic, psic_nc
USE units_ph, ONLY : lrwfc, iuwfc
USE noncollin_module, ONLY : noncolin, npol, nspin_mag
USE control_ph, ONLY : nbnd_occ
USE uspp, ONLY : okvan
USE nlcc_ph, ONLY : nlcc_any
USE iso_c_binding, ONLY : c_int
USE mp_bands, ONLY : ntask_groups, me_bgrp
USE spin_orb, ONLY : domag
IMPLICIT NONE
!
COMPLEX(kind=dp),INTENT(in) :: evc1(npwx*npol,nbnd,nksq)
COMPLEX(kind=dp),INTENT(out) :: evc1_new(npwx*npol,nbnd,nksq), &
sevc1_new(npwx*npol,nbnd,nksq)
! output : sevc1_new = S * evc1_new
LOGICAL, INTENT(in) :: interaction
LOGICAL :: interaction1
INTEGER :: i,j,ir, ibnd, ik, ig, ia, ios, ikk, ikq, is, &
incr, v_siz, ipol
COMPLEX(DP), ALLOCATABLE :: hpsi(:,:), spsi(:,:), revc(:,:), &
& dvrsc(:,:), dvrssc(:,:), &
! Change of the Hartree and exchange-correlation (HXC) potential
& tg_psic(:,:), tg_dvrssc(:,:)
! Task groups: wfct in R-space
! Task groups: HXC potential
INTEGER(kind=c_int) :: kilobytes
INTEGER, ALLOCATABLE :: ibuf(:)
!
CALL start_clock('lr_apply')
!
IF ( ntask_groups > 1 ) dffts%have_task_groups = .TRUE.
!
ALLOCATE (hpsi(npwx*npol,nbnd))
ALLOCATE (spsi(npwx*npol,nbnd))
ALLOCATE (revc(dffts%nnr,npol))
ALLOCATE (dvrsc(dfftp%nnr,nspin_mag))
ALLOCATE (dvrssc(dffts%nnr,nspin_mag))
IF (.not. ALLOCATED(psic)) ALLOCATE(psic(dfftp%nnr))
hpsi(:,:) = (0.d0,0.d0)
spsi(:,:) = (0.d0,0.d0)
revc(:,:) = (0.d0,0.d0)
dvrsc(:,:) = (0.0d0,0.0d0)
dvrssc(:,:) = (0.0d0,0.0d0)
!
incr = 1
!
IF ( dffts%have_task_groups ) THEN
!
v_siz = dffts%tg_nnr * dffts%nogrp
!
ALLOCATE( tg_dvrssc(v_siz,nspin_mag) )
ALLOCATE( tg_psic(v_siz,npol) )
!
incr = dffts%nogrp
!
ENDIF
!
! Memory usage
!
!CALL memstat( kilobytes )
!IF ( kilobytes > 0 ) WRITE(stdout,'(5X,"lr_apply_liouvillian_eels, &
! & per-process dynamical memory:",f7.1,"Mb")' ) kilobytes/1000.0
!
IF (no_hxc) THEN
interaction1 = .false.
ELSE
interaction1 = interaction
ENDIF
!
IF (interaction1) CALL start_clock('lr_apply_int')
IF (.not.interaction1) CALL start_clock('lr_apply_no')
!
! Calculation of the charge density response and the
! corresponding change of the Hartree and exchange-correlation
! potentials. If no_hxc=.true. this part is not needed and thus
! is not calculated.
!
IF ( interaction1 ) THEN
!
! Calculation of the charge density response, and symmetrization of it.
!
!if (.not. allocated(psic)) allocate(psic(dfftp%nnr))
!
IF (noncolin) THEN
call lr_calc_dens_eels_nc (dvrsc(1,1), evc1(1,1,1))
ELSE
call lr_calc_dens_eels (dvrsc(1,current_spin), evc1(1,1,1))
ENDIF
!
!if (allocated(psic)) deallocate(psic)
!
! Calculation of the HXC potential
! input: the change of the charge density (dvrsc)
! output: the change of the HXC potential (dvrsc)
! Note: check the implementation of the non-linear core correction.
!
!CALL dv_of_drho(0, dvrsc, .false.)
CALL lr_dv_of_drho_eels(dvrsc)
!
! Interpolation of the HXC potential from the thick mesh
! to a smoother mesh (if doublegrid=.true.)
! dvrsc -> dvrssc
!
DO is = 1, nspin_mag
CALL cinterpolate (dvrsc(1,is), dvrssc(1,is), -1)
ENDDO
!
ENDIF
!
! Now we will calculate two terms:
! 1) HXC term : P_c (delta V_HXC(q)) psi(k)
! 2) (H - E) * psi(k+q)
!
!if (nksq.gt.1) rewind (unit = iunigk)
!
DO ik = 1, nksq
!
IF (lr_periodic) THEN
ikk = ik
ikq = ik
ELSE
ikk = ikks(ik)
ikq = ikqs(ik)
ENDIF
!
! Determination of npw, igk, and npwq, igkq;
! g2kin is used here as a workspace.
!
CALL gk_sort( xk(1,ikk), ngm, g, ( ecutwfc / tpiba2 ), npw, igk, g2kin )
CALL gk_sort( xk(1,ikq), ngm, g, ( ecutwfc / tpiba2 ), npwq, igkq, g2kin )
!
! Calculate beta-functions vkb at k+q (Kleinman-Bylander projectors)
! The vks's are needed for the non-local potential in h_psiq,
! and for the ultrasoft term.
!
CALL init_us_2 (npwq, igkq, xk(1,ikq), vkb)
!
! if (nksq.gt.1) then
! read (iunigk, err = 100, iostat = ios) npw, igk
!100 call errore ('lr_apply_liouvillian', 'reading igk', abs (ios) )
! endif
! !
! if (nksq.gt.1) then
! read (iunigk, err = 200, iostat = ios) npwq, igkq
!200 call errore ('lr_apply_liouvillian', 'reading igkq', abs (ios) )
! endif
!
! Read unperturbed wavefuctions psi(k) and psi(k+q)
!
IF (lr_periodic) THEN
evc(:,:) = evc0(:,:,ik)
evq(:,:) = evc0(:,:,ik)
ELSE
IF (nksq.gt.1) THEN
CALL davcio (evc, lrwfc, iuwfc, ikk, - 1)
CALL davcio (evq, lrwfc, iuwfc, ikq, - 1)
ENDIF
ENDIF
!
dpsi(:,:) = (0.d0,0.d0)
dvpsi(:,:) = (0.d0,0.d0)
!
! 1) Hartree and exchange-correlation term.
! The multiplication of the HXC potential dvrssc with
! the unperturbed wavefunctions revc is done in R-space.
! If interaction1=.true. calculate HXC term
! If interaction1=.false. skip this step and go to 2)
!
IF (interaction1) THEN
!
IF ( ntask_groups > 1 ) dffts%have_task_groups = .TRUE.
!
! The potential in dvrssc is distributed across all processors.
! We need to redistribute it so that it is completely contained in the
! processors of an orbital TASK-GROUP.
!
IF ( dffts%have_task_groups ) THEN
!
IF (noncolin) THEN
!
CALL tg_cgather( dffts, dvrssc(:,1), tg_dvrssc(:,1))
!
IF (domag) THEN
DO ipol = 2, 4
CALL tg_cgather( dffts, dvrssc(:,ipol), tg_dvrssc(:,ipol))
ENDDO
ENDIF
!
ELSE
!
CALL tg_cgather( dffts, dvrssc(:,current_spin), tg_dvrssc(:,1))
!
ENDIF
!
ENDIF
!
DO ibnd = 1, nbnd_occ(ikk), incr
!
IF ( dffts%have_task_groups ) THEN
!
! FFT to R-space
!
CALL cft_wave_tg(evc, tg_psic, 1, v_siz, ibnd, nbnd_occ(ikk) )
!
! Multiply the HXC potential with unperturbed wfct's
!
CALL apply_dpot(v_siz, tg_psic, tg_dvrssc, 1)
!
! back-FFT to G-space
!
CALL cft_wave_tg(dvpsi, tg_psic, -1, v_siz, ibnd, nbnd_occ(ikk))
!
ELSE
!
! FFT to R-space
!
CALL cft_wave(evc(1,ibnd), revc, +1)
!
! Multiply the HXC potential with unperturbed wfct's
!
CALL apply_dpot(dffts%nnr, revc, dvrssc, current_spin)
!
! back-FFT to G-space
!
CALL cft_wave(dvpsi(1,ibnd), revc, -1)
!
ENDIF
!
ENDDO
!
dffts%have_task_groups = .FALSE.
!
! In the case of US pseudopotentials there is an additional term.
! See second part of Eq.(39) in J. Chem. Phys. 127, 164106 (2007)
!
IF (okvan) THEN
!
! Compute the integral of the perturbed potential with the Q function.
! Input : dvrsc = V_HXC(r)
! Output: int3 = \int conjg(V_HXC(r)) * Q_nm(r) dr
!
CALL newdq(dvrsc, 1)
!
CALL adddvscf(1, ik)
!
ENDIF
!
! Ortogonalize dvpsi to valence states.
! Apply -P_c, and then change the sign, because we need +P_c.
!
CALL orthogonalize(dvpsi, evq, ikk, ikq, dpsi, npwq)
dvpsi = -dvpsi
!
ENDIF
!
! 2) (H - E) * psi(k+q)
!
! Compute the kinetic energy g2kin: (k+q+G)^2
!
DO ig = 1, npwq
g2kin (ig) = ( (xk (1,ikq) + g (1, igkq(ig)) ) **2 + &
(xk (2,ikq) + g (2, igkq(ig)) ) **2 + &
(xk (3,ikq) + g (3, igkq(ig)) ) **2 ) * tpiba2
ENDDO
!
! Apply the operator ( H - \epsilon S + alpha_pv P_v) to evc1
! where alpha_pv = 0
!
!call ch_psi_all (npwq, evc1(1,1,ik), sevc1_new(1,1,ik), et(1,ikk), ik, nbnd_occ(ikk))
!
! Compute H*psi
!
IF (noncolin) THEN
IF (.NOT. ALLOCATED(psic_nc)) ALLOCATE(psic_nc(dfftp%nnr,npol))
!ELSE
! IF (.NOT. ALLOCATED(psic)) ALLOCATE(psic(dfftp%nnr))
ENDIF
!
IF (ntask_groups > 1) dffts%have_task_groups = .TRUE.
!
IF (dffts%have_task_groups) THEN
!
! With task groups we use the H*psi routine of PW parallelized on task groups
! (see PH/ch_psi_all.f90)
!
ALLOCATE(ibuf(npwx))
ibuf = igk
igk = igkq
CALL h_psi (npwx, npwq, nbnd_occ(ikk), evc1(:,:,ik), hpsi)
CALL s_psi (npwx, npwq, nbnd_occ(ikk), evc1(:,:,ik), spsi)
igk = ibuf
DEALLOCATE(ibuf)
!
ELSE
!
CALL h_psiq (npwx, npwq, nbnd_occ(ikk), evc1(:,:,ik), hpsi, spsi)
!
ENDIF
!
dffts%have_task_groups = .FALSE.
!
IF (noncolin) THEN
IF (ALLOCATED(psic_nc)) DEALLOCATE(psic_nc)
!ELSE
! IF (ALLOCATED(psic)) DEALLOCATE(psic)
ENDIF
!
! Subtract the eigenevalues H*psi(k+q) - et*psi(k+q)
!
DO ibnd = 1, nbnd_occ(ikk)
DO ig = 1, npwq
sevc1_new(ig,ibnd,ik) = hpsi(ig,ibnd) - &
& cmplx(et(ibnd,ikk),0.0d0,dp) * spsi(ig,ibnd)
ENDDO
ENDDO
!
IF (noncolin) THEN
DO ibnd = 1, nbnd_occ(ikk)
DO ig = 1, npwq
sevc1_new(ig+npwx,ibnd,ik) = hpsi(ig+npwx,ibnd) - &
cmplx(et(ibnd,ikk),0.0d0,dp) * spsi(ig+npwx,ibnd)
ENDDO
ENDDO
ENDIF
!
! 3) Sum up the two terms : (H - E)*psi(k+q) + HXC
!
IF (interaction1) THEN
!
DO ibnd = 1, nbnd_occ(ikk)
DO ig = 1, npwq
sevc1_new(ig,ibnd,ik) = sevc1_new(ig,ibnd,ik) + dvpsi(ig,ibnd)
ENDDO
ENDDO
!
IF (noncolin) THEN
DO ibnd = 1, nbnd_occ(ikk)
DO ig = 1, npwq
sevc1_new(ig+npwx,ibnd,ik) = sevc1_new(ig+npwx,ibnd,ik) + dvpsi(ig+npwx,ibnd)
ENDDO
ENDDO
ENDIF
!
ENDIF
!
! 4) Ultrasoft case: apply the S^{-1} operator.
! evc1_new = S^{-1} * sevc1_new
! If not ultrasoft: evc1_new = sevc1_new
!
CALL sm1_psi(.FALSE.,ik, npwx, npwq, nbnd_occ(ikk), sevc1_new(1,1,ik), evc1_new(1,1,ik))
!
ENDDO ! loop on ik
!
DEALLOCATE (dvrsc)
DEALLOCATE (dvrssc)
DEALLOCATE (hpsi)
DEALLOCATE (spsi)
DEALLOCATE (revc)
IF (ALLOCATED(psic)) DEALLOCATE(psic)
!
IF ( ntask_groups > 1) dffts%have_task_groups = .TRUE.
!
IF ( dffts%have_task_groups ) THEN
DEALLOCATE( tg_dvrssc )
DEALLOCATE( tg_psic )
ENDIF
!
dffts%have_task_groups = .FALSE.
!
IF (interaction1) CALL stop_clock('lr_apply_int')
IF (.NOT.interaction1) CALL stop_clock('lr_apply_no')
CALL stop_clock('lr_apply')
!
RETURN
!
CONTAINS
!-------------------------------------------------------------------------
SUBROUTINE lr_dv_of_drho_eels (dvscf)
!-----------------------------------------------------------------------
!
! This subroutine computes the change of the self consistent potential
! (Hartree and XC) due to the perturbation.
! Inspired by PH/dv_of_drho.f90
!
! Written by I. Timrov, Feb 2015
!
USE kinds, ONLY : DP
USE constants, ONLY : e2, fpi
USE fft_base, ONLY : dfftp
USE fft_interfaces, ONLY : fwfft, invfft
USE gvect, ONLY : nl, ngm, g, nlm
USE cell_base, ONLY : alat, tpiba2, omega
USE noncollin_module, ONLY : nspin_lsda, nspin_mag, nspin_gga
USE funct, ONLY : dft_is_gradient
USE scf, ONLY : rho, rho_core
USE eqv, ONLY : dmuxc
USE nlcc_ph, ONLY : nlcc_any
USE qpoint, ONLY : xq
USE gc_ph, ONLY : grho, dvxc_rr, dvxc_sr, dvxc_ss, dvxc_s
USE control_ph, ONLY : lrpa
USE control_flags, ONLY : gamma_only
USE lr_variables, ONLY : clfe !eps
IMPLICIT NONE
COMPLEX(DP), INTENT(inout):: dvscf(dfftp%nnr, nspin_mag)
! input: the change of the charge density
! output: the change of the HXC potential
INTEGER :: ir, is, is1, ig, ngm_, gstart
! counter on r vectors
! counter on spin polarizations
! counter on g vectors
! numver of G vectors to be considered
! initial starting G vector
REAL(DP) :: qg2, fac
! the modulus of (q+G)^2
! the structure factor
complex(DP), allocatable :: dvaux(:,:), drhoc(:)
! the change of the core charge
complex(DP), allocatable :: dvhart(:,:)
complex(DP), allocatable :: dvaux_mt(:), rgtot(:)
! auxiliary array for Martyna-Tuckerman correction in TDDFPT
! total response density
real(DP) :: eh_corr
! Correction to response Hartree energy due to Martyna-Tuckerman correction
! (only TDDFT). Not used.
CALL start_clock ('lr_dv_of_drho_eels')
!
ALLOCATE (dvaux(dfftp%nnr,nspin_mag))
dvaux(:,:) = (0.d0, 0.d0)
!
! 1) The exchange-correlation contribution is computed in real space.
!
IF (lrpa) goto 111
!
DO is = 1, nspin_mag
DO is1 = 1, nspin_mag
DO ir = 1, dfftp%nnr
dvaux(ir,is) = dvaux(ir,is) + dmuxc(ir,is,is1) * dvscf(ir,is1)
ENDDO
ENDDO
ENDDO
!
! Add a gradient correction to XC.
! If nlcc=.true. we need to add here its contribution.
! grho contains the core charge.
!
fac = 1.d0 / DBLE (nspin_lsda)
!
IF (nlcc_any) THEN
DO is = 1, nspin_lsda
rho%of_r(:, is) = rho%of_r(:, is) + fac * rho_core (:)
ENDDO
ENDIF
!
IF (dft_is_gradient()) CALL dgradcorr &
(rho%of_r, grho, dvxc_rr, dvxc_sr, dvxc_ss, dvxc_s, xq, &
dvscf, dfftp%nnr, nspin_mag, nspin_gga, nl, ngm, g, alat, dvaux)
!
IF (nlcc_any) THEN
DO is = 1, nspin_lsda
rho%of_r(:, is) = rho%of_r(:, is) - fac * rho_core (:)
ENDDO
ENDIF
!
111 CONTINUE
!
! Copy the total (up+down) delta rho in dvscf(*,1) and go to G-space
!
IF (nspin_mag == 2) THEN
dvscf(:,1) = dvscf(:,1) + dvscf(:,2)
ENDIF
!
CALL fwfft ('Dense', dvscf(:,1), dfftp)
!
! 2) The Hartree contribution is computed in reciprocal space.
!
! An extension to gamma_ionly case can be done from PH/dv_of_drho.f90
!
IF (gamma_only) CALL errore( 'lr_dv_of_drho_eels', 'gamma_only is not supported', 1 )
!
!IF (eps) THEN
! ! No G=0 term
! gstart = 2
!ELSE
! ! With G=0 term
! gstart = 1
!ENDIF
!
gstart = 1
!
IF (clfe) THEN
! All G vectors are considered
ngm_ = ngm
ELSE
! Only G=0 is considered
ngm_ = 1
ENDIF
!
!IF (eps .AND. .NOT.clfe) CALL errore( 'lr_dv_of_drho_eels', &
! & 'No Hartree term, because eps=.true. and clfe=.false.', 1 )
!
DO is = 1, nspin_lsda
!
! FFT from R-space to G-space.
!
CALL fwfft ('Dense', dvaux (:, is), dfftp)
!
DO ig = gstart, ngm_
!
qg2 = (g(1,ig)+xq(1))**2 + (g(2,ig)+xq(2))**2 + (g(3,ig)+xq(3))**2
!
! Hartree term: 4*pi*e2/|q+G|^2 * n'(G)
!
IF (qg2 > 1.d-8) THEN
dvaux(nl(ig),is) = dvaux(nl(ig),is) + &
e2 * fpi * dvscf(nl(ig),1) / (tpiba2 * qg2)
ENDIF
!
ENDDO
!
! back-FFT from G-space to R-space
!
CALL invfft ('Dense', dvaux (:, is), dfftp)
!
ENDDO
!
! At the end the two contributes are added
!
dvscf (:,:) = dvaux (:,:)
!
DEALLOCATE(dvaux)
!
CALL stop_clock ('lr_dv_of_drho_eels')
!
RETURN
!
END SUBROUTINE lr_dv_of_drho_eels
!
END SUBROUTINE lr_apply_liouvillian_eels
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.fortran-torture/execute/der_type.f90 | 191 | 1101 | ! Program to test derived types
program der_type
implicit none
type t1
integer, dimension (4, 5) :: a
integer :: s
end type
type my_type
character(20) :: c
type (t1), dimension (4, 3) :: ca
type (t1) :: r
end type
type init_type
integer :: i = 13
integer :: j = 14
end type
type (my_type) :: var
type (init_type) :: def_init
type (init_type) :: is_init = init_type (10, 11)
integer i;
if ((def_init%i .ne. 13) .or. (def_init%j .ne. 14)) call abort
if ((is_init%i .ne. 10) .or. (is_init%j .ne. 11)) call abort
! Passing a component as a parameter tests getting the addr of a component
call test_call(def_init%i)
var%c = "Hello World"
if (var%c .ne. "Hello World") call abort
var%r%a(:, :) = 0
var%ca(:, :)%s = 0
var%r%a(1, 1) = 42
var%r%a(4, 5) = 43
var%ca(:, :)%s = var%r%a(:, 1:5:2)
if (var%ca(1, 1)%s .ne. 42) call abort
if (var%ca(4, 3)%s .ne. 43) call abort
contains
subroutine test_call (p)
integer p
if (p .ne. 13) call abort
end subroutine
end program
| gpl-2.0 |
surhudm/scipy | scipy/sparse/linalg/eigen/arpack/ARPACK/SRC/dstats.f | 170 | 1166 | c
c\SCCS Information: @(#)
c FILE: stats.F SID: 2.1 DATE OF SID: 4/19/96 RELEASE: 2
c %---------------------------------------------%
c | Initialize statistic and timing information |
c | for symmetric Arnoldi code. |
c %---------------------------------------------%
subroutine dstats
c %--------------------------------%
c | See stat.doc for documentation |
c %--------------------------------%
include 'stat.h'
c %-----------------------%
c | Executable Statements |
c %-----------------------%
nopx = 0
nbx = 0
nrorth = 0
nitref = 0
nrstrt = 0
tsaupd = 0.0D+0
tsaup2 = 0.0D+0
tsaitr = 0.0D+0
tseigt = 0.0D+0
tsgets = 0.0D+0
tsapps = 0.0D+0
tsconv = 0.0D+0
titref = 0.0D+0
tgetv0 = 0.0D+0
trvec = 0.0D+0
c %----------------------------------------------------%
c | User time including reverse communication overhead |
c %----------------------------------------------------%
tmvopx = 0.0D+0
tmvbx = 0.0D+0
return
c
c End of dstats
c
end
| bsd-3-clause |
PUReIBM/PS3D | SRC/SHARED_MODULES/string_funcs.F90 | 1 | 9127 | !-------
! Independent module
!-------
! Some string manipulation functions
!-------
! Code: Steinli
! Author: Chidambaram Narayanan
! Nuclear Engineering Laboratory
! ETH Zurich
!-------
MODULE string_funcs
USE precision
Implicit none
Private
Public:: newfilename, upper_to_lower, lower_to_upper &
,positionnml, number_of_lines &
,append_integer_fixed, to_string
INTERFACE number_of_lines
MODULE PROCEDURE number_of_lines_unitno
MODULE PROCEDURE number_of_lines_filename
END INTERFACE
!-------
Contains
!-------
!----------
!----------
! To count the number of lines in a file given the UNIT number
! of the file.
!----------
!----------
FUNCTION number_of_lines_unitno(unitno)
Integer:: number_of_lines_unitno
Integer:: unitno
Integer:: count
Character:: c
count = 0
Do
Read(unitno,"(A)",END=101)c
count = count + 1
Enddo
101 Continue
number_of_lines_unitno = count
END FUNCTION number_of_lines_unitno
!----------
!----------
! To count the number of lines in a file given the name
! of the file.
!----------
!----------
FUNCTION number_of_lines_filename(filename)
Integer:: number_of_lines_filename
Character(LEN=*):: filename
Integer:: count, unitno
Character:: c
unitno = 102
open(unit=unitno,file=filename,form="formatted")
count = 0
Do
Read(unitno,"(A)",END=101)c
count = count + 1
Enddo
101 Continue
number_of_lines_filename = count
END FUNCTION number_of_lines_filename
!----------
!----------
! To position the file pointer to read a particular NAMELIST.
! Can be used to make an input file such that the order of
! the NAMELISTS can be arbitrary.
!----------
!----------
FUNCTION positionnml(unitno,nmlname)
Logical:: positionnml
Integer, Intent(in):: unitno
Character(LEN=*), Intent(in):: nmlname
Integer:: lengthnml, amppos
Character(LEN=80):: line
Character(LEN=LEN_TRIM(nmlname)+1):: nmlampstnd
nmlampstnd = "&"//nmlname
nmlampstnd = upper_to_lower(nmlampstnd)
lengthnml = LEN(nmlampstnd)
Rewind(unit=unitno)
DO
Read(unitno,'(A80)',END=999)line
line = upper_to_lower(line)
amppos = INDEX(line,nmlampstnd)
If (amppos.ne.0) then
BACKSPACE(unitno)
positionnml = .true.
Exit
Endif
ENDDO
Return
!-------
! the requested NAMELIST does not exist
!-------
999 positionnml = .false.
END FUNCTION positionnml
!----------
!----------
! To append an integer tag to a string template
! - preceeding zeros in the intergers are removed
! - the second integer is optional
! - a hyphen '-' is inserted between the two intergers
! - returns a string of length 80 => TRIM command is
! recommended by the calling routine.
!----------
!----------
FUNCTION newfilename(template,itnb,itne)
Character(LEN=80):: newfilename
Character(LEN=*), Intent(in):: template
Integer, Intent(in):: itnb
Integer, Intent(in), Optional:: itne
Integer:: i, j, tmp, ic, ipos
Integer:: sizeb, sizee, zero, tlen
Integer, Dimension(:), Allocatable:: strb, stre
newfilename(:) = " "
If (itnb.ne.0) then
sizeb = LOG10(REAL(itnb)) + 1
Else
sizeb = 1
Endif
allocate(strb(sizeb))
!-------
! split integer into array of integers
!-------
tmp = itnb
Do i = 1,sizeb
j = sizeb - i + 1
ic = MOD(tmp,10)
strb(j) = ic
tmp = tmp/10
Enddo
!-------
! create new file name
!-------
tlen = LEN_TRIM(template)
Do ipos = 1, tlen
newfilename(ipos:ipos) = template(ipos:ipos)
Enddo
!-------
! append the first iteration count
!-------
zero = IACHAR("0")
Do i = 1, sizeb
ipos = tlen + i
tmp = zero + strb(i)
newfilename(ipos:ipos) = ACHAR(tmp)
Enddo
!-------
! If ending integer is present
!-------
IF (PRESENT(itne)) then
If (itne.ne.0) then
sizee = LOG10(REAL(itne)) + 1
Else
sizee = 1
Endif
allocate(stre(sizee))
!-------
! split integer into array of integers
!-------
tmp = itne
Do i = 1,sizee
j = sizee - i + 1
ic = MOD(tmp,10)
stre(j) = ic
tmp = tmp/10
Enddo
!-------
! append a dash
!-------
ipos = ipos+1
newfilename(ipos:ipos) = "-"
!-------
! append the second iteration count
!-------
Do i = 1, sizee
ipos = ipos + 1
tmp = zero + stre(i)
newfilename(ipos:ipos) = ACHAR(tmp)
Enddo
ENDIF
END FUNCTION newfilename
!----------
!----------
! To append an integer tag to a string template
! - fixed string size given by ndigits.
! - returns a string of length 80 => TRIM command is
! recommended by the calling routine.
!----------
!----------
FUNCTION append_integer_fixed(template,intval,ndigits)
Character(LEN=80):: append_integer_fixed
Character(LEN=*), Intent(in):: template
Integer, Intent(in):: intval, ndigits
Integer:: i, j, tmp, ic, ipos, size_int
Integer:: zero, tlen
Integer, Dimension(ndigits):: isuffix
Integer, Dimension(:), Allocatable:: str_int
append_integer_fixed(:) = " "
If (intval.ne.0) then
size_int = LOG10(REAL(intval)) + 1
Else
size_int = 1
Endif
Allocate(str_int(size_int))
!-------
! split integer into array of integers
!-------
tmp = intval
Do i = 1,size_int
j = size_int - i + 1
ic = MOD(tmp,10)
str_int(j) = ic
tmp = tmp/10
Enddo
isuffix(:) = 0
Do i = 1,size_int
isuffix(ndigits-size_int+i) = str_int(i)
Enddo
!-------
! create new file name
!-------
tlen = LEN_TRIM(template)
Do ipos = 1, tlen
append_integer_fixed(ipos:ipos) = template(ipos:ipos)
Enddo
!-------
! append the integer
!-------
zero = IACHAR("0")
Do i = 1, ndigits
ipos = tlen + i
tmp = zero + isuffix(i)
append_integer_fixed(ipos:ipos) = ACHAR(tmp)
Enddo
END FUNCTION append_integer_fixed
!----------
!----------
! To convert a string from upper to lower case
! - leaves non-alphabet elements unchanged
! - returns a string of length 80 => TRIM command is
! recommended for the calling routine.
!----------
!----------
FUNCTION upper_to_lower(string)
Character(LEN=80):: upper_to_lower
Character(LEN=*):: string
Integer:: i, strlen
Integer, parameter:: aAdiff = IACHAR("a")-IACHAR("A")
strlen = LEN_TRIM(string)
Do i = 1,strlen
if ("A" <= string(i:i) .AND. string(i:i) <= "Z") then
upper_to_lower(i:i) = ACHAR(IACHAR(string(i:i)) + aAdiff)
else
upper_to_lower(i:i) = string(i:i)
endif
Enddo
upper_to_lower(strlen+1:) = " "
END FUNCTION upper_to_lower
!----------
!----------
! To convert a string from lower to upper case
! - leaves non-alphabet elements unchanged
! - returns a string of length 80 => TRIM command is
! recommended for the calling routine.
! - January 14, 2002
! (** not tested **)
!----------
!----------
FUNCTION lower_to_upper(string)
Character(LEN=80):: lower_to_upper
Character(LEN=*):: string
Integer:: i, strlen
Integer, parameter:: aAdiff = IACHAR("a")-IACHAR("A")
strlen = LEN_TRIM(string)
Do i = 1,strlen
if ("a" <= string(i:i) .AND. string(i:i) <= "z") then
lower_to_upper(i:i) = ACHAR(IACHAR(string(i:i)) - aAdiff)
else
lower_to_upper(i:i) = string(i:i)
endif
Enddo
lower_to_upper(strlen+1:) = " "
END FUNCTION lower_to_upper
SUBROUTINE to_string(number, string, size)
IMPLICIT NONE
INTEGER number
CHARACTER *(*) string
INTEGER size
CHARACTER*100 temp
INTEGER local
INTEGER last_digit
INTEGER i
local = number
i = 0
DO
last_digit = MOD(local,10)
local = local/10
i = i + 1
temp(i:i) = CHAR(last_digit + ICHAR('0'))
IF (local==0) EXIT
ENDDO
size = i
do i = 1, size
string(size-i+1:size-i+1) = temp(i:i)
ENDDO
END SUBROUTINE to_string
INTEGER FUNCTION string_len(string)
CHARACTER*(*) string
CHARACTER*1 space
PARAMETER (space = ' ')
INTEGER i
i = LEN(string)
DO
IF ((string(i:i).eq.space).and.(i.gt.1)) THEN
i = i - 1
ELSE
EXIT
ENDIF
ENDDO
IF ((i.eq.1).and.(string(i:i).eq.space)) THEN
string_len = 0
ELSE
string_len = i
ENDIF
END FUNCTION string_len
END MODULE string_funcs
!-------
!PROGRAM teststrings
! Use string_funcs
!
! Integer:: i1, i2
! Character(LEN=20):: template
!
! i1 = 10; i2 = 12
! template="evals"
! write(*,*)TRIM(newfilename(template,i1,i2))
! write(*,*)TRIM(newfilename(template,i1))
!END PROGRAM teststrings
!-------
!-------
! List of functions
!-------
! o Function positionnml
! o Function newfilename
! o Function upper_to_lower
! o Function lower_to_upper
!-------
| gpl-3.0 |
kito-cheng/riscv-gcc | gcc/testsuite/gfortran.dg/assumed_rank_bounds_1.f90 | 19 | 4914 | ! { dg-do run }
!
! Test the behavior of lbound, ubound of shape with assumed rank arguments
! in an array context (without DIM argument).
!
program test
integer :: a(2:4,-2:5)
integer, allocatable :: b(:,:)
integer, pointer :: c(:,:)
character(52) :: buffer
call foo(a)
allocate(b(2:4,-2:5))
call foo(b)
call bar(b)
allocate(c(2:4,-2:5))
call foo(c)
call baz(c)
contains
subroutine foo(arg)
integer :: arg(..)
!print *, lbound(arg)
!print *, id(lbound(arg))
if (any(lbound(arg) /= [1, 1])) STOP 1
if (any(id(lbound(arg)) /= [1, 1])) STOP 2
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) lbound(arg)
if (buffer /= ' 1 1') STOP 3
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(lbound(arg))
if (buffer /= ' 1 1') STOP 4
!print *, ubound(arg)
!print *, id(ubound(arg))
if (any(ubound(arg) /= [3, 8])) STOP 5
if (any(id(ubound(arg)) /= [3, 8])) STOP 6
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) ubound(arg)
if (buffer /= ' 3 8') STOP 7
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(ubound(arg))
if (buffer /= ' 3 8') STOP 8
!print *, shape(arg)
!print *, id(shape(arg))
if (any(shape(arg) /= [3, 8])) STOP 9
if (any(id(shape(arg)) /= [3, 8])) STOP 10
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) shape(arg)
if (buffer /= ' 3 8') STOP 11
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(shape(arg))
if (buffer /= ' 3 8') STOP 12
end subroutine foo
subroutine bar(arg)
integer, allocatable :: arg(:,:)
!print *, lbound(arg)
!print *, id(lbound(arg))
if (any(lbound(arg) /= [2, -2])) STOP 13
if (any(id(lbound(arg)) /= [2, -2])) STOP 14
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) lbound(arg)
if (buffer /= ' 2 -2') STOP 15
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(lbound(arg))
if (buffer /= ' 2 -2') STOP 16
!print *, ubound(arg)
!print *, id(ubound(arg))
if (any(ubound(arg) /= [4, 5])) STOP 17
if (any(id(ubound(arg)) /= [4, 5])) STOP 18
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) ubound(arg)
if (buffer /= ' 4 5') STOP 19
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(ubound(arg))
if (buffer /= ' 4 5') STOP 20
!print *, shape(arg)
!print *, id(shape(arg))
if (any(shape(arg) /= [3, 8])) STOP 21
if (any(id(shape(arg)) /= [3, 8])) STOP 22
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) shape(arg)
if (buffer /= ' 3 8') STOP 23
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(shape(arg))
if (buffer /= ' 3 8') STOP 24
end subroutine bar
subroutine baz(arg)
integer, pointer :: arg(..)
!print *, lbound(arg)
!print *, id(lbound(arg))
if (any(lbound(arg) /= [2, -2])) STOP 25
if (any(id(lbound(arg)) /= [2, -2])) STOP 26
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) lbound(arg)
if (buffer /= ' 2 -2') STOP 27
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(lbound(arg))
if (buffer /= ' 2 -2') STOP 28
!print *, ubound(arg)
!print *, id(ubound(arg))
if (any(ubound(arg) /= [4, 5])) STOP 29
if (any(id(ubound(arg)) /= [4, 5])) STOP 30
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) ubound(arg)
if (buffer /= ' 4 5') STOP 31
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(ubound(arg))
if (buffer /= ' 4 5') STOP 32
!print *, shape(arg)
!print *, id(shape(arg))
if (any(shape(arg) /= [3, 8])) STOP 33
if (any(id(shape(arg)) /= [3, 8])) STOP 34
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) shape(arg)
if (buffer /= ' 3 8') STOP 35
buffer = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
write(buffer,*) id(shape(arg))
if (buffer /= ' 3 8') STOP 36
end subroutine baz
elemental function id(arg)
integer, intent(in) :: arg
integer :: id
id = arg
end function id
end program test
| gpl-2.0 |
rhristov/gcc-modified | gcc/testsuite/gfortran.dg/g77/short.f | 166 | 1328 | c { dg-do run }
c { dg-options "-std=legacy" }
c
program short
parameter ( N=2 )
common /chb/ pi,sig(0:N)
common /parm/ h(2,2)
c initialize some variables
h(2,2) = 1117
h(2,1) = 1178
h(1,2) = 1568
h(1,1) = 1621
sig(0) = -1.
sig(1) = 0.
sig(2) = 1.
call printout
stop
end
c ******************************************************************
subroutine printout
parameter ( N=2 )
common /chb/ pi,sig(0:N)
common /parm/ h(2,2)
dimension yzin1(0:N), yzin2(0:N)
c function subprograms
z(i,j,k) = 0.5*h(i,j)*(sig(k)-1.)
c a four-way average of rhobar
do 260 k=0,N
yzin1(k) = 0.25 *
& ( z(2,2,k) + z(1,2,k) +
& z(2,1,k) + z(1,1,k) )
260 continue
c another four-way average of rhobar
do 270 k=0,N
rtmp1 = z(2,2,k)
rtmp2 = z(1,2,k)
rtmp3 = z(2,1,k)
rtmp4 = z(1,1,k)
yzin2(k) = 0.25 *
& ( rtmp1 + rtmp2 + rtmp3 + rtmp4 )
270 continue
do k=0,N
if (yzin1(k) .ne. yzin2(k)) call abort
enddo
if (yzin1(0) .ne. -1371.) call abort
if (yzin1(1) .ne. -685.5) call abort
if (yzin1(2) .ne. 0.) call abort
return
end
| gpl-2.0 |
nvarini/espresso_adios | atomic/src/elsdps_paw.f90 | 15 | 3050 | !
! Copyright (C) 2007 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!
!---------------------------------------------------------------
subroutine elsdps_paw( )
!---------------------------------------------------------------
!
! total paw energy in the local-spin-density scheme
!
use kinds, only: DP
use constants, only: fpi
use radial_grids, only : ndmx
use ld1_parameters, only : nwfsx
use ld1inc, only : nlcc, grid, nspin, rhoc, lsd, &
encl, ehrt, ecxc, evxt, ekin, ecc, epseu, &
nwfts, enlts, octs, paw_energy
use funct, only : dft_is_gradient
implicit none
real(DP) :: &
excc, vxcc(2), & ! exch-corr energy from core charge
int_0_inf_dr, & ! the integral function
rh0(2), & ! the charge in a given point
rhc, & ! core charge in a given point
edcts ! auxiliary energy
real(DP),allocatable :: &
vgc(:,:), & ! the gga potential
egc(:), & ! the gga energy
rho_aux(:,:), & ! auxiliary space
exccc(:) ! the exchange and correlation energy of the core
REAL(dp) :: & ! compatibility with metaGGA - not yet used
tau(ndmx) = 0.0_dp, vtau(ndmx) = 0.0_dp
integer :: &
i,ns,ierr
!
! If there is NLCC we calculate here also the exchange and correlation
! energy of the pseudo core charge.
! This quantity is printed but not added to the total energy
!
ecc=0.0_DP
if (nlcc) then
allocate(exccc(ndmx), stat=ierr)
exccc=0.0_DP
rh0(1)=0.0_DP
rh0(2)=0.0_DP
do i=1,grid%mesh
rhc= rhoc(i)/grid%r2(i)/fpi
call vxc_t(lsd,rh0,rhc,excc,vxcc)
exccc(i) = excc*rhoc(i)
enddo
if (dft_is_gradient()) then
allocate(rho_aux(ndmx,2), stat=ierr)
allocate(vgc(ndmx,2),stat=ierr)
allocate(egc(ndmx),stat=ierr)
vgc=0.0_DP
egc=0.0_DP
rho_aux=0.0_DP
call vxcgc ( ndmx, grid%mesh, nspin, grid%r, grid%r2, rho_aux, &
rhoc, vgc, egc, tau, vtau, 1)
do i=1,grid%mesh
exccc(i) = exccc(i) + egc(i)*fpi*grid%r2(i)
enddo
deallocate(egc)
deallocate(vgc)
deallocate(rho_aux)
endif
ecc= int_0_inf_dr(exccc,grid,grid%mesh,2)
deallocate(exccc)
endif
!
! Add the three contributions for each energy
!
encl= paw_energy(5,1)+paw_energy(5,2)-paw_energy(5,3)
ehrt= paw_energy(2,1)+paw_energy(2,2)-paw_energy(2,3)
ecxc= paw_energy(3,1)+paw_energy(3,2)-paw_energy(3,3)
edcts= paw_energy(4,1)+paw_energy(4,2)-paw_energy(4,3)
!
! The nonlocal pseudopotential energy is not computed.
!
epseu=0.0_DP
!
! Now compute the kinetic energy
!
ekin = -encl-edcts
do ns=1,nwfts
if (octs(ns) > 0.0_DP) then
ekin=ekin+octs(ns)*enlts(ns)
endif
end do
return
end subroutine elsdps_paw
| gpl-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.