      subroutine xy_met(lacpt) ! bernd berg, feb 15 2002. 
c xy model: sequential metropolis updating. 
c acceptance rate self-adjusting. recommended value acptrate=0.4. 
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
c     parameter(n=2,acptrate=one/1000) ! natural acceptance rate.
c     parameter(n=2,acptrate=one/four) ! set acceptance rate.
c     parameter(n=2,acptrate=three/10) ! set acceptance rate.
      parameter(n=2,acptrate=four/10)  ! set acceptance rate.
c     parameter(n=2,acptrate=(four+half)/10) ! set acceptance rate.
c     parameter(n=2,acptrate=five/10)  ! set acceptance rate.
c     parameter(n=2,acptrate=six/10)   ! set acceptance rate.
c     parameter(n=2,acptrate=seven/10) ! set acceptance rate.
      parameter(factor=one/acptrate)
      include 'lat.par'
      include 'mc.par'
      include '../../libs/fortran_par/common_lat.f'
      include '../../libs/on_par/common_on.f'
      data dphi/tpi/, facpt/zero/, sweep/zero/
      save dphi,facpt
      amin=act
      amax=act
      acpt0=zero
      do is=1,ms
        phi=dphi*(rmafun()-half)
        c_phi=cos(phi)
        s_phi=sin(phi)
        x=sta(1,is)
        y=sta(2,is)
        xnew=+c_phi*x-s_phi*y
        ynew=+s_phi*x+c_phi*y
        dx=xnew-x
        dy=ynew-y
        dact=zero
        do id=1,nd
          dact=dact+sta(1,ipf(id,is))*dx+sta(2,ipf(id,is))*dy
          dact=dact+sta(1,ipb(id,is))*dx+sta(2,ipb(id,is))*dy
        end do
        if(dact.lt.zero) then
        if(rmafun().ge.exp(beta*dact)) go to 1
        end if
          sta(1,is)=xnew
          sta(2,is)=ynew
          act=act+dact
          acpt0=acpt0+one
          amin=min(amin,act)
          amax=max(amax,act)
 1      continue
      end do
      acpt=acpt+acpt0
      facpt=facpt+factor*acpt0/ms
      sweep=sweep+one
      if(lacpt) then
	facpt=max(facpt,one/ms)/sweep
	dphi=min(tpi,facpt*dphi)
	facpt=zero
	sweep=zero
	lacpt=.false.
      end if 
      a_min=min(a_min,amin)
      a_max=max(a_max,amax)
      return
      end
