!-------------------------------------- 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 --------------------------------------
!

      subroutine ltt2phi_inmi(pgz,ptt,kni,knj,knk) 3
#if defined (DOC)
*
***s/r ltt2phi_inmi  - Grid-point computation of TL geopotential from Temperature.
*                      (ref.: Temperton & Roch 1991, (2.6) )
*
*Author  : L. Fillion *ARMA/AES  7 May 2007.
*     .
*Revision: L. Fillion *ARMA/EC 7 Nov 2008 - Cosmetic changes.
*
**
*Arguments
*     in-
*   ptt    : 3D Temperature Incr. appearing on r.h.s. of TL-eq.
*   ppsg   : Basic-state Surface-pressure
*     out-
*   pgz    : 3D GZ fields computed from TL-Hydrostatic equation
#endif
C
      IMPLICIT NONE
#include "taglam4d.cdk"
#include "pardim.cdk"
#include "comcst.cdk"
#include "comdim.cdk"
#include "comlun.cdk"
#include "comgem.cdk"
#include "comgrd_param.cdk"
*
      integer kni,knj,knk
      real*8 pgz(kni,knk,knj), ptt(kni,knk,knj)
*
      logical llprint
      integer ji,jj,jk
      real*8 ztt(kni,knk,knj)
      real*8 zvlev(knk),zfac(knk)
*------------------------------------------------------------------
**
!      WRITE(NULOUT,FMT='(/,4X,"Starting LTT2PHI_INMI",//)')
!      call vflush(nulout)
!
      do jk = 1,knk
        zvlev(jk) = vlev(jk)
      enddo
!
      if(vlev(1).eq.0.) then
        zvlev(1) = 0.5*vlev(2)
      endif
!
      do jk = 1,knk
        zfac(jk) = 0.5*rd*log(zvlev(jk)/zvlev(jk-1))
      enddo
!
      pgz(:,:,:) = 0.0
!
      do ji=1,kni
      do jj=1,knj
        do jk=knk,2,-1
          pgz(ji,jk-1,jj) = pgz(ji,jk,jj)
     &        + zfac(jk)*(ptt(ji,jk,jj)+ptt(ji,jk-1,jj))
        enddo
      enddo
      enddo
c
      return
      end