      subroutine advectbg

      include'mladv.inc'

      common/parm/kz,m,mm1,mm2,mp1,msq,tim,tmax,tstart,hy,rea,dt,
     +   xbasin,yy(mx0),icalc,kzp1,kzm1,iftop,ifbot,iftvv,ifrel,theta,
     +   ifsbl,ifeva

      dimension f(mnmax,lmax)

      do 10 ip=1,msq
         do 20 k=1,l 
            f(ip,k) = bqgofk(ip,k) + buoy(ip,k,mlcur)
  20      continue
  10   continue
 
      call advbg(f,bzero)
 
      do 30 ip=1,msq
         do 40 k=1,l
            buoy(ip,k,mlcur) = f(ip,k) - bqgofk(ip,k)
  40      continue
  30   continue


      do 50 ip=1,msq 
         do 60 k=1,l  
            f(ip,k) = tqgofk(ip,k) + temp(ip,k,mlcur) 
  60      continue 
  50   continue 
  
      call advbg(f,bzero) 
  
      do 70 ip=1,msq 
         do 80 k=1,l 
            temp(ip,k,mlcur) = f(ip,k) - tqgofk(ip,k) 
  80      continue 
  70   continue 


      do 150 itrace=1,ntrace

         icurtrace=itrace

         do 135 ip=1,msq
            do 125 k=1,l
               f(ip,k) = trcqgofk(ip,k) + trace(ip,k,mlcur,itrace)
  125        continue
  135     continue

         call advbg(f,bzero)

         do 155 ip=1,msq
            do 145 k=1,l
               trace(ip,k,mlcur,itrace) = f(ip,k) - trcqgofk(ip,k)
  145        continue
  155     continue

  150   continue

      do 90 ip=1,msq 
         hdpth(ip,mlcur) = hdpth(ip,mlcur) - qgts * wbgml(ip)
         if (hdpth(ip,mlcur) .gt. maxh) hdpth(ip,mlcur) = maxh
  90   continue 

      return
      end
