c    @(#)interp.f	1.1
c
c
c
      subroutine interp(tx)
c
c --- this subroutine interpolates between data updates for time
c --- steps where there is no data. subroutine getfld is called when
c --- there is new data to be read.
c
      include'qg_par.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
      common/field/psi(mn0,k0),zeta(mn0,k0),tlast,day1,tkeep,
     +  curpsi(mn0,k0),curzet(mn0,k0),psiprv(mn0,k0),zetprv(mn0,k0),
     +    topprv(mn0),topcur(mn0),topdens(mn0)
      common/verify/verpsi(mn0,k0),verzeta(mn0,k0)
c
c --- check to see if need new data. if so, call getfld to get it.
c
      data tcall/-999./
c
      if(tcall.eq.tx) return
      tcall=tx
      if(tx-tlast.le.day1) goto 50
      do 15 k=1,kz
        do 10 i=1,msq
          psiprv(i,k)=curpsi(i,k)
          zetprv(i,k)=curzet(i,k)
          if(k.eq.1)topprv(i)=topcur(i)
   10   continue
   15 continue
      tlast=tlast+day1
      call getfld(curpsi,curzet,topcur,tx)
   50 continue
c
c --- linearly interpolate between data updates
c
      ratio=(tx-tlast)/day1
      do 75 k=1,kz
        do 70 i=1,msq
          psi(i,k)=psiprv(i,k)+ratio*(curpsi(i,k)-psiprv(i,k))
          zeta(i,k)=zetprv(i,k)+ratio*(curzet(i,k)-zetprv(i,k))
         if(k.eq.1)topdens(i)=topprv(i)+ratio*(topcur(i)-topprv(i))
          verpsi(i,k)=psi(i,k)
          verzeta(i,k)=zeta(i,k)
   70   continue
   75 continue
c
      return
      end
