      subroutine gau_metro(a,ndat,data,acpt) ! bernd berg nov 17 2000.
c
c metropolis generation of gaussian random numbers.
c    
c    input:  (unchanged on exit)
c    ======
c    a:            stepsize parameter; del \in [-a,+a].
c    ndat:         array dimension (number of data).
c    ranmar has to be initialized by rmaset on entry.
c                                                                     
c    output:
c    ======= 
c    data(ndat):   markov sequence of gaussian random numbers.
c    acpt:         acceptance rate.
c
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension data(ndat)
      data icall/0/
      save x,icall
      if(icall.eq.0) x=zero
      icall=1
c
      twoa=two*a
      acpt=zero
      do i=1,ndat
        x2=x**2
        call ranmar(xr)
        xp=x+twoa*(xr-half)
        xp2=xp**2
        if(xp2.le.x2) then
          x=xp
          acpt=acpt+one
        else
          call ranmar(xr)
          if(exp(-half*(xp2-x2)).ge.xr) then
            x=xp
            acpt=acpt+one
          end if
        end if
        data(i)=x
      end do
      acpt=acpt/ndat
c
      return
      end
