      subroutine su3_mchb ! Bazvov / Berg Mar 6 2008. 
C SU(3) heatbath updating.
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      include '../../Libs/Fortran_par/lat.par'
      include '../../Libs/Fortran_par/mc.par'
      include '../../Libs/Fortran_par/common_lat.f'
      include '../../Libs/SU3_par/common_su3.f'
      dimension staple(1:18), aa(1:18)
      amin=act
      amax=act
c initialize a0acpt and a0prop (accepted and proposed a0)
      a0prop=zero
      a0acpt=zero
c loop on number of links = double cycle: on id=1,nd and is=1,ms
      do is=1,ms
        do id=1,nd
          call su3_getstaple(id,is,staple) ! staple for the link. Subtract
          call su3mult_m_m_m(staple,alsu3(1,id,is),aa) ! old value from act.
          trace=aa(1)+aa(5)+aa(9)
          act=act-trace/three
          call su3_update_su2(id,is,staple,1,2,iacc) ! Update 1,2 subgroup.
          a0prop=a0prop+iacc
          call su3_update_su2(id,is,staple,2,3,iacc) ! Update 2,3 subgroup.
          a0prop=a0prop+iacc
          call su3_update_su2(id,is,staple,3,1,iacc) ! Update 3,1 subgroup.
          a0prop=a0prop+iacc
          call su3mult_m_m_m(staple,alsu3(1,id,is),aa) ! Add new value to act.
          trace=aa(1)+aa(5)+aa(9)
          act=act+trace/three
          call su3reunit(alsu3(1,id,is)) ! Reunitarize link.
        end do
      end do
      a0acpt=mlink*3 ! Calculate average acceptance rate for this sweep:
      acpt=a0acpt/a0prop
      return
      end
