      subroutine forceWCfn(ngrid,nq,pplev,pt,dq,dqs)

      USE tracer_h

      implicit none

!==================================================================
!     
!     Purpose
!     -------
!     Force tracer conservation in a column for a given pair of 
!     delta q, delta q_s
!
!     Authors
!     ------- 
!     R. Wordsworth
!     
!==================================================================

#include "dimensions.h"
#include "dimphys.h"
#include "comcstfi.h"

      INTEGER ngrid,nq

      real masse, Wtot, Wdiff

      real pplev(ngrid,nlayermx+1)
      real pt(ngrid)

      real dqs(ngrid,nq) 
      real dq(ngrid,nlayermx,nq)

      integer iq, ig, ilay

      do iq=1,nq 
        do ig=1,ngrid
           Wtot = 0.0
           do ilay=1,nlayermx
              masse = (pplev(ig,ilay) - pplev(ig,ilay+1))/g
              Wtot  = Wtot + masse*dq(ig,ilay,iq)
           enddo
           Wdiff = Wtot + dqs(ig,iq)
         
           dqs(ig,iq) = dqs(ig,iq) - Wdiff
        enddo
      enddo

      end 

