      subroutine precondmatrix(nmax1, nzeromax1, spau1, spal1)
      implicit double precision (a-h,o-z)
      include 'params.for'
      common/mats/ sparsu(nmax*nzeromax),sparsl(nmax*nzeromax),
     $     spu(nmax*nzeromax),spl(nmax*nzeromax),
     $     index(nmax*nzeromax),irwst(nmax)
      dimension spau1(nmax1*nzeromax1),spal1(nmax1*nzeromax1)

      do i=1,nmax1
         do j=irwst(i),irwst(i+1)-1
            spu(j) = spau1(j)
            spl(j) = spal1(j)
         enddo
      enddo

      return
      end


      subroutine initmatrix(nmax1, nzeromax1, irwst1, index1)
      implicit double precision (a-h,o-z)
      include 'params.for'
c      common/mats/ sparsu(nmax*nzeromax),sparsl(nmax*nzeromax),
c     $     spu(nmax*nzeromax),spl(nmax*nzeromax),
c     $     index(nmax*nzeromax),irwst(nmax)
      common/matsC/ spars(nmax*nzeromax),index(nmax*nzeromax),
     $     irwst(nmax+1)

      dimension index1(nmax1*nzeromax1),irwst1(nmax1+1)

      if(nmax .lt. nmax1)then
         print*,'nmax in params.for is to small',nmax,'<',nmax1
         stop
      endif
      do i=1,nmax1+1
         irwst(i)=irwst1(i)+1
      enddo
      do i=1,nmax1
         do j=irwst(i),irwst(i+1)-1
            index(j) = index1(j)+1
         enddo
      enddo

      return
      end

c      subroutine interface(nmax1, nzeromax1, sparsu1, sparsl1, 
c     *     b, x, bcnods,it,rez)
      subroutine interface(nmax1, nzeromax1, spars1,irwst1, index1,
     *     b, x, bcnods,it,rez)
      implicit double precision (a-h,o-z)
      include 'params.for'
c      common/mats/ sparsu(nmax*nzeromax),sparsl(nmax*nzeromax),
c     $     spu(nmax*nzeromax),spl(nmax*nzeromax),
c     $     index(nmax*nzeromax),irwst(nmax)
  
      common/matsC/ spars(nmax*nzeromax),index(nmax*nzeromax),
     $     irwst(nmax+1)

c      dimension sparsu1(nmax1*nzeromax1),sparsl1(nmax1*nzeromax1),
c     *     bcnods(nmax1),b(nmax1),x(nmax1)

      dimension spars1(nmax1*nzeromax1),
     *     bcnods(nmax1),b(nmax1),x(nmax1),
     *     index1(nmax*nzeromax), irwst1(nmax+1)

      external ilufac,prod

      
c      do i=1,nmax1
c         do j=irwst(i),irwst(i+1)-1
c            spars(j) = spars1(j)
cc            sparsu(j) = sparsu1(j)
cc            sparsl(j) = sparsl1(j)
ccc            index(j) = index1(j)+1
c         enddo
c      enddo


c      do i=1,nmax1+1
c         irwst(i)=irwst1(i)+1
c      enddo
c      do i=1,nmax1
c         do j=irwst(i),irwst(i+1)-1
c            index(j) = index1(j)+1
c         enddo
c      enddo


      nits = 15
      gmrestol=5E-01
      gmrestol2=1E-06
      iout=0

c      print*,'INTERFACE'
c      do j=1,5
c         print*,j,irwst1(j),index1(j),spars1(j) 
c      enddo

c      call setup_precon(nmax1,bcnods)

c      print *,'Start GMRES'
      call gmres(x,b,nmax1,nits,gmrestol,bcnods,prod,
     &     ilufac,400,gmrestol2,iout,it,rez,spars1,irwst1, index1)
c      print *,'END   GMRES'

      return
      end
