c23456789012345678901234567890123456789012345678901234567890123456789012


      REAL*8 FUNCTION conse_m(opt,i,j,k) 

c     ******************************************************************
c
c     This routine calculates quantities from mass conservation 
c
c     ******************************************************************

c     -------------
c     Declarations
c     -------------

c     ''''''''''''''''''''''
      implicit none
      include 'commonvar.f'      
c     ''''''''''''''''''''''

c---- Argument variables

      character opt*1

      integer	i,j,k




c     -------------------------------------------------------------------
c     Computing transport component W at box top or mass residual for box 
c     -------------------------------------------------------------------

c---- Transport component W at top of grid box (i,j,k)

c++
      if (opt.eq.'W') then
c++

      conse_m = -(-V(i  ,j  ,k)
     >		  +U(i+1,j  ,k)
     >		  +V(i  ,j+1,k)
     >		  -U(i  ,j  ,k)
     >		  -W(i  ,j  ,k))

c++
      endif
c++


c---- Residual for grid box (i,j,k)

c++
      if (opt.eq.'R') then
c++

      conse_m = -V(i  ,j  ,k  )
     >          +U(i+1,j  ,k  )
     >          +V(i  ,j+1,k  )
     >          -U(i  ,j  ,k  )
     >          -W(i  ,j  ,k  )
     >          +W(i  ,j  ,k+1)

c++
      endif
c++




c     --------------------
c     End of the function
c     --------------------

      return

      end

c     ******************************************************************
