!=================================================================
!  subroutine EMONIT: for calculation of kinetic energy production
!                     and dissipation terms 
!
!  2001/01/16 M. Odaka
!=================================================================
      subroutine EMONIT
     I  (  U    , V    , W    , 
     I     DUVIS, DVVIS, DWVIS,
     I     DUNLV, DVNLV, DWNLV,
     I     DUFRIC,DVFRIC,
     I     BUOY , 
     I     IT1  , IT2  ,
     O     EKVIS, EKNLV, EKBUOY,
     B     DENS0, FDZ  , FDZM  , 
     G     DX   ,  
     D     NX   , NXB  , NZ    , NZB, NROT )

!-----------------------------------------------------------------      
      implicit real*8 ( a-h,o-z )
!-----------------------------------------------------------------      

      dimension
     \     U ( -2:NXB, -2:NZB, NROT ),
     \     V ( -2:NXB, -2:NZB, NROT ),
     \     W ( -2:NXB, -2:NZB, NROT )

      dimension
     \     DUVIS ( -2:NXB, -2:NZB ), DUNLV ( -2:NXB, -2:NZB ),
     \     DVVIS ( -2:NXB, -2:NZB ), DVNLV ( -2:NXB, -2:NZB ),
     \     DWVIS ( -2:NXB, -2:NZB ), DWNLV ( -2:NXB, -2:NZB ),
     \     BUOY  ( -2:NXB, -2:NZB )

      dimension
     \     DUFRIC ( -2:NXB,2 )     , DVFRIC( -2:NXB,2 )

      dimension
     \     DENS0 ( -2:NZB ), FDZ ( -2:NZB ), FDZM ( -2:NZB )

      dimension
     \     EKVIS ( -2:NXB, -2:NZB ),
     \     EKNLV ( -2:NXB, -2:NZB ),
     \     EKBUOY( -2:NXB, -2:NZB )

!-----------------------------------------------------------------      
!     Kinetic energy dissipation due to viscosity.
!-----------------------------------------------------------------      

      do IZ = 0, NZ-1
         DMZ = FDZ(IZ) * DX**2 * DENS0(IZ)
         do IX = 1, NX
            EKVIS(IX,IZ) = DMZ * (   U(IX,IZ,IT2) * DUVIS(IX,IZ)
     \              + V(IX,IZ,IT2) * DVVIS(IX,IZ) )
         end do
      end do

      do IZ = 1, NZ-1
         DMZ = FDZM(IZ)* DX**2 * (DENS0(IZ)+DENS0(IZ-1))/2.0D0
         do IX = 1, NX
            EKVIS(IX,IZ) = EKVIS(IX,IZ) + 
     \           DMZ * W(IX,IZ,IT2) * DWVIS(IX,IZ)
         end do
      end do

      do IX = 1, NX
         EKVIS(IX,0) = EKVIS(IX,0) + 
     \    DX**2 *
     \    (  FDZ(0) * DENS0(0)
     \     * (   U(IX,0,IT2)*DUFRIC(IX,1) 
     \         + V(IX,0,IT2)*DVFRIC(IX,1) ) )

         EKVIS(IX,NZ-1) = EKVIS(IX,NZ-1) + 
     \    DX**2 *
     \    (  FDZ(NZ-1) * DENS0(NZ-1)
     \     * (   U(IX,NZ-1,IT2)*DUFRIC(IX,2)
     \         + V(IX,NZ-1,IT2)*DVFRIC(IX,2) ) )
      end do

      CALL BOUND( EKVIS, NX, NZ, NXB, NZB, 1, 1, 1, 1 )

!-----------------------------------------------------------------
!     Kinetic energy dissipation due to computational viscosity.
!----------------------------------------------------------------- 

      do IZ = 0, NZ-1
         DMZ = FDZ(IZ) * DX**2 * DENS0(IZ)
         do IX = 1, NX
            EKNLV(IX,IZ) = 
     \           DMZ * (   U(IX,IZ,IT2) * DUNLV(IX,IZ)
     \           + V(IX,IZ,IT2) * DVNLV(IX,IZ) )
         end do
      end do
            
      do IZ = 1, NZ-1
         DMZ = FDZM(IZ)* DX**2 * (DENS0(IZ)+DENS0(IZ-1))/2.0D0
         do IX = 1, NX
            EKNLV(IX,IZ) = EKNLV(IX,IZ) +
     \           DMZ * W(IX,IZ,IT2) * DWNLV(IX,IZ)
         end do
      end do

      CALL BOUND ( EKNLV, NX, NZ, NXB, NZB, 1, 1, 1, 1 )

!-----------------------------------------------------------------
!     Conversion from Thermal energy to Kinetic energy 
!----------------------------------------------------------------- 

      do IZ = 1, NZ-1
         DMZT = FDZM(IZ) * DX**2 * (DENS0(IZ)+DENS0(IZ-1)) / 2.0D0
         do IX = 1, NX
            EKBUOY(IX,IZ) = BUOY(IX,IZ) * W(IX,IZ,IT1) * DMZT
         end do
      end do

      CALL BOUND ( EKBUOY , NX, NZ, NXB, NZB, 1, -1, 0, 1 )

      return
      end


