SUBROUTINE difcof(lmh,gm,gh,el,q2,z,akm,akh)
  !
  ! $Author: CPTEC $
  ! $Date: 2000/02/24 13:15:43 $
  ! $Revision: 1.0 $
  !
  !    level 2.5 diffusion coefficients
  !
  IMPLICIT NONE
  INCLUDE "parmeta.f90"
  INTEGER, PARAMETER :: lp1=lm+1, lm1=lm-1

  INTEGER, DIMENSION(im,jm    ), INTENT(IN ) :: lmh
  REAL   , DIMENSION(im,jm,lm1), INTENT(IN ) :: gm
  REAL   , DIMENSION(im,jm,lm1), INTENT(IN ) :: gh
  REAL   , DIMENSION(im,jm,lm1), INTENT(IN ) :: el
  REAL   , DIMENSION(im,jm,lm ), INTENT(IN ) :: q2
  REAL   , DIMENSION(0:im+1,0:jm+1,lp1), INTENT(IN ) :: z
  REAL   , DIMENSION(0:im+1,0:jm+1,lm1), INTENT(OUT) :: akm
  REAL   , DIMENSION(im,jm,lm1), INTENT(OUT) :: akh

  REAL, PARAMETER :: g=9.8
  REAL, PARAMETER :: beta=1./270.
  REAL, PARAMETER :: btg=beta*g
  REAL, PARAMETER :: prt=1.0
  REAL, PARAMETER :: gam1=0.2222222222222222222
  REAL, PARAMETER :: a1=0.659888514560862645
  REAL, PARAMETER :: a2=0.6574209922667784586
  REAL, PARAMETER :: b1=11.87799326209552761
  REAL, PARAMETER :: b2=7.226971804046074028
  REAL, PARAMETER :: c1=0.000830955950095854396

  !*** coefficients for the sm and sh determinants

  REAL, PARAMETER :: bsmh=-3.*a1*a2*(3.*a2+3.*b2*c1+12.*a1*c1-b2)*btg
  REAL, PARAMETER :: cesm=    a1*(1.-3.*c1)

  REAL, PARAMETER :: bshm=18.*a1*a1*a2*c1
  REAL, PARAMETER :: bshh= 9.*a1*a2*a2*btg
  REAL, PARAMETER :: cesh=    a2

  !*** coefficients of the terms in the denominator

  REAL, PARAMETER :: adnm=18.*a1*a1*a2*(b2-3.*a2)*btg
  REAL, PARAMETER :: adnh= 9.*a1*a2*a2*(12.*a1+3.*b2)*btg*btg
  REAL, PARAMETER :: bdnm= 6.*a1*a1
  REAL, PARAMETER :: bdnh= 3.*a2*(7.*a1+b2)*btg

  INTEGER :: i, j, l
  REAL    :: eloq2, eloq4
  REAL    :: aden, bden, cden, besm, besh, rden, esm, esh, rdz, q1l, elqdz


  DO l=1,lm
     DO j = 3, jm-2
        DO i = 1, im
           IF (l <= lmh(i,j)-1) THEN
              eloq2=el(i,j,l)*el(i,j,l)/q2(i,j,l)
              eloq4=eloq2*eloq2

              !*** coefficients of the terms in the denominator

              aden=(adnm*gm(i,j,l)+adnh*gh(i,j,l))*gh(i,j,l)
              bden= bdnm*gm(i,j,l)+bdnh*gh(i,j,l)
              cden= 1.

              !*** coefficients for the sm determinant

              besm=bsmh*gh(i,j,l)

              !*** coefficients for the sh determinant

              besh=bshm*gm(i,j,l)+bshh*gh(i,j,l)

              !*** 1./denominator

              rden=1./(aden*eloq4+bden*eloq2+cden)

              !*** sm and sh

              esm=(besm*eloq2+cesm)*rden
              esh=(besh*eloq2+cesh)*rden

              !*** diffusion coefficients

              rdz=2./(z(i,j,l)-z(i,j,l+2))
              q1l=SQRT(q2(i,j,l))
              elqdz=el(i,j,l)*q1l*rdz
              akm(i,j,l)=elqdz*esm
              akh(i,j,l)=elqdz*esh
           END IF
        END DO
     END DO
  END DO
END SUBROUTINE difcof
