c
c @(#)advtrans.f	1.2
c
      subroutine advtrans(f,iopt)

      include'mladv.inc'

      dimension f(mnmax,lmax), fml(mnmax), frl(mnmax)

      common /scrat/ r(mn0), r1(mn0), r2(mn0), r3(mn0)
 
      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
                 
      common /cnn/n,nm1,nm2,np1
 
      common /extpar/ rlat0, rlng0, t0, v0, dhor, ht, time0,
     +                r0,f0star

c
c
c

      sf=v0/(hy*dxyml)

      do 1 k=kmlmin,kmlmax

         do 2 ip=1,msq

            if (k.le.ihdpth(ip)) then
               fml(ip) = f(ip,k)
              else
               fml(ip) = f(ip,ihdpth(ip))
             endif

            if (k.gt.ihdpth(ip)) then
               frl(ip) = f(ip,k)
              else
               frl(ip) = f(ip,ihdpth(ip)+1)
             endif

  2      continue

        if (iopt .eq. 1) then

           call darajac(r,fml,advml(1,k),m,n,sf)
           call darajac(r,frl,advrl(1,k),m,n,sf)

          else

           call filter(fml,m,n,nord)
           call filter(frl,m,n,nord)

           do 3 ip=1,msq
              advml(ip,k)=fml(ip)
              advrl(ip,k)=frl(ip)
  3         continue

         endif


  1    continue

      return
      end
