      subroutine tsa_z(n,nmeas,tsa,betap,beta,actm,z,a1,a2) 
c bernd berg, jan 27 2006. reweighting of energy and specific heat.
c n:     multiplicative factor to convert energy (action) per 
c        degree of freedom to extensive energy (action
c nmeas: number of measurements in tsa(nmeas) on input. 
c tsa:   energy (action) times series on input.
c betap: beta value too which we reweight.
c beta:  beta value at which the data were produced.
c actm:  means value over all data of the action variable.
c z:     partition function patch one output.
c a1:    numerator of action density on output
c a2:    numerator of action density squared on output.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension tsa(nmeas)
      ltest=.true.
      ltest=.false.
      if(ltest) stop "tsa_z: ltest."
c
      act=tsa(1) 
      z=exp((betap-beta)*(act-actm)*n)
      a1=act*z
      a2=act*a1
      do imeas=2,nmeas
        act=tsa(imeas) 
        zadd=exp((betap-beta)*(act-actm)*n)
        a1add=act*zadd
        a2add=act*a1add
        z=z+zadd
        a1=a1+a1add
        a2=a2+a2add
      enddo
c
      return
      end
