!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software 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 above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
***S/P DIFVEF
*

      SUBROUTINE DIFVEF(D,F,SD,CON,NK,MAX)
*
#include "impnone.cdk"
      INTEGER NK, MAX
      REAL D(MAX,2),F(NK),SD(NK),CON
*
*Author
*          J. Cote (RPN 1983)
*
*Revision
* 001      J. Cote RPN(Nov 1984)SEF version documentation
* 002      M. Lepine  -  RFE model code revision project (Jan87)
*
*Object
*          to prepare the finite-element vertical diffusion operator
*
*Arguments
*
*          - Output -
* D        vertical diffusion E-F operator (MAX,2)
*          D(*,1) lower diagonal
*          D(*,2) diagonal
*
*          - Input -
* F        vertical diffusion coefficient
* SD       sigma intervals
* CON      multiplicative constant
* NK       vertical dimension
* MAX      1st dimension of D
*
*Notes
*          Must have NK <= MAX and NK <= 64
*
**
*
      REAL SC
      INTEGER K
*
      IF (NK.GT.MAX.OR.NK.GT.64) THEN
         WRITE (6,*) 'NK = ',NK,' MAX = ',MAX,' STOP DANS DIFVEF'
         STOP
      ENDIF
      SC=CON/2.0
      D(1,1)=0.0
*
CDIR$ SHORTLOOP
*VDIR LOOPCNT=64
      DO 1 K=2,NK
*
         D(K,1)=SC*(F(K-1)+F(K))/SD(K-1)
    1    D(K-1,2)=-(D(K-1,1)+D(K,1))
*
      D(NK,2)=-D(NK,1)
*
      RETURN
      END