      program pottsH0 ! BB Oct 17 2006. Modified from a0301_03 STMC_full.
C Potts models: Energy histogram from naive sampling.
      include '../../ForLib/implicit.sta'
      include '../../ForLib/constants.par'
      parameter(iud=9,iud0=10)
      include 'lat.par'
      include 'potts.par'
      include 'mc.par'
      include '../../ForLib/lat.com'
      include '../../ForLib/potts.com'
      include 'lat.dat'
      data iact/0/, ha/(mlink+1)*zero/
      ltest=.false.
      if(ltest) stop "pottsH0: ltest."
      ltest=.true.
C
      write(iuo,'(/,"pottsH0 sampling:")') 
      write(iuo,'(" nd,nq,nrpt,nmeas =",3I6,I12)') nd,nq,nrpt,nmeas
      call rmaset(iuo,iud,iseed1,iseed2,'ranmar.d')
      call lat_init(ns,nd,ipf,ipb,nla,ix,nlink)
      call potts_act_tab(idel,nqm1)
      open(iud,file='pottsDatH0.D',form='unformatted',status='unknown')
      write(iud) nrpt,nmeas,iseed1,iseed2
      do irpt=1,nrpt
        call write_progress(iud0,"irpt,iact,ha:",irpt,iact,ha(mlink))
        call razero(ha,0,mlink)
        do idat=1,nmeas
          call potts_ran(ista,ms,nq)
          call potts_act(ista,ipf,idel,ms,nqm1,nd,iact)
          ha(iact)=ha(iact)+one
        end do
        write(iuo,'(" irpt,iact,ha:",2I12,G14.5)') irpt,iact,ha(mlink)
        write(iud) irpt,iact,ha
      end do
      close(iud)
C
      write(iuo,'("pottsH0: All done.")') 
      stop
      end


      include '../../ForLib/rmaset.f'
      include '../../ForLib/ranmar.f'
      include '../../ForLib/rmasave.f'
      include '../../ForLib/ipointer.f'
      include '../../ForLib/ixcor.f'
      include '../../ForLib/isfun.f'
      include '../../ForLib/lat_init.f'
      include '../../ForLib/nsfun.f'
      include '../../ForLib/potts_act.f'
      include '../../ForLib/potts_act_tab.f'
      include '../../ForLib/potts_ran.f'
      include '../../ForLib/razero.f'
      include '../../ForLib/write_progress.f'
