SUBROUTINE pdte
  !
  ! $Author: CPTEC $
  ! $Date: 2000/02/24 13:15:43 $
  ! $Revision: 1.0 $
  !
  !                .      .    .     
  ! subprogram:    pdte        surface pressure tendency calc
  !   prgrmmr: janjic          org: w/np2      date: 94-03-08       
  !     
  ! abstract:
  !     pdte vertically integrates the mass flux divergence to
  !     obtain the surface pressure tendency and etadot on the
  !     layer interfaces.
  !     
  ! program history log:
  !   87-06-??  janjic     - originator
  !   95-03-25  black      - conversion from 1-d to 2-d in horizontal
  !   95-11-20  abeles     - parallel optimization
  !   96-03-29  black      - removed scrch
  !     
  ! usage: call pdte from main program ebu
  !   input argument list:
  !       none     
  !  
  !   output argument list: 
  !     none
  !     
  !   output files:
  !     none
  !     
  !   subprograms called:
  !  
  !     unique: none
  !  
  !     library: none
  !  
  !   common blocks: ctlblk
  !                  masks
  !                  dynam
  !                  vrbls
  !   
  IMPLICIT NONE

  !*** problem size

  INCLUDE "parmeta.f90"
  INTEGER, PARAMETER :: jam=6+2*(jm-10)
  INTEGER, PARAMETER :: lm1=lm-1
  INTEGER, PARAMETER :: lp1=lm+1

  !*** global variables

  INCLUDE "masks.f90"   ! htm(in)
  INCLUDE "dynam.f90"   ! eta(in); eft4(in)
  INCLUDE "vrbls.f90"   ! res(in); t(inout)
  INCLUDE "contin.f90"  ! div(inout); psdt(out); pdsl(in); 
  ! etadt(out); omgalf(inout); rtop(in)

  !*** local variables

  REAL, PARAMETER :: h1=1.0
  REAL, DIMENSION (im,jm):: pret
  REAL, DIMENSION (im,jm):: rpsl
  INTEGER                :: i, j, l

  !*** computation of pressure tendency & preparations

  DO  l=2,lm
     DO j=1,jm-2
        DO i=1,im
           div(i,j,l)=div(i,j,l-1)+div(i,j,l)
        END DO
     END DO
  END DO
  DO j=3,jm-2
     DO i=1,im
        psdt(i,j)=-div(i,j,lm)
        pret(i,j)=psdt(i,j)*res(i,j)
        rpsl(i,j)=h1/pdsl(i,j)
     END DO
  END DO

  !*** computation of etadt

  DO l=1,lm1
     DO j=3,jm-2
        DO i=1,im
           etadt(i,j,l)=-(pret(i,j)*eta(l+1)+div(i,j,l)) &
                *htm(i,j,l+1)*rpsl(i,j)
        END DO
     END DO
  END DO

  !*** kinetic energy generation terms in t equation

  DO j=3,jm-2
     DO i=1,im
        omgalf(i,j,1)=omgalf(i,j,1)-div(i,j,1)*rtop(i,j,1)*ef4t
        t(i,j,1)=t(i,j,1)-div(i,j,1)*rtop(i,j,1)*ef4t
     END DO
  END DO
  DO l=2,lm1
     DO j=3,jm-2
        DO i=1,im
           omgalf(i,j,l)=omgalf(i,j,l)-(div(i,j,l-1)+div(i,j,l)) &
                *rtop(i,j,l)*ef4t
           t(i,j,l)=t(i,j,l)-(div(i,j,l-1)+div(i,j,l))*rtop(i,j,l)*ef4t
        END DO
     END DO
  END DO
  DO j=3,jm-2
     DO i=1,im
        omgalf(i,j,lm)=omgalf(i,j,lm)+(pret(i,j)-div(i,j,lm1))&
             *rtop(i,j,lm)*ef4t
        t(i,j,lm)=t(i,j,lm)+(pret(i,j)-div(i,j,lm1))*rtop(i,j,lm)*ef4t
     END DO
  END DO
END SUBROUTINE pdte
