      program potts_rw0 ! BB Oct 17 2006. From a0301_03 STMC_full.
C Potts models: Energy histogram from re-weighting of naive sampling.
C               Error calculation from bins as stored.
      include '../../ForLib/implicit.sta'
      include '../../ForLib/constants.par'
      include 'lat.par'
      include 'potts.par'
      include 'mc.par'
      include '../../ForLib/lat.com'
      include '../../ForLib/potts.com'
      dimension hasum(0:mlink),hae(0:mlink),hb(0:mlink),hbe(0:mlink),
     & actl(0:nrpt),C(0:nrpt),Ca(nrpt)
      data hasum/(mlink+1)*zero/,hae/(mlink+1)*zero/,hbe/(mlink+1)*zero/
      include 'lat.dat'
      beta0=four/ten
      factor=ms*(beta0*2*nd)**2
      ltest=.true.
      ltest=.false.
      if(ltest) stop "potts_rw0: ltest."
C
      write(iuo,'(/,"potts_rw0: reweight to beta0 =",F12.8)') beta0
      write(iuo,'(/," Energy (action per link variable):")') 
      if(ltest) write(iuo,'(/,2X,"irpt",4X,"actl",7X,"ha(mlink)",/)') 
      open(iud1,file='pottsDatH0.D',form='unformatted',status='old')
      read(iud1) nrpt_in,nmeas_in
      if(nrpt.ne.nrpt_in) stop "nrpt.ne.nrpt_in."
      if(nmeas.ne.nmeas_in) stop "nmeas.ne.nmeas_in."
      do irpt=1,nrpt
        read(iud1) irpt_in,iact,ha
        do ilink=0,mlink
          hasum(ilink)=hasum(ilink)+ha(ilink)
        enddo
      enddo
      close(iud1)
C
      call potts_rwght(mlink,hasum,hae,zero,beta0,hb,hbe)
      actl(0)=potts_actl(mlink,hb)
      write(iuo,'(3X,"actlm =",F10.6,17X,"from all data")') actl(0)
      write(iuo,'(/,1X,"Specific heat:")') 
      act2lm=potts_act2l(mlink,hb)
      C(0)=factor*(act2lm-actl(0)**2) 
      write(iuo,'(3X,"Cm =  ",F10.6,17X,"from all data")') C(0)
C
      stop
      end

      include '../../MyLib/potts_actl.f'
      include '../../MyLib/potts_act2l.f'

      include '../../ForLib/razero.f'
      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/potts_rwght.f'
      include '../../ForLib/steb0.f'
