c    @(#)msolve.f	1.1
c
c
c
      subroutine msolve
c
c --- this subroutine solves the adams-bashforth finite-element
c --- equations for the interior of the field
c
c --- array r (entering) = right-hand side of eq's
c --- array r (leaving) = solution
c
      include 'qg_par.inc'
      common/scrat/r(mn0),r1(mn0),r2(mn0),r3(mn0)
      common/cnn/n,nm1,nm2,np1
      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/solver/vam(m0),vbm(m0),van(n0),vbn(n0)
      dimension aux(mx0)
      dimension va(mx0),vb(mx0)
c
      do 5 j=1,m
	va(j)=vam(j)
	vb(j)=vbm(j)
    5 continue
      do 40 j=2,nm1
        i1=(j-1)*m+2
        aux(1)=r(i1)
        do 10 i=2,mm2
          aux(i)=r(i1+i-1)-va(i)*aux(i-1)
   10   continue
        aux(mm2)=aux(mm2)/vb(mm2)
        do 20 i=2,mm2
          ii=mm1-i
          aux(ii)=(aux(ii)-aux(ii+1))/vb(ii)
   20   continue
        do 30 i=1,mm2
          r1(i1+i-1)=aux(i)
   30   continue
   40 continue
c
      do 45 j=1,n
	va(j)=van(j)
	vb(j)=vbn(j)
   45 continue
      do 80 i=2,mm1
        i1=m+i
        aux(1)=r1(i1)
        do 50 j=2,nm2
          aux(j)=r1(i1+(j-1)*m)-va(j)*aux(j-1)
   50   continue
        aux(nm2)=aux(nm2)/vb(nm2)
        do 60 j=2,nm2
          jj=nm1-j
          aux(jj)=(aux(jj)-aux(jj+1))/vb(jj)
   60   continue
        do 70 j=1,nm2
          ip=i1+(j-1)*m
          r(ip)=aux(j)
   70   continue
   80 continue
      return
      end
