c    @(#)rhs.f	1.2
c
c
c
      subroutine rhs(s,prv)
c
c --- this subroutine calculates the right-hand-side (rhs) of
c --- the finite-element vorticity equation
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/edges/icorn(4),ncorn(4),mast(4),nast(4)
      common/dynam/alpha,beta,rf
      common/cnn/n,nm1,nm2,np1
      dimension s(mn0),prv(mn0)
c
      fac=-36*dt/(hy**2)
      do 10 ip=1,msq
        s(ip)=fac*s(ip)
   10 continue
      do 30 iside=1,4
        ip=ncorn(iside)
        ib=icorn(iside)
        s(ip)=s(ip)+.25*s(ib)
	if(ib.eq.1.or.ib.eq.msq)mn1=mm1
	if(ib.eq.m.or.ib.eq.msq-m+1)mn1=nm1
        do 20 j=2,mn1
          ib=ip-nast(iside)
          s(ip)=s(ip)-.5*s(ib)
          ip=ip+mast(iside)
   20   continue
   30 continue
c
      do 40 ip=1,msq
        fq=prv(ip)
        prv(ip)=s(ip)
        s(ip)=1.5*s(ip)-0.5*fq
   40 continue
      return
      end
