c    @(#)wget.f	1.6
      subroutine wgetbg

      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
                

         tday = mltime
         wcyc = getflx(tday,wbgbar,wbgamp,wbgpha)

         do 70 ip=1,msq

            do 80 k=1,l

               zwbg = abs(zml(k))
               if (ifwbg .eq. 1) then
                  zwbgm = hdpth(ip,mlcur)
                 else
                  zwbgm = wbgref
                endif
               if (zwbg .le. zwbgm) then 
                  wbg(ip,k) = wcyc * (zwbg / zwbgm)
                 else 
                  wbg(ip,k) = wcyc * (-zml(l) - zwbg) / 
     .                               (-zml(l) - zwbgm)
                endif

   80        continue

             if (ifwbg .eq. 1) then
                wbgml(ip) = wcyc
               else
                zwbg = hdpth(ip,mlcur)
                if (zwbg .le. zwbgm) then 
                   wbgml(ip) = wcyc * (zwbg / zwbgm)
                  else 
                   wbgml(ip) = wcyc * (-zml(l) - zwbg) / 
     .                                (-zml(l) - zwbgm)
                 endif
              endif

   70     continue

      do 81 k=1,l
         write(82,*)zml(k),wbg(1,k)
   81  continue

      write(83,*)-hdpth(1,mlcur),wbgml(1)
c
c
      return
      end

      function getflx(t,bar,amp,pha)
      parameter (pi=3.14159)

      getflx = bar + amp * cos(2. * pi * (t - pha) / 365.) 

      return
      end
