      subroutine spill(nb)
      implicit none
      include 'pimc.par'
      integer iflag,l,js,nb,i,nj
      data iflag/0/
      save iflag
      include 'pimc.cm'

      if (iflag.eq.0) then
       iflag=1
       inquire(file=filen(1:ln)//'.rs',exist=ifex)
       if(ifex) then
        rewind(3)
       else
        open(3,file=filen(1:ln)//'.rs',form='formatted',status='new')
       endif
      else
       rewind(3)
      endif
      write(3,*) ndim,(ell(l),l=1,ndim),rnn
      write(3,*) np,nslices,(((x(l,nj,js),l=1,ndim),nj=1,np)
     &          ,js=1,nslices),((proton(l,nj),l=1,ndim),nj=1,2)
      write(3,*) nb,nstep,nav,(av(i),anorm(i),i=1,nav)
      call flush(3)
      return
      end
