      program anaw_cbsu3 ! Bernd Berg, Dec 6 2008. Reweighting.
C Master version in ../MPI_SU3.  Reweighting of energy (action), 
C specific heat, magnetization and its susceptibilities (chi).
      include '../../Libs/Fortran/implicit.sta'
      character cd*1,cf*1,cdmpi*1,clx*3,clt*3,cfl*14 ! cfile -> cfl.
      include '../../Libs/Fortran/constants.par'
      include 'latmpi.par' ! MPI.
      include 'mc.par'
      include '../../Libs/MPI_par/common_cblat.f'
      dimension tsa(nmeas),tsws(nmeas),tswt(nmeas)
      dimension act(nrpt),ws(nrpt),wt(nrpt)
      include 'latmpi.dat' ! nla needed.
      if(lsd2mpi) np=mpmpi     ! MPI total number of plaquettes.
      if(.not.lsd2mpi) np=mp   ! MPI total number of plaquettes.
      if(nlat.eq.1) beta=beta0 ! MPI beta.
      ltest=.true.
      ltest=.false.
      if(ltest) stop "anaw_cbsu3: ltest."
C
      write(iuo,'(/," anaw_cbsu3: nrpt,nskip =",2I4)') nrpt,nskip
      write(cd,'(I1.1)') nd ! Prepare to READ the data.
      write(cf,'(I1.1)') mpifactor
      write(cdmpi,'(I1.1)') ndmpi
      write(clx,'(I3.3)') nla(1)
      write(clt,'(I3.3)') nla(nd)
      write(cfl,'(A,"d",A,"f",A,"d",A,"x",A,"t")') cd,cf,cdmpi,clx,clt
      open(iud1,file=cfln//cfl//".D",form="unformatted",status="old")
c read rearranged for MPI:
      read(iud1) b0_in,b1_in,nd_in,nlat_in,ns,nlink,nla,ndmpi_in,
     &  msmpi_in,nla_mpi,nreq_in,nequi_in,nrpt_in,nmeas_in,nsw_in
      write(iuo,'(/," beta,nlink,nd,nla:",F15.10,I10,I3,2X,4I5)')
     &                beta,nlink,nd_in,nla
      write(iuo,'(" nequi,nrpt,nmeas,nsw: ",I15,2I10,I5)')
     &              nequi_in,nrpt_in,nmeas_in,nsw_in
      if(nd.ne.nd_in) stop "nd.ne.nd_in."
      if(nequi.ne.nequi_in) stop "nequi.ne.nequi_in."
      if(nrpt.ne.nrpt_in) stop "nrpt.ne.nrpt_in."
      if(nmeas.ne.nmeas_in) stop "nmeas.ne.nmeas_in."
      if(nsw.ne.nsw_in) stop "nws.ne.nw_in."
      ndat=0
      do irpt=1,nrpt
        read(iud1) tsa,tsws,tswt
        act(irpt)=stmean(nmeas,tsa)
        ws(irpt)=stmean(nmeas,tsws)
        wt(irpt)=stmean(nmeas,tswt)
      enddo
C
      call steb0(nrpt,act,actm,av,actme)
      write(iuo,'(" actm = ",F15.10," +/-",F15.10)') actm,actme
      call steb0(nrpt,ws,wsm,wv,wsme)
      write(iuo,'(" wsm =  ",F15.10," +/-",F15.10)') wsm,wsme
      call steb0(nrpt,wt,wtm,wv,wtme)
      write(iuo,'(" wst =  ",F15.10," +/-",F15.10)') wtm,wtme
C
      stop
      end

      include '../../Libs/Fortran/steb0.f'
      include '../../Libs/Fortran/stmean.f'
